card.php 112 KB

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