1 | <?php |
||
2 | /* Copyright (C) 2013-2017 Olivier Geffroy <[email protected]> |
||
3 | * Copyright (C) 2013-2017 Florian Henry <[email protected]> |
||
4 | * Copyright (C) 2013-2018 Alexandre Spangaro <[email protected]> |
||
5 | * Copyright (C) 2017 Laurent Destailleur <[email protected]> |
||
6 | * Copyright (C) 2018 Frédéric France <[email protected]> |
||
7 | * |
||
8 | * This program is free software; you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation; either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | /** |
||
23 | * \file htdocs/accountancy/bookkeeping/card.php |
||
24 | * \ingroup Advanced accountancy |
||
25 | * \brief Page to show book-entry |
||
26 | */ |
||
27 | |||
28 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
||
29 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
||
30 | require DOL_BASE_PATH . '/main.inc.php'; |
||
31 | require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; |
||
32 | require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; |
||
33 | require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; |
||
34 | require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; |
||
35 | require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; |
||
36 | require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; |
||
37 | require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; |
||
38 | |||
39 | // Load translation files required by the page |
||
40 | $langs->loadLangs(array("accountancy", "bills", "compta")); |
||
41 | |||
42 | $action = GETPOST('action','aZ09'); |
||
43 | |||
44 | $id = GETPOST('id', 'int'); // id of record |
||
45 | $mode = GETPOST('mode','aZ09'); // '' or 'tmp' |
||
46 | $piece_num = GETPOST("piece_num",'int'); // id of transaction (several lines share the same transaction id) |
||
47 | |||
48 | // Security check |
||
49 | if ($user->societe_id > 0) { |
||
50 | accessforbidden(); |
||
51 | } |
||
52 | |||
53 | $mesg = ''; |
||
54 | |||
55 | $accountingaccount = new AccountingAccount($db); |
||
56 | $accountingjournal = new AccountingJournal($db); |
||
57 | |||
58 | $accountingaccount_number = GETPOST('accountingaccount_number','alphanohtml'); |
||
59 | $accountingaccount->fetch(null, $accountingaccount_number, true); |
||
60 | $accountingaccount_label = $accountingaccount->label; |
||
61 | |||
62 | $journal_code = GETPOST('code_journal','alpha'); |
||
63 | $accountingjournal->fetch(null, $journal_code); |
||
64 | $journal_label = $accountingjournal->label; |
||
65 | |||
66 | $subledger_account = GETPOST('subledger_account','alphanohtml'); |
||
67 | if ($subledger_account == - 1) { |
||
68 | $subledger_account = null; |
||
69 | } |
||
70 | $label_operation= GETPOST('label_operation','alphanohtml'); |
||
71 | $debit = price2num(GETPOST('debit','alpha')); |
||
72 | $credit = price2num(GETPOST('credit','alpha')); |
||
73 | |||
74 | $save = GETPOST('save','alpha'); |
||
75 | if (! empty($save)) $action = 'add'; |
||
76 | $update = GETPOST('update','alpha'); |
||
77 | if (! empty($update)) $action = 'confirm_update'; |
||
78 | |||
79 | $object = new BookKeeping($db); |
||
80 | |||
81 | |||
82 | /* |
||
83 | * Actions |
||
84 | */ |
||
85 | |||
86 | if ($action == "confirm_update") { |
||
87 | |||
88 | $error = 0; |
||
89 | |||
90 | if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { |
||
91 | $error++; |
||
92 | setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); |
||
93 | $action='update'; |
||
94 | } |
||
95 | if (empty($accountingaccount_number) || $accountingaccount_number == '-1') |
||
96 | { |
||
97 | $error++; |
||
98 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); |
||
99 | $action='update'; |
||
100 | } |
||
101 | |||
102 | if (! $error) |
||
103 | { |
||
104 | $object = new BookKeeping($db); |
||
105 | |||
106 | $result = $object->fetch($id, null, $mode); |
||
107 | if ($result < 0) { |
||
108 | $error++; |
||
109 | setEventMessages($object->error, $object->errors, 'errors'); |
||
110 | } else { |
||
111 | $object->numero_compte = $accountingaccount_number; |
||
112 | $object->subledger_account = $subledger_account; |
||
113 | $object->label_compte = $accountingaccount_label; |
||
114 | $object->label_operation= $label_operation; |
||
115 | $object->debit = $debit; |
||
116 | $object->credit = $credit; |
||
117 | |||
118 | if (floatval($debit) != 0.0) { |
||
119 | $object->montant = $debit; |
||
120 | $object->sens = 'D'; |
||
121 | } |
||
122 | if (floatval($credit) != 0.0) { |
||
123 | $object->montant = $credit; |
||
124 | $object->sens = 'C'; |
||
125 | } |
||
126 | |||
127 | $result = $object->update($user, false, $mode); |
||
128 | if ($result < 0) { |
||
129 | setEventMessages($object->error, $object->errors, 'errors'); |
||
130 | } else { |
||
131 | if ($mode != '_tmp') |
||
132 | { |
||
133 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
134 | } |
||
135 | |||
136 | $debit = 0; |
||
137 | $credit = 0; |
||
138 | |||
139 | $action = ''; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | else if ($action == "add") { |
||
146 | $error = 0; |
||
147 | |||
148 | if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) |
||
149 | { |
||
150 | $error++; |
||
151 | setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); |
||
152 | $action=''; |
||
153 | } |
||
154 | if (empty($accountingaccount_number) || $accountingaccount_number == '-1') |
||
155 | { |
||
156 | $error++; |
||
157 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors'); |
||
158 | $action=''; |
||
159 | } |
||
160 | |||
161 | if (! $error) { |
||
162 | $object = new BookKeeping($db); |
||
163 | |||
164 | $object->numero_compte = $accountingaccount_number; |
||
165 | $object->subledger_account = $subledger_account; |
||
166 | $object->label_compte = $accountingaccount_label; |
||
167 | $object->label_operation= $label_operation; |
||
168 | $object->debit = $debit; |
||
169 | $object->credit = $credit; |
||
170 | $object->doc_date = GETPOST('doc_date','alpha'); |
||
171 | $object->doc_type = GETPOST('doc_type','alpha'); |
||
172 | $object->piece_num = $piece_num; |
||
173 | $object->doc_ref = GETPOST('doc_ref','alpha'); |
||
174 | $object->code_journal = $journal_code; |
||
175 | $object->journal_label = $journal_label; |
||
176 | $object->fk_doc = GETPOST('fk_doc','alpha'); |
||
0 ignored issues
–
show
|
|||
177 | $object->fk_docdet = GETPOST('fk_docdet','alpha'); |
||
0 ignored issues
–
show
The property
$fk_docdet was declared of type integer , but GETPOST('fk_docdet', 'alpha') is of type string . Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
178 | |||
179 | if (floatval($debit) != 0.0) { |
||
180 | $object->montant = $debit; |
||
181 | $object->sens = 'D'; |
||
182 | } |
||
183 | |||
184 | if (floatval($credit) != 0.0) { |
||
185 | $object->montant = $credit; |
||
186 | $object->sens = 'C'; |
||
187 | } |
||
188 | |||
189 | $result = $object->createStd($user, false, $mode); |
||
190 | if ($result < 0) { |
||
191 | setEventMessages($object->error, $object->errors, 'errors'); |
||
192 | } else { |
||
193 | if ($mode != '_tmp') |
||
194 | { |
||
195 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
196 | } |
||
197 | |||
198 | $debit = 0; |
||
199 | $credit = 0; |
||
200 | |||
201 | $action = ''; |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | |||
206 | else if ($action == "confirm_delete") { |
||
207 | $object = new BookKeeping($db); |
||
208 | |||
209 | $result = $object->fetch($id, null, $mode); |
||
210 | $piece_num = $object->piece_num; |
||
211 | |||
212 | if ($result < 0) { |
||
213 | setEventMessages($object->error, $object->errors, 'errors'); |
||
214 | } else { |
||
215 | $result = $object->delete($user, false, $mode); |
||
216 | if ($result < 0) { |
||
217 | setEventMessages($object->error, $object->errors, 'errors'); |
||
218 | } |
||
219 | } |
||
220 | $action = ''; |
||
221 | } |
||
222 | |||
223 | else if ($action == "confirm_create") { |
||
224 | $error = 0; |
||
225 | |||
226 | $object = new BookKeeping($db); |
||
227 | |||
228 | if (! $journal_code || $journal_code == '-1') { |
||
229 | setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors'); |
||
230 | $action='create'; |
||
231 | $error++; |
||
232 | } |
||
233 | if (! GETPOST('next_num_mvt', 'alpha')) |
||
234 | { |
||
235 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumPiece")), null, 'errors'); |
||
236 | $error++; |
||
237 | } |
||
238 | |||
239 | if (! $error) |
||
240 | { |
||
241 | $object->label_compte = ''; |
||
242 | $object->debit = 0; |
||
243 | $object->credit = 0; |
||
244 | $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth','int'), GETPOST('doc_dateday','int'), GETPOST('doc_dateyear','int')); |
||
245 | $object->doc_type = GETPOST('doc_type','alpha'); |
||
246 | $object->piece_num = GETPOST('next_num_mvt','alpha'); |
||
247 | $object->doc_ref = GETPOST('doc_ref','alpha'); |
||
248 | $object->code_journal = $journal_code; |
||
249 | $object->journal_label = $journal_label; |
||
250 | $object->fk_doc = 0; |
||
251 | $object->fk_docdet = 0; |
||
252 | $object->montant = 0; |
||
253 | |||
254 | $result = $object->createStd($user,0, $mode); |
||
255 | if ($result < 0) { |
||
256 | setEventMessages($object->error, $object->errors, 'errors'); |
||
257 | } else { |
||
258 | if ($mode != '_tmp') |
||
259 | { |
||
260 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
261 | } |
||
262 | $action = 'update'; |
||
263 | $id=$object->id; |
||
264 | $piece_num = $object->piece_num; |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | |||
269 | if ($action == 'setdate') { |
||
270 | $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); |
||
271 | $result = $object->updateByMvt($piece_num,'doc_date',$db->idate($datedoc),$mode); |
||
272 | if ($result < 0) { |
||
273 | setEventMessages($object->error, $object->errors, 'errors'); |
||
274 | } else { |
||
275 | if ($mode != '_tmp') |
||
276 | { |
||
277 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
278 | } |
||
279 | $action = ''; |
||
280 | } |
||
281 | } |
||
282 | |||
283 | if ($action == 'setjournal') { |
||
284 | $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode); |
||
285 | $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode); |
||
286 | if ($result < 0) { |
||
287 | setEventMessages($object->error, $object->errors, 'errors'); |
||
288 | } else { |
||
289 | if ($mode != '_tmp') |
||
290 | { |
||
291 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
292 | } |
||
293 | $action = ''; |
||
294 | } |
||
295 | } |
||
296 | |||
297 | if ($action == 'setdocref') { |
||
298 | $refdoc = trim(GETPOST('doc_ref','alpha')); |
||
299 | $result = $object->updateByMvt($piece_num,'doc_ref',$refdoc,$mode); |
||
300 | if ($result < 0) { |
||
301 | setEventMessages($object->error, $object->errors, 'errors'); |
||
302 | } else { |
||
303 | if ($mode != '_tmp') |
||
304 | { |
||
305 | setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); |
||
306 | } |
||
307 | $action = ''; |
||
308 | } |
||
309 | } |
||
310 | |||
311 | // Validate transaction |
||
312 | if ($action == 'valid') { |
||
313 | $result = $object->transformTransaction(0,$piece_num); |
||
314 | if ($result < 0) { |
||
315 | setEventMessages($object->error, $object->errors, 'errors'); |
||
316 | } else { |
||
317 | header("Location: list.php?sortfield=t.piece_num&sortorder=asc"); |
||
318 | exit; |
||
319 | } |
||
320 | } |
||
321 | |||
322 | |||
323 | /* |
||
324 | * View |
||
325 | */ |
||
326 | |||
327 | $html = new Form($db); |
||
328 | $formaccounting = new FormAccounting($db); |
||
329 | |||
330 | llxHeader('', $langs->trans("CreateMvts")); |
||
331 | |||
332 | // Confirmation to delete the command |
||
333 | if ($action == 'delete') { |
||
334 | $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id.'&mode='. $mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'confirm_delete', '', 0, 1); |
||
335 | print $formconfirm; |
||
336 | } |
||
337 | |||
338 | if ($action == 'create') |
||
339 | { |
||
340 | print load_fiche_titre($langs->trans("CreateMvts")); |
||
341 | |||
342 | $object = new BookKeeping($db); |
||
343 | $next_num_mvt = $object->getNextNumMvt('_tmp'); |
||
344 | |||
345 | if (empty($next_num_mvt)) |
||
346 | { |
||
347 | dol_print_error('', 'Failed to get next piece number'); |
||
348 | } |
||
349 | |||
350 | print '<form action="' . $_SERVER["PHP_SELF"] . '" name="create_mvt" method="POST">'; |
||
351 | print '<input type="hidden" name="action" value="confirm_create">' . "\n"; |
||
352 | print '<input type="hidden" name="next_num_mvt" value="' . $next_num_mvt . '">' . "\n"; |
||
353 | print '<input type="hidden" name="mode" value="_tmp">' . "\n"; |
||
354 | |||
355 | dol_fiche_head(); |
||
356 | |||
357 | print '<table class="border" width="100%">'; |
||
358 | |||
359 | /*print '<tr>'; |
||
360 | print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>'; |
||
361 | print '<td>' . $next_num_mvt . '</td>'; |
||
362 | print '</tr>';*/ |
||
363 | |||
364 | print '<tr>'; |
||
365 | print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("Docdate") . '</td>'; |
||
366 | print '<td>'; |
||
367 | print $html->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1); |
||
368 | print '</td>'; |
||
369 | print '</tr>'; |
||
370 | |||
371 | print '<tr>'; |
||
372 | print '<td class="fieldrequired">' . $langs->trans("Codejournal") . '</td>'; |
||
373 | print '<td>' . $formaccounting->select_journal($journal_code,'code_journal',0,0,1,1) . '</td>'; |
||
374 | print '</tr>'; |
||
375 | |||
376 | print '<tr>'; |
||
377 | print '<td>' . $langs->trans("Piece") . '</td>'; |
||
378 | print '<td><input type="text" class="minwidth200" name="doc_ref" value=""/></td>'; |
||
379 | print '</tr>'; |
||
380 | |||
381 | /* |
||
382 | print '<tr>'; |
||
383 | print '<td>' . $langs->trans("Doctype") . '</td>'; |
||
384 | print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>'; |
||
385 | print '</tr>'; |
||
386 | */ |
||
387 | |||
388 | print '</table>'; |
||
389 | |||
390 | dol_fiche_end(); |
||
391 | |||
392 | print '<div class="center">'; |
||
393 | print '<input type="submit" class="button" value="' . $langs->trans("Create") . '">'; |
||
394 | print ' '; |
||
395 | print '<input type="button" value="' . $langs->trans("Cancel") . '" class="button" onclick="history.go(-1)" />'; |
||
396 | print '</div>'; |
||
397 | |||
398 | print '</form>'; |
||
399 | } else { |
||
400 | $object = new BookKeeping($db); |
||
401 | $result = $object->fetchPerMvt($piece_num, $mode); |
||
402 | if ($result < 0) { |
||
403 | setEventMessages($object->error, $object->errors, 'errors'); |
||
404 | } |
||
405 | |||
406 | if (! empty($object->piece_num)) |
||
407 | { |
||
408 | $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">' . $langs->trans('BackToList') . '</a>'; |
||
409 | |||
410 | print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); |
||
411 | |||
412 | $head=array(); |
||
413 | $h=0; |
||
414 | $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode?'&mode='.$mode:''); |
||
415 | $head[$h][1] = $langs->trans("Transaction"); |
||
416 | $head[$h][2] = 'transaction'; |
||
417 | $h++; |
||
418 | |||
419 | dol_fiche_head($head, 'transaction', '', -1); |
||
420 | |||
421 | //dol_banner_tab($object, '', $backlink); |
||
422 | |||
423 | print '<div class="fichecenter">'; |
||
424 | print '<div class="fichehalfleft">'; |
||
425 | |||
426 | print '<div class="underbanner clearboth"></div>'; |
||
427 | print '<table class="border tableforfield" width="100%">'; |
||
428 | |||
429 | // Account movement |
||
430 | print '<tr>'; |
||
431 | print '<td class="titlefield">' . $langs->trans("NumMvts") . '</td>'; |
||
432 | print '<td>' . $object->piece_num . '</td>'; |
||
433 | print '</tr>'; |
||
434 | |||
435 | // Date |
||
436 | print '<tr><td>'; |
||
437 | print '<table class="nobordernopadding" width="100%"><tr><td>'; |
||
438 | print $langs->trans('Docdate'); |
||
439 | print '</td>'; |
||
440 | if ($action != 'editdate') |
||
441 | print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&piece_num='. $object->piece_num .'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('SetDate'),1).'</a></td>'; |
||
442 | print '</tr></table>'; |
||
443 | print '</td><td colspan="3">'; |
||
444 | if ($action == 'editdate') { |
||
445 | print '<form name="setdate" action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
446 | print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">'; |
||
447 | print '<input type="hidden" name="action" value="setdate">'; |
||
448 | print '<input type="hidden" name="mode" value="'.$mode.'">'; |
||
449 | print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate"); |
||
450 | print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">'; |
||
451 | print '</form>'; |
||
452 | } else { |
||
453 | print $object->doc_date ? dol_print_date($object->doc_date, 'day') : ' '; |
||
454 | } |
||
455 | print '</td>'; |
||
456 | print '</tr>'; |
||
457 | |||
458 | // Journal |
||
459 | print '<tr><td>'; |
||
460 | print '<table class="nobordernopadding" width="100%"><tr><td>'; |
||
461 | print $langs->trans('Codejournal'); |
||
462 | print '</td>'; |
||
463 | if ($action != 'editjournal') |
||
464 | print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editjournal&piece_num='.$object->piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>'; |
||
465 | print '</tr></table>'; |
||
466 | print '</td><td>'; |
||
467 | if ($action == 'editjournal') { |
||
468 | print '<form name="setjournal" action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
469 | print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">'; |
||
470 | print '<input type="hidden" name="action" value="setjournal">'; |
||
471 | print '<input type="hidden" name="mode" value="'.$mode.'">'; |
||
472 | print $formaccounting->select_journal($object->code_journal,'code_journal',0,0,array(),1,1); |
||
473 | print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">'; |
||
474 | print '</form>'; |
||
475 | } else { |
||
476 | print $object->code_journal ; |
||
477 | } |
||
478 | print '</td>'; |
||
479 | print '</tr>'; |
||
480 | |||
481 | // Ref document |
||
482 | print '<tr><td>'; |
||
483 | print '<table class="nobordernopadding" width="100%"><tr><td>'; |
||
484 | print $langs->trans('Piece'); |
||
485 | print '</td>'; |
||
486 | if ($action != 'editdocref') |
||
487 | print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdocref&piece_num='.$object->piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).'</a></td>'; |
||
488 | print '</tr></table>'; |
||
489 | print '</td><td>'; |
||
490 | if ($action == 'editdocref') { |
||
491 | print '<form name="setdocref" action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
492 | print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">'; |
||
493 | print '<input type="hidden" name="action" value="setdocref">'; |
||
494 | print '<input type="hidden" name="mode" value="'.$mode.'">'; |
||
495 | print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">'; |
||
496 | print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">'; |
||
497 | print '</form>'; |
||
498 | } else { |
||
499 | print $object->doc_ref ; |
||
500 | } |
||
501 | print '</td>'; |
||
502 | print '</tr>'; |
||
503 | |||
504 | print '</table>'; |
||
505 | |||
506 | print '</div>'; |
||
507 | |||
508 | print '<div class="fichehalfright"><div class="ficheaddleft">'; |
||
509 | |||
510 | print '<div class="underbanner clearboth"></div>'; |
||
511 | print '<table class="border tableforfield" width="100%">'; |
||
512 | |||
513 | // Doc type |
||
514 | if(! empty($object->doc_type)) |
||
515 | { |
||
516 | print '<tr>'; |
||
517 | print '<td class="titlefield">' . $langs->trans("Doctype") . '</td>'; |
||
518 | print '<td>' . $object->doc_type . '</td>'; |
||
519 | print '</tr>'; |
||
520 | } |
||
521 | |||
522 | // Date document creation |
||
523 | print '<tr>'; |
||
524 | print '<td class="titlefield">' . $langs->trans("DateCreation") . '</td>'; |
||
525 | print '<td>'; |
||
526 | print $object->date_creation ? dol_print_date($object->date_creation, 'day') : ' '; |
||
527 | print '</td>'; |
||
528 | print '</tr>'; |
||
529 | |||
530 | // Validate |
||
531 | /* |
||
532 | print '<tr>'; |
||
533 | print '<td class="titlefield">' . $langs->trans("Status") . '</td>'; |
||
534 | print '<td>'; |
||
535 | if (empty($object->validated)) { |
||
536 | print '<a href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->rowid . '&action=enable">'; |
||
537 | print img_picto($langs->trans("Disabled"), 'switch_off'); |
||
538 | print '</a>'; |
||
539 | } else { |
||
540 | print '<a href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->rowid . '&action=disable">'; |
||
541 | print img_picto($langs->trans("Activated"), 'switch_on'); |
||
542 | print '</a>'; |
||
543 | } |
||
544 | print '</td>'; |
||
545 | print '</tr>'; |
||
546 | */ |
||
547 | |||
548 | // check data |
||
549 | /* |
||
550 | print '<tr>'; |
||
551 | print '<td class="titlefield">' . $langs->trans("Control") . '</td>'; |
||
552 | if ($object->doc_type == 'customer_invoice') |
||
553 | { |
||
554 | $sqlmid = 'SELECT rowid as ref'; |
||
555 | $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac"; |
||
556 | $sqlmid .= " WHERE fac.rowid=" . $object->fk_doc; |
||
557 | dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG); |
||
558 | $resultmid = $db->query($sqlmid); |
||
559 | if ($resultmid) { |
||
560 | $objmid = $db->fetch_object($resultmid); |
||
561 | $invoicestatic = new Facture($db); |
||
562 | $invoicestatic->fetch($objmid->ref); |
||
563 | $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); |
||
564 | } |
||
565 | else dol_print_error($db); |
||
566 | } |
||
567 | print '<td>' . $ref .'</td>'; |
||
568 | print '</tr>'; |
||
569 | */ |
||
570 | print "</table>\n"; |
||
571 | |||
572 | print '</div></div><!-ee-->'; |
||
573 | |||
574 | dol_fiche_end(); |
||
575 | |||
576 | print '<div style="clear:both"></div>'; |
||
577 | |||
578 | print '<br>'; |
||
579 | |||
580 | $result = $object->fetchAllPerMvt($piece_num, $mode); |
||
581 | if ($result < 0) { |
||
582 | setEventMessages($object->error, $object->errors, 'errors'); |
||
583 | } else { |
||
584 | |||
585 | print load_fiche_titre($langs->trans("ListeMvts"), '', ''); |
||
586 | |||
587 | print '<form action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $object->piece_num . '" method="post">'; |
||
588 | print '<input type="hidden" name="doc_date" value="' . $object->doc_date . '">' . "\n"; |
||
589 | print '<input type="hidden" name="doc_type" value="' . $object->doc_type . '">' . "\n"; |
||
590 | print '<input type="hidden" name="doc_ref" value="' . $object->doc_ref . '">' . "\n"; |
||
591 | print '<input type="hidden" name="code_journal" value="' . $object->code_journal . '">' . "\n"; |
||
592 | print '<input type="hidden" name="fk_doc" value="' . $object->fk_doc . '">' . "\n"; |
||
593 | print '<input type="hidden" name="fk_docdet" value="' . $object->fk_docdet . '">' . "\n"; |
||
594 | print '<input type="hidden" name="mode" value="' . $mode . '">' . "\n"; |
||
595 | |||
596 | print "<table class=\"noborder\" width=\"100%\">"; |
||
597 | if (count($object->linesmvt) > 0) { |
||
598 | |||
599 | $total_debit = 0; |
||
600 | $total_credit = 0; |
||
601 | |||
602 | print '<tr class="liste_titre">'; |
||
603 | |||
604 | print_liste_field_titre("AccountAccountingShort"); |
||
605 | print_liste_field_titre("SubledgerAccount"); |
||
606 | print_liste_field_titre("LabelOperation"); |
||
607 | print_liste_field_titre("Debit", "", "", "", "", 'align="right"'); |
||
608 | print_liste_field_titre("Credit", "", "", "", "", 'align="right"'); |
||
609 | print_liste_field_titre("Action", "", "", "", "", 'width="60" align="center"'); |
||
610 | |||
611 | print "</tr>\n"; |
||
612 | |||
613 | foreach ($object->linesmvt as $line) { |
||
614 | print '<tr class="oddeven">'; |
||
615 | $total_debit += $line->debit; |
||
616 | $total_credit += $line->credit; |
||
617 | |||
618 | if ($action == 'update' && $line->id == $id) { |
||
619 | print '<td>'; |
||
620 | print $formaccounting->select_account($line->numero_compte, 'accountingaccount_number', 1, array (), 1, 1, ''); |
||
621 | print '</td>'; |
||
622 | print '<td>'; |
||
623 | // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not |
||
624 | // use setup of keypress to select thirdparty and this hang browser on large database. |
||
625 | if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) |
||
626 | { |
||
627 | print $formaccounting->select_auxaccount($line->subledger_account, 'subledger_account', 1); |
||
628 | } |
||
629 | else |
||
630 | { |
||
631 | print '<input type="text" name="subledger_account" value="'.$line->subledger_account.'">'; |
||
632 | } |
||
633 | print '</td>'; |
||
634 | print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $line->label_operation. '"/></td>'; |
||
635 | print '<td align="right"><input type="text" size="6" class="right" name="debit" value="' . price($line->debit) . '"/></td>'; |
||
636 | print '<td align="right"><input type="text" size="6" class="right" name="credit" value="' . price($line->credit) . '"/></td>'; |
||
637 | print '<td>'; |
||
638 | print '<input type="hidden" name="id" value="' . $line->id . '">' . "\n"; |
||
639 | print '<input type="submit" class="button" name="update" value="' . $langs->trans("Update") . '">'; |
||
640 | print '</td>'; |
||
641 | } else { |
||
642 | $accountingaccount->fetch(null, $line->numero_compte, true); |
||
643 | print '<td>' . $accountingaccount->getNomUrl(0,1,1,'',0) . '</td>'; |
||
644 | print '<td>' . length_accounta($line->subledger_account) . '</td>'; |
||
645 | print '<td>' . $line->label_operation. '</td>'; |
||
646 | print '<td align="right">' . price($line->debit) . '</td>'; |
||
647 | print '<td align="right">' . price($line->credit) . '</td>'; |
||
648 | |||
649 | print '<td align="center">'; |
||
650 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $line->id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; |
||
651 | print img_edit(); |
||
652 | print '</a> '; |
||
653 | |||
654 | $actiontodelete='delete'; |
||
655 | if ($mode == '_tmp' || $action != 'delmouv') $actiontodelete='confirm_delete'; |
||
656 | |||
657 | print '<a href="' . $_SERVER["PHP_SELF"] . '?action='.$actiontodelete.'&id=' . $line->id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; |
||
658 | print img_delete(); |
||
659 | |||
660 | print '</a>'; |
||
661 | print '</td>'; |
||
662 | } |
||
663 | print "</tr>\n"; |
||
664 | } |
||
665 | |||
666 | $total_debit = price2num($total_debit); |
||
667 | $total_credit = price2num($total_credit); |
||
668 | |||
669 | if ($total_debit != $total_credit) |
||
670 | { |
||
671 | setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings'); |
||
672 | } |
||
673 | |||
674 | if ($action == "" || $action == 'add') { |
||
675 | print '<tr class="oddeven">'; |
||
676 | print '<td>'; |
||
677 | print $formaccounting->select_account($accountingaccount_number, 'accountingaccount_number', 1, array (), 1, 1, ''); |
||
678 | print '</td>'; |
||
679 | print '<td>'; |
||
680 | // TODO For the moment we keep a fre input text instead of a combo. The select_auxaccount has problem because it does not |
||
681 | // use setup of keypress to select thirdparty and this hang browser on large database. |
||
682 | if (! empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) |
||
683 | { |
||
684 | print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1); |
||
685 | } |
||
686 | else |
||
687 | { |
||
688 | print '<input type="text" name="subledger_account" value="">'; |
||
689 | } |
||
690 | print '</td>'; |
||
691 | print '<td><input type="text" class="minwidth200" name="label_operation" value=""/></td>'; |
||
692 | print '<td align="right"><input type="text" size="6" class="right" name="debit" value=""/></td>'; |
||
693 | print '<td align="right"><input type="text" size="6" class="right" name="credit" value=""/></td>'; |
||
694 | print '<td><input type="submit" class="button" name="save" value="' . $langs->trans("Add") . '"></td>'; |
||
695 | print '</tr>'; |
||
696 | } |
||
697 | print '</table>'; |
||
698 | |||
699 | |||
700 | if ($mode=='_tmp' && $action=='') |
||
701 | { |
||
702 | print '<br>'; |
||
703 | print '<div class="center">'; |
||
704 | if ($total_debit == $total_credit) |
||
705 | { |
||
706 | print '<a class="button" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $object->piece_num . '&action=valid">'.$langs->trans("ValidTransaction").'</a>'; |
||
707 | } |
||
708 | else |
||
709 | { |
||
710 | 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")).'">'; |
||
711 | } |
||
712 | |||
713 | print ' '; |
||
714 | print '<a class="button" href="' . DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>'; |
||
715 | |||
716 | print "</div>"; |
||
717 | } |
||
718 | print '</form>'; |
||
719 | } |
||
720 | } |
||
721 | } else { |
||
722 | print load_fiche_titre($langs->trans("NoRecords")); |
||
723 | } |
||
724 | } |
||
725 | |||
726 | dol_fiche_end(); |
||
727 | |||
728 | // End of page |
||
729 | llxFooter(); |
||
730 | $db->close(); |
||
731 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.