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