card.php 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2019 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  12. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  14. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  15. * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/supplier_proposal/card.php
  32. * \ingroup supplier_proposal
  33. * \brief Card supplier proposal
  34. */
  35. // Load Dolibarr environment
  36. require '../main.inc.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  46. if (isModEnabled('project')) {
  47. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  49. }
  50. // Load translation files required by the page
  51. $langs->loadLangs(array('companies', 'supplier_proposal', 'compta', 'bills', 'propal', 'orders', 'products', 'deliveries', 'sendings'));
  52. if (isModEnabled('margin')) {
  53. $langs->load('margins');
  54. }
  55. $error = 0;
  56. $id = GETPOST('id', 'int');
  57. $ref = GETPOST('ref', 'alpha');
  58. $socid = GETPOST('socid', 'int');
  59. $action = GETPOST('action', 'aZ09');
  60. $cancel = GETPOST('cancel', 'alpha');
  61. $backtopage = GETPOST('backtopage', 'alpha');
  62. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  63. $origin = GETPOST('origin', 'alpha');
  64. $originid = GETPOST('originid', 'int');
  65. $confirm = GETPOST('confirm', 'alpha');
  66. $lineid = GETPOST('lineid', 'int');
  67. $contactid = GETPOST('contactid', 'int');
  68. $projectid = GETPOST('projectid', 'int');
  69. $rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
  70. // PDF
  71. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
  72. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
  73. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
  74. // Nombre de ligne pour choix de produit/service predefinis
  75. $NBLINES = 4;
  76. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  77. $hookmanager->initHooks(array('supplier_proposalcard', 'globalcard'));
  78. $object = new SupplierProposal($db);
  79. $extrafields = new ExtraFields($db);
  80. // fetch optionals attributes and labels
  81. $extrafields->fetch_name_optionals_label($object->table_element);
  82. // Load object
  83. if ($id > 0 || !empty($ref)) {
  84. $ret = $object->fetch($id, $ref);
  85. if ($ret > 0) {
  86. $ret = $object->fetch_thirdparty();
  87. }
  88. if ($ret <= 0) {
  89. setEventMessages($object->error, $object->errors, 'errors');
  90. $action = '';
  91. }
  92. }
  93. // Common permissions
  94. $usercanread = $user->rights->supplier_proposal->lire;
  95. $usercancreate = $user->rights->supplier_proposal->creer;
  96. $usercandelete = $user->rights->supplier_proposal->supprimer;
  97. // Advanced permissions
  98. $usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->supplier_proposal->validate_advance)));
  99. $usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->rights->supplier_proposal->send_advance);
  100. // Additional area permissions
  101. $usercanclose = $user->rights->supplier_proposal->cloturer;
  102. $usercancreateorder = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
  103. // Permissions for includes
  104. $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
  105. $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
  106. $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
  107. $permissiontoadd = $usercancreate;
  108. // Security check
  109. if (!empty($user->socid)) {
  110. $socid = $user->socid;
  111. }
  112. $result = restrictedArea($user, 'supplier_proposal', $object->id);
  113. /*
  114. * Actions
  115. */
  116. $parameters = array('socid' => $socid);
  117. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  118. if ($reshook < 0) {
  119. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  120. }
  121. if (empty($reshook)) {
  122. $backurlforlist = DOL_URL_ROOT.'/supplier_proposal/list.php';
  123. if (empty($backtopage) || ($cancel && empty($id))) {
  124. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  125. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  126. $backtopage = $backurlforlist;
  127. } else {
  128. $backtopage = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  129. }
  130. }
  131. }
  132. if ($cancel) {
  133. if (!empty($backtopageforcancel)) {
  134. header("Location: ".$backtopageforcancel);
  135. exit;
  136. } elseif (!empty($backtopage)) {
  137. header("Location: ".$backtopage);
  138. exit;
  139. }
  140. $action = '';
  141. }
  142. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  143. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  144. include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  145. // Action clone object
  146. if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
  147. if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
  148. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  149. } else {
  150. if ($object->id > 0) {
  151. $result = $object->createFromClone($user, $socid);
  152. if ($result > 0) {
  153. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  154. exit();
  155. } else {
  156. setEventMessages($object->error, $object->errors, 'errors');
  157. $action = '';
  158. }
  159. }
  160. }
  161. } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
  162. // Delete askprice
  163. $result = $object->delete($user);
  164. if ($result > 0) {
  165. header('Location: '.DOL_URL_ROOT.'/supplier_proposal/list.php');
  166. exit();
  167. } else {
  168. $langs->load("errors");
  169. setEventMessages($langs->trans($object->error), null, 'errors');
  170. }
  171. } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
  172. // Remove line
  173. $result = $object->deleteline($lineid);
  174. // reorder lines
  175. if ($result > 0) {
  176. $object->line_order(true);
  177. } else {
  178. $langs->load("errors");
  179. setEventMessages($object->error, $object->errors, 'errors');
  180. }
  181. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  182. // Define output language
  183. $outputlangs = $langs;
  184. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  185. $outputlangs = new Translate("", $conf);
  186. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  187. $outputlangs->setDefaultLang($newlang);
  188. }
  189. $ret = $object->fetch($id); // Reload to get new records
  190. if ($ret > 0) {
  191. $object->fetch_thirdparty();
  192. }
  193. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  194. }
  195. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  196. exit();
  197. } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) {
  198. // Validation
  199. $result = $object->valid($user);
  200. if ($result >= 0) {
  201. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  202. $outputlangs = $langs;
  203. $newlang = '';
  204. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  205. $newlang = GETPOST('lang_id', 'aZ09');
  206. }
  207. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  208. $newlang = $object->thirdparty->default_lang;
  209. }
  210. if (!empty($newlang)) {
  211. $outputlangs = new Translate("", $conf);
  212. $outputlangs->setDefaultLang($newlang);
  213. }
  214. $model = $object->model_pdf;
  215. $ret = $object->fetch($id); // Reload to get new records
  216. if ($ret > 0) {
  217. $object->fetch_thirdparty();
  218. }
  219. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  220. }
  221. } else {
  222. $langs->load("errors");
  223. if (count($object->errors) > 0) {
  224. setEventMessages($object->error, $object->errors, 'errors');
  225. } else {
  226. setEventMessages($langs->trans($object->error), null, 'errors');
  227. }
  228. }
  229. } elseif ($action == 'setdate_livraison' && $usercancreate) {
  230. $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')));
  231. if ($result < 0) {
  232. dol_print_error($db, $object->error);
  233. }
  234. } elseif ($action == 'add' && $usercancreate) {
  235. // Create supplier proposal
  236. $object->socid = $socid;
  237. $object->fetch_thirdparty();
  238. $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  239. if ($socid < 1) {
  240. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
  241. $action = 'create';
  242. $error++;
  243. }
  244. if (!$error) {
  245. $db->begin();
  246. // Si on a selectionne une demande a copier, on realise la copie
  247. if (GETPOST('createmode') == 'copy' && GETPOST('copie_supplier_proposal')) {
  248. if ($object->fetch(GETPOST('copie_supplier_proposal')) > 0) {
  249. $object->ref = GETPOST('ref');
  250. $object->delivery_date = $date_delivery;
  251. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  252. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  253. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  254. $object->fk_account = GETPOST('fk_account', 'int');
  255. $object->socid = GETPOST('socid');
  256. $object->fk_project = GETPOST('projectid', 'int');
  257. $object->model_pdf = GETPOST('model');
  258. $object->author = $user->id; // deprecated
  259. $object->note = GETPOST('note', 'restricthtml');
  260. $object->note_private = GETPOST('note', 'restricthtml');
  261. $object->statut = SupplierProposal::STATUS_DRAFT;
  262. } else {
  263. setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_supplier_proposal')), null, 'errors');
  264. }
  265. } else {
  266. $object->ref = GETPOST('ref');
  267. $object->delivery_date = $date_delivery;
  268. $object->demand_reason_id = GETPOST('demand_reason_id');
  269. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  270. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  271. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  272. $object->fk_account = GETPOST('fk_account', 'int');
  273. $object->fk_project = GETPOST('projectid', 'int');
  274. $object->model_pdf = GETPOST('model');
  275. $object->author = $user->id; // deprecated
  276. $object->note = GETPOST('note', 'restricthtml');
  277. $object->note_private = GETPOST('note', 'restricthtml');
  278. $object->origin = GETPOST('origin');
  279. $object->origin_id = GETPOST('originid');
  280. // Multicurrency
  281. if (isModEnabled("multicurrency")) {
  282. $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
  283. }
  284. // Fill array 'array_options' with data from add form
  285. $ret = $extrafields->setOptionalsFromPost(null, $object);
  286. if ($ret < 0) {
  287. $error++;
  288. $action = 'create';
  289. }
  290. }
  291. if (!$error) {
  292. if ($origin && $originid) {
  293. // Parse element/subelement (ex: project_task)
  294. $element = $subelement = $origin;
  295. if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
  296. $element = $regs[1];
  297. $subelement = $regs[2];
  298. }
  299. // For compatibility
  300. if ($element == 'order') {
  301. $element = $subelement = 'commande';
  302. }
  303. if ($element == 'propal') {
  304. $element = 'comm/propal';
  305. $subelement = 'propal';
  306. }
  307. if ($element == 'contract') {
  308. $element = $subelement = 'contrat';
  309. }
  310. if ($element == 'inter') {
  311. $element = $subelement = 'ficheinter';
  312. }
  313. if ($element == 'shipping') {
  314. $element = $subelement = 'expedition';
  315. }
  316. $object->origin = $origin;
  317. $object->origin_id = $originid;
  318. // Possibility to add external linked objects with hooks
  319. $object->linked_objects [$object->origin] = $object->origin_id;
  320. if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
  321. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  322. }
  323. $id = $object->create($user);
  324. if ($id > 0) {
  325. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  326. $classname = ucfirst($subelement);
  327. $srcobject = new $classname($db);
  328. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  329. $result = $srcobject->fetch($object->origin_id);
  330. if ($result > 0) {
  331. $lines = $srcobject->lines;
  332. if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
  333. $srcobject->fetch_lines();
  334. $lines = $srcobject->lines;
  335. }
  336. $fk_parent_line = 0;
  337. $num = count($lines);
  338. for ($i = 0; $i < $num; $i++) {
  339. $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
  340. $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
  341. // Positive line
  342. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  343. // Reset fk_parent_line for no child products and special product
  344. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  345. $fk_parent_line = 0;
  346. }
  347. // Extrafields
  348. if (method_exists($lines[$i], 'fetch_optionals')) {
  349. $lines[$i]->fetch_optionals();
  350. $array_options = $lines[$i]->array_options;
  351. }
  352. $result = $object->addline(
  353. $desc,
  354. $lines[$i]->subprice,
  355. $lines[$i]->qty,
  356. $lines[$i]->tva_tx,
  357. $lines[$i]->localtax1_tx,
  358. $lines[$i]->localtax2_tx,
  359. $lines[$i]->fk_product,
  360. $lines[$i]->remise_percent,
  361. 'HT',
  362. 0,
  363. $lines[$i]->info_bits,
  364. $product_type,
  365. $lines[$i]->rang,
  366. $lines[$i]->special_code,
  367. $fk_parent_line,
  368. $lines[$i]->fk_fournprice,
  369. $lines[$i]->pa_ht,
  370. $label,
  371. $array_options,
  372. $lines[$i]->ref_supplier,
  373. $lines[$i]->fk_unit
  374. );
  375. if ($result > 0) {
  376. $lineid = $result;
  377. } else {
  378. $lineid = 0;
  379. $error++;
  380. break;
  381. }
  382. // Defined the new fk_parent_line
  383. if ($result > 0 && $lines[$i]->product_type == 9) {
  384. $fk_parent_line = $result;
  385. }
  386. }
  387. // Hooks
  388. $parameters = array('objFrom' => $srcobject);
  389. $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
  390. // modified by hook
  391. if ($reshook < 0) {
  392. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  393. $error++;
  394. }
  395. } else {
  396. setEventMessages($srcobject->error, $srcobject->errors, 'errors');
  397. $error++;
  398. }
  399. } else {
  400. setEventMessages($object->error, $object->errors, 'errors');
  401. $error++;
  402. }
  403. } else {
  404. // Standard creation
  405. $id = $object->create($user);
  406. }
  407. if ($id > 0) {
  408. if (!$error) {
  409. $db->commit();
  410. // Define output language
  411. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  412. $outputlangs = $langs;
  413. $newlang = '';
  414. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  415. $newlang = GETPOST('lang_id', 'aZ09');
  416. }
  417. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  418. $newlang = $object->thirdparty->default_lang;
  419. }
  420. if (!empty($newlang)) {
  421. $outputlangs = new Translate("", $conf);
  422. $outputlangs->setDefaultLang($newlang);
  423. }
  424. $model = $object->model_pdf;
  425. $ret = $object->fetch($id); // Reload to get new records
  426. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  427. if ($result < 0) {
  428. dol_print_error($db, $result);
  429. }
  430. }
  431. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  432. exit();
  433. } else {
  434. $db->rollback();
  435. $action = 'create';
  436. }
  437. } else {
  438. setEventMessages($object->error, $object->errors, 'errors');
  439. $db->rollback();
  440. $action = 'create';
  441. }
  442. }
  443. }
  444. } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
  445. // Reopen proposal
  446. // prevent browser refresh from reopening proposal several times
  447. if ($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) {
  448. $object->reopen($user, SupplierProposal::STATUS_VALIDATED);
  449. }
  450. } elseif ($action == 'close' && $usercanclose && !GETPOST('cancel', 'alpha')) {
  451. // Close proposal
  452. // prevent browser refresh from reopening proposal several times
  453. if ($object->statut == SupplierProposal::STATUS_SIGNED) {
  454. $object->setStatut(SupplierProposal::STATUS_CLOSE);
  455. }
  456. } elseif ($action == 'setstatut' && $usercanclose && !GETPOST('cancel', 'alpha')) {
  457. // Set accepted/refused
  458. if (!GETPOST('statut')) {
  459. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors');
  460. $action = 'statut';
  461. } else {
  462. // prevent browser refresh from closing proposal several times
  463. if ($object->statut == SupplierProposal::STATUS_VALIDATED) {
  464. $object->cloture($user, GETPOST('statut'), GETPOST('note', 'restricthtml'));
  465. }
  466. }
  467. }
  468. // Actions when printing a doc from card
  469. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  470. // Actions to send emails
  471. $triggersendname = 'PROPOSAL_SUPPLIER_SENTBYMAIL';
  472. $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
  473. $trackid = 'spro'.$object->id;
  474. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  475. // Actions to build doc
  476. $upload_dir = $conf->supplier_proposal->dir_output;
  477. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  478. // Go back to draft
  479. if ($action == 'modif' && $usercancreate) {
  480. $object->setDraft($user);
  481. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  482. // Define output language
  483. $outputlangs = $langs;
  484. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  485. $outputlangs = new Translate("", $conf);
  486. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  487. $outputlangs->setDefaultLang($newlang);
  488. }
  489. $ret = $object->fetch($id); // Reload to get new records
  490. if ($ret > 0) {
  491. $object->fetch_thirdparty();
  492. }
  493. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  494. }
  495. } elseif ($action == "setabsolutediscount" && $usercancreate) {
  496. if (GETPOST("remise_id", 'int')) {
  497. if ($object->id > 0) {
  498. $result = $object->insert_discount(GETPOST("remise_id", 'int'));
  499. if ($result < 0) {
  500. setEventMessages($object->error, $object->errors, 'errors');
  501. }
  502. }
  503. }
  504. }
  505. // Add a product line
  506. if ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') && $usercancreate) {
  507. // Define vat_rate
  508. $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
  509. $vat_rate = str_replace('*', '', $vat_rate);
  510. $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
  511. $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
  512. foreach ($object->lines as $line) {
  513. $result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
  514. }
  515. } elseif ($action == 'addline' && $usercancreate) {
  516. $langs->load('errors');
  517. $error = 0;
  518. // Set if we used free entry or predefined product
  519. $predef = '';
  520. $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
  521. $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
  522. $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
  523. $ref_supplier = GETPOST('fourn_ref', 'alpha');
  524. $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
  525. if ($prod_entry_mode == 'free') {
  526. $idprod = 0;
  527. } else {
  528. $idprod = GETPOST('idprod', 'int');
  529. }
  530. $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
  531. $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
  532. $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
  533. $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
  534. $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
  535. $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
  536. $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
  537. if (empty($remise_percent)) {
  538. $remise_percent = 0;
  539. }
  540. // Extrafields
  541. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  542. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
  543. // Unset extrafield
  544. if (is_array($extralabelsline)) {
  545. // Get extra fields
  546. foreach ($extralabelsline as $key => $value) {
  547. unset($_POST["options_".$key]);
  548. }
  549. }
  550. if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
  551. setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
  552. $error++;
  553. }
  554. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
  555. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  556. $error++;
  557. }
  558. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && GETPOST('multicurrency_price_ht') === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
  559. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPrice")), null, 'errors');
  560. $error++;
  561. }
  562. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
  563. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
  564. $error++;
  565. }
  566. if (!$error && ($qty >= 0)) {
  567. $pu_ht = price2num($price_ht, 'MU');
  568. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  569. $price_min = 0;
  570. $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
  571. $db->begin();
  572. if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
  573. $productsupplier = new ProductFournisseur($db);
  574. $idprod = 0;
  575. if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
  576. $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
  577. }
  578. $reg = array();
  579. if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
  580. $idprod = $reg[1];
  581. $res = $productsupplier->fetch($idprod); // Load product from its id
  582. // Call to init some price properties of $productsupplier
  583. // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
  584. if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
  585. $fksoctosearch = 0;
  586. $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
  587. if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
  588. $productsupplier->ref_supplier = '';
  589. }
  590. } else {
  591. $fksoctosearch = $object->thirdparty->id;
  592. $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
  593. }
  594. } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
  595. //$qtytosearch=$qty; // Just to see if a price exists for the quantity. Not used to found vat.
  596. $qtytosearch = -1; // We force qty to -1 to be sure to find if the supplier price that exists
  597. $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
  598. $res = $productsupplier->fetch($idprod);
  599. }
  600. if ($idprod > 0) {
  601. $label = $productsupplier->label;
  602. // Define output language
  603. if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
  604. $outputlangs = $langs;
  605. $newlang = '';
  606. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  607. $newlang = GETPOST('lang_id', 'aZ09');
  608. }
  609. if (empty($newlang)) {
  610. $newlang = $object->thirdparty->default_lang;
  611. }
  612. if (!empty($newlang)) {
  613. $outputlangs = new Translate("", $conf);
  614. $outputlangs->setDefaultLang($newlang);
  615. }
  616. $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
  617. } else {
  618. $desc = $productsupplier->description;
  619. }
  620. // if we use supplier description of the products
  621. if (!empty($productsupplier->desc_supplier) && getDolGlobalString('PRODUIT_FOURN_TEXTS')) {
  622. $desc = $productsupplier->desc_supplier;
  623. }
  624. //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
  625. if (trim($product_desc) == trim($desc) && getDolGlobalString('PRODUIT_AUTOFILL_DESC')) {
  626. $product_desc='';
  627. }
  628. if (!empty($product_desc) && getDolGlobalString('MAIN_NO_CONCAT_DESCRIPTION')) {
  629. $desc = $product_desc;
  630. }
  631. if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
  632. $desc = dol_concatdesc($desc, $product_desc, '', getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION'));
  633. }
  634. $ref_supplier = $productsupplier->ref_supplier;
  635. // Get vat rate
  636. $tva_npr = 0;
  637. if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
  638. $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
  639. $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
  640. }
  641. if (empty($tva_tx)) {
  642. $tva_npr = 0;
  643. }
  644. $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
  645. $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
  646. $type = $productsupplier->type;
  647. if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
  648. $price_base_type = 'HT';
  649. $pu = price2num($price_ht, 'MU');
  650. $pu_devise = price2num($price_ht_devise, 'CU');
  651. } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') {
  652. $price_base_type = 'TTC';
  653. $pu = price2num($price_ttc, 'MU');
  654. $pu_devise = price2num($price_ttc_devise, 'CU');
  655. } else {
  656. $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
  657. if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
  658. $pu = $productsupplier->fourn_pu;
  659. $pu_devise = 0;
  660. } else {
  661. $pu = $productsupplier->fourn_pu;
  662. $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
  663. }
  664. }
  665. if (empty($pu)) {
  666. $pu = 0; // If pu is '' or null, we force to have a numeric value
  667. }
  668. // If GETPOST('idprodfournprice') is a numeric, we can use it. If it is empty or if it is 'idprod_123', we should use -1 (not used)
  669. $fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
  670. $buyingprice = 0;
  671. $result = $object->addline(
  672. $desc,
  673. ($price_base_type == 'HT' ? $pu : 0),
  674. $qty,
  675. $tva_tx,
  676. $localtax1_tx,
  677. $localtax2_tx,
  678. $productsupplier->id,
  679. $remise_percent,
  680. $price_base_type,
  681. ($price_base_type == 'TTC' ? $pu : 0),
  682. $tva_npr,
  683. $type,
  684. min($rank, count($object->lines) + 1),
  685. 0,
  686. GETPOST('fk_parent_line'),
  687. $fournprice,
  688. $buyingprice,
  689. $label,
  690. $array_options,
  691. $ref_supplier,
  692. $productsupplier->fk_unit,
  693. '',
  694. 0,
  695. $pu_devise,
  696. $date_start,
  697. $date_end
  698. );
  699. //var_dump($tva_tx);
  700. //var_dump($productsupplier->fourn_pu);
  701. //var_dump($price_base_type);exit;
  702. if ($result < 0) {
  703. $error++;
  704. setEventMessages($object->error, $object->errors, 'errors');
  705. }
  706. }
  707. if ($idprod == -99 || $idprod == 0) {
  708. // Product not selected
  709. $error++;
  710. $langs->load("errors");
  711. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")).' '.$langs->trans("or").' '.$langs->trans("NoPriceDefinedForThisSupplier"), null, 'errors');
  712. }
  713. if ($idprod == -1) {
  714. // Quantity too low
  715. $error++;
  716. $langs->load("errors");
  717. setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
  718. }
  719. } elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
  720. $pu_ht = price2num($price_ht, 'MU');
  721. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  722. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  723. $tva_tx = str_replace('*', '', $tva_tx);
  724. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  725. $desc = $product_desc;
  726. $type = GETPOST('type');
  727. $fk_unit = GETPOST('units', 'alpha');
  728. if (!preg_match('/\((.*)\)/', $tva_tx)) {
  729. $tva_tx = price2num($tva_tx); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1'
  730. }
  731. // Local Taxes
  732. $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
  733. $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
  734. if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
  735. $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
  736. } else {
  737. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  738. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
  739. }
  740. $price_base_type = 'HT';
  741. $pu_ht_devise = price2num($price_ht_devise, 'CU');
  742. $info_bits = 0;
  743. $result = $object->addline(
  744. $desc,
  745. $pu_ht,
  746. $qty,
  747. $tva_tx,
  748. $localtax1_tx,
  749. $localtax2_tx,
  750. $idprod,
  751. $remise_percent,
  752. $price_base_type,
  753. $pu_ttc,
  754. $info_bits,
  755. $type,
  756. -1, // rang
  757. 0, // special_code
  758. GETPOST('fk_parent_line'),
  759. $fournprice,
  760. $buyingprice,
  761. $label,
  762. $array_options,
  763. $ref_supplier,
  764. $fk_unit,
  765. '', // origin
  766. 0, // origin_id
  767. $pu_ht_devise
  768. );
  769. }
  770. if (!$error && $result > 0) {
  771. $db->commit();
  772. $ret = $object->fetch($object->id); // Reload to get new records
  773. // Define output language
  774. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  775. $outputlangs = $langs;
  776. $newlang = '';
  777. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  778. $newlang = GETPOST('lang_id', 'aZ09');
  779. }
  780. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  781. $newlang = $object->thirdparty->default_lang;
  782. }
  783. if (!empty($newlang)) {
  784. $outputlangs = new Translate("", $conf);
  785. $outputlangs->setDefaultLang($newlang);
  786. }
  787. $model = $object->model_pdf;
  788. $ret = $object->fetch($id); // Reload to get new records
  789. if ($ret > 0) {
  790. $object->fetch_thirdparty();
  791. }
  792. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  793. if ($result < 0) {
  794. dol_print_error($db, $result);
  795. }
  796. }
  797. unset($_POST['prod_entry_mode']);
  798. unset($_POST['qty']);
  799. unset($_POST['type']);
  800. unset($_POST['remise_percent']);
  801. unset($_POST['pu']);
  802. unset($_POST['price_ht']);
  803. unset($_POST['multicurrency_price_ht']);
  804. unset($_POST['price_ttc']);
  805. unset($_POST['fourn_ref']);
  806. unset($_POST['tva_tx']);
  807. unset($_POST['label']);
  808. unset($_POST['product_ref']);
  809. unset($_POST['product_label']);
  810. unset($_POST['product_desc']);
  811. unset($_POST['fournprice']);
  812. unset($_POST['buying_price']);
  813. unset($localtax1_tx);
  814. unset($localtax2_tx);
  815. unset($_POST['np_marginRate']);
  816. unset($_POST['np_markRate']);
  817. unset($_POST['dp_desc']);
  818. unset($_POST['idprodfournprice']);
  819. unset($_POST['units']);
  820. unset($_POST['idprod']);
  821. unset($_POST['date_starthour']);
  822. unset($_POST['date_startmin']);
  823. unset($_POST['date_startsec']);
  824. unset($_POST['date_startday']);
  825. unset($_POST['date_startmonth']);
  826. unset($_POST['date_startyear']);
  827. unset($_POST['date_endhour']);
  828. unset($_POST['date_endmin']);
  829. unset($_POST['date_endsec']);
  830. unset($_POST['date_endday']);
  831. unset($_POST['date_endmonth']);
  832. unset($_POST['date_endyear']);
  833. } else {
  834. $db->rollback();
  835. setEventMessages($object->error, $object->errors, 'errors');
  836. }
  837. }
  838. } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) {
  839. // Update a line within proposal
  840. $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0);
  841. // Define info_bits
  842. $info_bits = 0;
  843. if (preg_match('/\*/', $vat_rate)) {
  844. $info_bits |= 0x01;
  845. }
  846. // Clean parameters
  847. $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
  848. // Define vat_rate
  849. $vat_rate = str_replace('*', '', $vat_rate);
  850. $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty);
  851. $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
  852. if (GETPOST('price_ht') != '') {
  853. $price_base_type = 'HT';
  854. $ht = price2num(GETPOST('price_ht'), '', 2);
  855. } else {
  856. $reg = array();
  857. $vatratecleaned = $vat_rate;
  858. if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
  859. $vatratecleaned = trim($reg[1]);
  860. $vatratecode = $reg[2];
  861. }
  862. $ttc = price2num(GETPOST('price_ttc'), '', 2);
  863. $ht = (float) $ttc / (1 + ((float) $vatratecleaned / 100));
  864. $price_base_type = 'HT';
  865. }
  866. $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
  867. // Add buying price
  868. $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
  869. $buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
  870. // Extrafields Lines
  871. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  872. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  873. // Unset extrafield POST Data
  874. if (is_array($extralabelsline)) {
  875. foreach ($extralabelsline as $key => $value) {
  876. unset($_POST["options_".$key]);
  877. }
  878. }
  879. // Define special_code for special lines
  880. $special_code = GETPOST('special_code');
  881. if (!GETPOST('qty')) {
  882. $special_code = 3;
  883. }
  884. // Check minimum price
  885. $productid = GETPOST('productid', 'int');
  886. if (!empty($productid)) {
  887. $productsupplier = new ProductFournisseur($db);
  888. if (getDolGlobalString('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
  889. if ($productid > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty')), $productid, 'none', GETPOST('socid', 'int')) < 0) {
  890. setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
  891. }
  892. }
  893. $product = new Product($db);
  894. $res = $product->fetch($productid);
  895. $type = $product->type;
  896. $price_min = $product->price_min;
  897. if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
  898. $price_min = $product->multiprices_min [$object->thirdparty->price_level];
  899. }
  900. $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
  901. } else {
  902. $type = GETPOST('type');
  903. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  904. // Check parameters
  905. if (GETPOST('type') < 0) {
  906. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  907. $error++;
  908. }
  909. }
  910. if (!$error) {
  911. $db->begin();
  912. $ref_supplier = GETPOST('fourn_ref', 'alpha');
  913. $fk_unit = GETPOST('units');
  914. $result = $object->updateline(
  915. GETPOST('lineid', 'int'),
  916. $ht,
  917. price2num(GETPOST('qty'), 'MS', 2),
  918. price2num(GETPOST('remise_percent'), '', 2),
  919. $vat_rate,
  920. $localtax1_rate,
  921. $localtax2_rate,
  922. $description,
  923. $price_base_type,
  924. $info_bits,
  925. $special_code,
  926. GETPOST('fk_parent_line', 'int'),
  927. 0,
  928. $fournprice,
  929. $buyingprice,
  930. $label,
  931. $type,
  932. $array_options,
  933. $ref_supplier,
  934. $fk_unit,
  935. $pu_ht_devise
  936. );
  937. if ($result >= 0) {
  938. $db->commit();
  939. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  940. // Define output language
  941. $outputlangs = $langs;
  942. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  943. $outputlangs = new Translate("", $conf);
  944. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  945. $outputlangs->setDefaultLang($newlang);
  946. }
  947. $ret = $object->fetch($id); // Reload to get new records
  948. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  949. }
  950. unset($_POST['qty']);
  951. unset($_POST['type']);
  952. unset($_POST['productid']);
  953. unset($_POST['remise_percent']);
  954. unset($_POST['price_ht']);
  955. unset($_POST['multicurrency_price_ht']);
  956. unset($_POST['price_ttc']);
  957. unset($_POST['tva_tx']);
  958. unset($_POST['product_ref']);
  959. unset($_POST['product_label']);
  960. unset($_POST['product_desc']);
  961. unset($_POST['fournprice']);
  962. unset($_POST['buying_price']);
  963. unset($_POST['date_starthour']);
  964. unset($_POST['date_startmin']);
  965. unset($_POST['date_startsec']);
  966. unset($_POST['date_startday']);
  967. unset($_POST['date_startmonth']);
  968. unset($_POST['date_startyear']);
  969. unset($_POST['date_endhour']);
  970. unset($_POST['date_endmin']);
  971. unset($_POST['date_endsec']);
  972. unset($_POST['date_endday']);
  973. unset($_POST['date_endmonth']);
  974. unset($_POST['date_endyear']);
  975. } else {
  976. $db->rollback();
  977. setEventMessages($object->error, $object->errors, 'errors');
  978. }
  979. }
  980. } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
  981. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
  982. exit();
  983. } elseif ($action == 'classin' && $usercancreate) {
  984. // Set project
  985. $object->setProject(GETPOST('projectid'), 'int');
  986. } elseif ($action == 'setavailability' && $usercancreate) {
  987. // Delivery delay
  988. $result = $object->availability(GETPOST('availability_id'));
  989. } elseif ($action == 'setconditions' && $usercancreate) {
  990. // Terms of payments
  991. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
  992. //} elseif ($action == 'setremisepercent' && $usercancreate) {
  993. // $result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
  994. //} elseif ($action == 'setremiseabsolue' && $usercancreate) {
  995. // $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
  996. } elseif ($action == 'setmode' && $usercancreate) {
  997. // Payment mode
  998. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  999. } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
  1000. // Multicurrency Code
  1001. $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
  1002. } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
  1003. // Multicurrency rate
  1004. $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
  1005. } elseif ($action == 'update_extras') {
  1006. $object->oldcopy = dol_clone($object, 2);
  1007. // Fill array 'array_options' with data from update form
  1008. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  1009. if ($ret < 0) {
  1010. $error++;
  1011. }
  1012. if (!$error) {
  1013. $result = $object->insertExtraFields('PROPOSAL_SUPPLIER_MODIFY');
  1014. if ($result < 0) {
  1015. setEventMessages($object->error, $object->errors, 'errors');
  1016. $error++;
  1017. }
  1018. }
  1019. if ($error) {
  1020. $action = 'edit_extras';
  1021. }
  1022. }
  1023. }
  1024. /*
  1025. * View
  1026. */
  1027. $title = $object->ref." - ".$langs->trans('Card');
  1028. if ($action == 'create') {
  1029. $title = $langs->trans("SupplierProposalNew");
  1030. }
  1031. $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
  1032. llxHeader('', $title, $help_url);
  1033. $form = new Form($db);
  1034. $formother = new FormOther($db);
  1035. $formfile = new FormFile($db);
  1036. $formmargin = new FormMargin($db);
  1037. $companystatic = new Societe($db);
  1038. if (isModEnabled('project')) {
  1039. $formproject = new FormProjets($db);
  1040. }
  1041. $now = dol_now();
  1042. // Add new askprice
  1043. if ($action == 'create') {
  1044. $currency_code = $conf->currency;
  1045. print load_fiche_titre($langs->trans("SupplierProposalNew"), '', 'supplier_proposal');
  1046. $soc = new Societe($db);
  1047. if ($socid > 0) {
  1048. $res = $soc->fetch($socid);
  1049. }
  1050. // Load objectsrc
  1051. if (!empty($origin) && !empty($originid)) {
  1052. $element = $subelement = GETPOST('origin');
  1053. if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
  1054. $element = $regs[1];
  1055. $subelement = $regs[2];
  1056. }
  1057. // For compatibility
  1058. if ($element == 'order' || $element == 'commande') {
  1059. $element = $subelement = 'commande';
  1060. }
  1061. if ($element == 'propal') {
  1062. $element = 'comm/propal';
  1063. $subelement = 'propal';
  1064. }
  1065. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  1066. $classname = ucfirst($subelement);
  1067. $objectsrc = new $classname($db);
  1068. $objectsrc->fetch($originid);
  1069. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
  1070. $objectsrc->fetch_lines();
  1071. }
  1072. $objectsrc->fetch_thirdparty();
  1073. $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
  1074. $soc = $objectsrc->thirdparty;
  1075. $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
  1076. $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
  1077. // Replicate extrafields
  1078. $objectsrc->fetch_optionals();
  1079. $object->array_options = $objectsrc->array_options;
  1080. if (isModEnabled("multicurrency")) {
  1081. if (!empty($objectsrc->multicurrency_code)) {
  1082. $currency_code = $objectsrc->multicurrency_code;
  1083. }
  1084. if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($objectsrc->multicurrency_tx)) {
  1085. $currency_tx = $objectsrc->multicurrency_tx;
  1086. }
  1087. }
  1088. } else {
  1089. $cond_reglement_id = $soc->cond_reglement_supplier_id;
  1090. $mode_reglement_id = $soc->mode_reglement_supplier_id;
  1091. if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
  1092. $currency_code = $soc->multicurrency_code;
  1093. }
  1094. }
  1095. $object = new SupplierProposal($db);
  1096. print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1097. print '<input type="hidden" name="token" value="'.newToken().'">';
  1098. print '<input type="hidden" name="action" value="add">';
  1099. if ($origin != 'project' && $originid) {
  1100. print '<input type="hidden" name="origin" value="'.$origin.'">';
  1101. print '<input type="hidden" name="originid" value="'.$originid.'">';
  1102. }
  1103. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1104. print dol_get_fiche_head();
  1105. // Call Hook tabContentCreateSupplierProposal
  1106. $parameters = array();
  1107. // Note that $action and $object may be modified by hook
  1108. $reshook = $hookmanager->executeHooks('tabContentCreateSupplierProposal', $parameters, $object, $action);
  1109. if (empty($reshook)) {
  1110. print '<table class="border centpercent">';
  1111. // Reference
  1112. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
  1113. // Third party
  1114. print '<tr>';
  1115. print '<td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
  1116. if ($socid > 0) {
  1117. print '<td colspan="2">';
  1118. print $soc->getNomUrl(1, 'supplier');
  1119. print '<input type="hidden" name="socid" value="'.$soc->id.'">';
  1120. print '</td>';
  1121. } else {
  1122. print '<td colspan="2">';
  1123. $filter = '((s.fournisseur:=:1) AND (s.status:=:1))';
  1124. print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company((empty($socid) ? '' : $socid), 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
  1125. // reload page to retrieve customer informations
  1126. if (getDolGlobalString('RELOAD_PAGE_ON_SUPPLIER_CHANGE')) {
  1127. print '<script>
  1128. $(document).ready(function() {
  1129. $("#socid").change(function() {
  1130. console.log("We have changed the company - Reload page");
  1131. // reload page
  1132. $("input[name=action]").val("create");
  1133. $("form[name=add]").submit();
  1134. });
  1135. });
  1136. </script>';
  1137. }
  1138. print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
  1139. print '</td>';
  1140. }
  1141. print '</tr>'."\n";
  1142. if ($soc->id > 0) {
  1143. // Discounts for third party
  1144. print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
  1145. $absolute_discount = $soc->getAvailableDiscounts('', '', 0, 1);
  1146. $thirdparty = $soc;
  1147. $discount_type = 1;
  1148. $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
  1149. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  1150. print '</td></tr>';
  1151. }
  1152. // Terms of payment
  1153. print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
  1154. print img_picto('', 'payment', 'class="pictofixedwidth"');
  1155. print $form->getSelectConditionsPaiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
  1156. print '</td></tr>';
  1157. // Mode of payment
  1158. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
  1159. print img_picto('', 'bank', 'class="pictofixedwidth"');
  1160. $form->select_types_paiements(GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id');
  1161. print '</td></tr>';
  1162. // Bank Account
  1163. if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("banque")) {
  1164. print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">';
  1165. $form->select_comptes(GETPOST('fk_account') > 0 ? GETPOST('fk_account', 'int') : $fk_account, 'fk_account', 0, '', 1);
  1166. print '</td></tr>';
  1167. }
  1168. // Shipping Method
  1169. if (isModEnabled("expedition")) {
  1170. print '<tr><td>'.$langs->trans('SendingMethod').'</td><td colspan="2">';
  1171. print img_picto('', 'dolly', 'class="pictofixedwidth"');
  1172. $form->selectShippingMethod(GETPOST('shipping_method_id') > 0 ? GETPOST('shipping_method_id', 'int') : "", 'shipping_method_id', '', 1);
  1173. print '</td></tr>';
  1174. }
  1175. // Delivery date (or manufacturing)
  1176. print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
  1177. print '<td colspan="2">';
  1178. print img_picto('', 'action', 'class="pictofixedwidth"');
  1179. $datedelivery = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  1180. if (is_numeric(getDolGlobalString('DATE_LIVRAISON_WEEK_DELAY'))) { // If value set to 0 or a num, not empty
  1181. $tmpdte = time() + (7 * getDolGlobalInt('DATE_LIVRAISON_WEEK_DELAY') * 24 * 60 * 60);
  1182. $syear = date("Y", $tmpdte);
  1183. $smonth = date("m", $tmpdte);
  1184. $sday = date("d", $tmpdte);
  1185. print $form->selectDate($syear."-".$smonth."-".$sday, 'liv_', '', '', '', "addask");
  1186. } else {
  1187. print $form->selectDate($datedelivery ? $datedelivery : -1, 'liv_', '', '', '', "addask", 1, 1);
  1188. }
  1189. print '</td></tr>';
  1190. // Model
  1191. print '<tr>';
  1192. print '<td>'.$langs->trans("DefaultModel").'</td>';
  1193. print '<td colspan="2">';
  1194. print img_picto('', 'pdf', 'class="pictofixedwidth"');
  1195. $list = ModelePDFSupplierProposal::liste_modeles($db);
  1196. $preselected = (getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT') ? $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT : $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF);
  1197. print $form->selectarray('model', $list, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  1198. print "</td></tr>";
  1199. // Project
  1200. if (isModEnabled('project')) {
  1201. $langs->load("projects");
  1202. $formproject = new FormProjets($db);
  1203. if ($origin == 'project') {
  1204. $projectid = ($originid ? $originid : 0);
  1205. }
  1206. print '<tr>';
  1207. print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
  1208. print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
  1209. 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="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
  1210. print '</td>';
  1211. print '</tr>';
  1212. }
  1213. // Multicurrency
  1214. if (isModEnabled("multicurrency")) {
  1215. print '<tr>';
  1216. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  1217. print '<td colspan="3" class="maxwidthonsmartphone">';
  1218. print img_picto('', 'currency', 'class="pictofixedwidth"');
  1219. print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
  1220. print '</td></tr>';
  1221. }
  1222. // Other attributes
  1223. $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
  1224. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1225. print $hookmanager->resPrint;
  1226. if (empty($reshook)) {
  1227. print $object->showOptionals($extrafields, 'create', $parameters);
  1228. }
  1229. // Lines from source
  1230. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  1231. // TODO for compatibility
  1232. if ($origin == 'contrat') {
  1233. // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
  1234. //$objectsrc->remise_absolue = $remise_absolue;
  1235. //$objectsrc->remise_percent = $remise_percent;
  1236. $objectsrc->update_price(1, 'auto', 1);
  1237. }
  1238. print "\n<!-- ".$classname." info -->";
  1239. print "\n";
  1240. print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
  1241. print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
  1242. print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
  1243. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  1244. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  1245. print '<tr><td>'.$langs->trans('CommRequest').'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
  1246. print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
  1247. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
  1248. if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
  1249. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
  1250. }
  1251. if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
  1252. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
  1253. }
  1254. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
  1255. if (isModEnabled("multicurrency")) {
  1256. print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
  1257. print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
  1258. print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td colspan="2">'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
  1259. }
  1260. }
  1261. print "</table>\n";
  1262. /*
  1263. * Combobox for copy function
  1264. */
  1265. if (!getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
  1266. print '<input type="hidden" name="createmode" value="empty">';
  1267. }
  1268. if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
  1269. print '<br><table>';
  1270. // For backward compatibility
  1271. print '<tr>';
  1272. print '<td><input type="radio" name="createmode" value="copy"></td>';
  1273. print '<td>'.$langs->trans("CopyAskFrom").' </td>';
  1274. print '<td>';
  1275. $liste_ask = array();
  1276. $liste_ask [0] = '';
  1277. $sql = "SELECT p.rowid as id, p.ref, s.nom";
  1278. $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p";
  1279. $sql .= ", ".MAIN_DB_PREFIX."societe s";
  1280. $sql .= " WHERE s.rowid = p.fk_soc";
  1281. $sql .= " AND p.entityy IN (".getEntity('supplier_proposal').")";
  1282. $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT;
  1283. $sql .= " ORDER BY Id";
  1284. $resql = $db->query($sql);
  1285. if ($resql) {
  1286. $num = $db->num_rows($resql);
  1287. $i = 0;
  1288. while ($i < $num) {
  1289. $row = $db->fetch_row($resql);
  1290. $askPriceSupplierRefAndSocName = $row[1]." - ".$row[2];
  1291. $liste_ask[$row[0]] = $askPriceSupplierRefAndSocName;
  1292. $i++;
  1293. }
  1294. print $form->selectarray("copie_supplier_proposal", $liste_ask, 0);
  1295. } else {
  1296. dol_print_error($db);
  1297. }
  1298. print '</td></tr>';
  1299. print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
  1300. print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyAsk").'</td></tr>';
  1301. }
  1302. if (getDolGlobalString('SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE')) {
  1303. print '</table>';
  1304. }
  1305. }
  1306. print dol_get_fiche_end();
  1307. print $form->buttonsSaveCancel("CreateDraft");
  1308. print "</form>";
  1309. // Show origin lines
  1310. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  1311. print '<br>';
  1312. $title = $langs->trans('ProductsAndServices');
  1313. print load_fiche_titre($title);
  1314. print '<div class="div-table-responsive-no-min">';
  1315. print '<table class="noborder centpercent">';
  1316. $objectsrc->printOriginLinesList();
  1317. print '</table>';
  1318. print '</div>';
  1319. }
  1320. } else {
  1321. /*
  1322. * Show object in view mode
  1323. */
  1324. $soc = new Societe($db);
  1325. $soc->fetch($object->socid);
  1326. $head = supplier_proposal_prepare_head($object);
  1327. print dol_get_fiche_head($head, 'comm', $langs->trans('CommRequest'), -1, 'supplier_proposal');
  1328. $formconfirm = '';
  1329. // Clone confirmation
  1330. if ($action == 'clone') {
  1331. $filter = '(s.fournisseur:=:1)';
  1332. // Create an array for form
  1333. $formquestion = array(
  1334. // 'text' => $langs->trans("ConfirmClone"),
  1335. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1336. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
  1337. // 1),
  1338. array(
  1339. 'type' => 'other',
  1340. 'name' => 'socid',
  1341. 'label' => $langs->trans("SelectThirdParty"),
  1342. 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', $filter))
  1343. );
  1344. // Paiement incomplet. On demande si motif = escompte ou autre
  1345. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  1346. } elseif ($action == 'delete') {
  1347. // Confirm delete
  1348. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteAsk'), $langs->trans('ConfirmDeleteAsk', $object->ref), 'confirm_delete', '', 0, 1);
  1349. } elseif ($action == 'reopen') {
  1350. // Confirm reopen
  1351. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenAsk', $object->ref), 'confirm_reopen', '', 0, 1);
  1352. } elseif ($action == 'ask_deleteline') {
  1353. // Confirmation delete product/service line
  1354. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  1355. } elseif ($action == 'validate') {
  1356. // Confirm validate askprice
  1357. $error = 0;
  1358. // on verifie si l'objet est en numerotation provisoire
  1359. $ref = substr($object->ref, 1, 4);
  1360. if ($ref == 'PROV') {
  1361. $numref = $object->getNextNumRef($soc);
  1362. if (empty($numref)) {
  1363. $error++;
  1364. setEventMessages($object->error, $object->errors, 'errors');
  1365. }
  1366. } else {
  1367. $numref = $object->ref;
  1368. }
  1369. $text = $langs->trans('ConfirmValidateAsk', $numref);
  1370. if (isModEnabled('notification')) {
  1371. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  1372. $notify = new Notify($db);
  1373. $text .= '<br>';
  1374. $text .= $notify->confirmMessage('PROPOSAL_SUPPLIER_VALIDATE', $object->socid, $object);
  1375. }
  1376. if (!$error) {
  1377. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateAsk'), $text, 'confirm_validate', '', 0, 1);
  1378. }
  1379. }
  1380. // Call Hook formConfirm
  1381. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  1382. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1383. if (empty($reshook)) {
  1384. $formconfirm .= $hookmanager->resPrint;
  1385. } elseif ($reshook > 0) {
  1386. $formconfirm = $hookmanager->resPrint;
  1387. }
  1388. // Print form confirm
  1389. print $formconfirm;
  1390. // Supplier proposal card
  1391. $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  1392. $morehtmlref = '<div class="refidno">';
  1393. // Ref supplier
  1394. //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1);
  1395. //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1);
  1396. // Thirdparty
  1397. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'supplier');
  1398. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  1399. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
  1400. }
  1401. // Project
  1402. if (isModEnabled('project')) {
  1403. $langs->load("projects");
  1404. $morehtmlref .= '<br>';
  1405. if ($usercancreate) {
  1406. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  1407. if ($action != 'classify') {
  1408. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  1409. }
  1410. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  1411. } else {
  1412. if (!empty($object->fk_project)) {
  1413. $proj = new Project($db);
  1414. $proj->fetch($object->fk_project);
  1415. $morehtmlref .= $proj->getNomUrl(1);
  1416. if ($proj->title) {
  1417. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  1418. }
  1419. }
  1420. }
  1421. }
  1422. $morehtmlref .= '</div>';
  1423. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1424. // Call Hook tabContentViewSupplierProposal
  1425. $parameters = array();
  1426. // Note that $action and $object may be modified by hook
  1427. $reshook = $hookmanager->executeHooks('tabContentViewSupplierProposal', $parameters, $object, $action);
  1428. if (empty($reshook)) {
  1429. print '<div class="fichecenter">';
  1430. print '<div class="fichehalfleft">';
  1431. print '<div class="underbanner clearboth"></div>';
  1432. print '<table class="border tableforfield centpercent">';
  1433. // Relative and absolute discounts
  1434. if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
  1435. $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  1436. $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  1437. } else {
  1438. $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
  1439. $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
  1440. }
  1441. print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
  1442. $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
  1443. $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote, 0, 1);
  1444. $absolute_discount = price2num($absolute_discount, 'MT');
  1445. $absolute_creditnote = price2num($absolute_creditnote, 'MT');
  1446. $thirdparty = $soc;
  1447. $discount_type = 1;
  1448. $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
  1449. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  1450. print '</td></tr>';
  1451. // Payment term
  1452. print '<tr><td class="titlefield">';
  1453. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1454. print $langs->trans('PaymentConditionsShort');
  1455. print '</td>';
  1456. if ($action != 'editconditions' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
  1457. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'</a></td>';
  1458. }
  1459. print '</tr></table>';
  1460. print '</td><td class="valuefield">';
  1461. if ($action == 'editconditions') {
  1462. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
  1463. } else {
  1464. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
  1465. }
  1466. print '</td>';
  1467. print '</tr>';
  1468. // Delivery date
  1469. $langs->load('deliveries');
  1470. print '<tr><td>';
  1471. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1472. print $langs->trans('DeliveryDate');
  1473. print '</td>';
  1474. if ($action != 'editdate_livraison' && $object->statut == SupplierProposal::STATUS_VALIDATED) {
  1475. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'), 1).'</a></td>';
  1476. }
  1477. print '</tr></table>';
  1478. print '</td><td class="valuefield">';
  1479. if ($action == 'editdate_livraison') {
  1480. print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" class="formconsumeproduce">';
  1481. print '<input type="hidden" name="token" value="'.newToken().'">';
  1482. print '<input type="hidden" name="action" value="setdate_livraison">';
  1483. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1484. print $form->selectDate($object->delivery_date, 'liv_', '', '', '', "editdate_livraison");
  1485. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  1486. print '</form>';
  1487. } else {
  1488. print dol_print_date($object->delivery_date, 'daytext');
  1489. }
  1490. print '</td>';
  1491. print '</tr>';
  1492. // Payment mode
  1493. print '<tr>';
  1494. print '<td>';
  1495. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1496. print $langs->trans('PaymentMode');
  1497. print '</td>';
  1498. if ($action != 'editmode' && $object->statut != SupplierProposal::STATUS_NOTSIGNED) {
  1499. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'</a></td>';
  1500. }
  1501. print '</tr></table>';
  1502. print '</td><td class="valuefield">';
  1503. if ($action == 'editmode') {
  1504. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
  1505. } else {
  1506. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
  1507. }
  1508. print '</td></tr>';
  1509. // Multicurrency
  1510. if (isModEnabled("multicurrency")) {
  1511. // Multicurrency code
  1512. print '<tr>';
  1513. print '<td>';
  1514. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1515. print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
  1516. print '</td>';
  1517. if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_VALIDATED) {
  1518. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
  1519. }
  1520. print '</tr></table>';
  1521. print '</td><td class="valuefield">';
  1522. if ($action == 'editmulticurrencycode') {
  1523. $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
  1524. } else {
  1525. $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
  1526. }
  1527. print '</td></tr>';
  1528. // Multicurrency rate
  1529. if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
  1530. print '<tr>';
  1531. print '<td>';
  1532. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1533. print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
  1534. print '</td>';
  1535. if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_VALIDATED && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
  1536. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
  1537. }
  1538. print '</tr></table>';
  1539. print '</td><td class="valuefield">';
  1540. if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
  1541. if ($action == 'actualizemulticurrencyrate') {
  1542. list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
  1543. }
  1544. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
  1545. } else {
  1546. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
  1547. if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
  1548. print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
  1549. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
  1550. print '</div>';
  1551. }
  1552. }
  1553. print '</td></tr>';
  1554. }
  1555. }
  1556. /* Not for supplier proposals
  1557. if ($soc->outstanding_limit) {
  1558. // Outstanding Bill
  1559. print '<tr><td>';
  1560. print $langs->trans('OutstandingBill');
  1561. print '</td><td class="valuefield">';
  1562. $arrayoutstandingbills = $soc->getOutstandingBills('supplier');
  1563. $outstandingBills = $arrayoutstandingbills['opened'];
  1564. print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency);
  1565. print '</td>';
  1566. print '</tr>';
  1567. }*/
  1568. if (getDolGlobalString('BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL') && isModEnabled("banque")) {
  1569. // Bank Account
  1570. print '<tr><td>';
  1571. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1572. print $langs->trans('BankAccount');
  1573. print '</td>';
  1574. if ($action != 'editbankaccount' && $usercancreate) {
  1575. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  1576. }
  1577. print '</tr></table>';
  1578. print '</td><td class="valuefield">';
  1579. if ($action == 'editbankaccount') {
  1580. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  1581. } else {
  1582. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  1583. }
  1584. print '</td>';
  1585. print '</tr>';
  1586. }
  1587. // Other attributes
  1588. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1589. print '</table>';
  1590. print '</div>';
  1591. print '<div class="fichehalfright">';
  1592. print '<div class="underbanner clearboth"></div>';
  1593. print '<table class="border tableforfield centpercent">';
  1594. print '<tr>';
  1595. // Amount HT
  1596. print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
  1597. print '<td class="nowrap amountcard right">' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
  1598. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  1599. // Multicurrency Amount HT
  1600. print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
  1601. }
  1602. print '</tr>';
  1603. print '<tr>';
  1604. // Amount VAT
  1605. print '<td class="titlefieldmiddle">' . $langs->trans('AmountVAT') . '</td>';
  1606. print '<td class="nowrap amountcard right">' . price($object->total_tva, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
  1607. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  1608. // Multicurrency Amount VAT
  1609. print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
  1610. }
  1611. print '</tr>';
  1612. // Amount Local Taxes
  1613. if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) {
  1614. print '<tr>';
  1615. print '<td class="titlefieldmiddle">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
  1616. print '<td class="nowrap amountcard right">' . price($object->total_localtax1, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
  1617. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  1618. print '<td class="nowrap amountcard right">' . price($object->total_localtax1, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
  1619. }
  1620. print '</tr>';
  1621. if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) {
  1622. print '<tr>';
  1623. print '<td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
  1624. print '<td class="nowrap amountcard right">' . price($object->total_localtax2, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
  1625. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  1626. print '<td class="nowrap amountcard right">' . price($object->total_localtax2, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
  1627. }
  1628. print '</tr>';
  1629. }
  1630. }
  1631. print '<tr>';
  1632. // Amount TTC
  1633. print '<td>' . $langs->trans('AmountTTC') . '</td>';
  1634. print '<td class="nowrap amountcard right">' . price($object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
  1635. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  1636. // Multicurrency Amount TTC
  1637. print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
  1638. }
  1639. print '</tr>';
  1640. print '</table>';
  1641. // Margin Infos
  1642. /*if (isModEnabled('margin')) {
  1643. $formmargin->displayMarginInfos($object);
  1644. }*/
  1645. print '</div>';
  1646. print '</div>';
  1647. print '<div class="clearboth"></div><br>';
  1648. if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
  1649. $blocname = 'contacts';
  1650. $title = $langs->trans('ContactsAddresses');
  1651. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1652. }
  1653. if (getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  1654. $blocname = 'notes';
  1655. $title = $langs->trans('Notes');
  1656. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1657. }
  1658. /*
  1659. * Lines
  1660. */
  1661. // Show object lines
  1662. $result = $object->getLinesArray();
  1663. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '').'" method="POST">
  1664. <input type="hidden" name="token" value="' . newToken().'">
  1665. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  1666. <input type="hidden" name="mode" value="">
  1667. <input type="hidden" name="id" value="' . $object->id.'">
  1668. <input type="hidden" name="backtopage" value="'.$backtopage.'">
  1669. ';
  1670. if (!empty($conf->use_javascript_ajax) && $object->statut == SupplierProposal::STATUS_DRAFT) {
  1671. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  1672. }
  1673. print '<div class="div-table-responsive-no-min">';
  1674. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  1675. // Add free products/services form
  1676. global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
  1677. $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
  1678. $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty.
  1679. if (getDolGlobalString('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY')) {
  1680. $senderissupplier = 1;
  1681. }
  1682. if (!empty($object->lines)) {
  1683. $object->printObjectLines($action, $soc, $mysoc, $lineid, $dateSelector);
  1684. }
  1685. // Form to add new line
  1686. if ($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) {
  1687. if ($action != 'editline') {
  1688. // Add products/services form
  1689. $parameters = array();
  1690. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1691. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1692. if (empty($reshook))
  1693. $object->formAddObjectLine($dateSelector, $soc, $mysoc);
  1694. }
  1695. }
  1696. print '</table>';
  1697. print '</div>';
  1698. print "</form>\n";
  1699. }
  1700. print dol_get_fiche_end();
  1701. if ($action == 'statut') {
  1702. // Form to set proposal accepted/refused
  1703. $form_close = '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" id="formacceptrefuse" class="formconsumeproduce paddingbottom paddingleft paddingright">';
  1704. $form_close .= '<input type="hidden" name="token" value="'.newToken().'">';
  1705. $form_close .= '<input type="hidden" name="action" value="setstatut">';
  1706. if (getDolGlobalString('SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL')) {
  1707. $form_close .= '<p class="notice">'.$langs->trans('SupplierProposalRefFournNotice').'</p>'; // TODO Suggest a permanent checkbox instead of option
  1708. }
  1709. $form_close .= '<table class="border centpercent marginleftonly marginrightonly">';
  1710. $form_close .= '<tr><td>'.$langs->trans("CloseAs").'</td><td class="left">';
  1711. $form_close .= '<select id="statut" name="statut" class="flat">';
  1712. $form_close .= '<option value="0">&nbsp;</option>';
  1713. $form_close .= '<option value="2">'.$langs->trans('SupplierProposalStatusSigned').'</option>';
  1714. $form_close .= '<option value="3">'.$langs->trans('SupplierProposalStatusNotSigned').'</option>';
  1715. $form_close .= '</select>';
  1716. $form_close .= '</td></tr>';
  1717. $form_close .= '<tr><td class="left">'.$langs->trans('Note').'</td><td class="left"><textarea cols="70" rows="'.ROWS_3.'" wrap="soft" name="note">';
  1718. $form_close .= $object->note_private;
  1719. $form_close .= '</textarea></td></tr>';
  1720. $form_close .= '</table>';
  1721. $form_close .= $form->buttonsSaveCancel();
  1722. $form_close .= '<a id="acceptedrefused">&nbsp;</a>';
  1723. $form_close .= '</form>';
  1724. print $form_close;
  1725. }
  1726. /*
  1727. * Boutons Actions
  1728. */
  1729. if ($action != 'presend') {
  1730. print '<div class="tabsAction">';
  1731. $parameters = array();
  1732. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1733. // modified by hook
  1734. if (empty($reshook)) {
  1735. if ($action != 'statut' && $action != 'editline') {
  1736. // Validate
  1737. if ($object->statut == SupplierProposal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0 && $usercanvalidate) {
  1738. if (count($object->lines) > 0) {
  1739. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
  1740. }
  1741. // else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
  1742. }
  1743. // Edit
  1744. if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercancreate) {
  1745. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('Modify').'</a></div>';
  1746. }
  1747. // ReOpen
  1748. if (($object->statut == SupplierProposal::STATUS_SIGNED || $object->statut == SupplierProposal::STATUS_NOTSIGNED || $object->statut == SupplierProposal::STATUS_CLOSE) && $usercanclose) {
  1749. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#reopen').'"';
  1750. print '>'.$langs->trans('ReOpen').'</a></div>';
  1751. }
  1752. // Send
  1753. if (empty($user->socid)) {
  1754. if ($object->statut == SupplierProposal::STATUS_VALIDATED || $object->statut == SupplierProposal::STATUS_SIGNED) {
  1755. if ($usercansend) {
  1756. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
  1757. } else {
  1758. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
  1759. }
  1760. }
  1761. }
  1762. // Create an order
  1763. if (isModEnabled("supplier_order") && $object->statut == SupplierProposal::STATUS_SIGNED) {
  1764. if ($usercancreateorder) {
  1765. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'&amp;token='.newToken().'">'.$langs->trans("AddSupplierOrderShort").'</a></div>';
  1766. }
  1767. }
  1768. // Set accepted/refused
  1769. if ($object->statut == SupplierProposal::STATUS_VALIDATED && $usercanclose) {
  1770. print '<div class="inline-block divButAction"><a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=statut'.(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#acceptedrefused').'"';
  1771. print '>'.$langs->trans('SetAcceptedRefused').'</a></div>';
  1772. }
  1773. // Close
  1774. if ($object->statut == SupplierProposal::STATUS_SIGNED && $usercanclose) {
  1775. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;token='.newToken().'&amp;action=close'.(!getDolGlobalString('MAIN_JUMP_TAG') ? '' : '#close').'"';
  1776. print '>'.$langs->trans('Close').'</a></div>';
  1777. }
  1778. // Clone
  1779. if ($usercancreate) {
  1780. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&object='.$object->element.'&amp;token='.newToken().'">'.$langs->trans("ToClone").'</a></div>';
  1781. }
  1782. // Delete
  1783. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', (($object->statut == SupplierProposal::STATUS_DRAFT && $usercancreate) || $usercandelete));
  1784. }
  1785. }
  1786. print '</div>';
  1787. }
  1788. if ($action != 'presend') {
  1789. print '<div class="fichecenter"><div class="fichehalfleft">';
  1790. /*
  1791. * Generated documents
  1792. */
  1793. $filename = dol_sanitizeFileName($object->ref);
  1794. $filedir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
  1795. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1796. $genallowed = $usercanread;
  1797. $delallowed = $usercancreate;
  1798. print $formfile->showdocuments('supplier_proposal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
  1799. // Show links to link elements
  1800. $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal'));
  1801. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  1802. print '</div><div class="fichehalfright">';
  1803. // List of actions on element
  1804. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1805. $formactions = new FormActions($db);
  1806. $somethingshown = $formactions->showactions($object, 'supplier_proposal', $socid, 1);
  1807. print '</div></div>';
  1808. }
  1809. // Select mail models is same action as presend
  1810. if (GETPOST('modelselected')) {
  1811. $action = 'presend';
  1812. }
  1813. // Presend form
  1814. $modelmail = 'supplier_proposal_send';
  1815. $defaulttopic = 'SendAskRef';
  1816. $diroutput = $conf->supplier_proposal->dir_output;
  1817. $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO';
  1818. $trackid = 'spro'.$object->id;
  1819. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1820. }
  1821. // End of page
  1822. llxFooter();
  1823. $db->close();