コード例 #1
0
ファイル: SupplyOrder.php プロジェクト: zangles/lennyba
 /**
  * Historizes the order : its id, its state, and the employee responsible for the current action
  */
 protected function addHistory()
 {
     $context = Context::getContext();
     $history = new SupplyOrderHistory();
     $history->id_supply_order = $this->id;
     $history->id_state = $this->id_supply_order_state;
     $history->id_employee = (int) $context->employee->id;
     $history->employee_firstname = pSQL($context->employee->firstname);
     $history->employee_lastname = pSQL($context->employee->lastname);
     $history->save();
 }
 public function initOrderingContent()
 {
     // list order id by created providers
     $supply_order_created = array();
     $this->show_toolbar = true;
     $this->display = 'ordering';
     if ($this->is_1_6) {
         $this->initPageHeaderToolbar();
     }
     $this->initToolbar();
     $datas = $this->getDataGeneration();
     if (!empty($datas['data_return'])) {
         //get default currencie
         $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
         // get default id lang
         $id_default_lang = Configuration::get('PS_LANG_DEFAULT');
         foreach ($datas['data_return'] as $id_supplier => $products_info) {
             // Get provider datas
             $supplier = new Supplier((int) $id_supplier);
             // get warehouse datas, delivery date and tax for the provider order
             $id_warehouse_data = Tools::getValue('id_warehouse');
             $date_delivery_expected_data = Tools::getValue('date_delivery_expected');
             $tax_rate_data = Tools::getValue('tax_rate');
             $tax_rate_data = $tax_rate_data[$id_supplier];
             // id warehouse
             $id_warehouse = $id_warehouse_data[$id_supplier];
             // delivery date
             $date_delivery_expected = $date_delivery_expected_data[$id_supplier];
             // create the provider order
             $supply_order = new SupplyOrder();
             $supply_order->reference = ErpSupplyOrderClasses::getNextSupplyOrderReference();
             $supply_order->id_supplier = $id_supplier;
             $supply_order->supplier_name = $supplier->name;
             $supply_order->id_warehouse = $id_warehouse;
             $supply_order->id_currency = $id_default_currency;
             $supply_order->id_lang = $id_default_lang;
             $supply_order->id_supply_order_state = 1;
             $supply_order->id_ref_currency = (int) Currency::getDefaultCurrency()->id;
             $supply_order->date_delivery_expected = $date_delivery_expected;
             // if recording is ok, create the order lines
             if ($supply_order->add()) {
                 // get the provider id order
                 $id_supply_order = $this->getLastIdSupplyOrder();
                 $supply_order_created[] = $id_supply_order;
                 // Ajout de son historique
                 // add historical
                 $history = new SupplyOrderHistory();
                 $history->id_supply_order = $id_supply_order;
                 $history->id_state = 3;
                 $history->id_employee = (int) $this->context->employee->id;
                 $history->employee_firstname = pSQL($this->context->employee->firstname);
                 $history->employee_lastname = pSQL($this->context->employee->lastname);
                 $history->save();
                 // Create entries for provider order
                 if (!empty($products_info)) {
                     $i = 0;
                     foreach ($products_info as $item) {
                         if (!isset($item['product_id'])) {
                             continue;
                         }
                         $supply_order_detail = new SupplyOrderDetail();
                         $supply_order_detail->id_supply_order = $id_supply_order;
                         $supply_order_detail->id_currency = (int) Currency::getDefaultCurrency()->id;
                         $supply_order_detail->id_product = $item['product_id'];
                         $supply_order_detail->id_product_attribute = $item['product_attribute_id'];
                         $supply_order_detail->reference = $item['product_reference'];
                         $supply_order_detail->supplier_reference = $item['product_supplier_reference'];
                         $supply_order_detail->name = $item['product_name'];
                         $supply_order_detail->ean13 = $item['product_ean13'];
                         $supply_order_detail->upc = $item['product_upc'];
                         $supply_order_detail->quantity_expected = $item['total_product_quantity'];
                         $supply_order_detail->exchange_rate = 1;
                         $supply_order_detail->unit_price_te = $item['unit_price_tax_excl'];
                         $supply_order_detail->tax_rate = $tax_rate_data[$i];
                         $supply_order_detail->save();
                         // Get the supply order created
                         $id_supply_order_detail = $this->getLastIdSupplyOrderDetail();
                         // Record the relation between provider order and customer order
                         if (!empty($item)) {
                             foreach ($item['concerned_id_order_detail'] as $customer_link) {
                                 $supply_order_customer = new ErpSupplyOrderCustomer();
                                 $supply_order_customer->id_customer = $customer_link['id_customer'];
                                 $supply_order_customer->id_order_detail = $customer_link['id_order_detail'];
                                 $supply_order_customer->id_supply_order_detail = $id_supply_order_detail;
                                 $supply_order_customer->id_supply_order = $id_supply_order;
                                 $supply_order_customer->save();
                             }
                         }
                         $i++;
                     }
                     // Rerecording provider order data to update totals
                     $supply_order->save();
                 }
             }
         }
         // update provider order status
         if (!empty($datas['order_to_change_state'])) {
             foreach ($datas['order_to_change_state'] as $id_order) {
                 $order_change_state = new Order((int) $id_order);
                 $order_change_state->setCurrentState($this->generate_order_state_to, (int) $this->context->employee->id);
             }
         }
         $this->confirmations[] = $this->l('Order saved successfully !');
         // remove treated order in cookies
         $this->context->cookie->__unset('unselected_orders');
     } else {
         $this->errors[] = Tools::displayError($this->l('No data available for ordering ! You must select at least one order.'));
     }
     $this->context->smarty->assign(array('content' => '', 'show_toolbar ' => 'true', 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->l('Supply Order : order screen'), 'toolbar_scroll' => $this->toolbar_scroll, 'token' => $this->token, 'url_post' => self::$currentIndex . '&token=' . $this->token, 'supply_order_created' => !empty($supply_order_created) ? implode(',', $supply_order_created) : ''));
     $this->createTemplate('ordering.tpl');
     $this->template = 'ordering.tpl';
 }