stocktransfer_card.php 46 KB

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