Invoice : ps

This commit is contained in:
VE10-Sanjeev 2023-09-11 09:57:26 +05:30
parent e217655986
commit 996016a2e6
12 changed files with 789 additions and 565 deletions

View File

@ -95,8 +95,11 @@ $routes->get("new_event/(:any)", "Event::new_event/$1");
$routes->post("insert_event/", "Event::insert_event");
#invoices
$routes->get("invoice_list/", "Invoice::index");
$routes->get("new_invoice/", "Invoice::new_invoice/");
$routes->get("new_invoice/(:any)", "Invoice::new_invoice/$1");
$routes->post("load_details1/", "Invoice::load_details1/");
$routes->post("load_details2/", "Invoice::load_details2/");
$routes->post("save_invoice/", "Invoice::save_invoice/");
$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1");

View File

@ -242,6 +242,7 @@ class Authentication extends BaseController
// Clear session data and perform logout logic
$session->destroy();
// $cookie = \Config\Services::cookie();
// $cookie->delete('ci_session');
// $remembered_username = $cookie->getCookie('remember_username');
// $cookie->delete('remember_username');

View File

@ -191,104 +191,5 @@ class Customer extends BaseController
$address_details = $model->where($where)->findAll();
return $address_details;
}
## ApiIntegration For Customer.
public function apiintegration()
{
helper('apiIntegration');
helper('session');
$session_bid = get_business_id();
$session_uid = get_logged_user_id();
$response = perform_http_request('GET', VB_CUSTOMERS);
$message = "";
if (count($response['response']) > 0) {
//$message = "Reponse Count : ".count($response['response'])." <br/>";
echo "Note : This For CrossCheck Purpose 1ly <br/>";
echo "Total Customer API Reponse Count : " . count($response['response']) . " <br/>";
$CustomerModel = new CustomerModel();
$x=0;
foreach ($response['response'] as $row) {
$insertion_data['first_name'] = $row->first_name;
$insertion_data['last_name'] = $row->last_name;
$insertion_data['type'] = $row->role;
$insertion_data['email'] = $row->email;
// $insertion_data['profile_picture'] = $row->avatar_url;
$insertion_data['mode'] = 'online';
$insertion_data['created_by'] = $session_uid;
$insertion_data['business_id'] = $session_bid;
$billing = $row->billing;
$shipping = $row->shipping;
$CustomerModel->insert($insertion_data);
$lastInsertId = $CustomerModel->insertID();
$insertion_baddress_data = [];$insertion_saddress_data = [];
$i = 0; $j = 0;
if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];}
if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];}
echo "Customer ID : ".$lastInsertId." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)." <br/>";
if (count($billing) > 0) {
foreach ($billing as $bill) {
if ($bill->first_name !== '') {
$insertion_baddress_data[$i]['first_name'] = $bill->first_name;
$insertion_baddress_data[$i]['last_name'] = $bill->last_name;
$insertion_baddress_data[$i]['company'] = $bill->company;
$insertion_baddress_data[$i]['address_1'] = $bill->address_1;
$insertion_baddress_data[$i]['address_2'] = $bill->address_2;
$insertion_baddress_data[$i]['city'] = $bill->city;
$insertion_baddress_data[$i]['state'] = $bill->state;
$insertion_baddress_data[$i]['country'] = $bill->country;
$insertion_baddress_data[$i]['postal_code'] = $bill->postcode;
$insertion_baddress_data[$i]['customer_id'] = $lastInsertId;
$insertion_baddress_data[$i]['address_type'] = 1;
$insertion_baddress_data[$i]['created_by'] = $session_uid;
$insertion_baddress_data[$i]['email'] = isset($bill->email) ? $bill->email : '';
$insertion_baddress_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : '';
$i++;
echo "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Billing address has a value and Inserted ".$i." <br/>";
}else{
echo "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Keys are available but Billing address has no value; <br/>";
}
}
(!empty($insertion_baddress_data) ? $CustomerModel->insertAddressBatch($insertion_baddress_data) : "");
}
if (count($shipping) > 0) {
foreach ($shipping as $ship) {
if ($ship->first_name !== '') {
$insertion_saddress_data[$j]['first_name'] = $ship->first_name;
$insertion_saddress_data[$j]['last_name'] = $ship->last_name;
$insertion_saddress_data[$j]['company'] = $ship->company;
$insertion_saddress_data[$j]['address_1'] = $ship->address_1;
$insertion_saddress_data[$j]['address_2'] = $ship->address_2;
$insertion_saddress_data[$j]['city'] = $ship->city;
$insertion_saddress_data[$j]['state'] = $ship->state;
$insertion_saddress_data[$j]['country'] = $ship->country;
$insertion_saddress_data[$j]['postal_code'] = $ship->postcode;
$insertion_saddress_data[$j]['email'] = isset($ship->email)?$ship->email:"";
$insertion_saddress_data[$j]['mobile_no'] = isset($ship->phone)?$ship->phone:"";
$insertion_saddress_data[$j]['customer_id'] = $lastInsertId;
$insertion_saddress_data[$j]['address_type'] = 2;
$insertion_saddress_data[$j]['created_by'] = $session_uid;
$j++;
echo "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Shipping address has a value and Inserted ".$j." <br/>";
}
else{
echo "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; Keys are available but Shipping address has no value <br/>";
}
}
(!empty($insertion_saddress_data) ? $CustomerModel->insertAddressBatch($insertion_saddress_data) : "");
}
} //reponse foreach closed
} //reponse count if closed
if (!empty($response['error'])) {
echo $response['error'];
echo $response['error_msg'];
$message .= $response['error'] . $response['error_msg'];
echo "Error :".$response['error'] . $response['error_msg'];
}else{
echo "Done";
}
$go_to_list_page = base_url()."customer_list";
echo "<center><a href=".$go_to_list_page.">go to list page</a></center>";
// return $message;
}
}

View File

