/** * AdminController::renderForm() override * @see AdminController::renderForm() */ public function renderForm() { // loads current warehouse if (!($obj = $this->loadObject(true))) { return; } if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitUpdatesupply_order')) { if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('submitAddsupply_order')) { $this->toolbar_title = $this->l('Create a new supply order'); } if (Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitUpdatesupply_order')) { $this->toolbar_title = $this->l('Manage supply orders'); } if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) { $this->toolbar_title .= ' (' . $this->l('template') . ')'; } //get warehouses list $warehouses = Warehouse::getWarehouses(true); // displays warning if there are no warehouses if (!$warehouses) { $this->displayWarning($this->l('You must have at least one warehouse. 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); } //get suppliers list $suppliers = Supplier::getSuppliers(); //get languages list $languages = Language::getLanguages(true); $id_default_lang = Configuration::get('PS_LANG_DEFAULT'); $default_lang = Language::getLanguage($id_default_lang); if ($default_lang) { $languages = array_merge(array($default_lang, '-'), $languages); } $this->fields_form = array('legend' => array('title' => $this->l('Order information'), $this->is_1_6 ? 'icon' : 'image' => $this->is_1_6 ? 'icon-pencil' : '../img/admin/edit.gif'), 'input' => array(array('type' => 'hidden', 'name' => 'id_erpip_supply_order'), array('type' => 'text', 'label' => $this->l('Reference:'), 'name' => 'reference', 'size' => 50, 'required' => true, 'readonly' => true, 'desc' => $this->l('The reference number of your order.')), array('type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'cols' => 60, 'rows' => 10, 'lang' => false, 'hint' => $this->l('Invalid characters :') . ' <>;=#{}', 'desc' => $this->l('Will appear in the suppliers list'), 'autoload_rte' => 'rte'), array('type' => 'select', 'label' => $this->l('Supplier:'), 'name' => 'id_supplier', 'required' => true, 'options' => array('query' => $suppliers, 'id' => 'id_supplier', 'name' => 'name'), 'desc' => $this->l('Select the supplier you\'ll be purchasing from.'), 'hint' => $this->l('Warning: All products already added to the order will be removed.')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Which warehouse will the order be sent to?')), 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 of the order.'), 'hint' => $this->l('Warning: All products already added to the order will be removed.')), array('type' => 'select', 'label' => $this->l('Order Language:'), 'name' => 'id_lang', 'required' => true, 'options' => array('query' => $languages, 'id' => 'id_lang', 'name' => 'name'), 'desc' => $this->l('The language of the order.')), array('type' => 'radio', 'label' => $this->l('Global discount type:'), 'name' => 'global_discount_type', 'required' => true, 'br' => true, 'class' => 't', 'default_value' => 'amount', 'values' => array(array('id' => 'global_discount_type' . _PS_SMARTY_NO_COMPILE_, 'value' => 'rate', 'label' => $this->l('Ratio')), array('id' => 'global_discount_type' . _PS_SMARTY_CHECK_COMPILE_, 'value' => 'amount', 'label' => $this->l('Amount'))), 'desc' => $this->l('Please select the discount type which will be applied to this order : ratio or amount')), array('type' => 'text', 'label' => $this->l('Global discount rate (%):'), 'name' => 'discount_rate', 'size' => 10, 'required' => true, 'desc' => $this->l('This is the global discount rate in percent for the order.')), array('type' => 'text', 'label' => $this->l('Discount total amount:'), 'name' => 'global_discount_amount', 'size' => 10, 'required' => false, 'desc' => $this->l('Please indicate the discount total amount')), array('type' => 'text', 'label' => $this->l('Discount (%)'), 'name' => 'escompte', 'size' => 10, 'required' => false, 'desc' => $this->l('Percentage discount impacting the order total.')), array('type' => 'text', 'label' => $this->l('Shipping amount'), 'name' => 'shipping_amount', 'size' => 10, 'required' => false, 'desc' => $this->l('Shipping amount that will be added to the total order (tax excl.).')), array('type' => 'text', 'label' => $this->l('Automatically load products:'), 'name' => 'load_products', 'size' => 10, 'required' => false, 'hint' => $this->l('This will reset the order'), 'desc' => $this->l('If specified, each product quantity inferior or equal to this value will be loaded.'))), 'submit' => array('title' => $this->l('Save order'))); if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) { $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'is_template'); $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'date_delivery_expected'); } else { $this->fields_form['input'][] = array('type' => 'date', 'label' => $this->l('Expected delivery date:'), 'name' => 'date_delivery_expected', 'size' => 10, 'required' => true, 'desc' => $this->l('The expected delivery date for this order is...')); } //specific discount display if (isset($this->object->discount_rate)) { $this->object->discount_rate = Tools::ps_round($this->object->discount_rate, 4); } //specific date display if (isset($this->object->date_delivery_expected)) { $date = explode(' ', $this->object->date_delivery_expected); if ($date) { $this->object->date_delivery_expected = $date[0]; } } $this->displayInformation($this->l('If you wish to order products, they have to be available for the specified supplier/warehouse.') . ' ' . $this->l('See Catalog/Products/Your Product/Suppliers & Warehouses') . '<br />' . $this->l('Changing the currency or the supplier will reset the order.') . '<br />' . '<br />' . $this->l('Please note that you can only order from one supplier at a time.')); //-- ERP informations // add additional information $erp_filed_value = array(); $erp_filed_value['id_erpip_supply_order'] = 0; $franco_amount = 0; //if we are in add form if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('submitAddsupply_order')) { $erp_filed_value['reference'] = ErpSupplyOrderClasses::getNextSupplyOrderReference(); //get value of the first supplier : the default selected if (!empty($suppliers)) { // get additional information for the first supplier $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId((int) $suppliers[0]['id_supplier']); $erp_supplier = null; if ($id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } if ($erp_supplier != null) { $franco_amount = $erp_supplier->franco_amount; $erp_filed_value['escompte'] = $erp_supplier->escompte; $erp_filed_value['shipping_amount'] = $erp_supplier->shipping_amount; $erp_filed_value['global_discount_amount'] = $erp_supplier->discount_amount; if ((int) $erp_supplier->delivery_time > 0) { $erp_filed_value['date_delivery_expected'] = date('Y-m-d', strtotime('+ ' . (int) $erp_supplier->delivery_time . ' days')); } // the additional information not existe then the id_erpip_supply_order is 0 $erp_filed_value['id_erpip_supply_order'] = 0; } } } else { // set franco amount value if (isset($this->object->id_supplier)) { $supplier = new ErpSupplier($this->object->id_supplier); $franco_amount = $supplier->franco_amount; } // loads current erp_supplier_order information for this supplier order - if possible $erp_supplier_order = null; if (isset($obj->id)) { $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId($obj->id); if ($id_erpip_supply_order > 0) { $erp_supplier_order = new ErpSupplyOrder((int) $id_erpip_supply_order); } } // force specific fields values (erp_supplier_order) if ($erp_supplier_order != null) { $erp_filed_value['id_erpip_supply_order'] = $erp_supplier_order->id_erpip_supply_order; $erp_filed_value['escompte'] = $erp_supplier_order->escompte; $erp_filed_value['shipping_amount'] = $erp_supplier_order->shipping_amount; $erp_filed_value['global_discount_amount'] = $erp_supplier_order->global_discount_amount; $erp_filed_value['description'] = $erp_supplier_order->description; } } //Set form value $this->fields_value = $erp_filed_value; $this->context->smarty->assign(array('franco_amount' => $franco_amount, 'shipping_amount' => $erp_filed_value['shipping_amount'], 'supply_order_total_te' => number_format($this->object->total_te, 2, ',', ' '), 'amount_to_franco_with_produc_discount' => number_format((double) $franco_amount - $this->object->total_te, 2, ',', ' '), 'template_path' => $this->template_path, 'controller_status' => $this->controller_status, 'stock_management_active' => $this->advanced_stock_management)); $this->getFilters(); if (Tools::isSubmit('export_csv')) { $this->renderCSV(); } return parent::renderForm(); } }
public function renderForm() { // loads current warehouse if (!($obj = $this->loadObject(true))) { return; } $this->fields_form = array('legend' => array('title' => $this->l('Suppliers'), 'image' => '../img/admin/suppliers.gif'), 'input' => array(array('type' => 'hidden', 'name' => 'id_address'), array('type' => 'hidden', 'name' => 'id_erpip_supplier'), array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters :') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Email'), 'name' => 'email', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Fax'), 'name' => 'fax', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Franco Amount'), 'name' => 'franco_amount', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Discount Amount'), 'name' => 'discount_amount', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Shipping Amount'), 'name' => 'shipping_amount', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Discounting'), 'name' => 'escompte', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Delivery Time'), 'name' => 'delivery_time', 'size' => 40, 'required' => false), array('type' => 'text', 'label' => $this->l('Account Number Accounting'), 'name' => 'account_number_accounting', 'size' => 40, 'required' => false), array('type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'cols' => 60, 'rows' => 10, 'lang' => true, 'hint' => $this->l('Invalid characters :') . ' <>;=#{}', 'desc' => $this->l('Will appear in the suppliers list'), 'autoload_rte' => 'rte'), array('type' => 'text', 'label' => $this->l('Phone :'), 'name' => 'phone', 'size' => 15, 'maxlength' => 16, 'desc' => $this->l('Phone number of this supplier')), array('type' => 'text', 'label' => $this->l('Address :'), 'name' => 'address', 'size' => 100, 'maxlength' => 128, 'required' => true), array('type' => 'text', 'label' => $this->l('Address :') . ' (2)', 'name' => 'address2', 'size' => 100, 'maxlength' => 128), array('type' => 'text', 'label' => $this->l('Postal Code/Zip Code :'), 'name' => 'postcode', 'size' => 10, 'maxlength' => 12, 'required' => true), array('type' => 'text', 'label' => $this->l('City :'), 'name' => 'city', 'size' => 20, 'maxlength' => 32, 'required' => true), array('type' => 'select', 'label' => $this->l('Country :'), 'name' => 'id_country', 'required' => true, 'default_value' => (int) $this->context->country->id, 'options' => array('query' => Country::getCountries($this->context->language->id, false), 'id' => 'id_country', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('State :'), 'name' => 'id_state', 'options' => array('id' => 'id_state', 'query' => array(), 'name' => 'name')), array('type' => 'file', 'label' => $this->l('Logo :'), 'name' => 'logo', 'display_image' => true, 'desc' => $this->l('Upload a supplier logo from your computer')), array('type' => 'text', 'label' => $this->l('Meta title :'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters :') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta description :'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters :') . ' <>;=#{}'), array('type' => 'tags', 'label' => $this->l('Meta keywords :'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Forbidden characters :') . ' <>;=#{}', 'desc' => $this->l('To add "tags" click in the field, write something and then press "Enter"')), array('type' => 'radio', 'label' => $this->l('Enable :'), 'name' => 'active', 'required' => false, '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'))))), 'submit' => array('title' => $this->l(' Save '))); // loads current address for this supplier - if possible $address = null; if (isset($obj->id)) { $id_address = Address::getAddressIdBySupplierId($obj->id); if ($id_address > 0) { $address = new Address((int) $id_address); } } // force specific fields values (address) if ($address != null) { $this->fields_value = array('id_address' => $address->id, 'phone' => $address->phone, 'address' => $address->address1, 'address2' => $address->address2, 'postcode' => $address->postcode, 'city' => $address->city, 'id_country' => $address->id_country, 'id_state' => $address->id_state); } else { $this->fields_value = array('id_address' => 0, 'id_country' => Configuration::get('PS_COUNTRY_DEFAULT')); } // loads current erp_supplier` informationfor this supplier - if possible $erp_supplier = null; if (isset($obj->id)) { $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($obj->id); if ($id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } } // force specific fields values (erp_supplier) if ($erp_supplier != null) { $this->fields_value = array_merge($this->fields_value, array('id_erpip_supplier' => $erp_supplier->id, 'email' => $erp_supplier->email, 'fax' => $erp_supplier->fax, 'franco_amount' => $erp_supplier->franco_amount, 'discount_amount' => $erp_supplier->discount_amount, 'shipping_amount' => $erp_supplier->shipping_amount, 'escompte' => $erp_supplier->escompte, 'delivery_time' => $erp_supplier->delivery_time, 'account_number_accounting' => $erp_supplier->account_number_accounting)); } else { $this->fields_value = array_merge($this->fields_value, array('id_erpip_supplier' => 0)); } if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association :'), 'name' => 'checkBoxShopAsso'); } // set logo image $image = ImageManager::thumbnail(_PS_SUPP_IMG_DIR_ . '/' . $this->object->id . '.jpg', $this->table . '_' . (int) $this->object->id . '.' . $this->imageType, 350, $this->imageType, true); $this->fields_value['image'] = $image ? $image : false; $this->fields_value['size'] = $image ? filesize(_PS_SUPP_IMG_DIR_ . '/' . $this->object->id . '.jpg') / 1000 : false; return parent::renderForm(); }
public function renderForm() { // loads current warehouse if (!$this->loadObject(true)) { return; } // get the current warehouse areas $zones = ErpZone::getZonesByWarehouse(Tools::getValue('id_warehouse')); array_unshift($zones, array('name' => $this->l('Home'), 'id_erpip_zone' => 0)); // gets warehouses $warehouses_add = Warehouse::getWarehouses(true); // displays warning if no warehouses if (!$warehouses_add) { $this->displayWarning($this->l('You must choose a warehouse before adding areas. See Stock/Warehouses')); } // Default values if (Tools::isSubmit('id_zone_parent') && Tools::getValue('id_zone_parent') != '') { $this->fields_value['id_parent'] = Tools::getValue('id_zone_parent'); } if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != '') { $this->fields_value['id_warehouse'] = Tools::getValue('id_warehouse'); } $this->fields_value['active'] = true; // form fields définition // Name $base = array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}')); // warehouse // select warehouse only if create area level 1 if (Tools::getValue('id_zone_parent') == '' && Tools::getValue('id_warehouse') == '') { $warehouse = array(array('type' => 'select', 'label' => $this->l('Warehouse'), 'name' => 'id_warehouse', 'class' => 'chosen', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'))); } else { $warehouse = array(array('type' => 'text', 'label' => $this->l('Warehouse'), 'name' => 'warehouse_name', 'disabled' => true, 'size' => 40, 'required' => true), array('type' => 'hidden', 'name' => 'id_warehouse', 'required' => true)); } // Show area (level1) and select active/inactive // If we re on an create area (lvl1) --> set used variables by helperform on home (force to create a new area) if (Tools::getValue('id_parent') == '' && Tools::getValue('id_zone_parent') == '') { $_GET['zone_name'] = 'Accueil'; $_GET['id_parent'] = '0'; } $areaAndActive = array(array('type' => 'text', 'label' => $this->l('Parent zone'), 'name' => 'zone_name', 'disabled' => true, 'size' => 40, 'required' => true), array('type' => 'hidden', 'name' => 'id_parent', 'required' => true), array('type' => $this->is_1_6 ? 'switch' : 'radio', 'label' => $this->l('Enable:'), 'name' => 'active', 'required' => false, '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'))))); // full form $this->fields_form = array('legend' => array('title' => $this->l('Add or edit an area'), 'image' => '../img/admin/suppliers.gif'), 'input' => array_merge($base, $warehouse, $areaAndActive), 'submit' => array('title' => $this->l(' Save '))); return parent::renderForm(); }