--- /tmp/dsg/dolibarr/htdocs/margin/tabs/github_19.0.3_productMargins.php +++ /tmp/dsg/dolibarr/htdocs/margin/tabs/client_productMargins.php @@ -15 +15 @@ - * along with this program. If not, see . + * along with this program. If not, see . @@ -24 +23,0 @@ -// Load Dolibarr environment @@ -30 +29,4 @@ -$langs->loadLangs(array("companies", "bills", "products", "margins")); +$langs->load("companies"); +$langs->load("bills"); +$langs->load("products"); +$langs->load("margins"); @@ -34,2 +36,2 @@ -$action = GETPOST('action', 'aZ09'); -$confirm = GETPOST('confirm', 'alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); @@ -38,5 +40,4 @@ -$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); -$fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if (!empty($user->socid)) { - $socid = $user->socid; -} +$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); +$fieldtype = (! empty($ref) ? 'ref' : 'rowid'); +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); @@ -46,8 +47,7 @@ -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 -$offset = $limit * $page; +$mesg = ''; + +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; @@ -56,12 +56,2 @@ -if (!$sortorder) { - $sortorder = "DESC"; -} -if (!$sortfield) { - $sortfield = "f.datef"; -} - -$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); - -if (!$user->hasRight('margins', 'liretous')) { - accessforbidden(); -} +if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="f.datef"; @@ -74 +64 @@ -$invoicestatic = new Facture($db); +$invoicestatic=new Facture($db); @@ -77,4 +67,4 @@ -$totalMargin = 0; -$marginRate = ''; -$markRate = ''; -if ($id > 0 || !empty($ref)) { + + +if ($id > 0 || ! empty($ref)) +{ @@ -83,30 +73,34 @@ - $title = $langs->trans('ProductServiceCard'); - $help_url = ''; - $shortlabel = dol_trunc($object->label, 16); - if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { - $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card'); - $help_url = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; - } - if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { - $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card'); - $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; - } - - llxHeader('', $title, $help_url); - - // View mode - if ($result > 0) { - $head = product_prepare_head($object); - $titre = $langs->trans("CardProduct".$object->type); - $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); - print dol_get_fiche_head($head, 'margin', $titre, -1, $picto); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref'); - - - print '
'; - - print '
'; - print ''; + llxHeader("","",$langs->trans("CardProduct".$object->type)); + + /* + * En mode visu + */ + if ($result > 0) + { + $head=product_prepare_head($object); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); + dol_fiche_head($head, 'margin', $titre, 0, $picto); + + print '
'; + + // Reference + print ''; + print ''; + print ''; + + // Libelle + print ''; + print ''; + + // Status (to sell) + print ''; + + // Status (to buy) + print ''; @@ -115,2 +109,3 @@ - print '\n"; + // marge en cours + $sql = "SELECT price, datec FROM llx_product_fournisseur_price WHERE fk_product = ".$id." ORDER BY datec DESC"; + $calldata = $db->query($sql); + if ($db->num_rows($calldata) > 0) { + $objdata = $db->fetch_object($calldata); + $achat1 = $objdata->price; + $date1 = $objdata->datec; + } + $sql = "SELECT price, datem FROM llx_stock_mouvement WHERE (fk_product = ".$id.") AND (value > 0) ORDER BY datem DESC"; + $calldata = $db->query($sql); + if ($db->num_rows($calldata) > 0) { + $objdata = $db->fetch_object($calldata); + $achat2 = $objdata->price; + $date2 = $objdata->datec; + } + print "\n"; @@ -120,2 +143,3 @@ - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print '"; @@ -125 +149 @@ - + /* @@ -127,2 +151,2 @@ - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print ''; + print '\n"; + print ''; + print "\n"; + print ""; + print "\n"; + /* + print "\n"; + print "\n"; + print "\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 ""; + print "\n"; + print ""; + // coeff + if ($achat != 0) print ""; else print ""; + + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + //print "\n"; + + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "\n"; + print ''; + print "\n"; + $i++; + $cumul_achat += $objp->buying_price; + $cumul_vente += $objp->selling_price; + $cumul_qty += $objp->qty; + } + } + + // affichage totaux marges + $var=!$var; + $totalMargin = $cumul_vente - $cumul_achat; + var_dump($cumul_vente); + var_dump($cumul_achat); + if ($totalMargin < 0) + { + $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; + $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; + } + else + { + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; + } + print ''; + print '"; + print '\n"; + print '\n"; + print '\n"; + print '\n"; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print '\n"; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "\n"; + print ''; + print "\n"; + print "
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'ref','',1,'ref'); + print '
'.$langs->trans("Label").''.$object->label.'
'.$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 ''; // set by jquery (see below) + //print '
'.$langs->trans("TotalMargin").''; + print '
Marges réalisées'; + print ''; // set by jquery (see below) @@ -118 +113,29 @@ - + 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."%
'.$langs->trans("MarkRate").''; + if (! empty($conf->global->DISPLAY_MARK_RATES)) { + print '
'.$langs->trans("MarkRate").''; @@ -131,0 +156 @@ + */ @@ -134 +158,0 @@ - @@ -136,103 +160,74 @@ - print '
'; - - print dol_get_fiche_end(); - - - if ($user->hasRight("facture", "read")) { - $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,"; - $sql .= " f.rowid as facid, f.ref, f.total_ht,"; - $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,"; - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " sc.fk_soc, sc.fk_user,"; - } - $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive - $sql .= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty) as qty,"; // not always positive in case of Credit note - $sql .= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,"; // not always positive in case of Credit note - $sql .= " ".$db->ifsql('f.type = 2', -1, 1)." * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge"; // not always positive in case of Credit note - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql .= ", ".MAIN_DB_PREFIX."facture as f"; - $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= " WHERE f.fk_soc = s.rowid"; - $sql .= " AND f.fk_statut > 0"; - $sql .= " AND f.entity IN (".getEntity('invoice').")"; - $sql .= " AND d.fk_facture = f.rowid"; - $sql .= " AND d.fk_product = ".((int) $object->id); - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - if (!empty($socid)) { - $sql .= " AND f.fk_soc = ".((int) $socid); - } - $sql .= " AND d.buy_price_ht IS NOT NULL"; - // We should not use this here. Option ForceBuyingPriceIfNull should have effect only when inserting data. Once data is recorded, it must be used as it is for report. - // We keep it with value ForceBuyingPriceIfNull = 2 for retroactive effect but results are unpredicable. - if (getDolGlobalInt('ForceBuyingPriceIfNull') == 2) { - $sql .= " AND d.buy_price_ht <> 0"; - } - $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total_ht, f.datef, f.paye, f.fk_statut, f.type"; - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user"; - } - $sql .= $db->order($sortfield, $sortorder); - // TODO: calculate total to display then restore pagination - //$sql.= $db->plimit($conf->liste_limit +1, $offset); - dol_syslog('margin:tabs:productMargins.php', LOG_DEBUG); - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&id=$object->id", $sortfield, $sortorder, '', 0, 0, ''); - - $i = 0; - - print '
'; - print ''; - - print ''; - print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&id=".$object->id, '', $sortfield, $sortorder); - print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&id=".$object->id, '', $sortfield, $sortorder); - print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&id=".$object->id, '', $sortfield, $sortorder); - print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&id=".$object->id, '', $sortfield, $sortorder, 'left '); - print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "buying_price", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "qty", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - } - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - } - print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&id=".$object->id, '', $sortfield, $sortorder, 'right '); - print "\n"; - - $cumul_achat = 0; - $cumul_vente = 0; - $cumul_qty = 0; - - if ($num > 0) { - while ($i < $num /*&& $i < $conf->liste_limit*/) { - $objp = $db->fetch_object($result); - - $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : ''; - $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : ''; - - print ''; - print '\n"; - print ''; - print "\n"; - print '"; - print '\n"; - print '\n"; - print '\n"; - print '\n"; - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print "\n"; + + + if ($user->rights->facture->lire) { + $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,"; + $sql.= " f.rowid as facid, f.ref, f.total as total_ht,"; + $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,"; + $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive + $sql.= " sum(d.qty) as qty,"; + $sql.= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive + $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ; // always positive + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut > 0"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND d.fk_facture = f.rowid"; + $sql.= " AND d.fk_product =".$object->id; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if (! empty($socid)) $sql.= " AND f.fk_soc = $socid"; + $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"; + $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user"; + $sql.= $db->order($sortfield,$sortorder); + // TODO: calculate total to display then restore pagination + //$sql.= $db->plimit($conf->liste_limit +1, $offset); + dol_syslog('margin:tabs:productMargins.php', LOG_DEBUG); + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + + print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&id=$object->id",$sortfield,$sortorder,'',0,0,''); + + $i = 0; + print '
'; - $invoicestatic->id = $objp->facid; - $invoicestatic->ref = $objp->ref; - print $invoicestatic->getNomUrl(1); - print "'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).'".$objp->code_client."'; - print dol_print_date($db->jdate($objp->datef), 'day')."'.price(price2num($objp->selling_price, 'MT'))."'.price(price2num($objp->buying_price, 'MT'))."'.price(price2num($objp->qty, 'MT'))."'.price(price2num($objp->marge, 'MT'))."".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."
'; + + print ''; + print_liste_field_titre($langs->trans("Invoice"),$_SERVER["PHP_SELF"],"f.ref","","&id=".$object->id,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$object->id,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$object->id,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&id=".$object->id,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("Margin"),$_SERVER["PHP_SELF"],"marge","","&id=".$object->id,'align="right"',$sortfield,$sortorder); + print "\n"; + + $cumul_achat = 0; + $cumul_vente = 0; + $cumul_qty = 0; + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); + + if ($num > 0) { + $var=True; + /* + // marge en cours + $achat =0; + // pachat dans mvt + $sql = "SELECT price, datem FROM llx_stock_mouvement WHERE (fk_product = ".$object->id.") AND (value > 0) ORDER BY datem DESC"; + //print "
sql ".$sql; + $calldata = $db->query($sql); + $ok = 1; + if ($db->num_rows($calldata) == 0) $ok = 0; else { + $objdata = $db->fetch_object($calldata); + if ($objdata->price >0 ) $achat = $objdata->price; else $ok = 0; @@ -240,2 +235,8 @@ - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print "\n"; + if ($ok == 0 ) { + // sinon pachat dans product + $sql = "SELECT price, datec FROM llx_product_fournisseur_price WHERE fk_product = ".$object->id." ORDER BY datec DESC"; + $calldata = $db->query($sql); + if ($db->num_rows($calldata) > 0) { + $objdata = $db->fetch_object($calldata); + $achat = $objdata->price; + } @@ -243,41 +244,104 @@ - print ''; - print "\n"; - $i++; - $cumul_achat += $objp->buying_price; - $cumul_vente += $objp->selling_price; - $cumul_qty += $objp->qty; - } - } - - // affichage totaux marges - - $totalMargin = $cumul_vente - $cumul_achat; - if ($totalMargin < 0) { - $marginRate = ($cumul_achat != 0) ? -1 * (100 * $totalMargin / $cumul_achat) : ''; - $markRate = ($cumul_vente != 0) ? -1 * (100 * $totalMargin / $cumul_vente) : ''; - } else { - $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : ''; - $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : ''; - } - print ''; - print '"; - print '\n"; - print '\n"; - print '\n"; - print '\n"; - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print '\n"; - } - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print "\n"; - } - print ''; - print "\n"; - 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 "
".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'
'.$langs->trans('TotalMargin')."'.price(price2num($cumul_vente, 'MT'))."'.price(price2num($cumul_achat, 'MT'))."'.price(price2num($cumul_qty, 'MT'))."'.price(price2num($totalMargin, 'MT'))."'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." 
"; - print '
'; - } else { - dol_print_error($db); - } - $db->free($result); - } - } + //print "
achat :".$achat; + */ + $product = new Product($db); + while ($i < $num /*&& $i < $conf->liste_limit*/) { + $objp = $db->fetch_object($result); + $var=!$var; + + $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; + $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; + + print '
'; + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->ref; + print $invoicestatic->getNomUrl(1); + print "'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'".$objp->code_client.""; + print dol_print_date($db->jdate($objp->datef),'day')."".price($objp->selling_price, null, null, null, null, $rounding)."".price($objp->buying_price, null, null, null, null, $rounding)."".price($objp->qty, null, null, null, null, $rounding)."".price($objp->marge, null, null, null, null, $rounding)."".number_format($achat, 2,"."," ")."".price($objp->qty, null, null, null, null, $rounding)."".number_format(($objf->total_ht - ($achat * $objf->qty)), 2,"."," ")."".number_format(100 * ($objf->total_ht - ($achat * $objf->qty))/($achat * $objf->qty), 2,"."," ")."%".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'
'.$langs->trans('TotalMargin')."'.price($cumul_vente, null, null, null, null, $rounding)."'.price($cumul_achat, null, null, null, null, $rounding)."'.price($cumul_qty, null, null, null, null, $rounding)."'.price($totalMargin, null, null, null, null, $rounding)."'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")." 
"; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); + } + } @@ -285 +349 @@ - dol_print_error(); + dol_print_error(); @@ -291,3 +355,3 @@ - $("#totalMargin").html("'. price(price2num($totalMargin, 'MT')).'"); - $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'"); - $("#markRate").html("'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'"); + $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'"); + $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'"); + $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'"); @@ -298 +361,0 @@ -// End of page --- /tmp/dsg/dolibarr/htdocs/margin/tabs/github_19.0.3_thirdpartyMargins.php +++ /tmp/dsg/dolibarr/htdocs/margin/tabs/client_thirdpartyMargins.php @@ -15 +15 @@ - * along with this program. If not, see . + * along with this program. If not, see . @@ -21 +21 @@ - * \brief Page for invoice margins of a thirdparty + * \brief Page des marges des factures clients pour un tiers @@ -24 +23,0 @@ -// Load Dolibarr environment @@ -30 +29,4 @@ -$langs->loadLangs(array("companies", "bills", "products", "margins")); +$langs->load("companies"); +$langs->load("bills"); +$langs->load("products"); +$langs->load("margins"); @@ -33,13 +35,12 @@ -$socid = GETPOST('socid', 'int'); -if (!empty($user->socid)) { - $socid = $user->socid; -} - -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 -$offset = $limit * $page; +$socid = GETPOST('socid','int'); +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result = restrictedArea($user, 'societe','',''); + + +$mesg = ''; + +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; @@ -48,6 +49,2 @@ -if (!$sortorder) { - $sortorder = "DESC"; -} -if (!$sortfield) { - $sortfield = "f.datef"; -} +if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="f.datef"; @@ -56,12 +53,3 @@ -if ($socid > 0) { - $object->fetch($socid); -} - -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('thirdpartymargins', 'globalcard')); - -$result = restrictedArea($user, 'societe', $object->id, ''); - -if (!$user->hasRight('margins', 'liretous')) { - accessforbidden(); -} + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('thirdpartymargins','globalcard')); @@ -74,5 +62,3 @@ -$parameters = array('id'=>$socid); -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} +$parameters=array('id'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -86 +72 @@ -$invoicestatic = new Facture($db); +$invoicestatic=new Facture($db); @@ -89,3 +75,208 @@ -$title = $langs->trans("ThirdParty").' - '.$langs->trans("Margins"); -if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { - $title = $object->name.' - '.$langs->trans("Files"); +$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('',$langs->trans("ThirdParty").' - '.$langs->trans("Margins"),$help_url); + +if ($socid > 0) +{ + $object = new Societe($db); + $object->fetch($socid); + + /* + * Affichage onglets + */ + + $head = societe_prepare_head($object); + + dol_fiche_head($head, 'margin', $langs->trans("ThirdParty"),0,'company'); + + print ''; + + print ''; + print ''; + + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''; + } + + if ($object->client) + { + print ''; + } + + if ($object->fournisseur) + { + print ''; + } + + // Total Margin + print ''; + + // Margin Rate + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { + print ''; + } + + // Mark Rate + if (! empty($conf->global->DISPLAY_MARK_RATES)) { + print ''; + } + + print "
'.$langs->trans('ThirdPartyName').''; + print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom'); + print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; + print $langs->trans('CustomerCode').''; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + 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 '
"; + print '
'; + + + $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,"; + $sql.= " f.rowid as facid, f.facnumber, f.total as total_ht,"; + $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; + $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive + $sql.= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive + $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut > 0"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " AND d.fk_facture = f.rowid"; + $sql.= " AND f.fk_soc = $socid"; + $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"; + $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.facnumber, f.total, f.datef, f.paye, f.fk_statut, f.type"; + $sql.= $db->order($sortfield,$sortorder); + // TODO: calculate total to display then restore pagination + //$sql.= $db->plimit($conf->liste_limit +1, $offset); + + dol_syslog('margin:tabs:thirdpartyMargins.php', LOG_DEBUG); + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + + print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&socid=".$object->id,$sortfield,$sortorder,'',0,0,''); + + $i = 0; + print ""; + + print ''; + print_liste_field_titre($langs->trans("Invoice"),$_SERVER["PHP_SELF"],"f.facnumber","","&socid=".$_REQUEST["socid"],'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Margin"),$_SERVER["PHP_SELF"],"marge","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print_liste_field_titre($langs->trans("MarginRate"),$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print_liste_field_titre($langs->trans("MarkRate"),$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); + print "\n"; + + $cumul_achat = 0; + $cumul_vente = 0; + + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); + $product = new Product($db); + if ($num > 0) { + $var=True; + while ($i < $num /*&& $i < $conf->liste_limit*/) { + $objp = $db->fetch_object($result); + $var=!$var; + print ""; + print '\n"; + print ""; + // selling price integre le port + //print "\n"; + //print "\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 "
sql ".$sql; + $resf = $db->query($sql); + $achat = 0; + $ht = 0; + while ($objf = $db->fetch_object($resf)) { + $w = $product->prix_achat($objf->fk_product, $objp->datef); + // avoir qty > 0 et total_ht < 0 + if ($objf->total_ht > 0) $achat = $achat + ($w * $objf->qty); else $achat = $achat - ($w * $objf->qty); + $ht += $objf->total_ht; // montant negatif pour les avoirs + } + $cumul_achat += $achat; + print ""; + print ""; + // marge + print ""; + // coeff + if ($achat != 0) print ""; else print ""; + + + /* + $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; + $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; + print "\n"; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print "\n"; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "\n"; + */ + print ''; + print "\n"; + $i++; + //$cumul_achat += $objp->buying_price; + $cumul_vente += $ht; + } + } + + // affichage totaux marges + $var=!$var; + $totalMargin = $cumul_vente - $cumul_achat; + if ($totalMargin < 0) + { + $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; + $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; + } + else + { + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; + } + // totaux + print ''; + print '"; + print "\n"; + print "\n"; + print "\n"; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print "\n"; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print "\n"; + + print ''; + print "\n"; + } + else + { + dol_print_error($db); + } + print "
'; + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->facnumber; + print $invoicestatic->getNomUrl(1); + print ""; + print dol_print_date($db->jdate($objp->datef),'day')."".price($objp->selling_price, null, null, null, null, $rounding)."".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."".number_format($ht, 2,"."," ")."".number_format($achat, 2,"."," ")."".number_format(($ht - $achat), 2,"."," ")."".number_format(100 * ($ht - $achat )/$achat, 2,"."," ")."%".price($objp->marge, null, null, null, null, $rounding)."".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'
'.$langs->trans('TotalMargin')."".price($cumul_vente, null, null, null, null, $rounding)."".price($cumul_achat, null, null, null, null, $rounding)."".price($totalMargin, null, null, null, null, $rounding)."".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")." 
"; + print '
'; + $db->free($result); @@ -93,207 +284,2 @@ -$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; -llxHeader('', $title, $help_url); - -$totalMargin = 0; -$marginRate = ''; -$markRate = ''; -if ($socid > 0) { - $object = new Societe($db); - $object->fetch($socid); - - /* - * Affichage onglets - */ - - $head = societe_prepare_head($object); - - print dol_get_fiche_head($head, 'margin', $langs->trans("ThirdParty"), -1, 'company'); - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - // Type Prospect/Customer/Supplier - print ''; - - if ($object->client) { - print ''; - } - - if (((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) && $object->fournisseur) { - print ''; - } - - // Total Margin - print ''; - - // Margin Rate - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print ''; - } - - // Mark Rate - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print ''; - } - - print "
'.$langs->trans('NatureOfThirdParty').''; - print $object->getTypeUrl(1); - print '
'; - print $langs->trans('CustomerCode').''; - print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client)); - $tmpcheck = $object->check_codeclient(); - if ($tmpcheck != 0 && $tmpcheck != -5) { - print ' ('.$langs->trans("WrongCustomerCode").')'; - } - print '
'; - print $langs->trans('SupplierCode').''; - print showValueWithClipboardCPButton(dol_escape_htmltag($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 '
'; - print '
'; - - print dol_get_fiche_end(); - - print '
'; - - $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,"; - $sql .= " f.rowid as facid, f.ref, f.total_ht,"; - $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,"; - $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive - $sql .= " sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,"; // always positive - $sql .= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge"; // always positive - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql .= ", ".MAIN_DB_PREFIX."facture as f"; - $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; - $sql .= " WHERE f.fk_soc = s.rowid"; - $sql .= " AND f.fk_statut > 0"; - $sql .= " AND f.entity IN (".getEntity('invoice').")"; - $sql .= " AND d.fk_facture = f.rowid"; - $sql .= " AND f.fk_soc = $socid"; - $sql .= " AND d.buy_price_ht IS NOT NULL"; - // We should not use this here. Option ForceBuyingPriceIfNull should have effect only when inserting data. Once data is recorded, it must be used as it is for report. - // We keep it with value ForceBuyingPriceIfNull = 2 for retroactive effect but results are unpredicable. - if (getDolGlobalInt('ForceBuyingPriceIfNull') == 2) { - $sql .= " AND d.buy_price_ht <> 0"; - } - $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total_ht, f.datef, f.paye, f.fk_statut, f.type"; - $sql .= $db->order($sortfield, $sortorder); - // TODO: calculate total to display then restore pagination - //$sql.= $db->plimit($conf->liste_limit +1, $offset); - - dol_syslog('margin:tabs:thirdpartyMargins.php', LOG_DEBUG); - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&socid=".$object->id, $sortfield, $sortorder, '', $num, $num, ''); - - $i = 0; - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ""; - - print ''; - print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder); - print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'center '); - print_liste_field_titre("SoldAmount", $_SERVER["PHP_SELF"], "selling_price", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("PurchasedAmount", $_SERVER["PHP_SELF"], "buying_price", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - } - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - } - print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder, 'right '); - print "\n"; - - $cumul_achat = 0; - $cumul_vente = 0; - - if ($num > 0) { - while ($i < $num /*&& $i < $conf->liste_limit*/) { - $objp = $db->fetch_object($result); - - $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : ''; - $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : ''; - - $sign = ''; - if ($objp->type == Facture::TYPE_CREDIT_NOTE) { - $sign = '-'; - } - - print ''; - print '\n"; - print ""; - print "\n"; - print "\n"; - print "\n"; - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print "\n"; - } - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print "\n"; - } - print ''; - print "\n"; - $i++; - $cumul_vente += $objp->selling_price; - $cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price; - } - } - - // affichage totaux marges - - $totalMargin = $cumul_vente - $cumul_achat; - if ($totalMargin < 0) { - $marginRate = ($cumul_achat != 0) ? -1 * (100 * $totalMargin / $cumul_achat) : ''; - $markRate = ($cumul_vente != 0) ? -1 * (100 * $totalMargin / $cumul_vente) : ''; - } else { - $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : ''; - $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : ''; - } - - // Total - print ''; - print '"; - print "\n"; - print "\n"; - print "\n"; - if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { - print "\n"; - } - if (getDolGlobalString('DISPLAY_MARK_RATES')) { - print "\n"; - } - print ''; - print "\n"; - } else { - dol_print_error($db); - } - print "
'; - $invoicestatic->id = $objp->facid; - $invoicestatic->ref = $objp->ref; - print $invoicestatic->getNomUrl(1); - print ""; - print dol_print_date($db->jdate($objp->datef), 'day')."".price(price2num($objp->selling_price, 'MT'))."".price(price2num(($objp->type == 2 ? -1 : 1) * $objp->buying_price, 'MT'))."".$sign.price(price2num($objp->marge, 'MT'))."".(($marginRate === '') ? 'n/a' : $sign.price(price2num($marginRate, 'MT'))."%")."".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'
'.$langs->trans('TotalMargin')."".price(price2num($cumul_vente, 'MT'))."".price(price2num($cumul_achat, 'MT'))."".price(price2num($totalMargin, 'MT'))."".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")." 
"; - print '
'; - - print '
'; - $db->free($result); -} else { +else +{ @@ -307,3 +293,3 @@ - $("#totalMargin").html("'. price(price2num($totalMargin, 'MT')).'"); - $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'"); - $("#markRate").html("'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'"); + $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'"); + $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'"); + $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'"); @@ -314 +299,0 @@ -// End of page