Exemplo n.º 1
0
 function addSales($sale = null)
 {
     if ($sale == null) {
         $sale = $this;
     }
     $sale_id = $this->db_handler->add_model($sale);
     if (is_array($this->sales_items) and count($this->sales_items) != 0) {
         foreach ($this->sales_items as $sales_item) {
             $sales_item->sale_id = $sale_id;
             $sales_item->company_id = $sale->company_id;
             $sales_item->addSaleItem();
             $inv = new inventry();
             $inv->company_id = $sale->company_id;
             $inv->item_id = $sales_item->item_id;
             $invs = $inv->getInventryForSpecificCompanyAndItem();
             $inv = $invs[0];
             $inv->in_stock_count = $inv->in_stock_count - $sales_item->quantity;
             $inv->updateInventry();
         }
     }
     $description = "Added new Sale (" . $sale->to_string() . ")";
     $customer = new customer();
     $customer->id = $sale->customer_id;
     $customer->getCustomer();
     $customer->total_purchace_amount = $customer->total_purchace_amount + $sale->amount;
     $customer->updateCustomer();
     Log::i($this->tag, $description);
     return $sale_id;
 }
             }
             $responce = array('status' => 'failed', 'error' => $error_message, 'data' => array());
         }
     } else {
         $responce = array('status' => 'failed', 'error' => 'Data missing', 'data' => array());
     }
 } else {
     if ($form_id == 6) {
         ///edit customer
         if (isset($_POST['customer_id']) and !empty($_POST['customer_id']) and isset($_POST['customer_name']) and !empty($_POST['customer_name']) and isset($_POST['contact_number']) and !empty($_POST['contact_number'])) {
             $customer = new customer();
             $customer->id = $_POST['customer_id'];
             $customer->getCustomer();
             $customer->customer_name = $_POST['customer_name'];
             $customer->contact_number = $_POST['contact_number'];
             if ($customer->updateCustomer()) {
                 $message = "Customer Updated Successfuly";
                 $responce = array('status' => 'success', 'error' => '', 'data' => array("message" => $message, "id" => $customer->id));
             } else {
                 $description = "Customer update failed, Customer : " . $customer->to_string();
                 Log::e($tag, $description);
                 $mysql_error = mysql_error();
                 if (empty($mysql_error)) {
                     $error_message = 'Some server error occured';
                 } else {
                     $error_message = $mysql_error;
                 }
                 $responce = array('status' => 'failed', 'error' => $error_message, 'data' => array());
             }
         } else {
             $responce = array('status' => 'failed', 'error' => 'Data missing', 'data' => array());
Exemplo n.º 3
0
} elseif (isset($_GET['action']) && $_GET['action'] == 'edit') {
    $id = $_GET['id'];
    $smarty->assign('customer', $customer->getCustomer($id));
    $smarty->assign('billing', $customer->getCustomerBilling($id));
    $smarty->assign('shipping', $customer->getCustomerShipping($id));
    $smarty->assign('tax', $customer->getCustomerTax($id));
    $smarty->assign('content', $smarty->fetch('editcustomer.tpl'));
} elseif (isset($_POST['action']) && $_POST['action'] == 'add') {
    $data = $_POST['data']['Customer'];
    if ($customer->addCustomer($data)) {
        header('Location: ' . FRONTEND . 'customer.php');
        exit;
    }
} elseif (isset($_POST['action']) && $_POST['action'] == 'update') {
    $data = $_POST['data']['Customer'];
    if ($customer->updateCustomer($data)) {
        header('Location: ' . FRONTEND . 'customer.php');
        exit;
    }
} elseif (isset($_GET['action']) && $_GET['action'] == 'search') {
    $keyword = $_POST['keywords'];
    $smarty->assign('customer', $customer->getSearchCustomers($keyword));
    $smarty->assign('content', $smarty->fetch('customerlist.tpl'));
} else {
    $page = 1;
    if (isset($_GET['page'])) {
        $page = $_GET['page'];
    }
    $customers = $customer->getCustomers($page, $offset = 10);
    $smarty->assign('customercount', $customer->getCustomersCount());
    $smarty->assign('page', $page);