';
if ($row[0] == 'tobind')
@@ -247,21 +260,25 @@ print '';
print '| ' . $langs->trans("Account") . ' | ';
print '' . $langs->trans("Label") . ' | ';
for($i = 1; $i <= 12; $i ++) {
- print '' . $langs->trans('MonthShort' . 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;
+ print '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' | ';
$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 '| ';
if ($row[0] == 'tobind')
@@ -281,6 +298,7 @@ if ($resql) {
}
else print length_accountg($row[0]);
print ' | ';
+
print '';
if ($row[0] == 'tobind')
{
@@ -315,19 +333,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
print '';
print '| ' . $langs->trans("Total") . ' | ';
for($i = 1; $i <= 12; $i ++) {
- print '' . $langs->trans('MonthShort' . 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;
+ print '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' | ';
$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 '| ' . $row[0] . ' | ';
for($i = 1; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' | ';
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("SuppliersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy');
-print $langs->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 '';
print '| ' . $langs->trans("Account") . ' | ';
print '' . $langs->trans("Label") . ' | ';
for($i = 1; $i <= 12; $i ++) {
- print '' . $langs->trans('MonthShort' . 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;
+ print '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' | ';
$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 '';
print '| ' . $langs->trans("Account") . ' | ';
print '' . $langs->trans("Label") . ' | ';
for($i = 1; $i <= 12; $i ++) {
- print '' . $langs->trans('MonthShort' . 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;
+ print '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' | ';
$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 '' . price($row[$i]) . ' | ';
}
print '' . price($row[13]) . ' | ';
@@ -313,19 +330,23 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
print '';
print '| ' . $langs->trans("Total") . ' | ';
for($i = 1; $i <= 12; $i ++) {
- print '' . $langs->trans('MonthShort' . 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;
+ print '' . $langs->trans('MonthShort' . str_pad($j, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' | ';
$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 '| ' . $row[0] . ' | ';
for($i = 1; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' | ';
@@ -344,7 +363,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange.
print '' . price($row[13]) . ' | ';
print ' ';
}
-
$db->free($resql);
} else {
print $db->lasterror(); // Show last sql error
| |