accounting-files.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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-2024 Alexandre Spangaro <aspangaro@easya.solutions>
  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) && getDolGlobalString('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)) {
  164. $sql .= " AND fk_projet = ".((int) $projectid);
  165. }
  166. }
  167. // Vendor invoices
  168. if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) {
  169. if (!empty($sql)) {
  170. $sql .= " UNION ALL";
  171. }
  172. $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,";
  173. $sql .= " t.localtax1, t.localtax2, 0 as revenuestamp,";
  174. $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";
  175. $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";
  176. $sql .= " WHERE datef between ".$wheretail;
  177. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  178. $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT;
  179. if (!empty($projectid)) {
  180. $sql .= " AND fk_projet = ".((int) $projectid);
  181. }
  182. }
  183. // Expense reports
  184. if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) && empty($projectid)) {
  185. if (!empty($sql)) {
  186. $sql .= " UNION ALL";
  187. }
  188. $sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,";
  189. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  190. $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";
  191. $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";
  192. $sql .= " WHERE date_fin between ".$wheretail;
  193. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  194. $sql .= " AND t.fk_statut <> ".ExpenseReport::STATUS_DRAFT;
  195. }
  196. // Donations
  197. if (GETPOST('selectdonations') && !empty($listofchoices['selectdonations']['perms'])) {
  198. if (!empty($sql)) {
  199. $sql .= " UNION ALL";
  200. }
  201. $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat,";
  202. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  203. $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";
  204. $sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country";
  205. $sql .= " WHERE datedon between ".$wheretail;
  206. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  207. $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT;
  208. if (!empty($projectid)) {
  209. $sql .= " AND fk_projet = ".((int) $projectid);
  210. }
  211. }
  212. // Payments of salaries
  213. if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) {
  214. if (!empty($sql)) {
  215. $sql .= " UNION ALL";
  216. }
  217. $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,";
  218. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  219. $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";
  220. $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";
  221. $sql .= " WHERE datep between ".$wheretail;
  222. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  223. //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
  224. if (!empty($projectid)) {
  225. $sql .= " AND fk_projet = ".((int) $projectid);
  226. }
  227. }
  228. // Social contributions
  229. if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) {
  230. if (!empty($sql)) {
  231. $sql .= " UNION ALL";
  232. }
  233. $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,";
  234. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  235. $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";
  236. $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t";
  237. $sql .= " WHERE t.date_ech between ".$wheretail;
  238. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  239. //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT;
  240. if (!empty($projectid)) {
  241. $sql .= " AND fk_projet = ".((int) $projectid);
  242. }
  243. }
  244. // Various payments
  245. if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) {
  246. if (!empty($sql)) {
  247. $sql .= " UNION ALL";
  248. }
  249. $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,";
  250. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  251. $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";
  252. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t";
  253. $sql .= " WHERE datep between ".$wheretail;
  254. $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  255. if (!empty($projectid)) {
  256. $sql .= " AND fk_projet = ".((int) $projectid);
  257. }
  258. }
  259. // Loan payments
  260. if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) {
  261. if (!empty($sql)) {
  262. $sql .= " UNION ALL";
  263. }
  264. $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,";
  265. $sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,";
  266. $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";
  267. $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan";
  268. $sql .= " WHERE datep between ".$wheretail;
  269. $sql .= " AND l.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')';
  270. }
  271. if ($sql) {
  272. $sql .= $db->order($sortfield, $sortorder);
  273. //print $sql;
  274. $resd = $db->query($sql);
  275. $files = array();
  276. $link = '';
  277. if ($resd) {
  278. $numd = $db->num_rows($resd);
  279. $tmpinvoice = new Facture($db);
  280. $tmpinvoicesupplier = new FactureFournisseur($db);
  281. $tmpdonation = new Don($db);
  282. $upload_dir = '';
  283. $i = 0;
  284. while ($i < $numd) {
  285. $objd = $db->fetch_object($resd);
  286. switch ($objd->item) {
  287. case "Invoice":
  288. $subdir = '';
  289. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  290. $upload_dir = $conf->facture->dir_output.'/'.$subdir;
  291. $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F';
  292. $modulepart = "facture";
  293. break;
  294. case "SupplierInvoice":
  295. $tmpinvoicesupplier->fetch($objd->id);
  296. $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file
  297. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  298. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
  299. $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F';
  300. $modulepart = "facture_fournisseur";
  301. break;
  302. case "ExpenseReport":
  303. $subdir = '';
  304. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
  305. $upload_dir = $conf->expensereport->dir_output.'/'.$subdir;
  306. $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F';
  307. $modulepart = "expensereport";
  308. break;
  309. case "SalaryPayment":
  310. $subdir = '';
  311. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  312. $upload_dir = $conf->salaries->dir_output.'/'.$subdir;
  313. $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F';
  314. $modulepart = "salaries";
  315. break;
  316. case "Donation":
  317. $tmpdonation->fetch($objp->id);
  318. $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation');
  319. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  320. $upload_dir = $conf->don->dir_output.'/'.$subdir;
  321. $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F';
  322. $modulepart = "don";
  323. break;
  324. case "SocialContributions":
  325. $subdir = '';
  326. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  327. $upload_dir = $conf->tax->dir_output.'/'.$subdir;
  328. $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F';
  329. $modulepart = "tax";
  330. break;
  331. case "VariousPayment":
  332. $subdir = '';
  333. $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id);
  334. $upload_dir = $conf->bank->dir_output.'/'.$subdir;
  335. $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F';
  336. $modulepart = "banque";
  337. break;
  338. case "LoanPayment":
  339. // Loan payment has no linked file
  340. $subdir = '';
  341. $upload_dir = $conf->loan->dir_output.'/'.$subdir;
  342. $link = "";
  343. $modulepart = "";
  344. break;
  345. default:
  346. $subdir = '';
  347. $upload_dir = '';
  348. $link = '';
  349. break;
  350. }
  351. if (!empty($upload_dir)) {
  352. $result = true;
  353. $files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
  354. //var_dump($upload_dir);
  355. //var_dump($files);
  356. if (count($files) < 1) {
  357. $nofile = array();
  358. $nofile['id'] = $objd->id;
  359. $nofile['entity'] = $objd->entity;
  360. $nofile['date'] = $db->jdate($objd->date);
  361. $nofile['date_due'] = $db->jdate($objd->date_due);
  362. $nofile['paid'] = $objd->paid;
  363. $nofile['amount_ht'] = $objd->total_ht;
  364. $nofile['amount_ttc'] = $objd->total_ttc;
  365. $nofile['amount_vat'] = $objd->total_vat;
  366. $nofile['amount_localtax1'] = $objd->localtax1;
  367. $nofile['amount_localtax2'] = $objd->localtax2;
  368. $nofile['amount_revenuestamp'] = $objd->revenuestamp;
  369. $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id);
  370. $nofile['fk'] = $objd->fk_soc;
  371. $nofile['item'] = $objd->item;
  372. $nofile['thirdparty_name'] = $objd->thirdparty_name;
  373. $nofile['thirdparty_code'] = $objd->thirdparty_code;
  374. $nofile['country_code'] = $objd->country_code;
  375. $nofile['vatnum'] = $objd->vatnum;
  376. $nofile['sens'] = $objd->sens;
  377. $nofile['currency'] = $objd->currency;
  378. $nofile['link'] = '';
  379. $nofile['name'] = '';
  380. $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
  381. } else {
  382. foreach ($files as $key => $file) {
  383. $file['id'] = $objd->id;
  384. $file['entity'] = $objd->entity;
  385. $file['date'] = $db->jdate($objd->date);
  386. $file['date_due'] = $db->jdate($objd->date_due);
  387. $file['paid'] = $objd->paid;
  388. $file['amount_ht'] = $objd->total_ht;
  389. $file['amount_ttc'] = $objd->total_ttc;
  390. $file['amount_vat'] = $objd->total_vat;
  391. $file['amount_localtax1'] = $objd->localtax1;
  392. $file['amount_localtax2'] = $objd->localtax2;
  393. $file['amount_revenuestamp'] = $objd->revenuestamp;
  394. $file['ref'] = ($objd->ref ? $objd->ref : $objd->id);
  395. $file['fk'] = $objd->fk_soc;
  396. $file['item'] = $objd->item;
  397. $file['thirdparty_name'] = $objd->thirdparty_name;
  398. $file['thirdparty_code'] = $objd->thirdparty_code;
  399. $file['country_code'] = $objd->country_code;
  400. $file['vatnum'] = $objd->vatnum;
  401. $file['sens'] = $objd->sens;
  402. $file['currency'] = $objd->currency;
  403. // Save record into array (only the first time it is found)
  404. if (empty($filesarray[$file['item'].'_'.$file['id']])) {
  405. $filesarray[$file['item'].'_'.$file['id']] = $file;
  406. }
  407. // Add or concat file
  408. if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) {
  409. $filesarray[$file['item'].'_'.$file['id']]['files'] = array();
  410. }
  411. $filesarray[$file['item'].'_'.$file['id']]['files'][] = array(
  412. 'link' => $link.urlencode($file['name']),
  413. 'name'=>$file['name'],
  414. 'ref'=>$file['ref'],
  415. 'fullname' => $file['fullname'],
  416. 'relpath' => '/'.$file['name'],
  417. 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'],
  418. 'modulepart' => $modulepart,
  419. 'subdir' => $subdir,
  420. 'currency' => $file['currency']
  421. );
  422. //var_dump($file['item'].'_'.$file['id']);
  423. //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']);
  424. }
  425. }
  426. }
  427. $i++;
  428. }
  429. } else {
  430. dol_print_error($db);
  431. }
  432. $db->free($resd);
  433. } else {
  434. setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors');
  435. $error++;
  436. }
  437. }
  438. }
  439. /*
  440. *ZIP creation
  441. */
  442. $dirfortmpfile = (!empty($conf->accounting->dir_temp) ? $conf->accounting->dir_temp : $conf->comptabilite->dir_temp);
  443. if (empty($dirfortmpfile)) {
  444. setEventMessages($langs->trans("ErrorNoAccountingModuleEnabled"), null, 'errors');
  445. $error++;
  446. }
  447. if ($result && $action == "dl" && !$error) {
  448. if (!extension_loaded('zip')) {
  449. setEventMessages('PHPZIPExtentionNotLoaded', null, 'errors');
  450. } else {
  451. dol_mkdir($dirfortmpfile);
  452. $log = $langs->transnoentitiesnoconv("Type");
  453. if (isModEnabled('multicompany') && is_object($mc)) {
  454. $log .= ','.$langs->transnoentitiesnoconv("Entity");
  455. }
  456. $log .= ','.$langs->transnoentitiesnoconv("Date");
  457. $log .= ','.$langs->transnoentitiesnoconv("DateDue");
  458. $log .= ','.$langs->transnoentitiesnoconv("Ref");
  459. $log .= ','.$langs->transnoentitiesnoconv("TotalHT");
  460. $log .= ','.$langs->transnoentitiesnoconv("TotalTTC");
  461. $log .= ','.$langs->transnoentitiesnoconv("TotalVAT");
  462. $log .= ','.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code);
  463. $log .= ','.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code);
  464. $log .= ','.$langs->transnoentitiesnoconv("RevenueStamp");
  465. $log .= ','.$langs->transnoentitiesnoconv("Paid");
  466. $log .= ','.$langs->transnoentitiesnoconv("Document");
  467. $log .= ','.$langs->transnoentitiesnoconv("ItemID");
  468. $log .= ','.$langs->transnoentitiesnoconv("ThirdParty");
  469. $log .= ','.$langs->transnoentitiesnoconv("Code");
  470. $log .= ','.$langs->transnoentitiesnoconv("Country");
  471. $log .= ','.$langs->transnoentitiesnoconv("VATIntra");
  472. $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n";
  473. $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel');
  474. if (!empty($projectid)) {
  475. $project = new Project($db);
  476. $project->fetch($projectid);
  477. if ($project->ref) {
  478. $zipname .= '_'.$project->ref;
  479. }
  480. }
  481. $zipname .='_export.zip';
  482. dol_delete_file($zipname);
  483. $zip = new ZipArchive();
  484. $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE);
  485. if ($res) {
  486. foreach ($filesarray as $key => $file) {
  487. if (!empty($file['files'])) {
  488. foreach ($file['files'] as $filecursor) {
  489. if (file_exists($filecursor["fullname"])) {
  490. $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]);
  491. }
  492. }
  493. }
  494. $log .= '"'.$langs->transnoentitiesnoconv($file['item']).'"';
  495. if (isModEnabled('multicompany') && is_object($mc)) {
  496. $log .= ',"'.(empty($arrayofentities[$file['entity']]) ? $file['entity'] : $arrayofentities[$file['entity']]).'"';
  497. }
  498. $log .= ','.dol_print_date($file['date'], 'dayrfc');
  499. $log .= ','.dol_print_date($file['date_due'], 'dayrfc');
  500. $log .= ',"'.$file['ref'].'"';
  501. $log .= ','.$file['amount_ht'];
  502. $log .= ','.$file['amount_ttc'];
  503. $log .= ','.$file['amount_vat'];
  504. $log .= ','.$file['amount_localtax1'];
  505. $log .= ','.$file['amount_localtax2'];
  506. $log .= ','.$file['amount_revenuestamp'];
  507. $log .= ','.$file['paid'];
  508. $log .= ',"'.$file["name"].'"';
  509. $log .= ','.$file['fk'];
  510. $log .= ',"'.$file['thirdparty_name'].'"';
  511. $log .= ',"'.$file['thirdparty_code'].'"';
  512. $log .= ',"'.$file['country_code'].'"';
  513. $log .= ',"'.$file['vatnum'].'"';
  514. $log .= ',"'.$file['sens'].'"';
  515. $log .= "\n";
  516. }
  517. $zip->addFromString('transactions.csv', $log);
  518. $zip->close();
  519. // Then download the zipped file.
  520. header('Content-Type: application/zip');
  521. header('Content-disposition: attachment; filename='.basename($zipname));
  522. header('Content-Length: '.filesize($zipname));
  523. readfile($zipname);
  524. dol_delete_file($zipname);
  525. exit();
  526. } else {
  527. setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors');
  528. }
  529. }
  530. }
  531. /*
  532. * View
  533. */
  534. $form = new Form($db);
  535. $formfile = new FormFile($db);
  536. $userstatic = new User($db);
  537. $invoice = new Facture($db);
  538. $supplier_invoice = new FactureFournisseur($db);
  539. $expensereport = new ExpenseReport($db);
  540. $don = new Don($db);
  541. $salary_payment = new PaymentSalary($db);
  542. $charge_sociales = new ChargeSociales($db);
  543. $various_payment = new PaymentVarious($db);
  544. $payment_loan = new PaymentLoan($db);
  545. $title = $langs->trans("ComptaFiles").' - '.$langs->trans("List");
  546. $help_url = '';
  547. llxHeader('', $title, $help_url);
  548. $h = 0;
  549. $head = array();
  550. $head[$h][0] = $_SERVER["PHP_SELF"];
  551. $head[$h][1] = $langs->trans("AccountantFiles");
  552. $head[$h][2] = 'AccountancyFiles';
  553. print dol_get_fiche_head($head, 'AccountancyFiles');
  554. print '<form name="searchfiles" action="?action=searchfiles" method="POST">'."\n";
  555. print '<input type="hidden" name="token" value="'.newToken().'">';
  556. print '<span class="opacitymedium">'.$langs->trans("ExportAccountingSourceDocHelp");
  557. if (isModEnabled('accounting')) {
  558. print ' '.$langs->trans("ExportAccountingSourceDocHelp2", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Journals"));
  559. }
  560. print '</span><br>';
  561. print '<br>';
  562. print $langs->trans("ReportPeriod").': ';
  563. print $form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
  564. print ' - ';
  565. print $form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0, '', '', '', '', 1, '', '', 'tzuserrel');
  566. print "\n";
  567. // Export is for current company only
  568. $socid = 0;
  569. if (isModEnabled('multicompany') && is_object($mc)) {
  570. $mc->getInfo($conf->entity);
  571. print ' &nbsp; <span class="marginleftonly marginrightonly'.(!getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES') ? ' opacitymedium' : '').'">'.$langs->trans("Entity").' : ';
  572. if (getDolGlobalString('MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES')) {
  573. $socid = $mc->id;
  574. print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOST('search_entity', 'int') : $mc->id, 'search_entity', '', false, false, false, false, true);
  575. } else {
  576. print $mc->label;
  577. }
  578. print "</span>\n";
  579. }
  580. print '<br>';
  581. // Project filter
  582. if (isModEnabled('projet')) {
  583. $formproject = new FormProjets($db);
  584. $langs->load('projects');
  585. print '<span class="marginrightonly">'.$langs->trans('Project').":</span>";
  586. print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, '');
  587. 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>';
  588. print '<br>';
  589. }
  590. $i = 0;
  591. foreach ($listofchoices as $choice => $val) {
  592. if (empty($val['enabled'])) {
  593. continue; // list not qualified
  594. }
  595. $disabled = '';
  596. if (empty($val['perms'])) {
  597. $disabled = ' disabled';
  598. }
  599. $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : '');
  600. 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.'"> ';
  601. print img_picto($langs->trans($val['label']), $val['picto'], 'class=""').' '.$langs->trans($val['label']);
  602. print '</label></div>';
  603. $i++;
  604. }
  605. print '<input type="submit" class="button small" name="search" value="'.$langs->trans("Search").'">';
  606. print '</form>'."\n";
  607. print dol_get_fiche_end();
  608. $param = '';
  609. if (!empty($date_start) && !empty($date_stop)) {
  610. $param .= '&date_startday='.GETPOST('date_startday', 'int');
  611. $param .= '&date_startmonth='.GETPOST('date_startmonth', 'int');
  612. $param .= '&date_startyear='.GETPOST('date_startyear', 'int');
  613. $param .= '&date_stopday='.GETPOST('date_stopday', 'int');
  614. $param .= '&date_stopmonth='.GETPOST('date_stopmonth', 'int');
  615. $param .= '&date_stopyear='.GETPOST('date_stopyear', 'int');
  616. foreach ($listofchoices as $choice => $val) {
  617. if (GETPOST($choice, 'int')) {
  618. $param .= '&'.$choice.'=1';
  619. }
  620. }
  621. $TData = dol_sort_array($filesarray, $sortfield, $sortorder);
  622. $filename = dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip';
  623. echo dol_print_date($date_start, 'day', 'tzuserrel')." - ".dol_print_date($date_stop, 'day', 'tzuserrel');
  624. 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.'"';
  625. if (empty($TData)) {
  626. print " disabled";
  627. }
  628. print '>'."\n";
  629. print $langs->trans("Download");
  630. print '</a><br>';
  631. $param .= '&action=searchfiles';
  632. /*
  633. print '<input type="hidden" name="token" value="'.currentToken().'">';
  634. print '<input type="hidden" name="date_startday" value="'.GETPOST('date_startday', 'int').'" />';
  635. print '<input type="hidden" name="date_startmonth" value="'.GETPOST('date_startmonth', 'int').'" />';
  636. print '<input type="hidden" name="date_startyear" value="'.GETPOST('date_startyear', 'int').'" />';
  637. print '<input type="hidden" name="date_stopday" value="'.GETPOST('date_stopday', 'int').'" />';
  638. print '<input type="hidden" name="date_stopmonth" value="'.GETPOST('date_stopmonth', 'int').'" />';
  639. print '<input type="hidden" name="date_stopyear" value="'.GETPOST('date_stopyear', 'int').'" />';
  640. foreach ($listofchoices as $choice => $val) {
  641. print '<input type="hidden" name="'.$choice.'" value="'.GETPOST($choice).'">';
  642. }
  643. print '<input class="butAction butDownload small marginleftonly" type="submit" value="'.$langs->trans("Download").'"';
  644. if (empty($TData)) {
  645. print " disabled";
  646. }
  647. print '/>';
  648. print '</form>'."\n";
  649. */
  650. print '<br>';
  651. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  652. print '<table class="noborder centpercent">';
  653. print '<tr class="liste_titre">';
  654. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  655. print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  656. print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  657. print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall ');
  658. print '<th>'.$langs->trans("Document").'</th>';
  659. print '<th>'.$langs->trans("Paid").'</th>';
  660. print '<th class="right">'.$langs->trans("TotalHT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
  661. print '<th class="right">'.$langs->trans("TotalTTC").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
  662. print '<th class="right">'.$langs->trans("TotalVAT").(isModEnabled('multicurrency') ? ' ('.$langs->getCurrencySymbol($conf->currency).')' : '').'</th>';
  663. print '<th>'.$langs->trans("ThirdParty").'</th>';
  664. print '<th class="center">'.$langs->trans("Code").'</th>';
  665. print '<th class="center">'.$langs->trans("Country").'</th>';
  666. print '<th class="center">'.$langs->trans("VATIntra").'</th>';
  667. if (isModEnabled('multicurrency')) {
  668. print '<th class="center">'.$langs->trans("Currency").'</th>';
  669. }
  670. print '</tr>';
  671. if (empty($TData)) {
  672. print '<tr class="oddeven"><td colspan="13"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td>';
  673. if (isModEnabled('multicurrency')) {
  674. print '<td></td>';
  675. }
  676. print '</tr>';
  677. } else {
  678. // Sort array by date ASC to calculate balance
  679. $totalET_debit = 0;
  680. $totalIT_debit = 0;
  681. $totalVAT_debit = 0;
  682. $totalET_credit = 0;
  683. $totalIT_credit = 0;
  684. $totalVAT_credit = 0;
  685. // Display array
  686. foreach ($TData as $data) {
  687. $html_class = '';
  688. //if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
  689. //elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
  690. print '<tr class="oddeven '.$html_class.'">';
  691. // Type
  692. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans($data['item'])).'">'.$langs->trans($data['item']).'</td>';
  693. // Date
  694. print '<td class="center">';
  695. print dol_print_date($data['date'], 'day');
  696. print "</td>\n";
  697. // Date due
  698. print '<td class="center">';
  699. print dol_print_date($data['date_due'], 'day');
  700. print "</td>\n";
  701. // Ref
  702. print '<td class="nowraponall tdoverflowmax150">';
  703. if ($data['item'] == 'Invoice') {
  704. $invoice->id = $data['id'];
  705. $invoice->ref = $data['ref'];
  706. $invoice->total_ht = $data['amount_ht'];
  707. $invoice->total_ttc = $data['amount_ttc'];
  708. $invoice->total_tva = $data['amount_vat'];
  709. $invoice->total_localtax1 = $data['amount_localtax1'];
  710. $invoice->total_localtax2 = $data['amount_localtax2'];
  711. $invoice->revenuestamp = $data['amount_revenuestamp'];
  712. $invoice->multicurrency_code = $data['currency'];
  713. print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
  714. } elseif ($data['item'] == 'SupplierInvoice') {
  715. $supplier_invoice->id = $data['id'];
  716. $supplier_invoice->ref = $data['ref'];
  717. $supplier_invoice->total_ht = $data['amount_ht'];
  718. $supplier_invoice->total_ttc = $data['amount_ttc'];
  719. $supplier_invoice->total_tva = $data['amount_vat'];
  720. $supplier_invoice->total_localtax1 = $data['amount_localtax1'];
  721. $supplier_invoice->total_localtax2 = $data['amount_localtax2'];
  722. $supplier_invoice->revenuestamp = $data['amount_revenuestamp'];
  723. $supplier_invoice->multicurrency_code = $data['currency'];
  724. print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0);
  725. } elseif ($data['item'] == 'ExpenseReport') {
  726. $expensereport->id = $data['id'];
  727. $expensereport->ref = $data['ref'];
  728. print $expensereport->getNomUrl(1, 0, 0, '', 0, 0);
  729. } elseif ($data['item'] == 'SalaryPayment') {
  730. $salary_payment->id = $data['id'];
  731. $salary_payment->ref = $data['ref'];
  732. print $salary_payment->getNomUrl(1);
  733. } elseif ($data['item'] == 'Donation') {
  734. $don->id = $data['id'];
  735. $don->ref = $data['ref'];
  736. print $don->getNomUrl(1, 0, '', 0);
  737. } elseif ($data['item'] == 'SocialContributions') {
  738. $charge_sociales->id = $data['id'];
  739. $charge_sociales->ref = $data['ref'];
  740. print $charge_sociales->getNomUrl(1, 0, 0, 0, 0);
  741. } elseif ($data['item'] == 'VariousPayment') {
  742. $various_payment->id = $data['id'];
  743. $various_payment->ref = $data['ref'];
  744. print $various_payment->getNomUrl(1, '', 0, 0);
  745. } elseif ($data['item'] == 'LoanPayment') {
  746. $payment_loan->id = $data['id'];
  747. $payment_loan->ref = $data['ref'];
  748. print $payment_loan->getNomUrl(1, 0, 0, '', 0);
  749. } else {
  750. print $data['ref'];
  751. }
  752. print '</td>';
  753. // File link
  754. print '<td class="tdoverflowmax150">';
  755. if (!empty($data['files'])) {
  756. foreach ($data['files'] as $id => $filecursor) {
  757. $tmppreview = $formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name'], 0);
  758. if ($tmppreview) {
  759. print $tmppreview;
  760. }
  761. $filename = ($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']);
  762. print '<a href='.DOL_URL_ROOT.'/'.$filecursor['link'].' target="_blank" rel="noopener noreferrer" title="'.dol_escape_htmltag($filename).'">';
  763. if (empty($tmppreview)) {
  764. print img_picto('', 'generic', '', false, 0, 0, '', 'pictonopreview pictofixedwidth paddingright');
  765. }
  766. print $filename;
  767. print '</a><br>';
  768. }
  769. }
  770. print "</td>\n";
  771. // Paid
  772. print '<td class="center">'.($data['paid'] ? yn($data['paid']) : '').'</td>';
  773. // Total WOT
  774. print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_ht'] : -$data['amount_ht'], 'MT'))."</span></td>\n";
  775. // Total INCT
  776. print '<td class="right"><span class="amount">';
  777. $tooltip = $langs->trans("TotalVAT").' : '.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'));
  778. if (!empty($data['amount_localtax1'])) {
  779. $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT1", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax1'] : -$data['amount_localtax1'], 'MT'));
  780. }
  781. if (!empty($data['amount_localtax2'])) {
  782. $tooltip .= '<br>'.$langs->transcountrynoentities("TotalLT2", $mysoc->country_code).' : '.price(price2num($data['sens'] ? $data['amount_localtax2'] : -$data['amount_localtax2'], 'MT'));
  783. }
  784. if (!empty($data['amount_revenuestamp'])) {
  785. $tooltip .= '<br>'.$langs->trans("RevenueStamp").' : '.price(price2num($data['sens'] ? $data['amount_revenuestamp'] : -$data['amount_revenuestamp'], 'MT'));
  786. }
  787. print '<span class="classfortooltip" title="'.dol_escape_htmltag($tooltip).'">'.price(price2num($data['sens'] ? $data['amount_ttc'] : -$data['amount_ttc'], 'MT')).'</span>';
  788. print "</span></td>\n";
  789. // Total VAT
  790. print '<td class="right"><span class="amount">'.price(price2num($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'], 'MT'))."</span></td>\n";
  791. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($data['thirdparty_name']).'">'.dol_escape_htmltag($data['thirdparty_name'])."</td>\n";
  792. print '<td class="center">'.$data['thirdparty_code']."</td>\n";
  793. print '<td class="center">'.$data['country_code']."</td>\n";
  794. // VAT number
  795. print '<td class="tdoverflowmax150 right" title="'.dol_escape_htmltag($data['vatnum']).'">'.dol_escape_htmltag($data['vatnum'])."</td>\n";
  796. if ($data['sens']) {
  797. $totalET_credit += $data['amount_ht'];
  798. $totalIT_credit += $data['amount_ttc'];
  799. $totalVAT_credit += $data['amount_vat'];
  800. } else {
  801. $totalET_debit -= $data['amount_ht'];
  802. $totalIT_debit -= $data['amount_ttc'];
  803. $totalVAT_debit -= $data['amount_vat'];
  804. }
  805. if (isModEnabled('multicurrency')) {
  806. print '<td class="center">'.$data['currency']."</td>\n";
  807. }
  808. print "</tr>\n";
  809. }
  810. // Total credits
  811. print '<tr class="liste_total">';
  812. print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Income').'</td>';
  813. print '<td class="right">'.price(price2num($totalET_credit, 'MT')).'</td>';
  814. print '<td class="right">'.price(price2num($totalIT_credit, 'MT')).'</td>';
  815. print '<td class="right">'.price(price2num($totalVAT_credit, 'MT')).'</td>';
  816. print '<td colspan="4"></td>';
  817. if (isModEnabled('multicurrency')) {
  818. print '<td></td>';
  819. }
  820. print "</tr>\n";
  821. // Total debits
  822. print '<tr class="liste_total">';
  823. print '<td colspan="6" class="right">'.$langs->trans('Total').' '.$langs->trans('Outcome').'</td>';
  824. print '<td class="right">'.price(price2num($totalET_debit, 'MT')).'</td>';
  825. print '<td class="right">'.price(price2num($totalIT_debit, 'MT')).'</td>';
  826. print '<td class="right">'.price(price2num($totalVAT_debit, 'MT')).'</td>';
  827. print '<td colspan="4"></td>';
  828. if (isModEnabled('multicurrency')) {
  829. print '<td></td>';
  830. }
  831. print "</tr>\n";
  832. // Balance
  833. print '<tr class="liste_total">';
  834. print '<td colspan="6" class="right">'.$langs->trans('Total').'</td>';
  835. print '<td class="right">'.price(price2num($totalET_credit + $totalET_debit, 'MT')).'</td>';
  836. print '<td class="right">'.price(price2num($totalIT_credit + $totalIT_debit, 'MT')).'</td>';
  837. print '<td class="right">'.price(price2num($totalVAT_credit + $totalVAT_debit, 'MT')).'</td>';
  838. print '<td colspan="4"></td>';
  839. if (isModEnabled('multicurrency')) {
  840. print '<td></td>';
  841. }
  842. print "</tr>\n";
  843. }
  844. print "</table>";
  845. print '</div>';
  846. }
  847. llxFooter();
  848. $db->close();