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