CHANGE_CONFICLT_MERGE : AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-27 12:55:26 +05:30
commit 4c6a88db01
10 changed files with 580 additions and 184 deletions

View File

@ -3,18 +3,25 @@
namespace App\Controllers;
use App\Models\JobcardModel;
use App\Models\JobcardProductModel;
use App\Models\JobcardComplaintModel;
use App\Models\JobcardCustomComplaintModel;
use App\Models\JobcardServiceModel;
use App\Models\JobcardProductModel;
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()
{
@ -29,7 +36,6 @@ class Jobcard extends BaseController
$JobcardModel = new JobcardModel();
$jobs=$JobcardModel->getJobCardsWithProductsAndService($this->session->get('logged_user_branch_id'));
$data['jobs']=$jobs;
// echo "<pre>";
// print_r($jobs);die;
@ -51,7 +57,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;
@ -61,10 +74,26 @@ class Jobcard extends BaseController
} else if ($job_card_id !== '0')
{
$productModel = new ProductModel();
$JobcardModel = new JobcardModel();
$JobcardProductModel = new JobcardProductModel();
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
$servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
foreach ($servicedata as $key => $value) {
$product_ids = json_decode($value['product_id'], true);
$product = $JobcardProductModel->whereIn('job_card_product_id', $product_ids)->findAll();
echo json_encode($product);die;
}
$data['page_name']="Edit Job Card";
$ClientModel = new ClientModel();
$client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$JobcardModel = new JobcardModel();
$JobcardModel = new JobcardModel();
$productdata = $JobcardModel->job_card_edit($job_card_id, $this->session->get('logged_user_branch_id'));
$jobs=$JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray();
$data['jobs']=$jobs;
$VehicleModel = new VehicleModel();
@ -84,7 +113,7 @@ class Jobcard extends BaseController
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
$productModel = new ProductModel();
// Query the database to find the product based on make_id and model_id
$product = $productModel->where('make_id', $makeId)
@ -104,10 +133,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();
$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();
$data['jobs_service']=$jobs_service;
$data['client']=$client;
@ -125,109 +152,160 @@ class Jobcard extends BaseController
return view('job_card_form',$data);
}
public function add_jobs()
{
// echo json_encode($this->request->getPost());die;
$JobcardModel = new JobcardModel();
$ProductModel = new ProductModel();
$JobcardProductModel = new JobcardProductModel(); // Assuming you have a model for sales_order_product
$JobcardProductModel = new JobcardProductModel();
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
// Prepare data for sales order
$data = [
// Job card INSERT
$job_card_data = [
'client_name' => $this->request->getPost('client_id'),
'mobile_no' => $this->request->getPost('mobile_no'),
'vehicle_id'=>$this->request->getPost('vehicle_id'),
'branch_id'=> $this->session->get('logged_user_branch_id'),
'billing_address' => $this->request->getPost('billing_address'),
'billing_city' => $this->request->getPost('city'),
'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
'branch_id'=> $this->session->get('logged_user_branch_id'),
'subtotal'=> $this->request->getPost('sub_total'),
'tax'=> $this->request->getPost('invoicetax'),
'total'=> $this->request->getPost('grand_total'),
'isactive' => 1
];
// print_r($data);die;
// Insert or update sales order
$job_card_id = $this->request->getPost('job_card_id');
if (!empty($job_card_id)) {
// print_r("hello");die;
$JobcardModel->update($job_card_id, $data);
$JobcardModel->update($job_card_id, $job_card_data);
} else {
$JobcardModel->insert($data);
$JobcardModel->insert($job_card_data);
$job_card_id = $JobcardModel->getInsertID(); // Get the last inserted ID
}
$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]);
// Prepare data for sales order product
// echo "<pre>";
// print_r($this->request->getPost());die;
$product_ids = $this->request->getPost('item_details');
$quantities = $this->request->getPost('quantity');
$discounts = $this->request->getPost('discount_amount');
$discount_types = $this->request->getPost('discount_type');
$amounts = $this->request->getPost('amount');
$itemtax=$this->request->getPost('item-tax');
$unitprice=$this->request->getPost('unit-price');
$job_card_product_id = $this->request->getPost('job_card_product_id');
// print_r($product_ids);die;
// print_r($status);die;
$status = $this->request->getPost('status');
foreach ($product_ids as $key => $product_id) {
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
if ($status == 'Created') {
// echo "hello";die;
$this->updateProductQuantity($ProductModel, $product_id, $qty);
}elseif ($status == 'Cancelled'){
// echo "cancel";die;
/********** INSERT SERVICE DATA ************/
$data = json_decode($_POST['products']);
$service_data = $data[0]->service;
$status = $this->request->getPost('status');
// echo"hello";die;
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
}
foreach ($service_data as $item) {
// Insert into the service table
$service['job_card_id'] = $job_card_id;
$service['service_id'] = $item->service_id;
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardServiceModel->insert($service);
$service_id = $JobcardServiceModel->getInsertID();
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
$discount_type = isset($discount_types[$key]) ? $discount_types[$key] : '';
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
// print_r($discount_type);die;
$product_data = [
'job_card_id' => $job_card_id,
'product_id' => $product_id,
'qty' => $qty,
'discount' => $discount,
'discount_type' => $discount_type,
'net_price'=>$rate,
'tax'=>$tax,
'amount' => $amount,
'isactive'=>1,
];
// print_r($product_data);die;
if (!empty($job_card_product_id[$key])) {
$JobcardProductModel->update($job_card_product_id[$key], $product_data);
} else {
$JobcardProductModel->insert($product_data);
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
$product['job_card_id'] = $job_card_id;
$product['product_id'] = $pt->p_id;
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
array_push($id, $job_card_product_id);
}
$res = $JobcardServiceModel->update($service_id, ['product_id' => json_encode($id) ]);
if($res) {
$this->product_data_maintanence($id, $status);
}
}
/********** INSERT COMPLAINT DATA ************/
$complaint_data = $data[0]->complaint;
foreach ($complaint_data as $item) {
// Insert into the service table
$service['job_card_id'] = $job_card_id;
$service['complaint_id'] = $item->complaint_id;
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardComplaintModel->insert($service);
$complaint_id = $JobcardComplaintModel->getInsertID();
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
$product['job_card_id'] = $job_card_id;
$product['product_id'] = $pt->p_id;
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
array_push($id, $job_card_product_id);
}
$res =$JobcardComplaintModel->update($complaint_id, ['product_id' => json_encode($id) ]);
if($res) {
$this->product_data_maintanence($id, $status);
}
}
/********** INSERT CUSTOM COMPLAINT DATA ************/
$c_complaint_data = $data[0]->custom_complaint;
foreach ($c_complaint_data as $item) {
// Insert into the service table
$service['job_card_id'] = $job_card_id;
$service['complaint_name'] = $item->complaint_id;
$service['qty'] = $item->quality;
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
$JobcardCustomComplaintModel->insert($service);
$cc_complaint_id = $JobcardCustomComplaintModel->getInsertID();
// Insert into the product table
$id = [];
foreach ($item->product as $pt) {
$product['job_card_id'] = $job_card_id;
$product['product_id'] = $pt->p_id;
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount;
$JobcardProductModel->insert($product);
$job_card_product_id = $JobcardProductModel->getInsertID();
array_push($id, $job_card_product_id);
}
$res =$JobcardCustomComplaintModel->update($cc_complaint_id, ['product_id' => json_encode($id) ]);
if($res) {
$this->product_data_maintanence($id, $status);
}
}
return redirect()->to('job_card_index');
}
public function product_data_maintanence($id_array,$status)
{
$ProductModel = new ProductModel();
$JobcardProductModel = new JobcardProductModel();
foreach ($id_array as $key => $product_id) {
$product = $JobcardProductModel->find($product_id);
$qty = isset($product['qty']) ? $product['qty'] : 0;
if ($status == 'Created') {
$this->updateProductQuantity($ProductModel, $product['product_id'], $qty);
}elseif ($status == 'Cancelled'){
$this->addBackProductQuantity($ProductModel, $product['product_id'], $qty);
}
}
}
private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
{
// Fetch current product quantity

View File

@ -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'];
}

