accounting-files.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2017 Pierre-Henry Favre <support@atm-consulting.fr>
  5. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  7. * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/accounting-files.php
  24. * \ingroup compta
  25. * \brief Page to show portoflio and files of a thirdparty and download it
  26. */
  27. if ((array_key_exists('action', $_GET) && $_GET['action'] == 'dl') || (array_key_exists('action', $_POST) && $_POST['action'] == 'dl')) { // To not replace token when downloading file
  28. if (!defined('NOTOKENRENEWAL')) {
  29. define('NOTOKENRENEWAL', '1');
  30. }
  31. }
  32. // Load Dolibarr environment
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
  48. if (isModEnabled('project')) {
  49. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  51. }
  52. // Constant to define payment sens
  53. const PAY_DEBIT = 0;
  54. const PAY_CREDIT = 1;
  55. $langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks", "loan"));
  56. $date_start = GETPOST('date_start', 'alpha');
  57. $date_startDay = GETPOST('date_startday', 'int');
  58. $date_startMonth = GETPOST('date_startmonth', 'int');
  59. $date_startYear = GETPOST('date_startyear', 'int');
  60. $date_start = dol_mktime(0, 0, 0, $date_startMonth, $date_startDay, $date_startYear, 'tzuserrel');
  61. $date_stop = GETPOST('date_stop', 'alpha');
  62. $date_stopDay = GETPOST('date_stopday', 'int');
  63. $date_stopMonth = GETPOST('date_stopmonth', 'int');
  64. $date_stopYear = GETPOST('date_stopyear', 'int');
  65. $date_stop = dol_mktime(23, 59, 59, $date_stopMonth, $date_stopDay, $date_stopYear, 'tzuserrel');
  66. $action = GETPOST('action', 'aZ09');
  67. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0);
  68. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  69. $hookmanager->initHooks(array('comptafileslist', 'globallist'));
  70. // Load variable for pagination
  71. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  72. $sortfield = GETPOST('sortfield', 'aZ09comma');
  73. $sortorder = GETPOST('sortorder', 'aZ09comma');
  74. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  75. if (empty($page) || $page == -1) {
  76. $page = 0;
  77. } // If $page is not defined, or '' or -1
  78. $offset = $limit * $page;
  79. $pageprev = $page - 1;
  80. $pagenext = $page + 1;
  81. if (!$sortfield) {
  82. $sortfield = "date,item"; // Set here default search field
  83. }
  84. if (!$sortorder) {
  85. $sortorder = "DESC";
  86. }
  87. $arrayfields = array(
  88. 'type'=>array('label'=>"Type", 'checked'=>1),
  89. 'date'=>array('label'=>"Date", 'checked'=>1),
  90. 'date_due'=>array('label'=>"DateDue", 'checked'=>1),
  91. 'ref'=>array('label'=>"Ref", 'checked'=>1),
  92. 'documents'=>array('label'=>"Documents", 'checked'=>1),
  93. 'paid'=>array('label'=>"Paid", 'checked'=>1),
  94. 'total_ht'=>array('label'=>"TotalHT", 'checked'=>1),
  95. 'total_ttc'=>array('label'=>"TotalTTC", 'checked'=>1),
  96. 'total_vat'=>array('label'=>"TotalVAT", 'checked'=>1),
  97. //...
  98. );
  99. // Security check
  100. if (!isModEnabled('comptabilite') && !isModEnabled('accounting')) {
  101. accessforbidden();
  102. }
  103. if ($user->socid > 0) {
  104. accessforbidden();
  105. }
  106. // Define $arrayofentities if multientity is set.
  107. $arrayofentities = array();
  108. if (isModEnabled('multicompany') && is_object($mc)) {
  109. $arrayofentities = $mc->getEntitiesList();
  110. }
  111. $entity = (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : (GETPOSTISSET('search_entity') ? GETPOST('search_entity', 'int') : $conf->entity));
  112. if (isModEnabled('multicompany') && is_object($mc)) {
  113. if (empty($entity) && !empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES)) {
  114. $entity = '0,'.join(',', array_keys($arrayofentities));
  115. }
  116. }
  117. if (empty($entity)) {
  118. $entity = $conf->entity;
  119. }
  120. $error = 0;
  121. $listofchoices = array(
  122. 'selectinvoices'=>array('label'=>'Invoices', 'picto'=>'bill', 'lang'=>'bills', 'enabled' => isModEnabled('facture'), 'perms' => $user->hasRight('facture', 'lire')),
  123. 'selectsupplierinvoices'=>array('label'=>'BillsSuppliers', 'picto'=>'supplier_invoice', 'lang'=>'bills', 'enabled' => isModEnabled('supplier_invoice'), 'perms' => !empty($user->rights->fournisseur->facture->lire)),
  124. 'selectexpensereports'=>array('label'=>'ExpenseReports', 'picto'=>'expensereport', 'lang'=>'trips', 'enabled' => isModEnabled('expensereport'), 'perms' => !empty($user->rights->expensereport->lire)),
  125. 'selectdonations'=>array('label'=>'Donations', 'picto'=>'donation', 'lang'=>'donation', 'enabled' => isModEnabled('don'), 'perms' => !empty($user->rights->don->lire)),
  126. 'selectsocialcontributions'=>array('label'=>'SocialContributions', 'picto'=>'bill', 'enabled' => isModEnabled('tax'), 'perms' => !empty($user->rights->tax->charges->lire)),
  127. 'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'picto'=>'salary', 'lang'=>'salaries', 'enabled' => isModEnabled('salaries'), 'perms' => !empty($user->rights->salaries->read)),
  128. 'selectvariouspayment'=>array('label'=>'VariousPayment', 'picto'=>'payment', 'enabled' => isModEnabled('banque'), 'perms' => !empty($user->rights->banque->lire)),
  129. 'selectloanspayment'=>array('label'=>'PaymentLoan','picto'=>'loan', 'enabled' => isModEnabled('don'), 'perms' => !empty($user->rights->loan->read)),
  130. );
  131. /*
  132. * Actions
  133. */
  134. //$parameters = array('socid' => $id);
  135. //$reshook = $hookmanager->executeHooks('doActions', $parameters, $object); // Note that $object may have been modified by some hooks
  136. //if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  137. $filesarray = array();
  138. $result = false;
  139. if (($action == 'searchfiles' || $action == 'dl')) {
  140. if (empty($date_start)) {
  141. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateStart")), null, 'errors');
  142. $error++;
  143. }
  144. if (empty($date_stop)) {
  145. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
  146. $error++;
  147. }
  148. if (!$error) {
  149. $sql = '';
  150. $wheretail = " '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'";
  151. // Customer invoices
  152. if (GETPOST('selectinvoices') && !empty($listofchoices['selectinvoices']['perms'])) {
  153. if (!empty($sql)) {
  154. $sql .= " UNION ALL";
  155. }
  156. $sql .= "SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
  157. $sql .= " t.localtax1, t.localtax2, t.revenuestamp,";
  158. $sql .= " t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'Invoice' as item, s.nom as thirdparty_name, s.code_client as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, ".PAY_CREDIT." as sens";
  159. $sql .= " FROM ".MAIN_DB_PREFIX."facture as t LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
  160. $sql .= " WHERE datef between ".$wheretail;
  161. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  162. $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT;
  163. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  164. }
  165. // Vendor invoices
  166. if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) {
  167. if (!empty($sql)) {
  168. $sql .= " UNION ALL";
  169. }
  170. $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
  171. $sql .= " t.localtax1, t.localtax2, 0 as revenuestamp,";
  172. $sql .= " t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'SupplierInvoice' as item, s.nom as thirdparty_name, s.code_fournisseur as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, ".PAY_DEBIT." as sens";
  173. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as t LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
  174. $sql .= " WHERE datef between ".$wheretail;
  175. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  176. $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT;
  177. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  178. }
  179. // Expense reports
  180. if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) && empty($projectid)) {
  181. if (!empty($sql)) {
  182. $sql .= " UNION ALL";
  183. }
  184. $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
  185. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  186. $sql .= " t.multicurrency_code as currency, t.fk_user_author as fk_soc, t.date_fin as date, t.date_fin as date_due, 'ExpenseReport' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
  187. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user_author LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country";
  188. $sql .= " WHERE date_fin between ".$wheretail;
  189. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  190. $sql .= " AND t.fk_statut <> ".ExpenseReport::STATUS_DRAFT;
  191. }
  192. // Donations
  193. if (GETPOST('selectdonations') && !empty($listofchoices['selectdonations']['perms'])) {
  194. if (!empty($sql)) {
  195. $sql .= " UNION ALL";
  196. }
  197. $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat,";
  198. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  199. $sql .= " '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datedon as date, t.datedon as date_due, 'Donation' as item, t.societe as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_CREDIT." as sens";
  200. $sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country";
  201. $sql .= " WHERE datedon between ".$wheretail;
  202. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  203. $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT;
  204. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  205. }
  206. // Payments of salaries
  207. if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) {
  208. if (!empty($sql)) {
  209. $sql .= " UNION ALL";
  210. }
  211. $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat,";
  212. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  213. $sql .= " '".$db->escape($conf->currency)."' as currency, t.fk_user as fk_soc, t.datep as date, t.dateep as date_due, 'SalaryPayment' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
  214. $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country";
  215. $sql .= " WHERE datep between ".$wheretail;
  216. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  217. //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
  218. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  219. }
  220. // Social contributions
  221. if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) {
  222. if (!empty($sql)) {
  223. $sql .= " UNION ALL";
  224. }
  225. $sql .= " SELECT t.rowid as id, t.entity, t.libelle as ref, t.paye as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat,";
  226. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  227. $sql .= " '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.date_ech as date, t.periode as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
  228. $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t";
  229. $sql .= " WHERE t.date_ech between ".$wheretail;
  230. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  231. //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT;
  232. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  233. }
  234. // Various payments
  235. if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) {
  236. if (!empty($sql)) {
  237. $sql .= " UNION ALL";
  238. }
  239. $sql .= " SELECT t.rowid as id, t.entity, t.ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat,";
  240. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  241. $sql .= " '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'VariousPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, sens";
  242. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t";
  243. $sql .= " WHERE datep between ".$wheretail;
  244. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  245. if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid);
  246. }
  247. // Loan payments
  248. if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) {
  249. if (!empty($sql)) {
  250. $sql .= " UNION ALL";
  251. }
  252. $sql .= " SELECT t.rowid as id, l.entity, l.label as ref, 1 as paid, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ht, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ttc, 0 as total_vat,";
  253. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  254. $sql .= " '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'LoanPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
  255. $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan";
  256. $sql .= " WHERE datep between ".$wheretail;
  257. $sql .= " AND l.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  258. }
  259. if ($sql) {
  260. $sql .= $db->order($sortfield, $sortorder);
  261. //print $sql;
  262. $resd = $db->query($sql);
  263. $files = array();
  264. $link = '';
  265. if ($resd) {
  266. $numd = $db->num_rows($resd);
  267. $tmpinvoice = new Facture($db);
  268. $tmpinvoicesupplier = new FactureFournisseur($db);
  269. $tmpdonation = new Don($db);
  270. $upload_dir = '';
  271. $i = 0;
  272. while ($i < $numd) {
  273. $objd = $db->fetch_object($resd);
  274. switch ($objd->item) {
  275. case "Invoice":
  276. $subdir = '';
  277. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  278. $upload_dir = $conf->facture->dir_output.'/'.$subdir;
  279. $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F';
  280. $modulepart = "facture";
  281. break;
  282. case "SupplierInvoice":
  283. $tmpinvoicesupplier->fetch($objd->id);
  284. $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file
  285. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  286. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
  287. $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F';
  288. $modulepart = "facture_fournisseur";
  289. break;
  290. case "ExpenseReport":
  291. $subdir = '';
  292. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  293. $upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
  294. $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F';
  295. $modulepart = "expensereport";
  296. break;
  297. case "SalaryPayment":
  298. $subdir = '';
  299. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  300. $upload_dir = $conf->salaries->dir_output.'/'.$subdir;
  301. $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F';
  302. $modulepart = "salaries";
  303. break;
  304. case "Donation":
  305. $tmpdonation->fetch($objp->id);
  306. $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation');
  307. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  308. $upload_dir = $conf->don->dir_output.'/'.$subdir;
  309. $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F';
  310. $modulepart = "don";
  311. break;
  312. case "SocialContributions":
  313. $subdir = '';
  314. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  315. $upload_dir = $conf->tax->dir_output.'/'.$subdir;
  316. $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F';
  317. $modulepart = "tax";
  318. break;
  319. case "VariousPayment":
  320. $subdir = '';
  321. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  322. $upload_dir = $conf->bank->dir_output.'/'.$subdir;
  323. $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F';
  324. $modulepart = "banque";
  325. break;
  326. case "LoanPayment":
  327. // Loan payment has no linked file
  328. $subdir = '';
  329. $upload_dir = $conf->loan->dir_output.'/'.$subdir;
  330. $link = "";
  331. $modulepart = "";
  332. break;
  333. default:
  334. $subdir = '';
  335. $upload_dir = '';
  336. $link = '';
  337. break;
  338. }
  339. if (!empty($upload_dir)) {
  340. $result = true;
  341. $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
  342. //var_dump($upload_dir);
  343. //var_dump($files);
  344. if (count($files) < 1) {
  345. $nofile = array();
  346. $nofile['id'] = $objd->id;
  347. $nofile['entity'] = $objd->entity;
  348. $nofile['date'] = $db->jdate($objd->date);
  349. $nofile['date_due'] = $db->jdate($objd->date_due);
  350. $nofile['paid'] = $objd->paid;
  351. $nofile['amount_ht'] = $objd->total_ht;
  352. $nofile['amount_ttc'] = $objd->total_ttc;
  353. $nofile['amount_vat'] = $objd->total_vat;
  354. $nofile['amount_localtax1'] = $objd->localtax1;
  355. $nofile['amount_localtax2'] = $objd->localtax2;
  356. $nofile['amount_revenuestamp'] = $objd->revenuestamp;
  357. $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id);
  358. $nofile['fk'] = $objd->fk_soc;
  359. $nofile['item'] = $objd->item;
  360. $nofile['thirdparty_name'] = $objd->thirdparty_name;
  361. $nofile['thirdparty_code'] = $objd->thirdparty_code;
  362. $nofile['country_code'] = $objd->country_code;
  363. $nofile['vatnum'] = $objd->vatnum;
  364. $nofile['sens'] = $objd->sens;
  365. $nofile['currency'] = $objd->currency;
  366. $nofile['link'] = '';
  367. $nofile['name'] = '';
  368. $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
  369. } else {
  370. foreach ($files as $key => $file) {
  371. $file['id'] = $objd->id;
  372. $file['entity'] = $objd->entity;
  373. $file['date'] = $db->jdate($objd->date);
  374. $file['date_due'] = $db->jdate($objd->date_due);
  375. $file['paid'] = $objd->paid;
  376. $file['amount_ht'] = $objd->total_ht;
  377. $file['amount_ttc'] = $objd->total_ttc;
  378. $file['amount_vat'] = $objd->total_vat;
  379. $file['amount_localtax1'] = $objd->localtax1;
  380. $file['amount_localtax2'] = $objd->localtax2;
  381. $file['amount_revenuestamp'] = $objd->revenuestamp;
  382. $file['ref'] = ($objd->ref ? $objd->ref : $objd->id);
  383. $file['fk'] = $objd->fk_soc;
  384. $file['item'] = $objd->item;
  385. $file['thirdparty_name'] = $objd->thirdparty_name;
  386. $file['thirdparty_code'] = $objd->thirdparty_code;
  387. $file['country_code'] = $objd->country_code;
  388. $file['vatnum'] = $objd->vatnum;
  389. $file['sens'] = $objd->sens;
  390. $file['currency'] = $objd->currency;
  391. // Save record into array (only the first time it is found)
  392. if (empty($filesarray[$file['item'].'_'.$file['id']])) {
  393. $filesarray[$file['item'].'_'.$file['id']] = $file;
  394. }
  395. // Add or concat file
  396. if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) {
  397. $filesarray[$file['item'].'_'.$file['id']]['files'] = array();
  398. }
  399. $filesarray[$file['item'].'_'.$file['id']]['files'][] = array(
  400. 'link' => $link.urlencode($file['name']),
  401. 'name'=>$file['name'],
  402. 'ref'=>$file['ref'],
  403. 'fullname' => $file['fullname'],
  404. 'relpath' => '/'.$file['name'],
  405. 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'],
  406. 'modulepart' => $modulepart,
  407. 'subdir' => $subdir,
  408. 'currency' => $file['currency']
  409. );
  410. //var_dump($file['item'].'_'.$file['id']);
  411. //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']);
  412. }
  413. }
  414. }
  415. $i++;
  416. }
  417. } else {
  418. dol_print_error($db);
  419. }
  420. $db->free($resd);
  421. } else {
  422. setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors');
  423. $error++;
  424. }
  425. }
  426. }
  427. /*
  428. *ZIP creation
  429. */
  430. $dirfortmpfile = ($conf->accounting->dir_temp ? $conf->accounting->dir_temp : $conf->comptabilite->dir_temp);
  431. if (empty($dirfortmpfile)) {
  432. setEventMessages($langs->trans("ErrorNoAccountingModuleEnabled"), null, 'errors');
  433. $error++;
  434. }
  435. if ($result && $action == "dl" && !$error) {
  436. if (!extension_loaded('zip')) {
  437. setEventMessages('PHPZIPExtentionNotLoaded', null, 'errors');
  438. } else {
  439. dol_mkdir($dirfortmpfile);
  440. $log = $langs->transnoentitiesnoconv("Type");
  441. if (isModEnabled('multicompany') && is_object($mc)) {
  442. $log .= ','.$langs->transnoentitiesnoconv("Entity");
  443. }
  444. $log .= ','.$langs->transnoentitiesnoconv("Date");
  445. $log .= ','.$langs->transnoentitiesnoconv("DateDue");
  446. $log .= ','.$langs->transnoentitiesnoconv("Ref");
  447. $log .= ','.$langs->transnoentitiesnoconv("TotalHT");
  448. $log .= ','.$langs->transnoentitiesnoconv("TotalTTC");
  449. $log .= ','.$langs->transnoentitiesnoconv("TotalVAT");
  450. $log .= ','.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code);
  451. $log .= ','.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code);
  452. $log .= ','.$langs->transnoentitiesnoconv("RevenueStamp");
  453. $log .= ','.$langs->transnoentitiesnoconv("Paid");
  454. $log .= ','.$langs->transnoentitiesnoconv("Document");
  455. $log .= ','.$langs->transnoentitiesnoconv("ItemID");
  456. $log .= ','.$langs->transnoentitiesnoconv("ThirdParty");
  457. $log .= ','.$langs->transnoentitiesnoconv("Code");
  458. $log .= ','.$langs->transnoentitiesnoconv("Country");
  459. $log .= ','.$langs->transnoentitiesnoconv("VATIntra");
  460. $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n";
  461. $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel');
  462. if (!empty($projectid)) {
  463. $project = new Project($db);
  464. $project->fetch($projectid);
  465. if ($project->ref) {
  466. $zipname .= '_'.$project->ref;
  467. }
  468. }
  469. $zipname .='_export.zip';
  470. dol_delete_file($zipname);
  471. $zip = new ZipArchive;
  472. $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE);
  473. if ($res) {
  474. foreach ($filesarray as $key => $file) {
  475. if (!empty($file['files'])) {
  476. foreach ($file['files'] as $filecursor) {
  477. if (file_exists($filecursor["fullname"])) {
  478. $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]);
  479. }
  480. }
  481. }
  482. $log .= '"'.$langs->transnoentitiesnoconv($file['item']).'"';
  483. if (isModEnabled('multicompany') && is_object($mc)) {
  484. $log .= ',"'.(empty($arrayofentities[$file['entity']]) ? $file['entity'] : $arrayofentities[$file['entity']]).'"';
  485. }
  486. $log .= ','.dol_print_date($file['date'], 'dayrfc');
  487. $log .= ','.dol_print_date($file['date_due'], 'dayrfc');
  488. $log .= ',"'.$file['ref'].'"';
  489. $log .= ','.$file['amount_ht'];
  490. $log .= ','.$file['amount_ttc'];
  491. $log .= ','.$file['amount_vat'];
  492. $log .= ','.$file['amount_localtax1'];
  493. $log .= ','.$file['amount_localtax2'];
  494. $log .= ','.$file['amount_revenuestamp'];
  495. $log .= ','.$file['paid'];
  496. $log .= ',"'.$file["name"].'"';
  497. $log .= ','.$file['fk'];
  498. $log .= ',"'.$file['thirdparty_name'].'"';
  499. $log .= ',"'.$file['thirdparty_code'].'"';
  500. $log .= ',"'.$file['country_code'].'"';
  501. $log .= ',"'.$file['vatnum'].'"';
  502. $log .= ',"'.$file['sens'].'"';
  503. $log .= "\n";
  504. }
  505. $zip->addFromString('transactions.csv', $log);
  506. $zip->close();
  507. // Then download the zipped file.
  508. header('Content-Type: application/zip');
  509. header('Content-disposition: attachment; filename='.basename($zipname));
  510. header('Content-Length: '.filesize($zipname));
  511. readfile($zipname);
  512. dol_delete_file($zipname);
  513. exit();
  514. } else {
  515. setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors');
  516. }
  517. }
  518. }
  519. /*
  520. * View
  521. */
  522. $form = new Form($db);
  523. $formfile = new FormFile($db);
  524. $userstatic = new User($db);
  525. $invoice = new Facture($db);
  526. $supplier_invoice = new FactureFournisseur($db);
  527. $expensereport = new ExpenseReport($db);
  528. $don = new Don($db);
  529. $salary_payment = new PaymentSalary($db);
  530. $charge_sociales = new ChargeSociales($db);
  531. $various_payment = new PaymentVarious($db);
  532. $payment_loan = new PaymentLoan($db);
  533. $title = $langs->trans("ComptaFiles").' - '.$langs->trans("List");
  534. $help_url = '';
  535. llxHeader('', $title, $help_url);
  536. $h = 0;
  537. $head = array();
  538. $head[$h][0] = $_SERVER["PHP_SELF"];
  539. $head[$h][1] = $langs->trans("AccountantFiles");
  540. $head[$h][2] = 'AccountancyFiles';
  541. print dol_get_fiche_head($head, 'AccountancyFiles');
  542. print '<form name="searchfiles" action="?action=searchfiles" method="POST">'."\n";
  543. print '<input type="hidden" name="token" value="'.newToken().'">';
  544. print '<span class="opacitymedium">'.$langs->trans("ExportAccountingSourceDocHelp");
  545. if (isModEnabled('accounting')) {
  546. print ' '.$langs->trans("ExportAccountingSourceDocHelp2", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Journals"));
  547. }
  548. print '</span><br>';
  549. print '<br>';
  550. print $langs->trans("ReportPeriod").': ';
  551. print $form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
  552. print ' - ';
  553. print $form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
  554. print "\n";
  555. // Export is for current company only
  556. $socid = 0;
  557. if (isModEnabled('multicompany') && is_object($mc)) {
  558. $mc->getInfo($conf->entity);
  559. print ' &nbsp; <span class="marginleftonly marginrightonly'.(empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES) ? ' opacitymedium' : '').'">'.$langs->trans("Entity").' : ';
  560. if (!empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES)) {
  561. $socid = $mc->id;
  562. print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOST('search_entity', 'int') : $mc->id, 'search_entity', '', false, false, false, false, true);
  563. } else {
  564. print $mc->label;
  565. }
  566. print "</span>\n";
  567. }
  568. print '<br>';
  569. // Project filter
  570. if (isModEnabled('projet')) {
  571. $formproject = new FormProjets($db);
  572. $langs->load('projects');
  573. print '<span class="marginrightonly">'.$langs->trans('Project').":</span>";
  574. print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, '');
  575. print '<span class="classfortooltip" style="padding: 0px; padding: 0px; padding-right: 3px !important;" title="'.$langs->trans('ExportAccountingProjectHelp').'"><span class="fas fa-info-circle em088 opacityhigh" style=" vertical-align: middle; cursor: help"></span></span>';
  576. print '<br>';
  577. }
  578. $i = 0;
  579. foreach ($listofchoices as $choice => $val) {
  580. if (empty($val['enabled'])) {
  581. continue; // list not qualified
  582. }
  583. $disabled = '';
  584. if (empty($val['perms'])) {
  585. $disabled = ' disabled';
  586. }
  587. $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : '');
  588. print '<div class="'.($i > 0 ? 'paddingleft marginleftonly' : '').' inline-block marginrightonly paddingright"><input type="checkbox" id="'.$choice.'" name="'.$choice.'" value="1"'.$checked.$disabled.'><label for="'.$choice.'"> ';
  589. print img_picto($langs->trans($val['label']), $val['picto'], 'class=""').' '.$langs->trans($val['label']);
  590. print '</label></div>';
  591. $i++;
  592. }
  593. print '<input type="submit" class="button small" name="search" value="'.$langs->trans("Search").'">';
  594. print '</form>'."\n";
  595. print dol_get_fiche_end();
  596. $param = '';
  597. if (!empty($date_start) && !empty($date_stop)) {
  598. $param .= '&date_startday='.GETPOST('date_startday', 'int');
  599. $param .= '&date_startmonth='.GETPOST('date_startmonth', 'int');
  600. $param .= '&date_startyear='.GETPOST('date_startyear', 'int');
  601. $param .= '&date_stopday='.GETPOST('date_stopday', 'int');
  602. $param .= '&date_stopmonth='.GETPOST('date_stopmonth', 'int');
  603. $param .= '&date_stopyear='.GETPOST('date_stopyear', 'int');
  604. foreach ($listofchoices as $choice => $val) {
  605. if (GETPOST($choice, 'int')) {
  606. $param .= '&'.$choice.'=1';
  607. }
  608. }
  609. $TData = dol_sort_array($filesarray, $sortfield, $sortorder);
  610. $filename = dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip';
  611. echo dol_print_date($date_start, 'day', 'tzuserrel')." - ".dol_print_date($date_stop, 'day', 'tzuserrel');
  612. print '<a class="marginleftonly small'.(empty($TData) ? ' butActionRefused' : ' butAction').'" href="'.$_SERVER["PHP_SELF"].'?action=dl&token='.currentToken().'&projectid='.$projectid.'&output=file&file='.urlencode($filename).$param.'"';
  613. if (empty($TData)) {
  614. print " disabled";
  615. }
  616. print '>'."\n";
  617. print $langs->trans("Download");
  618. print '</a><br>';
  619. $param .= '&action=searchfiles';
  620. /*
  621. print '<input type="hidden" name="token" value="'.currentToken().'">';
  622. print '<input type="hidden" name="date_startday" value="'.GETPOST('date_startday', 'int').'" />';
  623. print '<input type="hidden" name="date_startmonth" value="'.GETPOST('date_startmonth', 'int').'" />';
  624. print '<input type="hidden" name="date_startyear" value="'.GETPOST('date_startyear', 'int').'" />';
  625. print '<input type="hidden" name="date_stopday" value="'.GETPOST('date_stopday', 'int').'" />';
  626. print '<input type="hidden" name="date_stopmonth" value="'.GETPOST('date_stopmonth', 'int').'" />';
  627. print '<input type="hidden" name="date_stopyear" value="'.GETPOST('date_stopyear', 'int').'" />';
  628. foreach ($listofchoices as $choice => $val) {
  629. print '<input type="hidden" name="'.$choice.'" value="'.GETPOST($choice).'">';
  630. }
  631. print '<input class="butAction butDownload small marginleftonly" type="submit" value="'.$langs->trans("Download").'"';
  632. if (empty($TData)) {
  633. print " disabled";
  634. }
  635. print '/>';
  636. print '</form>'."\n";
  637. */
  638. print '<br>';
  639. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  640. print '<table class="noborder centpercent">';
  641. print '<tr class="liste_titre">';
  642. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  643. print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  644. print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  645. print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall ');
  646. print '<td>'.$langs->trans("Document").'</td>';
  647. print '<td>'.$langs->trans("Paid").'</td>';
  648. print '<td align="right">'.$langs->trans("TotalHT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</td>';
  649. print '<td align="right">'.$langs->trans("TotalTTC").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</td>';
  650. print '<td align="right">'.$langs->trans("TotalVAT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</td>';
  651. print '<td>'.$langs->trans("ThirdParty").'</td>';
  652. print '<td class="center">'.$langs->trans("Code").'</td>';
  653. print '<td class="center">'.$langs->trans("Country").'</td>';
  654. print '<td class="center">'.$langs->trans("VATIntra").'</td>';
  655. if (isModEnabled('multicurrency')) {
  656. print '<td class="center">'.$langs->trans("Currency").'</td>';
  657. }
  658. print '</tr>';
  659. if (empty($TData)) {
  660. print '<tr class="oddeven"><td colspan="13"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td>';
  661. if (isModEnabled('multicurrency')) {
  662. print '<td></td>';
  663. }
  664. print '</tr>';
  665. } else {
  666. // Sort array by date ASC to calculate balance
  667. $totalET_debit = 0;
  668. $totalIT_debit = 0;
  669. $totalVAT_debit = 0;
  670. $totalET_credit = 0;
  671. $totalIT_credit = 0;
  672. $totalVAT_credit = 0;
  673. // Display array
  674. foreach ($TData as $data) {
  675. $html_class = '';
  676. //if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
  677. //elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
  678. print '<tr class="oddeven '.$html_class.'">';
  679. // Type
  680. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans($data['item'])).'">'.$langs->trans($data['item']).'</td>';
  681. // Date
  682. print '<td class="center">';
  683. print dol_print_date($data['date'], 'day');
  684. print "</td>\n";
  685. // Date due
  686. print '<td class="center">';
  687. print dol_print_date($data['date_due'], 'day');
  688. print "</td>\n";
  689. // Ref
  690. print '<td class="nowraponall tdoverflowmax150">';
  691. if ($data['item'] == 'Invoice') {
  692. $invoice->id = $data['id'];
  693. $invoice->ref = $data['ref'];
  694. $invoice->total_ht = $data['amount_ht'];
  695. $invoice->total_ttc = $data['amount_ttc'];
  696. $invoice->total_tva = $data['amount_vat'];
  697. $invoice->total_localtax1 = $data['amount_localtax1'];
  698. $invoice->total_localtax2 = $data['amount_localtax2'];
  699. $invoice->revenuestamp = $data['amount_revenuestamp'];
  700. $invoice->multicurrency_code = $data['currency'];
  701. print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
  702. } elseif ($data['item'] == 'SupplierInvoice') {
  703. $supplier_invoice->id = $data['id'];
  704. $supplier_invoice->ref = $data['ref'];
  705. $supplier_invoice->total_ht = $data['amount_ht'];
  706. $supplier_invoice->total_ttc = $data['amount_ttc'];
  707. $supplier_invoice->total_tva = $data['amount_vat'];
  708. $supplier_invoice->total_localtax1 = $data['amount_localtax1'];
  709. $supplier_invoice->total_localtax2 = $data['amount_localtax2'];
  710. $supplier_invoice->revenuestamp = $data['amount_revenuestamp'];
  711. $supplier_invoice->multicurrency_code = $data['currency'];
  712. print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
  713. } elseif ($data['item'] == 'ExpenseReport') {
  714. $expensereport->id = $data['id'];
  715. $expensereport->ref = $data['ref'];
  716. print $expensereport->getNomUrl(1, 0, 0, '', 0, 0);
  717. } elseif ($data['item'] == 'SalaryPayment') {
  718. $salary_payment->id = $data['id'];
  719. $salary_payment->ref = $data['ref'];
  720. print $salary_payment->getNomUrl(1);
  721. } elseif ($data['item'] == 'Donation') {
  722. $don->id = $data['id'];
  723. $don->ref = $data['ref'];
  724. print $don->getNomUrl(1, 0, '', 0);
  725. } elseif ($data['item'] == 'SocialContributions') {
  726. $charge_sociales->id = $data['id'];
  727. $charge_sociales->ref = $data['ref'];
  728. print $charge_sociales->getNomUrl(1, 0, 0, 0, 0);
  729. } elseif ($data['item'] == 'VariousPayment') {
  730. $various_payment->id = $data['id'];
  731. $various_payment->ref = $data['ref'];
  732. print $various_payment->getNomUrl(1, '', 0, 0);
  733. } elseif ($data['item'] == 'LoanPayment') {
  734. $payment_loan->id = $data['id'];
  735. $payment_loan->ref = $data['ref'];
  736. print $payment_loan->getNomUrl(1, 0, 0, '', 0);
  737. } else {
  738. print $data['ref'];
  739. }
  740. print '</td>';
  741. // File link
  742. print '<td class="tdoverflowmax150">';
  743. if (!empty($data['files'])) {
  744. foreach ($data['files'] as $id => $filecursor) {
  745. $tmppreview = $formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name'], 0);
  746. if ($tmppreview) {
  747. print $tmppreview;
  748. }
  749. $filename = ($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']);
  750. print '<a href='.DOL_URL_ROOT.'/'.$filecursor['link'].' target="_blank" rel="noopener noreferrer" title="'.dol_escape_htmltag($filename).'">';
  751. if (empty($tmppreview)) {
  752. print img_picto('', 'generic', '', false, 0, 0, '', 'pictonopreview pictofixedwidth paddingright');
  753. }
  754. print $filename;
  755. print '</a><br>';
  756. }
  757. }
  758. print "</td>\n";
  759. // Paid
  760. print '<td class="center">'.($data['paid'] ? yn($data['paid']) : '').'</td>';
  761. // Total WOT
  762. print '<td align="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_ht'] : -$data['amount_ht'], 'MT'))."</span></td>\n";
  763. // Total INCT
  764. print '<td align="right"><span class="amount">';
  765. $tooltip = $langs->trans("TotalVAT").' : '.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'));
  766. if (!empty($data['amount_localtax1'])) {
  767. $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax1'] : -$data['amount_localtax1'], 'MT'));
  768. }
  769. if (!empty($data['amount_localtax2'])) {
  770. $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax2'] : -$data['amount_localtax2'], 'MT'));
  771. }
  772. if (!empty($data['amount_revenuestamp'])) {
  773. $tooltip .= '<br>'.$langs->trans("RevenueStamp").' : '.price(price2num($data['sens'] ? $data['amount_revenuestamp'] : -$data['amount_revenuestamp'], 'MT'));
  774. }
  775. print '<span class="classfortooltip" title="'.dol_escape_htmltag($tooltip).'">'.price(price2num($data['sens'] ? $data['amount_ttc'] : -$data['amount_ttc'], 'MT')).'</span>';
  776. print "</span></td>\n";
  777. // Total VAT
  778. print '<td align="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'))."</span></td>\n";
  779. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($data['thirdparty_name']).'">'.dol_escape_htmltag($data['thirdparty_name'])."</td>\n";
  780. print '<td class="center">'.$data['thirdparty_code']."</td>\n";
  781. print '<td class="center">'.$data['country_code']."</td>\n";
  782. // VAT number
  783. print '<td class="tdoverflowmax150 right" title="'.dol_escape_htmltag($data['vatnum']).'">'.dol_escape_htmltag($data['vatnum'])."</td>\n";
  784. if ($data['sens']) {
  785. $totalET_credit += $data['amount_ht'];
  786. $totalIT_credit += $data['amount_ttc'];
  787. $totalVAT_credit += $data['amount_vat'];
  788. } else {
  789. $totalET_debit -= $data['amount_ht'];
  790. $totalIT_debit -= $data['amount_ttc'];
  791. $totalVAT_debit -= $data['amount_vat'];
  792. }
  793. if (isModEnabled('multicurrency')) {
  794. print '<td class="center">'.$data['currency']."</td>\n";
  795. }
  796. print "</tr>\n";
  797. }
  798. // Total credits
  799. print '<tr class="liste_total">';
  800. print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Income').'</td>';
  801. print '<td align="right">'.price(price2num($totalET_credit, 'MT')).'</td>';
  802. print '<td align="right">'.price(price2num($totalIT_credit, 'MT')).'</td>';
  803. print '<td align="right">'.price(price2num($totalVAT_credit, 'MT')).'</td>';
  804. print '<td colspan="4"></td>';
  805. if (isModEnabled('multicurrency')) {
  806. print '<td></td>';
  807. }
  808. print "</tr>\n";
  809. // Total debits
  810. print '<tr class="liste_total">';
  811. print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Outcome').'</td>';
  812. print '<td align="right">'.price(price2num($totalET_debit, 'MT')).'</td>';
  813. print '<td align="right">'.price(price2num($totalIT_debit, 'MT')).'</td>';
  814. print '<td align="right">'.price(price2num($totalVAT_debit, 'MT')).'</td>';
  815. print '<td colspan="4"></td>';
  816. if (isModEnabled('multicurrency')) {
  817. print '<td></td>';
  818. }
  819. print "</tr>\n";
  820. // Balance
  821. print '<tr class="liste_total">';
  822. print '<td colspan="6" class="right">'.$langs->trans('Total').'</td>';
  823. print '<td align="right">'.price(price2num($totalET_credit + $totalET_debit, 'MT')).'</td>';
  824. print '<td align="right">'.price(price2num($totalIT_credit + $totalIT_debit, 'MT')).'</td>';
  825. print '<td align="right">'.price(price2num($totalVAT_credit + $totalVAT_debit, 'MT')).'</td>';
  826. print '<td colspan="4"></td>';
  827. if (isModEnabled('multicurrency')) {
  828. print '<td></td>';
  829. }
  830. print "</tr>\n";
  831. }
  832. print "</table>";
  833. print '</div>';
  834. }
  835. llxFooter();
  836. $db->close();