* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2015 Marcos GarcĂ­a * * 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/societe/price.php * \ingroup product * \brief Page to show product prices by customer */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; $prodcustprice = new Productcustomerprice($db); } $langs->load("products"); $langs->load("companies"); $langs->load("bills"); $action = GETPOST('action', 'alpha'); // Security check $socid = GETPOST('socid', 'int'); if ($user->societe_id) $socid = $user->societe_id; $result = restrictedArea($user, 'societe', $socid, '&societe'); /** * *************************************************** * Price by customer * **************************************************** */ if ($action == 'add_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { $update_child_soc = GETPOST('updatechildprice'); // add price by customer $prodcustprice->fk_soc = $socid; $prodcustprice->fk_product = GETPOST('prodid', 'int'); $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); $result = $prodcustprice->create($user, 0, $update_child_soc); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } else { setEventMessage($langs->trans('Save'), 'mesgs'); } $action = ''; } if ($action == 'delete_customer_price' && ($user->rights->produit->creer || $user->rights->service->creer)) { // Delete price by customer $prodcustprice->id = GETPOST('lineid'); $result = $prodcustprice->delete($user); if ($result < 0) { setEventMessage($prodcustprice->error, 'mesgs'); } else { setEventMessage($langs->trans('Delete'), 'errors'); } $action = ''; } if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { $prodcustprice->fetch(GETPOST('lineid', 'int')); $update_child_soc = GETPOST('updatechildprice'); // update price by customer $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); $result = $prodcustprice->update($user, 0, $update_child_soc); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } else { setEventMessage($langs->trans('Save'), 'mesgs'); } $action = ''; } /* * View */ $form = new Form($db); $soc = new Societe($db); $result = $soc->fetch($socid); llxHeader("", $langs->trans("ThirdParty") . '-' . $langs->trans('PriceByCustomer')); if (! empty($conf->notification->enabled)) $langs->load("mails"); $head = societe_prepare_head($soc); dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), 0, 'company'); print ''; print ''; // Alias names (commercial, trademark or alias names) print '"; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } if ($soc->client) { print ''; } if ($soc->fournisseur) { print ''; } if (! empty($conf->barcode->enabled)) { print ''; } print ""; // Zip / Town print '"; print '"; // Country if ($soc->country) { print ''; } // EMail print ''; // Web print ''; // Phone / Fax print ''; print ''; print '
' . $langs->trans("ThirdPartyName") . ''; print $form->showrefnav($soc, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom'); print '
'.$langs->trans('AliasNames').''; print $soc->name_alias; print "
' . $langs->trans('Prefix') . '' . $soc->prefix_comm . '
'; print $langs->trans('CustomerCode') . ''; print $soc->code_client; if ($soc->check_codeclient() != 0) print ' (' . $langs->trans("WrongCustomerCode") . ')'; print '
'; print $langs->trans('SupplierCode') . ''; print $soc->code_fournisseur; if ($soc->check_codefournisseur() != 0) print ' (' . $langs->trans("WrongSupplierCode") . ')'; print '
' . $langs->trans('Gencod') . '' . $soc->barcode . '
" . $langs->trans('Address') . ""; dol_print_address($soc->address, 'gmap', 'thirdparty', $soc->id); print "
' . $langs->trans('Zip') . '' . $soc->zip . "' . $langs->trans('Town') . '' . $soc->town . "
' . $langs->trans('Country') . ''; $img = picto_from_langcode($soc->country_code); print($img ? $img . ' ' : ''); print $soc->country; print '
' . $langs->trans('EMail') . ''; print dol_print_email($soc->email, 0, $soc->id, 'AC_EMAIL'); print '
' . $langs->trans('Web') . ''; print dol_print_url($soc->url); print '
' . $langs->trans('Phone') . '' . dol_print_phone($soc->tel, $soc->country_code, 0, $soc->id, 'AC_TEL') . '' . $langs->trans('Fax') . '' . dol_print_phone($soc->fax, $soc->country_code, 0, $soc->id, 'AC_FAX') . '
'; print ''; if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { $prodcustprice = new Productcustomerprice($db); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", 'int'); if ($page == - 1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder = "ASC"; if (! $sortfield) $sortfield = "soc.nom"; // Build filter to diplay only concerned lines $filter = array ( 't.fk_soc' => $soc->id ); $search_soc = GETPOST('search_soc'); if (! empty($search_soc)) { $filter ['soc.nom'] = $search_soc; } if ($action == 'add_customer_price') { // Create mode print_fiche_titre($langs->trans('PriceByCustomer')); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // VAT print ''; // Price base print ''; print ''; print ''; // Price print ''; // Price minimum print ''; // Update all child soc print ''; print ''; print ''; print '
' . $langs->trans('Product') . ''; print $form->select_produits('', 'prodid', '', 0); print '
' . $langs->trans("VATRate") . ''; print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr); print '
'; print $langs->trans('PriceBase'); print ''; print $form->selectPriceBaseType($object->price_base_type, "price_base_type"); print '
'; $text = $langs->trans('SellingPrice'); print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); print ''; if ($object->price_base_type == 'TTC') { print ''; } else { print ''; } print '
'; $text = $langs->trans('MinPrice'); print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); if ($object->price_base_type == 'TTC') { print ''; } else { print ''; } print '
'; print $langs->trans('ForceUpdateChildPriceSoc'); print ''; print ''; print '
'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; } elseif ($action == 'edit_customer_price') { // Edit mode print_fiche_titre($langs->trans('PriceByCustomer')); $result = $prodcustprice->fetch(GETPOST('lineid', 'int')); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; $staticprod = new Product($db); $staticprod->fetch($prodcustprice->fk_product); print ""; print ''; // VAT print ''; // Price base print ''; print ''; print ''; // Price print ''; // Price minimum print ''; // Update all child soc print ''; print ''; print ''; print '
' . $langs->trans('Product') . '" . $staticprod->getNomUrl(1) . "
' . $langs->trans("VATRate") . ''; print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $staticprod->id, $prodcustprice->recuperableonly); print '
'; print $langs->trans('PriceBase'); print ''; print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type"); print '
'; $text = $langs->trans('SellingPrice'); print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); print ''; if ($prodcustprice->price_base_type == 'TTC') { print ''; } else { print ''; } print '
'; $text = $langs->trans('MinPrice'); print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); print ''; if ($prodcustprice->price_base_type == 'TTC') { print ''; } else { print ''; } print '
'; print $langs->trans('ForceUpdateChildPriceSoc'); print ''; print ''; print '
'; print '
'; print ''; print '     '; print ''; print '
'; print '
'; } elseif ($action == 'showlog_customer_price') { $filter = array ( 't.fk_product' => GETPOST('prodid', 'int'),'t.fk_soc' => $socid ); // Count total nb of records $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); } $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } $option = '&socid=' . GETPOST('socid', 'int') . '&prodid=' . GETPOST('prodid', 'int'); print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords); if (count($prodcustprice->lines) > 0) { print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var = True; foreach ( $prodcustprice->lines as $line ) { print ""; $staticprod = new Product($db); $staticprod->fetch($line->fk_product); print ""; print ""; print '"; print '"; print '"; print '"; print ''; print ''; // User $userstatic = new User($db); $userstatic->fetch($line->fk_user); print ''; } print "
' . $langs->trans("Product") . '' . $langs->trans("AppliedPricesFrom") . '' . $langs->trans("PriceBase") . '' . $langs->trans("VAT") . '' . $langs->trans("HT") . '' . $langs->trans("TTC") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . '' . $langs->trans("ChangedBy") . ' 
" . $staticprod->getNomUrl(1) . "" . dol_print_date($line->datec, "dayhour") . "' . $langs->trans($line->price_base_type) . "' . vatrate($line->tva_tx, true, $line->recuperableonly) . "' . price($line->price) . "' . price($line->price_ttc) . "' . price($line->price_min) . '' . price($line->price_min_ttc) . ''; print $userstatic->getLoginUrl(1); print '
"; } else { print $langs->trans('None'); } print "\n" . '
' . "\n"; print ''; print "\n

