accounting-files.php 39 KB

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