card.php 77 KB

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