Merge pull request 'Added customer record on sales' (#5) from paulcortezl5 into main

Reviewed-on: #5
pull/6/head
paul 2 years ago
commit dab7dc2f1a

@ -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();
}

@ -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()
{

@ -0,0 +1,35 @@
<?php
class SalesCustomer extends CI_Model
{
public $recordID;
public $customerid;
public function __construct()
{
parent::__construct();
$this->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());
}
}

@ -34,7 +34,7 @@
<!-- Modal Customer Information -->
<div id="mdlCustomer" class="modal fade" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
@ -43,23 +43,96 @@
</div>
<!-- form start -->
<div class="modal-body">
<div class="row">
<div class="box box-success">
<div class="box-header with border">
<h4 class="box-title">Search for Existing Customer</h4>
</div>
<div class="box-body">
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label for="txtCustomerSearch">Customer Name</label>
<div class="input-group">
<input type="text" class="form-control" id="txtCustomerSearch" name="txtCustomerSearch">
<span class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" >Search</button>
<button type="button" class="btn btn-info btn-flat" onclick="searchCustomerByName()">Search</button>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<table id="dtCustomerList" class="table table-bordered table-striped">
<thead><th>ID</th><th>Name</th><th>Date of Birth</th><th>Contact Info</th><th>e-Mail Address</th><th>Address</th><th>&nbsp;</th></thead>
<tbody id="dtCustomerListBody">
<tr><td colspan="7">No data</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>You may search for an existing customer above by searching for the last name and first name <i>(FORMAT: Dela Cruz, Juan)</i> or you can add a new record below.</p>
<div class="box box-warning">
<div class="box-header with border">
<h4 class="box-title">OR Add New Customer</h4>
</div>
<div class="box-body">
<div class="row">
<div class="col-lg-6 col-xs-12">
<div class="form-group">
<label>Enter Full Name <i>(Last name, first name)</i></label>
<input type="text" class="form-control" id="txtLastName" name="txtLastName" placeholder="Last Name">
</div>
</div>
<div class="col-lg-6 col-xs-12">
<div class="form-group">
<label>&nbsp;</label>
<input type="text" class="form-control" id="txtFirstName" name="txtFirstName" placeholder="First Name">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-4 col-xs-12">
<div class="form-group">
<label>Select Date of Birth</label>
<input id="dtDOB" name="dtDOB" type="text" class="form-control datepicker" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask>
</div>
</div>
<div class="col-lg-4 col-xs-12">
<div class="form-group">
<label>Enter Contact Information</label>
<input type="text" class="form-control" id="txtContactInfo" name="txtContactInfo" placeholder="Mobile or Landline">
</div>
</div>
<div class="col-lg-4 col-xs-12">
<div class="form-group">
<label>Enter e-Mail Address</label>
<input type="text" class="form-control" id="txtEmail" name="txtEmail" placeholder="myemail@gmail.com">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-xs-12">
<div class="form-group">
<label>Home Address</label>
<input type="text" class="form-control" id="txtAddress" name="txtAddress" placeholder="Address">
</div>
</div>
</div>
</div>
<div class="box-footer">
<div class="row">
<div class="col-lg-12 col-xs-12">
<button id="btnAddCustomer" type="button" class="btn btn-primary" onclick="addCustomer()">Add Customer</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close Customer Selection</button>
</div>
</div>
<!-- /.modal-content -->
@ -96,8 +169,8 @@
<small>it all starts here</small>
</h1>
<ol class="breadcrumb">
<li><a href="<?php echo site_url(); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="<?php echo site_url(); ?>salesnew">Sales Transaction</a></li>
<li><a href="<?= site_url(); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="<?= site_url(); ?>salesnew">Sales Transaction</a></li>
<li class="active">New Sales</li>
</ol>
</section>
@ -136,7 +209,8 @@
if($this->input->get("transDate", true) != null)
{
?>
<form action="addSalesNew?transDate=<?= $selectedDate ?>" method="post" class="box">
<form action="<?= site_url(); ?>addSalesNew?transDate=<?= $selectedDate ?>" method="post">
<div class="box">
<div class="box-header">
<h3>New Sales for date <?= $selectedDate ?></h3>
</div>
@ -150,11 +224,13 @@
</div>
<div class="col-lg-7 col-xs-12">
<div class="form-group">
<label for="txtCustomer">Customer Name</label>
<label for="txtCustomerName">Customer Name</label>
<div class="input-group">
<input type="text" class="form-control" id="txtCustomer" name="txtCustomer" disabled="true">
<span class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" data-dismiss="modal" data-toggle="modal" data-target="#mdlCustomer">Customer Info</button>
<input type="hidden" name="txtCustomerID" id="txtCustomerID">
<input type="hidden" name="txtCustomer" id="txtCustomer">
<input type="text" class="form-control" id="txtCustomerName" name="txtCustomerName" disabled="true">
<span class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" data-dismiss="modal" data-toggle="modal" data-target="#mdlCustomer">Customer Info</button>
</span>
</div>
</div>
@ -279,6 +355,7 @@
<button type="submit" class="btn btn-primary">Save changes</button>
<a href="<?= site_url(); ?>salesnew?transDate=<?= $selectedDate ?>" class="btn btn-default">Back to Sales</a>
</div>
</div>
</form>
<?php
}
@ -352,6 +429,85 @@
$("#txtBalance").val(balance.toFixed(2));
}
function searchCustomerByName()
{
$("#dtCustomerListBody").html('<tr><td colspan="7">Searching for data. Please wait...</td></tr>');
var dtCustomerListBodyHtml = "";
$.get("/customerSearch", {s:$("#txtCustomerSearch").val()}, function(data){
if(data["success"])
{
data["data"].forEach(function(data){
dtCustomerListBodyHtml += "<tr>" +
"<td>"+data.customerid+"</td>" +
"<td>"+data.lastname+", "+data.firstname+"</td>" +
"<td>"+data.dob+"</td>" +
"<td>"+data.contactinfo+"</td>" +
"<td>"+data.emailadd+"</td>" +
"<td>"+data.address+"</td>" +
'<td><button class="btn btn-default" data-customerid="'+data.customerid+'" data-customername="['+data.customerid+'] '+data.lastname+', '+data.firstname+'" onclick="selectCustomer(this)">Use This record</button></td>' +
"</tr>"
});
$("#dtCustomerListBody").html(dtCustomerListBodyHtml);
}
else
{
$("#dtCustomerListBody").html('<tr><td colspan="7">No records found.</td></tr>');
}
}, "json");
}
function selectCustomer(customer)
{
$("#txtCustomerID").val($(customer).data("customerid"));
$("#txtCustomer").val($(customer).data("customername"));
$("#txtCustomerName").val($(customer).data("customername"));
$("#mdlCustomer").modal('hide');
}
function errorMessage(msg)
{
return '<div class="alert alert-danger alert-dismissable">'+
'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+
'<h4><i class="icon fa fa-ban"></i> Opppppps!</h4>'+
'<div>' + msg + '</div>'+
'</div>'
}
function addCustomer()
{
$("#btnAddCustomer").prop("disabled", true);
var inputdata = {
lastname:$("#txtLastName").val(),
firstname:$("#txtFirstName").val(),
dob:$("#dtDOB").val(),
contactinfo:$("#txtContactInfo").val(),
emailadd:$("#txtEmail").val(),
address:$("#txtAddress").val()
};
$.post("addNewCustomer", inputdata, function(data){
$("#btnAddCustomer").prop("disabled", false);
if(data["success"] == true)
{
$("#mdlCustomer").modal("hide");
$("#txtCustomerID").val(data["data"]);
$("#txtCustomer").val('['+data["data"]+'] ' + $("#txtLastName").val() + ', ' + $("#txtFirstName").val());
$("#txtCustomerName").val('['+data["data"]+'] ' + $("#txtLastName").val() + ', ' + $("#txtFirstName").val());
}
else
{
$("#mdlCustomer .modal-body").prepend(errorMessage("Error saving data. " + data["data"]));
}
}, "json");
}
</script>
</body>
</html>

Loading…
Cancel
Save