dolibarr 19.0.4
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 = GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int');
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 technical object to manage hooks of page. Note that conf->hooks_modules contains 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 (!(GETPOST('prodid', 'int') > 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 = GETPOST('prodid', 'int');
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 = GETPOST('lineid', 'int');
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(GETPOST('lineid', 'int'));
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
207if (isModEnabled('notification')) {
208 $langs->load("mails");
209}
210$head = societe_prepare_head($object);
211
212print dol_get_fiche_head($head, 'price', $langs->trans("ThirdParty"), -1, 'company');
213
214$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
215
216dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
217
218print '<div class="fichecenter">';
219
220print '<div class="underbanner clearboth"></div>';
221print '<table class="border centpercent tableforfield">';
222
223// Type Prospect/Customer/Supplier
224print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
225print $object->getTypeUrl(1);
226print '</td></tr>';
227
228if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
229 print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
230}
231
232if ($object->client) {
233 print '<tr><td class="titlefield">';
234 print $langs->trans('CustomerCode').'</td><td colspan="3">';
235 print $object->code_client;
236 $tmpcheck = $object->check_codeclient();
237 if ($tmpcheck != 0 && $tmpcheck != -5) {
238 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
239 }
240 print '</td></tr>';
241}
242
243if ($object->fournisseur) {
244 print '<tr><td class="titlefield">';
245 print $langs->trans('SupplierCode').'</td><td colspan="3">';
246 print $object->code_fournisseur;
247 $tmpcheck = $object->check_codefournisseur();
248 if ($tmpcheck != 0 && $tmpcheck != -5) {
249 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
250 }
251 print '</td></tr>';
252}
253
254print '</table>';
255
256print '</div>';
257
258print dol_get_fiche_end();
259
260
261
262if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
263 $prodcustprice = new ProductCustomerPrice($db);
264
265 $sortfield = GETPOST('sortfield', 'aZ09comma');
266 $sortorder = GETPOST('sortorder', 'aZ09comma');
267 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
268 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
269 if (empty($page) || $page == -1) {
270 $page = 0;
271 } // If $page is not defined, or '' or -1
272 $offset = $limit * $page;
273 $pageprev = $page - 1;
274 $pagenext = $page + 1;
275 if (!$sortorder) {
276 $sortorder = "ASC";
277 }
278 if (!$sortfield) {
279 $sortfield = "soc.nom";
280 }
281
282 // Build filter to display only concerned lines
283 $filter = array(
284 't.fk_soc' => $object->id
285 );
286
287 if (!empty($search_prod)) {
288 $filter ['prod.ref'] = $search_prod;
289 }
290
291 if (!empty($search_label)) {
292 $filter ['prod.label'] = $search_label;
293 }
294
295 if (!empty($search_price)) {
296 $filter ['t.price'] = $search_price;
297 }
298
299 if (!empty($search_price_ttc)) {
300 $filter ['t.price_ttc'] = $search_price_ttc;
301 }
302
303 if ($action == 'add_customer_price') {
304 // Create mode
305
306 print '<br>';
307 print '<!-- Price by customer -->'."\n";
308
309 print load_fiche_titre($langs->trans('PriceByCustomer'));
310
311 print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
312 print '<input type="hidden" name="token" value="'.newToken().'">';
313 print '<input type="hidden" name="action" value="add_customer_price_confirm">';
314 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
315 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
316 print '<input type="hidden" name="socid" value="'.$object->id.'">';
317 print '<table class="border centpercent">';
318 print '<tr>';
319 print '<td>'.$langs->trans('Product').'</td>';
320 print '<td>';
321 $form->select_produits('', 'prodid', '', 0);
322 print '</td>';
323 print '</tr>';
324
325 // Ref. Customer
326 print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
327 print '<td><input name="ref_customer" size="12"></td></tr>';
328
329 // VAT
330 print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
331 print $form->load_tva("tva_tx", GETPOST("tva_tx", "alpha"), $mysoc, '', $object->id, 0, '', false, 1);
332 print '</td></tr>';
333
334 // Price base
335 print '<tr><td width="15%">';
336 print $langs->trans('PriceBase');
337 print '</td>';
338 print '<td>';
339 print $form->selectPriceBaseType(GETPOST("price_base_type", "aZ09"), "price_base_type");
340 print '</td>';
341 print '</tr>';
342
343 // Price
344 print '<tr><td width="20%">';
345 $text = $langs->trans('SellingPrice');
346 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
347 print '</td><td>';
348 print '<input name="price" size="10" value="'.GETPOST('price', 'int').'">';
349 print '</td></tr>';
350
351 // Price minimum
352 print '<tr><td>';
353 $text = $langs->trans('MinPrice');
354 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
355 print '<td><input name="price_min" size="10" value="'.GETPOST('price_min', 'int').'">';
356 print '</td></tr>';
357
358 // Update all child soc
359 print '<tr><td width="15%">';
360 print $langs->trans('ForceUpdateChildPriceSoc');
361 print '</td>';
362 print '<td>';
363 print '<input type="checkbox" name="updatechildprice" value="1"/>';
364 print '</td>';
365 print '</tr>';
366
367 print '</table>';
368
369 print $form->buttonsSaveCancel();
370
371 print '</form>';
372 } elseif ($action == 'edit_customer_price') {
373 // Edit mode
374
375 print load_fiche_titre($langs->trans('PriceByCustomer'));
376
377 $result = $prodcustprice->fetch(GETPOST('lineid', 'int'));
378
379 if ($result <= 0) {
380 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
381 } else {
382 print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="POST">';
383 print '<input type="hidden" name="token" value="'.newToken().'">';
384 print '<input type="hidden" name="action" value="update_customer_price_confirm">';
385 print '<input type="hidden" name="lineid" value="'.$prodcustprice->id.'">';
386 print '<table class="border centpercent">';
387 print '<tr>';
388 print '<td>'.$langs->trans('Product').'</td>';
389 $staticprod = new Product($db);
390 $staticprod->fetch($prodcustprice->fk_product);
391 print "<td>".$staticprod->getNomUrl(1)."</td>";
392 print '</tr>';
393
394 // Ref. Customer
395 print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
396 print '<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).'"></td></tr>';
397
398 // VAT
399 print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
400 print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $staticprod->id, $prodcustprice->recuperableonly);
401 print '</td></tr>';
402
403 // Price base
404 print '<tr><td width="15%">';
405 print $langs->trans('PriceBase');
406 print '</td>';
407 print '<td>';
408 print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type");
409 print '</td>';
410 print '</tr>';
411
412 // Price
413 print '<tr><td>';
414 $text = $langs->trans('SellingPrice');
415 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
416 print '</td><td>';
417 if ($prodcustprice->price_base_type == 'TTC') {
418 print '<input name="price" size="10" value="'.price($prodcustprice->price_ttc).'">';
419 } else {
420 print '<input name="price" size="10" value="'.price($prodcustprice->price).'">';
421 }
422 print '</td></tr>';
423
424 // Price minimum
425 print '<tr><td>';
426 $text = $langs->trans('MinPrice');
427 print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
428 print '</td><td>';
429 if ($prodcustprice->price_base_type == 'TTC') {
430 print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).'">';
431 } else {
432 print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min).'">';
433 }
434 print '</td></tr>';
435
436 // Update all child soc
437 print '<tr><td>';
438 print $langs->trans('ForceUpdateChildPriceSoc');
439 print '</td>';
440 print '<td>';
441 print '<input type="checkbox" name="updatechildprice" value="1">';
442 print '</td>';
443 print '</tr>';
444
445 print '</table>';
446
447 print $form->buttonsSaveCancel();
448
449 print '</form>';
450 }
451 } elseif ($action == 'showlog_customer_price') {
452 print '<br>';
453 print '<!-- showlog_customer_price -->'."\n";
454
455 $filter = array(
456 't.fk_product' => GETPOST('prodid', 'int'),
457 't.fk_soc' => $socid
458 );
459
460 // Count total nb of records
461 $nbtotalofrecords = '';
462 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
463 if ($result < 0) {
464 setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
465 } else {
466 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
467 $nbtotalofrecords = $result;
468 }
469 }
470
471 $option = '&socid='.GETPOST('socid', 'int').'&prodid='.GETPOST('prodid', 'int');
472
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($val['visible'], 1, 1, '1');
549 $arrayfields['t.'.$key] = array(
550 'label'=>$val['label'],
551 'checked'=>(($visible < 0) ? 0 : 1),
552 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '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 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(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
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 second index function, which produces ascending (default) or descending output...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
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.
print_barre_liste($titre, $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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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.