card.php 74 KB

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