From 0850570e951e98b1b50de544844f9a19e669a97a Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Tue, 12 May 2020 13:15:49 +0200 Subject: [PATCH 1/7] Fix and imporve some points for compta/accounting-flles.php * Fix zip generation for accouning-files if line has no document. The zip file generated if $filesarray contain a line with empty 'files' was unsustainable because it try to add empty files. * Add clickable link to jump on card for other line than Invoice and Supplier Invoice * Add various payment * Use label as ref for paiements of salaries line to display more explicit line --- htdocs/compta/accounting-files.php | 64 +++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 471637461f6..9c26cc0999c 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -37,8 +37,10 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php' require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; -$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips")); +$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks")); $date_start = GETPOST('date_start', 'alpha'); $date_startDay = GETPOST('date_startday', 'int'); @@ -176,7 +178,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Paiements of salaries if (GETPOST('selectpaymentsofsalaries')) { if (!empty($sql)) $sql .= " UNION ALL"; - $sql .= " SELECT t.rowid as id, t.entity, t.ref as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat, 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"; + $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, 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"; $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"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -191,6 +193,14 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; } + // Various payments + if (GETPOST('selectvariouspayment')) { + if (!empty($sql)) $sql .= " UNION ALL"; + $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 0 as fk_soc, t.datec as date, t.datep as date_due, 'VariousPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; + $sql .= " WHERE datec between ".$wheretail; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + } if ($sql) { $sql .= $db->order($sortfield, $sortorder); @@ -254,6 +264,12 @@ if (($action == 'searchfiles' || $action == 'dl')) { $upload_dir = $conf->tax->dir_output.'/'.$subdir; $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; break; + case "VariousPayment": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->bank->dir_output.'/'.$subdir; + $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F'; + break; default: $subdir = ''; $upload_dir = ''; @@ -394,11 +410,13 @@ if ($result && $action == "dl" && !$error) { foreach ($filesarray as $key => $file) { - foreach ($file['files'] as $filecursor) { - if (file_exists($filecursor["fullname"])) { - $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]); - } - } + if (!empty($file['files'])) { + foreach ($file['files'] as $filecursor) { + if (file_exists($filecursor["fullname"])) { + $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]); + } + } + } $log .= '"'.$langs->trans($file['item']).'"'; if (!empty($conf->multicompany->enabled) && is_object($mc)) @@ -448,6 +466,11 @@ $form = new Form($db); $userstatic = new User($db); $invoice = new Facture($db); $supplier_invoice = new FactureFournisseur($db); +$expensereport = new ExpenseReport($db); +$don = new Don($db); +$salary_payment = new PaymentSalary($db); +$charge_sociales = new ChargeSociales($db); +$various_payment = new PaymentVarious($db); $title = $langs->trans("ComptaFiles").' - '.$langs->trans("List"); $help_url = ''; @@ -492,7 +515,8 @@ $listofchoices = array( 'selectexpensereports'=>array('label'=>'ExpenseReports', 'lang'=>'trips'), 'selectdonations'=>array('label'=>'Donations', 'lang'=>'donation'), 'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'lang'=>'salaries'), - 'selectsocialcontributions'=>array('label'=>'SocialContributions') + 'selectsocialcontributions'=>array('label'=>'SocialContributions'), + 'selectvariouspayment'=>array('label'=>'VariousPayment') ); foreach ($listofchoices as $choice => $val) { $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : ''); @@ -592,14 +616,34 @@ if (!empty($date_start) && !empty($date_stop)) // Ref print ''; - if ($data['item'] == 'Invoice') { - $invoice->id = $data['id']; + if ($data['item'] == 'Invoice') { + $invoice->id = $data['id']; $invoice->ref = $data['ref']; print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); } elseif ($data['item'] == 'SupplierInvoice') { $supplier_invoice->id = $data['id']; $supplier_invoice->ref = $data['ref']; print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'ExpenseReport') { + $expensereport->id = $data['id']; + $expensereport->ref = $data['ref']; + print $expensereport->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'SalaryPayment') { + $salary_payment->id = $data['id']; + $salary_payment->ref = $data['ref']; + print $salary_payment->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'Donation') { + $don->id = $data['id']; + $don->ref = $data['ref']; + print $don->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'SocialContributions') { + $charge_sociales->id = $data['id']; + $charge_sociales->ref = $data['ref']; + print $charge_sociales->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'VariousPayment') { + $various_payment->id = $data['id']; + $various_payment->ref = $data['ref']; + print $various_payment->getNomUrl(1, '', 0, 0, '', 0, 0, 0); } else { print $data['ref']; } From b7ae5ffa1d085661bed4906ad4540562e6134219 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 13 May 2020 06:12:45 +0000 Subject: [PATCH 2/7] Fixing style errors. --- htdocs/compta/accounting-files.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 9c26cc0999c..66d36df25b2 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -616,37 +616,37 @@ if (!empty($date_start) && !empty($date_stop)) // Ref print ''; - if ($data['item'] == 'Invoice') { - $invoice->id = $data['id']; + if ($data['item'] == 'Invoice') { + $invoice->id = $data['id']; $invoice->ref = $data['ref']; print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'SupplierInvoice') { + } elseif ($data['item'] == 'SupplierInvoice') { $supplier_invoice->id = $data['id']; $supplier_invoice->ref = $data['ref']; print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'ExpenseReport') { + } elseif ($data['item'] == 'ExpenseReport') { $expensereport->id = $data['id']; $expensereport->ref = $data['ref']; print $expensereport->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'SalaryPayment') { + } elseif ($data['item'] == 'SalaryPayment') { $salary_payment->id = $data['id']; $salary_payment->ref = $data['ref']; print $salary_payment->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'Donation') { + } elseif ($data['item'] == 'Donation') { $don->id = $data['id']; $don->ref = $data['ref']; print $don->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'SocialContributions') { + } elseif ($data['item'] == 'SocialContributions') { $charge_sociales->id = $data['id']; $charge_sociales->ref = $data['ref']; print $charge_sociales->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } elseif ($data['item'] == 'VariousPayment') { + } elseif ($data['item'] == 'VariousPayment') { $various_payment->id = $data['id']; $various_payment->ref = $data['ref']; print $various_payment->getNomUrl(1, '', 0, 0, '', 0, 0, 0); - } else { + } else { print $data['ref']; - } + } print ''; // File link From fcb3b112d9b084defe46137c18f4eb67a016f190 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 13 May 2020 09:31:14 +0200 Subject: [PATCH 3/7] Fix use datep field for various payment in accouting-files.php --- htdocs/compta/accounting-files.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 66d36df25b2..c567c5e99ee 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2006 Rodolphe Quiedeville * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2017 Pierre-Henry Favre + * Copyright (C) 2020 Maxime DEMAREST * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -196,9 +197,9 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Various payments if (GETPOST('selectvariouspayment')) { if (!empty($sql)) $sql .= " UNION ALL"; - $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 0 as fk_soc, t.datec as date, t.datep as date_due, 'VariousPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum"; + $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 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"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; - $sql .= " WHERE datec between ".$wheretail; + $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; } From 5f400d27b4a7909efcad5f2914cdefddb4d64983 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 13 May 2020 15:01:32 +0200 Subject: [PATCH 4/7] Add preview file in compta/accounting-files.php --- htdocs/compta/accounting-files.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index c567c5e99ee..98d8c9b9983 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks")); @@ -232,6 +233,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); $upload_dir = $conf->facture->dir_output.'/'.$subdir; $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "facture"; break; case "SupplierInvoice": $tmpinvoicesupplier->fetch($objd->id); @@ -239,18 +241,21 @@ if (($action == 'searchfiles' || $action == 'dl')) { $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "facture_fournisseur"; break; case "ExpenseReport": $subdir = ''; $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "expensereport"; break; case "SalaryPayment": $subdir = ''; $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); $upload_dir = $conf->salaries->dir_output.'/'.$subdir; $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "salaries"; break; case "Donation": $tmpdonation->fetch($objp->id); @@ -258,18 +263,21 @@ if (($action == 'searchfiles' || $action == 'dl')) { $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); $upload_dir = $conf->don->dir_output.'/'.$subdir; $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "don"; break; case "SocialContributions": $subdir = ''; $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); $upload_dir = $conf->tax->dir_output.'/'.$subdir; $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "tax"; break; case "VariousPayment": $subdir = ''; $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); $upload_dir = $conf->bank->dir_output.'/'.$subdir; $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "banque"; break; default: $subdir = ''; @@ -336,7 +344,16 @@ if (($action == 'searchfiles' || $action == 'dl')) { if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) { $filesarray[$file['item'].'_'.$file['id']]['files'] = array(); } - $filesarray[$file['item'].'_'.$file['id']]['files'][] = array('link' => $link.$file['name'], 'name'=>$file['name'], 'ref'=>$file['ref'], 'fullname' => $file['fullname'], 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name']); + $filesarray[$file['item'].'_'.$file['id']]['files'][] = array( + 'link' => $link.urlencode($file['name']), + 'name'=>$file['name'], + 'ref'=>$file['ref'], + 'fullname' => $file['fullname'], + 'relpath' => '/'.$file['name'], + 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'], + 'modulepart' => $modulepart, + 'subdir' => $subdir, + ); //var_dump($file['item'].'_'.$file['id']); //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']); } @@ -463,7 +480,8 @@ if ($result && $action == "dl" && !$error) * View */ -$form = new Form($db); +$form = new form($db); +$formfile = new FormFile($db); $userstatic = new User($db); $invoice = new Facture($db); $supplier_invoice = new FactureFournisseur($db); @@ -654,8 +672,8 @@ if (!empty($date_start) && !empty($date_stop)) print ''; if (!empty($data['files'])) { - foreach ($data['files'] as $filecursor) { - print ''.($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']).'
'; + foreach ($data['files'] as $id=>$filecursor) { + print ''.($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']).' '.$formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name']).'
'; } } print "\n"; From 872518a91fa2f30318f298c5bb630af616ee32e4 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 13 May 2020 16:54:53 +0200 Subject: [PATCH 5/7] Add total by credit/debit for accounting-file.php --- htdocs/compta/accounting-files.php | 104 ++++++++++++++++------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 98d8c9b9983..64332671b5d 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -42,6 +42,10 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +// Constant to define payment sens +const PAY_DEBIT = 0; +const PAY_CREDIT = 1; + $langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks")); $date_start = GETPOST('date_start', 'alpha'); @@ -144,7 +148,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Customer invoices if (GETPOST('selectinvoices')) { if (!empty($sql)) $sql .= " UNION ALL"; - $sql .= "SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total as total_ht, t.total_ttc, t.tva as total_vat, 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"; + $sql .= "SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total as total_ht, t.total_ttc, t.tva as total_vat, 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"; $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"; $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -153,7 +157,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Vendor invoices if (GETPOST('selectsupplierinvoices')) { if (!empty($sql)) $sql .= " UNION ALL"; - $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.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"; + $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.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"; $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"; $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -162,7 +166,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Expense reports if (GETPOST('selectexpensereports')) { if (!empty($sql)) $sql .= " UNION ALL"; - $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.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"; + $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.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"; $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"; $sql .= " WHERE date_fin between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -171,7 +175,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Donations if (GETPOST('selectdonations')) { if (!empty($sql)) $sql .= " UNION ALL"; - $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat, 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"; + $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat, 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"; $sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country"; $sql .= " WHERE datedon between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -180,7 +184,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Paiements of salaries if (GETPOST('selectpaymentsofsalaries')) { if (!empty($sql)) $sql .= " UNION ALL"; - $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, 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"; + $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, 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"; $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"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -189,7 +193,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Social contributions if (GETPOST('selectsocialcontributions')) { if (!empty($sql)) $sql .= " UNION ALL"; - $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_tva, 0 as fk_soc, t.date_creation as date, t.date_ech as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum"; + $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_tva, 0 as fk_soc, t.date_creation as date, t.date_ech as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens"; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t"; $sql .= " WHERE date_creation between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -198,7 +202,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Various payments if (GETPOST('selectvariouspayment')) { if (!empty($sql)) $sql .= " UNION ALL"; - $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 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"; + $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 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"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -311,6 +315,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $nofile['thirdparty_code'] = $objd->thirdparty_code; $nofile['country_code'] = $objd->country_code; $nofile['vatnum'] = $objd->vatnum; + $nofile['sens'] = $objd->sens; $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile; } @@ -329,11 +334,11 @@ if (($action == 'searchfiles' || $action == 'dl')) { $file['ref'] = ($objd->ref ? $objd->ref : $objd->id); $file['fk'] = $objd->fk_soc; $file['item'] = $objd->item; - $file['thirdparty_name'] = $objd->thirdparty_name; $file['thirdparty_code'] = $objd->thirdparty_code; $file['country_code'] = $objd->country_code; $file['vatnum'] = $objd->vatnum; + $file['sens'] = $objd->sens; // Save record into array (only the first time it is found) if (empty($filesarray[$file['item'].'_'.$file['id']])) { @@ -417,7 +422,8 @@ if ($result && $action == "dl" && !$error) $log .= ','.$langs->transnoentitiesnoconv("ThirdParty"); $log .= ','.$langs->transnoentitiesnoconv("Code"); $log .= ','.$langs->transnoentitiesnoconv("Country"); - $log .= ','.$langs->transnoentitiesnoconv("VATIntra")."\n"; + $log .= ','.$langs->transnoentitiesnoconv("VATIntra"); + $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc')."-".dol_print_date($date_stop, 'dayrfc').'_export.zip'; dol_delete_file($zipname); @@ -454,6 +460,7 @@ if ($result && $action == "dl" && !$error) $log .= ',"'.$file['thirdparty_code'].'"'; $log .= ',"'.$file['country_code'].'"'; $log .= ',"'.$file['vatnum'].'"'; + $log .= ',"'.$file['sens'].'"'; $log .= "\n"; } $zip->addFromString('transactions.csv', $log); @@ -605,11 +612,12 @@ if (!empty($date_start) && !empty($date_stop)) { // Sort array by date ASC to calculate balance - $totalET = 0; - $totalIT = 0; - $totalVAT = 0; - $totalDebit = 0; - $totalCredit = 0; + $totalET_debit = 0; + $totalIT_debit = 0; + $totalVAT_debit = 0; + $totalET_credit = 0; + $totalIT_credit = 0; + $totalVAT_credit = 0; // Display array foreach ($TData as $data) @@ -682,11 +690,11 @@ if (!empty($date_start) && !empty($date_stop)) print ''.$data['paid'].''; // Total ET - print ''.price($data['amount_ht'])."\n"; + print ''.price($data['sens']?$data['amount_ht']:-$data['amount_ht'])."\n"; // Total IT - print ''.price($data['amount_ttc'])."\n"; + print ''.price($data['sens']?$data['amount_ttc']:-$data['amount_ttc'])."\n"; // Total VAT - print ''.price($data['amount_vat'])."\n"; + print ''.price($data['sens']?$data['amount_vat']:-$data['amount_vat'])."\n"; print ''.$data['thirdparty_name']."\n"; @@ -696,42 +704,42 @@ if (!empty($date_start) && !empty($date_stop)) print ''.$data['vatnum']."\n"; - // Debit - //print ''.(($data['amount_ttc'] > 0) ? price(abs($data['amount_ttc'])) : '')."\n"; - // Credit - //print ''.(($data['amount_ttc'] > 0) ? '' : price(abs($data['amount_ttc'])))."\n"; - - $totalET += $data['amount_ht']; - $totalIT += $data['amount_ttc']; - $totalVAT += $data['amount_vat']; - - $totalDebit += ($data['amount_ttc'] > 0) ? abs($data['amount_ttc']) : 0; - $totalCredit += ($data['amount_ttc'] > 0) ? 0 : abs($data['amount_ttc']); - - // Balance - //print ''.price($data['balance'])."\n"; + if ($data['sens']) { + $totalET_credit += $data['amount_ht']; + $totalIT_credit += $data['amount_ttc']; + $totalVAT_credit += $data['amount_vat']; + } else { + $totalET_debit -= $data['amount_ht']; + $totalIT_debit -= $data['amount_ttc']; + $totalVAT_debit -= $data['amount_vat']; + } print "\n"; } + // Total credits print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''.price(price2num($totalET, 'MT')).''; - print ''.price(price2num($totalIT, 'MT')).''; - print ''.price(price2num($totalVAT, 'MT')).''; - print ''; - print ''; - print ''; - print ''; - /*print ''.price($totalDebit).''; - print ''.price($totalCredit).''; - print ''.price(price2num($totalDebit - $totalCredit, 'MT')).''; - */ + print ''.$langs->trans('Total').' '.$langs->trans('Income').''; + print ''.price(price2num($totalET_credit, 'MT')).''; + print ''.price(price2num($totalIT_credit, 'MT')).''; + print ''.price(price2num($totalVAT_credit, 'MT')).''; + print ''; + print "\n"; + // Total debits + print ''; + print ''.$langs->trans('Total').' '.$langs->trans('Outcome').''; + print ''.price(price2num($totalET_debit, 'MT')).''; + print ''.price(price2num($totalIT_debit, 'MT')).''; + print ''.price(price2num($totalVAT_debit, 'MT')).''; + print ''; + print "\n"; + // Balance + print ''; + print ''.$langs->trans('Total').''; + print ''.price(price2num($totalET_credit+$totalET_debit, 'MT')).''; + print ''.price(price2num($totalIT_credit+$totalIT_debit, 'MT')).''; + print ''.price(price2num($totalVAT_credit+$totalVAT_debit, 'MT')).''; + print ''; print "\n"; } } From ee6e717f4632716ce1e4d6a12301882b17850524 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 13 May 2020 17:47:30 +0200 Subject: [PATCH 6/7] Add payment loan in accounting-files.php --- htdocs/compta/accounting-files.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 64332671b5d..a97a0a815b7 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -41,12 +41,13 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; // Constant to define payment sens const PAY_DEBIT = 0; const PAY_CREDIT = 1; -$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks")); +$langs->loadLangs(array("accountancy", "bills", "companies", "salaries", "compta", "trips", "banks", "loan")); $date_start = GETPOST('date_start', 'alpha'); $date_startDay = GETPOST('date_startday', 'int'); @@ -207,6 +208,14 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; } + // Loan payments + if (GETPOST('selectloanspayment')) { + if (!empty($sql)) $sql .= " UNION ALL"; + $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_tva, 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"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan"; + $sql .= " WHERE datep between ".$wheretail; + $sql .= " AND l.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + } if ($sql) { $sql .= $db->order($sortfield, $sortorder); @@ -283,6 +292,13 @@ if (($action == 'searchfiles' || $action == 'dl')) { $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F'; $modulepart = "banque"; break; + case "LoanPayment": + // Loan payment has no linked file + $subdir = ''; + $upload_dir = $conf->loan->dir_output.'/'.$subdir; + $link = ""; + $modulepart = ""; + break; default: $subdir = ''; $upload_dir = ''; @@ -497,6 +513,7 @@ $don = new Don($db); $salary_payment = new PaymentSalary($db); $charge_sociales = new ChargeSociales($db); $various_payment = new PaymentVarious($db); +$payment_loan = new PaymentLoan($db); $title = $langs->trans("ComptaFiles").' - '.$langs->trans("List"); $help_url = ''; @@ -542,7 +559,8 @@ $listofchoices = array( 'selectdonations'=>array('label'=>'Donations', 'lang'=>'donation'), 'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'lang'=>'salaries'), 'selectsocialcontributions'=>array('label'=>'SocialContributions'), - 'selectvariouspayment'=>array('label'=>'VariousPayment') + 'selectvariouspayment'=>array('label'=>'VariousPayment'), + 'selectloanspayment'=>array('label'=>'PaymentLoan'), ); foreach ($listofchoices as $choice => $val) { $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : ''); @@ -671,6 +689,10 @@ if (!empty($date_start) && !empty($date_stop)) $various_payment->id = $data['id']; $various_payment->ref = $data['ref']; print $various_payment->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + } elseif ($data['item'] == 'LoanPayment') { + $payment_loan->id = $data['id']; + $payment_loan->ref = $data['ref']; + print $payment_loan->getNomUrl(1, '', 0, 0, '', 0, 0, 0); } else { print $data['ref']; } From ac0b735131af206c67d34420ed38a3fff43a8482 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 13 May 2020 18:01:00 +0200 Subject: [PATCH 7/7] Fix use date_ech for social contributions in accounting-file.php --- htdocs/compta/accounting-files.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index a97a0a815b7..f9bc453d999 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -194,9 +194,9 @@ if (($action == 'searchfiles' || $action == 'dl')) { // Social contributions if (GETPOST('selectsocialcontributions')) { if (!empty($sql)) $sql .= " UNION ALL"; - $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_tva, 0 as fk_soc, t.date_creation as date, t.date_ech as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens"; + $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_tva, 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"; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t"; - $sql .= " WHERE date_creation between ".$wheretail; + $sql .= " WHERE t.date_ech between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; }