card.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. <?php
  2. /* Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Florian Henry <florian.henry@open-concept.pro>
  4. * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  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 <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/bookkeeping/card.php
  23. * \ingroup Accountancy (Double entries)
  24. * \brief Page to show book-entry
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("accountancy", "bills", "compta"));
  36. $action = GETPOST('action', 'aZ09');
  37. $cancel = GETPOST('cancel', 'aZ09');
  38. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  39. $id = GETPOST('id', 'int'); // id of record
  40. $mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
  41. $piece_num = GETPOST("piece_num", 'int'); // id of transaction (several lines share the same transaction id)
  42. $accountingaccount = new AccountingAccount($db);
  43. $accountingjournal = new AccountingJournal($db);
  44. $accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
  45. $accountingaccount->fetch(null, $accountingaccount_number, true);
  46. $accountingaccount_label = $accountingaccount->label;
  47. $journal_code = GETPOST('code_journal', 'alpha');
  48. $accountingjournal->fetch(null, $journal_code);
  49. $journal_label = $accountingjournal->label;
  50. $subledger_account = GETPOST('subledger_account', 'alphanohtml');
  51. if ($subledger_account == -1) {
  52. $subledger_account = null;
  53. }
  54. $subledger_label = GETPOST('subledger_label', 'alphanohtml');
  55. $label_operation = GETPOST('label_operation', 'alphanohtml');
  56. $debit = price2num(GETPOST('debit', 'alpha'));
  57. $credit = price2num(GETPOST('credit', 'alpha'));
  58. $save = GETPOST('save', 'alpha');
  59. if (!empty($save)) {
  60. $action = 'add';
  61. }
  62. $update = GETPOST('update', 'alpha');
  63. if (!empty($update)) {
  64. $action = 'confirm_update';
  65. }
  66. $object = new BookKeeping($db);
  67. // Security check
  68. if (empty($conf->accounting->enabled)) {
  69. accessforbidden();
  70. }
  71. if ($user->socid > 0) {
  72. accessforbidden();
  73. }
  74. if (empty($user->rights->accounting->mouvements->lire)) {
  75. accessforbidden();
  76. }
  77. /*
  78. * Actions
  79. */
  80. if ($cancel) {
  81. header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php');
  82. exit;
  83. }
  84. if ($action == "confirm_update") {
  85. $error = 0;
  86. if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
  87. $error++;
  88. setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
  89. $action = 'update';
  90. }
  91. if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
  92. $error++;
  93. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
  94. $action = 'update';
  95. }
  96. if (!$error) {
  97. $object = new BookKeeping($db);
  98. $result = $object->fetch($id, null, $mode);
  99. if ($result < 0) {
  100. $error++;
  101. setEventMessages($object->error, $object->errors, 'errors');
  102. } else {
  103. $object->numero_compte = $accountingaccount_number;
  104. $object->subledger_account = $subledger_account;
  105. $object->subledger_label = $subledger_label;
  106. $object->label_compte = $accountingaccount_label;
  107. $object->label_operation = $label_operation;
  108. $object->debit = $debit;
  109. $object->credit = $credit;
  110. if (floatval($debit) != 0.0) {
  111. $object->montant = $debit; // deprecated
  112. $object->amount = $debit;
  113. $object->sens = 'D';
  114. }
  115. if (floatval($credit) != 0.0) {
  116. $object->montant = $credit; // deprecated
  117. $object->amount = $credit;
  118. $object->sens = 'C';
  119. }
  120. $result = $object->update($user, false, $mode);
  121. if ($result < 0) {
  122. setEventMessages($object->error, $object->errors, 'errors');
  123. } else {
  124. if ($mode != '_tmp') {
  125. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  126. }
  127. $debit = 0;
  128. $credit = 0;
  129. $action = '';
  130. }
  131. }
  132. }
  133. } elseif ($action == "add") {
  134. $error = 0;
  135. if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
  136. $error++;
  137. setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
  138. $action = '';
  139. }
  140. if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
  141. $error++;
  142. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
  143. $action = '';
  144. }
  145. if (!$error) {
  146. $object = new BookKeeping($db);
  147. $object->numero_compte = $accountingaccount_number;
  148. $object->subledger_account = $subledger_account;
  149. $object->subledger_label = $subledger_label;
  150. $object->label_compte = $accountingaccount_label;
  151. $object->label_operation = $label_operation;
  152. $object->debit = $debit;
  153. $object->credit = $credit;
  154. $object->doc_date = (string) GETPOST('doc_date', 'alpha');
  155. $object->doc_type = (string) GETPOST('doc_type', 'alpha');
  156. $object->piece_num = $piece_num;
  157. $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
  158. $object->code_journal = $journal_code;
  159. $object->journal_label = $journal_label;
  160. $object->fk_doc = GETPOSTINT('fk_doc');
  161. $object->fk_docdet = GETPOSTINT('fk_docdet');
  162. if (floatval($debit) != 0.0) {
  163. $object->montant = $debit; // deprecated
  164. $object->amount = $debit;
  165. $object->sens = 'D';
  166. }
  167. if (floatval($credit) != 0.0) {
  168. $object->montant = $credit; // deprecated
  169. $object->amount = $credit;
  170. $object->sens = 'C';
  171. }
  172. $result = $object->createStd($user, false, $mode);
  173. if ($result < 0) {
  174. setEventMessages($object->error, $object->errors, 'errors');
  175. } else {
  176. if ($mode != '_tmp') {
  177. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  178. }
  179. $debit = 0;
  180. $credit = 0;
  181. $action = '';
  182. }
  183. }
  184. } elseif ($action == "confirm_delete") {
  185. $object = new BookKeeping($db);
  186. $result = $object->fetch($id, null, $mode);
  187. $piece_num = $object->piece_num;
  188. if ($result < 0) {
  189. setEventMessages($object->error, $object->errors, 'errors');
  190. } else {
  191. $result = $object->delete($user, false, $mode);
  192. if ($result < 0) {
  193. setEventMessages($object->error, $object->errors, 'errors');
  194. }
  195. }
  196. $action = '';
  197. } elseif ($action == "confirm_create") {
  198. $error = 0;
  199. $object = new BookKeeping($db);
  200. if (!$journal_code || $journal_code == '-1') {
  201. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
  202. $action = 'create';
  203. $error++;
  204. }
  205. if (!GETPOST('doc_ref', 'alpha')) {
  206. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
  207. $action = 'create';
  208. $error++;
  209. }
  210. if (!$error) {
  211. $object->label_compte = '';
  212. $object->debit = 0;
  213. $object->credit = 0;
  214. $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  215. $object->doc_type = GETPOST('doc_type', 'alpha');
  216. $object->piece_num = GETPOST('next_num_mvt', 'alpha');
  217. $object->doc_ref = GETPOST('doc_ref', 'alpha');
  218. $object->code_journal = $journal_code;
  219. $object->journal_label = $journal_label;
  220. $object->fk_doc = 0;
  221. $object->fk_docdet = 0;
  222. $object->montant = 0; // deprecated
  223. $object->amount = 0;
  224. $result = $object->createStd($user, 0, $mode);
  225. if ($result < 0) {
  226. setEventMessages($object->error, $object->errors, 'errors');
  227. } else {
  228. if ($mode != '_tmp') {
  229. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  230. }
  231. $action = '';
  232. $id = $object->id;
  233. $piece_num = $object->piece_num;
  234. }
  235. }
  236. }
  237. if ($action == 'setdate') {
  238. $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
  239. $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
  240. if ($result < 0) {
  241. setEventMessages($object->error, $object->errors, 'errors');
  242. } else {
  243. if ($mode != '_tmp') {
  244. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  245. }
  246. $action = '';
  247. }
  248. }
  249. if ($action == 'setjournal') {
  250. $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
  251. $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
  252. if ($result < 0) {
  253. setEventMessages($object->error, $object->errors, 'errors');
  254. } else {
  255. if ($mode != '_tmp') {
  256. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  257. }
  258. $action = '';
  259. }
  260. }
  261. if ($action == 'setdocref') {
  262. $refdoc = GETPOST('doc_ref', 'alpha');
  263. $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
  264. if ($result < 0) {
  265. setEventMessages($object->error, $object->errors, 'errors');
  266. } else {
  267. if ($mode != '_tmp') {
  268. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  269. }
  270. $action = '';
  271. }
  272. }
  273. // Validate transaction
  274. if ($action == 'valid') {
  275. $result = $object->transformTransaction(0, $piece_num);
  276. if ($result < 0) {
  277. setEventMessages($object->error, $object->errors, 'errors');
  278. } else {
  279. header("Location: list.php?sortfield=t.piece_num&sortorder=asc");
  280. exit;
  281. }
  282. }
  283. /*
  284. * View
  285. */
  286. $html = new Form($db);
  287. $formaccounting = new FormAccounting($db);
  288. llxHeader('', $langs->trans("CreateMvts"));
  289. // Confirmation to delete the command
  290. if ($action == 'delete') {
  291. $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
  292. print $formconfirm;
  293. }
  294. if ($action == 'create') {
  295. print load_fiche_titre($langs->trans("CreateMvts"));
  296. $object = new BookKeeping($db);
  297. $next_num_mvt = $object->getNextNumMvt('_tmp');
  298. if (empty($next_num_mvt)) {
  299. dol_print_error('', 'Failed to get next piece number');
  300. }
  301. print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
  302. if ($optioncss != '') {
  303. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  304. }
  305. print '<input type="hidden" name="token" value="'.newToken().'">';
  306. print '<input type="hidden" name="action" value="confirm_create">'."\n";
  307. print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
  308. print '<input type="hidden" name="mode" value="_tmp">'."\n";
  309. print dol_get_fiche_head();
  310. print '<table class="border centpercent">';
  311. /*print '<tr>';
  312. print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
  313. print '<td>' . $next_num_mvt . '</td>';
  314. print '</tr>';*/
  315. print '<tr>';
  316. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
  317. print '<td>';
  318. print $html->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
  319. print '</td>';
  320. print '</tr>';
  321. print '<tr>';
  322. print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
  323. print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
  324. print '</tr>';
  325. print '<tr>';
  326. print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
  327. print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
  328. print '</tr>';
  329. /*
  330. print '<tr>';
  331. print '<td>' . $langs->trans("Doctype") . '</td>';
  332. print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
  333. print '</tr>';
  334. */
  335. print '</table>';
  336. print dol_get_fiche_end();
  337. print $form->buttonsSaveCancel("Create");
  338. print '</form>';
  339. } else {
  340. $object = new BookKeeping($db);
  341. $result = $object->fetchPerMvt($piece_num, $mode);
  342. if ($result < 0) {
  343. setEventMessages($object->error, $object->errors, 'errors');
  344. }
  345. if (!empty($object->piece_num)) {
  346. $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
  347. print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
  348. $head = array();
  349. $h = 0;
  350. $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : '');
  351. $head[$h][1] = $langs->trans("Transaction");
  352. $head[$h][2] = 'transaction';
  353. $h++;
  354. print dol_get_fiche_head($head, 'transaction', '', -1);
  355. //dol_banner_tab($object, '', $backlink);
  356. print '<div class="fichecenter">';
  357. print '<div class="fichehalfleft">';
  358. print '<div class="underbanner clearboth"></div>';
  359. print '<table class="border tableforfield" width="100%">';
  360. // Account movement
  361. print '<tr>';
  362. print '<td class="titlefield">'.$langs->trans("NumMvts").'</td>';
  363. print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
  364. print '</tr>';
  365. // Date
  366. print '<tr><td>';
  367. print '<table class="nobordernopadding centpercent"><tr><td>';
  368. print $langs->trans('Docdate');
  369. print '</td>';
  370. if ($action != 'editdate') {
  371. print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).'</a></td>';
  372. }
  373. print '</tr></table>';
  374. print '</td><td colspan="3">';
  375. if ($action == 'editdate') {
  376. print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
  377. if ($optioncss != '') {
  378. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  379. }
  380. print '<input type="hidden" name="token" value="'.newToken().'">';
  381. print '<input type="hidden" name="action" value="setdate">';
  382. print '<input type="hidden" name="mode" value="'.$mode.'">';
  383. print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
  384. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  385. print '</form>';
  386. } else {
  387. print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
  388. }
  389. print '</td>';
  390. print '</tr>';
  391. // Journal
  392. print '<tr><td>';
  393. print '<table class="nobordernopadding" width="100%"><tr><td>';
  394. print $langs->trans('Codejournal');
  395. print '</td>';
  396. if ($action != 'editjournal') {
  397. print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editjournal&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
  398. }
  399. print '</tr></table>';
  400. print '</td><td>';
  401. if ($action == 'editjournal') {
  402. print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
  403. if ($optioncss != '') {
  404. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  405. }
  406. print '<input type="hidden" name="token" value="'.newToken().'">';
  407. print '<input type="hidden" name="action" value="setjournal">';
  408. print '<input type="hidden" name="mode" value="'.$mode.'">';
  409. print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1);
  410. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  411. print '</form>';
  412. } else {
  413. print $object->code_journal;
  414. }
  415. print '</td>';
  416. print '</tr>';
  417. // Ref document
  418. print '<tr><td>';
  419. print '<table class="nobordernopadding" width="100%"><tr><td>';
  420. print $langs->trans('Piece');
  421. print '</td>';
  422. if ($action != 'editdocref') {
  423. print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
  424. }
  425. print '</tr></table>';
  426. print '</td><td>';
  427. if ($action == 'editdocref') {
  428. print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
  429. if ($optioncss != '') {
  430. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  431. }
  432. print '<input type="hidden" name="token" value="'.newToken().'">';
  433. print '<input type="hidden" name="action" value="setdocref">';
  434. print '<input type="hidden" name="mode" value="'.$mode.'">';
  435. print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
  436. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  437. print '</form>';
  438. } else {
  439. print $object->doc_ref;
  440. }
  441. print '</td>';
  442. print '</tr>';
  443. print '</table>';
  444. print '</div>';
  445. print '<div class="fichehalfright">';
  446. print '<div class="underbanner clearboth"></div>';
  447. print '<table class="border tableforfield centpercent">';
  448. // Doc type
  449. if (!empty($object->doc_type)) {
  450. print '<tr>';
  451. print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
  452. print '<td>'.$object->doc_type.'</td>';
  453. print '</tr>';
  454. }
  455. // Date document creation
  456. print '<tr>';
  457. print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  458. print '<td>';
  459. print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
  460. print '</td>';
  461. print '</tr>';
  462. // Date document creation
  463. print '<tr>';
  464. print '<td class="titlefield">'.$langs->trans("DateExport").'</td>';
  465. print '<td>';
  466. print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
  467. print '</td>';
  468. print '</tr>';
  469. // Date document creation
  470. print '<tr>';
  471. print '<td class="titlefield">'.$langs->trans("DateValidation").'</td>';
  472. print '<td>';
  473. print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
  474. print '</td>';
  475. print '</tr>';
  476. // Validate
  477. /*
  478. print '<tr>';
  479. print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
  480. print '<td>';
  481. if (empty($object->validated)) {
  482. print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
  483. print img_picto($langs->trans("Disabled"), 'switch_off');
  484. print '</a>';
  485. } else {
  486. print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
  487. print img_picto($langs->trans("Activated"), 'switch_on');
  488. print '</a>';
  489. }
  490. print '</td>';
  491. print '</tr>';
  492. */
  493. // check data
  494. /*
  495. print '<tr>';
  496. print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
  497. if ($object->doc_type == 'customer_invoice')
  498. {
  499. $sqlmid = 'SELECT rowid as ref';
  500. $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
  501. $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
  502. dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
  503. $resultmid = $db->query($sqlmid);
  504. if ($resultmid) {
  505. $objmid = $db->fetch_object($resultmid);
  506. $invoicestatic = new Facture($db);
  507. $invoicestatic->fetch($objmid->ref);
  508. $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
  509. }
  510. else dol_print_error($db);
  511. }
  512. print '<td>' . $ref .'</td>';
  513. print '</tr>';
  514. */
  515. print "</table>\n";
  516. print '</div>';
  517. print dol_get_fiche_end();
  518. print '<div style="clear:both"></div>';
  519. print '<br>';
  520. $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
  521. if ($result < 0) {
  522. setEventMessages($object->error, $object->errors, 'errors');
  523. } else {
  524. print load_fiche_titre($langs->trans("ListeMvts"), '', '');
  525. print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
  526. if ($optioncss != '') {
  527. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  528. }
  529. print '<input type="hidden" name="token" value="'.newToken().'">';
  530. print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
  531. print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
  532. print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
  533. print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
  534. print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
  535. print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
  536. print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
  537. if (count($object->linesmvt) > 0) {
  538. print '<div class="div-table-responsive-no-min">';
  539. print '<table class="noborder centpercent">';
  540. $total_debit = 0;
  541. $total_credit = 0;
  542. print '<tr class="liste_titre">';
  543. print_liste_field_titre("AccountAccountingShort");
  544. print_liste_field_titre("SubledgerAccount");
  545. print_liste_field_titre("LabelOperation");
  546. print_liste_field_titre("Debit", "", "", "", "", 'class="right"');
  547. print_liste_field_titre("Credit", "", "", "", "", 'class="right"');
  548. if (empty($object->date_validation)) {
  549. print_liste_field_titre("Action", "", "", "", "", 'width="60" class="center"');
  550. } else {
  551. print_liste_field_titre("");
  552. }
  553. print "</tr>\n";
  554. // Empty line is the first line of $object->linesmvt
  555. // So we must get the first line (the empty one) and put it at the end of the array
  556. // in order to display it correctly to the user
  557. $empty_line = array_shift($object->linesmvt);
  558. $object->linesmvt[]= $empty_line;
  559. foreach ($object->linesmvt as $line) {
  560. print '<tr class="oddeven">';
  561. $total_debit += $line->debit;
  562. $total_credit += $line->credit;
  563. if ($action == 'update' && $line->id == $id) {
  564. print '<!-- td columns in edit mode -->';
  565. print '<td>';
  566. print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, '');
  567. print '</td>';
  568. print '<td>';
  569. // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
  570. // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
  571. // Also, it is not possible to use a value that is not in the list.
  572. // Also, the label is not automatically filled when a value is selected.
  573. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  574. print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
  575. } else {
  576. 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")).'">';
  577. }
  578. // Add also input for subledger label
  579. 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")).'">';
  580. print '</td>';
  581. print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
  582. print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
  583. print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
  584. print '<td>';
  585. print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
  586. print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
  587. print '</td>';
  588. } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
  589. if ($action == "" || $action == 'add') {
  590. print '<!-- td columns in add mode -->';
  591. print '<td>';
  592. print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, '');
  593. print '</td>';
  594. print '<td>';
  595. // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
  596. // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
  597. // Also, it is not possible to use a value that is not in the list.
  598. // Also, the label is not automatically filled when a value is selected.
  599. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  600. print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
  601. } else {
  602. print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
  603. }
  604. print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
  605. print '</td>';
  606. print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $label_operation . '"/></td>';
  607. print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>';
  608. print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>';
  609. print '<td>';
  610. print '<input type="submit" class="button" name="save" value="' . $langs->trans("Add") . '">';
  611. print '</td>';
  612. }
  613. } else {
  614. print '<!-- td columns in display mode -->';
  615. $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true);
  616. print '<td>';
  617. if ($resultfetch > 0) {
  618. print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
  619. } else {
  620. print $line->numero_compte.' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
  621. }
  622. print '</td>';
  623. print '<td>'.length_accounta($line->subledger_account);
  624. if ($line->subledger_label) {
  625. print ' - <span class="opacitymedium">'.$line->subledger_label.'</span>';
  626. }
  627. print '</td>';
  628. print '<td>'.$line->label_operation.'</td>';
  629. print '<td class="right nowraponall amount">'.price($line->debit).'</td>';
  630. print '<td class="right nowraponall amount">'.price($line->credit).'</td>';
  631. print '<td class="center nowraponall">';
  632. if (empty($line->date_export) && empty($line->date_validation)) {
  633. 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()) . '">';
  634. print img_edit('', 0, 'class="marginrightonly"');
  635. print '</a> &nbsp;';
  636. } else {
  637. print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
  638. print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
  639. print '</a> &nbsp;';
  640. }
  641. if (empty($line->date_validation)) {
  642. $actiontodelete = 'delete';
  643. if ($mode == '_tmp' || $action != 'delmouv') {
  644. $actiontodelete = 'confirm_delete';
  645. }
  646. print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">';
  647. print img_delete();
  648. print '</a>';
  649. } else {
  650. print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
  651. print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
  652. print '</a>';
  653. }
  654. print '</td>';
  655. }
  656. print "</tr>\n";
  657. }
  658. $total_debit = price2num($total_debit, 'MT');
  659. $total_credit = price2num($total_credit, 'MT');
  660. if ($total_debit != $total_credit) {
  661. setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
  662. }
  663. print '</table>';
  664. print '</div>';
  665. if ($mode == '_tmp' && $action == '') {
  666. print '<br>';
  667. print '<div class="center">';
  668. if ($total_debit == $total_credit) {
  669. print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
  670. } else {
  671. 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")).'">';
  672. }
  673. print ' &nbsp; ';
  674. print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
  675. print "</div>";
  676. }
  677. }
  678. print '</form>';
  679. }
  680. } else {
  681. print load_fiche_titre($langs->trans("NoRecords"));
  682. }
  683. }
  684. print dol_get_fiche_end();
  685. // End of page
  686. llxFooter();
  687. $db->close();