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