CHANGE_JOB_CARD_SUB_SERVICE_DESCRIPTION_CUSTOM_COMPLAINT : AADHAVAN

This commit is contained in:
aadhavan valli 2024-05-23 09:00:03 +05:30
parent c5580b4a9d
commit bc36cceaa3
12 changed files with 302 additions and 47 deletions

View File

@ -9,6 +9,7 @@ use App\Models\JobcardCustomComplaintModel;
use App\Models\JobcardOSModel;
use App\Models\JobcardServiceModel;
use App\Models\JobcardProductModel;
use App\Models\JobcardSubServiceModel;
use App\Models\ProductModel;
use App\Models\ServiceModel;
use App\Models\ClientModel;
@ -427,23 +428,36 @@ class Jobcard extends BaseController
$productModel = new ProductModel();
$JobcardModel = new JobcardModel();
$JobcardProductModel = new JobcardProductModel();
$JobcardSubServiceModel = new JobcardSubServiceModel();
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
$JobcardOSModel = new JobcardOSModel();
$ComplaintModel = new ComplaintModel();
$OutsourceModel = new OutsourceModel();
$ServiceModel = new ServiceModel();
/*** SERVICE DATA ***/
$servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
// Using '&' to reference the original array element
foreach ($servicedata as &$value) {
// sub product datas
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
$product = $JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock')
->join('products', 'products.product_id = job_card_product.product_id')
->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll();
$value['product'] = $product;
// sub service data
$service_ids = !empty(json_decode($value['sub_service_id'], true)) ? json_decode($value['sub_service_id'], true) : [0];
$service = $JobcardSubServiceModel->select('job_card_sub_service.* , services.service_name as s_name')
->join('services', 'services.service_id = job_card_sub_service.sub_service_id')
->whereIn('job_card_sub_service.job_card_sub_service_id', $service_ids)->findAll();
$value['sub_service'] = $service;
}
// echo "<pre>";
// print_r($value);die;
$data['editservicedata'] = $servicedata;
/*** COMPLAINT DATA ***/
$complaintdata = $JobcardModel->complaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
@ -519,7 +533,7 @@ class Jobcard extends BaseController
->where('qty_stock >',0)
->findAll();
$product = array_merge($product1, $product2);
$data['product']=$product;
// $data['product']=$product;
$data['product']=$product;
// echo json_encode($product);die;
@ -572,6 +586,8 @@ class Jobcard extends BaseController
// echo $this->request->getPost('delete_items');die;
// echo $this->request->getPost('issued_items');die;
// echo json_encode($this->request->getPost());die;
// echo "<pre>";
// print_r($this->request->getPost());die;
$JobcardModel = new JobcardModel();
if($this->session->get('logged_user_role') == "Store Manager") {
$data['status'] = $this->request->getPost('status');
@ -582,6 +598,7 @@ class Jobcard extends BaseController
return redirect()->to('job_card_index');
}
$JobcardProductModel = new JobcardProductModel();
$JobcardSubServiceModel = new JobcardSubServiceModel();
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
@ -642,6 +659,9 @@ class Jobcard extends BaseController
$data = json_decode($_POST['products']);
$service_data = $data[0]->service;
// echo "<pre>";
// print_r($service_data);die;
foreach ($service_data as $item) {
// Insert into the service table
$service['job_card_id'] = $job_card_id;
@ -664,10 +684,12 @@ class Jobcard extends BaseController
$JobcardServiceModel->update($item->id, $service);
$service_id = $item->id;
}
// do same as sub_service product_data_insertion
if(isset($item->product)) { $this->product_data_insertion($job_card_id, $service_id, $JobcardServiceModel, $item, $JobcardProductModel, $status, $rework); }
if(isset($item->sub_service)) { $this->sub_service_data_insertion($job_card_id, $service_id, $JobcardServiceModel, $item, $JobcardSubServiceModel, $status, $rework); }
}
/********** INSERT COMPLAINT DATA ************/
$complaint_data = $data[0]->complaint;
@ -782,9 +804,14 @@ class Jobcard extends BaseController
{
// Insert into the product table
$id = [];
// echo "<pre>";
// print_r($item);die;
foreach ($item->product as $pt) {
$product['job_card_id'] = $job_card_id;
$product['product_id'] = $pt->p_id;
if(isset($pt->name)){
$product['name'] = $pt->name;
}
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount / $pt->qty; //(isset($rework) ? 0 : $pt->amount / $pt->qty );
@ -814,9 +841,63 @@ class Jobcard extends BaseController
}
}
public function sub_service_data_insertion($job_card_id, $parent_id, $ParentModel, $item, $JobcardSubServiceModel, $status, $rework)
{
// Insert into the product table
$id = [];
foreach ($item->sub_service as $pt) {
$product['job_card_id'] = $job_card_id;
$product['sub_service_id'] = $pt->s_id;
if(isset($pt->name)){
$product['name'] = $pt->name;
}
$product['qty'] = $pt->qty;
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount / $pt->qty; //(isset($rework) ? 0 : $pt->amount / $pt->qty );
if(empty($pt->id)) {
$JobcardSubServiceModel->insert($product);
$job_card_sub_service_id = $JobcardSubServiceModel->getInsertID();
}
else {
if($status == 'Cancelled')
{
$product = [];
$product['job_card_id'] = $job_card_id;
$product['sub_service_id'] = $pt->s_id;
$product['is_active'] = 0;
}
$old_data = $JobcardSubServiceModel->find($pt->id);
if($pt->qty != $old_data['issued_qty'] && $pt->qty > $old_data['issued_qty']) { $product['status'] = 0; }
// echo $pt->id;die;
$JobcardSubServiceModel->update($pt->id, $product);
$job_card_sub_service_id = $pt->id;
}
array_push($id, $job_card_sub_service_id);
}
// $job_card_service_id = $parent_id;
// $res =$ParentModel->update($parent_id, ['sub_service_id' => json_encode($id) ]);
$parent_data_get = $ParentModel->where('job_card_id', $job_card_id)->first();
$job_card_service_id = $parent_data_get['job_card_service_id'];
$res= $ParentModel->update($job_card_service_id, ['sub_service_id' => json_encode($id)]);
if($res) {
// print_r($parent_id);
// print_r($id);
// die;
// $this->product_data_maintanence($id, $status);
}
}
public function delete_items($delArr)
{
$JobcardProductModel = new JobcardProductModel();
$JobcardSubServiceModel = new JobcardSubServiceModel();
$JobcardServiceModel = new JobcardServiceModel();
$JobcardComplaintModel = new JobcardComplaintModel();
$JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
@ -833,6 +914,16 @@ class Jobcard extends BaseController
}
}
$sub_service_data = $data[0]->sub_service;
if(!empty($sub_service_data)) {
foreach ($sub_service_data as $item) {
$conditions = [ 'job_card_sub_service_id' => $item ];
// $product_deleted_data = $JobcardProductModel->where($conditions)->findAll();
// $this->product_delete($service_deleted_data[0]['product_id']);
$JobcardSubServiceModel->where($conditions)->delete();
}
}
$service_data = $data[0]->service;
if(!empty($service_data)) {
foreach ($service_data as $item) {

View File

@ -34,6 +34,7 @@ class Outsourcing extends BaseController
"labour_cost" => $this->request->getPost('labour_cost'),
"cost_with_tax" => $this->request->getPost('cost_with_tax'),
"tax" => $this->request->getPost('tax'),
"description" => $this->request->getPost('description'),
];
if ($this->request->getPost('id') == '') {

View File

@ -5,5 +5,5 @@ class JobcardProductModel extends Model
{
protected $table = 'job_card_product';
protected $primaryKey = 'job_card_product_id';
protected $allowedFields = ['job_card_product_id','job_card_id' , 'product_id', 'qty', 'tax', 'amount', 'status', 'issued_qty', 'is_active'];
protected $allowedFields = ['job_card_product_id','job_card_id' ,'name', 'product_id', 'qty', 'tax', 'amount', 'status', 'issued_qty', 'is_active'];
}

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', 'job_card_id', 'service_id', 'labour_cost', 'product_id', 'qty','tax','amount', 'isactive'];
protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'labour_cost', 'product_id','sub_service_id', 'qty','tax','amount', 'isactive'];
}

