コード例 #1
0
 /**
  * AdminController::renderForm() override
  * @see AdminController::renderForm()
  */
 public function renderForm()
 {
     // gets the product
     $id_product = (int) Tools::getValue('id_product');
     $id_product_attribute = (int) Tools::getValue('id_product_attribute');
     // gets warehouses
     $warehouses_add = $warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
     // displays warning if no warehouses
     if (!$warehouses_add) {
         $this->displayWarning($this->l('You must choose a warehouses before adding stock. See Stock/Warehouses.'));
     }
     //get currencies list
     $currencies = Currency::getCurrencies();
     $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
     $default_currency = Currency::getCurrency($id_default_currency);
     if ($default_currency) {
         $currencies = array_merge(array($default_currency, '-'), $currencies);
     }
     // switch, in order to display the form corresponding to the current action
     switch ($this->display) {
         case 'addstock':
             // gets the last stock mvt for this product, so we can display the last unit price te and the last quantity added
             $last_sm_unit_price_te = $this->l('N/A');
             $last_sm_quantity = 0;
             $last_sm_quantity_is_usable = -1;
             $last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
             // if there is a stock mvt
             if ($last_sm != false) {
                 $last_sm_currency = new Currency((int) $last_sm['id_currency']);
                 $last_sm_quantity = (int) $last_sm['physical_quantity'];
                 $last_sm_quantity_is_usable = (int) $last_sm['is_usable'];
                 if (Validate::isLoadedObject($last_sm_currency)) {
                     $last_sm_unit_price_te = Tools::displayPrice((double) $last_sm['price_te'], $last_sm_currency);
                 }
             }
             $this->displayInformation($this->l('Moving the mouse cursor over the quantity and price fields will give you the details about the last stock movement.'));
             // fields in the form
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Add a product to your stock.'), 'icon' => 'icon-long-arrow-up'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference'), 'name' => 'reference', 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN-13 or JAN barcode'), 'name' => 'ean13', 'disabled' => true), array('type' => 'text', 'label' => $this->l('UPC barcode'), 'name' => 'upc', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to add'), 'name' => 'quantity', 'maxlength' => 6, 'required' => true, 'hint' => array($this->l('Indicate the physical quantity of this product that you want to add.'), $this->l('Last physical quantity added: %s items (usable for sale: %s).'), $last_sm_quantity > 0 ? $last_sm_quantity : $this->l('N/A'), $last_sm_quantity > 0 ? $last_sm_quantity_is_usable >= 0 ? $this->l('Yes') : $this->l('No') : $this->l('N/A'))), array('type' => 'switch', 'label' => $this->l('Usable for sale?'), 'name' => 'usable', 'required' => true, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'hint' => $this->l('Is this quantity ready to be displayed in your shop, or is it reserved in the warehouse for other purposes?')), array('type' => 'select', 'label' => $this->l('Warehouse'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'hint' => $this->l('Please select the warehouse that you\'ll be adding products to.')), array('type' => 'text', 'label' => $this->l('Unit price (tax excl.)'), 'name' => 'price', 'required' => true, 'size' => 10, 'maxlength' => 10, 'hint' => array($this->l('Unit purchase price or unit manufacturing cost for this product (tax excl.).'), sprintf($this->l('Last unit price (tax excl.): %s.'), $last_sm_unit_price_te))), array('type' => 'select', 'label' => $this->l('Currency'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'hint' => $this->l('The currency associated to the product unit price.')), array('type' => 'select', 'label' => $this->l('Label'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')), 1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'hint' => $this->l('Label used in stock movements.'))), 'submit' => array('title' => $this->l('Add to stock')));
             $this->fields_value['usable'] = 1;
             break;
         case 'removestock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Remove the product from your stock.'), 'icon' => 'icon-long-arrow-down'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference'), 'name' => 'reference', 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN-13 or JAN barcode'), 'name' => 'ean13', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to remove'), 'name' => 'quantity', 'maxlength' => 6, 'required' => true, 'hint' => $this->l('Indicate the physical quantity of this product that you want to remove.')), array('type' => 'switch', 'label' => $this->l('Usable for sale'), 'name' => 'usable', 'required' => true, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'hint' => $this->l('Do you want to remove this quantity from the usable quantity (yes) or the physical quantity (no)?')), array('type' => 'select', 'label' => $this->l('Warehouse'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'hint' => $this->l('Select the warehouse you\'d like to remove the product from.')), array('type' => 'select', 'label' => $this->l('Label'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')), -1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'hint' => $this->l('Label used in stock movements.'))), 'submit' => array('title' => $this->l('Remove from stock')));
             break;
         case 'transferstock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Transfer a product from one warehouse to another'), 'icon' => 'icon-share-alt'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference'), 'name' => 'reference', 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN-13 or JAN barcode'), 'name' => 'ean13', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to transfer'), 'name' => 'quantity', 'maxlength' => 6, 'required' => true, 'hint' => $this->l('Indicate the physical quantity of this product that you want to transfer.')), array('type' => 'select', 'label' => $this->l('Source warehouse'), 'name' => 'id_warehouse_from', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'hint' => $this->l('Select the warehouse you\'d like to transfer the product from.')), array('type' => 'switch', 'label' => $this->l('Is this product usable for sale in your source warehouse?'), 'name' => 'usable_from', 'required' => true, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No'))), 'hint' => $this->l('Is this the usable quantity for sale?')), array('type' => 'select', 'label' => $this->l('Destination warehouse'), 'name' => 'id_warehouse_to', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'hint' => $this->l('Select the warehouse you\'d like to transfer your product(s) to. ')), array('type' => 'switch', 'label' => $this->l('Is this product usable for sale in your destination warehouse?'), 'name' => 'usable_to', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('No'))), 'hint' => $this->l('Do you want it to be for sale/usable?'))), 'submit' => array('title' => $this->l('Transfer')));
             break;
     }
     $this->initToolbar();
 }
