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