card.php 80 KB

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