card.php 30 KB

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