card.php 24 KB

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