card.php 83 KB

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