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