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;
 }
Ejemplo n.º 2
0
 public function index()
 {
     $this->view->addCss('dashboard/index.css');
     $stockService = new StockService();
     $itemsLowInStock = $stockService->fetchLowInStock();
     $currentDate = date('Y-m-d');
     $totalExpenses = $this->_getTotalExpense($currentDate);
     $totalSales = 0;
     $overdueCredits = array();
     $salesTransactionService = new SalesTransactionService();
     $totalSales = $salesTransactionService->fetchTotalSales($currentDate);
     $creditService = new CreditService();
     $overdueCredits = $creditService->fetchOverdueCredits();
     $this->renderView('index', array('itemsLowInStock' => $itemsLowInStock, 'totalExpenses' => $totalExpenses, 'totalSales' => $totalSales, 'overdueCredits' => $overdueCredits));
 }