This commit is contained in:
heama 2023-09-06 12:14:02 +05:30
parent 1fbef1b7ed
commit 8ea1d07d0f
7 changed files with 278 additions and 214 deletions

View File

@ -290,4 +290,5 @@ class Customer extends BaseController
echo "<center><a href=".$go_to_list_page.">go to list page</a></center>"; echo "<center><a href=".$go_to_list_page.">go to list page</a></center>";
// return $message; // return $message;
} }
} }

View File

@ -1,27 +1,53 @@
<?php <?php
namespace App\Controllers; namespace App\Controllers;
use App\Models\EventModel;
use App\Models\CustomerModel;
use App\Models\InvoiceModel; use App\Models\InvoiceModel;
class Invoice extends BaseController class Invoice extends BaseController
{ {
public function index() public function index()
{ {
helper('session');
if (is_session_active()) {
$session_role = get_user_role();
$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();
$data['page_name'] = 'Invoice Details'; $data['page_name'] = 'Invoice Details';
$data['invoice'] = []; // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
$this->render_page('invoice_list', $data); // $data['invoice'] = $InvoiceModel->getAllSubscribersWithNames($where);
$this->render_page('invoice_list', $data);
}else {
return redirect()->to('login');
} }
}
public function new_invoice() public function new_invoice()
{ {
helper('session');
$session_bid = get_business_id();
$data['page_name'] = 'Invoice Details'; $data['page_name'] = 'Invoice Details';
$customerModel = new CustomerModel();
$eventModel = new EventModel();
$business_id = 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'] = '';
$this->render_page('invoice_form', $data); $this->render_page('invoice_form', $data);
} }
} }

View File

@ -90,5 +90,6 @@ class CustomerModel extends Model
$dataToUpdate = ['isactive' => 0]; $dataToUpdate = ['isactive' => 0];
$this->db->table('customer_addresses')->where($where)->whereIn('customer_address_id',$missingValues)->update($dataToUpdate); $this->db->table('customer_addresses')->where($where)->whereIn('customer_address_id',$missingValues)->update($dataToUpdate);
} }
} }
?> ?>

View File

@ -12,5 +12,14 @@ class EventModel extends Model
protected $allowedFields = ['id','event_name','next_id','left_pad','id_formating','created_by','created_on','updated_on' ,'updated_by','business_id']; protected $allowedFields = ['id','event_name','next_id','left_pad','id_formating','created_by','created_on','updated_on' ,'updated_by','business_id'];
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

@ -0,0 +1,16 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
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'];
}

View File

@ -1,4 +1,5 @@
<html> <html>
<body> <body>
<style> <style>
.align-to-right { .align-to-right {
@ -6,10 +7,10 @@
padding: 30px; padding: 30px;
} }
.btn btn-primary { .btn btn-primary {
text-align: right; text-align: right;
} }
</style> </style>
@ -21,20 +22,22 @@
<div class="card-body"> <div class="card-body">
<h4 class="header-title"><?= $page_name; ?></h4> <h4 class="header-title"><?= $page_name; ?></h4>
<p class="sub-header"> </p> <p class="sub-header"> </p>
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data" action="<?php echo base_url(); ?>insert_event"> <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-group">
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="customerName">Customer Name</label> <label for="customerName">Customer Name</label>
<select class="form-control" id="customerName"> <select class="form-control" id="customerName" onchange="updateCustomerDetails()">
<!-- Populate this dropdown with customer names --> <option value="">Select a customer</option>
<option>Customer 1</option> <?php foreach ($customers as $customer): ?>
<option>Customer 2</option> <option value="<?= $customer->customer_id ?>"><?= $customer->full_name ?></option>
<!-- Add more options as needed --> <?php endforeach; ?>
</select> </select>
</div> </div>
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="shipping">Shipping Address</label> <label for="shipping">Shipping Address</label>
@ -77,6 +80,7 @@
<div class="row"> <div class="row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="invoiceDate">Invoice Date</label> <label for="invoiceDate">Invoice Date</label>
@ -89,6 +93,21 @@
</div> </div>
</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>
<?php endforeach; ?>
</select>
<div class="invalid-feedback"> Please select a customer. </div>
</div>
</div>
</form> </form>
@ -97,7 +116,7 @@
<!-- <button style="float: right;"><i class="fa fa-plus" aria-hidden="true"></i></button> --> <!-- <button style="float: right;"><i class="fa fa-plus" aria-hidden="true"></i></button> -->
<div class="col-lg-12"> <div class="col-lg-12">
<h5>Item Details</h5> <h5>Item Details</h5>
<button style="float:right;" id="addItem"><i class="fa fa-plus" aria-hidden="true"></i></button>
<br> <br>
<table class="table table-bordered" id="itemTable"> <table class="table table-bordered" id="itemTable">
@ -125,7 +144,8 @@
<!-- You can add more rows as needed using JavaScript --> <!-- You can add more rows as needed using JavaScript -->
</tbody> </tbody>
</table> </table>
<button style="float:left;" id="addItem"><i class="fa fa-plus"
aria-hidden="true"></i></button>
</div> </div>
</div> </div>
@ -155,13 +175,18 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="form-group text-left col-md-5 "> <div class="form-group text-left col-md-5 ">
<label for="terms">Terms & Conditions</label> <label for="terms">Terms & Conditions</label>
<textarea class="form-control" id="terms" readonly></textarea> <textarea class="form-control" id="terms" readonly></textarea>
</div>
</div> </div>
</div>
<div class="form-group text-right m-b-0"> <div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light mr-1" type="submit"> <button class="btn btn-success waves-effect waves-light mr-1" type="submit">
Submit Submit
@ -170,10 +195,8 @@
Reset Reset
</button> </button>
<!-- Save Button --> </div> <!-- Save Button -->
</div> </div>
</div> </div>
@ -207,7 +230,6 @@ document.getElementById("addItem").addEventListener("click", function () {
cell4.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); cell4.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
}); });
</script> </script>
@ -231,16 +253,5 @@ document.getElementById("addItem").addEventListener("click", function () {
</body> </body>
</html> </html>