Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
aadhavan valli 2024-04-09 13:48:35 +05:30
commit 7a52bcd32d
13 changed files with 355 additions and 162 deletions

View File

@ -50,7 +50,7 @@ $routes->get("new_sale/(:any)", "Sales::new_sale/$1");
$routes->get("delete_sale/(:any)", "Sales::delete_sale/$1");
$routes->post("delete_sales_product", "Sales::delete_sales_product");
$routes->get("download_invoice/(:any)", "Sales::download_invoice/$1");
$routes->post("save_client", "Sales::save_client");
$routes->post("save_vehicle", "Sales::save_vehicle");
//end salle order//
//Client//
@ -58,6 +58,7 @@ $routes->get('client_index/', 'Client::client_index');
$routes->post("add_client", "Client::add_client");
$routes->get("new_client/(:any)", "Client::new_client/$1");
$routes->get("delete_client/(:any)", "Client::delete_client/$1");
$routes->post("save_client", "Client::client_quick_create");
//end clent
//Vendor//
$routes->get('vendor_index/', 'Vendor::vendor_index');

View File

@ -104,5 +104,43 @@ class Client extends BaseController
return redirect()->to('client_index');
}
public function client_quick_create(){
// Load ClientModel
$ClientModel = new ClientModel();
// Validate inputs
$validationRules = [
'client_name' => 'required|max_length[100]',
'mobile_no' => 'required' // Assuming mobile number is 10 digits long
];
if (!$this->validate($validationRules)) {
// If validation fails, return validation errors
return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]);
}
// If validation passes, proceed to save the client
$data = [
'client_name' => $this->request->getPost('client_name'),
'mobile_no' => $this->request->getPost('mobile_no'),
'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai',
'state'=>'Tamil Nadu',
'isactive' => 1
];
// Attempt to insert the client data
$id = $ClientModel->insert($data);
if ($id) {
$clientData = $ClientModel->where('client_id',$id)->first();
// If insertion succeeds, return success response
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]);
} else {
// If insertion fails, return error response
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
}
}
}

View File

@ -65,7 +65,7 @@ class Products extends BaseController
$ProductModel = new ProductModel();
$tax= $this->request->getPost('tax')/2;
// print_r($this->request->getPost());die;
$data = [
'product_name' => $this->request->getPost('productname'),
'product_category' => $this->request->getPost('productcategory'),
@ -82,6 +82,8 @@ class Products extends BaseController
'vendor' => $this->request->getPost('vendor'),
'purchase_order_level' => $this->request->getPost('purchase_order_level'),
'quality' => $this->request->getPost('quality'),
'make_id' => $this->request->getPost('make'),
'models_id' => json_encode($this->request->getPost('model')),
'isactive' => 1 ,
'branch_id' => $this->session->get('logged_user_branch_id')
];
@ -124,26 +126,53 @@ class Products extends BaseController
// Retrieve the make_id from the AJAX request
public function get_vendors_by_model()
{
$make_id = $this->request->getPost('make_id');
$model_ids = $this->request->getPost('model_ids');
// print_r( $model_ids);die;
// If make_id or model_ids is not provided, return an empty response
// Create an instance of VendorModel
$make_id = $this->request->getPost('make_id');
$vendorModel = new VendorModel();
// Call the get_vendors_by_model method from the model
$vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids);
// print_r($vendors);
// Return the response as JSON
// return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
if ($vendors) {
// Return the retrieved vendors as JSON response
return $this->response->setJSON($vendors);
} else {
// If no vendors were found, return an empty response or handle the error accordingly
$Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
if($Vendors){
$data = [];
foreach ($model_ids as $modelKey => $modelValue)
{
foreach ($Vendors as $vendorsKey => $vendorsValue)
{
$modelsArray = json_decode($vendorsValue['model'], true);
if (is_array($modelsArray))
{
$findIfModelExist = array_search($modelValue, $modelsArray);
if ($findIfModelExist !== false)
{
array_push($data,$vendorsValue);
}
}
}
}
if (count($data)) {
$arrayOfArrays = array_map(function($obj) {
return (array) $obj;
}, $data);
// Remove duplicates based on string representation of each object
$uniqueArray = array_map('unserialize', array_unique(array_map('serialize', $arrayOfArrays)));
// Convert the unique array of associative arrays back to an array of objects
$uniqueObjectsArray = array_map(function($arr) {
return (object) $arr;
}, $uniqueArray);
return $this->response->setJSON($uniqueArray);
} else {
return $this->response->setJSON([]);
}
}else {
return $this->response->setJSON([]);
}
}

