dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransferline.class.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/modules/stocktransfer/modules_stocktransfer.php';
38
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
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->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
111//if ($user->socid > 0) accessforbidden();
112//if ($user->socid > 0) $socid = $user->socid;
113//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
114//$result = restrictedArea($user, 'stocktransfer', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
115
116if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
118}
119
120
121/*
122 * Actions
123 */
124
125$parameters = array();
126$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
127if ($reshook < 0) {
128 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
129}
130
131if (empty($reshook)) {
132 $error = 0;
133
134 $backurlforlist = dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1);
135
136 if (empty($backtopage) || ($cancel && empty($id))) {
137 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
138 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
139 $backtopage = $backurlforlist;
140 } else {
141 $backtopage = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
142 }
143 }
144 }
145
146 $triggermodname = 'STOCKTRANSFER_STOCKTRANSFER_MODIFY'; // Name of trigger action code to execute when we modify record
147
148 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
149 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
150
151 // On remet cette lecture de permission ici car nécessaire d'avoir le nouveau statut de l'objet après toute action exécutée dessus (après incrémentation par example, le bouton supprimer doit disparaître)
152 $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
153
154 // Actions when linking object each other
155 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
156
157 // Actions when printing a doc from card
158 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
159
160 // Action to move up and down lines of object
161 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
162
163 // Action to build doc
164 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
165
166 if ($action == 'set_thirdparty' && $permissiontoadd) {
167 $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname);
168 }
169 if ($action == 'classin' && $permissiontoadd) {
170 $object->setProject(GETPOSTINT('projectid'));
171 }
172
173 if ($action == 'addline' && $permissiontoadd && $object->status == $object::STATUS_DRAFT) {
174 if ($qty <= 0) {
175 $error++;
176 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
177 $action = 'view';
178 }
179
180 if ($fk_warehouse_source <= 0) {
181 $error++;
182 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
183 $action = 'view';
184 }
185
186 if ($fk_warehouse_destination <= 0) {
187 $error++;
188 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
189 $action = 'view';
190 }
191
192 $prod = new Product($db);
193 $prod->fetch($fk_product);
194 if ($prod->hasbatch()) {
195 if (empty($batch)) {
196 $error++;
197 $langs->load("errors");
198 setEventMessages($langs->transnoentities("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors');
199 }
200 } else {
201 if (!empty($batch)) {
202 $error++;
203 setEventMessages($langs->transnoentities('StockTransferNoBatchForProduct', $prod->getNomUrl()), null, 'errors');
204 }
205 }
206
207 if ($prod->status_batch == 2 && abs($qty) > 1) {
208 $error++;
209 setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref), null, 'errors');
210 }
211
212 // 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)
213 if (!$error && $prod->status_batch == 2) {
214 foreach ($object->lines as $tmpline) {
215 if ($tmpline->fk_product == $fk_product && dol_strtolower((string) $tmpline->batch) == dol_strtolower($batch)) {
216 $error++;
217 setEventMessages($langs->transnoentities('TooManyQtyForSerialNumber', $prod->ref, $batch), null, 'errors');
218 break;
219 }
220 }
221 }
222
223 if (empty($error)) {
224 $line = new StockTransferLine($db);
225 $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)."'").')');
226 if (!empty($records[key($records)])) {
227 $line = $records[key($records)];
228 }
229 $line->fk_stocktransfer = $id;
230 $line->qty += $qty;
231 $line->fk_warehouse_source = $fk_warehouse_source;
232 $line->fk_warehouse_destination = $fk_warehouse_destination;
233 $line->fk_product = $fk_product;
234 $line->batch = $batch;
235
236 $line->pmp = $prod->pmp;
237 if ($line->id > 0) {
238 $line->update($user);
239 } else {
240 $line->rang = (is_array($object->lines) || $object->lines instanceof Countable) ? count($object->lines) + 1 : 1;
241 $line->create($user);
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 $object->update($user);
342 setEventMessage('StockStransferDecremented');
343 }
344 }
345
346 // Annulation décrémentation
347 if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
348 $lines = $object->getLinesArray();
349 if (!empty($lines)) {
350 $db->begin();
351 foreach ($lines as $line) {
352 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0);
353 if ($res <= 0) {
354 $error++;
355 setEventMessages($line->error, $line->errors, 'errors');
356 }
357 }
358 if (empty($error)) {
359 $db->commit();
360 } else {
361 $db->rollback();
362 }
363 }
364 if (empty($error)) {
365 $object->setStatut($object::STATUS_VALIDATED, $id);
366 $object->status = $object::STATUS_VALIDATED;
367 $object->date_reelle_depart = null;
368 $object->update($user);
369 setEventMessage('StockStransferDecrementedCancel', 'warnings');
370 }
371 }
372
373 // Incrémentation
374 if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
375 $lines = $object->getLinesArray();
376 if (!empty($lines)) {
377 $db->begin();
378 foreach ($lines as $line) {
379 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0);
380 if ($res <= 0) {
381 $error++;
382 setEventMessages($line->error, $line->errors, 'errors');
383 }
384 }
385 if (empty($error)) {
386 $db->commit();
387 } else {
388 $db->rollback();
389 }
390 }
391 if (empty($error)) {
392 $object->setStatut($object::STATUS_CLOSED, $id);
393 $object->status = $object::STATUS_CLOSED;
394 $object->date_reelle_arrivee = dol_now();
395 $object->update($user);
396 setEventMessage('StockStransferIncrementedShort');
397 }
398 }
399
400 // Annulation incrémentation
401 if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED && $permissiontoadd) {
402 $lines = $object->getLinesArray();
403 if (!empty($lines)) {
404 $db->begin();
405 foreach ($lines as $line) {
406 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination);
407 if ($res <= 0) {
408 $error++;
409 setEventMessages($line->error, $line->errors, 'errors');
410 }
411 }
412 if (empty($error)) {
413 $db->commit();
414 } else {
415 $db->rollback();
416 }
417 }
418 if (empty($error)) {
419 $object->setStatut($object::STATUS_TRANSFERED, $id);
420 $object->status = $object::STATUS_TRANSFERED;
421 $object->date_reelle_arrivee = null;
422 $object->update($user);
423 setEventMessage('StockStransferIncrementedShortCancel', 'warnings');
424 }
425 }
426
427 // Set incoterm
428 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
429 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
430 }
431 // Actions to send emails
432 $triggersendname = 'STOCKTRANSFER_SENTBYMAIL';
433 $autocopy = 'MAIN_MAIL_AUTOCOPY_STOCKTRANSFER_TO';
434 $trackid = 'stocktransfer'.$object->id;
435 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
436}
437
438
439
440
441/*
442 * View
443 */
444
445$form = new Form($db);
446$formfile = new FormFile($db);
447$formproject = new FormProjets($db);
448
449$title = $langs->trans("StockTransfer");
450$help_url = '';
451
452llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-stock-stocktransfer_stocktransfer_card');
453
454
455
456// Example : Adding jquery code
457print '<script type="text/javascript" language="javascript">
458jQuery(document).ready(function() {';
459
460// Show alert for planned departure date if the transfer is related
461$date_prevue_depart = $object->date_prevue_depart;
462$date_prevue_depart_plus_delai = $date_prevue_depart;
463if ($object->lead_time_for_warning > 0) {
464 $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
465}
466if (!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) {
467 print "$('.valuefield.fieldname_date_prevue_depart').append('";
468 print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
469 print "');";
470}
471
472print '});
473</script>';
474
475
476// Part to create
477if ($action == 'create') {
478 if (empty($permissiontoadd)) {
479 accessforbidden('NotEnoughPermissions', 0, 1);
480 }
481
482 print load_fiche_titre($title, '', 'object_'.$object->picto);
483
484 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
485 print '<input type="hidden" name="token" value="'.newToken().'">';
486 print '<input type="hidden" name="action" value="add">';
487 if ($backtopage) {
488 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
489 }
490 if ($backtopageforcancel) {
491 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
492 }
493
494 print dol_get_fiche_head(array(), '');
495
496
497 print '<table class="border centpercent tableforfieldcreate">'."\n";
498
499 // Common attributes
500 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
501
502 if (isModEnabled('incoterm')) {
503 $soc = new Societe($db);
504 if (!empty($object->fk_soc)) {
505 $soc->fetch($object->fk_soc);
506 }
507 print '<tr>';
508 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->label_incoterms, 1).'</label></td>';
509 print '<td class="maxwidthonsmartphone">';
510 print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''), '', 'fk_incoterms');
511 print '</td></tr>';
512 }
513 // Template to use by default
514 print '<tr><td>'.$langs->trans('DefaultModel').'</td>';
515 print '<td>';
516 print img_picto('', 'pdf', 'class="pictofixedwidth"');
517 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
519 $preselected = getDolGlobalString('STOCKTRANSFER_ADDON_PDF');
520 print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
521 print "</td></tr>";
522
523 // Other attributes
524 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
525
526 print '</table>'."\n";
527
528 print dol_get_fiche_end();
529
530 print $form->buttonsSaveCancel("Create");
531
532 print '</form>';
533
534 //dol_set_focus('input[name="ref"]');
535}
536
537// Part to edit record
538if (($id || $ref) && $action == 'edit') {
539 print load_fiche_titre($langs->trans("StockTransfer"), '', 'object_' . $object->picto);
540
541 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
542 print '<input type="hidden" name="token" value="' . newToken() . '">';
543 print '<input type="hidden" name="action" value="update">';
544 print '<input type="hidden" name="id" value="' . $object->id . '">';
545 if ($backtopage) {
546 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
547 }
548 if ($backtopageforcancel) {
549 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
550 }
551
552 print dol_get_fiche_head();
553
554 print '<table class="border centpercent tableforfieldedit">' . "\n";
555
556 // Common attributes
557 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
558
559 // Other attributes
560 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
561
562 print '</table>';
563
564 print dol_get_fiche_end();
565
566 print $form->buttonsSaveCancel();
567
568 print '</form>';
569}
570
571// Part to show record
572if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
573 $res = $object->fetch_optionals();
574
575 $head = stocktransferPrepareHead($object);
576
577 print dol_get_fiche_head($head, 'card', $langs->trans("StockTransfer"), -1, $object->picto);
578
579 $formconfirm = '';
580
581 // Confirmation to delete (using preloaded confirm popup)
582 if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
583 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 'action-delete');
584 }
585 // Confirmation to delete line
586 if ($action == 'deleteline') {
587 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
588 }
589 $formquestion = array();
590 // Clone confirmation
591 if ($action == 'clone') {
592 // Create an array for form
593 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
594 } elseif ($action == 'destock') { // Destock confirmation
595 // Create an array for form
596 $formquestion = array( 'text' => '',
597 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestock', $object->ref), 'size' => 40),
598 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size' => 25)
599 );
600 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProduct'), '', 'confirm_destock', $formquestion, 'yes', 1);
601 } elseif ($action == 'destockcancel') { // Destock confirmation cancel
602 // Create an array for form
603 $formquestion = array( 'text' => '',
604 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label"), 'value' => $langs->trans('ConfirmDestockCancel', $object->ref), 'size' => 40),
605 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size' => 25)
606 );
607 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DestockAllProductCancel'), '', 'confirm_destockcancel', $formquestion, 'yes', 1);
608 } elseif ($action == 'addstock') { // Addstock confirmation
609 // Create an array for form
610 $formquestion = array( 'text' => '',
611 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStock', $object->ref), 'size' => 40),
612 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size' => 25)
613 );
614 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProduct'), '', 'confirm_addstock', $formquestion, 'yes', 1);
615 } elseif ($action == 'addstockcancel') { // Addstock confirmation cancel
616 // Create an array for form
617 $formquestion = array( 'text' => '',
618 0 => array('type' => 'text', 'name' => 'label', 'label' => $langs->trans("Label").'&nbsp;:', 'value' => $langs->trans('ConfirmAddStockCancel', $object->ref), 'size' => 40),
619 1 => array('type' => 'text', 'name' => 'inventorycode', 'label' => $langs->trans("InventoryCode"), 'value' => dol_print_date(dol_now(), '%y%m%d%H%M%S'), 'size' => 25)
620 );
621 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('AddStockAllProductCancel'), '', 'confirm_addstockcancel', $formquestion, 'yes', 1);
622 }
623
624 if ($action == 'valid' && $permissiontoadd) {
625 $nextref = $object->getNextNumRef();
626 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $langs->transnoentities('ConfirmValidateStockTransfer', $nextref), 'confirm_validate', $formquestion, 0, 2);
627 }
628
629 // Call Hook formConfirm
630 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
631 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
632 if (empty($reshook)) {
633 $formconfirm .= $hookmanager->resPrint;
634 } elseif ($reshook > 0) {
635 $formconfirm = $hookmanager->resPrint;
636 }
637
638 // Print form confirm
639 print $formconfirm;
640
641
642 // Object card
643 // ------------------------------------------------------------
644 $linkback = '<a href="'.dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
645
646 $morehtmlref = '<div class="refidno">';
647 // Thirdparty
648 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
649 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && !empty($object->thirdparty) && $object->thirdparty->id > 0) {
650 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherOrders").'</a>)';
651 }
652 // Project
653 if (isModEnabled('project')) {
654 $langs->load("projects");
655 $morehtmlref .= (empty($object->thirdparty) ? '' : '<br>');
656 if ($permissiontoadd) {
657 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
658 if ($action != 'classify') {
659 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
660 }
661 $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');
662 } else {
663 if (!empty($object->fk_project)) {
664 $proj = new Project($db);
665 $proj->fetch($object->fk_project);
666 $morehtmlref .= $proj->getNomUrl(1);
667 if ($proj->title) {
668 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
669 }
670 }
671 }
672 }
673 $morehtmlref .= '</div>';
674
675
676 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
677
678
679 print '<div class="fichecenter">';
680 print '<div class="fichehalfleft">';
681 print '<div class="underbanner clearboth"></div>';
682 print '<table class="border centpercent tableforfield">'."\n";
683
684 // Common attributes
685 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
686 //unset($object->fields['fk_project']); // Hide field already shown in banner
687 //unset($object->fields['fk_soc']); // Hide field already shown in banner
688
689 $object->fields['fk_soc']['visible'] = 0; // Already available in banner
690 $object->fields['fk_project']['visible'] = 0; // Already available in banner
691 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
692
693 // Incoterms
694 if (isModEnabled('incoterm')) {
695 print '<tr><td>';
696 print '<table width="100%" class="nobordernopadding"><tr><td>';
697 print $langs->trans('IncotermLabel');
698 print '<td><td class="right">';
699 if ($permissiontoadd && $action != 'editincoterm') {
700 print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
701 } else {
702 print '&nbsp;';
703 }
704 print '</td></tr></table>';
705 print '</td>';
706 print '<td>';
707 if ($action != 'editincoterm') {
708 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
709 } else {
710 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
711 }
712 print '</td></tr>';
713 }
714
715 echo '<tr>';
716 echo '<td>'.$langs->trans('EnhancedValue').'&nbsp;'.strtolower($langs->trans('TotalWoman'));
717 echo '<td>'.price($object->getValorisationTotale(), 0, '', 1, -1, -1, $conf->currency).'</td>';
718 echo '</tr>';
719
720 // Other attributes. Fields from hook formObjectOptions and Extrafields.
721 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
722
723 print '</table>';
724 print '</div>';
725 print '</div>';
726
727 print '<div class="clearboth"></div>';
728
729 print dol_get_fiche_end();
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="liste centpercent">';
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
833 foreach ($listofdata as $key => $line) {
834 $productstatic->fetch($line->fk_product);
835 $warehousestatics->fetch($line->fk_warehouse_source);
836 $warehousestatict->fetch($line->fk_warehouse_destination);
837
838 // add html5 elements
839 $domData = ' data-element="'.$line->element.'"';
840 $domData .= ' data-id="'.$line->id.'"';
841 $domData .= ' data-qty="'.$line->qty.'"';
842 //$domData .= ' data-product_type="'.$line->product_type.'"';
843
844 print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.'>';
845 print '<td class="titlefield">';
846 if ($action === 'editline' && $line->id == $lineid) {
847 $form->select_produits($line->fk_product, 'fk_product', '', 0, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
848 } else {
849 print $productstatic->getNomUrl(1).' - '.$productstatic->label;
850 }
851 print '</td>';
852 if (isModEnabled('productbatch')) {
853 print '<td>';
854 if ($action === 'editline' && $line->id == $lineid) {
855 print '<input type="text" value="'.$line->batch.'" name="batch" class="flat maxwidth50"/>';
856 } else {
857 $productlot = new Productlot($db);
858 if ($productlot->fetch(0, $line->fk_product, $line->batch) > 0) {
859 print $productlot->getNomUrl(1);
860 } elseif (!empty($line->batch)) {
861 print $line->batch.'&nbsp;'.img_warning($langs->trans('BatchNotFound'));
862 }
863 }
864 print '</td>';
865 }
866
867 // Warehouse source
868 print '<td class="tdoverflowmax150">';
869 if ($action === 'editline' && $line->id == $lineid) {
870 print $formproduct->selectWarehouses($line->fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
871 } else {
872 print $warehousestatics->getNomUrl(1);
873 }
874 print '</td>';
875
876 // Warehouse target
877 print '<td class="tdoverflowmax150">';
878 if ($action === 'editline' && $line->id == $lineid) {
879 print $formproduct->selectWarehouses($line->fk_warehouse_destination, 'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
880 } else {
881 print $warehousestatict->getNomUrl(1);
882 }
883 print '</td>';
884
885 if ($action === 'editline' && $line->id == $lineid) {
886 print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" value="'.$line->qty.'"></td>';
887 } else {
888 print '<td class="center">'.$line->qty.'</td>';
889 }
890
891 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
892 print '<td class="linecoluseunit nowrap left">';
893 $label = $productstatic->getLabelOfUnit('short');
894 print $label;
895 print '</td>';
896 }
897
898 print '<td class="center">';
899 print price($line->pmp, 0, '', 1, -1, -1, $conf->currency);
900 print '</td>';
901
902 print '<td class="center">';
903 print price($line->pmp * $line->qty, 0, '', 1, -1, -1, $conf->currency);
904 print '</td>';
905
906 if (empty($object->status) && $permissiontoadd) {
907 if ($action === 'editline' && $line->id == $lineid) {
908 //print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Save')) . '"></td>';
909 print '<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
910 print '<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
911 } else {
912 print '<td class="right">';
913 print '<a class="editfielda reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $line->id . '#line_' . $line->id . '">';
914 print img_edit() . '</a>';
915 print '</td>';
916 print '<td class="right">';
917 print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '&action=deleteline&lineid=' . $line->id . '">' . img_delete($langs->trans("Remove")) . '</a>';
918 print '</td>';
919 }
920
921 $num = count($object->lines);
922
923 if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
924 print '<td class="linecolmove tdlineupdown center">';
925 if ($i > 0) { ?>
926 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=up&amp;rowid='.$line->id; ?>">
927 <?php print img_up('default', 0, 'imgupforline'); ?>
928 </a>
929 <?php }
930 if ($i < $num - 1) { ?>
931 <a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=down&amp;rowid='.$line->id; ?>">
932 <?php print img_down('default', 0, 'imgdownforline'); ?>
933 </a>
934 <?php }
935 print '</td>';
936 } else {
937 print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
938 }
939 }
940
941 print '</tr>';
942 }
943
944 if (empty($object->status) && $action !== 'editline' && $permissiontoadd) {
945 print '<tr class="oddeven">';
946 // Product
947 print '<td class="titlefield">';
948 $filtertype = 0;
949 if (getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
950 $filtertype = '';
951 }
952 if (getDolGlobalInt('PRODUIT_LIMIT_SIZE') <= 0) {
953 $limit = 0;
954 } else {
955 $limit = getDolGlobalInt('PRODUIT_LIMIT_SIZE');
956 }
957
958 $form->select_produits($fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
959 print '</td>';
960 // Batch number
961 if (isModEnabled('productbatch')) {
962 print '<td>';
963 print '<input type="text" name="batch" class="flat maxwidth50" '.(!empty($error) ? 'value="'.$batch.'"' : '').'>';
964 print '</td>';
965 }
966
967 $formproduct->loadWarehouses(); // Pour charger la totalité des entrepôts
968
969 // Define a list of warehouse to not show on the list
970 $TExcludedWarehouseSource = array();
971 if (!empty($object->fk_warehouse_source)) {
972 $source_ent = new Entrepot($db);
973 $source_ent->fetch($object->fk_warehouse_source);
974 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
975 if (strpos($TDataCacheWarehouse['full_label'], $source_ent->label) === false) {
976 $TExcludedWarehouseSource[] = $TDataCacheWarehouse['id'];
977 }
978 }
979 }
980
981 // Define a list of warehouse to not show on the list
982 $TExcludedWarehouseDestination = array();
983 if (!empty($object->fk_warehouse_destination)) {
984 $dest_ent = new Entrepot($db);
985 $dest_ent->fetch($object->fk_warehouse_destination);
986 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
987 if (strpos($TDataCacheWarehouse['full_label'], $dest_ent->label) === false) {
988 $TExcludedWarehouseDestination[] = $TDataCacheWarehouse['id'];
989 }
990 }
991 }
992
993 // We clean array. It is filled automatically when calling function select_warehouses
994 $formproduct->cache_warehouses = array();
995 // In warehouse
996 print '<td>';
997 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);
998 print '</td>';
999
1000 // We clean array. It is filled automatically when calling function select_warehouses
1001 $formproduct->cache_warehouses = array();
1002 // Out warehouse
1003 print '<td>';
1004 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);
1005 print '</td>';
1006
1007 // Qty
1008 print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" '.(!empty($error) ? 'value="'.$qty.'"' : '').'></td>';
1009
1010 // PMP
1011 print '<td></td>';
1012 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1013 // Unité
1014 print '<td></td>';
1015 }
1016
1017 // PMP * Qty
1018 print '<td></td>';
1019
1020 // Button to add line
1021 print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Add')) . '"></td>';
1022
1023 // Grad and drop lines
1024 print '<td></td>';
1025
1026 print '</tr>';
1027 }
1028
1029 print '</table>';
1030 print '</form>';
1031 print '</div>';
1032
1033 // Buttons for actions
1034
1035 if ($action != 'presend' && $action != 'editline') {
1036 print '<div class="tabsAction">'."\n";
1037 $parameters = array();
1038 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1039 if ($reshook < 0) {
1040 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1041 }
1042
1043 if (empty($reshook)) {
1044 // Send
1045 if (empty($user->socid)) {
1046 print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle');
1047 }
1048
1049 // Back to draft
1050 if ($object->status == $object::STATUS_VALIDATED) {
1051 print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
1052 }
1053
1054 // Modify
1055 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
1056
1057 // Validate
1058 if ($object->status == $object::STATUS_DRAFT) {
1059 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
1060 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken(), '', $permissiontoadd);
1061 } else {
1062 $langs->load("errors");
1063 print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
1064 }
1065 } elseif ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
1066 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destock&token='.newToken().'">'.$langs->trans("StockTransferDecrementation").'</a>';
1067 } elseif ($object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
1068 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destockcancel&token='.newToken().'">'.$langs->trans("StockTransferDecrementationCancel").'</a>';
1069 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstock&token='.newToken().'">'.$langs->trans("StockTransferIncrementation").'</a>';
1070 } elseif ($object->status == $object::STATUS_CLOSED && $permissiontoadd) {
1071 print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstockcancel&token='.newToken().'">'.$langs->trans("StockTransferIncrementationCancel").'</a>';
1072 }
1073
1074 // Clone
1075 if ($permissiontoadd) {
1076 print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : '').'&action=clone&token='.newToken(), '', $permissiontoadd);
1077 }
1078
1079 /*
1080 if ($permissiontoadd) {
1081 if ($object->status == $object::STATUS_ENABLED) {
1082 print dolGetButtonAction('', $langs->trans('Disable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
1083 } else {
1084 print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
1085 }
1086 }
1087 if ($permissiontoadd) {
1088 if ($object->status == $object::STATUS_VALIDATED) {
1089 print dolGetButtonAction('', $langs->trans('Cancel'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
1090 } else {
1091 print dolGetButtonAction('', $langs->trans('Re-Open'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
1092 }
1093 }
1094
1095 */
1096
1097 // Delete (with preloaded confirm popup)
1098 $deleteUrl = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken();
1099 $buttonId = 'action-delete-no-ajax';
1100 if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can use preloaded confirm if not jmobile
1101 $deleteUrl = '';
1102 $buttonId = 'action-delete';
1103 }
1104 $params = array();
1105 print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $deleteUrl, $buttonId, $permissiontodelete, $params);
1106 }
1107 print '</div>'."\n";
1108 }
1109
1110
1111 // Select mail models is same action as presend
1112 if (GETPOST('modelselected')) {
1113 $action = 'presend';
1114 }
1115
1116 if ($action != 'presend') {
1117 print '<div class="fichecenter"><div class="fichehalfleft">';
1118 print '<a name="builddoc"></a>'; // ancre
1119
1120 $includedocgeneration = 1;
1121
1122 // Documents
1123 if ($includedocgeneration) {
1124 $objref = dol_sanitizeFileName($object->ref);
1125 $relativepath = $objref . '/' . $objref . '.pdf';
1126 $filedir = $conf->stocktransfer->dir_output.'/'.$object->element.'/'.$objref;
1127 $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
1128 $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
1129 $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
1130 print $formfile->showdocuments('stocktransfer:StockTransfer', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1131 }
1132
1133 // Show links to link elements
1134 $tmparray = $form->showLinkToObjectBlock($object, array(), array('stocktransfer'), 1);
1135 $linktoelem = $tmparray['linktoelem'];
1136 $htmltoenteralink = $tmparray['htmltoenteralink'];
1137 print $htmltoenteralink;
1138
1139 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1140
1141
1142 print '</div><div class="fichehalfright">';
1143
1144 $MAXEVENT = 10;
1145
1146 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
1147
1148 // List of actions on element
1149 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1150 $formactions = new FormActions($db);
1151 $somethingshown = $formactions->showactions($object, 'stocktransfer', 0, 1, '', $MAXEVENT, '');
1152
1153 print '</div></div>';
1154 }
1155
1156 //Select mail models is same action as presend
1157 if (GETPOST('modelselected')) {
1158 $action = 'presend';
1159 }
1160
1161 // Presend form
1162 $modelmail = 'stocktransfer';
1163 $defaulttopic = 'InformationMessage';
1164 $diroutput = $conf->stocktransfer->dir_output;
1165 $trackid = 'stocktransfer'.$object->id;
1166
1167 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
1168}
1169
1170// End of page
1171llxFooter();
1172$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.