PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/propal/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1667 lines | 1021 code | 197 blank | 449 comment | 405 complexity | 815ade85883932a07107c38964917389 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2012 David Moothen <dmoothen@websitti.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formpropal.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/propal/class/propal.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/propal/core/modules/propale/modules_propale.php';
  32. require_once DOL_DOCUMENT_ROOT . '/propal/lib/propal.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  34. if (!empty($conf->projet->enabled))
  35. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  36. $langs->load('companies');
  37. $langs->load('propal');
  38. $langs->load('compta');
  39. $langs->load('bills');
  40. $langs->load('orders');
  41. $langs->load('products');
  42. if (!empty($conf->margin->enabled))
  43. $langs->load('margins');
  44. $error = 0;
  45. $id = GETPOST('id', 'alpha');
  46. $ref = GETPOST('ref', 'alpha');
  47. $socid = GETPOST('socid', 'alpha');
  48. $action = GETPOST('action', 'alpha');
  49. $confirm = GETPOST('confirm', 'alpha');
  50. $lineid = GETPOST('lineid', 'alpha');
  51. //PDF
  52. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  53. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  54. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  55. // Nombre de ligne pour choix de produit/service predefinis
  56. $NBLINES = 4;
  57. // Security check
  58. if (!empty($user->societe_id))
  59. $socid = $user->societe_id;
  60. $result = restrictedArea($user, 'propal', $id);
  61. $object = new Propal($db);
  62. // Load object
  63. //if (!(empty($id)) || !empty($ref)) {
  64. // if ($action != 'add') {
  65. // $ret = $object->fetch($id);
  66. // $object->fetch_thirdparty();
  67. // if (empty($id)) {
  68. // $langs->load("errors");
  69. // setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
  70. // $error++;
  71. // }
  72. //// else if ($ret < 0) {
  73. //// setEventMessage($object->error, 'errors');
  74. //// $error++;
  75. //// }
  76. //// else
  77. //// $object->fetch_thirdparty();
  78. // }
  79. //} else {
  80. // header('Location: ' . DOL_URL_ROOT . '/propal/list.php');
  81. // exit;
  82. //}
  83. if (!empty($id)) {
  84. $object->fetch($id);
  85. $object->fetch_thirdparty();
  86. }
  87. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  88. $hookmanager->initHooks(array('propalcard'));
  89. if (!empty($_GET['json'])) {
  90. $output = array(
  91. "sEcho" => intval($_GET['sEcho']),
  92. "iTotalRecords" => 0,
  93. "iTotalDisplayRecords" => 0,
  94. "aaData" => array()
  95. );
  96. // $keystart[0] = $user->id;
  97. // $keyend[0] = $user->id;
  98. // $keyend[1] = new stdClass();
  99. /* $params = array('startkey' => array($user->id, mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"))),
  100. 'endkey' => array($user->id, mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")))); */
  101. try {
  102. $result = $object->getView($_GET["json"], array('key' => $id));
  103. } catch (Exception $exc) {
  104. print $exc->getMessage();
  105. }
  106. $iTotal = count($result->rows);
  107. $output["iTotalRecords"] = $iTotal;
  108. $output["iTotalDisplayRecords"] = $iTotal;
  109. $i = 0;
  110. foreach ($result->rows as $aRow) {
  111. $output["aaData"][] = $aRow->value;
  112. }
  113. header('Content-type: application/json');
  114. echo json_encode($output);
  115. exit;
  116. }
  117. /*
  118. * Actions
  119. */
  120. $parameters = array('socid' => $socid);
  121. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  122. // Action clone object
  123. if ($action == 'confirm_clone' && $confirm == 'yes') {
  124. if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
  125. setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
  126. } else {
  127. if (!empty($object->id)) {
  128. $result = $object->createFromClone($socid);
  129. if ($result > 0) {
  130. header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
  131. exit;
  132. } else {
  133. setEventMessage($object->error, 'errors');
  134. $action = '';
  135. }
  136. }
  137. }
  138. }
  139. // Suppression de la propale
  140. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) {
  141. $result = $object->delete($user);
  142. if ($result > 0) {
  143. header('Location: ' . DOL_URL_ROOT . '/propal/list.php');
  144. exit;
  145. } else {
  146. $langs->load("errors");
  147. setEventMessage($langs->trans($object->error), 'errors');
  148. }
  149. }
  150. // Remove line
  151. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) {
  152. $result = $object->deleteline($lineid);
  153. // reorder lines
  154. if ($result)
  155. $object->line_order(true);
  156. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  157. // Define output language
  158. $outputlangs = $langs;
  159. if (!empty($conf->global->MAIN_MULTILANGS)) {
  160. $outputlangs = new Translate();
  161. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  162. $outputlangs->setDefaultLang($newlang);
  163. }
  164. $ret = $object->fetch($id); // Reload to get new records
  165. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  166. }
  167. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  168. exit;
  169. }
  170. // Validation
  171. else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) {
  172. $result = $object->valid($user);
  173. if ($result >= 0) {
  174. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  175. // Define output language
  176. $outputlangs = $langs;
  177. if (!empty($conf->global->MAIN_MULTILANGS)) {
  178. $outputlangs = new Translate();
  179. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  180. $outputlangs->setDefaultLang($newlang);
  181. }
  182. $ret = $object->fetch($id); // Reload to get new records
  183. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  184. }
  185. } else {
  186. $langs->load("errors");
  187. setEventMessage($langs->trans($object->error), 'errors');
  188. }
  189. } else if ($action == 'setdate' && $user->rights->propal->creer) {
  190. $datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  191. if (empty($datep)) {
  192. $error++;
  193. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
  194. }
  195. if (!$error) {
  196. $result = $object->set_date($user, $datep);
  197. if ($result < 0)
  198. dol_print_error($db, $object->error);
  199. }
  200. }
  201. else if ($action == 'setecheance' && $user->rights->propal->creer) {
  202. $result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
  203. if ($result < 0)
  204. dol_print_error($db, $object->error);
  205. }
  206. else if ($action == 'setdate_livraison' && $user->rights->propal->creer) {
  207. $result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']));
  208. if ($result < 0)
  209. dol_print_error($db, $object->error);
  210. }
  211. // Positionne ref client
  212. else if ($action == 'set_ref_client' && $user->rights->propal->creer) {
  213. $object->set_ref_client($user, $_POST['ref_client']);
  214. } else if ($action == 'setnote_public' && $user->rights->propal->creer) {
  215. $result = $object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
  216. if ($result < 0)
  217. dol_print_error($db, $object->error);
  218. }
  219. else if ($action == 'setnote' && $user->rights->propal->creer) {
  220. $result = $object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
  221. if ($result < 0)
  222. dol_print_error($db, $object->error);
  223. }
  224. // Create proposal
  225. else if ($action == 'add' && $user->rights->propal->creer) {
  226. // $object->socid=$socid;
  227. // $object->fetch_thirdparty();
  228. $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  229. $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  230. $duration = GETPOST('duree_validite');
  231. if (empty($datep)) {
  232. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
  233. header("Location: " . DOL_URL_ROOT . '/propal/addpropal.php?socid=' . $socid . '&action=create');
  234. exit;
  235. }
  236. if (empty($duration)) {
  237. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
  238. header("Location: " . DOL_URL_ROOT . '/propal/addpropal.php?socid=' . $socid . '&action=create');
  239. exit;
  240. }
  241. $object->datec = $datep;
  242. $object->date_livraison = $date_delivery;
  243. if (!$error) {
  244. // Si on a selectionne une propal a copier, on realise la copie
  245. if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal')) {
  246. if ($object->fetch(GETPOST('copie_propal')) > 0) {
  247. $object->ref = GETPOST('ref');
  248. $object->datep = $datep;
  249. $object->date_livraison = $date_delivery;
  250. $object->availability_id = GETPOST('availability_id');
  251. $object->demand_reason_id = GETPOST('demand_reason_id');
  252. $object->fk_delivery_address = GETPOST('fk_address');
  253. $object->duree_validite = $duration;
  254. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  255. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  256. $object->remise_percent = GETPOST('remise_percent');
  257. $object->remise_absolue = GETPOST('remise_absolue');
  258. $object->socid = GETPOST('socid');
  259. $object->contactid = GETPOST('contactidp');
  260. $object->fk_project = GETPOST('projectid');
  261. $object->modelpdf = GETPOST('model');
  262. $object->author = $user->id; // deprecated
  263. $object->note = GETPOST('note');
  264. $object->statut = 0;
  265. $id = $object->create_from($user);
  266. } else {
  267. setEventMessage($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), 'errors');
  268. }
  269. } else {
  270. $object->socid = GETPOST('socid');
  271. $object->ref = GETPOST('ref');
  272. $object->ref_client = GETPOST('ref_client');
  273. $object->datep = $datep;
  274. $object->date_livraison = $date_delivery;
  275. $object->availability_code = GETPOST('availability_code');
  276. $object->demand_reason_code = GETPOST('demand_reason_code');
  277. $object->fk_delivery_address = GETPOST('fk_address');
  278. $object->duree_validite = GETPOST('duree_validite');
  279. $object->cond_reglement_code = GETPOST('cond_reglement_code');
  280. $object->mode_reglement_code = GETPOST('mode_reglement_code');
  281. $object->contactid = GETPOST('contactidp');
  282. $object->fk_project = GETPOST('projectid');
  283. $object->modelpdf = GETPOST('model');
  284. $object->note = GETPOST('note');
  285. $object->origin = GETPOST('origin');
  286. $object->origin_id = GETPOST('originid');
  287. for ($i = 1; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) {
  288. if ($_POST['idprod' . $i]) {
  289. $xid = 'idprod' . $i;
  290. $xqty = 'qty' . $i;
  291. $xremise = 'remise' . $i;
  292. $object->add_product($_POST[$xid], $_POST[$xqty], $_POST[$xremise]);
  293. }
  294. }
  295. $id = $object->create($user);
  296. }
  297. if (!empty($id)) {
  298. // Insertion contact par defaut si defini
  299. if (GETPOST('contactidp')) {
  300. $result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external');
  301. if ($result < 0) {
  302. $error++;
  303. setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
  304. }
  305. }
  306. if (!$error) {
  307. // $db->commit();
  308. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  309. // Define output language
  310. $outputlangs = $langs;
  311. if (!empty($conf->global->MAIN_MULTILANGS)) {
  312. $outputlangs = new Translate();
  313. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  314. $outputlangs->setDefaultLang($newlang);
  315. }
  316. $ret = $object->fetch($id); // Reload to get new records
  317. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  318. }
  319. header('Location: fiche.php?id=' . $id);
  320. exit;
  321. }
  322. // else
  323. // {
  324. // $db->rollback();
  325. // }
  326. } else {
  327. dol_print_error($db, $object->error);
  328. // $db->rollback();
  329. exit;
  330. }
  331. }
  332. }
  333. // Classify billed
  334. else if ($action == 'classifybilled' && $user->rights->propal->cloturer) {
  335. $object->cloture($user, 4, '');
  336. }
  337. // Reopen proposal
  338. else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && !GETPOST('cancel')) {
  339. // prevent browser refresh from reopening proposal several times
  340. if (in_array($object->Status, array('SIGNED', 'NOT_SIGNED'))) {
  341. $object->setStatut('OPENED');
  342. }
  343. }
  344. // Close proposal
  345. else if ($action == 'setstatut' && $user->rights->propal->cloturer && !GETPOST('cancel')) {
  346. if (!GETPOST('statut')) {
  347. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), 'errors');
  348. $action = 'statut';
  349. } else {
  350. // prevent browser refresh from closing proposal several times
  351. if ($object->Status == "OPENED") {
  352. $object->cloture($user, GETPOST('statut'), GETPOST('note'));
  353. }
  354. }
  355. }
  356. /*
  357. * Add file in email form
  358. */
  359. if (GETPOST('addfile')) {
  360. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  361. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  362. $vardir = $conf->user->dir_output . "/" . $user->id;
  363. $upload_dir_tmp = $vardir . '/temp';
  364. dol_add_file_process($upload_dir_tmp, 0, 0);
  365. $action = 'presend';
  366. }
  367. /*
  368. * Remove file in email form
  369. */
  370. if (GETPOST('removedfile')) {
  371. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  372. // Set tmp user directory
  373. $vardir = $conf->user->dir_output . "/" . $user->id;
  374. $upload_dir_tmp = $vardir . '/temp';
  375. // TODO Delete only files that was uploaded from email form
  376. dol_remove_file_process($_POST['removedfile'], 0);
  377. $action = 'presend';
  378. }
  379. /*
  380. * Send mail
  381. */
  382. if ($action == 'send' && !GETPOST('addfile') && !GETPOST('removedfile') && !GETPOST('cancel')) {
  383. $langs->load('mails');
  384. if ($object->id > 0) {
  385. if ($_POST['sendto']) {
  386. // Le destinataire a ete fourni via le champ libre
  387. $sendto = $_POST['sendto'];
  388. $sendtoid = 0;
  389. } elseif ($_POST['receiver'] != '-1') {
  390. // Recipient was provided from combo list
  391. if ($_POST['receiver'] == 'thirdparty') { // Id of third party
  392. $sendto = $object->client->email;
  393. $sendtoid = 0;
  394. } else { // Id du contact
  395. $sendto = $object->client->contact_get_property($_POST['receiver'], 'email');
  396. $sendtoid = $_POST['receiver'];
  397. }
  398. }
  399. if (dol_strlen($sendto)) {
  400. $langs->load("commercial");
  401. $from = $_POST['fromname'] . ' <' . $_POST['frommail'] . '>';
  402. $replyto = $_POST['replytoname'] . ' <' . $_POST['replytomail'] . '>';
  403. $message = $_POST['message'];
  404. $sendtocc = $_POST['sendtocc'];
  405. $deliveryreceipt = $_POST['deliveryreceipt'];
  406. if (dol_strlen($_POST['subject']))
  407. $subject = $_POST['subject'];
  408. else
  409. $subject = $langs->transnoentities('Propal') . ' ' . $object->ref;
  410. $actiontypecode = 'AC_PROP';
  411. $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
  412. if ($message) {
  413. $actionmsg.=$langs->transnoentities('MailTopic') . ": " . $subject . "\n";
  414. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
  415. $actionmsg.=$message;
  416. }
  417. $actionmsg2 = $langs->transnoentities('Action' . $actiontypecode);
  418. // Create form object
  419. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  420. $formmail = new FormMail($db);
  421. $attachedfiles = $formmail->get_attached_files();
  422. $filepath = $attachedfiles['paths'];
  423. $filename = $attachedfiles['names'];
  424. $mimetype = $attachedfiles['mimes'];
  425. // Envoi de la propal
  426. require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
  427. $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt);
  428. if ($mailfile->error) {
  429. setEventMessage($mailfile->error, 'errors');
  430. } else {
  431. $result = $mailfile->sendfile();
  432. if ($result) {
  433. // Initialisation donnees
  434. $object->sendtoid = $sendtoid;
  435. $object->actiontypecode = $actiontypecode;
  436. $object->actionmsg = $actionmsg;
  437. $object->actionmsg2 = $actionmsg2;
  438. $object->fk_element = $object->id;
  439. $object->elementtype = $object->element;
  440. // Appel des triggers
  441. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  442. $interface = new Interfaces($db);
  443. $result = $interface->run_triggers('PROPAL_SENTBYMAIL', $object, $user, $langs, $conf);
  444. if ($result < 0) {
  445. $error++;
  446. $this->errors = $interface->errors;
  447. }
  448. // Fin appel triggers
  449. if (!$error) {
  450. // Redirect here
  451. // This avoid sending mail twice if going out and then back to page
  452. $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
  453. setEventMessage($mesg);
  454. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  455. exit;
  456. } else {
  457. dol_print_error($db);
  458. }
  459. } else {
  460. $langs->load("other");
  461. if ($mailfile->error) {
  462. $mesg.=$langs->trans('ErrorFailedToSendMail', $from, $sendto);
  463. $mesg.='<br>' . $mailfile->error;
  464. } else {
  465. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  466. }
  467. setEventMessage($mesg, 'errors');
  468. }
  469. }
  470. } else {
  471. $langs->load("other");
  472. setEventMessage($langs->trans('ErrorMailRecipientIsEmpty') . '!', 'errors');
  473. dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
  474. }
  475. } else {
  476. $langs->load("other");
  477. setEventMessage($langs->trans('ErrorFailedToReadEntity', $langs->trans("Proposal")), 'errors');
  478. dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Proposal")));
  479. }
  480. }
  481. // Go back to draft
  482. if ($action == 'modif' && $user->rights->propal->creer) {
  483. $object->set_draft($user);
  484. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  485. // Define output language
  486. $outputlangs = $langs;
  487. if (!empty($conf->global->MAIN_MULTILANGS)) {
  488. $outputlangs = new Translate();
  489. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  490. $outputlangs->setDefaultLang($newlang);
  491. }
  492. $ret = $object->fetch($id); // Reload to get new records
  493. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  494. }
  495. } else if ($action == "setabsolutediscount" && $user->rights->propal->creer) {
  496. if ($_POST["remise_id"]) {
  497. if ($object->id > 0) {
  498. $result = $object->insert_discount($_POST["remise_id"]);
  499. if ($result < 0) {
  500. setEventMessage($object->error, 'errors');
  501. }
  502. }
  503. }
  504. }
  505. //Ajout d'une ligne produit dans la propale
  506. else if ($action == "addline" && $user->rights->propal->creer) {
  507. $idprod = GETPOST('idprod', 'alpha');
  508. $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : (GETPOST('dp_desc') ? GETPOST('dp_desc') : '')));
  509. $price_ht = GETPOST('price_ht');
  510. $tva_tx = GETPOST('tva_tx');
  511. if (empty($idprod) && GETPOST('type') < 0) {
  512. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors');
  513. $error++;
  514. }
  515. if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht >= 0) || $price_ht == '')) { // Unit price can be 0 but not ''
  516. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
  517. $error++;
  518. }
  519. if (empty($idprod) && empty($product_desc)) {
  520. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), 'errors');
  521. $error++;
  522. }
  523. if (!$error && (GETPOST('qty') >= 0) && (!empty($product_desc) || !empty($idprod))) {
  524. $pu_ht = 0;
  525. $pu_ttc = 0;
  526. $price_min = 0;
  527. $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
  528. // Ecrase $pu par celui du produit
  529. // Ecrase $desc par celui du produit
  530. // Ecrase $txtva par celui du produit
  531. if (!empty($idprod)) {
  532. $prod = new Product($db);
  533. $prod->fetch($idprod);
  534. $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
  535. // If prices fields are update
  536. if (GETPOST('usenewaddlineform')) {
  537. $pu_ht = price2num($price_ht, 'MU');
  538. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  539. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  540. $tva_tx = str_replace('*', '', $tva_tx);
  541. $desc = $product_desc;
  542. } else {
  543. $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
  544. $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
  545. // On defini prix unitaire
  546. if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
  547. $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
  548. $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
  549. $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
  550. $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
  551. } else {
  552. $pu_ht = $prod->price->price;
  553. $pu_ttc = $prod->price->price_ttc;
  554. $price_min = $prod->price_min;
  555. $price_base_type = $prod->price->price_base_type;
  556. }
  557. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  558. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  559. if ($tva_tx != $prod->tva_tx) {
  560. if ($price_base_type != 'HT') {
  561. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU');
  562. } else {
  563. $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
  564. }
  565. }
  566. $desc = '';
  567. // Define output language
  568. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  569. $outputlangs = $langs;
  570. $newlang = '';
  571. if (empty($newlang) && GETPOST('lang_id'))
  572. $newlang = GETPOST('lang_id');
  573. if (empty($newlang))
  574. $newlang = $object->client->default_lang;
  575. if (!empty($newlang)) {
  576. $outputlangs = new Translate();
  577. $outputlangs->setDefaultLang($newlang);
  578. }
  579. $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
  580. } else {
  581. $desc = $prod->description;
  582. }
  583. $desc = dol_concatdesc($desc, $product_desc);
  584. }
  585. $type = $prod->type;
  586. } else {
  587. $pu_ht = price2num($price_ht, 'MU');
  588. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  589. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  590. $tva_tx = str_replace('*', '', $tva_tx);
  591. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  592. $desc = $product_desc;
  593. $type = GETPOST('type');
  594. }
  595. // Margin
  596. $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
  597. $buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
  598. // Local Taxes
  599. $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
  600. $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
  601. $info_bits = 0;
  602. if ($tva_npr)
  603. $info_bits |= 0x01;
  604. if (!empty($price_min) && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
  605. $mesg = $langs->trans("CantBeLessThanMinPrice", price2num($price_min, 'MU') . $langs->getCurrencySymbol($conf->currency));
  606. setEventMessage($mesg, 'errors');
  607. } else {
  608. // Insert line
  609. $result = $object->addline(
  610. $id, $desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, GETPOST('remise_percent'), $price_base_type, $pu_ttc, $info_bits, $type, -1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label
  611. );
  612. if ($result > 0) {
  613. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  614. // Define output language
  615. $outputlangs = $langs;
  616. if (!empty($conf->global->MAIN_MULTILANGS)) {
  617. $outputlangs = new Translate();
  618. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  619. $outputlangs->setDefaultLang($newlang);
  620. }
  621. $ret = $object->fetch($id); // Reload to get new records
  622. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  623. }
  624. unset($_POST['qty']);
  625. unset($_POST['type']);
  626. unset($_POST['idprod']);
  627. unset($_POST['remise_percent']);
  628. unset($_POST['price_ht']);
  629. unset($_POST['price_ttc']);
  630. unset($_POST['tva_tx']);
  631. unset($_POST['product_ref']);
  632. unset($_POST['product_label']);
  633. unset($_POST['product_desc']);
  634. unset($_POST['fournprice']);
  635. unset($_POST['buying_price']);
  636. // old method
  637. unset($_POST['np_desc']);
  638. unset($_POST['dp_desc']);
  639. } else {
  640. setEventMessage($object->error, 'errors');
  641. }
  642. }
  643. }
  644. }
  645. // Mise a jour d'une ligne dans la propale
  646. else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save') == $langs->trans("Save")) {
  647. // Define info_bits
  648. $info_bits = 0;
  649. if (preg_match('/\*/', GETPOST('tva_tx')))
  650. $info_bits |= 0x01;
  651. // Clean parameters
  652. $description = dol_htmlcleanlastbr(GETPOST('product_desc'));
  653. // Define vat_rate
  654. $vat_rate = GETPOST('tva_tx');
  655. $vat_rate = str_replace('*', '', $vat_rate);
  656. $localtax1_rate = get_localtax($vat_rate, 1, $object->client);
  657. $localtax2_rate = get_localtax($vat_rate, 2, $object->client);
  658. $pu_ht = GETPOST('price_ht');
  659. // Add buying price
  660. $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
  661. $buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
  662. // Define special_code for special lines
  663. $special_code = 0;
  664. if (!GETPOST('qty'))
  665. $special_code = 3;
  666. // Check minimum price
  667. $productid = GETPOST('productid', 'int');
  668. if (!empty($productid)) {
  669. $product = new Product($db);
  670. $res = $product->fetch($productid);
  671. $type = $product->type;
  672. $price_min = $product->price_min;
  673. if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->client->price_level))
  674. $price_min = $product->multiprices_min[$object->client->price_level];
  675. $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
  676. if ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
  677. setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min, 'MU')) . $langs->getCurrencySymbol($conf->currency), 'errors');
  678. $error++;
  679. }
  680. } else {
  681. $type = GETPOST('type');
  682. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  683. // Check parameters
  684. if (GETPOST('type') < 0) {
  685. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors');
  686. $error++;
  687. }
  688. }
  689. if (!$error) {
  690. $result = $object->updateline(
  691. $id, GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buying_price, $label, $type
  692. );
  693. if ($result >= 0) {
  694. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  695. // Define output language
  696. $outputlangs = $langs;
  697. if (!empty($conf->global->MAIN_MULTILANGS)) {
  698. $outputlangs = new Translate();
  699. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  700. $outputlangs->setDefaultLang($newlang);
  701. }
  702. $ret = $object->fetch($id); // Reload to get new records
  703. // propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  704. }
  705. unset($_POST['qty']);
  706. unset($_POST['type']);
  707. unset($_POST['productid']);
  708. unset($_POST['remise_percent']);
  709. unset($_POST['price_ht']);
  710. unset($_POST['price_ttc']);
  711. unset($_POST['tva_tx']);
  712. unset($_POST['product_ref']);
  713. unset($_POST['product_label']);
  714. unset($_POST['product_desc']);
  715. unset($_POST['fournprice']);
  716. unset($_POST['buying_price']);
  717. } else {
  718. setEventMessage($object->error, 'errors');
  719. }
  720. }
  721. } else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel') == $langs->trans('Cancel')) {
  722. header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
  723. exit;
  724. }
  725. // Generation doc (depuis lien ou depuis cartouche doc)
  726. else if ($action == 'builddoc' && $user->rights->propal->creer) {
  727. if (GETPOST('model')) {
  728. $object->setDocModel($user, GETPOST('model'));
  729. }
  730. // Define output language
  731. $outputlangs = $langs;
  732. if (!empty($conf->global->MAIN_MULTILANGS)) {
  733. $outputlangs = new Translate();
  734. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  735. $outputlangs->setDefaultLang($newlang);
  736. }
  737. $ret = $object->fetch($id); // Reload to get new records
  738. $object->fetch_thirdparty();
  739. $result = propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  740. if ($result <= 0) {
  741. dol_print_error($db, $result);
  742. exit;
  743. } else {
  744. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
  745. exit;
  746. }
  747. }
  748. // Remove file in doc form
  749. else if ($action == 'remove_file' && $user->rights->propal->creer) {
  750. if (!empty($object->id)) {
  751. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  752. $langs->load("other");
  753. $upload_dir = $conf->propal->dir_output;
  754. $file = $upload_dir . '/' . GETPOST('file');
  755. $ret = dol_delete_file($file, 0, 0, 0, $object);
  756. if ($ret)
  757. setEventMessage($langs->trans("FileWasRemoved", GETPOST('file')));
  758. else
  759. setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors');
  760. }
  761. }
  762. // Set project
  763. else if ($action == 'classin' && $user->rights->propal->creer) {
  764. $object->setProject($_POST['projectid']);
  765. }
  766. // Delai de livraison
  767. else if ($action == 'setavailability' && $user->rights->propal->creer) {
  768. $result = $object->availability($_POST['availability_code']);
  769. }
  770. // Origine de la propale
  771. else if ($action == 'setdemandreason' && $user->rights->propal->creer) {
  772. $result = $object->demand_reason($_POST['demand_reason_code']);
  773. }
  774. // Conditions de reglement
  775. else if ($action == 'setconditions' && $user->rights->propal->creer) {
  776. $result = $object->setPaymentTerms(GETPOST('cond_reglement_code', 'alpha'));
  777. } else if ($action == 'setremisepercent' && $user->rights->propal->creer) {
  778. $result = $object->set_remise_percent($user, $_POST['remise_percent']);
  779. } else if ($action == 'setremiseabsolue' && $user->rights->propal->creer) {
  780. $result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
  781. }
  782. // Mode de reglement
  783. else if ($action == 'setmode' && $user->rights->propal->creer) {
  784. $result = $object->setPaymentMethods(GETPOST('mode_reglement_code', 'alpha'));
  785. }
  786. /*
  787. * Ordonnancement des lignes
  788. */ else if ($action == 'up' && $user->rights->propal->creer) {
  789. $object->line_up(GETPOST('rowid'));
  790. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  791. // Define output language
  792. $outputlangs = $langs;
  793. if (!empty($conf->global->MAIN_MULTILANGS)) {
  794. $outputlangs = new Translate();
  795. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  796. $outputlangs->setDefaultLang($newlang);
  797. }
  798. $ret = $object->fetch($id); // Reload to get new records
  799. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  800. }
  801. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id . '#' . GETPOST('rowid'));
  802. exit;
  803. } else if ($action == 'down' && $user->rights->propal->creer) {
  804. $object->line_down(GETPOST('rowid'));
  805. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  806. // Define output language
  807. $outputlangs = $langs;
  808. if (!empty($conf->global->MAIN_MULTILANGS)) {
  809. $outputlangs = new Translate();
  810. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  811. $outputlangs->setDefaultLang($newlang);
  812. }
  813. $ret = $object->fetch($id); // Reload to get new records
  814. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  815. }
  816. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id . '#' . GETPOST('rowid'));
  817. exit;
  818. }
  819. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) {
  820. if ($action == 'addcontact') {
  821. if ($object->id > 0) {
  822. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  823. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  824. }
  825. if ($result >= 0) {
  826. header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
  827. exit;
  828. } else {
  829. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  830. $langs->load("errors");
  831. setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
  832. } else {
  833. setEventMessage($object->error, 'errors');
  834. }
  835. }
  836. }
  837. // Bascule du statut d'un contact
  838. else if ($action == 'swapstatut') {
  839. if ($object->fetch($id) > 0) {
  840. $result = $object->swapContactStatus(GETPOST('ligne'));
  841. } else {
  842. dol_print_error($db);
  843. }
  844. }
  845. // Efface un contact
  846. else if ($action == 'deletecontact') {
  847. $object->fetch($id);
  848. $result = $object->delete_contact($lineid);
  849. if ($result >= 0) {
  850. header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
  851. exit;
  852. } else {
  853. dol_print_error($db);
  854. }
  855. }
  856. }
  857. /*
  858. * View
  859. */
  860. llxHeader('', $langs->trans('Proposal'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  861. $titre = $langs->trans('Proposal');
  862. print_fiche_titre($titre);
  863. print '<div class="with-padding" >';
  864. print '<div class="columns" >';
  865. $form = new Form($db);
  866. $formother = new FormOther($db);
  867. $formfile = new FormFile($db);
  868. $formpropal = new FormPropal($db);
  869. $companystatic = new Societe($db);
  870. $now = dol_now();
  871. /*
  872. * Show object in view mode
  873. */
  874. $soc = new Societe($db);
  875. $soc->fetch($object->client->id);
  876. //$head = propal_prepare_head($object);
  877. //dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal');
  878. $formconfirm = '';
  879. // Clone confirmation
  880. if ($action == 'clone') {
  881. // Create an array for form
  882. $formquestion = array(
  883. //'text' => $langs->trans("ConfirmClone"),
  884. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  885. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  886. 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)'))
  887. );
  888. // Paiement incomplet. On demande si motif = escompte ou autre
  889. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ClonePropal'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  890. }
  891. // Confirm delete
  892. else if ($action == 'delete') {
  893. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp', $object->ref), 'confirm_delete', '', 0, 1);
  894. }
  895. // Confirm reopen
  896. else if ($action == 'reopen') {
  897. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp', $object->ref), 'confirm_reopen', '', 0, 1);
  898. }
  899. // Confirmation delete product/service line
  900. else if ($action == 'ask_deleteline') {
  901. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  902. }
  903. // Confirm validate proposal
  904. else if ($action == 'validate') {
  905. $error = 0;
  906. // on verifie si l'objet est en numerotation provisoire
  907. $ref = substr($object->ref, 1, 4);
  908. if ($ref == 'PROV') {
  909. $numref = $object->getNextNumRef($soc);
  910. if (empty($numref)) {
  911. $error++;
  912. dol_htmloutput_errors($object->error);
  913. }
  914. } else {
  915. $numref = $object->ref;
  916. }
  917. $text = $langs->trans('ConfirmValidateProp', $numref);
  918. if (!empty($conf->notification->enabled)) {
  919. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  920. $notify = new Notify($db);
  921. $text.='<br>';
  922. $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL', $object->socid);
  923. }
  924. if (!$error)
  925. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1);
  926. }
  927. if (!$formconfirm) {
  928. $parameters = array('lineid' => $lineid);
  929. $formconfirm = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  930. }
  931. // Print form confirm
  932. print $formconfirm;
  933. /*
  934. * Boutons Actions
  935. */
  936. if ($action != 'presend') {
  937. print '<div class="tabsAction">';
  938. if ($action != 'statut' && $action <> 'editline') {
  939. // Send
  940. // if ($object->Status == "OPENED" || $object->statut == 2) {
  941. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) {
  942. print '<a class="button icon-mail" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=presend&amp;mode=init">' . $langs->trans('SendByMail') . '</a>';
  943. }
  944. // else
  945. // print '<a class="buttonRefused" href="#">' . $langs->trans('SendByMail') . '</a>';
  946. // }
  947. // Create an order
  948. if (!empty($conf->commande->enabled) /* && $object->Status == "SIGNED" */ && $user->societe_id == 0) {
  949. if ($user->rights->commande->creer) {
  950. print '<a class="button icon-folder" href="' . DOL_URL_ROOT . '/commande/fiche.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->client->id . '">' . $langs->trans("AddOrder") . '</a>';
  951. }
  952. }
  953. // Create an invoice and classify billed
  954. // if ($object->Status == "SIGNED" && $user->societe_id == 0) {
  955. // if (!empty($conf->facture->enabled) && $user->rights->facture->creer) {
  956. // print '<a class="button" href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddBill") . '</a>';
  957. // }
  958. //
  959. // $arraypropal = $object->getInvoiceArrayList();
  960. // if (is_array($arraypropal) && count($arraypropal) > 0) {
  961. // print '<a class="button" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled&amp;socid=' . $object->socid . '">' . $langs->trans("ClassifyBilled") . '</a>';
  962. // }
  963. // }
  964. // Delete
  965. if ($user->rights->propal->supprimer) {
  966. print '<a class="button icon-cross" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete"';
  967. print '>' . $langs->trans('Delete') . '</a>';
  968. }
  969. }
  970. print '</div>';
  971. print "<br>\n";
  972. }
  973. print start_box($titre, "twelve", $object->fk_extrafields->ico, false);
  974. dol_fiche_head($head, 'card', $title, 0, $picto);
  975. print '<table class="border" width="100%">';
  976. $linkback = '<a href="' . DOL_URL_ROOT . '/propal/list.php">' . $langs->trans("BackToList") . '</a>';
  977. // Ref
  978. print '<tr><td>' . $langs->trans('Ref') . '</td><td colspan="5">';
  979. //print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  980. print $object->ref;
  981. print '</td></tr>';
  982. // Ref client
  983. print '<tr><td>' . $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "text") . '</td>';
  984. print '<td td colspan="5">';
  985. print $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "text");
  986. print '</td>';
  987. print '</tr>';
  988. // Ref client
  989. /*print '<tr><td>';
  990. print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
  991. print $langs->trans('RefCustomer') . '</td><td align="left">';
  992. print '</td>';
  993. if ($action != 'refclient' && $object->Status == "DRAFT")
  994. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=refclient&amp;id=' . $object->id . '">' . img_edit($langs->trans('Modify')) . '</a></td>';
  995. print '</tr></table>';
  996. print '</td><td colspan="5">';
  997. if ($user->rights->propal->creer && $action == 'refclient') {
  998. print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  999. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1000. print '<input type="hidden" name="action" value="set_ref_client">';
  1001. print '<input type="text" class="flat" size="20" name="ref_client" value="' . $object->ref_client . '">';
  1002. print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1003. print '</form>';
  1004. } else {
  1005. print $object->ref_client;
  1006. }
  1007. print '</td>';
  1008. print '</tr>';*/
  1009. // Company
  1010. print '<tr><td>' . $langs->trans('Company') . '</td><td colspan="5">' . $soc->getNomUrl(1) . '</td>';
  1011. print '</tr>';
  1012. // Ligne info remises tiers
  1013. //print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="5">';
  1014. //if ($soc->remise_client)
  1015. // print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_client);
  1016. //else
  1017. // print $langs->trans("CompanyHasNoRelativeDiscount");
  1018. //print '. ';
  1019. //$absolute_discount = $soc->getAvailableDiscounts('', 'fk_facture_source IS NULL');
  1020. //$absolute_creditnote = $soc->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
  1021. //$absolute_discount = price2num($absolute_discount, 'MT');
  1022. //$absolute_creditnote = price2num($absolute_creditnote, 'MT');
  1023. //if ($absolute_discount) {
  1024. // if ($object->statut > 0) {
  1025. // print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency));
  1026. // } else {
  1027. // // Remise dispo de type non avoir
  1028. // $filter = 'fk_facture_source IS NULL';
  1029. // print '<br>';
  1030. // $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?id=' . $object->id, 0, 'remise_id', $soc->id, $absolute_discount, $filter);
  1031. // }
  1032. //}
  1033. //if ($absolute_creditnote) {
  1034. // print $langs->trans("CompanyHasCreditNote", price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '. ';
  1035. //}
  1036. //if (!$absolute_discount && !$absolute_creditnote)
  1037. // print $langs->trans("CompanyHasNoAbsoluteDiscount") . '.';
  1038. //print '</td></tr>';
  1039. // Date of proposal
  1040. //print '<tr>';
  1041. //print '<td>';
  1042. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1043. //print $langs->trans('Date');
  1044. //print '</td>';
  1045. //if ($action != 'editdate' && $object->Status == "DRAFT")
  1046. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdate&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetDate'), 1) . '</a></td>';
  1047. //print '</tr></table>';
  1048. //print '</td><td colspan="3">';
  1049. //if ($object->Status == "DRAFT" && $action == 'editdate') {
  1050. // print '<form name="editdate" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1051. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1052. // print '<input type="hidden" name="action" value="setdate">';
  1053. // $form->select_date($object->date, 're', '', '', 0, "editdate");
  1054. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1055. // print '</form>';
  1056. //} else {
  1057. // if ($object->date) {
  1058. // print dol_print_date($object->date, 'daytext');
  1059. // } else {
  1060. // print '&nbsp;';
  1061. // }
  1062. //}
  1063. //print '</td>';
  1064. print '<tr><td>' . $form->editfieldkey("Date", 'date', $object->date, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker") . '</td>';
  1065. print '<td td colspan="5">';
  1066. print $form->editfieldval("Date", 'date', $object->date, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker");
  1067. print '</td>';
  1068. print '</tr>';
  1069. // Date end proposal
  1070. //print '<tr>';
  1071. //print '<td>';
  1072. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1073. //print $langs->trans('DateEndPropal');
  1074. //print '</td>';
  1075. //if ($action != 'editecheance' && $object->Status == "DRAFT")
  1076. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editecheance&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
  1077. //print '</tr></table>';
  1078. //print '</td><td colspan="3">';
  1079. //if ($object->Status == "DRAFT" && $action == 'editecheance') {
  1080. // print '<form name="editecheance" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1081. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1082. // print '<input type="hidden" name="action" value="setecheance">';
  1083. // $form->select_date($object->fin_validite, 'ech', '', '', '', "editecheance");
  1084. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1085. // print '</form>';
  1086. //} else {
  1087. // if (!empty($object->fin_validite)) {
  1088. // print dol_print_date($object->fin_validite, 'daytext');
  1089. // if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay))
  1090. // print img_warning($langs->trans("Late"));
  1091. // }
  1092. // else {
  1093. // print '&nbsp;';
  1094. // }
  1095. //}
  1096. //print '</td>';
  1097. //print '</tr>';
  1098. print '<tr><td>' . $form->editfieldkey("DateEndPropal", 'fin_validite', $object->fin_validite, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker") . '</td>';
  1099. print '<td td colspan="5">';
  1100. print $form->editfieldval("DateEndPropal", 'fin_validite', $object->fin_validite, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker");
  1101. print '</td>';
  1102. print '</tr>';
  1103. // Payment term
  1104. //print '<tr><td>';
  1105. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1106. //print $langs->trans('PaymentConditionsShort');
  1107. //print '</td>';
  1108. //if ($action != 'editconditions' && $object->Status == "DRAFT")
  1109. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetConditions'), 1) . '</a></td>';
  1110. //print '</tr></table>';
  1111. //print '</td><td colspan="3">';
  1112. //if ($action == 'editconditions') {
  1113. //// $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
  1114. // print '<form name="editconditions" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1115. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1116. // print '<input type="hidden" name="action" value="setconditions">';
  1117. // print $object->select_fk_extrafields("cond_reglement_code", "cond_reglement_code", $object->cond_reglement_code);
  1118. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1119. // print '</form>';
  1120. //} else {
  1121. //// $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none');
  1122. // print $object->getExtraFieldLabel('cond_reglement_code');
  1123. //}
  1124. //print '</td>';
  1125. //print '</tr>';
  1126. print '<tr><td>' . $form->editfieldkey("PaymentConditionsShort", 'cond_reglement_code', $object->cond_reglement_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select") . '</td>';
  1127. print '<td td colspan="5">';
  1128. print $form->editfieldval("PaymentConditionsShort", 'cond_reglement_code', $object->cond_reglement_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select");
  1129. print '</td>';
  1130. print '</tr>';
  1131. // Delivery date
  1132. //$langs->load('deliveries');
  1133. //print '<tr><td>';
  1134. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1135. //print $langs->trans('DeliveryDate');
  1136. //print '</td>';
  1137. //if ($action != 'editdate_livraison' && $object->Status == "DRAFT")
  1138. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdate_livraison&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'), 1) . '</a></td>';
  1139. //print '</tr></table>';
  1140. //print '</td><td colspan="3">';
  1141. //if ($action == 'editdate_livraison') {
  1142. // print '<form name="editdate_livraison" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1143. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1144. // print '<input type="hidden" name="action" value="setdate_livraison">';
  1145. // $form->select_date($object->date_livraison, 'liv_', '', '', '', "editdate_livraison");
  1146. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1147. // print '</form>';
  1148. //} else {
  1149. // print dol_print_date($object->date_livraison, 'daytext');
  1150. //}
  1151. //print '</td>';
  1152. //print '</tr>';
  1153. print '<tr><td>' . $form->editfieldkey("DeliveryDate", 'date_livraison', $object->date_livraison, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker") . '</td>';
  1154. print '<td td colspan="5">';
  1155. print $form->editfieldval("DeliveryDate", 'date_livraison', $object->date_livraison, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "datepicker");
  1156. print '</td>';
  1157. print '</tr>';
  1158. // Delivery delay
  1159. //print '<tr><td>';
  1160. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1161. //print $langs->trans('AvailabilityPeriod');
  1162. //if (!empty($conf->commande->enabled))
  1163. // print ' (' . $langs->trans('AfterOrder') . ')';
  1164. //print '</td>';
  1165. //if ($action != 'editavailability' && $object->Status == "DRAFT")
  1166. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editavailability&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1) . '</a></td>';
  1167. //print '</tr></table>';
  1168. //print '</td><td colspan="3">';
  1169. //if ($action == 'editavailability') {
  1170. // print '<form name="editavailability" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1171. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1172. // print '<input type="hidden" name="action" value="setavailability">';
  1173. // print $object->select_fk_extrafields("availability_code", "availability_code", $object->availability_code);
  1174. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1175. // print '</form>';
  1176. //// $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'availability_id', 1);
  1177. //} else {
  1178. //// $form->form_availability($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->availability_id, 'none', 1);
  1179. // print $langs->trans($object->getExtraFieldLabel('availability_code'));
  1180. //}
  1181. //
  1182. //print '</td>';
  1183. //print '</tr>';
  1184. print '<tr><td>' . $form->editfieldkey("AvailabilityPeriod", 'availability_code', $object->availability_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select") . '</td>';
  1185. print '<td td colspan="5">';
  1186. print $form->editfieldval("AvailabilityPeriod", 'availability_code', $object->availability_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select");
  1187. print '</td>';
  1188. print '</tr>';
  1189. // Origin of demand
  1190. //print '<tr><td>';
  1191. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1192. //print $langs->trans('Source');
  1193. //print '</td>';
  1194. //if ($action != 'editdemandreason' && $object->Status == "DRAFT")
  1195. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editdemandreason&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1) . '</a></td>';
  1196. //print '</tr></table>';
  1197. //print '</td><td colspan="3">';
  1198. ////print $object->demand_reason_id;
  1199. //if ($action == 'editdemandreason') {
  1200. // print '<form name="editdemandreason" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1201. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1202. // print '<input type="hidden" name="action" value="setdemandreason">';
  1203. // print $object->select_fk_extrafields("demand_reason_code", "demand_reason_code", $object->demand_reason_code);
  1204. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1205. // print '</form>';
  1206. //// $form->form_demand_reason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'demand_reason_id', 1);
  1207. //} else {
  1208. // //$form->form_demand_reason($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->demand_reason_id, 'none');
  1209. // print $langs->trans($object->getExtraFieldLabel('demand_reason_code'));
  1210. //}
  1211. print '<tr><td>' . $form->editfieldkey("Source", 'demand_reason_code', $object->demand_reason_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select") . '</td>';
  1212. print '<td td colspan="5">';
  1213. print $form->editfieldval("Source", 'demand_reason_code', $object->demand_reason_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select");
  1214. print '</td>';
  1215. print '</tr>';
  1216. print '</td>';
  1217. print '</tr>';
  1218. // Payment mode
  1219. //print '<tr>';
  1220. //print '<td width="25%">';
  1221. //print '<table class="nobordernopadding" width="100%"><tr><td>';
  1222. //print $langs->trans('PaymentMode');
  1223. //print '</td>';
  1224. //if ($action != 'editmode' && $object->Status == "DRAFT")
  1225. // print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetMode'), 1) . '</a></td>';
  1226. //print '</tr></table>';
  1227. //print '</td><td colspan="3">';
  1228. //if ($action == 'editmode') {
  1229. // print '<form name="editmode" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1230. // print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1231. // print '<input type="hidden" name="action" value="setmode">';
  1232. // print $object->select_fk_extrafields("mode_reglement_code", "mode_reglement_code", $object->mode_reglement_code);
  1233. // print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  1234. // print '</form>';
  1235. //// $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
  1236. //} else {
  1237. //// $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none');
  1238. // print $langs->trans($object->fk_extrafields->fields->mode_reglement_code->values->{$object->mode_reglement_code}->label);
  1239. //}
  1240. //print '</td></tr>';
  1241. print '<tr><td>' . $form->editfieldkey("PaymentMode", 'mode_reglement_code', $object->mode_reglement_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select") . '</td>';
  1242. print '<td td colspan="5">';
  1243. print $form->editfieldval("PaymentMode", 'mode_reglement_code', $object->mode_reglement_code, $object, $user->rights->propal->creer && $object->Status == "DRAFT", "select");
  1244. print '</td>';
  1245. print '</tr>';
  1246. // Project
  1247. if (!empty($conf->projet->enabled)) {
  1248. $langs->load("projects");
  1249. print '<tr><td>';
  1250. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1251. print $langs->trans('Project') . '</td>';
  1252. if ($user->rights->propal->creer) {
  1253. if ($action != 'classify')
  1254. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a></td>';
  1255. print '</tr></table>';
  1256. print '</td><td colspan="3">';
  1257. if ($action == 'classify') {
  1258. $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid');
  1259. } else {
  1260. $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none');
  1261. }
  1262. print '</td></tr>';
  1263. } else {
  1264. print '</td></tr></table>';
  1265. if (!empty($object->fk_project)) {
  1266. print '<td colspan="3">';
  1267. $proj = new Project($db);
  1268. $proj->fetch($object->fk_project);
  1269. print '<a href="../projet/fiche.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  1270. print $proj->ref;
  1271. print '</a>';
  1272. print '</td>';
  1273. } else {
  1274. print '<td colspan="3">&nbsp;</td>';
  1275. }
  1276. }
  1277. print '</tr>';
  1278. }
  1279. // Other attributes
  1280. $parameters = array('colspan' => ' colspan="3"');
  1281. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1282. if (empty($reshook) && !empty($extrafields->attribute_label)) {
  1283. foreach ($extrafields->attribute_label as $key => $label) {
  1284. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);
  1285. print "<tr><td>" . $label . '</td><td colspan="3">';
  1286. print $extrafields->showInputField($key, $value);
  1287. print '</td></tr>' . "\n";
  1288. }
  1289. }
  1290. // Amount HT
  1291. print '<tr><td height="10">' . $langs->trans('AmountHT') . '</td>';
  1292. print '<td align="right" nowrap><b>' . price($object->total_ht) . '</b></td>';
  1293. print '<td>' . $langs->trans("Currency" . $conf->currency) . '</td>';
  1294. // Margin Infos
  1295. if (!empty($conf->margin->enabled)) {
  1296. print '<td valign="top" width="50%" rowspan="4">';
  1297. $object->displayMarginInfos();
  1298. print '</td>';
  1299. }
  1300. print '</tr>';
  1301. // Amount VAT
  1302. print '<tr><td height="10">' . $langs->trans('AmountVAT') . '</td>';
  1303. print '<td align="right" nowrap>' . price($object->total_tva) . '</td>';
  1304. print '<td>' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
  1305. // Amount Local Taxes
  1306. if ($mysoc->country_code == 'ES') {
  1307. if ($mysoc->localtax1_assuj == "1") { //Localtax1 RE
  1308. print '<tr><td height="10">' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
  1309. print '<td align="right" nowrap>' . price($object->total_localtax1) . '</td>';
  1310. print '<td>' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
  1311. }
  1312. if ($mysoc->localtax2_assuj == "1") { //Localtax2 IRPF
  1313. print '<tr><td height="10">' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
  1314. print '<td align="right" nowrap>' . price($object->total_localtax2) . '</td>';
  1315. print '<td>' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
  1316. }
  1317. }
  1318. // Amount TTC
  1319. print '<tr><td height="10">' . $langs->trans('AmountTTC') . '</td>';
  1320. print '<td align="right" nowrap>' . price($object->total_ttc) . '</td>';
  1321. print '<td>' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
  1322. // Statut
  1323. //print '<tr><td height="10">' . $langs->trans('Status') . '</td><td align="left" colspan="2">' . $langs->trans($object->getExtraFieldLabel('Status')) . '</td></tr>';
  1324. print '<tr><td>' . $form->editfieldkey("Status", 'Status', $object->Status, $object, $user->rights->propal->creer, "select") . '</td>';
  1325. print '<td td colspan="5">';
  1326. print $form->editfieldval("Status", 'Status', $object->Status, $object, $user->rights->propal->creer, "select");
  1327. print '</td>';
  1328. print '</tr>';
  1329. print '</table><br>';
  1330. dol_fiche_end();
  1331. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  1332. $blocname = 'contacts';
  1333. $title = $langs->trans('ContactsAddresses');
  1334. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  1335. }
  1336. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  1337. $blocname = 'notes';
  1338. $title = $langs->trans('Notes');
  1339. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  1340. }
  1341. print end_box();
  1342. /*
  1343. * Lines
  1344. */
  1345. $object->showLines();
  1346. if ($action == 'statut') {
  1347. /*
  1348. * Formulaire cloture (signe ou non)
  1349. */
  1350. $form_close = '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
  1351. $form_close.= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1352. $form_close.= '<table class="border" width="100%">';
  1353. $form_close.= '<tr><td width="150" align="left">' . $langs->trans("CloseAs") . '</td><td align="left">';
  1354. $form_close.= '<input type="hidden" name="action" value="setstatut">';
  1355. $form_close.= '<select id="statut" name="statut" class="flat">';
  1356. $form_close.= '<option value="SIGNED">' . $langs->trans($object->fk_extrafields->fields->Status->values->SIGNED->label) . '</option>';
  1357. $form_close.= '<option value="NOT_SIGNED">' . $langs->trans($object->fk_extrafields->fields->Status->values->NOT_SIGNED->label) . '</option>';
  1358. $form_close.= '</select>';
  1359. $form_close.= '</td></tr>';
  1360. $form_close.= '<tr><td width="150" align="left">' . $langs->trans('Note') . '</td><td align="left"><textarea cols="70" rows="' . ROWS_3 . '" wrap="soft" name="note">';
  1361. $form_close.= $object->note;
  1362. $form_close.= '</textarea></td></tr>';
  1363. $form_close.= '<tr><td align="center" colspan="2">';
  1364. $form_close.= '<input type="submit" class="button" name="validate" value="' . $langs->trans('Validate') . '">';
  1365. $form_close.= ' &nbsp; <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '">';
  1366. $form_close.= '<a name="close">&nbsp;</a>';
  1367. $form_close.= '</td>';
  1368. $form_close.= '</tr></table></form>';
  1369. print $form_close;
  1370. }
  1371. if ($action != 'presend') {
  1372. // print '<table width="100%"><tr><td width="100%" valign="top">';
  1373. // print '<a name="builddoc"></a>'; // ancre
  1374. /*
  1375. * Documents generes
  1376. */
  1377. $filename = dol_sanitizeFileName($object->ref);
  1378. $filedir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
  1379. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  1380. $genallowed = $user->rights->propal->creer;
  1381. $delallowed = $user->rights->propal->supprimer;
  1382. $var = true;
  1383. $somethingshown = $formfile->show_documents('propal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
  1384. /*
  1385. * Linked object block
  1386. */
  1387. // $object->printLinkedObjects();
  1388. $object->showLinkedObjects();
  1389. // $somethingshown = $object->showLinkedObjectBlock();
  1390. // print '</td><td valign="top" width="50%">';
  1391. //
  1392. // // List of actions on element
  1393. // include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  1394. // $formactions = new FormActions($db);
  1395. // $somethingshown = $formactions->showactions($object, 'propal', $socid);
  1396. // print '</td></tr></table>';
  1397. }
  1398. /*
  1399. * Action presend
  1400. *
  1401. */
  1402. if ($action == 'presend') {
  1403. $ref = dol_sanitizeFileName($object->ref);
  1404. include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  1405. $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref);
  1406. $file = $fileparams['fullname'];
  1407. // Build document if it not exists
  1408. if (!$file || !is_readable($file)) {
  1409. // Define output language
  1410. $outputlangs = $langs;
  1411. $newlang = '';
  1412. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  1413. $newlang = $_REQUEST['lang_id'];
  1414. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1415. $newlang = $object->client->default_lang;
  1416. if (!empty($newlang)) {
  1417. $outputlangs = new Translate();
  1418. $outputlangs->setDefaultLang($newlang);
  1419. }
  1420. $result = propale_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1421. if ($result <= 0) {
  1422. dol_print_error($db, $result);
  1423. exit;
  1424. }
  1425. $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref);
  1426. $file = $fileparams['fullname'];
  1427. }
  1428. print '<br>';
  1429. print_titre($langs->trans('SendPropalByMail'));
  1430. // Create form object
  1431. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  1432. $formmail = new FormMail($db);
  1433. $formmail->fromtype = 'user';
  1434. $formmail->fromid = $user->id;
  1435. $formmail->fromname = $user->getFullName($langs);
  1436. $formmail->frommail = $user->email;
  1437. $formmail->withfrom = 1;
  1438. $formmail->withto = empty($_POST["sendto"]) ? 1 : $_POST["sendto"];
  1439. $formmail->withtosocid = $soc->id;
  1440. $formmail->withtocc = 1;
  1441. $formmail->withtoccsocid = 0;
  1442. $formmail->withtoccc = (!empty($conf->global->MAIN_EMAIL_USECCC) ? $conf->global->MAIN_EMAIL_USECCC : false);
  1443. $formmail->withtocccsocid = 0;
  1444. $formmail->withtopic = $langs->trans('SendPropalRef', '__PROPREF__');
  1445. $formmail->withfile = 2;
  1446. $formmail->withbody = 1;
  1447. $formmail->withdeliveryreceipt = 1;
  1448. $formmail->withcancel = 1;
  1449. // Tableau des substitutions
  1450. $formmail->substit['__PROPREF__'] = $object->ref;
  1451. $formmail->substit['__SIGNATURE__'] = $user->signature;
  1452. $formmail->substit['__PERSONALIZED__'] = '';
  1453. // Tableau des parametres complementaires
  1454. $formmail->param['action'] = 'send';
  1455. $formmail->param['models'] = 'propal_send';
  1456. $formmail->param['id'] = $object->id;
  1457. $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
  1458. // Init list of files
  1459. if (GETPOST("mode") == 'init') {
  1460. $formmail->clear_attached_files();
  1461. $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
  1462. }
  1463. $formmail->show_form();
  1464. print '<br>';
  1465. }
  1466. // End of page
  1467. print '</div>';
  1468. print '</div>';
  1469. llxFooter();
  1470. ?>