PageRenderTime 50ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/commande/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1234 lines | 817 code | 172 blank | 245 comment | 323 complexity | 3f838fcdd6dc0bc451d676251f82470c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
  5. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  9. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  10. * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
  11. * Copyright (C) 2012 David Moothen <dmoothen@gmail.com>
  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. if (!empty($_GET["json"]) && !defined('NOTOKENRENEWAL'))
  27. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formorder.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/commande/core/modules/commande/modules_commande.php';
  32. require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/lib/order.lib.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  37. if (!empty($conf->propal->enabled))
  38. require DOL_DOCUMENT_ROOT . '/propal/class/propal.class.php';
  39. if (!empty($conf->projet->enabled)) {
  40. require DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  41. require DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
  42. }
  43. /* Loading langs ************************************************************ */
  44. $langs->load('orders');
  45. $langs->load('sendings');
  46. $langs->load('companies');
  47. $langs->load('bills');
  48. $langs->load('propal');
  49. $langs->load('deliveries');
  50. $langs->load('products');
  51. if (!empty($conf->margin->enabled))
  52. $langs->load('margins');
  53. //$product = new Product($db);
  54. //$res = $product->getView('list', array('startkey' => 'd', 'endkey' => 'dZ'));
  55. //echo '<pre>' . print_r($res, true) . '</pre>';die;
  56. /* Post params ************************************************************** */
  57. $id = GETPOST('id', 'alpha');
  58. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  59. $confirm = GETPOST('confirm');
  60. $lineid = GETPOST('lineid', 'alpha');
  61. $origin = GETPOST('origin', 'alpha');
  62. $originid = (GETPOST('originid', 'alpha') ? GETPOST('originid', 'alpha') : GETPOST('origin_id', 'alpha')); // For backward compatibility
  63. $title = $langs->trans('Order');
  64. $object = new Commande($db);
  65. $soc = new Societe($db);
  66. if (!empty($id)) {
  67. $object->fetch($id);
  68. $object->fetch_thirdparty();
  69. $soc->load($object->client->id);
  70. }
  71. //echo '<pre>' . print_r($object->getLinkedObject(), true) . '</pre>';die;
  72. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  73. $hookmanager->initHooks(array('ordercard'));
  74. if (!empty($_GET['json'])) {
  75. $output = array(
  76. "sEcho" => intval($_GET['sEcho']),
  77. "iTotalRecords" => 0,
  78. "iTotalDisplayRecords" => 0,
  79. "aaData" => array()
  80. );
  81. // $keystart[0] = $user->id;
  82. // $keyend[0] = $user->id;
  83. // $keyend[1] = new stdClass();
  84. /* $params = array('startkey' => array($user->id, mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"))),
  85. 'endkey' => array($user->id, mktime(0, 0, 0, date("m") + 1, date("d"), date("Y")))); */
  86. try {
  87. $result = $object->getView($_GET["json"], array('key' => $id));
  88. } catch (Exception $exc) {
  89. print $exc->getMessage();
  90. }
  91. $iTotal = count($result->rows);
  92. $output["iTotalRecords"] = $iTotal;
  93. $output["iTotalDisplayRecords"] = $iTotal;
  94. $i = 0;
  95. if (count($result->rows))
  96. foreach ($result->rows as $aRow) {
  97. $output["aaData"][] = $aRow->value;
  98. }
  99. header('Content-type: application/json');
  100. echo json_encode($output);
  101. exit;
  102. }
  103. /* Actions ****************************************************************** */
  104. if ($action == 'add' && $user->rights->commande->creer) {
  105. $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  106. $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  107. $object->socid = GETPOST('socid');
  108. $object->date_commande = $datecommande;
  109. $object->note = GETPOST('note');
  110. $object->note_public = GETPOST('note_public');
  111. $object->source = GETPOST('source_id');
  112. $object->fk_project = GETPOST('projectid');
  113. $object->ref_client = GETPOST('ref_client');
  114. $object->modelpdf = GETPOST('model');
  115. $object->cond_reglement_code = GETPOST('cond_reglement_code');
  116. $object->mode_reglement_code = GETPOST('mode_reglement_code');
  117. $object->availability_code = GETPOST('availability_code');
  118. $object->demand_reason_code = GETPOST('demand_reason_code');
  119. $object->date_livraison = $datelivraison;
  120. $object->fk_delivery_address = GETPOST('fk_address');
  121. $object->contactid = GETPOST('contactidp');
  122. // If creation from another object of another module (Example: origin=propal, originid=1)
  123. if ($_POST['origin'] && $_POST['originid']) {
  124. // Parse element/subelement (ex: project_task)
  125. $element = $subelement = $_POST['origin'];
  126. if (preg_match('/^([^_]+)_([^_]+)/i', $_POST['origin'], $regs)) {
  127. $element = $regs[1];
  128. $subelement = $regs[2];
  129. }
  130. // For compatibility
  131. if ($element == 'order') {
  132. $element = $subelement = 'commande';
  133. }
  134. if ($element == 'propal') {
  135. $element = 'propal/propal';
  136. $subelement = 'propal';
  137. }
  138. if ($element == 'contract') {
  139. $element = $subelement = 'contrat';
  140. }
  141. $object->origin = $_POST['origin'];
  142. $object->origin_id = $_POST['originid'];
  143. // Possibility to add external linked objects with hooks
  144. // $object->linked_objects[$object->origin] = $object->origin_id;
  145. $object->linked_objects[] = array('type' => $object->origin, 'id' => $object->origin_id);
  146. if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
  147. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  148. }
  149. $id = $object->create($user);
  150. if (!(empty($id))) {
  151. dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
  152. $classname = ucfirst($subelement);
  153. $srcobject = new $classname($db);
  154. dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
  155. $result = $srcobject->fetch($object->origin_id);
  156. if (!empty($result)) {
  157. // Hooks
  158. $parameters = array('objFrom' => $srcobject);
  159. $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  160. if ($reshook < 0)
  161. $error++;
  162. }
  163. else {
  164. $mesg = $srcobject->error;
  165. $error++;
  166. }
  167. } else {
  168. $mesg = $object->error;
  169. $error++;
  170. }
  171. } else {
  172. $id = $object->create($user);
  173. }
  174. if (!empty($id)) {
  175. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
  176. exit;
  177. }
  178. } else if ($action == 'update' && $user->rights->commande->creer) {
  179. $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  180. $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  181. $object->socid = GETPOST('socid');
  182. $object->date_commande = $datecommande;
  183. $object->note = GETPOST('note');
  184. $object->note_public = GETPOST('note_public');
  185. $object->source = GETPOST('source_id');
  186. $object->fk_project = GETPOST('projectid');
  187. $object->ref_client = GETPOST('ref_client');
  188. $object->modelpdf = GETPOST('model');
  189. $object->cond_reglement_code = GETPOST('cond_reglement_code');
  190. $object->mode_reglement_code = GETPOST('mode_reglement_code');
  191. $object->availability_code = GETPOST('availability_code');
  192. $object->demand_reason_code = GETPOST('demand_reason_code');
  193. $object->date_livraison = $datelivraison;
  194. $object->fk_delivery_address = GETPOST('fk_address');
  195. $object->contactid = GETPOST('contactidp');
  196. $id = $object->update();
  197. if (!empty($id)) {
  198. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
  199. exit;
  200. }
  201. } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer) {
  202. $result = $object->delete($user);
  203. if ($result > 0) {
  204. header('Location: list.php');
  205. exit;
  206. } else {
  207. $mesg = '<div class="error">' . $object->error . '</div>';
  208. }
  209. } else if ($action == 'remove_file') {
  210. $langs->load("other");
  211. $comref = dol_sanitizeFileName($object->ref);
  212. $file = $conf->commande->dir_output . '/' . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  213. $ret = dol_delete_file($file);
  214. } else if ($action == 'builddoc') { // In get or post
  215. /*
  216. * Generate order document
  217. * define into /core/modules/commande/modules_commande.php
  218. */
  219. // Sauvegarde le dernier modele choisi pour generer un document
  220. if ($_REQUEST['model']) {
  221. $object->setDocModel($user, $_REQUEST['model']);
  222. }
  223. // Define output language
  224. $outputlangs = $langs;
  225. $newlang = '';
  226. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  227. $newlang = $_REQUEST['lang_id'];
  228. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  229. $newlang = $object->client->default_lang;
  230. if (!empty($newlang)) {
  231. $outputlangs = new Translate();
  232. $outputlangs->setDefaultLang($newlang);
  233. }
  234. $result = commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  235. if ($result <= 0) {
  236. dol_print_error($db, $result);
  237. exit;
  238. } else {
  239. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
  240. exit;
  241. }
  242. } else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->commande->valider) {
  243. $idwarehouse = GETPOST('idwarehouse');
  244. // Check parameters
  245. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  246. if (!$idwarehouse || $idwarehouse == -1) {
  247. $error++;
  248. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  249. $action = '';
  250. }
  251. }
  252. if (!$error) {
  253. $result = $object->valid($user, $idwarehouse);
  254. if ($result >= 0) {
  255. // Define output language
  256. $outputlangs = $langs;
  257. $newlang = '';
  258. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  259. $newlang = $_REQUEST['lang_id'];
  260. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  261. $newlang = $object->client->default_lang;
  262. if (!empty($newlang)) {
  263. $outputlangs = new Translate();
  264. $outputlangs->setDefaultLang($newlang);
  265. }
  266. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  267. commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  268. }
  269. }
  270. }
  271. else if ($action == 'confirm_modif' && $user->rights->commande->creer) {
  272. $idwarehouse = GETPOST('idwarehouse');
  273. // Check parameters
  274. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  275. if (!$idwarehouse || $idwarehouse == -1) {
  276. $error++;
  277. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  278. $action = '';
  279. }
  280. }
  281. if (!$error) {
  282. $result = $object->set_draft($user, $idwarehouse);
  283. if ($result >= 0) {
  284. // Define output language
  285. $outputlangs = $langs;
  286. $newlang = '';
  287. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  288. $newlang = $_REQUEST['lang_id'];
  289. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  290. $newlang = $object->client->default_lang;
  291. if (!empty($newlang)) {
  292. $outputlangs = new Translate();
  293. $outputlangs->setDefaultLang($newlang);
  294. }
  295. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  296. $ret = $object->fetch($object->id); // Reload to get new records
  297. commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  298. }
  299. }
  300. }
  301. } else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->commande->valider) {
  302. $idwarehouse = GETPOST('idwarehouse');
  303. // Check parameters
  304. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  305. if (!$idwarehouse || $idwarehouse == -1) {
  306. $error++;
  307. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  308. $action = '';
  309. }
  310. }
  311. if (!$error) {
  312. $result = $object->cancel($idwarehouse);
  313. }
  314. } else if ($action == 'confirm_shipped' && $confirm == 'yes' && $user->rights->commande->cloturer) {
  315. $result = $object->cloture($user);
  316. if ($result < 0)
  317. $mesgs = $object->errors;
  318. }
  319. // Reopen a closed order
  320. else if ($action == 'reopen' && $user->rights->commande->creer) {
  321. if ($object->Status == "TO_BILL" || $object->Status == "PROCESSED") {
  322. $result = $object->set_reopen($user);
  323. if ($result > 0) {
  324. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  325. exit;
  326. } else {
  327. $mesg = '<div class="error">' . $object->error . '</div>';
  328. }
  329. }
  330. } else if ($action == 'classifybilled' && $user->rights->commande->creer) {
  331. $ret = $object->classifyBilled();
  332. }
  333. /*
  334. * Add file in email form
  335. */
  336. if (GETPOST('addfile')) {
  337. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  338. $vardir = $conf->user->dir_output . "/" . $user->id;
  339. $upload_dir_tmp = $vardir . '/temp';
  340. dol_add_file_process($upload_dir_tmp, 0, 0);
  341. $action = 'presend';
  342. }
  343. /*
  344. * Remove file in email form
  345. */
  346. if (GETPOST('removedfile')) {
  347. require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  348. // Set tmp user directory
  349. $vardir = $conf->user->dir_output . "/" . $user->id;
  350. $upload_dir_tmp = $vardir . '/temp';
  351. // TODO Delete only files that was uploaded from email form
  352. dol_remove_file_process(GETPOST('removedfile'), 0);
  353. $action = 'presend';
  354. }
  355. /*
  356. * Send mail
  357. */
  358. if ($action == 'send' && !GETPOST('addfile') && !GETPOST('removedfile') && !GETPOST('cancel')) {
  359. $langs->load('mails');
  360. if ($object->id > 0) {
  361. // $ref = dol_sanitizeFileName($object->ref);
  362. // $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
  363. // if (is_readable($file))
  364. // {
  365. if (GETPOST('sendto')) {
  366. // Le destinataire a ete fourni via le champ libre
  367. $sendto = GETPOST('sendto');
  368. $sendtoid = 0;
  369. } elseif (GETPOST('receiver') != '-1') {
  370. // Recipient was provided from combo list
  371. if (GETPOST('receiver') == 'thirdparty') { // Id of third party
  372. $sendto = $object->client->email;
  373. $sendtoid = 0;
  374. } else { // Id du contact
  375. $sendto = $object->client->contact_get_property(GETPOST('receiver'), 'email');
  376. $sendtoid = GETPOST('receiver');
  377. }
  378. }
  379. if (dol_strlen($sendto)) {
  380. $langs->load("commercial");
  381. $from = GETPOST('fromname') . ' <' . GETPOST('frommail') . '>';
  382. $replyto = GETPOST('replytoname') . ' <' . GETPOST('replytomail') . '>';
  383. $message = GETPOST('message');
  384. $sendtocc = GETPOST('sendtocc');
  385. $deliveryreceipt = GETPOST('deliveryreceipt');
  386. if ($action == 'send') {
  387. if (dol_strlen(GETPOST('subject')))
  388. $subject = GETPOST('subject');
  389. else
  390. $subject = $langs->transnoentities('Order') . ' ' . $object->ref;
  391. $actiontypecode = 'AC_COM';
  392. $actionmsg = $langs->transnoentities('MailSentBy') . ' ' . $from . ' ' . $langs->transnoentities('To') . ' ' . $sendto . ".\n";
  393. if ($message) {
  394. $actionmsg.=$langs->transnoentities('MailTopic') . ": " . $subject . "\n";
  395. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody') . ":\n";
  396. $actionmsg.=$message;
  397. }
  398. $actionmsg2 = $langs->transnoentities('Action' . $actiontypecode);
  399. }
  400. // Create form object
  401. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  402. $formmail = new FormMail($db);
  403. $attachedfiles = $formmail->get_attached_files();
  404. $filepath = $attachedfiles['paths'];
  405. $filename = $attachedfiles['names'];
  406. $mimetype = $attachedfiles['mimes'];
  407. // Send mail
  408. require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php';
  409. $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt);
  410. if ($mailfile->error) {
  411. $mesg = '<div class="error">' . $mailfile->error . '</div>';
  412. } else {
  413. $result = $mailfile->sendfile();
  414. if ($result) {
  415. $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)); // Must not contains "
  416. $error = 0;
  417. // Initialisation donnees
  418. $object->sendtoid = $sendtoid;
  419. $object->actiontypecode = $actiontypecode;
  420. $object->actionmsg = $actionmsg;
  421. $object->actionmsg2 = $actionmsg2;
  422. $object->fk_element = $object->id;
  423. $object->elementtype = $object->element;
  424. // Appel des triggers
  425. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  426. $interface = new Interfaces($db);
  427. $result = $interface->run_triggers('ORDER_SENTBYMAIL', $object, $user, $langs, $conf);
  428. if ($result < 0) {
  429. $error++;
  430. $this->errors = $interface->errors;
  431. }
  432. // Fin appel triggers
  433. if ($error) {
  434. dol_print_error($db);
  435. } else {
  436. // Redirect here
  437. // This avoid sending mail twice if going out and then back to page
  438. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&mesg=' . urlencode($mesg));
  439. exit;
  440. }
  441. } else {
  442. $langs->load("other");
  443. $mesg = '<div class="error">';
  444. if ($mailfile->error) {
  445. $mesg.=$langs->trans('ErrorFailedToSendMail', $from, $sendto);
  446. $mesg.='<br>' . $mailfile->error;
  447. } else {
  448. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  449. }
  450. $mesg.='</div>';
  451. }
  452. }
  453. /* }
  454. else
  455. {
  456. $langs->load("other");
  457. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  458. $action='presend';
  459. dol_syslog('Recipient email is empty');
  460. } */
  461. } else {
  462. $langs->load("errors");
  463. $mesg = '<div class="error">' . $langs->trans('ErrorCantReadFile', $file) . '</div>';
  464. dol_syslog('Failed to read file: ' . $file);
  465. }
  466. } else {
  467. $langs->load("other");
  468. $mesg = '<div class="error">' . $langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")) . '</div>';
  469. dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")));
  470. }
  471. }
  472. /* View ********************************************************************* */
  473. $form = new Form($db);
  474. $formfile = new FormFile($db);
  475. $formorder = new FormOrder($db);
  476. llxHeader('', $title);
  477. print_fiche_titre($title . " " . $object->ref_client);
  478. $formconfirm = null;
  479. if ($action == 'delete') {
  480. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
  481. } else if ($action == 'ask_deleteline') {
  482. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  483. } else if ($action == 'validate') {
  484. // on verifie si l'objet est en numerotation provisoire
  485. $numref = $object->ref;
  486. $text = $langs->trans('ConfirmValidateOrder', $numref);
  487. if (!empty($conf->notification->enabled)) {
  488. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  489. $notify = new Notify($db);
  490. $text.='<br>';
  491. $text.=$notify->confirmMessage('NOTIFY_VAL_ORDER', $object->socid);
  492. }
  493. $formquestion = array();
  494. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  495. $langs->load("stocks");
  496. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  497. $formproduct = new FormProduct($db);
  498. $formquestion = array(
  499. //'text' => $langs->trans("ConfirmClone"),
  500. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  501. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  502. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  503. }
  504. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  505. } else if ($action == 'modify') {
  506. $text = $langs->trans('ConfirmUnvalidateOrder', $object->ref);
  507. $formquestion = array();
  508. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  509. $langs->load("stocks");
  510. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  511. $formproduct = new FormProduct($db);
  512. $formquestion = array(
  513. //'text' => $langs->trans("ConfirmClone"),
  514. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  515. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  516. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  517. }
  518. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
  519. } else if ($action == 'cancel') {
  520. $text = $langs->trans('ConfirmCancelOrder', $object->ref);
  521. $formquestion = array();
  522. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  523. $langs->load("stocks");
  524. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  525. $formproduct = new FormProduct($db);
  526. $formquestion = array(
  527. //'text' => $langs->trans("ConfirmClone"),
  528. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  529. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  530. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  531. }
  532. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
  533. } else if ($action == 'shipped') {
  534. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
  535. }
  536. print $formconfirm;
  537. print '<div class="with-padding" >';
  538. print '<div class="columns" >';
  539. /* Create View */
  540. if (($action == 'create' || $action == 'edit') && $user->rights->commande->creer) {
  541. $objectsrc = null;
  542. if (GETPOST('origin') && GETPOST('originid')) {
  543. // Parse element/subelement (ex: project_task)
  544. $element = $subelement = GETPOST('origin');
  545. if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
  546. $element = $regs[1];
  547. $subelement = $regs[2];
  548. }
  549. if ($element == 'project') {
  550. $projectid = GETPOST('originid');
  551. } else {
  552. // For compatibility
  553. if ($element == 'order' || $element == 'commande') {
  554. $element = $subelement = 'commande';
  555. }
  556. if ($element == 'propal') {
  557. $element = 'propal/propal';
  558. $subelement = 'propal';
  559. }
  560. if ($element == 'contract') {
  561. $element = $subelement = 'contrat';
  562. }
  563. dol_include_once('/' . $element . '/class/' . $subelement . '.class.php');
  564. $classname = ucfirst($subelement);
  565. $objectsrc = new $classname($db);
  566. $objectsrc->fetch(GETPOST('originid'));
  567. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines'))
  568. $objectsrc->fetch_lines();
  569. $objectsrc->fetch_thirdparty();
  570. $projectid = (!empty($objectsrc->fk_project) ? $object->fk_project : '');
  571. $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
  572. $soc = $objectsrc->thirdparty;
  573. $cond_reglement_code = (!empty($objectsrc->cond_reglement_code) ? $objectsrc->cond_reglement_code : (!empty($soc->cond_reglement_code) ? $soc->cond_reglement_code : 'RECEP'));
  574. $mode_reglement_code = (!empty($objectsrc->mode_reglement_code) ? $objectsrc->mode_reglement_code : (!empty($soc->mode_reglement_code) ? $soc->mode_reglement_code : 'TIP'));
  575. $availability_code = (!empty($objectsrc->availability_code) ? $objectsrc->availability_code : (!empty($soc->availability_code) ? $soc->availability_code : 'AV_NOW'));
  576. $demand_reason_code = (!empty($objectsrc->demand_reason_code) ? $objectsrc->demand_reason_code : (!empty($soc->demand_reason_code) ? $soc->demand_reason_code : 'SRC_EMAIL'));
  577. $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
  578. $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0));
  579. $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0;
  580. $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
  581. $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : '');
  582. $socid = (!empty($objectsrc->client->id) ? $objectsrc->client->id : $object->client->id);
  583. // Object source contacts list
  584. //$srccontactslist = $objectsrc->liste_contact(-1,'external',1);
  585. }
  586. }
  587. //print start_box($title, $object->fk_extrafields->ico);
  588. print column_start();
  589. print '<form name="crea_commande" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  590. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  591. print '<input type="hidden" name="action" value="' . ($action == 'create' ? 'add' : 'update') . '">';
  592. print '<input type="hidden" name="id" value="' . $id . '">';
  593. print '<input type="hidden" name="origin" value="' . $origin . '">';
  594. print '<input type="hidden" name="originid" value="' . $originid . '">';
  595. print '<table class="border" width="100%">';
  596. // Reference
  597. print '<tr><td class="fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . ($action == 'edit' ? $object->ref : $langs->trans("Draft")) . '</td></tr>';
  598. // Reference client
  599. print '<tr><td>' . $langs->trans('RefCustomer') . '</td><td colspan="2">';
  600. print '<input type="text" name="ref_client" value="' . $ref_client . '"></td>';
  601. print '</tr>';
  602. // Client
  603. print '<tr><td class="fieldrequired">' . $langs->trans('Customer') . '</td><td colspan="2">' . $form->select_company($socid, "socid") . '</td></tr>';
  604. // Contact de la commande
  605. // print "<tr><td>".$langs->trans("DefaultContact").'</td><td colspan="2">';
  606. // $form->select_contacts($soc->id,$setcontact,'contactidp',1,$srccontactslist);
  607. // print '</td></tr>';
  608. // Date
  609. print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td colspan="2">';
  610. $form->select_date($object->date, 're', '', '', '', "crea_commande", 1, 1);
  611. print '</td></tr>';
  612. // Date de livraison
  613. print "<tr><td>" . $langs->trans("DeliveryDate") . '</td><td colspan="2">';
  614. if ($action == 'edit') {
  615. $datedelivery = $object->date_livraison;
  616. } else if (!empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
  617. $datedelivery = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
  618. } else {
  619. $datedelivery = empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0;
  620. }
  621. $form->select_date($datedelivery, 'liv_', '', '', '', "crea_commande", 1, 1);
  622. print "</td></tr>";
  623. // Conditions de reglement
  624. print '<tr><td nowrap="nowrap">' . $langs->trans('PaymentConditionsShort') . '</td><td colspan="2">';
  625. print $object->select_fk_extrafields('cond_reglement_code', 'cond_reglement_code', $cond_reglement_code);
  626. print '</td></tr>';
  627. // Delivery delay
  628. print '<tr><td>' . $langs->trans('AvailabilityPeriod') . '</td><td colspan="2">';
  629. print $object->select_fk_extrafields('availability_code', 'availability_code', $availability_code);
  630. print '</td></tr>';
  631. // Mode de reglement
  632. print '<tr><td nowrap="nowrap">' . $langs->trans('PaymentMode') . '</td><td colspan="2">';
  633. print $object->select_fk_extrafields('mode_reglement_code', 'mode_reglement_code', $mode_reglement_code);
  634. print '</td></tr>';
  635. // What trigger creation
  636. print '<tr><td>' . $langs->trans('Source') . '</td><td colspan="2">';
  637. print $object->select_fk_extrafields('demand_reason_code', 'demand_reason_code', $demand_reason_code);
  638. print '</td></tr>';
  639. // Project
  640. if (!empty($conf->projet->enabled)) {
  641. $projectid = 0;
  642. if ($origin == 'project')
  643. $projectid = ($originid ? $originid : 0);
  644. print '<tr><td>' . $langs->trans('Project') . '</td><td colspan="2">';
  645. $numprojet = select_projects($soc->id, $projectid);
  646. if ($numprojet == 0) {
  647. print ' &nbsp; <a href="' . DOL_URL_ROOT . '/projet/fiche.php?socid=' . $soc->id . '&action=create">' . $langs->trans("AddProject") . '</a>';
  648. }
  649. print '</td></tr>';
  650. }
  651. // Other attributes
  652. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
  653. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  654. if (empty($reshook) && !empty($extrafields->attribute_label)) {
  655. foreach ($extrafields->attribute_label as $key => $label) {
  656. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);
  657. print "<tr><td>" . $label . '</td><td colspan="3">';
  658. print $extrafields->showInputField($key, $value);
  659. print '</td></tr>' . "\n";
  660. }
  661. }
  662. // Template to use by default
  663. print '<tr><td>' . $langs->trans('Model') . '</td>';
  664. print '<td colspan="2">';
  665. include_once DOL_DOCUMENT_ROOT . '/commande/core/modules/commande/modules_commande.php';
  666. $liste = ModelePDFCommandes::liste_modeles($db);
  667. print $form->selectarray('model', $liste, $conf->global->COMMANDE_ADDON_PDF);
  668. print "</td></tr>";
  669. // Note publique
  670. print '<tr>';
  671. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  672. print '<td valign="top" colspan="2">';
  673. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  674. print $doleditor->Create(1);
  675. print '</td></tr>';
  676. // Note privee
  677. if (!$user->societe_id) {
  678. print '<tr>';
  679. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  680. print '<td valign="top" colspan="2">';
  681. $doleditor = new DolEditor('note', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  682. print $doleditor->Create(1);
  683. print '</td></tr>';
  684. }
  685. if (is_object($objectsrc)) {
  686. // TODO for compatibility
  687. if ($_GET['origin'] == 'contrat') {
  688. // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
  689. $objectsrc->remise_absolue = $remise_absolue;
  690. $objectsrc->remise_percent = $remise_percent;
  691. $objectsrc->update_price(1);
  692. }
  693. print "\n<!-- " . $classname . " info -->";
  694. print "\n";
  695. print '<input type="hidden" name="amount" value="' . $objectsrc->total_ht . '">' . "\n";
  696. print '<input type="hidden" name="total" value="' . $objectsrc->total_ttc . '">' . "\n";
  697. print '<input type="hidden" name="tva" value="' . $objectsrc->total_tva . '">' . "\n";
  698. print '<input type="hidden" name="origin" value="' . $objectsrc->element . '">';
  699. print '<input type="hidden" name="originid" value="' . $objectsrc->id . '">';
  700. $newclassname = $classname;
  701. if ($newclassname == 'Propal')
  702. $newclassname = 'CommercialProposal';
  703. print '<tr><td>' . $langs->trans($newclassname) . '</td><td colspan="2">' . $objectsrc->getNomUrl(1) . '</td></tr>';
  704. print '<tr><td>' . $langs->trans('TotalHT') . '</td><td colspan="2">' . price($objectsrc->total_ht) . '</td></tr>';
  705. print '<tr><td>' . $langs->trans('TotalVAT') . '</td><td colspan="2">' . price($objectsrc->total_tva) . "</td></tr>";
  706. if ($mysoc->country_code == 'ES') {
  707. if ($mysoc->localtax1_assuj == "1") { //Localtax1 RE
  708. print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td colspan="2">' . price($objectsrc->total_localtax1) . "</td></tr>";
  709. }
  710. if ($mysoc->localtax2_assuj == "1") { //Localtax2 IRPF
  711. print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td colspan="2">' . price($objectsrc->total_localtax2) . "</td></tr>";
  712. }
  713. }
  714. print '<tr><td>' . $langs->trans('TotalTTC') . '</td><td colspan="2">' . price($objectsrc->total_ttc) . "</td></tr>";
  715. }
  716. print '</table>';
  717. // Button "Create Draft"
  718. print '<br><center><input type="submit" class="button" name="bouton" value="' . ($action == 'edit' ? $langs->trans('Modify') : $langs->trans('CreateDraft')) . '"></center>';
  719. print '</form>';
  720. print column_end();
  721. } else {
  722. print '<br>';
  723. /* Default View */
  724. print column_start("six");
  725. //print '<fieldset class="fieldset">';
  726. dol_fiche_head();
  727. print '<table class="table responsive-table">';
  728. // Ref
  729. print '<tr><td width="30%">' . $langs->trans('Ref') . '</td>';
  730. print '<td colspan="3">';
  731. print $object->ref;
  732. print '</td>';
  733. print '</tr>';
  734. // Societe
  735. print '<tr><td>' . $langs->trans('Company') . '</td>';
  736. print '<td colspan="3">' . $soc->getNomUrl(1) . '</td>';
  737. print '</tr>';
  738. // Ref commande client
  739. // print '<tr><td>' . $langs->trans('RefCustomer') . '</td>';
  740. // print '<td colspan="3">' . $object->ref_client . '</td>';
  741. // print '</tr>';
  742. print '<tr><td>' . $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "text") . '</td>';
  743. print '<td td colspan="5">';
  744. print $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "text");
  745. print '</td>';
  746. print '</tr>';
  747. // Date
  748. // print '<tr><td>' . $langs->trans('Date') . '</td>';
  749. // print '<td colspan="3">' . ($object->date ? dol_print_date($object->date, 'daytext') : '&nbsp;') . '</td>';
  750. // print '</tr>';
  751. print '<tr><td>' . $form->editfieldkey("Date", 'date', $object->date, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "datepicker") . '</td>';
  752. print '<td td colspan="5">';
  753. print $form->editfieldval("Date", 'date', $object->date, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "datepicker");
  754. print '</td>';
  755. print '</tr>';
  756. // Delivery date planed
  757. // print '<tr><td>' . $langs->trans('DateDeliveryPlanned') . '</td>';
  758. // print '<td colspan="3">' . ($object->date_livraison ? dol_print_date($object->date_livraison, 'daytext') : '&nbsp;') . '</td>';
  759. // print '</tr>';
  760. print '<tr><td>' . $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', $object->date_livraison, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "datepicker") . '</td>';
  761. print '<td td colspan="5">';
  762. print $form->editfieldval("DateDeliveryPlanned", 'date_livraison', $object->date_livraison, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "datepicker");
  763. print '</td>';
  764. print '</tr>';
  765. // Terms of payment
  766. // print '<tr><td>' . $langs->trans('PaymentConditionsShort') . '</td>';
  767. // print '<td colspan="3">' . $object->getExtraFieldLabel('cond_reglement_code') . '</td>';
  768. // print '</tr>';
  769. print '<tr><td>' . $form->editfieldkey("PaymentConditionsShort", 'cond_reglement_code', $object->cond_reglement_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select") . '</td>';
  770. print '<td td colspan="5">';
  771. print $form->editfieldval("PaymentConditionsShort", 'cond_reglement_code', $object->cond_reglement_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select");
  772. print '</td>';
  773. print '</tr>';
  774. // Mode of payment
  775. // print '<tr><td>' . $langs->trans('PaymentMode') . '</td>';
  776. // print '<td colspan="3">' . $object->getExtraFieldLabel('mode_reglement_code') . '</td>';
  777. // print '</tr>';
  778. print '<tr><td>' . $form->editfieldkey("PaymentMode", 'mode_reglement_code', $object->mode_reglement_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select") . '</td>';
  779. print '<td td colspan="5">';
  780. print $form->editfieldval("PaymentMode", 'mode_reglement_code', $object->mode_reglement_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select");
  781. print '</td>';
  782. print '</tr>';
  783. // Availability
  784. // print '<tr><td>' . $langs->trans('AvailabilityPeriod') . '</td>';
  785. // print '<td colspan="3">' . $object->getExtraFieldLabel('availability_code') . '</td>';
  786. // print '</tr>';
  787. print '<tr><td>' . $form->editfieldkey("AvailabilityPeriod", 'availability_code', $object->availability_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select") . '</td>';
  788. print '<td td colspan="5">';
  789. print $form->editfieldval("AvailabilityPeriod", 'availability_code', $object->availability_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select");
  790. print '</td>';
  791. print '</tr>';
  792. // Source
  793. // print '<tr><td>' . $langs->trans('Source') . '</td>';
  794. // print '<td colspan="3">' . $object->getExtraFieldLabel('demand_reason_code') . '</td>';
  795. // print '</tr>';
  796. print '<tr><td>' . $form->editfieldkey("Source", 'demand_reason_code', $object->demand_reason_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select") . '</td>';
  797. print '<td td colspan="5">';
  798. print $form->editfieldval("Source", 'demand_reason_code', $object->demand_reason_code, $object, $user->rights->commande->creer && $object->Status == "DRAFT", "select");
  799. print '</td>';
  800. print '</tr>';
  801. // Margin Infos
  802. if (!empty($conf->margin->enabled)) {
  803. print '<td valign="top" width="50%" rowspan="4">';
  804. $object->displayMarginInfos();
  805. print '</td>';
  806. }
  807. print '</tr>';
  808. // Statut
  809. // print '<tr><td>' . $langs->trans('Status') . '</td>';
  810. // print '<td colspan="2">' . $object->getExtraFieldLabel('Status') . '</td>';
  811. // print '</tr>';
  812. $status = $object->Status;
  813. print '<tr><td>' . $form->editfieldkey("Status", 'Status', $object->Status, $object, $user->rights->commande->creer && !$object->fk_extrafields->fields->Status->values->$status->notEditable, "select") . '</td>';
  814. print '<td td colspan="5">';
  815. print $form->editfieldval("Status", 'Status', $object->Status, $object, $user->rights->commande->creer && !$object->fk_extrafields->fields->Status->values->$status->notEditable, "select");
  816. print '</td>';
  817. print '</tr>';
  818. print '</table>';
  819. /*
  820. * Boutons actions
  821. */
  822. if ($action != 'presend') {
  823. if ($user->societe_id == 0 && $action <> 'editline') {
  824. print '<div class="tabsAction">';
  825. print '<div class="button-height">';
  826. print '<span class="button-group">';
  827. if ($user->rights->commande->creer) {
  828. print '<a class="button icon-pencil" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=edit">' . $langs->trans("Modify") . '</a>' . "\n";
  829. }
  830. // Ship
  831. $numshipping = 0;
  832. if (!empty($conf->expedition->enabled)) {
  833. $numshipping = $object->nb_expedition();
  834. if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) {
  835. if (($conf->expedition_bon->enabled && $user->rights->expedition->creer) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) {
  836. if ($user->rights->expedition->creer) {
  837. print '<a class="butAction" href="' . DOL_URL_ROOT . '/expedition/shipment.php?id=' . $object->id . '">' . $langs->trans('ShipProduct') . '</a>';
  838. } else {
  839. print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('ShipProduct') . '</a>';
  840. }
  841. } else {
  842. $langs->load("errors");
  843. print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("ErrorModuleSetupNotComplete")) . '">' . $langs->trans('ShipProduct') . '</a>';
  844. }
  845. }
  846. }
  847. // Validate
  848. if (($object->Status == "DRAFT" || $object->Status == "AUTO") && $user->rights->commande->valider) {
  849. print '<a class="button icon-tick" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=validate">' . $langs->trans('Validate') . '</a>';
  850. }
  851. // Clone
  852. // if ($user->rights->commande->creer) {
  853. // print '<p class="button-height right">';
  854. // print '<a class="button icon-pages" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=clone">' . $langs->trans("ToClone") . '</a>';
  855. // print "</p>";
  856. // }
  857. // Classify billed
  858. if ($object->Status == "TO_BILL" && $user->rights->commande->cloturer) {
  859. print '<a class="button icon-tick" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans('ClassifyBilled') . '</a>';
  860. }
  861. // Create bill and Classify billed
  862. if (!empty($conf->facture->enabled) && $object->Status == "TO_BILL") {
  863. if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
  864. print '<a class="button icon-folder" href="' . DOL_URL_ROOT . '/facture/fiche.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->client->id . '">' . $langs->trans("CreateBill") . '</a>';
  865. }
  866. if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT)) {
  867. print '<a class="button icon-drawer" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans("ClassifyBilled") . '</a>';
  868. }
  869. }
  870. // Send
  871. if ($object->Status != "DRAFT" && $object->Status != "CANCELED") {
  872. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) {
  873. print '<a class="button icon-mail" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=presend&amp;mode=init">' . $langs->trans('SendByMail') . '</a>';
  874. } else {
  875. print '<a class="button icon-mail" href="#">' . $langs->trans('SendByMail') . '</a>';
  876. }
  877. }
  878. // Delete order
  879. if ($user->rights->commande->supprimer) {
  880. if ($numshipping == 0) {
  881. print '<a class="button icon-trash red-gradient" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete">' . $langs->trans("Delete") . '</a>';
  882. } else {
  883. print '<a class="butActionRefused" href="#" title="' . $langs->trans("ShippingExist") . '">' . $langs->trans("Delete") . '</a>';
  884. }
  885. }
  886. print "</span>";
  887. print "</div>";
  888. print '</div>';
  889. }
  890. }
  891. dol_fiche_end();
  892. print column_end();
  893. // Print Addresses
  894. print column_start("six");
  895. print $object->showAddresses();
  896. print column_end();
  897. // Print Notes
  898. print column_start("six");
  899. print $object->show_notes();
  900. print column_end();
  901. // Print Total
  902. print column_start("six", "new-row");
  903. print $object->showAmounts();
  904. print column_end();
  905. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  906. $blocname = 'contacts';
  907. $title = $langs->trans('ContactsAddresses');
  908. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  909. }
  910. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  911. $blocname = 'notes';
  912. $title = $langs->trans('Notes');
  913. include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php';
  914. }
  915. /*
  916. * Documents generes
  917. *
  918. */
  919. $comref = dol_sanitizeFileName($object->ref);
  920. $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
  921. $relativepath = $comref . '/' . $comref . '.pdf';
  922. $filedir = $conf->commande->dir_output . '/' . $comref;
  923. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  924. $genallowed = $user->rights->commande->creer;
  925. $delallowed = $user->rights->commande->supprimer;
  926. print column_start("six");
  927. $somethingshown = $formfile->show_documents('commande', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  928. print column_end();
  929. // Lines
  930. print column_start();
  931. $object->showLines();
  932. print column_end();
  933. // print start_box($langs->trans('OrderLines'), "twelve", $object->fk_extrafields->ico, false);
  934. // print '<table id="tablelines" class="noborder" width="100%">';
  935. //
  936. // $nbLines = count($object->lines);
  937. //
  938. // // Show object lines
  939. // if (!empty($object->lines))
  940. // $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
  941. //
  942. // // Form to add new line
  943. //
  944. // if ($object->Status == "DRAFT" && $user->rights->commande->creer) {
  945. // if ($action != 'editline') {
  946. // $var = true;
  947. //
  948. // if ($conf->global->MAIN_FEATURES_LEVEL > 1) {
  949. // // Add free or predefined products/services
  950. // $object->formAddObjectLine(1, $mysoc, $soc);
  951. // } else {
  952. // // Add free products/services
  953. // $object->formAddFreeProduct(1, $mysoc, $soc);
  954. //
  955. // // Add predefined products/services
  956. // if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  957. // $var = !$var;
  958. // $object->formAddPredefinedProduct(1, $mysoc, $soc);
  959. // }
  960. // }
  961. //
  962. // $parameters = array();
  963. // $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  964. // }
  965. // }
  966. // print '</table>';
  967. // print end_box();
  968. //
  969. if ($action != 'presend') {
  970. /*
  971. * Linked object block
  972. */
  973. //$somethingshown = $object->showLinkedObjectBlock();
  974. // $object->printLinkedObjects();
  975. print column_start("six");
  976. $object->showLinkedObjects();
  977. print column_end();
  978. // Print History
  979. print column_start("six");
  980. print $object->show_history();
  981. print column_end();
  982. // print '</td><td valign="top" width="50%">';
  983. // List of actions on element
  984. // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  985. // $formactions=new FormActions($db);
  986. // $somethingshown=$formactions->showactions($object,'order',$socid);
  987. // print '</td></tr></table>';
  988. }
  989. /*
  990. * Action presend
  991. *
  992. */
  993. if ($action == 'presend') {
  994. $ref = dol_sanitizeFileName($object->ref);
  995. include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
  996. $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref);
  997. $file = $fileparams['fullname'];
  998. // Build document if it not exists
  999. if (!$file || !is_readable($file)) {
  1000. // Define output language
  1001. $outputlangs = $langs;
  1002. $newlang = '';
  1003. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  1004. $newlang = $_REQUEST['lang_id'];
  1005. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1006. $newlang = $object->client->default_lang;
  1007. if (!empty($newlang)) {
  1008. $outputlangs = new Translate();
  1009. $outputlangs->setDefaultLang($newlang);
  1010. }
  1011. $result = commande_pdf_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1012. if ($result <= 0) {
  1013. dol_print_error($db, $result);
  1014. exit;
  1015. }
  1016. $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref);
  1017. $file = $fileparams['fullname'];
  1018. }
  1019. print '<br>';
  1020. print_titre($langs->trans('SendOrderByMail'));
  1021. // Cree l'objet formulaire mail
  1022. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  1023. $formmail = new FormMail($db);
  1024. $formmail->fromtype = 'user';
  1025. $formmail->fromid = $user->id;
  1026. $formmail->fromname = $user->getFullName($langs);
  1027. $formmail->frommail = $user->email;
  1028. $formmail->withfrom = 1;
  1029. $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : 1;
  1030. $formmail->withtosocid = $soc->id;
  1031. $formmail->withtocc = 1;
  1032. $formmail->withtoccsocid = 0;
  1033. $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
  1034. $formmail->withtocccsocid = 0;
  1035. $formmail->withtopic = $langs->trans('SendOrderRef', '__ORDERREF__');
  1036. $formmail->withfile = 2;
  1037. $formmail->withbody = 1;
  1038. $formmail->withdeliveryreceipt = 1;
  1039. $formmail->withcancel = 1;
  1040. // Tableau des substitutions
  1041. $formmail->substit['__ORDERREF__'] = $object->ref;
  1042. $formmail->substit['__SIGNATURE__'] = $user->signature;
  1043. $formmail->substit['__PERSONALIZED__'] = '';
  1044. // Tableau des parametres complementaires
  1045. $formmail->param['action'] = 'send';
  1046. $formmail->param['models'] = 'order_send';
  1047. $formmail->param['orderid'] = $object->id;
  1048. $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
  1049. // Init list of files
  1050. if (GETPOST("mode") == 'init') {
  1051. $formmail->clear_attached_files();
  1052. $formmail->add_attached_files($file, basename($file), dol_mimetype($file));
  1053. }
  1054. // Show form
  1055. $formmail->show_form();
  1056. print '<br>';
  1057. }
  1058. }
  1059. print '</div>';
  1060. print '</div>';
  1061. llxFooter();
  1062. ?>