View 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', 'tax', 'amount','isactive'];
}

View 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','complaint_name', 'product_id', 'qty', 'tax', 'amount','isactive'];
}

View File

@ -5,7 +5,10 @@ class JobcardModel extends Model
{
protected $table = 'job_card';
protected $primaryKey = 'job_card_id';
protected $allowedFields = ['job_card_id','vehicle_id','branch_id','order_number','sale_order','client_mobile_no','client_name','delivery_on','fuel','kilometer','materiality','customer_complaints','billing_address','billing_city','billing_state','billing_country','billing_postal_code','isactive','total','tax','subtotal','discount','status'];
protected $allowedFields = ['job_card_id','vehicle_id','branch_id',
'order_number','client_mobile_no','client_name',
'billing_address','billing_city','billing_state','billing_country',
'billing_postal_code','status','subtotal','tax','total','isactive'];
@ -13,24 +16,34 @@ 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_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_product.job_card_id) AS product_count, vehicle.reg_no');
// Join the sales_order_product table based on job_card_id
$this->join('job_card_service', 'job_card_service.job_card_id = job_card.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('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id');
// Group by job_card_id to get count of products per sales order
$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');
// Get the results
return $this->findAll();
}
public function service_data($job_card_id, $logged_user_branch_id)
{
$this->select('job_card.*, job_card_service.*');
$this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
$this->where('job_card_service.isactive', 1);
$this ->where('job_card.job_card_id',$job_card_id);
$this ->where('job_card.branch_id',$logged_user_branch_id);
return $this->findAll();
}
}

