--- /tmp/dsg/dolibarr/htdocs/margin/tabs/github_productMargins.php
+++ /tmp/dsg/dolibarr/htdocs/margin/tabs/client_productMargins.php
@@ -12,7 +12,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see
'.$langs->trans("Ref").' | '; + print $form->showrefnav($object,'ref','',1,'ref'); + print ' | '; + print '||||
'.$langs->trans("Label").' | '.$object->label.' | '; + print '||||
'.$langs->trans("Status").' ('.$langs->trans("Sell").') | '; + print $object->getLibStatut(2,0); + print ' | ||||
'.$langs->trans("Status").' ('.$langs->trans("Buy").') | '; + print $object->getLibStatut(2,1); + print ' | ||||
'.$langs->trans("TotalMargin").' | '; + //print ' | ||||
'.$langs->trans("TotalMargin").' | '; + print ' | ||||
Marges réalisées | '; print ''; // set by jquery (see below) print ' | ||||
Prix de vente | ".number_format($object->price,2,".","")." | ||||
Marge en cours | "; //achat1 : ".$achat1." achat2: ".$achat2." marge :"; + //if ($date1 > $date2) print number_format($object->price - $achat1,2,".",""); else print number_format($object->price - $achat2,2,".",""); + $marge = 0; + if ($achat2 == 0) { + print number_format($object->price - $achat1,2,".",""); + //if ($object->price != 0) $marge = number_format(100 * ($object->price - $achat1)/$object->price,2,".",""); + if ($achat1 != 0) $marge = number_format(100 * ($object->price - $achat1)/$achat1,2,".",""); + } else { + print number_format($object->price - $achat2,2,".",""); + //if ($object->price != 0) $marge = number_format(100 * ($object->price - $achat2)/$object->price,2,".",""); + if ($achat2 != 0) $marge = number_format(100 * ($object->price - $achat2)/$achat2,2,".",""); + } + print " (prix fournisseur : ".number_format($achat1,2,".","")." - entrée stock à: ".number_format($achat2,2,".","").") | ||||
'.$langs->trans("MarginRate").' | '; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { + //print ' | ||||
'.$langs->trans("MarginRate").' | '; + print " | Taux de marge sur dernier prix d'achat | ".$marge."% | "; print ''; // set by jquery (see below) print '||
'.$langs->trans("MarkRate").' | '; print ''; // set by jquery (see below) print ' |
'; - $invoicestatic->id = $objp->facid; - $invoicestatic->ref = $objp->ref; - print $invoicestatic->getNomUrl(1); - print " | \n"; - print ''.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).' | '; - print "".$objp->code_client." | \n"; - print ""; - print dol_print_date($db->jdate($objp->datef), 'day')." | "; - print "".price(price2num($objp->selling_price, 'MT'))." | \n"; - print "".price(price2num($objp->buying_price, 'MT'))." | \n"; - print "".price(price2num($objp->qty, 'MT'))." | \n"; - print "".price(price2num($objp->marge, 'MT'))." | \n"; - if (!empty($conf->global->DISPLAY_MARGIN_RATES)) - print "".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")." | \n"; - if (!empty($conf->global->DISPLAY_MARK_RATES)) - print "".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." | \n"; - print ''.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).' | '; - print "
'.$langs->trans('TotalMargin')." | "; - print ''.price(price2num($cumul_vente, 'MT'))." | \n"; - print ''.price(price2num($cumul_achat, 'MT'))." | \n"; - print ''.price(price2num($cumul_qty, 'MT'))." | \n"; - print ''.price(price2num($totalMargin, 'MT'))." | \n"; - if (!empty($conf->global->DISPLAY_MARGIN_RATES)) - print ''.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")." | \n"; - if (!empty($conf->global->DISPLAY_MARK_RATES)) - print "".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." | \n"; - print ''; - print " |
Marge"; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print_liste_field_titre($langs->trans("MarginRate"),$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print_liste_field_titre($langs->trans("MarkRate"),$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + print " | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'; + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->ref; + print $invoicestatic->getNomUrl(1); + print " | \n"; + print ''.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).' | '; + print "".$objp->code_client." | \n"; + print ""; + print dol_print_date($db->jdate($objp->datef),'day')." | "; + print "".price($objp->selling_price, null, null, null, null, $rounding)." | \n"; + /* + print "".price($objp->buying_price, null, null, null, null, $rounding)." | \n"; + print "".price($objp->qty, null, null, null, null, $rounding)." | \n"; + print "".price($objp->marge, null, null, null, null, $rounding)." | \n"; + */ + $sql = "SELECT f.fk_product, f.qty, f.total_ht FROM llx_facturedet as f INNER JOIN llx_product AS p ON p.rowid = f.fk_product + WHERE f.fk_facture = ".$objp->facid." AND f.fk_product = ".$object->id; + $resf = $db->query($sql); + $objf = $db->fetch_object($resf); + + // $sql2 = "SELECT * FROM llx_product_fournisseur_price as f + // WHERE f.datec <= '".$objp->datef."' AND f.fk_product = ".$object->id." ORDER BY f.datec DESC LIMIT 1"; + // $query2 = $db->query($sql2); + // $prix_achat = $db->fetch_object($query2); + $achat = null; + $sql2 = "SELECT price, datem FROM llx_stock_mouvement WHERE (datem < '".$objp->datef."') AND (price != 0) AND (fk_product = ".$object->id.") AND (value > 0) ORDER BY datem DESC LIMIT 1"; + $calldata2 = $db->query($sql2); + if ($db->num_rows($calldata2) > 0) { + $objdata2 = $db->fetch_object($calldata2); + $achat = $objdata2->price; + } + if (!$achat) { + $achat = $product->prix_achat($object->id, $objp->datef); + } + + // marge + // $achat = $product->prix_achat($object->id, $objp->datef); + + print "".number_format($achat, 2,"."," ")." | "; + print "".price($objp->qty, null, null, null, null, $rounding)." | \n"; + print "".number_format(($objf->total_ht - ($achat * $objf->qty)), 2,"."," ")." | "; + // coeff + if ($achat != 0) print "".number_format(100 * ($objf->total_ht - ($achat * $objf->qty))/($achat * $objf->qty), 2,"."," ")."% | "; else print ""; + + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + //print " | ".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")." | \n"; + + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")." | \n"; + print ''.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).' | '; + print "
'.$langs->trans('TotalMargin')." | "; + print ''.price($cumul_vente, null, null, null, null, $rounding)." | \n"; + print ''.price($cumul_achat, null, null, null, null, $rounding)." | \n"; + print ''.price($cumul_qty, null, null, null, null, $rounding)." | \n"; + print ''.price($totalMargin, null, null, null, null, $rounding)." | \n"; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print ''.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")." | \n"; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")." | \n"; + print ''; + print " |
'.$langs->trans('ThirdPartyName').' | '; + print ''; + print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom'); + print ' | ||
'.$langs->trans('Prefix').' | '.$object->prefix_comm.' | ||
'; + print ' | |||
'; print $langs->trans('CustomerCode').' | '; print $object->code_client; - $tmpcheck = $object->check_codeclient(); - if ($tmpcheck != 0 && $tmpcheck != -5) { - print ' ('.$langs->trans("WrongCustomerCode").')'; - } + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; print ' | ||
'; - print $langs->trans('SupplierCode').' | '; - print $object->code_fournisseur; - $tmpcheck = $object->check_codefournisseur(); - if ($tmpcheck != 0 && $tmpcheck != -5) { - print ' ('.$langs->trans("WrongSupplierCode").')'; - } - print ' | ||
'.$langs->trans("TotalMargin").' | '; - print ''; // set by jquery (see below) - print ' | ||
'.$langs->trans("MarginRate").' | '; - print ''; // set by jquery (see below) - print ' | ||
'.$langs->trans("MarkRate").' | '; - print ''; // set by jquery (see below) - print ' |
'; + print $langs->trans('SupplierCode').' | '; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print ' | ||
'.$langs->trans("TotalMargin").' | '; + print ''; // set by jquery (see below) + print ' | ||
'.$langs->trans("MarginRate").' | '; + print ''; // set by jquery (see below) + print ' | ||
'.$langs->trans("MarkRate").' | '; + print ''; // set by jquery (see below) + 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')." | "; + // selling price integre le port + //print "".price($objp->selling_price, null, null, null, null, $rounding)." | \n"; + //print "".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)." | \n"; + // CAI calcul de marge + $sql = "SELECT f.fk_product, f.qty, f.total_ht FROM llx_facturedet as f INNER JOIN llx_product AS p ON p.rowid = f.fk_product + WHERE f.fk_facture = ".$objp->facid." AND f.product_type = 0"; + //print "||||
'; - $invoicestatic->id = $objp->facid; - $invoicestatic->ref = $objp->ref; - print $invoicestatic->getNomUrl(1); - print " | \n"; - print ""; - print dol_print_date($db->jdate($objp->datef), 'day')." | "; - print "".price(price2num($objp->selling_price, 'MT'))." | \n"; - print "".price(price2num(($objp->type == 2 ? -1 : 1) * $objp->buying_price, 'MT'))." | \n"; - print "".$sign.price(price2num($objp->marge, 'MT'))." | \n"; - if (!empty($conf->global->DISPLAY_MARGIN_RATES)) - print "".(($marginRate === '') ? 'n/a' : $sign.price(price2num($marginRate, 'MT'))."%")." | \n"; - if (!empty($conf->global->DISPLAY_MARK_RATES)) - print "".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." | \n"; - print ''.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).' | '; - print "
'.$langs->trans('TotalMargin')." | "; - print "".price(price2num($cumul_vente, 'MT'))." | \n"; - print "".price(price2num($cumul_achat, 'MT'))." | \n"; - print "".price(price2num($totalMargin, 'MT'))." | \n"; - if (!empty($conf->global->DISPLAY_MARGIN_RATES)) - print "".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")." | \n"; - if (!empty($conf->global->DISPLAY_MARK_RATES)) - print "".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." | \n"; - print ''; - print " |