* Copyright (C) 2014 Ferran Marcet * Copyright (C) 2015 Marcos GarcĂ­a * Copyright (C) 2016 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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 . */ /** * \file htdocs/margin/checkMargins.php * \ingroup margin * \brief Check margins */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php'; $langs->load("companies"); $langs->load("bills"); $langs->load("products"); $langs->load("margins"); // Load variable for pagination $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder = "DESC"; if (! $sortfield) $sortfield = 'f.facnumber'; $startdate = $enddate = ''; $startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int')); $enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int')); $search_ref = GETPOST('search_ref','alpha'); // Security check $result=restrictedArea($user,'margins'); // Both test are required to be compatible with all browsers if (GETPOST("button_search_x") || GETPOST("button_search")) { $action = 'search'; } elseif (GETPOST("button_updatemagins_x") || GETPOST("button_updatemagins")) { $action = 'update'; } /* * Actions */ if (GETPOST('cancel')) { $action='list'; $massaction=''; } if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } $parameters=array(); $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'); if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; if ($action == 'update') { $datapost = $_POST; foreach ( $datapost as $key => $value ) { if (strpos($key, 'buyingprice_') !== false) { $tmp_array = explode('_', $key); if (count($tmp_array) > 0) { $invoicedet_id = $tmp_array[1]; if (! empty($invoicedet_id)) { $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet'; $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\''; $sql .= ' WHERE rowid=' . $invoicedet_id; $result = $db->query($sql); if (!$result) { setEventMessages($db->lasterror, null, 'errors'); } } } } } } // Purge search criteria if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers { $search_ref=''; $search_array_options=array(); } // Mass actions /* $objectclass='Product'; if ((string) $type == '1') { $objectlabel='Services'; } if ((string) $type == '0') { $objectlabel='Products'; } $permtoread = $user->rights->produit->lire; $permtodelete = $user->rights->produit->supprimer; $uploaddir = $conf->product->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; */ } /* * View */ $userstatic = new User($db); $companystatic = new Societe($db); $invoicestatic = new Facture($db); $productstatic = new Product($db); $form = new Form($db); $title = $langs->trans("Margins"); llxHeader('', $title); // print_fiche_titre($text); $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if (! empty($startdate)) { $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int'); } if (! empty($enddate)) { $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int'); } if ($optioncss != '') $param.='&optioncss='.$optioncss; // Show tabs $head = marges_prepare_head($user); $picto = 'margin'; print '
'; dol_fiche_head($head, $langs->trans('checkMargins'), $title, 0, $picto); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "
' . $langs->trans('DateStart') . ' (' . $langs->trans("DateValidation") . ')'; $form->select_date($startdate, 'startdate', '', '', 1, "sel", 1, 1); print '' . $langs->trans('DateEnd') . ' (' . $langs->trans("DateValidation") . ')'; $form->select_date($enddate, 'enddate', '', '', 1, "sel", 1, 1); print ''; print ''; print '
"; dol_fiche_end(); $arrayfields=array(); $massactionbutton=''; $sql = "SELECT"; $sql .= " f.facnumber, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty"; $sql .= " ,d.fk_product"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d ON d.fk_facture = f.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid"; $sql .= " WHERE f.fk_statut > 0"; $sql .= " AND f.entity = " . getEntity('facture'); if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; if (! empty($enddate)) $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; if ($search_ref) $sql.=natural_search('f.facnumber', $search_ref); $sql .= " AND d.buy_price_ht IS NOT NULL"; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { dol_syslog(__FILE__, LOG_DEBUG); $result = $db->query($sql); if ($result) { $nbtotalofrecords = $db->num_rows($result); } else { setEventMessages($db->lasterror, null, 'errors'); } } $sql .= $db->plimit($limit+1, $offset); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); print '
'; print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); if ($conf->global->MARGIN_TYPE == "1") $labelcostprice='BuyingPrice'; else // value is 'costprice' or 'pmp' $labelcostprice='CostPrice'; $moreforfilter=''; $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); $selectedfields=''; print '
'; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.facnumber", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder); print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; $i=0; while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $i ++; } print "
'; $result_inner = $invoicestatic->fetch($objp->invoiceid); if ($result_inner < 0) { setEventMessages($invoicestatic->error, null, 'errors'); } else { print $invoicestatic->getNomUrl(1); } print ''; if (! empty($objp->fk_product)) { $result_inner = $productstatic->fetch($objp->fk_product); if ($result_inner < 0) { setEventMessages($productstatic->error, null, 'errors'); } else { print $productstatic->getNomUrl(1); } } else { print $objp->label; print ' '; print $objp->description; } print ''; print price($objp->subprice); print ''; print ''; print ''; print $objp->qty; print ''; print price($objp->total_ht); print '
"; print "
"; } else { dol_print_error($db); } print '
' . "\n"; print ''; print '
'; print '
'; $db->free($result); llxFooter(); $db->close();