@ -16,14 +16,12 @@ class Invoice extends BaseController
$session_bid = get_business_id();
if (!empty($session_role) && $session_role !== "sadmin") {
$where = ['invoice.business_id'=>(int)$session_bid];
}else{ $where = ['invoice.business_id != '=>NULL];}
$InvoiceModel = new InvoiceModel();
$where = ['I.business_id'=>(int)$session_bid,'I.isactive' => 0];
}else{ $where = ['I.business_id != '=>NULL,'I.isactive != ' => NULL];}
$model = new InvoiceModel();
$data['page_name'] = 'Invoice Details';
// $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
// $data['invoice'] = $InvoiceModel->getAllSubscribersWithNames($where);
$data['invoice'] = $model->getJoinedData($where);
$this->render_page('invoice_list', $data);
}else {
return redirect()->to('login');
@ -31,23 +29,205 @@ class Invoice extends BaseController
}
public function new_invoice()
public function new_invoice($id)
{
helper('session');
$session_bid = get_business_id();
$data['page_name'] = 'Invoice Details';
$customerModel = new CustomerModel();
$eventModel = new EventModel();
$business_id = get_business_id();
$model = new InvoiceModel();
$where = ['business_id'=>(int)get_business_id()];
// Get customer names for the dropdown
$data['customers'] = $customerModel->getCustomerNamesByBusiness($business_id);
$data['events']= $eventModel->getEventnamesByBusiness($business_id);
// Initialize billing and shipping addresses as empty
$data['billingAddress'] = '';
$data['shippingAddress'] = '';
$data['customers'] = $model->getData('customers',$where);
$data['events']= $model->getData('events',$where);
$data['books']= $model->getData('books',$where);
if ($id === '0') {
$data['page_name'] = 'Add Invoice Details';
$data['invoice_details'] = [];
$data['invoice_item_details'] = [];
} else if ($id !== '0') {
$data['page_name'] = 'Edit Invoice Details';
$data['invoice_details'] = $model->where(['invoice_id' => $id,'isactive' => 1])->first();
$data['invoice_item_details'] = $this->get_invoice_item($id);
}
$this->render_page('invoice_form', $data);
}
public function load_details1()
{
$id = $this->request->getPost('selectedValue');
$where = ['isactive' => 1, 'customer_id' => (int)$id];
$where['address_type'] = 1;
$data['customer_billing'] = $this->get_customer_address($where,[]);
$select = ["customer_address_id","CONCAT(address_1,' ',address_2) as address"];
$where['address_type'] = 2;
$data['customer_shipping'] = $this->get_customer_address($where,$select);
return $this->response->setJSON(['data' => $data]);
}
public function load_details2()
{
$customer_id = $this->request->getPost('customerValue');
$address_id = $this->request->getPost('selectedValue');
$where = ['isactive' => 1, 'customer_id' => (int)$customer_id,'address_type'=>2,'customer_address_id'=>(int)$address_id];
$data['customer_shipping'] = $this->get_customer_address($where,[]);
return $this->response->setJSON(['data' => $data]);
}
public function get_customer_address($where,$select){
$model = new CustomerModel();
$model->setTable('customer_addresses');
if(!empty($select)){
$address_details = $model->select($select)->where($where)->findAll();
}else{
$address_details = $model->where($where)->findAll();
}
return $address_details;
}
public function save_invoice(){
helper('session');
$model = new InvoiceModel();
// print_r($this->request->getPost());
// echo "<br/><br/>";
// Array ( [customer_name] => 1 [shipping_address] => 2 [event_next_id] => 134 [event_id] => 1 [invoice_number] => NBF2023-INV-00133 [order_number] => 12 [invoice_date] => 2023-09-07 [due_date] => 2023-09-07 [item_details] => Array ( [0] => 1 ) [quantity] => Array ( [0] => 2 [1] => 2 ) [rate] => Array ( [0] => 3 [1] => 3 ) [tax] => [amount] => Array ( [0] => 5 [1] => 5 ) [itemDetails] => Array ( [0] => 1 ) [subtotal] => [discount] => 9 [total] => [terms] => i don't like... )
$duedate = $this->request->getVar('due_date');
$invdate = $this->request->getVar('invoice_date');
$data = [
'invoice_number' => $this->request->getPost('invoice_number'),
'customer_id' => (int)$this->request->getPost('customer_name'),
'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
'billing_address' => $this->request->getPost('billing_address'),
'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
'shipping_address' => $this->request->getPost('shipping_address'),
'invoice_date' => date("Y-m-d", strtotime($invdate)),
'due_date' => date("Y-m-d", strtotime($duedate)),
'subtotal' => (int)$this->request->getPost('sub_total'),
'tax' => (int)$this->request->getPost('invoice_tax'),
'discount'=> (int)$this->request->getPost('discount'),
'total_amount'=> (int)$this->request->getPost('grand_total'),
'order_number'=> $this->request->getPost('order_number'),
'payment_method'=> 'Cash on Delivery',// "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
'payment_status'=> 'Pending',//"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
'event_id'=> (int)$this->request->getPost('event_id'),
'business_id'=> (int)get_business_id(),
'isactive'=> 1];
$invoice_id = $this->request->getPost('invoice_id');
if (empty($invoice_id)) {
$data['created_by'] = (int)get_logged_user_id();
$model->insert($data);
$IID = $model->insertID();
// $IID = 1;
} else {
$data['updated_by'] = (int)get_logged_user_id();
$model->update($invoice_id, $data);
$IID = $invoice_id;
// $IID = 1;
}
// print_r($data);
// echo "<br/><br/>";
$requestData = $this->request->getPost();
$update_events=['id'=>$this->request->getPost('event_id'),
'next_id' => $this->request->getPost('event_next_id'),
'business_id' => get_business_id(),
'updated_by' => get_logged_user_id()];
$this->update_events($update_events);
// print_r($update_events);echo "<br/><br/>";
$this->save_invoice_item($IID,$requestData);//die();
return redirect()->route('invoice_list');
}
public function update_events($update_events){
// `id``event_name``business_id``updated_by``updated_on``next_id`
$model = new InvoiceModel();
$model->setTable('events');
$where = ['isactive' => 1, 'id' => (int)$update_events['id'],'business_id'=>(int)$update_events['business_id'],'next_id'=>$update_events['next_id']];
$details = $model->where($where)->findAll();
if(empty($details)){
$update_where = ['id' => (int)$update_events['id'],'business_id'=>(int)$update_events['business_id']];
$update_data = ['next_id'=>$update_events['next_id'],'updated_by'=>$update_events['updated_by']];
$model->updateData('events', $update_data, $update_where);
}
}
public function save_invoice_item($id,$requestData){
// print_r($requestData['invoice_child_id']);
$getInvoiceItemDetails = $this->get_invoice_item($id);
$itemid = $requestData['invoice_child_id'];
$statement = "";
$model = new InvoiceModel();
// IF Any Missing value Means that values are Inactive here....
if(!empty($itemid)){
$filteringInvoiceItemIds = [];
for ($y = 0; $y < count($getInvoiceItemDetails); $y++) {
$filteringInvoiceItemIds[$y] = $getInvoiceItemDetails[$y]['invoice_child_id'];
}
if(!empty($filteringInvoiceItemIds)){
$A = $filteringInvoiceItemIds;
$B = $itemid;
$missingValues = array_diff($A,$B);
if(!empty($missingValues)){
$where = ['isactive'=>1,'invoice_id'=>(int)$id];
$model->inactiveMissingInvoiceItemDetails($where,$missingValues);
}
}
}
// echo "<br/>....................";
$count = count($itemid);
$invoiceitem_arr = [];
if($count > 0){
for ($x = 0; $x < $count; $x++) {
$invoiceitem_arr[$x]['invoice_id'] = $id;
$invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
$invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
$invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x];
$invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x];
$invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x];
$invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
$invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
$invoiceitem_arr[$x]['isactive'] = 1;
$invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
}
$statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
}
return $statement;
}
public function get_invoice_item($id){
$model = new InvoiceModel();
$model->setTable('invoiceitems');
$where = ['isactive' => 1, 'invoice_id' => (int)$id];
$details = $model->where($where)->findAll();
return $details;
}
public function delete_invoice($id){
helper('session');
$model = new InvoiceModel();
$where = ['isactive' => 1, 'business_id' => (int)get_business_id(),'invoice_id' => (int)$id];
$existed = $model->where($where)->findAll();
if ($existed) {
$data['isactive'] = 0;
$data['updated_by'] = get_logged_user_id();
$model->update($id, $data);
$getInvoiceItemDetails = $this->get_invoice_item($id);
if ($getInvoiceItemDetails) {
$update_where = ['invoice_id' => (int)$id];
$model->updateData('invoiceitems', $data, $update_where);
}
}
return redirect()->route('invoice_list');
}
}

