Fix several fixes on margin reports

This commit is contained in:
Laurent Destailleur 2016-07-30 18:57:26 +02:00
parent 246321cd8f
commit a87c2f9579
9 changed files with 32 additions and 18 deletions

View File

@ -68,6 +68,7 @@ $tables=array(
'facture'=>array(0=>'datef', 1=>'date_valid', 2=>'date_lim_reglement'),
'paiement'=>array(0=>'datep'),
'bank'=>array(0=>'datev', 1=>'dateo'),
'commande_fournisseur'=>array(0=>'date_commande', 1=>'date_valid', 3=>'date_creation', 4=>'date_approve', 5=>'date_approve2', 6=>'date_livraison'),
'supplier_proposal'=>array(0=>'datec', 1=>'date_valid', 2=>'date_cloture')
);

View File

@ -41,3 +41,4 @@ rateMustBeNumeric=Rate must be a numeric value
markRateShouldBeLesserThan100=Mark rate should be lower than 100
ShowMarginInfos=Show margin infos
CheckMargins=Margins detail
MarginPerSaleRepresentativeWarning=The report of margin per user use the link between thirdparties and sale representatives to calculate the margin of each user. Because some thirdparties may not be linked to any sale representative and some thirdparties may be linked to several users, some margins may not appears in these report or may appears in several different lines.

View File

@ -59,6 +59,8 @@ SellingPriceHT=Selling price (net of tax)
SellingPriceTTC=Selling price (inc. tax)
CostPriceDescription=This price (net of tax) can be used to store the average amount this product cost to your company. It may be any price you calculate yourself, for example from the average buying price plus average production and distribution cost.
CostPriceUsage=In a future version, this value could be used for margin calculation.
SoldAmount=Sold amount
PurchasedAmount=Purchased amount
NewPrice=New price
MinPrice=Min. selling price
CantBeLessThanMinPrice=The selling price can't be lower than minimum allowed for this product (%s without tax). This message can also appears if you type a too important discount.

View File

@ -91,12 +91,10 @@ dol_fiche_head($head, 'agentMargins', $titre, 0, $picto);
print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
print '<table class="border" width="100%">';
if ($user->rights->margins->read->all) {
print '<tr><td width="20%">'.$langs->trans('SalesRepresentative').'</td>';
print '<td colspan="4">';
print $form->select_dolusers($agentid, 'agentid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '</td></tr>';
}
print '<tr><td width="20%">'.$langs->trans('SalesRepresentative').'</td>';
print '<td colspan="4">';
print $form->select_dolusers($agentid, 'agentid', 1, '', $user->rights->margins->read->all ? 0 : 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '</td></tr>';
// Start date
print '<td>'.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')</td>';
@ -153,6 +151,11 @@ $sql.=$db->order($sortfield,$sortorder);
// TODO: calculate total to display then restore pagination
//$sql.= $db->plimit($conf->liste_limit +1, $offset);
print '<br>';
print img_info('').' '.$langs->trans("MarginPerSaleRepresentativeWarning").'<br>';
dol_syslog('margin::agentMargins.php', LOG_DEBUG);
$result = $db->query($sql);
if ($result)

View File

@ -261,7 +261,7 @@ if ($result)
$companystatic->id=$objp->socid;
$companystatic->name=$objp->name;
$companystatic->client=$objp->client;
print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n";
}
print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
@ -282,16 +282,16 @@ if ($result)
// affichage totaux marges
$var=!$var;
$totalMargin = $cumul_vente - $cumul_achat;
if ($totalMargin < 0)
/*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 '<tr class="liste_total">';
if ($client)

View File

@ -295,16 +295,16 @@ if ($result)
// affichage totaux marges
$var=!$var;
$totalMargin = $cumul_vente - $cumul_achat;
if ($totalMargin < 0)
/*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 '<tr class="liste_total">';
if ($id > 0)
print '<td colspan=2>';

View File

@ -225,7 +225,7 @@ if ($id > 0 || ! empty($ref))
$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):'';
}

View File

@ -176,8 +176,8 @@ if ($socid > 0)
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Invoice"),$_SERVER["PHP_SELF"],"f.facnumber","","&amp;socid=".$_REQUEST["socid"],'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&amp;socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("SellingPrice"),$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("SoldAmount"),$_SERVER["PHP_SELF"],"selling_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("PurchasedAmount"),$_SERVER["PHP_SELF"],"buying_price","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Margin"),$_SERVER["PHP_SELF"],"marge","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
print_liste_field_titre($langs->trans("MarginRate"),$_SERVER["PHP_SELF"],"","","&amp;socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder);
@ -221,8 +221,8 @@ if ($socid > 0)
print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
print "</tr>\n";
$i++;
$cumul_achat += $objp->buying_price;
$cumul_vente += $objp->selling_price;
$cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price;
}
}
@ -239,6 +239,8 @@ if ($socid > 0)
$marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):'';
$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
}
// Total
print '<tr class="liste_total">';
print '<td colspan=2>'.$langs->trans('TotalMargin')."</td>";
print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";

View File

@ -1869,7 +1869,12 @@ class Societe extends CommonObject
$label.= '<u>' . $langs->trans("ShowCategorySupplier") . '</u>';
$link = '<a href="'.DOL_URL_ROOT.'/categories/categorie.php?id='.$this->id.'&type=1';
}
else if ($option == 'margin')
{
$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
$link = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
}
// By default
if (empty($link))
{