dolibarr 21.0.0-alpha
stockcorrection.tpl.php
1<?php
2/* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * $object must be defined
20 * $backtopage
21 */
22
23// Protection to avoid direct call of template
24if (empty($conf) || !is_object($conf)) {
25 print "Error, template page can't be called as URL";
26 exit(1);
27}
28
29'
30@phan-var-force Entrepot|MouvementStock $object
31@phan-var-force FormProduct $formproduct
32@phan-var-force FormProjets $formproject
33@phan-var-force string $backtopage
34';
35
36?>
37
38<!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
39<?php
44$productref = '';
45if ($object->element == 'product') {
46 $productref = $object->ref;
47}
48
49$langs->load("productbatch");
50
51
52if (empty($id)) {
53 $id = $object->id;
54}
55
56$pdluoid = GETPOSTINT('pdluoid');
57
58$pdluo = new Productbatch($db);
59
60if ($pdluoid > 0) {
61 $result = $pdluo->fetch($pdluoid);
62 if ($result > 0) {
63 $pdluoid = $pdluo->id;
64 } else {
65 dol_print_error($db, $pdluo->error, $pdluo->errors);
66 }
67}
68
69$sellByCss = '';
70$eatByCss = '';
71// A date is mandatory when we record the lot the first time. Then once lot and date is recorded
72// a user should be able to manage the lot only (this is main goal of lot)
73/*
74if ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY) {
75 $sellByCss = 'fieldrequired';
76} elseif ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY) {
77 $eatByCss = 'fieldrequired';
78} elseif ($object->sell_or_eat_by_mandatory == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
79 $sellByCss = 'fieldrequired';
80 $eatByCss = 'fieldrequired';
81}
82*/
83
84$disableSellBy = getDolGlobalInt('PRODUCT_DISABLE_SELLBY');
85$disableEatBy = getDolGlobalInt('PRODUCT_DISABLE_EATBY');
86print '<script type="text/javascript">
87 jQuery(document).ready(function() {
88 function init_price()
89 {
90 if (jQuery("#mouvement").val() == \'0\') jQuery("#unitprice").removeAttr("disabled");
91 else jQuery("#unitprice").prop("disabled", true);
92 }
93 init_price();
94 jQuery("#mouvement").change(function() {
95 console.log("We change the direction of movement");
96 init_price();
97 });
98 jQuery("#nbpiece").keyup(function(event) {
99 console.log("We enter a qty on "+event.key);
100 if ( event.key == "-" ) { /* char - */
101 console.log("We set direction to value 1");
102 jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("-", ""));
103 jQuery("#mouvement option").removeAttr("selected").change();
104 jQuery("#mouvement option[value=1]").attr("selected","selected").trigger("change");
105 jQuery("#mouvement").trigger("change");
106 } else if ( event.key == "+" ) { /* char + */
107 console.log("We set direction to value 0");
108 jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("+", ""));
109 jQuery("#mouvement option").removeAttr("selected").change();
110 jQuery("#mouvement option[value=0]").attr("selected","selected").trigger("change");
111 jQuery("#mouvement").trigger("change");
112 }
113 });';
114
115if ($disableSellBy == 0 || $disableEatBy == 0) {
116 print '
117 var disableSellBy = '.dol_escape_js((string) $disableSellBy).';
118 var disableEatBy = '.dol_escape_js((string) $disableSellBy).';
119 jQuery("#batch_number").change(function(event) {
120 var batch = jQuery(this).val();
121 jQuery.getJSON("'.DOL_URL_ROOT.'/product/ajax/product_lot.php?action=search&token='.currentToken().'&product_id='.$id.'&batch="+batch, function(data) {
122 if (data.length > 0) {
123 var productLot = data[0];
124 if (disableSellBy == 0) {
125 jQuery("#sellby").val(productLot.sellby);
126 }
127 if (disableEatBy == 0) {
128 jQuery("#eatby").val(productLot.eatby);
129 }
130 }
131 });
132 });';
133}
134print '});';
135print '</script>';
136
137
138print load_fiche_titre($langs->trans("StockCorrection"), '', 'generic');
139
140print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
141
142print dol_get_fiche_head();
143
144print '<input type="hidden" name="token" value="'.newToken().'">';
145print '<input type="hidden" name="action" value="correct_stock">';
146print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
147if ($pdluoid) {
148 print '<input type="hidden" name="pdluoid" value="'.$pdluoid.'">';
149}
150print '<table class="border centpercent">';
151
152// Warehouse or product
153print '<tr>';
154if ($object->element == 'product') {
155 print '<td class="fieldrequired">'.$langs->trans("Warehouse").'</td>';
156 print '<td>';
157 $ident = (GETPOST("dwid") ? GETPOSTINT("dwid") : (GETPOST('id_entrepot') ? GETPOSTINT('id_entrepot') : ($object->element == 'product' && $object->fk_default_warehouse ? $object->fk_default_warehouse : 'ifone')));
158 if (empty($ident) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE')) {
159 $ident = getDolGlobalString('MAIN_DEFAULT_WAREHOUSE');
160 }
161 print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($ident, 'id_entrepot', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth100 maxwidth300 widthcentpercentminusx');
162 print '</td>';
163}
164if ($object->element == 'stockmouvement') {
165 print '<td class="fieldrequired">'.$langs->trans("Product").'</td>';
166 print '<td>';
167 print img_picto('', 'product');
168 $form->select_produits(GETPOSTINT('product_id'), 'product_id', (!getDolGlobalString('STOCK_SUPPORTS_SERVICES') ? '0' : ''), 0, 0, -1, 2, '', 0, array(), 0, 1, 0, 'maxwidth500');
169 print '</td>';
170}
171print '<td class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td>';
172print '<td>';
173if ($object->element == 'product' || $object->element == 'stockmouvement') {
174 print '<select name="mouvement" id="mouvement" class="minwidth100 valignmiddle">';
175 print '<option value="0">'.$langs->trans("Add").'</option>';
176 print '<option value="1"'.(GETPOST('mouvement') ? ' selected="selected"' : '').'>'.$langs->trans("Delete").'</option>';
177 print '</select>';
178 print ajax_combobox("mouvement");
179}
180print '<input name="nbpiece" id="nbpiece" class="center valignmiddle maxwidth75" value="'.GETPOST("nbpiece").'">';
181print '</td>';
182print '</tr>';
183
184// If product is a Kit, we ask if we must disable stock change of subproducts
185if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $object->element == 'product' && $object->hasFatherOrChild(1)) {
186 print '<tr>';
187 print '<td></td>';
188 print '<td colspan="3">';
189 print '<input type="checkbox" name="disablesubproductstockchange" id="disablesubproductstockchange" value="1"'.(GETPOST('disablesubproductstockchange') ? ' checked="checked"' : '').'">';
190 print ' <label for="disablesubproductstockchange">'.$langs->trans("DisableStockChangeOfSubProduct").'</label>';
191 print '</td>';
192 print '</tr>';
193}
194
195// Serial / Eat-by date
196if (isModEnabled('productbatch') &&
197(($object->element == 'product' && $object->hasbatch())
198|| ($object->element == 'stockmouvement'))
199) {
200 print '<tr>';
201 print '<td'.($object->element == 'stockmouvement' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="3">';
202 if ($pdluoid > 0) {
203 // If form was opened for a specific pdluoid, field is disabled
204 print '<input type="text" name="batch_number_bis" size="40" disabled="disabled" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
205 print '<input type="hidden" name="batch_number" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
206 } else {
207 print img_picto('', 'barcode', 'class="pictofixedwidth"').'<input type="text" id="batch_number" name="batch_number" class="minwidth300" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
208 }
209 print '</td>';
210 print '</tr>';
211
212 print '<tr>';
213 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
214 print '<td'.($sellByCss ? ' class="'.$sellByCss.'"' : '').'>'.$langs->trans("SellByDate").'</td><td>';
215 $sellbyselected = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear'));
216 // If form was opened for a specific pdluoid, field is disabled
217 print $form->selectDate(($pdluo->id > 0 ? $pdluo->sellby : $sellbyselected), 'sellby', 0, 0, 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
218 print '</td>';
219 }
220 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
221 print '<td'.($eatByCss ? ' class="'.$eatByCss.'"' : '').'>'.$langs->trans("EatByDate").'</td><td>';
222 $eatbyselected = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear'));
223 // If form was opened for a specific pdluoid, field is disabled
224 print $form->selectDate(($pdluo->id > 0 ? $pdluo->eatby : $eatbyselected), 'eatby', 0, 0, 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
225 print '</td>';
226 }
227 print '</tr>';
228}
229
230// Purchase price and project
231print '<tr>';
232print '<td>'.$langs->trans("UnitPurchaseValue").'</td>';
233print '<td colspan="'.(isModEnabled('project') ? '1' : '3').'"><input name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
234if (isModEnabled('project')) {
235 print '<td>'.$langs->trans('Project').'</td>';
236 print '<td>';
237 print img_picto('', 'project');
238 $formproject->select_projects(-1, '', 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth300 widthcentpercentminusx');
239 print '</td>';
240}
241print '</tr>';
242
243// Label for movement of id of inventory
244$valformovementlabel = ((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock", ''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $productref));
245print '<tr>';
246print '<td>'.$langs->trans("MovementLabel").'</td>';
247print '<td>';
248print '<input type="text" name="label" class="minwidth400" value="'.dol_escape_htmltag($valformovementlabel).'">';
249print '</td>';
250print '<td>'.$langs->trans("InventoryCode").'</td>';
251print '<td>';
252print '<input class="maxwidth100onsmartphone" name="inventorycode" id="inventorycode" value="'.(GETPOSTISSET("inventorycode") ? GETPOST("inventorycode", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S')).'">';
253print '</td>';
254print '</tr>';
255
256print '</table>';
257
258print dol_get_fiche_end();
259
260print '<div class="center">';
261print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
262print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
263print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
264print '</div>';
265
266print '</form>';
267?>
268<!-- END PHP STOCKCORRECTION.TPL.PHP -->
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:457
Manage record for batch number management.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.