コード例 #2
0
 /**
  * AdminController::renderForm() override
  * @see AdminController::renderForm()
  */
 public function renderForm()
 {
     // gets the product
     $id_product = (int) Tools::getValue('id_product');
     $id_product_attribute = (int) Tools::getValue('id_product_attribute');
     // gets warehouses
     $warehouses_add = Warehouse::getWarehouses(true);
     $warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
     // displays warning if no warehouses
     if (!$warehouses_add) {
         $this->displayWarning($this->l('You have to have Warehouses before adding stock. See Stock/Warehouses'));
     }
     //get currencies list
     $currencies = Currency::getCurrencies();
     $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
     $default_currency = Currency::getCurrency($id_default_currency);
     if ($default_currency) {
         $currencies = array_merge(array($default_currency, '-'), $currencies);
     }
     // switch, in order to display the form corresponding to the current action
     switch ($this->display) {
         case 'addstock':
             // gets the last stock mvt for this product, so we can display the last unit price te and the last quantity added
             $last_sm_unit_price_te = $this->l('N/A');
             $last_sm_quantity = 0;
             $last_sm_quantity_is_usable = -1;
             $last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
             // if there is a stock mvt
             if ($last_sm != false) {
                 $last_sm_currency = new Currency((int) $last_sm['id_currency']);
                 $last_sm_quantity = (int) $last_sm['physical_quantity'];
                 $last_sm_quantity_is_usable = (int) $last_sm['is_usable'];
                 if (Validate::isLoadedObject($last_sm_currency)) {
                     $last_sm_unit_price_te = Tools::displayPrice((double) $last_sm['price_te'], $last_sm_currency);
                 }
             }
             $this->displayInformation($this->l('Note that rolling over the quantity and price fields will give you the details of the last stock movement.'));
             // fields in the form
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Add product to stock'), 'image' => '../img/admin/add_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('UPC:'), 'name' => 'upc', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to add:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to add'), 'hint' => sprintf($this->l('Last physical quantity added : %s (%s)'), $last_sm_quantity > 0 ? $last_sm_quantity : $this->l('N/A'), $last_sm_quantity > 0 ? $last_sm_quantity_is_usable >= 0 ? $this->l('usable') : $this->l('not usable') : $this->l('N/A'))), array('type' => 'radio', 'label' => $this->l('Usable for sale?'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this quantity usable for sale on shops, or reserved in the warehouse for other purposes?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse where you want to add the product into')), array('type' => 'text', 'label' => $this->l('Unit price (tax excl.):'), 'name' => 'price', 'required' => true, 'size' => 10, 'maxlength' => 10, 'desc' => $this->l('Unit purchase price or unit manufacturing cost for this product (tax excl.)'), 'hint' => sprintf($this->l('Last unit price (tax excl.): %s'), $last_sm_unit_price_te)), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'desc' => $this->l('The currency associated to the product unit price')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')), 1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Add to stock'), 'class' => 'button'));
             $this->fields_value['usable'] = 1;
             break;
         case 'removestock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Remove product from stock'), 'image' => '../img/admin/remove_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to remove:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to remove')), array('type' => 'radio', 'label' => $this->l('Usable for sale:'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want to remove this quantity from the usable quantity (yes) or the physical quantity (no)?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse from where you want to remove the product')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')), -1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Remove from stock'), 'class' => 'button'));
             break;
         case 'transferstock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Transfer product from one warehouse to another'), 'image' => '../img/admin/transfer_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to transfer:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Quantity to transfer:')), array('type' => 'select', 'label' => $this->l('Source Warehouse:'), 'name' => 'id_warehouse_from', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse from which you want to transfer the product.')), array('type' => 'radio', 'label' => $this->l('Usable for sale in source warehouse?'), 'name' => 'usable_from', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this a usable quantity for sale?')), array('type' => 'select', 'label' => $this->l('Destination Warehouse:'), 'name' => 'id_warehouse_to', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse to which to transfer the product.')), array('type' => 'radio', 'label' => $this->l('Usable for sale in destination warehouse?'), 'name' => 'usable_to', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want it to be usable for sale?'))), 'submit' => array('title' => $this->l('Transfer'), 'class' => 'button'));
             break;
     }
     $this->initToolbar();
 }