View File

@ -15,7 +15,6 @@ class EventModel extends Model
public function getEventnamesByBusiness($business_id)
{
$this->builder()->select('id,event_name');
$this->builder()->where('business_id ', $business_id); // Filter by business_id
$query = $this->builder()->get(); // Use findAll() instead of get()
return ($query->getResult());

View File

@ -7,8 +7,68 @@ class InvoiceModel extends Model
{
protected $table = 'invoice';
protected $primaryKey = 'invoice_id';
protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
// protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'total_amount', 'payment_status', 'order_number', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by', 'isactive','billing_address','shipping_address'];
public function saveInvoiceItemDetails($data){
$i = 0;
$statement = [];
foreach ($data as $row) {
$id = isset($row['invoice_child_id']) ? $row['invoice_child_id'] : '';
if($id != ''){
unset($row['invoice_child_id']); // Remove the id from the data to avoid updating it
unset($row['created_by']); // bcoz here data are Updating here.
$this->db->table('invoiceitems')->where('invoice_child_id', $id)->update($row);// Update the row with the specified id
$affectedRows = $this->db->affectedRows();
$statement[$i] = "Invoice Item - ".$id." ".$affectedRows ? " Updated":" Not Updated";
}else{
unset($row['updated_by']); // bcoz here data are inserting here.
$this->db->table('invoiceitems')->insert($row);
$insertID = $this->db->insertID();
$statement[$i] = "Invoice Item - ".$insertID." Inserted";
}
}
return $statement;
}
public function inactiveMissingInvoiceItemDetails($where,$missingValues){
$dataToUpdate = ['isactive' => 0];
$this->db->table('invoiceitems')->where($where)->whereIn('invoice_child_id',$missingValues)->update($dataToUpdate);
}
public function updateData($table, $data, $where)
{
$this->db->table($table)->update($data, $where);
$affected_rows = $this->db->affectedRows();
return $affected_rows;
}
public function getJoinedData($where)
{
return $this->db->table($this->table.' as I' )
->join('customers as C', 'C.customer_id = I.customer_id', 'left')
->join('events as E', 'E.id = I.event_id', 'left')
->join('business as B', 'B.business_id = I.business_id', 'left')
->join('users as U1', 'U1.user_id = I.created_by', 'left')
->join('users as U2', 'U2.user_id = I.updated_by', 'left')
->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount, I.payment_status, I.order_number, I.payment_method, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive')
->where($where)
->get()
->getResult();
// I.shipping_address_id, I.billing_address_id,
}
public function getData($table, $where = null)
{
$query = $this->db->table($table);
if ($where) {
$query->where($where);
}
return $query->get()->getResult();
}

View File

@ -1,188 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Auth Pages | Create Account | Sign In 2 | Minton - Responsive Admin Dashboard Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description" />
<meta content="Coderthemes" name="author" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- App favicon -->
<link rel="shortcut icon" href="./assets/images/favicon.ico">
<!-- App css -->
<link href="./assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" id="bs-default-stylesheet" />
<link href="./assets/css/app.min.css" rel="stylesheet" type="text/css" id="app-default-stylesheet" />
<link href="./assets/css/bootstrap-dark.min.css" rel="stylesheet" type="text/css" id="bs-dark-stylesheet" />
<link href="./assets/css/app-dark.min.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" />
<!-- icons -->
<link href="./assets/css/icons.min.css" rel="stylesheet" type="text/css" />
</head>
<body class="loading auth-fluid-pages pb-0">
<div class="auth-fluid">
<!-- Auth fluid right content -->
<div class="auth-fluid-right">
<div class="auth-user-testimonial">
<h3 class="mb-3 text-white">Very elegant & impressive!</h3>
<p class="lead font-weight-normal"><i class="mdi mdi-format-quote-open"></i> I've been using this theme for a while and I must say that whenever I am looking for a design - I refer to this theme for specifics & implementation. With wide arrays of components, designs, charts - I would highly recommend this theme for anyone using it for dashboard or project management usage.. <i class="mdi mdi-format-quote-close"></i>
</p>
<h5 class="text-white">
- Admin User
</h5>
</div> <!-- end auth-user-testimonial-->
</div>
<!-- end Auth fluid right content -->
<!--Auth fluid left content -->
<div class="auth-fluid-form-box">
<div class="align-items-center d-flex h-100">
<div class="card-body">
<!-- Logo -->
<div class="auth-brand text-center text-lg-left">
<div class="auth-logo">
<a href="index.html" class="logo logo-dark text-center">
<span class="logo-lg">
<img src="./assets/images/logo-dark.png" alt="" height="22">
</span>
</a>
<a href="index.html" class="logo logo-light text-center">
<span class="logo-lg">
<img src="./assets/images/logo-light.png" alt="" height="22">
</span>
</a>
</div>
</div>
<ul class="nav nav-tabs nav-bordered">
<li class="nav-item">
<a href="#tab-login" data-toggle="tab" aria-expanded="false" class="nav-link active">
Log In
</a>
</li>
<li class="nav-item">
<a href="#tab-signup" data-toggle="tab" aria-expanded="true" class="nav-link">
Sign Up
</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane show active" id="tab-login">
<p class="text-muted mb-3">Enter your email address and password to access admin panel.</p>
<!-- form -->
<form action="#">
<div class="form-group">
<label for="emailaddress">Email address</label>
<input class="form-control" type="email" id="emailaddress" required="" placeholder="Enter your email">
</div>
<div class="form-group">
<a href="auth-recoverpw-2.html" class="text-muted float-right"><small>Forgot your password?</small></a>
<label for="password">Password</label>
<input class="form-control" type="password" required="" id="password" placeholder="Enter your password">
</div>
<div class="form-group mb-3">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="checkbox-signin">
<label class="custom-control-label" for="checkbox-signin">Remember me</label>
</div>
</div>
<div class="form-group mb-0 text-center">
<button class="btn btn-primary btn-block" type="submit">Log In </button>
</div>
<!-- social-->
<div class="text-center mt-4">
<h5 class="mt-3 text-muted">Sign in with</h5>
<ul class="social-list list-inline mt-3">
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-purple text-purple"><i class="mdi mdi-facebook"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-danger text-danger"><i class="mdi mdi-google"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-info text-info"><i class="mdi mdi-twitter"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-secondary text-secondary"><i class="mdi mdi-github"></i></a>
</li>
</ul>
</div>
</form>
<!-- end form-->
</div>
<div class="tab-pane" id="tab-signup">
<p class="text-muted mb-3">Don't have an account? Create your own account, it takes less than a minute</p>
<!-- form -->
<form action="#">
<div class="form-group">
<label for="fullname">Full Name</label>
<input class="form-control" type="text" id="fullname" placeholder="Enter your name" required>
</div>
<div class="form-group">
<label for="emailaddress">Email address</label>
<input class="form-control" type="email" id="emailaddress" required placeholder="Enter your email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input class="form-control" type="password" required id="password" placeholder="Enter your password">
</div>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="checkbox-signup">
<label class="custom-control-label" for="checkbox-signup">I accept <a href="javascript: void(0);" class="text-dark">Terms and Conditions</a></label>
</div>
</div>
<div class="form-group mb-0 text-center">
<button class="btn btn-primary waves-effect waves-light btn-block" type="submit"> Sign Up </button>
</div>
<!-- social-->
<div class="text-center mt-4">
<h5 class="mt-3 text-muted">Sign Up using</h5>
<ul class="social-list list-inline mt-3 mb-0">
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-purple text-purple"><i class="mdi mdi-facebook"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-danger text-danger"><i class="mdi mdi-google"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-info text-info"><i class="mdi mdi-twitter"></i></a>
</li>
<li class="list-inline-item">
<a href="javascript: void(0);" class="social-list-item border-secondary text-secondary"><i class="mdi mdi-github"></i></a>
</li>
</ul>
</div>
</form>
<!-- end form-->
</div>
</div>
<!-- Footer-->
<footer class="footer footer-alt">
<p class="text-muted"><script>document.write(new Date().getFullYear())</script> &copy; Minton theme by <a href="javascript: void(0);" class="text-dark">Coderthemes</a> </p>
</footer>
</div> <!-- end .card-body -->
</div> <!-- end .align-items-center.d-flex.h-100-->
</div>
<!-- end auth-fluid-form-box-->
</div>
<!-- end auth-fluid-->
<!-- Vendor js -->
<script src="./assets/js/vendor.min.js"></script>
<!-- App js -->
<script src="./assets/js/app.min.js"></script>
</body>
</html>

View File

@ -48,29 +48,29 @@
<div class="form-row">
<div class="form-group col-md-12">
<label for="caddress" class="col-form-label">Address<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="address" value="<?= isset($customer['address']) ? $customer['address'] : '' ?>" placeholder="Address (eg : 1234 Main St)" required />
<input type="text" class="form-control" id="caddress" name="address" value="<?= isset($customer['address']) ? $customer['address'] : '' ?>" placeholder="Address (eg : 1234 Main St)" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="ccountry" class="col-form-label">Country<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="ccountry" value="<?= isset($customer['country']) ? $customer['country'] : '' ?>" placeholder="Country" required />
<input type="text" class="form-control" id="ccountry" name="ccountry" value="<?= isset($customer['country']) ? $customer['country'] : '' ?>" placeholder="Country" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-3">
<label for="ccity" class="col-form-label">City<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="ccity" value="<?= isset($customer['city']) ? $customer['city'] : '' ?>" placeholder="City" required />
<input type="text" class="form-control" id="ccity" name="ccity" value="<?= isset($customer['city']) ? $customer['city'] : '' ?>" placeholder="City" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-3">
<label for="cstate" class="col-form-label">State<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="cstate" value="<?= isset($customer['state']) ? $customer['state'] : '' ?>" placeholder="State" required />
<input type="text" class="form-control" id="cstate" name="cstate" value="<?= isset($customer['state']) ? $customer['state'] : '' ?>" placeholder="State" required />
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-3">
<label for="czip" class="col-form-label">Postal Code<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="czip" value="<?= isset($customer['postal_code']) ? $customer['postal_code'] : '' ?>" placeholder="Postal Code (PIN)" required pattern="\d*" maxlength="10" />
<input type="text" class="form-control" id="czip" name="czip" value="<?= isset($customer['postal_code']) ? $customer['postal_code'] : '' ?>" placeholder="Postal Code (PIN)" required pattern="\d*" maxlength="10" />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
@ -90,7 +90,19 @@
<input type="hidden" id="business_id" name="business_id" placeholder="hidden for business id" value="<?= $session_bid ?>" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<br />
<h5> Billing Address </h5>
<div class="form-row">
<div class="col-md-6 text-left">
<h5> Billing Address </h5>
</div>
<div class="col-md-6 text-right checkbox checkbox-purple">
<input type="checkbox" id="copyToBillingCheckbox"/>
<label for="copyToBillingCheckbox"> Is the above address same as the billing address?</label>
</div>
</div>
<div class="after-add-more">
<hr />
<div class="form-group">
@ -158,17 +170,9 @@
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<input type="hidden" id="bcustomer_address_id" name="bcustomer_address_id[]" placeholder="hidden for billing customer address id" />
</div>
<div class="form-group col-md-9 change text-right m-b-0"></div>
</div>
<input type="hidden" id="bcustomer_address_id" name="bcustomer_address_id[]" placeholder="hidden for billing customer address id" />
</div>
</div>
<div class="form-group text-right m-b-0">
<a class="btn btn-success add-more">+ Add More Billing Address </a>
</div>
<br />
<h5> Shipping Address </h5>
<div class="after-add-smore">
@ -213,14 +217,16 @@
<div class="form-group col-md-3">
<input type="hidden" id="scustomer_address_id" name="scustomer_address_id[]" placeholder="hidden for shipping customer address id" />
</div>
<div class="form-group col-md-9 schange text-right m-b-0"></div>
<div class="form-group col-md-9 schange text-right m-b-0">
<!-- <a class="btn btn-success waves-effect waves-light mr-1 add-smore">+ Add More Shipping Address </a> -->
<a class="btn btn-danger waves-effect waves-light mr-1 sremove">- Remove </a>
</div>
</div>
</div>
</div>
<div class="form-group text-right m-b-0">
<a class="btn btn-success add-smore">+ Add More Shipping Address </a>
</div>
<?php if (!empty($customer)) { ?>
<div class="form-group text-right m-b-0 checkbox checkbox-purple">
<input type="checkbox" id="isactive" name="isactive" class="form-control" <?= isset($customer) && $customer['isactive'] == 1 ? 'checked' : '' ?>>
@ -243,40 +249,62 @@
</div> <!-- end col-->
</div>
<script>
$("#copyToBillingCheckbox").on("change", function() {
if ($(this).is(":checked")) {
var customerAddress = $("#caddress").val();
var customerCountry = $("#ccountry").val();
var customerState = $("#cstate").val();
var customerCity = $("#ccity").val();
var customerPostalCode = $("#czip").val();
$("#baddress1").val(customerAddress).prop("readonly", true);
$("#baddress2").val("").prop("readonly", true);
$("#bcountry").val(customerCountry).prop("readonly", true);
$("#bcity").val(customerCity).prop("readonly", true);
$("#bstate").val(customerState).prop("readonly", true);
$("#bzip").val(customerPostalCode).prop("readonly", true);
} else {
// Clear the billing address fields when the checkbox is unchecked
$("#baddress1").val("").prop("readonly", false);
$("#baddress2").val("").prop("readonly", false);
$("#bcountry").val("").prop("readonly", false);
$("#bcity").val("").prop("readonly", false);
$("#bstate").val("").prop("readonly", false);
$("#bzip").val("").prop("readonly", false);
$("#bcustomer_address_id").val("") // Hidden Field ressetted bcoz Adress history
}
});
$(document).ready(function() {
var barray = <?php echo json_encode($customer_billing); ?>;
var carray = <?php echo json_encode($customer); ?>;
if (barray.length > 0) {
for (var i = 0; i < barray.length; i++) {
if (i == 0) {
var html = $(".after-add-more").first();
} else {
var html = $(".after-add-more").first().clone();
if((barray[i]['address_1'] == carray['address']) &&
(barray[i]['city'] == carray['city']) &&
(barray[i]['state'] == carray['state']) &&
(barray[i]['country'] == carray['country']) &&
(barray[i]['postal_code']== carray['postal_code'])){
$("#copyToBillingCheckbox").prop("checked",true);
$("#baddress1").val(barray[i]['address_1']).prop("readonly", true);
$("#baddress2").val(barray[i]['address_2']).prop("readonly", true);
$("#bcountry").val(barray[i]['country']).prop("readonly", true);
$("#bcity").val(barray[i]['city']).prop("readonly", true);
$("#bstate").val(barray[i]['state']).prop("readonly", true);
$("#bzip").val(barray[i]['postal_code']).prop("readonly", true);
}
html.find('input#bcustomer_address_id').val(barray[i]['customer_address_id']);
html.find('input#baddress1').val(barray[i]['address_1']);
html.find('input#baddress2').val(barray[i]['address_2']);
html.find('input#bcity').val(barray[i]['city']);
html.find('input#bstate').val(barray[i]['state']);
html.find('input#bcountry').val(barray[i]['country']);
html.find('input#bzip').val(barray[i]['postal_code']);
if (i !== 0) {
html.find(".change").html("<label for=''>&nbsp;</label><br/><a class='btn btn-danger remove'>- Remove</a>");
html.insertAfter(".after-add-more:last");
else{
$("#baddress1").val(barray[i]['address_1']);
$("#baddress2").val(barray[i]['address_2']);
$("#bcountry").val(barray[i]['country']);
$("#bcity").val(barray[i]['city']);
$("#bstate").val(barray[i]['state']);
$("#bzip").val(barray[i]['postal_code']);
}
$('#bcustomer_address_id').val(barray[i]['customer_address_id']);
}
}
$("body").on("click", ".add-more", function() {
var html = $(".after-add-more").first().clone();
html.find('input').val(''); // Clear input values in the cloned element
html.find(".change").html("<label for=''>&nbsp;</label><br/><a class='btn btn-danger remove'>- Remove</a>");
html.insertAfter(".after-add-more:last");
});
$("body").on("click", ".remove", function() {
$(this).parents(".after-add-more").remove();
});
/*****************************************************************************************/
var sarray = <?php echo json_encode($customer_shipping); ?>;
@ -295,22 +323,40 @@
html.find('input#scountry').val(sarray[i]['country']);
html.find('input#szip').val(sarray[i]['postal_code']);
if (i !== 0) {
html.find(".schange").html("<label for=''>&nbsp;</label><br/><a class='btn btn-danger sremove'>- Remove</a>");
// html.find(".schange").html("<a class='btn btn-success waves-effect waves-light mr-1 add-smore'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 sremove'>- Remove </a>");
html.find(".schange").html("<a class='btn btn-danger waves-effect waves-light mr-1 sremove'>- Remove </a>");
html.insertAfter(".after-add-smore:last");
}
}
}else{
$(".sremove").hide();
$(".add-smore").show();
}
$("body").on("click", ".add-smore", function() {
var html = $(".after-add-smore").first().clone();
html.find('input').val(''); // Clear input values in the cloned element
html.find(".schange").html("<label for=''>&nbsp;</label><br/><a class='btn btn-danger sremove'>- Remove</a>");
// html.find(".schange").html("<a class='btn btn-success waves-effect waves-light mr-1 add-smore'>+ Add More Shipping Address </a><a class='btn btn-danger waves-effect waves-light mr-1 sremove'>- Remove </a>");
html.find(".schange").html("<a class='btn btn-danger waves-effect waves-light mr-1 sremove'>- Remove </a>");
html.insertAfter(".after-add-smore:last");
toggleButtons();
});
$("body").on("click", ".sremove", function() {
$(this).parents(".after-add-smore").remove();
toggleButtons();
});
function toggleButtons() {
var elementCount = $(".after-add-smore").length;
if (elementCount > 1) {
$(".schange").show();
} else {
$(".schange").hide();
}
}
});
</script>

View File

@ -1,211 +1,180 @@
<html>
<body>
<style>
.align-to-right {
float: right;
padding: 30px;
}
.btn btn-primary {
text-align: right;
}
</style>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h4 class="header-title"><?= $page_name; ?></h4>
<p class="sub-header"> </p>
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data"
action="<?php echo base_url(); ?>insert_event">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="customerName">Customer Name</label>
<select class="form-control" id="customerName" onchange="updateCustomerDetails()">
<option value="">Select a customer</option>
<?php foreach ($customers as $customer): ?>
<option value="<?= $customer->customer_id ?>"><?= $customer->full_name ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="invalid-feedback"> Please provide. </div>
<div class="form-group col-md-6">
<label for="shipping">Shipping Address</label>
<select class="form-control" id="shipping">
<!-- Populate this dropdown with customer names -->
<option>Address 1</option>
<option>Address 2</option>
<!-- Add more options as needed -->
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="customerAddress">Billing Address</label>
<textarea class="form-control" id="customerAddress" readonly></textarea>
<!-- JavaScript will populate this field based on the selected customer -->
</div>
<div class="form-group col-md-6">
<label for="subject">Shipping Address</label>
<textarea class="form-control" id="shippingaaddress"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="invoiceNumber">Invoice Number</label>
<input type="text" class="form-control" id="invoiceNumber">
</div>
<div class="form-group col-md-6">
<label for="orderNumber">Order Number</label>
<input type="text" class="form-control" id="orderNumber">
</div>
</div>
</div>
<div class="row">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h4 class="header-title"><?= $page_name; ?></h4>
<p class="sub-header"> </p>
<form method="POST" enctype="multipart/form-data" action="<?php echo base_url(); ?>save_invoice">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
<label for="invoiceDate">Invoice Date</label>
<input type="date" class="form-control" id="invoiceDate">
</div>
<div class="form-group col-md-6">
<label for="dueDate">Due Date</label>
<input type="date" class="form-control" id="dueDate">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="events" class="col-form-label">Events<span
class="text-danger">*</span></label>
<select class="form-control" id="event" name="events" required>
<option value="">Select Events</option>
<?php foreach ($events as $event): ?>
<option value="<?= $event->id ?>"><?= $event->event_name ?></option>
<label for="customerName">Customer Name</label>
<select class="form-control" id="customerName" name="customer_name">
<option value="">Select a customer</option>
<?php foreach ($customers as $customer) : ?>
<option value="<?= $customer->customer_id ?>" <?php if (isset($invoice_details['customer_id']) && ($invoice_details['customer_id'] === $customer->customer_id)) echo "selected"; ?> >
<?= $customer->first_name.' '.$customer->last_name; ?></option>
<?php endforeach; ?>
</select>
<div class="invalid-feedback"> Please select a customer. </div>
</div>
<div class="form-group col-md-6">
<label for="loadShippingDropdown">Shipping Address</label>
<select class="form-control" id="loadShippingDropdown" name="shipping_address_id">
<option value="">Select an address</option>
</select>
</div>
</div>
</form>
<div class="row">
<!-- <button style="float: right;"><i class="fa fa-plus" aria-hidden="true"></i></button> -->
<div class="col-lg-12">
<h5>Item Details</h5>
<br>
<table class="table table-bordered" id="itemTable">
<thead>
<tr>
<th>Item Details</th>
<th>Quantity</th>
<th>Rate</th>
<th>Tax</th>
<th>Amount </th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Dynamically add rows for item details -->
<tr>
<td><input type="text" class="form-control" name="itemDetails[]"></td>
<td><input type="text" class="form-control" name="quantity[]"></td>
<td><input type="text" class="form-control" name="rate[]"></td>
<td><input type="text" class="form-control" name="tax[]"></td>
<td><input type="text" class="form-control" name="amount[]"></td>
<td><i class="fa fa-trash remove-item "></td>
</tr>
<!-- You can add more rows as needed using JavaScript -->
</tbody>
</table>
<button style="float:left;" id="addItem"><i class="fa fa-plus"
aria-hidden="true"></i></button>
<div class="form-row">
<div class="form-group col-md-6">
<label for="storeBillingAddress"> Billing Address &ensp;( <input type="checkbox" id="editAddressesCheckbox"/> Do you want to edit/change addresses?)</label>
<input type="hidden" id="hiddenBillingAddressId" name="billing_address_id" placeholder="hidden for billing address id" value="<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : '' ?>" />
<textarea class="form-control" id="storeBillingAddress" name="billing_address" readonly><?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : '' ?></textarea>
</div>
<div class="form-group col-md-6">
<label for="storeShippingAddress">Shipping Address</label>
<textarea class="form-control" id="storeShippingAddress" name="shipping_address" readonly><?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : '' ?></textarea>
</div>
</div>
</div>
<!-- Calculation Card -->
<div class="align-to-right">
<div class="card">
<div class="form-row">
<div class="form-group col-md-12">
<label for="event" class="col-form-label">Events<span class="text-danger">*</span></label>
<input type="hidden" id="hiddenEventNextId" name="event_next_id" placeholder="hidden for event next id" />
<select class="form-control" id="event" name="event_id" required>
<option value="">Select an Events</option>
<?php foreach ($events as $event) : ?>
<!-- <option value="<?= $event->id ?>"><?= $event->event_name ?></option> -->
<option value="<?= $event->id ?>" <?php if (isset($invoice_details['event_id']) && ($invoice_details['event_id'] === $event->id)) echo "selected"; ?> ><?= $event->event_name ?></option>
<?php endforeach; ?>
</select>
<div class="invalid-feedback"> Please select an events. </div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="invoiceNumber">Invoice Number</label>
<input type="text" class="form-control" id="invoiceNumber" name="invoice_number" value="<?= isset($invoice_details['invoice_number']) ? $invoice_details['invoice_number'] : '' ?>" >
</div>
<div class="form-group col-md-6">
<label for="orderNumber">Order Number</label>
<input type="text" class="form-control" id="orderNumber" name="order_number" value="<?= isset($invoice_details['order_number']) ? $invoice_details['order_number'] : '' ?>">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="invoiceDate">Invoice Date</label>
<input type="date" class="form-control" id="invoiceDate" name="invoice_date" value="<?= isset($invoice_details['invoice_date']) ? $invoice_details['invoice_date'] : '' ?>">
</div>
<div class="form-group col-md-6">
<label for="dueDate">Due Date</label>
<input type="date" class="form-control" id="dueDate" name="due_date" value="<?= isset($invoice_details['due_date']) ? $invoice_details['due_date'] : '' ?>">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<h4>Item Details</h4>
<br/>
<table class="table table-bordered" id="itemTable">
<thead>
<tr>
<th>Item Details</th>
<th>Quantity</th>
<th>Rate</th>
<th>Tax</th>
<th>Amount </th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Dynamically add rows for item details -->
<?php if(!empty($invoice_item_details)){ foreach ($invoice_item_details as $ii_details): ?>
<tr>
<td><select class="form-control" id="book" name="item_details[]" onchange="displayBookTag(this)">
<option value="">Select a book</option>
<?php foreach ($books as $book) : ?>
<option value="<?= $book->book_id ?>" <?php if (isset($ii_details['product']) && ($ii_details['product'] === $book->book_id)) echo "selected"; ?> ><?= $book->title ?></option>
<?php endforeach; ?>
</select></td>
<td><input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['quantity']) ? $ii_details['quantity'] : '' ?>" /></td>
<td><input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price']: '' ?>" readonly /></td>
<td><input type="text" class="form-control" id="tax" name="tax[]" value="<?= isset($ii_details['tax']) ? $ii_details['tax'] : '' ?>" readonly /></td>
<td><input type="text" class="form-control" id="amount" name="amount[]" value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" /></td>
<td><input type="hidden" class="form-control" id="hiddenInvoiceChildId" name="invoice_child_id[]" value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" placeholder="hidden for invoice child/item id" />
<center><i class="fa fa-trash remove-item "></i></center></td>
</tr>
<?php endforeach; }else{ ?>
<tr>
<td><select class="form-control" id="book" name="item_details[]" onchange="displayBookTag(this)">
<option value="">Select a book</option>
<?php foreach ($books as $book) : ?>
<option value="<?= $book->book_id ?>"><?= $book->title ?></option>
<?php endforeach; ?>
</select></td>
<td><input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)"/></td>
<td><input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)"/></td>
<td><input type="text" class="form-control" id="tax" name="tax[]" /></td>
<td><input type="text" class="form-control" id="amount" name="amount[]" /></td>
<td><input type="hidden" class="form-control" id="hiddenInvoiceChildId" name="invoice_child_id[]" value="" placeholder="hidden for invoice child/item id" />
<center><i class="fa fa-trash remove-item "></i></center></td>
</tr>
<?php } ?>
<!-- You can add more rows as needed using JavaScript -->
</tbody>
</table>
<div class="form-group text-right m-b-0">
<a class="btn" id="addItem"><h4><i class="fa fa-plus" aria-hidden="true"></i> Add More Item</h4></a>
</div>
</div>
</div>
<div class="form-row">
<div class="offset-md-7 col-md-5 card">
<div class="card-body">
<h4>Calculation</h4>
<div class="form-group">
<label for="subtotal">Subtotal</label>
<input type="text" class="form-control" id="subtotal" readonly>
<input type="text" class="form-control" id="subtotal" name="sub_total" readonly value="<?= isset($invoice_details['subtotal']) ? $invoice_details['subtotal'] : '' ?>">
</div>
<div class="form-group">
<label for="tax">Tax Amount</label>
<input type="text" class="form-control" id="tax" readonly>
<label for="invoicetax">Tax Amount</label>
<input type="text" class="form-control" id="invoicetax" name="invoice_tax" readonly value="<?= isset($invoice_details['tax']) ? $invoice_details['tax'] : '' ?>">
</div>
<div class="form-group">
<label for="discount">Discount</label>
<input type="text" class="form-control" id="discount">
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" value="<?= isset($invoice_details['discount']) ? $invoice_details['discount'] : '' ?>">
</div>
<div class="form-group">
<label for="total">Total</label>
<input type="text" class="form-control" id="total" readonly>
<label for="grandtotal">Total</label>
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '' ?>">
</div>
</div>
</div>
</div>
<div class="form-row">
<div class="form-group text-left col-md-12 ">
<label for="terms">Terms & Conditions</label>
<textarea class="form-control" id="terms" name="terms" ></textarea>
</div>
</div>
</div>
</div>
<div class="form-group text-left col-md-5 ">
<label for="terms">Terms & Conditions</label>
<textarea class="form-control" id="terms" readonly></textarea>
<input type="hidden" id="hiddenInvoiceId" name="invoice_id" placeholder="hidden for invoice id" value="<?= isset($invoice_details['invoice_id']) ? $invoice_details['invoice_id'] : '' ?>" />
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light mr-1" type="submit">
Submit
</button>
<button type="reset" class="btn btn-primary waves-effect mr-1">
Reset
</button>
</div>
</div>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light mr-1" type="submit">
Submit
</button>
<button type="reset" class="btn btn-primary waves-effect mr-1">
Reset
</button>
<!-- Save Button -->
</div>
</form>
</div>
</div>
</div>
<script>
</div>
<script>
document.getElementById("addItem").addEventListener("click", function() {
var bookArray = <?php echo json_encode($books); ?>;
var table = document.getElementById("itemTable").getElementsByTagName("tbody")[0];
var newRow = table.insertRow(table.rows.length);
@ -215,31 +184,126 @@
var cell4 = newRow.insertCell(3);
var cell5 = newRow.insertCell(4);
var cell6 = newRow.insertCell(5);
cell1.innerHTML = '<input type="text" class="form-control" name="itemDetails[]">';
cell2.innerHTML = '<input type="text" class="form-control" name="quantity[]">';
cell3.innerHTML = '<input type="text" class="form-control" name="rate[]">';
cell4.innerHTML = '<input type="text" class="form-control" name="tax[]">';
cell5.innerHTML = '<input type="text" class="form-control" name="amount[]">';
cell6.innerHTML = '<i class="fa fa-trash remove-item ">';
const select = document.createElement('select');
select.className = 'form-control';
select.id = 'book';
select.name = 'item_details[]';
select.onchange = function() { displayBookTag(select); };
const defaultOption = document.createElement('option');
defaultOption.value = '';
defaultOption.text = 'Select a book';
select.appendChild(defaultOption);
// Use forEach to add options to the select element
bookArray.forEach((option) => {
const optionElement = document.createElement('option');
optionElement.value = option.book_id;
optionElement.text = option.title;
select.appendChild(optionElement);
});
cell1.appendChild(select);
// cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">';
cell2.innerHTML = '<input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)">';
cell3.innerHTML = '<input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)">';
cell4.innerHTML = '<input type="text" class="form-control" id="tax" name="tax[]">';
cell5.innerHTML = '<input type="text" class="form-control" id="amount" name="amount[]">';
cell6.innerHTML = '<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';
// Attach the calculateInvoice function to new input fields' change events
cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
cell2.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
cell3.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
cell4.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
// cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
// cell2.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
// cell3.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
// cell4.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
});
function displayBookTag(inputElement) {
var row = inputElement.parentElement.parentElement;
var bookId = inputElement.value;
var bookArray = <?php echo json_encode($books); ?>;
const selectedBook = bookArray.find(book => book.book_id == bookId);
row.querySelector('#rate').value = selectedBook.price;
row.querySelector('#rate').readOnly = true;
row.querySelector("#tax").value = selectedBook.tax ? selectedBook.tax : 0;
row.querySelector("#tax").readOnly = true;
}
function calculateInvoice(inputElement) {
var row = inputElement.parentElement.parentElement;
var quantity = parseFloat(row.querySelector('#quantity').value);
var rate = parseFloat(row.querySelector('#rate').value);
if (!isNaN(quantity) && !isNaN(rate)) {
var amount = quantity * rate;
row.querySelector('#amount').value = amount.toFixed(2); // Format to two decimal places
} else {
row.querySelector('#amount').value = ''; // Clear the amount if either quantity or rate is not a number
}
calculateSubTotal();
}
function calculateSubTotal() {
var amountInputs = document.querySelectorAll('input[name="amount[]"]');
var subTotal = 0;
amountInputs.forEach(function (input) {
var amount = parseFloat(input.value) || 0;
subTotal += amount;
});
var subTotalElement = subTotal.toFixed(2);
$("#subtotal").val(subTotalElement);
// var rateInputs = document.querySelectorAll('input[name="rate[]"]');
// var rateTotal = 0;
// rateInputs.forEach(function (input) {
// var rate = parseFloat(input.value) || 0;
// rateTotal += rate;
// });
// var rateElement = rate.toFixed(2);
var taxInputs = document.querySelectorAll('input[name="tax[]"]');
var taxTotal = 0;
taxInputs.forEach(function (input) {
var tax = parseFloat(input.value) || 0;
taxTotal += tax;
});
var taxElement = taxTotal.toFixed(2);
$("#invoicetax").val(taxElement);
var discount = parseFloat($("#discount").val()) || 0
calculateGrandTotal(discount);
}
function calculateGrandTotal(value) {
var discount = value ? value : 0;
var invoiceTax = $("#invoicetax").val();
var subTotal = $("#subtotal").val();
var grandTotal = 0;
if (!isNaN(discount)) {
grandTotal = (parseFloat(subTotal) + parseFloat(invoiceTax)) - parseFloat(discount);
}
var grandElement = grandTotal.toFixed(2);
$("#grandtotal").val(grandElement);
}
</script>
<!-- JavaScript for removing a row from the table -->
<script>
<!-- JavaScript for removing a row from the table -->
<script>
// Function to remove a row from the table
function removeItem(row) {
var table = document.getElementById("itemTable").getElementsByTagName("tbody")[0];
table.removeChild(row);
calculateInvoice(); // Call the calculation function to update the totals
calculateSubTotal(); // Call the calculation function to update the totals
}
// Attach the removeItem function to the Remove buttons using event delegation
@ -249,9 +313,151 @@
removeItem(row);
}
});
</script>
</script>
<script>
$(document).ready(function() {
var iid_arr = <?php echo json_encode($invoice_item_details); ?>;
console.log(iid_arr);
var cust_id = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>";
var ship_addr_id = "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
var bill_addr = "<?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : ""; ?>";
if(cust_id != ''){
load_details1(ship_addr_id,cust_id);
load_details2(ship_addr_id,cust_id);
}
// $("#customerName").val(customer_id).change();
$("#customerName").change(function() {
var cust_id = $(this).val();
var ship_addr_id = "";
load_details1(ship_addr_id,cust_id);
});
</body>
$("#loadShippingDropdown").change(function() {
var ship_addr_id = $(this).val();
var cust_id = $("#customerName").val();
load_details2(ship_addr_id,cust_id);
});
</html>
$("#event").change(function() {
var selectedValue = $(this).val();
var earray = <?php echo json_encode($events); ?>;
if (earray.length > 0) {
var filtered_data = $.grep(earray, function(item) {
return item.id === selectedValue;
});
var final_sno = generateSerialNumber(filtered_data);
$("#invoiceNumber").val(final_sno).prop("readonly", true);
}else{
$("#invoiceNumber").val(final_sno).prop("readonly", false);
}
});
$("#editAddressesCheckbox").on("change", function() {
if ($(this).is(":checked")) {
$("#storeBillingAddress").prop("readonly", false);
} else {
$("#storeBillingAddress").prop("readonly", true);
}
});
function load_details1(ship_addr_id,cust_id) {
$.ajax({
type: "POST",
url: "<?= base_url() . 'load_details1' ?>",
data: {
selectedValue: cust_id
},
success: function(response) {
cs = response['data']['customer_shipping'];
cb = response['data']['customer_billing'];
$('#hiddenBillingAddressId').val('');
customer_billing = "";
if (cb.length > 0) {
$.each(cb, function(k, v) {
customer_billing = v.address_1 + "," + v.address_2 + "," + v.city + "," + v.state + "," + v.country + "." + v.postal_code
customer_billing_id = v.customer_address_id
});
}
// console.log(customer_billing);
// var address_compare = bill_addr == customer_billing ? customer_billing : bill_addr
//
if((bill_addr != "") && (bill_addr != customer_billing)){
$("#storeBillingAddress").val(bill_addr).prop("readonly", false);
$('#editAddressesCheckbox').prop('checked', true);
}else{
$("#storeBillingAddress").val(customer_billing).prop("readonly", true);
$('#editAddressesCheckbox').prop('checked', false);
}
$('#hiddenBillingAddressId').val(customer_billing_id);
if (cs.length > 0) {
$('#loadShippingDropdown').empty();
$('#storeShippingAddress').val('');
$('#loadShippingDropdown').append($('<option>', {
value: "",
text: "Select an address"
}));
$.each(cs, function(k, v) {
$('#loadShippingDropdown').append($('<option>', {
value: v.customer_address_id,
text: v.address,
selected: (v.customer_address_id == ship_addr_id) ? true : false
}));
});
}
},
error: function() {
alert("Error fetching address.");
}
});
}
function load_details2(ship_addr_id,cust_id) {
$.ajax({
type: "POST",
url: "<?= base_url() . 'load_details2' ?>",
data: {
selectedValue: ship_addr_id,
customerValue: cust_id
},
success: function(response) {
cs = response['data']['customer_shipping'];
customer_shipping = "";
if (cs.length > 0) {
$.each(cs, function(k, v) {
customer_shipping = v.address_1 + "," + v.address_2 + "," + v.city + "," + v.state + "," + v.country + "." + v.postal_code
});
}
// console.log(customer_shipping);
$("#storeShippingAddress").val(customer_shipping);
},
error: function() {
alert("Error fetching address.");
}
});
}
function generateSerialNumber(filtered_data) {
var next_id_string = filtered_data[0].next_id;
var left_pad_string = filtered_data[0].left_pad;
var prefix_string = String(filtered_data[0].id_formating);
var left_pad_numberic = parseInt(left_pad_string);
var next_id_numberic = parseInt(next_id_string);
var padded_id = next_id_string.padStart(left_pad_numberic, '0');
var serial_number = prefix_string + '-' + padded_id;
next_id_numberic++;
$("#hiddenEventNextId").val(next_id_numberic).prop("readonly", true);
return serial_number;
}
});
</script>

