48 if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER[
"CONTEXT_DOCUMENT_ROOT"].
"/main.inc.php";
50 $tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
51 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
52 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
53 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
55 if (!$res && file_exists(
"../main.inc.php")) $res = @include
"../main.inc.php";
56 if (!$res && file_exists(
"../../main.inc.php")) $res = @include
"../../main.inc.php";
57 if (!$res && file_exists(
"../../../main.inc.php")) $res = @include
"../../../main.inc.php";
58 if (!$res) die(
"Include of main fails");
60 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
66 require_once DOL_DOCUMENT_ROOT.
'/product/stock/stocktransfer/class/stocktransfer.class.php';
67 require_once DOL_DOCUMENT_ROOT.
'/product/stock/stocktransfer/class/stocktransferline.class.php';
68 require_once DOL_DOCUMENT_ROOT.
'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
69 require_once DOL_DOCUMENT_ROOT.
'/core/modules/stocktransfer/modules_stocktransfer.php';
72 $langs->loadLangs(array(
"stocks",
"other",
"productbatch",
"companies"));
73 if (!empty($conf->incoterm->enabled)) $langs->load(
'incoterm');
78 $action =
GETPOST(
'action',
'aZ09');
79 $confirm =
GETPOST(
'confirm',
'alpha');
80 $cancel =
GETPOST(
'cancel',
'aZ09');
81 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'stocktransfercard';
82 $backtopage =
GETPOST(
'backtopage',
'alpha');
83 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
85 $fk_product =
GETPOST(
'fk_product',
'int');
86 $fk_warehouse_source =
GETPOST(
'fk_warehouse_source',
'int');
87 $fk_warehouse_destination =
GETPOST(
'fk_warehouse_destination',
'int');
88 $lineid =
GETPOST(
'lineid',
'int');
89 $label =
GETPOST(
'label',
'alpha');
90 $batch =
GETPOST(
'batch',
'alpha');
91 $code_inv =
GETPOST(
'inventorycode',
'alphanohtml');
96 $diroutputmassaction = $conf->stocktransfer->dir_output.
'/temp/massgeneration/'.$user->id;
97 $hookmanager->initHooks(array(
'stocktransfercard',
'globalcard'));
100 $extrafields->fetch_name_optionals_label($object->table_element);
102 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
105 $search_all = trim(
GETPOST(
"search_all",
'alpha'));
107 foreach ($object->fields as $key => $val) {
108 if (
GETPOST(
'search_'.$key,
'alpha')) $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
111 if (empty($action) && empty($id) && empty($ref)) $action =
'view';
114 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
117 $permissiontoread = $user->rights->stocktransfer->stocktransfer->read;
118 $permissiontoadd = $user->rights->stocktransfer->stocktransfer->write;
119 $permissionnote = $user->rights->stocktransfer->stocktransfer->write;
120 $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
121 $permissiondellink = $user->rights->stocktransfer->stocktransfer->write;
122 $upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1];
130 if (!$permissiontoread || ($action ===
'create' && !$permissiontoadd))
accessforbidden();
141 $parameters = array();
142 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
143 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
145 if (empty($reshook)) {
148 $backurlforlist =
dol_buildpath(
'/product/stock/stocktransfer/stocktransfer_list.php', 1);
150 if (empty($backtopage) || ($cancel && empty($id))) {
151 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
152 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) $backtopage = $backurlforlist;
153 else $backtopage =
dol_buildpath(
'/product/stock/stocktransfer/stocktransfer_card.php', 1).
'?id='.($id > 0 ? $id :
'__ID__');
156 $triggermodname =
'STOCKTRANSFER_STOCKTRANSFER_MODIFY';
159 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
162 $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
165 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
168 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
171 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
174 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
176 if ($action ==
'set_thirdparty' && $permissiontoadd) {
177 $object->setValueFrom(
'fk_soc',
GETPOST(
'fk_soc',
'int'),
'',
'',
'date',
'', $user,
'STOCKTRANSFER_MODIFY');
179 if ($action ==
'classin' && $permissiontoadd) {
180 $object->setProject(
GETPOST(
'projectid',
'int'));
183 if ($action ==
'addline' && $permissiontoadd) {
186 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
190 if ($fk_warehouse_source <= 0) {
192 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WarehouseSource")),
null,
'errors');
196 if ($fk_warehouse_destination <= 0) {
198 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WarehouseTarget")),
null,
'errors');
203 $prod->fetch($fk_product);
204 if ($prod->hasbatch()) {
207 $langs->load(
"errors");
208 setEventMessages($langs->transnoentities(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref),
null,
'errors');
211 if (!empty($batch)) {
213 setEventMessages($langs->transnoentities(
'StockTransferNoBatchForProduct', $prod->getNomUrl()),
'',
'errors');
219 $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).
"'" ).
')'));
220 if (!empty($records[key($records)])) $line = $records[key($records)];
221 $line->fk_stocktransfer = $id;
223 $line->fk_warehouse_source = $fk_warehouse_source;
224 $line->fk_warehouse_destination = $fk_warehouse_destination;
225 $line->fk_product = $fk_product;
226 $line->batch = $batch;
228 $line->pmp = $prod->pmp;
229 if ($line->id > 0) $line->update($user);
231 $line->rang = count($object->lines) + 1;
232 $line->create($user);
234 $object->fetchLines();
236 } elseif ($action ===
'updateline' && $permissiontoadd) {
239 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
240 $action =
'editline';
243 if ($fk_warehouse_source <= 0) {
245 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WarehouseSource")),
null,
'errors');
246 $action =
'editline';
249 if ($fk_warehouse_destination <= 0) {
251 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WarehouseTarget")),
null,
'errors');
252 $action =
'editline';
256 $prod->fetch($fk_product);
257 if ($prod->hasbatch()) {
260 $langs->load(
"errors");
261 setEventMessages($langs->transnoentities(
"ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->getNomUrl()),
null,
'errors');
262 $action =
'editline';
265 if (!empty($batch)) {
267 setEventMessages($langs->transnoentities(
'StockTransferNoBatchForProduct', $prod->getNomUrl()),
'',
'errors');
268 $action =
'editline';
274 $line->fetch($lineid);
276 $line->fk_warehouse_source = $fk_warehouse_source;
277 $line->fk_warehouse_destination = $fk_warehouse_destination;
278 $line->fk_product = $fk_product;
279 $line->batch = $batch;
280 $line->pmp = $prod->pmp;
281 $line->update($user);
285 if ($permissiontoadd) {
287 if ($action ==
'confirm_destock' && $confirm ==
'yes' && $object->status == $object::STATUS_VALIDATED) {
288 $lines = $object->getLinesArray();
289 if (!empty($lines)) {
291 foreach ($lines as $line) {
292 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source);
293 if ($res <= 0) $error++;
295 if (empty($error)) $db->commit();
296 else $db->rollback();
299 $object->setStatut($object::STATUS_TRANSFERED, $id);
300 $object->status = $object::STATUS_TRANSFERED;
301 $object->date_reelle_depart = date(
'Y-m-d');
302 $object->update($user);
308 if ($action ==
'confirm_destockcancel' && $confirm ==
'yes' && $object->status == $object::STATUS_TRANSFERED) {
309 $lines = $object->getLinesArray();
310 if (!empty($lines)) {
312 foreach ($lines as $line) {
313 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0);
314 if ($res <= 0) $error++;
316 if (empty($error)) $db->commit();
317 else $db->rollback();
320 $object->setStatut($object::STATUS_VALIDATED, $id);
321 $object->status = $object::STATUS_VALIDATED;
322 $object->date_reelle_depart =
null;
323 $object->update($user);
329 if ($action ==
'confirm_addstock' && $confirm ==
'yes' && $object->status == $object::STATUS_TRANSFERED) {
330 $lines = $object->getLinesArray();
331 if (!empty($lines)) {
333 foreach ($lines as $line) {
334 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0);
335 if ($res <= 0) $error++;
337 if (empty($error)) $db->commit();
338 else $db->rollback();
341 $object->setStatut($object::STATUS_CLOSED, $id);
342 $object->status = $object::STATUS_CLOSED;
343 $object->date_reelle_arrivee = date(
'Y-m-d');
344 $object->update($user);
350 if ($action ==
'confirm_addstockcancel' && $confirm ==
'yes' && $object->status == $object::STATUS_CLOSED) {
351 $lines = $object->getLinesArray();
352 if (!empty($lines)) {
354 foreach ($lines as $line) {
355 $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination);
356 if ($res <= 0) $error++;
358 if (empty($error)) $db->commit();
359 else $db->rollback();
362 $object->setStatut($object::STATUS_TRANSFERED, $id);
363 $object->status = $object::STATUS_TRANSFERED;
364 $object->date_reelle_arrivee =
null;
365 $object->update($user);
372 if ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled) && $permissiontoadd) {
373 $result = $object->setIncoterms(
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
376 $triggersendname =
'STOCKTRANSFER_SENTBYMAIL';
377 $autocopy =
'MAIN_MAIL_AUTOCOPY_STOCKTRANSFER_TO';
378 $trackid =
'stocktransfer'.$object->id;
379 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
391 $title = $langs->trans(
"StockTransfer");
398 print
'<script type="text/javascript" language="javascript">
399 jQuery(document).ready(function() {';
402 $date_prevue_depart = $object->date_prevue_depart;
403 $date_prevue_depart_plus_delai = $date_prevue_depart;
404 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');
405 if (!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date(
'Y-m-d'))) {
406 print
"$('.valuefield.fieldname_date_prevue_depart').append('";
407 print
img_warning($langs->trans(
'Alert').
' - '.$langs->trans(
'Late'));
416 if ($action ==
'create') {
417 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"StockTransfer")),
'',
'object_'.$object->picto);
419 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
420 print
'<input type="hidden" name="token" value="'.newToken().
'">';
421 print
'<input type="hidden" name="action" value="add">';
422 if ($backtopage) print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
423 if ($backtopageforcancel) print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
430 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
433 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
435 if (!empty($conf->incoterm->enabled)) {
437 print
'<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans(
"IncotermLabel"), $soc->label_incoterms, 1).
'</label></td>';
438 print
'<td class="maxwidthonsmartphone">';
439 print
$form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms :
''), (!empty($soc->location_incoterms) ? $soc->location_incoterms :
''),
'',
'fk_incoterms');
443 print
'<tr><td>'.$langs->trans(
'DefaultModel').
'</td>';
445 print
img_picto(
'',
'pdf',
'class="pictofixedwidth"');
446 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
448 $preselected = $conf->global->STOCKTRANSFER_ADDON_PDF;
449 print
$form->selectarray(
'model', $liste, $preselected, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth200 widthcentpercentminusx', 1);
453 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
455 print
'</table>'.
"\n";
459 print
'<div class="center">';
460 print
'<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans(
"Create")).
'">';
462 print
'<input type="'.($backtopage ?
"submit" :
"button").
'" class="button" name="cancel" value="'.
dol_escape_htmltag($langs->trans(
"Cancel")).
'"'.($backtopage ?
'' :
' onclick="javascript:history.go(-1)"').
'>';
471 if (($id || $ref) && $action ==
'edit') {
473 print
load_fiche_titre($langs->trans(
"StockTransfer"),
'',
'object_' . $object->picto);
475 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
476 print
'<input type="hidden" name="token" value="' .
newToken() .
'">';
477 print
'<input type="hidden" name="action" value="update">';
478 print
'<input type="hidden" name="id" value="' . $object->id .
'">';
479 if ($backtopage) print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
480 if ($backtopageforcancel) print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
484 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
487 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
490 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_edit.tpl.php';
496 print
'<div class="center"><input type="submit" class="button" name="save" value="' . $langs->trans(
"Save") .
'">';
497 print
' <input type="submit" class="button" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
505 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
506 $res = $object->fetch_optionals();
509 print
dol_get_fiche_head($head,
'card', $langs->trans(
"StockTransfer"), -1, $object->picto);
514 if ($action ==
'delete') {
515 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'Delete'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
518 if ($action ==
'deleteline') {
519 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
522 if ($action ==
'clone') {
524 $formquestion = array();
525 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
526 } elseif ($action ==
'destock') {
528 $formquestion = array(
'text' =>
'',
529 array(
'type' =>
'text',
'name' =>
'label',
'label' => $langs->trans(
"Label"),
'value' => $langs->trans(
'ConfirmDestock', $object->ref),
'size'=>40),
530 array(
'type' =>
'text',
'name' =>
'inventorycode',
'label' => $langs->trans(
"InventoryCode"),
'value' =>
dol_print_date(
dol_now(),
'%y%m%d%H%M%S'),
'size'=>25)
532 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DestockAllProduct'),
'',
'confirm_destock', $formquestion,
'yes', 1);
533 } elseif ($action ==
'destockcancel') {
535 $formquestion = array(
'text' =>
'',
536 array(
'type' =>
'text',
'name' =>
'label',
'label' => $langs->trans(
"Label"),
'value' => $langs->trans(
'ConfirmDestockCancel', $object->ref),
'size'=>40),
537 array(
'type' =>
'text',
'name' =>
'inventorycode',
'label' => $langs->trans(
"InventoryCode"),
'value' =>
dol_print_date(
dol_now(),
'%y%m%d%H%M%S'),
'size'=>25)
539 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DestockAllProductCancel'),
'',
'confirm_destockcancel', $formquestion,
'yes', 1);
540 } elseif ($action ==
'addstock') {
542 $formquestion = array(
'text' =>
'',
543 array(
'type' =>
'text',
'name' =>
'label',
'label' => $langs->trans(
"Label").
' :',
'value' => $langs->trans(
'ConfirmAddStock', $object->ref),
'size'=>40),
544 array(
'type' =>
'text',
'name' =>
'inventorycode',
'label' => $langs->trans(
"InventoryCode"),
'value' =>
dol_print_date(
dol_now(),
'%y%m%d%H%M%S'),
'size'=>25)
546 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'AddStockAllProduct'),
'',
'confirm_addstock', $formquestion,
'yes', 1);
547 } elseif ($action ==
'addstockcancel') {
549 $formquestion = array(
'text' =>
'',
550 array(
'type' =>
'text',
'name' =>
'label',
'label' => $langs->trans(
"Label").
' :',
'value' => $langs->trans(
'ConfirmAddStockCancel', $object->ref),
'size'=>40),
551 array(
'type' =>
'text',
'name' =>
'inventorycode',
'label' => $langs->trans(
"InventoryCode"),
'value' =>
dol_print_date(
dol_now(),
'%y%m%d%H%M%S'),
'size'=>25)
553 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'AddStockAllProductCancel'),
'',
'confirm_addstockcancel', $formquestion,
'yes', 1);
557 if ($action ==
'xxx') {
558 $formquestion = array();
569 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'XXX'), $text,
'confirm_xxx', $formquestion, 0, 1, 220);
573 if ($action ==
'valid' && $permissiontoadd) {
574 $nextref=$object->getNextNumRef();
575 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'Validate'), $langs->transnoentities(
'ConfirmValidateStockTransfer', $nextref),
'confirm_validate', $formquestion, 0, 2);
579 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
580 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
581 if (empty($reshook))
$formconfirm .= $hookmanager->resPrint;
582 elseif ($reshook > 0)
$formconfirm = $hookmanager->resPrint;
590 $linkback = '<a href="'.
dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
592 $morehtmlref = '<div class="refidno">';
596 $morehtmlref .= $langs->trans(
'ThirdParty') .
' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) :
'').
'<br>';
599 if (! empty($conf->project->enabled)) {
600 $langs->load(
"projects");
601 $morehtmlref.=$langs->trans(
'Project') .
' ';
602 if ($permissiontoadd) {
605 if ($action ==
'classify') {
607 $morehtmlref.=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
608 $morehtmlref.=
'<input type="hidden" name="action" value="classin">';
609 $morehtmlref.=
'<input type="hidden" name="token" value="'.newToken().
'">';
610 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
611 $morehtmlref.=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
612 $morehtmlref.=
'</form>';
614 $morehtmlref.=
$form->form_project($_SERVER[
'PHP_SELF'] .
'?id=' . $object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
617 if (! empty($object->fk_project)) {
619 $proj->fetch($object->fk_project);
620 $morehtmlref .=
': '.$proj->getNomUrl();
626 $morehtmlref .=
'</div>';
629 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
632 print
'<div class="fichecenter">';
633 print
'<div class="fichehalfleft">';
634 print
'<div class="underbanner clearboth"></div>';
635 print
'<table class="border centpercent tableforfield">'.
"\n";
642 $object->fields[
'fk_soc'][
'visible']=0;
643 $object->fields[
'fk_project'][
'visible']=0;
644 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
647 if (!empty($conf->incoterm->enabled)) {
649 print
'<table width="100%" class="nobordernopadding"><tr><td>';
650 print $langs->trans(
'IncotermLabel');
651 print
'<td><td class="right">';
652 if ($permissiontoadd && $action !=
'editincoterm') print
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editincoterm">'.
img_edit().
'</a>';
654 print
'</td></tr></table>';
657 if ($action !=
'editincoterm') {
658 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
660 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
666 echo
'<td>'.$langs->trans(
'EnhancedValue').
' '.strtolower($langs->trans(
'TotalWoman'));
667 echo
'<td>'.price($object->getValorisationTotale(), 0,
'', 1, -1, -1, $conf->currency).
'</td>';
670 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
676 print
'<div class="clearboth"></div>';
685 if (!empty($object->table_element_line)) {
696 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
697 include DOL_DOCUMENT_ROOT.
'/core/tpl/ajaxrow.tpl.php';
735 print
'<div class="div-table-responsive-no-min">';
736 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#addline' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
737 <input type="hidden" name="token" value="' .
newToken().
'">
738 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
739 <input type="hidden" name="mode" value="">
740 <input type="hidden" name="id" value="' . $object->id.
'">
742 if ($lineid > 0) print
'<input type="hidden" name="lineid" value="'.$lineid.
'" />';
743 print
'<table id="tablelines" class="liste centpercent">';
748 $conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE=
true;
750 print
'<tr class="liste_titre">';
751 print
getTitleFieldOfList($langs->trans(
'ProductRef'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'tagtd maxwidthonsmartphone ');
753 print
getTitleFieldOfList($langs->trans(
'Batch'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'tagtd maxwidthonsmartphone ');
755 print
getTitleFieldOfList($langs->trans(
'WarehouseSource'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'tagtd maxwidthonsmartphone ');
756 print
getTitleFieldOfList($langs->trans(
'WarehouseTarget'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'tagtd maxwidthonsmartphone ');
757 print
getTitleFieldOfList($langs->trans(
'Qty'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'center tagtd maxwidthonsmartphone ');
758 if ($conf->global->PRODUCT_USE_UNITS) {
759 print
getTitleFieldOfList($langs->trans(
'Unit'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'tagtd maxwidthonsmartphone ');
761 print
getTitleFieldOfList($langs->trans(
'AverageUnitPricePMPShort'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'center tagtd maxwidthonsmartphone ');
762 print
getTitleFieldOfList($langs->trans(
'EstimatedStockValueShort'), 0, $_SERVER[
"PHP_SELF"],
'', $param,
'',
'', $sortfield, $sortorder,
'center tagtd maxwidthonsmartphone ');
763 if (empty($object->status) && $permissiontoadd) {
771 $listofdata = $object->getLinesArray();
772 $productstatic =
new Product($db);
773 $warehousestatics =
new Entrepot($db);
774 $warehousestatict =
new Entrepot($db);
776 foreach ($listofdata as $key => $line) {
777 $productstatic->fetch($line->fk_product);
778 $warehousestatics->fetch($line->fk_warehouse_source);
779 $warehousestatict->fetch($line->fk_warehouse_destination);
782 $domData =
' data-element="'.$line->element.
'"';
783 $domData .=
' data-id="'.$line->id.
'"';
784 $domData .=
' data-qty="'.$line->qty.
'"';
787 print
'<tr id="row-'.$line->id.
'" class="drag drop oddeven" '.$domData.
'>';
788 print
'<td class="titlefield">';
789 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);
790 else print $productstatic->getNomUrl(1).
' - '.$productstatic->label;
794 if ($action ===
'editline' && $line->id == $lineid) print
'<input type="text" value="'.$line->batch.
'" name="batch" class="flat maxwidth50"/>';
797 if ($productlot->fetch(0, $line->fk_product, $line->batch) > 0) {
798 print $productlot->getNomUrl(1);
799 } elseif (!empty($line->batch)) print $line->batch.' '.
img_warning($langs->trans('BatchNotFound'));;
806 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);
807 else print $warehousestatics->getNomUrl(1);
810 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);
811 else print $warehousestatict->getNomUrl(1);
813 if ($action === 'editline' && $line->
id == $lineid) print '<td class="center"><input
type="text" class="flat maxwidth50"
name="qty" value="'.$line->qty.'"></td>';
814 else print '<td class="center">'.$line->qty.'</td>';
816 if ($conf->global->PRODUCT_USE_UNITS) {
817 print
'<td class="linecoluseunit nowrap left">';
818 $label = $productstatic->getLabelOfUnit(
'short');
820 print $langs->trans($label);
825 print
'<td class="center">';
826 print
price($line->pmp, 0,
'', 1, -1, -1, $conf->currency);
828 print
'<td class="center">';
829 print
price($line->pmp * $line->qty, 0,
'', 1, -1, -1, $conf->currency);
831 if (empty($object->status) && $permissiontoadd) {
832 if ($action ===
'editline' && $line->id == $lineid) {
834 print
'<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans(
"Save").
'"><br>';
835 print
'<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans(
"Cancel").
'"></td>';
837 print
'<td class="right">';
838 print
'<a class="editfielda reposition" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $object->id .
'&action=editline&lineid=' . $line->id .
'#line_' . $line->id .
'">';
841 print
'<td class="right">';
842 print
'<a href="' . $_SERVER[
"PHP_SELF"] .
'?id=' . $id .
'&action=deleteline&lineid=' . $line->id .
'">' .
img_delete($langs->trans(
"Remove")) .
'</a>';
846 $num = count($object->lines);
848 if ($num > 1 && $conf->browser->layout !=
'phone' && empty($disablemove)) {
849 print
'<td class="linecolmove tdlineupdown center">';
852 <a
class=
"lineupdown" href=
"<?php print $_SERVER["PHP_SELF
"].'?id='.$id.'&action=up&rowid='.$line->id; ?>">
853 <?php print
img_up(
'default', 0,
'imgupforline'); ?>
856 if ($i < $num - 1) { ?>
857 <a
class=
"lineupdown" href=
"<?php print $_SERVER["PHP_SELF
"].'?id='.$id.'&action=down&rowid='.$line->id; ?>">
858 <?php print
img_down(
'default', 0,
'imgdownforline'); ?>
863 print
'<td '.(($conf->browser->layout !=
'phone' && empty($disablemove)) ?
' class="linecolmove tdlineupdown center"' :
' class="linecolmove center"').
'></td>';
871 if (empty($object->status) && $action !==
'editline' && $permissiontoadd) {
872 print
'<tr class="oddeven">';
874 print
'<td class="titlefield">';
876 if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype =
'';
877 if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) {
880 $limit = $conf->global->PRODUIT_LIMIT_SIZE;
883 $form->select_produits($fk_product,
'fk_product', $filtertype, $limit, 0, -1, 2,
'', 0, array(), 0, 0, 0,
'minwidth200imp maxwidth300', 1);
888 print
'<input type="text" name="batch" class="flat maxwidth50" '.(!empty($error) ?
'value="'.$batch.
'"' :
'').
'>';
892 $formproduct->loadWarehouses();
895 $TExcludedWarehouseSource=array();
896 if (!empty($object->fk_warehouse_source)) {
898 $source_ent->fetch($object->fk_warehouse_source);
899 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
900 if (strpos($TDataCacheWarehouse[
'full_label'], $source_ent->label) ===
false) $TExcludedWarehouseSource[] = $TDataCacheWarehouse[
'id'];
905 $TExcludedWarehouseDestination=array();
906 if (!empty($object->fk_warehouse_destination)) {
908 $dest_ent->fetch($object->fk_warehouse_destination);
909 foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
910 if (strpos($TDataCacheWarehouse[
'full_label'], $dest_ent->label) ===
false) $TExcludedWarehouseDestination[] = $TDataCacheWarehouse[
'id'];
915 $formproduct->cache_warehouses=array();
918 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);
922 $formproduct->cache_warehouses=array();
925 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);
929 print
'<td class="center"><input type="text" class="flat maxwidth50" name="qty" '.(!empty($error) ?
'value="'.$qty.
'"' :
'').
'></td>';
932 if ($conf->global->PRODUCT_USE_UNITS) {
939 print
'<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' .
dol_escape_htmltag($langs->trans(
'Add')) .
'"></td>';
951 if ($action !=
'presend' && $action !=
'editline') {
952 print
'<div class="tabsAction">'.
"\n";
953 $parameters = array();
954 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
955 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
957 if (empty($reshook)) {
959 if (empty($user->socid)) {
960 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>'.
"\n";
964 if ($object->status == $object::STATUS_VALIDATED) {
965 if ($permissiontoadd) {
966 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=confirm_setdraft&confirm=yes">'.$langs->trans(
"SetToDraft").
'</a>';
971 if ($permissiontoadd) {
972 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit">'.$langs->trans(
"Modify").
'</a>'.
"\n";
980 if ($object->status == $object::STATUS_DRAFT) {
981 if ($permissiontoadd) {
982 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
983 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=valid">'.$langs->trans(
"Validate").
'</a>';
985 $langs->load(
"errors");
986 print
'<a class="butActionRefused" href="" title="'.$langs->trans(
"ErrorAddAtLeastOneLineFirst").
'">'.$langs->trans(
"Validate").
'</a>';
989 } elseif ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) {
990 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=destock">'.$langs->trans(
"StockTransferDecrementation").
'</a>';
991 } elseif ($object->status == $object::STATUS_TRANSFERED && $permissiontoadd) {
992 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=destockcancel">'.$langs->trans(
"StockTransferDecrementationCancel").
'</a>';
993 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=addstock">'.$langs->trans(
"StockTransferIncrementation").
'</a>';
994 } elseif ($object->status == $object::STATUS_CLOSED && $permissiontoadd) {
995 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=addstockcancel">'.$langs->trans(
"StockTransferIncrementationCancel").
'</a>';
999 if ($permissiontoadd) {
1000 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&object=stocktransfer">'.$langs->trans(
"ToClone").
'</a>'.
"\n";
1029 if ($object->status < $object::STATUS_TRANSFERED && $permissiontodelete) {
1030 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>'.
"\n";
1037 print
'</div>'.
"\n";
1042 if (
GETPOST(
'modelselected')) {
1043 $action =
'presend';
1046 if ($action !=
'presend') {
1047 print
'<div class="fichecenter"><div class="fichehalfleft">';
1048 print
'<a name="builddoc"></a>';
1050 $includedocgeneration = 1;
1053 if ($includedocgeneration) {
1055 $relativepath = $objref .
'/' . $objref .
'.pdf';
1056 $filedir = $conf->stocktransfer->dir_output.
'/'.$object->element.
'/'.$objref;
1057 $urlsource = $_SERVER[
"PHP_SELF"] .
"?id=" . $object->id;
1058 $genallowed = $user->rights->stocktransfer->stocktransfer->read;
1059 $delallowed = $user->rights->stocktransfer->stocktransfer->write;
1060 print $formfile->showdocuments(
'stocktransfer:StockTransfer', $object->element.
'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
1064 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'stocktransfer'));
1065 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
1068 print
'</div><div class="fichehalfright"><div class="ficheaddleft">';
1072 $morehtmlright =
'<a href="'.dol_buildpath(
'/product/stock/stocktransfer/stocktransfer_agenda.php', 1).
'?id='.$object->id.
'">';
1073 $morehtmlright .= $langs->trans(
"SeeAll");
1074 $morehtmlright .=
'</a>';
1077 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
1079 $somethingshown =
$formactions->showactions($object,
'stocktransfer', 0, 1,
'', $MAXEVENT,
'', $morehtmlright);
1081 print
'</div></div></div>';
1085 if (
GETPOST(
'modelselected')) $action =
'presend';
1088 $modelmail =
'stocktransfer';
1089 $defaulttopic =
'InformationMessage';
1090 $diroutput = $conf->stocktransfer->dir_output;
1091 $trackid =
'stocktransfer'.$object->id;
1093 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';