View File

@ -6,6 +6,8 @@ use App\Models\SalesOrderModel;
use App\Models\SalesOrderProductModel;
use App\Models\ProductModel;
use App\Models\ClientModel;
use App\Models\BikeMakeModel;
use App\Models\VehicleModel;
use Mpdf\Mpdf;
class Sales extends BaseController
{
@ -23,7 +25,7 @@ class Sales extends BaseController
$SalesOrderModel = new SalesOrderModel();
$sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
$data['sales']=$sales;
// print_r($sales);die;
return view('sales_list',$data);
}
@ -39,13 +41,18 @@ class Sales extends BaseController
$client=$ClientModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
// print_r($client);die;
$VehicleModel = new VehicleModel();
$vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
// ->where('isactive',1)
// ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
// print_r($vehicle);die;
$ProductModel = new ProductModel();
$product=$ProductModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product;
$data['client']=$client;
$data['vehicle']=$vehicle;
} else if ($sales_order_id !== '0') {
$data['page_name']="Edit Sale Order";
$ClientModel = new ClientModel();
@ -58,14 +65,19 @@ $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)
$data['sales_product']=$sales_product;
$data['client']=$client;
// print_r($sales_product);die;
$VehicleModel = new VehicleModel();
$vehicle=$VehicleModel
->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['vehicle']=$vehicle;
$ProductModel = new ProductModel();
$product=$ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product;
}
// print_r($data);die;
$data['sales_order_id'] = $sales_order_id;
$bikeMakeModel = new BikeMakeModel();
$data['makeData'] =$bikeMakeModel->findAll();
return view('sales_order_form',$data);
}
@ -78,7 +90,8 @@ $data['product']=$product;
// Prepare data for sales order
$data = [
'client_id' => $this->request->getPost('client_id'),
'client_name' => $this->request->getPost('client_id'),
'vehicle_id'=>$this->request->getPost('vehicle_id'),
'billing_address' => $this->request->getPost('billing_address'),
'billing_city' => $this->request->getPost('city'),
'mobile_no' => $this->request->getPost('mobile_no'),
@ -88,13 +101,13 @@ $data['product']=$product;
'terms_condition' => $this->request->getPost('terms_condition'),
'subtotal' => $this->request->getPost('sub_total'),
'tax' => $this->request->getPost('invoice_tax'),
'discount'=> $this->request->getPost('discount'),
'total'=> $this->request->getPost('grand_total'),
'status'=> $this->request->getPost('status'),
'isactive' => 1, // Assuming this is a default value or handled separately
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
// print_r($data);die;
// print_r($data);die;
// Insert or update sales order
$sales_order_id = $this->request->getPost('sales_order_id');
if (!empty($sales_order_id)) {
@ -280,38 +293,36 @@ public function delete_sales_product()
// Output the PDF to the browser for download
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
}
public function save_client(){
public function save_vehicle(){
// Load ClientModel
$ClientModel = new ClientModel();
$VehicleModel = new VehicleModel();
// Validate inputs
$validationRules = [
'client_name' => 'required|max_length[100]',
'mobile_no' => 'required' // Assuming mobile number is 10 digits long
];
if (!$this->validate($validationRules)) {
// If validation fails, return validation errors
return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]);
}
// If validation passes, proceed to save the client
$data = [
'client_name' => $this->request->getPost('client_name'),
'client_id' => $this->request->getPost('client_id'),
'mobile_no' => $this->request->getPost('mobile_no'),
'reg_no' => $this->request->getPost('reg_no'),
'model' => $this->request->getPost('model'),
'make' => $this->request->getPost('make'),
'branch_id'=> $this->session->get('logged_user_branch_id'),
'city'=>'Chennai',
'state'=>'Tamil Nadu',
'isactive' => 1
];
// Attempt to insert the client data
$id = $ClientModel->insert($data);
$id = $VehicleModel->insert($data);
if ($id) {
$clientData = $ClientModel->where('client_id',$id)->first();
$vehicleData = $VehicleModel->where('vehicle_id',$id)->first();
// If insertion succeeds, return success response
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]);
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData]);
} else {
// If insertion fails, return error response
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);

