diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 393629ae505..0d74bf8a10a 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -142,8 +142,8 @@ if ($action == 'validatehistory') { }*/ // Customer Invoice lines (must be same request than into page list.php for manual binding) - $sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype, f.fk_facture_source,"; - $sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,"; + $sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype, f.situation_cycle_ref, f.fk_facture_source,"; + $sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.situation_percent, l.tva_tx as tva_tx_line, l.vat_src_code,"; $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,"; @@ -321,6 +321,10 @@ print ''.$langs->trans("DescVentilCustomer").''.$langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")).'
'; print '
'; +if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { + print info_admin($langs->trans("SorryThisModuleIsNotCompatibleWithTheExperimentalFeatureOfSituationInvoices")); + print "
"; +} $y = $year_current; @@ -395,6 +399,11 @@ if ($resql) { $num = $db->num_rows($resql); while ($row = $db->fetch_row($resql)) { + // TODO When INVOICE_USE_SITUATION = 1, values here are wrong. There is no compensation on bad stored amounts + //$situation_ratio = 1; + //if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { + //} + print ''; print ''; if ($row[0] == 'tobind') { @@ -512,6 +521,11 @@ if ($resql) { $num = $db->num_rows($resql); while ($row = $db->fetch_row($resql)) { + // TODO When INVOICE_USE_SITUATION = 1, values here are wrong. There is no compensation on bad stored amounts + //$situation_ratio = 1; + //if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { + //} + print ''; print ''; if ($row[0] == 'tobind') { @@ -623,7 +637,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print "\n"; print ''; - if (isModEnabled('margin')) { print "
\n"; print '
'; @@ -637,22 +650,41 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print ''.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).''; } print ''.$langs->trans("Total").''; - $sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,"; - for ($i = 1; $i <= 12; $i++) { - $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, - " (".$db->ifsql("fd.total_ht < 0", - " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", - " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").")", - 0).") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; - } - $sql .= " SUM(".$db->ifsql("fd.total_ht < 0", - " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", - " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").") as total"; + if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { + // With old situation invoice setup + $sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,"; + for ($i = 1; $i <= 12; $i++) { + $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, + " (".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", // TODO This is bugged, we must use the percent for the invoice and fd.situation_percent is cumulated percent ! + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").")", + 0).") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; + } + $sql .= " SUM(".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", // TODO This is bugged, we must use the percent for the invoice and fd.situation_percent is cumulated percent ! + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").") as total"; + } else { + $sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,"; + for ($i = 1; $i <= 12; $i++) { + $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, + " (".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty))").")", + 0).") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; + } + $sql .= " SUM(".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty)))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty))").") 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($search_date_start)."'"; diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index b8df8890a01..888cc568cf8 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -189,8 +189,8 @@ print '