dolibarr 19.0.3
objectline_create.tpl.php
1<?php
2/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
10 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
12 * Copyright (C) 2022 OpenDSI <support@open-dsi.fr>
13 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 *
28 * Need to have following variables defined:
29 * $object (invoice, order, ...)
30 * $conf
31 * $langs
32 * $dateSelector
33 * $forceall (0 by default, 1 for supplier invoices/orders)
34 * $senderissupplier (0 by default, 1 or 2 for supplier invoices/orders)
35 * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
36 */
37
38// Protection to avoid direct call of template
39if (empty($object) || !is_object($object)) {
40 print "Error: this template page cannot be called directly as an URL";
41 exit;
42}
43
44$usemargins = 0;
45if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'facturerec', 'propal', 'commande'))) {
46 $usemargins = 1;
47}
48if (!isset($dateSelector)) {
49 global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
50}
51global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
52global $mysoc;
53
54if (!isset($dateSelector)) {
55 $dateSelector = 1; // For backward compatibility
56} elseif (empty($dateSelector)) {
57 $dateSelector = 0;
58}
59if (empty($forceall)) {
60 $forceall = 0;
61}
62if (empty($senderissupplier)) {
63 $senderissupplier = 0;
64}
65if (empty($inputalsopricewithtax)) {
66 $inputalsopricewithtax = 0;
67}
68// Define colspan for the button 'Add'
69$colspan = 3; // Columns: total ht + col edit + col delete
70if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
71 $colspan++; //Add column for Total (currency) if required
72}
73if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier', 'invoice_supplier_rec'))) {
74 $colspan++; // With this, there is a column move button
75}
76if (isModEnabled('asset') && $object->element == 'invoice_supplier') {
77 $colspan++;
78}
79
80//print $object->element;
81// Lines for extrafield
82$objectline = null;
83if (!empty($extrafields)) {
84 if ($this->table_element_line == 'commandedet') {
85 $objectline = new OrderLine($this->db);
86 } elseif ($this->table_element_line == 'propaldet') {
87 $objectline = new PropaleLigne($this->db);
88 } elseif ($this->table_element_line == 'supplier_proposaldet') {
89 $objectline = new SupplierProposalLine($this->db);
90 } elseif ($this->table_element_line == 'facturedet') {
91 $objectline = new FactureLigne($this->db);
92 } elseif ($this->table_element_line == 'contratdet') {
93 $objectline = new ContratLigne($this->db);
94 } elseif ($this->table_element_line == 'commande_fournisseurdet') {
95 $objectline = new CommandeFournisseurLigne($this->db);
96 } elseif ($this->table_element_line == 'facture_fourn_det') {
97 $objectline = new SupplierInvoiceLine($this->db);
98 } elseif ($this->table_element_line == 'facturedet_rec') {
99 $objectline = new FactureLigneRec($this->db);
100 } elseif ($this->table_element_line == 'facture_fourn_det_rec') {
101 $objectline = new FactureFournisseurLigneRec($this->db);
102 }
103}
104print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
105$nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
106if ($nolinesbefore) {
107 ?>
108 <tr class="liste_titre<?php echo(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_add_') ?> nodrag nodrop">
109 <?php if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { ?>
110 <td class="linecolnum center"></td>
111 <?php } ?>
112 <td class="linecoldescription minwidth400imp">
113 <div id="add"></div><span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine'); ?></span>
114 </td>
115 <?php
116 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
117 ?>
118 <td class="linecolrefsupplier"><span id="title_fourn_ref"><?php echo $langs->trans('SupplierRef'); ?></span></td>
119 <?php
120 } ?>
121 <td class="linecolvat right"><span id="title_vat"><?php echo $langs->trans('VAT'); ?></span></td>
122 <td class="linecoluht right"><span id="title_up_ht"><?php echo $langs->trans('PriceUHT'); ?></span></td>
123 <?php if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) { ?>
124 <td class="linecoluht_currency right"><span id="title_up_ht_currency"><?php echo $langs->trans('PriceUHTCurrency'); ?></span></td>
125 <?php } ?>
126 <?php if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) { ?>
127 <td class="linecoluttc right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
128 <?php } ?>
129 <td class="linecolqty right"><?php echo $langs->trans('Qty'); ?></td>
130 <?php
131 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
132 print '<td class="linecoluseunit left">';
133 print '<span id="title_units">';
134 print $langs->trans('Unit');
135 print '</span></td>';
136 } ?>
137 <td class="linecoldiscount right"><?php echo $langs->trans('ReductionShort'); ?></td>
138 <?php
139 // Fields for situation invoice
140 if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
141 print '<td class="linecolcycleref right">'.$langs->trans('Progress').'</td>';
142 print '<td class="linecolcycleref2 right"></td>';
143 }
144 if (!empty($usemargins)) {
145 if (!$user->hasRight('margins', 'creer')) {
146 $colspan++;
147 } else {
148 print '<td class="margininfos linecolmargin1 right">';
149 if (getDolGlobalString('MARGIN_TYPE') == "1") {
150 echo $langs->trans('BuyingPrice');
151 } else {
152 echo $langs->trans('CostPrice');
153 }
154 echo '</td>';
155 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
156 echo '<td class="margininfos linecolmargin2 right"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
157 }
158 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
159 echo '<td class="margininfos linecolmargin2 right"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
160 }
161 }
162 } ?>
163 <td class="linecoledit" colspan="<?php echo $colspan; ?>">&nbsp;</td>
164 </tr>
165 <?php
166}
167?>
168<tr class="pair nodrag nodrop nohoverpair<?php echo ($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create'; ?>">
169 <?php
170 $coldisplay = 0;
171 // Adds a line numbering column
172 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
173 $coldisplay++;
174 echo '<td class="nobottom linecolnum center"></td>';
175 }
176 $coldisplay++;
177 ?>
178 <td class="nobottom linecoldescription minwidth400imp">
179 <?php
180 $freelines = false;
181 if (!getDolGlobalString('MAIN_DISABLE_FREE_LINES')) {
182 $freelines = true;
183 $forceall = 1; // We always force all type for free lines (module product or service means we use predefined product or service)
184 if ($object->element == 'contrat') {
185 if (!isModEnabled('product') && !isModEnabled('service') && !getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS')) {
186 $forceall = -1; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
187 } elseif (!getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS')) {
188 $forceall = 3;
189 }
190 }
191 // Free line
192 echo '<span class="prod_entry_mode_free">';
193 // Show radio free line
194 if ($forceall >= 0 && (isModEnabled("product") || isModEnabled("service"))) {
195 echo '<label for="prod_entry_mode_free">';
196 echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"';
197 //echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (!isModEnabled('product') || !isModEnabled('service')))?' checked':'') );
198 echo((GETPOST('prod_entry_mode', 'alpha') == 'free' || getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT')) ? ' checked' : '');
199 echo '> ';
200 // Show type selector
201 echo '<span class="textradioforitem">'.$langs->trans("FreeLineOfType").'</span>';
202 echo '</label>';
203 echo ' ';
204 } else {
205 echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
206 // Show type selector
207 if ($forceall >= 0) {
208 if (!isModEnabled('product') || !isModEnabled('service')) {
209 echo $langs->trans("Type");
210 } else {
211 echo $langs->trans("FreeLineOfType");
212 }
213 echo ' ';
214 }
215 }
216 $form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', 1, 1, $forceall);
217 echo '</span>';
218 }
219 // Predefined product/service
220 if (isModEnabled("product") || isModEnabled("service")) {
221 if ($forceall >= 0 && $freelines) {
222 echo '<br><span class="prod_entry_mode_predef paddingtop">';
223 } else {
224 echo '<span class="prod_entry_mode_predef">';
225 }
226 echo '<label for="prod_entry_mode_predef">';
227 echo '<input type="radio" class="prod_entry_mode_predef" name="prod_entry_mode" id="prod_entry_mode_predef" value="predef"'.(GETPOST('prod_entry_mode') == 'predef' ? ' checked' : '').'> ';
228 $labelforradio = '';
229 if (empty($conf->dol_optimize_smallscreen)) {
230 if (empty($senderissupplier)) {
231 if (isModEnabled("product") && !isModEnabled('service')) {
232 $labelforradio = $langs->trans('PredefinedProductsToSell');
233 } elseif ((!isModEnabled('product') && isModEnabled('service')) || ($object->element == 'contrat' && !getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS'))) {
234 $labelforradio = $langs->trans('PredefinedServicesToSell');
235 } else {
236 $labelforradio = $langs->trans('PredefinedProductsAndServicesToSell');
237 }
238 } else {
239 if (isModEnabled("product") && !isModEnabled('service')) {
240 $labelforradio = $langs->trans('PredefinedProductsToPurchase');
241 } elseif (!isModEnabled('product') && isModEnabled('service')) {
242 $labelforradio = $langs->trans('PredefinedServicesToPurchase');
243 } else {
244 $labelforradio = $langs->trans('PredefinedProductsAndServicesToPurchase');
245 }
246 }
247 } else {
248 $labelforradio = $langs->trans('PredefinedItem');
249 }
250 print '<span class="textradioforitem">'.$labelforradio.'</span>';
251 echo '</label>';
252 echo ' ';
253 $filtertype = '';
254 if (!empty($object->element) && $object->element == 'contrat' && !getDolGlobalString('CONTRACT_SUPPORT_PRODUCTS')) {
255 $filtertype = '1';
256 }
257 if (empty($senderissupplier)) {
258 $statustoshow = 1;
259 $statuswarehouse = 'warehouseopen,warehouseinternal';
260 if (getDolGlobalString('ENTREPOT_WAREHOUSEINTERNAL_NOT_SELL')) {
261 $statuswarehouse = 'warehouseopen';
262 }
263 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
264 // hide products in closed warehouse, but show products for internal transfer
265 $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, $statuswarehouse, GETPOST('combinations', 'array'));
266 } else {
267 $form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOST('combinations', 'array'));
268 }
269 if (getDolGlobalString('MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS')) {
270 ?>
271 <script>
272 $(document).ready(function(){
273 // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
274 $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
275 console.log('focus on a select2');
276 if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
277 {
278 console.log('open combo');
279 $('#idprod').select2('open');
280 }
281 });
282 });
283 </script>
284 <?php
285 }
286 } else {
287 // $senderissupplier=2 is the same as 1 but disables test on minimum qty, disable autofill qty with minimum and autofill unit price
288 if ($senderissupplier != 2) {
289 $ajaxoptions = array(
290 'update' => array('qty'=>'qty', 'remise_percent' => 'discount', 'idprod' => 'idprod'), // html id tags that will be edited with each ajax json response key
291 'option_disabled' => 'idthatdoesnotexists', // html id to disable once select is done
292 'warning' => $langs->trans("NoPriceDefinedForThisSupplier") // translation of an error saved into var 'warning' (for example shown we select a disabled option into combo)
293 );
294 $alsoproductwithnosupplierprice = 0;
295 } else {
296 $ajaxoptions = array(
297 // Disabled: This is useless because setting discount and price_ht after a selection is already managed
298 // by ths page itself with a .change on the combolist '#idprodfournprice'
299 //'update' => array('remise_percent' => 'discount', 'price_ht' => 'price_ht') // html id tags that will be edited with each ajax json response key
300 );
301 $alsoproductwithnosupplierprice = 1;
302 }
303 $form->select_produits_fournisseurs($object->socid, GETPOST('idprodfournprice'), 'idprodfournprice', '', '', $ajaxoptions, 1, $alsoproductwithnosupplierprice, 'minwidth300imp maxwidth500');
304 if (getDolGlobalString('MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS')) {
305 ?>
306 <script>
307 $(document).ready(function(){
308 // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
309 $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
310 //console.log('focus on a select2');
311 if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
312 {
313 $('#idprodfournprice').select2('open');
314 }
315 });
316 });
317 </script>
318 <?php
319 }
320 }
321
322 $parentId = GETPOST('parentId', 'int');
323
324 $addproducton = (isModEnabled('product') && $user->hasRight('produit', 'creer'));
325 $addserviceon = (isModEnabled('service') && $user->hasRight('service', 'creer'));
326 if ($addproducton || $addserviceon) {
327 if ($addproducton && $addserviceon) {
328 echo '<div id="dropdownAddProductAndService" class="dropdown inline-block">';
329 echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" id="dropdownAddProductAndServiceLink" aria-haspopup="true" aria-expanded="false">';
330 echo '<span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
331 echo '</a>';
332 echo '<div class="dropdown-menu" aria-labelledby="dropdownAddProductAndServiceLink" style="top:auto; left:auto;">';
333 echo '<a class="dropdown-item" href="'.DOL_URL_ROOT.'/product/card.php?action=create&type=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'"> '.$langs->trans("NewProduct").'</a>';
334 echo '<a class="dropdown-item" href="'.DOL_URL_ROOT.'/product/card.php?action=create&type=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'"> '.$langs->trans("NewService").'</a>';
335 echo '</div>';
336 echo '</div>';
337 } else {
338 if ($addproducton) {
339 $url = '/product/card.php?leftmenu=product&action=create&type=0&backtopage='.urlencode($_SERVER["PHP_SELF"]);
340 $newbutton = '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("NewProduct").'"></span>';
341 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
342 // @FIXME Not working yet
343 $tmpbacktopagejsfields = 'addproduct:id,search_id';
344 print dolButtonToOpenUrlInDialogPopup('addproduct', $langs->transnoentitiesnoconv('AddProduct'), $newbutton, $url, '', '', $tmpbacktopagejsfields);
345 } else {
346 print '<a href="'.DOL_URL_ROOT.'/product/card.php?action=create&type=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'" title="'.dol_escape_htmltag($langs->trans("NewProduct")).'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
347 }
348 }
349 if ($addserviceon) {
350 $url = '/product/card.php?leftmenu=product&action=create&type=1&backtopage='.urlencode($_SERVER["PHP_SELF"]);
351 $newbutton = '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("NewService").'"></span>';
352 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
353 // @FIXME Not working yet
354 $tmpbacktopagejsfields = 'addproduct:id,search_id';
355 print dolButtonToOpenUrlInDialogPopup('addproduct', $langs->transnoentitiesnoconv('AddService'), $newbutton, $url, '', '', $tmpbacktopagejsfields);
356 } else {
357 print '<a href="'.DOL_URL_ROOT.'/product/card.php?action=create&type=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'" title="'.dol_escape_htmltag($langs->trans("NewService")).'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
358 }
359 }
360 }
361 } ?>
362 <script>
363 $(document).ready(function(){
364 $("#dropdownAddProductAndService .dropdown-toggle").on("click", function(event) {
365 console.log("toggle addproduct dropdown");
366 event.preventDefault();
367 $("#dropdownAddProductAndService").toggleClass("open");
368 });
369 });
370 </script>
371 <?php
372
373 echo '<input type="hidden" name="pbq" id="pbq" value="">';
374 echo '</span>';
375 }
376
377 if (getDolGlobalString('MAIN_ADD_LINE_AT_POSITION')) {
378 echo '<br>'.$langs->trans('AddLineOnPosition').' : <input type="number" name="rank" step="1" min="0" style="width: 5em;">';
379 }
380
381 if (is_object($hookmanager) && empty($senderissupplier)) {
382 $parameters = array('fk_parent_line'=>GETPOST('fk_parent_line', 'int'));
383 $reshook = $hookmanager->executeHooks('formCreateProductOptions', $parameters, $object, $action);
384 if (!empty($hookmanager->resPrint)) {
385 print $hookmanager->resPrint;
386 }
387 }
388 if (is_object($hookmanager) && !empty($senderissupplier)) {
389 $parameters = array('htmlname'=>'addproduct');
390 $reshook = $hookmanager->executeHooks('formCreateProductSupplierOptions', $parameters, $object, $action);
391 if (!empty($hookmanager->resPrint)) {
392 print $hookmanager->resPrint;
393 }
394 }
395 if (isModEnabled("product") || isModEnabled("service")) {
396 echo '<br>';
397 if (isModEnabled('variants')) {
398 echo '<div id="attributes_box"></div>';
399 }
400 }
401 // Editor wysiwyg
402 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
403 $nbrows = ROWS_2;
404 $enabled = (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS') ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
405 if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) {
406 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
407 }
408 $toolbarname = 'dolibarr_details';
409 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) {
410 $toolbarname = 'dolibarr_notes';
411 }
412 $doleditor = new DolEditor('dp_desc', GETPOST('dp_desc', 'restricthtml'), '', (!getDolGlobalString('MAIN_DOLEDITOR_HEIGHT') ? 100 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%');
413 $doleditor->Create();
414 // Show autofill date for recurring invoices
415 if (isModEnabled("service") && ($object->element == 'facturerec' || $object->element == 'invoice_supplier_rec')) {
416 echo '<div class="divlinefordates"><br>';
417 echo $langs->trans('AutoFillDateFrom').' ';
418 if (getDolGlobalString('INVOICE_REC_DATE_TO_YES')) {
419 $line->date_start_fill = 1;
420 $line->date_end_fill = 1;
421 }
422 echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1);
423 echo ' - ';
424 echo $langs->trans('AutoFillDateTo').' ';
425 echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1);
426 echo '</div>';
427 }
428 if (is_object($objectline)) {
429 $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
430
431 if (!empty($temps)) {
432 print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
433 print $temps;
434 print '</div>';
435 }
436 }
437 echo '</td>';
438 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
439 $coldisplay++; ?>
440 <td class="nobottom linecolrefsupplier"><input id="fourn_ref" name="fourn_ref" class="flat minwidth50 maxwidth100 maxwidth125onsmartphone" value="<?php echo(GETPOSTISSET("fourn_ref") ? GETPOST("fourn_ref", 'alpha', 2) : ''); ?>"></td>
441 <?php
442 }
443 print '<td class="nobottom linecolvat right">';
444 $coldisplay++;
445 if ($seller->tva_assuj == "0") {
446 echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">'.vatrate(0, true);
447 } else {
448 echo $form->load_tva('tva_tx', (GETPOSTISSET("tva_tx") ? GETPOST("tva_tx", 'alpha', 2) : -1), $seller, $buyer, 0, 0, '', false, 1);
449 }
450 ?>
451 </td>
452
453 <td class="nobottom linecoluht right"><?php $coldisplay++; ?>
454 <input type="text" size="5" name="price_ht" id="price_ht" class="flat right" value="<?php echo(GETPOSTISSET("price_ht") ? GETPOST("price_ht", 'alpha', 2) : ''); ?>">
455 </td>
456
457 <?php
458 if (isModEnabled("multicurrency") && $this->multicurrency_code != $conf->currency) {
459 $coldisplay++; ?>
460 <td class="nobottom linecoluht_currency right">
461 <input type="text" size="5" name="multicurrency_price_ht" id="multicurrency_price_ht" class="flat right" value="<?php echo(GETPOSTISSET("multicurrency_price_ht") ? GETPOST("multicurrency_price_ht", 'alpha', 2) : ''); ?>">
462 </td>
463 <?php
464 }
465 if (!empty($inputalsopricewithtax) && !getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX')) {
466 $coldisplay++; ?>
467 <td class="nobottom linecoluttc right">
468 <input type="text" size="5" name="price_ttc" id="price_ttc" class="flat right" value="<?php echo(GETPOSTISSET("price_ttc") ? GETPOST("price_ttc", 'alpha', 2) : ''); ?>">
469 </td>
470 <?php
471 }
472 $coldisplay++;
473 ?>
474 <td class="nobottom linecolqty right">
475 <?php $default_qty = (!getDolGlobalString('MAIN_OBJECTLINE_CREATE_EMPTY_QTY_BY_DEFAULT') ? 1 : ''); ?>
476 <input type="text" name="qty" id="qty" class="flat width40 right" value="<?php echo(GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : $default_qty); ?>">
477 </td>
478 <?php
479 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
480 $coldisplay++;
481 print '<td class="nobottom linecoluseunit left">';
482 print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, "units");
483 print '</td>';
484 }
485 $remise_percent = $buyer->remise_percent;
486 if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
487 $remise_percent = $seller->remise_supplier_percent;
488 }
489 $coldisplay++;
490 ?>
491
492 <td class="nobottom nowrap linecoldiscount right"><input type="text" name="remise_percent" id="remise_percent" class="flat width40 right" value="<?php echo(GETPOSTISSET("remise_percent") ? GETPOST("remise_percent", 'alpha', 2) : ($remise_percent ? $remise_percent : '')); ?>"><span class="opacitymedium hideonsmartphone">%</span></td>
493 <?php
494 if (isset($this->situation_cycle_ref) && $this->situation_cycle_ref) {
495 $coldisplay++;
496 print '<td class="nobottom nowrap right"><input class="falt right" type="text" size="1" value="" name="progress"><span class="opacitymedium hideonsmartphone">%</span></td>';
497 $coldisplay++;
498 print '<td></td>';
499 }
500 if (!empty($usemargins)) {
501 if ($user->hasRight('margins', 'creer')) {
502 $coldisplay++; ?>
503 <td class="nobottom margininfos linecolmargin right">
504 <!-- For predef product -->
505 <?php if (isModEnabled("product") || isModEnabled("service")) { ?>
506 <select id="fournprice_predef" name="fournprice_predef" class="flat minwidth75imp maxwidth150" style="display: none;"></select>
507 <?php } ?>
508 <!-- For free product -->
509 <input type="text" id="buying_price" name="buying_price" class="flat maxwidth75 right" value="<?php echo(GETPOSTISSET("buying_price") ? GETPOST("buying_price", 'alpha', 2) : ''); ?>">
510 </td>
511 <?php
512 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
513 echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_marginRate" name="np_marginRate" value="'.(GETPOSTISSET("np_marginRate") ? GETPOST("np_marginRate", 'alpha', 2) : '').'"><span class="np_marginRate opacitymedium hideonsmartphone">%</span></td>';
514 $coldisplay++;
515 }
516 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
517 echo '<td class="nobottom nowraponall margininfos right"><input class="flat right width40" type="text" id="np_markRate" name="np_markRate" value="'.(GETPOSTISSET("np_markRate") ? GETPOST("np_markRate", 'alpha', 2) : '').'"><span class="np_markRate opacitymedium hideonsmartphone">%</span></td>';
518 $coldisplay++;
519 }
520 }
521 }
522 $coldisplay += $colspan;
523 ?>
524 <td class="nobottom linecoledit center valignmiddle" colspan="<?php echo $colspan; ?>">
525 <input type="submit" class="button reposition" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
526 </td>
527</tr>
528
529<?php
530if ((isModEnabled("service") || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') { // We show date field if required
531 print '<tr id="trlinefordates" class="oddeven">'."\n";
532 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
533 print '<td></td>';
534 }
535 print '<td colspan="'.($coldisplay - (!getDolGlobalString('MAIN_VIEW_LINE_NUMBER') ? 0 : 1)).'">';
536 $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
537 $date_end = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
538
539 $prefillDates = false;
540
541 if (getDolGlobalString('MAIN_FILL_SERVICE_DATES_FROM_LAST_SERVICE_LINE') && !empty($object->lines)) {
542 for ($i = count($object->lines) - 1; $i >= 0; $i--) {
543 $lastline = $object->lines[$i];
544
545 if ($lastline->product_type == Product::TYPE_SERVICE && (!empty($lastline->date_start) || !empty($lastline->date_end))) {
546 $date_start_prefill = $lastline->date_start;
547 $date_end_prefill = $lastline->date_end;
548
549 $prefillDates = true;
550 break;
551 }
552 }
553 }
554
555 if (!empty($object->element) && $object->element == 'contrat') {
556 print $langs->trans("DateStartPlanned").' ';
557 print $form->selectDate($date_start, "date_start", $usehm, $usehm, 1, "addproduct");
558 print ' &nbsp; '.$langs->trans("DateEndPlanned").' ';
559 print $form->selectDate($date_end, "date_end", $usehm, $usehm, 1, "addproduct");
560 } else {
561 print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
562 print $form->selectDate($date_start, 'date_start', !getDolGlobalString('MAIN_USE_HOURMIN_IN_DATE_RANGE') ? 0 : 1, !getDolGlobalString('MAIN_USE_HOURMIN_IN_DATE_RANGE') ? 0 : 1, 1, "addproduct", 1, 0);
563 print ' '.$langs->trans('to').' ';
564 print $form->selectDate($date_end, 'date_end', !getDolGlobalString('MAIN_USE_HOURMIN_IN_DATE_RANGE') ? 0 : 1, !getDolGlobalString('MAIN_USE_HOURMIN_IN_DATE_RANGE') ? 0 : 1, 1, "addproduct", 1, 0);
565 }
566
567 if ($prefillDates) {
568 echo ' <span class="small"><a href="#" id="prefill_service_dates">'.$langs->trans('FillWithLastServiceDates').'</a></span>';
569 }
570
571 print '<script>';
572
573 if ($prefillDates) {
574 ?>
575 function prefill_service_dates()
576 {
577 $('#date_start').val("<?php echo dol_escape_js(dol_print_date($date_start_prefill, 'day')); ?>").trigger('change');
578 $('#date_end').val("<?php echo dol_escape_js(dol_print_date($date_end_prefill, 'day')); ?>").trigger('change');
579
580 return false; // Prevent default link behaviour (which is go to href URL)
581 }
582
583 $(document).ready(function()
584 {
585 $('#prefill_service_dates').click(prefill_service_dates);
586 });
587
588 <?php
589 }
590
591 if (!$date_start) {
592 if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) {
593 print 'jQuery("#date_starthour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_HOUR').'");';
594 }
595 if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) {
596 print 'jQuery("#date_startmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_START_MIN').'");';
597 }
598 }
599 if (!$date_end) {
600 if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) {
601 print 'jQuery("#date_endhour").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_HOUR').'");';
602 }
603 if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) {
604 print 'jQuery("#date_endmin").val("' . getDolGlobalString('MAIN_DEFAULT_DATE_END_MIN').'");';
605 }
606 }
607 print '</script>';
608 print '</td>';
609 print '</tr>'."\n";
610}
611
612
613print "<script>\n";
614if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
615 ?>
616 /* Some js test when we click on button "Add" */
617 jQuery(document).ready(function() {
618 <?php
619 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { ?>
620 $("input[name='np_marginRate']:first").blur(function(e) {
621 return checkFreeLine(e, "np_marginRate");
622 });
623 <?php
624 }
625 if (getDolGlobalString('DISPLAY_MARK_RATES')) { ?>
626 $("input[name='np_markRate']:first").blur(function(e) {
627 return checkFreeLine(e, "np_markRate");
628 });
629 <?php
630 } ?>
631 });
632
633 /* TODO This does not work for number with thousand separator that is , */
634 function checkFreeLine(e, npRate)
635 {
636 var buying_price = $("input[name='buying_price']:first");
637 var remise = $("input[name='remise_percent']:first");
638
639 var rate = $("input[name='"+npRate+"']:first");
640 if (rate.val() == '')
641 return true;
642
643 if (! $.isNumeric(rate.val().replace(',','.')))
644 {
645 alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
646 e.stopPropagation();
647 setTimeout(function () { rate.focus() }, 50);
648 return false;
649 }
650 if (npRate == "np_markRate" && rate.val() >= 100)
651 {
652 alert('<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>');
653 e.stopPropagation();
654 setTimeout(function () { rate.focus() }, 50);
655 return false;
656 }
657
658 var price = 0;
659 remisejs=price2numjs(remise.val());
660
661 if (remisejs != 100) // If a discount not 100 or no discount
662 {
663 if (remisejs == '') remisejs=0;
664
665 bpjs=price2numjs(buying_price.val());
666 ratejs=price2numjs(rate.val());
667
668 if (npRate == "np_marginRate")
669 price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
670 else if (npRate == "np_markRate")
671 price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
672 }
673
674 $("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
675
676 return true;
677 }
678
679 <?php
680}
681?>
682
683 /* JQuery for product free or predefined select */
684 jQuery(document).ready(function() {
685 jQuery("#price_ht").keyup(function(event) {
686 // console.log(event.which); // discard event tag and arrows
687 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#price_ht").val() != '') {
688 jQuery("#price_ttc").val('');
689 jQuery("#multicurrency_subprice").val('');
690 jQuery("#multicurrency_price_ht").val('');
691 }
692 });
693 jQuery("#price_ttc").keyup(function(event) {
694 // console.log(event.which); // discard event tag and arrows
695 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
696 jQuery("#price_ht").val('');
697 jQuery("#multicurrency_subprice").val('');
698 jQuery("#multicurrency_price_ht").val('');
699 }
700 });
701 jQuery("#multicurrency_subprice").keyup(function(event) {
702 // console.log(event.which); // discard event tag and arrows
703 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#multicurrency_subprice").val() != '') {
704 jQuery("#price_ht").val('');
705 jQuery("#price_ttc").val('');
706 }
707 });
708 jQuery("#multicurrency_price_ht").keyup(function(event) {
709 // console.log(event.which); // discard event tag and arrows
710 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#multicurrency_price_ht").val() != '') {
711 jQuery("#price_ht").val('');
712 jQuery("#price_ttc").val('');
713 }
714 });
715
716 $("#prod_entry_mode_free").on( "click", function() {
717 setforfree();
718 });
719 $("#select_type").change(function()
720 {
721 setforfree();
722
723 if (jQuery('#select_type').val() >= 0) {
724 console.log("Set focus on description field");
725 /* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
726 jQuery('#dp_desc').focus();
727 /* this focus code works for CKEDITOR */
728 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
729 var editor = CKEDITOR.instances['dp_desc'];
730 if (editor) {
731 editor.focus();
732 }
733 }
734 }
735
736 console.log("Hide/show date according to product type");
737 if (jQuery('#select_type').val() == '0')
738 {
739 jQuery('#trlinefordates').hide();
740 jQuery('.divlinefordates').hide();
741 }
742 else
743 {
744 jQuery('#trlinefordates').show();
745 jQuery('.divlinefordates').show();
746 }
747 });
748
749 $("#prod_entry_mode_predef").on( "click", function() {
750 console.log("click prod_entry_mode_predef");
751 setforpredef();
752 jQuery('#trlinefordates').show();
753 });
754
755 <?php
756 if (!$freelines) { ?>
757 $("#prod_entry_mode_predef").click();
758 <?php
759 }
760
761 if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
762 $("#date_start, #date_end").focusout(function() {
763 let type = $(this).attr('type');
764 let mandatoryP = $(this).attr('mandatoryperiod');
765 if (type == 1 && mandatoryP == 1) {
766 if ($(this).val() == '' && !$(this).hasClass('inputmandatory')) {
767 $(this).addClass('inputmandatory');
768 }else{
769 $(this).removeClass('inputmandatory');
770 }
771 }
772 });
773 <?php
774 } ?>
775 /* When changing predefined product, we reload list of supplier prices required for margin combo */
776 $("#idprod, #idprodfournprice").change(function()
777 {
778 console.log("objectline_create.tpl Call method change() after change on #idprod or #idprodfournprice (senderissupplier=<?php echo $senderissupplier; ?>). this.val = "+$(this).val());
779
780 setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva(product)
781
782 jQuery('#trlinefordates').show();
783
784 <?php
785 if (!getDolGlobalString('MAIN_DISABLE_EDIT_PREDEF_PRICEHT') && empty($senderissupplier)) {
786 ?>
787 var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
788 if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
789
790 if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
791 {
792 console.log("objectline_create.tpl We are in a price per qty context, we do not call ajax/product, init of fields is done few lines later");
793 } else {
794 <?php if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { ?>
795 if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we could not get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
796 <?php } ?>
797 // Get the price for the product and display it
798 console.log("Load unit price and set it into #price_ht or #price_ttc for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
799 $.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
800 { 'id': $(this).val(), 'socid': <?php print $object->socid; ?>, 'token': '<?php print currentToken(); ?>', 'addalsovatforthirdpartyid': 1 },
801 function(data) {
802 console.log("objectline_create.tpl Load unit price ends, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
803
804 $('#date_start').removeAttr('type');
805 $('#date_end').removeAttr('type');
806 $('#date_start').attr('type', data.type);
807 $('#date_end').attr('type', data.type);
808
809 $('#date_start').removeAttr('mandatoryperiod');
810 $('#date_end').removeAttr('mandatoryperiod');
811 $('#date_start').attr('mandatoryperiod', data.mandatory_period);
812 $('#date_end').attr('mandatoryperiod', data.mandatory_period);
813
814 // service and we setted mandatory_period to true
815 if (data.mandatory_period == 1 && data.type == 1) {
816 jQuery('#date_start').addClass('inputmandatory');
817 jQuery('#date_end').addClass('inputmandatory');
818 } else {
819 jQuery('#date_start').removeClass('inputmandatory');
820 jQuery('#date_end').removeClass('inputmandatory');
821 }
822
823 if (<?php echo (int) $inputalsopricewithtax; ?> == 1 && data.pricebasetype == 'TTC' && <?php print getDolGlobalInt('MAIN_NO_INPUT_PRICE_WITH_TAX') ? 'false' : 'true'; ?>) {
824 console.log("objectline_create.tpl set content of price_ttc");
825 jQuery("#price_ttc").val(data.price_ttc);
826 } else {
827 console.log("objectline_create.tpl set content of price_ht");
828 jQuery("#price_ht").val(data.price_ht);
829 }
830
831 var tva_tx = data.tva_tx;
832 var default_vat_code = data.default_vat_code;
833
834 // Now set the VAT
835 var stringforvatrateselection = tva_tx;
836 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
837 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
838 <?php
839 // Special case for India
840 if (getDolGlobalString('MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
841 ?>
842 console.log("MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA is on so we check if we need to autoswith the vat code");
843 console.log("mysoc->country_code=<?php echo $mysoc->country_code; ?> thirdparty->country_code=<?php echo $object->thirdparty->country_code; ?>");
844 new_default_vat_code = default_vat_code;
845 <?php
846 if ($mysoc->country_code == 'IN' && !empty($object->thirdparty) && $object->thirdparty->country_code == 'IN' && $mysoc->state_code == $object->thirdparty->state_code) {
847 // We are in India and states are same, we revert the vat code "I-x" into "CS-x"
848 ?>
849 console.log("Countries are both IN and states are same, so we revert I into CS in default_vat_code="+default_vat_code);
850 new_default_vat_code = default_vat_code.replace(/^I\-/, 'C+S-');
851 <?php
852 } elseif ($mysoc->country_code == 'IN' && !empty($object->thirdparty) && $object->thirdparty->country_code == 'IN' && $mysoc->state_code != $object->thirdparty->state_code) {
853 // We are in India and states differs, we revert the vat code "CS-x" into "I-x"
854 ?>
855 console.log("Countries are both IN and states differs, so we revert CS into I in default_vat_code="+default_vat_code);
856 new_default_vat_code = default_vat_code.replace(/^C\+S\-/, 'I-');
857 <?php
858 } ?>
859 if (new_default_vat_code != default_vat_code && jQuery('#tva_tx option:contains("'+new_default_vat_code+'")').val()) {
860 console.log("We found en entry into VAT with new default_vat_code, we will use it");
861 stringforvatrateselection = jQuery('#tva_tx option:contains("'+new_default_vat_code+'")').val();
862 }
863 <?php
864 } ?>
865 }
866 // Set vat rate if field is an input box
867 $('#tva_tx').val(tva_tx);
868 // Set vat rate by selecting the combo
869 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
870 $('#tva_tx option').removeAttr('selected');
871 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
872 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
873
874 <?php
875 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
876 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { ?>
877 var proddesc = data.desc_trans;
878 <?php
879 } else { ?>
880 var proddesc = data.desc;
881 <?php
882 } ?>
883 console.log("objectline_create.tpl Load desciption into text area : "+proddesc);
884 <?php
885 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS')) { ?>
886 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
887 {
888 var editor = CKEDITOR.instances['dp_desc'];
889 if (editor) {
890 editor.setData(proddesc);
891 }
892 }
893 <?php
894 } else { ?>
895 jQuery('#dp_desc').text(proddesc);
896 <?php
897 } ?>
898 <?php
899 } ?>
900 <?php
901 if (getDolGlobalString('PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES')) { ?>
902 jQuery.each(data.array_options, function( key, value ) {
903 jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value);
904 });
905 <?php
906 } ?>
907 },
908 'json'
909 );
910 }
911 <?php
912 }
913
914 if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
915 $langs->load('stocks'); ?>
916
917 /* Code for margin */
918 $("#fournprice_predef").find("option").remove();
919 $("#fournprice_predef").hide();
920 $("#buying_price").val("").show();
921
922 /* Call post to load content of combo list fournprice_predef */
923 var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
924 $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1', { 'idprod': $(this).val(), 'token': token }, function(data) {
925 if (data && data.length > 0)
926 {
927 var options = ''; var defaultkey = ''; var defaultprice = ''; var bestpricefound = 0;
928
929 var bestpriceid = 0; var bestpricevalue = 0;
930 var pmppriceid = 0; var pmppricevalue = 0;
931 var costpriceid = 0; var costpricevalue = 0;
932
933 /* setup of margin calculation */
934 var defaultbuyprice = '<?php
935 if (isset($conf->global->MARGIN_TYPE)) {
936 if (getDolGlobalString('MARGIN_TYPE') == '1') {
937 print 'bestsupplierprice';
938 }
939 if (getDolGlobalString('MARGIN_TYPE') == 'pmp') {
940 print 'pmp';
941 }
942 if (getDolGlobalString('MARGIN_TYPE') == 'costprice') {
943 print 'costprice';
944 }
945 } ?>';
946 console.log("objectline_create.tpl we will set the field for margin. defaultbuyprice="+defaultbuyprice);
947
948 var i = 0;
949 $(data).each(function() {
950 /* Warning: Lines must be processed in order: best supplier price, then pmpprice line then costprice */
951 if (this.id != 'pmpprice' && this.id != 'costprice')
952 {
953 i++;
954 this.price = parseFloat(this.price); // to fix when this.price >0
955 // If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
956 //console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
957 if (bestpricefound == 0 && this.price > 0) { defaultkey = this.id; defaultprice = this.price; bestpriceid = this.id; bestpricevalue = this.price; bestpricefound=1; } // bestpricefound is used to take the first price > 0
958 }
959 if (this.id == 'pmpprice')
960 {
961 // If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
962 console.log("id="+this.id+"-price="+this.price);
963 if ('pmp' == defaultbuyprice || 'costprice' == defaultbuyprice)
964 {
965 if (this.price > 0) {
966 defaultkey = this.id; defaultprice = this.price; pmppriceid = this.id; pmppricevalue = this.price;
967 //console.log("pmppricevalue="+pmppricevalue);
968 }
969 }
970 }
971 if (this.id == 'costprice')
972 {
973 // If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
974 console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
975 if ('costprice' == defaultbuyprice)
976 {
977 if (this.price > 0) { defaultkey = this.id; defaultprice = this.price; costpriceid = this.id; costpricevalue = this.price; }
978 else if (pmppricevalue > 0) { defaultkey = 'pmpprice'; defaultprice = pmppricevalue; }
979 }
980 }
981 options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
982 });
983 options += '<option value="inputprice" price="'+defaultprice+'"><?php echo dol_escape_js($langs->trans("InputPrice").'...'); ?></option>';
984
985 console.log("finally selected defaultkey="+defaultkey+" defaultprice for buying price="+defaultprice);
986
987 $("#fournprice_predef").html(options).show();
988 if (defaultkey != '')
989 {
990 $("#fournprice_predef").val(defaultkey);
991 }
992
993 /* At loading, no product are yet selected, so we hide field of buying_price */
994 $("#buying_price").hide();
995
996 /* Define default price at loading */
997 var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
998 $("#buying_price").val(defaultprice);
999
1000 $("#fournprice_predef").change(function() {
1001 console.log("change on fournprice_predef");
1002 /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
1003 var linevalue=$(this).find('option:selected').val();
1004 var pricevalue = $(this).find('option:selected').attr("price");
1005 if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
1006 $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
1007 }
1008 if (linevalue == 'inputprice') {
1009 $('#buying_price').show();
1010 }
1011 if (linevalue == 'pmpprice') {
1012 $("#buying_price").val(pricevalue);
1013 $('#buying_price').hide();
1014 }
1015 });
1016 }
1017 },
1018 'json');
1019
1020 <?php
1021 }
1022 ?>
1023
1024 <?php
1025 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
1026 ?>
1027 /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
1028 var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
1029 if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
1030 var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
1031 if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
1032 var pbqbase = $('option:selected', this).attr('data-pbqbase');
1033 if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
1034 var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
1035 if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
1036 var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
1037 if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
1038
1039 if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
1040 {
1041 var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
1042
1043 console.log("We choose a price by quanty price_by_qty id = "+pbq+" price_by_qty upht = "+pbqupht+" price_by_qty qty = "+pbqqty+" price_by_qty percent = "+pbqpercent);
1044 jQuery("#pbq").val(pbq);
1045 jQuery("#price_ht").val(pbqupht);
1046 if (jQuery("#qty").val() < pbqqty)
1047 {
1048 jQuery("#qty").val(pbqqty);
1049 }
1050 if (jQuery("#remise_percent").val() < pbqpercent)
1051 {
1052 jQuery("#remise_percent").val(pbqpercent);
1053 }
1054 } else { jQuery("#pbq").val(''); }
1055 <?php
1056 }
1057 ?>
1058
1059
1060 // Deal with supplier ref price (idprodfournprice = int)
1061 if (jQuery('#idprodfournprice').val() > 0)
1062 {
1063 console.log("objectline_create.tpl #idprodfournprice is an ID > 0, so we set some properties into page");
1064
1065 var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
1066 if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
1067
1068 var up_locale = $('option:selected', this).attr('data-up-locale'); // When select is done from HTML select
1069 if (typeof up_locale === 'undefined') { up_locale = jQuery('#idprodfournprice').attr('data-up-locale');} // When select is done from HTML input with ajax autocomplete
1070
1071 var qty = parseFloat($('option:selected', this).attr('data-qty'));
1072 if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
1073
1074 var discount = parseFloat($('option:selected', this).attr('data-discount'));
1075 if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
1076
1077 var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
1078 if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
1079
1080 var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
1081 if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
1082
1083 var stringforvatrateselection = tva_tx;
1084 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1085 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1086 }
1087
1088 var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
1089 if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref');} // When select is done from HTML input with ajax autocomplete
1090
1091 var has_multicurrency_up = false;
1092 <?php
1093 if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
1094 ?>
1095 var object_multicurrency_code = '<?php print dol_escape_js($object->multicurrency_code); ?>';
1096
1097 var multicurrency_code = $('option:selected', this).attr('data-multicurrency-code'); // When select is done from HTML select
1098 if (multicurrency_code == undefined) { multicurrency_code = jQuery('#idprodfournprice').attr('data-multicurrency-code'); } // When select is done from HTML input with ajax autocomplete
1099
1100 var multicurrency_up = parseFloat($('option:selected', this).attr('data-multicurrency-unitprice')); // When select is done from HTML select
1101 if (isNaN(multicurrency_up)) { multicurrency_up = parseFloat(jQuery('#idprodfournprice').attr('data-multicurrency-unitprice')); } // When select is done from HTML input with ajax autocomplete
1102
1103 if (multicurrency_code == object_multicurrency_code) {
1104 has_multicurrency_up = true;
1105 jQuery("#multicurrency_price_ht").val(multicurrency_up);
1106 }
1107
1108 console.log("objectline_create.tpl Multicurrency values : object_multicurrency_code = "+object_multicurrency_code+", multicurrency_code = "+multicurrency_code+", multicurrency_up = "+multicurrency_up);
1109 <?php
1110 }
1111 ?>
1112
1113 console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", has_multicurrency_up = "+has_multicurrency_up+", supplier_ref = "+supplier_ref+" qty = "+qty+", tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+", discount = "+discount+" for product supplier ref id = "+jQuery('#idprodfournprice').val());
1114
1115 if (has_multicurrency_up === false) {
1116 if (typeof up_locale === 'undefined') {
1117 jQuery("#price_ht").val(up);
1118 } else {
1119 jQuery("#price_ht").val(up_locale);
1120 }
1121 }
1122
1123 // Set supplier_ref
1124 $('#fourn_ref').val(supplier_ref);
1125 // Set vat rate if field is an input box
1126 $('#tva_tx').val(tva_tx);
1127 // Set vat rate by selecting the combo
1128 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1129 $('#tva_tx option').removeAttr('selected');
1130 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1131 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1132
1133 if (jQuery("#qty").val() < qty) {
1134 jQuery("#qty").val(qty);
1135 }
1136 if (jQuery("#remise_percent").val() < discount) {
1137 jQuery("#remise_percent").val(discount);
1138 }
1139
1140 <?php
1141 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
1142 ?>
1143 var description = $('option:selected', this).attr('data-description');
1144 if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
1145
1146 console.log("Load desciption into text area : "+description);
1147 <?php
1148 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS')) {
1149 ?>
1150 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1151 {
1152 var editor = CKEDITOR.instances['dp_desc'];
1153 if (editor) {
1154 editor.setData(description);
1155 }
1156 }
1157 <?php
1158 } else {
1159 ?>
1160 jQuery('#dp_desc').text(description);
1161 <?php
1162 }
1163 }
1164 ?>
1165 } else if (jQuery('#idprodfournprice').length > 0) {
1166 console.log("objectline_create.tpl #idprodfournprice is not an int but is a string so we set only few properties into page");
1167
1168 var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
1169 if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
1170
1171 var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
1172 if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
1173
1174 var stringforvatrateselection = tva_tx;
1175 if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
1176 stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
1177 }
1178
1179 console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
1180
1181 // Set vat rate if field is an input box
1182 $('#tva_tx').val(tva_tx);
1183 // Set vat rate by selecting the combo
1184 //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
1185 $('#tva_tx option').removeAttr('selected');
1186 console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
1187 $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
1188 <?php
1189 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
1190 if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS')) {
1191 ?>
1192 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1193 {
1194 var editor = CKEDITOR.instances['dp_desc'];
1195 if (editor) {
1196 editor.setData('');
1197 }
1198 }
1199 <?php
1200 } else {
1201 ?>
1202 jQuery('#dp_desc').text('');
1203 <?php
1204 }
1205 }
1206 ?>
1207 }
1208
1209
1210 /* To set focus */
1211 if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
1212 {
1213 /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
1214 jQuery('#dp_desc').focus();
1215 /* focus if CKEDITOR */
1216 if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
1217 {
1218 var editor = CKEDITOR.instances['dp_desc'];
1219 if (editor) { editor.focus(); }
1220 }
1221 }
1222 });
1223
1224 <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef?>
1225 setforpredef();
1226 <?php } ?>
1227 });
1228
1229 /* Function to set fields visibility after selecting a free product */
1230 function setforfree() {
1231 console.log("objectline_create.tpl::setforfree. We show most fields");
1232 jQuery("#idprodfournprice").val('0'); // Set cursor on not selected product
1233 jQuery("#prod_entry_mode_free").prop('checked',true).change();
1234 jQuery("#prod_entry_mode_predef").prop('checked',false).change();
1235 jQuery("#search_idprod, #idprod, #search_idprodfournprice, #buying_price").val('');
1236 jQuery("#price_ht, #multicurrency_price_ht, #price_ttc, #multicurrency_price_ttc, #fourn_ref, #tva_tx, #buying_price, #title_fourn_ref, #title_vat, #title_up_ht, #title_up_ht_currency, #title_up_ttc, #title_up_ttc_currency").show();
1237 jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show();
1238 jQuery("#fournprice_predef").hide();
1239 }
1240
1241 function setforpredef() {
1242 console.log("objectline_create.tpl::setforpredef We hide some fields, show dates");
1243 jQuery("#select_type").val(-1);
1244 jQuery("#prod_entry_mode_free").prop('checked',false).change();
1245 jQuery("#prod_entry_mode_predef").prop('checked',true).change();
1246 <?php if (!getDolGlobalString('MAIN_DISABLE_EDIT_PREDEF_PRICEHT')) { ?>
1247 jQuery("#price_ht").val('').show();
1248 jQuery("#multicurrency_price_ht").val('').show();
1249 jQuery("#title_up_ht, #title_up_ht_currency").show();
1250 <?php } else { ?>
1251 //jQuery("#price_ht").val('').hide();
1252 jQuery("#multicurrency_price_ht").val('').hide();
1253 jQuery("#title_up_ht, #title_up_ht_currency").hide();
1254 <?php } ?>
1255 <?php if (!getDolGlobalString('MAIN_DISABLE_EDIT_PREDEF_PRICETTC')) { ?>
1256 jQuery("#price_ttc").val('').show();
1257 jQuery("#multicurrency_price_ttc").val('').show();
1258 jQuery("#title_up_ttc, #title_up_ttc_currency").show();
1259 <?php } else { ?>
1260 jQuery("#price_ttc").val('').hide();
1261 jQuery("#multicurrency_price_ttc").val('').hide();
1262 jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
1263 <?php } ?>
1264 /* jQuery("#tva_tx, #title_vat").hide(); */
1265 /* jQuery("#title_fourn_ref").hide(); */
1266 jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").hide();
1267 jQuery("#buying_price").show();
1268 jQuery('#trlinefordates, .divlinefordates').show();
1269 }
1270
1271<?php
1272
1273print '</script>';
1274
1275print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";
Class to manage lines of contracts.
Class to manage a WYSIWYG editor.
Class to manage supplier invoice lines of templates.
Class to manage invoice lines.
Class to manage invoice lines of templates.
Class to manage order lines.
const TYPE_SERVICE
Service.
Class to manage commercial proposal lines.
Class to manage line invoices.
Class to manage supplier_proposal lines.
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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:121
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124