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