diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index e165e62..77802f1 100644 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -120,6 +120,7 @@ class Pages extends CI_controller $isTimeout = false; return $isTimeout; + //return false; } public function currentTime() @@ -1104,18 +1105,28 @@ class Pages extends CI_controller $dob = $this->input->post("dob"); if(!$this->isDateValid($dob)) - echo json_encode(array("success"=>false, "data" => "Invalid Date Format")); + { + if($dob != null) + { + echo json_encode(array("success"=>false, "data" => "Invalid Date Format")); + return; + } + } $this->load->model("Customer"); $this->Customer->lastname = $this->input->post("lastname"); $this->Customer->firstname = $this->input->post("firstname"); - $this->Customer->dob = $this->convertToMysqlFormatDate($dob); + if($dob == null) + $this->Customer->dob = null; + else + $this->Customer->dob = $this->convertToMysqlFormatDate($dob); $this->Customer->contactinfo = $this->input->post("contactinfo"); $this->Customer->emailadd = $this->input->post("emailadd"); $this->Customer->address = $this->input->post("address"); echo json_encode($this->Customer->addNewCustomer()); + return; } public function addNewCustomerCard() @@ -1263,10 +1274,23 @@ class Pages extends CI_controller } $this->load->view('pages/customer', $data); - } + } - public function kcardtransaction() - { + + public function customerSearch() + { + $this->load->model("Customer"); + + $result = $this->Customer->getCustomerByLastnameFirstname($this->input->get("s")); + + if($result->num_rows() > 0) + echo json_encode(array("success"=>true, "data"=>$result->result())); + else + echo json_encode(array("success"=>false, "data"=>"No result")); + } + + public function kcardtransaction() + { if(!$this->isLogged()) redirect('login', 'refresh'); @@ -1666,7 +1690,7 @@ class Pages extends CI_controller } } - redirect('/stockinnew/transDate?transDate='.$this->input->get("transDate", true), 'refresh'); + redirect('/stockinnew?transDate='.$this->input->get("transDate", true), 'refresh'); } public function stockinmaintenancenew() @@ -1948,6 +1972,7 @@ class Pages extends CI_controller $this->load->model("Sales"); $this->load->model("BranchItemLedger"); $this->load->model("Items"); + $this->load->model("SalesCustomer"); $this->form_validation->set_rules('txtInvoiceNo', 'Invoice', 'trim|required'); $this->form_validation->set_rules('txtModelNo', 'Model No', 'trim|required'); @@ -2022,10 +2047,20 @@ class Pages extends CI_controller if($this->BranchItemLedger->addNewData() == false) $this->Sales->deleteSales($recordID); } + + if($this->input->post("txtCustomerID") != null) + { + $this->SalesCustomer->recordID = $recordID; + $this->SalesCustomer->customerid = $this->input->post("txtCustomerID"); + + $this->SalesCustomer->addSalesCustomer(); + } } - } - $this->salesnew(); + redirect("/salesnew?transDate=".$this->input->get("transDate", true), "refresh"); + } + else + $this->salesnew(); } diff --git a/application/models/Customer.php b/application/models/Customer.php index f999cc7..06d9e72 100644 --- a/application/models/Customer.php +++ b/application/models/Customer.php @@ -30,6 +30,11 @@ class Customer extends CI_Model return $this->db->order_by($col, $order)->get("customer"); } + public function getCustomerByLastnameFirstname($name) + { + return $this->db->like("CONCAT(lastname, ', ', firstname)", $name)->get("customer"); + } + public function addNewCustomer() { diff --git a/application/models/SalesCustomer.php b/application/models/SalesCustomer.php new file mode 100644 index 0000000..e91c729 --- /dev/null +++ b/application/models/SalesCustomer.php @@ -0,0 +1,35 @@ +load->database(); + } + + public function getSalesCustomerByRecordIDCustomerID() + { + return $this->db->get_where("salescustomer", array("recordID"=>$this->recordID, "customerid"=>$this->customerid)); + } + + + public function addSalesCustomer() + { + $data = array( + "recordID" => $this->recordID, + "customerid" => $this->customerid + ); + + $success = $this->db->insert("salescustomer", $data); + + if($success) + return array("success"=>$success, "data" => $data); + else + return array("success"=>$success, "data" => $this->db->error()); + } +} \ No newline at end of file diff --git a/application/views/pages/salesnewwithcustomer.php b/application/views/pages/salesnewwithcustomer.php index 2b4d352..5775ab7 100644 --- a/application/views/pages/salesnewwithcustomer.php +++ b/application/views/pages/salesnewwithcustomer.php @@ -34,7 +34,7 @@