/** * AdminController::postProcess() override * @see AdminController::postProcess() */ public function postProcess() { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); if (Tools::isSubmit('export_csv')) { $this->renderCSV(); } // checks access if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) { $this->errors[] = Tools::displayError($this->l('You do not have permission to add suppliers.')); return parent::postProcess(); } if (Tools::isSubmit('submitAdd' . $this->table)) { if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) { return; } // updates/creates address if it does not exist if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) { $address = new Address((int) Tools::getValue('id_address')); } else { $address = new Address(); } // creates address $address->alias = Tools::getValue('name', null); $address->lastname = 'supplier'; // skip problem with numeric characters in supplier name $address->firstname = 'supplier'; // skip problem with numeric characters in supplier name $address->address1 = Tools::getValue('address', null); $address->address2 = Tools::getValue('address2', null); $address->postcode = Tools::getValue('postcode', null); $address->phone = Tools::getValue('phone', null); $address->id_country = Tools::getValue('id_country', null); $address->id_state = Tools::getValue('id_state', null); $address->city = Tools::getValue('city', null); $validation = $address->validateController(); // checks address validity if (count($validation) > 0) { foreach ($validation as $item) { $this->errors[] = $item; } $this->errors[] = Tools::displayError($this->l('The address is not correct. Please make sure all of the required fields are completed.')); } else { if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) { $address->update(); } else { $address->save(); $_POST['id_address'] = $address->id; } } //--ERP informations // updates/creates erp_supplier if it does not exist if (Tools::isSubmit('id_erpip_supplier') && (int) Tools::getValue('id_erpip_supplier') > 0) { $erp_supplier = new ErpSupplier((int) Tools::getValue('id_erpip_supplier')); } else { $erp_supplier = new ErpSupplier(); } // creates erp_supplier $erp_supplier->email = Tools::getValue('email', null); $erp_supplier->fax = Tools::getValue('fax', null); $erp_supplier->franco_amount = Tools::getValue('franco_amount', null); $erp_supplier->discount_amount = Tools::getValue('discount_amount', null); $erp_supplier->shipping_amount = Tools::getValue('shipping_amount', null); $erp_supplier->escompte = Tools::getValue('escompte', null); $erp_supplier->delivery_time = Tools::getValue('delivery_time', null); $erp_supplier->account_number_accounting = Tools::getValue('account_number_accounting', null); $validation2 = $erp_supplier->validateController(); //print_r($validation2); // checks erp_supplier validity if (count($validation2) > 0) { foreach ($validation2 as $item) { $this->errors[] = $item; } $this->errors[] = Tools::displayError($this->l('The ErpIllicopresta Supplier is not correct. Please make sure all of the required fields are completed.')); } else { if (Tools::isSubmit('id_erpip_supplier') && Tools::getValue('id_erpip_supplier') > 0) { $erp_supplier->update(); } else { $erp_supplier->save(); $_POST['id_erpip_supplier'] = $erp_supplier->id; } } return parent::postProcess(); } else { if (Tools::isSubmit('delete' . $this->table)) { if (!($obj = $this->loadObject(true))) { return; } else { if (SupplyOrder::supplierHasPendingOrders($obj->id)) { $this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.'); } else { //delete all product_supplier linked to this supplier Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'product_supplier` WHERE `id_supplier`=' . (int) $obj->id); $id_address = Address::getAddressIdBySupplierId($obj->id); $address = new Address($id_address); if (Validate::isLoadedObject($address)) { $address->deleted = 1; $address->save(); } //delete erp supplier $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($obj->id); $erp_supplier = new ErpSupplier($id_erpip_supplier); if (Validate::isLoadedObject($erp_supplier)) { $erp_supplier->delete(); } return parent::postProcess(); } } } else { return parent::postProcess(); } } }
/** * @see HTMLTemplate::getContent() */ public function getContent() { $final_pdf = ''; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrderCustomer.php'; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplier.php'; require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrder.php'; // Retrieval of the link between supplier order AND customer order if exists $erp_supply_order_customer = ErpSupplyOrderCustomer::getSupplyOrdersCustomer((int) $this->supply_order->id); $supply_order_details = $this->supply_order->getEntriesCollection((int) $this->supply_order->id_lang); $this->roundSupplyOrderDetails($supply_order_details); $supply_order_receipt_history = array(); foreach ($supply_order_details as $supply_order_detail) { $supply_order_receipt_history[$supply_order_detail->id] = $this->getSupplyOrderReceiptHistoryCollection($supply_order_detail->id); } $this->roundSupplyOrder($this->supply_order); $tax_order_summary = $this->getTaxOrderSummary(); $currency = new Currency((int) $this->supply_order->id_currency); //-ERP information // get additional supplier information $erp_supplier = null; $erp_supplier_fax = ''; if (isset($this->supply_order->id_supplier) && (int) $this->supply_order->id_supplier > 0) { $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId((int) $this->supply_order->id_supplier); if ((int) $id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } } if ($erp_supplier != null) { $erp_supplier_fax = $erp_supplier->fax; } //-ERP information // get additional supply order information $erp_supply_order = null; if (isset($this->supply_order->id) && (int) $this->supply_order->id > 0) { $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId((int) $this->supply_order->id); if ((int) $id_erpip_supply_order > 0) { $erp_supply_order = new ErpSupplyOrder((int) $id_erpip_supply_order); } } // get shipping address $adresse_livraison = self::getStoreByName('Adresse livraison'); $this->smarty->assign(array('warehouse' => $this->warehouse, 'address_warehouse' => $this->address_warehouse, 'address_supplier' => $this->address_supplier, 'supply_order' => $this->supply_order, 'erp_supply_order' => $erp_supply_order, 'supply_order_details' => $supply_order_details, 'supply_order_receipt_history' => $supply_order_receipt_history, 'tax_order_summary' => $tax_order_summary, 'currency' => $currency, 'fax' => $erp_supplier_fax, 'action' => Tools::getValue('submitAction'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'shop_addr' => Configuration::get('PS_SHOP_ADDR1'), 'shop_addr2' => Configuration::get('PS_SHOP_ADDR2'), 'shop_code' => Configuration::get('PS_SHOP_CODE'), 'shop_city' => Configuration::get('PS_SHOP_CITY'), 'shop_country' => Configuration::get('PS_SHOP_COUNTRY'), 'adresse_livraison' => $adresse_livraison)); // if there is an supply order generated : display a PDF page by customer if (!empty($erp_supply_order_customer)) { // distribution by customer : one page per customer $final_item = array(); foreach ($erp_supply_order_customer as $item) { $final_item[$item['id_customer']][] = $item; } $pdf_customer = ''; // Create page per customer foreach ($final_item as $id_customer => $datas) { $customer = new Customer((int) $id_customer); $order_detail = array(); foreach ($datas as $data) { $order_detail_line = new OrderDetailCore((int) $data['id_order_detail']); $order_detail_line->tax_rate = Tax::getProductTaxRate($order_detail_line->product_id); $order_detail[] = $order_detail_line; } $this->smarty->assign(array('is_customer_page' => 'true')); $this->smarty->assign(array('supply_order_details' => $order_detail)); $this->smarty->assign(array('customer_name' => $customer->lastname . ' ' . $customer->firstname)); $pdf_customer .= '<div style="page-break-before:always"><div>'; $pdf_customer .= $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order-customer.tpl'); } $this->smarty->assign(array('is_customer_page' => 'false')); $this->smarty->assign(array('supply_order_details' => $supply_order_details)); $final_pdf = $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order.tpl') . $pdf_customer; } else { $final_pdf = $this->smarty->fetch(_PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/pdf/erp-supply-order.tpl'); } return $final_pdf; }
} } break; case 'supplier': default: /* Execute AJAX requests */ if (Tools::isSubmit('action')) { switch (Tools::getValue('action')) { /* get supplier info */ case 'getSupplier': if (Tools::isSubmit('id_supplier') && (int) Tools::getValue('id_supplier') > 0) { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplier.php'; $id_supplier = (int) Tools::getValue('id_supplier'); //-ERP information $erp_supplier = null; $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($id_supplier); if ($id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } if (!is_null($erp_supplier)) { echo Tools::jsonEncode($erp_supplier); } } else { echo Tools::jsonEncode(array('error' => $erpip->l('Error : no supplier found !'))); } break; case 'getSupplyOrderDescription': if (Tools::isSubmit('id_supplier_order')) { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpSupplyOrder.php'; $id_supplier_order = (int) Tools::getValue('id_supplier_order'); if ($id_supplier_order > 0) {
public function sendMailOnValidateSupplyOrder($supply_order) { // Verify that the provider mail is activate $enable_sending_mail_supplier = Configuration::get('ERP_ENABLE_SENDING_MAIL_SUPPLIER'); if (!empty($enable_sending_mail_supplier) && $enable_sending_mail_supplier == '1') { // if status is configured to send mail $supply_order_state_to_send_mail = Configuration::get('ERP_SO_STATE_TO_SEND_MAIL'); $id_state_to = (int) Tools::getValue('id_supply_order_state', 0); // send mail to provider if validation step if ($id_state_to == $supply_order_state_to_send_mail) { // Get the order provider $supplier = new Supplier($supply_order->id_supplier); //If supplier is valid if (Validate::isLoadedObject($supplier)) { //--ERP information // get additional information from erp supplier $erp_supplier = null; if (isset($supplier->id)) { $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId((int) $supplier->id); if ($id_erpip_supplier > 0) { $erp_supplier = new ErpSupplier((int) $id_erpip_supplier); } } // if ERP supplier existe if ($erp_supplier != null) { require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/ErpSupplierClass.php'; //get supplier mail or emails sseparated by ";" $supplier_emails = $erp_supplier->email; //explode if caractère ";" find if (strpos($supplier_emails, ';') !== false) { $to = explode(';', $supplier_emails); } else { $to = $supplier_emails; } if (empty($to)) { $this->errors[] = Tools::displayError($this->l('Error while sending validation email to the suppplier : email not informed ! ')); return false; } //Shop email $from = Configuration::get('PS_SHOP_EMAIL'); //shop name $from_name = Configuration::get('PS_SHOP_NAME'); //Id order_lang // if the provider come from a francophone country France, DOM, TOM, id lang = fr (5) if (ErpSupplierClass::isSupplierFrench((int) $supplier->id)) { $supplier_id_lang = Language::getIdByIso('fr'); //subject $subject = 'Commande fournisseur valide'; } else { $languages = Language::getLanguages(); $supplier_id_lang = $languages[0]['id_lang']; //subject $subject = $this->l('Order validated'); } //Template path $template_path = _PS_MODULE_DIR_ . 'erpillicopresta/mails/'; // Get the purchased products $supply_order_details = $supply_order->getEntries(); $html_order_details = ''; $txt_order_details = ''; // Build html and text code for email if (!empty($supply_order_details)) { foreach ($supply_order_details as $product) { $html_order_details .= '<tr> <td>' . $product['reference'] . '</td> <td>' . $product['supplier_reference'] . '</td> <td>' . $product['name'] . '</td> <td>' . @$product['comment'] . '</td> <td>' . Tools::displayPrice($product['unit_price_te']) . '</td> <td>' . $product['quantity_expected'] . '</td> </tr>'; $txt_order_details .= $product['reference'] . ' - ' . $product['supplier_reference'] . ' - ' . $product['name'] . ' - ' . @$product['comment'] . ' - ' . Tools::displayPrice($product['unit_price_te']) . ' - ' . $product['quantity_expected'] . ' - ' . "\n\r"; } } //template_vars $template_vars = array(); $template_vars['{id_supply_order}'] = $supply_order->id; $template_vars['{html_order_details}'] = $html_order_details; $template_vars['{txt_order_details}'] = $txt_order_details; //Send mail return Mail::send($supplier_id_lang, 'supply_order_validated', $subject, $template_vars, $to, null, $from, $from_name, null, null, $template_path); } } } } return true; }