card.php 86 KB

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