dolibarr 24.0.3
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-2025 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"));
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
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->rights->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->rights->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 $line->update($user);
236 } else {
237 $line->rang = (is_array($object->lines) || $object->lines instanceof Countable) ? count($object->lines) + 1 : 1;
238 $line->create($user);
239 }
240 $object->fetchLines();
241 }
242 } elseif ($action === 'updateline' && $permissiontoadd && $object->status == $object::STATUS_DRAFT) {
243 $line = new StockTransferLine($db);
244 if ($line->fetch($lineid) <= 0 || $line->fk_stocktransfer != $object->id) {
245 $error++;
246 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
247 $action = '';
248 }
249
250 if ($qty <= 0) {
251 $error++;
252 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
253 $action = 'editline';
254 }
255
256 if ($fk_warehouse_source <= 0) {
257 $error++;
258 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
259 $action = 'editline';
260 }
261
262 if ($fk_warehouse_destination <= 0) {
263 $error++;
264 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
265 $action = 'editline';
266 }
267
268 $prod = new Product($db);
269 $prod->fetch($fk_product);
270 if ($prod->hasbatch()) {
271 if (empty($batch)) {
272 $error++;
273 $langs->load("errors");
274 setEventMessages($langs->transnoentities("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->getNomUrl()), null, 'errors');
275 $action = 'editline';
276 }
277 } else {
278 if (!empty($batch)) {
279 $error++;
280 setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), null, 'errors');
281 $action = 'editline';
282 }
283 }
284
285 if ($prod->status_batch == 2 && abs($qty) > 1) {
286 $error++;
287 setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref), null, 'errors');
288 $action = 'editline';
289 }
290
291 // A serial number can be only once in a transfer
292 if (!$error && $prod->status_batch == 2) {
293 foreach ($object->lines as $tmpline) {
294 if ($tmpline->id != $lineid && $tmpline->fk_product == $fk_product && dol_strtolower((string) $tmpline->batch) == dol_strtolower($batch)) {
295 $error++;
296 setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref, $batch), null, 'errors');
297 $action = 'editline';
298 break;
299 }
300 }
301 }
302
303 if (empty($error)) {
304 $line = new StockTransferLine($db);
305 $line->fetch($lineid);
306 $line->qty = $qty;
307 $line->fk_warehouse_source = $fk_warehouse_source;
308 $line->fk_warehouse_destination = $fk_warehouse_destination;
309 $line->fk_product = $fk_product;
310 $line->batch = $batch;
311 $line->pmp = $prod->pmp;
312 $line->update($user);
313 }
314 }
315
316 // Decrease
317 if ($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
318 $lines = $object->getLinesArray();
319 if (!empty($lines)) {
320 $db->begin();
321 foreach ($lines as $line) {
322 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source);
323 if ($res < 0) {
324 $error++;
325 setEventMessages($line->error, $line->errors, 'errors');
326 }
327 }
328 if (empty($error)) {
329 $db->commit();
330 } else {
331 $db->rollback();
332 }
333 }
334 if (empty($error)) {
335 $object->setStatut($object::STATUS_TRANSFERED, $id);
336 $object->status = $object::STATUS_TRANSFERED;
337 $object->date_reelle_depart = dol_now();
338 $object->update($user);
339 setEventMessage('StockStransferDecremented');
340 }
341 }
342
343 // Cancel Decrementation
344 if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
345 $lines = $object->getLinesArray();
346 if (!empty($lines)) {
347 $db->begin();
348 foreach ($lines as $line) {
349 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0);
350 if ($res <= 0) {
351 $error++;
352 setEventMessages($line->error, $line->errors, 'errors');
353 }
354 }
355 if (empty($error)) {
356 $db->commit();
357 } else {
358 $db->rollback();
359 }
360 }
361 if (empty($error)) {
362 $object->setStatut($object::STATUS_VALIDATED, $id);
363 $object->status = $object::STATUS_VALIDATED;
364 $object->date_reelle_depart = null;
365 $object->update($user);
366 setEventMessage('StockStransferDecrementedCancel', 'warnings');
367 }
368 }
369
370 // Incrementing
371 if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
372 $lines = $object->getLinesArray();
373 if (!empty($lines)) {
374 $db->begin();
375 foreach ($lines as $line) {
376 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0);
377 if ($res <= 0) {
378 $error++;
379 setEventMessages($line->error, $line->errors, 'errors');
380 }
381 }
382 if (empty($error)) {
383 $db->commit();
384 } else {
385 $db->rollback();
386 }
387 }
388 if (empty($error)) {
389 $object->setStatut($object::STATUS_CLOSED, $id);
390 $object->status = $object::STATUS_CLOSED;
391 $object->date_reelle_arrivee = dol_now();
392 $object->update($user);
393 $result = $object->call_trigger('STOCKTRANSFER_CLOSE', $user);
394 if ($result < 0) {
395 $error++;
396 setEventMessages($object->error, $object->errors, 'errors');
397 }
398 setEventMessage('StockStransferIncrementedShort');
399 }
400 }
401
402 // Cancel Incrementing
403 if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED && $permissiontoadd) {
404 $lines = $object->getLinesArray();
405 if (!empty($lines)) {
406 $db->begin();
407 foreach ($lines as $line) {
408 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination);
409 if ($res <= 0) {
410 $error++;
411 setEventMessages($line->error, $line->errors, 'errors');
412 }
413 }
414 if (empty($error)) {
415 $db->commit();
416 } else {
417 $db->rollback();
418 }
419 }
420 if (empty($error)) {
421 $object->setStatut($object::STATUS_TRANSFERED, $id);
422 $object->status = $object::STATUS_TRANSFERED;
423 $object->date_reelle_arrivee = null;
424 $object->update($user);
425 setEventMessage('StockStransferIncrementedShortCancel', 'warnings');
426 }
427 }
428
429 // Set incoterm
430 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
431 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
432 }
433 // Actions to send emails
434 $triggersendname = 'STOCKTRANSFER_SENTBYMAIL';
435 $autocopy = 'MAIN_MAIL_AUTOCOPY_STOCKTRANSFER_TO';
436 $trackid = 'stocktransfer'.$object->id;
437 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
438}
439
440
441
442
443/*
444 * View
445 */
446
447$form = new Form($db);
448$formfile = new FormFile($db);
449$formproject = new FormProjets($db);
450
451$title = $langs->trans("StockTransfer");
452$help_url = '';
453
454llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-stock-stocktransfer_stocktransfer_card');
455
456
457// Example: Adding jQuery code
458print '<script type="text/javascript" language="javascript">
459jQuery(document).ready(function() {';
460
461// Show alert for planned departure date if the transfer is related
462$date_prevue_depart = $object->date_prevue_depart;
463$date_prevue_depart_plus_delai = $date_prevue_depart;
464if ($object->lead_time_for_warning > 0) {
465 $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
466}
467if (!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) {
468 print "$('.valuefield.fieldname_date_prevue_depart').append('";
469 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
470 print "');";
471}
472
473print '});
474</script>';
475
476
477// Part to create
478if ($action == 'create') {
479 if (empty($permissiontoadd)) {
480 accessforbidden('NotEnoughPermissions', 0, 1);
481 }
482
483 print load_fiche_titre($title, '', 'object_'.$object->picto);
484
485 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
486 print '<input type="hidden" name="token" value="'.newToken().'">';
487 print '<input type="hidden" name="action" value="add">';
488 if ($backtopage) {
489 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
490 }
491 if ($backtopageforcancel) {
492 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
493 }
494
495 print dol_get_fiche_head(array(), '');
496
497
498 print '<table class="border centpercent tableforfieldcreate">'."\n";
499
500 // Common attributes
501 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
502
503 if (isModEnabled('incoterm')) {
504 $soc = new Societe($db);
505 if (!empty($object->fk_soc)) {
506 $soc->fetch($object->fk_soc);
507 }
508 print '<tr>';
509 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->label_incoterms, 1).'</label></td>';
510 print '<td class="maxwidthonsmartphone">';
511 print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''), '', 'fk_incoterms');
512 print '</td></tr>';
513 }
514 // Template to use by default
515 print '<tr><td>'.$langs->trans('DefaultModel').'</td>';
516 print '<td>';
517 print img_picto('', 'pdf', 'class="pictofixedwidth"');
518 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
520 $preselected = getDolGlobalString('STOCKTRANSFER_ADDON_PDF');
521 print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
522 print "</td></tr>";
523
524 // Other attributes
525 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
526
527 print '</table>'."\n";
528
529 print dol_get_fiche_end();
530
531 print $form->buttonsSaveCancel("Create");
532
533 print '</form>';
534
535 //dol_set_focus('input[name="ref"]');
536}
537
538// Part to edit record
539if (($id || $ref) && $action == 'edit') {
540 print load_fiche_titre($langs->trans("StockTransfer"), '', 'object_' . $object->picto);
541
542 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
543 print '<input type="hidden" name="token" value="' . newToken() . '">';
544 print '<input type="hidden" name="action" value="update">';
545 print '<input type="hidden" name="id" value="' . $object->id . '">';
546 if ($backtopage) {
547 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
548 }
549 if ($backtopageforcancel) {
550 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
551 }
552
553 print dol_get_fiche_head();
554
555 print '<table class="border centpercent tableforfieldedit">' . "\n";
556
557 // Common attributes
558 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
559
560 // Other attributes
561 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
562
563 print '</table>';
564
565 print dol_get_fiche_end();
566
567 print $form->buttonsSaveCancel();
568
569 print '</form>';
570}
571
572// Part to show record
573if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
574 $res = $object->fetch_optionals();
575
576 $head = stocktransferPrepareHead($object);
577
578 print dol_get_fiche_head($head, 'card', $langs->trans("StockTransfer"), -1, $object->picto);
579
580 $formconfirm = '';
581
582 // Confirmation to delete (using preloaded confirm popup)
583 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
584 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 'action-delete');
585 }
586 // Confirmation to delete line
587 if ($action == 'deleteline') {
588 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
589 }
590 $formquestion = array();
591 // Clone confirmation
592 if ($action == 'clone') {
593 // Create an array for form
594 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
595 } elseif ($action == 'destock') { // Destock confirmation
596 // Create an array for form
597 $formquestion = array( 'text' => '',
598 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestock', $object->ref), 'morecss' => 'minwidth300'),
599 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'morecss' => 'minwidth200')
600 );
601 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProduct'), '', 'confirm_destock', $formquestion, 'yes', 1);
602 } elseif ($action == 'destockcancel') { // Destock confirmation cancel
603 // Create an array for form
604 $formquestion = array( 'text' => '',
605 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestockCancel', $object->ref), 'morecss' => 'minwidth300'),
606 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'morecss' => 'minwidth200')
607 );
608 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProductCancel'), '', 'confirm_destockcancel', $formquestion, 'yes', 1);
609 } elseif ($action == 'addstock') { // Addstock confirmation
610 // Create an array for form
611 $formquestion = array( 'text' => '',
612 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStock', $object->ref), 'morecss' => 'minwidth300'),
613 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'morecss' => 'minwidth200')
614 );
615 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProduct'), '', 'confirm_addstock', $formquestion, 'yes', 1);
616 } elseif ($action == 'addstockcancel') { // Addstock confirmation cancel
617 // Create an array for form
618 $formquestion = array( 'text' => '',
619 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStockCancel', $object->ref), 'morecss' => 'minwidth300'),
620 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'morecss' => 'minwidth200')
621 );
622 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProductCancel'), '', 'confirm_addstockcancel', $formquestion, 'yes', 1);
623 }
624
625 if ($action == 'valid' && $permissiontoadd) {
626 $nextref = $object->getNextNumRef();
627 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $langs->transnoentities('ConfirmValidateStockTransfer', $nextref), 'confirm_validate', $formquestion, 0, 2);
628 }
629
630 // Call Hook formConfirm
631 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
632 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
633 if (empty($reshook)) {
634 $formconfirm .= $hookmanager->resPrint;
635 } elseif ($reshook > 0) {
636 $formconfirm = $hookmanager->resPrint;
637 }
638
639 // Print form confirm
640 print $formconfirm;
641
642
643 // Object card
644 // ------------------------------------------------------------
645 $linkback = '<a href="'.dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
646
647 $morehtmlref = '<div class="refidno">';
648 // Thirdparty
649 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
650 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && !empty($object->thirdparty) && $object->thirdparty->id > 0) {
651 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherOrders").'</a>)';
652 }
653 // Project
654 if (isModEnabled('project')) {
655 $langs->load("projects");
656 $morehtmlref .= (empty($object->thirdparty) ? '' : '<br>');
657 if ($permissiontoadd) {
658 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
659 if ($action != 'classify') {
660 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
661 }
662 $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');
663 } else {
664 if (!empty($object->fk_project)) {
665 $proj = new Project($db);
666 $proj->fetch($object->fk_project);
667 $morehtmlref .= $proj->getNomUrl(1);
668 if ($proj->title) {
669 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
670 }
671 }
672 }
673 }
674 $morehtmlref .= '</div>';
675
676
677 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
678
679
680 print '<div class="fichecenter">';
681 print '<div class="fichehalfleft">';
682 print '<div class="underbanner clearboth"></div>';
683 print '<table class="border centpercent tableforfield">'."\n";
684
685 // Common attributes
686 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
687 //unset($object->fields['fk_project']); // Hide field already shown in banner
688 //unset($object->fields['fk_soc']); // Hide field already shown in banner
689
690 $object->fields['fk_soc']['visible'] = 0; // Already available in banner
691 $object->fields['fk_project']['visible'] = 0; // Already available in banner
692 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
693
694 // Incoterms
695 if (isModEnabled('incoterm')) {
696 print '<tr><td>';
697 print '<table width="100%" class="nobordernopadding"><tr><td>';
698 print $langs->trans('IncotermLabel');
699 print '<td><td class="right">';
700 if ($permissiontoadd && $action != 'editincoterm') {
701 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
702 } else {
703 print '&nbsp;';
704 }
705 print '</td></tr></table>';
706 print '</td>';
707 print '<td>';
708 if ($action != 'editincoterm') {
709 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
710 } else {
711 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
712 }
713 print '</td></tr>';
714 }
715
716 echo '<tr>';
717 echo '<td>'.$langs->trans('EnhancedValue').'&nbsp;'.strtolower($langs->trans('TotalWoman'));
718 echo '<td>'.price($object->getValorisationTotale(), 0, '', 1, -1, -1, $conf->currency).'</td>';
719 echo '</tr>';
720
721 // Other attributes. Fields from hook formObjectOptions and Extrafields.
722 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
723
724 print '</table>';
725 print '</div>';
726 print '</div>';
727
728 print '<div class="clearboth"></div>';
729
730
731
732 /*
733 * Lines
734 */
735
736 if (!empty($object->table_element_line)) {
737 // Show object lines
738 /*
739 $result = $object->getLinesArray();
740
741 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
742 <input type="hidden" name="token" value="' . newToken().'">
743 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
744 <input type="hidden" name="mode" value="">
745 <input type="hidden" name="page_y" value="">
746 <input type="hidden" name="id" value="' . $object->id.'">
747 ';
748 */
749
750 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
751 $fk_element = $object->id;
752 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
753 }
754
755 /*
756 print '<div class="div-table-responsive-no-min">';
757 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
758 print '<table id="tablelines" class="noborder noshadow" width="100%">';
759 }
760
761 if (!empty($object->lines)) {
762 $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
763 }
764
765 // Form to add new line
766 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
767 if ($action != 'editline') {
768 // Add products/services form
769
770 $parameters = array();
771 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
772 if ($reshook < 0) {
773 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
774 }
775 if (empty($reshook)) {
776 $object->formAddObjectLine(1, $mysoc, $soc);
777 }
778 }
779 }
780
781 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
782 print '</table>';
783 }
784 print '</div>';
785
786 print "</form>\n";
787 */
788 }
789
790
791 $formproduct = new FormProduct($db);
792 print '<div class="div-table-responsive-no-min">';
793 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
794 <input type="hidden" name="token" value="' . newToken().'">
795 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
796 <input type="hidden" name="mode" value="">
797 <input type="hidden" name="id" value="' . $object->id.'">
798 ';
799 if ($lineid > 0) {
800 print '<input type="hidden" name="lineid" value="'.$lineid.'" />';
801 }
802 print '<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
803 //print '<div class="tagtable centpercent">';
804
805 $param = '';
806
807 print '<tr class="liste_titre">';
808 print getTitleFieldOfList($langs->trans('ProductRef'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
809 if (isModEnabled('productbatch')) {
810 print getTitleFieldOfList($langs->trans('Batch'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
811 }
812 print getTitleFieldOfList($langs->trans('WarehouseSource'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
813 print getTitleFieldOfList($langs->trans('WarehouseTarget'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
814 print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
815 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
816 print getTitleFieldOfList($langs->trans('Unit'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
817 }
818 print getTitleFieldOfList($langs->trans('AverageUnitPricePMPShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
819 print getTitleFieldOfList($langs->trans('EstimatedStockValueShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
820 if (empty($object->status) && $permissiontoadd) {
821 print getTitleFieldOfList('', 0);
822 print getTitleFieldOfList('', 0);
823 print getTitleFieldOfList('', 0);
824 }
825
826 print '</tr>';
827
828 $listofdata = $object->getLinesArray();
829 $productstatic = new Product($db);
830 $warehousestatics = new Entrepot($db);
831 $warehousestatict = new Entrepot($db);
832 $i = 0;
833
834 foreach ($listofdata as $key => $line) {
835 $productstatic->fetch($line->fk_product);
836 $warehousestatics->fetch($line->fk_warehouse_source);
837 $warehousestatict->fetch($line->fk_warehouse_destination);
838
839 // add html5 elements
840 $domData = ' data-element="'.$line->element.'"';
841 $domData .= ' data-id="'.$line->id.'"';
842 $domData .= ' data-qty="'.$line->qty.'"';
843 //$domData .= ' data-product_type="'.$line->product_type.'"';
844
845 print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.'>';
846 print '<td class="titlefield">';
847 if ($action === 'editline' && $line->id == $lineid) {
848 $form->select_produits($line->fk_product, 'fk_product', '', 0, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
849 } else {
850 print $productstatic->getNomUrl(1).' - '.$productstatic->label;
851 }
852 print '</td>';
853 if (isModEnabled('productbatch')) {
854 print '<td>';
855 if ($action === 'editline' && $line->id == $lineid) {
856 print '<input type="text" value="'.$line->batch.'" name="batch" class="flat maxwidth50"/>';
857 } else {
858 $productlot = new Productlot($db);
859 if ($productlot->fetch(0, $line->fk_product, $line->batch) > 0) {
860 print $productlot->getNomUrl(1);
861 } elseif (!empty($line->batch)) {
862 print $line->batch.'&nbsp;'.img_warning($langs->trans('BatchNotFound'));
863 }
864 }
865 print '</td>';
866 }
867
868 // Warehouse source
869 print '<td class="tdoverflowmax150">';
870 if ($action === 'editline' && $line->id == $lineid) {
871 print $formproduct->selectWarehouses($line->fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
872 } else {
873 print $warehousestatics->getNomUrl(1);
874 }
875 print '</td>';
876
877 // Warehouse target
878 print '<td class="tdoverflowmax150">';
879 if ($action === 'editline' && $line->id == $lineid) {
880 print $formproduct->selectWarehouses($line->fk_warehouse_destination, 'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
881 } else {
882 print $warehousestatict->getNomUrl(1);
883 }
884 print '</td>';
885
886 if ($action === 'editline' && $line->id == $lineid) {
887 print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" value="'.$line->qty.'"></td>';
888 } else {
889 print '<td class="center">'.$line->qty.'</td>';
890 }
891
892 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
893 print '<td class="linecoluseunit nowrap left">';
894 $label = $productstatic->getLabelOfUnit('short');
895 print $label;
896 print '</td>';
897 }
898
899 print '<td class="center">';
900 print price($line->pmp, 0, '', 1, -1, -1, $conf->currency);
901 print '</td>';
902
903 print '<td class="center">';
904 print price($line->pmp * $line->qty, 0, '', 1, -1, -1, $conf->currency);
905 print '</td>';
906
907 if (empty($object->status) && $permissiontoadd) {
908 if ($action === 'editline' && $line->id == $lineid) {
909 //print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Save')) . '"></td>';
910 print '<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
911 print '<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
912 } else {
913 print '<td class="right">';
914 print '<a class="editfielda reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;token='.newToken().'&amp;lineid=' . $line->id . '#line_' . $line->id . '">';
915 print img_edit() . '</a>';
916 print '</td>';
917 print '<td class="right">';
918 // Ensure the delete line link embeds a CSRF token.
919 $deleteLineUrl = $_SERVER["PHP_SELF"] . '?id=' . $id . '&action=deleteline&lineid=' . $line->id . '&token=' . newToken();
920 print '<a href="' . $deleteLineUrl . '">' . img_delete($langs->trans("Remove")) . '</a>';
921 print '</td>';
922 }
923
924 $num = count($object->lines);
925
926 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
927 print '<td class="linecolmove tdlineupdown center">';
928 if ($i > 0) { ?>
929 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=up&amp;token='.newToken().'&amp;rowid='.$line->id; ?>">
930 <?php print img_up('default', 0, 'imgupforline'); ?>
931 </a>
932 <?php }
933 if ($i < $num - 1) { ?>
934 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=down&amp;token='.newToken().'&amp;rowid='.$line->id; ?>">
935 <?php print img_down('default', 0, 'imgdownforline'); ?>
936 </a>
937 <?php }
938 print '</td>';
939 } else {
940 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
941 }
942 }
943
944 $i ++;
945 print '</tr>';
946 }
947
948 // Line to add a new line
949 if (empty($object->status) && $action !== 'editline' && $permissiontoadd) {
950 print '<tr class="oddeven">';
951 // Product
952 print '<td class="titlefield">';
953 $filtertype = 0;
954 if (getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
955 $filtertype = '';
956 }
957 if (getDolGlobalInt('PRODUIT_LIMIT_SIZE') <= 0) {
958 $limit = 0;
959 } else {
960 $limit = getDolGlobalInt('PRODUIT_LIMIT_SIZE');
961 }
962
963 $form->select_produits($fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
964 print '</td>';
965 // Batch number
966 if (isModEnabled('productbatch')) {
967 print '<td>';
968 print '<input type="text" name="batch" class="flat maxwidth50" '.(!empty($error) ? 'value="'.$batch.'"' : '').'>';
969 print '</td>';
970 }
971
972 $formproduct->loadWarehouses(); // To load all warehouses
973
974 // Define a list of warehouses to exclude from the selection
975 $TExcludedWarehouseSource = array();
976 if (!empty($object->fk_warehouse_source)) {
977 $source_ent = new Entrepot($db);
978 $source_ent->fetch($object->fk_warehouse_source);
979 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
980 if (strpos($TDataCacheWarehouse['full_label'], $source_ent->label) === false) {
981 $TExcludedWarehouseSource[] = $TDataCacheWarehouse['id'];
982 }
983 }
984 }
985
986 // Define a list of warehouses to exclude from the selection
987 $TExcludedWarehouseDestination = array();
988 if (!empty($object->fk_warehouse_destination)) {
989 $dest_ent = new Entrepot($db);
990 $dest_ent->fetch($object->fk_warehouse_destination);
991 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
992 if (strpos($TDataCacheWarehouse['full_label'], $dest_ent->label) === false) {
993 $TExcludedWarehouseDestination[] = $TDataCacheWarehouse['id'];
994 }
995 }
996 }
997
998 // We clean array. It is filled automatically when calling function select_warehouses
999 $formproduct->cache_warehouses = array();
1000 // In warehouse
1001 print '<td>';
1002 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);
1003 print '</td>';
1004
1005 // We clean array. It is filled automatically when calling function select_warehouses
1006 $formproduct->cache_warehouses = array();
1007 // Out warehouse
1008 print '<td>';
1009 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);
1010 print '</td>';
1011
1012 // Qty
1013 print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" '.(!empty($error) ? 'value="'.(GETPOSTISSET('qty') ? GETPOST('qty') : $qty).'"' : '').'></td>';
1014
1015 // PMP
1016 print '<td></td>';
1017 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1018 // Unit
1019 print '<td></td>';
1020 }
1021
1022 // PMP * Qty
1023 print '<td></td>';
1024
1025 // Button to add line
1026 print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Add')) . '"></td>';
1027
1028 // Grad and drop lines
1029 print '<td></td>';
1030
1031 print '</tr>';
1032 }
1033
1034 print '</table>';
1035 print '</form>';
1036 print '</div>';
1037
1038 print dol_get_fiche_end();
1039
1040
1041 // Buttons for actions
1042
1043 if ($action != 'presend' && $action != 'editline') {
1044 print '<div class="tabsAction">'."\n";
1045 $parameters = array();
1046 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1047 if ($reshook < 0) {
1048 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1049 }
1050
1051 if (empty($reshook)) {
1052 // Send
1053 if (empty($user->socid)) {
1054 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
1055 }
1056
1057 // Back to draft
1058 if ($object->status == $object::STATUS_VALIDATED) {
1059 print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
1060 }
1061
1062 // Modify
1063 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
1064
1065 // Validate
1066 if ($object->status == $object::STATUS_DRAFT) {
1067 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
1068 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
1069 } else {
1070 $langs->load("errors");
1071 print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
1072 }
1073 } elseif ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
1074 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destock&token='.newToken().'">'.$langs->trans("StockTransferDecrementation").'</a>';
1075 } elseif ($object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
1076 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destockcancel&token='.newToken().'">'.$langs->trans("StockTransferDecrementationCancel").'</a>';
1077 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstock&token='.newToken().'">'.$langs->trans("StockTransferIncrementation").'</a>';
1078 } elseif ($object->status == $object::STATUS_CLOSED && $permissiontoadd) {
1079 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstockcancel&token='.newToken().'">'.$langs->trans("StockTransferIncrementationCancel").'</a>';
1080 }
1081
1082 // Clone
1083 if ($permissiontoadd) {
1084 print dolGetButtonAction('', $langs->trans('ToClone'), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
1085 }
1086
1087 /*
1088 if ($permissiontoadd) {
1089 if ($object->status == $object::STATUS_ENABLED) {
1090 print dolGetButtonAction('', $langs->trans('Disable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
1091 } else {
1092 print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
1093 }
1094 }
1095 if ($permissiontoadd) {
1096 if ($object->status == $object::STATUS_VALIDATED) {
1097 print dolGetButtonAction('', $langs->trans('Cancel'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
1098 } else {
1099 print dolGetButtonAction('', $langs->trans('Re-Open'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
1100 }
1101 }
1102
1103 */
1104
1105 // Delete (with preloaded confirm popup)
1106 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
1107 $buttonId = 'action-delete-no-ajax';
1108 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can use preloaded confirm if not jmobile
1109 $deleteUrl = '';
1110 $buttonId = 'action-delete';
1111 }
1112 $params = array();
1113 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete, $params);
1114 }
1115 print '</div>'."\n";
1116 }
1117
1118
1119 // Select mail models is same action as presend
1120 if (GETPOST('modelselected')) {
1121 $action = 'presend';
1122 }
1123
1124 if ($action != 'presend') {
1125 print '<div class="fichecenter"><div class="fichehalfleft">';
1126 print '<a name="builddoc"></a>'; // ancre
1127
1128 $includedocgeneration = 1;
1129
1130 // Documents
1131 if ($includedocgeneration) {
1132 $objref = dol_sanitizeFileName($object->ref);
1133 $relativepath = $objref . '/' . $objref . '.pdf';
1134 $filedir = $conf->stocktransfer->dir_output.'/'.$object->element.'/'.$objref;
1135 $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
1136 $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1137 $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1138 print $formfile->showdocuments('stocktransfer:StockTransfer', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1139 }
1140
1141 // Show links to link elements
1142 $tmparray = $form->showLinkToObjectBlock($object, array(), array('stocktransfer'), 1);
1143 $linktoelem = $tmparray['linktoelem'];
1144 $htmltoenteralink = $tmparray['htmltoenteralink'];
1145 print $htmltoenteralink;
1146
1147 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1148
1149
1150 print '</div><div class="fichehalfright">';
1151
1152 $MAXEVENT = 10;
1153
1154 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1155
1156 // List of actions on element
1157 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1158 $formactions = new FormActions($db);
1159 $somethingshown = $formactions->showactions($object, 'stocktransfer', 0, 1, '', $MAXEVENT, '');
1160
1161 print '</div></div>';
1162 }
1163
1164 //Select mail models is same action as presend
1165 if (GETPOST('modelselected')) {
1166 $action = 'presend';
1167 }
1168
1169 // Presend form
1170 $modelmail = 'stocktransfer_send';
1171 $defaulttopic = 'InformationMessage';
1172 $diroutput = $conf->stocktransfer->dir_output.'/'.$object->element;
1173 $trackid = 'stocktransfer'.$object->id;
1174
1175 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1176}
1177
1178// End of page
1179llxFooter();
1180$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
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
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.
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.
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).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
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.