View File

@ -3,16 +3,13 @@
<div class="card">
<div class="card-body">
<div class="float-right">
<a href="new_invoice" class="btn btn-primary"><i class="fe-file-text"></i> Add New </a>
<a href="<?= base_url()."new_invoice/0"; ?>" class="btn btn-primary"><i class="fe-file-text"></i> Add New </a>
</div><!-- end col-->
<br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
<div class="table-responsive">
<table id="scroll-horizontal-datatable" class="table w-100 nowrap">
<thead class="thead-light">
<tr>
<th>Invoice Number</th>
<th>Invoice Date</th>
@ -23,10 +20,29 @@
<th>Discount</th>
<th>Tax</th>
<th>Total Value</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($invoice as $row): ?>
<tr>
<td><?php echo $row->invoice_number; ?></td>
<td><?php echo $row->invoice_date; ?></td>
<td><?php echo $row->customer_name; ?></td>
<td></td>
<td></td>
<td></td>
<td><?php echo $row->discount; ?></td>
<td><?php echo $row->tax; ?></td>
<td><?php echo $row->total_amount; ?></td>
<td>
<a href="<?= "new_invoice/" . $row->invoice_id; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
<a href="<?= "delete_invoice/" . $row->invoice_id; ?>" class="delete-button"><i class="ri-delete-bin-line"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div> <!-- end card body-->

