dolibarr 21.0.0-alpha
price.php
Go to the documentation of this file.
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
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
37
38if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
39 require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
40
41 $prodcustprice = new ProductCustomerPrice($db);
42}
43
44
45// Load translation files required by the page
46$langs->loadLangs(array("products", "companies", "bills"));
47
48
49// Get parameters
50$action = GETPOST('action', 'aZ09');
51$search_prod = GETPOST('search_prod', 'alpha');
52$cancel = GETPOST('cancel', 'alpha');
53$search_label = GETPOST('search_label', 'alpha');
54$search_price = GETPOST('search_price');
55$search_price_ttc = GETPOST('search_price_ttc');
56
57// Security check
58$socid = GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id');
59if ($user->socid) {
60 $socid = $user->socid;
61}
62
63// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
64$hookmanager->initHooks(array('thirdpartycustomerprice', 'globalcard'));
65
66$result = restrictedArea($user, 'societe', $socid, '&societe');
67
68// Initialize objects
69$object = new Societe($db);
70
71$error = 0;
72
73
74/*
75 * Actions
76 */
77
78$parameters = array('id' => $socid);
79$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
80if ($reshook < 0) {
81 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
82}
83
84if (empty($reshook)) {
85 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
86 $search_prod = $search_label = $search_price = $search_price_ttc = '';
87 }
88
89 if ($action == 'add_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
90 if (!(GETPOSTINT('prodid') > 0)) {
91 $error++;
92 setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Product")), null, 'errors');
93 $action = 'add_customer_price';
94 }
95
96 if (!$error) {
97 $update_child_soc = GETPOST('updatechildprice');
98
99 // add price by customer
100 $prodcustprice->fk_soc = $socid;
101 $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
102 $prodcustprice->fk_product = GETPOSTINT('prodid');
103 $prodcustprice->price = price2num(GETPOST("price"), 'MU');
104 $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
105 $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
106
107 $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
108
109 // We must define tva_tx, npr and local taxes
110 $vatratecode = '';
111 $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
112 $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
113 $localtax1 = 0;
114 $localtax2 = 0;
115 $localtax1_type = '0';
116 $localtax2_type = '0';
117 // If value contains the unique code of vat line (new recommended method), we use it to find npr and local taxes
118 if (preg_match('/\‍((.*)\‍)/', $tva_tx_txt, $reg)) {
119 // 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.
120 $vatratecode = $reg[1];
121 // Get record from code
122 $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
123 $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
124 $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
125 $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
126 $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
127 $sql .= " AND t.entity IN (".getEntity('c_tva').")";
128 $resql = $db->query($sql);
129 if ($resql) {
130 $obj = $db->fetch_object($resql);
131 $npr = $obj->recuperableonly;
132 $localtax1 = $obj->localtax1;
133 $localtax2 = $obj->localtax2;
134 $localtax1_type = $obj->localtax1_type;
135 $localtax2_type = $obj->localtax2_type;
136 }
137 }
138
139 $prodcustprice->default_vat_code = $vatratecode;
140 $prodcustprice->tva_tx = $tva_tx;
141 $prodcustprice->recuperableonly = $npr;
142 $prodcustprice->localtax1_tx = $localtax1;
143 $prodcustprice->localtax2_tx = $localtax2;
144 $prodcustprice->localtax1_type = $localtax1_type;
145 $prodcustprice->localtax2_type = $localtax2_type;
146
147 $result = $prodcustprice->create($user, 0, $update_child_soc);
148
149 if ($result < 0) {
150 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
151 } else {
152 setEventMessages($langs->trans("Save"), null, 'mesgs');
153 }
154
155 $action = '';
156 }
157 }
158
159 if ($action == 'delete_customer_price' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
160 // Delete price by customer
161 $prodcustprice->id = GETPOSTINT('lineid');
162 $result = $prodcustprice->delete($user);
163
164 if ($result < 0) {
165 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'mesgs');
166 } else {
167 setEventMessages($langs->trans('RecordDeleted'), null, 'errors');
168 }
169 $action = '';
170 }
171
172 if ($action == 'update_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
173 $prodcustprice->fetch(GETPOSTINT('lineid'));
174
175 $update_child_soc = GETPOST('updatechildprice');
176
177 // update price by customer
178 $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
179 $prodcustprice->price = price2num(GETPOST("price"), 'MU');
180 $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
181 $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
182 $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx"));
183 $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0);
184
185 $result = $prodcustprice->update($user, 0, $update_child_soc);
186 if ($result < 0) {
187 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
188 } else {
189 setEventMessages($langs->trans("Save"), null, 'mesgs');
190 }
191
192 $action = '';
193 }
194}
195
196
197/*
198 * View
199 */
200
201$form = new Form($db);
202
203$object = new Societe($db);
204
205$result = $object->fetch($socid);
206llxHeader("", $langs->trans("ThirdParty").'-'.$langs->trans('PriceByCustomer'));
207
208$head = societe_prepare_head($object);
209
210print dol_get_fiche_head($head, 'price', $langs->trans("ThirdParty"), -1, 'company');
211
212$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
213
214dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
215
216print '<div class="fichecenter">';
217
218print '<div class="underbanner clearboth"></div>';
219print '<table class="border centpercent tableforfield">';
220
221// Type Prospect/Customer/Supplier
222print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
223print $object->getTypeUrl(1);
224print '</td></tr>';
225
226if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
227 print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
228}
229
230if ($object->client) {
231 print '<tr><td class="titlefield">';
232 print $langs->trans('CustomerCode').'</td><td colspan="3">';
233 print $object->code_client;
234 $tmpcheck = $object->check_codeclient();
235 if ($tmpcheck != 0 && $tmpcheck != -5) {
236 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
237 }
238 print '</td></tr>';
239}
240
241if ($object->fournisseur) {
242 print '<tr><td class="titlefield">';
243 print $langs->trans('SupplierCode').'</td><td colspan="3">';
244 print $object->code_fournisseur;
245 $tmpcheck = $object->check_codefournisseur();
246 if ($tmpcheck != 0 && $tmpcheck != -5) {
247 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
248 }
249 print '</td></tr>';
250}
251
252print '</table>';
253
254print '</div>';
255
256print dol_get_fiche_end();
257
258
259
260if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
261 $prodcustprice = new ProductCustomerPrice($db);
262
263 $sortfield = GETPOST('sortfield', 'aZ09comma');
264 $sortorder = GETPOST('sortorder', 'aZ09comma');
265 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
266 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
267 if (empty($page) || $page == -1) {
268 $page = 0;
269 } // If $page is not defined, or '' or -1
270 $offset = $limit * $page;
271 $pageprev = $page - 1;
272 $pagenext = $page + 1;
273 if (!$sortorder) {
274 $sortorder = "ASC";
275 }
276 if (!$sortfield) {
277 $sortfield = "soc.nom";
278 }
279
280 // Build filter to display only concerned lines
281 $filter = array(
282 't.fk_soc' => $object->id
283 );
284
285 if (!empty($search_prod)) {
286 $filter ['prod.ref'] = $search_prod;
287 }
288
289 if (!empty($search_label)) {
290 $filter ['prod.label'] = $search_label;
291 }
292
293 if (!empty($search_price)) {
294 $filter ['t.price'] = $search_price;
295 }
296
297 if (!empty($search_price_ttc)) {
298 $filter ['t.price_ttc'] = $search_price_ttc;
299 }
300
301 if ($action == 'add_customer_price') {
302 // Create mode
303
304 print '<br>';
305 print '<!-- Price by customer -->'."\n";
306
307 print load_fiche_titre($langs->trans('PriceByCustomer'));
308
309 print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
310 print '<input type="hidden" name="token" value="'.newToken().'">';
311 print '<input type="hidden" name="action" value="add_customer_price_confirm">';
312 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
313 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
314 print '<input type="hidden" name="socid" value="'.$object->id.'">';
315 print '<table class="border centpercent">';
316 print '<tr>';
317 print '<td>'.$langs->trans('Product').'</td>';
318 print '<td>';
319 $form->select_produits('', 'prodid', '', 0);
320 print '</td>';
321 print '</tr>';
322
323 // Ref. Customer
324 print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
325 print '<td><input name="ref_customer" size="12"></td></tr>';
326
327 // VAT
328 print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
329 print $form->load_tva("tva_tx", GETPOST("tva_tx", "alpha"), $mysoc, '', $object->id, 0, '', false, 1);
330 print '</td></tr>';
331
332 // Price base
333 print '<tr><td width="15%">';
334 print $langs->trans('PriceBase');
335 print '</td>';
336 print '<td>';
337 print $form->selectPriceBaseType(GETPOST("price_base_type", "aZ09"), "price_base_type");
338 print '</td>';
339 print '</tr>';
340
341 // Price
342 print '<tr><td width="20%">';
343 $text = $langs->trans('SellingPrice');
344 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", getDolGlobalString('MAIN_MAX_DECIMALS_UNIT')), 1, 1);
345 print '</td><td>';
346 print '<input name="price" size="10" value="'.GETPOSTINT('price').'">';
347 print '</td></tr>';
348
349 // Price minimum
350 print '<tr><td>';
351 $text = $langs->trans('MinPrice');
352 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", getDolGlobalString('MAIN_MAX_DECIMALS_UNIT')), 1, 1);
353 print '<td><input name="price_min" size="10" value="'.GETPOSTINT('price_min').'">';
354 print '</td></tr>';
355
356 // Update all child soc
357 print '<tr><td width="15%">';
358 print $langs->trans('ForceUpdateChildPriceSoc');
359 print '</td>';
360 print '<td>';
361 print '<input type="checkbox" name="updatechildprice" value="1"/>';
362 print '</td>';
363 print '</tr>';
364
365 print '</table>';
366
367 print $form->buttonsSaveCancel();
368
369 print '</form>';
370 } elseif ($action == 'edit_customer_price') {
371 // Edit mode
372
373 print load_fiche_titre($langs->trans('PriceByCustomer'));
374
375 $result = $prodcustprice->fetch(GETPOSTINT('lineid'));
376
377 if ($result <= 0) {
378 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
379 } else {
380 print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
381 print '<input type="hidden" name="token" value="'.newToken().'">';
382 print '<input type="hidden" name="action" value="update_customer_price_confirm">';
383 print '<input type="hidden" name="lineid" value="'.$prodcustprice->id.'">';
384 print '<table class="border centpercent">';
385 print '<tr>';
386 print '<td>'.$langs->trans('Product').'</td>';
387 $staticprod = new Product($db);
388 $staticprod->fetch($prodcustprice->fk_product);
389 print "<td>".$staticprod->getNomUrl(1)."</td>";
390 print '</tr>';
391
392 // Ref. Customer
393 print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
394 print '<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).'"></td></tr>';
395
396 // VAT
397 print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
398 print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $staticprod->id, $prodcustprice->recuperableonly);
399 print '</td></tr>';
400
401 // Price base
402 print '<tr><td width="15%">';
403 print $langs->trans('PriceBase');
404 print '</td>';
405 print '<td>';
406 print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type");
407 print '</td>';
408 print '</tr>';
409
410 // Price
411 print '<tr><td>';
412 $text = $langs->trans('SellingPrice');
413 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", getDolGlobalString('MAIN_MAX_DECIMALS_UNIT')), 1, 1);
414 print '</td><td>';
415 if ($prodcustprice->price_base_type == 'TTC') {
416 print '<input name="price" size="10" value="'.price($prodcustprice->price_ttc).'">';
417 } else {
418 print '<input name="price" size="10" value="'.price($prodcustprice->price).'">';
419 }
420 print '</td></tr>';
421
422 // Price minimum
423 print '<tr><td>';
424 $text = $langs->trans('MinPrice');
425 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", getDolGlobalString('MAIN_MAX_DECIMALS_UNIT')), 1, 1);
426 print '</td><td>';
427 if ($prodcustprice->price_base_type == 'TTC') {
428 print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).'">';
429 } else {
430 print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min).'">';
431 }
432 print '</td></tr>';
433
434 // Update all child soc
435 print '<tr><td>';
436 print $langs->trans('ForceUpdateChildPriceSoc');
437 print '</td>';
438 print '<td>';
439 print '<input type="checkbox" name="updatechildprice" value="1">';
440 print '</td>';
441 print '</tr>';
442
443 print '</table>';
444
445 print $form->buttonsSaveCancel();
446
447 print '</form>';
448 }
449 } elseif ($action == 'showlog_customer_price') {
450 print '<br>';
451 print '<!-- showlog_customer_price -->'."\n";
452
453 $filter = array(
454 't.fk_product' => GETPOSTINT('prodid'),
455 't.fk_soc' => $socid
456 );
457
458 // Count total nb of records
459 $nbtotalofrecords = '';
460 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
461 if ($result < 0) {
462 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
463 } else {
464 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
465 $nbtotalofrecords = $result;
466 }
467 }
468
469 $option = '&socid='.GETPOSTINT('socid').'&prodid='.GETPOSTINT('prodid');
470
471 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
472 print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
473
474 if (count($prodcustprice->lines) > 0) {
475 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
476 print '<input type="hidden" name="token" value="'.newToken().'">';
477 print '<input type="hidden" name="id" value="'.$object->id.'">';
478
479 print '<table class="noborder centpercent">';
480
481 print '<tr class="liste_titre">';
482 print '<td>'.$langs->trans("Product").'</td>';
483 print '<td>'.$langs->trans('RefCustomer').'</td>';
484 print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
485 print '<td class="center">'.$langs->trans("PriceBase").'</td>';
486 print '<td class="right">'.$langs->trans("VAT").'</td>';
487 print '<td class="right">'.$langs->trans("HT").'</td>';
488 print '<td class="right">'.$langs->trans("TTC").'</td>';
489 print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
490 print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
491 print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
492 print '<td></td>';
493 print '</tr>';
494
495 foreach ($prodcustprice->lines as $line) {
496 $staticprod = new Product($db);
497 $staticprod->fetch($line->fk_product);
498
499 $userstatic = new User($db);
500 $userstatic->fetch($line->fk_user);
501
502 print '<tr class="oddeven">';
503
504 print "<td>".$staticprod->getNomUrl(1)."</td>";
505 print '<td>'.$line->ref_customer.'</td>';
506 print "<td>".dol_print_date($line->datec, "dayhour")."</td>";
507
508 print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
509 print '<td class="right">'.vatrate($line->tva_tx, true, $line->recuperableonly)."</td>";
510 print '<td class="right">'.price($line->price)."</td>";
511 print '<td class="right">'.price($line->price_ttc)."</td>";
512 print '<td class="right">'.price($line->price_min).'</td>';
513 print '<td class="right">'.price($line->price_min_ttc).'</td>';
514
515 // User
516 print '<td class="right">';
517 print $userstatic->getNomUrl(-1);
518 print '</td>';
519 print '<td></td>';
520 }
521 print "</table>";
522 } else {
523 print $langs->trans('None');
524 }
525
526 print "\n".'<div class="tabsAction">'."\n";
527 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'">'.$langs->trans("Ok").'</a></div>';
528 print "\n</div><br>\n";
529 } else {
530 // View mode
531
532 /*
533 * Action bar
534 */
535 print "\n".'<div class="tabsAction">'."\n";
536
537 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
538 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>';
539 }
540 print "\n</div>\n";
541
542
543 $arrayfields = array();
544 foreach ($prodcustprice->fields as $key => $val) {
545 // If $val['visible']==0, then we never show the field
546 if (!empty($val['visible'])) {
547 $visible = (int) dol_eval($val['visible'], 1, 1, '1');
548 $arrayfields['t.'.$key] = array(
549 'label' => $val['label'],
550 'checked' => (($visible < 0) ? 0 : 1),
551 'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
552 'position' => $val['position'],
553 'help' => isset($val['help']) ? $val['help'] : ''
554 );
555 }
556 }
557 $arrayfields = dol_sort_array($arrayfields, 'position');
558
559 // Count total nb of records
560 $nbtotalofrecords = '';
561 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
562 $nbtotalofrecords = $prodcustprice->fetchAll('', '', 0, 0, $filter);
563 }
564
565 $result = $prodcustprice->fetchAll($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
566 if ($result < 0) {
567 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
568 }
569
570 $option = '&search_prod='.$search_prod.'&id='.$object->id.'&label='.$search_label.'&price='.$search_price.'&price_ttc='.$search_price_ttc;
571
572 print '<!-- view specific price for each product -->'."\n";
573
574 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
575 print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, '');
576
577 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
578 print '<input type="hidden" name="token" value="'.newToken().'">';
579 print '<input type="hidden" name="id" value="'.$object->id.'">';
580 if (!empty($sortfield)) {
581 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
582 }
583 if (!empty($sortorder)) {
584 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
585 }
586 print '<div class="div-table-responsive-no-min">';
587 print '<table class="noborder centpercent liste">';
588
589 $param = 'socid='.$object->id.'&';
590 if ($search_prod) {
591 $param .= '&search_prod='.urlencode($search_prod);
592 }
593 if ($search_label) {
594 $param .= '&search_label='.urlencode($search_label);
595 }
596 if ($search_price) {
597 $param .= '&search_price='.urlencode($search_price);
598 }
599 if ($search_price) {
600 $param .= '&search_price='.urlencode($search_price);
601 }
602 if ($search_price_ttc) {
603 $param .= '&search_price_ttc='.urlencode($search_price_ttc);
604 }
605
606 print '<tr class="liste_titre">';
607 foreach ($prodcustprice->fields as $key => $val) {
608 if (!empty($arrayfields['t.'.$key]['checked'])) {
609 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], $key, '', $param, '', $sortfield, $sortorder)."\n";
610 }
611 }
612 print '<td></td>';
613 print '</tr>';
614
615 if (count($prodcustprice->lines) > 0 || $search_prod) {
616 print '<tr class="liste_titre">';
617 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="'.$search_prod.'"></td>';
618 print '<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="'.$search_label.'"></td>';
619 print '<td class="liste_titre"></td>';
620 print '<td class="liste_titre"></td>';
621 print '<td class="liste_titre"></td>';
622 print '<td class="liste_titre"></td>';
623 print '<td class="liste_titre left"><input type="text" class="flat width75" name="search_price" value="'.$search_price.'"></td>';
624 print '<td class="liste_titre left"><input type="text" class="flat width75" name="search_price_ttc" value="'.$search_price_ttc.'"></td>';
625 print '<td class="liste_titre"></td>';
626 print '<td class="liste_titre"></td>';
627 print '<td class="liste_titre"></td>';
628 // Print the search button
629 print '<td class="liste_titre maxwidthsearch">';
630 $searchpicto = $form->showFilterAndCheckAddButtons(0);
631 print $searchpicto;
632 print '</td>';
633 print '</tr>';
634 }
635
636 if (count($prodcustprice->lines) > 0) {
637 foreach ($prodcustprice->lines as $line) {
638 $staticprod = new Product($db);
639 $staticprod->fetch($line->fk_product);
640
641 $userstatic = new User($db);
642 $userstatic->fetch($line->fk_user);
643
644 print '<tr class="oddeven">';
645
646 print '<td class="left">'.$staticprod->getNomUrl(1)."</td>";
647 print '<td class="left">'.$staticprod->label."</td>";
648 print '<td class="left">'.$line->ref_customer.'</td>';
649 print '<td class="left">'.dol_print_date($line->datec, "dayhour")."</td>";
650 print '<td class="left">'.$langs->trans($line->price_base_type)."</td>";
651 print '<td class="left">'.vatrate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), true, $line->recuperableonly)."</td>";
652 print '<td class="left">'.price($line->price)."</td>";
653 print '<td class="left">'.price($line->price_ttc)."</td>";
654 print '<td class="left">'.price($line->price_min).'</td>';
655 print '<td class="left">'.price($line->price_min_ttc).'</td>';
656 // User
657 print '<td class="left">';
658 print $userstatic->getNomUrl(-1);
659 print '</td>';
660 // Action
661 if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
662 print '<td class="right nowraponall">';
663 print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=showlog_customer_price&token='.newToken().'&socid='.$object->id.'&prodid='.$line->fk_product.'">';
664 print img_info();
665 print '</a>';
666 print ' ';
667 print '<a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=edit_customer_price&token='.newToken().'&socid='.$object->id.'&lineid='.$line->id.'">';
668 print img_edit('default', 0, 'style="vertical-align: middle;"');
669 print '</a>';
670 print ' ';
671 print '<a class="paddingleftonly paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?action=delete_customer_price&token='.newToken().'&socid='.$object->id.'&lineid='.$line->id.'">';
672 print img_delete('default', 'style="vertical-align: middle;"');
673 print '</a>';
674 print '</td>';
675 }
676
677 print "</tr>\n";
678 }
679 } else {
680 $colspan = 10;
681 if ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer')) {
682 $colspan += 1;
683 }
684 print '<tr class="oddeven"><td colspan="'.$colspan.'">'.$langs->trans('None').'</td></tr>';
685 }
686
687 print "</table>";
688 print '</div>';
689
690 print "</form>";
691 }
692}
693
694// End of page
695llxFooter();
696$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
print_barre_liste($title, $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.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_info($titlealt='default')
Show info logo.
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.