View File

@ -0,0 +1,9 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class JobcardSubServiceModel extends Model
{
protected $table = 'job_card_sub_service';
protected $primaryKey = 'job_card_sub_service_id';
protected $allowedFields = ['job_card_sub_service_id','job_card_id' ,'name', 'sub_service_id', 'qty', 'tax', 'amount', 'status', 'issued_qty', 'is_active'];
}

View File

@ -5,5 +5,5 @@ class OutsourceModel extends Model
{
protected $table = 'out_source';
protected $primaryKey = 'id';
protected $allowedFields = ['id','business_id','name','labour_cost','tax','cost_with_tax','is_active'];
protected $allowedFields = ['id','business_id','name','labour_cost','tax','cost_with_tax','description','is_active'];
}

View File

@ -13,8 +13,7 @@
<div class="page-title-right">
<a href="<?= base_url() . "job_card_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</li>
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
<li class="breadcrumb-item active">Datatables</li> -->
</ol>
@ -26,7 +25,7 @@
<div class="col-md-12">
<div class="card">
<div class="card-body">
<form id="form-submit" action="<?= base_url() . "add_jobs"; ?>" method="post">
<form id="form-submit" action="<?= base_url() . "add_jobs"; ?>" method="post" style="line-height:0.5;">
<input type="hidden" id="product_response" name="products" value="">
<input type="hidden" id="delete_items" name="delete_items" value="">
<input type="hidden" id="issued_items" name="issued_items" value="">
@ -177,16 +176,16 @@
<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="addService">
<h4><i class="fa fa-plus" aria-hidden="true"></i>Service</h4>
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Service</h4>
</a>
<a class="btn" id="addcomplaint">
<h4><i class="fa fa-plus" aria-hidden="true"></i>Complaint</h4>
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Complaint</h4>
</a>
<a class="btn" id="addCustomComplaint">
<h4><i class="fa fa-plus" aria-hidden="true"></i>Custom Complaint</h4>
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Custom Complaint</h4>
</a>
<a class="btn" id="addOutsource">
<h4><i class="fa fa-plus" aria-hidden="true"></i>Outsource</h4>
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Outsource</h4>
</a>
</div>
<?php } ?>
@ -385,6 +384,7 @@ $(document).ready(async function() {
tr = $('#productItemTable tbody').append(newRow);
// initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_sub_service_data(value.sub_service);
await edit_product_data(value.product);
editlabourcost(value,'service_lb');
}
@ -570,7 +570,7 @@ $(document).ready(async function() {
action = '<center><i class="fa fa-trash remove-item" id="remove-item"></i></center>';
}
var newRow = `<tr class="product"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td>
<td style="padding-left: 40px !important;"><i class="fa fa-wrench" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i>
<td style="padding-left: 40px !important;"><i class="fa fa-archive" style="font-size: 13px;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 + '" selected>' + product.pname + '</option>';
@ -589,11 +589,61 @@ $(document).ready(async function() {
'<input value="product" name="item_type" hidden>'+
'</td>';
<?php if(!isset($rework)) { ?>
newRow += '<td hidden><input name="id" value="'+product.job_card_product_id+'"></td></tr>';
newRow += '<td hidden><input name="id" value="'+product.job_card_product_id+'"></td>';
<?php } else { ?>
newRow += '<td hidden><input name="id" value=""></td></tr>';
newRow += '<td hidden><input name="id" value=""></td>';
<?php } ?>
newRow += '<td hidden><input value="'+product.pname+'" name="name"></td></tr>' ;
$('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr);
// initializeSelect2();
}
}
function edit_sub_service_data(sub_services) {
for (const sub_service of sub_services) {
<?php if(isset($rework)) { ?> sub_service.amount = 0; <?php } ?>
total_wih_tax =( Number(sub_service.amount) + (Number(sub_service.amount) * (sub_service.tax / 100)) )* sub_service.qty;
total_tax_amt = Number(sub_service.amount) * (sub_service.tax / 100);
var action;
if(logged_user == 'Store Manager')
{
action = `<center><input type="checkbox" class="checkbox-item" ${sub_service.status == 1 ? 'checked' : ''} id="issued-item"></center>`;
}
else
{
action = '<center><i class="fa fa-trash remove-item" id="remove-item"></i></center>';
}
var newRow = `<tr class="sub_service"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td>
<td style="padding-left: 40px !important;"><i class="fa fa-wrench" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i>
<select class="form-control book-select SelExample sub_service" name="item_details[]" required data-toggle="select2" style="width: 249px !important;">`;
newRow += '<option value="' + sub_service.sub_service_id + '" selected>' + sub_service.name + '</option>';
newRow += '</select></td>' +
'<td><input type="text" class="form-control rate-d-only" value="'+sub_service.amount+'" readonly /></td>' +
'<td hidden><input hidden type="text" class="form-control item-rate" name="unit-price[]" value="' + sub_service.amount * sub_service.qty + '" readonly /></td>' +
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(sub_service.qty_stock)+'" value="' + sub_service.qty + '" name="quantity[]"/></td>';
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
newRow += '<td><input type="number" class="form-control issued-qty" min="'+sub_service.issued_qty+'" max="'+sub_service.qty+'" value="'+sub_service.issued_qty+'" name="issued-qty" /></td>';
<?php } ?>
newRow += '<td> <input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + sub_service.tax + '" readonly /></td>' +
'<td><input type="text" class="form-control total-tax-amount" value="'+total_tax_amt.toFixed(2)+'" readonly /></td>' +
'<td><input type="text" class="form-control item-amount" name="amount[]" value="' + total_wih_tax.toFixed(2) + '" readonly/></center></td>' +
'<td>'+
action+
'<input value="sub_service" name="item_type" hidden>'+
'</td>';
<?php if(!isset($rework)) { ?>
newRow += '<td hidden><input name="id" value="'+sub_service.job_card_sub_service_id+'"></td>';
<?php } else { ?>
newRow += '<td hidden><input name="id" value=""></td>';
<?php } ?>
newRow += '<td hidden><input value="'+sub_service.name+'" name="name"></td></tr>' ;
$('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr);
@ -783,7 +833,8 @@ $(window).on('load', function() {
else if(className == 'custom_complaint_lb') {
previousRow = $(this).closest('tr').prevAll(".custom_complaint_class").first();
labour_rate = previousRow.find('.labour_cost');
labour_rate.val(actual_amount.toFixed(2));
// labour_rate.val(actual_amount.toFixed(2));
labour_rate.val(parseInt(actual_amount, 10));
item_rate = previousRow.find('.item-rate1');
item_rate.val(actual_amount.toFixed(2));
@ -934,6 +985,10 @@ $(window).on('load', function() {
var fifthTd = row.querySelector("td:nth-child(6)");
var sixthTd = row.querySelector("td:nth-child(4)");
var eigthTd = row.querySelector("td:nth-child(10)");
if (row.querySelector("td:nth-child(11)")) {
var ninthTd = row.querySelector("td:nth-child(11)");
}
// Check if the second <td> element contains a <select> element
var selectFirstElement = firstTd.querySelector("input");
@ -942,6 +997,9 @@ $(window).on('load', function() {
var selectFifthElement = fifthTd.querySelector("input");
var selectsixthElement = sixthTd.querySelector("input");
var selecteightElement = eigthTd.querySelector("input");
if(ninthTd){
var selectninthElement = ninthTd.querySelector("input");
}
if (selectElement) {
// Get the class name of the <select> element
@ -954,16 +1012,20 @@ $(window).on('load', function() {
var amount = selectsixthElement.value;
var id = selecteightElement.value;
var labour_cost = selectFirstElement.value;
var name ='';
if(selectninthElement){
var name = selectninthElement.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", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
addProductToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'name' : name, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
else if(mapTable == "complaint") {
addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'id': id, 'name' :name, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
else if(mapTable == "custom-comp") {
addProductToLastObjectByKey(dataMapArray, "custom_complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
@ -972,6 +1034,14 @@ $(window).on('load', function() {
addProductToLastObjectByKey(dataMapArray, "os", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
}
}
else if (className.includes("sub_service") )
{
if(mapTable == "service"){
addSubServiceToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'name' : name, 's_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }],true);
}
}
else if(className.includes("service"))
{
mapTable = "service";
@ -1012,10 +1082,25 @@ $(window).on('load', function() {
}
}
}
console.log(array,'dataMapArray11');
}
function addSubServiceToLastObjectByKey(array, key, sub_service) {
for (const obj of array) {
if (obj[key]) {
const lastObjectIndex = obj[key].length - 1;
const lastObject = obj[key][lastObjectIndex];
if (!lastObject.sub_service) {
lastObject.sub_service = sub_service;
}
else {
lastObject.sub_service.push(sub_service[0]);
}
}
}
}
$(document).ready(function() {
$('#submit-btn').click(function(event) {
var isValid = $('#form-submit')[0].checkValidity();
@ -1090,7 +1175,8 @@ $(window).on('load', function() {
$(this).closest('tr').find('.item-tax').val(Number(service_data.tax));
$(this).closest('tr').find('.labour_cost').val(unitPrice);
await labourcost(service_data.labour_cost,service_data.tax,$(this).closest('tr'),'service_lb');
service_child_products(service_data,$(this).closest('tr'))
service_child_products(service_data,$(this).closest('tr'));
service_child_services(service_data,$(this).closest('tr'));
}
calculateAmount($(this).closest('tr'),className,'parent');
@ -1270,20 +1356,22 @@ $(window).on('load', function() {
}
const service_child_products = async (data,tr) => {
console.log(JSON.parse(data.product_id));
// console.log("products");
// console.log(products);
// 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 && item.qty_stock > 0;
});
var cgst = parseFloat(product.cgst);
var sgst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
total_wih_tax = ( Number(product.unit_price) ) + ( Number(product.unit_price) * (tax / 100) );
total_tax_amt = Number(product.unit_price) * (tax / 100);
var newRow = '<tr class="product"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fa fa-wrench" style="font-size: 13px;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;">';
var newRow = '<tr class="product"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fa fa-archive" style="font-size: 13px;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><input type="text" class="form-control rate-d-only" value="'+ Number(product.unit_price).toFixed(2) +'" readonly /></td>' +
@ -1294,6 +1382,7 @@ $(window).on('load', function() {
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + total_wih_tax.toFixed(2) + '" readonly/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id" value=""></td>' +
'<td hidden><input value="'+product.product_name+'" name="name"></td>' +
'</tr>';
@ -1304,6 +1393,47 @@ $(window).on('load', function() {
});
}
const service_child_services = async (data,tr) => {
JSON.parse(data.sub_service_id).forEach(async(element,index) => {
if(element == 0) return;
var service = services.find(function(item) {
return item.service_id == element ;
});
var cgst = parseFloat(service.cgst);
var sgst = parseFloat(service.sgst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
total_wih_tax = ( Number(service.labour_cost) ) + ( Number(service.labour_cost) * (tax / 100) );
total_tax_amt = Number(service.labour_cost) * (tax / 100);
var newRow = '<tr class="sub_service"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fa fa-wrench" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><select class="form-control book-select SelExample sub_service" name="item_details[]" required data-toggle="select2" style="width: 249px !important;">';
newRow += '<option value="' + service.service_id + '">' + service.service_name + '</option>';
newRow += '</select></td>' +
'<td><input type="text" class="form-control rate-d-only" value="'+ Number(service.labour_cost).toFixed(2) +'" readonly /></td>' +
'<td hidden><input type="text" class="form-control item-rate" name="unit-price[]" value="' + service.labour_cost + '" readonly /></td>' +
'<td><input type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]"/></td>' +
'<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
'<td><input type="text" class="form-control total-tax-amount" value="'+ total_tax_amt.toFixed(2) +'" readonly /></td>' +
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + total_wih_tax.toFixed(2) + '" readonly/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="sub_service" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id" value=""></td>' +
'<td hidden><input value="'+service.service_name+'" name="name"></td>' +
'</tr>';
// $('#productItemTable tbody').append(newRow);
$(newRow).insertAfter(tr);
// initializeSelect2();
});
}
// Event listener for quantity change
$(document).on('input', '.item-quantity', async function() {
calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
@ -1428,7 +1558,7 @@ $(window).on('load', function() {
selected_pr.push(rowProductid);
});
var newRow = '<tr class="product"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fa fa-wrench" style="font-size: 13px;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>';
var newRow = '<tr class="product"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fa fa-archive" style="font-size: 13px;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++)
{
var product = productarray[i];
@ -1447,6 +1577,7 @@ $(window).on('load', function() {
'<td><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
'<td hidden><input type="hidden" name="id"></td>' +
'<td hidden><input value="'+product.product_name+'" name="name"></td>' +
'</tr>';
// $('#productItemTable tbody').append(newRow);
@ -1615,7 +1746,7 @@ $(window).on('load', function() {
var $targetField = $previousRow.find('.item-rate1');
$targetField.val(enteredValue);
var $targetField2 = $previousRow.find('.labour_cost');
$targetField2.val(enteredValue);
$targetField2.val(int(enteredValue));
updateCalculations();
});
/** TAX FIELD */
@ -1701,7 +1832,7 @@ $(window).on('load', function() {
/**
* REMOVE ITEMS FROM THE TABLE
* **/
delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [], 'os': [], 'product' : [] }];
delete_items_id = [{ 'service': [], 'complaint': [] , 'sub_service': [], 'custom_complaint': [], 'os': [], 'product' : [] }];
$(document).on('click', '.remove-item', function() {
var $closestTR = $(this).closest('tr');
@ -1717,6 +1848,12 @@ $(window).on('load', function() {
delete_items_id[0].complaint.push(id);
console.log(delete_items_id);
}
else if($closestTR.attr('class') == "sub_service")
{
id = $closestTR.find('input[name="id"]').val();
delete_items_id[0].sub_service.push(id);
console.log(delete_items_id);
}
else if($closestTR.attr('class') == "custom_complaint_class")
{
id = $closestTR.find('input[name="id"]').val();
@ -1736,14 +1873,16 @@ $(window).on('load', function() {
console.log(delete_items_id);
}
while ($closestTR.next().length > 0 && $closestTR.attr('class') != "product") {
if ($closestTR.next().hasClass('service_class') || $closestTR.next().hasClass('complaint_class') || $closestTR.next().hasClass('custom_complaint_class') || $closestTR.next().hasClass('os_class')) {
break;
if ($closestTR.attr('class') !== "product" && $closestTR.attr('class') !== "sub_service") {
while ($closestTR.next().length > 0 ) {
if ($closestTR.next().hasClass('service_class') || $closestTR.next().hasClass('complaint_class') || $closestTR.next().hasClass('custom_complaint_class') || $closestTR.next().hasClass('os_class')) {
break;
}
// Remove the next row
$closestTR.next().remove();
}
// Remove the next row
$closestTR.next().remove();
// Remove the clicked row
}
// Remove the clicked row
$closestTR.remove();
updateCalculations();
});

View File

@ -23,6 +23,7 @@
<th>Tax</th>
<th>Labour Charge With Tax</th>
<th>Labour Charge</th>
<th>Description</th>
<th hidden>Status</th>
<th>Actions</th>
</tr>
@ -34,6 +35,7 @@
<td><?= $value['tax']; ?></td>
<td><?= $value['cost_with_tax']; ?></td>
<td><?= $value['labour_cost']; ?></td>
<td><?= $value['description']; ?></td>
<td hidden>
<?php if($value['is_active'] == 1): ?>
<span style="color:green">Active</span>
@ -91,6 +93,10 @@
<label for="labour_cost">Labour Cost </label>
<input class="form-control" type="text" id="labour_cost" placeholder="Labour Charge" required readonly>
</div>
<div class="form-group">
<label for="description">Description </label>
<input class="form-control" type="text" id="description" placeholder="Description" >
</div>
<div class="form-group text-center">
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitComplaint(this)">Submit</button>
</div>
@ -129,6 +135,7 @@
labour_cost: $('#labour_cost').val(),
tax: $('#tax').val(),
cost_with_tax: $('#cost_with_tax').val(),
description: $('#description').val(),
};
$.ajax({
@ -161,6 +168,7 @@
$('#name').val(response.os_data[0].name);
$('#labour_cost').val(response.os_data[0].labour_cost);
$('#cost_with_tax').val(response.os_data[0].cost_with_tax);
$('#description').val(response.os_data[0].description);
var tax = parseFloat(response.os_data[0].tax);
var selectElement = document.getElementById('tax');

View File

@ -188,7 +188,6 @@ p {
<tr style="border: 1px solid black;">
<th style="border: 0.5px solid black;">Bike Detail</th>
<th style="border: 0.5px solid black;">Out Source List</th>
<th style="border: 0.5px solid black;"></th>
</tr>
<?php foreach ($outsource as $key => $item) : ?>
@ -212,11 +211,6 @@ p {
<?php endforeach; ?>
</table>
</td>
<td style="border: 0.5px solid black;">
<?php foreach ($item['products'] as $key => $item) : ?>
(<?= $item['pname'] ?> x <?= $item['qty'] ?>)<br>
<?php endforeach; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -238,8 +238,8 @@
<h4 class="header-title">Description Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Description</label>
<textarea class="form-control" name="description" placeholder="Description"value="<?= isset($products['description']) ? $products['description'] : '' ?>" required>
<label for="description" class="col-form-label">Description</label>
<textarea class="form-control" name="description" placeholder="Description"value="<?= isset($products['description']) ? $products['description'] : '' ?>" >
</textarea>
</div>
</div>

View File

@ -20,7 +20,7 @@
<div class="card">
<div class="card-body">
<form action="<?= base_url() . "add_sales"; ?>" method="post">
<form action="<?= base_url() . "add_sales"; ?>" method="post" style="line-height:0.5;">
<!-- <h4 class="header-title">Sales Order Details :</h4><br> -->
<div class="form-row">

View File

@ -64,7 +64,7 @@
<option value="">Select a Product</option>
<?php foreach ($product as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["product_id"] ?>" <?= isset($services['product_id']) && is_array(json_decode($services['sub_service_id'])) && in_array($value['product_id'], json_decode($services['product_id'])) ? 'selected' : '' ?>>
<option value="<?= $value["product_id"] ?>" <?= isset($services['product_id']) && is_array(json_decode($services['product_id'])) && in_array($value['product_id'], json_decode($services['product_id'])) ? 'selected' : '' ?>>
<?= $value["product_name"]; ?>
</option>
<?php endif; ?>
@ -105,7 +105,16 @@
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Labour Cost + Tax<span class="text-danger">*</span></label>
<input type="number" class="form-control" name="labour_cost_With_Tax" id="LabourCostWithTax" placeholder="Labour Cost + Tax" value="<?= isset($services['price']) ? $services['price'] : '' ?>" required>
<?php
if(isset($services['labour_cost'])){
$labour_cost = ($services['labour_cost'] / 100) * $tax;
$labour_cost = $labour_cost + $services['labour_cost'];
}else{
$labour_cost = 0;
}
?>
<input type="number" class="form-control" name="labour_cost_With_Tax" id="LabourCostWithTax" placeholder="Labour Cost + Tax" value="<?= (int)$labour_cost; ?>" required>
</div>
@ -128,8 +137,8 @@
<h4 class="header-title">Description Details :</h4>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Description</label>
<textarea class="form-control" name="description" placeholder="Description" required><?= isset($services['description']) ? $services['description'] : '' ?></textarea>
<label for="description" class="col-form-label">Description</label>
<textarea class="form-control" name="description" placeholder="Description" ><?= isset($services['description']) ? $services['description'] : '' ?></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
@ -344,7 +353,8 @@ document.getElementById('category').addEventListener('change', function() {
}
else if(this.value == '' ) {
$('#productCost').val(0);
labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
// labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val());
labour_cost = ($('#LabourCostWithTax').val() == '') ? 0 : parseInt($('#LabourCostWithTax').val());
add = parseInt($('#productCost').val()) + parseInt($('#serviceCost').val()) + labour_cost;
console.log("New value of #serviceCost:", add);
@ -426,7 +436,10 @@ document.getElementById('category').addEventListener('change', function() {
var labour_cost = labour_cost_With_Tax / parseFloat((tax / 100) + 1);
$("input[name='labour_cost']").val(labour_cost.toFixed(2));
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost.toFixed(2));
// add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost.toFixed(2));
add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost_With_Tax);
// console.log("add");
// console.log(add);
$('#price').val(add);
}