card.php 77 KB

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