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