View File

@ -5,7 +5,7 @@ class ProductModel extends Model
{
protected $table = 'products';
protected $primaryKey = 'product_id';
protected $allowedFields = ['product_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive'];
protected $allowedFields = ['product_id','make_id','models_id','quality','product_name','branch_id','search_tag','product_category','mfr_part_no','purchase_order_level','serial_no','unit_price','commision_rate','sgst','cgst','purchase_cost','usage_unit','vendor','qty_stock','reorder_level','handler','qty_in_demand','product_image','description','isactive'];
public function getTax()

View File

@ -5,14 +5,14 @@ class SalesOrderModel extends Model
{
protected $table = 'sales_order';
protected $primaryKey = 'sales_order_id';
protected $allowedFields = ['sales_order_id','client_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
protected $allowedFields = ['sales_order_id','client_name','vehicle_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
//
public function getSalesPdf($sales_order_id){
return $this->db->table('sales_order')
->where('sales_order_id', $sales_order_id)
->join('client as C','C.client_id= sales_order.client_id','left')
->join('branches as B','B.branch_id = sales_order.branch_id','left')
->select('sales_order.*,C.client_name,C.mobile_no,C.address,C.city,C.state')
->select('sales_order.*')
->select('B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no')
->get()
@ -22,11 +22,11 @@ class SalesOrderModel extends Model
public function getSalesOrdersWithProducts($logged_user_branch_id)
{
// Select required fields from both tables
$this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,client.client_name');
$this->select('sales_order.*, COUNT(sales_order_product.sales_order_id) AS product_count,vehicle.reg_no');
// Join the sales_order_product table based on sales_order_id
$this->join('sales_order_product', 'sales_order_product.sales_order_id = sales_order.sales_order_id');
$this->join('client', 'client.client_id = sales_order.client_id');
$this->join('vehicle', 'vehicle.vehicle_id = sales_order.vehicle_id');
// Group by sales_order_id to get count of products per sales order
$this->groupBy('sales_order.sales_order_id');

View File

@ -12,7 +12,7 @@ class VehicleModel extends Model
public function getCustomerandVehicle($branch_id)
{
// Select required fields from both tables
$this->select('vehicle.*, client.client_name , make.make as make_name , model.model_name as model_name');
$this->select('vehicle.*, client.client_name ,client.address,client.city,client.state,client.postal_code, make.make as make_name , model.model_name as model_name');
$this->join('client', 'client.client_id = vehicle.client_id');
$this->join('make', 'make.make_id = vehicle.make');
$this->join('model', 'model.model_id = vehicle.model');

View File

@ -21,6 +21,7 @@
<div class="card-body">
<form action="<?= base_url() . "add_client"; ?>" method="post">
<h4 class="header-title">Client Details :</h4>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Client Name<span class="text-danger">*</span></label>
@ -30,6 +31,16 @@
<label for="inputAddress" class="col-form-label">Mobile<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile" placeholder="Mobile" value="<?= isset($client['mobile_no']) ? $client['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required/>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Client Type<span class="text-danger">*</span></label>
<select class="form-control status-select" name="clienttype" required data-toggle="select2" >
<!-- <option value="">Select a Type</option> -->
<option value="Direct" <?= isset($client['client_type']) && $client['client_type'] === 'Direct' ? 'selected' : '' ?>>Direct</option>
<option value="Mechanic" <?= isset($client['client_type']) && $client['client_type'] === 'Mechanic' ? 'selected' : '' ?>>Mechanic</option>
<option value="Exp" <?= isset($client['client_type']) && $client['client_type'] === 'Exp' ? 'selected' : '' ?>>Exp</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Email</label>
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($client['email']) ? $client['email'] : '' ?>" >
@ -38,23 +49,10 @@
<label for="inputAddress" class="col-form-label">GST Number<span class="text-danger"></span></label>
<input type="text" class="form-control" name="gstnumber" placeholder="GST Number" value="<?= isset($client['gstnumber']) ? $client['gstnumber'] : '' ?>"pattern="[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}[Z]{1}[0-9A-Z]{1}" title="Enter a valid GST Number" />
</div>
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Client Type<span class="text-danger">*</span></label>
<select class="form-control status-select" name="clienttype" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> -->
<option value="Direct" <?= isset($client['client_type']) && $client['client_type'] === 'Direct' ? 'selected' : '' ?>>Direct</option>
<option value="Mechanic" <?= isset($client['client_type']) && $client['client_type'] === 'Mechanic' ? 'selected' : '' ?>>Mechanic</option>
<option value="Exp" <?= isset($client['client_type']) && $client['client_type'] === 'Exp' ? 'selected' : '' ?>>Exp</option>
</select>
</div>
</div>
<input type="hidden" id="client_id" name="client_id" value="<?= isset($client['client_id']) ? $client['client_id'] : '' ?>">
<h4 class="header-title">Address Information :</h4>
</br><h4 class="header-title">Address Information :</h4>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Address</label>

View File

@ -214,7 +214,7 @@ p {
<th>MRP</th>
<th>Qty</th>
<th>Discount</th>
<th>Total</th>
</tr>
</thead>
@ -230,7 +230,7 @@ p {
<td><?= $item->product_name ?></td>
<td><?= number_format($item->net_price, 2, '.', ',') ?></td>
<td><?= $item->qty ?></td>
<td><?= $item->discount_type == '₹' ? $item->discount_type.$item->discount : $item->discount.$item->discount_type; ?></td>
<td><?= number_format($item->amount, 2, '.', ',') ?></td>
@ -252,13 +252,7 @@ p {
<?php if ($value->discount!=0): ?>
<!-- Set Balance if status is draft and paid is 0 -->
<tr>
<td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total, 2, '.', ',') ?></td>
</tr>
@ -277,11 +271,7 @@ p {
<div class="terms">
<?php if ($value->discount!=0): ?>
<br><p >"You have saved ₹<?= $value->discount; ?>- in this purchase"</p><br>
<?php endif; ?>
<p style=text-align:left><?= $value->terms_condition;?></p>
</div>

View File

@ -26,6 +26,7 @@
<div class="form-group col-md-4">
<label for="make" class="col-form-label">Make<span class="text-danger">*</span></label>
<select class="form-control SelExample" id="make" name="make" required>
<option value="">Select a Make</option>
<!-- Options for make -->
<?php foreach ($make as $value): ?>
<option value="<?= $value['make_id'] ?>" <?= isset($vendor['make_ids']) && in_array($value['make_id'], $vendor['make_ids']) ? 'selected' : '' ?>><?= $value['make'] ?></option>
@ -43,23 +44,23 @@
<input type="text" class="form-control" name="productname" placeholder="Product Name" value="<?= isset($products['product_name']) ? $products['product_name'] : '' ?>" required>
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Vendor<span class="text-danger">*</span></label>
<select class="form-control" id="vendor" name="vendor" required>
<!-- Placeholder option -->
<option value="">Select Vendor</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Quality<span class="text-danger">*</span></label>
<select class="form-control " name="quality" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> -->
<option value="Q1" <?= isset($products['quality']) && $products['quality'] === 'Q1' ? 'selected' : '' ?>>Q1</option>
<option value="Q2" <?= isset($products['quality']) && $products['quality'] === 'Q2' ? 'selected' : '' ?>>Q2 </option>
<option value="Q3" <?= isset($products['quality']) && $products['quality'] === 'Q3' ? 'selected' : '' ?>>Q3</option>
<option value="Q4" <?= isset($products['quality']) && $products['quality'] === 'Q4' ? 'selected' : '' ?>>Q4</option>
</select>
</div>
<label for="vendor" class="col-form-label">Vendor<span class="text-danger">*</span></label>
<select class="form-control" id="vendor" name="vendor" required>
<!-- Placeholder option -->
<option value="">Select Vendor</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="vendor" class="col-form-label">Quality<span class="text-danger">*</span></label>
<select class="form-control " name="quality" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> -->
<option value="Q1" <?= isset($products['quality']) && $products['quality'] === 'Q1' ? 'selected' : '' ?>>Q1</option>
<option value="Q2" <?= isset($products['quality']) && $products['quality'] === 'Q2' ? 'selected' : '' ?>>Q2 </option>
<option value="Q3" <?= isset($products['quality']) && $products['quality'] === 'Q3' ? 'selected' : '' ?>>Q3</option>
<option value="Q4" <?= isset($products['quality']) && $products['quality'] === 'Q4' ? 'selected' : '' ?>>Q4</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="inputAddress" class="col-form-label">Manfacturer Part Number</label>
<input type="text" class="form-control" name="mfr_part_no" placeholder="Manfacturer Part Number" value="<?= isset($products['mfr_part_no']) ? $products['mfr_part_no'] : '' ?>" >
@ -200,6 +201,7 @@ $(document).ready(function() {
// Clear existing options
$('#model').empty();
// Append new options
$("#model").append('<option value=""> Select a Model </option>');
$.each(response, function(index, model) {
$('#model').append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
});
@ -218,23 +220,24 @@ $(document).ready(function() {
$(document).ready(function() {
$('#model').change(function() {
var make_id = $(this).val(); // Get the selected make ID
var model_ids = $('#model').val(); // Get the selected model IDs
console.log(model_ids);
var make_id = $('#make').val();
console.log(model_ids);
// AJAX request to get vendors based on the selected model ID
$.ajax({
url: '<?php echo base_url('get_vendors_by_model') ?>', // URL to your CodeIgniter controller method
type: 'POST',
dataType: 'json',
data: { make_id: make_id, model_ids: model_ids }, // Send the selected make ID and model IDs to the controller
data: { model_ids: model_ids , make_id : make_id }, // Send the selected make ID and model IDs to the controller
success: function(response) {
// Update vendor dropdown based on the response
if (response) {
// Clear existing options
$('#vendor').empty();
// Append new options
$('#vendor').append('<option value>"hello"</option>');
$('#vendor').append('<option value>Select Vendor</option>');
$.each(response, function(index, vendor) {
$('#vendor').append('<option value="' + vendor.vendor_id + '">' + vendor.vendor_name + '</option>');
});

View File

@ -40,6 +40,7 @@
<tr>
<th>Order Number</th>
<th>Reg No</th>
<th>Client Name</th>
<th>Client Mobile</th>
<th>Quantity</th>
@ -61,6 +62,7 @@
if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['order_number']; ?></td>
<td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?></td>
<td><?= $value['mobile_no']; ?></td>
<td><?= $value['product_count']; ?></td>

View File

@ -25,23 +25,31 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail4" class="col-form-label">Client Name<span class="text-danger">*</span></label>
<?= isset($sales['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addClientModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addClientModal" title="Add Client"></i>' ?>
<label for="inputEmail4" class="col-form-label">Vehicle<span class="text-danger">*</span></label>
<?= isset($sales['vehicle_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addVehicleModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addVehicleModal" title="Add Client"></i>' ?>
<select class="form-control cleint-select SelExample" name="client_id" <?= isset($sales['client_id']) ? '' : 'required' ?>>
<select class="form-control vehicle-select SelExample" name="vehicle_id" <?= isset($sales['vehicle_id']) ? '' : 'required' ?>>
<?= isset($sales['client_id']) ? '' : '<option value="">Select a Client</option>' ?>
<?php foreach ($client as $value) : ?>
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
<?php foreach ($vehicle as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["client_id"] ?>" <?= isset($sales['client_id']) && $sales['client_id'] == $value["client_id"] ? 'selected' : '' ?>>
<?= $value["mobile_no"].' - '.$value["client_name"]; ?>
<option value="<?= $value["vehicle_id"] ?>" <?= isset($sales['vehicle_id']) && $sales['vehicle_id'] == $value["vehicle_id"] ? 'selected' : '' ?>>
<?= $value["reg_no"]?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Client Name<span class="text-danger"></span></label>
<input type="text" class="form-control" name="client_id" placeholder="Client"value="<?= isset($sales['client_name']) ? $sales['client_name'] : '' ?>" >
</div>
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Mobile No<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
</div>
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span></label>
<select class="form-control status-select" name="status" required data-toggle="select2" >
<!-- <option value="">Select a Status</option> -->
@ -53,7 +61,7 @@
</div><br>
<h4 class="header-title">Billing Address Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Address<span class="text-danger"></span></label>
<input type="text" class="form-control" name="billing_address" placeholder="Address"value="<?= isset($sales['billing_address']) ? $sales['billing_address'] : '' ?>" >
</div>
@ -61,24 +69,21 @@
<input type="hidden" id="sales_order_id" name="sales_order_id" value="<?= isset($sales['sales_order_id']) ? $sales['sales_order_id'] : '' ?>"readonly>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">City<span class="text-danger"></span></label>
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($sales['billing_city']) ? $sales['billing_city'] : 'Chennai' ?>" >
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">State<span class="text-danger"></span></label>
<input type="text" class="form-control" name="state" placeholder="State"value="<?= isset($sales['billing_state']) ? $sales['billing_state'] : 'Tamil Nadu' ?>" >
</div>
<div class="form-group col-md-6">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Pin Code<span class="text-danger"></span></label>
<input type="text" class="form-control" name="postalcode" placeholder="Pin Code"value="<?= isset($sales['billing_postal_code']) ? $sales['billing_postal_code'] : '' ?>" maxlength="6" minlength="6" >
</div>
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Mobile No<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($sales['mobile_no']) ? $sales['mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
</div>
</div>
<div class="form-row" id="itemTableContainer">
@ -93,7 +98,7 @@
<th>Qty</th>
<th>Rate</th>
<th>Tax</th>
<th style="text-align: center !important" colspan="2">Discount</th>
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
<th>Amount</th>
<th hidden></th>
<th></th>
@ -127,7 +132,7 @@
<td style="width:10%;">
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>">
</td>
<td style="width:12%;">
<!-- <td style="width:12%;">
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($salechild['discount']) ? $salechild['discount'] : '' ?>">
</td>
<td style="width:10%;">
@ -135,12 +140,12 @@
<option value="" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
<option value="%" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
</select>
</td>
</td> -->
<td style="width:12%;">
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>">
</td>
<td hidden><input type="hidden" value="<?= isset($salechild['sales_order_product_id']) ? $salechild['sales_order_product_id'] : '' ?>"name="sales_order_product_id[]"></td>
<td>
<td style="width:12%;">
<center><i class="fa fa-trash remove-item"></i></center>
</td>
</tr>
@ -177,10 +182,10 @@
<div class="form-group">
<!-- <div class="form-group">
<label for="discount">Discount Amount</label>
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" min="0" readonly value="<?= isset($sales['discount']) ? $sales['discount'] : '' ?>" >
</div>
</div> -->
<div class="form-group">
<label for="grandtotal">Total</label>
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
@ -213,30 +218,79 @@
</div>
<?php include('layout/footer.php'); ?>
</div>
<div class="modal fade" id="addClientModal" tabindex="-1" role="dialog" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal fade" id="addVehicleModal" tabindex="-1" role="dialog" aria-labelledby="addVehicleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addClientModalLabel">Add New Client</h5>
<h5 class="modal-title" id="addVehicleModalLabel">Add New Vehicle</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="addClientForm">
<div class="form-group">
<label for="clientName">Client Name</label>
<input type="text" class="form-control" id="clientName" placeholder="Enter client name"required>
<div class="form-row">
<div class="form-group col-md-6">
<!-- <div class="form-group"> -->
<label for="inputPassword4" class="col-form-label">Make</label>
<select class="form-control SelExample" name="make" id="make" <?= isset($vehicle['make']) ? '' : 'required' ?>>
<?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?>
<?php foreach ($makeData as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["make_id"] ?>" <?= isset($vehicle['make']) && $vehicle['make'] == $value["make_id"] ? 'selected' : '' ?>>
<?= $value["make"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<div class="form-group col-md-6">
<label for="inputPassword4" class="col-form-label">Model</label>
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
<?php if (isset($vehicle["model_name"])) : ?>
<option value="<?= $vehicle["model"] ?>" >
<?= $vehicle["model_name"]; ?>
</option>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Reg Number</label>
<input type="text" class="form-control" name="reg_no" id="reg_no" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<!-- <div class="form-group"> -->
<label for="clientName">Client Name</label>
<select class="form-control cleint-select SelExample" name="client_id" id=clientName <?= isset($sales['client_id']) ? '' : 'required' ?>>
<?= isset($sales['client_id']) ? '' : '<option value="">Select a Client</option>' ?>
<?php foreach ($client as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["client_id"] ?>" <?= isset($sales['client_id']) && $sales['client_id'] == $value["client_id"] ? 'selected' : '' ?>>
<?= $value["client_name"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-12">
<label for="clientMobile">Mobile</label>
<input type="text" class="form-control" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required>
<input type="text" class="form-control" id="mobile" name="mobile"placeholder="Enter mobile number" maxlength="10" minlength="10"onkeypress = "return onlyNumbers(event)"required>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="saveClientBtn">Save Client</button>
<button type="button" class="btn btn-primary" id="saveVehcileBtn">Save Vehicle</button>
</div>
</div>
</div>
@ -386,12 +440,10 @@ $(document).ready(function() {
'<td style="width:10%;"><input type="number" class="form-control item-quantity"min="0" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]"readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax"name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" /></td>' +
'<td style="width:10%;"><select class="form-control item-discount-type"name="discount_type[]"><option value="₹">₹</option><option value="%">%</option></select></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount"name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
'<td ><center><i class="fa fa-trash remove-item"></i></center></td>' +
'</tr>';
$('#itemTable tbody').append(newRow);
@ -437,16 +489,20 @@ $(document).on('click', '.remove-item', function() {
});
$(document).ready(function() {
// Event listener for customer selection change
$('.cleint-select').change(function() {
$('.vehicle-select').change(function() {
var clientId = $(this).val();
if (clientId !== '') {
var vehicleId = $(this).val();
// console.log(vehicleId);
if (vehicleId !== '') {
// Find the selected client in the client data
var selectedClient = clients.find(function(client) {
return client.client_id == clientId;
var selectedClient = vehicles.find(function(vehicle) {
return vehicle.vehicle_id == vehicleId;
});
console.log(selectedClient);
// Populate the billing address, city, state, country, and postal code fields
$('input[name="client_id"]').val(selectedClient.client_name);
$('input[name="billing_address"]').val(selectedClient.address);
$('input[name="billing_address"]').val(selectedClient.address);
$('input[name="city"]').val(selectedClient.city);
$('input[name="state"]').val(selectedClient.state);
@ -457,9 +513,32 @@ $(document).ready(function() {
});
});
</script>
<script>
$(document).ready(function() {
// Event listener for customer selection change
$('.cleint-select').change(function() {
var clientId = $(this).val();
// console.log(vehicleId);
if (clientId !== '') {
// Find the selected client in the client data
var selectedClients = clients.find(function(client) {
return client.client_id == clientId;
});
console.log(selectedClients);
// Populate the billing address, city, state, country, and postal code fields
$('input[name="mobile"]').val(selectedClients.mobile_no);
}
});
});
</script>
<script>
// Define the clients array and populate it with data
var vehicles = <?php echo json_encode($vehicle); ?>;
var clients = <?php echo json_encode($client); ?>;
</script>
<script>
@ -489,44 +568,50 @@ function initializeSelect2() {
$(document).ready(function() {
// AJAX request to save client
$('#saveClientBtn').click(function() {
$('#saveVehcileBtn').click(function() {
var clientName = $('#clientName').val();
var clientMobile = $('#clientMobile').val();
if(clientName != '' && clientMobile != ''){
var clientMobile = $('#mobile').val();
var reg_no = $('#reg_no').val();
var model = $('#model').val();
var make = $('#make').val();
if(clientName != '' && clientMobile != ''&&reg_no != '' && model != '' && make != ''){
// Send AJAX request to save the client
$.ajax({
url: '<?php echo base_url().'save_client'?>', // URL to your save_client method
url: '<?php echo base_url().'save_vehicle'?>', // URL to your save_client method
method: 'POST',
data: {
client_name: clientName,
mobile_no: clientMobile
client_id: clientName,
mobile_no: clientMobile,
reg_no:reg_no,
model:model,
make:make
},
success: function(response) {
// Check if the operation was successful
if (response.success) {
// Client saved successfully, close the modal and do any additional actions
$('#addClientModal').modal('hide');
$('#addVehicleModal').modal('hide');
// Optionally, you can update the client dropdown or show a success message
toastr.success("Client saved successfully!");
toastr.success("Vehicle saved successfully!");
window.location.reload(); // Reload the page
} else {
// Client save operation failed, display error message
toastr.warning("Failed to save client. Please try again");
toastr.warning("Failed to save vehicle. Please try again");
}
},
error: function(xhr, status, error) {
// AJAX request failed, display error message
console.error('Error occurred while saving client:', error);
toastr.warning("Failed to save client. Please try again");
console.error('Error occurred while saving vehicle:', error);
toastr.warning("Failed to save vehicle. Please try again");
}
});
}else{
toastr.warning("Please Fill Name and Mobile data");
toastr.warning("Please Fill All Data");
}
@ -534,9 +619,43 @@ $(document).ready(function() {
});
</script>
<script>
$(".SelExample").select2();
// Event listener for change in make select dropdown
$("#make").on('change', function() {
var selected_makes = $(this).val(); // Get an array of selected make IDs
// AJAX request to fetch models based on selected make IDs
$.ajax({
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
type: 'POST',
dataType: 'json',
data: { selected_makes: [selected_makes] },
success: function(response) {
// Clear existing options in model select dropdown
$("#model").empty();
$("#model").append('<option value=""> Select a Model </option>');
// Populate model select dropdown with fetched models
$.each(response, function(index, model) {
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
});
// Refresh select2 to reflect changes
$("#model").trigger('change');
},
error: function(xhr, status, error) {
console.error(error); // Log any errors to the console
}
});
});
document.getElementById('reg_no').addEventListener('input', function(event) {
var inputText = event.target.value;
event.target.value = inputText.toUpperCase();
});
</script>

View File

@ -20,10 +20,10 @@
<form action="<?= base_url() . "add_vehicle"; ?>" method="post">
<h4 class="header-title">Vehicle Details :</h4><br>
<h4 class="header-title">Vehicle Details :</h4>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Make</label>
<label for="inputPassword4" class="col-form-label">Make<span class="text-danger">*</span></label>
<select class="form-control SelExample" name="make" id="make" <?= isset($vehicle['make']) ? '' : 'required' ?>>
<?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?>
<?php foreach ($makeData as $value) : ?>
@ -36,7 +36,7 @@
</select>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Model</label>
<label for="inputPassword4" class="col-form-label">Model<span class="text-danger">*</span></label>
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
<?php if (isset($vehicle["model_name"])) : ?>
<option value="<?= $vehicle["model"] ?>" >
@ -46,7 +46,7 @@
</select>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Reg Number</label>
<label for="inputPassword4" class="col-form-label">Reg Number<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="regno" id="regno" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
</div>
<div class="form-group col-md-4">
@ -58,10 +58,11 @@
<input type="text" class="form-control" name="colour" placeholder="Colour"value="<?= isset($vehicle['colour']) ? $vehicle['colour'] : '' ?>" >
</div>
</div>
<h4 class="header-title">Client Details :</h4><br>
</br>
<h4 class="header-title">Client Details :</h4>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Client Name</label>
<label for="inputEmail4" class="col-form-label">Client Name<span class="text-danger">*</span></label>
<?= isset($vehicle['client_id']) ? '' : '<i type="button" class="fe-plus-circle" id="addClientModalButton" style="font-size: 18px;" data-toggle="modal" data-target="#addClientModal" title="Add Client"></i>' ?>
<select class="form-control cleint-select SelExample" id="clientData" name="client_name" required data-toggle="select2" >
<option value="">Select a Client</option>
@ -74,14 +75,15 @@
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="inputAddress" class="col-form-label">Mobile<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($vehicle['mobile_no']) ? $vehicle['mobile_no'] : '' ?>" required maxlength="10" minlength="10">
</div>
<div class="form-group col-md-4">
<label for="inputEmail4" class="col-form-label">Email</label>
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($vehicle['email']) ? $vehicle['email'] : '' ?>" >
</div>
<div class="form-group col-md-4">
<label for="inputAddress" class="col-form-label">Mobile</label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($vehicle['mobile_no']) ? $vehicle['mobile_no'] : '' ?>" required maxlength="10" minlength="10">
</div>
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Address</label>
<input type="text" class="form-control" name="address" placeholder="Address"value="<?= isset($vehicle['address']) ? $vehicle['address'] : '' ?>" >