\n"; } else { // View mode // Count total nb of records $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $prodcustprice->fetch_all('', '', 0, 0, $filter); } $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } $option = '&search_soc=' . $search_soc . '&id=' . $object->id; print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords); if (count($prodcustprice->lines) > 0) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Print the search button print ''; print ''; $var = False; foreach($prodcustprice->lines as $line) { print ""; $staticprod = new Product($db); $staticprod->fetch($line->fk_product); print ""; print ""; print '"; print '"; print '"; print '"; print ''; print ''; // User $userstatic = new User($db); $userstatic->fetch($line->fk_user); print ''; // Todo Edit or delete button // Action if ($user->rights->produit->creer || $user->rights->service->creer) { print ''; } print "\n"; } print "
' . $langs->trans("Product") . '' . $langs->trans("AppliedPricesFrom") . '' . $langs->trans("PriceBase") . '' . $langs->trans("VAT") . '' . $langs->trans("HT") . '' . $langs->trans("TTC") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . '' . $langs->trans("ChangedBy") . ' 
 '; print ''; print '
" . $staticprod->getNomUrl(1) . "" . dol_print_date($line->datec, "dayhour") . "' . $langs->trans($line->price_base_type) . "' . vatrate($line->tva_tx, true, $line->recuperableonly) . "' . price($line->price) . "' . price($line->price_ttc) . "' . price($line->price_min) . '' . price($line->price_min_ttc) . ''; print $userstatic->getLoginUrl(1); print ''; print 'id . '&prodid=' . $line->fk_product . '">'; print img_info(); print ''; print ' '; print 'id . '&lineid=' . $line->id . '">'; print img_edit('default', 0, 'style="vertical-align: middle;"'); print ''; print ' '; print 'id . '&lineid=' . $line->id . '">'; print img_delete('default', 'style="vertical-align: middle;"'); print ''; print '
"; print "
"; } else { print $langs->trans('None'); } /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n" . '
' . "\n"; if ($user->rights->produit->creer || $user->rights->service->creer) { print ''; } print "\n

\n"; } } llxFooter(); $db->close();