diff --git a/ChangeLog b/ChangeLog index 15f31a52fbe..22b71858b4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -142,6 +142,9 @@ Fix: Delete linked element to supplier invoice when deleted Fix: [ bug #1061 ] Bad info shipped products Fix: [ bug #1062 ] Documents lost in propals and contracts validating Fix: Supplier price displayed on document lines and margin infos didnt take discount +Fix: sorting on qty did not work in supplier product list +Fix: there was no escaping on filter fields in supplier product list +Fix: bugs on margin reports and better margin calculation on credit notes Qual: Add travis-ci integration @@ -243,6 +246,8 @@ backport commit 384e3812eb73a15adafb472cacfb93397a54459b to fix W3C/edit contrac ***** ChangeLog for 3.3.4 compared to 3.3.3 ***** - Fix: [ bug #1001 ] Social Contribution : State not correct +- Fix: Better management of pdf generation when tcpdf is not available. +- Fix: Change to be more debian compliant natively. ***** ChangeLog for 3.3.3 compared to 3.3.2 ***** - Fix: [ bug #903 ] Fatal error: Call to undefined function dol_get_first_day() in htdocs/commande/liste.php diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index a8b8a8dfdb6..fbe3fb98bbf 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -315,7 +315,7 @@ class pdf_azur extends ModelePDFPropales $posYAfterDescription=0; // We start with Photo of product line - if (($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo to high, we moved completely on new page + if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page { $pdf->AddPage('','',true); if (! empty($tplidx)) $pdf->useTemplate($tplidx); diff --git a/htdocs/fourn/product/liste.php b/htdocs/fourn/product/liste.php index d189ea9f343..7806fdab1bd 100644 --- a/htdocs/fourn/product/liste.php +++ b/htdocs/fourn/product/liste.php @@ -108,6 +108,10 @@ else { $sql .= natural_search('p.ref', $sref); } + if ($sRefSupplier) + { + $sql .= natural_search('ppf.ref_fourn', $sRefSupplier); + } if ($snom) { $sql .= natural_search('p.label', $snom); @@ -174,7 +178,7 @@ if ($resql) print_liste_field_titre($langs->trans("Label"),"liste.php", "p.label",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),"liste.php", "ppf.fk_soc",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("BuyingPrice"),"liste.php", "ppf.price",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("QtyMin"),"liste.php", "ppf.qty",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("QtyMin"),"liste.php", "ppf.quantity",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("UnitPrice"),"liste.php", "ppf.unitprice",$param,"",'align="right"',$sortfield,$sortorder); print "\n"; diff --git a/htdocs/install/etape2.php b/htdocs/install/etape2.php index 92b5f2111b7..a9d5b3ea85a 100644 --- a/htdocs/install/etape2.php +++ b/htdocs/install/etape2.php @@ -35,7 +35,7 @@ $ok = 0; $err=error_reporting(); error_reporting(0); // Disable all errors //error_reporting(E_ALL); -@set_time_limit(300); // Need more than 240 on Windows 7/64 +@set_time_limit(900); // Need 900 on some OS like Windows 7/64 error_reporting($err); $action=GETPOST('action'); diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index 459537e1506..7125c5da976 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -101,37 +101,17 @@ print ''; print ''; print ''; print ''; - -// Total Margin -print ''.$langs->trans("TotalMargin").''; -print ''; // set by jquery (see below) -print ''; - -// Margin Rate -if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { - print ''.$langs->trans("MarginRate").''; - print ''; // set by jquery (see below) - print ''; -} - -// Mark Rate -if (! empty($conf->global->DISPLAY_MARK_RATES)) { - print ''.$langs->trans("MarkRate").''; - print ''; // set by jquery (see below) - print ''; -} - print ""; print ''; -$sql = "SELECT s.nom, s.rowid as socid, s.code_client, s.client, u.rowid as agent,"; -$sql.= " u.login, u.lastname, u.firstname,"; +$sql = "SELECT s.rowid as socid, s.nom, s.code_client, s.client, "; +$sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; $sql.= " sum(d.total_ht) as selling_price,"; -$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, "; -$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge" ; +$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,"; +$sql.= " sum(".$db->ifsql('d.total_ht <=0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge" ; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE); +$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE); $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ", ".MAIN_DB_PREFIX."user as u"; @@ -155,13 +135,9 @@ if (!empty($startdate)) if (!empty($enddate)) $sql.= " AND f.datef <= '".$enddate."'"; $sql .= " AND d.buy_price_ht IS NOT NULL"; -if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) - $sql .= " AND d.buy_price_ht <> 0"; -if ($agentid > 0) - $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname, f.type"; -else - $sql.= " GROUP BY u.rowid"; -$sql.= " ORDER BY $sortfield $sortorder "; +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; +$sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; +$sql.= " ORDER BY ".$sortfield." ".$sortorder; // TODO: calculate total to display then restore pagination //$sql.= $db->plimit($conf->liste_limit +1, $offset); @@ -179,9 +155,9 @@ if ($result) print ''; if ($agentid > 0) - print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); else - print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); @@ -200,12 +176,25 @@ if ($result) if ($num > 0) { $var=true; + while ($i < $num /*&& $i < $conf->liste_limit*/) { $objp = $db->fetch_object($result); - $marginRate = ($objp->buying_price != 0)?(100 * round($objp->marge / $objp->buying_price, 5)):''; - $markRate = ($objp->selling_price != 0)?(100 * round($objp->marge / $objp->selling_price, 5)):''; + $pa = $objp->buying_price; + $pv = $objp->selling_price; + $marge = $objp->marge; + + if ($marge < 0) + { + $marginRate = ($pa != 0)?-1*(100 * round($marge / $pa, 5)):'' ; + $markRate = ($pv != 0)?-1*(100 * round($marge / $pv, 5)):'' ; + } + else + { + $marginRate = ($pa != 0)?(100 * round($marge / $pa, 5)):'' ; + $markRate = ($pv != 0)?(100 * round($marge / $pv, 5)):'' ; + } $var=!$var; @@ -220,9 +209,10 @@ if ($result) $userstatic->fetch($objp->agent); print "".$userstatic->getFullName($langs,0,0,0)."\n"; } - print "".price($objp->selling_price)."\n"; - print "".price($objp->buying_price)."\n"; - print "".price($objp->marge)."\n"; + + print "".price($pv)."\n"; + print "".price($pa)."\n"; + print "".price($marge)."\n"; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) print "".(($marginRate === '')?'n/a':price($marginRate)."%")."\n"; if (! empty($conf->global->DISPLAY_MARK_RATES)) @@ -230,30 +220,10 @@ if ($result) print "\n"; $i++; - $cumul_achat += round($objp->buying_price, $rounding); $cumul_vente += round($objp->selling_price, $rounding); } } - - // affichage totaux marges - $var=!$var; - $totalMargin = $cumul_vente - $cumul_achat; - $marginRate = ($cumul_achat != 0)?(100 * round($totalMargin / $cumul_achat, 5)):''; - $markRate = ($cumul_vente != 0)?(100 * round($totalMargin / $cumul_vente, 5)):''; - print ''; - print ''; - print $langs->trans('Total'); - print ""; - print "".price($cumul_vente)."\n"; - print "".price($cumul_achat)."\n"; - print "".price($totalMargin)."\n"; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print "".(($marginRate === '')?'n/a':price($marginRate)."%")."\n"; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print "".(($markRate === '')?'n/a':price($markRate)."%")."\n"; - print "\n"; - print ""; } else @@ -265,17 +235,14 @@ $db->free($result); llxFooter(); $db->close(); + ?> + diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php index 484f86ad9e0..d2e1879e51b 100644 --- a/htdocs/margin/customerMargins.php +++ b/htdocs/margin/customerMargins.php @@ -153,12 +153,12 @@ if (! empty($conf->global->DISPLAY_MARK_RATES)) { print ""; print ''; -$sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, s.client,"; -$sql.= " f.facnumber, f.total as total_ht,"; +$sql = "SELECT s.rowid as socid, s.nom, s.code_client, s.client,"; +$sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,"; +$sql.= " f.datef, f.paye, f.fk_statut as statut,"; $sql.= " sum(d.total_ht) as selling_price,"; -$sql.= $db->ifsql('f.type =2','sum(d.buy_price_ht * d.qty *-1)','sum(d.buy_price_ht * d.qty)')." as buying_price, "; -$sql.= $db->ifsql('f.type =2','sum(d.total_ht + (d.buy_price_ht * d.qty))','sum(d.total_ht - (d.buy_price_ht * d.qty))')." as marge," ; -$sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid"; +$sql.= " sum(".$db->ifsql('d.total_ht <=0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,"; +$sql.= " sum(".$db->ifsql('d.total_ht <=0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."facture as f"; $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; @@ -175,10 +175,7 @@ if (!empty($enddate)) $sql .= " AND d.buy_price_ht IS NOT NULL"; if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; -if ($client) - $sql.= " GROUP BY f.rowid, s.rowid, s.nom, s.code_client, s.client, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.type "; -else - $sql.= " GROUP BY s.rowid"; +if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut"; $sql.= " ORDER BY $sortfield $sortorder "; // TODO: calculate total to display then restore pagination //$sql.= $db->plimit($conf->liste_limit +1, $offset); @@ -189,7 +186,7 @@ if ($result) { $num = $db->num_rows($result); - print '
'; + print '
'; print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',0,0,''); $i = 0; @@ -197,11 +194,11 @@ if ($result) print ''; if (! empty($client)) { - print_liste_field_titre($langs->trans("Invoice"),$_SERVER["PHP_SELF"],"f.facnumber","","&socid=".$socid,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); - } - else - print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Invoice"),$_SERVER["PHP_SELF"],"f.facnumber","","&socid=".$socid,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); + } + else + print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Margin"),$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); @@ -219,39 +216,54 @@ if ($result) if ($num > 0) { $var=True; + while ($i < $num /*&& $i < $conf->liste_limit*/) { $objp = $db->fetch_object($result); - $marginRate = ($objp->buying_price != 0)?(100 * round($objp->marge / $objp->buying_price, 5)):'' ; - $markRate = ($objp->selling_price != 0)?(100 * round($objp->marge / $objp->selling_price, 5)):'' ; + $pa = $objp->buying_price; + $pv = $objp->selling_price; + $marge = $objp->marge; + + if ($marge < 0) + { + $marginRate = ($pa != 0)?-1*(100 * round($marge / $pa, 5)):'' ; + $markRate = ($pv != 0)?-1*(100 * round($marge / $pv, 5)):'' ; + } + else + { + $marginRate = ($pa != 0)?(100 * round($marge / $pa, 5)):'' ; + $markRate = ($pv != 0)?(100 * round($marge / $pv, 5)):'' ; + } $var=!$var; print ""; if ($client) { - print ''; - $invoicestatic->id=$objp->facid; - $invoicestatic->ref=$objp->facnumber; - print $invoicestatic->getNomUrl(1); - print "\n"; - print ""; - print dol_print_date($db->jdate($objp->datef),'day').""; - } - else { - $companystatic->id=$objp->socid; - $companystatic->nom=$objp->nom; - $companystatic->client=$objp->client; - print "".$companystatic->getNomUrl(1,'customer')."\n"; - } - print "".price($objp->selling_price)."\n"; - print "".price($objp->buying_price)."\n"; - print "".price($objp->marge)."\n"; + print ''; + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->facnumber; + print $invoicestatic->getNomUrl(1); + print "\n"; + print ""; + print dol_print_date($db->jdate($objp->datef),'day').""; + } + else { + $companystatic->id=$objp->socid; + $companystatic->nom=$objp->nom; + $companystatic->client=$objp->client; + print "".$companystatic->getNomUrl(1,'customer')."\n"; + } + + print "".price($pv)."\n"; + print "".price($pa)."\n"; + print "".price($marge)."\n"; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) print "".(($marginRate === '')?'n/a':price($marginRate)."%")."\n"; if (! empty($conf->global->DISPLAY_MARK_RATES)) print "".(($markRate === '')?'n/a':price($markRate)."%")."\n"; print "\n"; + $i++; $cumul_achat += round($objp->buying_price, $rounding); $cumul_vente += round($objp->selling_price, $rounding); @@ -261,14 +273,23 @@ if ($result) // affichage totaux marges $var=!$var; $totalMargin = $cumul_vente - $cumul_achat; - $marginRate = ($cumul_achat != 0)?(100 * round($totalMargin / $cumul_achat, 5)):'' ; - $markRate = ($cumul_vente != 0)?(100 * round($totalMargin / $cumul_vente, 5)):'' ; + if ($totalMargin < 0) + { + $marginRate = ($cumul_achat != 0)?-1*(100 * round($totalMargin / $cumul_achat, 5)):''; + $markRate = ($cumul_vente != 0)?-1*(100 * round($totalMargin / $cumul_vente, 5)):''; + } + else + { + $marginRate = ($cumul_achat != 0)?(100 * round($totalMargin / $cumul_achat, 5)):''; + $markRate = ($cumul_vente != 0)?(100 * round($totalMargin / $cumul_vente, 5)):''; + } + print ''; if ($client) - print ''; - else - print ''; - print $langs->trans('TotalMargin').""; + print ''; + else + print ''; + print $langs->trans('TotalMargin').""; print "".price($cumul_vente)."\n"; print "".price($cumul_achat)."\n"; print "".price($totalMargin)."\n"; @@ -289,7 +310,9 @@ $db->free($result); llxFooter(); $db->close(); + ?> + \ No newline at end of file +