View File

@ -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','job_card_id' , 'product_id', 'qty', 'tax', 'amount', 'isactive'];
}

View File

@ -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','tax','amount', 'isactive'];
}

View File

@ -19,11 +19,12 @@
<div class="col-md-12">
<div class="card">
<div class="card-body">
<form action="<?= base_url() . "add_jobs"; ?>" method="post">
<form id="form-submit" 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>
@ -200,7 +210,7 @@
</div>
</div>
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="submit" id="submit-btn" class="btn btn-primary">Submit</button>
<?php endif; ?>
</form>
</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,192 @@
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');
}
$(document).ready(function() {
$('#submit-btn').click(function(event) {
// Prevent the default form submission
event.preventDefault();
data_contruction_for_save();
$('#form-submit').submit();
});
});
// 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,65 +613,92 @@
// 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);
// 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();
var product = services.find(function(item) {
return item.service_id == productId;
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-service').val(tax.toFixed(2));
$(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;
});
var cgst = parseFloat(product.cgst);
var igst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + igst;
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() {
$(document).on('input change', '.item-quantity', async function() {
// let promise = new Promise((resolve,reject) => {
calculateAmount($(this).closest('tr'));
updateCalculations(); // Added for updating calculations when quantity changes
// resolve()
// })
// promise.then(() => {
updateCalculations(); // Added for updating calculations when quantity changes
// });
});
// Function to calculate subtotal
function calculateSubtotal() {
@ -554,9 +772,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++)
{
@ -574,15 +792,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++)
{
@ -591,12 +811,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>';
@ -615,6 +899,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

View File

@ -39,7 +39,7 @@
<thead>
<tr>
<th>Order Number</th>
<th>Order Number</th>
<th>Reg No</th>
<th>Client Name</th>
<th>Client Mobile</th>

View File

@ -320,16 +320,18 @@ 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;
console.log("New value of #serviceCostttt:", add);
// 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);
}
});
@ -364,14 +366,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);
@ -390,13 +392,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>