price.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/societe/price.php
  24. * \ingroup product
  25. * \brief Page to show product prices by customer
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  33. if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
  35. $prodcustprice = new Productcustomerprice($db);
  36. }
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("products", "companies", "bills"));
  39. // Get parameters
  40. $action = GETPOST('action', 'aZ09');
  41. $search_prod = GETPOST('search_prod', 'alpha');
  42. $cancel = GETPOST('cancel', 'alpha');
  43. $search_label = GETPOST('search_label', 'alpha');
  44. $search_price = GETPOST('search_price');
  45. $search_price_ttc = GETPOST('search_price_ttc');
  46. // Security check
  47. $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
  48. if ($user->socid) {
  49. $socid = $user->socid;
  50. }
  51. $result = restrictedArea($user, 'societe', $socid, '&societe');
  52. // Initialize objects
  53. $object = new Societe($db);
  54. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  55. $hookmanager->initHooks(array('thirdpartycustomerprice', 'globalcard'));
  56. $error = 0;
  57. /*
  58. * Actions
  59. */
  60. $parameters = array('id'=>$socid);
  61. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  62. if ($reshook < 0) {
  63. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  64. }
  65. if (empty($reshook)) {
  66. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  67. $search_prod = $search_label = $search_price = $search_price_ttc = '';
  68. }
  69. if ($action == 'add_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  70. if (!(GETPOST('prodid', 'int') > 0)) {
  71. $error++;
  72. setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Product")), null, 'errors');
  73. $action = 'add_customer_price';
  74. }
  75. if (!$error) {
  76. $update_child_soc = GETPOST('updatechildprice');
  77. // add price by customer
  78. $prodcustprice->fk_soc = $socid;
  79. $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
  80. $prodcustprice->fk_product = GETPOST('prodid', 'int');
  81. $prodcustprice->price = price2num(GETPOST("price"), 'MU');
  82. $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
  83. $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
  84. $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
  85. // We must define tva_tx, npr and local taxes
  86. $vatratecode = '';
  87. $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
  88. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  89. $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
  90. // If value contains the unique code of vat line (new recommended method), we use it to find npr and local taxes
  91. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  92. // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
  93. $vatratecode = $reg[1];
  94. // Get record from code
  95. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  96. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  97. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  98. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  99. $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
  100. $resql = $db->query($sql);
  101. if ($resql) {
  102. $obj = $db->fetch_object($resql);
  103. $npr = $obj->recuperableonly;
  104. $localtax1 = $obj->localtax1;
  105. $localtax2 = $obj->localtax2;
  106. $localtax1_type = $obj->localtax1_type;
  107. $localtax2_type = $obj->localtax2_type;
  108. }
  109. }
  110. $prodcustprice->default_vat_code = $vatratecode;
  111. $prodcustprice->tva_tx = $tva_tx;
  112. $prodcustprice->recuperableonly = $npr;
  113. $prodcustprice->localtax1_tx = $localtax1;
  114. $prodcustprice->localtax2_tx = $localtax2;
  115. $prodcustprice->localtax1_type = $localtax1_type;
  116. $prodcustprice->localtax2_type = $localtax2_type;
  117. $result = $prodcustprice->create($user, 0, $update_child_soc);
  118. if ($result < 0) {
  119. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  120. } else {
  121. setEventMessages($langs->trans("Save"), null, 'mesgs');
  122. }
  123. $action = '';
  124. }
  125. }
  126. if ($action == 'delete_customer_price' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  127. // Delete price by customer
  128. $prodcustprice->id = GETPOST('lineid', 'int');
  129. $result = $prodcustprice->delete($user);
  130. if ($result < 0) {
  131. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'mesgs');
  132. } else {
  133. setEventMessages($langs->trans('RecordDeleted'), null, 'errors');
  134. }
  135. $action = '';
  136. }
  137. if ($action == 'update_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  138. $prodcustprice->fetch(GETPOST('lineid', 'int'));
  139. $update_child_soc = GETPOST('updatechildprice');
  140. // update price by customer
  141. $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
  142. $prodcustprice->price = price2num(GETPOST("price"), 'MU');
  143. $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
  144. $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
  145. $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx"));
  146. $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0);
  147. $result = $prodcustprice->update($user, 0, $update_child_soc);
  148. if ($result < 0) {
  149. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  150. } else {
  151. setEventMessages($langs->trans("Save"), null, 'mesgs');
  152. }
  153. $action = '';
  154. }
  155. }
  156. /*
  157. * View
  158. */
  159. $form = new Form($db);
  160. $object = new Societe($db);
  161. $result = $object->fetch($socid);
  162. llxHeader("", $langs->trans("ThirdParty").'-'.$langs->trans('PriceByCustomer'));
  163. if (isModEnabled('notification')) {
  164. $langs->load("mails");
  165. }
  166. $head = societe_prepare_head($object);
  167. print dol_get_fiche_head($head, 'price', $langs->trans("ThirdParty"), -1, 'company');
  168. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  169. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  170. print '<div class="fichecenter">';
  171. print '<div class="underbanner clearboth"></div>';
  172. print '<table class="border centpercent tableforfield">';
  173. // Type Prospect/Customer/Supplier
  174. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  175. print $object->getTypeUrl(1);
  176. print '</td></tr>';
  177. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  178. print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  179. }
  180. if ($object->client) {
  181. print '<tr><td class="titlefield">';
  182. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  183. print $object->code_client;
  184. $tmpcheck = $object->check_codeclient();
  185. if ($tmpcheck != 0 && $tmpcheck != -5) {
  186. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  187. }
  188. print '</td></tr>';
  189. }
  190. if ($object->fournisseur) {
  191. print '<tr><td class="titlefield">';
  192. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  193. print $object->code_fournisseur;
  194. $tmpcheck = $object->check_codefournisseur();
  195. if ($tmpcheck != 0 && $tmpcheck != -5) {
  196. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  197. }
  198. print '</td></tr>';
  199. }
  200. print '</table>';
  201. print '</div>';
  202. print dol_get_fiche_end();
  203. if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  204. $prodcustprice = new Productcustomerprice($db);
  205. $sortfield = GETPOST('sortfield', 'aZ09comma');
  206. $sortorder = GETPOST('sortorder', 'aZ09comma');
  207. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  208. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  209. if (empty($page) || $page == -1) {
  210. $page = 0;
  211. } // If $page is not defined, or '' or -1
  212. $offset = $limit * $page;
  213. $pageprev = $page - 1;
  214. $pagenext = $page + 1;
  215. if (!$sortorder) {
  216. $sortorder = "ASC";
  217. }
  218. if (!$sortfield) {
  219. $sortfield = "soc.nom";
  220. }
  221. // Build filter to display only concerned lines
  222. $filter = array(
  223. 't.fk_soc' => $object->id
  224. );
  225. if (!empty($search_prod)) {
  226. $filter ['prod.ref'] = $search_prod;
  227. }
  228. if (!empty($search_label)) {
  229. $filter ['prod.label'] = $search_label;
  230. }
  231. if (!empty($search_price)) {
  232. $filter ['t.price'] = $search_price;
  233. }
  234. if (!empty($search_price_ttc)) {
  235. $filter ['t.price_ttc'] = $search_price_ttc;
  236. }
  237. if ($action == 'add_customer_price') {
  238. // Create mode
  239. print '<br>';
  240. print '<!-- Price by customer -->'."\n";
  241. print load_fiche_titre($langs->trans('PriceByCustomer'));
  242. print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
  243. print '<input type="hidden" name="token" value="'.newToken().'">';
  244. print '<input type="hidden" name="action" value="add_customer_price_confirm">';
  245. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  246. print '<table class="border centpercent">';
  247. print '<tr>';
  248. print '<td>'.$langs->trans('Product').'</td>';
  249. print '<td>';
  250. $form->select_produits('', 'prodid', '', 0);
  251. print '</td>';
  252. print '</tr>';
  253. // Ref. Customer
  254. print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
  255. print '<td><input name="ref_customer" size="12"></td></tr>';
  256. // VAT
  257. print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
  258. print $form->load_tva("tva_tx", GETPOST("tva_tx", "alpha"), $mysoc, '', $object->id, 0, '', false, 1);
  259. print '</td></tr>';
  260. // Price base
  261. print '<tr><td width="15%">';
  262. print $langs->trans('PriceBase');
  263. print '</td>';
  264. print '<td>';
  265. print $form->selectPriceBaseType(GETPOST("price_base_type", "aZ09"), "price_base_type");
  266. print '</td>';
  267. print '</tr>';
  268. // Price
  269. print '<tr><td width="20%">';
  270. $text = $langs->trans('SellingPrice');
  271. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  272. print '</td><td>';
  273. print '<input name="price" size="10" value="'.GETPOST('price', 'int').'">';
  274. print '</td></tr>';
  275. // Price minimum
  276. print '<tr><td>';
  277. $text = $langs->trans('MinPrice');
  278. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  279. print '<td><input name="price_min" size="10" value="'.GETPOST('price_min', 'int').'">';
  280. print '</td></tr>';
  281. // Update all child soc
  282. print '<tr><td width="15%">';
  283. print $langs->trans('ForceUpdateChildPriceSoc');
  284. print '</td>';
  285. print '<td>';
  286. print '<input type="checkbox" name="updatechildprice" value="1"/>';
  287. print '</td>';
  288. print '</tr>';
  289. print '</table>';
  290. print $form->buttonsSaveCancel();
  291. print '</form>';
  292. } elseif ($action == 'edit_customer_price') {
  293. // Edit mode
  294. print load_fiche_titre($langs->trans('PriceByCustomer'));
  295. $result = $prodcustprice->fetch(GETPOST('lineid', 'int'));
  296. if ($result <= 0) {
  297. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  298. } else {
  299. print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
  300. print '<input type="hidden" name="token" value="'.newToken().'">';
  301. print '<input type="hidden" name="action" value="update_customer_price_confirm">';
  302. print '<input type="hidden" name="lineid" value="'.$prodcustprice->id.'">';
  303. print '<table class="border centpercent">';
  304. print '<tr>';
  305. print '<td>'.$langs->trans('Product').'</td>';
  306. $staticprod = new Product($db);
  307. $staticprod->fetch($prodcustprice->fk_product);
  308. print "<td>".$staticprod->getNomUrl(1)."</td>";
  309. print '</tr>';
  310. // Ref. Customer
  311. print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
  312. print '<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).'"></td></tr>';
  313. // VAT
  314. print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
  315. print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $staticprod->id, $prodcustprice->recuperableonly);
  316. print '</td></tr>';
  317. // Price base
  318. print '<tr><td width="15%">';
  319. print $langs->trans('PriceBase');
  320. print '</td>';
  321. print '<td>';
  322. print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type");
  323. print '</td>';
  324. print '</tr>';
  325. // Price
  326. print '<tr><td>';
  327. $text = $langs->trans('SellingPrice');
  328. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  329. print '</td><td>';
  330. if ($prodcustprice->price_base_type == 'TTC') {
  331. print '<input name="price" size="10" value="'.price($prodcustprice->price_ttc).'">';
  332. } else {
  333. print '<input name="price" size="10" value="'.price($prodcustprice->price).'">';
  334. }
  335. print '</td></tr>';
  336. // Price minimum
  337. print '<tr><td>';
  338. $text = $langs->trans('MinPrice');
  339. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  340. print '</td><td>';
  341. if ($prodcustprice->price_base_type == 'TTC') {
  342. print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).'">';
  343. } else {
  344. print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min).'">';
  345. }
  346. print '</td></tr>';
  347. // Update all child soc
  348. print '<tr><td>';
  349. print $langs->trans('ForceUpdateChildPriceSoc');
  350. print '</td>';
  351. print '<td>';
  352. print '<input type="checkbox" name="updatechildprice" value="1">';
  353. print '</td>';
  354. print '</tr>';
  355. print '</table>';
  356. print $form->buttonsSaveCancel();
  357. print '</form>';
  358. }
  359. } elseif ($action == 'showlog_customer_price') {
  360. print '<br>';
  361. print '<!-- showlog_customer_price -->'."\n";
  362. $filter = array(
  363. 't.fk_product' => GETPOST('prodid', 'int'),
  364. 't.fk_soc' => $socid
  365. );
  366. // Count total nb of records
  367. $nbtotalofrecords = '';
  368. $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
  369. if ($result < 0) {
  370. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  371. } else {
  372. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  373. $nbtotalofrecords = $result;
  374. }
  375. }
  376. $option = '&socid='.GETPOST('socid', 'int').'&prodid='.GETPOST('prodid', 'int');
  377. print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
  378. if (count($prodcustprice->lines) > 0) {
  379. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  380. print '<input type="hidden" name="token" value="'.newToken().'">';
  381. print '<input type="hidden" name="id" value="'.$object->id.'">';
  382. print '<table class="noborder centpercent">';
  383. print '<tr class="liste_titre">';
  384. print '<td>'.$langs->trans("Product").'</td>';
  385. print '<td>'.$langs->trans('RefCustomer').'</td>';
  386. print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
  387. print '<td class="center">'.$langs->trans("PriceBase").'</td>';
  388. print '<td class="right">'.$langs->trans("VAT").'</td>';
  389. print '<td class="right">'.$langs->trans("HT").'</td>';
  390. print '<td class="right">'.$langs->trans("TTC").'</td>';
  391. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
  392. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
  393. print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
  394. print '<td></td>';
  395. print '</tr>';
  396. foreach ($prodcustprice->lines as $line) {
  397. $staticprod = new Product($db);
  398. $staticprod->fetch($line->fk_product);
  399. $userstatic = new User($db);
  400. $userstatic->fetch($line->fk_user);
  401. print '<tr class="oddeven">';
  402. print "<td>".$staticprod->getNomUrl(1)."</td>";
  403. print '<td>'.$line->ref_customer.'</td>';
  404. print "<td>".dol_print_date($line->datec, "dayhour")."</td>";
  405. print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
  406. print '<td class="right">'.vatrate($line->tva_tx, true, $line->recuperableonly)."</td>";
  407. print '<td class="right">'.price($line->price)."</td>";
  408. print '<td class="right">'.price($line->price_ttc)."</td>";
  409. print '<td class="right">'.price($line->price_min).'</td>';
  410. print '<td class="right">'.price($line->price_min_ttc).'</td>';
  411. // User
  412. print '<td class="right">';
  413. print $userstatic->getNomUrl(-1);
  414. print '</td>';
  415. print '<td></td>';
  416. }
  417. print "</table>";
  418. } else {
  419. print $langs->trans('None');
  420. }
  421. print "\n".'<div class="tabsAction">'."\n";
  422. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'">'.$langs->trans("Ok").'</a></div>';
  423. print "\n</div><br>\n";
  424. } else {
  425. // View mode
  426. /*
  427. * Action bar
  428. */
  429. print "\n".'<div class="tabsAction">'."\n";
  430. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  431. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=add_customer_price&token='.newToken().'&socid='.$object->id.'">'.$langs->trans("AddCustomerPrice").'</a></div>';
  432. }
  433. print "\n</div>\n";
  434. // Count total nb of records
  435. $nbtotalofrecords = '';
  436. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  437. $nbtotalofrecords = $prodcustprice->fetchAll('', '', 0, 0, $filter);
  438. }
  439. $result = $prodcustprice->fetchAll($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
  440. if ($result < 0) {
  441. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  442. }
  443. $option = '&search_prod='.$search_prod.'&id='.$object->id.'&label='.$search_label.'&price='.$search_price.'&price_ttc='.$search_price_ttc;
  444. print '<!-- view specific price for each product -->'."\n";
  445. print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, '');
  446. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  447. print '<input type="hidden" name="token" value="'.newToken().'">';
  448. print '<input type="hidden" name="id" value="'.$object->id.'">';
  449. print '<div class="div-table-responsive-no-min">';
  450. print '<table class="noborder centpercent">';
  451. print '<tr class="liste_titre">';
  452. print '<td>'.$langs->trans("Ref").'</td>';
  453. print '<td>'.$langs->trans("Product").'</td>';
  454. print '<td>'.$langs->trans('RefCustomer').'</td>';
  455. print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
  456. print '<td class="center">'.$langs->trans("PriceBase").'</td>';
  457. print '<td class="right">'.$langs->trans("VAT").'</td>';
  458. print '<td class="right">'.$langs->trans("HT").'</td>';
  459. print '<td class="right">'.$langs->trans("TTC").'</td>';
  460. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
  461. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
  462. print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
  463. print '<td></td>';
  464. print '</tr>';
  465. if (count($prodcustprice->lines) > 0 || $search_prod) {
  466. print '<tr class="liste_titre">';
  467. print '<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="'.$search_prod.'"></td>';
  468. print '<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="'.$search_label.'"></td>';
  469. print '<td class="liste_titre"></td>';
  470. print '<td class="liste_titre"></td>';
  471. print '<td class="liste_titre"></td>';
  472. print '<td class="liste_titre"></td>';
  473. print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price" value="'.$search_price.'"></td>';
  474. print '<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price_ttc" value="'.$search_price_ttc.'"></td>';
  475. print '<td class="liste_titre"></td>';
  476. print '<td class="liste_titre"></td>';
  477. print '<td class="liste_titre"></td>';
  478. // Print the search button
  479. print '<td class="liste_titre maxwidthsearch">';
  480. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  481. print $searchpicto;
  482. print '</td>';
  483. print '</tr>';
  484. }
  485. if (count($prodcustprice->lines) > 0) {
  486. foreach ($prodcustprice->lines as $line) {
  487. $staticprod = new Product($db);
  488. $staticprod->fetch($line->fk_product);
  489. $userstatic = new User($db);
  490. $userstatic->fetch($line->fk_user);
  491. print '<tr class="oddeven">';
  492. print "<td>".$staticprod->getNomUrl(1)."</td>";
  493. print "<td>".$staticprod->label."</td>";
  494. print '<td>'.$line->ref_customer.'</td>';
  495. print "<td>".dol_print_date($line->datec, "dayhour")."</td>";
  496. print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
  497. print '<td class="right">'.vatrate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), true, $line->recuperableonly)."</td>";
  498. print '<td class="right">'.price($line->price)."</td>";
  499. print '<td class="right">'.price($line->price_ttc)."</td>";
  500. print '<td class="right">'.price($line->price_min).'</td>';
  501. print '<td class="right">'.price($line->price_min_ttc).'</td>';
  502. // User
  503. print '<td class="right">';
  504. print $userstatic->getNomUrl(-1);
  505. print '</td>';
  506. // Action
  507. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  508. print '<td class="right nowraponall">';
  509. print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=showlog_customer_price&token='.newToken().'&socid='.$object->id.'&prodid='.$line->fk_product.'">';
  510. print img_info();
  511. print '</a>';
  512. print ' ';
  513. print '<a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=edit_customer_price&token='.newToken().'&socid='.$object->id.'&lineid='.$line->id.'">';
  514. print img_edit('default', 0, 'style="vertical-align: middle;"');
  515. print '</a>';
  516. print ' ';
  517. print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=delete_customer_price&token='.newToken().'&socid='.$object->id.'&lineid='.$line->id.'">';
  518. print img_delete('default', 'style="vertical-align: middle;"');
  519. print '</a>';
  520. print '</td>';
  521. }
  522. print "</tr>\n";
  523. }
  524. } else {
  525. $colspan = 10;
  526. if ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer')) {
  527. $colspan += 1;
  528. }
  529. print '<tr class="oddeven"><td colspan="'.$colspan.'">'.$langs->trans('None').'</td></tr>';
  530. }
  531. print "</table>";
  532. print '</div>';
  533. print "</form>";
  534. }
  535. }
  536. // End of page
  537. llxFooter();
  538. $db->close();