price.php 25 KB

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