dolibarr 18.0.6
stocktransfer_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) ---Put here your own copyright and developer email---
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
25// Load Dolibarr environment
26require '../../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
30require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransferline.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/modules/stocktransfer/modules_stocktransfer.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array("stocks", "other", "productbatch", "companies"));
40 if (isModEnabled('incoterm')) $langs->load('incoterm');
41
42
43// Get parameters
44$id = GETPOST('id', 'int');
45$ref = GETPOST('ref', 'alpha');
46$action = GETPOST('action', 'aZ09');
47$confirm = GETPOST('confirm', 'alpha');
48$cancel = GETPOST('cancel', 'aZ09');
49$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'stocktransfercard'; // To manage different context of search
50$backtopage = GETPOST('backtopage', 'alpha');
51$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
52$qty = GETPOST('qty', 'int');
53$fk_product = GETPOST('fk_product', 'int');
54$fk_warehouse_source = GETPOST('fk_warehouse_source', 'int');
55$fk_warehouse_destination = GETPOST('fk_warehouse_destination', 'int');
56$lineid = GETPOST('lineid', 'int');
57$label = GETPOST('label', 'alpha');
58$batch = GETPOST('batch', 'alpha');
59$code_inv = GETPOST('inventorycode', 'alphanohtml');
60
61// Initialize technical objects
62$object = new StockTransfer($db);
63$extrafields = new ExtraFields($db);
64$diroutputmassaction = $conf->stocktransfer->dir_output.'/temp/massgeneration/'.$user->id;
65$hookmanager->initHooks(array('stocktransfercard', 'globalcard')); // Note that conf->hooks_modules contains array
66
67// Fetch optionals attributes and labels
68$extrafields->fetch_name_optionals_label($object->table_element);
69
70$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
71
72// Initialize array of search criterias
73$search_all = trim(GETPOST("search_all", 'alpha'));
74$search = array();
75foreach ($object->fields as $key => $val) {
76 if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
77}
78
79if (empty($action) && empty($id) && empty($ref)) $action = 'view';
80
81// Load object
82include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
83
84
85$permissiontoread = $user->rights->stocktransfer->stocktransfer->read;
86$permissiontoadd = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
87$permissionnote = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_setnotes.inc.php
88$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status < $object::STATUS_TRANSFERED);
89$permissiondellink = $user->rights->stocktransfer->stocktransfer->write; // Used by the include of actions_dellink.inc.php
90$upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1];
91
92// Security check - Protection if external user
93//if ($user->socid > 0) accessforbidden();
94//if ($user->socid > 0) $socid = $user->socid;
95//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
96//$result = restrictedArea($user, 'stocktransfer', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
97
98if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
99
100
101/*
102 * Actions
103 */
104
105$form = new Form($db);
106$formfile = new FormFile($db);
107$formproject = new FormProjets($db);
108
109$parameters = array();
110$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
111if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112
113if (empty($reshook)) {
114 $error = 0;
115
116 $backurlforlist = dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1);
117
118 if (empty($backtopage) || ($cancel && empty($id))) {
119 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
120 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist;
121 else $backtopage = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
122 }
123 }
124 $triggermodname = 'STOCKTRANSFER_STOCKTRANSFER_MODIFY'; // Name of trigger action code to execute when we modify record
125
126 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
127 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
128
129 // On remet cette lecture de permission ici car nécessaire d'avoir le nouveau statut de l'objet après toute action exécutée dessus (après incrémentation par exemple, le bouton supprimer doit disparaître)
130 $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
131
132 // Actions when linking object each other
133 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
134
135 // Actions when printing a doc from card
136 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
137
138 // Action to move up and down lines of object
139 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
140
141 // Action to build doc
142 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
143
144 if ($action == 'set_thirdparty' && $permissiontoadd) {
145 $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'STOCKTRANSFER_MODIFY');
146 }
147 if ($action == 'classin' && $permissiontoadd) {
148 $object->setProject(GETPOST('projectid', 'int'));
149 }
150
151 if ($action == 'addline' && $permissiontoadd) {
152 if ($qty <= 0) {
153 $error++;
154 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
155 $action = 'view';
156 }
157
158 if ($fk_warehouse_source <= 0) {
159 $error++;
160 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
161 $action = 'view';
162 }
163
164 if ($fk_warehouse_destination <= 0) {
165 $error++;
166 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
167 $action = 'view';
168 }
169
170 $prod = new Product($db);
171 $prod->fetch($fk_product);
172 if ($prod->hasbatch()) {
173 if (empty($batch)) {
174 $error++;
175 $langs->load("errors");
176 setEventMessages($langs->transnoentities("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors');
177 }
178 } else {
179 if (!empty($batch)) {
180 $error++;
181 setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors');
182 }
183 }
184
185 if (empty($error)) {
186 $line = new StockTransferLine($db);
187 $records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.((int) $id).' AND fk_product = '.((int) $fk_product).' AND fk_warehouse_source = '.((int) $fk_warehouse_source).' AND fk_warehouse_destination = '.((int) $fk_warehouse_destination).' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : "batch = '".$db->escape($batch)."'" ).')'));
188 if (!empty($records[key($records)])) $line = $records[key($records)];
189 $line->fk_stocktransfer = $id;
190 $line->qty += $qty;
191 $line->fk_warehouse_source = $fk_warehouse_source;
192 $line->fk_warehouse_destination = $fk_warehouse_destination;
193 $line->fk_product = $fk_product;
194 $line->batch = $batch;
195
196 $line->pmp = $prod->pmp;
197 if ($line->id > 0) $line->update($user);
198 else {
199 $line->rang = count($object->lines) + 1;
200 $line->create($user);
201 }
202 $object->fetchLines();
203 }
204 } elseif ($action === 'updateline' && $permissiontoadd) {
205 if ($qty <= 0) {
206 $error++;
207 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
208 $action = 'editline';
209 }
210
211 if ($fk_warehouse_source <= 0) {
212 $error++;
213 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
214 $action = 'editline';
215 }
216
217 if ($fk_warehouse_destination <= 0) {
218 $error++;
219 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
220 $action = 'editline';
221 }
222
223 $prod = new Product($db);
224 $prod->fetch($fk_product);
225 if ($prod->hasbatch()) {
226 if (empty($batch)) {
227 $error++;
228 $langs->load("errors");
229 setEventMessages($langs->transnoentities("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->getNomUrl()), null, 'errors');
230 $action = 'editline';
231 }
232 } else {
233 if (!empty($batch)) {
234 $error++;
235 setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors');
236 $action = 'editline';
237 }
238 }
239
240 if (empty($error)) {
241 $line = new StockTransferLine($db);
242 $line->fetch($lineid);
243 $line->qty = $qty;
244 $line->fk_warehouse_source = $fk_warehouse_source;
245 $line->fk_warehouse_destination = $fk_warehouse_destination;
246 $line->fk_product = $fk_product;
247 $line->batch = $batch;
248 $line->pmp = $prod->pmp;
249 $line->update($user);
250 }
251 }
252
253 if ($permissiontoadd) {
254 // Décrémentation
255 if ($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED) {
256 $lines = $object->getLinesArray();
257 if (!empty($lines)) {
258 $db->begin();
259 foreach ($lines as $line) {
260 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source);
261 if ($res <= 0) $error++;
262 }
263 if (empty($error)) $db->commit();
264 else $db->rollback();
265 }
266 if (empty($error)) {
267 $object->setStatut($object::STATUS_TRANSFERED, $id);
268 $object->status = $object::STATUS_TRANSFERED;
269 $object->date_reelle_depart = date('Y-m-d');
270 $object->update($user);
271 setEventMessage('StockStransferDecremented');
272 }
273 }
274
275 // Annulation décrémentation
276 if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) {
277 $lines = $object->getLinesArray();
278 if (!empty($lines)) {
279 $db->begin();
280 foreach ($lines as $line) {
281 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0);
282 if ($res <= 0) $error++;
283 }
284 if (empty($error)) $db->commit();
285 else $db->rollback();
286 }
287 if (empty($error)) {
288 $object->setStatut($object::STATUS_VALIDATED, $id);
289 $object->status = $object::STATUS_VALIDATED;
290 $object->date_reelle_depart = null;
291 $object->update($user);
292 setEventMessage('StockStransferDecrementedCancel', 'warnings');
293 }
294 }
295
296 // Incrémentation
297 if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) {
298 $lines = $object->getLinesArray();
299 if (!empty($lines)) {
300 $db->begin();
301 foreach ($lines as $line) {
302 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0);
303 if ($res <= 0) $error++;
304 }
305 if (empty($error)) $db->commit();
306 else $db->rollback();
307 }
308 if (empty($error)) {
309 $object->setStatut($object::STATUS_CLOSED, $id);
310 $object->status = $object::STATUS_CLOSED;
311 $object->date_reelle_arrivee = date('Y-m-d');
312 $object->update($user);
313 setEventMessage('StockStransferIncrementedShort');
314 }
315 }
316
317 // Annulation incrémentation
318 if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED) {
319 $lines = $object->getLinesArray();
320 if (!empty($lines)) {
321 $db->begin();
322 foreach ($lines as $line) {
323 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination);
324 if ($res <= 0) $error++;
325 }
326 if (empty($error)) $db->commit();
327 else $db->rollback();
328 }
329 if (empty($error)) {
330 $object->setStatut($object::STATUS_TRANSFERED, $id);
331 $object->status = $object::STATUS_TRANSFERED;
332 $object->date_reelle_arrivee = null;
333 $object->update($user);
334 setEventMessage('StockStransferIncrementedShortCancel', 'warnings');
335 }
336 }
337 }
338
339 // Set incoterm
340 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
341 $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
342 }
343 // Actions to send emails
344 $triggersendname = 'STOCKTRANSFER_SENTBYMAIL';
345 $autocopy = 'MAIN_MAIL_AUTOCOPY_STOCKTRANSFER_TO';
346 $trackid = 'stocktransfer'.$object->id;
347 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
348}
349
350
351
352
353/*
354 * View
355 *
356 * Put here all code to build page
357 */
358
359$title = $langs->trans("StockTransfer");
360$help_url = '';
361llxHeader('', $title, $help_url);
362
363
364
365// Example : Adding jquery code
366print '<script type="text/javascript" language="javascript">
367jQuery(document).ready(function() {';
368
369// Affichage alerte date prévue de départ si transfert concerné
370$date_prevue_depart = $object->date_prevue_depart;
371$date_prevue_depart_plus_delai = $date_prevue_depart;
372if ($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
373if (!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) {
374 print "$('.valuefield.fieldname_date_prevue_depart').append('";
375 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
376 print "');";
377}
378
379print '});
380</script>';
381
382
383// Part to create
384if ($action == 'create') {
385 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("StockTransfer")), '', 'object_'.$object->picto);
386
387 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
388 print '<input type="hidden" name="token" value="'.newToken().'">';
389 print '<input type="hidden" name="action" value="add">';
390 if ($backtopage) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
391 if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
392
393 print dol_get_fiche_head(array(), '');
394
395 // Set some default values
396 //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
397
398 print '<table class="border centpercent tableforfieldcreate">'."\n";
399
400 // Common attributes
401 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
402
403 if (isModEnabled('incoterm')) {
404 print '<tr>';
405 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->label_incoterms, 1).'</label></td>';
406 print '<td class="maxwidthonsmartphone">';
407 print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''), '', 'fk_incoterms');
408 print '</td></tr>';
409 }
410 // Template to use by default
411 print '<tr><td>'.$langs->trans('DefaultModel').'</td>';
412 print '<td>';
413 print img_picto('', 'pdf', 'class="pictofixedwidth"');
414 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
416 $preselected = $conf->global->STOCKTRANSFER_ADDON_PDF;
417 print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
418 print "</td></tr>";
419
420 // Other attributes
421 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
422
423 print '</table>'."\n";
424
425 print dol_get_fiche_end();
426
427 print '<div class="center">';
428 print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
429 print '&nbsp; ';
430 print '<input type="'.($backtopage ? "submit" : "button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage ? '' : ' onclick="history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
431 print '</div>';
432
433 print '</form>';
434
435 //dol_set_focus('input[name="ref"]');
436}
437
438// Part to edit record
439if (($id || $ref) && $action == 'edit') {
440 //if($object->status < 3) {
441 print load_fiche_titre($langs->trans("StockTransfer"), '', 'object_' . $object->picto);
442
443 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
444 print '<input type="hidden" name="token" value="' . newToken() . '">';
445 print '<input type="hidden" name="action" value="update">';
446 print '<input type="hidden" name="id" value="' . $object->id . '">';
447 if ($backtopage) print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
448 if ($backtopageforcancel) print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
449
450 print dol_get_fiche_head();
451
452 print '<table class="border centpercent tableforfieldedit">' . "\n";
453
454 // Common attributes
455 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
456
457 // Other attributes
458 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
459
460 print '</table>';
461
462 print dol_get_fiche_end();
463
464 print '<div class="center"><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
465 print ' &nbsp; <input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
466 print '</div>';
467
468 print '</form>';
469 //} else $action = 'view';
470}
471
472// Part to show record
473if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
474 $res = $object->fetch_optionals();
475
476 $head = stocktransferPrepareHead($object);
477 print dol_get_fiche_head($head, 'card', $langs->trans("StockTransfer"), -1, $object->picto);
478
479 $formconfirm = '';
480
481 // Confirmation to delete
482 if ($action == 'delete') {
483 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
484 }
485 // Confirmation to delete line
486 if ($action == 'deleteline') {
487 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
488 }
489 // Clone confirmation
490 if ($action == 'clone') {
491 // Create an array for form
492 $formquestion = array();
493 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
494 } elseif ($action == 'destock') { // Destock confirmation
495 // Create an array for form
496 $formquestion = array( 'text' => '',
497 array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestock', $object->ref), 'size'=>40),
498 array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size'=>25)
499 );
500 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProduct'), '', 'confirm_destock', $formquestion, 'yes', 1);
501 } elseif ($action == 'destockcancel') { // Destock confirmation cancel
502 // Create an array for form
503 $formquestion = array( 'text' => '',
504 array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestockCancel', $object->ref), 'size'=>40),
505 array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size'=>25)
506 );
507 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProductCancel'), '', 'confirm_destockcancel', $formquestion, 'yes', 1);
508 } elseif ($action == 'addstock') { // Addstock confirmation
509 // Create an array for form
510 $formquestion = array( 'text' => '',
511 array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStock', $object->ref), 'size'=>40),
512 array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size'=>25)
513 );
514 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProduct'), '', 'confirm_addstock', $formquestion, 'yes', 1);
515 } elseif ($action == 'addstockcancel') { // Addstock confirmation cancel
516 // Create an array for form
517 $formquestion = array( 'text' => '',
518 array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStockCancel', $object->ref), 'size'=>40),
519 array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size'=>25)
520 );
521 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProductCancel'), '', 'confirm_addstockcancel', $formquestion, 'yes', 1);
522 }
523
524 // Confirmation of action xxxx
525 if ($action == 'xxx') {
526 $formquestion = array();
527 /*
528 $forcecombo=0;
529 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
530 $formquestion = array(
531 // 'text' => $langs->trans("ConfirmClone"),
532 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
533 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
534 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
535 );
536 */
537 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
538 }
539
540
541 if ($action == 'valid' && $permissiontoadd) {
542 $nextref=$object->getNextNumRef();
543 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $langs->transnoentities('ConfirmValidateStockTransfer', $nextref), 'confirm_validate', $formquestion, 0, 2);
544 }
545
546 // Call Hook formConfirm
547 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
548 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
549 if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
550 elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
551
552 // Print form confirm
553 print $formconfirm;
554
555
556 // Object card
557 // ------------------------------------------------------------
558 $linkback = '<a href="'.dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
559
560 $morehtmlref = '<div class="refidno">';
561
562 // Thirdparty
563 if (isModEnabled('societe')) {
564 $morehtmlref .= $langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '').'<br>';
565 }
566 // Project
567 if (isModEnabled('project')) {
568 $langs->load("projects");
569 $morehtmlref.=$langs->trans('Project') . ' ';
570 if ($permissiontoadd) {
571 //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
572 $morehtmlref.=' : ';
573 if ($action == 'classify') {
574 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
575 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
576 $morehtmlref.='<input type="hidden" name="action" value="classin">';
577 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
578 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
579 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
580 $morehtmlref.='</form>';
581 } else {
582 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
583 }
584 } else {
585 if (!empty($object->fk_project)) {
586 $proj = new Project($db);
587 $proj->fetch($object->fk_project);
588 $morehtmlref .= ': '.$proj->getNomUrl();
589 } else {
590 $morehtmlref .= '';
591 }
592 }
593 }
594 $morehtmlref .= '</div>';
595
596
597 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
598
599
600 print '<div class="fichecenter">';
601 print '<div class="fichehalfleft">';
602 print '<div class="underbanner clearboth"></div>';
603 print '<table class="border centpercent tableforfield">'."\n";
604
605 // Common attributes
606 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
607 //unset($object->fields['fk_project']); // Hide field already shown in banner
608 //unset($object->fields['fk_soc']); // Hide field already shown in banner
609
610 $object->fields['fk_soc']['visible']=0; // Already available in banner
611 $object->fields['fk_project']['visible']=0; // Already available in banner
612 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
613
614 // Incoterms
615 if (isModEnabled('incoterm')) {
616 print '<tr><td>';
617 print '<table width="100%" class="nobordernopadding"><tr><td>';
618 print $langs->trans('IncotermLabel');
619 print '<td><td class="right">';
620 if ($permissiontoadd && $action != 'editincoterm') print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
621 else print '&nbsp;';
622 print '</td></tr></table>';
623 print '</td>';
624 print '<td>';
625 if ($action != 'editincoterm') {
626 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
627 } else {
628 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
629 }
630 print '</td></tr>';
631 }
632
633 echo '<tr>';
634 echo '<td>'.$langs->trans('EnhancedValue').'&nbsp;'.strtolower($langs->trans('TotalWoman'));
635 echo '<td>'.price($object->getValorisationTotale(), 0, '', 1, -1, -1, $conf->currency).'</td>';
636 echo '</tr>';
637 // Other attributes. Fields from hook formObjectOptions and Extrafields.
638 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
639
640 print '</table>';
641 print '</div>';
642 print '</div>';
643
644 print '<div class="clearboth"></div>';
645
646 print dol_get_fiche_end();
647
648
649 /*
650 * Lines
651 */
652
653 if (!empty($object->table_element_line)) {
654 // Show object lines
655 /*$result = $object->getLinesArray();
656
657 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
658 <input type="hidden" name="token" value="' . newToken().'">
659 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
660 <input type="hidden" name="mode" value="">
661 <input type="hidden" name="id" value="' . $object->id.'">
662 ';*/
663
664 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
665 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
666 }
667
668 /*print '<div class="div-table-responsive-no-min">';
669 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
670 {
671 print '<table id="tablelines" class="noborder noshadow" width="100%">';
672 }
673
674 if (!empty($object->lines))
675 {
676 $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
677 }
678
679 // Form to add new line
680 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines')
681 {
682 if ($action != 'editline')
683 {
684 // Add products/services form
685 $object->formAddObjectLine(1, $mysoc, $soc);
686
687 $parameters = array();
688 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
689 }
690 }
691
692 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
693 {
694 print '</table>';
695 }
696 print '</div>';
697
698 print "</form>\n";*/
699 }
700
701
702 $formproduct = new FormProduct($db);
703 print '<div class="div-table-responsive-no-min">';
704 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
705 <input type="hidden" name="token" value="' . newToken().'">
706 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
707 <input type="hidden" name="mode" value="">
708 <input type="hidden" name="id" value="' . $object->id.'">
709 ';
710 if ($lineid > 0) print '<input type="hidden" name="lineid" value="'.$lineid.'" />';
711 print '<table id="tablelines" class="liste centpercent">';
712 //print '<div class="tagtable centpercent">';
713
714 $param = '';
715
716 $conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE=true; // Full display needed to see all column title details
717
718 print '<tr class="liste_titre">';
719 print getTitleFieldOfList($langs->trans('ProductRef'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
720 if (isModEnabled('productbatch')) {
721 print getTitleFieldOfList($langs->trans('Batch'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
722 }
723 print getTitleFieldOfList($langs->trans('WarehouseSource'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
724 print getTitleFieldOfList($langs->trans('WarehouseTarget'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
725 print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
726 if ($conf->global->PRODUCT_USE_UNITS) {
727 print getTitleFieldOfList($langs->trans('Unit'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
728 }
729 print getTitleFieldOfList($langs->trans('AverageUnitPricePMPShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
730 print getTitleFieldOfList($langs->trans('EstimatedStockValueShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
731 if (empty($object->status) && $permissiontoadd) {
732 print getTitleFieldOfList('', 0);
733 print getTitleFieldOfList('', 0);
734 print getTitleFieldOfList('', 0);
735 }
736
737 print '</tr>';
738
739 $listofdata = $object->getLinesArray();
740 $productstatic = new Product($db);
741 $warehousestatics = new Entrepot($db);
742 $warehousestatict = new Entrepot($db);
743
744 foreach ($listofdata as $key => $line) {
745 $productstatic->fetch($line->fk_product);
746 $warehousestatics->fetch($line->fk_warehouse_source);
747 $warehousestatict->fetch($line->fk_warehouse_destination);
748
749 // add html5 elements
750 $domData = ' data-element="'.$line->element.'"';
751 $domData .= ' data-id="'.$line->id.'"';
752 $domData .= ' data-qty="'.$line->qty.'"';
753 //$domData .= ' data-product_type="'.$line->product_type.'"';
754
755 print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.'>';
756 print '<td class="titlefield">';
757 if ($action === 'editline' && $line->id == $lineid) $form->select_produits($line->fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
758 else print $productstatic->getNomUrl(1).' - '.$productstatic->label;
759 print '</td>';
760 if (isModEnabled('productbatch')) {
761 print '<td>';
762 if ($action === 'editline' && $line->id == $lineid) print '<input type="text" value="'.$line->batch.'" name="batch" class="flat maxwidth50"/>';
763 else {
764 $productlot = new Productlot($db);
765 if ($productlot->fetch(0, $line->fk_product, $line->batch) > 0) {
766 print $productlot->getNomUrl(1);
767 } elseif (!empty($line->batch)) print $line->batch.'&nbsp;'.img_warning($langs->trans('BatchNotFound'));
768 }
769 print '</td>';
770 }
771
772 print '<td>';
773
774 if ($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseSource);
775 else print $warehousestatics->getNomUrl(1);
776 print '</td>';
777 print '<td>';
778 if ($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_destination, 'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseDestination);
779 else print $warehousestatict->getNomUrl(1);
780 print '</td>';
781 if ($action === 'editline' && $line->id == $lineid) print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" value="'.$line->qty.'"></td>';
782 else print '<td class="center">'.$line->qty.'</td>';
783
784 if ($conf->global->PRODUCT_USE_UNITS) {
785 print '<td class="linecoluseunit nowrap left">';
786 $label = $productstatic->getLabelOfUnit('short');
787 if ($label !== '') {
788 print $langs->trans($label);
789 }
790 print '</td>';
791 }
792
793 print '<td class="center">';
794 print price($line->pmp, 0, '', 1, -1, -1, $conf->currency);
795 print '</td>';
796 print '<td class="center">';
797 print price($line->pmp * $line->qty, 0, '', 1, -1, -1, $conf->currency);
798 print '</td>';
799 if (empty($object->status) && $permissiontoadd) {
800 if ($action === 'editline' && $line->id == $lineid) {
801 //print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Save')) . '"></td>';
802 print '<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
803 print '<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
804 } else {
805 print '<td class="right">';
806 print '<a class="editfielda reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $line->id . '#line_' . $line->id . '">';
807 print img_edit() . '</a>';
808 print '</td>';
809 print '<td class="right">';
810 print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '&action=deleteline&lineid=' . $line->id . '">' . img_delete($langs->trans("Remove")) . '</a>';
811 print '</td>';
812 }
813
814 $num = count($object->lines);
815
816 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
817 print '<td class="linecolmove tdlineupdown center">';
818 $coldisplay++;
819 if ($i > 0) { ?>
820 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=up&amp;rowid='.$line->id; ?>">
821 <?php print img_up('default', 0, 'imgupforline'); ?>
822 </a>
823 <?php }
824 if ($i < $num - 1) { ?>
825 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=down&amp;rowid='.$line->id; ?>">
826 <?php print img_down('default', 0, 'imgdownforline'); ?>
827 </a>
828 <?php }
829 print '</td>';
830 } else {
831 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
832 $coldisplay++;
833 }
834 }
835
836 print '</tr>';
837 }
838
839 if (empty($object->status) && $action !== 'editline' && $permissiontoadd) {
840 print '<tr class="oddeven">';
841 // Product
842 print '<td class="titlefield">';
843 $filtertype = 0;
844 if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype = '';
845 if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) {
846 $limit = '';
847 } else {
848 $limit = $conf->global->PRODUIT_LIMIT_SIZE;
849 }
850
851 $form->select_produits($fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
852 print '</td>';
853 // Batch number
854 if (isModEnabled('productbatch')) {
855 print '<td>';
856 print '<input type="text" name="batch" class="flat maxwidth50" '.(!empty($error) ? 'value="'.$batch.'"' : '').'>';
857 print '</td>';
858 }
859
860 $formproduct->loadWarehouses(); // Pour charger la totalité des entrepôts
861
862 // On stock ceux qui ne doivent pas être proposés dans la liste
863 $TExcludedWarehouseSource=array();
864 if (!empty($object->fk_warehouse_source)) {
865 $source_ent = new Entrepot($db);
866 $source_ent->fetch($object->fk_warehouse_source);
867 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
868 if (strpos($TDataCacheWarehouse['full_label'], $source_ent->label) === false) $TExcludedWarehouseSource[] = $TDataCacheWarehouse['id'];
869 }
870 }
871
872 // On stock ceux qui ne doivent pas être proposés dans la liste
873 $TExcludedWarehouseDestination=array();
874 if (!empty($object->fk_warehouse_destination)) {
875 $dest_ent = new Entrepot($db);
876 $dest_ent->fetch($object->fk_warehouse_destination);
877 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
878 if (strpos($TDataCacheWarehouse['full_label'], $dest_ent->label) === false) $TExcludedWarehouseDestination[] = $TDataCacheWarehouse['id'];
879 }
880 }
881
882 // On vide le tableau pour qu'il se charge tout seul lors de l'appel à la fonction select_warehouses
883 $formproduct->cache_warehouses=array();
884 // In warehouse
885 print '<td>';
886 print $formproduct->selectWarehouses(empty($fk_warehouse_source) ? $object->fk_warehouse_source : $fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseSource);
887 print '</td>';
888
889 // On vide le tableau pour qu'il se charge tout seul lors de l'appel à la fonction select_warehouses
890 $formproduct->cache_warehouses=array();
891 // Out warehouse
892 print '<td>';
893 print $formproduct->selectWarehouses(empty($fk_warehouse_destination) ? $object->fk_warehouse_destination : $fk_warehouse_destination, 'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseDestination);
894 print '</td>';
895
896 // Qty
897 print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" '.(!empty($error) ? 'value="'.$qty.'"' : '').'></td>';
898 // PMP
899 print '<td></td>';
900 if ($conf->global->PRODUCT_USE_UNITS) {
901 // Unité
902 print '<td></td>';
903 }
904 // PMP * Qty
905 print '<td></td>';
906 // Button to add line
907 print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Add')) . '"></td>';
908 // Grad and drop lines
909 print '<td></td>';
910 print '</tr>';
911 }
912
913 print '</table>';
914 print '</form>';
915 print '</div>';
916
917 // Buttons for actions
918
919 if ($action != 'presend' && $action != 'editline') {
920 print '<div class="tabsAction">'."\n";
921 $parameters = array();
922 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
923 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
924
925 if (empty($reshook)) {
926 // Send
927 if (empty($user->socid)) {
928 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
929 }
930
931 // Back to draft
932 if ($object->status == $object::STATUS_VALIDATED) {
933 if ($permissiontoadd) {
934 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
935 }
936 }
937
938 // Modify
939 if ($permissiontoadd) {
940 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
941 }
942 /*else
943 {
944 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
945 }*/
946
947 // Validate
948 if ($object->status == $object::STATUS_DRAFT) {
949 if ($permissiontoadd) {
950 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
951 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=valid">'.$langs->trans("Validate").'</a>';
952 } else {
953 $langs->load("errors");
954 print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
955 }
956 }
957 } elseif ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
958 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destock&token='.newToken().'">'.$langs->trans("StockTransferDecrementation").'</a>';
959 } elseif ($object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
960 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destockcancel&token='.newToken().'">'.$langs->trans("StockTransferDecrementationCancel").'</a>';
961 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstock&token='.newToken().'">'.$langs->trans("StockTransferIncrementation").'</a>';
962 } elseif ($object->status == $object::STATUS_CLOSED && $permissiontoadd) {
963 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstockcancel&token='.newToken().'">'.$langs->trans("StockTransferIncrementationCancel").'</a>';
964 }
965
966 // Clone
967 if ($permissiontoadd) {
968 print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=stocktransfer', 'clone', $permissiontoadd);
969 }
970
971 /*
972 if ($permissiontoadd)
973 {
974 if ($object->status == $object::STATUS_ENABLED)
975 {
976 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n";
977 }
978 else
979 {
980 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n";
981 }
982 }
983 if ($permissiontoadd)
984 {
985 if ($object->status == $object::STATUS_VALIDATED)
986 {
987 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close">'.$langs->trans("Cancel").'</a>'."\n";
988 }
989 else
990 {
991 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen">'.$langs->trans("Re-Open").'</a>'."\n";
992 }
993 }
994 */
995
996 // Delete
997 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
998 }
999 print '</div>'."\n";
1000 }
1001
1002
1003 // Select mail models is same action as presend
1004 if (GETPOST('modelselected')) {
1005 $action = 'presend';
1006 }
1007
1008 if ($action != 'presend') {
1009 print '<div class="fichecenter"><div class="fichehalfleft">';
1010 print '<a name="builddoc"></a>'; // ancre
1011
1012 $includedocgeneration = 1;
1013
1014 // Documents
1015 if ($includedocgeneration) {
1016 $objref = dol_sanitizeFileName($object->ref);
1017 $relativepath = $objref . '/' . $objref . '.pdf';
1018 $filedir = $conf->stocktransfer->dir_output.'/'.$object->element.'/'.$objref;
1019 $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
1020 $genallowed = $user->rights->stocktransfer->stocktransfer->read; // If you can read, you can build the PDF to read content
1021 $delallowed = $user->rights->stocktransfer->stocktransfer->write; // If you can create/edit, you can remove a file on card
1022 print $formfile->showdocuments('stocktransfer:StockTransfer', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1023 }
1024
1025 // Show links to link elements
1026 $linktoelem = $form->showLinkToObjectBlock($object, null, array('stocktransfer'));
1027 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1028
1029
1030 print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1031
1032 $MAXEVENT = 10;
1033
1034 $morehtmlright = '<a href="'.dol_buildpath('/product/stock/stocktransfer/stocktransfer_agenda.php', 1).'?id='.$object->id.'">';
1035 $morehtmlright .= $langs->trans("SeeAll");
1036 $morehtmlright .= '</a>';
1037
1038 // List of actions on element
1039 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1040 $formactions = new FormActions($db);
1041 $somethingshown = $formactions->showactions($object, 'stocktransfer', 0, 1, '', $MAXEVENT, '', $morehtmlright);
1042
1043 print '</div></div></div>';
1044 }
1045
1046 //Select mail models is same action as presend
1047 if (GETPOST('modelselected')) $action = 'presend';
1048
1049 // Presend form
1050 $modelmail = 'stocktransfer';
1051 $defaulttopic = 'InformationMessage';
1052 $diroutput = $conf->stocktransfer->dir_output;
1053 $trackid = 'stocktransfer'.$object->id;
1054
1055 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1056}
1057
1058// End of page
1059llxFooter();
1060$db->close();
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage warehouses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage products or services.
Class with list of lots and properties.
Class to manage projects.
Class for StockTransfer.
Class for StockTransferLine.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
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.
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)
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
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...
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
stocktransferPrepareHead($object)
Prepare array of tabs for StockTransfer.