PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/propal/propal.new.php

https://bitbucket.org/speedealing/speedealing
PHP | 1249 lines | 896 code | 187 blank | 166 comment | 359 complexity | dc28fb182a5c76441d715f6050c1c7dc MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  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. /**
  27. * \file htdocs/comm/propal.php
  28. * \ingroup propale
  29. * \brief Page of commercial proposals card and list
  30. */
  31. /* Includes ***************************************************************** */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formpropal.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/propal/class/propal.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/propal/core/modules/propale/modules_propale.php';
  38. require_once DOL_DOCUMENT_ROOT . '/propal/lib/propal.lib.php';
  39. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  40. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  41. if (!empty($conf->projet->enabled))
  42. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  43. /* Loading langs ************************************************************ */
  44. $langs->load('companies');
  45. $langs->load('propal');
  46. $langs->load('compta');
  47. $langs->load('bills');
  48. $langs->load('orders');
  49. $langs->load('products');
  50. if (!empty($conf->margin->enabled))
  51. $langs->load('margins');
  52. /* Post params ************************************************************** */
  53. $id = GETPOST('id', 'alpha');
  54. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  55. $confirm = GETPOST('confirm');
  56. $lineid = GETPOST('lineid', 'alpha');
  57. $origin = GETPOST('origin', 'alpha');
  58. $originid = (GETPOST('originid', 'alpha') ? GETPOST('originid', 'alpha') : GETPOST('origin_id', 'alpha')); // For backward compatibility
  59. //PDF
  60. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  61. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  62. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  63. $title = $langs->trans('Proposal');
  64. $object = new Propal($db);
  65. $soc = new Societe($db);
  66. if (!empty($id)) {
  67. $object->fetch($id);
  68. $soc->fetch($object->socid);
  69. $object->getLinesArray();
  70. }
  71. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  72. $hookmanager->initHooks(array('ordercard'));
  73. /* Actions ****************************************************************** */
  74. if ($action == 'add' && $user->rights->propal->creer) {
  75. // $object->socid=$socid;
  76. // $object->fetch_thirdparty();
  77. $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  78. $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  79. $duration = GETPOST('duree_validite');
  80. if (empty($datep)) {
  81. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
  82. header("Location: " . DOL_URL_ROOT . '/comm/addpropal.php?socid=' . $socid . '&action=create');
  83. exit;
  84. }
  85. if (empty($duration)) {
  86. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
  87. header("Location: " . DOL_URL_ROOT . '/comm/addpropal.php?socid=' . $socid . '&action=create');
  88. exit;
  89. }
  90. $object->datec = $datep;
  91. $object->date_livraison = $date_delivery;
  92. if (!$error) {
  93. // Si on a selectionne une propal a copier, on realise la copie
  94. if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal')) {
  95. if ($object->fetch(GETPOST('copie_propal')) > 0) {
  96. $object->ref = GETPOST('ref');
  97. $object->datep = $datep;
  98. $object->date_livraison = $date_delivery;
  99. $object->availability_id = GETPOST('availability_id');
  100. $object->demand_reason_id = GETPOST('demand_reason_id');
  101. $object->fk_delivery_address = GETPOST('fk_address');
  102. $object->duree_validite = $duration;
  103. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  104. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  105. $object->remise_percent = GETPOST('remise_percent');
  106. $object->remise_absolue = GETPOST('remise_absolue');
  107. $object->socid = GETPOST('socid');
  108. $object->contactid = GETPOST('contactidp');
  109. $object->fk_project = GETPOST('projectid');
  110. $object->modelpdf = GETPOST('model');
  111. $object->author = $user->id; // deprecated
  112. $object->note = GETPOST('note');
  113. $object->statut = 0;
  114. $id = $object->create_from($user);
  115. } else {
  116. setEventMessage($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), 'errors');
  117. }
  118. } else {
  119. $object->socid = GETPOST('socid');
  120. $object->ref_client = GETPOST('ref_client');
  121. $object->datep = $datep;
  122. $object->date_livraison = $date_delivery;
  123. $object->availability_code = GETPOST('availability_code');
  124. $object->demand_reason_code = GETPOST('demand_reason_code');
  125. $object->fk_delivery_address = GETPOST('fk_address');
  126. $object->duree_validite = GETPOST('duree_validite');
  127. $object->cond_reglement_code = GETPOST('cond_reglement_code');
  128. $object->mode_reglement_code = GETPOST('mode_reglement_code');
  129. $object->contactid = GETPOST('contactidp');
  130. $object->fk_project = GETPOST('projectid');
  131. $object->modelpdf = GETPOST('model');
  132. $object->author = $user->id; // deprecated
  133. $object->note = GETPOST('note');
  134. $object->note_public = GETPOST('note_public');
  135. $object->origin = GETPOST('origin');
  136. $object->origin_id = GETPOST('originid');
  137. for ($i = 1; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) {
  138. if ($_POST['idprod' . $i]) {
  139. $xid = 'idprod' . $i;
  140. $xqty = 'qty' . $i;
  141. $xremise = 'remise' . $i;
  142. $object->add_product($_POST[$xid], $_POST[$xqty], $_POST[$xremise]);
  143. }
  144. }
  145. $id = $object->create($user);
  146. }
  147. if (!empty($id)) {
  148. // Insertion contact par defaut si defini
  149. if (GETPOST('contactidp')) {
  150. $result = $object->add_contact(GETPOST('contactidp'), 'CUSTOMER', 'external');
  151. if ($result < 0) {
  152. $error++;
  153. setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
  154. }
  155. }
  156. if (!$error) {
  157. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  158. // Define output language
  159. $outputlangs = $langs;
  160. if (!empty($conf->global->MAIN_MULTILANGS)) {
  161. $outputlangs = new Translate();
  162. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  163. $outputlangs->setDefaultLang($newlang);
  164. }
  165. $ret = $object->fetch($id); // Reload to get new records
  166. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  167. }
  168. header('Location: propal.php?id=' . $id);
  169. exit;
  170. }
  171. } else {
  172. dol_print_error($db, $object->error);
  173. exit;
  174. }
  175. }
  176. }
  177. else if ($action == 'update' && $user->rights->propal->creer) {
  178. $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  179. $date_delivery = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  180. $duration = GETPOST('duree_validite');
  181. if (empty($datep)) {
  182. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), 'errors');
  183. header("Location: " . DOL_URL_ROOT . '/comm/addpropal.php?socid=' . $socid . '&action=create');
  184. exit;
  185. }
  186. if (empty($duration)) {
  187. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
  188. header("Location: " . DOL_URL_ROOT . '/comm/addpropal.php?socid=' . $socid . '&action=create');
  189. exit;
  190. }
  191. $object->datec = $datep;
  192. $object->date_livraison = $date_delivery;
  193. if (!$error) {
  194. $object->socid = GETPOST('socid');
  195. $object->ref_client = GETPOST('ref_client');
  196. $object->datep = $datep;
  197. $object->date_livraison = $date_delivery;
  198. $object->availability_code = GETPOST('availability_code');
  199. $object->demand_reason_code = GETPOST('demand_reason_code');
  200. $object->fk_delivery_address = GETPOST('fk_address');
  201. $object->duree_validite = GETPOST('duree_validite');
  202. $object->cond_reglement_code = GETPOST('cond_reglement_code');
  203. $object->mode_reglement_code = GETPOST('mode_reglement_code');
  204. $object->contactid = GETPOST('contactidp');
  205. $object->fk_project = GETPOST('projectid');
  206. $object->modelpdf = GETPOST('model');
  207. $object->author = $user->id; // deprecated
  208. $object->note = GETPOST('note');
  209. $object->note_public = GETPOST('note_public');
  210. $object->origin = GETPOST('origin');
  211. $object->origin_id = GETPOST('originid');
  212. $result = $object->update();
  213. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  214. // Define output language
  215. $outputlangs = $langs;
  216. if (!empty($conf->global->MAIN_MULTILANGS)) {
  217. $outputlangs = new Translate();
  218. $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->client->default_lang);
  219. $outputlangs->setDefaultLang($newlang);
  220. }
  221. $ret = $object->fetch($id); // Reload to get new records
  222. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  223. }
  224. header('Location: propal.php?id=' . $id);
  225. exit;
  226. }
  227. } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) {
  228. $result = $object->delete($user);
  229. if ($result > 0) {
  230. header('Location: index.php');
  231. exit;
  232. } else {
  233. $mesg = '<div class="error">' . $object->error . '</div>';
  234. }
  235. } else if ($action == 'addline' && $user->rights->propal->creer) {
  236. $langs->load('errors');
  237. $error = false;
  238. $idprod = GETPOST('idprod', 'int');
  239. $product_desc = (GETPOST('product_desc') ? GETPOST('product_desc') : (GETPOST('np_desc') ? GETPOST('np_desc') : (GETPOST('dp_desc') ? GETPOST('dp_desc') : '')));
  240. $price_ht = GETPOST('price_ht');
  241. $tva_tx = GETPOST('tva_tx');
  242. if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0)) {
  243. setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
  244. $error = true;
  245. }
  246. if (empty($idprod) && GETPOST('type') < 0) {
  247. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
  248. $error = true;
  249. }
  250. if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht >= 0) || $price_ht == '')) { // Unit price can be 0 but not ''
  251. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
  252. $error++;
  253. }
  254. if (!GETPOST('qty') && GETPOST('qty') == '') {
  255. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
  256. $error = true;
  257. }
  258. if (empty($idprod) && empty($product_desc)) {
  259. setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
  260. $error = true;
  261. }
  262. if (!$error && (GETPOST('qty') >= 0) && (!empty($product_desc) || !empty($idprod))) {
  263. // Clean parameters
  264. $predef = ((!empty($idprod) && $conf->global->MAIN_FEATURES_LEVEL < 2) ? '_predef' : '');
  265. $date_start = dol_mktime(0, 0, 0, GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
  266. $date_end = dol_mktime(0, 0, 0, GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
  267. $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
  268. // Ecrase $pu par celui du produit
  269. // Ecrase $desc par celui du produit
  270. // Ecrase $txtva par celui du produit
  271. // Ecrase $base_price_type par celui du produit
  272. if (!empty($idprod)) {
  273. $prod = new Product($db);
  274. $prod->fetch($idprod);
  275. $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
  276. // Update if prices fields are defined
  277. if (GETPOST('usenewaddlineform')) {
  278. $pu_ht = price2num($price_ht, 'MU');
  279. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  280. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  281. $tva_tx = str_replace('*', '', $tva_tx);
  282. $desc = $product_desc;
  283. } else {
  284. $tva_tx = get_default_tva($mysoc, $object->client, $prod->id);
  285. $tva_npr = get_default_npr($mysoc, $object->client, $prod->id);
  286. // multiprix
  287. if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->client->price_level)) {
  288. $pu_ht = $prod->multiprices[$object->client->price_level];
  289. $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
  290. $price_min = $prod->multiprices_min[$object->client->price_level];
  291. $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
  292. } else {
  293. $pu_ht = $prod->price;
  294. $pu_ttc = $prod->price_ttc;
  295. $price_min = $prod->price_min;
  296. $price_base_type = $prod->price_base_type;
  297. }
  298. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  299. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  300. if ($tva_tx != $prod->tva_tx) {
  301. if ($price_base_type != 'HT') {
  302. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU');
  303. } else {
  304. $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
  305. }
  306. }
  307. $desc = '';
  308. // Define output language
  309. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  310. $outputlangs = $langs;
  311. $newlang = '';
  312. if (empty($newlang) && GETPOST('lang_id'))
  313. $newlang = GETPOST('lang_id');
  314. if (empty($newlang))
  315. $newlang = $object->client->default_lang;
  316. if (!empty($newlang)) {
  317. $outputlangs = new Translate();
  318. $outputlangs->setDefaultLang($newlang);
  319. }
  320. $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
  321. } else {
  322. $desc = $prod->description;
  323. }
  324. $desc = dol_concatdesc($desc, $product_desc);
  325. }
  326. $type = $prod->type;
  327. } else {
  328. $pu_ht = price2num($price_ht, 'MU');
  329. $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
  330. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  331. $tva_tx = str_replace('*', '', $tva_tx);
  332. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  333. $desc = $product_desc;
  334. $type = GETPOST('type');
  335. }
  336. // Margin
  337. $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
  338. $buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
  339. // Local Taxes
  340. $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
  341. $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
  342. $desc = dol_htmlcleanlastbr($desc);
  343. $info_bits = 0;
  344. if ($tva_npr)
  345. $info_bits |= 0x01;
  346. if (!empty($price_min) && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
  347. $mesg = $langs->trans("CantBeLessThanMinPrice", price2num($price_min, 'MU') . $langs->getCurrencySymbol($conf->currency));
  348. setEventMessage($mesg, 'errors');
  349. } else {
  350. // Insert line
  351. $result = $object->addline(
  352. $object->id, $desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, GETPOST('remise_percent'), $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, -1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label
  353. );
  354. if ($result > 0) {
  355. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  356. // Define output language
  357. $outputlangs = $langs;
  358. $newlang = GETPOST('lang_id', 'alpha');
  359. if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
  360. $newlang = $object->client->default_lang;
  361. if (!empty($newlang)) {
  362. $outputlangs = new Translate();
  363. $outputlangs->setDefaultLang($newlang);
  364. }
  365. $ret = $object->fetch($object->id); // Reload to get new records
  366. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  367. }
  368. unset($_POST['qty']);
  369. unset($_POST['type']);
  370. unset($_POST['idprod']);
  371. unset($_POST['remise_percent']);
  372. unset($_POST['price_ht']);
  373. unset($_POST['price_ttc']);
  374. unset($_POST['tva_tx']);
  375. unset($_POST['product_ref']);
  376. unset($_POST['product_label']);
  377. unset($_POST['product_desc']);
  378. unset($_POST['fournprice']);
  379. unset($_POST['buying_price']);
  380. // old method
  381. unset($_POST['np_desc']);
  382. unset($_POST['dp_desc']);
  383. } else {
  384. setEventMessage($object->error, 'errors');
  385. }
  386. }
  387. }
  388. } else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save') == $langs->trans('Save')) {
  389. // Clean parameters
  390. $date_start = '';
  391. $date_end = '';
  392. $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  393. $date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  394. $description = dol_htmlcleanlastbr(GETPOST('product_desc'));
  395. $pu_ht = GETPOST('price_ht');
  396. // Define info_bits
  397. $info_bits = 0;
  398. if (preg_match('/\*/', GETPOST('tva_tx')))
  399. $info_bits |= 0x01;
  400. // Define vat_rate
  401. $vat_rate = GETPOST('tva_tx');
  402. $vat_rate = str_replace('*', '', $vat_rate);
  403. $localtax1_rate = get_localtax($vat_rate, 1, $object->client);
  404. $localtax2_rate = get_localtax($vat_rate, 2, $object->client);
  405. // Add buying price
  406. $fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
  407. $buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
  408. // Check minimum price
  409. $productid = GETPOST('productid', 'int');
  410. if (!empty($productid)) {
  411. $product = new Product($db);
  412. $product->fetch($productid);
  413. $type = $product->type;
  414. $price_min = $product->price_min;
  415. if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->client->price_level))
  416. $price_min = $product->multiprices_min[$object->client->price_level];
  417. $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
  418. if ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
  419. setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min, 'MU')) . $langs->getCurrencySymbol($conf->currency), 'errors');
  420. $error++;
  421. }
  422. } else {
  423. $type = GETPOST('type');
  424. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  425. // Check parameters
  426. if (GETPOST('type') < 0) {
  427. setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), 'errors');
  428. $error++;
  429. }
  430. }
  431. if (!$error) {
  432. $result = $object->updateline(
  433. $id, GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label
  434. );
  435. if ($result >= 0) {
  436. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  437. // Define output language
  438. $outputlangs = $langs;
  439. $newlang = '';
  440. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
  441. $newlang = GETPOST('lang_id');
  442. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  443. $newlang = $object->client->default_lang;
  444. if (!empty($newlang)) {
  445. $outputlangs = new Translate();
  446. $outputlangs->setDefaultLang($newlang);
  447. }
  448. $ret = $object->fetch($object->id); // Reload to get new records
  449. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  450. }
  451. unset($_POST['qty']);
  452. unset($_POST['type']);
  453. unset($_POST['productid']);
  454. unset($_POST['remise_percent']);
  455. unset($_POST['price_ht']);
  456. unset($_POST['price_ttc']);
  457. unset($_POST['tva_tx']);
  458. unset($_POST['product_ref']);
  459. unset($_POST['product_label']);
  460. unset($_POST['product_desc']);
  461. unset($_POST['fournprice']);
  462. unset($_POST['buying_price']);
  463. } else {
  464. setEventMessage($object->error, 'errors');
  465. }
  466. }
  467. } else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) {
  468. $result = $object->deleteline($lineid);
  469. if ($result > 0) {
  470. // Define output language
  471. $outputlangs = $langs;
  472. $newlang = '';
  473. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
  474. $newlang = GETPOST('lang_id');
  475. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  476. $newlang = $object->client->default_lang;
  477. if (!empty($newlang)) {
  478. $outputlangs = new Translate();
  479. $outputlangs->setDefaultLang($newlang);
  480. }
  481. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  482. $ret = $object->fetch($object->id); // Reload to get new records
  483. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  484. }
  485. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  486. exit;
  487. } else {
  488. $mesg = '<div class="error">' . $object->error . '</div>';
  489. }
  490. } else if ($action == 'builddoc') { // In get or post
  491. /*
  492. * Generate order document
  493. * define into /core/modules/commande/modules_commande.php
  494. */
  495. // Sauvegarde le dernier modele choisi pour generer un document
  496. if ($_REQUEST['model']) {
  497. $object->setDocModel($user, $_REQUEST['model']);
  498. }
  499. // Define output language
  500. $outputlangs = $langs;
  501. $newlang = '';
  502. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  503. $newlang = $_REQUEST['lang_id'];
  504. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  505. $newlang = $object->client->default_lang;
  506. if (!empty($newlang)) {
  507. $outputlangs = new Translate();
  508. $outputlangs->setDefaultLang($newlang);
  509. }
  510. $result = propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  511. if ($result <= 0) {
  512. dol_print_error($db, $result);
  513. exit;
  514. } else {
  515. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
  516. exit;
  517. }
  518. } else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) {
  519. $idwarehouse = GETPOST('idwarehouse');
  520. // Check parameters
  521. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  522. if (!$idwarehouse || $idwarehouse == -1) {
  523. $error++;
  524. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  525. $action = '';
  526. }
  527. }
  528. if (!$error) {
  529. $result = $object->valid($user, $idwarehouse);
  530. if ($result >= 0) {
  531. // Define output language
  532. $outputlangs = $langs;
  533. $newlang = '';
  534. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  535. $newlang = $_REQUEST['lang_id'];
  536. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  537. $newlang = $object->client->default_lang;
  538. if (!empty($newlang)) {
  539. $outputlangs = new Translate();
  540. $outputlangs->setDefaultLang($newlang);
  541. }
  542. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  543. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  544. }
  545. }
  546. }
  547. else if ($action == 'confirm_modif' && $user->rights->propal->creer) {
  548. $idwarehouse = GETPOST('idwarehouse');
  549. // Check parameters
  550. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  551. if (!$idwarehouse || $idwarehouse == -1) {
  552. $error++;
  553. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  554. $action = '';
  555. }
  556. }
  557. if (!$error) {
  558. $result = $object->set_draft($user, $idwarehouse);
  559. if ($result >= 0) {
  560. // Define output language
  561. $outputlangs = $langs;
  562. $newlang = '';
  563. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  564. $newlang = $_REQUEST['lang_id'];
  565. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  566. $newlang = $object->client->default_lang;
  567. if (!empty($newlang)) {
  568. $outputlangs = new Translate();
  569. $outputlangs->setDefaultLang($newlang);
  570. }
  571. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  572. $ret = $object->fetch($object->id); // Reload to get new records
  573. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  574. }
  575. }
  576. }
  577. } else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->propal->valider) {
  578. $idwarehouse = GETPOST('idwarehouse');
  579. // Check parameters
  580. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  581. if (!$idwarehouse || $idwarehouse == -1) {
  582. $error++;
  583. $mesgs[] = '<div class="error">' . $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")) . '</div>';
  584. $action = '';
  585. }
  586. }
  587. if (!$error) {
  588. $result = $object->cancel($idwarehouse);
  589. }
  590. } else if ($action == 'confirm_shipped' && $confirm == 'yes' && $user->rights->propal->cloturer) {
  591. $result = $object->cloture($user);
  592. if ($result < 0)
  593. $mesgs = $object->errors;
  594. }
  595. // Reopen a closed order
  596. else if ($action == 'reopen' && $user->rights->propal->creer) {
  597. if ($object->Status == "TO_BILL" || $object->Status == "PROCESSED") {
  598. $result = $object->set_reopen($user);
  599. if ($result > 0) {
  600. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  601. exit;
  602. } else {
  603. $mesg = '<div class="error">' . $object->error . '</div>';
  604. }
  605. }
  606. } else if ($action == 'classifybilled' && $user->rights->propal->creer) {
  607. $ret = $object->classifyBilled();
  608. }
  609. /* View ********************************************************************* */
  610. $form = new Form($db);
  611. $formfile = new FormFile($db);
  612. $formpropal = new FormPropal($db);
  613. llxHeader('', $title, 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
  614. print_fiche_titre($title);
  615. $formconfirm = null;
  616. if ($action == 'delete') {
  617. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePropal'), $langs->trans('ConfirmDeletePropal'), 'confirm_delete', '', 0, 1);
  618. } else if ($action == 'ask_deleteline') {
  619. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  620. } else if ($action == 'validate') {
  621. // on verifie si l'objet est en numerotation provisoire
  622. $numref = $object->ref;
  623. $text = $langs->trans('ConfirmValidatePropal', $numref);
  624. if (!empty($conf->notification->enabled)) {
  625. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  626. $notify = new Notify($db);
  627. $text.='<br>';
  628. $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL', $object->socid);
  629. }
  630. $formquestion = array();
  631. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  632. $langs->load("stocks");
  633. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  634. $formproduct = new FormProduct($db);
  635. $formquestion = array(
  636. //'text' => $langs->trans("ConfirmClone"),
  637. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  638. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  639. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  640. }
  641. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  642. } else if ($action == 'modify') {
  643. $text = $langs->trans('ConfirmUnvalidateOrder', $object->ref);
  644. $formquestion = array();
  645. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  646. $langs->load("stocks");
  647. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  648. $formproduct = new FormProduct($db);
  649. $formquestion = array(
  650. //'text' => $langs->trans("ConfirmClone"),
  651. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  652. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  653. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  654. }
  655. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
  656. } else if ($action == 'cancel') {
  657. $text = $langs->trans('ConfirmCancelOrder', $object->ref);
  658. $formquestion = array();
  659. if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) {
  660. $langs->load("stocks");
  661. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  662. $formproduct = new FormProduct($db);
  663. $formquestion = array(
  664. //'text' => $langs->trans("ConfirmClone"),
  665. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  666. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  667. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'), 'idwarehouse', '', 1)));
  668. }
  669. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
  670. } else if ($action == 'shipped') {
  671. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
  672. }
  673. print $formconfirm;
  674. print '<div class="with-padding" >';
  675. print '<div class="columns" >';
  676. /* Create View */
  677. if (($action == 'create' || $action == 'edit') && $user->rights->propal->creer) {
  678. print start_box($title, "twelve", $object->fk_extrafields->ico, false);
  679. print '<form name="crea_propal" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  680. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  681. print '<input type="hidden" name="action" value="' . ($action == 'create' ? 'add' : 'update') . '">';
  682. print '<input type="hidden" name="id" value="' . $id . '">';
  683. print '<input type="hidden" name="origin" value="' . $origin . '">';
  684. print '<input type="hidden" name="originid" value="' . $originid . '">';
  685. print '<table class="border" width="100%">';
  686. // Reference
  687. print '<tr><td class="fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . ($action == 'edit' ? $object->ref : $langs->trans("Draft")) . '</td></tr>';
  688. // Reference client
  689. print '<tr><td>' . $langs->trans('RefCustomer') . '</td><td colspan="2">';
  690. print '<input type="text" name="ref_client" value="' . $object->ref_client . '"></td>';
  691. print '</tr>';
  692. // Client
  693. print '<tr><td class="fieldrequired">' . $langs->trans('Customer') . '</td><td colspan="2">' . $form->select_company($object->socid, "socid") . '</td></tr>';
  694. // Contact de la commande
  695. // print "<tr><td>" . $langs->trans("DefaultContact") . '</td><td colspan="2">';
  696. // $form->select_contacts($soc->id, $setcontact, 'contactidp', 1, $srccontactslist);
  697. // print '</td></tr>';
  698. // Date
  699. print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td colspan="2">';
  700. $form->select_date($object->date, 're', '', '', '', "crea_commande", 1, 1);
  701. print '</td></tr>';
  702. // Validaty duration
  703. print '<tr><td class="fieldrequired">' . $langs->trans("ValidityDuration") . '</td><td colspan="2"><input name="duree_validite" size="5" value="' . $conf->global->PROPALE_VALIDITY_DURATION . '"> ' . $langs->trans("days") . '</td></tr>';
  704. // Date de livraison
  705. print "<tr><td>" . $langs->trans("DeliveryDate") . '</td><td colspan="2">';
  706. if ($action == 'edit') {
  707. $datedelivery = $object->date_livraison;
  708. } else if (!empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
  709. $datedelivery = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
  710. } else {
  711. $datedelivery = empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0;
  712. }
  713. $form->select_date($datedelivery, 'liv_', '', '', '', "crea_commande", 1, 1);
  714. print "</td></tr>";
  715. // Conditions de reglement
  716. print '<tr><td nowrap="nowrap">' . $langs->trans('PaymentConditionsShort') . '</td><td colspan="2">';
  717. print $object->select_fk_extrafields('cond_reglement_code', 'cond_reglement_code', $object->cond_reglement_code);
  718. print '</td></tr>';
  719. // Delivery delay
  720. print '<tr><td>' . $langs->trans('AvailabilityPeriod') . '</td><td colspan="2">';
  721. print $object->select_fk_extrafields('availability_code', 'availability_code', $object->availability_code);
  722. print '</td></tr>';
  723. // Mode de reglement
  724. print '<tr><td nowrap="nowrap">' . $langs->trans('PaymentMode') . '</td><td colspan="2">';
  725. print $object->select_fk_extrafields('mode_reglement_code', 'mode_reglement_code', $object->mode_reglement_code);
  726. print '</td></tr>';
  727. // What trigger creation
  728. print '<tr><td>' . $langs->trans('Source') . '</td><td colspan="2">';
  729. print $object->select_fk_extrafields('demand_reason_code', 'demand_reason_code', $object->demand_reason_code);
  730. print '</td></tr>';
  731. // Project
  732. if (!empty($conf->projet->enabled)) {
  733. $projectid = 0;
  734. if ($origin == 'project')
  735. $projectid = ($originid ? $originid : 0);
  736. print '<tr><td>' . $langs->trans('Project') . '</td><td colspan="2">';
  737. $numprojet = select_projects($soc->id, $projectid);
  738. if ($numprojet == 0) {
  739. print ' &nbsp; <a href="' . DOL_URL_ROOT . '/projet/fiche.php?socid=' . $soc->id . '&action=create">' . $langs->trans("AddProject") . '</a>';
  740. }
  741. print '</td></tr>';
  742. }
  743. // Other attributes
  744. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
  745. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  746. if (empty($reshook) && !empty($extrafields->attribute_label)) {
  747. foreach ($extrafields->attribute_label as $key => $label) {
  748. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);
  749. print "<tr><td>" . $label . '</td><td colspan="3">';
  750. print $extrafields->showInputField($key, $value);
  751. print '</td></tr>' . "\n";
  752. }
  753. }
  754. // Template to use by default
  755. print '<tr><td>' . $langs->trans('Model') . '</td>';
  756. print '<td colspan="2">';
  757. include_once DOL_DOCUMENT_ROOT . '/propal/core/modules/propale/modules_propale.php';
  758. $liste = ModelePDFPropales::liste_modeles($db);
  759. print $form->selectarray('model', $liste, $conf->global->COMMANDE_ADDON_PDF);
  760. print "</td></tr>";
  761. // Note publique
  762. print '<tr>';
  763. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  764. print '<td valign="top" colspan="2">';
  765. $doleditor = new DolEditor('note_public', $object->note, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  766. print $doleditor->Create(1);
  767. print '</td></tr>';
  768. // Note privee
  769. if (!$user->societe_id) {
  770. print '<tr>';
  771. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  772. print '<td valign="top" colspan="2">';
  773. $doleditor = new DolEditor('note', $object->note, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  774. print $doleditor->Create(1);
  775. print '</td></tr>';
  776. }
  777. print '</table>';
  778. // Button "Create Draft"
  779. print '<br><center><input type="submit" class="button" name="bouton" value="' . ($action == 'edit' ? $langs->trans('Modify') : $langs->trans('CreateDraft')) . '"></center>';
  780. print '</form>';
  781. print end_box();
  782. }
  783. /* Default View */ else {
  784. /*
  785. * Boutons actions
  786. */
  787. if ($action != 'presend') {
  788. if ($user->societe_id == 0 && $action <> 'editline') {
  789. print '<div class="tabsAction">';
  790. // Ship
  791. $numshipping = 0;
  792. if (!empty($conf->expedition->enabled)) {
  793. $numshipping = $object->nb_expedition();
  794. if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0) {
  795. if (($conf->expedition_bon->enabled && $user->rights->expedition->creer)
  796. || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) {
  797. if ($user->rights->expedition->creer) {
  798. print '<a class="butAction" href="' . DOL_URL_ROOT . '/expedition/shipment.php?id=' . $object->id . '">' . $langs->trans('ShipProduct') . '</a>';
  799. } else {
  800. print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('ShipProduct') . '</a>';
  801. }
  802. } else {
  803. $langs->load("errors");
  804. print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("ErrorModuleSetupNotComplete")) . '">' . $langs->trans('ShipProduct') . '</a>';
  805. }
  806. }
  807. }
  808. // Create bill and Classify billed
  809. if (!empty($conf->facture->enabled) && $object->Status == "TO_BILL") {
  810. if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
  811. print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("CreateBill") . '</a>';
  812. }
  813. if ($user->rights->propal->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT)) {
  814. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans("ClassifyBilled") . '</a>';
  815. }
  816. }
  817. // Delete order
  818. if ($user->rights->propal->supprimer) {
  819. if ($numshipping == 0) {
  820. print '<p class="button-height right">';
  821. print '<a class="button icon-cross" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete">' . $langs->trans("Delete") . '</a>';
  822. print "</p>";
  823. } else {
  824. print '<a class="butActionRefused" href="#" title="' . $langs->trans("ShippingExist") . '">' . $langs->trans("Delete") . '</a>';
  825. }
  826. }
  827. // Cancel order
  828. if ($object->Status == "VALIDATED" && $user->rights->propal->annuler) {
  829. print '<p class="button-height right">';
  830. print '<a class="button icon-lightning" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=cancel">' . $langs->trans('Cancel') . '</a>';
  831. print "</p>";
  832. }
  833. // Clone
  834. if ($user->rights->propal->creer) {
  835. print '<p class="button-height right">';
  836. print '<a class="button icon-pages" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=clone">' . $langs->trans("ToClone") . '</a>';
  837. print "</p>";
  838. }
  839. // Create bill and Classify billed
  840. // if (!empty($conf->facture->enabled) && $object->Status == "TO_BILL") {
  841. // if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
  842. // print '<a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("CreateBill") . '</a>';
  843. // }
  844. // if ($user->rights->propal->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT)) {
  845. // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans("ClassifyBilled") . '</a>';
  846. // }
  847. // }
  848. // Classify billed
  849. if ($object->Status == "TO_BILL" && $user->rights->propal->cloturer) {
  850. print '<p class="button-height right">';
  851. print '<a class="button icon-tick" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans('ClassifyBilled') . '</a>';
  852. print "</p>";
  853. }
  854. // Set to shipped (Close)
  855. if (($object->Status == "VALIDATED" || $object->Status == "IN_PROCESS") && $user->rights->propal->cloturer) {
  856. print '<p class="button-height right">';
  857. print '<a class="button icon-tick" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=shipped">' . $langs->trans('ClassifyShipped') . '</a>';
  858. print "</p>";
  859. }
  860. // Valid
  861. if ($object->Status == "DRAFT" && $object->total_ttc >= 0 && count($object->lines) > 0 && $user->rights->propal->valider) {
  862. print '<p class="button-height right">';
  863. print '<a class="button icon-tick" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=validate">' . $langs->trans('Validate') . '</a>';
  864. print "</p>";
  865. }
  866. // Create bill and Classify billed
  867. if (!empty($conf->facture->enabled) && !in_array($object->Status, array("DRAFT", "CANCELED", "PROCESSED"))) {
  868. if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
  869. print '<p class="button-height right">';
  870. print '<a class="button icon-folder" href="' . DOL_URL_ROOT . '/compta/facture.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("CreateBill") . '</a>';
  871. print "</p>";
  872. }
  873. if ($user->rights->propal->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT)) {
  874. print '<p class="button-height right">';
  875. print '<a class="button icon-drawer" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=classifybilled">' . $langs->trans("ClassifyBilled") . '</a>';
  876. print "</p>";
  877. }
  878. }
  879. // Send
  880. if ($object->Status != "DRAFT" && $object->Status != "CANCELED") {
  881. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->order_advance->send)) {
  882. print '<p class="button-height right">';
  883. print '<a class="button icon-mail" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=presend&amp;mode=init">' . $langs->trans('SendByMail') . '</a>';
  884. print "</p>";
  885. } else {
  886. print '<p class="button-height right">';

Large files files are truncated, but you can click here to view the full file