card.php 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  1. <?php
  2. /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  10. * Copyright (C) 2014-2017 Francis Appels <francis.appels@yahoo.com>
  11. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  12. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Yasser Carreón <yacasia@gmail.com>
  14. * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/reception/card.php
  31. * \ingroup reception
  32. * \brief Card of a reception
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  45. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  46. if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  47. if (!empty($conf->fournisseur->enabled)) {
  48. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
  50. }
  51. if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  52. if (!empty($conf->projet->enabled)) {
  53. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  54. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  55. }
  56. $langs->loadLangs(array("receptions", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'sendings'));
  57. if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
  58. if (!empty($conf->productbatch->enabled)) $langs->load('productbatch');
  59. $origin = GETPOST('origin', 'alpha') ?GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal
  60. $origin_id = GETPOST('id', 'int') ?GETPOST('id', 'int') : '';
  61. $id = $origin_id;
  62. if (empty($origin_id)) $origin_id = GETPOST('origin_id', 'int'); // Id of order or propal
  63. if (empty($origin_id)) $origin_id = GETPOST('object_id', 'int'); // Id of order or propal
  64. if (empty($origin_id)) $origin_id = GETPOST('originid', 'int'); // Id of order or propal
  65. $ref = GETPOST('ref', 'alpha');
  66. $line_id = GETPOST('lineid', 'int') ?GETPOST('lineid', 'int') : '';
  67. // Security check
  68. $socid = '';
  69. if ($user->socid) $socid = $user->socid;
  70. if ($origin == 'reception') $result = restrictedArea($user, $origin, $id);
  71. else {
  72. $result = restrictedArea($user, 'reception');
  73. if ($origin == 'supplierorder') {
  74. if (empty($user->rights->fournisseur->commande->lire) && empty($user->rights->fournisseur->commande->read)) accessforbidden();
  75. }elseif (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
  76. }
  77. $action = GETPOST('action', 'alpha');
  78. //Select mail models is same action as presend
  79. if (GETPOST('modelselected')) {
  80. $action = 'presend';
  81. }
  82. $confirm = GETPOST('confirm', 'alpha');
  83. $cancel = GETPOST('cancel', 'alpha');
  84. //PDF
  85. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  86. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  87. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  88. $object = new Reception($db);
  89. $extrafields = new ExtraFields($db);
  90. // fetch optionals attributes and labels
  91. $extrafields->fetch_name_optionals_label($object->table_element);
  92. $extrafields->fetch_name_optionals_label($object->table_element_line);
  93. // Load object. Make an object->fetch
  94. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  95. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  96. $hookmanager->initHooks(array('receptioncard', 'globalcard'));
  97. $permissiondellink = $user->rights->reception->creer; // Used by the include of actions_dellink.inc.php
  98. //var_dump($object->lines[0]->detail_batch);
  99. /*
  100. * Actions
  101. */
  102. $parameters = array();
  103. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  104. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  105. if (empty($reshook))
  106. {
  107. if ($cancel)
  108. {
  109. $action = '';
  110. $object->fetch($id); // show reception also after canceling modification
  111. }
  112. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  113. // Reopen
  114. if ($action == 'reopen' && $user->rights->reception->creer)
  115. {
  116. $object->fetch($id);
  117. $result = $object->reOpen();
  118. }
  119. // Confirm back to draft status
  120. if ($action == 'modif' && $user->rights->reception->creer)
  121. {
  122. $result = $object->setDraft($user);
  123. if ($result >= 0)
  124. {
  125. // Define output language
  126. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  127. {
  128. $outputlangs = $langs;
  129. $newlang = '';
  130. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  131. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  132. if (!empty($newlang)) {
  133. $outputlangs = new Translate("", $conf);
  134. $outputlangs->setDefaultLang($newlang);
  135. }
  136. $model = $object->modelpdf;
  137. $ret = $object->fetch($id); // Reload to get new records
  138. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  139. }
  140. }
  141. }
  142. // Set incoterm
  143. if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
  144. {
  145. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  146. }
  147. if ($action == 'setref_supplier')
  148. {
  149. $result = $object->fetch($id);
  150. if ($result < 0) {
  151. setEventMessages($object->error, $object->errors, 'errors');
  152. }
  153. $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
  154. if ($result < 0) {
  155. setEventMessages($object->error, $object->errors, 'errors');
  156. $action = 'editref_supplier';
  157. } else {
  158. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  159. exit;
  160. }
  161. }
  162. if ($action == 'update_extras')
  163. {
  164. $object->oldcopy = dol_clone($object);
  165. // Fill array 'array_options' with data from update form
  166. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none'));
  167. if ($ret < 0) $error++;
  168. if (!$error)
  169. {
  170. // Actions on extra fields
  171. $result = $object->insertExtraFields('RECEPTION_MODIFY');
  172. if ($result < 0)
  173. {
  174. setEventMessages($object->error, $object->errors, 'errors');
  175. $error++;
  176. }
  177. }
  178. if ($error)
  179. $action = 'edit_extras';
  180. }
  181. // Create reception
  182. if ($action == 'add' && $user->rights->reception->creer)
  183. {
  184. $error = 0;
  185. $predef = '';
  186. $db->begin();
  187. $object->note = GETPOST('note', 'alpha');
  188. $object->origin = $origin;
  189. $object->origin_id = $origin_id;
  190. $object->fk_project = GETPOST('projectid', 'int');
  191. $object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');
  192. $object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');
  193. $object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');
  194. $object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');
  195. $object->size_units = GETPOST('size_units', 'int');
  196. $object->weight_units = GETPOST('weight_units', 'int');
  197. $date_delivery = dol_mktime(GETPOST('date_deliveryhour', 'int'), GETPOST('date_deliverymin', 'int'), 0, GETPOST('date_deliverymonth', 'int'), GETPOST('date_deliveryday', 'int'), GETPOST('date_deliveryyear', 'int'));
  198. // On va boucler sur chaque ligne du document d'origine pour completer objet reception
  199. // avec info diverses + qte a livrer
  200. if ($object->origin == "supplierorder")
  201. $classname = 'CommandeFournisseur';
  202. else
  203. $classname = ucfirst($object->origin);
  204. $objectsrc = new $classname($db);
  205. $objectsrc->fetch($object->origin_id);
  206. $object->socid = $objectsrc->socid;
  207. $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
  208. $object->model_pdf = GETPOST('model');
  209. $object->date_delivery = $date_delivery; // Date delivery planed
  210. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  211. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  212. $object->tracking_number = GETPOST('tracking_number', 'alpha');
  213. $object->ref_int = GETPOST('ref_int', 'alpha');
  214. $object->note_private = GETPOST('note_private', 'none');
  215. $object->note_public = GETPOST('note_public', 'none');
  216. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  217. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  218. $batch_line = array();
  219. $stockLine = array();
  220. $array_options = array();
  221. $totalqty = 0;
  222. $num = 0;
  223. foreach ($_POST as $key => $value)
  224. {
  225. // without batch module enabled
  226. if (strpos($key, 'qtyasked') !== false)
  227. {
  228. $num++;
  229. }
  230. }
  231. for ($i = 1; $i <= $num; $i++)
  232. {
  233. $idl = "idl".$i;
  234. $sub_qty = array();
  235. $subtotalqty = 0;
  236. $j = 0;
  237. $batch = "batchl".$i."_0";
  238. $stockLocation = "ent1".$i."_0";
  239. $qty = "qtyl".$i;
  240. //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
  241. //reception line for product with no batch management and no multiple stock location
  242. if (GETPOST($qty, 'int') > 0)
  243. $totalqty += GETPOST($qty, 'int');
  244. // Extrafields
  245. $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, $i);
  246. }
  247. if ($totalqty > 0) // There is at least one thing to ship
  248. {
  249. //var_dump($_POST);exit;
  250. for ($i = 1; $i <= $num; $i++)
  251. {
  252. $lineToTest = '';
  253. foreach ($objectsrc->lines as $linesrc) {
  254. if ($linesrc->id == GETPOST($idl, 'int')) $lineToTest = $linesrc;
  255. }
  256. $qty = "qtyl".$i;
  257. $comment = "comment".$i;
  258. $eatby = "dlc".$i;
  259. $sellby = "dluo".$i;
  260. $batch = "batch".$i;
  261. $timeFormat = '%d/%m/%Y';
  262. if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS))
  263. {
  264. $ent = "entl".$i;
  265. $idl = "idl".$i;
  266. $entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');
  267. if ($entrepot_id < 0)
  268. $entrepot_id = '';
  269. if (!($linesrc->fk_product > 0) && empty($conf->global->STOCK_SUPPORTS_SERVICES))
  270. $entrepot_id = 0;
  271. $eatby = GETPOST($eatby, 'alpha');
  272. $sellby = GETPOST($sellby, 'alpha');
  273. $eatbydate = str_replace('/', '-', $eatby);
  274. $sellbydate = str_replace('/', '-', $sellby);
  275. $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
  276. if ($ret < 0)
  277. {
  278. setEventMessages($object->error, $object->errors, 'errors');
  279. $error++;
  280. }
  281. }
  282. }
  283. // Fill array 'array_options' with data from add form
  284. $ret = $extrafields->setOptionalsFromPost(null, $object);
  285. if ($ret < 0) $error++;
  286. if (!$error)
  287. {
  288. $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
  289. if ($ret <= 0)
  290. {
  291. setEventMessages($object->error, $object->errors, 'errors');
  292. $error++;
  293. }
  294. }
  295. }
  296. else
  297. {
  298. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  299. $error++;
  300. }
  301. if (!$error)
  302. {
  303. $db->commit();
  304. header("Location: card.php?id=".$object->id);
  305. exit;
  306. }
  307. else
  308. {
  309. $db->rollback();
  310. $_GET["commande_id"] = GETPOST('commande_id', 'int');
  311. $action = 'create';
  312. }
  313. }
  314. elseif ($action == 'confirm_valid' && $confirm == 'yes' &&
  315. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
  316. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))
  317. )
  318. {
  319. $object->fetch_thirdparty();
  320. $result = $object->valid($user);
  321. if ($result < 0)
  322. {
  323. $langs->load("errors");
  324. setEventMessages($langs->trans($object->error), null, 'errors');
  325. }
  326. else
  327. {
  328. // Define output language
  329. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  330. {
  331. $outputlangs = $langs;
  332. $newlang = '';
  333. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  334. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  335. if (!empty($newlang)) {
  336. $outputlangs = new Translate("", $conf);
  337. $outputlangs->setDefaultLang($newlang);
  338. }
  339. $model = $object->modelpdf;
  340. $ret = $object->fetch($id); // Reload to get new records
  341. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  342. if ($result < 0) dol_print_error($db, $result);
  343. }
  344. }
  345. }
  346. elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer)
  347. {
  348. $result = $object->delete($user);
  349. if ($result > 0)
  350. {
  351. header("Location: ".DOL_URL_ROOT.'/reception/index.php');
  352. exit;
  353. }
  354. else
  355. {
  356. setEventMessages($object->error, $object->errors, 'errors');
  357. }
  358. }
  359. // TODO add alternative status
  360. /*elseif ($action == 'reopen' && (! empty($user->rights->reception->creer) || ! empty($user->rights->reception->reception_advance->validate)))
  361. {
  362. $result = $object->setStatut(0);
  363. if ($result < 0)
  364. {
  365. setEventMessages($object->error, $object->errors, 'errors');
  366. }
  367. }*/
  368. elseif ($action == 'setdate_livraison' && $user->rights->reception->creer)
  369. {
  370. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  371. $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
  372. $object->fetch($id);
  373. $result = $object->set_date_livraison($user, $datedelivery);
  374. if ($result < 0)
  375. {
  376. setEventMessages($object->error, $object->errors, 'errors');
  377. }
  378. }
  379. // Action update
  380. elseif ($action == 'settracking_number' || $action == 'settracking_url'
  381. || $action == 'settrueWeight'
  382. || $action == 'settrueWidth'
  383. || $action == 'settrueHeight'
  384. || $action == 'settrueDepth'
  385. || $action == 'setshipping_method_id')
  386. {
  387. $error = 0;
  388. if ($action == 'settracking_number') $object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
  389. if ($action == 'settracking_url') $object->tracking_url = trim(GETPOST('tracking_url', 'int'));
  390. if ($action == 'settrueWeight') {
  391. $object->trueWeight = trim(GETPOST('trueWeight', 'int'));
  392. $object->weight_units = GETPOST('weight_units', 'int');
  393. }
  394. if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth', 'int'));
  395. if ($action == 'settrueHeight') {
  396. $object->trueHeight = trim(GETPOST('trueHeight', 'int'));
  397. $object->size_units = GETPOST('size_units', 'int');
  398. }
  399. if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth', 'int'));
  400. if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int'));
  401. if (!$error)
  402. {
  403. if ($object->update($user) >= 0)
  404. {
  405. header("Location: card.php?id=".$object->id);
  406. exit;
  407. }
  408. setEventMessages($object->error, $object->errors, 'errors');
  409. }
  410. $action = "";
  411. }
  412. // Build document
  413. elseif ($action == 'builddoc') // En get ou en post
  414. {
  415. // Save last template used to generate document
  416. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model', 'alpha'));
  417. // Define output language
  418. $outputlangs = $langs;
  419. $newlang = '';
  420. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  421. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $reception->thirdparty->default_lang;
  422. if (!empty($newlang))
  423. {
  424. $outputlangs = new Translate("", $conf);
  425. $outputlangs->setDefaultLang($newlang);
  426. }
  427. $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  428. if ($result <= 0)
  429. {
  430. setEventMessages($object->error, $object->errors, 'errors');
  431. $action = '';
  432. }
  433. }
  434. // Delete file in doc form
  435. elseif ($action == 'remove_file')
  436. {
  437. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  438. $upload_dir = $conf->reception->dir_output;
  439. $file = $upload_dir.'/'.GETPOST('file');
  440. $ret = dol_delete_file($file, 0, 0, 0, $object);
  441. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  442. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  443. }
  444. elseif ($action == 'classifybilled')
  445. {
  446. $object->fetch($id);
  447. $result = $object->set_billed();
  448. if ($result >= 0) {
  449. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  450. exit();
  451. }
  452. }
  453. elseif ($action == 'classifyclosed')
  454. {
  455. $object->fetch($id);
  456. $result = $object->setClosed();
  457. if ($result >= 0) {
  458. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  459. exit();
  460. }
  461. }
  462. /*
  463. * delete a line
  464. */
  465. elseif ($action == 'deleteline' && !empty($line_id))
  466. {
  467. $object->fetch($id);
  468. $lines = $object->lines;
  469. $line = new CommandeFournisseurDispatch($db);
  470. $num_prod = count($lines);
  471. for ($i = 0; $i < $num_prod; $i++)
  472. {
  473. if ($lines[$i]->id == $line_id)
  474. {
  475. // delete single warehouse line
  476. $line->id = $line_id;
  477. if (!$error && $line->delete($user) < 0)
  478. {
  479. $error++;
  480. }
  481. }
  482. unset($_POST["lineid"]);
  483. }
  484. if (!$error) {
  485. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  486. exit();
  487. }
  488. else
  489. {
  490. setEventMessages($line->error, $line->errors, 'errors');
  491. }
  492. }
  493. /*
  494. * Update a line
  495. */
  496. elseif ($action == 'updateline' && $user->rights->reception->creer && GETPOST('save'))
  497. {
  498. // Clean parameters
  499. $qty = 0;
  500. $entrepot_id = 0;
  501. $batch_id = 0;
  502. $lines = $object->lines;
  503. $num_prod = count($lines);
  504. for ($i = 0; $i < $num_prod; $i++)
  505. {
  506. if ($lines[$i]->id == $line_id) // we have found line to update
  507. {
  508. $line = new CommandeFournisseurDispatch($db);
  509. $line->fetch($line_id);
  510. // Extrafields Lines
  511. $extrafields->fetch_name_optionals_label($object->table_element_line);
  512. $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  513. $line->fk_product = $lines[$i]->fk_product;
  514. if ($lines[$i]->fk_product > 0)
  515. {
  516. // single warehouse reception line
  517. $stockLocation = "entl".$line_id;
  518. $qty = "qtyl".$line_id;
  519. $comment = "comment".$line_id;
  520. $line->id = $line_id;
  521. $line->fk_entrepot = GETPOST($stockLocation, 'int');
  522. $line->qty = GETPOST($qty, 'int');
  523. $line->comment = GETPOST($comment, 'alpha');
  524. if (!empty($conf->productbatch->enabled)) {
  525. $batch = "batch".$line_id;
  526. $dlc = "dlc".$line_id;
  527. $dluo = "dluo".$line_id;
  528. $eatby = GETPOST($dlc, 'alpha');
  529. $eatbydate = str_replace('/', '-', $eatby);
  530. $sellby = GETPOST($dluo, 'alpha');
  531. $sellbydate = str_replace('/', '-', $sellby);
  532. $line->batch = GETPOST($batch, 'alpha');
  533. $line->eatby = strtotime($eatbydate);
  534. $line->sellby = strtotime($sellbydate);
  535. }
  536. if ($line->update($user) < 0)
  537. {
  538. setEventMessages($line->error, $line->errors, 'errors');
  539. $error++;
  540. }
  541. }
  542. else // Product no predefined
  543. {
  544. $qty = "qtyl".$line_id;
  545. $line->id = $line_id;
  546. $line->qty = GETPOST($qty, 'int');
  547. $line->fk_entrepot = 0;
  548. if ($line->update($user) < 0)
  549. {
  550. setEventMessages($line->error, $line->errors, 'errors');
  551. $error++;
  552. }
  553. unset($_POST[$qty]);
  554. }
  555. }
  556. }
  557. unset($_POST["lineid"]);
  558. if (!$error) {
  559. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  560. // Define output language
  561. $outputlangs = $langs;
  562. $newlang = '';
  563. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09'))
  564. $newlang = GETPOST('lang_id', 'aZ09');
  565. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  566. $newlang = $object->thirdparty->default_lang;
  567. if (!empty($newlang)) {
  568. $outputlangs = new Translate("", $conf);
  569. $outputlangs->setDefaultLang($newlang);
  570. }
  571. $ret = $object->fetch($object->id); // Reload to get new records
  572. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  573. }
  574. }
  575. else
  576. {
  577. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
  578. exit();
  579. }
  580. } elseif ($action == 'updateline' && $user->rights->reception->creer && GETPOST('cancel', 'alpha') == $langs->trans('Cancel')) {
  581. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
  582. exit();
  583. }
  584. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  585. // Actions to send emails
  586. if (empty($id)) $id = $facid;
  587. $triggersendname = 'RECEPTION_SENTBYMAIL';
  588. $paramname = 'id';
  589. $mode = 'emailfromreception';
  590. $trackid = 'shi'.$object->id;
  591. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  592. }
  593. /*
  594. * View
  595. */
  596. llxHeader('', $langs->trans('Reception'), 'Reception');
  597. $form = new Form($db);
  598. $formfile = new FormFile($db);
  599. $formproduct = new FormProduct($db);
  600. if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  601. $product_static = new Product($db);
  602. $reception_static = new Reception($db);
  603. $warehousestatic = new Entrepot($db);
  604. if ($action == 'create2')
  605. {
  606. print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert');
  607. print '<br>'.$langs->trans("ReceptionCreationIsDoneFromOrder");
  608. $action = ''; $id = ''; $ref = '';
  609. }
  610. // Mode creation.
  611. if ($action == 'create')
  612. {
  613. $recept = new Reception($db);
  614. print load_fiche_titre($langs->trans("CreateReception"));
  615. if (!$origin)
  616. {
  617. setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
  618. }
  619. if ($origin)
  620. {
  621. if ($origin == 'supplierorder')$classname = 'CommandeFournisseur';
  622. else $classname = ucfirst($origin);
  623. $object = new $classname($db);
  624. if ($object->fetch($origin_id)) // This include the fetch_lines
  625. {
  626. $soc = new Societe($db);
  627. $soc->fetch($object->socid);
  628. $author = new User($db);
  629. $author->fetch($object->user_author_id);
  630. if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
  631. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  632. print '<input type="hidden" name="token" value="'.newToken().'">';
  633. print '<input type="hidden" name="action" value="add">';
  634. print '<input type="hidden" name="origin" value="'.$origin.'">';
  635. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  636. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  637. if (GETPOST('entrepot_id', 'int'))
  638. {
  639. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';
  640. }
  641. dol_fiche_head('');
  642. print '<table class="border centpercent">';
  643. // Ref
  644. print '<tr><td class="titlefieldcreate fieldrequired">';
  645. if ($origin == 'supplierorder' && !empty($conf->fournisseur->enabled))
  646. {
  647. print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref;
  648. }
  649. if ($origin == 'propal' && !empty($conf->propal->enabled))
  650. {
  651. print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref;
  652. }
  653. print '</a></td>';
  654. print "</tr>\n";
  655. // Ref client
  656. print '<tr><td>';
  657. if ($origin == 'supplier_order') print $langs->trans('SupplierOrder');
  658. else print $langs->trans('RefSupplier');
  659. print '</td><td colspan="3">';
  660. print '<input type="text" name="ref_supplier" value="'.$object->ref_supplier.'" />';
  661. print '</td>';
  662. print '</tr>';
  663. // Tiers
  664. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
  665. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  666. print '</tr>';
  667. // Project
  668. if (!empty($conf->projet->enabled))
  669. {
  670. $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0;
  671. if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project;
  672. if ($origin == 'project') $projectid = ($originid ? $originid : 0);
  673. $langs->load("projects");
  674. print '<tr>';
  675. print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
  676. $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);
  677. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="valignmiddle text-plus-circle">'.$langs->trans("AddProject").'</span><span class="fa fa-plus-circle valignmiddle"></span></a>';
  678. print '</td>';
  679. print '</tr>';
  680. }
  681. // Date delivery planned
  682. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  683. print '<td colspan="3">';
  684. //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
  685. $date_delivery = ($date_delivery ? $date_delivery : $object->date_livraison); // $date_delivery comes from GETPOST
  686. print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
  687. print "</td>\n";
  688. print '</tr>';
  689. // Note Public
  690. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  691. print '<td colspan="3">';
  692. $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  693. print $doleditor->Create(1);
  694. print "</td></tr>";
  695. // Note Private
  696. if ($object->note_private && !$user->socid)
  697. {
  698. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  699. print '<td colspan="3">';
  700. $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  701. print $doleditor->Create(1);
  702. print "</td></tr>";
  703. }
  704. // Weight
  705. print '<tr><td>';
  706. print $langs->trans("Weight");
  707. print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';
  708. $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2);
  709. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  710. print $form->textwithpicto($text, $htmltext);
  711. print '</td></tr>';
  712. // Dim
  713. print '<tr><td>';
  714. print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
  715. print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW', 'int').'">';
  716. print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH', 'int').'">';
  717. print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS', 'int').'">';
  718. print ' ';
  719. $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2);
  720. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  721. print $form->textwithpicto($text, $htmltext);
  722. print '</td></tr>';
  723. // Delivery method
  724. print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
  725. print '<td colspan="3">';
  726. $recept->fetch_delivery_methods();
  727. print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);
  728. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  729. print "</td></tr>\n";
  730. // Tracking number
  731. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  732. print '<td colspan="3">';
  733. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
  734. print "</td></tr>\n";
  735. // Other attributes
  736. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid'=>$socid);
  737. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $object may have been modified by hook
  738. print $hookmanager->resPrint;
  739. // Here $object can be of an object Order
  740. $extrafields->fetch_name_optionals_label($object->table_element);
  741. if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
  742. // copy from order
  743. if ($object->fetch_optionals() > 0) {
  744. $recept->array_options = array_merge($recept->array_options, $object->array_options);
  745. }
  746. print $object->showOptionals($extrafields, 'edit', $parameters);
  747. }
  748. // Incoterms
  749. if (!empty($conf->incoterm->enabled))
  750. {
  751. print '<tr>';
  752. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
  753. print '<td colspan="3" class="maxwidthonsmartphone">';
  754. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  755. print '</td></tr>';
  756. }
  757. // Document model
  758. include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  759. $liste = ModelePdfReception::liste_modeles($db);
  760. if (count($liste) > 1)
  761. {
  762. print "<tr><td>".$langs->trans("DefaultModel")."</td>";
  763. print '<td colspan="3">';
  764. print $form->selectarray('model', $liste, $conf->global->RECEPTION_ADDON_PDF);
  765. print "</td></tr>\n";
  766. }
  767. print "</table>";
  768. dol_fiche_end();
  769. // Reception lines
  770. $numAsked = 0;
  771. $dispatchLines = array();
  772. foreach ($_POST as $key => $value)
  773. {
  774. // without batch module enabled
  775. if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
  776. {
  777. $numAsked++;
  778. // $numline=$reg[2] + 1; // line of product
  779. $numline = $numAsked;
  780. $prod = "product_".$reg[1].'_'.$reg[2];
  781. $qty = "qty_".$reg[1].'_'.$reg[2];
  782. $ent = "entrepot_".$reg[1].'_'.$reg[2];
  783. $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
  784. $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
  785. $dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
  786. }
  787. // with batch module enabled
  788. if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
  789. {
  790. $numAsked++;
  791. // eat-by date dispatch
  792. // $numline=$reg[2] + 1; // line of product
  793. $numline = $numAsked;
  794. $prod = 'product_batch_'.$reg[1].'_'.$reg[2];
  795. $qty = 'qty_'.$reg[1].'_'.$reg[2];
  796. $ent = 'entrepot_'.$reg[1].'_'.$reg[2];
  797. $pu = 'pu_'.$reg[1].'_'.$reg[2];
  798. $lot = 'lot_number_'.$reg[1].'_'.$reg[2];
  799. $dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']);
  800. $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']);
  801. $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
  802. $dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
  803. }
  804. }
  805. print '<script type="text/javascript" language="javascript">
  806. jQuery(document).ready(function() {
  807. jQuery("#autofill").click(function() {';
  808. $i = 1;
  809. while ($i <= $numAsked)
  810. {
  811. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  812. $i++;
  813. }
  814. print '});
  815. jQuery("#autoreset").click(function() {';
  816. $i = 1;
  817. while ($i <= $numAsked)
  818. {
  819. print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
  820. $i++;
  821. }
  822. print '});
  823. });
  824. </script>';
  825. print '<br>';
  826. print '<table class="noborder centpercent">';
  827. // Load receptions already done for same order
  828. $object->loadReceptions();
  829. if ($numAsked)
  830. {
  831. print '<tr class="liste_titre">';
  832. print '<td>'.$langs->trans("Description").'</td>';
  833. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  834. print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
  835. print '<td class="center">'.$langs->trans("QtyToReceive");
  836. if (empty($conf->productbatch->enabled))
  837. {
  838. print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
  839. print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
  840. }
  841. print '</td>';
  842. if (!empty($conf->stock->enabled))
  843. {
  844. print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
  845. }
  846. if (!empty($conf->productbatch->enabled))
  847. {
  848. print '<td class="left">'.$langs->trans("batch_number").'</td>';
  849. print '<td class="left">'.$langs->trans("EatByDate").'</td>';
  850. print '<td class="left">'.$langs->trans("SellByDate").'</td>';
  851. }
  852. print "</tr>\n";
  853. }
  854. $indiceAsked = 1;
  855. while ($indiceAsked <= $numAsked)
  856. {
  857. $product = new Product($db);
  858. foreach ($object->lines as $supplierLine) {
  859. if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
  860. $line = $supplierLine;
  861. break;
  862. }
  863. }
  864. // Show product and description
  865. $type = $line->product_type ? $line->product_type : $line->fk_product_type;
  866. // Try to enhance type detection using date_start and date_end for free lines where type
  867. // was not saved.
  868. if (!empty($line->date_start)) $type = 1;
  869. if (!empty($line->date_end)) $type = 1;
  870. print '<!-- line '.$line->rowid.' for product -->'."\n";
  871. print '<tr class="oddeven">'."\n";
  872. // Product label
  873. if ($line->fk_product > 0) // If predefined product
  874. {
  875. $product->fetch($line->fk_product);
  876. $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
  877. //var_dump($product->stock_warehouse[1]);
  878. print '<td>';
  879. print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
  880. // Show product and description
  881. $product_static->type = $line->fk_product_type;
  882. $product_static->id = $line->fk_product;
  883. $product_static->ref = $line->ref;
  884. $product_static->status_batch = $line->product_tobatch;
  885. $text = $product_static->getNomUrl(1);
  886. $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
  887. $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->desc));
  888. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  889. // Show range
  890. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  891. // Add description in form
  892. if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
  893. {
  894. print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
  895. }
  896. print '</td>';
  897. }
  898. else
  899. {
  900. print "<td>";
  901. if ($type == 1) $text = img_object($langs->trans('Service'), 'service');
  902. else $text = img_object($langs->trans('Product'), 'product');
  903. if (!empty($line->label)) {
  904. $text .= ' <strong>'.$line->label.'</strong>';
  905. print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);
  906. } else {
  907. print $text.' '.nl2br($line->desc);
  908. }
  909. // Show range
  910. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  911. print "</td>\n";
  912. }
  913. // Qty
  914. print '<td class="center">'.$line->qty;
  915. print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value=\''.$line->id.'\' />';
  916. print '<textarea style="display:none;" name="comment'.$indiceAsked.'" >'.$line->desc.'</textarea>';
  917. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  918. print '</td>';
  919. $qtyProdCom = $line->qty;
  920. // Qty already received
  921. print '<td class="center">';
  922. $quantityDelivered = $object->receptions[$line->id];
  923. print $quantityDelivered;
  924. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  925. print '</td>';
  926. if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
  927. {
  928. $quantityToBeDelivered = 0;
  929. }
  930. else
  931. {
  932. $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
  933. }
  934. $warehouse_id = $dispatchLines[$indiceAsked]['ent'];
  935. $warehouseObject = null;
  936. if (!empty($conf->stock->enabled)) // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
  937. {
  938. print '<!-- Case warehouse already known or product not a predefined product -->';
  939. $stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
  940. $deliverableQty = $dispatchLines[$indiceAsked]['qty'];
  941. // Quantity to send
  942. print '<td class="center">';
  943. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))
  944. {
  945. if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty = GETPOST('qtyl'.$indiceAsked, 'int');
  946. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  947. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  948. }
  949. else print $langs->trans("NA");
  950. print '</td>';
  951. // Stock
  952. if (!empty($conf->stock->enabled))
  953. {
  954. print '<td class="left">';
  955. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Type of product need stock change ?
  956. {
  957. // Show warehouse combo list
  958. $ent = "entl".$indiceAsked;
  959. $idl = "idl".$indiceAsked;
  960. $tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : $warehouse_id;
  961. if ($line->fk_product > 0)
  962. {
  963. print '<!-- Show warehouse selection -->';
  964. print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
  965. }
  966. }
  967. else
  968. {
  969. print $langs->trans("Service");
  970. }
  971. print '</td>';
  972. }
  973. if (!empty($conf->productbatch->enabled))
  974. {
  975. if (!empty($product->status_batch))
  976. {
  977. print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
  978. print '<td>';
  979. print $form->selectDate($dispatchLines[$indiceAsked]['DLC'], 'dlc'.$indiceAsked, '', '', 1, "");
  980. print '</td>';
  981. print '<td>';
  982. print $form->selectDate($dispatchLines[$indiceAsked]['DLUO'], 'dluo'.$indiceAsked, '', '', 1, "");
  983. print '</td>';
  984. }
  985. else {
  986. print '<td colspan="3"></td>';
  987. }
  988. }
  989. print "</tr>\n";
  990. }
  991. //Display lines extrafields
  992. if (is_array($extralabelslines) && count($extralabelslines) > 0)
  993. {
  994. $colspan = 5;
  995. if ($conf->productbatch->enabled) $colspan += 3;
  996. $srcLine = new CommandeFournisseurLigne($db);
  997. $line = new CommandeFournisseurDispatch($db);
  998. $extrafields->fetch_name_optionals_label($srcLine->table_element);
  999. $extrafields->fetch_name_optionals_label($line->table_element);
  1000. $srcLine->id = $line->id;
  1001. $srcLine->fetch_optionals(); // fetch extrafields also available in orderline
  1002. $line->fetch_optionals();
  1003. $line->array_options = array_merge($line->array_options, $srcLine->array_options);
  1004. print $line->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), $indiceAsked);
  1005. }
  1006. $indiceAsked++;
  1007. }
  1008. print "</table>";
  1009. print '<br>';
  1010. print '<div class="center">';
  1011. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  1012. print '&nbsp; ';
  1013. 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
  1014. print '</div>';
  1015. print '</form>';
  1016. print '<br>';
  1017. }
  1018. else
  1019. {
  1020. dol_print_error($db);
  1021. }
  1022. }
  1023. }
  1024. elseif ($id || $ref)
  1025. /* *************************************************************************** */
  1026. /* */
  1027. /* Edit and view mode */
  1028. /* */
  1029. /* *************************************************************************** */
  1030. {
  1031. $lines = $object->lines;
  1032. $num_prod = count($lines);
  1033. if ($object->id > 0)
  1034. {
  1035. if (!empty($object->origin) && $object->origin_id > 0)
  1036. {
  1037. $object->origin = 'CommandeFournisseur';
  1038. $typeobject = $object->origin;
  1039. $origin = $object->origin;
  1040. $origin_id = $object->origin_id;
  1041. $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
  1042. }
  1043. $soc = new Societe($db);
  1044. $soc->fetch($object->socid);
  1045. $res = $object->fetch_optionals();
  1046. $head = reception_prepare_head($object);
  1047. dol_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'dollyrevert');
  1048. $formconfirm = '';
  1049. // Confirm deleteion
  1050. if ($action == 'delete')
  1051. {
  1052. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteReception'), $langs->trans("ConfirmDeleteReception", $object->ref), 'confirm_delete', '', 0, 1);
  1053. }
  1054. // Confirmation validation
  1055. if ($action == 'valid')
  1056. {
  1057. $objectref = substr($object->ref, 1, 4);
  1058. if ($objectref == 'PROV')
  1059. {
  1060. $numref = $object->getNextNumRef($soc);
  1061. }
  1062. else
  1063. {
  1064. $numref = $object->ref;
  1065. }
  1066. $text = $langs->trans("ConfirmValidateReception", $numref);
  1067. if (!empty($conf->notification->enabled))
  1068. {
  1069. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  1070. $notify = new Notify($db);
  1071. $text .= '<br>';
  1072. $text .= $notify->confirmMessage('RECEPTION_VALIDATE', $object->socid, $object);
  1073. }
  1074. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateReception'), $text, 'confirm_valid', '', 0, 1);
  1075. }
  1076. // Confirm cancelation
  1077. if ($action == 'annuler')
  1078. {
  1079. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelReception'), $langs->trans("ConfirmCancelReception", $object->ref), 'confirm_cancel', '', 0, 1);
  1080. }
  1081. if (!$formconfirm) {
  1082. $parameters = array('formConfirm' => $formconfirm);
  1083. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1084. if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
  1085. elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
  1086. }
  1087. // Print form confirm
  1088. print $formconfirm;
  1089. // Calculate totalWeight and totalVolume for all products
  1090. // by adding weight and volume of each product line.
  1091. $tmparray = $object->getTotalWeightVolume();
  1092. $totalWeight = $tmparray['weight'];
  1093. $totalVolume = $tmparray['volume'];
  1094. if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
  1095. {
  1096. $objectsrc = new Commande($db);
  1097. $objectsrc->fetch($object->$typeobject->id);
  1098. }
  1099. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
  1100. {
  1101. $objectsrc = new Propal($db);
  1102. $objectsrc->fetch($object->$typeobject->id);
  1103. }
  1104. if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && !empty($conf->fournisseur->enabled))
  1105. {
  1106. $objectsrc = new CommandeFournisseur($db);
  1107. $objectsrc->fetch($object->$typeobject->id);
  1108. }
  1109. // Reception card
  1110. $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  1111. $morehtmlref = '<div class="refidno">';
  1112. // Ref customer reception
  1113. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
  1114. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
  1115. // Thirdparty
  1116. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  1117. // Project
  1118. if (!empty($conf->projet->enabled))
  1119. {
  1120. $langs->load("projects");
  1121. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  1122. if (0) { // Do not change on reception
  1123. if ($action != 'classify') {
  1124. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  1125. }
  1126. if ($action == 'classify') {
  1127. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  1128. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  1129. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  1130. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  1131. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  1132. $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  1133. $morehtmlref .= '</form>';
  1134. } else {
  1135. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  1136. }
  1137. } else {
  1138. // We don't have project on reception, so we will use the project or source object instead
  1139. // TODO Add project on reception
  1140. $morehtmlref .= ' : ';
  1141. if (!empty($objectsrc->fk_project)) {
  1142. $proj = new Project($db);
  1143. $proj->fetch($objectsrc->fk_project);
  1144. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  1145. $morehtmlref .= $proj->ref;
  1146. $morehtmlref .= '</a>';
  1147. } else {
  1148. $morehtmlref .= '';
  1149. }
  1150. }
  1151. }
  1152. $morehtmlref .= '</div>';
  1153. $object->picto = 'sending';
  1154. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1155. print '<div class="fichecenter">';
  1156. print '<div class="fichehalfleft">';
  1157. print '<div class="underbanner clearboth"></div>';
  1158. print '<table class="border centpercent">';
  1159. // Linked documents
  1160. if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
  1161. {
  1162. print '<tr><td>';
  1163. print $langs->trans("RefOrder").'</td>';
  1164. print '<td colspan="3">';
  1165. print $objectsrc->getNomUrl(1, 'commande');
  1166. print "</td>\n";
  1167. print '</tr>';
  1168. }
  1169. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
  1170. {
  1171. print '<tr><td>';
  1172. print $langs->trans("RefProposal").'</td>';
  1173. print '<td colspan="3">';
  1174. print $objectsrc->getNomUrl(1, 'reception');
  1175. print "</td>\n";
  1176. print '</tr>';
  1177. }
  1178. if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && !empty($conf->propal->enabled))
  1179. {
  1180. print '<tr><td>';
  1181. print $langs->trans("SupplierOrder").'</td>';
  1182. print '<td colspan="3">';
  1183. print $objectsrc->getNomUrl(1, 'reception');
  1184. print "</td>\n";
  1185. print '</tr>';
  1186. }
  1187. // Date creation
  1188. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  1189. print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour")."</td>\n";
  1190. print '</tr>';
  1191. // Delivery date planned
  1192. print '<tr><td height="10">';
  1193. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1194. print $langs->trans('DateDeliveryPlanned');
  1195. print '</td>';
  1196. if ($action != 'editdate_livraison') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
  1197. print '</tr></table>';
  1198. print '</td><td colspan="2">';
  1199. if ($action == 'editdate_livraison')
  1200. {
  1201. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1202. print '<input type="hidden" name="token" value="'.newToken().'">';
  1203. print '<input type="hidden" name="action" value="setdate_livraison">';
  1204. print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
  1205. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1206. print '</form>';
  1207. }
  1208. else
  1209. {
  1210. print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
  1211. }
  1212. print '</td>';
  1213. print '</tr>';
  1214. // Weight
  1215. print '<tr><td>';
  1216. print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->rights->reception->creer);
  1217. print '</td><td colspan="3">';
  1218. if ($action == 'edittrueWeight')
  1219. {
  1220. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1221. print '<input name="action" value="settrueWeight" type="hidden">';
  1222. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1223. print '<input type="hidden" name="token" value="'.newToken().'">';
  1224. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
  1225. print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2);
  1226. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1227. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1228. print '</form>';
  1229. }
  1230. else
  1231. {
  1232. print $object->trueWeight;
  1233. print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
  1234. }
  1235. // Calculated
  1236. if ($totalWeight > 0)
  1237. {
  1238. if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
  1239. print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no');
  1240. if (!empty($object->trueWeight)) print ')';
  1241. }
  1242. print '</td></tr>';
  1243. // Width
  1244. print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->reception->creer).'</td><td colspan="3">';
  1245. print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->reception->creer);
  1246. print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';
  1247. print '</td></tr>';
  1248. // Height
  1249. print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->rights->reception->creer).'</td><td colspan="3">';
  1250. if ($action == 'edittrueHeight')
  1251. {
  1252. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1253. print '<input name="action" value="settrueHeight" type="hidden">';
  1254. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1255. print '<input type="hidden" name="token" value="'.newToken().'">';
  1256. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
  1257. print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
  1258. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1259. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1260. print '</form>';
  1261. }
  1262. else
  1263. {
  1264. print $object->trueHeight;
  1265. print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';
  1266. }
  1267. print '</td></tr>';
  1268. // Depth
  1269. print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->reception->creer).'</td><td colspan="3">';
  1270. print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->reception->creer);
  1271. print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';
  1272. print '</td></tr>';
  1273. // Volume
  1274. print '<tr><td>';
  1275. print $langs->trans("Volume");
  1276. print '</td>';
  1277. print '<td colspan="3">';
  1278. $calculatedVolume = 0;
  1279. $volumeUnit = 0;
  1280. if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  1281. {
  1282. $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1283. $volumeUnit = $object->size_units * 3;
  1284. }
  1285. // If reception volume not defined we use sum of products
  1286. if ($calculatedVolume > 0)
  1287. {
  1288. if ($volumeUnit < 50)
  1289. {
  1290. print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
  1291. }
  1292. else print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);
  1293. }
  1294. if ($totalVolume > 0)
  1295. {
  1296. if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1297. print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no');
  1298. //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
  1299. if ($calculatedVolume) print ')';
  1300. }
  1301. print "</td>\n";
  1302. print '</tr>';
  1303. // Other attributes
  1304. $cols = 2;
  1305. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1306. print '</table>';
  1307. print '</div>';
  1308. print '<div class="fichehalfright">';
  1309. print '<div class="ficheaddleft">';
  1310. print '<div class="underbanner clearboth"></div>';
  1311. print '<table class="border centpercent">';
  1312. // Reception method
  1313. print '<tr><td height="10">';
  1314. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1315. print $langs->trans('ReceptionMethod');
  1316. print '</td>';
  1317. if ($action != 'editshipping_method_id') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'), 1).'</a></td>';
  1318. print '</tr></table>';
  1319. print '</td><td colspan="2">';
  1320. if ($action == 'editshipping_method_id')
  1321. {
  1322. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1323. print '<input type="hidden" name="token" value="'.newToken().'">';
  1324. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1325. $object->fetch_delivery_methods();
  1326. print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
  1327. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1328. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1329. print '</form>';
  1330. }
  1331. else
  1332. {
  1333. if ($object->shipping_method_id > 0)
  1334. {
  1335. // Get code using getLabelFromKey
  1336. $code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  1337. print $langs->trans("SendingMethod".strtoupper($code));
  1338. }
  1339. }
  1340. print '</td>';
  1341. print '</tr>';
  1342. // Tracking Number
  1343. print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->rights->reception->creer).'</td><td colspan="3">';
  1344. print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->rights->reception->creer, 'string', $object->tracking_number);
  1345. print '</td></tr>';
  1346. // Incoterms
  1347. if (!empty($conf->incoterm->enabled))
  1348. {
  1349. print '<tr><td>';
  1350. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1351. print $langs->trans('IncotermLabel');
  1352. print '<td><td class="right">';
  1353. if ($user->rights->reception->creer) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
  1354. else print '&nbsp;';
  1355. print '</td></tr></table>';
  1356. print '</td>';
  1357. print '<td colspan="3">';
  1358. if ($action != 'editincoterm')
  1359. {
  1360. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  1361. }
  1362. else
  1363. {
  1364. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1365. }
  1366. print '</td></tr>';
  1367. }
  1368. print "</table>";
  1369. print '</div>';
  1370. print '</div>';
  1371. print '</div>';
  1372. print '<div class="clearboth"></div>';
  1373. // Lines of products
  1374. if ($action == 'editline')
  1375. {
  1376. print '<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
  1377. <input type="hidden" name="token" value="' . newToken().'">
  1378. <input type="hidden" name="action" value="updateline">
  1379. <input type="hidden" name="mode" value="">
  1380. <input type="hidden" name="id" value="' . $object->id.'">';
  1381. }
  1382. print '<br>';
  1383. print '<div class="div-table-responsive-no-min">';
  1384. print '<table class="noborder centpercent">';
  1385. print '<tr class="liste_titre">';
  1386. // #
  1387. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1388. {
  1389. print '<td width="5" class="center">&nbsp;</td>';
  1390. }
  1391. // Product/Service
  1392. print '<td>'.$langs->trans("Products").'</td>';
  1393. // Comment
  1394. print '<td>'.$langs->trans("Description").'</td>';
  1395. // Qty
  1396. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  1397. if ($origin && $origin_id > 0)
  1398. {
  1399. print '<td class="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
  1400. }
  1401. if ($action == 'editline')
  1402. {
  1403. $editColspan = 3;
  1404. if (empty($conf->stock->enabled)) $editColspan--;
  1405. if (empty($conf->productbatch->enabled)) $editColspan--;
  1406. print '<td class="center" colspan="'.$editColspan.'">';
  1407. if ($object->statut <= 1)
  1408. {
  1409. print $langs->trans("QtyToReceive").' - ';
  1410. }
  1411. else
  1412. {
  1413. print $langs->trans("QtyReceived").' - ';
  1414. }
  1415. if (!empty($conf->stock->enabled))
  1416. {
  1417. print $langs->trans("WarehouseSource").' - ';
  1418. }
  1419. if (!empty($conf->productbatch->enabled))
  1420. {
  1421. print $langs->trans("Batch");
  1422. }
  1423. print '</td>';
  1424. }
  1425. else
  1426. {
  1427. if ($object->statut <= 1)
  1428. {
  1429. print '<td class="center">'.$langs->trans("QtyToReceive").'</td>';
  1430. }
  1431. else
  1432. {
  1433. print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
  1434. }
  1435. if (!empty($conf->stock->enabled))
  1436. {
  1437. print '<td class="left">'.$langs->trans("WarehouseSource").'</td>';
  1438. }
  1439. if (!empty($conf->productbatch->enabled))
  1440. {
  1441. print '<td class="left">'.$langs->trans("Batch").'</td>';
  1442. }
  1443. }
  1444. print '<td class="center">'.$langs->trans("CalculatedWeight").'</td>';
  1445. print '<td class="center">'.$langs->trans("CalculatedVolume").'</td>';
  1446. //print '<td class="center">'.$langs->trans("Size").'</td>';
  1447. if ($object->statut == 0)
  1448. {
  1449. print '<td class="linecoledit"></td>';
  1450. print '<td class="linecoldelete" width="10"></td>';
  1451. }
  1452. print "</tr>\n";
  1453. $var = false;
  1454. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1455. {
  1456. $object->fetch_thirdparty();
  1457. $outputlangs = $langs;
  1458. $newlang = '';
  1459. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  1460. if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
  1461. if (!empty($newlang))
  1462. {
  1463. $outputlangs = new Translate("", $conf);
  1464. $outputlangs->setDefaultLang($newlang);
  1465. }
  1466. }
  1467. // Get list of products already sent for same source object into $alreadysent
  1468. $alreadysent = array();
  1469. $origin = 'commande_fournisseur';
  1470. if ($origin && $origin_id > 0)
  1471. {
  1472. $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
  1473. $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot";
  1474. $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
  1475. //if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
  1476. $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
  1477. $sql .= ', p.description as product_desc';
  1478. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
  1479. $sql .= ", ".MAIN_DB_PREFIX."reception as e";
  1480. $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  1481. //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
  1482. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  1483. $sql .= " WHERE e.entity IN (".getEntity('reception').")";
  1484. $sql .= " AND obj.fk_commande = ".$origin_id;
  1485. $sql .= " AND obj.rowid = ed.fk_commandefourndet";
  1486. $sql .= " AND ed.fk_reception = e.rowid";
  1487. $sql .= " AND ed.fk_reception !=".$object->id;
  1488. //if ($filter) $sql.= $filter;
  1489. $sql .= " ORDER BY obj.fk_product";
  1490. dol_syslog("get list of reception lines", LOG_DEBUG);
  1491. $resql = $db->query($sql);
  1492. if ($resql)
  1493. {
  1494. $num = $db->num_rows($resql);
  1495. $i = 0;
  1496. while ($i < $num)
  1497. {
  1498. $obj = $db->fetch_object($resql);
  1499. if ($obj)
  1500. {
  1501. // $obj->rowid is rowid in $origin."det" table
  1502. $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
  1503. }
  1504. $i++;
  1505. }
  1506. }
  1507. //var_dump($alreadysent);
  1508. }
  1509. // Loop on each product to send/sent
  1510. for ($i = 0; $i < $num_prod; $i++)
  1511. {
  1512. print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
  1513. print '<tr class="oddeven">';
  1514. // #
  1515. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1516. {
  1517. print '<td class="center">'.($i + 1).'</td>';
  1518. }
  1519. // Predefined product or service
  1520. if ($lines[$i]->fk_product > 0)
  1521. {
  1522. // Define output language
  1523. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1524. {
  1525. $prod = new Product($db);
  1526. $prod->fetch($lines[$i]->fk_product);
  1527. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
  1528. }
  1529. else
  1530. $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label);
  1531. print '<td>';
  1532. $text = $lines[$i]->product->getNomUrl(1);
  1533. $text .= ' - '.$label;
  1534. $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($lines[$i]->product->description));
  1535. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  1536. print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
  1537. if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
  1538. {
  1539. print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
  1540. }
  1541. print "</td>\n";
  1542. }
  1543. else
  1544. {
  1545. print "<td>";
  1546. if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'), 'service');
  1547. else $text = img_object($langs->trans('Product'), 'product');
  1548. if (!empty($lines[$i]->label)) {
  1549. $text .= ' <strong>'.$lines[$i]->label.'</strong>';
  1550. print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);
  1551. } else {
  1552. print $text.' '.nl2br($lines[$i]->description);
  1553. }
  1554. print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
  1555. print "</td>\n";
  1556. }
  1557. if ($action == 'editline' && $lines[$i]->id == $line_id)
  1558. {
  1559. print '<td ><textarea name="comment'.$line_id.'" id="comment'.$line_id.'" /> '.$lines[$i]->comment.'</textarea></td>';
  1560. }
  1561. else
  1562. {
  1563. print '<td style="white-space: pre-wrap;max-width: 200px;" >'.$lines[$i]->comment.'</td>';
  1564. }
  1565. // Qty ordered
  1566. print '<td class="center">'.$lines[$i]->qty_asked.'</td>';
  1567. // Qty in other receptions (with reception and warehouse used)
  1568. if ($origin && $origin_id > 0)
  1569. {
  1570. print '<td class="center nowrap">';
  1571. foreach ($alreadysent as $key => $val)
  1572. {
  1573. if ($lines[$i]->fk_commandefourndet == $key)
  1574. {
  1575. $j = 0;
  1576. foreach ($val as $receptionline_id=> $receptionline_var)
  1577. {
  1578. if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions"
  1579. $j++;
  1580. if ($j > 1) print '<br>';
  1581. $reception_static->fetch($receptionline_var['reception_id']);
  1582. print $reception_static->getNomUrl(1);
  1583. print ' - '.$receptionline_var['qty'];
  1584. $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour'));
  1585. if (!empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0)
  1586. {
  1587. $warehousestatic->fetch($receptionline_var['warehouse']);
  1588. $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1);
  1589. }
  1590. print ' '.$form->textwithpicto('', $htmltext, 1);
  1591. }
  1592. }
  1593. }
  1594. }
  1595. print '</td>';
  1596. if ($action == 'editline' && $lines[$i]->id == $line_id)
  1597. {
  1598. // edit mode
  1599. print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding">';
  1600. if (!empty($conf->stock->enabled))
  1601. {
  1602. if ($lines[$i]->fk_product > 0)
  1603. {
  1604. print '<!-- case edit 1 -->';
  1605. print '<tr>';
  1606. // Qty to receive or received
  1607. print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
  1608. // Warehouse source
  1609. print '<td>'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
  1610. // Batch number managment
  1611. if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch))
  1612. {
  1613. print '<td> <input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"> </br>';
  1614. print $langs->trans('EatByDate').' : ';
  1615. print $form->selectDate($lines[$i]->eatby, 'dlc'.$line_id, '', '', 1, "").'</br>';
  1616. print $langs->trans('SellByDate').' : ';
  1617. print $form->selectDate($lines[$i]->sellby, 'dluo'.$line_id, '', '', 1, "");
  1618. print '</td>';
  1619. }
  1620. print '</tr>';
  1621. }
  1622. else
  1623. {
  1624. print '<!-- case edit 2 -->';
  1625. print '<tr>';
  1626. // Qty to receive or received
  1627. print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
  1628. // Warehouse source
  1629. print '<td></td>';
  1630. // Batch number managment
  1631. print '<td></td>';
  1632. print '</tr>';
  1633. }
  1634. }
  1635. print '</table></td>';
  1636. }
  1637. else
  1638. {
  1639. // Qty to receive or received
  1640. print '<td class="center">'.$lines[$i]->qty.'</td>';
  1641. // Warehouse source
  1642. if (!empty($conf->stock->enabled))
  1643. {
  1644. print '<td class="left">';
  1645. if ($lines[$i]->fk_entrepot > 0)
  1646. {
  1647. $entrepot = new Entrepot($db);
  1648. $entrepot->fetch($lines[$i]->fk_entrepot);
  1649. print $entrepot->getNomUrl(1);
  1650. }
  1651. print '</td>';
  1652. }
  1653. // Batch number managment
  1654. if (!empty($conf->productbatch->enabled))
  1655. {
  1656. if (isset($lines[$i]->batch))
  1657. {
  1658. print '<!-- Detail of lot -->';
  1659. print '<td>';
  1660. $detail = '';
  1661. if ($lines[$i]->product->status_batch)
  1662. {
  1663. $detail .= $langs->trans("Batch").': '.$lines[$i]->batch;
  1664. $detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day");
  1665. $detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");
  1666. $detail .= '<br>';
  1667. print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $detail);
  1668. }
  1669. else
  1670. {
  1671. print $langs->trans("NA");
  1672. }
  1673. print '</td>';
  1674. } else {
  1675. print '<td></td>';
  1676. }
  1677. }
  1678. }
  1679. // Weight
  1680. print '<td class="center">';
  1681. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units);
  1682. else print '&nbsp;';
  1683. print '</td>';
  1684. // Volume
  1685. print '<td class="center">';
  1686. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units);
  1687. else print '&nbsp;';
  1688. print '</td>';
  1689. if ($action == 'editline' && $lines[$i]->id == $line_id)
  1690. {
  1691. print '<td class="center" colspan="2" valign="middle">';
  1692. print '<input type="submit" class="button" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
  1693. print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
  1694. }
  1695. elseif ($object->statut == Reception::STATUS_DRAFT)
  1696. {
  1697. // edit-delete buttons
  1698. print '<td class="linecoledit center">';
  1699. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
  1700. print '</td>';
  1701. print '<td class="linecoldelete" width="10">';
  1702. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
  1703. print '</td>';
  1704. // Display lines extrafields
  1705. if (!empty($rowExtrafieldsStart))
  1706. {
  1707. print $rowExtrafieldsStart;
  1708. print $rowExtrafieldsView;
  1709. print $rowEnd;
  1710. }
  1711. }
  1712. print "</tr>";
  1713. // Display lines extrafields
  1714. if (is_array($extralabelslines) && count($extralabelslines) > 0)
  1715. {
  1716. $colspan = empty($conf->productbatch->enabled) ? 8 : 9;
  1717. $line = new CommandeFournisseurDispatch($db);
  1718. $line->id = $lines[$i]->id;
  1719. $line->fetch_optionals();
  1720. if ($action == 'editline' && $lines[$i]->id == $line_id)
  1721. {
  1722. print $line->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), $indiceAsked);
  1723. }
  1724. else
  1725. {
  1726. print $line->showOptionals($extrafields, 'view', array('colspan'=>$colspan), $indiceAsked);
  1727. }
  1728. }
  1729. }
  1730. // TODO Show also lines ordered but not delivered
  1731. print "</table>\n";
  1732. print '</div>';
  1733. }
  1734. dol_fiche_end();
  1735. $object->fetchObjectLinked($object->id, $object->element);
  1736. /*
  1737. * Boutons actions
  1738. */
  1739. if (($user->socid == 0) && ($action != 'presend'))
  1740. {
  1741. print '<div class="tabsAction">';
  1742. $parameters = array();
  1743. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1744. if (empty($reshook))
  1745. {
  1746. if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0)
  1747. {
  1748. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer))
  1749. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))
  1750. {
  1751. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
  1752. }
  1753. else
  1754. {
  1755. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
  1756. }
  1757. }
  1758. // Edit
  1759. if ($object->statut == Reception::STATUS_VALIDATED && $user->rights->reception->creer) {
  1760. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
  1761. }
  1762. // TODO add alternative status
  1763. // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
  1764. if ($object->statut == Reception::STATUS_CLOSED && $user->rights->reception->creer)
  1765. {
  1766. if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
  1767. {
  1768. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
  1769. }
  1770. else
  1771. {
  1772. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  1773. }
  1774. }
  1775. // Send
  1776. if (empty($user->socid)) {
  1777. if ($object->statut > 0)
  1778. {
  1779. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->reception->reception_advance->send)
  1780. {
  1781. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
  1782. }
  1783. else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
  1784. }
  1785. }
  1786. // Create bill
  1787. if (!empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED))
  1788. {
  1789. if ($user->rights->fournisseur->facture->creer)
  1790. {
  1791. // TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION))
  1792. // If we do that, we must also make this option official.
  1793. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  1794. }
  1795. }
  1796. // Close
  1797. if ($object->statut == Reception::STATUS_VALIDATED)
  1798. {
  1799. if ($user->rights->reception->creer && $object->statut > 0 && !$object->billed)
  1800. {
  1801. $label = "Close"; $paramaction = 'classifyclosed'; // = Transferred/Received
  1802. // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders
  1803. if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
  1804. {
  1805. $label = "ClassifyBilled";
  1806. $paramaction = 'classifybilled';
  1807. }
  1808. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
  1809. }
  1810. }
  1811. if ($user->rights->reception->supprimer)
  1812. {
  1813. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  1814. }
  1815. }
  1816. print '</div>';
  1817. }
  1818. /*
  1819. * Documents generated
  1820. */
  1821. if ($action != 'presend' && $action != 'editline')
  1822. {
  1823. print '<div class="fichecenter"><div class="fichehalfleft">';
  1824. $objectref = dol_sanitizeFileName($object->ref);
  1825. $filedir = $conf->reception->dir_output."/".$objectref;
  1826. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1827. $genallowed = $user->rights->reception->lire;
  1828. $delallowed = $user->rights->reception->creer;
  1829. print $formfile->showdocuments('reception', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  1830. // Show links to link elements
  1831. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  1832. $somethingshown = $form->showLinkedObjectBlock($object, '');
  1833. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  1834. }
  1835. if ($action == 'presend')
  1836. {
  1837. $ref = dol_sanitizeFileName($object->ref);
  1838. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1839. $fileparams = dol_most_recent_file($conf->reception->dir_output.'/'.$ref, preg_quote($ref, '/').'[^\-]+');
  1840. $file = $fileparams['fullname'];
  1841. // Define output language
  1842. $outputlangs = $langs;
  1843. $newlang = '';
  1844. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  1845. $newlang = $_REQUEST['lang_id'];
  1846. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1847. $newlang = $object->thirdparty->default_lang;
  1848. if (!empty($newlang))
  1849. {
  1850. $outputlangs = new Translate('', $conf);
  1851. $outputlangs->setDefaultLang($newlang);
  1852. $outputlangs->load('receptions');
  1853. }
  1854. // Build document if it not exists
  1855. if (!$file || !is_readable($file))
  1856. {
  1857. $result = $object->generateDocument(GETPOST('model') ?GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1858. if ($result <= 0)
  1859. {
  1860. dol_print_error($db, $object->error, $object->errors);
  1861. exit;
  1862. }
  1863. $fileparams = dol_most_recent_file($conf->reception->dir_output.'/reception/'.$ref, preg_quote($ref, '/').'[^\-]+');
  1864. $file = $fileparams['fullname'];
  1865. }
  1866. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  1867. print '<div class="clearboth"></div>';
  1868. print '<br>';
  1869. print load_fiche_titre($langs->trans('SendReceptionByEMail'));
  1870. dol_fiche_head('');
  1871. // Cree l'objet formulaire mail
  1872. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1873. $formmail = new FormMail($db);
  1874. $formmail->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
  1875. $formmail->fromtype = (GETPOST('fromtype') ?GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
  1876. if ($formmail->fromtype === 'user') {
  1877. $formmail->fromid = $user->id;
  1878. }
  1879. $formmail->trackid = 'shi'.$object->id;
  1880. if (!empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  1881. {
  1882. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1883. $formmail->frommail = dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
  1884. }
  1885. $formmail->withfrom = 1;
  1886. $liste = array();
  1887. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key] = $value;
  1888. $formmail->withto = GETPOST("sendto") ?GETPOST("sendto") : $liste;
  1889. $formmail->withtocc = $liste;
  1890. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  1891. $formmail->withtopic = $outputlangs->trans('SendReceptionRef', '__RECEPTIONREF__');
  1892. $formmail->withfile = 2;
  1893. $formmail->withbody = 1;
  1894. $formmail->withdeliveryreceipt = 1;
  1895. $formmail->withcancel = 1;
  1896. // Tableau des substitutions
  1897. $formmail->setSubstitFromObject($object, $langs);
  1898. $formmail->substit['__RECEPTIONREF__'] = $object->ref;
  1899. $formmail->substit['__RECEPTIONTRACKNUM__'] = $object->tracking_number;
  1900. $formmail->substit['__RECEPTIONTRACKNUMURL__'] = $object->tracking_url;
  1901. //Find the good contact adress
  1902. if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
  1903. $objectsrc = new Commande($db);
  1904. $objectsrc->fetch($object->$typeobject->id);
  1905. }
  1906. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
  1907. $objectsrc = new Propal($db);
  1908. $objectsrc->fetch($object->$typeobject->id);
  1909. }
  1910. $custcontact = '';
  1911. $contactarr = array();
  1912. if (is_object($objectsrc)) // For the case the reception was created without orders
  1913. {
  1914. $contactarr = $objectsrc->liste_contact(-1, 'external');
  1915. }
  1916. if (is_array($contactarr) && count($contactarr) > 0) {
  1917. foreach ($contactarr as $contact) {
  1918. if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) {
  1919. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  1920. $contactstatic = new Contact($db);
  1921. $contactstatic->fetch($contact['id']);
  1922. $custcontact = $contactstatic->getFullName($langs, 1);
  1923. }
  1924. }
  1925. if (!empty($custcontact)) {
  1926. $formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
  1927. }
  1928. }
  1929. // Tableau des parametres complementaires
  1930. $formmail->param['action'] = 'send';
  1931. $formmail->param['models'] = 'reception_send';
  1932. $formmail->param['models_id'] = GETPOST('modelmailselected', 'int');
  1933. $formmail->param['receptionid'] = $object->id;
  1934. $formmail->param['returnurl'] = $_SERVER["PHP_SELF"].'?id='.$object->id;
  1935. // Init list of files
  1936. if (GETPOST("mode") == 'init')
  1937. {
  1938. $formmail->clear_attached_files();
  1939. $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
  1940. }
  1941. // Show form
  1942. print $formmail->get_form();
  1943. dol_fiche_end();
  1944. }
  1945. }
  1946. llxFooter();
  1947. $db->close();