diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php
index fce70e56051..9a4b1d2e2f0 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -43,7 +43,7 @@ if ($user->societe_id > 0)
accessforbidden();
if (! $user->rights->accounting->ventilation->read)
accessforbidden();
-
+
// Filter
$year = $_GET["year"];
if ($year == 0) {
@@ -57,17 +57,17 @@ if ($year == 0) {
// Validate History
$action = GETPOST('action');
if ($action == 'validatehistory') {
-
+
$error = 0;
$db->begin();
-
+
if ($db->type == 'pgsql') {
- $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
- $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
+ $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet";
+ $sql1 .= " SET fk_code_ventilation = accnt.rowid";
$sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
- $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
+ $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
- $sql1 .= " AND fd.fk_code_ventilation = 0";
+ $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0";
} else {
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
@@ -75,9 +75,9 @@ if ($action == 'validatehistory') {
$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
$sql1 .= " AND fd.fk_code_ventilation = 0";
}
-
+
dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -90,7 +90,7 @@ if ($action == 'validatehistory') {
} elseif ($action == 'fixaccountancycode') {
$error = 0;
$db->begin();
-
+
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
$sql1 .= " SET fd.fk_code_ventilation = 0";
$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN ';
@@ -98,9 +98,9 @@ if ($action == 'validatehistory') {
$sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt';
$sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
-
+
dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -113,15 +113,15 @@ if ($action == 'validatehistory') {
} elseif ($action == 'cleanaccountancycode') {
$error = 0;
$db->begin();
-
+
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
$sql1 .= " SET fd.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)) . "')";
-
+
dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -198,7 +198,7 @@ $resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
$var = ! $var;
@@ -245,10 +245,10 @@ $resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
-
+
print '
| ' . $row[0] . ' | ';
for($i = 1; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' | ';
@@ -271,37 +271,34 @@ if (! empty($conf->margin->enabled)) {
print '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . ' | ';
}
print '' . $langs->trans("Total") . ' |
';
-
- $sql = "SELECT '" . $langs->trans("Vide") . "' AS 'Marge',";
+
+ $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) . ",";
}
- $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as 'Total'";
+ $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)) . "'";
-
+
if (! empty($conf->multicompany->enabled)) {
$sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
}
-
+
dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql);
$resql = $db->query($sql);
if ($resql) {
- $i = 0;
$num = $db->num_rows($resql);
-
- while ( $i < $num ) {
- $row = $db->fetch_row($resql);
-
+
+ while ($row = $db->fetch_row($resql)) {
+
print '| ' . $row[0] . ' | ';
for($i = 1; $i <= 12; $i ++) {
print '' . price($row[$i]) . ' | ';
}
print '' . price($row[13]) . ' | ';
print '
';
- $i ++;
}
$db->free($resql);
} else {
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 167f558d830..db73fe7e947 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -307,6 +307,7 @@ if ($result) {
// Ref Invoice
$facture_static->ref = $objp->facnumber;
$facture_static->id = $objp->facid;
+ $facture_static->type = $objp->ftype;
print '' . $facture_static->getNomUrl(1) . ' | ';
// Ref Product
$product_static->ref = $objp->product_ref;
diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php
index 5e87985ce61..bbef2a6dcc0 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -41,7 +41,7 @@ if ($user->societe_id > 0)
accessforbidden();
if (! $user->rights->accounting->ventilation->read)
accessforbidden();
-
+
// Filter
$year = $_GET["year"];
if ($year == 0) {
@@ -55,17 +55,17 @@ if ($year == 0) {
// Validate History
$action = GETPOST('action');
if ($action == 'validatehistory') {
-
+
$error = 0;
$db->begin();
-
+
if ($db->type == 'pgsql') {
- $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
- $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
+ $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
+ $sql1 .= " SET fk_code_ventilation = accnt.rowid";
$sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
- $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
+ $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
- $sql1 .= " AND fd.fk_code_ventilation = 0";
+ $sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0";
} else {
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
@@ -73,7 +73,7 @@ if ($action == 'validatehistory') {
$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
$sql1 .= " AND fd.fk_code_ventilation = 0";
}
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -86,7 +86,7 @@ if ($action == 'validatehistory') {
} elseif ($action == 'fixaccountancycode') {
$error = 0;
$db->begin();
-
+
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
$sql1 .= " SET fd.fk_code_ventilation = 0";
$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN ';
@@ -94,9 +94,9 @@ if ($action == 'validatehistory') {
$sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt';
$sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
$sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
-
+
dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -109,15 +109,15 @@ if ($action == 'validatehistory') {
} elseif ($action == 'cleanaccountancycode') {
$error = 0;
$db->begin();
-
+
$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
$sql1 .= " SET fd.fk_code_ventilation = 0";
$sql1 .= " WHERE fd.fk_facture_fourn IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture_fourn 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)) . "')";
-
+
dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-
+
$resql1 = $db->query($sql1);
if (! $resql1) {
$error ++;
@@ -154,35 +154,17 @@ $var = true;
print '';
print '| ' . $langs->trans("Account") . ' | ';
print '' . $langs->trans("Label") . ' | ';
-print '' . $langs->trans("JanuaryMin") . ' | ';
-print '' . $langs->trans("FebruaryMin") . ' | ';
-print '' . $langs->trans("MarchMin") . ' | ';
-print '' . $langs->trans("AprilMin") . ' | ';
-print '' . $langs->trans("MayMin") . ' | ';
-print '' . $langs->trans("JuneMin") . ' | ';
-print '' . $langs->trans("JulyMin") . ' | ';
-print '' . $langs->trans("AugustMin") . ' | ';
-print '' . $langs->trans("SeptemberMin") . ' | ';
-print '' . $langs->trans("OctoberMin") . ' | ';
-print '' . $langs->trans("NovemberMin") . ' | ';
-print '' . $langs->trans("DecemberMin") . ' | ';
+for($i = 1; $i <= 12; $i ++) {
+ print '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . ' | ';
+}
print '' . $langs->trans("Total") . ' |
';
-$sql = "SELECT IF(aa.account_number IS NULL, 'Non pointe', aa.account_number) AS 'code comptable',";
-$sql .= " IF(aa.label IS NULL, 'Non pointe', aa.label) AS 'Intitulé',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',";
-$sql .= " ROUND(SUM(ffd.total_ht),2) as 'Total'";
+$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') ." AS codecomptable,";
+$sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", '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) . ",";
+}
+$sql .= " ROUND(SUM(ffd.total_ht),2) 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";
@@ -194,31 +176,23 @@ if (! empty($conf->multicompany->enabled)) {
$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")";
}
-$sql .= " GROUP BY ffd.fk_code_ventilation";
+$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql);
$resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
-
+
$row = $db->fetch_row($resql);
$var = ! $var;
print '| ' . length_accountg($row[0]) . ' | ';
print '' . $row[1] . ' | ';
- print '' . price($row[2]) . ' | ';
- print '' . price($row[3]) . ' | ';
- print '' . price($row[4]) . ' | ';
- print '' . price($row[5]) . ' | ';
- print '' . price($row[6]) . ' | ';
- print '' . price($row[7]) . ' | ';
- print '' . price($row[8]) . ' | ';
- print '' . price($row[9]) . ' | ';
- print '' . price($row[10]) . ' | ';
- print '' . price($row[11]) . ' | ';
- print '' . price($row[12]) . ' | ';
+ for($i = 2; $i <= 12; $i ++) {
+ print '' . price($row[$i]) . ' | ';
+ }
print '' . price($row[13]) . ' | ';
print '' . price($row[14]) . ' | ';
print '
';
@@ -233,34 +207,16 @@ print "
\n";
print "
\n";
print '';
print '| ' . $langs->trans("Total") . ' | ';
-print '' . $langs->trans("JanuaryMin") . ' | ';
-print '' . $langs->trans("FebruaryMin") . ' | ';
-print '' . $langs->trans("MarchMin") . ' | ';
-print '' . $langs->trans("AprilMin") . ' | ';
-print '' . $langs->trans("MayMin") . ' | ';
-print '' . $langs->trans("JuneMin") . ' | ';
-print '' . $langs->trans("JulyMin") . ' | ';
-print '' . $langs->trans("AugustMin") . ' | ';
-print '' . $langs->trans("SeptemberMin") . ' | ';
-print '' . $langs->trans("OctoberMin") . ' | ';
-print '' . $langs->trans("NovemberMin") . ' | ';
-print '' . $langs->trans("DecemberMin") . ' | ';
+for($i = 1; $i <= 12; $i ++) {
+ print '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . ' | ';
+}
print '' . $langs->trans("Total") . ' |
';
-$sql = "SELECT '" . $langs->trans("CAHTF") . "' AS 'Total',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',";
-$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',";
-$sql .= " ROUND(SUM(ffd.total_ht),2) as '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) . ",";
+}
+$sql .= " ROUND(SUM(ffd.total_ht),2) 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)) . "'";
@@ -276,29 +232,20 @@ $resql = $db->query($sql);
if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
-
+
while ( $i < $num ) {
$row = $db->fetch_row($resql);
-
+
print '| ' . $row[0] . ' | ';
- print '' . $row[1] . ' | ';
- print '' . price($row[2]) . ' | ';
- print '' . price($row[3]) . ' | ';
- print '' . price($row[4]) . ' | ';
- print '' . price($row[5]) . ' | ';
- print '' . price($row[6]) . ' | ';
- print '' . price($row[7]) . ' | ';
- print '' . price($row[8]) . ' | ';
- print '' . price($row[9]) . ' | ';
- print '' . price($row[10]) . ' | ';
- print '' . price($row[11]) . ' | ';
- print '' . price($row[12]) . ' | ';
+ for($i = 1; $i <= 12; $i ++) {
+ print '' . price($row[$i]) . ' | ';
+ }
print '' . price($row[13]) . ' | ';
print '
';
-
+
$i ++;
}
-
+
$db->free($resql);
} else {
print $db->lasterror(); // Show last sql error
diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang
index a663d683fe3..056466706a1 100644
--- a/htdocs/langs/en_US/accountancy.lang
+++ b/htdocs/langs/en_US/accountancy.lang
@@ -158,6 +158,8 @@ OptionModeProductSell=Mode sales
OptionModeProductBuy=Mode purchases
OptionModeProductSellDesc=Show all products with no accounting account defined for sales.
OptionModeProductBuyDesc=Show all products with no accounting account defined for purchases.
+CleanFixHistory=Remove accountancy code from lines that not exists into charts of account
+CleanHistory=Reset all accountancy for selected year
## Dictionary
Range=Range of accounting account