Пример #1
0
 public function delete($cid = array())
 {
     $producthelper = new producthelper();
     $order_functions = new order_functions();
     $quotationHelper = new quotationHelper();
     $stockroomhelper = new rsstockroomhelper();
     if (count($cid)) {
         if (ECONOMIC_INTEGRATION == 1) {
             $economic = new economic();
             for ($i = 0; $i < count($cid); $i++) {
                 $orderdata = $this->getTable('order_detail');
                 $orderdata->load($cid[$i]);
                 $invoiceHandle = $economic->deleteInvoiceInEconomic($orderdata);
             }
         }
         $cids = implode(',', $cid);
         $db = JFactory::getDbo();
         $order_item = $order_functions->getOrderItemDetail($cids);
         for ($i = 0; $i < count($order_item); $i++) {
             $quntity = $order_item[$i]->product_quantity;
             $order_id = $order_item[$i]->order_id;
             $order_detail = $order_functions->getOrderDetails($order_id);
             if ($order_detail->order_payment_status == "Unpaid") {
                 // Update stock roommanageStockAmount
                 $stockroomhelper->manageStockAmount($order_item[$i]->product_id, $quntity, $order_item[$i]->stockroom_id);
             }
             $producthelper->makeAttributeOrder($order_item[$i]->order_item_id, 0, $order_item[$i]->product_id, 1);
             $query = "DELETE FROM `" . $this->_table_prefix . "order_attribute_item` " . "WHERE `order_item_id` = " . $order_item[$i]->order_item_id;
             $this->_db->setQuery($query);
             $this->_db->query();
             $query = "DELETE FROM `" . $this->_table_prefix . "order_acc_item` " . "WHERE `order_item_id` = " . $order_item[$i]->order_item_id;
             $this->_db->setQuery($query);
             $this->_db->query();
         }
         $query = 'DELETE FROM ' . $this->_table_prefix . 'orders WHERE order_id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $query = 'DELETE FROM ' . $this->_table_prefix . 'order_item WHERE order_id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $query = 'DELETE FROM ' . $this->_table_prefix . 'order_payment WHERE order_id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $query = 'DELETE FROM ' . $this->_table_prefix . 'order_users_info WHERE order_id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $quotation = $quotationHelper->getQuotationwithOrder($cids);
         for ($q = 0; $q < count($quotation); $q++) {
             $quotation_item = $quotationHelper->getQuotationProduct($quotation[$q]->quotation_id);
             for ($j = 0; $j < count($quotation_item); $j++) {
                 $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation_fields_data ' . 'WHERE quotation_item_id=' . $quotation_item[$j]->quotation_item_id;
                 $this->_db->setQuery($query);
                 if (!$this->_db->query()) {
                     $this->setError($this->_db->getErrorMsg());
                     return false;
                 }
             }
             $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation_item ' . 'WHERE quotation_id=' . $quotation[$q]->quotation_id;
             $this->_db->setQuery($query);
             if (!$this->_db->query()) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
         }
         $query = 'DELETE FROM ' . $this->_table_prefix . 'quotation WHERE order_id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     }
     return true;
 }