purchasesjournal.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.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/purchasesjournal.php
  25. * \ingroup Advanced accountancy
  26. * \brief Page with purchases 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 . '/fourn/class/fournisseur.facture.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  37. // Langs
  38. $langs->load("compta");
  39. $langs->load("bills");
  40. $langs->load("other");
  41. $langs->load("main");
  42. $langs->load("accountancy");
  43. $date_startmonth = GETPOST('date_startmonth');
  44. $date_startday = GETPOST('date_startday');
  45. $date_startyear = GETPOST('date_startyear');
  46. $date_endmonth = GETPOST('date_endmonth');
  47. $date_endday = GETPOST('date_endday');
  48. $date_endyear = GETPOST('date_endyear');
  49. $now = dol_now();
  50. // Security check
  51. if ($user->societe_id > 0)
  52. accessforbidden();
  53. $action = GETPOST('action');
  54. /*
  55. * Actions
  56. */
  57. $year_current = strftime("%Y", dol_now());
  58. $pastmonth = strftime("%m", dol_now()) - 1;
  59. $pastmonthyear = $year_current;
  60. if ($pastmonth == 0) {
  61. $pastmonth = 12;
  62. $pastmonthyear --;
  63. }
  64. $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
  65. $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
  66. if (empty($date_start) || empty($date_end)) // We define date_start and date_end
  67. {
  68. $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
  69. $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
  70. }
  71. $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
  72. $idpays = $p[0];
  73. $sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.libelle,f.ref_supplier,";
  74. $sql .= " fd.rowid as fdid, fd.description, fd.total_ttc, fd.tva_tx, fd.total_ht, fd.tva as total_tva, fd.product_type,";
  75. $sql .= " s.rowid as socid, s.nom as name, s.code_compta_fournisseur, s.fournisseur,";
  76. $sql .= " s.code_compta_fournisseur, p.accountancy_code_buy , ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte";
  77. $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
  78. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
  79. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_product";
  80. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation";
  81. $sql .= " JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
  82. $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
  83. $sql .= " WHERE f.fk_statut > 0 ";
  84. $sql .= " AND fd.fk_code_ventilation > 0 ";
  85. if (! empty($conf->multicompany->enabled)) {
  86. $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 1) . ")";
  87. }
  88. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
  89. $sql .= " AND f.type IN (0,1,2)";
  90. else
  91. $sql .= " AND f.type IN (0,1,2,3)";
  92. if ($date_start && $date_end)
  93. $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
  94. $sql .= " ORDER BY f.datef";
  95. dol_syslog('accountancy/journal/purchasesjournal.php:: $sql=' . $sql);
  96. $result = $db->query($sql);
  97. if ($result) {
  98. $num = $db->num_rows($result);
  99. // les variables
  100. $cptfour = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER)) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef");
  101. $cpttva = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef");
  102. $tabfac = array ();
  103. $tabht = array ();
  104. $tabtva = array ();
  105. $def_tva = array ();
  106. $tabttc = array ();
  107. $tabcompany = array ();
  108. $i = 0;
  109. while ( $i < $num ) {
  110. $obj = $db->fetch_object($result);
  111. // contrôles
  112. $compta_soc = (! empty($obj->code_compta_fournisseur)) ? $obj->code_compta_fournisseur : $cptfour;
  113. $compta_prod = $obj->compte;
  114. if (empty($compta_prod)) {
  115. if ($obj->product_type == 0)
  116. $compta_prod = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef");
  117. else
  118. $compta_prod = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef");
  119. }
  120. $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva);
  121. //Define array for display vat tx
  122. $def_tva[$obj->rowid]=price($obj->tva_tx);
  123. $tabfac[$obj->rowid]["date"] = $obj->df;
  124. $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')';
  125. $tabfac[$obj->rowid]["refsologest"] = $obj->ref;
  126. $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier;
  127. $tabfac[$obj->rowid]["type"] = $obj->type;
  128. $tabfac[$obj->rowid]["description"] = $obj->description;
  129. $tabfac[$obj->rowid]["fk_facturefourndet"] = $obj->fdid;
  130. $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
  131. $tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
  132. $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
  133. $tabcompany[$obj->rowid] = array (
  134. 'id' => $obj->socid,
  135. 'name' => $obj->name,
  136. 'code_fournisseur' => $obj->code_compta_fournisseur
  137. );
  138. $i ++;
  139. }
  140. } else {
  141. dol_print_error($db);
  142. }
  143. // Bookkeeping Write
  144. if ($action == 'writebookkeeping') {
  145. $now = dol_now();
  146. $error = 0;
  147. foreach ($tabfac as $key => $val)
  148. {
  149. $companystatic = new Societe($db);
  150. $invoicestatic = new FactureFournisseur($db);
  151. $invoicestatic->id = $key;
  152. $invoicestatic->ref = (string) $val["refsologest"];
  153. $invoicestatic->refsupplier = $val["refsuppliersologest"];
  154. $invoicestatic->type = $val["type"];
  155. $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
  156. $companystatic->id = $tabcompany[$key]['id'];
  157. $companystatic->name = $tabcompany[$key]['name'];
  158. $companystatic->client = $tabcompany[$key]['code_client'];
  159. foreach ( $tabttc[$key] as $k => $mt ) {
  160. // get compte id and label
  161. $bookkeeping = new BookKeeping($db);
  162. $bookkeeping->doc_date = $val["date"];
  163. $bookkeeping->doc_ref = $val["ref"];
  164. $bookkeeping->date_create = $now;
  165. $bookkeeping->doc_type = 'supplier_invoice';
  166. $bookkeeping->fk_doc = $key;
  167. $bookkeeping->fk_docdet = $val["fk_facturefourndet"];
  168. $bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur'];
  169. $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers");
  170. $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
  171. $bookkeeping->montant = $mt;
  172. $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
  173. $bookkeeping->debit = ($mt <= 0) ? $mt : 0;
  174. $bookkeeping->credit = ($mt > 0) ? $mt : 0;
  175. $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
  176. $bookkeeping->fk_user_author = $user->id;
  177. $result = $bookkeeping->create($user);
  178. if ($result < 0) {
  179. $error ++;
  180. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  181. }
  182. }
  183. // Product / Service
  184. foreach ( $tabht[$key] as $k => $mt ) {
  185. $accountingaccount = new AccountingAccount($db);
  186. $accountingaccount->fetch(null, $k);
  187. if ($mt) {
  188. // get compte id and label
  189. $accountingaccount = new AccountingAccount($db);
  190. if ($accountingaccount->fetch(null, $k)) {
  191. $bookkeeping = new BookKeeping($db);
  192. $bookkeeping->doc_date = $val["date"];
  193. $bookkeeping->doc_ref = $val["ref"];
  194. $bookkeeping->date_create = $now;
  195. $bookkeeping->doc_type = 'supplier_invoice';
  196. $bookkeeping->fk_doc = $key;
  197. $bookkeeping->fk_docdet = $val["fk_facturefourndet"];
  198. $bookkeeping->code_tiers = '';
  199. $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . utf8_decode($accountingaccount->label);
  200. $bookkeeping->numero_compte = $k;
  201. $bookkeeping->montant = $mt;
  202. $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
  203. $bookkeeping->debit = ($mt > 0) ? $mt : 0;
  204. $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
  205. $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
  206. $bookkeeping->fk_user_author = $user->id;
  207. $result = $bookkeeping->create($user);
  208. if ($result < 0) {
  209. $error ++;
  210. setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
  211. }
  212. }
  213. }
  214. }
  215. // VAT
  216. // var_dump($tabtva);
  217. foreach ( $tabtva[$key] as $k => $mt ) {
  218. if ($mt) {
  219. // get compte id and label
  220. $bookkeeping = new BookKeeping($db);
  221. $bookkeeping->doc_date = $val["date"];
  222. $bookkeeping->doc_ref = $val["ref"];
  223. $bookkeeping->date_create = $now;
  224. $bookkeeping->doc_type = 'supplier_invoice';
  225. $bookkeeping->fk_doc = $key;
  226. $bookkeeping->fk_docdet = $val["fk_facturefourndet"];
  227. $bookkeeping->code_tiers = '';
  228. $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key];
  229. $bookkeeping->numero_compte = $k;
  230. $bookkeeping->montant = $mt;
  231. $bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
  232. $bookkeeping->debit = ($mt > 0) ? $mt : 0;
  233. $bookkeeping->credit = ($mt <= 0) ? $mt : 0;
  234. $bookkeeping->code_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
  235. $bookkeeping->fk_user_author = $user->id;
  236. $result = $bookkeeping->create($user);
  237. if ($result < 0) {
  238. $error ++;
  239. setEventMessages($object->error, $object->errors, 'errors');
  240. }
  241. }
  242. }
  243. }
  244. if (empty($error)) {
  245. setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
  246. }
  247. }
  248. /*
  249. * View
  250. */
  251. $companystatic = new Fournisseur($db);
  252. // Export
  253. if ($action == 'export_csv') {
  254. $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  255. $journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
  256. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  257. // Model Cegid Expert Export
  258. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
  259. $sep = ";";
  260. foreach ( $tabfac as $key => $val ) {
  261. $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
  262. // Product / Service
  263. foreach ( $tabht[$key] as $k => $mt ) {
  264. $companystatic->id = $tabcompany[$key]['id'];
  265. $companystatic->name = $tabcompany[$key]['name'];
  266. $companystatic->client = $tabcompany[$key]['code_client'];
  267. if ($mt) {
  268. print $date . $sep;
  269. print $purchase_journal . $sep;
  270. print length_accountg(html_entity_decode($k)) . $sep;
  271. print $sep;
  272. print ($mt < 0 ? 'C' : 'D') . $sep;
  273. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  274. print dol_trunc($val["description"], 32) . $sep;
  275. print $val["ref"];
  276. print "\n";
  277. }
  278. }
  279. // VAT
  280. foreach ( $tabtva[$key] as $k => $mt ) {
  281. if ($mt) {
  282. print $date . $sep;
  283. print $purchase_journal . $sep;
  284. print length_accountg(html_entity_decode($k)) . $sep;
  285. print $sep;
  286. print ($mt < 0 ? 'C' : 'D') . $sep;
  287. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  288. print $langs->trans("VAT") . $sep;
  289. print $val["ref"];
  290. print "\n";
  291. }
  292. }
  293. foreach ( $tabttc[$key] as $k => $mt ) {
  294. print $date . $sep;
  295. print $purchase_journal . $sep;
  296. print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
  297. print length_accounta(html_entity_decode($k)) . $sep;
  298. print ($mt < 0 ? 'D' : 'C') . $sep;
  299. print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
  300. print utf8_decode($companystatic->name) . $sep;
  301. print $val["ref"];
  302. print "\n";
  303. }
  304. }
  305. } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
  306. // Model Classic Export
  307. foreach ( $tabfac as $key => $val ) {
  308. $invoicestatic->id = $key;
  309. $invoicestatic->ref = $val["ref"];
  310. $invoicestatic->ref = $val["refsologest"];
  311. $invoicestatic->refsupplier = $val["refsuppliersologest"];
  312. $invoicestatic->type = $val["type"];
  313. $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
  314. $date = dol_print_date($db->jdate($val["date"]), 'day');
  315. $companystatic->id = $tabcompany[$key]['id'];
  316. $companystatic->name = $tabcompany[$key]['name'];
  317. $companystatic->client = $tabcompany[$key]['code_client'];
  318. // Product / Service
  319. foreach ( $tabht[$key] as $k => $mt ) {
  320. $accountingaccount = new AccountingAccount($db);
  321. $accountingaccount->fetch(null, $k);
  322. if ($mt) {
  323. print '"' . $date . '"' . $sep;
  324. print '"' . $val["ref"] . '"' . $sep;
  325. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  326. print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep;
  327. // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
  328. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  329. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  330. print "\n";
  331. }
  332. }
  333. // VAT
  334. foreach ( $tabtva[$key] as $k => $mt ) {
  335. if ($mt) {
  336. print '"' . $date . '"' . $sep;
  337. print '"' . $val["ref"] . '"' . $sep;
  338. print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
  339. // print '"' . $langs->trans("VAT") . '"' . $sep;
  340. print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep;
  341. print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
  342. print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
  343. print "\n";
  344. }
  345. }
  346. // Third party
  347. foreach ( $tabttc[$key] as $k => $mt ) {
  348. print '"' . $date . '"' . $sep;
  349. print '"' . $val["ref"] . '"' . $sep;
  350. print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
  351. // print '"' . utf8_decode($companystatic->name) . '"' . $sep;
  352. print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
  353. print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
  354. print '"' . ($mt >= 0 ? price($mt) : '') . '"';
  355. }
  356. print "\n";
  357. }
  358. }
  359. } else {
  360. llxHeader('', $langs->trans("PurchasesJournal"));
  361. $form = new Form($db);
  362. $nom = $langs->trans("PurchasesJournal");
  363. $nomlink = '';
  364. $periodlink = '';
  365. $exportlink = '';
  366. $builddate = time();
  367. $description = $langs->trans("DescPurchasesJournal") . '<br>';
  368. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  369. $description .= $langs->trans("DepositsAreNotIncluded");
  370. } else {
  371. $description .= $langs->trans("DepositsAreIncluded");
  372. }
  373. $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);
  374. report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
  375. 'action' => ''
  376. ));
  377. if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 || $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
  378. print '<input type="button" class="butActionRefused" style="float: right;" value="' . $langs->trans("Export") . '" disabeld="disabled" title="' . $langs->trans('ExportNotSupported') . '"/>';
  379. } else {
  380. print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
  381. }
  382. print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
  383. print '
  384. <script type="text/javascript">
  385. function launch_export() {
  386. $("div.fiche div.tabBar form input[name=\"action\"]").val("export_csv");
  387. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  388. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  389. }
  390. function writebookkeeping() {
  391. $("div.fiche div.tabBar form input[name=\"action\"]").val("writebookkeeping");
  392. $("div.fiche div.tabBar form input[type=\"submit\"]").click();
  393. $("div.fiche div.tabBar form input[name=\"action\"]").val("");
  394. }
  395. </script>';
  396. /*
  397. * Show result array
  398. */
  399. print '<br><br>';
  400. $i = 0;
  401. print "<table class=\"noborder\" width=\"100%\">";
  402. print "<tr class=\"liste_titre\">";
  403. // /print "<td>".$langs->trans("JournalNum")."</td>";
  404. print "<td>" . $langs->trans("Date") . "</td>";
  405. print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
  406. print "<td>" . $langs->trans("Account") . "</td>";
  407. print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>";
  408. print "</tr>\n";
  409. $var = true;
  410. $r = '';
  411. $invoicestatic = new FactureFournisseur($db);
  412. foreach ( $tabfac as $key => $val ) {
  413. $invoicestatic->id = $key;
  414. $invoicestatic->ref = $val["ref"];
  415. $invoicestatic->ref = $val["refsologest"];
  416. $invoicestatic->refsupplier = $val["refsuppliersologest"];
  417. $invoicestatic->type = $val["type"];
  418. $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
  419. $date = dol_print_date($db->jdate($val["date"]), 'day');
  420. // Product / Service
  421. foreach ( $tabht[$key] as $k => $mt ) {
  422. $accountingaccount = new AccountingAccount($db);
  423. $accountingaccount->fetch(null, $k);
  424. if ($mt) {
  425. print "<tr " . $bc[$var] . " >";
  426. print "<td>" . $date . "</td>";
  427. print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
  428. print "<td>" . length_accountg($k) . "</td>";
  429. $companystatic->id = $tabcompany[$key]['id'];
  430. $companystatic->name = $tabcompany[$key]['name'];
  431. print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label . "</td>";
  432. // print "<td>" . $accountingaccount->label . "</td>";
  433. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  434. print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
  435. print "</tr>";
  436. }
  437. }
  438. // VAT
  439. foreach ( $tabtva[$key] as $k => $mt ) {
  440. if ($mt) {
  441. print "<tr " . $bc[$var] . " >";
  442. print "<td>" . $date . "</td>";
  443. print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
  444. print "<td>" . length_accountg($k) . "</td>";
  445. print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]. "</td>";
  446. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  447. print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
  448. print "</tr>";
  449. }
  450. }
  451. print "<tr " . $bc[$var] . ">";
  452. // Third party
  453. foreach ( $tabttc[$key] as $k => $mt ) {
  454. print "<td>" . $date . "</td>";
  455. print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
  456. $companystatic->id = $tabcompany[$key]['id'];
  457. $companystatic->name = $tabcompany[$key]['name'];
  458. print "<td>" . length_accounta($k) . "</td>";
  459. print "<td>" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers") . "</td>";
  460. // print "</td><td>" . $langs->trans("ThirdParty");
  461. // print ' (' . $companystatic->getNomUrl(0, 'supplier', 16) . ')';
  462. // print "</td>";
  463. print '<td align="right">' . ($mt < 0 ? - price(- $mt) : '') . "</td>";
  464. print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
  465. }
  466. print "</tr>";
  467. $var = ! $var;
  468. }
  469. print "</table>";
  470. // End of page
  471. llxFooter();
  472. }
  473. $db->close();