25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
30$langs->loadLangs(array(
"companies",
"bills",
"products",
"margins"));
34if (!empty($user->socid)) {
35 $socid = $user->socid;
39$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
40$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
42if (empty($page) || $page == -1) {
45$offset = $limit * $page;
52 $sortfield =
"f.datef";
61$hookmanager->initHooks(array(
'thirdpartymargins',
'globalcard'));
65if (!$user->hasRight(
'margins',
'liretous')) {
74$parameters = array(
'id' => $socid);
75$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
86$invoicestatic =
new Facture($db);
89$title = $langs->trans(
"ThirdParty").
' - '.$langs->trans(
"Margins");
91 $title =
$object->name.
' - '.$langs->trans(
"Files");
93$help_url =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
109 print
dol_get_fiche_head($head,
'margin', $langs->trans(
"ThirdParty"), -1,
'company');
111 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
113 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
115 print
'<div class="fichecenter">';
117 print
'<div class="underbanner clearboth"></div>';
118 print
'<table class="border tableforfield" width="100%">';
121 print
'<tr><td class="titlefield">'.$langs->trans(
'NatureOfThirdParty').
'</td><td>';
126 print
'<tr><td class="titlefield">';
127 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
129 $tmpcheck =
$object->check_codeclient();
130 if ($tmpcheck != 0 && $tmpcheck != -5) {
131 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
136 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) {
137 print
'<tr><td class="titlefield">';
138 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
140 $tmpcheck =
$object->check_codefournisseur();
141 if ($tmpcheck != 0 && $tmpcheck != -5) {
142 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
148 print
'<tr><td class="titlefield">'.$langs->trans(
"TotalMargin").
'</td><td colspan="3">';
149 print
'<span id="totalMargin" class="amount"></span>';
154 print
'<tr><td>'.$langs->trans(
"MarginRate").
'</td><td colspan="3">';
155 print
'<span id="marginRate"></span>';
161 print
'<tr><td>'.$langs->trans(
"MarkRate").
'</td><td colspan="3">';
162 print
'<span id="markRate"></span>';
169 print
'<div class="clearboth"></div>';
175 $sql =
"SELECT distinct s.nom, s.rowid as socid, s.code_client,";
176 $sql .=
" f.rowid as facid, f.ref, f.total_ht,";
177 $sql .=
" f.datef, f.paye, f.fk_statut as statut, f.type,";
178 $sql .=
" sum(d.total_ht) as selling_price,";
179 $sql .=
" sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,";
180 $sql .=
" sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge";
181 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
182 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
183 $sql .=
", ".MAIN_DB_PREFIX.
"facturedet as d";
184 $sql .=
" WHERE f.fk_soc = s.rowid";
185 $sql .=
" AND f.fk_statut > 0";
186 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
187 $sql .=
" AND d.fk_facture = f.rowid";
188 $sql .=
" AND f.fk_soc = $socid";
189 $sql .=
" AND d.buy_price_ht IS NOT NULL";
193 $sql .=
" AND d.buy_price_ht <> 0";
195 $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";
196 $sql .= $db->order($sortfield, $sortorder);
200 dol_syslog(
'margin:tabs:thirdpartyMargins.php', LOG_DEBUG);
201 $result = $db->query($sql);
203 $num = $db->num_rows($result);
206 print_barre_liste($langs->trans(
"MarginDetails"), $page, $_SERVER[
"PHP_SELF"],
"&socid=".$object->id, $sortfield, $sortorder,
'', $num, $num,
'');
209 print
'<div class="div-table-responsive">';
210 print
"<table class=\"noborder\" width=\"100%\">";
212 print
'<tr class="liste_titre">';
213 print_liste_field_titre(
"Invoice", $_SERVER[
"PHP_SELF"],
"f.ref",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder);
214 print_liste_field_titre(
"DateInvoice", $_SERVER[
"PHP_SELF"],
"f.datef",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'center ');
215 print_liste_field_titre(
"SoldAmount", $_SERVER[
"PHP_SELF"],
"selling_price",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
216 print_liste_field_titre(
"PurchasedAmount", $_SERVER[
"PHP_SELF"],
"buying_price",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
217 print_liste_field_titre(
"Margin", $_SERVER[
"PHP_SELF"],
"marge",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
219 print_liste_field_titre(
"MarginRate", $_SERVER[
"PHP_SELF"],
"",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
222 print_liste_field_titre(
"MarkRate", $_SERVER[
"PHP_SELF"],
"",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
224 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"f.paye,f.fk_statut",
"",
"&socid=".$_REQUEST[
"socid"],
'', $sortfield, $sortorder,
'right ');
232 $objp = $db->fetch_object($result);
234 $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) :
'';
235 $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) :
'';
242 print
'<tr class="oddeven">';
244 $invoicestatic->id = $objp->facid;
245 $invoicestatic->ref = $objp->ref;
246 print $invoicestatic->getNomUrl(1);
248 print
"<td class=\"center\">";
250 print
"<td class=\"right amount\">".price(
price2num($objp->selling_price,
'MT')).
"</td>\n";
251 print
"<td class=\"right amount\">".price(
price2num(($objp->type == 2 ? -1 : 1) * $objp->buying_price,
'MT')).
"</td>\n";
252 print
"<td class=\"right amount\">".$sign.price(
price2num($objp->marge,
'MT')).
"</td>\n";
254 print
"<td class=\"right\">".(($marginRate ===
'') ?
'n/a' : $sign.
price(
price2num($marginRate,
'MT')).
"%").
"</td>\n";
257 print
"<td class=\"right\">".(($markRate ===
'') ?
'n/a' :
price(
price2num($markRate,
'MT')).
"%").
"</td>\n";
259 print
'<td class="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).
'</td>';
262 $cumul_vente += $objp->selling_price;
263 $cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price;
269 $totalMargin = $cumul_vente - $cumul_achat;
270 if ($totalMargin < 0) {
271 $marginRate = ($cumul_achat != 0) ? -1 * (100 * $totalMargin / $cumul_achat) :
'';
272 $markRate = ($cumul_vente != 0) ? -1 * (100 * $totalMargin / $cumul_vente) :
'';
274 $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) :
'';
275 $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) :
'';
279 print
'<tr class="liste_total">';
280 print
'<td colspan=2>'.$langs->trans(
'TotalMargin').
"</td>";
281 print
"<td class=\"right\">".price(
price2num($cumul_vente,
'MT')).
"</td>\n";
282 print
"<td class=\"right\">".price(
price2num($cumul_achat,
'MT')).
"</td>\n";
283 print
"<td class=\"right\">".price(
price2num($totalMargin,
'MT')).
"</td>\n";
285 print
"<td class=\"right\">".(($marginRate ===
'') ?
'n/a' :
price(
price2num($marginRate,
'MT')).
"%").
"</td>\n";
288 print
"<td class=\"right\">".(($markRate ===
'') ?
'n/a' :
price(
price2num($markRate,
'MT')).
"%").
"</td>\n";
290 print
'<td class="right"> </td>';
306 <script type="text/javascript">
307 $(document).ready(function() {
308 $("#totalMargin").html("'.
price(
price2num($totalMargin,
'MT')).
'");
309 $("#marginRate").html("'.(($marginRate ===
'') ?
'n/a' :
price(
price2num($marginRate,
'MT')).
"%").
'");
310 $("#markRate").html("'.(($markRate ===
'') ?
'n/a' :
price(
price2num($markRate,
'MT')).
"%").
'");
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage third parties objects (customers, suppliers, prospects...)
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.