26require
'../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/margin/lib/margins.lib.php';
33$langs->loadLangs(array(
'companies',
'bills',
'products',
'margins'));
35$action =
GETPOST(
'action',
'alpha');
36$massaction =
GETPOST(
'massaction',
'alpha');
37$toselect =
GETPOST(
'toselect',
'array');
38$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'margindetail';
39$backtopage =
GETPOST(
'backtopage',
'alpha');
40$optioncss =
GETPOST(
'optioncss',
'alpha');
43$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
44$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
45$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
46$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
47if (empty($page) || $page == -1) {
50$offset = $limit * $page;
60$startdate = $enddate =
'';
65$search_ref =
GETPOST(
'search_ref',
'alpha');
73} elseif (
GETPOST(
"button_updatemagins_x") ||
GETPOST(
"button_updatemagins")) {
82if (
GETPOST(
'cancel',
'alpha')) {
83 $action =
'list'; $massaction =
'';
85if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
90$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
97 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
99 if ($action ==
'update') {
102 foreach ($datapost as $key => $value) {
103 if (strpos($key,
'buyingprice_') !==
false) {
104 $tmp_array = explode(
'_', $key);
105 if (count($tmp_array) > 0) {
106 $invoicedet_id = $tmp_array[1];
107 if (!empty($invoicedet_id)) {
108 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'facturedet';
109 $sql .=
" SET buy_price_ht = ".((float)
price2num($value));
110 $sql .=
' WHERE rowid = '.((int) $invoicedet_id);
111 $result = $db->query($sql);
122 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
124 $search_array_options = array();
145$userstatic =
new User($db);
146$companystatic =
new Societe($db);
147$invoicestatic =
new Facture($db);
148$productstatic =
new Product($db);
150$form =
new Form($db);
152$title = $langs->trans(
"Margins");
159if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
160 $param .=
'&contextpage='.$contextpage;
162if ($limit > 0 && $limit != $conf->liste_limit) {
163 $param .=
'&limit='.$limit;
165if ($search_ref !=
'') {
166 $param .=
'&search_ref='.urlencode($search_ref);
168if (!empty($startdate)) {
169 $param .=
'&startdatemonth='.GETPOST(
'startdatemonth',
'int').
'&startdateday='.
GETPOST(
'startdateday',
'int').
'&startdateyear='.
GETPOST(
'startdateyear',
'int');
171if (!empty($enddate)) {
172 $param .=
'&enddatemonth='.GETPOST(
'enddatemonth',
'int').
'&enddateday='.
GETPOST(
'enddateday',
'int').
'&enddateyear='.
GETPOST(
'enddateyear',
'int');
174if ($optioncss !=
'') {
175 $param .=
'&optioncss='.$optioncss;
183print
'<form method="post" name="sel" action="'.$_SERVER[
'PHP_SELF'].
'">';
184print
'<input type="hidden" name="token" value="'.newToken().
'">';
188print
'<table class="border centpercent">';
190print
'<tr><td class="titlefield">'.$langs->trans(
'DateStart').
' ('.$langs->trans(
"DateValidation").
')</td>';
192print $form->selectDate($startdate,
'startdate',
'',
'', 1,
"sel", 1, 1);
194print
'<td>'.$langs->trans(
'DateEnd').
' ('.$langs->trans(
"DateValidation").
')</td>';
196print $form->selectDate($enddate,
'enddate',
'',
'', 1,
"sel", 1, 1);
198print
'<td style="text-align: center;">';
199print
'<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans(
'Refresh')).
'" name="button_search" />';
207$arrayfields = array();
208$massactionbutton =
'';
213$sql .=
" f.ref, f.rowid as invoiceid,";
214$sql .=
" d.rowid as invoicedetid, d.product_type, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description, d.qty, d.fk_product";
215$sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f ";
216$sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facturedet as d ON d.fk_facture = f.rowid";
217$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON d.fk_product = p.rowid";
218$sql .=
" WHERE f.fk_statut NOT IN (".$db->sanitize(implode(
', ', $invoice_status_except_list)).
")";
219$sql .=
" AND f.entity IN (".getEntity(
'invoice').
") ";
220if (!empty($startdate)) {
221 $sql .=
" AND f.datef >= '".$db->idate($startdate).
"'";
223if (!empty($enddate)) {
224 $sql .=
" AND f.datef <= '".$db->idate($enddate).
"'";
229$sql .=
" AND d.buy_price_ht IS NOT NULL";
230$sql .= $db->order($sortfield, $sortorder);
232$nbtotalofrecords =
'';
235 $result = $db->query($sql);
236 $nbtotalofrecords = $db->num_rows($result);
237 if (($page * $limit) > $nbtotalofrecords) {
243$sql .= $db->plimit($limit + 1, $offset);
245$result = $db->query($sql);
247 $num = $db->num_rows($result);
250 print_barre_liste($langs->trans(
"MarginDetails"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'', 0,
'',
'', $limit);
252 if ($conf->global->MARGIN_TYPE ==
"1") {
253 $labelcostprice =
'BuyingPrice';
255 $labelcostprice =
'CostPrice';
260 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
263 $selectedfields =
'';
265 print
'<div class="div-table-responsive">';
266 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
268 print
'<tr class="liste_titre liste_titre_search">';
269 print
'<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).
'"></td>';
275 print
'<td class="liste_titre" align="middle">';
276 $searchpitco = $form->showFilterButtons();
281 print
'<tr class="liste_titre">';
284 print_liste_field_titre(
"UnitPriceHT", $_SERVER[
"PHP_SELF"],
"d.subprice",
"", $param,
'', $sortfield, $sortorder,
'right ');
285 print_liste_field_titre($labelcostprice, $_SERVER[
"PHP_SELF"],
"d.buy_price_ht",
"", $param,
'', $sortfield, $sortorder,
'right ');
286 print_liste_field_titre(
"Qty", $_SERVER[
"PHP_SELF"],
"d.qty",
"", $param,
'', $sortfield, $sortorder,
'right ');
287 print_liste_field_titre(
"AmountTTC", $_SERVER[
"PHP_SELF"],
"d.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right ');
288 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'', $param,
'', $sortfield, $sortorder,
'maxwidthsearch center ');
292 while ($i < min($num, $limit)) {
293 $objp = $db->fetch_object($result);
295 print
'<tr class="oddeven">';
297 $result_inner = $invoicestatic->fetch($objp->invoiceid);
298 if ($result_inner < 0) {
301 print $invoicestatic->getNomUrl(1);
305 if (!empty($objp->fk_product)) {
306 $result_inner = $productstatic->fetch($objp->fk_product);
307 if ($result_inner < 0) {
310 print $productstatic->getNomUrl(1);
313 if ($objp->product_type == $productstatic::TYPE_PRODUCT) {
316 if ($objp->product_type == $productstatic::TYPE_SERVICE) {
321 print $objp->description;
324 print
'<td class="right">';
325 print
price($objp->subprice);
327 print
'<td class="right">';
328 print
'<input type="text" name="buyingprice_'.$objp->invoicedetid.
'" id="buyingprice_'.$objp->invoicedetid.
'" size="6" value="'.
price($objp->buy_price_ht).
'" class="right flat">';
330 print
'<td class="right">';
333 print
'<td class="right">';
334 print
'<span class="amount">'.price($objp->total_ht).
'</span>';
351print
'<div class="center">'.
"\n";
352print
'<input type="submit" class="button" name="button_updatemagins" id="button_updatemagins" value="'.$langs->trans(
"Update").
'">';
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 STATUS_DRAFT
Draft status.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
print_barre_liste($titre, $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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
marges_prepare_head()
Return array of tabs to used on pages for third parties cards.
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.