card.php 26 KB

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