From dab8dbd671a375e79956ef32585b8df644142b12 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Mar 2018 12:31:08 +0200 Subject: [PATCH 1/2] FIX Binding pages must start on fiscal month not calendar month --- htdocs/accountancy/customer/index.php | 99 ++++++++++++---------- htdocs/accountancy/expensereport/index.php | 88 +++++++++++-------- htdocs/accountancy/supplier/index.php | 80 ++++++++++------- 3 files changed, 157 insertions(+), 110 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 0ccb799aaa0..4001208819a 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -47,15 +47,24 @@ if ($user->societe_id > 0) if (! $user->rights->accounting->bind->write) accessforbidden(); -// Filter -$year = GETPOST("year",'int'); -if ($year == 0) { - $year_current = strftime("%Y", time()); - $year_start = $year_current; -} else { - $year_current = $year; - $year_start = $year; + +$month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); +if (GETPOST("year",'int')) $year_start = GETPOST("year",'int'); +else +{ + $year_start = dol_print_date(dol_now(), '%Y'); + if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year } +$year_end = $year_start + 1; +$month_end = $month_start - 1; +if ($month_end < 1) +{ + $month_end = 12; + $year_end--; +} +$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); +$search_date_end = dol_get_last_day($year_end, $month_end); +$year_current = $year_start; // Validate History $action = GETPOST('action','aZ09'); @@ -116,8 +125,8 @@ if ($action == 'validatehistory') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; $sql1.= " SET fk_code_ventilation = 0"; $sql1.= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f"; - $sql1.= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; - $sql1.= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'"; + $sql1.= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; + $sql1.= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; $sql1.= " AND f.entity IN (" . getEntity('accountancy') . ")"; $sql1.=")"; @@ -170,25 +179,6 @@ print $langs->trans("DescVentilCustomer") . '
'; print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; -$sql = "SELECT count(*) FROM " . MAIN_DB_PREFIX . "facturedet as fd"; -$sql .= " , " . MAIN_DB_PREFIX . "facture as f"; -$sql .= " WHERE fd.fk_code_ventilation = 0"; -$sql .= " AND f.rowid = fd.fk_facture"; -$sql .= " AND f.fk_statut > 0"; -if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; -} else { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; -} -$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy - -dol_syslog('htdocs/accountancy/customer/index.php'); -$result = $db->query($sql); -if ($result) { - $row = $db->fetch_row($result); - $nbfac = $row[0]; - $db->free($result); -} $y = $year_current; @@ -203,21 +193,25 @@ print ''; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') . " AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(fd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; -$sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND f.fk_statut > 0"; $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; @@ -263,6 +257,7 @@ if ($resql) { print "
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
\n"; print ''; + print '
'; @@ -273,21 +268,25 @@ print ''; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') . " AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(fd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; -$sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -321,7 +320,7 @@ if ($resql) { else print $row[1]; print ''; - for($i = 2; $i <= 12; $i ++) { + for($i = 2; $i <= 12; $i++) { print ''; } print ''; @@ -347,19 +346,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . price($row[$i]) . '' . price($row[13]) . '
'; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT '" . $langs->trans("TotalVente") . "' AS total,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(fd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; - $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; + $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -395,19 +398,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print '
' . $langs->trans("TotalVente") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
'; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; - $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; + $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index 60ab93c054d..470c54f2fab 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -38,27 +38,36 @@ $langs->load("accountancy"); // Security check if (empty($conf->accounting->enabled)) { - accessforbidden(); + accessforbidden(); } if ($user->societe_id > 0) accessforbidden(); if (! $user->rights->accounting->bind->write) accessforbidden(); -// Filter -$year = GETPOST('year', 'int'); -if ($year == 0) { - $year_current = strftime("%Y", time()); - $year_start = $year_current; -} else { - $year_current = $year; - $year_start = $year; +$month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); +if (GETPOST("year",'int')) $year_start = GETPOST("year",'int'); +else +{ + $year_start = dol_print_date(dol_now(), '%Y'); + if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year } +$year_end = $year_start + 1; +$month_end = $month_start - 1; +if ($month_end < 1) +{ + $month_end = 12; + $year_end--; +} +$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); +$search_date_end = dol_get_last_day($year_end, $month_end); +$year_current = $year_start; // Validate History $action = GETPOST('action','aZ09'); + /* * Actions */ @@ -113,8 +122,8 @@ if ($action == 'validatehistory') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql1.= " SET fk_code_ventilation = 0"; $sql1.= " WHERE erd.fk_expensereport IN ( SELECT er.rowid FROM " . MAIN_DB_PREFIX . "expensereport as er"; - $sql1.= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; - $sql1.= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'"; + $sql1.= " WHERE er.date_debut >= '" . $db->idate($search_date_start) . "'"; + $sql1.= " AND er.date_debut <= '" . $db->idate($search_date_end) . "'"; $sql1.= " AND er.entity IN (" . getEntity('accountancy') . ")"; $sql1.=")"; @@ -131,6 +140,7 @@ if ($action == 'validatehistory') { } } + /* * View */ @@ -142,10 +152,6 @@ $textnextyear = ' trans("DescVentilExpenseReport") . '
'; -print $langs->trans("DescVentilExpenseReportMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; -print '
'; - // Clean database $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; @@ -166,6 +172,10 @@ if (! $resql1) { } // End clean database +print $langs->trans("DescVentilExpenseReport") . '
'; +print $langs->trans("DescVentilExpenseReportMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; +print '
'; + $y = $year_current; @@ -175,27 +185,30 @@ $buttonreset = '
'; print '
' . $langs->trans("TotalMarge") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
'; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(er.date_debut)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(er.date_debut)=' . $j, 'erd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(erd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation"; -$sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE er.date_debut >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND er.date_debut <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")"; $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; @@ -204,9 +217,9 @@ $sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label"; dol_syslog('/accountancy/expensereport/index.php:: sql=' . $sql); $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $db->num_rows($resql); - while ( $row = $db->fetch_row($resql)) { + while ( $row = $db->fetch_row($resql)) { print '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
'; if ($row[0] == 'tobind') @@ -247,21 +260,25 @@ print ''; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(er.date_debut)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(er.date_debut)=' . $j, 'erd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " ROUND(SUM(erd.total_ht),2) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation"; -$sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE er.date_debut >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND er.date_debut <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")"; $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NOT NULL"; @@ -270,9 +287,9 @@ $sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label"; dol_syslog('htdocs/accountancy/expensereport/index.php'); $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $db->num_rows($resql); - while ( $row = $db->fetch_row($resql)) { + while ( $row = $db->fetch_row($resql)) { print ''; + print '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
'; if ($row[0] == 'tobind') @@ -281,6 +298,7 @@ if ($resql) { } else print length_accountg($row[0]); print ''; if ($row[0] == 'tobind') { @@ -315,19 +333,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT '" . $langs->trans("TotalExpenseReport") . "' AS label,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(er.date_create)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(er.date_create)=' . $j, 'erd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(erd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; - $sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " WHERE er.date_debut >= '" . $db->idate($search_date_start) . "'"; + $sql .= " AND er.date_debut <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")"; $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy @@ -336,7 +358,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. if ($resql) { $num = $db->num_rows($resql); - while ( $row = $db->fetch_row($resql)) { + while ($row = $db->fetch_row($resql)) { print ''; for($i = 1; $i <= 12; $i ++) { print ''; diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 64993490537..9635d765578 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -38,25 +38,35 @@ $langs->load("accountancy"); // Security check if (empty($conf->accounting->enabled)) { - accessforbidden(); + accessforbidden(); } if ($user->societe_id > 0) accessforbidden(); if (! $user->rights->accounting->bind->write) accessforbidden(); -// Filter -$year = GETPOST("year",'int'); -if ($year == 0) { - $year_current = strftime("%Y", time()); - $year_start = $year_current; -} else { - $year_current = $year; - $year_start = $year; + +$month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); +if (GETPOST("year",'int')) $year_start = GETPOST("year",'int'); +else +{ + $year_start = dol_print_date(dol_now(), '%Y'); + if (dol_print_date(dol_now(), '%m') < $month_start) $year_start--; // If current month is lower that starting fiscal month, we start last year } +$year_end = $year_start + 1; +$month_end = $month_start - 1; +if ($month_end < 1) +{ + $month_end = 12; + $year_end--; +} +$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); +$search_date_end = dol_get_last_day($year_end, $month_end); +$year_current = $year_start; // Validate History -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action','aZ09'); + /* @@ -141,10 +151,6 @@ $textnextyear = ' trans("DescVentilSupplier") . '
'; -print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; -print '
'; - // Clean database $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; @@ -165,6 +171,9 @@ if (! $resql1) { } // End clean database +print $langs->trans("DescVentilSupplier") . '
'; +print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; +print '
'; $y = $year_current; @@ -179,21 +188,25 @@ print '
' . $langs->trans("Total") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price($row[$i]) . '
'; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $j, 'ffd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation"; -$sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE ff.datef >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND ff.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND ff.fk_statut > 0"; $sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; @@ -245,21 +258,25 @@ print '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
'; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') ." AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $j, 'ffd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation"; -$sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; -$sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; +$sql .= " WHERE ff.datef >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND ff.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND ff.fk_statut > 0"; $sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NOT NULL"; @@ -286,7 +303,7 @@ if ($resql) { } else print $row[1]; print ''; - for($i = 2; $i <= 12; $i ++) { + for($i = 2; $i <= 12; $i++) { print ''; } print ''; @@ -313,19 +330,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . price($row[$i]) . '' . price($row[13]) . '
'; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + print ''; } print ''; $sql = "SELECT '" . $langs->trans("CAHTF") . "' AS label,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; + if ($j > 12) $j-=12; + $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $j, 'ffd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; - $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " WHERE ff.datef >= '" . $db->idate($search_date_start) . "'"; + $sql .= " AND ff.datef <= '" . $db->idate($search_date_end) . "'"; $sql .= " AND ff.fk_statut > 0"; $sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy @@ -334,9 +355,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. if ($resql) { $num = $db->num_rows($resql); - while ( $row = $db->fetch_row($resql)) { - - + while ($row = $db->fetch_row($resql)) { print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -344,7 +363,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print ''; print ''; } - $db->free($resql); } else { print $db->lasterror(); // Show last sql error From 56944115cb67407c6cb20b7f37fa2cf6471ee455 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Mar 2018 12:46:15 +0200 Subject: [PATCH 2/2] Hide a very dangerous feature. Should be useless. --- htdocs/accountancy/customer/index.php | 3 ++- htdocs/accountancy/expensereport/index.php | 3 ++- htdocs/accountancy/supplier/index.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 4001208819a..b7d61674fd8 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -183,7 +183,8 @@ print '
'; $y = $year_current; $buttonbind = '
' . $langs->trans("ValidateHistory") . ''; -$buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; +$buttonreset = ''; +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index 470c54f2fab..0768ee01bf8 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -180,7 +180,8 @@ print '
'; $y = $year_current; $buttonbind = '' . $langs->trans("ValidateHistory") . ''; -$buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; +$buttonreset = ''; +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 9635d765578..1425dde58f7 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -178,7 +178,8 @@ print '
'; $y = $year_current; $buttonbind = '' . $langs->trans("ValidateHistory") . ''; -$buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; +$buttonreset = ''; +if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
' . $langs->trans("Total") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price($row[$i]) . '' . price($row[13]) . '