CHANGE_jobcard_module:ss
This commit is contained in:
parent
1bec144563
commit
64a2499c2a
@ -3,18 +3,23 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\JobcardModel;
|
||||
use App\Models\JobcardProductModel;
|
||||
use App\Models\JobcardCustomComplaintModel;
|
||||
use App\Models\JobcardServiceModel;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\ServiceModel;
|
||||
use App\Models\ClientModel;
|
||||
use App\Models\ComplaintModel;
|
||||
use App\Models\BikemodelsModel;
|
||||
use App\Models\BikemakeModel;
|
||||
use App\Models\VehicleModel;
|
||||
use App\Models\SalesOrderModel;
|
||||
use App\Models\SalesOrderProductModel;
|
||||
use Mpdf\Mpdf;
|
||||
class Jobcard extends BaseController
|
||||
{
|
||||
public $session;
|
||||
public $BikemodelsModel;
|
||||
public $BikemakeModel;
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@ -51,7 +56,14 @@ class Jobcard extends BaseController
|
||||
$ProductModel = new ProductModel();
|
||||
$product=$ProductModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
$ServiceModel = new ServiceModel();
|
||||
// echo $this->session->get('logged_user_branch_id');die;
|
||||
$service=$ServiceModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
|
||||
// echo json_encode($service);die;
|
||||
|
||||
$ComplaintModel = new ComplaintModel();
|
||||
$complaint=$ComplaintModel->where('isactive',1)->findAll();
|
||||
|
||||
$data['complaint']= $complaint;
|
||||
$data['product_1']=$product;
|
||||
$data['product']="";
|
||||
$data['service_1']=$service;
|
||||
@ -104,8 +116,8 @@ class Jobcard extends BaseController
|
||||
->findAll();
|
||||
$data['product']=$product;
|
||||
$data['service']=$service;
|
||||
$JobcardProductModel = new JobcardProductModel();
|
||||
$jobs_product= $JobcardProductModel->where('job_card_id', $job_card_id)->findAll();
|
||||
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
|
||||
$jobs_product= $JobcardCustomComplaintModel->where('job_card_id', $job_card_id)->findAll();
|
||||
$data['jobs_product']=$jobs_product;
|
||||
$JobcardServiceModel = new JobcardServiceModel();
|
||||
$jobs_service= $JobcardServiceModel->where('job_card_id', $job_card_id)->findAll();
|
||||
@ -128,13 +140,13 @@ class Jobcard extends BaseController
|
||||
|
||||
public function add_jobs()
|
||||
{
|
||||
// echo $this->request->getPost('products');die;
|
||||
$JobcardModel = new JobcardModel();
|
||||
$ProductModel = new ProductModel();
|
||||
$JobcardProductModel = new JobcardProductModel(); // Assuming you have a model for sales_order_product
|
||||
|
||||
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
|
||||
$JobcardServiceModel = new JobcardServiceModel();
|
||||
|
||||
// Prepare data for sales order
|
||||
// Job card INSERT
|
||||
$data = [
|
||||
'client_name' => $this->request->getPost('client_id'),
|
||||
'vehicle_id'=>$this->request->getPost('vehicle_id'),
|
||||
@ -143,11 +155,6 @@ class Jobcard extends BaseController
|
||||
'mobile_no' => $this->request->getPost('mobile_no'),
|
||||
'billing_state' => $this->request->getPost('state'),
|
||||
'billing_postal_code' => $this->request->getPost('postalcode'),
|
||||
// 'billing_country' => $this->request->getPost('country'),
|
||||
// 'terms_condition' => $this->request->getPost('terms_condition'),
|
||||
// 'subtotal' => $this->request->getPost('sub_total'),
|
||||
// 'tax' => $this->request->getPost('invoice_tax'),
|
||||
|
||||
'total'=> $this->request->getPost('grand_total'),
|
||||
'status'=> $this->request->getPost('status'),
|
||||
'isactive' => 1, // Assuming this is a default value or handled separately
|
||||
@ -166,10 +173,36 @@ class Jobcard extends BaseController
|
||||
$orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT);
|
||||
// print_r($orderNumber);die;
|
||||
// Update sales order with generated order number
|
||||
$JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
|
||||
// $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
|
||||
// Prepare data for sales order product
|
||||
// echo "<pre>";
|
||||
// print_r($this->request->getPost());die;
|
||||
|
||||
/********** INSERT SERVICE DATA ************/
|
||||
$data = json_decode($_POST['products']);
|
||||
$service_data = $data[0]->service;
|
||||
|
||||
foreach ($service_data as $item) {
|
||||
// Insert into the service table
|
||||
$service['job_card_id'] = $job_card_id;
|
||||
$service['service_id'] = $item->service_id;
|
||||
$service['quality'] = $item->quality;
|
||||
$service['tax'] = $item->tax;
|
||||
$service['amount'] = $item->amount;
|
||||
$JobcardServiceModel->insert($service);
|
||||
$service_id = $JobcardModel->getInsertID();
|
||||
|
||||
// Insert into the product table
|
||||
foreach ($item->product as $product) {
|
||||
$product['product_id'] = $product->p_id;
|
||||
$product['qty'] = $product->qty;
|
||||
$product['tax'] = $product->tax;
|
||||
$product['amount'] = $product->amount;
|
||||
$ProductModel->insert($product);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$product_ids = $this->request->getPost('item_details');
|
||||
$quantities = $this->request->getPost('quantity');
|
||||
$discounts = $this->request->getPost('discount_amount');
|
||||
@ -216,10 +249,10 @@ class Jobcard extends BaseController
|
||||
if (!empty($job_card_product_id[$key])) {
|
||||
|
||||
|
||||
$JobcardProductModel->update($job_card_product_id[$key], $product_data);
|
||||
$JobcardCustomComplaintModel->update($job_card_product_id[$key], $product_data);
|
||||
|
||||
} else {
|
||||
$JobcardProductModel->insert($product_data);
|
||||
$JobcardCustomComplaintModel->insert($product_data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class JobcardOtherWorksModel extends Model
|
||||
{
|
||||
protected $table = 'job_card_other_works';
|
||||
protected $primaryKey = 'job_card_other_works_id';
|
||||
protected $allowedFields = ['job_card_other_works_id','lath','wellding','electrical','painting','fork_bend','lath_note','wellding_note','electrical_note','electrical_note','painting_note','fork_bend_note','job_card_id','isactive'];
|
||||
|
||||
|
||||
}
|
||||
9
app/Models/JobcardComplaintModel.php
Normal file
9
app/Models/JobcardComplaintModel.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class JobcardComplaintModel extends Model
|
||||
{
|
||||
protected $table = 'job_card_complaint';
|
||||
protected $primaryKey = 'job_card_complaint_id';
|
||||
protected $allowedFields = ['job_card_complaint_id','job_card_id','complaint_id','product_id', 'qty', 'isactive'];
|
||||
}
|
||||
9
app/Models/JobcardCustomComplaintModel.php
Normal file
9
app/Models/JobcardCustomComplaintModel.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
class JobcardCustomComplaintModel extends Model
|
||||
{
|
||||
protected $table = 'job_card_custom_complaint';
|
||||
protected $primaryKey = 'job_card_cc_id';
|
||||
protected $allowedFields = ['job_card_cc_id', 'job_card_id', 'product_id', 'qty', 'isactive'];
|
||||
}
|
||||
@ -13,11 +13,11 @@ class JobcardModel extends Model
|
||||
{
|
||||
// Select required fields from both tables
|
||||
// $this->select('job_card.*, COUNT(sales_order_product.job_card_id) AS product_count,vehicle.reg_no');
|
||||
// $this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
|
||||
$this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, vehicle.reg_no');
|
||||
// $this->select('job_card.*, COUNT(job_card_service.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
|
||||
$this->select('job_card.*, COUNT(job_card_service.job_card_id) AS product_count, vehicle.reg_no');
|
||||
|
||||
// Join the sales_order_product table based on job_card_id
|
||||
$this->join('job_card_product', 'job_card_product.job_card_id = job_card.job_card_id');
|
||||
$this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
|
||||
// $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
|
||||
$this->join('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id');
|
||||
|
||||
@ -25,7 +25,7 @@ class JobcardModel extends Model
|
||||
$this->groupBy('job_card.job_card_id');
|
||||
|
||||
// Add condition to fetch only active sales orders
|
||||
$this->where('job_card_product.isactive', 1);
|
||||
$this->where('job_card_service.isactive', 1);
|
||||
// $this->where('job_card_service.isactive', 1);
|
||||
$this ->where('job_card.branch_id',$logged_user_branch_id);
|
||||
$this->orderBy('job_card.job_card_id','DESC');
|
||||
|
||||
@ -5,7 +5,5 @@ class JobcardProductModel extends Model
|
||||
{
|
||||
protected $table = 'job_card_product';
|
||||
protected $primaryKey = 'job_card_product_id';
|
||||
protected $allowedFields = ['job_card_product_id','item_name','qty','total','net_price','selling_price','discount','job_card_id','isactive'];
|
||||
|
||||
|
||||
protected $allowedFields = ['job_card_product_id', 'product_id', 'qty', 'tax', 'isactive'];
|
||||
}
|
||||
@ -5,7 +5,7 @@ class JobcardServiceModel extends Model
|
||||
{
|
||||
protected $table = 'job_card_service';
|
||||
protected $primaryKey = 'job_card_service_id';
|
||||
protected $allowedFields = ['job_card_service_id','service_name','qty','total','selling_price','discount','net_price','job_card_id','isactive'];
|
||||
protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'product_id', 'qty', 'isactive'];
|
||||
|
||||
|
||||
}
|
||||
@ -20,10 +20,11 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="<?= base_url() . "add_jobs"; ?>" method="post">
|
||||
<input type="hidden" id="product_response" name="products" value="">
|
||||
<!-- <h4 class="header-title">Sales Order Details :</h4><br> -->
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<div class="form-group col-md-3">
|
||||
<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>' ?>
|
||||
|
||||
@ -40,36 +41,19 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-6">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">Make and Model</label>
|
||||
<input type="text" class="form-control" id="makeAndModel" value="<?php echo isset($make_model) ? $make_model : ''; ?>" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-3">
|
||||
<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($jobs['client_name']) ? $jobs['client_name'] : '' ?>" readonly>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<div class="form-group col-md-3">
|
||||
<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($jobs['client_mobile_no']) ? $jobs['client_mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($jobs['status']) ? $jobs['status'] : '' ?>)</label>
|
||||
<select class="form-control status-select" name="status" required data-toggle="select2">
|
||||
<?php if (isset($jobs['status'])): ?>
|
||||
<?php if ($jobs['status'] === 'Cancelled'): ?>
|
||||
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
||||
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<?php else: ?>
|
||||
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<option value="Created" selected>Created</option>
|
||||
<option value="Paid">Paid</option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div><br>
|
||||
<h4 class="header-title">Billing Address Details :</h4><br>
|
||||
<div class="form-row">
|
||||
@ -91,6 +75,25 @@
|
||||
<input type="text" class="form-control" name="postalcode" placeholder="Pin Code"value="<?= isset($jobs['billing_postal_code']) ? $jobs['billing_postal_code'] : '' ?>" maxlength="6" minlength="6" >
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($jobs['status']) ? $jobs['status'] : '' ?>)</label>
|
||||
<select class="form-control status-select" name="status" required data-toggle="select2">
|
||||
<?php if (isset($jobs['status'])): ?>
|
||||
<?php if ($jobs['status'] === 'Cancelled'): ?>
|
||||
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
|
||||
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<?php else: ?>
|
||||
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
|
||||
<option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<option value="Created" selected>Created</option>
|
||||
<option value="Paid">Paid</option>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
@ -98,6 +101,7 @@
|
||||
<table class="table table-bordered" id="productItemTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th hidden></th>
|
||||
<th>Item Details</th>
|
||||
<th>Qty</th>
|
||||
<th>Rate</th>
|
||||
@ -115,8 +119,11 @@
|
||||
<?php foreach ($product as $salechild) :
|
||||
if ($salechild['isactive'] == 1) : ?>
|
||||
<tr>
|
||||
<td hidden style="width:10%;">
|
||||
<input type="number" class="form-control labour-cost" name="labour_cost[]">
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
|
||||
<select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
|
||||
<option value="">Select a Product</option>
|
||||
<?php foreach ($product as $value) : ?>
|
||||
<?php if ((int)$value["isactive"] === 1) : ?>
|
||||
@ -161,12 +168,15 @@
|
||||
</table>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<!-- Show the "Add More Item" button only if invoice_type is not 1 -->
|
||||
<a class="btn" id="addProduct">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
<a class="btn" id="addService">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Service</h4>
|
||||
</a>
|
||||
<a class="btn" id="addcomplaint">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Complaint</h4>
|
||||
</a>
|
||||
<a class="btn" id="addCustomComplaint">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Custom Complaint</h4>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -387,8 +397,8 @@
|
||||
});
|
||||
|
||||
<?php
|
||||
$product_json = json_encode($product_1);
|
||||
$service_json = json_encode($service_1);
|
||||
$product_json = json_encode($product_1);
|
||||
$service_json = json_encode($service_1);
|
||||
?>
|
||||
|
||||
|
||||
@ -409,11 +419,183 @@
|
||||
return validateProductAdded();
|
||||
});
|
||||
|
||||
$(document).on('keyup change', '.item-amount', function() {
|
||||
// Calculate amount and update amount input field
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
var products = <?php echo $product_json; ?>;
|
||||
var services = <?php echo $service_json; ?>;
|
||||
var complaint = <?php echo json_encode($complaint) ?>;
|
||||
var mapTable;
|
||||
function data_contruction_for_save() {
|
||||
|
||||
var dataMapArray = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }];
|
||||
|
||||
// Select all <tr> elements within the tbody of the table with id productItemTable
|
||||
var tableRows = document.querySelectorAll("#productItemTable tbody tr");
|
||||
|
||||
// Loop through each <tr> element
|
||||
tableRows.forEach(function(row) {
|
||||
var secondTd = row.querySelector("td:nth-child(2)");
|
||||
var thirdTd = row.querySelector("td:nth-child(3)");
|
||||
var fifthTd = row.querySelector("td:nth-child(5)");
|
||||
var sixthTd = row.querySelector("td:nth-child(6)");
|
||||
|
||||
// Check if the second <td> element contains a <select> element
|
||||
var selectElement = secondTd.querySelector("select, textarea");
|
||||
var selectThirdElement = thirdTd.querySelector("input");
|
||||
var selectFifthElement = fifthTd.querySelector("input");
|
||||
var selectsixthElement = sixthTd.querySelector("input");
|
||||
|
||||
if (selectElement) {
|
||||
// Get the class name of the <select> element
|
||||
var className = selectElement.className;
|
||||
|
||||
// Get the selected value of the <select> element
|
||||
var selectedValue = selectElement.value;
|
||||
var quality = selectThirdElement.value;
|
||||
var tax = selectFifthElement.value;
|
||||
var amount = selectsixthElement.value;
|
||||
|
||||
// Output the class name and selected value
|
||||
// console.log("Class Name: " + className + ", Selected Value: " + selectedValue);
|
||||
|
||||
if (className.includes("product"))
|
||||
{
|
||||
if(mapTable == "service") {
|
||||
addProductToLastObjectByKey(dataMapArray, "service", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
|
||||
}
|
||||
else if(mapTable == "complaint") {
|
||||
addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
|
||||
}
|
||||
else if(mapTable == "custom-comp") {
|
||||
addProductToLastObjectByKey(dataMapArray, "custom_complaint", [{ 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
|
||||
}
|
||||
}
|
||||
else if(className.includes("service"))
|
||||
{
|
||||
mapTable = "service";
|
||||
dataMapArray[0].service.push({ 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
||||
}
|
||||
else if(className.includes("complaint"))
|
||||
{
|
||||
mapTable = "complaint";
|
||||
dataMapArray[0].complaint.push({ 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
||||
}
|
||||
else if(className.includes("custom-comp"))
|
||||
{
|
||||
mapTable = "custom-comp";
|
||||
dataMapArray[0].custom_complaint.push({ 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log(dataMapArray,'dataMapArray');
|
||||
$('#product_response').val(JSON.stringify(dataMapArray))
|
||||
}
|
||||
|
||||
function addProductToLastObjectByKey(array, key, product) {
|
||||
console.log(product);
|
||||
for (const obj of array) {
|
||||
if (obj[key]) {
|
||||
const lastObjectIndex = obj[key].length - 1;
|
||||
const lastObject = obj[key][lastObjectIndex];
|
||||
if (!lastObject.product) {
|
||||
lastObject.product = product;
|
||||
}
|
||||
else {
|
||||
lastObject.product.push(product[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(array,'dataMapArray11');
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
data_contruction_for_save();
|
||||
// Get class name of the select element
|
||||
var className = $(this).attr('class');
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
if (className.includes("product")) {
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
// calculateAmount($(this).closest('tr'));
|
||||
|
||||
}
|
||||
|
||||
calculateAmount($(this).closest('tr'),className);
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="service_details[]"]', function() {
|
||||
|
||||
data_contruction_for_save();
|
||||
|
||||
// Get class name of the select element
|
||||
var className = $(this).attr('class');
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
if(className.includes("service")) {
|
||||
// Find product details from JSON
|
||||
var service_data = services.find(function(item) {
|
||||
return item.service_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseInt(service_data.price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
service_child_products(service_data,$(this).closest('tr'))
|
||||
// Calculate amount and update amount input field
|
||||
// calculateAmount($(this).closest('tr'));
|
||||
}
|
||||
|
||||
calculateAmount($(this).closest('tr'),className);
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="complaint_details[]"]', function() {
|
||||
data_contruction_for_save();
|
||||
// Get class name of the select element
|
||||
var className = $(this).attr('class');
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
||||
|
||||
|
||||
if(className.includes("complaint")) {
|
||||
// Find product details from JSON
|
||||
var complaint_data = complaint.find(function(item) {
|
||||
return item.complaint_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseInt(complaint_data.labour_charge); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
// calculateAmount($(this).closest('tr'));
|
||||
}
|
||||
|
||||
calculateAmount($(this).closest('tr'),className);
|
||||
updateCalculations();
|
||||
});
|
||||
|
||||
// Function to calculate amount based on rate and quantity
|
||||
function calculateAmount(row) {
|
||||
function calculateAmount(row,type) {
|
||||
// console.log(row);
|
||||
var rate = $(row).find('.item-rate').val();
|
||||
var quantity = $(row).find('.item-quantity').val();
|
||||
@ -422,58 +604,82 @@
|
||||
|
||||
// Retrieve CGST and SGST values from the database for the selected product
|
||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||
if (productId) {
|
||||
if (type.includes("product")) {
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
console.log("22222222222");
|
||||
console.log(product);
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
return item.product_id == productId;
|
||||
});
|
||||
console.log("22222222222");
|
||||
console.log(product);
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
} else {
|
||||
var productId = $(row).find('select[name="item_details_service[]"]').val();
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
}
|
||||
else if(type.includes("service")) {
|
||||
var productId = $(row).find('select[name="service_details[]"]').val();
|
||||
var product = services.find(function(item) {
|
||||
return item.service_id == productId;
|
||||
});
|
||||
console.log("3333333");
|
||||
console.log(product);
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var igst = parseFloat(product.igst);
|
||||
var igst = parseFloat(product.sgst);
|
||||
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + igst;
|
||||
$(row).find('.item-tax-service').val(tax.toFixed(2));
|
||||
console.log(tax);
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
}
|
||||
else if(type.includes("complaint")) {
|
||||
var productId = $(row).find('select[name="complaint_details[]"]').val();
|
||||
var product = complaint.find(function(item) {
|
||||
return item.complaint_id == productId;
|
||||
});
|
||||
console.log("3333333");
|
||||
console.log(product);
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var igst = parseFloat(product.sgst);
|
||||
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + igst;
|
||||
$(row).find('.item-tax').val(tax.toFixed(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const service_child_products = async (data,tr) => {
|
||||
console.log(JSON.parse(data.product_id));
|
||||
JSON.parse(data.product_id).forEach(async(element,index) => {
|
||||
if(element == 0) return;
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == element;
|
||||
});
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
console.log("111111111111");
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
|
||||
var cgst = parseFloat(product.cgst);
|
||||
var sgst = parseFloat(product.sgst);
|
||||
// Calculate total tax by adding CGST and SGST
|
||||
var tax = cgst + sgst;
|
||||
|
||||
var newRow = '<tr><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" style="width: 249px !important;">';
|
||||
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
|
||||
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.unit_price + '" readonly /></td>' +
|
||||
'<td style="width:8%;"> <input type="text" class="form-control item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
|
||||
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + product.unit_price + '" readonly/></td>' +
|
||||
'<td hidden><input type="hidden"></td>' +
|
||||
'<td></td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
// $('#productItemTable tbody').append(newRow);
|
||||
$(newRow).insertAfter(tr);
|
||||
initializeSelect2();
|
||||
|
||||
// Find product details from JSON
|
||||
console.log(products);
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
calculateAmount($(this).closest('tr'));
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Event listener for quantity change
|
||||
$(document).on('input', '.item-quantity', function() {
|
||||
@ -481,8 +687,6 @@
|
||||
updateCalculations(); // Added for updating calculations when quantity changes
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Function to calculate subtotal
|
||||
function calculateSubtotal() {
|
||||
|
||||
@ -556,9 +760,9 @@
|
||||
updateCalculations();
|
||||
|
||||
// Event listener for "Add More Item" button
|
||||
$('#addProduct').click(function() {
|
||||
// console.log(productarray);
|
||||
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
|
||||
$(document).on('click', '#addProduct', function() {
|
||||
|
||||
var newRow = '<tr><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
|
||||
|
||||
for (var i = 0; i < productarray.length; i++)
|
||||
{
|
||||
@ -576,15 +780,17 @@
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#productItemTable tbody').append(newRow);
|
||||
// $('#productItemTable tbody').append(newRow);
|
||||
$(newRow).insertAfter($(this).closest('tr'));
|
||||
initializeSelect2();
|
||||
|
||||
|
||||
});
|
||||
|
||||
$('#addService').click(function() {
|
||||
servicearray = <?php echo json_encode($service_1) ?>;
|
||||
// console.log(servicearray);
|
||||
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
|
||||
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Service</option>';
|
||||
|
||||
for (var i = 0; i < servicearray.length; i++)
|
||||
{
|
||||
@ -593,12 +799,76 @@
|
||||
}
|
||||
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></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="text" class="form-control item-amount" name="amount[]"/></td>' +
|
||||
'<td hidden></td><td hidden><input type="hidden"></td>' +
|
||||
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#productItemTable tbody').append(newRow);
|
||||
initializeSelect2();
|
||||
|
||||
|
||||
});
|
||||
|
||||
$('#addcomplaint').click(function() {
|
||||
complaint = <?php echo json_encode($complaint) ?>;
|
||||
// console.log(productarray);
|
||||
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample complaint" id="complaint_detail" name="complaint_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Complaint</option>';
|
||||
|
||||
for (var i = 0; i < complaint.length; i++)
|
||||
{
|
||||
var complaints = complaint[i];
|
||||
newRow += '<option value="' + complaints.complaint_id + '">' + complaints.name + '</option>';
|
||||
}
|
||||
|
||||
newRow += '</select></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></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="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><input value="service" name="item_type" hidden></td>' +
|
||||
'<td><div style="display: inline-block;">'+
|
||||
'<center><i class="fa fa-trash remove-item"></i></center>'+
|
||||
'</div>'+
|
||||
'<div style="display: inline-block; margin-left: 10px;">'+
|
||||
'<input value="product" name="item_type" hidden>'+
|
||||
'<a class="complaint_detail" id="addProduct" title="Add Product">'+
|
||||
'<i class="fa fa-plus" aria-hidden="true"></i>'+
|
||||
'</a>'+
|
||||
'</div>'+
|
||||
'</td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#productItemTable tbody').append(newRow);
|
||||
initializeSelect2();
|
||||
|
||||
|
||||
});
|
||||
|
||||
$('#addCustomComplaint').click(function() {
|
||||
complaint = <?php echo json_encode($complaint) ?>;
|
||||
// console.log(productarray);
|
||||
var newRow = '<tr><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><textarea class="form-control custom-comp" id="custom_complaint_detail" rows="5"></textarea></td>' +
|
||||
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
|
||||
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" /></td>' +
|
||||
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" /></td>' +
|
||||
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
|
||||
'<td hidden><input type="hidden"></td>' +
|
||||
'<td><div style="display: inline-block;">'+
|
||||
'<center><i class="fa fa-trash remove-item"></i></center>'+
|
||||
'</div>'+
|
||||
'<div style="display: inline-block; margin-left: 10px;">'+
|
||||
'<input value="product" name="item_type" hidden>'+
|
||||
'<a class="custom_complaint_detail" id="addProduct" title="Add Product">'+
|
||||
'<i class="fa fa-plus" aria-hidden="true"></i>'+
|
||||
'</a>'+
|
||||
'</div>'+
|
||||
'</td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
@ -617,6 +887,20 @@
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
$('#addcomplaint').click(function() {
|
||||
var table = document.getElementById("productItemTable");
|
||||
var sum = 0;
|
||||
|
||||
// Loop through each row
|
||||
for (var i = 0; i < table.rows.length; i++) {
|
||||
// Access the 4th cell (index 3) in each row and add its value to the sum
|
||||
sum += parseInt(table.rows[i].cells[0].textContent);
|
||||
}
|
||||
|
||||
console.log("Sum of 4th row values:", sum);
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Event listener for removing item
|
||||
|
||||
@ -293,15 +293,15 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
$('#productCost').val(parseInt(sum));
|
||||
console.log(sum);
|
||||
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + labour_cost;
|
||||
// labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) //+ labour_cost;
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
else if(this.value == '') {
|
||||
$('#productCost').val(0);
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#productCost').val()) + parseInt($('#serviceCost').val()) + labour_cost;
|
||||
// labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
|
||||
add = parseInt($('#productCost').val()) + parseInt($('#serviceCost').val()) //+ labour_cost;
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
@ -337,14 +337,14 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
$('#serviceCost').val(parseInt(ssum));
|
||||
console.log(ssum);
|
||||
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
// labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val());
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
}
|
||||
else if(this.value == '') {
|
||||
$('#serviceCost').val(0);
|
||||
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
// labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()) + labour_cost;
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val());
|
||||
console.log("New value of #serviceCost:", add);
|
||||
$('#price').val(add);
|
||||
@ -363,13 +363,13 @@ document.getElementById('category').addEventListener('change', function() {
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
<!-- <script>
|
||||
$('#labour_cost').on('keyup change', function() {
|
||||
var newValue = ($(this).val() == '') ? 0 : $(this).val();
|
||||
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(newValue);
|
||||
$('#price').val(add);
|
||||
});
|
||||
</script>
|
||||
</script> -->
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user