From 82cfca1a80d04e883fbcc6658246042c67aeeafa Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 19 Jun 2022 00:48:06 +0200 Subject: [PATCH 1/8] Filter accounting reports by projects --- htdocs/compta/accounting-files.php | 44 ++++++++++++++++++++++++++--- htdocs/langs/en_US/accountancy.lang | 3 +- htdocs/langs/en_US/projects.lang | 3 +- htdocs/projet/card.php | 11 ++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 996ad22fbce..88dd1c317f2 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -47,6 +47,11 @@ 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'; +if (!empty($conf->project->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +} + // Constant to define payment sens const PAY_DEBIT = 0; const PAY_CREDIT = 1; @@ -64,6 +69,7 @@ $date_stopMonth = GETPOST('date_stopmonth', 'int'); $date_stopYear = GETPOST('date_stopyear', 'int'); $date_stop = dol_mktime(23, 59, 59, $date_stopMonth, $date_stopDay, $date_stopYear, 'tzuserrel'); $action = GETPOST('action', 'aZ09'); +$projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('comptafileslist', 'globallist')); @@ -175,6 +181,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Vendor invoices if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) { @@ -186,9 +193,10 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Expense reports - if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms'])) { + if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) and empty($projectid)) { if (!empty($sql)) { $sql .= " UNION ALL"; } @@ -208,6 +216,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datedon between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Payments of salaries if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) { @@ -219,6 +228,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Social contributions if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) { @@ -230,6 +240,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE t.date_ech between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Various payments if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) { @@ -240,9 +251,10 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; + if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Loan payments - if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms'])) { + if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) and empty($projectid)) { if (!empty($sql)) { $sql .= " UNION ALL"; } @@ -460,7 +472,19 @@ if ($result && $action == "dl" && !$error) { $log .= ','.$langs->transnoentitiesnoconv("Country"); $log .= ','.$langs->transnoentitiesnoconv("VATIntra"); $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; - $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip'; + $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel'); + if(!empty($projectid)) { + $sql = 'SELECT t.ref FROM '.MAIN_DB_PREFIX.'projet as t'; + $sql .= ' WHERE t.rowid = '.((int) $db->sanitize($projectid)); + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + $zipname .= '_'.$obj->ref; + } else { + dol_print_error($db); + } + } + $zipname .='_export.zip'; dol_delete_file($zipname); @@ -561,11 +585,13 @@ print $form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0, '', '', ' print "\n"; // Export is for current company only +$socid = 0; if (!empty($conf->multicompany->enabled) && is_object($mc)) { $mc->getInfo($conf->entity); print '('.$langs->trans("Entity").' : '; print ""; if (!empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES)) { + $socid = $mc->id; print $mc->select_entities(GETPOSTISSET('search_entity') ? GETPOST('search_entity', 'int') : $mc->id, 'search_entity', '', false, false, false, false, true); } else { print $mc->label; @@ -576,6 +602,16 @@ if (!empty($conf->multicompany->enabled) && is_object($mc)) { print '
'; +// Project filter +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); + $langs->load('projects'); + print ''.$langs->trans('Project').":"; + print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, ''); + print ''; + print '
'; +} + foreach ($listofchoices as $choice => $val) { if (empty($val['enabled'])) { continue; // list not qualified @@ -614,7 +650,7 @@ if (!empty($date_start) && !empty($date_stop)) { echo dol_print_date($date_start, 'day', 'tzuserrel')." - ".dol_print_date($date_stop, 'day', 'tzuserrel'); - print 'The exported ZIP file will contain the lists of requested items in CSV, as well as their attached files in their original format (PDF, ODT, DOCX...). ExportAccountingSourceDocHelp2=To export your journals, use the menu entry %s - %s. +ExportAccountingProjectHelp=Specify a project if you need an accounting report only for a specific project. Expense reports and loan payments are not included in project reports. VueByAccountAccounting=View by accounting account VueBySubAccountAccounting=View by accounting subaccount diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index e0fa85dd273..b4bd6f75d9a 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -293,4 +293,5 @@ LeadPublicFormDesc=You can enable here a public page to allow your prospects to EnablePublicLeadForm=Enable the public form for contact NewLeadbyWeb=Your message or request has been recorded. We will answer or contact your soon. NewLeadForm=New contact form -LeadFromPublicForm=Online lead from public form \ No newline at end of file +LeadFromPublicForm=Online lead from public form +ExportAccountingReportButtonLabel=Get report \ No newline at end of file diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 0cfe126d69b..f3b60e8593c 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -1280,6 +1280,17 @@ if ($action == 'create' && $user->rights->projet->creer) { } } + // Accounting Report + $accouting_module_activated = !empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled); + if ($accouting_module_activated && $object->statut != Project::STATUS_DRAFT) { + $start = dol_getdate((int)$object->date_start); + $end = dol_getdate((int)$object->date_end); + $url = DOL_URL_ROOT.'/compta/accounting-files.php?projectid='.$object->id; + if(!empty($object->date_start)) $url .= '&date_startday='.$start['mday'].'&date_startmonth='.$start['mon'].'&date_startyear='.$start['year']; + if(!empty($object->date_end)) $url .= '&date_stopday='.$end['mday'].'&date_stopmonth='.$end['mon'].'&date_stopyear='.$end['year']; + print dolGetButtonAction('', $langs->trans('ExportAccountingReportButtonLabel'), 'default', $url, ''); + } + // Modify if ($object->statut != Project::STATUS_CLOSED && $user->rights->projet->creer) { if ($userWrite > 0) { From eb4c42e98758abd117f88afc54e60ba59e1a1405 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 19 Jun 2022 19:21:51 +0200 Subject: [PATCH 2/8] Fixed AND operator to standardize code --- htdocs/compta/accounting-files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 88dd1c317f2..327298a033d 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -254,7 +254,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Loan payments - if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) and empty($projectid)) { + if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) { if (!empty($sql)) { $sql .= " UNION ALL"; } From 13511d983eeb1487530951b5aa232303a3cecf71 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 19 Jun 2022 17:27:15 +0000 Subject: [PATCH 3/8] Fixing style errors. --- htdocs/compta/accounting-files.php | 14 +++++++------- htdocs/projet/card.php | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 327298a033d..571d17bea08 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -181,7 +181,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Vendor invoices if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) { @@ -193,7 +193,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Expense reports if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) and empty($projectid)) { @@ -216,7 +216,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datedon between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Payments of salaries if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) { @@ -228,7 +228,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Social contributions if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) { @@ -240,7 +240,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE t.date_ech between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Various payments if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) { @@ -251,7 +251,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; - if(!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); } // Loan payments if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) { @@ -473,7 +473,7 @@ if ($result && $action == "dl" && !$error) { $log .= ','.$langs->transnoentitiesnoconv("VATIntra"); $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel'); - if(!empty($projectid)) { + if (!empty($projectid)) { $sql = 'SELECT t.ref FROM '.MAIN_DB_PREFIX.'projet as t'; $sql .= ' WHERE t.rowid = '.((int) $db->sanitize($projectid)); $resql = $db->query($sql); diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index f3b60e8593c..7a3690fb39f 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -1283,11 +1283,11 @@ if ($action == 'create' && $user->rights->projet->creer) { // Accounting Report $accouting_module_activated = !empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled); if ($accouting_module_activated && $object->statut != Project::STATUS_DRAFT) { - $start = dol_getdate((int)$object->date_start); - $end = dol_getdate((int)$object->date_end); + $start = dol_getdate((int) $object->date_start); + $end = dol_getdate((int) $object->date_end); $url = DOL_URL_ROOT.'/compta/accounting-files.php?projectid='.$object->id; - if(!empty($object->date_start)) $url .= '&date_startday='.$start['mday'].'&date_startmonth='.$start['mon'].'&date_startyear='.$start['year']; - if(!empty($object->date_end)) $url .= '&date_stopday='.$end['mday'].'&date_stopmonth='.$end['mon'].'&date_stopyear='.$end['year']; + if (!empty($object->date_start)) $url .= '&date_startday='.$start['mday'].'&date_startmonth='.$start['mon'].'&date_startyear='.$start['year']; + if (!empty($object->date_end)) $url .= '&date_stopday='.$end['mday'].'&date_stopmonth='.$end['mon'].'&date_stopyear='.$end['year']; print dolGetButtonAction('', $langs->trans('ExportAccountingReportButtonLabel'), 'default', $url, ''); } From 623917291085f3ee8293b0187eb9ea08c8bd8577 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sun, 19 Jun 2022 19:30:10 +0200 Subject: [PATCH 4/8] Fixed sanitization of int --- htdocs/compta/accounting-files.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 571d17bea08..a0a592c72e1 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -181,7 +181,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Vendor invoices if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) { @@ -193,7 +193,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Expense reports if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) and empty($projectid)) { @@ -216,7 +216,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datedon between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Payments of salaries if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) { @@ -228,7 +228,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Social contributions if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) { @@ -240,7 +240,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE t.date_ech between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Various payments if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) { @@ -251,7 +251,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; - if (!empty($projectid)) $sql .= " AND fk_projet = ".$db->sanitize($projectid); + if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Loan payments if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) { From 4e2bacb039af2b48a6e219c77f090533af44adea Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 19 Jun 2022 18:26:33 +0000 Subject: [PATCH 5/8] Fixing style errors. --- htdocs/compta/accounting-files.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index a0a592c72e1..e754af8c60e 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -181,7 +181,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Vendor invoices if (GETPOST('selectsupplierinvoices') && !empty($listofchoices['selectsupplierinvoices']['perms'])) { @@ -193,7 +193,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datef between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Expense reports if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) and empty($projectid)) { @@ -216,7 +216,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datedon between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Payments of salaries if (GETPOST('selectpaymentsofsalaries') && !empty($listofchoices['selectpaymentsofsalaries']['perms'])) { @@ -228,7 +228,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Social contributions if (GETPOST('selectsocialcontributions') && !empty($listofchoices['selectsocialcontributions']['perms'])) { @@ -240,7 +240,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " WHERE t.date_ech between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Various payments if (GETPOST('selectvariouspayment') && !empty($listofchoices['selectvariouspayment']['perms'])) { @@ -251,7 +251,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; - if(!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); + if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Loan payments if (GETPOST('selectloanspayment') && !empty($listofchoices['selectloanspayment']['perms']) && empty($projectid)) { From 6b421823f55de7b9f4466e47164da54a037826dc Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Sat, 25 Jun 2022 00:11:40 +0200 Subject: [PATCH 6/8] Use class instance instead of SQL req --- htdocs/compta/accounting-files.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index e754af8c60e..24d0c191d33 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -474,14 +474,10 @@ if ($result && $action == "dl" && !$error) { $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel'); if (!empty($projectid)) { - $sql = 'SELECT t.ref FROM '.MAIN_DB_PREFIX.'projet as t'; - $sql .= ' WHERE t.rowid = '.((int) $db->sanitize($projectid)); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - $zipname .= '_'.$obj->ref; - } else { - dol_print_error($db); + $project = new Project($db); + $project->fetch($projectid); + if ($project->ref) { + $zipname .= '_'.$project->ref; } } $zipname .='_export.zip'; From 1e1be459b3c21c0ad26b4a6d021f392e570f83be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jul 2022 21:15:28 +0200 Subject: [PATCH 7/8] Update accounting-files.php --- htdocs/compta/accounting-files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 24d0c191d33..ab8175c4d38 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -196,7 +196,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { if (!empty($projectid)) $sql .= " AND fk_projet = ".((int) $projectid); } // Expense reports - if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) and empty($projectid)) { + if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) && empty($projectid)) { if (!empty($sql)) { $sql .= " UNION ALL"; } From 2ffdb19bdff4cb506bb24dd31ead04dbd403aa90 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jul 2022 21:20:09 +0200 Subject: [PATCH 8/8] Because button are reserved for action on workflow, i comment this to not break consistency of position of feature. I will think to a better place... --- htdocs/projet/card.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 7a3690fb39f..d5db377fe08 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -1281,6 +1281,7 @@ if ($action == 'create' && $user->rights->projet->creer) { } // Accounting Report + /* $accouting_module_activated = !empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled); if ($accouting_module_activated && $object->statut != Project::STATUS_DRAFT) { $start = dol_getdate((int) $object->date_start); @@ -1290,7 +1291,8 @@ if ($action == 'create' && $user->rights->projet->creer) { if (!empty($object->date_end)) $url .= '&date_stopday='.$end['mday'].'&date_stopmonth='.$end['mon'].'&date_stopyear='.$end['year']; print dolGetButtonAction('', $langs->trans('ExportAccountingReportButtonLabel'), 'default', $url, ''); } - + */ + // Modify if ($object->statut != Project::STATUS_CLOSED && $user->rights->projet->creer) { if ($userWrite > 0) {