Ejemplo n.º 1
0
 public function processSalesForm($data)
 {
     $this->db->trans_begin();
     $salesTransactionId = null;
     try {
         Debug::log($data);
         $customerService = new CustomerService();
         $customerId = $customerService->saveOrUpdate($data);
         $data['customerId'] = $customerId;
         $salesTransactionService = new SalesTransactionService();
         $salesTransactionId = $salesTransactionService->insert($data);
         $data['salesTransactionId'] = $salesTransactionId;
         $salesObjs = $this->marshallSales($data);
         $salesObjs = $this->mergeSimilarItems($salesObjs);
         $totals = $this->saveAndComputeTotal($salesObjs);
         $data['totalPrice'] = $totals['totalPrice'];
         $data['totalVatable'] = $totals['totalVatable'];
         $data['totalVat'] = $totals['totalVat'];
         Debug::log('removing items from the stocks');
         $this->removeItemsFromStocks($salesObjs);
         Debug::log('updating sales transaction data');
         $salesTransactionService->update($data);
         $this->_createCreditPayment($data);
     } catch (Exception $e) {
         $this->db->trans_rollback();
         throw new Exception($e->getMessage());
     }
     $this->db->trans_commit();
     return $salesTransactionId;
 }