card.php 82 KB

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