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