dolibarr 19.0.3
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;
26}
27
28?>
29
30<!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
31<?php
32$productref = '';
33if ($object->element == 'product') {
34 $productref = $object->ref;
35}
36
37$langs->load("productbatch");
38
39
40if (empty($id)) {
41 $id = $object->id;
42}
43
44$pdluoid = GETPOST('pdluoid', 'int');
45
46$pdluo = new Productbatch($db);
47
48if ($pdluoid > 0) {
49 $result = $pdluo->fetch($pdluoid);
50 if ($result > 0) {
51 $pdluoid = $pdluo->id;
52 } else {
53 dol_print_error($db, $pdluo->error, $pdluo->errors);
54 }
55}
56
57print '<script type="text/javascript">
58 jQuery(document).ready(function() {
59 function init_price()
60 {
61 if (jQuery("#mouvement").val() == \'0\') jQuery("#unitprice").removeAttr("disabled");
62 else jQuery("#unitprice").prop("disabled", true);
63 }
64 init_price();
65 jQuery("#mouvement").change(function() {
66 console.log("We change the direction of movement");
67 init_price();
68 });
69 jQuery("#nbpiece").keyup(function(event) {
70 console.log("We enter a qty on "+event.key);
71 if ( event.key == "-" ) { /* char - */
72 console.log("We set direction to value 1");
73 jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("-", ""));
74 jQuery("#mouvement option").removeAttr("selected").change();
75 jQuery("#mouvement option[value=1]").attr("selected","selected").trigger("change");
76 jQuery("#mouvement").trigger("change");
77 } else if ( event.key == "+" ) { /* char + */
78 console.log("We set direction to value 0");
79 jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("+", ""));
80 jQuery("#mouvement option").removeAttr("selected").change();
81 jQuery("#mouvement option[value=0]").attr("selected","selected").trigger("change");
82 jQuery("#mouvement").trigger("change");
83 }
84 });
85 });
86 </script>';
87
88
89print load_fiche_titre($langs->trans("StockCorrection"), '', 'generic');
90
91print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
92
93print dol_get_fiche_head();
94
95print '<input type="hidden" name="token" value="'.newToken().'">';
96print '<input type="hidden" name="action" value="correct_stock">';
97print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
98if ($pdluoid) {
99 print '<input type="hidden" name="pdluoid" value="'.$pdluoid.'">';
100}
101print '<table class="border centpercent">';
102
103// Warehouse or product
104print '<tr>';
105if ($object->element == 'product') {
106 print '<td class="fieldrequired">'.$langs->trans("Warehouse").'</td>';
107 print '<td>';
108 $ident = (GETPOST("dwid") ? GETPOST("dwid", 'int') : (GETPOST('id_entrepot') ? GETPOST('id_entrepot', 'int') : ($object->element == 'product' && $object->fk_default_warehouse ? $object->fk_default_warehouse : 'ifone')));
109 if (empty($ident) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE')) {
110 $ident = $conf->global->MAIN_DEFAULT_WAREHOUSE;
111 }
112 print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($ident, 'id_entrepot', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'minwidth100 maxwidth300 widthcentpercentminusx');
113 print '</td>';
114}
115if ($object->element == 'stock') {
116 print '<td class="fieldrequired">'.$langs->trans("Product").'</td>';
117 print '<td>';
118 print img_picto('', 'product');
119 $form->select_produits(GETPOST('product_id', 'int'), 'product_id', (!getDolGlobalString('STOCK_SUPPORTS_SERVICES') ? '0' : ''), 0, 0, -1, 2, '', 0, null, 0, 1, 0, 'maxwidth500');
120 print '</td>';
121}
122print '<td class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td>';
123print '<td>';
124if ($object->element == 'product' || $object->element == 'stock') {
125 print '<select name="mouvement" id="mouvement" class="minwidth100 valignmiddle">';
126 print '<option value="0">'.$langs->trans("Add").'</option>';
127 print '<option value="1"'.(GETPOST('mouvement') ? ' selected="selected"' : '').'>'.$langs->trans("Delete").'</option>';
128 print '</select>';
129 print ajax_combobox("mouvement");
130}
131print '<input name="nbpiece" id="nbpiece" class="center valignmiddle maxwidth75" value="'.GETPOST("nbpiece").'">';
132print '</td>';
133print '</tr>';
134
135// If product is a Kit, we ask if we must disable stock change of subproducts
136if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $object->element == 'product' && $object->hasFatherOrChild(1)) {
137 print '<tr>';
138 print '<td></td>';
139 print '<td colspan="3">';
140 print '<input type="checkbox" name="disablesubproductstockchange" id="disablesubproductstockchange" value="1"'.(GETPOST('disablesubproductstockchange') ? ' checked="checked"' : '').'">';
141 print ' <label for="disablesubproductstockchange">'.$langs->trans("DisableStockChangeOfSubProduct").'</label>';
142 print '</td>';
143 print '</tr>';
144}
145
146// Serial / Eat-by date
147if (ismodEnabled('productbatch') &&
148(($object->element == 'product' && $object->hasbatch())
149|| ($object->element == 'stock'))
150) {
151 print '<tr>';
152 print '<td'.($object->element == 'stock' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="3">';
153 if ($pdluoid > 0) {
154 // If form was opened for a specific pdluoid, field is disabled
155 print '<input type="text" name="batch_number_bis" size="40" disabled="disabled" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
156 print '<input type="hidden" name="batch_number" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
157 } else {
158 print img_picto('', 'barcode', 'class="pictofixedwidth"').'<input type="text" name="batch_number" class="minwidth300" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
159 }
160 print '</td>';
161 print '</tr>';
162
163 print '<tr>';
164 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
165 print '<td>'.$langs->trans("SellByDate").'</td><td>';
166 $sellbyselected = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear'));
167 // If form was opened for a specific pdluoid, field is disabled
168 print $form->selectDate(($pdluo->id > 0 ? $pdluo->sellby : $sellbyselected), 'sellby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
169 print '</td>';
170 }
171 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
172 print '<td>'.$langs->trans("EatByDate").'</td><td>';
173 $eatbyselected = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear'));
174 // If form was opened for a specific pdluoid, field is disabled
175 print $form->selectDate(($pdluo->id > 0 ? $pdluo->eatby : $eatbyselected), 'eatby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
176 print '</td>';
177 }
178 print '</tr>';
179}
180
181// Purchase price and project
182print '<tr>';
183print '<td>'.$langs->trans("UnitPurchaseValue").'</td>';
184print '<td colspan="'.(isModEnabled('project') ? '1' : '3').'"><input name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
185if (isModEnabled('project')) {
186 print '<td>'.$langs->trans('Project').'</td>';
187 print '<td>';
188 print img_picto('', 'project');
189 $formproject->select_projects(-1, '', 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth300 widthcentpercentminusx');
190 print '</td>';
191}
192print '</tr>';
193
194// Label of mouvement of id of inventory
195$valformovementlabel = ((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock", ''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $productref));
196print '<tr>';
197print '<td>'.$langs->trans("MovementLabel").'</td>';
198print '<td>';
199print '<input type="text" name="label" class="minwidth400" value="'.dol_escape_htmltag($valformovementlabel).'">';
200print '</td>';
201print '<td>'.$langs->trans("InventoryCode").'</td>';
202print '<td>';
203print '<input class="maxwidth100onsmartphone" name="inventorycode" id="inventorycode" value="'.(GETPOSTISSET("inventorycode") ? GETPOST("inventorycode", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S')).'">';
204print '</td>';
205print '</tr>';
206
207print '</table>';
208
209print dol_get_fiche_end();
210
211print '<div class="center">';
212print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
213print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
214print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
215print '</div>';
216
217print '</form>';
218?>
219<!-- END PHP STOCKCORRECTION.TPL.PHP -->
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:447
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 informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.