dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.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 the 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
48 // Protection to avoid direct call of template
49if (empty($object) || !is_object($object)) {
50 print "Error, template page can't be called as URL";
51 exit(1);
52}
53
54'
55@phan-var-force Propal|Contrat|Commande|Facture|Expedition|Delivery|FactureFournisseur|FactureFournisseur|SupplierProposal $object
56@phan-var-force PropaleLigne|ContratLigne|CommonObjectLine|CommonInvoiceLine|CommonOrderLine|ExpeditionLigne|DeliveryLine|FactureFournisseurLigneRec|SupplierInvoiceLine|SupplierProposalLine $line
57@phan-var-force ThirdParty $seller
58@phan-var-force ThirdParty $buyer
59@phan-var-force string $var
60';
61
62$usemargins = 0;
63if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
64 $usemargins = 1;
65}
66
67global $forceall, $senderissupplier, $inputalsopricewithtax, $canchangeproduct;
68if (empty($dateSelector)) {
69 $dateSelector = 0;
70}
71if (empty($forceall)) {
72 $forceall = 0;
73}
74if (empty($senderissupplier)) {
75 $senderissupplier = 0;
76}
77if (empty($inputalsopricewithtax)) {
78 $inputalsopricewithtax = 0;
79}
80if (empty($canchangeproduct)) {
81 $canchangeproduct = 0;
82}
83
84// Define colspan for the button 'Add'
85$colspan = 3; // Col total ht + col edit + col delete
86if (!empty($inputalsopricewithtax)) {
87 $colspan++; // We add 1 if col total ttc
88}
89if (in_array($object->element, array('propal', 'supplier_proposal', 'facture', 'facturerec', 'invoice', 'commande', 'order', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
90 $colspan++; // With this, there is a column move button
91}
92if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
93 $colspan += 2;
94}
95if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
96 $colspan++;
97}
98
99
100
101print "<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->\n";
102
103$coldisplay = 0;
104?>
105<tr class="oddeven tredited">
106<?php if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { ?>
107 <td class="linecolnum center"><?php $coldisplay++; ?><?php echo($i + 1); ?></td>
108<?php }
109
110$coldisplay++;
111?>
112 <td class="linecoldesc minwidth250onall">
113 <div id="line_<?php echo $line->id; ?>"></div>
114
115 <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
116 <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
117 <input type="hidden" id="special_code" name="special_code" value="<?php echo $line->special_code; ?>">
118 <input type="hidden" id="fk_parent_line" name="fk_parent_line" value="<?php echo $line->fk_parent_line; ?>">
119
120 <?php if ($line->fk_product > 0) { ?>
121 <?php
122 if (empty($canchangeproduct)) {
123 if ($line->fk_parent_line > 0) {
124 echo img_picto('', 'rightarrow');
125 } ?>
126 <a href="<?php echo DOL_URL_ROOT.'/product/card.php?id='.$line->fk_product; ?>">
127 <?php
128 if ($line->product_type == 1) {
129 echo img_object($langs->trans('ShowService'), 'service');
130 } else {
131 print img_object($langs->trans('ShowProduct'), 'product');
132 }
133 echo ' '.$line->ref; ?>
134 </a>
135 <?php
136 echo ' - '.nl2br($line->product_label);
137 print '<input type="hidden" id="product_id" name="productid" value="'.(!empty($line->fk_product) ? $line->fk_product : 0).'">';
138 } else {
139 if ($senderissupplier) {
140 $form->select_produits_fournisseurs(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
141 } else {
142 print $form->select_produits(!empty($line->fk_product) ? $line->fk_product : 0, 'productid');
143 }
144 }
145 ?>
146 <br><br>
147 <?php } ?>
148
149 <?php
150 if (is_object($hookmanager)) {
151 $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOSTINT('fk_parent_line') : $line->fk_parent_line);
152 $parameters = array('line' => $line, 'fk_parent_line' => $fk_parent_line, 'var' => $var, 'dateSelector' => $dateSelector, 'seller' => $seller, 'buyer' => $buyer);
153 $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action);
154 }
155
156 $situationinvoicelinewithparent = 0;
157 if ($line->fk_prev_id != null && in_array($object->element, array('facture', 'facturedet'))) {
159 // @phan-suppress-next-line PhanUndeclaredConstantOfClass
160 if ($object->type == $object::TYPE_SITUATION) { // The constant TYPE_SITUATION exists only for object invoice
161 // Set constant to disallow editing during a situation cycle
162 $situationinvoicelinewithparent = 1;
163 }
164 }
165
166 // Do not allow editing during a situation cycle
167 // but in some situations that is required (update legal information for example)
168 if (getDolGlobalString('INVOICE_SITUATION_CAN_FORCE_UPDATE_DESCRIPTION')) {
169 $situationinvoicelinewithparent = 0;
170 }
171
172 if (!$situationinvoicelinewithparent) {
173 // editor wysiwyg
174 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
175 $nbrows = ROWS_2;
176 if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) {
177 $nbrows = getDolGlobalString('MAIN_INPUT_DESC_HEIGHT');
178 }
179 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
180 $toolbarname = 'dolibarr_details';
181 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) {
182 $toolbarname = 'dolibarr_notes';
183 }
184 $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%');
185 $doleditor->Create();
186 } else {
187 print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">';
188 print GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description;
189 print '</textarea>';
190 }
191
192 //Line extrafield
193 if (!empty($extrafields)) {
194 $temps = $line->showOptionals($extrafields, 'edit', array('class' => 'tredited'), '', '', 1, 'line');
195 if (!empty($temps)) {
196 print '<div style="padding-top: 10px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
197 print $temps;
198 print '</div>';
199 }
200 }
201
202 // Show autofill date for recurring invoices
203 if (isModEnabled("service") && $line->product_type == 1 && ($line->element == 'facturedetrec' || $line->element == 'invoice_supplier_det_rec')) {
204 if ($line->element == 'invoice_supplier_det_rec') {
205 $line->date_start_fill = $line->date_start;
206 $line->date_end_fill = $line->date_end;
207 }
208 echo '<br>';
209 echo $langs->trans('AutoFillDateFrom').' ';
210 echo $form->selectyesno('date_start_fill', GETPOSTISSET('date_start_fill') ? GETPOSTINT('date_start_fill') : $line->date_start_fill, 1);
211 echo ' - ';
212 echo $langs->trans('AutoFillDateTo').' ';
213 echo $form->selectyesno('date_end_fill', GETPOSTISSET('date_end_fill') ? GETPOSTINT('date_end_fill') : $line->date_end_fill, 1);
214 }
215
216 ?>
217 </td>
218
219 <?php
220 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
221 $coldisplay++; ?>
222 <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>
223 <?php
224 print '<input type="hidden" id="fournprice" name="fournprice" class="" value="'.$line->fk_fournprice.'">';
225 }
226
227 // VAT Rate
228 $coldisplay++;
229 $type_tva = null;
230 if ($object->element == 'propal' || $object->element == 'commande' || $object->element == 'facture' || $object->element == 'facturerec') {
231 $type_tva = 1;
232 } elseif ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') {
233 $type_tva = 2;
234 }
235 if (!$situationinvoicelinewithparent) {
236 print '<td class="right">';
237 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);
238 print '</td>';
239 } else {
240 print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="'.price($line->tva_tx).'" readonly />%</td>';
241 }
242
243 $coldisplay++;
244 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))).'"';
245 if ($situationinvoicelinewithparent) {
246 print ' readonly';
247 }
248 print '></td>';
249
250 if (isModEnabled("multicurrency") && $object->multicurrency_code != $conf->currency) {
251 $coldisplay++;
252 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>';
253 }
254
255 if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
256 $coldisplay++;
257 $upinctax = isset($line->pu_ttc) ? $line->pu_ttc : null;
258 if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES')) {
259 $upinctax = price2num($line->total_ttc / (float) $line->qty, 'MU');
260 }
261 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) : '')).'"';
262 if ($situationinvoicelinewithparent) {
263 print ' readonly';
264 }
265 print '></td>';
266 }
267 ?>
268 <td class="right">
269 <?php $coldisplay++;
270 if (($line->info_bits & 2) != 2) {
271 // I comment warning of stock because it shows the info even when it should not.
272 // 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
273 // must also not be output for most entities (proposal, intervention, ...)
274 //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
275 print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="'.(GETPOSTISSET('qty') ? GETPOST('qty') : $line->qty).'"';
276 if ($situationinvoicelinewithparent) { // Do not allow editing during a situation cycle
277 print ' readonly';
278 }
279 print '>';
280 } else { ?>
281 &nbsp;
282 <?php } ?>
283 </td>
284
285 <?php
286 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
287 $unit_type = false;
288 // limit unit select to unit type
289 if (!empty($line->fk_unit) && !getDolGlobalString('MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE')) {
290 include_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
291 $cUnit = new CUnits($line->db);
292 if ($cUnit->fetch($line->fk_unit) > 0) {
293 if (!empty($cUnit->unit_type)) {
294 $unit_type = $cUnit->unit_type;
295 }
296 }
297 }
298 $coldisplay++;
299 print '<td class="left">';
300 print $form->selectUnits(GETPOSTISSET('units') ? GETPOST('units') : $line->fk_unit, "units", 0, $unit_type);
301 print '</td>';
302 }
303 ?>
304
305 <td class="nowraponall right linecoldiscount">
306 <?php
307 // Discount
308 $coldisplay++;
309 if (($line->info_bits & 2) != 2) {
310 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 : '')).'"';
311 if ($situationinvoicelinewithparent) {
312 print ' readonly';
313 }
314 print '><span class="hideonsmartphone opacitymedium">%</span>';
315 } else { ?>
316 &nbsp;
317 <?php } ?>
318 </td>
319
320 <?php
321 // Progression for situation invoices
322 if ($object->situation_cycle_ref) {
323 $coldisplay++;
324 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 2) {
325 $tmp_fieldv = (GETPOSTISSET('progress') ? GETPOST('progress') : $line->situation_percent);
326 $old_fieldv = $line->getAllPrevProgress($line->fk_facture);
327 $fieldv = $tmp_fieldv + $old_fieldv;
328
329 print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="'.$fieldv.'" name="progress">%</td>';
330 } else {
331 print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="' . (GETPOSTISSET('progress') ? GETPOST('progress') : $line->situation_percent) . '" name="progress">%</td>';
332 }
333 $coldisplay++;
334 print '<td></td>';
335 }
336
337 if (!empty($usemargins)) {
338 if ($user->hasRight('margins', 'creer')) {
339 $coldisplay++; ?>
340 <td class="margininfos right">
341 <!-- For predef product -->
342 <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
343 <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp right" style="display: none;"></select>
344 <?php } ?>
345 <!-- For free product -->
346 <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)); ?>">
347 </td>
348 <?php
349 }
350
351 if ($user->hasRight('margins', 'creer')) {
352 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
353 $margin_rate = (GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", "alpha", 2) : (($line->pa_ht == 0) ? '' : price($line->marge_tx)));
354 // if credit note, don't allow to modify margin
355 if ($line->subprice < 0) {
356 echo '<td class="right nowrap margininfos">'.$margin_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
357 } else {
358 echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_marginRate" value="'.$margin_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
359 }
360 $coldisplay++;
361 }
362 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
363 $mark_rate = (GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : price($line->marque_tx));
364 // if credit note, don't allow to modify margin
365 if ($line->subprice < 0) {
366 echo '<td class="right nowrap margininfos">'.$mark_rate.'<span class="opacitymedium hideonsmartphone">%</span></td>';
367 } else {
368 echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_markRate" value="'.$mark_rate.'"><span class="opacitymedium hideonsmartphone">%</span></td>';
369 }
370 $coldisplay++;
371 }
372 }
373 }
374 ?>
375
376 <!-- colspan for this td because it replace total_ht+3 td for buttons+... -->
377 <td class="center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay += $colspan; ?>
378 <input type="submit" class="reposition button buttongen marginbottomonly button-save" id="savelinebutton marginbottomonly" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
379 <input type="submit" class="reposition button buttongen marginbottomonly button-cancel" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
380 </td>
381</tr>
382
383<?php if (isModEnabled("service") && $line->product_type == 1 && $dateSelector) { ?>
384<tr id="service_duration_area" class="treditedlinefordate">
385 <?php if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { ?>
386 <td class="linecolnum center"></td>
387 <?php } ?>
388 <td colspan="<?php echo $coldisplay - (!getDolGlobalString('MAIN_VIEW_LINE_NUMBER') ? 0 : 1) ?>"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
389 <?php
390 $prefillDates = false;
391 $date_start_prefill = 0;
392 $date_end_prefill = 0;
393 if (getDolGlobalString('MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE') && !empty($object->lines) && $i > 0) {
394 for ($j = $i - 1; $j >= 0; $j--) {
395 $lastline = $object->lines[$j];
396 if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
397 $date_start_prefill = $lastline->date_start;
398 $date_end_prefill = $lastline->date_end;
399 $prefillDates = true;
400 break;
401 }
402 }
403 }
404 $hourmin = (isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : '');
405 print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start ? 0 : 1, "updateline", 1, 0);
406 print ' '.$langs->trans('to').' ';
407 print $form->selectDate($line->date_end, 'date_end', $hourmin, $hourmin, $line->date_end ? 0 : 1, "updateline", 1, 0);
408 if ($prefillDates) {
409 echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
410 }
411
412 print '<script>';
413 if ($prefillDates) {
414 ?>
415 function prefill_service_dates()
416 {
417 $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
418 $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
419
420 return false; // Prevent default link behaviour (which is go to href URL)
421 }
422
423 $(document).ready(function()
424 {
425 $('#prefill_service_dates').click(prefill_service_dates);
426 });
427
428 <?php
429 }
430 if (!$line->date_start) {
431 if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
432 print 'jQuery("#date_starthour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_HOUR').'");';
433 }
434
435
436 if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
437 print 'jQuery("#date_startmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_MIN').'");';
438 }
439
440 $res = 1;
441 if (!is_object($line->product)) {
442 $res = $line->fetch_product(); // fetch product to know its type and allow isMandatoryperiod()
443 }
444 if ($res > 0) {
445 if ($line->product->isMandatoryPeriod() && $line->product->isService()) {
446 print 'jQuery("#date_start").addClass("inputmandatory");'; // Do not add tag "required", this block the cancel action when value not set
447 }
448 }
449 }
450 if (!$line->date_end) {
451 if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
452 print 'jQuery("#date_endhour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_HOUR').'");';
453 }
454 if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
455 print 'jQuery("#date_endmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_MIN').'");';
456 }
457
458 $res = 1;
459 if (!is_object($line->product)) {
460 $res = $line->fetch_product(); // fetch product to know its type and allow isMandatoryperiod()
461 }
462 if ($res > 0) {
463 if ($line->product->isMandatoryperiod() && $line->product->isService()) {
464 print 'jQuery("#date_end").addClass("inputmandatory");'; // Do not add tag "required", this block the cancel action when value not set
465 }
466 }
467 }
468 print '</script>'
469 ?>
470 </td>
471</tr>
472<?php }
473?>
474
475
476<script>
477
478<?php
479if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
480 ?>
481 /* Some js test when we click on button "Add" */
482 jQuery(document).ready(function() {
483 <?php
484 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
485 ?>
486 $("input[name='np_marginRate']:first").blur(function(e) {
487 return checkFreeLine(e, "np_marginRate");
488 });
489 <?php
490 }
491 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
492 ?>
493 $("input[name='np_markRate']:first").blur(function(e) {
494 return checkFreeLine(e, "np_markRate");
495 });
496 <?php
497 } ?>
498 });
499
500 /* TODO This does not work for number with thousand separator that is , */
501 function checkFreeLine(e, npRate)
502 {
503 var buying_price = $("input[name='buying_price']:first");
504 var remise = $("input[name='remise_percent']:first");
505
506 var rate = $("input[name='"+npRate+"']:first");
507 if (rate.val() == '')
508 return true;
509
510 var ratejs = price2numjs(rate.val());
511 if (! $.isNumeric(ratejs))
512 {
513 alert('<?php echo dol_escape_js($langs->transnoentities("rateMustBeNumeric")); ?>');
514 e.stopPropagation();
515 setTimeout(function () { rate.focus() }, 50);
516 return false;
517 }
518 if (npRate == "np_markRate" && rate.val() >= 100)
519 {
520 alert('<?php echo dol_escape_js($langs->transnoentities("markRateShouldBeLesserThan100")); ?>');
521 e.stopPropagation();
522 setTimeout(function () { rate.focus() }, 50);
523 return false;
524 }
525
526 var price = 0;
527 remisejs = price2numjs(remise.val());
528
529 if (remisejs != 100) { // If a discount not 100 or no discount
530 if (remisejs == '') {
531 remisejs = 0;
532 }
533
534 bpjs=price2numjs(buying_price.val());
535 ratejs=price2numjs(rate.val());
536
537 if (npRate == "np_marginRate")
538 price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
539 else if (npRate == "np_markRate")
540 price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
541 }
542 $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formatted value
543
544 return true;
545 }
546 <?php
547}
548?>
549
550jQuery(document).ready(function()
551{
552 jQuery("#price_ht").keyup(function(event) {
553 // console.log(event.which); // discard event tag and arrows
554 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
555 jQuery("#price_ttc").val('');
556 jQuery("#multicurrency_subprice").val('');
557 }
558 });
559 jQuery("#price_ttc").keyup(function(event) {
560 // console.log(event.which); // discard event tag and arrows
561 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
562 jQuery("#price_ht").val('');
563 jQuery("#multicurrency_subprice").val('');
564 }
565 });
566 jQuery("#multicurrency_subprice").keyup(function(event) {
567 // console.log(event.which); // discard event tag and arrows
568 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
569 jQuery("#price_ht").val('');
570 jQuery("#price_ttc").val('');
571 }
572 });
573
574 <?php if (in_array($object->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
575 $("#date_start, #date_end").focusout(function() {
576 if ( $(this).val() == '' && !$(this).hasClass('inputmandatory') ) {
577 $(this).addClass('inputmandatory');
578 } else {
579 $(this).removeClass('inputmandatory');
580 }
581 });
582 <?php
583 }
584
585 if (isModEnabled('margin')) {
586 ?>
587 /* 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 */
588 jQuery("#tva_tx").click(function() { /* sometimes field is a text, sometimes a combo */
589 jQuery("input[name='np_marginRate']:first").val('');
590 jQuery("input[name='np_markRate']:first").val('');
591 });
592 jQuery("#tva_tx").keyup(function() { /* sometimes field is a text, sometimes a combo */
593 jQuery("input[name='np_marginRate']:first").val('');
594 jQuery("input[name='np_markRate']:first").val('');
595 });
596 jQuery("#price_ht").keyup(function() {
597 jQuery("input[name='np_marginRate']:first").val('');
598 jQuery("input[name='np_markRate']:first").val('');
599 });
600 jQuery("#qty").keyup(function() {
601 jQuery("input[name='np_marginRate']:first").val('');
602 jQuery("input[name='np_markRate']:first").val('');
603 });
604 jQuery("#remise_percent").keyup(function() {
605 jQuery("input[name='np_marginRate']:first").val('');
606 jQuery("input[name='np_markRate']:first").val('');
607 });
608 jQuery("#buying_price").keyup(function() {
609 jQuery("input[name='np_marginRate']:first").val('');
610 jQuery("input[name='np_markRate']:first").val('');
611 });
612
613 /* Init field buying_price and fournprice */
614 var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
615 $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product ? $line->fk_product : 0; ?>, 'token': token }, function(data) {
616 if (data && data.length > 0) {
617 var options = '';
618 var trouve=false;
619 $(data).each(function() {
620 options += '<option value="'+this.id+'" price="'+this.price+'"';
621 <?php if ($line->fk_fournprice > 0) { ?>
622 if (this.id == <?php echo $line->fk_fournprice; ?>) {
623 options += ' selected';
624 $("#buying_price").val(this.price);
625 trouve = true;
626 }
627 <?php } ?>
628 options += '>'+this.label+'</option>';
629 });
630 options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
631 $("#fournprice").html(options);
632 if (trouve) {
633 $("#buying_price").hide();
634 $("#fournprice").show();
635 } else {
636 $("#buying_price").show();
637 }
638 $("#fournprice").change(function() {
639 var selval = $(this).find('option:selected').attr("price");
640 if (selval)
641 $("#buying_price").val(selval).hide();
642 else
643 $('#buying_price').show();
644 });
645 } else {
646 $("#fournprice").hide();
647 $('#buying_price').show();
648 }
649 }, 'json');
650 <?php
651 }
652 ?>
653});
654
655</script>
656<!-- END PHP TEMPLATE objectline_edit.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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 a Dolibarr global constant string value.
price2numjs(amount)
Function similar to PHP price2num()
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152