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