dolibarr 20.0.0
objectline_edit.tpl.php
1<?php
2/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2010-2022 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
9 * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
10 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 *
26 * Need to have following variables defined:
27 * $object (invoice, order, ...)
28 * $conf
29 * $langs
30 * $seller, $buyer
31 * $dateSelector
32 * $forceall (0 by default, 1 for supplier invoices/orders)
33 * $senderissupplier (0 by default, 1 for supplier invoices/orders)
34 * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
35 * $canchangeproduct (0 by default, 1 to allow to change the product if it is a predefined product)
36 */
37
38// Protection to avoid direct call of template
39if (empty($object) || !is_object($object)) {
40 print "Error, template page can't be called as URL";
41 exit(1);
42}
43
44
45$usemargins = 0;
46if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
47 $usemargins = 1;
48}
49
50global $forceall, $senderissupplier, $inputalsopricewithtax, $canchangeproduct;
51if (empty($dateSelector)) {
52 $dateSelector = 0;
53}
54if (empty($forceall)) {
55 $forceall = 0;
56}
57if (empty($senderissupplier)) {
58 $senderissupplier = 0;
59}
60if (empty($inputalsopricewithtax)) {
61 $inputalsopricewithtax = 0;
62}
63if (empty($canchangeproduct)) {
64 $canchangeproduct = 0;
65}
66
67// Define colspan for the button 'Add'
68$colspan = 3; // Col total ht + col edit + col delete
69if (!empty($inputalsopricewithtax)) {
70 $colspan++; // We add 1 if col total ttc
71}
72if (in_array($object->element, array('propal', 'supplier_proposal', 'facture', 'facturerec', 'invoice', 'commande', 'order', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
73 $colspan++; // With this, there is a column move button
74}
75if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
76 $colspan += 2;
77}
78if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
79 $colspan++;
80}
81
82
83
84print "<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->\n";
85
86$coldisplay = 0;
87?>
88<tr class="oddeven tredited">
89<?php if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { ?>
90 <td class="linecolnum center"><?php $coldisplay++; ?><?php echo($i + 1); ?></td>
91<?php }
92
93$coldisplay++;
94?>
95 <td class="linecoldesc minwidth250onall">
96 <div id="line_<?php echo $line->id; ?>"></div>
97
98 <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
99 <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
100 <input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
101 <input type="hidden" id="fk_parent_line" name="fk_parent_line" value="<?php echo $line->fk_parent_line; ?>">
102
103 <?php if ($line->fk_product > 0) { ?>
104 <?php
105 if (empty($canchangeproduct)) {
106 if ($line->fk_parent_line > 0) {
107 echo img_picto('', 'rightarrow');
108 } ?>
109 <a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
110 <?php
111 if ($line->product_type == 1) {
112 echo img_object($langs->trans('ShowService'), 'service');
113 } else {
114 print img_object($langs->trans('ShowProduct'), 'product');
115 }
116 echo ' '.$line->ref; ?>
117 </a>
118 <?php
119 echo ' - '.nl2br($line->product_label);
120 print '<input type="hidden" id="product_id" name="productid" value="'.(!empty($line->fk_product) ? $line->fk_product : 0).'">';
121 } else {
122 if ($senderissupplier) {
123 $form->select_produits_fournisseurs(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
124 } else {
125 print $form->select_produits(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
126 }
127 }
128 ?>
129 <br><br>
130 <?php } ?>
131
132 <?php
133 if (is_object($hookmanager)) {
134 $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOSTINT('fk_parent_line') : $line->fk_parent_line);
135 $parameters = array('line' => $line, 'fk_parent_line' => $fk_parent_line, 'var' => $var, 'dateSelector' => $dateSelector, 'seller' => $seller, 'buyer' => $buyer);
136 $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action);
137 }
138
139 $situationinvoicelinewithparent = 0;
140 if ($line->fk_prev_id != null && in_array($object->element, array('facture', 'facturedet'))) {
141 // @phan-suppress-next-line PhanUndeclaredConstantOfClass
142 if ($object->type == $object::TYPE_SITUATION) { // The constant TYPE_SITUATION exists only for object invoice
143 // Set constant to disallow editing during a situation cycle
144 $situationinvoicelinewithparent = 1;
145 }
146 }
147
148 // Do not allow editing during a situation cycle
149 // but in some situations that is required (update legal information for example)
150 if (getDolGlobalString('INVOICE_SITUATION_CAN_FORCE_UPDATE_DESCRIPTION')) {
151 $situationinvoicelinewithparent = 0;
152 }
153
154 if (!$situationinvoicelinewithparent) {
155 // editor wysiwyg
156 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
157 $nbrows = ROWS_2;
158 if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) {
159 $nbrows = getDolGlobalString('MAIN_INPUT_DESC_HEIGHT');
160 }
161 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
162 $toolbarname = 'dolibarr_details';
163 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) {
164 $toolbarname = 'dolibarr_notes';
165 }
166 $doleditor = new DolEditor('product_desc', GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description, '', (!getDolGlobalString('MAIN_DOLEDITOR_HEIGHT') ? 164 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enable, $nbrows, '98%');
167 $doleditor->Create();
168 } else {
169 print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">';
170 print GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description;
171 print '</textarea>';
172 }
173
174 //Line extrafield
175 if (!empty($extrafields)) {
176 $temps = $line->showOptionals($extrafields, 'edit', array('class' => 'tredited'), '', '', 1, 'line');
177 if (!empty($temps)) {
178 print '<div style="padding-top: 10px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
179 print $temps;
180 print '</div>';
181 }
182 }
183
184 // Show autofill date for recurring invoices
185 if (isModEnabled("service") && $line->product_type == 1 && ($line->element == 'facturedetrec' || $line->element == 'invoice_supplier_det_rec')) {
186 if ($line->element == 'invoice_supplier_det_rec') {
187 $line->date_start_fill = $line->date_start;
188 $line->date_end_fill = $line->date_end;
189 }
190 echo '<br>';
191 echo $langs->trans('AutoFillDateFrom').' ';
192 echo $form->selectyesno('date_start_fill', GETPOSTISSET('date_start_fill') ? GETPOSTINT('date_start_fill') : $line->date_start_fill, 1);
193 echo ' - ';
194 echo $langs->trans('AutoFillDateTo').' ';
195 echo $form->selectyesno('date_end_fill', GETPOSTISSET('date_end_fill') ? GETPOSTINT('date_end_fill') : $line->date_end_fill, 1);
196 }
197
198 ?>
199 </td>
200
201 <?php
202 if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') { // We must have same test in printObjectLines
203 $coldisplay++; ?>
204 <td class="right linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth100 maxwidth125onsmartphone" value="<?php echo GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref') : ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn); ?>"></td>
205 <?php
206 print '<input type="hidden" id="fournprice" name="fournprice" class="" value="'.$line->fk_fournprice.'">';
207 }
208
209 // VAT Rate
210 $coldisplay++;
211 if ($object->element == 'propal' || $object->element == 'commande' || $object->element == 'facture' || $object->element == 'facturerec') {
212 $type_tva = 1;
213 } elseif ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') {
214 $type_tva = 2;
215 }
216 if (!$situationinvoicelinewithparent) {
217 print '<td class="right">';
218 print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : ($line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : '')), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1, $type_tva);
219 print '</td>';
220 } else {
221 print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="'.price($line->tva_tx).'" readonly />%</td>';
222 }
223
224 $coldisplay++;
225 print '<td class="right"><input type="text" class="flat right width50" id="price_ht" name="price_ht" value="'.(GETPOSTISSET('price_ht') ? GETPOST('price_ht', 'alpha') : (isset($line->pu_ht) ? price($line->pu_ht, 0, '', 0) : price($line->subprice, 0, '', 0))).'"';
226 if ($situationinvoicelinewithparent) {
227 print ' readonly';
228 }
229 print '></td>';
230
231 if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
232 $coldisplay++;
233 print '<td class="right"><input rel="'.$object->multicurrency_tx.'" type="text" class="flat right width50" id="multicurrency_subprice" name="multicurrency_subprice" value="'.(GETPOSTISSET('multicurrency_subprice') ? GETPOST('multicurrency_subprice', 'alpha') : price($line->multicurrency_subprice)).'" /></td>';
234 }
235
236 if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
237 $coldisplay++;
238 $upinctax = isset($line->pu_ttc) ? $line->pu_ttc : null;
239 if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES')) {
240 $upinctax = price2num($line->total_ttc / (float) $line->qty, 'MU');
241 }
242 print '<td class="right"><input type="text" class="flat right width50" id="price_ttc" name="price_ttc" value="'.(GETPOSTISSET('price_ttc') ? GETPOST('price_ttc') : (isset($upinctax) ? price($upinctax, 0, '', 0) : '')).'"';
243 if ($situationinvoicelinewithparent) {
244 print ' readonly';
245 }
246 print '></td>';
247 }
248 ?>
249 <td class="right">
250 <?php $coldisplay++;
251 if (($line->info_bits & 2) != 2) {
252 // I comment warning of stock because it shows the info even when it should not.
253 // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
254 // must also not be output for most entities (proposal, intervention, ...)
255 //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
256 print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="'.(GETPOSTISSET('qty') ? GETPOST('qty') : $line->qty).'"';
257 if ($situationinvoicelinewithparent) { // Do not allow editing during a situation cycle
258 print ' readonly';
259 }
260 print '>';
261 } else { ?>
262 &nbsp;
263 <?php } ?>
264 </td>
265
266 <?php
267 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
268 $unit_type = false;
269 // limit unit select to unit type
270 if (!empty($line->fk_unit) && !getDolGlobalString('MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE')) {
271 include_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
272 $cUnit = new CUnits($line->db);
273 if ($cUnit->fetch($line->fk_unit) > 0) {
274 if (!empty($cUnit->unit_type)) {
275 $unit_type = $cUnit->unit_type;
276 }
277 }
278 }
279 $coldisplay++;
280 print '<td class="left">';
281 print $form->selectUnits(GETPOSTISSET('units') ? GETPOST('units') : $line->fk_unit, "units", 0, $unit_type);
282 print '</td>';
283 }
284 ?>
285
286 <td class="nowraponall right linecoldiscount">
287 <?php
288 // Discount
289 $coldisplay++;
290 if (($line->info_bits & 2) != 2) {
291 print '<input type="text" class="flat right width40" name="remise_percent" id="remise_percent" value="'.(GETPOSTISSET('remise_percent') ? GETPOST('remise_percent') : ($line->remise_percent ? $line->remise_percent : '')).'"';
292 if ($situationinvoicelinewithparent) {
293 print ' readonly';
294 }
295 print '><span class="hideonsmartphone opacitymedium">%</span>';
296 } else { ?>
297 &nbsp;
298 <?php } ?>
299 </td>
300
301 <?php
302 // Progression for situation invoices
303 if ($object->situation_cycle_ref) {
304 $coldisplay++;
305 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 2) {
306 $tmp_fieldv = (GETPOSTISSET('progress') ? GETPOST('progress') : $line->situation_percent);
307 $old_fieldv = $line->get_allprev_progress($line->fk_facture);
308 $fieldv = $tmp_fieldv + $old_fieldv;
309
310 print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="'.$fieldv.'" name="progress">%</td>';
311 } else {
312 print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="' . (GETPOSTISSET('progress') ? GETPOST('progress') : $line->situation_percent) . '" name="progress">%</td>';
313 }
314 $coldisplay++;
315 print '<td></td>';
316 }
317
318 if (!empty($usemargins)) {
319 if ($user->hasRight('margins', 'creer')) {
320 $coldisplay++; ?>
321 <td class="margininfos right">
322 <!-- For predef product -->
323 <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
324 <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp right" style="display: none;"></select>
325 <?php } ?>
326 <!-- For free product -->
327 <input class="flat maxwidth75 right" type="text" id="buying_price" name="buying_price" class="hideobject" value="<?php echo(GETPOSTISSET('buying_price') ? GETPOST('buying_price') : price($line->pa_ht, 0, '', 0)); ?>">
328 </td>
329 <?php
330 }
331
332 if ($user->hasRight('margins', 'creer')) {
333 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
334 $margin_rate = (GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", "alpha", 2) : (($line->pa_ht == 0) ? '' : price($line->marge_tx)));
335 // if credit note, don't allow to modify margin
336 if ($line->subprice < 0) {
337 echo '<td class="right nowrap margininfos">'.$margin_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
338 } else {
339 echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_marginRate" value="'.$margin_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
340 }
341 $coldisplay++;
342 }
343 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
344 $mark_rate = (GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : price($line->marque_tx));
345 // if credit note, don't allow to modify margin
346 if ($line->subprice < 0) {
347 echo '<td class="right nowrap margininfos">'.$mark_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
348 } else {
349 echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_markRate" value="'.$mark_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
350 }
351 $coldisplay++;
352 }
353 }
354 }
355 ?>
356
357 <!-- colspan for this td because it replace total_ht+3 td for buttons+... -->
358 <td class="center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay += $colspan; ?>
359 <input type="submit" class="reposition button buttongen marginbottomonly button-save" id="savelinebutton marginbottomonly" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
360 <input type="submit" class="reposition button buttongen marginbottomonly button-cancel" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
361 </td>
362</tr>
363
364<?php if (isModEnabled("service") && $line->product_type == 1 && $dateSelector) { ?>
365<tr id="service_duration_area" class="treditedlinefordate">
366 <?php if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { ?>
367 <td class="linecolnum center"></td>
368 <?php } ?>
369 <td colspan="<?php echo $coldisplay - (!getDolGlobalString('MAIN_VIEW_LINE_NUMBER') ? 0 : 1) ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
370 <?php
371 $prefillDates = false;
372 if (getDolGlobalString('MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE') && !empty($object->lines) && $i > 0) {
373 for ($j = $i - 1; $j >= 0; $j--) {
374 $lastline = $object->lines[$j];
375 if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
376 $date_start_prefill = $lastline->date_start;
377 $date_end_prefill = $lastline->date_end;
378 $prefillDates = true;
379 break;
380 }
381 }
382 }
383 $hourmin = (isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : '');
384 print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start ? 0 : 1, "updateline", 1, 0);
385 print ' '.$langs->trans('to').' ';
386 print $form->selectDate($line->date_end, 'date_end', $hourmin, $hourmin, $line->date_end ? 0 : 1, "updateline", 1, 0);
387 if ($prefillDates) {
388 echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
389 }
390
391 print '<script>';
392 if ($prefillDates) {
393 ?>
394 function prefill_service_dates()
395 {
396 $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
397 $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
398
399 return false; // Prevent default link behaviour (which is go to href URL)
400 }
401
402 $(document).ready(function()
403 {
404 $('#prefill_service_dates').click(prefill_service_dates);
405 });
406
407 <?php
408 }
409 if (!$line->date_start) {
410 if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
411 print 'jQuery("#date_starthour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_HOUR').'");';
412 }
413
414
415 if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
416 print 'jQuery("#date_startmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_MIN').'");';
417 }
418
419 $res = 1;
420 if (!is_object($line->product)) {
421 $res = $line->fetch_product(); // fetch product to know its type and allow isMandatoryperiod()
422 }
423 if ($res > 0) {
424 if ($line->product->isMandatoryPeriod() && $line->product->isService()) {
425 print 'jQuery("#date_start").addClass("inputmandatory");'; // Do not add tag "required", this block the cancel action when value not set
426 }
427 }
428 }
429 if (!$line->date_end) {
430 if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
431 print 'jQuery("#date_endhour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_HOUR').'");';
432 }
433 if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
434 print 'jQuery("#date_endmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_MIN').'");';
435 }
436
437 $res = 1;
438 if (!is_object($line->product)) {
439 $res = $line->fetch_product(); // fetch product to know its type and allow isMandatoryperiod()
440 }
441 if ($res > 0) {
442 if ($line->product->isMandatoryperiod() && $line->product->isService()) {
443 print 'jQuery("#date_end").addClass("inputmandatory");'; // Do not add tag "required", this block the cancel action when value not set
444 }
445 }
446 }
447 print '</script>'
448 ?>
449 </td>
450</tr>
451<?php }
452?>
453
454
455<script>
456
457<?php
458if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
459 ?>
460 /* Some js test when we click on button "Add" */
461 jQuery(document).ready(function() {
462 <?php
463 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
464 ?>
465 $("input[name='np_marginRate']:first").blur(function(e) {
466 return checkFreeLine(e, "np_marginRate");
467 });
468 <?php
469 }
470 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
471 ?>
472 $("input[name='np_markRate']:first").blur(function(e) {
473 return checkFreeLine(e, "np_markRate");
474 });
475 <?php
476 } ?>
477 });
478
479 /* TODO This does not work for number with thousand separator that is , */
480 function checkFreeLine(e, npRate)
481 {
482 var buying_price = $("input[name='buying_price']:first");
483 var remise = $("input[name='remise_percent']:first");
484
485 var rate = $("input[name='"+npRate+"']:first");
486 if (rate.val() == '')
487 return true;
488
489 var ratejs = price2numjs(rate.val());
490 if (! $.isNumeric(ratejs))
491 {
492 alert('<?php echo dol_escape_js($langs->transnoentities("rateMustBeNumeric")); ?>');
493 e.stopPropagation();
494 setTimeout(function () { rate.focus() }, 50);
495 return false;
496 }
497 if (npRate == "np_markRate" && rate.val() >= 100)
498 {
499 alert('<?php echo dol_escape_js($langs->transnoentities("markRateShouldBeLesserThan100")); ?>');
500 e.stopPropagation();
501 setTimeout(function () { rate.focus() }, 50);
502 return false;
503 }
504
505 var price = 0;
506 remisejs = price2numjs(remise.val());
507
508 if (remisejs != 100) { // If a discount not 100 or no discount
509 if (remisejs == '') {
510 remisejs = 0;
511 }
512
513 bpjs=price2numjs(buying_price.val());
514 ratejs=price2numjs(rate.val());
515
516 if (npRate == "np_marginRate")
517 price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
518 else if (npRate == "np_markRate")
519 price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
520 }
521 $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formatted value
522
523 return true;
524 }
525 <?php
526}
527?>
528
529jQuery(document).ready(function()
530{
531 jQuery("#price_ht").keyup(function(event) {
532 // console.log(event.which); // discard event tag and arrows
533 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
534 jQuery("#price_ttc").val('');
535 jQuery("#multicurrency_subprice").val('');
536 }
537 });
538 jQuery("#price_ttc").keyup(function(event) {
539 // console.log(event.which); // discard event tag and arrows
540 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
541 jQuery("#price_ht").val('');
542 jQuery("#multicurrency_subprice").val('');
543 }
544 });
545 jQuery("#multicurrency_subprice").keyup(function(event) {
546 // console.log(event.which); // discard event tag and arrows
547 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
548 jQuery("#price_ht").val('');
549 jQuery("#price_ttc").val('');
550 }
551 });
552
553 <?php if (in_array($object->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
554 $("#date_start, #date_end").focusout(function() {
555 if ( $(this).val() == '' && !$(this).hasClass('inputmandatory') ) {
556 $(this).addClass('inputmandatory');
557 } else {
558 $(this).removeClass('inputmandatory');
559 }
560 });
561 <?php
562 }
563
564 if (isModEnabled('margin')) {
565 ?>
566 /* Add rule to clear margin when we change some data, so when we change sell or buy price, margin will be recalculated after submitting form */
567 jQuery("#tva_tx").click(function() { /* sometimes field is a text, sometimes a combo */
568 jQuery("input[name='np_marginRate']:first").val('');
569 jQuery("input[name='np_markRate']:first").val('');
570 });
571 jQuery("#tva_tx").keyup(function() { /* sometimes field is a text, sometimes a combo */
572 jQuery("input[name='np_marginRate']:first").val('');
573 jQuery("input[name='np_markRate']:first").val('');
574 });
575 jQuery("#price_ht").keyup(function() {
576 jQuery("input[name='np_marginRate']:first").val('');
577 jQuery("input[name='np_markRate']:first").val('');
578 });
579 jQuery("#qty").keyup(function() {
580 jQuery("input[name='np_marginRate']:first").val('');
581 jQuery("input[name='np_markRate']:first").val('');
582 });
583 jQuery("#remise_percent").keyup(function() {
584 jQuery("input[name='np_marginRate']:first").val('');
585 jQuery("input[name='np_markRate']:first").val('');
586 });
587 jQuery("#buying_price").keyup(function() {
588 jQuery("input[name='np_marginRate']:first").val('');
589 jQuery("input[name='np_markRate']:first").val('');
590 });
591
592 /* Init field buying_price and fournprice */
593 var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
594 $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product ? $line->fk_product : 0; ?>, 'token': token }, function(data) {
595 if (data && data.length > 0) {
596 var options = '';
597 var trouve=false;
598 $(data).each(function() {
599 options += '<option value="'+this.id+'" price="'+this.price+'"';
600 <?php if ($line->fk_fournprice > 0) { ?>
601 if (this.id == <?php echo $line->fk_fournprice; ?>) {
602 options += ' selected';
603 $("#buying_price").val(this.price);
604 trouve = true;
605 }
606 <?php } ?>
607 options += '>'+this.label+'</option>';
608 });
609 options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
610 $("#fournprice").html(options);
611 if (trouve) {
612 $("#buying_price").hide();
613 $("#fournprice").show();
614 } else {
615 $("#buying_price").show();
616 }
617 $("#fournprice").change(function() {
618 var selval = $(this).find('option:selected').attr("price");
619 if (selval)
620 $("#buying_price").val(selval).hide();
621 else
622 $('#buying_price').show();
623 });
624 } else {
625 $("#fournprice").hide();
626 $('#buying_price').show();
627 }
628 }, 'json');
629 <?php
630 }
631 ?>
632});
633
634</script>
635<!-- END PHP TEMPLATE objectline_edit.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class of dictionary type of thirdparty (used by imports)
Class to manage a WYSIWYG editor.
const TYPE_SERVICE
Service.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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 dolibarr global constant string value.
price2numjs(amount)
Function similar to PHP price2num()
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:139
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142