PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/admin/AdminStockConfigurationController.php

https://bitbucket.org/yhjohn/ayanapure.com
PHP | 575 lines | 465 code | 33 blank | 77 comment | 18 complexity | 9b5593c447703afaf003bd9f583c497b MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * 2007-2012 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2012 PrestaShop SA
  23. * @version Release: $Revision: 17889 $
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. * International Registered Trademark & Property of PrestaShop SA
  26. */
  27. /**
  28. * @since 1.5.0
  29. */
  30. class AdminStockConfigurationControllerCore extends AdminController
  31. {
  32. /*
  33. * By default, we use StockMvtReason as the table / className
  34. */
  35. public function __construct()
  36. {
  37. $this->context = Context::getContext();
  38. $this->table = 'stock_mvt_reason';
  39. $this->className = 'StockMvtReason';
  40. $this->lang = true;
  41. $this->multishop_context = Shop::CONTEXT_ALL;
  42. // defines fields
  43. $this->fields_list = array(
  44. 'id_stock_mvt_reason' => array(
  45. 'title' => $this->l('ID'),
  46. 'align' => 'center',
  47. 'width' => 40,
  48. 'search' => false,
  49. ),
  50. 'sign' => array(
  51. 'title' => $this->l('Sign'),
  52. 'width' => 100,
  53. 'align' => 'center',
  54. 'type' => 'select',
  55. 'filter_key' => 'a!sign',
  56. 'list' => array(
  57. '1' => $this->l('Increase'),
  58. '-1' => $this->l('Decrease'),
  59. ),
  60. 'icon' => array(
  61. -1 => 'remove_stock.png',
  62. 1 => 'add_stock.png'
  63. ),
  64. 'orderby' => false
  65. ),
  66. 'name' => array(
  67. 'title' => $this->l('Name'),
  68. 'filter_key' => 'b!name',
  69. 'width' => 250
  70. ),
  71. );
  72. // loads labels (incremenation)
  73. $reasons_inc = StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id,
  74. array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')), 1);
  75. // loads labaels (decremenation)
  76. $reasons_dec = StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id,
  77. array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')), -1);
  78. // defines options for StockMvt
  79. $this->fields_options = array(
  80. 'general' => array(
  81. 'title' => $this->l('Options'),
  82. 'fields' => array(
  83. 'PS_STOCK_MVT_INC_REASON_DEFAULT' => array(
  84. 'title' => $this->l('Default label when increasing stock:'),
  85. 'cast' => 'intval',
  86. 'type' => 'select',
  87. 'list' => $reasons_inc,
  88. 'identifier' => 'id_stock_mvt_reason',
  89. 'visibility' => Shop::CONTEXT_ALL
  90. ),
  91. 'PS_STOCK_MVT_DEC_REASON_DEFAULT' => array(
  92. 'title' => $this->l('Default label when decreasing stock:'),
  93. 'cast' => 'intval',
  94. 'type' => 'select',
  95. 'list' => $reasons_dec,
  96. 'identifier' => 'id_stock_mvt_reason',
  97. 'visibility' => Shop::CONTEXT_ALL
  98. ),
  99. 'PS_STOCK_CUSTOMER_ORDER_REASON' => array(
  100. 'title' => $this->l('Default label when decreasing stock when a customer order is shipped:'),
  101. 'cast' => 'intval',
  102. 'type' => 'select',
  103. 'list' => $reasons_dec,
  104. 'identifier' => 'id_stock_mvt_reason',
  105. 'visibility' => Shop::CONTEXT_ALL
  106. ),
  107. 'PS_STOCK_MVT_SUPPLY_ORDER' => array(
  108. 'title' => $this->l('Default label when increasing stock when a supply order is received:'),
  109. 'cast' => 'intval',
  110. 'type' => 'select',
  111. 'list' => $reasons_inc,
  112. 'identifier' => 'id_stock_mvt_reason',
  113. 'visibility' => Shop::CONTEXT_ALL
  114. ),
  115. ),
  116. 'submit' => array(),
  117. )
  118. );
  119. parent::__construct();
  120. }
  121. public function init()
  122. {
  123. // if we are managing the second list (i.e. supply order state)
  124. if (Tools::isSubmit('submitAddsupply_order_state') ||
  125. Tools::isSubmit('addsupply_order_state') ||
  126. Tools::isSubmit('updatesupply_order_state') ||
  127. Tools::isSubmit('deletesupply_order_state'))
  128. {
  129. $this->table = 'supply_order_state';
  130. $this->className = 'SupplyOrderState';
  131. $this->identifier = 'id_supply_order_state';
  132. $this->display = 'edit';
  133. }
  134. parent::init();
  135. }
  136. /**
  137. * AdminController::renderForm() override
  138. * @see AdminController::renderForm()
  139. */
  140. public function renderForm()
  141. {
  142. // if we are managing StockMvtReason
  143. if (Tools::isSubmit('addstock_mvt_reason') ||
  144. Tools::isSubmit('updatestock_mvt_reason') ||
  145. Tools::isSubmit('submitAddstock_mvt_reason') ||
  146. Tools::isSubmit('submitUpdatestock_mvt_reason'))
  147. {
  148. $this->toolbar_title = $this->l('Stock: Add stock movement label');
  149. $this->fields_form = array(
  150. 'legend' => array(
  151. 'title' => $this->l('Stock Movement Label'),
  152. 'image' => '../img/admin/edit.gif'
  153. ),
  154. 'input' => array(
  155. array(
  156. 'type' => 'text',
  157. 'lang' => true,
  158. 'label' => $this->l('Name:'),
  159. 'name' => 'name',
  160. 'size' => 50,
  161. 'required' => true
  162. ),
  163. array(
  164. 'type' => 'select',
  165. 'label' => $this->l('Action:'),
  166. 'name' => 'sign',
  167. 'required' => true,
  168. 'options' => array(
  169. 'query' => array(
  170. array(
  171. 'id' => '1',
  172. 'name' => $this->l('Increase stock')
  173. ),
  174. array(
  175. 'id' => '-1',
  176. 'name' => $this->l('Decrease stock')
  177. ),
  178. ),
  179. 'id' => 'id',
  180. 'name' => 'name'
  181. ),
  182. 'desc' => $this->l('Select the corresponding action: increase or decrease stock.')
  183. ),
  184. ),
  185. 'submit' => array(
  186. 'title' => $this->l('Save'),
  187. 'class' => 'button'
  188. )
  189. );
  190. }
  191. // else, if we are managing Supply Order State
  192. else if (Tools::isSubmit('addsupply_order_state') ||
  193. Tools::isSubmit('updatesupply_order_state') ||
  194. Tools::isSubmit('submitAddsupply_order_state') ||
  195. Tools::isSubmit('submitUpdatesupply_order_state'))
  196. {
  197. $this->fields_form = array(
  198. 'legend' => array(
  199. 'title' => $this->l('Supply Order Status'),
  200. 'image' => '../img/admin/edit.gif'
  201. ),
  202. 'input' => array(
  203. array(
  204. 'type' => 'text',
  205. 'lang' => true,
  206. 'label' => $this->l('Status:'),
  207. 'name' => 'name',
  208. 'size' => 50,
  209. 'required' => true
  210. ),
  211. array(
  212. 'type' => 'color',
  213. 'label' => $this->l('Color:'),
  214. 'name' => 'color',
  215. 'size' => 20,
  216. 'desc' => $this->l('Back Office background will be displayed in this color. HTML colors only.'),
  217. ),
  218. array(
  219. 'type' => 'radio',
  220. 'label' => $this->l('Editable:'),
  221. 'name' => 'editable',
  222. 'required' => true,
  223. 'class' => 't',
  224. 'is_bool' => true,
  225. 'values' => array(
  226. array(
  227. 'id' => 'active_on',
  228. 'value' => 1,
  229. 'label' => $this->l('Yes')
  230. ),
  231. array(
  232. 'id' => 'active_off',
  233. 'value' => 0,
  234. 'label' => $this->l('No')
  235. )
  236. ),
  237. 'desc' => $this->l('Define if it is possible to edit the order. An editable order is not valid to send to the supplier.')
  238. ),
  239. array(
  240. 'type' => 'radio',
  241. 'label' => $this->l('Delivery note:'),
  242. 'name' => 'delivery_note',
  243. 'required' => true,
  244. 'class' => 't',
  245. 'is_bool' => true,
  246. 'values' => array(
  247. array(
  248. 'id' => 'active_on',
  249. 'value' => 1,
  250. 'label' => $this->l('Yes')
  251. ),
  252. array(
  253. 'id' => 'active_off',
  254. 'value' => 0,
  255. 'label' => $this->l('No')
  256. )
  257. ),
  258. 'desc' => $this->l('Define if it is possible to generate a delivery note of the order.')
  259. ),
  260. array(
  261. 'type' => 'radio',
  262. 'label' => $this->l('Delivery state:'),
  263. 'name' => 'receipt_state',
  264. 'required' => true,
  265. 'class' => 't',
  266. 'is_bool' => true,
  267. 'values' => array(
  268. array(
  269. 'id' => 'active_on',
  270. 'value' => 1,
  271. 'label' => $this->l('Yes')
  272. ),
  273. array(
  274. 'id' => 'active_off',
  275. 'value' => 0,
  276. 'label' => $this->l('No')
  277. )
  278. ),
  279. 'desc' => $this->l('Define if products have been partially/completely received. This allows you to know if the products ordered have to be added to the corresponding warehouse.'),
  280. ),
  281. array(
  282. 'type' => 'radio',
  283. 'label' => $this->l('Pending receipt:'),
  284. 'name' => 'pending_receipt',
  285. 'required' => true,
  286. 'class' => 't',
  287. 'is_bool' => true,
  288. 'values' => array(
  289. array(
  290. 'id' => 'active_on',
  291. 'value' => 1,
  292. 'label' => $this->l('Yes')
  293. ),
  294. array(
  295. 'id' => 'active_off',
  296. 'value' => 0,
  297. 'label' => $this->l('No')
  298. )
  299. ),
  300. 'desc' => $this->l('Customer is awaiting delivery')
  301. ),
  302. ),
  303. 'submit' => array(
  304. 'title' => $this->l('Save'),
  305. 'class' => 'button'
  306. )
  307. );
  308. if (Tools::isSubmit('addsupply_order_state'))
  309. $this->toolbar_title = $this->l('Stock: Add supply order status');
  310. else
  311. {
  312. $this->toolbar_title = $this->l('Stock: Update Supply order status');
  313. $id_supply_order_state = Tools::getValue('id_supply_order_state', 0);
  314. // only some fields are editable for initial states
  315. if (in_array($id_supply_order_state, array(1, 2, 3, 4, 5, 6)))
  316. {
  317. $this->fields_form = array(
  318. 'legend' => array(
  319. 'title' => $this->l('Supply Order status'),
  320. 'image' => '../img/admin/edit.gif'
  321. ),
  322. 'input' => array(
  323. array(
  324. 'type' => 'text',
  325. 'lang' => true,
  326. 'label' => $this->l('Status:'),
  327. 'name' => 'name',
  328. 'size' => 50,
  329. 'required' => true
  330. ),
  331. array(
  332. 'type' => 'color',
  333. 'label' => $this->l('Back Office color:'),
  334. 'name' => 'color',
  335. 'size' => 20,
  336. 'desc' => $this->l('Back Office background will be displayed in this color. HTML colors only'),
  337. ),
  338. ),
  339. 'submit' => array(
  340. 'title' => $this->l('Save'),
  341. 'class' => 'button'
  342. )
  343. );
  344. }
  345. if (!($obj = new SupplyOrderState((int)$id_supply_order_state)))
  346. return;
  347. $this->fields_value = array(
  348. 'color' => $obj->color,
  349. 'editable' => $obj->editable,
  350. 'delivery_note' => $obj->delivery_note,
  351. 'receipt_state' => $obj->receipt_state,
  352. 'pending_receipt' => $obj->pending_receipt,
  353. );
  354. foreach ($this->getLanguages() as $language)
  355. $this->fields_value['name'][$language['id_lang']] = $this->getFieldValue($obj, 'name', $language['id_lang']);
  356. }
  357. }
  358. return parent::renderForm();
  359. }
  360. /**
  361. * AdminController::renderList() override
  362. * @see AdminController::renderList()
  363. */
  364. public function renderList()
  365. {
  366. /**
  367. * General messages displayed for all lists
  368. */
  369. $this->displayInformation($this->l('This interface allows you to configure your supply order statuses and stock movement labels.').'<br />');
  370. // Checks access
  371. if (!($this->tabAccess['add'] === '1'))
  372. unset($this->toolbar_btn['new']);
  373. /**
  374. * First list
  375. * Stock Mvt Labels/Reasons
  376. */
  377. $first_list = null;
  378. $this->list_no_link = true;
  379. $this->addRowAction('edit');
  380. $this->addRowAction('delete');
  381. $this->addRowActionSkipList('edit', array(1, 2, 3, 4, 5, 6, 7, 8));
  382. $this->addRowActionSkipList('delete', array(1, 2, 3, 4, 5, 6, 7, 8));
  383. $this->_where = ' AND a.deleted = 0';
  384. $this->toolbar_title = $this->l('Stock: Stock movement labels');
  385. $first_list = parent::renderList();
  386. /**
  387. * Second list
  388. * Supply Order Status/State
  389. */
  390. $second_list = null;
  391. unset($this->_select, $this->_where, $this->_join, $this->_group, $this->_filterHaving, $this->_filter, $this->list_skip_actions['delete'], $this->list_skip_actions['edit']);
  392. // generates the actual second list
  393. $second_list = $this->initSupplyOrderStatusList();
  394. // resets default table and className for options list management
  395. $this->table = 'stock_mvt_reason';
  396. $this->className = 'StockMvtReason';
  397. // returns the final list
  398. return $second_list.$first_list;
  399. }
  400. /*
  401. * Help function for AdminStockConfigurationController::renderList()
  402. * @see AdminStockConfigurationController::renderList()
  403. */
  404. public function initSupplyOrderStatusList()
  405. {
  406. $this->table = 'supply_order_state';
  407. $this->className = 'SupplyOrderState';
  408. $this->identifier = 'id_supply_order_state';
  409. $this->_defaultOrderBy = 'id_supply_order_state';
  410. $this->lang = true;
  411. $this->list_no_link = true;
  412. $this->_orderBy = null;
  413. $this->addRowActionSkipList('delete', array(1, 2, 3, 4, 5, 6));
  414. $this->toolbar_title = $this->l('Stock: Supply Order status');
  415. $this->initToolbar();
  416. $this->fields_list = array(
  417. 'name' => array(
  418. 'title' => $this->l('Name'),
  419. 'color' => 'color',
  420. ),
  421. 'editable' => array(
  422. 'title' => $this->l('Editable?'),
  423. 'align' => 'center',
  424. 'icon' => array(
  425. '1' => 'enabled.gif',
  426. '0' => 'disabled.gif'
  427. ),
  428. 'type' => 'bool',
  429. 'width' => 170,
  430. 'orderby' => false
  431. ),
  432. 'delivery_note' => array(
  433. 'title' => $this->l('Delivery note available?'),
  434. 'align' => 'center',
  435. 'icon' => array(
  436. '1' => 'enabled.gif',
  437. '0' => 'disabled.gif'
  438. ),
  439. 'type' => 'bool',
  440. 'width' => 170,
  441. 'orderby' => false
  442. ),
  443. 'pending_receipt' => array(
  444. 'title' => $this->l('Is a pending receipt state?'),
  445. 'align' => 'center',
  446. 'icon' => array(
  447. '1' => 'enabled.gif',
  448. '0' => 'disabled.gif'
  449. ),
  450. 'type' => 'bool',
  451. 'width' => 170,
  452. 'orderby' => false
  453. ),
  454. 'receipt_state' => array(
  455. 'title' => $this->l('Is a delivery state?'),
  456. 'align' => 'center',
  457. 'icon' => array(
  458. '1' => 'enabled.gif',
  459. '0' => 'disabled.gif'
  460. ),
  461. 'type' => 'bool',
  462. 'width' => 170,
  463. 'orderby' => false
  464. ),
  465. 'enclosed' => array(
  466. 'title' => $this->l('Is an enclosed order state?'),
  467. 'align' => 'center',
  468. 'icon' => array(
  469. '1' => 'enabled.gif',
  470. '0' => 'disabled.gif'
  471. ),
  472. 'type' => 'bool',
  473. 'width' => 170,
  474. 'orderby' => false
  475. ),
  476. );
  477. return parent::renderList();
  478. }
  479. /**
  480. * AdminController::postProcess() override
  481. * @see AdminController::postProcess()
  482. */
  483. public function postProcess()
  484. {
  485. // SupplyOrderState
  486. if (Tools::isSubmit('submitAddsupply_order_state') ||
  487. Tools::isSubmit('deletesupply_order_state') ||
  488. Tools::isSubmit('submitUpdatesupply_order_state'))
  489. {
  490. if (Tools::isSubmit('deletesupply_order_state'))
  491. $this->action = 'delete';
  492. else
  493. $this->action = 'save';
  494. $this->table = 'supply_order_state';
  495. $this->className = 'SupplyOrderState';
  496. $this->identifier = 'id_supply_order_state';
  497. $this->_defaultOrderBy = 'id_supply_order_state';
  498. }
  499. // StockMvtReason
  500. else if (Tools::isSubmit('delete'.$this->table))
  501. $this->deleted = true;
  502. return parent::postProcess();
  503. }
  504. /**
  505. * AdminController::getList() override
  506. * @see AdminController::getList()
  507. */
  508. public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
  509. {
  510. parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
  511. //If there is a field product_name in the list, check if this field is null and display standard message
  512. foreach ($this->fields_list as $key => $value)
  513. if ($key == 'product_name')
  514. {
  515. $nb_items = count($this->_list);
  516. for ($i = 0; $i < $nb_items; ++$i)
  517. {
  518. $item = &$this->_list[$i];
  519. if (empty($item['product_name']))
  520. $item['product_name'] = $this->l('The name of this product is not available. It may been deleted from the system.');
  521. }
  522. }
  523. }
  524. public function initContent()
  525. {
  526. if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
  527. {
  528. $this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You need to activate advanced stock management prior to use this feature.');
  529. return false;
  530. }
  531. parent::initContent();
  532. }
  533. public function initProcess()
  534. {
  535. if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
  536. {
  537. $this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You need to activate advanced stock management prior to use this feature.');
  538. return false;
  539. }
  540. parent::initProcess();
  541. }
  542. }