-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX #30772 Accountancy document export - The project filter on expens…
…es report don't work (#30824) * FIX #30772 Accountancy document export - The project filter on expenses report don't work * Add SUM() if several lines exist on an expense report
- Loading branch information
Showing
1 changed file
with
30 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?php | ||
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <[email protected]> | ||
* Copyright (C) 2004-2019 Laurent Destailleur <[email protected]> | ||
* Copyright (C) 2017 Pierre-Henry Favre <[email protected]> | ||
* Copyright (C) 2020 Maxime DEMAREST <[email protected]> | ||
* Copyright (C) 2021 Gauthier VERDOL <[email protected]> | ||
* Copyright (C) 2022-2024 Alexandre Spangaro <[email protected]> | ||
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <[email protected]> | ||
* Copyright (C) 2004-2019 Laurent Destailleur <[email protected]> | ||
* Copyright (C) 2017 Pierre-Henry Favre <[email protected]> | ||
* Copyright (C) 2020 Maxime DEMAREST <[email protected]> | ||
* Copyright (C) 2021 Gauthier VERDOL <[email protected]> | ||
* Copyright (C) 2022-2024 Alexandre Spangaro <[email protected]> | ||
* | ||
* 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 | ||
|
@@ -206,17 +206,33 @@ | |
} | ||
} | ||
// Expense reports | ||
if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms']) && empty($projectid)) { | ||
if (GETPOST('selectexpensereports') && !empty($listofchoices['selectexpensereports']['perms'])) { | ||
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,"; | ||
$sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,"; | ||
$sql .= " t.multicurrency_code as currency, t.fk_user_author as fk_soc, t.date_fin as date, t.date_fin as date_due, 'ExpenseReport' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_DEBIT." as sens"; | ||
$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 (".$db->sanitize($entity == 1 ? '0,1' : $entity).')'; | ||
$sql .= " AND t.fk_statut <> ".ExpenseReport::STATUS_DRAFT; | ||
// if project filter is used on an expense report, | ||
// show only total_ht/total_tva/total_ttc of the line considered by the project | ||
if (!empty($projectid)) { | ||
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, SUM(td.total_ht) as total_ht, SUM(td.total_ttc) as total_ttc, SUM(td.total_tva) as total_vat,"; | ||
$sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,"; | ||
$sql .= " td.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"; | ||
$sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as t"; | ||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport_det as td ON t.rowid = td.fk_expensereport"; | ||
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = t.fk_user_author"; | ||
$sql .= " 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 (" . $db->sanitize($entity == 1 ? '0,1' : $entity) . ')'; | ||
$sql .= " AND t.fk_statut <> " . ExpenseReport::STATUS_DRAFT; | ||
$sql .= " AND fk_projet = ".((int) $projectid); | ||
} else { | ||
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat,"; | ||
$sql .= " 0 as localtax1, 0 as localtax2, 0 as revenuestamp,"; | ||
$sql .= " t.multicurrency_code as currency, t.fk_user_author as fk_soc, t.date_fin as date, t.date_fin as date_due, 'ExpenseReport' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, " . PAY_DEBIT . " as sens"; | ||
$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 (" . $db->sanitize($entity == 1 ? '0,1' : $entity) . ')'; | ||
$sql .= " AND t.fk_statut <> " . ExpenseReport::STATUS_DRAFT; | ||
} | ||
} | ||
// Donations | ||
if (GETPOST('selectdonations') && !empty($listofchoices['selectdonations']['perms'])) { | ||
|