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