View File

@ -436,14 +436,14 @@
<!-- KNOB JS -->
<script src="<?= base_url()."public/assets/libs/jquery-knob/jquery.knob.min.js" ?>"></script>
<!-- Apex js-->
<script src="<?= base_url()."public/assets/libs/apexcharts/apexcharts.min.js" ?>"></script>
<!-- <script src="<?= base_url()."public/assets/libs/apexcharts/apexcharts.min.js" ?>"></script>-->
<!-- Plugins js-->
<script src="<?= base_url()."public/assets/libs/admin-resources/jquery.vectormap/jquery-jvectormap-1.2.2.min.js" ?>"></script>
<script src="<?= base_url()."public/assets/libs/admin-resources/jquery.vectormap/maps/jquery-jvectormap-world-mill-en.js" ?>"></script>
<!-- Dashboard init-->
<script src="<?= base_url()."public/assets/js/pages/dashboard-sales.init.js" ?>"></script>
<!-- <script src="<?= base_url()."public/assets/js/pages/dashboard-sales.init.js" ?>"></script> -->
<!-- third party js -->
<script src="<?= base_url()."public/assets/libs/datatables.net/js/jquery.dataTables.min.js" ?>"></script>

View File

@ -29,7 +29,7 @@
<!-- icons -->
<link href="<?= base_url()."public/assets/css/icons.min.css" ?>" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body class="loading">