Total Complexity | 1051 |
Total Lines | 5684 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AccountingBookkeepingController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AccountingBookkeepingController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
59 | class AccountingBookkeepingController extends DolibarrController |
||
|
|||
60 | { |
||
61 | public function index() |
||
62 | { |
||
63 | $this->list(); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * \file htdocs/accountancy/bookkeeping/balance.php |
||
68 | * \ingroup Accountancy (Double entries) |
||
69 | * \brief Balance of book keeping |
||
70 | */ |
||
71 | public function balance() |
||
72 | { |
||
73 | global $conf; |
||
74 | global $db; |
||
75 | global $user; |
||
76 | global $hookmanager; |
||
77 | global $user; |
||
78 | global $menumanager; |
||
79 | global $langs; |
||
80 | |||
81 | // Load translation files required by the page |
||
82 | $langs->loadLangs(array("accountancy", "compta")); |
||
83 | |||
84 | $action = GETPOST('action', 'aZ09'); |
||
85 | $optioncss = GETPOST('optioncss', 'alpha'); |
||
86 | $type = GETPOST('type', 'alpha'); |
||
87 | if ($type == 'sub') { |
||
88 | $context_default = 'balancesubaccountlist'; |
||
89 | } else { |
||
90 | $context_default = 'balancelist'; |
||
91 | } |
||
92 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : $context_default; |
||
93 | $show_subgroup = GETPOST('show_subgroup', 'alpha'); |
||
94 | $search_date_start = dol_mktime(0, 0, 0, GETPOSTINT('date_startmonth'), GETPOSTINT('date_startday'), GETPOSTINT('date_startyear')); |
||
95 | $search_date_end = dol_mktime(23, 59, 59, GETPOSTINT('date_endmonth'), GETPOSTINT('date_endday'), GETPOSTINT('date_endyear')); |
||
96 | $search_ledger_code = GETPOST('search_ledger_code', 'array'); |
||
97 | $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); |
||
98 | if ($search_accountancy_code_start == - 1) { |
||
99 | $search_accountancy_code_start = ''; |
||
100 | } |
||
101 | $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha'); |
||
102 | if ($search_accountancy_code_end == - 1) { |
||
103 | $search_accountancy_code_end = ''; |
||
104 | } |
||
105 | $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha'); |
||
106 | |||
107 | // Load variable for pagination |
||
108 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; |
||
109 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
110 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
111 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
112 | if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { |
||
113 | $page = 0; |
||
114 | } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action |
||
115 | $offset = $limit * $page; |
||
116 | $pageprev = $page - 1; |
||
117 | $pagenext = $page + 1; |
||
118 | if ($sortorder == "") { |
||
119 | $sortorder = "ASC"; |
||
120 | } |
||
121 | if ($sortfield == "") { |
||
122 | $sortfield = "t.numero_compte"; |
||
123 | } |
||
124 | |||
125 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
126 | $object = new BookKeeping($db); |
||
127 | $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array |
||
128 | |||
129 | $formaccounting = new FormAccounting($db); |
||
130 | $formother = new FormOther($db); |
||
131 | $form = new Form($db); |
||
132 | |||
133 | if (empty($search_date_start) && !GETPOSTISSET('formfilteraction')) { |
||
134 | $sql = "SELECT date_start, date_end from " . MAIN_DB_PREFIX . "accounting_fiscalyear "; |
||
135 | $sql .= " WHERE date_start < '" . $db->idate(dol_now()) . "' AND date_end > '" . $db->idate(dol_now()) . "'"; |
||
136 | $sql .= $db->plimit(1); |
||
137 | $res = $db->query($sql); |
||
138 | |||
139 | if ($res->num_rows > 0) { |
||
140 | $fiscalYear = $db->fetch_object($res); |
||
141 | $search_date_start = strtotime($fiscalYear->date_start); |
||
142 | $search_date_end = strtotime($fiscalYear->date_end); |
||
143 | } else { |
||
144 | $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); |
||
145 | $year_start = dol_print_date(dol_now(), '%Y'); |
||
146 | if (dol_print_date(dol_now(), '%m') < $month_start) { |
||
147 | $year_start--; // If current month is lower that starting fiscal month, we start last year |
||
148 | } |
||
149 | $year_end = $year_start + 1; |
||
150 | $month_end = $month_start - 1; |
||
151 | if ($month_end < 1) { |
||
152 | $month_end = 12; |
||
153 | $year_end--; |
||
154 | } |
||
155 | $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); |
||
156 | $search_date_end = dol_get_last_day($year_end, $month_end); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if (!isModEnabled('accounting')) { |
||
161 | accessforbidden(); |
||
162 | } |
||
163 | if ($user->socid > 0) { |
||
164 | accessforbidden(); |
||
165 | } |
||
166 | if (!$user->hasRight('accounting', 'mouvements', 'lire')) { |
||
167 | accessforbidden(); |
||
168 | } |
||
169 | |||
170 | /* |
||
171 | * Action |
||
172 | */ |
||
173 | |||
174 | $param = ''; |
||
175 | |||
176 | $parameters = array(); |
||
177 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
178 | if ($reshook < 0) { |
||
179 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
180 | } |
||
181 | |||
182 | if (empty($reshook)) { |
||
183 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
||
184 | $show_subgroup = ''; |
||
185 | $search_date_start = ''; |
||
186 | $search_date_end = ''; |
||
187 | $search_date_startyear = ''; |
||
188 | $search_date_startmonth = ''; |
||
189 | $search_date_startday = ''; |
||
190 | $search_date_endyear = ''; |
||
191 | $search_date_endmonth = ''; |
||
192 | $search_date_endday = ''; |
||
193 | $search_accountancy_code_start = ''; |
||
194 | $search_accountancy_code_end = ''; |
||
195 | $search_not_reconciled = ''; |
||
196 | $search_ledger_code = array(); |
||
197 | $filter = array(); |
||
198 | } |
||
199 | |||
200 | // Must be after the remove filter action, before the export. |
||
201 | $filter = array(); |
||
202 | |||
203 | if (!empty($search_date_start)) { |
||
204 | $filter['t.doc_date>='] = $search_date_start; |
||
205 | $param .= '&date_startmonth=' . GETPOSTINT('date_startmonth') . '&date_startday=' . GETPOSTINT('date_startday') . '&date_startyear=' . GETPOSTINT('date_startyear'); |
||
206 | } |
||
207 | if (!empty($search_date_end)) { |
||
208 | $filter['t.doc_date<='] = $search_date_end; |
||
209 | $param .= '&date_endmonth=' . GETPOSTINT('date_endmonth') . '&date_endday=' . GETPOSTINT('date_endday') . '&date_endyear=' . GETPOSTINT('date_endyear'); |
||
210 | } |
||
211 | if (!empty($search_doc_date)) { |
||
212 | $filter['t.doc_date'] = $search_doc_date; |
||
213 | $param .= '&doc_datemonth=' . GETPOSTINT('doc_datemonth') . '&doc_dateday=' . GETPOSTINT('doc_dateday') . '&doc_dateyear=' . GETPOSTINT('doc_dateyear'); |
||
214 | } |
||
215 | if (!empty($search_accountancy_code_start)) { |
||
216 | if ($type == 'sub') { |
||
217 | $filter['t.subledger_account>='] = $search_accountancy_code_start; |
||
218 | } else { |
||
219 | $filter['t.numero_compte>='] = $search_accountancy_code_start; |
||
220 | } |
||
221 | $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start); |
||
222 | } |
||
223 | if (!empty($search_accountancy_code_end)) { |
||
224 | if ($type == 'sub') { |
||
225 | $filter['t.subledger_account<='] = $search_accountancy_code_end; |
||
226 | } else { |
||
227 | $filter['t.numero_compte<='] = $search_accountancy_code_end; |
||
228 | } |
||
229 | $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end); |
||
230 | } |
||
231 | if (!empty($search_ledger_code)) { |
||
232 | $filter['t.code_journal'] = $search_ledger_code; |
||
233 | foreach ($search_ledger_code as $code) { |
||
234 | $param .= '&search_ledger_code[]=' . urlencode($code); |
||
235 | } |
||
236 | } |
||
237 | if (!empty($search_not_reconciled)) { |
||
238 | $filter['t.reconciled_option'] = $search_not_reconciled; |
||
239 | $param .= '&search_not_reconciled=' . urlencode($search_not_reconciled); |
||
240 | } |
||
241 | |||
242 | // param with type of list |
||
243 | $url_param = substr($param, 1); // remove first "&" |
||
244 | if (!empty($type)) { |
||
245 | $param = '&type=' . $type . $param; |
||
246 | } |
||
247 | } |
||
248 | |||
249 | if ($action == 'export_csv') { |
||
250 | $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV'); |
||
251 | |||
252 | $filename = 'balance'; |
||
253 | $type_export = 'balance'; |
||
254 | include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; |
||
255 | |||
256 | if ($type == 'sub') { |
||
257 | $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, 0, $filter, 'AND', 1); |
||
258 | } else { |
||
259 | $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, 0, $filter); |
||
260 | } |
||
261 | if ($result < 0) { |
||
262 | setEventMessages($object->error, $object->errors, 'errors'); |
||
263 | } |
||
264 | |||
265 | foreach ($object->lines as $line) { |
||
266 | if ($type == 'sub') { |
||
267 | print '"' . length_accounta($line->subledger_account) . '"' . $sep; |
||
268 | print '"' . $line->subledger_label . '"' . $sep; |
||
269 | } else { |
||
270 | print '"' . length_accountg($line->numero_compte) . '"' . $sep; |
||
271 | print '"' . $object->get_compte_desc($line->numero_compte) . '"' . $sep; |
||
272 | } |
||
273 | print '"' . price($line->debit) . '"' . $sep; |
||
274 | print '"' . price($line->credit) . '"' . $sep; |
||
275 | print '"' . price($line->debit - $line->credit) . '"' . $sep; |
||
276 | print "\n"; |
||
277 | } |
||
278 | |||
279 | exit; |
||
280 | } |
||
281 | |||
282 | |||
283 | /* |
||
284 | * View |
||
285 | */ |
||
286 | |||
287 | if ($type == 'sub') { |
||
288 | $title_page = $langs->trans("AccountBalanceSubAccount"); |
||
289 | } else { |
||
290 | $title_page = $langs->trans("AccountBalance"); |
||
291 | } |
||
292 | |||
293 | $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double'; |
||
294 | |||
295 | llxHeader('', $title_page, $help_url); |
||
296 | |||
297 | |||
298 | if ($action != 'export_csv') { |
||
299 | // List |
||
300 | $nbtotalofrecords = ''; |
||
301 | if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { |
||
302 | if ($type == 'sub') { |
||
303 | $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter, 'AND', 1); |
||
304 | } else { |
||
305 | $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); |
||
306 | } |
||
307 | |||
308 | if ($nbtotalofrecords < 0) { |
||
309 | setEventMessages($object->error, $object->errors, 'errors'); |
||
310 | } |
||
311 | } |
||
312 | |||
313 | if ($type == 'sub') { |
||
314 | $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter, 'AND', 1); |
||
315 | } else { |
||
316 | $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter); |
||
317 | } |
||
318 | |||
319 | if ($result < 0) { |
||
320 | setEventMessages($object->error, $object->errors, 'errors'); |
||
321 | } |
||
322 | |||
323 | print '<form method="POST" id="searchFormList" action="' . $_SERVER['PHP_SELF'] . '">'; |
||
324 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
325 | print '<input type="hidden" name="action" id="action" value="list">'; |
||
326 | if ($optioncss != '') { |
||
327 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
328 | } |
||
329 | print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; |
||
330 | print '<input type="hidden" name="type" value="' . $type . '">'; |
||
331 | print '<input type="hidden" name="sortfield" value="' . $sortfield . '">'; |
||
332 | print '<input type="hidden" name="sortorder" value="' . $sortorder . '">'; |
||
333 | print '<input type="hidden" name="contextpage" value="' . $contextpage . '">'; |
||
334 | print '<input type="hidden" name="page" value="' . $page . '">'; |
||
335 | |||
336 | |||
337 | $parameters = array(); |
||
338 | $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
339 | |||
340 | if ($reshook < 0) { |
||
341 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
342 | } |
||
343 | |||
344 | $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint; |
||
345 | |||
346 | if (empty($reshook)) { |
||
347 | $newcardbutton = '<input type="button" id="exportcsvbutton" name="exportcsvbutton" class="butAction" value="' . $langs->trans("Export") . ' (' . getDolGlobalString('ACCOUNTING_EXPORT_FORMAT') . ')" />'; |
||
348 | |||
349 | print '<script type="text/javascript"> |
||
350 | jQuery(document).ready(function() { |
||
351 | jQuery("#exportcsvbutton").click(function(event) { |
||
352 | event.preventDefault(); |
||
353 | console.log("Set action to export_csv"); |
||
354 | jQuery("#action").val("export_csv"); |
||
355 | jQuery("#searchFormList").submit(); |
||
356 | jQuery("#action").val("list"); |
||
357 | }); |
||
358 | }); |
||
359 | </script>'; |
||
360 | |||
361 | if ($type == 'sub') { |
||
362 | $newcardbutton .= dolGetButtonTitle($langs->trans('AccountBalance') . " - " . $langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/balance.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly')); |
||
363 | $newcardbutton .= dolGetButtonTitle($langs->trans('AccountBalance') . " - " . $langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/balance.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); |
||
364 | } else { |
||
365 | $newcardbutton .= dolGetButtonTitle($langs->trans('AccountBalance') . " - " . $langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/balance.php?' . $url_param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); |
||
366 | $newcardbutton .= dolGetButtonTitle($langs->trans('AccountBalance') . " - " . $langs->trans('GroupBySubAccountAccounting'), '', 'fa fa-align-left vmirror paddingleft imgforviewmode', DOL_URL_ROOT . '/accountancy/bookkeeping/balance.php?type=sub&' . $url_param, '', 1, array('morecss' => 'marginleftonly')); |
||
367 | } |
||
368 | $newcardbutton .= dolGetButtonTitleSeparator(); |
||
369 | $newcardbutton .= dolGetButtonTitle($langs->trans('NewAccountingMvt'), '', 'fa fa-plus-circle paddingleft', DOL_URL_ROOT . '/accountancy/bookkeeping/card.php?action=create'); |
||
370 | } |
||
371 | if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) { |
||
372 | $param .= '&contextpage=' . urlencode($contextpage); |
||
373 | } |
||
374 | if ($limit > 0 && $limit != $conf->liste_limit) { |
||
375 | $param .= '&limit=' . ((int) $limit); |
||
376 | } |
||
377 | |||
378 | print_barre_liste($title_page, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); |
||
379 | |||
380 | $selectedfields = ''; |
||
381 | |||
382 | // Warning to explain why list of record is not consistent with the other list view (missing a lot of lines) |
||
383 | if ($type == 'sub') { |
||
384 | print info_admin($langs->trans("WarningRecordWithoutSubledgerAreExcluded")); |
||
385 | } |
||
386 | |||
387 | $moreforfilter = ''; |
||
388 | |||
389 | $moreforfilter .= '<div class="divsearchfield">'; |
||
390 | $moreforfilter .= $langs->trans('DateStart') . ': '; |
||
391 | $moreforfilter .= $form->selectDate($search_date_start ? $search_date_start : -1, 'date_start', 0, 0, 1, '', 1, 0); |
||
392 | $moreforfilter .= $langs->trans('DateEnd') . ': '; |
||
393 | $moreforfilter .= $form->selectDate($search_date_end ? $search_date_end : -1, 'date_end', 0, 0, 1, '', 1, 0); |
||
394 | $moreforfilter .= '</div>'; |
||
395 | |||
396 | $moreforfilter .= '<div class="divsearchfield">'; |
||
397 | $moreforfilter .= '<label for="show_subgroup">' . $langs->trans('ShowSubtotalByGroup') . '</label>: '; |
||
398 | $moreforfilter .= '<input type="checkbox" name="show_subgroup" id="show_subgroup" value="show_subgroup"' . ($show_subgroup == 'show_subgroup' ? ' checked' : '') . '>'; |
||
399 | $moreforfilter .= '</div>'; |
||
400 | |||
401 | $moreforfilter .= '<div class="divsearchfield">'; |
||
402 | $moreforfilter .= $langs->trans("Journals") . ': '; |
||
403 | $moreforfilter .= $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1); |
||
404 | $moreforfilter .= '</div>'; |
||
405 | |||
406 | //$moreforfilter .= '<br>'; |
||
407 | $moreforfilter .= '<div class="divsearchfield">'; |
||
408 | // Accountancy account |
||
409 | $moreforfilter .= $langs->trans('AccountAccounting') . ': '; |
||
410 | if ($type == 'sub') { |
||
411 | $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), 'maxwidth200'); |
||
412 | } else { |
||
413 | $moreforfilter .= $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200', 'accounts'); |
||
414 | } |
||
415 | $moreforfilter .= ' '; |
||
416 | if ($type == 'sub') { |
||
417 | $moreforfilter .= $formaccounting->select_auxaccount($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), 'maxwidth200'); |
||
418 | } else { |
||
419 | $moreforfilter .= $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200', 'accounts'); |
||
420 | } |
||
421 | $moreforfilter .= '</div>'; |
||
422 | |||
423 | if (getDolGlobalString('ACCOUNTING_ENABLE_LETTERING')) { |
||
424 | $moreforfilter .= '<div class="divsearchfield">'; |
||
425 | $moreforfilter .= '<label for="notreconciled">' . $langs->trans('NotReconciled') . '</label>: '; |
||
426 | $moreforfilter .= '<input type="checkbox" name="search_not_reconciled" id="notreconciled" value="notreconciled"' . ($search_not_reconciled == 'notreconciled' ? ' checked' : '') . '>'; |
||
427 | $moreforfilter .= '</div>'; |
||
428 | } |
||
429 | |||
430 | if (!empty($moreforfilter)) { |
||
431 | print '<div class="liste_titre liste_titre_bydiv centpercent">'; |
||
432 | print $moreforfilter; |
||
433 | $parameters = array(); |
||
434 | $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook |
||
435 | print $hookmanager->resPrint; |
||
436 | print '</div>'; |
||
437 | } |
||
438 | |||
439 | |||
440 | $colspan = (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE') ? 5 : 4); |
||
441 | |||
442 | print '<table class="liste ' . ($moreforfilter ? "listwithfilterbefore" : "") . '">'; |
||
443 | |||
444 | print '<tr class="liste_titre_filter">'; |
||
445 | |||
446 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
447 | print '<td class="liste_titre maxwidthsearch">'; |
||
448 | $searchpicto = $form->showFilterButtons(); |
||
449 | print $searchpicto; |
||
450 | print '</td>'; |
||
451 | } |
||
452 | |||
453 | print '<td class="liste_titre" colspan="' . $colspan . '">'; |
||
454 | print '</td>'; |
||
455 | |||
456 | // Fields from hook |
||
457 | $parameters = array(); |
||
458 | $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook |
||
459 | print $hookmanager->resPrint; |
||
460 | |||
461 | // Action column |
||
462 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
463 | print '<td class="liste_titre maxwidthsearch">'; |
||
464 | $searchpicto = $form->showFilterButtons(); |
||
465 | print $searchpicto; |
||
466 | print '</td>'; |
||
467 | } |
||
468 | print '</tr>' . "\n"; |
||
469 | |||
470 | print '<tr class="liste_titre">'; |
||
471 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
472 | print getTitleFieldOfList($selectedfields, 0, $_SERVER['PHP_SELF'], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n"; |
||
473 | } |
||
474 | print_liste_field_titre("AccountAccounting", $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); |
||
475 | // TODO : Retrieve the type of third party: Customer / Supplier / Employee |
||
476 | //if ($type == 'sub') { |
||
477 | // print_liste_field_titre("Type", $_SERVER['PHP_SELF'], "t.type", "", $param, "", $sortfield, $sortorder); |
||
478 | //} |
||
479 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
480 | print_liste_field_titre("OpeningBalance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); |
||
481 | } |
||
482 | print_liste_field_titre("AccountingDebit", $_SERVER['PHP_SELF'], "t.debit", "", $param, 'class="right"', $sortfield, $sortorder); |
||
483 | print_liste_field_titre("AccountingCredit", $_SERVER['PHP_SELF'], "t.credit", "", $param, 'class="right"', $sortfield, $sortorder); |
||
484 | print_liste_field_titre("Balance", $_SERVER['PHP_SELF'], "", $param, "", 'class="right"', $sortfield, $sortorder); |
||
485 | |||
486 | // Hook fields |
||
487 | $parameters = array('param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder); |
||
488 | $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook |
||
489 | print $hookmanager->resPrint; |
||
490 | // Action column |
||
491 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
492 | print getTitleFieldOfList($selectedfields, 0, $_SERVER['PHP_SELF'], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n"; |
||
493 | } |
||
494 | print '</tr>' . "\n"; |
||
495 | |||
496 | $total_debit = 0; |
||
497 | $total_credit = 0; |
||
498 | $sous_total_debit = 0; |
||
499 | $sous_total_credit = 0; |
||
500 | $total_opening_balance = 0; |
||
501 | $sous_total_opening_balance = 0; |
||
502 | $displayed_account = ""; |
||
503 | |||
504 | $accountingaccountstatic = new AccountingAccount($db); |
||
505 | |||
506 | // TODO Debug - This feature is dangerous, it takes all the entries and adds all the accounts |
||
507 | // without time and class limits (Class 6 and 7 accounts ???) and does not take into account the "a-nouveau" journal. |
||
508 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
509 | $sql = "SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance"; |
||
510 | $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; |
||
511 | $sql .= " WHERE t.entity = " . $conf->entity; // Never do sharing into accounting features |
||
512 | $sql .= " AND t.doc_date < '" . $db->idate($search_date_start) . "'"; |
||
513 | $sql .= " GROUP BY t.numero_compte"; |
||
514 | |||
515 | $resql = $db->query($sql); |
||
516 | $nrows = $resql->num_rows; |
||
517 | $opening_balances = array(); |
||
518 | for ($i = 0; $i < $nrows; $i++) { |
||
519 | $arr = $resql->fetch_array(); |
||
520 | $opening_balances["'" . $arr['numero_compte'] . "'"] = $arr['opening_balance']; |
||
521 | } |
||
522 | } |
||
523 | |||
524 | foreach ($object->lines as $line) { |
||
525 | // reset before the fetch (in case of the fetch fails) |
||
526 | $accountingaccountstatic->id = 0; |
||
527 | $accountingaccountstatic->account_number = ''; |
||
528 | |||
529 | if ($type != 'sub') { |
||
530 | $accountingaccountstatic->fetch(null, $line->numero_compte, true); |
||
531 | if (!empty($accountingaccountstatic->account_number)) { |
||
532 | $accounting_account = $accountingaccountstatic->getNomUrl(0, 1, 1); |
||
533 | } else { |
||
534 | $accounting_account = length_accountg($line->numero_compte); |
||
535 | } |
||
536 | } |
||
537 | |||
538 | $link = ''; |
||
539 | $total_debit += $line->debit; |
||
540 | $total_credit += $line->credit; |
||
541 | $opening_balance = isset($opening_balances["'" . $line->numero_compte . "'"]) ? $opening_balances["'" . $line->numero_compte . "'"] : 0; |
||
542 | $total_opening_balance += $opening_balance; |
||
543 | |||
544 | $tmparrayforrootaccount = $object->getRootAccount($line->numero_compte); |
||
545 | $root_account_description = $tmparrayforrootaccount['label']; |
||
546 | $root_account_number = $tmparrayforrootaccount['account_number']; |
||
547 | |||
548 | //var_dump($tmparrayforrootaccount); |
||
549 | //var_dump($accounting_account); |
||
550 | //var_dump($accountingaccountstatic); |
||
551 | if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) { |
||
552 | $link = '<a class="editfielda reposition" href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=update&token=' . newToken() . '&id=' . $accountingaccountstatic->id . '">' . img_edit() . '</a>'; |
||
553 | } elseif ($accounting_account == 'NotDefined') { |
||
554 | $link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>'; |
||
555 | } elseif (empty($tmparrayforrootaccount['label'])) { |
||
556 | // $tmparrayforrootaccount['label'] not defined = the account has not parent with a parent. |
||
557 | // This is useless, we should not create a new account when an account has no parent, we must edit it to fix its parent. |
||
558 | // BUG 1: Accounts on level root or level 1 must not have a parent 2 level higher, so should not show a link to create another account. |
||
559 | // BUG 2: Adding a link to create a new accounting account here is useless because it is not add as parent of the orphelin. |
||
560 | //$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>'; |
||
561 | } |
||
562 | |||
563 | if (!empty($show_subgroup)) { |
||
564 | // Show accounting account |
||
565 | if (empty($displayed_account) || $root_account_number != $displayed_account) { |
||
566 | // Show subtotal per accounting account |
||
567 | if ($displayed_account != "") { |
||
568 | print '<tr class="liste_total">'; |
||
569 | print '<td class="right">' . $langs->trans("SubTotal") . ':</td>'; |
||
570 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
571 | print '<td></td>'; |
||
572 | } |
||
573 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
574 | print '<td class="right nowraponall amount">' . price($sous_total_opening_balance) . '</td>'; |
||
575 | } |
||
576 | print '<td class="right nowraponall amount">' . price($sous_total_debit) . '</td>'; |
||
577 | print '<td class="right nowraponall amount">' . price($sous_total_credit) . '</td>'; |
||
578 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
579 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit)) . '</td>'; |
||
580 | } else { |
||
581 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_debit - $sous_total_credit)) . '</td>'; |
||
582 | } |
||
583 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
584 | print "<td></td>\n"; |
||
585 | } |
||
586 | print '</tr>'; |
||
587 | } |
||
588 | |||
589 | // Show first line of a break |
||
590 | print '<tr class="trforbreak">'; |
||
591 | print '<td colspan="' . ($colspan + 1) . '" class="tdforbreak">' . $root_account_number . ($root_account_description ? ' - ' . $root_account_description : '') . '</td>'; |
||
592 | print '</tr>'; |
||
593 | |||
594 | $displayed_account = $root_account_number; |
||
595 | $sous_total_debit = 0; |
||
596 | $sous_total_credit = 0; |
||
597 | $sous_total_opening_balance = 0; |
||
598 | } |
||
599 | } |
||
600 | |||
601 | print '<tr class="oddeven">'; |
||
602 | |||
603 | // Action column |
||
604 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
605 | print '<td class="center">'; |
||
606 | print $link; |
||
607 | print '</td>'; |
||
608 | } |
||
609 | |||
610 | // Accounting account |
||
611 | if ($type == 'sub') { |
||
612 | print '<td>' . $line->subledger_account . ' <span class="opacitymedium">(' . $line->subledger_label . ')</span></td>'; |
||
613 | } else { |
||
614 | print '<td>' . $accounting_account . '</td>'; |
||
615 | } |
||
616 | |||
617 | // Type |
||
618 | // TODO Retrieve the type of third party: Customer / Supplier / Employee |
||
619 | //if ($type == 'sub') { |
||
620 | // print '<td></td>'; |
||
621 | //} |
||
622 | |||
623 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
624 | print '<td class="right nowraponall amount">' . price(price2num($opening_balance, 'MT')) . '</td>'; |
||
625 | } |
||
626 | |||
627 | $urlzoom = ''; |
||
628 | if ($type == 'sub') { |
||
629 | if ($line->subledger_account) { |
||
630 | $urlzoom = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?type=sub&search_accountancy_code_start=' . urlencode($line->subledger_account) . '&search_accountancy_code_end=' . urlencode($line->subledger_account); |
||
631 | if (GETPOSTISSET('date_startmonth')) { |
||
632 | $urlzoom .= '&search_date_startmonth=' . GETPOSTINT('date_startmonth') . '&search_date_startday=' . GETPOSTINT('date_startday') . '&search_date_startyear=' . GETPOSTINT('date_startyear'); |
||
633 | } |
||
634 | if (GETPOSTISSET('date_endmonth')) { |
||
635 | $urlzoom .= '&search_date_endmonth=' . GETPOSTINT('date_endmonth') . '&search_date_endday=' . GETPOSTINT('date_endday') . '&search_date_endyear=' . GETPOSTINT('date_endyear'); |
||
636 | } |
||
637 | } |
||
638 | } else { |
||
639 | if ($line->numero_compte) { |
||
640 | $urlzoom = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start=' . urlencode($line->numero_compte) . '&search_accountancy_code_end=' . urlencode($line->numero_compte); |
||
641 | if (GETPOSTISSET('date_startmonth')) { |
||
642 | $urlzoom .= '&search_date_startmonth=' . GETPOSTINT('date_startmonth') . '&search_date_startday=' . GETPOSTINT('date_startday') . '&search_date_startyear=' . GETPOSTINT('date_startyear'); |
||
643 | } |
||
644 | if (GETPOSTISSET('date_endmonth')) { |
||
645 | $urlzoom .= '&search_date_endmonth=' . GETPOSTINT('date_endmonth') . '&search_date_endday=' . GETPOSTINT('date_endday') . '&search_date_endyear=' . GETPOSTINT('date_endyear'); |
||
646 | } |
||
647 | } |
||
648 | } |
||
649 | // Debit |
||
650 | print '<td class="right nowraponall amount"><a href="' . $urlzoom . '">' . price(price2num($line->debit, 'MT')) . '</a></td>'; |
||
651 | // Credit |
||
652 | print '<td class="right nowraponall amount"><a href="' . $urlzoom . '">' . price(price2num($line->credit, 'MT')) . '</a></td>'; |
||
653 | |||
654 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
655 | print '<td class="right nowraponall amount">' . price(price2num($opening_balance + $line->debit - $line->credit, 'MT')) . '</td>'; |
||
656 | } else { |
||
657 | print '<td class="right nowraponall amount">' . price(price2num($line->debit - $line->credit, 'MT')) . '</td>'; |
||
658 | } |
||
659 | |||
660 | // Action column |
||
661 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
662 | print '<td class="center">'; |
||
663 | print $link; |
||
664 | print '</td>'; |
||
665 | } |
||
666 | |||
667 | print "</tr>\n"; |
||
668 | |||
669 | // Records the sub-total |
||
670 | $sous_total_debit += $line->debit; |
||
671 | $sous_total_credit += $line->credit; |
||
672 | $sous_total_opening_balance += $opening_balance; |
||
673 | } |
||
674 | |||
675 | if (!empty($show_subgroup)) { |
||
676 | print '<tr class="liste_total">'; |
||
677 | // Action column |
||
678 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
679 | print "<td></td>\n"; |
||
680 | } |
||
681 | print '<td class="right">' . $langs->trans("SubTotal") . ':</td>'; |
||
682 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
683 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_opening_balance, 'MT')) . '</td>'; |
||
684 | } |
||
685 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_debit, 'MT')) . '</td>'; |
||
686 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_credit, 'MT')) . '</td>'; |
||
687 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
688 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit, 'MT')) . '</td>'; |
||
689 | } else { |
||
690 | print '<td class="right nowraponall amount">' . price(price2num($sous_total_debit - $sous_total_credit, 'MT')) . '</td>'; |
||
691 | } |
||
692 | // Action column |
||
693 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
694 | print "<td></td>\n"; |
||
695 | } |
||
696 | print '</tr>'; |
||
697 | } |
||
698 | |||
699 | print '<tr class="liste_total">'; |
||
700 | // Action column |
||
701 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
702 | print "<td></td>\n"; |
||
703 | } |
||
704 | print '<td class="right">' . $langs->trans("AccountBalance") . ':</td>'; |
||
705 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
706 | print '<td class="nowrap right">' . price(price2num($total_opening_balance, 'MT')) . '</td>'; |
||
707 | } |
||
708 | print '<td class="right nowraponall amount">' . price(price2num($total_debit, 'MT')) . '</td>'; |
||
709 | print '<td class="right nowraponall amount">' . price(price2num($total_credit, 'MT')) . '</td>'; |
||
710 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
711 | print '<td class="right nowraponall amount">' . price(price2num($total_opening_balance + $total_debit - $total_credit, 'MT')) . '</td>'; |
||
712 | } else { |
||
713 | print '<td class="right nowraponall amount">' . price(price2num($total_debit - $total_credit, 'MT')) . '</td>'; |
||
714 | } |
||
715 | // Action column |
||
716 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
717 | print "<td></td>\n"; |
||
718 | } |
||
719 | print '</tr>'; |
||
720 | |||
721 | // Accounting result |
||
722 | if (getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) { |
||
723 | print '<tr class="liste_total">'; |
||
724 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
725 | print "<td></td>\n"; |
||
726 | } |
||
727 | print '<td class="right">' . $langs->trans("AccountingResult") . ':</td>'; |
||
728 | if (getDolGlobalString('ACCOUNTANCY_SHOW_OPENING_BALANCE')) { |
||
729 | print '<td></td>'; |
||
730 | } |
||
731 | |||
732 | $accountingResult = $object->accountingResult($search_date_start, $search_date_end); |
||
733 | if ($accountingResult < 0) { |
||
734 | $accountingResultDebit = price(price2num(abs($accountingResult), 'MT')); |
||
735 | $accountingResultClassCSS = ' error'; |
||
736 | } else { |
||
737 | $accountingResultCredit = price(price2num($accountingResult, 'MT')); |
||
738 | $accountingResultClassCSS = ' green'; |
||
739 | } |
||
740 | print '<td class="right nowraponall amount' . $accountingResultClassCSS . '">' . $accountingResultDebit . '</td>'; |
||
741 | print '<td class="right nowraponall amount' . $accountingResultClassCSS . '">' . $accountingResultCredit . '</td>'; |
||
742 | |||
743 | print '<td></td>'; |
||
744 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
745 | print "<td></td>\n"; |
||
746 | } |
||
747 | print '</tr>'; |
||
748 | } |
||
749 | |||
750 | $parameters = array(); |
||
751 | $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
752 | print $hookmanager->resPrint; |
||
753 | |||
754 | print "</table>"; |
||
755 | print '</form>'; |
||
756 | } |
||
757 | |||
758 | // End of page |
||
759 | llxFooter(); |
||
760 | $db->close(); |
||
761 | } |
||
762 | |||
763 | /** |
||
764 | * \file htdocs/accountancy/bookkeeping/card.php |
||
765 | * \ingroup Accountancy (Double entries) |
||
766 | * \brief Page to show book-entry |
||
767 | */ |
||
768 | public function card() |
||
769 | { |
||
770 | global $conf; |
||
771 | global $db; |
||
772 | global $user; |
||
773 | global $hookmanager; |
||
774 | global $user; |
||
775 | global $menumanager; |
||
776 | global $langs; |
||
777 | // Load translation files required by the page |
||
778 | $langs->loadLangs(array("accountancy", "bills", "compta")); |
||
779 | |||
780 | $action = GETPOST('action', 'aZ09'); |
||
781 | $cancel = GETPOST('cancel', 'aZ09'); |
||
782 | |||
783 | $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') |
||
784 | |||
785 | $id = GETPOSTINT('id'); // id of record |
||
786 | $mode = GETPOST('mode', 'aZ09'); // '' or '_tmp' |
||
787 | $piece_num = GETPOSTINT("piece_num"); // id of transaction (several lines share the same transaction id) |
||
788 | |||
789 | $accountingaccount = new AccountingAccount($db); |
||
790 | $accountingjournal = new AccountingJournal($db); |
||
791 | |||
792 | $accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml'); |
||
793 | $accountingaccount->fetch(null, $accountingaccount_number, true); |
||
794 | $accountingaccount_label = $accountingaccount->label; |
||
795 | |||
796 | $journal_code = GETPOST('code_journal', 'alpha'); |
||
797 | $accountingjournal->fetch(null, $journal_code); |
||
798 | $journal_label = $accountingjournal->label; |
||
799 | |||
800 | $subledger_account = GETPOST('subledger_account', 'alphanohtml'); |
||
801 | if ($subledger_account == -1) { |
||
802 | $subledger_account = null; |
||
803 | } |
||
804 | $subledger_label = GETPOST('subledger_label', 'alphanohtml'); |
||
805 | |||
806 | $label_operation = GETPOST('label_operation', 'alphanohtml'); |
||
807 | $debit = (float) price2num(GETPOST('debit', 'alpha')); |
||
808 | $credit = (float) price2num(GETPOST('credit', 'alpha')); |
||
809 | |||
810 | $save = GETPOST('save', 'alpha'); |
||
811 | if (!empty($save)) { |
||
812 | $action = 'add'; |
||
813 | } |
||
814 | $update = GETPOST('update', 'alpha'); |
||
815 | if (!empty($update)) { |
||
816 | $action = 'confirm_update'; |
||
817 | } |
||
818 | |||
819 | $object = new BookKeeping($db); |
||
820 | |||
821 | // Security check |
||
822 | if (!isModEnabled('accounting')) { |
||
823 | accessforbidden(); |
||
824 | } |
||
825 | if ($user->socid > 0) { |
||
826 | accessforbidden(); |
||
827 | } |
||
828 | if (!$user->hasRight('accounting', 'mouvements', 'lire')) { |
||
829 | accessforbidden(); |
||
830 | } |
||
831 | |||
832 | |||
833 | /* |
||
834 | * Actions |
||
835 | */ |
||
836 | |||
837 | if ($cancel) { |
||
838 | header("Location: " . DOL_URL_ROOT . '/accountancy/bookkeeping/list.php'); |
||
839 | exit; |
||
840 | } |
||
841 | |||
842 | if ($action == "confirm_update") { |
||
843 | $error = 0; |
||
844 | |||
845 | if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { |
||
846 | $error++; |
||
847 | setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); |
||
848 | $action = 'update'; |
||
849 | } |
||
850 | if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { |
||
851 | $error++; |
||
852 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); |
||
853 | $action = 'update'; |
||
854 | } |
||
855 | |||
856 | if (!$error) { |
||
857 | $object = new BookKeeping($db); |
||
858 | |||
859 | $result = $object->fetch($id, null, $mode); |
||
860 | if ($result < 0) { |
||
861 | $error++; |
||
862 | setEventMessages($object->error, $object->errors, 'errors'); |
||
863 | } else { |
||
864 | $object->numero_compte = $accountingaccount_number; |
||
865 | $object->subledger_account = $subledger_account; |
||
866 | $object->subledger_label = $subledger_label; |
||
867 | $object->label_compte = $accountingaccount_label; |
||
868 | $object->label_operation = $label_operation; |
||
869 | $object->debit = $debit; |
||
870 | $object->credit = $credit; |
||
871 | |||
872 | if ((float) $debit != 0.0) { |
||
873 | $object->montant = $debit; // deprecated |
||
874 | $object->amount = $debit; |
||
875 | $object->sens = 'D'; |
||
876 | } |
||
877 | if ((float) $credit != 0.0) { |
||
878 | $object->montant = $credit; // deprecated |
||
879 | $object->amount = $credit; |
||
880 | $object->sens = 'C'; |
||
881 | } |
||
882 | |||
883 | $result = $object->update($user, false, $mode); |
||
884 | if ($result < 0) { |
||
885 | setEventMessages($object->error, $object->errors, 'errors'); |
||
886 | } else { |
||
887 | if ($mode != '_tmp') { |
||
888 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
889 | } |
||
890 | |||
891 | $debit = 0; |
||
892 | $credit = 0; |
||
893 | |||
894 | $action = ''; |
||
895 | } |
||
896 | } |
||
897 | } |
||
898 | } elseif ($action == "add") { |
||
899 | $error = 0; |
||
900 | |||
901 | if (((float) $debit != 0.0) && ((float) $credit != 0.0)) { |
||
902 | $error++; |
||
903 | setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); |
||
904 | $action = ''; |
||
905 | } |
||
906 | if (empty($accountingaccount_number) || $accountingaccount_number == '-1') { |
||
907 | $error++; |
||
908 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); |
||
909 | $action = ''; |
||
910 | } |
||
911 | |||
912 | if (!$error) { |
||
913 | $object = new BookKeeping($db); |
||
914 | |||
915 | $object->numero_compte = $accountingaccount_number; |
||
916 | $object->subledger_account = $subledger_account; |
||
917 | $object->subledger_label = $subledger_label; |
||
918 | $object->label_compte = $accountingaccount_label; |
||
919 | $object->label_operation = $label_operation; |
||
920 | $object->debit = $debit; |
||
921 | $object->credit = $credit; |
||
922 | $object->doc_date = (string) GETPOST('doc_date', 'alpha'); |
||
923 | $object->doc_type = (string) GETPOST('doc_type', 'alpha'); |
||
924 | $object->piece_num = $piece_num; |
||
925 | $object->doc_ref = (string) GETPOST('doc_ref', 'alpha'); |
||
926 | $object->code_journal = $journal_code; |
||
927 | $object->journal_label = $journal_label; |
||
928 | $object->fk_doc = GETPOSTINT('fk_doc'); |
||
929 | $object->fk_docdet = GETPOSTINT('fk_docdet'); |
||
930 | |||
931 | if ((float) $debit != 0.0) { |
||
932 | $object->montant = $debit; // deprecated |
||
933 | $object->amount = $debit; |
||
934 | $object->sens = 'D'; |
||
935 | } |
||
936 | |||
937 | if ((float) $credit != 0.0) { |
||
938 | $object->montant = $credit; // deprecated |
||
939 | $object->amount = $credit; |
||
940 | $object->sens = 'C'; |
||
941 | } |
||
942 | |||
943 | $result = $object->createStd($user, false, $mode); |
||
944 | if ($result < 0) { |
||
945 | setEventMessages($object->error, $object->errors, 'errors'); |
||
946 | } else { |
||
947 | if ($mode != '_tmp') { |
||
948 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
949 | } |
||
950 | |||
951 | $debit = 0; |
||
952 | $credit = 0; |
||
953 | |||
954 | $action = ''; |
||
955 | } |
||
956 | } |
||
957 | } elseif ($action == "confirm_delete") { |
||
958 | $object = new BookKeeping($db); |
||
959 | |||
960 | $result = $object->fetch($id, null, $mode); |
||
961 | $piece_num = $object->piece_num; |
||
962 | |||
963 | if ($result < 0) { |
||
964 | setEventMessages($object->error, $object->errors, 'errors'); |
||
965 | } else { |
||
966 | $result = $object->delete($user, false, $mode); |
||
967 | if ($result < 0) { |
||
968 | setEventMessages($object->error, $object->errors, 'errors'); |
||
969 | } |
||
970 | } |
||
971 | $action = ''; |
||
972 | } elseif ($action == "confirm_create") { |
||
973 | $error = 0; |
||
974 | |||
975 | $object = new BookKeeping($db); |
||
976 | |||
977 | if (!$journal_code || $journal_code == '-1') { |
||
978 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); |
||
979 | $action = 'create'; |
||
980 | $error++; |
||
981 | } |
||
982 | if (!GETPOST('doc_ref', 'alpha')) { |
||
983 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors'); |
||
984 | $action = 'create'; |
||
985 | $error++; |
||
986 | } |
||
987 | |||
988 | if (!$error) { |
||
989 | $object->label_compte = ''; |
||
990 | $object->debit = 0; |
||
991 | $object->credit = 0; |
||
992 | $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); |
||
993 | $object->doc_type = GETPOST('doc_type', 'alpha'); |
||
994 | $object->piece_num = GETPOSTINT('next_num_mvt'); |
||
995 | $object->doc_ref = GETPOST('doc_ref', 'alpha'); |
||
996 | $object->code_journal = $journal_code; |
||
997 | $object->journal_label = $journal_label; |
||
998 | $object->fk_doc = 0; |
||
999 | $object->fk_docdet = 0; |
||
1000 | $object->montant = 0; // deprecated |
||
1001 | $object->amount = 0; |
||
1002 | |||
1003 | $result = $object->createStd($user, 0, $mode); |
||
1004 | if ($result < 0) { |
||
1005 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1006 | } else { |
||
1007 | if ($mode != '_tmp') { |
||
1008 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
1009 | } |
||
1010 | $action = ''; |
||
1011 | $id = $object->id; |
||
1012 | $piece_num = $object->piece_num; |
||
1013 | } |
||
1014 | } |
||
1015 | } |
||
1016 | |||
1017 | if ($action == 'setdate') { |
||
1018 | $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); |
||
1019 | $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode); |
||
1020 | if ($result < 0) { |
||
1021 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1022 | } else { |
||
1023 | if ($mode != '_tmp') { |
||
1024 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
1025 | } |
||
1026 | $action = ''; |
||
1027 | } |
||
1028 | } |
||
1029 | |||
1030 | if ($action == 'setjournal') { |
||
1031 | $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode); |
||
1032 | $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode); |
||
1033 | if ($result < 0) { |
||
1034 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1035 | } else { |
||
1036 | if ($mode != '_tmp') { |
||
1037 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
1038 | } |
||
1039 | $action = ''; |
||
1040 | } |
||
1041 | } |
||
1042 | |||
1043 | if ($action == 'setdocref') { |
||
1044 | $refdoc = GETPOST('doc_ref', 'alpha'); |
||
1045 | $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode); |
||
1046 | if ($result < 0) { |
||
1047 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1048 | } else { |
||
1049 | if ($mode != '_tmp') { |
||
1050 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
1051 | } |
||
1052 | $action = ''; |
||
1053 | } |
||
1054 | } |
||
1055 | |||
1056 | // Validate transaction |
||
1057 | if ($action == 'valid') { |
||
1058 | $result = $object->transformTransaction(0, $piece_num); |
||
1059 | if ($result < 0) { |
||
1060 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1061 | } else { |
||
1062 | header("Location: list.php?sortfield=t.piece_num&sortorder=asc"); |
||
1063 | exit; |
||
1064 | } |
||
1065 | } |
||
1066 | |||
1067 | |||
1068 | /* |
||
1069 | * View |
||
1070 | */ |
||
1071 | |||
1072 | $form = new Form($db); |
||
1073 | $formaccounting = new FormAccounting($db); |
||
1074 | |||
1075 | $title = $langs->trans("CreateMvts"); |
||
1076 | $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double'; |
||
1077 | llxHeader('', $title, $help_url); |
||
1078 | |||
1079 | // Confirmation to delete the command |
||
1080 | if ($action == 'delete') { |
||
1081 | $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $id . '&mode=' . $mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1); |
||
1082 | print $formconfirm; |
||
1083 | } |
||
1084 | |||
1085 | if ($action == 'create') { |
||
1086 | print load_fiche_titre($title); |
||
1087 | |||
1088 | $object = new BookKeeping($db); |
||
1089 | $next_num_mvt = $object->getNextNumMvt('_tmp'); |
||
1090 | |||
1091 | if (empty($next_num_mvt)) { |
||
1092 | dol_print_error(null, 'Failed to get next piece number'); |
||
1093 | } |
||
1094 | |||
1095 | print '<form action="' . $_SERVER['PHP_SELF'] . '" name="create_mvt" method="POST">'; |
||
1096 | if ($optioncss != '') { |
||
1097 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
1098 | } |
||
1099 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
1100 | print '<input type="hidden" name="action" value="confirm_create">' . "\n"; |
||
1101 | print '<input type="hidden" name="next_num_mvt" value="' . $next_num_mvt . '">' . "\n"; |
||
1102 | print '<input type="hidden" name="mode" value="_tmp">' . "\n"; |
||
1103 | |||
1104 | print dol_get_fiche_head(); |
||
1105 | |||
1106 | print '<table class="border centpercent">'; |
||
1107 | |||
1108 | /*print '<tr>'; |
||
1109 | print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>'; |
||
1110 | print '<td>' . $next_num_mvt . '</td>'; |
||
1111 | print '</tr>';*/ |
||
1112 | |||
1113 | print '<tr>'; |
||
1114 | print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("Docdate") . '</td>'; |
||
1115 | print '<td>'; |
||
1116 | print $form->selectDate('', 'doc_date', 0, 0, 0, "create_mvt", 1, 1); |
||
1117 | print '</td>'; |
||
1118 | print '</tr>'; |
||
1119 | |||
1120 | print '<tr>'; |
||
1121 | print '<td class="fieldrequired">' . $langs->trans("Codejournal") . '</td>'; |
||
1122 | print '<td>' . $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1) . '</td>'; |
||
1123 | print '</tr>'; |
||
1124 | |||
1125 | print '<tr>'; |
||
1126 | print '<td class="fieldrequired">' . $langs->trans("Piece") . '</td>'; |
||
1127 | print '<td><input type="text" class="minwidth200" name="doc_ref" value="' . GETPOST('doc_ref', 'alpha') . '"></td>'; |
||
1128 | print '</tr>'; |
||
1129 | |||
1130 | /* |
||
1131 | print '<tr>'; |
||
1132 | print '<td>' . $langs->trans("Doctype") . '</td>'; |
||
1133 | print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>'; |
||
1134 | print '</tr>'; |
||
1135 | */ |
||
1136 | |||
1137 | print '</table>'; |
||
1138 | |||
1139 | print dol_get_fiche_end(); |
||
1140 | |||
1141 | print $form->buttonsSaveCancel("Create"); |
||
1142 | |||
1143 | print '</form>'; |
||
1144 | } else { |
||
1145 | $object = new BookKeeping($db); |
||
1146 | $result = $object->fetchPerMvt($piece_num, $mode); |
||
1147 | if ($result < 0) { |
||
1148 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1149 | } |
||
1150 | |||
1151 | if (!empty($object->piece_num)) { |
||
1152 | $backlink = '<a href="' . DOL_URL_ROOT . '/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">' . $langs->trans('BackToList') . '</a>'; |
||
1153 | |||
1154 | if ($mode == '_tmp') { |
||
1155 | print load_fiche_titre($langs->trans("CreateMvts"), $backlink); |
||
1156 | } else { |
||
1157 | print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); |
||
1158 | } |
||
1159 | |||
1160 | $head = array(); |
||
1161 | $h = 0; |
||
1162 | $head[$h][0] = $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . ($mode ? '&mode=' . $mode : ''); |
||
1163 | $head[$h][1] = $langs->trans("Transaction"); |
||
1164 | $head[$h][2] = 'transaction'; |
||
1165 | $h++; |
||
1166 | |||
1167 | print dol_get_fiche_head($head, 'transaction', '', -1); |
||
1168 | |||
1169 | //dol_banner_tab($object, '', $backlink); |
||
1170 | |||
1171 | print '<div class="fichecenter">'; |
||
1172 | print '<div class="fichehalfleft">'; |
||
1173 | |||
1174 | print '<div class="underbanner clearboth"></div>'; |
||
1175 | print '<table class="border tableforfield" width="100%">'; |
||
1176 | |||
1177 | // Account movement |
||
1178 | print '<tr>'; |
||
1179 | print '<td class="titlefield">' . $langs->trans("NumMvts") . '</td>'; |
||
1180 | print '<td>' . ($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp ' . $object->piece_num . '">' . $langs->trans("Draft") . '</span>' : $object->piece_num) . '</td>'; |
||
1181 | print '</tr>'; |
||
1182 | |||
1183 | // Date |
||
1184 | print '<tr><td>'; |
||
1185 | print '<table class="nobordernopadding centpercent"><tr><td>'; |
||
1186 | print $langs->trans('Docdate'); |
||
1187 | print '</td>'; |
||
1188 | if ($action != 'editdate') { |
||
1189 | print '<td class="right"><a class="editfielda reposition" href="' . $_SERVER['PHP_SELF'] . '?action=editdate&token=' . newToken() . '&piece_num=' . urlencode((string) ($object->piece_num)) . '&mode=' . urlencode((string) ($mode)) . '">' . img_edit($langs->transnoentitiesnoconv('SetDate'), 1) . '</a></td>'; |
||
1190 | } |
||
1191 | print '</tr></table>'; |
||
1192 | print '</td><td colspan="3">'; |
||
1193 | if ($action == 'editdate') { |
||
1194 | print '<form name="setdate" action="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
1195 | if ($optioncss != '') { |
||
1196 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
1197 | } |
||
1198 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
1199 | print '<input type="hidden" name="action" value="setdate">'; |
||
1200 | print '<input type="hidden" name="mode" value="' . $mode . '">'; |
||
1201 | print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', 0, 0, 0, "setdate"); |
||
1202 | print '<input type="submit" class="button button-edit" value="' . $langs->trans('Modify') . '">'; |
||
1203 | print '</form>'; |
||
1204 | } else { |
||
1205 | print $object->doc_date ? dol_print_date($object->doc_date, 'day') : ' '; |
||
1206 | } |
||
1207 | print '</td>'; |
||
1208 | print '</tr>'; |
||
1209 | |||
1210 | // Journal |
||
1211 | print '<tr><td>'; |
||
1212 | print '<table class="nobordernopadding" width="100%"><tr><td>'; |
||
1213 | print $langs->trans('Codejournal'); |
||
1214 | print '</td>'; |
||
1215 | if ($action != 'editjournal') { |
||
1216 | print '<td class="right"><a class="editfielda reposition" href="' . $_SERVER['PHP_SELF'] . '?action=editjournal&token=' . newToken() . '&piece_num=' . urlencode((string) ($object->piece_num)) . '&mode=' . urlencode((string) ($mode)) . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a></td>'; |
||
1217 | } |
||
1218 | print '</tr></table>'; |
||
1219 | print '</td><td>'; |
||
1220 | if ($action == 'editjournal') { |
||
1221 | print '<form name="setjournal" action="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
1222 | if ($optioncss != '') { |
||
1223 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
1224 | } |
||
1225 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
1226 | print '<input type="hidden" name="action" value="setjournal">'; |
||
1227 | print '<input type="hidden" name="mode" value="' . $mode . '">'; |
||
1228 | print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1); |
||
1229 | print '<input type="submit" class="button button-edit" value="' . $langs->trans('Modify') . '">'; |
||
1230 | print '</form>'; |
||
1231 | } else { |
||
1232 | print $object->code_journal; |
||
1233 | } |
||
1234 | print '</td>'; |
||
1235 | print '</tr>'; |
||
1236 | |||
1237 | // Ref document |
||
1238 | print '<tr><td>'; |
||
1239 | print '<table class="nobordernopadding centpercent"><tr><td>'; |
||
1240 | print $langs->trans('Piece'); |
||
1241 | print '</td>'; |
||
1242 | if ($action != 'editdocref') { |
||
1243 | print '<td class="right"><a class="editfielda reposition" href="' . $_SERVER['PHP_SELF'] . '?action=editdocref&token=' . newToken() . '&piece_num=' . urlencode((string) ($object->piece_num)) . '&mode=' . urlencode((string) ($mode)) . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a></td>'; |
||
1244 | } |
||
1245 | print '</tr></table>'; |
||
1246 | print '</td><td>'; |
||
1247 | if ($action == 'editdocref') { |
||
1248 | print '<form name="setdocref" action="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
1249 | if ($optioncss != '') { |
||
1250 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
1251 | } |
||
1252 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
1253 | print '<input type="hidden" name="action" value="setdocref">'; |
||
1254 | print '<input type="hidden" name="mode" value="' . $mode . '">'; |
||
1255 | print '<input type="text" size="20" name="doc_ref" value="' . dol_escape_htmltag($object->doc_ref) . '">'; |
||
1256 | print '<input type="submit" class="button button-edit" value="' . $langs->trans('Modify') . '">'; |
||
1257 | print '</form>'; |
||
1258 | } else { |
||
1259 | print $object->doc_ref; |
||
1260 | } |
||
1261 | print '</td>'; |
||
1262 | print '</tr>'; |
||
1263 | |||
1264 | print '</table>'; |
||
1265 | |||
1266 | print '</div>'; |
||
1267 | |||
1268 | print '<div class="fichehalfright">'; |
||
1269 | |||
1270 | print '<div class="underbanner clearboth"></div>'; |
||
1271 | print '<table class="border tableforfield centpercent">'; |
||
1272 | |||
1273 | // Doc type |
||
1274 | if (!empty($object->doc_type)) { |
||
1275 | print '<tr>'; |
||
1276 | print '<td class="titlefield">' . $langs->trans("Doctype") . '</td>'; |
||
1277 | print '<td>' . $object->doc_type . '</td>'; |
||
1278 | print '</tr>'; |
||
1279 | } |
||
1280 | |||
1281 | // Date document creation |
||
1282 | print '<tr>'; |
||
1283 | print '<td class="titlefield">' . $langs->trans("DateCreation") . '</td>'; |
||
1284 | print '<td>'; |
||
1285 | print $object->date_creation ? dol_print_date($object->date_creation, 'day') : ' '; |
||
1286 | print '</td>'; |
||
1287 | print '</tr>'; |
||
1288 | |||
1289 | // Don't show in tmp mode, inevitably empty |
||
1290 | if ($mode != "_tmp") { |
||
1291 | // Date document export |
||
1292 | print '<tr>'; |
||
1293 | print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>'; |
||
1294 | print '<td>'; |
||
1295 | print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : ' '; |
||
1296 | print '</td>'; |
||
1297 | print '</tr>'; |
||
1298 | |||
1299 | // Date document validation |
||
1300 | print '<tr>'; |
||
1301 | print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>'; |
||
1302 | print '<td>'; |
||
1303 | print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : ' '; |
||
1304 | print '</td>'; |
||
1305 | print '</tr>'; |
||
1306 | } |
||
1307 | |||
1308 | // Validate |
||
1309 | /* |
||
1310 | print '<tr>'; |
||
1311 | print '<td class="titlefield">' . $langs->trans("Status") . '</td>'; |
||
1312 | print '<td>'; |
||
1313 | if (empty($object->validated)) { |
||
1314 | print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">'; |
||
1315 | print img_picto($langs->trans("Disabled"), 'switch_off'); |
||
1316 | print '</a>'; |
||
1317 | } else { |
||
1318 | print '<a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">'; |
||
1319 | print img_picto($langs->trans("Activated"), 'switch_on'); |
||
1320 | print '</a>'; |
||
1321 | } |
||
1322 | print '</td>'; |
||
1323 | print '</tr>'; |
||
1324 | */ |
||
1325 | |||
1326 | // check data |
||
1327 | /* |
||
1328 | print '<tr>'; |
||
1329 | print '<td class="titlefield">' . $langs->trans("Control") . '</td>'; |
||
1330 | if ($object->doc_type == 'customer_invoice') |
||
1331 | { |
||
1332 | $sqlmid = 'SELECT rowid as ref'; |
||
1333 | $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac"; |
||
1334 | $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc); |
||
1335 | dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG); |
||
1336 | $resultmid = $db->query($sqlmid); |
||
1337 | if ($resultmid) { |
||
1338 | $objmid = $db->fetch_object($resultmid); |
||
1339 | $invoicestatic = new Facture($db); |
||
1340 | $invoicestatic->fetch($objmid->ref); |
||
1341 | $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); |
||
1342 | } |
||
1343 | else dol_print_error($db); |
||
1344 | } |
||
1345 | print '<td>' . $ref .'</td>'; |
||
1346 | print '</tr>'; |
||
1347 | */ |
||
1348 | print "</table>\n"; |
||
1349 | |||
1350 | print '</div>'; |
||
1351 | |||
1352 | print dol_get_fiche_end(); |
||
1353 | |||
1354 | print '<div class="clearboth"></div>'; |
||
1355 | |||
1356 | print '<br>'; |
||
1357 | |||
1358 | $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt |
||
1359 | |||
1360 | if ($result < 0) { |
||
1361 | setEventMessages($object->error, $object->errors, 'errors'); |
||
1362 | } else { |
||
1363 | // List of movements |
||
1364 | print load_fiche_titre($langs->trans("ListeMvts"), '', ''); |
||
1365 | |||
1366 | print '<form action="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
1367 | if ($optioncss != '') { |
||
1368 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
1369 | } |
||
1370 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
1371 | print '<input type="hidden" name="doc_date" value="' . $object->doc_date . '">' . "\n"; |
||
1372 | print '<input type="hidden" name="doc_type" value="' . $object->doc_type . '">' . "\n"; |
||
1373 | print '<input type="hidden" name="doc_ref" value="' . $object->doc_ref . '">' . "\n"; |
||
1374 | print '<input type="hidden" name="code_journal" value="' . $object->code_journal . '">' . "\n"; |
||
1375 | print '<input type="hidden" name="fk_doc" value="' . $object->fk_doc . '">' . "\n"; |
||
1376 | print '<input type="hidden" name="fk_docdet" value="' . $object->fk_docdet . '">' . "\n"; |
||
1377 | print '<input type="hidden" name="mode" value="' . $mode . '">' . "\n"; |
||
1378 | |||
1379 | if (count($object->linesmvt) > 0) { |
||
1380 | print '<div class="div-table-responsive-no-min">'; |
||
1381 | print '<table class="noborder centpercent">'; |
||
1382 | |||
1383 | $total_debit = 0; |
||
1384 | $total_credit = 0; |
||
1385 | |||
1386 | print '<tr class="liste_titre">'; |
||
1387 | |||
1388 | print_liste_field_titre("AccountAccountingShort"); |
||
1389 | print_liste_field_titre("SubledgerAccount"); |
||
1390 | print_liste_field_titre("LabelOperation"); |
||
1391 | print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"'); |
||
1392 | print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"'); |
||
1393 | if (empty($object->date_validation)) { |
||
1394 | print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center '); |
||
1395 | } else { |
||
1396 | print_liste_field_titre(""); |
||
1397 | } |
||
1398 | |||
1399 | print "</tr>\n"; |
||
1400 | |||
1401 | // Add an empty line if there is not yet |
||
1402 | if (!empty($object->linesmvt[0])) { |
||
1403 | $tmpline = $object->linesmvt[0]; |
||
1404 | if (!empty($tmpline->numero_compte)) { |
||
1405 | $line = new BookKeepingLine($db); |
||
1406 | $object->linesmvt[] = $line; |
||
1407 | } |
||
1408 | } |
||
1409 | |||
1410 | foreach ($object->linesmvt as $line) { |
||
1411 | print '<tr class="oddeven" data-lineid="' . ((int) $line->id) . '">'; |
||
1412 | $total_debit += $line->debit; |
||
1413 | $total_credit += $line->credit; |
||
1414 | |||
1415 | if ($action == 'update' && $line->id == $id) { |
||
1416 | print '<!-- td columns in edit mode -->'; |
||
1417 | print '<td>'; |
||
1418 | print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500'); |
||
1419 | print '</td>'; |
||
1420 | print '<td>'; |
||
1421 | // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: |
||
1422 | // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases. |
||
1423 | // Also, it is not possible to use a value that is not in the list. |
||
1424 | // Also, the label is not automatically filled when a value is selected. |
||
1425 | if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) { |
||
1426 | print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label'); |
||
1427 | } else { |
||
1428 | print '<input type="text" class="maxwidth150" name="subledger_account" value="' . (GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account) . '" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">'; |
||
1429 | } |
||
1430 | // Add also input for subledger label |
||
1431 | print '<br><input type="text" class="maxwidth150" name="subledger_label" value="' . (GETPOSTISSET("subledger_label") ? GETPOST("subledger_label", "alpha") : $line->subledger_label) . '" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">'; |
||
1432 | print '</td>'; |
||
1433 | print '<td><input type="text" class="minwidth200" name="label_operation" value="' . (GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation) . '"></td>'; |
||
1434 | print '<td class="right"><input type="text" size="6" class="right" name="debit" value="' . (GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)) . '"></td>'; |
||
1435 | print '<td class="right"><input type="text" size="6" class="right" name="credit" value="' . (GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)) . '"></td>'; |
||
1436 | print '<td>'; |
||
1437 | print '<input type="hidden" name="id" value="' . $line->id . '">' . "\n"; |
||
1438 | print '<input type="submit" class="button" name="update" value="' . $langs->trans("Update") . '">'; |
||
1439 | print '</td>'; |
||
1440 | } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) { |
||
1441 | if ($action == "" || $action == 'add') { |
||
1442 | print '<!-- td columns in add mode -->'; |
||
1443 | print '<td>'; |
||
1444 | print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500'); |
||
1445 | print '</td>'; |
||
1446 | print '<td>'; |
||
1447 | // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because: |
||
1448 | // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases. |
||
1449 | // Also, it is not possible to use a value that is not in the list. |
||
1450 | // Also, the label is not automatically filled when a value is selected. |
||
1451 | if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) { |
||
1452 | print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label'); |
||
1453 | } else { |
||
1454 | print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">'; |
||
1455 | } |
||
1456 | print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">'; |
||
1457 | print '</td>'; |
||
1458 | print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $label_operation . '"/></td>'; |
||
1459 | print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>'; |
||
1460 | print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>'; |
||
1461 | print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>'; |
||
1462 | } |
||
1463 | } else { |
||
1464 | print '<!-- td columns in display mode -->'; |
||
1465 | $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true); |
||
1466 | print '<td>'; |
||
1467 | if ($resultfetch > 0) { |
||
1468 | print $accountingaccount->getNomUrl(0, 1, 1, '', 0); |
||
1469 | } else { |
||
1470 | print $line->numero_compte . ' <span class="warning">(' . $langs->trans("AccountRemovedFromCurrentChartOfAccount") . ')</span>'; |
||
1471 | } |
||
1472 | print '</td>'; |
||
1473 | print '<td>' . length_accounta($line->subledger_account); |
||
1474 | if ($line->subledger_label) { |
||
1475 | print ' - <span class="opacitymedium">' . $line->subledger_label . '</span>'; |
||
1476 | } |
||
1477 | print '</td>'; |
||
1478 | print '<td>' . $line->label_operation . '</td>'; |
||
1479 | print '<td class="right nowraponall amount">' . ($line->debit != 0 ? price($line->debit) : '') . '</td>'; |
||
1480 | print '<td class="right nowraponall amount">' . ($line->credit != 0 ? price($line->credit) : '') . '</td>'; |
||
1481 | |||
1482 | print '<td class="center nowraponall">'; |
||
1483 | if (empty($line->date_export) && empty($line->date_validation)) { |
||
1484 | print '<a class="editfielda reposition" href="' . $_SERVER['PHP_SELF'] . '?action=update&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">'; |
||
1485 | print img_edit('', 0, 'class="marginrightonly"'); |
||
1486 | print '</a> '; |
||
1487 | } else { |
||
1488 | print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="' . dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")) . '">'; |
||
1489 | print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"'); |
||
1490 | print '</a> '; |
||
1491 | } |
||
1492 | |||
1493 | if (empty($line->date_validation)) { |
||
1494 | $actiontodelete = 'delete'; |
||
1495 | if ($mode == '_tmp' || $action != 'delmouv') { |
||
1496 | $actiontodelete = 'confirm_delete'; |
||
1497 | } |
||
1498 | |||
1499 | print '<a href="' . $_SERVER['PHP_SELF'] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">'; |
||
1500 | print img_delete(); |
||
1501 | print '</a>'; |
||
1502 | } else { |
||
1503 | print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="' . dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")) . '">'; |
||
1504 | print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated")); |
||
1505 | print '</a>'; |
||
1506 | } |
||
1507 | |||
1508 | print '</td>'; |
||
1509 | } |
||
1510 | print "</tr>\n"; |
||
1511 | } |
||
1512 | |||
1513 | $total_debit = price2num($total_debit, 'MT'); |
||
1514 | $total_credit = price2num($total_credit, 'MT'); |
||
1515 | |||
1516 | if ($total_debit != $total_credit) { |
||
1517 | setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings'); |
||
1518 | } |
||
1519 | |||
1520 | print '</table>'; |
||
1521 | print '</div>'; |
||
1522 | |||
1523 | if ($mode == '_tmp' && $action == '') { |
||
1524 | print '<br>'; |
||
1525 | print '<div class="center">'; |
||
1526 | if ($total_debit == $total_credit) { |
||
1527 | print '<a class="button" href="' . $_SERVER['PHP_SELF'] . '?piece_num=' . $object->piece_num . '&action=valid">' . $langs->trans("ValidTransaction") . '</a>'; |
||
1528 | } else { |
||
1529 | print '<input type="submit" class="button" disabled="disabled" href="#" title="' . dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $debit, $credit)) . '" value="' . dol_escape_htmltag($langs->trans("ValidTransaction")) . '">'; |
||
1530 | } |
||
1531 | |||
1532 | print ' '; |
||
1533 | print '<a class="button button-cancel" href="' . DOL_URL_ROOT . '/accountancy/bookkeeping/list.php">' . $langs->trans("Cancel") . '</a>'; |
||
1534 | |||
1535 | print "</div>"; |
||
1536 | } |
||
1537 | } |
||
1538 | |||
1539 | print '</form>'; |
||
1540 | } |
||
1541 | } else { |
||
1542 | print load_fiche_titre($langs->trans("NoRecords")); |
||
1543 | } |
||
1544 | } |
||
1545 | |||
1546 | print dol_get_fiche_end(); |
||
1547 | |||
1548 | // End of page |
||
1549 | llxFooter(); |
||
1550 | $db->close(); |
||
1551 | } |
||
1552 | |||
1553 | /** |
||
1554 | * \file htdocs/accountancy/bookkeeping/export.php |
||
1555 | * \ingroup Accountancy (Double entries) |
||
1556 | * \brief Export operation of book keeping |
||
1557 | */ |
||
1558 | public function export() |
||
1559 | { |
||
1560 | global $conf; |
||
1561 | global $db; |
||
1562 | global $user; |
||
1563 | global $hookmanager; |
||
1564 | global $user; |
||
1565 | global $menumanager; |
||
1566 | global $langs; |
||
1567 | |||
1568 | // Load translation files required by the page |
||
1569 | $langs->loadLangs(array("accountancy", "compta")); |
||
1570 | |||
1571 | $socid = GETPOSTINT('socid'); |
||
1572 | |||
1573 | $action = GETPOST('action', 'aZ09'); |
||
1574 | $massaction = GETPOST('massaction', 'alpha'); |
||
1575 | $confirm = GETPOST('confirm', 'alpha'); |
||
1576 | $toselect = GETPOST('toselect', 'array'); |
||
1577 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bookkeepinglist'; |
||
1578 | $search_mvt_num = GETPOSTINT('search_mvt_num'); |
||
1579 | $search_doc_type = GETPOST("search_doc_type", 'alpha'); |
||
1580 | $search_doc_ref = GETPOST("search_doc_ref", 'alpha'); |
||
1581 | $search_date_startyear = GETPOSTINT('search_date_startyear'); |
||
1582 | $search_date_startmonth = GETPOSTINT('search_date_startmonth'); |
||
1583 | $search_date_startday = GETPOSTINT('search_date_startday'); |
||
1584 | $search_date_endyear = GETPOSTINT('search_date_endyear'); |
||
1585 | $search_date_endmonth = GETPOSTINT('search_date_endmonth'); |
||
1586 | $search_date_endday = GETPOSTINT('search_date_endday'); |
||
1587 | $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); |
||
1588 | $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); |
||
1589 | $search_doc_date = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear')); |
||
1590 | $search_date_creation_startyear = GETPOSTINT('search_date_creation_startyear'); |
||
1591 | $search_date_creation_startmonth = GETPOSTINT('search_date_creation_startmonth'); |
||
1592 | $search_date_creation_startday = GETPOSTINT('search_date_creation_startday'); |
||
1593 | $search_date_creation_endyear = GETPOSTINT('search_date_creation_endyear'); |
||
1594 | $search_date_creation_endmonth = GETPOSTINT('search_date_creation_endmonth'); |
||
1595 | $search_date_creation_endday = GETPOSTINT('search_date_creation_endday'); |
||
1596 | $search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); |
||
1597 | $search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); |
||
1598 | $search_date_modification_startyear = GETPOSTINT('search_date_modification_startyear'); |
||
1599 | $search_date_modification_startmonth = GETPOSTINT('search_date_modification_startmonth'); |
||
1600 | $search_date_modification_startday = GETPOSTINT('search_date_modification_startday'); |
||
1601 | $search_date_modification_endyear = GETPOSTINT('search_date_modification_endyear'); |
||
1602 | $search_date_modification_endmonth = GETPOSTINT('search_date_modification_endmonth'); |
||
1603 | $search_date_modification_endday = GETPOSTINT('search_date_modification_endday'); |
||
1604 | $search_date_modification_start = dol_mktime(0, 0, 0, $search_date_modification_startmonth, $search_date_modification_startday, $search_date_modification_startyear); |
||
1605 | $search_date_modification_end = dol_mktime(23, 59, 59, $search_date_modification_endmonth, $search_date_modification_endday, $search_date_modification_endyear); |
||
1606 | $search_date_export_startyear = GETPOSTINT('search_date_export_startyear'); |
||
1607 | $search_date_export_startmonth = GETPOSTINT('search_date_export_startmonth'); |
||
1608 | $search_date_export_startday = GETPOSTINT('search_date_export_startday'); |
||
1609 | $search_date_export_endyear = GETPOSTINT('search_date_export_endyear'); |
||
1610 | $search_date_export_endmonth = GETPOSTINT('search_date_export_endmonth'); |
||
1611 | $search_date_export_endday = GETPOSTINT('search_date_export_endday'); |
||
1612 | $search_date_export_start = dol_mktime(0, 0, 0, $search_date_export_startmonth, $search_date_export_startday, $search_date_export_startyear); |
||
1613 | $search_date_export_end = dol_mktime(23, 59, 59, $search_date_export_endmonth, $search_date_export_endday, $search_date_export_endyear); |
||
1614 | $search_date_validation_startyear = GETPOSTINT('search_date_validation_startyear'); |
||
1615 | $search_date_validation_startmonth = GETPOSTINT('search_date_validation_startmonth'); |
||
1616 | $search_date_validation_startday = GETPOSTINT('search_date_validation_startday'); |
||
1617 | $search_date_validation_endyear = GETPOSTINT('search_date_validation_endyear'); |
||
1618 | $search_date_validation_endmonth = GETPOSTINT('search_date_validation_endmonth'); |
||
1619 | $search_date_validation_endday = GETPOSTINT('search_date_validation_endday'); |
||
1620 | $search_date_validation_start = dol_mktime(0, 0, 0, $search_date_validation_startmonth, $search_date_validation_startday, $search_date_validation_startyear); |
||
1621 | $search_date_validation_end = dol_mktime(23, 59, 59, $search_date_validation_endmonth, $search_date_validation_endday, $search_date_validation_endyear); |
||
1622 | $search_import_key = GETPOST("search_import_key", 'alpha'); |
||
1623 | |||
1624 | //var_dump($search_date_start);exit; |
||
1625 | if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) { |
||
1626 | $action = 'delbookkeepingyear'; |
||
1627 | } |
||
1628 | if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) { |
||
1629 | $action = 'export_file'; |
||
1630 | } |
||
1631 | |||
1632 | $search_account_category = GETPOSTINT('search_account_category'); |
||
1633 | |||
1634 | $search_accountancy_code = GETPOST("search_accountancy_code", 'alpha'); |
||
1635 | $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); |
||
1636 | if ($search_accountancy_code_start == - 1) { |
||
1637 | $search_accountancy_code_start = ''; |
||
1638 | } |
||
1639 | $search_accountancy_code_end = GETPOST('search_accountancy_code_end', 'alpha'); |
||
1640 | if ($search_accountancy_code_end == - 1) { |
||
1641 | $search_accountancy_code_end = ''; |
||
1642 | } |
||
1643 | |||
1644 | $search_accountancy_aux_code = GETPOST("search_accountancy_aux_code", 'alpha'); |
||
1645 | $search_accountancy_aux_code_start = GETPOST('search_accountancy_aux_code_start', 'alpha'); |
||
1646 | if ($search_accountancy_aux_code_start == - 1) { |
||
1647 | $search_accountancy_aux_code_start = ''; |
||
1648 | } |
||
1649 | $search_accountancy_aux_code_end = GETPOST('search_accountancy_aux_code_end', 'alpha'); |
||
1650 | if ($search_accountancy_aux_code_end == - 1) { |
||
1651 | $search_accountancy_aux_code_end = ''; |
||
1652 | } |
||
1653 | $search_mvt_label = GETPOST('search_mvt_label', 'alpha'); |
||
1654 | $search_direction = GETPOST('search_direction', 'alpha'); |
||
1655 | $search_debit = GETPOST('search_debit', 'alpha'); |
||
1656 | $search_credit = GETPOST('search_credit', 'alpha'); |
||
1657 | $search_ledger_code = GETPOST('search_ledger_code', 'array'); |
||
1658 | $search_lettering_code = GETPOST('search_lettering_code', 'alpha'); |
||
1659 | $search_not_reconciled = GETPOST('search_not_reconciled', 'alpha'); |
||
1660 | |||
1661 | // Load variable for pagination |
||
1662 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit); |
||
1663 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
1664 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
1665 | $optioncss = GETPOST('optioncss', 'alpha'); |
||
1666 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
1667 | if (empty($page) || $page < 0) { |
||
1668 | $page = 0; |
||
1669 | } |
||
1670 | $offset = $limit * $page; |
||
1671 | $pageprev = $page - 1; |
||
1672 | $pagenext = $page + 1; |
||
1673 | if ($sortorder == "") { |
||
1674 | $sortorder = "ASC"; |
||
1675 | } |
||
1676 | if ($sortfield == "") { |
||
1677 | $sortfield = "t.piece_num,t.rowid"; |
||
1678 | } |
||
1679 | |||
1680 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
1681 | $object = new BookKeeping($db); |
||
1682 | $hookmanager->initHooks(array('bookkeepingexport')); |
||
1683 | |||
1684 | $formaccounting = new FormAccounting($db); |
||
1685 | $form = new Form($db); |
||
1686 | |||
1687 | if (!in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && !GETPOSTISSET('begin') && !GETPOSTISSET('formfilteraction') && GETPOSTINT('page') == '' && !GETPOSTINT('noreset') && $user->hasRight('accounting', 'mouvements', 'export')) { |
||
1688 | if (empty($search_date_start) && empty($search_date_end) && !GETPOSTISSET('restore_lastsearch_values') && !GETPOST('search_accountancy_code_start')) { |
||
1689 | $query = "SELECT date_start, date_end from " . MAIN_DB_PREFIX . "accounting_fiscalyear "; |
||
1690 | $query .= " where date_start < '" . $db->idate(dol_now()) . "' and date_end > '" . $db->idate(dol_now()) . "' limit 1"; |
||
1691 | $res = $db->query($query); |
||
1692 | |||
1693 | if ($res->num_rows > 0) { |
||
1694 | $fiscalYear = $db->fetch_object($res); |
||
1695 | $search_date_start = strtotime($fiscalYear->date_start); |
||
1696 | $search_date_end = strtotime($fiscalYear->date_end); |
||
1697 | } else { |
||
1698 | $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1); |
||
1699 | $year_start = dol_print_date(dol_now(), '%Y'); |
||
1700 | if (dol_print_date(dol_now(), '%m') < $month_start) { |
||
1701 | $year_start--; // If current month is lower that starting fiscal month, we start last year |
||
1702 | } |
||
1703 | $year_end = $year_start + 1; |
||
1704 | $month_end = $month_start - 1; |
||
1705 | if ($month_end < 1) { |
||
1706 | $month_end = 12; |
||
1707 | $year_end--; |
||
1708 | } |
||
1709 | $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); |
||
1710 | $search_date_end = dol_get_last_day($year_end, $month_end); |
||
1711 | } |
||
1712 | } |
||
1713 | } |
||
1714 | |||
1715 | |||
1716 | $arrayfields = array( |
||
1717 | 't.piece_num' => array('label' => $langs->trans("TransactionNumShort"), 'checked' => 1), |
||
1718 | 't.code_journal' => array('label' => $langs->trans("Codejournal"), 'checked' => 1), |
||
1719 | 't.doc_date' => array('label' => $langs->trans("Docdate"), 'checked' => 1), |
||
1720 | 't.doc_ref' => array('label' => $langs->trans("Piece"), 'checked' => 1), |
||
1721 | 't.numero_compte' => array('label' => $langs->trans("AccountAccountingShort"), 'checked' => 1), |
||
1722 | 't.subledger_account' => array('label' => $langs->trans("SubledgerAccount"), 'checked' => 1), |
||
1723 | 't.label_operation' => array('label' => $langs->trans("Label"), 'checked' => 1), |
||
1724 | 't.debit' => array('label' => $langs->trans("AccountingDebit"), 'checked' => 1), |
||
1725 | 't.credit' => array('label' => $langs->trans("AccountingCredit"), 'checked' => 1), |
||
1726 | 't.lettering_code' => array('label' => $langs->trans("LetteringCode"), 'checked' => 1), |
||
1727 | 't.date_creation' => array('label' => $langs->trans("DateCreation"), 'checked' => 0), |
||
1728 | 't.tms' => array('label' => $langs->trans("DateModification"), 'checked' => 0), |
||
1729 | 't.date_export' => array('label' => $langs->trans("DateExport"), 'checked' => 1), |
||
1730 | 't.date_validated' => array('label' => $langs->trans("DateValidationAndLock"), 'checked' => 1, 'enabled' => !getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")), |
||
1731 | 't.import_key' => array('label' => $langs->trans("ImportId"), 'checked' => 0, 'position' => 1100), |
||
1732 | ); |
||
1733 | |||
1734 | if (!getDolGlobalString('ACCOUNTING_ENABLE_LETTERING')) { |
||
1735 | unset($arrayfields['t.lettering_code']); |
||
1736 | } |
||
1737 | |||
1738 | $accountancyexport = new AccountancyExport($db); |
||
1739 | $listofformat = $accountancyexport->getType(); |
||
1740 | $formatexportset = getDolGlobalString('ACCOUNTING_EXPORT_MODELCSV'); |
||
1741 | if (empty($listofformat[$formatexportset])) { |
||
1742 | $formatexportset = 1; |
||
1743 | } |
||
1744 | |||
1745 | $error = 0; |
||
1746 | |||
1747 | if (!isModEnabled('accounting')) { |
||
1748 | accessforbidden(); |
||
1749 | } |
||
1750 | if ($user->socid > 0) { |
||
1751 | accessforbidden(); |
||
1752 | } |
||
1753 | if (!$user->hasRight('accounting', 'mouvements', 'lire')) { |
||
1754 | accessforbidden(); |
||
1755 | } |
||
1756 | |||
1757 | |||
1758 | /* |
||
1759 | * Actions |
||
1760 | */ |
||
1761 | |||
1762 | $param = ''; |
||
1763 | |||
1764 | if (GETPOST('cancel', 'alpha')) { |
||
1765 | $action = 'list'; |
||
1766 | $massaction = ''; |
||
1767 | } |
||
1768 | if (!GETPOST('confirmmassaction', 'alpha')) { |
||
1769 | $massaction = ''; |
||
1770 | } |
||
1771 | |||
1772 | $parameters = array('socid' => $socid); |
||
1773 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
1774 | if ($reshook < 0) { |
||
1775 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
1776 | } |
||
1777 | |||
1778 | if (empty($reshook)) { |
||
1779 | include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php'; |
||
1780 | |||
1781 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
||
1782 | $search_mvt_num = ''; |
||
1783 | $search_doc_type = ''; |
||
1784 | $search_doc_ref = ''; |
||
1785 | $search_doc_date = ''; |
||
1786 | $search_account_category = ''; |
||
1787 | $search_accountancy_code = ''; |
||
1788 | $search_accountancy_code_start = ''; |
||
1789 | $search_accountancy_code_end = ''; |
||
1790 | $search_accountancy_aux_code = ''; |
||
1791 | $search_accountancy_aux_code_start = ''; |
||
1792 | $search_accountancy_aux_code_end = ''; |
||
1793 | $search_mvt_label = ''; |
||
1794 | $search_direction = ''; |
||
1795 | $search_ledger_code = array(); |
||
1796 | $search_date_startyear = ''; |
||
1797 | $search_date_startmonth = ''; |
||
1798 | $search_date_startday = ''; |
||
1799 | $search_date_endyear = ''; |
||
1800 | $search_date_endmonth = ''; |
||
1801 | $search_date_endday = ''; |
||
1802 | $search_date_start = ''; |
||
1803 | $search_date_end = ''; |
||
1804 | $search_date_creation_startyear = ''; |
||
1805 | $search_date_creation_startmonth = ''; |
||
1806 | $search_date_creation_startday = ''; |
||
1807 | $search_date_creation_endyear = ''; |
||
1808 | $search_date_creation_endmonth = ''; |
||
1809 | $search_date_creation_endday = ''; |
||
1810 | $search_date_creation_start = ''; |
||
1811 | $search_date_creation_end = ''; |
||
1812 | $search_date_modification_startyear = ''; |
||
1813 | $search_date_modification_startmonth = ''; |
||
1814 | $search_date_modification_startday = ''; |
||
1815 | $search_date_modification_endyear = ''; |
||
1816 | $search_date_modification_endmonth = ''; |
||
1817 | $search_date_modification_endday = ''; |
||
1818 | $search_date_modification_start = ''; |
||
1819 | $search_date_modification_end = ''; |
||
1820 | $search_date_export_startyear = ''; |
||
1821 | $search_date_export_startmonth = ''; |
||
1822 | $search_date_export_startday = ''; |
||
1823 | $search_date_export_endyear = ''; |
||
1824 | $search_date_export_endmonth = ''; |
||
1825 | $search_date_export_endday = ''; |
||
1826 | $search_date_export_start = ''; |
||
1827 | $search_date_export_end = ''; |
||
1828 | $search_date_validation_startyear = ''; |
||
1829 | $search_date_validation_startmonth = ''; |
||
1830 | $search_date_validation_startday = ''; |
||
1831 | $search_date_validation_endyear = ''; |
||
1832 | $search_date_validation_endmonth = ''; |
||
1833 | $search_date_validation_endday = ''; |
||
1834 | $search_date_validation_start = ''; |
||
1835 | $search_date_validation_end = ''; |
||
1836 | $search_debit = ''; |
||
1837 | $search_credit = ''; |
||
1838 | $search_lettering_code = ''; |
||
1839 | $search_not_reconciled = ''; |
||
1840 | $search_import_key = ''; |
||
1841 | $toselect = array(); |
||
1842 | } |
||
1843 | |||
1844 | // Must be after the remove filter action, before the export. |
||
1845 | $filter = array(); |
||
1846 | if (!empty($search_date_start)) { |
||
1847 | $filter['t.doc_date>='] = $search_date_start; |
||
1848 | $tmp = dol_getdate($search_date_start); |
||
1849 | $param .= '&search_date_startmonth=' . urlencode($tmp['mon']) . '&search_date_startday=' . urlencode($tmp['mday']) . '&search_date_startyear=' . urlencode($tmp['year']); |
||
1850 | } |
||
1851 | if (!empty($search_date_end)) { |
||
1852 | $filter['t.doc_date<='] = $search_date_end; |
||
1853 | $tmp = dol_getdate($search_date_end); |
||
1854 | $param .= '&search_date_endmonth=' . urlencode($tmp['mon']) . '&search_date_endday=' . urlencode($tmp['mday']) . '&search_date_endyear=' . urlencode($tmp['year']); |
||
1855 | } |
||
1856 | if (!empty($search_doc_date)) { |
||
1857 | $filter['t.doc_date'] = $search_doc_date; |
||
1858 | $tmp = dol_getdate($search_doc_date); |
||
1859 | $param .= '&doc_datemonth=' . urlencode($tmp['mon']) . '&doc_dateday=' . urlencode($tmp['mday']) . '&doc_dateyear=' . urlencode($tmp['year']); |
||
1860 | } |
||
1861 | if (!empty($search_doc_type)) { |
||
1862 | $filter['t.doc_type'] = $search_doc_type; |
||
1863 | $param .= '&search_doc_type=' . urlencode($search_doc_type); |
||
1864 | } |
||
1865 | if (!empty($search_doc_ref)) { |
||
1866 | $filter['t.doc_ref'] = $search_doc_ref; |
||
1867 | $param .= '&search_doc_ref=' . urlencode($search_doc_ref); |
||
1868 | } |
||
1869 | if ($search_account_category != '-1' && !empty($search_account_category)) { |
||
1870 | require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php'; |
||
1871 | $accountingcategory = new AccountancyCategory($db); |
||
1872 | |||
1873 | $listofaccountsforgroup = $accountingcategory->getCptsCat(0, 'fk_accounting_category = ' . ((int) $search_account_category)); |
||
1874 | $listofaccountsforgroup2 = array(); |
||
1875 | if (is_array($listofaccountsforgroup)) { |
||
1876 | foreach ($listofaccountsforgroup as $tmpval) { |
||
1877 | $listofaccountsforgroup2[] = "'" . $db->escape($tmpval['id']) . "'"; |
||
1878 | } |
||
1879 | } |
||
1880 | $filter['t.search_accounting_code_in'] = implode(',', $listofaccountsforgroup2); |
||
1881 | $param .= '&search_account_category=' . urlencode((string) ($search_account_category)); |
||
1882 | } |
||
1883 | if (!empty($search_accountancy_code)) { |
||
1884 | $filter['t.numero_compte'] = $search_accountancy_code; |
||
1885 | $param .= '&search_accountancy_code=' . urlencode($search_accountancy_code); |
||
1886 | } |
||
1887 | if (!empty($search_accountancy_code_start)) { |
||
1888 | $filter['t.numero_compte>='] = $search_accountancy_code_start; |
||
1889 | $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start); |
||
1890 | } |
||
1891 | if (!empty($search_accountancy_code_end)) { |
||
1892 | $filter['t.numero_compte<='] = $search_accountancy_code_end; |
||
1893 | $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end); |
||
1894 | } |
||
1895 | if (!empty($search_accountancy_aux_code)) { |
||
1896 | $filter['t.subledger_account'] = $search_accountancy_aux_code; |
||
1897 | $param .= '&search_accountancy_aux_code=' . urlencode($search_accountancy_aux_code); |
||
1898 | } |
||
1899 | if (!empty($search_accountancy_aux_code_start)) { |
||
1900 | $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; |
||
1901 | $param .= '&search_accountancy_aux_code_start=' . urlencode($search_accountancy_aux_code_start); |
||
1902 | } |
||
1903 | if (!empty($search_accountancy_aux_code_end)) { |
||
1904 | $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; |
||
1905 | $param .= '&search_accountancy_aux_code_end=' . urlencode($search_accountancy_aux_code_end); |
||
1906 | } |
||
1907 | if (!empty($search_mvt_label)) { |
||
1908 | $filter['t.label_operation'] = $search_mvt_label; |
||
1909 | $param .= '&search_mvt_label=' . urlencode($search_mvt_label); |
||
1910 | } |
||
1911 | if (!empty($search_direction)) { |
||
1912 | $filter['t.sens'] = $search_direction; |
||
1913 | $param .= '&search_direction=' . urlencode($search_direction); |
||
1914 | } |
||
1915 | if (!empty($search_ledger_code)) { |
||
1916 | $filter['t.code_journal'] = $search_ledger_code; |
||
1917 | foreach ($search_ledger_code as $code) { |
||
1918 | $param .= '&search_ledger_code[]=' . urlencode($code); |
||
1919 | } |
||
1920 | } |
||
1921 | if (!empty($search_mvt_num)) { |
||
1922 | $filter['t.piece_num'] = $search_mvt_num; |
||
1923 | $param .= '&search_mvt_num=' . urlencode((string) ($search_mvt_num)); |
||
1924 | } |
||
1925 | if (!empty($search_date_creation_start)) { |
||
1926 | $filter['t.date_creation>='] = $search_date_creation_start; |
||
1927 | $tmp = dol_getdate($search_date_creation_start); |
||
1928 | $param .= '&search_date_creation_startmonth=' . urlencode($tmp['mon']) . '&search_date_creation_startday=' . urlencode($tmp['mday']) . '&search_date_creation_startyear=' . urlencode($tmp['year']); |
||
1929 | } |
||
1930 | if (!empty($search_date_creation_end)) { |
||
1931 | $filter['t.date_creation<='] = $search_date_creation_end; |
||
1932 | $tmp = dol_getdate($search_date_creation_end); |
||
1933 | $param .= '&search_date_creation_endmonth=' . urlencode($tmp['mon']) . '&search_date_creation_endday=' . urlencode($tmp['mday']) . '&search_date_creation_endyear=' . urlencode($tmp['year']); |
||
1934 | } |
||
1935 | if (!empty($search_date_modification_start)) { |
||
1936 | $filter['t.tms>='] = $search_date_modification_start; |
||
1937 | $tmp = dol_getdate($search_date_modification_start); |
||
1938 | $param .= '&search_date_modification_startmonth=' . urlencode($tmp['mon']) . '&search_date_modification_startday=' . urlencode($tmp['mday']) . '&search_date_modification_startyear=' . urlencode($tmp['year']); |
||
1939 | } |
||
1940 | if (!empty($search_date_modification_end)) { |
||
1941 | $filter['t.tms<='] = $search_date_modification_end; |
||
1942 | $tmp = dol_getdate($search_date_modification_end); |
||
1943 | $param .= '&search_date_modification_endmonth=' . urlencode($tmp['mon']) . '&search_date_modification_endday=' . urlencode($tmp['mday']) . '&search_date_modification_endyear=' . urlencode($tmp['year']); |
||
1944 | } |
||
1945 | if (!empty($search_date_export_start)) { |
||
1946 | $filter['t.date_export>='] = $search_date_export_start; |
||
1947 | $tmp = dol_getdate($search_date_export_start); |
||
1948 | $param .= '&search_date_export_startmonth=' . urlencode($tmp['mon']) . '&search_date_export_startday=' . urlencode($tmp['mday']) . '&search_date_export_startyear=' . urlencode($tmp['year']); |
||
1949 | } |
||
1950 | if (!empty($search_date_export_end)) { |
||
1951 | $filter['t.date_export<='] = $search_date_export_end; |
||
1952 | $tmp = dol_getdate($search_date_export_end); |
||
1953 | $param .= '&search_date_export_endmonth=' . urlencode($tmp['mon']) . '&search_date_export_endday=' . urlencode($tmp['mday']) . '&search_date_export_endyear=' . urlencode($tmp['year']); |
||
1954 | } |
||
1955 | if (!empty($search_date_validation_start)) { |
||
1956 | $filter['t.date_validated>='] = $search_date_validation_start; |
||
1957 | $tmp = dol_getdate($search_date_validation_start); |
||
1958 | $param .= '&search_date_validation_startmonth=' . urlencode($tmp['mon']) . '&search_date_validation_startday=' . urlencode($tmp['mday']) . '&search_date_validation_startyear=' . urlencode($tmp['year']); |
||
1959 | } |
||
1960 | if (!empty($search_date_validation_end)) { |
||
1961 | $filter['t.date_validated<='] = $search_date_validation_end; |
||
1962 | $tmp = dol_getdate($search_date_validation_end); |
||
1963 | $param .= '&search_date_validation_endmonth=' . urlencode($tmp['mon']) . '&search_date_validation_endday=' . urlencode($tmp['mday']) . '&search_date_validation_endyear=' . urlencode($tmp['year']); |
||
1964 | } |
||
1965 | if (!empty($search_debit)) { |
||
1966 | $filter['t.debit'] = $search_debit; |
||
1967 | $param .= '&search_debit=' . urlencode($search_debit); |
||
1968 | } |
||
1969 | if (!empty($search_credit)) { |
||
1970 | $filter['t.credit'] = $search_credit; |
||
1971 | $param .= '&search_credit=' . urlencode($search_credit); |
||
1972 | } |
||
1973 | if (!empty($search_lettering_code)) { |
||
1974 | $filter['t.lettering_code'] = $search_lettering_code; |
||
1975 | $param .= '&search_lettering_code=' . urlencode($search_lettering_code); |
||
1976 | } |
||
1977 | if (!empty($search_not_reconciled)) { |
||
1978 | $filter['t.reconciled_option'] = $search_not_reconciled; |
||
1979 | $param .= '&search_not_reconciled=' . urlencode($search_not_reconciled); |
||
1980 | } |
||
1981 | if (!empty($search_import_key)) { |
||
1982 | $filter['t.import_key'] = $search_import_key; |
||
1983 | $param .= '&search_import_key=' . urlencode($search_import_key); |
||
1984 | } |
||
1985 | |||
1986 | if ($action == 'setreexport') { |
||
1987 | $setreexport = GETPOSTINT('value'); |
||
1988 | if (!dolibarr_set_const($db, "ACCOUNTING_REEXPORT", $setreexport, 'yesno', 0, '', $conf->entity)) { |
||
1989 | $error++; |
||
1990 | } |
||
1991 | |||
1992 | if (!$error) { |
||
1993 | if (!getDolGlobalString('ACCOUNTING_REEXPORT')) { |
||
1994 | setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsDisable"), null, 'mesgs'); |
||
1995 | } else { |
||
1996 | setEventMessages($langs->trans("ExportOfPiecesAlreadyExportedIsEnable"), null, 'warnings'); |
||
1997 | } |
||
1998 | } else { |
||
1999 | setEventMessages($langs->trans("Error"), null, 'errors'); |
||
2000 | } |
||
2001 | } |
||
2002 | |||
2003 | // Mass actions |
||
2004 | $objectclass = 'Bookkeeping'; |
||
2005 | $objectlabel = 'Bookkeeping'; |
||
2006 | $permissiontoread = $user->hasRight('societe', 'lire'); |
||
2007 | $permissiontodelete = $user->hasRight('societe', 'supprimer'); |
||
2008 | $permissiontoadd = $user->hasRight('societe', 'creer'); |
||
2009 | $uploaddir = $conf->societe->dir_output; |
||
2010 | include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; |
||
2011 | } |
||
2012 | |||
2013 | // Build and execute select (used by page and export action) |
||
2014 | // must de set after the action that set $filter |
||
2015 | // -------------------------------------------------------------------- |
||
2016 | |||
2017 | $sql = 'SELECT'; |
||
2018 | $sql .= ' t.rowid,'; |
||
2019 | $sql .= " t.doc_date,"; |
||
2020 | $sql .= " t.doc_type,"; |
||
2021 | $sql .= " t.doc_ref,"; |
||
2022 | $sql .= " t.fk_doc,"; |
||
2023 | $sql .= " t.fk_docdet,"; |
||
2024 | $sql .= " t.thirdparty_code,"; |
||
2025 | $sql .= " t.subledger_account,"; |
||
2026 | $sql .= " t.subledger_label,"; |
||
2027 | $sql .= " t.numero_compte,"; |
||
2028 | $sql .= " t.label_compte,"; |
||
2029 | $sql .= " t.label_operation,"; |
||
2030 | $sql .= " t.debit,"; |
||
2031 | $sql .= " t.credit,"; |
||
2032 | $sql .= " t.lettering_code,"; |
||
2033 | $sql .= " t.date_lettering,"; |
||
2034 | $sql .= " t.montant as amount,"; |
||
2035 | $sql .= " t.sens,"; |
||
2036 | $sql .= " t.fk_user_author,"; |
||
2037 | $sql .= " t.import_key,"; |
||
2038 | $sql .= " t.code_journal,"; |
||
2039 | $sql .= " t.journal_label,"; |
||
2040 | $sql .= " t.piece_num,"; |
||
2041 | $sql .= " t.date_creation,"; |
||
2042 | $sql .= " t.date_lim_reglement,"; |
||
2043 | $sql .= " t.tms as date_modification,"; |
||
2044 | $sql .= " t.date_export,"; |
||
2045 | $sql .= " t.date_validated as date_validation,"; |
||
2046 | $sql .= " t.import_key"; |
||
2047 | |||
2048 | $sqlfields = $sql; // $sql fields to remove for count total |
||
2049 | |||
2050 | $sql .= ' FROM ' . MAIN_DB_PREFIX . $object->table_element . ' as t'; |
||
2051 | // Manage filter |
||
2052 | $sqlwhere = array(); |
||
2053 | if (count($filter) > 0) { |
||
2054 | foreach ($filter as $key => $value) { |
||
2055 | if ($key == 't.doc_date') { |
||
2056 | $sqlwhere[] = $db->sanitize($key) . " = '" . $db->idate($value) . "'"; |
||
2057 | } elseif ($key == 't.doc_date>=') { |
||
2058 | $sqlwhere[] = "t.doc_date >= '" . $db->idate($value) . "'"; |
||
2059 | } elseif ($key == 't.doc_date<=') { |
||
2060 | $sqlwhere[] = "t.doc_date <= '" . $db->idate($value) . "'"; |
||
2061 | } elseif ($key == 't.doc_date>') { |
||
2062 | $sqlwhere[] = "t.doc_date > '" . $db->idate($value) . "'"; |
||
2063 | } elseif ($key == 't.doc_date<') { |
||
2064 | $sqlwhere[] = "t.doc_date < '" . $db->idate($value) . "'"; |
||
2065 | } elseif ($key == 't.numero_compte>=') { |
||
2066 | $sqlwhere[] = "t.numero_compte >= '" . $db->escape($value) . "'"; |
||
2067 | } elseif ($key == 't.numero_compte<=') { |
||
2068 | $sqlwhere[] = "t.numero_compte <= '" . $db->escape($value) . "'"; |
||
2069 | } elseif ($key == 't.subledger_account>=') { |
||
2070 | $sqlwhere[] = "t.subledger_account >= '" . $db->escape($value) . "'"; |
||
2071 | } elseif ($key == 't.subledger_account<=') { |
||
2072 | $sqlwhere[] = "t.subledger_account <= '" . $db->escape($value) . "'"; |
||
2073 | } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { |
||
2074 | $sqlwhere[] = $db->sanitize($key) . '=' . ((int) $value); |
||
2075 | } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { |
||
2076 | $sqlwhere[] = $db->sanitize($key) . " LIKE '" . $db->escape($db->escapeforlike($value)) . "%'"; |
||
2077 | } elseif ($key == 't.subledger_account') { |
||
2078 | $sqlwhere[] = natural_search($key, $value, 0, 1); |
||
2079 | } elseif ($key == 't.tms>=') { |
||
2080 | $sqlwhere[] = "t.tms >= '" . $db->idate($value) . "'"; |
||
2081 | } elseif ($key == 't.tms<=') { |
||
2082 | $sqlwhere[] = "t.tms <= '" . $db->idate($value) . "'"; |
||
2083 | } elseif ($key == 't.date_creation>=') { |
||
2084 | $sqlwhere[] = "t.date_creation >= '" . $db->idate($value) . "'"; |
||
2085 | } elseif ($key == 't.date_creation<=') { |
||
2086 | $sqlwhere[] = "t.date_creation <= '" . $db->idate($value) . "'"; |
||
2087 | } elseif ($key == 't.date_export>=') { |
||
2088 | $sqlwhere[] = "t.date_export >= '" . $db->idate($value) . "'"; |
||
2089 | } elseif ($key == 't.date_export<=') { |
||
2090 | $sqlwhere[] = "t.date_export <= '" . $db->idate($value) . "'"; |
||
2091 | } elseif ($key == 't.date_validated>=') { |
||
2092 | $sqlwhere[] = "t;date_validate >= '" . $db->idate($value) . "'"; |
||
2093 | } elseif ($key == 't.date_validated<=') { |
||
2094 | $sqlwhere[] = "t;date_validate <= '" . $db->idate($value) . "'"; |
||
2095 | } elseif ($key == 't.credit' || $key == 't.debit') { |
||
2096 | $sqlwhere[] = natural_search($key, $value, 1, 1); |
||
2097 | } elseif ($key == 't.reconciled_option') { |
||
2098 | $sqlwhere[] = 't.lettering_code IS NULL'; |
||
2099 | } elseif ($key == 't.code_journal' && !empty($value)) { |
||
2100 | if (is_array($value)) { |
||
2101 | $sqlwhere[] = natural_search("t.code_journal", implode(',', $value), 3, 1); |
||
2102 | } else { |
||
2103 | $sqlwhere[] = natural_search("t.code_journal", $value, 3, 1); |
||
2104 | } |
||
2105 | } elseif ($key == 't.search_accounting_code_in' && !empty($value)) { |
||
2106 | $sqlwhere[] = 't.numero_compte IN (' . $db->sanitize($value, 1) . ')'; |
||
2107 | } else { |
||
2108 | $sqlwhere[] = natural_search($key, $value, 0, 1); |
||
2109 | } |
||
2110 | } |
||
2111 | } |
||
2112 | $sql .= ' WHERE t.entity IN (' . getEntity('accountancy') . ')'; |
||
2113 | if (!getDolGlobalString('ACCOUNTING_REEXPORT')) { // Reexport not enabled (default mode) |
||
2114 | $sql .= " AND t.date_export IS NULL"; |
||
2115 | } |
||
2116 | if (count($sqlwhere) > 0) { |
||
2117 | $sql .= ' AND ' . implode(' AND ', $sqlwhere); |
||
2118 | } |
||
2119 | //print $sql; |
||
2120 | |||
2121 | |||
2122 | // Export into a file with format defined into setup (FEC, CSV, ...) |
||
2123 | // Must be after definition of $sql |
||
2124 | if ($action == 'export_fileconfirm' && $user->hasRight('accounting', 'mouvements', 'export')) { |
||
2125 | // Export files then exit |
||
2126 | $accountancyexport = new AccountancyExport($db); |
||
2127 | |||
2128 | $error = 0; |
||
2129 | $nbtotalofrecords = 0; |
||
2130 | |||
2131 | // Open transaction to read lines to export, export them and update field date_export or date_validated |
||
2132 | $db->begin(); |
||
2133 | |||
2134 | /* The fast and low memory method to get and count full list converts the sql into a sql count */ |
||
2135 | $sqlforcount = preg_replace('/^' . preg_quote($sqlfields, '/') . '/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); |
||
2136 | $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); |
||
2137 | $resql = $db->query($sqlforcount); |
||
2138 | if ($resql) { |
||
2139 | $objforcount = $db->fetch_object($resql); |
||
2140 | $nbtotalofrecords = $objforcount->nbtotalofrecords; |
||
2141 | } else { |
||
2142 | dol_print_error($db); |
||
2143 | } |
||
2144 | |||
2145 | $db->free($resql); |
||
2146 | |||
2147 | //$sqlforexport = $sql; |
||
2148 | //$sqlforexport .= $db->order($sortfield, $sortorder); |
||
2149 | |||
2150 | |||
2151 | // TODO Call the fetchAll for a $limit and $offset |
||
2152 | // Replace the fetchAll to get all ->line followed by call to ->export(). fetchAll() currently consumes too much memory on large export. |
||
2153 | // Replace this with the query($sqlforexport) on a limited block and loop on each line to export them. |
||
2154 | $limit = 0; |
||
2155 | $offset = 0; |
||
2156 | $result = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter, 'AND', (getDolGlobalString('ACCOUNTING_REEXPORT') ? 1 : 0)); |
||
2157 | |||
2158 | if ($result < 0) { |
||
2159 | $error++; |
||
2160 | setEventMessages($object->error, $object->errors, 'errors'); |
||
2161 | } else { |
||
2162 | $formatexport = GETPOSTINT('formatexport'); |
||
2163 | $notexportlettering = GETPOST('notexportlettering', 'alpha'); |
||
2164 | |||
2165 | |||
2166 | if (!empty($notexportlettering)) { |
||
2167 | if (is_array($object->lines)) { |
||
2168 | foreach ($object->lines as $k => $movement) { |
||
2169 | unset($object->lines[$k]->lettering_code); |
||
2170 | unset($object->lines[$k]->date_lettering); |
||
2171 | } |
||
2172 | } |
||
2173 | } |
||
2174 | |||
2175 | $notifiedexportdate = GETPOST('notifiedexportdate', 'alpha'); |
||
2176 | $notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha'); |
||
2177 | $withAttachment = !empty(trim(GETPOST('notifiedexportfull', 'alphanohtml'))) ? 1 : 0; |
||
2178 | |||
2179 | // Output data on screen or download |
||
2180 | //$result = $accountancyexport->export($object->lines, $formatexport, $withAttachment); |
||
2181 | $result = $accountancyexport->export($object->lines, $formatexport, $withAttachment, 1, 1, 1); |
||
2182 | |||
2183 | if ($result < 0) { |
||
2184 | $error++; |
||
2185 | } else { |
||
2186 | if (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) { |
||
2187 | if (is_array($object->lines)) { |
||
2188 | dol_syslog("/accountancy/bookkeeping/list.php Function export_file Specify movements as exported", LOG_DEBUG); |
||
2189 | |||
2190 | // TODO Merge update for each line into one global using rowid IN (list of movement ids) |
||
2191 | foreach ($object->lines as $movement) { |
||
2192 | // Update the line to set date_export and/or date_validated (if not already set !) |
||
2193 | $now = dol_now(); |
||
2194 | |||
2195 | $setfields = ''; |
||
2196 | if (!empty($notifiedexportdate) && empty($movement->date_export)) { |
||
2197 | $setfields .= ($setfields ? "," : "") . " date_export = '" . $db->idate($now) . "'"; |
||
2198 | } |
||
2199 | if (!empty($notifiedvalidationdate) && empty($movement->date_validation)) { |
||
2200 | $setfields .= ($setfields ? "," : "") . " date_validated = '" . $db->idate($now) . "'"; |
||
2201 | } |
||
2202 | |||
2203 | if ($setfields) { |
||
2204 | $sql = " UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping"; |
||
2205 | $sql .= " SET " . $db->sanitize($setfields); |
||
2206 | $sql .= " WHERE rowid = " . ((int) $movement->id); |
||
2207 | |||
2208 | $result = $db->query($sql); |
||
2209 | if (!$result) { |
||
2210 | $error++; |
||
2211 | break; |
||
2212 | } |
||
2213 | } |
||
2214 | } |
||
2215 | |||
2216 | if ($error) { |
||
2217 | $accountancyexport->errors[] = $langs->trans('NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated'); |
||
2218 | } |
||
2219 | } |
||
2220 | } |
||
2221 | } |
||
2222 | } |
||
2223 | |||
2224 | if (!$error) { |
||
2225 | $db->commit(); |
||
2226 | |||
2227 | $downloadFilePath = $accountancyexport->generatedfiledata['downloadFilePath']; |
||
2228 | $downloadFileMimeType = $accountancyexport->generatedfiledata['downloadFileMimeType']; |
||
2229 | $downloadFileFullName = $accountancyexport->generatedfiledata['downloadFileFullName']; |
||
2230 | |||
2231 | // No error, we can output the file |
||
2232 | top_httphead($downloadFileMimeType); |
||
2233 | |||
2234 | header('Content-Description: File Transfer'); |
||
2235 | // Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, attachment=need user action to open) |
||
2236 | $attachment = 1; |
||
2237 | if ($attachment) { |
||
2238 | header('Content-Disposition: attachment; filename="' . $downloadFileFullName . '"'); |
||
2239 | } else { |
||
2240 | header('Content-Disposition: inline; filename="' . $downloadFileFullName . '"'); |
||
2241 | } |
||
2242 | // Ajout directives pour resoudre bug IE |
||
2243 | header('Cache-Control: Public, must-revalidate'); |
||
2244 | header('Pragma: public'); |
||
2245 | header('Content-Length: ' . dol_filesize($downloadFilePath)); |
||
2246 | |||
2247 | readfileLowMemory($downloadFilePath); |
||
2248 | } else { |
||
2249 | $db->rollback(); |
||
2250 | |||
2251 | setEventMessages('', $accountancyexport->errors, 'errors'); |
||
2252 | header('Location: ' . $_SERVER['PHP_SELF']); |
||
2253 | } |
||
2254 | exit(); // download or show errors |
||
2255 | } |
||
2256 | |||
2257 | |||
2258 | /* |
||
2259 | * View |
||
2260 | */ |
||
2261 | |||
2262 | $formother = new FormOther($db); |
||
2263 | $formfile = new FormFile($db); |
||
2264 | |||
2265 | $title_page = $langs->trans("Operations") . ' - ' . $langs->trans("ExportAccountancy"); |
||
2266 | |||
2267 | // Count total nb of records |
||
2268 | $nbtotalofrecords = ''; |
||
2269 | if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { |
||
2270 | /* The fast and low memory method to get and count full list converts the sql into a sql count */ |
||
2271 | $sqlforcount = preg_replace('/^' . preg_quote($sqlfields, '/') . '/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); |
||
2272 | $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); |
||
2273 | $resql = $db->query($sqlforcount); |
||
2274 | if ($resql) { |
||
2275 | $objforcount = $db->fetch_object($resql); |
||
2276 | $nbtotalofrecords = $objforcount->nbtotalofrecords; |
||
2277 | } else { |
||
2278 | dol_print_error($db); |
||
2279 | } |
||
2280 | |||
2281 | if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 |
||
2282 | $page = 0; |
||
2283 | $offset = 0; |
||
2284 | } |
||
2285 | $db->free($resql); |
||
2286 | } |
||
2287 | |||
2288 | // Complete request and execute it with limit |
||
2289 | $sql .= $db->order($sortfield, $sortorder); |
||
2290 | if ($limit) { |
||
2291 | $sql .= $db->plimit($limit + 1, $offset); |
||
2292 | } |
||
2293 | |||
2294 | $resql = $db->query($sql); |
||
2295 | if (!$resql) { |
||
2296 | dol_print_error($db); |
||
2297 | exit; |
||
2298 | } |
||
2299 | |||
2300 | $num = $db->num_rows($resql); |
||
2301 | |||
2302 | $arrayofselected = is_array($toselect) ? $toselect : array(); |
||
2303 | |||
2304 | // Output page |
||
2305 | // -------------------------------------------------------------------- |
||
2306 | $help_url = 'EN:Module_Double_Entry_Accounting#Exports|FR:Module_Comptabilité_en_Partie_Double#Exports'; |
||
2307 | |||
2308 | llxHeader('', $title_page, $help_url); |
||
2309 | |||
2310 | $formconfirm = ''; |
||
2311 | |||
2312 | if ($action == 'export_file') { |
||
2313 | $form_question = array(); |
||
2314 | |||
2315 | $form_question['formatexport'] = array( |
||
2316 | 'name' => 'formatexport', |
||
2317 | 'type' => 'select', |
||
2318 | 'label' => $langs->trans('Modelcsv'), // TODO Use Selectmodelcsv and show a select combo |
||
2319 | 'values' => $listofformat, |
||
2320 | 'default' => $formatexportset, |
||
2321 | 'morecss' => 'minwidth200 maxwidth200' |
||
2322 | ); |
||
2323 | |||
2324 | $form_question['separator0'] = array('name' => 'separator0', 'type' => 'separator'); |
||
2325 | |||
2326 | if (getDolGlobalInt("ACCOUNTING_ENABLE_LETTERING")) { |
||
2327 | // If 1, we check by default. |
||
2328 | $checked = getDolGlobalString('ACCOUNTING_DEFAULT_NOT_EXPORT_LETTERING') ? 'true' : 'false'; |
||
2329 | $form_question['notexportlettering'] = array( |
||
2330 | 'name' => 'notexportlettering', |
||
2331 | 'type' => 'checkbox', |
||
2332 | 'label' => $langs->trans('NotExportLettering'), |
||
2333 | 'value' => $checked, |
||
2334 | ); |
||
2335 | |||
2336 | $form_question['separator1'] = array('name' => 'separator1', 'type' => 'separator'); |
||
2337 | } |
||
2338 | |||
2339 | // If 1 or not set, we check by default. |
||
2340 | $checked = (!isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) || getDolGlobalString('ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE')); |
||
2341 | $form_question['notifiedexportdate'] = array( |
||
2342 | 'name' => 'notifiedexportdate', |
||
2343 | 'type' => 'checkbox', |
||
2344 | 'label' => $langs->trans('NotifiedExportDate'), |
||
2345 | 'value' => (getDolGlobalString('ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE') ? 'false' : 'true'), |
||
2346 | ); |
||
2347 | |||
2348 | $form_question['separator2'] = array('name' => 'separator2', 'type' => 'separator'); |
||
2349 | |||
2350 | if (!getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) { |
||
2351 | // If 0 or not set, we NOT check by default. |
||
2352 | $checked = (isset($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE) || getDolGlobalString('ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE')); |
||
2353 | $form_question['notifiedvalidationdate'] = array( |
||
2354 | 'name' => 'notifiedvalidationdate', |
||
2355 | 'type' => 'checkbox', |
||
2356 | 'label' => $langs->trans('NotifiedValidationDate', $langs->transnoentitiesnoconv("MenuAccountancyClosure")), |
||
2357 | 'value' => $checked, |
||
2358 | ); |
||
2359 | |||
2360 | $form_question['separator3'] = array('name' => 'separator3', 'type' => 'separator'); |
||
2361 | } |
||
2362 | |||
2363 | // add documents in an archive for accountancy export (Quadratus) |
||
2364 | if (getDolGlobalString('ACCOUNTING_EXPORT_MODELCSV') == AccountancyExport::$EXPORT_TYPE_QUADRATUS) { |
||
2365 | $form_question['notifiedexportfull'] = array( |
||
2366 | 'name' => 'notifiedexportfull', |
||
2367 | 'type' => 'checkbox', |
||
2368 | 'label' => $langs->trans('NotifiedExportFull'), |
||
2369 | 'value' => 'false', |
||
2370 | ); |
||
2371 | } |
||
2372 | |||
2373 | $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?' . $param, $langs->trans("ExportFilteredList") . '...', $langs->trans('ConfirmExportFile'), 'export_fileconfirm', $form_question, '', 1, 420, 600); |
||
2374 | } |
||
2375 | |||
2376 | // Print form confirm |
||
2377 | print $formconfirm; |
||
2378 | |||
2379 | //$param=''; param started before |
||
2380 | if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) { |
||
2381 | $param .= '&contextpage=' . urlencode($contextpage); |
||
2382 | } |
||
2383 | if ($limit > 0 && $limit != $conf->liste_limit) { |
||
2384 | $param .= '&limit=' . urlencode($limit); |
||
2385 | } |
||
2386 | |||
2387 | // List of mass actions available |
||
2388 | $arrayofmassactions = array(); |
||
2389 | $massactionbutton = $form->selectMassAction($massaction, $arrayofmassactions); |
||
2390 | |||
2391 | print '<form method="POST" id="searchFormList" action="' . $_SERVER['PHP_SELF'] . '">'; |
||
2392 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
2393 | print '<input type="hidden" name="action" value="list">'; |
||
2394 | if ($optioncss != '') { |
||
2395 | print '<input type="hidden" name="optioncss" value="' . urlencode($optioncss) . '">'; |
||
2396 | } |
||
2397 | print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; |
||
2398 | print '<input type="hidden" name="sortfield" value="' . $sortfield . '">'; |
||
2399 | print '<input type="hidden" name="sortorder" value="' . $sortorder . '">'; |
||
2400 | print '<input type="hidden" name="contextpage" value="' . $contextpage . '">'; |
||
2401 | |||
2402 | if (count($filter)) { |
||
2403 | $buttonLabel = $langs->trans("ExportFilteredList"); |
||
2404 | } else { |
||
2405 | $buttonLabel = $langs->trans("ExportList"); |
||
2406 | } |
||
2407 | |||
2408 | $parameters = array('param' => $param); |
||
2409 | $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
2410 | if ($reshook < 0) { |
||
2411 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
2412 | } |
||
2413 | |||
2414 | $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint; |
||
2415 | if (empty($reshook)) { |
||
2416 | // Button re-export |
||
2417 | if (!getDolGlobalString('ACCOUNTING_REEXPORT')) { |
||
2418 | $newcardbutton .= '<a class="valignmiddle" href="' . $_SERVER['PHP_SELF'] . '?action=setreexport&token=' . newToken() . '&value=1' . ($param ? '&' . $param : '') . '&sortfield=' . urlencode($sortfield) . '&sortorder=' . urlencode($sortorder) . '">' . img_picto($langs->trans("ClickToShowAlreadyExportedLines"), 'switch_off', 'class="small size15x valignmiddle"'); |
||
2419 | $newcardbutton .= '<span class="valignmiddle marginrightonly paddingleft">' . $langs->trans("ClickToShowAlreadyExportedLines") . '</span>'; |
||
2420 | $newcardbutton .= '</a>'; |
||
2421 | } else { |
||
2422 | $newcardbutton .= '<a class="valignmiddle" href="' . $_SERVER['PHP_SELF'] . '?action=setreexport&token=' . newToken() . '&value=0' . ($param ? '&' . $param : '') . '&sortfield=' . urlencode($sortfield) . '&sortorder=' . urlencode($sortorder) . '">' . img_picto($langs->trans("DocsAlreadyExportedAreIncluded"), 'switch_on', 'class="warning size15x valignmiddle"'); |
||
2423 | $newcardbutton .= '<span class="valignmiddle marginrightonly paddingleft">' . $langs->trans("DocsAlreadyExportedAreIncluded") . '</span>'; |
||
2424 | $newcardbutton .= '</a>'; |
||
2425 | } |
||
2426 | |||
2427 | if ($user->hasRight('accounting', 'mouvements', 'export')) { |
||
2428 | $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList"), 'fa fa-file-export paddingleft', $_SERVER['PHP_SELF'] . '?action=export_file&token=' . newToken() . ($param ? '&' . $param : '') . '&sortfield=' . urlencode($sortfield) . '&sortorder=' . urlencode($sortorder), $user->hasRight('accounting', 'mouvements', 'export')); |
||
2429 | } |
||
2430 | } |
||
2431 | |||
2432 | print_barre_liste($title_page, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); |
||
2433 | |||
2434 | // Not display message when all the list of docs are included |
||
2435 | if (!getDolGlobalString('ACCOUNTING_REEXPORT')) { |
||
2436 | print info_admin($langs->trans("WarningDataDisappearsWhenDataIsExported"), 0, 0, 0, 'hideonsmartphone info'); |
||
2437 | } |
||
2438 | |||
2439 | //$topicmail = "Information"; |
||
2440 | //$modelmail = "accountingbookkeeping"; |
||
2441 | //$objecttmp = new BookKeeping($db); |
||
2442 | //$trackid = 'bk'.$object->id; |
||
2443 | include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php'; |
||
2444 | |||
2445 | $varpage = empty($contextpage) ? $_SERVER['PHP_SELF'] : $contextpage; |
||
2446 | $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields |
||
2447 | if ($massactionbutton && $contextpage != 'poslist') { |
||
2448 | $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); |
||
2449 | } |
||
2450 | |||
2451 | $moreforfilter = ''; |
||
2452 | $moreforfilter .= '<div class="divsearchfield">'; |
||
2453 | $moreforfilter .= $langs->trans('AccountingCategory') . ': '; |
||
2454 | $moreforfilter .= '<div class="nowrap inline-block">'; |
||
2455 | $moreforfilter .= $formaccounting->select_accounting_category($search_account_category, 'search_account_category', 1, 0, 0, 0); |
||
2456 | $moreforfilter .= '</div>'; |
||
2457 | $moreforfilter .= '</div>'; |
||
2458 | |||
2459 | $parameters = array(); |
||
2460 | $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
2461 | if (empty($reshook)) { |
||
2462 | $moreforfilter .= $hookmanager->resPrint; |
||
2463 | } else { |
||
2464 | $moreforfilter = $hookmanager->resPrint; |
||
2465 | } |
||
2466 | |||
2467 | print '<div class="liste_titre liste_titre_bydiv centpercent">'; |
||
2468 | print $moreforfilter; |
||
2469 | print '</div>'; |
||
2470 | |||
2471 | print '<div class="div-table-responsive">'; |
||
2472 | print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">'; |
||
2473 | |||
2474 | // Filters lines |
||
2475 | print '<tr class="liste_titre_filter">'; |
||
2476 | // Action column |
||
2477 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2478 | print '<td class="liste_titre center">'; |
||
2479 | $searchpicto = $form->showFilterButtons('left'); |
||
2480 | print $searchpicto; |
||
2481 | print '</td>'; |
||
2482 | } |
||
2483 | // Movement number |
||
2484 | if (!empty($arrayfields['t.piece_num']['checked'])) { |
||
2485 | print '<td class="liste_titre"><input type="text" name="search_mvt_num" size="6" value="' . dol_escape_htmltag($search_mvt_num) . '"></td>'; |
||
2486 | } |
||
2487 | // Code journal |
||
2488 | if (!empty($arrayfields['t.code_journal']['checked'])) { |
||
2489 | print '<td class="liste_titre center">'; |
||
2490 | print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1, 'small maxwidth75'); |
||
2491 | print '</td>'; |
||
2492 | } |
||
2493 | // Date document |
||
2494 | if (!empty($arrayfields['t.doc_date']['checked'])) { |
||
2495 | print '<td class="liste_titre center">'; |
||
2496 | print '<div class="nowrapfordate">'; |
||
2497 | print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2498 | print '</div>'; |
||
2499 | print '<div class="nowrapfordate">'; |
||
2500 | print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); |
||
2501 | print '</div>'; |
||
2502 | print '</td>'; |
||
2503 | } |
||
2504 | // Ref document |
||
2505 | if (!empty($arrayfields['t.doc_ref']['checked'])) { |
||
2506 | print '<td class="liste_titre"><input type="text" name="search_doc_ref" size="8" value="' . dol_escape_htmltag($search_doc_ref) . '"></td>'; |
||
2507 | } |
||
2508 | // Accountancy account |
||
2509 | if (!empty($arrayfields['t.numero_compte']['checked'])) { |
||
2510 | print '<td class="liste_titre">'; |
||
2511 | print '<div class="nowrap">'; |
||
2512 | print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth150', 'account'); |
||
2513 | print '</div>'; |
||
2514 | print '<div class="nowrap">'; |
||
2515 | print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth150', 'account'); |
||
2516 | print '</div>'; |
||
2517 | print '</td>'; |
||
2518 | } |
||
2519 | // Subledger account |
||
2520 | if (!empty($arrayfields['t.subledger_account']['checked'])) { |
||
2521 | print '<td class="liste_titre">'; |
||
2522 | // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not |
||
2523 | // use setup of keypress to select thirdparty and this hang browser on large database. |
||
2524 | if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) { |
||
2525 | print '<div class="nowrap">'; |
||
2526 | //print $langs->trans('From').' '; |
||
2527 | print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount'); |
||
2528 | print '</div>'; |
||
2529 | print '<div class="nowrap">'; |
||
2530 | print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount'); |
||
2531 | print '</div>'; |
||
2532 | } else { |
||
2533 | print '<input type="text" class="maxwidth75" name="search_accountancy_aux_code" value="' . dol_escape_htmltag($search_accountancy_aux_code) . '">'; |
||
2534 | } |
||
2535 | print '</td>'; |
||
2536 | } |
||
2537 | // Label operation |
||
2538 | if (!empty($arrayfields['t.label_operation']['checked'])) { |
||
2539 | print '<td class="liste_titre">'; |
||
2540 | print '<input type="text" size="7" class="flat" name="search_mvt_label" value="' . dol_escape_htmltag($search_mvt_label) . '"/>'; |
||
2541 | print '</td>'; |
||
2542 | } |
||
2543 | // Debit |
||
2544 | if (!empty($arrayfields['t.debit']['checked'])) { |
||
2545 | print '<td class="liste_titre right">'; |
||
2546 | print '<input type="text" class="flat" name="search_debit" size="4" value="' . dol_escape_htmltag($search_debit) . '">'; |
||
2547 | print '</td>'; |
||
2548 | } |
||
2549 | // Credit |
||
2550 | if (!empty($arrayfields['t.credit']['checked'])) { |
||
2551 | print '<td class="liste_titre right">'; |
||
2552 | print '<input type="text" class="flat" name="search_credit" size="4" value="' . dol_escape_htmltag($search_credit) . '">'; |
||
2553 | print '</td>'; |
||
2554 | } |
||
2555 | // Lettering code |
||
2556 | if (!empty($arrayfields['t.lettering_code']['checked'])) { |
||
2557 | print '<td class="liste_titre center">'; |
||
2558 | print '<input type="text" size="3" class="flat" name="search_lettering_code" value="' . dol_escape_htmltag($search_lettering_code) . '"/>'; |
||
2559 | print '<br><span class="nowrap"><input type="checkbox" id="search_not_reconciled" name="search_not_reconciled" value="notreconciled"' . ($search_not_reconciled == 'notreconciled' ? ' checked' : '') . '><label for="search_not_reconciled">' . $langs->trans("NotReconciled") . '</label></span>'; |
||
2560 | print '</td>'; |
||
2561 | } |
||
2562 | |||
2563 | // Fields from hook |
||
2564 | $parameters = array('arrayfields' => $arrayfields); |
||
2565 | $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook |
||
2566 | print $hookmanager->resPrint; |
||
2567 | |||
2568 | // Date creation |
||
2569 | if (!empty($arrayfields['t.date_creation']['checked'])) { |
||
2570 | print '<td class="liste_titre center">'; |
||
2571 | print '<div class="nowrapfordate">'; |
||
2572 | print $form->selectDate($search_date_creation_start, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2573 | print '</div>'; |
||
2574 | print '<div class="nowrapfordate">'; |
||
2575 | print $form->selectDate($search_date_creation_end, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); |
||
2576 | print '</div>'; |
||
2577 | print '</td>'; |
||
2578 | } |
||
2579 | // Date modification |
||
2580 | if (!empty($arrayfields['t.tms']['checked'])) { |
||
2581 | print '<td class="liste_titre center">'; |
||
2582 | print '<div class="nowrapfordate">'; |
||
2583 | print $form->selectDate($search_date_modification_start, 'search_date_modification_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2584 | print '</div>'; |
||
2585 | print '<div class="nowrapfordate">'; |
||
2586 | print $form->selectDate($search_date_modification_end, 'search_date_modification_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2587 | print '</div>'; |
||
2588 | print '</td>'; |
||
2589 | } |
||
2590 | // Date export |
||
2591 | if (!empty($arrayfields['t.date_export']['checked'])) { |
||
2592 | print '<td class="liste_titre center">'; |
||
2593 | print '<div class="nowrapfordate">'; |
||
2594 | print $form->selectDate($search_date_export_start, 'search_date_export_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2595 | print '</div>'; |
||
2596 | print '<div class="nowrapfordate">'; |
||
2597 | print $form->selectDate($search_date_export_end, 'search_date_export_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); |
||
2598 | print '</div>'; |
||
2599 | print '</td>'; |
||
2600 | } |
||
2601 | // Date validation |
||
2602 | if (!empty($arrayfields['t.date_validated']['checked'])) { |
||
2603 | print '<td class="liste_titre center">'; |
||
2604 | print '<div class="nowrapfordate">'; |
||
2605 | print $form->selectDate($search_date_validation_start, 'search_date_validation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); |
||
2606 | print '</div>'; |
||
2607 | print '<div class="nowrapfordate">'; |
||
2608 | print $form->selectDate($search_date_validation_end, 'search_date_validation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); |
||
2609 | print '</div>'; |
||
2610 | print '</td>'; |
||
2611 | } |
||
2612 | if (!empty($arrayfields['t.import_key']['checked'])) { |
||
2613 | print '<td class="liste_titre center">'; |
||
2614 | print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="' . dol_escape_htmltag($search_import_key) . '">'; |
||
2615 | print '</td>'; |
||
2616 | } |
||
2617 | // Action column |
||
2618 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2619 | print '<td class="liste_titre center">'; |
||
2620 | $searchpicto = $form->showFilterButtons(); |
||
2621 | print $searchpicto; |
||
2622 | print '</td>'; |
||
2623 | } |
||
2624 | print "</tr>\n"; |
||
2625 | |||
2626 | print '<tr class="liste_titre">'; |
||
2627 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2628 | print_liste_field_titre($selectedfields, $_SERVER['PHP_SELF'], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn '); |
||
2629 | } |
||
2630 | if (!empty($arrayfields['t.piece_num']['checked'])) { |
||
2631 | print_liste_field_titre($arrayfields['t.piece_num']['label'], $_SERVER['PHP_SELF'], "t.piece_num", "", $param, "", $sortfield, $sortorder); |
||
2632 | } |
||
2633 | if (!empty($arrayfields['t.code_journal']['checked'])) { |
||
2634 | print_liste_field_titre($arrayfields['t.code_journal']['label'], $_SERVER['PHP_SELF'], "t.code_journal", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2635 | } |
||
2636 | if (!empty($arrayfields['t.doc_date']['checked'])) { |
||
2637 | print_liste_field_titre($arrayfields['t.doc_date']['label'], $_SERVER['PHP_SELF'], "t.doc_date", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2638 | } |
||
2639 | if (!empty($arrayfields['t.doc_ref']['checked'])) { |
||
2640 | print_liste_field_titre($arrayfields['t.doc_ref']['label'], $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder); |
||
2641 | } |
||
2642 | if (!empty($arrayfields['t.numero_compte']['checked'])) { |
||
2643 | print_liste_field_titre($arrayfields['t.numero_compte']['label'], $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); |
||
2644 | } |
||
2645 | if (!empty($arrayfields['t.subledger_account']['checked'])) { |
||
2646 | print_liste_field_titre($arrayfields['t.subledger_account']['label'], $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder); |
||
2647 | } |
||
2648 | if (!empty($arrayfields['t.label_operation']['checked'])) { |
||
2649 | print_liste_field_titre($arrayfields['t.label_operation']['label'], $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); |
||
2650 | } |
||
2651 | if (!empty($arrayfields['t.debit']['checked'])) { |
||
2652 | print_liste_field_titre($arrayfields['t.debit']['label'], $_SERVER['PHP_SELF'], "t.debit", "", $param, '', $sortfield, $sortorder, 'right '); |
||
2653 | } |
||
2654 | if (!empty($arrayfields['t.credit']['checked'])) { |
||
2655 | print_liste_field_titre($arrayfields['t.credit']['label'], $_SERVER['PHP_SELF'], "t.credit", "", $param, '', $sortfield, $sortorder, 'right '); |
||
2656 | } |
||
2657 | if (!empty($arrayfields['t.lettering_code']['checked'])) { |
||
2658 | print_liste_field_titre($arrayfields['t.lettering_code']['label'], $_SERVER['PHP_SELF'], "t.lettering_code", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2659 | } |
||
2660 | // Hook fields |
||
2661 | $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder); |
||
2662 | $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook |
||
2663 | print $hookmanager->resPrint; |
||
2664 | if (!empty($arrayfields['t.date_creation']['checked'])) { |
||
2665 | print_liste_field_titre($arrayfields['t.date_creation']['label'], $_SERVER['PHP_SELF'], "t.date_creation", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2666 | } |
||
2667 | if (!empty($arrayfields['t.tms']['checked'])) { |
||
2668 | print_liste_field_titre($arrayfields['t.tms']['label'], $_SERVER['PHP_SELF'], "t.tms", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2669 | } |
||
2670 | if (!empty($arrayfields['t.date_export']['checked'])) { |
||
2671 | print_liste_field_titre($arrayfields['t.date_export']['label'], $_SERVER['PHP_SELF'], "t.date_export,t.doc_date", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2672 | } |
||
2673 | if (!empty($arrayfields['t.date_validated']['checked'])) { |
||
2674 | print_liste_field_titre($arrayfields['t.date_validated']['label'], $_SERVER['PHP_SELF'], "t.date_validated,t.doc_date", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2675 | } |
||
2676 | if (!empty($arrayfields['t.import_key']['checked'])) { |
||
2677 | print_liste_field_titre($arrayfields['t.import_key']['label'], $_SERVER['PHP_SELF'], "t.import_key", "", $param, '', $sortfield, $sortorder, 'center '); |
||
2678 | } |
||
2679 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2680 | print_liste_field_titre($selectedfields, $_SERVER['PHP_SELF'], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); |
||
2681 | } |
||
2682 | print "</tr>\n"; |
||
2683 | |||
2684 | |||
2685 | $line = new BookKeepingLine($db); |
||
2686 | |||
2687 | // Loop on record |
||
2688 | // -------------------------------------------------------------------- |
||
2689 | $i = 0; |
||
2690 | $totalarray = array(); |
||
2691 | $totalarray['nbfield'] = 0; |
||
2692 | $total_debit = 0; |
||
2693 | $total_credit = 0; |
||
2694 | $totalarray['val'] = array(); |
||
2695 | $totalarray['val']['totaldebit'] = 0; |
||
2696 | $totalarray['val']['totalcredit'] = 0; |
||
2697 | |||
2698 | while ($i < min($num, $limit)) { |
||
2699 | $obj = $db->fetch_object($resql); |
||
2700 | if (empty($obj)) { |
||
2701 | break; // Should not happen |
||
2702 | } |
||
2703 | |||
2704 | $line->id = $obj->rowid; |
||
2705 | $line->doc_date = $db->jdate($obj->doc_date); |
||
2706 | $line->doc_type = $obj->doc_type; |
||
2707 | $line->doc_ref = $obj->doc_ref; |
||
2708 | $line->fk_doc = $obj->fk_doc; |
||
2709 | $line->fk_docdet = $obj->fk_docdet; |
||
2710 | $line->thirdparty_code = $obj->thirdparty_code; |
||
2711 | $line->subledger_account = $obj->subledger_account; |
||
2712 | $line->subledger_label = $obj->subledger_label; |
||
2713 | $line->numero_compte = $obj->numero_compte; |
||
2714 | $line->label_compte = $obj->label_compte; |
||
2715 | $line->label_operation = $obj->label_operation; |
||
2716 | $line->debit = $obj->debit; |
||
2717 | $line->credit = $obj->credit; |
||
2718 | $line->montant = $obj->amount; // deprecated |
||
2719 | $line->amount = $obj->amount; |
||
2720 | $line->sens = $obj->sens; |
||
2721 | $line->lettering_code = $obj->lettering_code; |
||
2722 | $line->fk_user_author = $obj->fk_user_author; |
||
2723 | $line->import_key = $obj->import_key; |
||
2724 | $line->code_journal = $obj->code_journal; |
||
2725 | $line->journal_label = $obj->journal_label; |
||
2726 | $line->piece_num = $obj->piece_num; |
||
2727 | $line->date_creation = $db->jdate($obj->date_creation); |
||
2728 | $line->date_modification = $db->jdate($obj->date_modification); |
||
2729 | $line->date_export = $db->jdate($obj->date_export); |
||
2730 | $line->date_validation = $db->jdate($obj->date_validation); |
||
2731 | |||
2732 | $total_debit += $line->debit; |
||
2733 | $total_credit += $line->credit; |
||
2734 | |||
2735 | print '<tr class="oddeven">'; |
||
2736 | // Action column |
||
2737 | if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2738 | print '<td class="nowraponall center">'; |
||
2739 | if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined |
||
2740 | $selected = 0; |
||
2741 | if (in_array($line->id, $arrayofselected)) { |
||
2742 | $selected = 1; |
||
2743 | } |
||
2744 | print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />'; |
||
2745 | } |
||
2746 | print '</td>'; |
||
2747 | if (!$i) { |
||
2748 | $totalarray['nbfield']++; |
||
2749 | } |
||
2750 | } |
||
2751 | |||
2752 | // Piece number |
||
2753 | if (!empty($arrayfields['t.piece_num']['checked'])) { |
||
2754 | print '<td>'; |
||
2755 | $object->id = $line->id; |
||
2756 | $object->piece_num = $line->piece_num; |
||
2757 | print $object->getNomUrl(1, '', 0, '', 1); |
||
2758 | print '</td>'; |
||
2759 | if (!$i) { |
||
2760 | $totalarray['nbfield']++; |
||
2761 | } |
||
2762 | } |
||
2763 | |||
2764 | // Journal code |
||
2765 | if (!empty($arrayfields['t.code_journal']['checked'])) { |
||
2766 | $accountingjournal = new AccountingJournal($db); |
||
2767 | $result = $accountingjournal->fetch('', $line->code_journal); |
||
2768 | $journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal); |
||
2769 | print '<td class="center tdoverflowmax150">' . $journaltoshow . '</td>'; |
||
2770 | if (!$i) { |
||
2771 | $totalarray['nbfield']++; |
||
2772 | } |
||
2773 | } |
||
2774 | |||
2775 | // Document date |
||
2776 | if (!empty($arrayfields['t.doc_date']['checked'])) { |
||
2777 | print '<td class="center">' . dol_print_date($line->doc_date, 'day') . '</td>'; |
||
2778 | if (!$i) { |
||
2779 | $totalarray['nbfield']++; |
||
2780 | } |
||
2781 | } |
||
2782 | |||
2783 | // Document ref |
||
2784 | if (!empty($arrayfields['t.doc_ref']['checked'])) { |
||
2785 | if ($line->doc_type == 'customer_invoice') { |
||
2786 | $langs->loadLangs(array('bills')); |
||
2787 | |||
2788 | require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; |
||
2789 | $objectstatic = new Facture($db); |
||
2790 | $objectstatic->fetch($line->fk_doc); |
||
2791 | //$modulepart = 'facture'; |
||
2792 | |||
2793 | $filename = dol_sanitizeFileName($line->doc_ref); |
||
2794 | $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($line->doc_ref); |
||
2795 | $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $objectstatic->id; |
||
2796 | $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); |
||
2797 | } elseif ($line->doc_type == 'supplier_invoice') { |
||
2798 | $langs->loadLangs(array('bills')); |
||
2799 | |||
2800 | require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; |
||
2801 | $objectstatic = new FactureFournisseur($db); |
||
2802 | $objectstatic->fetch($line->fk_doc); |
||
2803 | //$modulepart = 'invoice_supplier'; |
||
2804 | |||
2805 | $filename = dol_sanitizeFileName($line->doc_ref); |
||
2806 | $filedir = $conf->fournisseur->facture->dir_output . '/' . get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart) . dol_sanitizeFileName($line->doc_ref); |
||
2807 | $subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart) . dol_sanitizeFileName($line->doc_ref); |
||
2808 | $documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir); |
||
2809 | } elseif ($line->doc_type == 'expense_report') { |
||
2810 | $langs->loadLangs(array('trips')); |
||
2811 | |||
2812 | require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; |
||
2813 | $objectstatic = new ExpenseReport($db); |
||
2814 | $objectstatic->fetch($line->fk_doc); |
||
2815 | //$modulepart = 'expensereport'; |
||
2816 | |||
2817 | $filename = dol_sanitizeFileName($line->doc_ref); |
||
2818 | $filedir = $conf->expensereport->dir_output . '/' . dol_sanitizeFileName($line->doc_ref); |
||
2819 | $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $objectstatic->id; |
||
2820 | $documentlink = $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); |
||
2821 | } elseif ($line->doc_type == 'bank') { |
||
2822 | require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; |
||
2823 | $objectstatic = new AccountLine($db); |
||
2824 | $objectstatic->fetch($line->fk_doc); |
||
2825 | } else { |
||
2826 | // Other type |
||
2827 | } |
||
2828 | |||
2829 | $labeltoshow = ''; |
||
2830 | $labeltoshowalt = ''; |
||
2831 | if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') { |
||
2832 | $labeltoshow .= $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1); |
||
2833 | $labeltoshow .= $documentlink; |
||
2834 | $labeltoshowalt .= $objectstatic->ref; |
||
2835 | } elseif ($line->doc_type == 'bank') { |
||
2836 | $labeltoshow .= $objectstatic->getNomUrl(1); |
||
2837 | $labeltoshowalt .= $objectstatic->ref; |
||
2838 | $bank_ref = strstr($line->doc_ref, '-'); |
||
2839 | $labeltoshow .= " " . $bank_ref; |
||
2840 | $labeltoshowalt .= " " . $bank_ref; |
||
2841 | } else { |
||
2842 | $labeltoshow .= $line->doc_ref; |
||
2843 | $labeltoshowalt .= $line->doc_ref; |
||
2844 | } |
||
2845 | |||
2846 | print '<td class="nowraponall tdoverflowmax200" title="' . dol_escape_htmltag($labeltoshowalt) . '">'; |
||
2847 | print $labeltoshow; |
||
2848 | print "</td>\n"; |
||
2849 | if (!$i) { |
||
2850 | $totalarray['nbfield']++; |
||
2851 | } |
||
2852 | } |
||
2853 | |||
2854 | // Account number |
||
2855 | if (!empty($arrayfields['t.numero_compte']['checked'])) { |
||
2856 | print '<td>' . length_accountg($line->numero_compte) . '</td>'; |
||
2857 | if (!$i) { |
||
2858 | $totalarray['nbfield']++; |
||
2859 | } |
||
2860 | } |
||
2861 | |||
2862 | // Subledger account |
||
2863 | if (!empty($arrayfields['t.subledger_account']['checked'])) { |
||
2864 | print '<td>' . length_accounta($line->subledger_account) . '</td>'; |
||
2865 | if (!$i) { |
||
2866 | $totalarray['nbfield']++; |
||
2867 | } |
||
2868 | } |
||
2869 | |||
2870 | // Label operation |
||
2871 | if (!empty($arrayfields['t.label_operation']['checked'])) { |
||
2872 | print '<td class="small tdoverflowmax200" title="' . dol_escape_htmltag($line->label_operation) . '">' . dol_escape_htmltag($line->label_operation) . '</td>'; |
||
2873 | if (!$i) { |
||
2874 | $totalarray['nbfield']++; |
||
2875 | } |
||
2876 | } |
||
2877 | |||
2878 | // Amount debit |
||
2879 | if (!empty($arrayfields['t.debit']['checked'])) { |
||
2880 | print '<td class="right nowraponall amount">' . ($line->debit != 0 ? price($line->debit) : '') . '</td>'; |
||
2881 | if (!$i) { |
||
2882 | $totalarray['nbfield']++; |
||
2883 | } |
||
2884 | if (!$i) { |
||
2885 | $totalarray['pos'][$totalarray['nbfield']] = 'totaldebit'; |
||
2886 | } |
||
2887 | $totalarray['val']['totaldebit'] += $line->debit; |
||
2888 | } |
||
2889 | |||
2890 | // Amount credit |
||
2891 | if (!empty($arrayfields['t.credit']['checked'])) { |
||
2892 | print '<td class="right nowraponall amount">' . ($line->credit != 0 ? price($line->credit) : '') . '</td>'; |
||
2893 | if (!$i) { |
||
2894 | $totalarray['nbfield']++; |
||
2895 | } |
||
2896 | if (!$i) { |
||
2897 | $totalarray['pos'][$totalarray['nbfield']] = 'totalcredit'; |
||
2898 | } |
||
2899 | $totalarray['val']['totalcredit'] += $line->credit; |
||
2900 | } |
||
2901 | |||
2902 | // Lettering code |
||
2903 | if (!empty($arrayfields['t.lettering_code']['checked'])) { |
||
2904 | print '<td class="center">' . $line->lettering_code . '</td>'; |
||
2905 | if (!$i) { |
||
2906 | $totalarray['nbfield']++; |
||
2907 | } |
||
2908 | } |
||
2909 | |||
2910 | // Fields from hook |
||
2911 | $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray); |
||
2912 | $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook |
||
2913 | print $hookmanager->resPrint; |
||
2914 | |||
2915 | // Creation operation date |
||
2916 | if (!empty($arrayfields['t.date_creation']['checked'])) { |
||
2917 | print '<td class="center">' . dol_print_date($line->date_creation, 'dayhour', 'tzuserrel') . '</td>'; |
||
2918 | if (!$i) { |
||
2919 | $totalarray['nbfield']++; |
||
2920 | } |
||
2921 | } |
||
2922 | |||
2923 | // Modification operation date |
||
2924 | if (!empty($arrayfields['t.tms']['checked'])) { |
||
2925 | print '<td class="center">' . dol_print_date($line->date_modification, 'dayhour', 'tzuserrel') . '</td>'; |
||
2926 | if (!$i) { |
||
2927 | $totalarray['nbfield']++; |
||
2928 | } |
||
2929 | } |
||
2930 | |||
2931 | // Exported operation date |
||
2932 | if (!empty($arrayfields['t.date_export']['checked'])) { |
||
2933 | print '<td class="center nowraponall">' . dol_print_date($line->date_export, 'dayhour', 'tzuserrel') . '</td>'; |
||
2934 | if (!$i) { |
||
2935 | $totalarray['nbfield']++; |
||
2936 | } |
||
2937 | } |
||
2938 | |||
2939 | // Validated operation date |
||
2940 | if (!empty($arrayfields['t.date_validated']['checked'])) { |
||
2941 | print '<td class="center nowraponall">' . dol_print_date($line->date_validation, 'dayhour', 'tzuserrel') . '</td>'; |
||
2942 | if (!$i) { |
||
2943 | $totalarray['nbfield']++; |
||
2944 | } |
||
2945 | } |
||
2946 | |||
2947 | if (!empty($arrayfields['t.import_key']['checked'])) { |
||
2948 | print '<td class="tdoverflowmax100">' . $obj->import_key . "</td>\n"; |
||
2949 | if (!$i) { |
||
2950 | $totalarray['nbfield']++; |
||
2951 | } |
||
2952 | } |
||
2953 | |||
2954 | // Action column |
||
2955 | if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { |
||
2956 | print '<td class="nowraponall center">'; |
||
2957 | if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined |
||
2958 | $selected = 0; |
||
2959 | if (in_array($line->id, $arrayofselected)) { |
||
2960 | $selected = 1; |
||
2961 | } |
||
2962 | print '<input id="cb' . $line->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $line->id . '"' . ($selected ? ' checked="checked"' : '') . ' />'; |
||
2963 | } |
||
2964 | print '</td>'; |
||
2965 | if (!$i) { |
||
2966 | $totalarray['nbfield']++; |
||
2967 | } |
||
2968 | } |
||
2969 | |||
2970 | |||
2971 | print "</tr>\n"; |
||
2972 | |||
2973 | $i++; |
||
2974 | } |
||
2975 | |||
2976 | // Show total line |
||
2977 | include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php'; |
||
2978 | |||
2979 | // If no record found |
||
2980 | if ($num == 0) { |
||
2981 | $colspan = 1; |
||
2982 | foreach ($arrayfields as $key => $val) { |
||
2983 | if (!empty($val['checked'])) { |
||
2984 | $colspan++; |
||
2985 | } |
||
2986 | } |
||
2987 | print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>'; |
||
2988 | } |
||
2989 | |||
2990 | $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql); |
||
2991 | $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
||
2992 | print $hookmanager->resPrint; |
||
2993 | |||
2994 | print "</table>"; |
||
2995 | print '</div>'; |
||
2996 | |||
2997 | print '</form>'; |
||
2998 | |||
2999 | // End of page |
||
3000 | llxFooter(); |
||
3001 | |||
3002 | $db->close(); |
||
3003 | } |
||
3004 | |||
3005 | /** |
||
3006 | * \file htdocs/accountancy/bookkeeping/list.php |
||
3007 | * \ingroup Accountancy (Double entries) |
||
3008 | * \brief List operation of book keeping |
||
3009 | */ |
||
3010 | public function list() |
||
4357 | } |
||
4358 | |||
4359 | /** |
||
4360 | * \file htdocs/accountancy/bookkeeping/listbyaccount.php |
||
4361 | * \ingroup Accountancy (Double entries) |
||
4362 | * \brief List operation of ledger ordered by account number |
||
4363 | */ |
||
4364 | public function listbyaccount() |
||
5743 | } |
||
5744 | } |
||
5745 |