card.php 76 KB

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