expensereportsjournal.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?php
  2. /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007-2010 Jean Heimburger <jean@tiaris.info>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  7. * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  8. * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/accountancy/journal/expensereportsjournal.php
  25. * \ingroup Advanced accountancy
  26. * \brief Page with expense reports journal
  27. */
  28. require '../../main.inc.php';
  29. // Class
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  38. // Langs
  39. $langs->load("compta");
  40. $langs->load("bills");
  41. $langs->load("other");
  42. $langs->load("main");
  43. $langs->load("accountancy");
  44. $langs->load("trips");
  45. // Multi journal
  46. $id_journal = GETPOST('id_journal', 'int');
  47. $date_startmonth = GETPOST('date_startmonth');
  48. $date_startday = GETPOST('date_startday');
  49. $date_startyear = GETPOST('date_startyear');
  50. $date_endmonth = GETPOST('date_endmonth');
  51. $date_endday = GETPOST('date_endday');
  52. $date_endyear = GETPOST('date_endyear');
  53. $now = dol_now();
  54. // Security check
  55. if ($user->societe_id > 0)
  56. accessforbidden();
  57. $action = GETPOST('action','aZ09');
  58. /*
  59. * Actions
  60. */
  61. // Get code of finance journal
  62. $accountingjournalstatic = new AccountingJournal($db);
  63. $accountingjournalstatic->fetch($id_journal);
  64. $journal = $accountingjournalstatic->code;
  65. $year_current = strftime("%Y", dol_now());
  66. $pastmonth = strftime("%m", dol_now()) - 1;
  67. $pastmonthyear = $year_current;
  68. if ($pastmonth == 0) {
  69. $pastmonth = 12;
  70. $pastmonthyear --;
  71. }
  72. $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  73. $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  74. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  75. {
  76. $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
  77. $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
  78. }
  79. $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
  80. $idpays = $p[0];
  81. $sql = "SELECT er.rowid, er.ref, er.date_debut as de,";
  82. $sql .= " erd.rowid as erdid, erd.comments, erd.total_ttc, erd.tva_tx, erd.total_ht, erd.total_tva, erd.fk_code_ventilation,";
  83. $sql .= " u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,";
  84. $sql .= " f.accountancy_code, ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
  85. $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd";
  86. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON erd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
  87. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
  88. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
  89. $sql .= " JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport";
  90. $sql .= " JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = er.fk_user_author";
  91. $sql .= " WHERE er.fk_statut > 0 ";
  92. $sql .= " AND erd.fk_code_ventilation > 0 ";
  93. $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy
  94. if ($date_start && $date_end)
  95. $sql .= " AND er.date_debut >= '" . $db->idate($date_start) . "' AND er.date_debut <= '" . $db->idate($date_end) . "'";
  96. $sql .= " ORDER BY er.date_debut";
  97. dol_syslog('accountancy/journal/expensereportsjournal.php:: $sql=' . $sql);
  98. $result = $db->query($sql);
  99. if ($result) {
  100. $num = $db->num_rows($result);
  101. // les variables
  102. $account_salary = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : $langs->trans("CodeNotDef");
  103. $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef");
  104. $taber = array ();
  105. $tabht = array ();
  106. $tabtva = array ();
  107. $def_tva = array ();
  108. $tabttc = array ();
  109. $tabuser = array ();
  110. $i = 0;
  111. while ( $i < $num ) {
  112. $obj = $db->fetch_object($result);
  113. // Controls
  114. $compta_user = (! empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary;
  115. $compta_fees = $obj->compte;
  116. $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $account_vat);
  117. // Define array for display vat tx
  118. $def_tva[$obj->rowid]=price($obj->tva_tx);
  119. $taber[$obj->rowid]["date"] = $db->jdate($obj->de);
  120. $taber[$obj->rowid]["ref"] = $obj->ref;
  121. $taber[$obj->rowid]["comments"] = $obj->comments;
  122. $taber[$obj->rowid]["fk_expensereportdet"] = $obj->erdid;
  123. $tabttc[$obj->rowid][$compta_user] += $obj->total_ttc;
  124. $tabht[$obj->rowid][$compta_fees] += $obj->total_ht;
  125. $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
  126. $tabuser[$obj->rowid] = array (
  127. 'id' => $obj->uid,
  128. 'name' => $obj->firstname.' '.$obj->lastname,
  129. 'user_accountancy_code' => $obj->user_accountancy_account
  130. );
  131. $i ++;
  132. }
  133. } else {
  134. dol_print_error($db);
  135. }
  136. // Bookkeeping Write
  137. if ($action == 'writebookkeeping') {
  138. $now = dol_now();
  139. $error = 0;
  140. foreach ($taber as $key => $val)
  141. {
  142. $errorforline = 0;
  143. $db->begin();
  144. if (! $errorforline)
  145. {
  146. foreach ( $tabttc[$key] as $k => $mt ) {
  147. if ($mt) {
  148. // get compte id and label
  149. $bookkeeping = new BookKeeping($db);
  150. $bookkeeping->doc_date = $val["date"];
  151. $bookkeeping->doc_ref = $val["ref"];
  152. $bookkeeping->date_create = $now;
  153. $bookkeeping->doc_type = 'expense_report';
  154. $bookkeeping->fk_doc = $key;
  155. $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
  156. $bookkeeping->code_tiers = $tabuser[$key]['user_accountancy_code'];
  157. $bookkeeping->label_compte = $tabuser[$key]['name'];
  158. $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT;
  159. $bookkeeping->montant = $mt;
  160. $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
  161. $bookkeeping->debit = ($mt <= 0) ? $mt : 0;
  162. $bookkeeping->credit = ($mt > 0) ? $mt : 0;
  163. $bookkeeping->code_journal = $journal;
  164. $bookkeeping->fk_user_author = $user->id;
  165. $result = $bookkeeping->create($user);
  166. if ($result < 0) {
  167. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  168. {
  169. $error++;
  170. $errorforline++;
  171. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  172. }
  173. else
  174. {
  175. $error++;
  176. $errorforline++;
  177. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  178. }
  179. }
  180. }
  181. }
  182. }
  183. if (! $errorforline)
  184. {
  185. // Fees
  186. foreach ( $tabht[$key] as $k => $mt ) {
  187. $accountingaccount = new AccountingAccount($db);
  188. $accountingaccount->fetch(null, $k, true);
  189. if ($mt) {
  190. // get compte id and label
  191. $accountingaccount = new AccountingAccount($db);
  192. if ($accountingaccount->fetch(null, $k, true)) {
  193. $bookkeeping = new BookKeeping($db);
  194. $bookkeeping->doc_date = $val["date"];
  195. $bookkeeping->doc_ref = $val["ref"];
  196. $bookkeeping->date_create = $now;
  197. $bookkeeping->doc_type = 'expense_report';
  198. $bookkeeping->fk_doc = $key;
  199. $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
  200. $bookkeeping->code_tiers = '';
  201. $bookkeeping->label_compte = $accountingaccount->label;
  202. $bookkeeping->numero_compte = $k;
  203. $bookkeeping->montant = $mt;
  204. $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
  205. $bookkeeping->debit = ($mt > 0) ? $mt : 0;
  206. $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
  207. $bookkeeping->code_journal = $journal;
  208. $bookkeeping->fk_user_author = $user->id;
  209. $result = $bookkeeping->create($user);
  210. if ($result < 0) {
  211. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  212. {
  213. $error++;
  214. $errorforline++;
  215. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  216. }
  217. else
  218. {
  219. $error++;
  220. $errorforline++;
  221. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. if (! $errorforline)
  229. {
  230. // VAT
  231. // var_dump($tabtva);
  232. foreach ( $tabtva[$key] as $k => $mt ) {
  233. if ($mt) {
  234. // get compte id and label
  235. $bookkeeping = new BookKeeping($db);
  236. $bookkeeping->doc_date = $val["date"];
  237. $bookkeeping->doc_ref = $val["ref"];
  238. $bookkeeping->date_create = $now;
  239. $bookkeeping->doc_type = 'expense_report';
  240. $bookkeeping->fk_doc = $key;
  241. $bookkeeping->fk_docdet = $val["fk_expensereportdet"];
  242. $bookkeeping->code_tiers = '';
  243. $bookkeeping->label_compte = $langs->trans("VAT"). ' '.$def_tva[$key];
  244. $bookkeeping->numero_compte = $k;
  245. $bookkeeping->montant = $mt;
  246. $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
  247. $bookkeeping->debit = ($mt > 0) ? $mt : 0;
  248. $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
  249. $bookkeeping->code_journal = $journal;
  250. $bookkeeping->fk_user_author = $user->id;
  251. $result = $bookkeeping->create($user);
  252. if ($result < 0) {
  253. if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
  254. {
  255. $error++;
  256. $errorforline++;
  257. //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
  258. }
  259. else
  260. {
  261. $error++;
  262. $errorforline++;
  263. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  264. }
  265. }
  266. }
  267. }
  268. }
  269. if (! $errorforline)
  270. {
  271. $db->commit();
  272. }
  273. else
  274. {
  275. $db->rollback();
  276. }
  277. }
  278. if (empty($error) && count($tabpay)) {
  279. setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
  280. }
  281. elseif (count($tabpay) == $error)
  282. {
  283. setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
  284. }
  285. else
  286. {
  287. setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
  288. }
  289. $action='';
  290. }
  291. /*
  292. * View
  293. */
  294. $form = new Form($db);
  295. $userstatic = new User($db);
  296. // Export
  297. /*if ($action == 'export_csv') {
  298. $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  299. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  300. // Model Cegid Expert Export
  301. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
  302. $sep = ";";
  303. foreach ( $taber as $key => $val ) {
  304. $date = dol_print_date($val["date"], '%d%m%Y');
  305. // Fees
  306. foreach ( $tabht[$key] as $k => $mt ) {
  307. $userstatic->id = $tabuser[$key]['id'];
  308. $userstatic->name = $tabuser[$key]['name'];
  309. $userstatic->client = $tabuser[$key]['code_client'];
  310. if ($mt) {
  311. print $date . $sep;
  312. print $journal . $sep;
  313. print length_accountg(html_entity_decode($k)) . $sep;
  314. print $sep;
  315. print ($mt < 0 ? 'C' : 'D') . $sep;
  316. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  317. print dol_trunc($val["comments"], 32) . $sep;
  318. print $val["ref"];
  319. print "\n";
  320. }
  321. }
  322. // VAT
  323. foreach ( $tabtva[$key] as $k => $mt ) {
  324. if ($mt) {
  325. print $date . $sep;
  326. print $journal . $sep;
  327. print length_accountg(html_entity_decode($k)) . $sep;
  328. print $sep;
  329. print ($mt < 0 ? 'C' : 'D') . $sep;
  330. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  331. print $langs->trans("VAT") . $sep;
  332. print $val["ref"];
  333. print "\n";
  334. }
  335. }
  336. foreach ( $tabttc[$key] as $k => $mt ) {
  337. print $date . $sep;
  338. print $journal . $sep;
  339. print length_accountg($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) . $sep;
  340. print length_accounta(html_entity_decode($k)) . $sep;
  341. print ($mt < 0 ? 'D' : 'C') . $sep;
  342. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  343. print $userstatic->name . $sep;
  344. print $val["ref"];
  345. print "\n";
  346. }
  347. }
  348. } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
  349. // Model Classic Export
  350. foreach ( $taber as $key => $val ) {
  351. $date = dol_print_date($val["date"], 'day');
  352. $userstatic->id = $tabuser[$key]['id'];
  353. $userstatic->name = $tabuser[$key]['name'];
  354. // Fees
  355. foreach ( $tabht[$key] as $k => $mt ) {
  356. $accountingaccount = new AccountingAccount($db);
  357. $accountingaccount->fetch(null, $k, true);
  358. if ($mt) {
  359. print '"' . $date . '"' . $sep;
  360. print '"' . $val["ref"] . '"' . $sep;
  361. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  362. print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
  363. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  364. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  365. print "\n";
  366. }
  367. }
  368. // VAT
  369. foreach ( $tabtva[$key] as $k => $mt ) {
  370. if ($mt) {
  371. print '"' . $date . '"' . $sep;
  372. print '"' . $val["ref"] . '"' . $sep;
  373. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  374. print '"' . dol_trunc($langs->trans("VAT")) . '"' . $sep;
  375. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  376. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  377. print "\n";
  378. }
  379. }
  380. // Third party
  381. foreach ( $tabttc[$key] as $k => $mt ) {
  382. print '"' . $date . '"' . $sep;
  383. print '"' . $val["ref"] . '"' . $sep;
  384. print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
  385. print '"' . dol_trunc($userstatic->name) . '"' . $sep;
  386. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  387. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  388. }
  389. print "\n";
  390. }
  391. }
  392. }
  393. */
  394. if (empty($action) || $action == 'view') {
  395. llxHeader('', $langs->trans("ExpenseReportsJournal"));
  396. $nom = $langs->trans("ExpenseReportsJournal");
  397. $nomlink = '';
  398. $periodlink = '';
  399. $exportlink = '';
  400. $builddate = time();
  401. $description.= $langs->trans("DescJournalOnlyBindedVisible").'<br>';
  402. $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
  403. $varlink = 'id_journal=' . $id_journal;
  404. journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
  405. /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
  406. print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabled="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
  407. } else {
  408. print '<input type="button" class="butAction" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
  409. }*/
  410. print '<div class="tabsAction">';
  411. print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
  412. print '</div>';
  413. print '
  414. <script type="text/javascript">
  415. function launch_export() {
  416. $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
  417. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  418. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  419. }
  420. function writebookkeeping() {
  421. $("div.fiche div.tabBar form input[name=\"action\"]").val("writebookkeeping");
  422. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  423. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  424. }
  425. </script>';
  426. /*
  427. * Show result array
  428. */
  429. print '<br>';
  430. $i = 0;
  431. print "<table class=\"noborder\" width=\"100%\">";
  432. print "<tr class=\"liste_titre\">";
  433. print "<td></td>";
  434. print "<td>" . $langs->trans("Date") . "</td>";
  435. print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("ExpenseReportRef") . ")</td>";
  436. print "<td>" . $langs->trans("Account") . "</td>";
  437. print "<td>" . $langs->trans("Label") . "</td>";
  438. print "<td align='right'>" . $langs->trans("Debit") . "</td>";
  439. print "<td align='right'>" . $langs->trans("Credit") . "</td>";
  440. print "</tr>\n";
  441. $r = '';
  442. $expensereportstatic = new ExpenseReport($db);
  443. $expensereportlinestatic = new ExpenseReportLine($db);
  444. foreach ( $taber as $key => $val ) {
  445. $expensereportstatic->id = $key;
  446. $expensereportstatic->ref = $val["ref"];
  447. $expensereportlinestatic->comments = html_entity_decode(dol_trunc($val["comments"], 32));
  448. $date = dol_print_date($val["date"], 'day');
  449. // Fees
  450. foreach ( $tabht[$key] as $k => $mt ) {
  451. $accountingaccount = new AccountingAccount($db);
  452. $accountingaccount->fetch(null, $k, true);
  453. if ($mt) {
  454. print '<tr class="oddeven">';
  455. print "<td><!-- Fees --></td>";
  456. print "<td>" . $date . "</td>";
  457. print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
  458. $userstatic->id = $tabuser[$key]['id'];
  459. $userstatic->name = $tabuser[$key]['name'];
  460. print "<td>";
  461. $accountoshow = length_accountg($k);
  462. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  463. {
  464. print '<span class="error">'.$langs->trans("FeeAccountNotDefined").'</span>';
  465. }
  466. else print $accountoshow;
  467. print "</td>";
  468. $userstatic->id = $tabuser[$key]['id'];
  469. $userstatic->name = $tabuser[$key]['name'];
  470. print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $accountingaccount->label . "</td>";
  471. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  472. print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
  473. print "</tr>";
  474. }
  475. }
  476. // VAT
  477. foreach ( $tabtva[$key] as $k => $mt ) {
  478. if ($mt) {
  479. print '<tr class="oddeven">';
  480. print "<td><!-- VAT --></td>";
  481. print "<td>" . $date . "</td>";
  482. print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
  483. print "<td>";
  484. $accountoshow = length_accountg($k);
  485. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  486. {
  487. print '<span class="error">'.$langs->trans("VatAccountNotDefined").'</span>';
  488. }
  489. else print $accountoshow;
  490. print "</td>";
  491. print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]. "</td>";
  492. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  493. print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
  494. print "</tr>";
  495. }
  496. }
  497. // Third party
  498. foreach ( $tabttc[$key] as $k => $mt ) {
  499. print '<tr class="oddeven">';
  500. print "<td><!-- Thirdparty --></td>";
  501. print "<td>" . $date . "</td>";
  502. print "<td>" . $expensereportstatic->getNomUrl(1) . "</td>";
  503. $userstatic->id = $tabuser[$key]['id'];
  504. $userstatic->name = $tabuser[$key]['name'];
  505. print "<td>";
  506. $accountoshow = length_accounta($k);
  507. if (empty($accountoshow) || $accountoshow == 'NotDefined')
  508. {
  509. print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
  510. }
  511. else print $accountoshow;
  512. print "</td>";
  513. print "<td>" . $userstatic->getNomUrl(0, 'user', 16) . ' - ' . $langs->trans("Code_tiers") . "</td>";
  514. print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
  515. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  516. print "</tr>";
  517. }
  518. }
  519. print "</table>";
  520. // End of page
  521. llxFooter();
  522. }
  523. $db->close();