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