stocktransfer_card.php 46 KB

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