card.php 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 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@capnetworks.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2018 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  12. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  13. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  15. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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 <http://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/comm/propal/card.php
  32. * \ingroup propale
  33. * \brief Page of commercial proposals card and list
  34. */
  35. require '../../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formpropal.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmargin.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
  42. require_once DOL_DOCUMENT_ROOT . '/core/modules/propale/modules_propale.php';
  43. require_once DOL_DOCUMENT_ROOT . '/core/lib/propal.lib.php';
  44. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  45. require_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php';
  46. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  47. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  48. if (! empty($conf->projet->enabled)) {
  49. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  50. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  51. }
  52. if (!empty($conf->variants->enabled)) {
  53. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
  54. }
  55. // Load translation files required by the page
  56. $langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'sendings'));
  57. if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
  58. if (! empty($conf->margin->enabled))
  59. $langs->load('margins');
  60. $error = 0;
  61. $id = GETPOST('id', 'int');
  62. $ref = GETPOST('ref', 'alpha');
  63. $socid = GETPOST('socid', 'int');
  64. $action = GETPOST('action', 'alpha');
  65. $cancel = GETPOST('cancel', 'alpha');
  66. $origin = GETPOST('origin', 'alpha');
  67. $originid = GETPOST('originid', 'int');
  68. $confirm = GETPOST('confirm', 'alpha');
  69. $lineid = GETPOST('lineid', 'int');
  70. $contactid = GETPOST('contactid','int');
  71. $projectid = GETPOST('projectid','int');
  72. // PDF
  73. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  74. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  75. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  76. // Nombre de ligne pour choix de produit/service predefinis
  77. $NBLINES = 4;
  78. // Security check
  79. if (! empty($user->societe_id)) $socid = $user->societe_id;
  80. $result = restrictedArea($user, 'propal', $id);
  81. $object = new Propal($db);
  82. $extrafields = new ExtraFields($db);
  83. // fetch optionals attributes and labels
  84. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  85. // Load object
  86. if ($id > 0 || ! empty($ref)) {
  87. $ret = $object->fetch($id, $ref);
  88. if ($ret > 0)
  89. $ret = $object->fetch_thirdparty();
  90. if ($ret <= 0)
  91. {
  92. setEventMessages($object->error, $object->errors, 'errors');
  93. $action = '';
  94. }
  95. }
  96. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  97. $hookmanager->initHooks(array('propalcard','globalcard'));
  98. $usercanread = $user->rights->propal->lire;
  99. $usercancreate = $user->rights->propal->creer;
  100. $usercanclose = $user->rights->propal->cloturer;
  101. $usercandelete = $user->rights->propal->supprimer;
  102. $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->propal->propal_advance->validate)));
  103. $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send);
  104. $usercancreateorder = $user->rights->commande->creer;
  105. $usercancreateinvoice = $user->rights->facture->creer;
  106. $usercancreatecontract = $user->rights->contrat->creer;
  107. $usercancreateintervention = $user->rights->ficheinter->creer;
  108. $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
  109. $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
  110. $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
  111. /*
  112. * Actions
  113. */
  114. $parameters = array('socid' => $socid);
  115. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  116. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  117. if (empty($reshook))
  118. {
  119. if ($cancel)
  120. {
  121. if (! empty($backtopage))
  122. {
  123. header("Location: ".$backtopage);
  124. exit;
  125. }
  126. $action='';
  127. }
  128. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
  129. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  130. include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  131. // Action clone object
  132. if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate)
  133. {
  134. if (! GETPOST('socid', 3))
  135. {
  136. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  137. }
  138. else
  139. {
  140. if ($object->id > 0) {
  141. if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
  142. //Get difference between old and new delivery date and change lines according to difference
  143. $date_delivery = dol_mktime(12, 0, 0,
  144. GETPOST('date_deliverymonth', 'int'),
  145. GETPOST('date_deliveryday', 'int'),
  146. GETPOST('date_deliveryyear', 'int')
  147. );
  148. if (!empty($object->date_livraison) && !empty($date_delivery))
  149. {
  150. //Attempt to get the date without possible hour rounding errors
  151. $old_date_delivery = dol_mktime(12, 0, 0,
  152. dol_print_date($object->date_livraison, '%m'),
  153. dol_print_date($object->date_livraison, '%d'),
  154. dol_print_date($object->date_livraison, '%Y')
  155. );
  156. //Calculate the difference and apply if necessary
  157. $difference = $date_delivery - $old_date_delivery;
  158. if ($difference != 0)
  159. {
  160. $object->date_livraison = $date_delivery;
  161. foreach ($object->lines as $line)
  162. {
  163. if (isset($line->date_start)) $line->date_start = $line->date_start + $difference;
  164. if (isset($line->date_end)) $line->date_end = $line->date_end + $difference;
  165. }
  166. }
  167. }
  168. }
  169. $result = $object->createFromClone($socid);
  170. if ($result > 0) {
  171. header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
  172. exit();
  173. } else {
  174. if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');
  175. $action = '';
  176. }
  177. }
  178. }
  179. }
  180. // Delete proposal
  181. else if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete)
  182. {
  183. $result = $object->delete($user);
  184. if ($result > 0) {
  185. header('Location: ' . DOL_URL_ROOT . '/comm/propal/list.php?restore_lastsearch_values=1');
  186. exit();
  187. } else {
  188. $langs->load("errors");
  189. setEventMessages($object->error, $object->errors, 'errors');
  190. }
  191. }
  192. // Remove line
  193. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate)
  194. {
  195. $result = $object->deleteline($lineid);
  196. // reorder lines
  197. if ($result)
  198. $object->line_order(true);
  199. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  200. // Define output language
  201. $outputlangs = $langs;
  202. if (! empty($conf->global->MAIN_MULTILANGS)) {
  203. $outputlangs = new Translate("", $conf);
  204. $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
  205. $outputlangs->setDefaultLang($newlang);
  206. }
  207. $ret = $object->fetch($id); // Reload to get new records
  208. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  209. }
  210. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  211. exit();
  212. }
  213. // Validation
  214. else if ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate)
  215. {
  216. $result = $object->valid($user);
  217. if ($result >= 0)
  218. {
  219. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  220. {
  221. $outputlangs = $langs;
  222. $newlang = '';
  223. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
  224. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  225. if (! empty($newlang)) {
  226. $outputlangs = new Translate("", $conf);
  227. $outputlangs->setDefaultLang($newlang);
  228. }
  229. $model=$object->modelpdf;
  230. $ret = $object->fetch($id); // Reload to get new records
  231. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  232. }
  233. } else {
  234. $langs->load("errors");
  235. if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors');
  236. else setEventMessages($langs->trans($object->error), null, 'errors');
  237. }
  238. }
  239. else if ($action == 'setdate' && $usercancreate)
  240. {
  241. $datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  242. if (empty($datep)) {
  243. $error ++;
  244. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  245. }
  246. if (! $error) {
  247. $result = $object->set_date($user, $datep);
  248. if ($result < 0)
  249. dol_print_error($db, $object->error);
  250. }
  251. }
  252. else if ($action == 'setecheance' && $usercancreate)
  253. {
  254. $result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
  255. if ($result < 0)
  256. dol_print_error($db, $object->error);
  257. }
  258. else if ($action == 'setdate_livraison' && $usercancreate)
  259. {
  260. $result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear']));
  261. if ($result < 0)
  262. dol_print_error($db, $object->error);
  263. }
  264. // Positionne ref client
  265. else if ($action == 'setref_client' && $usercancreate)
  266. {
  267. $result = $object->set_ref_client($user, GETPOST('ref_client'));
  268. if ($result < 0)
  269. {
  270. setEventMessages($object->error, $object->errors, 'errors');
  271. }
  272. }
  273. // Set incoterm
  274. elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled) && $usercancreate)
  275. {
  276. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  277. }
  278. // Create proposal
  279. else if ($action == 'add' && $usercancreate)
  280. {
  281. $object->socid = $socid;
  282. $object->fetch_thirdparty();
  283. $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  284. $date_delivery = dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth'), GETPOST('date_livraisonday'), GETPOST('date_livraisonyear'));
  285. $duration = GETPOST('duree_validite');
  286. if (empty($datep)) {
  287. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  288. $action = 'create';
  289. $error ++;
  290. }
  291. if (empty($duration)) {
  292. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), null, 'errors');
  293. $action = 'create';
  294. $error ++;
  295. }
  296. if ($socid < 1) {
  297. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
  298. $action = 'create';
  299. $error ++;
  300. }
  301. if (! $error)
  302. {
  303. $db->begin();
  304. // If we select proposal to clone during creation (when option PROPAL_CLONE_ON_CREATE_PAGE is on)
  305. if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal'))
  306. {
  307. if ($object->fetch(GETPOST('copie_propal')) > 0) {
  308. $object->ref = GETPOST('ref');
  309. $object->datep = $datep;
  310. $object->date_livraison = $date_delivery;
  311. $object->availability_id = GETPOST('availability_id');
  312. $object->demand_reason_id = GETPOST('demand_reason_id');
  313. $object->fk_delivery_address = GETPOST('fk_address');
  314. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  315. $object->duree_validite = $duration;
  316. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  317. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  318. $object->fk_account = GETPOST('fk_account', 'int');
  319. $object->remise_percent = GETPOST('remise_percent');
  320. $object->remise_absolue = GETPOST('remise_absolue');
  321. $object->socid = GETPOST('socid');
  322. $object->contactid = GETPOST('contactid');
  323. $object->fk_project = GETPOST('projectid');
  324. $object->modelpdf = GETPOST('model');
  325. $object->author = $user->id; // deprecated
  326. $object->note_private = GETPOST('note_private','none');
  327. $object->note_public = GETPOST('note_public','none');
  328. $object->statut = Propal::STATUS_DRAFT;
  329. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  330. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  331. // the create is done below and further more the existing create_from function is quite hilarating
  332. //$id = $object->create_from($user);
  333. } else {
  334. setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors');
  335. }
  336. } else {
  337. $object->ref = GETPOST('ref');
  338. $object->ref_client = GETPOST('ref_client');
  339. $object->datep = $datep;
  340. $object->date_livraison = $date_delivery;
  341. $object->availability_id = GETPOST('availability_id');
  342. $object->demand_reason_id = GETPOST('demand_reason_id');
  343. $object->fk_delivery_address = GETPOST('fk_address');
  344. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  345. $object->duree_validite = GETPOST('duree_validite');
  346. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  347. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  348. $object->fk_account = GETPOST('fk_account', 'int');
  349. $object->contactid = GETPOST('contactid');
  350. $object->fk_project = GETPOST('projectid');
  351. $object->modelpdf = GETPOST('model');
  352. $object->author = $user->id; // deprecated
  353. $object->note_private = GETPOST('note_private','none');
  354. $object->note_public = GETPOST('note_public','none');
  355. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  356. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  357. $object->origin = GETPOST('origin');
  358. $object->origin_id = GETPOST('originid');
  359. // Multicurrency
  360. if (!empty($conf->multicurrency->enabled))
  361. {
  362. $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
  363. }
  364. // Fill array 'array_options' with data from add form
  365. $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  366. if ($ret < 0) {
  367. $error ++;
  368. $action = 'create';
  369. }
  370. }
  371. if (! $error)
  372. {
  373. if ($origin && $originid)
  374. {
  375. // Parse element/subelement (ex: project_task)
  376. $element = $subelement = $origin;
  377. if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
  378. $element = $regs [1];
  379. $subelement = $regs [2];
  380. }
  381. // For compatibility
  382. if ($element == 'order') {
  383. $element = $subelement = 'commande';
  384. }
  385. if ($element == 'propal') {
  386. $element = 'comm/propal';
  387. $subelement = 'propal';
  388. }
  389. if ($element == 'contract') {
  390. $element = $subelement = 'contrat';
  391. }
  392. if ($element == 'inter') {
  393. $element = $subelement = 'ficheinter';
  394. }
  395. if ($element == 'shipping') {
  396. $element = $subelement = 'expedition';
  397. }
  398. $object->origin = $origin;
  399. $object->origin_id = $originid;
  400. // Possibility to add external linked objects with hooks
  401. $object->linked_objects [$object->origin] = $object->origin_id;
  402. if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) {
  403. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  404. }
  405. $id = $object->create($user);
  406. if ($id > 0)
  407. {
  408. dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
  409. $classname = ucfirst($subelement);
  410. $srcobject = new $classname($db);
  411. dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
  412. $result = $srcobject->fetch($object->origin_id);
  413. if ($result > 0)
  414. {
  415. $lines = $srcobject->lines;
  416. if (empty($lines) && method_exists($srcobject, 'fetch_lines'))
  417. {
  418. $srcobject->fetch_lines();
  419. $lines = $srcobject->lines;
  420. }
  421. $fk_parent_line=0;
  422. $num=count($lines);
  423. for ($i=0;$i<$num;$i++)
  424. {
  425. $label=(! empty($lines[$i]->label)?$lines[$i]->label:'');
  426. $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle);
  427. // Positive line
  428. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  429. // Date start
  430. $date_start = false;
  431. if ($lines[$i]->date_debut_prevue)
  432. $date_start = $lines[$i]->date_debut_prevue;
  433. if ($lines[$i]->date_debut_reel)
  434. $date_start = $lines[$i]->date_debut_reel;
  435. if ($lines[$i]->date_start)
  436. $date_start = $lines[$i]->date_start;
  437. // Date end
  438. $date_end = false;
  439. if ($lines[$i]->date_fin_prevue)
  440. $date_end = $lines[$i]->date_fin_prevue;
  441. if ($lines[$i]->date_fin_reel)
  442. $date_end = $lines[$i]->date_fin_reel;
  443. if ($lines[$i]->date_end)
  444. $date_end = $lines[$i]->date_end;
  445. // Reset fk_parent_line for no child products and special product
  446. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  447. $fk_parent_line = 0;
  448. }
  449. // Extrafields
  450. if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
  451. $lines[$i]->fetch_optionals();
  452. $array_options = $lines[$i]->array_options;
  453. }
  454. $tva_tx = $lines[$i]->tva_tx;
  455. if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
  456. $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
  457. if ($result > 0) {
  458. $lineid = $result;
  459. } else {
  460. $lineid = 0;
  461. $error ++;
  462. break;
  463. }
  464. // Defined the new fk_parent_line
  465. if ($result > 0 && $lines[$i]->product_type == 9) {
  466. $fk_parent_line = $result;
  467. }
  468. }
  469. // Hooks
  470. $parameters = array('objFrom' => $srcobject);
  471. $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
  472. // modified by hook
  473. if ($reshook < 0)
  474. $error ++;
  475. } else {
  476. setEventMessages($srcobject->error, $srcobject->errors, 'errors');
  477. $error ++;
  478. }
  479. } else {
  480. setEventMessages($object->error, $object->errors, 'errors');
  481. $error ++;
  482. }
  483. } // Standard creation
  484. else
  485. {
  486. $id = $object->create($user);
  487. }
  488. if ($id > 0)
  489. {
  490. // Insertion contact par defaut si defini
  491. if (GETPOST('contactid') > 0)
  492. {
  493. $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
  494. if ($result < 0)
  495. {
  496. $error++;
  497. setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors');
  498. }
  499. }
  500. if (! $error)
  501. {
  502. $db->commit();
  503. // Define output language
  504. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  505. {
  506. $outputlangs = $langs;
  507. $newlang = '';
  508. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
  509. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  510. if (! empty($newlang)) {
  511. $outputlangs = new Translate("", $conf);
  512. $outputlangs->setDefaultLang($newlang);
  513. }
  514. $model=$object->modelpdf;
  515. $ret = $object->fetch($id); // Reload to get new records
  516. $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  517. if ($result < 0) dol_print_error($db,$result);
  518. }
  519. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
  520. exit();
  521. }
  522. else
  523. {
  524. $db->rollback();
  525. $action='create';
  526. }
  527. }
  528. else
  529. {
  530. setEventMessages($object->error, $object->errors, 'errors');
  531. $db->rollback();
  532. $action='create';
  533. }
  534. }
  535. }
  536. }
  537. // Classify billed
  538. else if ($action == 'classifybilled' && $usercanclose)
  539. {
  540. $result=$object->cloture($user, 4, '');
  541. if ($result < 0)
  542. {
  543. setEventMessages($object->error, $object->errors, 'errors');
  544. $error++;
  545. }
  546. }
  547. // Close proposal
  548. else if ($action == 'setstatut' && $usercanclose && ! GETPOST('cancel','alpha'))
  549. {
  550. if (! (GETPOST('statut','int') > 0)) {
  551. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
  552. $action = 'statut';
  553. } else {
  554. // prevent browser refresh from closing proposal several times
  555. if ($object->statut == Propal::STATUS_VALIDATED)
  556. {
  557. $result=$object->cloture($user, GETPOST('statut','int'), GETPOST('note_private','none'));
  558. if ($result < 0)
  559. {
  560. setEventMessages($object->error, $object->errors, 'errors');
  561. $error++;
  562. }
  563. }
  564. }
  565. }
  566. // Reopen proposal
  567. else if ($action == 'confirm_reopen' && $usercanclose && ! GETPOST('cancel','alpha'))
  568. {
  569. // prevent browser refresh from reopening proposal several times
  570. if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED)
  571. {
  572. $result=$object->reopen($user, 1);
  573. if ($result < 0)
  574. {
  575. setEventMessages($object->error, $object->errors, 'errors');
  576. $error++;
  577. }
  578. }
  579. }
  580. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  581. // Actions to send emails
  582. $actiontypecode='AC_OTH_AUTO';
  583. $trigger_name='PROPAL_SENTBYMAIL';
  584. $autocopy='MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
  585. $trackid='pro'.$object->id;
  586. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  587. // Go back to draft
  588. if ($action == 'modif' && $usercancreate)
  589. {
  590. $object->set_draft($user);
  591. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  592. {
  593. // Define output language
  594. $outputlangs = $langs;
  595. if (! empty($conf->global->MAIN_MULTILANGS)) {
  596. $outputlangs = new Translate("", $conf);
  597. $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
  598. $outputlangs->setDefaultLang($newlang);
  599. }
  600. $ret = $object->fetch($id); // Reload to get new records
  601. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  602. }
  603. }
  604. else if ($action == "setabsolutediscount" && $usercancreate) {
  605. if ($_POST["remise_id"]) {
  606. if ($object->id > 0) {
  607. $result = $object->insert_discount($_POST["remise_id"]);
  608. if ($result < 0) {
  609. setEventMessages($object->error, $object->errors, 'errors');
  610. }
  611. }
  612. }
  613. }
  614. // Add line
  615. else if ($action == 'addline' && $usercancreate) {
  616. // Set if we used free entry or predefined product
  617. $predef='';
  618. $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
  619. $price_ht = GETPOST('price_ht');
  620. $price_ht_devise = GETPOST('multicurrency_price_ht');
  621. $prod_entry_mode = GETPOST('prod_entry_mode');
  622. if ($prod_entry_mode == 'free')
  623. {
  624. $idprod=0;
  625. $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
  626. }
  627. else
  628. {
  629. $idprod=GETPOST('idprod', 'int');
  630. $tva_tx = '';
  631. }
  632. $qty = GETPOST('qty' . $predef);
  633. $remise_percent = GETPOST('remise_percent' . $predef);
  634. // Extrafields
  635. $extrafieldsline = new ExtraFields($db);
  636. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  637. $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
  638. // Unset extrafield
  639. if (is_array($extralabelsline)) {
  640. // Get extra fields
  641. foreach ($extralabelsline as $key => $value) {
  642. unset($_POST["options_" . $key]);
  643. }
  644. }
  645. if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('type') < 0) {
  646. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  647. $error ++;
  648. }
  649. if ($prod_entry_mode == 'free' && empty($idprod) && $price_ht == '' && $price_ht_devise == '') // Unit price can be 0 but not ''. Also price can be negative for proposal.
  650. {
  651. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
  652. $error ++;
  653. }
  654. if ($prod_entry_mode == 'free' && empty($idprod) && empty($product_desc)) {
  655. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
  656. $error ++;
  657. }
  658. if (!$error && !empty($conf->variants->enabled) && $prod_entry_mode != 'free') {
  659. if ($combinations = GETPOST('combinations', 'array')) {
  660. //Check if there is a product with the given combination
  661. $prodcomb = new ProductCombination($db);
  662. if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
  663. $idprod = $res->fk_product_child;
  664. } else {
  665. setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
  666. $error ++;
  667. }
  668. }
  669. }
  670. if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
  671. $pu_ht = 0;
  672. $pu_ttc = 0;
  673. $price_min = 0;
  674. $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
  675. $db->begin();
  676. // $tva_tx can be 'x.x (XXX)'
  677. // Ecrase $pu par celui du produit
  678. // Ecrase $desc par celui du produit
  679. // Ecrase $tva_tx par celui du produit
  680. // Replaces $fk_unit with the product unit
  681. if (! empty($idprod)) {
  682. $prod = new Product($db);
  683. $prod->fetch($idprod);
  684. $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
  685. // Update if prices fields are defined
  686. $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
  687. $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
  688. if (empty($tva_tx)) $tva_npr=0;
  689. // Price unique per product
  690. $pu_ht = $prod->price;
  691. $pu_ttc = $prod->price_ttc;
  692. $price_min = $prod->price_min;
  693. $price_base_type = $prod->price_base_type;
  694. // If price per segment
  695. if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level)
  696. {
  697. $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
  698. $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
  699. $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
  700. $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
  701. if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility
  702. {
  703. if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
  704. if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
  705. }
  706. }
  707. // If price per customer
  708. elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
  709. {
  710. require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
  711. $prodcustprice = new Productcustomerprice($db);
  712. $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
  713. $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
  714. if ($result) {
  715. // If there is some prices specific to the customer
  716. if (count($prodcustprice->lines) > 0) {
  717. $pu_ht = price($prodcustprice->lines[0]->price);
  718. $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
  719. $price_base_type = $prodcustprice->lines[0]->price_base_type;
  720. $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx . ' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
  721. if ($prodcustprice->lines[0]->default_vat_code && ! preg_match('/\(.*\)/', $tva_tx)) $tva_tx.= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
  722. $tva_npr = $prodcustprice->lines[0]->recuperableonly;
  723. if (empty($tva_tx)) $tva_npr=0;
  724. }
  725. }
  726. }
  727. // If price per quantity
  728. elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
  729. {
  730. if ($prod->prices_by_qty[0]) // yes, this product has some prices per quantity
  731. {
  732. // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
  733. $pqp = GETPOST('pbq','int');
  734. // Search price into product_price_by_qty from $prod->id
  735. foreach($prod->prices_by_qty_list[0] as $priceforthequantityarray)
  736. {
  737. if ($priceforthequantityarray['rowid'] != $pqp) continue;
  738. // We found the price
  739. if ($priceforthequantityarray['price_base_type'] == 'HT')
  740. {
  741. $pu_ht = $priceforthequantityarray['unitprice'];
  742. }
  743. else
  744. {
  745. $pu_ttc = $priceforthequantityarray['unitprice'];
  746. }
  747. // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
  748. break;
  749. }
  750. }
  751. }
  752. // If price per quantity and customer
  753. elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
  754. {
  755. if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity
  756. {
  757. // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
  758. $pqp = GETPOST('pbq','int');
  759. // Search price into product_price_by_qty from $prod->id
  760. foreach($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray)
  761. {
  762. if ($priceforthequantityarray['rowid'] != $pqp) continue;
  763. // We found the price
  764. if ($priceforthequantityarray['price_base_type'] == 'HT')
  765. {
  766. $pu_ht = $priceforthequantityarray['unitprice'];
  767. }
  768. else
  769. {
  770. $pu_ttc = $priceforthequantityarray['unitprice'];
  771. }
  772. // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
  773. break;
  774. }
  775. }
  776. }
  777. $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
  778. $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
  779. // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ?
  780. if (! empty($price_ht)) {
  781. $pu_ht = price2num($price_ht, 'MU');
  782. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  783. }
  784. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  785. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  786. elseif ($tmpvat != $tmpprodvat) {
  787. if ($price_base_type != 'HT') {
  788. $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
  789. } else {
  790. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  791. }
  792. }
  793. $desc = '';
  794. // Define output language
  795. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  796. $outputlangs = $langs;
  797. $newlang = '';
  798. if (empty($newlang) && GETPOST('lang_id','aZ09'))
  799. $newlang = GETPOST('lang_id','aZ09');
  800. if (empty($newlang))
  801. $newlang = $object->thirdparty->default_lang;
  802. if (! empty($newlang)) {
  803. $outputlangs = new Translate("", $conf);
  804. $outputlangs->setDefaultLang($newlang);
  805. }
  806. $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
  807. } else {
  808. $desc = $prod->description;
  809. }
  810. $desc = dol_concatdesc($desc, $product_desc);
  811. // Add dimensions into product description
  812. /*if (empty($conf->global->MAIN_PRODUCT_DISABLE_AUTOADD_DIM))
  813. {
  814. $text='';
  815. if ($prod->weight) $text.=($text?"\n":"").$outputlangs->trans("Weight").': '.$prod->weight.' '.$prod->weight_units;
  816. if ($prod->length) $text.=($text?"\n":"").$outputlangs->trans("Length").': '.$prod->length.' '.$prod->length_units;
  817. if ($prod->surface) $text.=($text?"\n":"").$outputlangs->trans("Surface").': '.$prod->surface.' '.$prod->surface_units;
  818. if ($prod->volume) $text.=($text?"\n":"").$outputlangs->trans("Volume").': '.$prod->volume.' '.$prod->volume_units;
  819. $desc = dol_concatdesc($desc, $text);
  820. }*/
  821. // Add custom code and origin country into description
  822. if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
  823. {
  824. // Define output language
  825. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  826. $outputlangs = $langs;
  827. $newlang = '';
  828. if (empty($newlang) && GETPOST('lang_id','alpha'))
  829. $newlang = GETPOST('lang_id','alpha');
  830. if (empty($newlang))
  831. $newlang = $object->thirdparty->default_lang;
  832. if (! empty($newlang)) {
  833. $outputlangs = new Translate("", $conf);
  834. $outputlangs->setDefaultLang($newlang);
  835. $outputlangs->load('products');
  836. }
  837. if (! empty($prod->customcode))
  838. $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
  839. if (! empty($prod->customcode) && ! empty($prod->country_code))
  840. $tmptxt .= ' - ';
  841. if (! empty($prod->country_code))
  842. $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
  843. } else {
  844. if (! empty($prod->customcode))
  845. $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
  846. if (! empty($prod->customcode) && ! empty($prod->country_code))
  847. $tmptxt .= ' - ';
  848. if (! empty($prod->country_code))
  849. $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
  850. }
  851. $tmptxt .= ')';
  852. $desc = dol_concatdesc($desc, $tmptxt);
  853. }
  854. $type = $prod->type;
  855. $fk_unit = $prod->fk_unit;
  856. } else {
  857. $pu_ht = price2num($price_ht, 'MU');
  858. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  859. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  860. $tva_tx = str_replace('*', '', $tva_tx);
  861. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  862. $desc = $product_desc;
  863. $type = GETPOST('type');
  864. $fk_unit = GETPOST('units', 'alpha');
  865. $pu_ht_devise = price2num($price_ht_devise, 'MU');
  866. }
  867. // Margin
  868. $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
  869. $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
  870. $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'));
  871. $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'));
  872. // Local Taxes
  873. $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
  874. $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
  875. $info_bits = 0;
  876. if ($tva_npr)
  877. $info_bits |= 0x01;
  878. if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS) ) && (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) {
  879. $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
  880. setEventMessages($mesg, null, 'errors');
  881. } else {
  882. // Insert line
  883. $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, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
  884. if ($result > 0) {
  885. $db->commit();
  886. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  887. // Define output language
  888. $outputlangs = $langs;
  889. if (! empty($conf->global->MAIN_MULTILANGS)) {
  890. $outputlangs = new Translate("", $conf);
  891. $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
  892. $outputlangs->setDefaultLang($newlang);
  893. }
  894. $ret = $object->fetch($id); // Reload to get new records
  895. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  896. }
  897. unset($_POST['prod_entry_mode']);
  898. unset($_POST['qty']);
  899. unset($_POST['type']);
  900. unset($_POST['remise_percent']);
  901. unset($_POST['price_ht']);
  902. unset($_POST['multicurrency_price_ht']);
  903. unset($_POST['price_ttc']);
  904. unset($_POST['tva_tx']);
  905. unset($_POST['product_ref']);
  906. unset($_POST['product_label']);
  907. unset($_POST['product_desc']);
  908. unset($_POST['fournprice']);
  909. unset($_POST['buying_price']);
  910. unset($_POST['np_marginRate']);
  911. unset($_POST['np_markRate']);
  912. unset($_POST['dp_desc']);
  913. unset($_POST['idprod']);
  914. unset($_POST['units']);
  915. unset($_POST['date_starthour']);
  916. unset($_POST['date_startmin']);
  917. unset($_POST['date_startsec']);
  918. unset($_POST['date_startday']);
  919. unset($_POST['date_startmonth']);
  920. unset($_POST['date_startyear']);
  921. unset($_POST['date_endhour']);
  922. unset($_POST['date_endmin']);
  923. unset($_POST['date_endsec']);
  924. unset($_POST['date_endday']);
  925. unset($_POST['date_endmonth']);
  926. unset($_POST['date_endyear']);
  927. } else {
  928. $db->rollback();
  929. setEventMessages($object->error, $object->errors, 'errors');
  930. }
  931. }
  932. }
  933. }
  934. // Update a line within proposal
  935. else if ($action == 'updateligne' && $usercancreate && GETPOST('save'))
  936. {
  937. // Define info_bits
  938. $info_bits = 0;
  939. if (preg_match('/\*/', GETPOST('tva_tx')))
  940. $info_bits |= 0x01;
  941. // Clean parameters
  942. $description = dol_htmlcleanlastbr(GETPOST('product_desc','none'));
  943. // Define vat_rate
  944. $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
  945. $vat_rate = str_replace('*', '', $vat_rate);
  946. $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
  947. $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
  948. $pu_ht = GETPOST('price_ht');
  949. // Add buying price
  950. $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
  951. $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
  952. $pu_ht_devise = GETPOST('multicurrency_subprice');
  953. $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  954. $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  955. // Extrafields
  956. $extrafieldsline = new ExtraFields($db);
  957. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  958. $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
  959. // Unset extrafield
  960. if (is_array($extralabelsline)) {
  961. // Get extra fields
  962. foreach ($extralabelsline as $key => $value) {
  963. unset($_POST["options_" . $key]);
  964. }
  965. }
  966. // Define special_code for special lines
  967. $special_code=GETPOST('special_code');
  968. if (! GETPOST('qty')) $special_code=3;
  969. // Check minimum price
  970. $productid = GETPOST('productid', 'int');
  971. if (! empty($productid)) {
  972. $product = new Product($db);
  973. $res = $product->fetch($productid);
  974. $type = $product->type;
  975. $price_min = $product->price_min;
  976. if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
  977. $price_min = $product->multiprices_min [$object->thirdparty->price_level];
  978. $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
  979. if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS) )&& ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min)))) {
  980. setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
  981. $error ++;
  982. }
  983. } else {
  984. $type = GETPOST('type');
  985. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  986. // Check parameters
  987. if (GETPOST('type') < 0) {
  988. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  989. $error ++;
  990. }
  991. }
  992. if (! $error) {
  993. $db->begin();
  994. if (empty($user->rights->margins->creer))
  995. {
  996. foreach ($object->lines as &$line)
  997. {
  998. if ($line->id == GETPOST('lineid'))
  999. {
  1000. $fournprice = $line->fk_fournprice;
  1001. $buyingprice = $line->pa_ht;
  1002. break;
  1003. }
  1004. }
  1005. }
  1006. $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, $date_start, $date_end, $array_options, $_POST["units"], $pu_ht_devise);
  1007. if ($result >= 0) {
  1008. $db->commit();
  1009. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  1010. // Define output language
  1011. $outputlangs = $langs;
  1012. if (! empty($conf->global->MAIN_MULTILANGS)) {
  1013. $outputlangs = new Translate("", $conf);
  1014. $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang);
  1015. $outputlangs->setDefaultLang($newlang);
  1016. }
  1017. $ret = $object->fetch($id); // Reload to get new records
  1018. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1019. }
  1020. unset($_POST['qty']);
  1021. unset($_POST['type']);
  1022. unset($_POST['productid']);
  1023. unset($_POST['remise_percent']);
  1024. unset($_POST['price_ht']);
  1025. unset($_POST['multicurrency_price_ht']);
  1026. unset($_POST['price_ttc']);
  1027. unset($_POST['tva_tx']);
  1028. unset($_POST['product_ref']);
  1029. unset($_POST['product_label']);
  1030. unset($_POST['product_desc']);
  1031. unset($_POST['fournprice']);
  1032. unset($_POST['buying_price']);
  1033. unset($_POST['date_starthour']);
  1034. unset($_POST['date_startmin']);
  1035. unset($_POST['date_startsec']);
  1036. unset($_POST['date_startday']);
  1037. unset($_POST['date_startmonth']);
  1038. unset($_POST['date_startyear']);
  1039. unset($_POST['date_endhour']);
  1040. unset($_POST['date_endmin']);
  1041. unset($_POST['date_endsec']);
  1042. unset($_POST['date_endday']);
  1043. unset($_POST['date_endmonth']);
  1044. unset($_POST['date_endyear']);
  1045. } else {
  1046. $db->rollback();
  1047. setEventMessages($object->error, $object->errors, 'errors');
  1048. }
  1049. }
  1050. }
  1051. else if ($action == 'updateligne' && $usercancreate && GETPOST('cancel','alpha'))
  1052. {
  1053. header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
  1054. exit();
  1055. }
  1056. // Set project
  1057. else if ($action == 'classin' && $usercancreate) {
  1058. $object->setProject(GETPOST('projectid','int'));
  1059. }
  1060. // Delai de livraison
  1061. else if ($action == 'setavailability' && $usercancreate) {
  1062. $result = $object->set_availability($user, GETPOST('availability_id','int'));
  1063. }
  1064. // Origine de la propale
  1065. else if ($action == 'setdemandreason' && $usercancreate) {
  1066. $result = $object->set_demand_reason($user, GETPOST('demand_reason_id','int'));
  1067. }
  1068. // Conditions de reglement
  1069. else if ($action == 'setconditions' && $usercancreate) {
  1070. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
  1071. }
  1072. else if ($action == 'setremisepercent' && $usercancreate) {
  1073. $result = $object->set_remise_percent($user, $_POST['remise_percent']);
  1074. }
  1075. else if ($action == 'setremiseabsolue' && $usercancreate) {
  1076. $result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
  1077. }
  1078. // Mode de reglement
  1079. else if ($action == 'setmode' && $usercancreate) {
  1080. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  1081. }
  1082. // Multicurrency Code
  1083. else if ($action == 'setmulticurrencycode' && $usercancreate) {
  1084. $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
  1085. }
  1086. // Multicurrency rate
  1087. else if ($action == 'setmulticurrencyrate' && $usercancreate) {
  1088. $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')));
  1089. }
  1090. // bank account
  1091. else if ($action == 'setbankaccount' && $usercancreate) {
  1092. $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
  1093. }
  1094. // shipping method
  1095. else if ($action == 'setshippingmethod' && $usercancreate) {
  1096. $result=$object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
  1097. }
  1098. else if ($action == 'update_extras') {
  1099. $object->oldcopy = dol_clone($object);
  1100. // Fill array 'array_options' with data from update form
  1101. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  1102. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
  1103. if ($ret < 0) $error++;
  1104. if (! $error)
  1105. {
  1106. $result = $object->insertExtraFields('PROPAL_MODIFY');
  1107. if ($result < 0)
  1108. {
  1109. setEventMessages($object->error, $object->errors, 'errors');
  1110. $error++;
  1111. }
  1112. }
  1113. if ($error) $action = 'edit_extras';
  1114. }
  1115. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate)
  1116. {
  1117. if ($action == 'addcontact')
  1118. {
  1119. if ($object->id > 0) {
  1120. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  1121. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  1122. }
  1123. if ($result >= 0) {
  1124. header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
  1125. exit();
  1126. } else {
  1127. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  1128. $langs->load("errors");
  1129. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  1130. } else {
  1131. setEventMessages($object->error, $object->errors, 'errors');
  1132. }
  1133. }
  1134. }
  1135. // Bascule du statut d'un contact
  1136. else if ($action == 'swapstatut') {
  1137. if ($object->fetch($id) > 0) {
  1138. $result = $object->swapContactStatus(GETPOST('ligne'));
  1139. } else {
  1140. dol_print_error($db);
  1141. }
  1142. }
  1143. // Efface un contact
  1144. else if ($action == 'deletecontact') {
  1145. $object->fetch($id);
  1146. $result = $object->delete_contact($lineid);
  1147. if ($result >= 0) {
  1148. header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
  1149. exit();
  1150. } else {
  1151. dol_print_error($db);
  1152. }
  1153. }
  1154. }
  1155. // Actions to build doc
  1156. $upload_dir = $conf->propal->multidir_output[$object->entity];
  1157. $permissioncreate=$usercancreate;
  1158. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  1159. }
  1160. /*
  1161. * View
  1162. */
  1163. llxHeader('', $langs->trans('Proposal'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  1164. $form = new Form($db);
  1165. $formother = new FormOther($db);
  1166. $formfile = new FormFile($db);
  1167. $formpropal = new FormPropal($db);
  1168. $formmargin = new FormMargin($db);
  1169. $companystatic = new Societe($db);
  1170. if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  1171. $now = dol_now();
  1172. // Add new proposal
  1173. if ($action == 'create')
  1174. {
  1175. $currency_code = $conf->currency;
  1176. print load_fiche_titre($langs->trans("NewProp"));
  1177. $soc = new Societe($db);
  1178. if ($socid > 0)
  1179. $res = $soc->fetch($socid);
  1180. // Load objectsrc
  1181. if (! empty($origin) && ! empty($originid))
  1182. {
  1183. // Parse element/subelement (ex: project_task)
  1184. $element = $subelement = $origin;
  1185. if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
  1186. $element = $regs [1];
  1187. $subelement = $regs [2];
  1188. }
  1189. if ($element == 'project') {
  1190. $projectid = $originid;
  1191. } else {
  1192. // For compatibility
  1193. if ($element == 'order' || $element == 'commande') {
  1194. $element = $subelement = 'commande';
  1195. }
  1196. if ($element == 'propal') {
  1197. $element = 'comm/propal';
  1198. $subelement = 'propal';
  1199. }
  1200. if ($element == 'contract') {
  1201. $element = $subelement = 'contrat';
  1202. }
  1203. if ($element == 'shipping') {
  1204. $element = $subelement = 'expedition';
  1205. }
  1206. dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
  1207. $classname = ucfirst($subelement);
  1208. $objectsrc = new $classname($db);
  1209. $objectsrc->fetch($originid);
  1210. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
  1211. {
  1212. $objectsrc->fetch_lines();
  1213. }
  1214. $objectsrc->fetch_thirdparty();
  1215. $projectid = (! empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
  1216. $ref_client = (! empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
  1217. $ref_int = (! empty($objectsrc->ref_int) ? $objectsrc->ref_int : '');
  1218. $soc = $objectsrc->thirdparty;
  1219. $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
  1220. $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
  1221. $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0));
  1222. $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
  1223. $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice);
  1224. // Replicate extrafields
  1225. $objectsrc->fetch_optionals($originid);
  1226. $object->array_options = $objectsrc->array_options;
  1227. if (!empty($conf->multicurrency->enabled))
  1228. {
  1229. if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
  1230. if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
  1231. }
  1232. }
  1233. }
  1234. else
  1235. {
  1236. if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
  1237. }
  1238. $object = new Propal($db);
  1239. print '<form name="addprop" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  1240. print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  1241. print '<input type="hidden" name="action" value="add">';
  1242. if ($origin != 'project' && $originid) {
  1243. print '<input type="hidden" name="origin" value="' . $origin . '">';
  1244. print '<input type="hidden" name="originid" value="' . $originid . '">';
  1245. } elseif ($origin == 'project' && !empty($projectid)) {
  1246. print '<input type="hidden" name="projectid" value="' . $projectid . '">';
  1247. }
  1248. dol_fiche_head();
  1249. print '<table class="border" width="100%">';
  1250. // Reference
  1251. print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans('Ref') . '</td><td>' . $langs->trans("Draft") . '</td></tr>';
  1252. // Ref customer
  1253. print '<tr><td>' . $langs->trans('RefCustomer') . '</td><td>';
  1254. print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
  1255. print '</tr>';
  1256. // Third party
  1257. print '<tr>';
  1258. print '<td class="fieldrequired">' . $langs->trans('Customer') . '</td>';
  1259. if ($socid > 0) {
  1260. print '<td>';
  1261. print $soc->getNomUrl(1);
  1262. print '<input type="hidden" name="socid" value="' . $soc->id . '">';
  1263. print '</td>';
  1264. if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && ! empty($soc->shipping_method_id)) {
  1265. $shipping_method_id = $soc->shipping_method_id;
  1266. }
  1267. } else {
  1268. print '<td>';
  1269. print $form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300');
  1270. // reload page to retrieve customer informations
  1271. if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE))
  1272. {
  1273. print '<script type="text/javascript">
  1274. $(document).ready(function() {
  1275. $("#socid").change(function() {
  1276. var socid = $(this).val();
  1277. // reload page
  1278. window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&ref_client="+$("input[name=ref_client]").val();
  1279. });
  1280. });
  1281. </script>';
  1282. }
  1283. print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'">'.$langs->trans("AddThirdParty").'</a>';
  1284. print '</td>';
  1285. }
  1286. print '</tr>' . "\n";
  1287. if ($socid > 0)
  1288. {
  1289. // Contacts (ask contact only if thirdparty already defined). TODO do this also into order and invoice.
  1290. print "<tr><td>" . $langs->trans("DefaultContact") . '</td><td>';
  1291. $form->select_contacts($soc->id, $contactid, 'contactid', 1, $srccontactslist);
  1292. print '</td></tr>';
  1293. // Ligne info remises tiers
  1294. print '<tr><td>' . $langs->trans('Discounts') . '</td><td>';
  1295. $absolute_discount = $soc->getAvailableDiscounts();
  1296. $thirdparty = $soc;
  1297. $discount_type = 0;
  1298. $backtopage = urlencode($_SERVER["PHP_SELF"] . '?socid=' . $thirdparty->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid'));
  1299. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  1300. print '</td></tr>';
  1301. }
  1302. // Date
  1303. print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td>';
  1304. print $form->selectDate('', '', '', '', '', "addprop", 1, 1);
  1305. print '</td></tr>';
  1306. // Validaty duration
  1307. print '<tr><td class="fieldrequired">' . $langs->trans("ValidityDuration") . '</td><td><input name="duree_validite" size="5" value="' . $conf->global->PROPALE_VALIDITY_DURATION . '"> ' . $langs->trans("days") . '</td></tr>';
  1308. // Terms of payment
  1309. print '<tr><td class="nowrap fieldrequired">' . $langs->trans('PaymentConditionsShort') . '</td><td>';
  1310. $form->select_conditions_paiements($soc->cond_reglement_id, 'cond_reglement_id');
  1311. print '</td></tr>';
  1312. // Mode of payment
  1313. print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td>';
  1314. $form->select_types_paiements($soc->mode_reglement_id, 'mode_reglement_id');
  1315. print '</td></tr>';
  1316. // Bank Account
  1317. if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && ! empty($conf->banque->enabled)) {
  1318. print '<tr><td>' . $langs->trans('BankAccount') . '</td><td>';
  1319. $form->select_comptes($soc->fk_account, 'fk_account', 0, '', 1);
  1320. print '</td></tr>';
  1321. }
  1322. // What trigger creation
  1323. print '<tr><td>' . $langs->trans('Source') . '</td><td>';
  1324. $form->selectInputReason('', 'demand_reason_id', "SRC_PROP", 1);
  1325. print '</td></tr>';
  1326. // Delivery delay
  1327. print '<tr class="fielddeliverydelay"><td>' . $langs->trans('AvailabilityPeriod') . '</td><td>';
  1328. $form->selectAvailabilityDelay('', 'availability_id', '', 1);
  1329. print '</td></tr>';
  1330. // Shipping Method
  1331. if (! empty($conf->expedition->enabled)) {
  1332. print '<tr><td>' . $langs->trans('SendingMethod') . '</td><td>';
  1333. print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1);
  1334. print '</td></tr>';
  1335. }
  1336. // Delivery date (or manufacturing)
  1337. print '<tr><td>' . $langs->trans("DeliveryDate") . '</td>';
  1338. print '<td>';
  1339. if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "") {
  1340. $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
  1341. $syear = date("Y", $tmpdte);
  1342. $smonth = date("m", $tmpdte);
  1343. $sday = date("d", $tmpdte);
  1344. print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop");
  1345. } else {
  1346. print $form->selectDate(-1, 'date_livraison', '', '', '', "addprop", 1, 1);
  1347. }
  1348. print '</td></tr>';
  1349. // Project
  1350. if (! empty($conf->projet->enabled))
  1351. {
  1352. $langs->load("projects");
  1353. print '<tr>';
  1354. print '<td>' . $langs->trans("Project") . '</td><td>';
  1355. $numprojet = $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1);
  1356. 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>';
  1357. print '</td>';
  1358. print '</tr>';
  1359. }
  1360. // Incoterms
  1361. if (!empty($conf->incoterm->enabled))
  1362. {
  1363. print '<tr>';
  1364. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->libelle_incoterms, 1).'</label></td>';
  1365. print '<td class="maxwidthonsmartphone">';
  1366. print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms)?$soc->location_incoterms:''));
  1367. print '</td></tr>';
  1368. }
  1369. // Template to use by default
  1370. print '<tr>';
  1371. print '<td>' . $langs->trans("DefaultModel") . '</td>';
  1372. print '<td>';
  1373. $liste = ModelePDFPropales::liste_modeles($db);
  1374. print $form->selectarray('model', $liste, ($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : $conf->global->PROPALE_ADDON_PDF));
  1375. print "</td></tr>";
  1376. // Multicurrency
  1377. if (! empty($conf->multicurrency->enabled))
  1378. {
  1379. print '<tr>';
  1380. print '<td>'.fieldLabel('Currency','multicurrency_code').'</td>';
  1381. print '<td class="maxwidthonsmartphone">';
  1382. print $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0);
  1383. print '</td></tr>';
  1384. }
  1385. // Public note
  1386. print '<tr>';
  1387. print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
  1388. print '<td valign="top">';
  1389. $note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
  1390. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  1391. print $doleditor->Create(1);
  1392. // Private note
  1393. if (empty($user->societe_id))
  1394. {
  1395. print '<tr>';
  1396. print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>';
  1397. print '<td valign="top">';
  1398. $note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
  1399. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  1400. print $doleditor->Create(1);
  1401. // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
  1402. print '</td></tr>';
  1403. }
  1404. // Other attributes
  1405. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  1406. // Lines from source
  1407. if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
  1408. {
  1409. // TODO for compatibility
  1410. if ($origin == 'contrat') {
  1411. // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
  1412. $objectsrc->remise_absolue = $remise_absolue;
  1413. $objectsrc->remise_percent = $remise_percent;
  1414. $objectsrc->update_price(1, - 1, 1);
  1415. }
  1416. print "\n<!-- " . $classname . " info -->";
  1417. print "\n";
  1418. print '<input type="hidden" name="amount" value="' . $objectsrc->total_ht . '">' . "\n";
  1419. print '<input type="hidden" name="total" value="' . $objectsrc->total_ttc . '">' . "\n";
  1420. print '<input type="hidden" name="tva" value="' . $objectsrc->total_tva . '">' . "\n";
  1421. print '<input type="hidden" name="origin" value="' . $objectsrc->element . '">';
  1422. print '<input type="hidden" name="originid" value="' . $objectsrc->id . '">';
  1423. $newclassname = $classname;
  1424. if ($newclassname == 'Propal')
  1425. $newclassname = 'CommercialProposal';
  1426. elseif ($newclassname == 'Commande')
  1427. $newclassname = 'Order';
  1428. elseif ($newclassname == 'Expedition')
  1429. $newclassname = 'Sending';
  1430. elseif ($newclassname == 'Fichinter')
  1431. $newclassname = 'Intervention';
  1432. print '<tr><td>' . $langs->trans($newclassname) . '</td><td>' . $objectsrc->getNomUrl(1) . '</td></tr>';
  1433. print '<tr><td>' . $langs->trans('TotalHT') . '</td><td>' . price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . '</td></tr>';
  1434. print '<tr><td>' . $langs->trans('TotalVAT') . '</td><td>' . price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
  1435. if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0 ) // Localtax1
  1436. {
  1437. print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
  1438. }
  1439. if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2
  1440. {
  1441. print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
  1442. }
  1443. print '<tr><td>' . $langs->trans('TotalTTC') . '</td><td>' . price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . "</td></tr>";
  1444. }
  1445. print "</table>\n";
  1446. /*
  1447. * Combobox pour la fonction de copie
  1448. */
  1449. if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) print '<input type="hidden" name="createmode" value="empty">';
  1450. if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
  1451. {
  1452. print '<br><table>';
  1453. // For backward compatibility
  1454. print '<tr>';
  1455. print '<td><input type="radio" name="createmode" value="copy"></td>';
  1456. print '<td>' . $langs->trans("CopyPropalFrom") . ' </td>';
  1457. print '<td>';
  1458. $liste_propal = array();
  1459. $liste_propal [0] = '';
  1460. $sql = "SELECT p.rowid as id, p.ref, s.nom";
  1461. $sql .= " FROM " . MAIN_DB_PREFIX . "propal p";
  1462. $sql .= ", " . MAIN_DB_PREFIX . "societe s";
  1463. $sql .= " WHERE s.rowid = p.fk_soc";
  1464. $sql .= " AND p.entity IN (".getEntity('propal').")";
  1465. $sql .= " AND p.fk_statut <> 0";
  1466. $sql .= " ORDER BY Id";
  1467. $resql = $db->query($sql);
  1468. if ($resql) {
  1469. $num = $db->num_rows($resql);
  1470. $i = 0;
  1471. while ($i < $num) {
  1472. $row = $db->fetch_row($resql);
  1473. $propalRefAndSocName = $row [1] . " - " . $row [2];
  1474. $liste_propal [$row [0]] = $propalRefAndSocName;
  1475. $i ++;
  1476. }
  1477. print $form->selectarray("copie_propal", $liste_propal, 0);
  1478. } else {
  1479. dol_print_error($db);
  1480. }
  1481. print '</td></tr>';
  1482. print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
  1483. print '<td valign="top" colspan="2">' . $langs->trans("CreateEmptyPropal") . '</td></tr>';
  1484. }
  1485. if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) print '</table>';
  1486. dol_fiche_end();
  1487. $langs->load("bills");
  1488. print '<div class="center">';
  1489. print '<input type="submit" class="button" value="' . $langs->trans("CreateDraft") . '">';
  1490. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1491. print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
  1492. print '</div>';
  1493. print "</form>";
  1494. // Show origin lines
  1495. if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) {
  1496. print '<br>';
  1497. $title = $langs->trans('ProductsAndServices');
  1498. print load_fiche_titre($title);
  1499. print '<table class="noborder" width="100%">';
  1500. $objectsrc->printOriginLinesList();
  1501. print '</table>';
  1502. }
  1503. } elseif ($object->id > 0) {
  1504. /*
  1505. * Show object in view mode
  1506. */
  1507. $soc = new Societe($db);
  1508. $soc->fetch($object->socid);
  1509. $head = propal_prepare_head($object);
  1510. dol_fiche_head($head, 'comm', $langs->trans('Proposal'), -1, 'propal');
  1511. $formconfirm = '';
  1512. // Clone confirmation
  1513. if ($action == 'clone') {
  1514. // Create an array for form
  1515. $formquestion = array(
  1516. // 'text' => $langs->trans("ConfirmClone"),
  1517. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1518. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' =>
  1519. // 1),
  1520. array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)')));
  1521. if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->date_livraison)) {
  1522. $formquestion[] = array('type' => 'date','name' => 'date_delivery','label' => $langs->trans("DeliveryDate"),'value' => $object->date_livraison);
  1523. }
  1524. // Paiement incomplet. On demande si motif = escompte ou autre
  1525. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ClonePropal'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  1526. }
  1527. if ($action == 'statut')
  1528. {
  1529. //Form to close proposal (signed or not)
  1530. $formquestion = array(
  1531. array('type' => 'select','name' => 'statut','label' => $langs->trans("CloseAs"),'values' => array(2=>$object->LibStatut(Propal::STATUS_SIGNED), 3=>$object->LibStatut(Propal::STATUS_NOTSIGNED))),
  1532. array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"),'value' => '') // Field to complete private note (not replace)
  1533. );
  1534. if (! empty($conf->notification->enabled))
  1535. {
  1536. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  1537. $notify = new Notify($db);
  1538. $formquestion = array_merge($formquestion, array(
  1539. array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PROPAL_CLOSE_SIGNED', $object->socid, $object)),
  1540. ));
  1541. }
  1542. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('SetAcceptedRefused'), $text, 'setstatut', $formquestion, '', 1, 250);
  1543. }
  1544. // Confirm delete
  1545. else if ($action == 'delete') {
  1546. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp', $object->ref), 'confirm_delete', '', 0, 1);
  1547. }
  1548. // Confirm reopen
  1549. else if ($action == 'reopen') {
  1550. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp', $object->ref), 'confirm_reopen', '', 0, 1);
  1551. }
  1552. // Confirmation delete product/service line
  1553. else if ($action == 'ask_deleteline') {
  1554. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  1555. }
  1556. // Confirm validate proposal
  1557. else if ($action == 'validate') {
  1558. $error = 0;
  1559. // We verifie whether the object is provisionally numbering
  1560. $ref = substr($object->ref, 1, 4);
  1561. if ($ref == 'PROV') {
  1562. $numref = $object->getNextNumRef($soc);
  1563. if (empty($numref)) {
  1564. $error ++;
  1565. setEventMessages($object->error, $object->errors, 'errors');
  1566. }
  1567. } else {
  1568. $numref = $object->ref;
  1569. }
  1570. $text = $langs->trans('ConfirmValidateProp', $numref);
  1571. if (! empty($conf->notification->enabled)) {
  1572. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  1573. $notify = new Notify($db);
  1574. $text .= '<br>';
  1575. $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object);
  1576. }
  1577. if (! $error)
  1578. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1);
  1579. }
  1580. // Call Hook formConfirm
  1581. $parameters = array('lineid' => $lineid);
  1582. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1583. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  1584. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
  1585. // Print form confirm
  1586. print $formconfirm;
  1587. // Proposal card
  1588. $linkback = '<a href="' . DOL_URL_ROOT . '/comm/propal/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  1589. $morehtmlref='<div class="refidno">';
  1590. // Ref customer
  1591. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
  1592. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', null, null, '', 1);
  1593. // Thirdparty
  1594. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer');
  1595. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' (<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
  1596. // Project
  1597. if (! empty($conf->projet->enabled))
  1598. {
  1599. $langs->load("projects");
  1600. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  1601. if ($usercancreate)
  1602. {
  1603. if ($action != 'classify')
  1604. $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  1605. if ($action == 'classify') {
  1606. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  1607. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  1608. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  1609. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1610. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  1611. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  1612. $morehtmlref.='</form>';
  1613. } else {
  1614. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  1615. }
  1616. } else {
  1617. if (! empty($object->fk_project)) {
  1618. $proj = new Project($db);
  1619. $proj->fetch($object->fk_project);
  1620. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  1621. $morehtmlref.=$proj->ref;
  1622. $morehtmlref.='</a>';
  1623. } else {
  1624. $morehtmlref.='';
  1625. }
  1626. }
  1627. }
  1628. $morehtmlref.='</div>';
  1629. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1630. print '<div class="fichecenter">';
  1631. print '<div class="fichehalfleft">';
  1632. print '<div class="underbanner clearboth"></div>';
  1633. print '<table class="border" width="100%">';
  1634. // Link for thirdparty discounts
  1635. if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  1636. $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  1637. $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  1638. } else {
  1639. $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
  1640. $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
  1641. }
  1642. print '<tr><td class="titlefield">' . $langs->trans('Discounts') . '</td><td>';
  1643. $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
  1644. $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
  1645. $absolute_discount = price2num($absolute_discount, 'MT');
  1646. $absolute_creditnote = price2num($absolute_creditnote, 'MT');
  1647. $thirdparty = $soc;
  1648. $discount_type = 0;
  1649. $backtopage = urlencode($_SERVER["PHP_SELF"] . '?id=' . $object->id);
  1650. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  1651. print '</td></tr>';
  1652. // Date of proposal
  1653. print '<tr>';
  1654. print '<td>';
  1655. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1656. print $langs->trans('Date');
  1657. print '</td>';
  1658. if ($action != 'editdate' && ! empty($object->brouillon) && $usercancreate)
  1659. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdate&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
  1660. print '</tr></table>';
  1661. print '</td><td>';
  1662. if (! empty($object->brouillon) && $action == 'editdate' && $usercancreate) {
  1663. print '<form name="editdate" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1664. print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  1665. print '<input type="hidden" name="action" value="setdate">';
  1666. print $form->selectDate($object->date, 're', '', '', 0, "editdate");
  1667. print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1668. print '</form>';
  1669. } else {
  1670. if ($object->date) {
  1671. print dol_print_date($object->date, 'day');
  1672. } else {
  1673. print '&nbsp;';
  1674. }
  1675. }
  1676. print '</td>';
  1677. // Date end proposal
  1678. print '<tr>';
  1679. print '<td>';
  1680. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1681. print $langs->trans('DateEndPropal');
  1682. print '</td>';
  1683. if ($action != 'editecheance' && ! empty($object->brouillon) && $usercancreate)
  1684. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editecheance&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
  1685. print '</tr></table>';
  1686. print '</td><td>';
  1687. if (! empty($object->brouillon) && $action == 'editecheance' && $usercancreate) {
  1688. print '<form name="editecheance" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1689. print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  1690. print '<input type="hidden" name="action" value="setecheance">';
  1691. print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance");
  1692. print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1693. print '</form>';
  1694. } else {
  1695. if (! empty($object->fin_validite)) {
  1696. print dol_print_date($object->fin_validite, 'day');
  1697. if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay))
  1698. print img_warning($langs->trans("Late"));
  1699. } else {
  1700. print '&nbsp;';
  1701. }
  1702. }
  1703. print '</td>';
  1704. print '</tr>';
  1705. // Payment term
  1706. print '<tr><td>';
  1707. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1708. print $langs->trans('PaymentConditionsShort');
  1709. print '</td>';
  1710. if ($action != 'editconditions' && ! empty($object->brouillon) && $usercancreate)
  1711. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetConditions'), 1) . '</a></td>';
  1712. print '</tr></table>';
  1713. print '</td><td>';
  1714. if (! empty($object->brouillon) && $action == 'editconditions' && $usercancreate) {
  1715. $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
  1716. } else {
  1717. $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none');
  1718. }
  1719. print '</td>';
  1720. print '</tr>';
  1721. // Delivery date
  1722. $langs->load('deliveries');
  1723. print '<tr><td>';
  1724. print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->date_livraison, $object, $usercancreate, 'datepicker');
  1725. print '</td><td>';
  1726. print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->date_livraison, $object, $usercancreate, 'datepicker');
  1727. print '</td>';
  1728. print '</tr>';
  1729. // Delivery delay
  1730. print '<tr class="fielddeliverydelay"><td>';
  1731. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1732. print $langs->trans('AvailabilityPeriod');
  1733. if (! empty($conf->commande->enabled))
  1734. print ' (' . $langs->trans('AfterOrder') . ')';
  1735. print '</td>';
  1736. if ($action != 'editavailability' && ! empty($object->brouillon) && $usercancreate)
  1737. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editavailability&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1) . '</a></td>';
  1738. print '</tr></table>';
  1739. print '</td><td>';
  1740. if (! empty($object->brouillon) && $action == 'editavailability' && $usercancreate) {
  1741. $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'availability_id', 1);
  1742. } else {
  1743. $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'none', 1);
  1744. }
  1745. print '</td>';
  1746. print '</tr>';
  1747. // Shipping Method
  1748. if (! empty($conf->expedition->enabled)) {
  1749. print '<tr><td>';
  1750. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1751. print $langs->trans('SendingMethod');
  1752. print '</td>';
  1753. if ($action != 'editshippingmethod' && $usercancreate)
  1754. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&amp;id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'),1).'</a></td>';
  1755. print '</tr></table>';
  1756. print '</td><td>';
  1757. if ($action == 'editshippingmethod' && $usercancreate) {
  1758. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
  1759. } else {
  1760. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
  1761. }
  1762. print '</td>';
  1763. print '</tr>';
  1764. }
  1765. // Origin of demand
  1766. print '<tr><td>';
  1767. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1768. print $langs->trans('Source');
  1769. print '</td>';
  1770. if ($action != 'editdemandreason' && ! empty($object->brouillon) && $usercancreate)
  1771. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdemandreason&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1) . '</a></td>';
  1772. print '</tr></table>';
  1773. print '</td><td>';
  1774. if (! empty($object->brouillon) && $action == 'editdemandreason' && $usercancreate) {
  1775. $form->formInputReason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'demand_reason_id', 1);
  1776. } else {
  1777. $form->formInputReason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'none');
  1778. }
  1779. print '</td>';
  1780. print '</tr>';
  1781. // Payment mode
  1782. print '<tr>';
  1783. print '<td>';
  1784. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1785. print $langs->trans('PaymentMode');
  1786. print '</td>';
  1787. if ($action != 'editmode' && ! empty($object->brouillon) && $usercancreate)
  1788. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMode'), 1) . '</a></td>';
  1789. print '</tr></table>';
  1790. print '</td><td>';
  1791. if (! empty($object->brouillon) && $action == 'editmode' && $usercancreate) {
  1792. $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
  1793. } else {
  1794. $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none');
  1795. }
  1796. print '</td></tr>';
  1797. // Multicurrency
  1798. if (! empty($conf->multicurrency->enabled))
  1799. {
  1800. // Multicurrency code
  1801. print '<tr>';
  1802. print '<td>';
  1803. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1804. print fieldLabel('Currency','multicurrency_code');
  1805. print '</td>';
  1806. if ($action != 'editmulticurrencycode' && ! empty($object->brouillon) && $usercancreate)
  1807. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencycode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
  1808. print '</tr></table>';
  1809. print '</td><td>';
  1810. if (! empty($object->brouillon) && $action == 'editmulticurrencycode' && $usercancreate) {
  1811. $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code');
  1812. } else {
  1813. $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'none');
  1814. }
  1815. print '</td></tr>';
  1816. // Multicurrency rate
  1817. print '<tr>';
  1818. print '<td>';
  1819. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1820. print fieldLabel('CurrencyRate','multicurrency_tx');
  1821. print '</td>';
  1822. if ($action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate)
  1823. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmulticurrencyrate&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '</a></td>';
  1824. print '</tr></table>';
  1825. print '</td><td>';
  1826. if (! empty($object->brouillon) && ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') && $usercancreate) {
  1827. if($action == 'actualizemulticurrencyrate') {
  1828. list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
  1829. }
  1830. $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
  1831. } else {
  1832. $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
  1833. if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
  1834. print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
  1835. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
  1836. print '</div>';
  1837. }
  1838. }
  1839. print '</td></tr>';
  1840. }
  1841. if ($soc->outstanding_limit)
  1842. {
  1843. // Outstanding Bill
  1844. print '<tr><td>';
  1845. print $langs->trans('OutstandingBill');
  1846. print '</td><td align="right">';
  1847. print price($soc->get_OutstandingBill()) . ' / ';
  1848. print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
  1849. print '</td>';
  1850. print '</tr>';
  1851. }
  1852. if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && ! empty($conf->banque->enabled))
  1853. {
  1854. // Bank Account
  1855. print '<tr><td>';
  1856. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1857. print $langs->trans('BankAccount');
  1858. print '</td>';
  1859. if ($action != 'editbankaccount' && $usercancreate)
  1860. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  1861. print '</tr></table>';
  1862. print '</td><td>';
  1863. if ($action == 'editbankaccount') {
  1864. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  1865. } else {
  1866. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  1867. }
  1868. print '</td>';
  1869. print '</tr>';
  1870. }
  1871. $tmparray=$object->getTotalWeightVolume();
  1872. $totalWeight=$tmparray['weight'];
  1873. $totalVolume=$tmparray['volume'];
  1874. if ($totalWeight) {
  1875. print '<tr><td>' . $langs->trans("CalculatedWeight") . '</td>';
  1876. print '<td>';
  1877. print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
  1878. print '</td></tr>';
  1879. }
  1880. if ($totalVolume) {
  1881. print '<tr><td>' . $langs->trans("CalculatedVolume") . '</td>';
  1882. print '<td>';
  1883. print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
  1884. print '</td></tr>';
  1885. }
  1886. // Incoterms
  1887. if (!empty($conf->incoterm->enabled))
  1888. {
  1889. print '<tr><td>';
  1890. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1891. print $langs->trans('IncotermLabel');
  1892. print '<td><td align="right">';
  1893. if ($usercancreate) print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
  1894. else print '&nbsp;';
  1895. print '</td></tr></table>';
  1896. print '</td>';
  1897. print '<td>';
  1898. if ($action != 'editincoterm')
  1899. {
  1900. print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
  1901. }
  1902. else
  1903. {
  1904. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1905. }
  1906. print '</td></tr>';
  1907. }
  1908. // Other attributes
  1909. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  1910. print '</table>';
  1911. print '</div>';
  1912. print '<div class="fichehalfright">';
  1913. print '<div class="ficheaddleft">';
  1914. print '<div class="underbanner clearboth"></div>';
  1915. print '<table class="border centpercent">';
  1916. if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
  1917. {
  1918. // Multicurrency Amount HT
  1919. print '<tr><td class="titlefieldmiddle">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
  1920. print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
  1921. print '</tr>';
  1922. // Multicurrency Amount VAT
  1923. print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
  1924. print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
  1925. print '</tr>';
  1926. // Multicurrency Amount TTC
  1927. print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
  1928. print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
  1929. print '</tr>';
  1930. }
  1931. // Amount HT
  1932. print '<tr><td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
  1933. print '<td class="nowrap">' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
  1934. print '</tr>';
  1935. // Amount VAT
  1936. print '<tr><td>' . $langs->trans('AmountVAT') . '</td>';
  1937. print '<td class="nowrap">' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
  1938. print '</tr>';
  1939. // Amount Local Taxes
  1940. if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1
  1941. {
  1942. print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
  1943. print '<td class="nowrap">' . price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
  1944. print '</tr>';
  1945. }
  1946. if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2
  1947. {
  1948. print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
  1949. print '<td class="nowrap">' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
  1950. print '</tr>';
  1951. }
  1952. // Amount TTC
  1953. print '<tr><td>' . $langs->trans('AmountTTC') . '</td>';
  1954. print '<td class="nowrap">' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . '</td>';
  1955. print '</tr>';
  1956. // Statut
  1957. //print '<tr><td height="10">' . $langs->trans('Status') . '</td><td align="left" colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
  1958. print '</table>';
  1959. // Margin Infos
  1960. if (! empty($conf->margin->enabled))
  1961. {
  1962. $formmargin->displayMarginInfos($object);
  1963. }
  1964. print '</div>';
  1965. print '</div>';
  1966. print '</div>';
  1967. print '<div class="clearboth"></div><br>';
  1968. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  1969. $blocname = 'contacts';
  1970. $title = $langs->trans('ContactsAddresses');
  1971. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  1972. }
  1973. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  1974. $blocname = 'notes';
  1975. $title = $langs->trans('Notes');
  1976. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  1977. }
  1978. /*
  1979. * Lines
  1980. */
  1981. // Show object lines
  1982. $result = $object->getLinesArray();
  1983. print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid')) . '" method="POST">
  1984. <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
  1985. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
  1986. <input type="hidden" name="mode" value="">
  1987. <input type="hidden" name="id" value="' . $object->id . '">
  1988. ';
  1989. if (! empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) {
  1990. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  1991. }
  1992. print '<div class="div-table-responsive-no-min">';
  1993. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  1994. if (! empty($object->lines))
  1995. $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
  1996. // Form to add new line
  1997. if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines')
  1998. {
  1999. if ($action != 'editline')
  2000. {
  2001. // Add products/services form
  2002. $object->formAddObjectLine(1, $mysoc, $soc);
  2003. $parameters = array();
  2004. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2005. }
  2006. }
  2007. print '</table>';
  2008. print '</div>';
  2009. print "</form>\n";
  2010. dol_fiche_end();
  2011. /*
  2012. * Boutons Actions
  2013. */
  2014. if ($action != 'presend') {
  2015. print '<div class="tabsAction">';
  2016. $parameters = array();
  2017. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  2018. // modified by hook
  2019. if (empty($reshook))
  2020. {
  2021. if ($action != 'editline')
  2022. {
  2023. // Validate
  2024. if ($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
  2025. {
  2026. if ($usercanvalidate)
  2027. {
  2028. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=validate">' . $langs->trans('Validate') . '</a></div>';
  2029. }
  2030. else
  2031. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('Validate') . '</a></div>';
  2032. }
  2033. // Create event
  2034. /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
  2035. {
  2036. print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddAction") . '</a></div>';
  2037. }*/
  2038. // Edit
  2039. if ($object->statut == Propal::STATUS_VALIDATED && $usercancreate) {
  2040. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=modif">' . $langs->trans('Modify') . '</a></div>';
  2041. }
  2042. // ReOpen
  2043. if (($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) && $usercanclose) {
  2044. 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') . '"';
  2045. print '>' . $langs->trans('ReOpen') . '</a></div>';
  2046. }
  2047. // Send
  2048. if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED) {
  2049. if ($usercansend) {
  2050. 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>';
  2051. } else
  2052. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('SendMail') . '</a></div>';
  2053. }
  2054. // Create an order
  2055. if (! empty($conf->commande->enabled) && $object->statut == Propal::STATUS_SIGNED) {
  2056. if ($usercancreateorder) {
  2057. print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/commande/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddOrder") . '</a></div>';
  2058. }
  2059. }
  2060. // Create an intervention
  2061. if (! empty($conf->service->enabled) && ! empty($conf->ficheinter->enabled) && $object->statut == Propal::STATUS_SIGNED) {
  2062. if ($usercancreateintervention) {
  2063. $langs->load("interventions");
  2064. print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/fichinter/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddIntervention") . '</a></div>';
  2065. }
  2066. }
  2067. // Create contract
  2068. if ($conf->contrat->enabled && $object->statut == Propal::STATUS_SIGNED) {
  2069. $langs->load("contracts");
  2070. if ($usercancreatecontract) {
  2071. print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/contrat/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans('AddContract') . '</a></div>';
  2072. }
  2073. }
  2074. // Create an invoice and classify billed
  2075. if ($object->statut == Propal::STATUS_SIGNED)
  2076. {
  2077. if (! empty($conf->facture->enabled) && $usercancreateinvoice)
  2078. {
  2079. print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddBill") . '</a></div>';
  2080. }
  2081. $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
  2082. if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED))
  2083. {
  2084. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled&amp;socid=' . $object->socid . '">' . $langs->trans("ClassifyBilled") . '</a></div>';
  2085. }
  2086. }
  2087. // Set accepted/refused
  2088. if ($object->statut == Propal::STATUS_VALIDATED && $usercanclose) {
  2089. 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) ? '' : '#close') . '"';
  2090. print '>' . $langs->trans('SetAcceptedRefused') . '</a></div>';
  2091. }
  2092. // Clone
  2093. if ($usercancreate) {
  2094. 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>';
  2095. }
  2096. // Delete
  2097. if ($usercandelete) {
  2098. print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete"';
  2099. print '>' . $langs->trans('Delete') . '</a></div>';
  2100. }
  2101. }
  2102. }
  2103. print '</div>';
  2104. }
  2105. //Select mail models is same action as presend
  2106. if (GETPOST('modelselected')) $action = 'presend';
  2107. if ($action != 'presend')
  2108. {
  2109. print '<div class="fichecenter"><div class="fichehalfleft">';
  2110. print '<a name="builddoc"></a>'; // ancre
  2111. /*
  2112. * Documents generes
  2113. */
  2114. $filename = dol_sanitizeFileName($object->ref);
  2115. $filedir = $conf->propal->multidir_output[$object->entity] . "/" . dol_sanitizeFileName($object->ref);
  2116. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  2117. $genallowed = $usercanread;
  2118. $delallowed = $usercancreate;
  2119. print $formfile->showdocuments('propal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);
  2120. // Show links to link elements
  2121. $linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
  2122. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  2123. // Show online signature link
  2124. $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok
  2125. if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature)
  2126. {
  2127. print '<br><!-- Link to sign -->';
  2128. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  2129. print showOnlineSignatureUrl('proposal', $object->ref).'<br>';
  2130. }
  2131. // Show direct download link
  2132. if ($object->statut != Propal::STATUS_DRAFT && ! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD))
  2133. {
  2134. print '<br><!-- Link to download main doc -->'."\n";
  2135. print showDirectDownloadLink($object).'<br>';
  2136. }
  2137. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  2138. // List of actions on element
  2139. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  2140. $formactions = new FormActions($db);
  2141. $somethingshown = $formactions->showactions($object, 'propal', $socid, 1);
  2142. print '</div></div></div>';
  2143. }
  2144. // Presend form
  2145. $modelmail='propal_send';
  2146. $defaulttopic='SendPropalRef';
  2147. $diroutput = $conf->propal->multidir_output[$object->entity];
  2148. $trackid = 'pro'.$object->id;
  2149. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2150. }
  2151. // End of page
  2152. llxFooter();
  2153. $db->close();