2396 lines
125 KiB
PHP
Executable File
2396 lines
125 KiB
PHP
Executable File
<?php include('layout/header.php'); ?>
|
|
<style>
|
|
.disabled {
|
|
pointer-events: none;
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
<style>
|
|
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
|
color:#ffffff;
|
|
background: #526dee!important;
|
|
}
|
|
.select2-container .select2-selection--single{
|
|
height: 36px;
|
|
border:1px solid #ced4da;
|
|
}
|
|
.select2-container--default .select2-selection--single .select2-selection__rendered{
|
|
line-height: 36px;
|
|
}
|
|
.select2-container--default .select2-selection--single .select2-selection__arrow{
|
|
top:4px;
|
|
}
|
|
|
|
|
|
</style>
|
|
<style>
|
|
.select2-container .select2-selection--multiple .select2-selection__choice{
|
|
padding: 5px 7px 5px 0 !important;
|
|
color: #000000;
|
|
|
|
}
|
|
.select2-container--default .select2-results__option--highlighted[aria-selected]{
|
|
color:#ffffff;
|
|
background-color: #526dee;
|
|
}
|
|
.select2-container--default .select2-results__option{
|
|
border-bottom: 1px solid #dddddd;
|
|
}
|
|
.select2-container--default .select2-results__option[aria-selected=true]{
|
|
color: #000000;
|
|
background-color: #3efba4;
|
|
font-weight: 500;
|
|
border-bottom: 1px solid #747474;
|
|
}
|
|
</style>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box page-title-box-alt">
|
|
<h4 class="page-title"><?php echo $page_name?></h4>
|
|
<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 class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
|
|
<li class="breadcrumb-item active">Datatables</li> -->
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form id="form-submit" action="<?= base_url() . "add_jobs"; ?>" method="post" style="line-height:0.5;" enctype="multipart/form-data">
|
|
|
|
<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="">
|
|
<!-- <h4 class="header-title">Sales Order Details :</h4><br> -->
|
|
|
|
<div class="form-row">
|
|
<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>' ?>
|
|
|
|
<select class="form-control vehicle-select SelExample job_card_basic_details" name="vehicle_id" id="vehicle_name" <?= isset($sales['vehicle_id']) ? 'readonly' : 'required="true"' ?>>
|
|
|
|
<?= isset($sales['vehicle_id']) ? '' : '<option value="">Select a vehicle</option>' ?>
|
|
<?php foreach ($vehicle as $value) : ?>
|
|
<?php if ((int)$value["isactive"] === 1) : ?>
|
|
<option value="<?= $value["vehicle_id"] ?>" <?= isset($jobs['vehicle_id']) && $jobs['vehicle_id'] == $value["vehicle_id"] ? 'selected' : '' ?>>
|
|
<?= $value["reg_no"]?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<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-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-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="16" minlength="6" onkeypress = "return onlyNumbers(event)" readonly>
|
|
</div>
|
|
</div><br>
|
|
<h4 class="header-title">Billing Address Details :</h4><br>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Address<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="billing_address" placeholder="Address"value="<?= isset($jobs['billing_address']) ? $jobs['billing_address'] : '' ?>" >
|
|
</div>
|
|
|
|
<?php if(!isset($rework)) { ?>
|
|
<input type="hidden" id="job_card_id" name="job_card_id" value="<?= isset($jobs['job_card_id']) ? $jobs['job_card_id'] : '' ?>"readonly>
|
|
<?php } else { ?>
|
|
<input type="hidden" name="rework" value="<?= isset($jobs['job_card_id']) ? $jobs['job_card_id'] : '' ?>"readonly>
|
|
<?php } ?>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">City<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="city" placeholder="City"value="<?= isset($jobs['billing_city']) ? $jobs['billing_city'] : 'Chennai' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">State<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="state" placeholder="State"value="<?= isset($jobs['billing_state']) ? $jobs['billing_state'] : 'Tamil Nadu' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">PIN Code<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="postalcode" placeholder="PIN Code"value="<?= isset($jobs['billing_postal_code']) ? $jobs['billing_postal_code'] : '' ?>" maxlength="6" minlength="6" >
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Fuel Qty<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="fuel_qty" placeholder="Fuel Qty"value="<?= isset($jobs['fuel_qty']) ? $jobs['fuel_qty'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Meter Reading<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="meter" placeholder="Meter Reading"value="<?= isset($jobs['meter']) ? $jobs['meter'] : '' ?>" >
|
|
</div>
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Delivery Date<span class="text-danger"></span></label>
|
|
<input type="date" class="form-control job_card_basic_details" name="delivery_date" placeholder="Delivery Date" value="<?= isset($jobs['delivery_date']) ? $jobs['delivery_date'] : '' ?>">
|
|
</div>
|
|
<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 status_class_for_change" 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>Select Status</option>
|
|
<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>
|
|
<?php if(isset($workers)) { ?>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Assign To</label>
|
|
<select class="form-control SelExample" name="assigned_to[]" id="assigned_to" data-toggle="select2" multiple>
|
|
<?= isset($jobs['assigned_to']) ? '' : '<option value="">Select a Mechanic</option>' ?>
|
|
<?php foreach ($workers as $value) : ?>
|
|
<?php if ((int)$value["isactive"] === 1) : ?>
|
|
<option value="<?= $value["user_id"] ?>" <?= isset($jobs['assigned_to']) && is_array(json_decode($jobs['assigned_to'])) && in_array($value["user_id"], json_decode($jobs['assigned_to'])) ? 'selected' : ''; ?>>
|
|
<?= $value["name"]." - ".$value['roles']; ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-3">
|
|
<label for="inputPassword4" class="col-form-label">Trial Mechanic</label>
|
|
<select class="form-control SelExample" name="trial_mechanic" id="trial_mechanic" data-toggle="select2" >
|
|
<?= isset($jobs['trial_mechanic']) ? '' : '<option value="">Select a Mechanic</option>' ?>
|
|
<?php foreach ($workers as $value) : ?>
|
|
<?php if ((int)$value["isactive"] === 1) : ?>
|
|
<option value="<?= $value["user_id"] ?>" <?= isset($jobs['trial_mechanic']) && $value["user_id"] = $jobs['trial_mechanic'] ? 'selected' : ''; ?>>
|
|
<?= $value["name"]." - ".$value['roles']; ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<?php } ?>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">Note<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control job_card_basic_details" name="note" placeholder="Note"value="<?= isset($jobs['note']) ? $jobs['note'] : '' ?>" >
|
|
</div>
|
|
|
|
</div>
|
|
<div class="form-row">
|
|
<?php if (isset($jobs['status']) && $jobs['status'] !== ''): ?>
|
|
|
|
<div class="form-group col-md-4" id="mode_of_payment_parent_div_id" <?= $jobs['status'] === 'Paid' ? '' : 'style="display:none;"' ?>>
|
|
<label for="mode_of_payment" class="col-form-label">Mode Of Payment<span class="text-danger">*</span>
|
|
<select class="form-control" name="mode_of_payment" id="mode_of_payment" >
|
|
<option value>Select Mode Of Payment</option>
|
|
<option value="online" <?= $jobs['mode_of_payment'] === 'online' ? 'selected' : '' ?> >Online</option>
|
|
<option value="cash" <?= $jobs['mode_of_payment'] === 'cash' ? 'selected' : '' ?>>Cash</option>
|
|
</select>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="files">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12" style="text-align: right;">
|
|
<button type="button" class="btn btn-primary waves-effect btn-sm a1"
|
|
onclick="appendFilesFileds()" id="filebtn">
|
|
Add File
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div id="existingContainer"></div>
|
|
<div id="filesContainer"></div>
|
|
</div>
|
|
|
|
<div class="form-row" id="itemTableContainer">
|
|
<div class="form-group col-md-12">
|
|
<h4>Item Details</h4>
|
|
<br />
|
|
<table class="table table-bordered" id="productItemTable">
|
|
<thead>
|
|
<tr>
|
|
<th hidden></th>
|
|
<th>Item Details</th>
|
|
<th>Rate</th>
|
|
<th hidden>Rate</th>
|
|
<th hidden></th>
|
|
<th>Qty</th>
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
<th>Issued Qty</th>
|
|
<?php } ?>
|
|
<th>Tax (%)</th>
|
|
<th>Tax Amount</th>
|
|
<th>Amount</th>
|
|
<th style="width: 10px;">Action</th>
|
|
<th hidden></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
</tbody>
|
|
</table>
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == 'Administrator' || $logged_user_role == 'Job Card Manager' || $logged_user_role == "Floor Manager" ) ) { ?>
|
|
<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" style="margin-right: 5px;"></i>Service</h4>
|
|
</a>
|
|
<a class="btn" id="addcomplaint">
|
|
<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" style="margin-right: 5px;"></i>Customer Complaint</h4>
|
|
</a>
|
|
<a class="btn" id="addOutsource">
|
|
<h4><i class="fa fa-plus" aria-hidden="true" style="margin-right: 5px;"></i>Outsource</h4>
|
|
</a>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="offset-md-7 col-md-5 card">
|
|
<div class="card-body">
|
|
<h4>Calculation</h4>
|
|
<div class="form-group">
|
|
<label for="subtotal">Subtotal</label>
|
|
<input type="text" class="form-control" id="subtotal" name="sub_total" value="<?= isset($sales['subtotal']) ? $sales['subtotal'] : '' ?>"readonly >
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="invoicetax">Tax Amount<span id=""></span></label>
|
|
<input type="text" class="form-control" id="invoicetax" name="invoicetax" readonly value="<?= isset($sales['tax']) ? $sales['tax'] : '' ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="grandtotal">Estimate</label>
|
|
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="grandtotal">Discount</label>
|
|
<!-- <div class="input-group"> -->
|
|
<input type="number" class="form-control" id="dt_amount" name="discount" value="<?= isset($jobs['discount']) ? $jobs['discount'] : '' ?>">
|
|
<!-- <div class="input-group-append">
|
|
<button class="btn btn-outline-secondary" type="button" id="applyDiscountBtn">Apply</button>
|
|
<button class="btn btn-outline-secondary" type="button" id="refreshDiscountBtn">
|
|
<span class="fas fa-sync-alt"></span>
|
|
</button>
|
|
</div>
|
|
</div> -->
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (!isset($jobs['status']) || $jobs['status'] !== 'Paid') : ?>
|
|
<button type="submit" id="submit-btn" class="btn btn-primary">Submit</button>
|
|
<?php endif; ?>
|
|
<?php if (isset($rework) && $rework = 'Paid') : ?>
|
|
<button type="submit" id="submit-btn" class="btn btn-primary">Submit</button>
|
|
<?php endif; ?>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('layout/footer.php'); ?>
|
|
</div>
|
|
<div class="modal fade" id="addVehicleModal" tabindex="-1" role="dialog" aria-labelledby="addVehicleModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addVehicleModalLabel">Add New Vehicle</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="job_card_add_vehicle">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<!-- <div class="form-group"> -->
|
|
|
|
<label for="inputPassword4" class="col-form-label">Make</label>
|
|
<select class="form-control SelExample" name="make" id="make" <?= isset($vehicle['make']) ? '' : 'required' ?>>
|
|
<?= isset($vehicle['make']) ? '' : '<option value="">Select a Make</option>' ?>
|
|
<?php foreach ($makeData as $value) : ?>
|
|
<?php if ((int)$value["isactive"] === 1) : ?>
|
|
<option value="<?= $value["make_id"] ?>" <?= isset($vehicle['make']) && $vehicle['make'] == $value["make_id"] ? 'selected' : '' ?>>
|
|
<?= $value["make"]; ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">Model</label>
|
|
<select class="form-control SelExample" name="model" id="model" <?= isset($vehicle['model']) ? '' : 'required' ?>>
|
|
<?php if (isset($vehicle["model_name"])) : ?>
|
|
<option value="<?= $vehicle["model"] ?>" >
|
|
<?= $vehicle["model_name"]; ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-12">
|
|
<label for="inputPassword4" class="col-form-label">Reg Number</label>
|
|
<input type="text" class="form-control" name="reg_no" id="reg_no" placeholder="Reg Number"value="<?= isset($vehicle['reg_no']) ? $vehicle['reg_no'] : '' ?>" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<input type="text" value="select" id="formType" hidden>
|
|
|
|
<div class="form-group col-md-12 select">
|
|
<label for="clientName">Client Name</label>
|
|
<i type="button" class="fe-user-plus" id="createClient" style="font-size: 18px;" ></i>
|
|
<select class="form-control cleint-select SelExample" id="clientName" required>
|
|
<option value="">Select a Client</option>
|
|
<?php foreach ($client as $value) : ?>
|
|
<option value="<?= $value["client_id"] ?>">
|
|
<?= $value["mobile_no"] .' - '. $value["client_name"]; ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-12 select">
|
|
<label for="clientMobile">Mobile</label>
|
|
<input type="text" class="form-control client_mob_no" id="clientMobile" placeholder="Enter mobile number" maxlength="16" minlength="6"onkeypress = "return onlyNumbers(event)"required>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="form-group col-md-12 create" style="display:none;">
|
|
<label for="create-clientName">Client Name</label>
|
|
<i type="button" class="fe-user-check" id="selectClient" style="font-size: 18px;" ></i>
|
|
<input type="text" class="form-control" id="create-clientName" placeholder="Enter client name" required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-6 create" style="display:none;">
|
|
<label for="create-clientMobile">Mobile</label>
|
|
<input type="text" class="form-control" id="create-clientMobile" placeholder="Enter mobile number" maxlength="16" minlength="6"onkeypress = "return onlyNumbers(event)"required>
|
|
</div>
|
|
|
|
<div class="form-group col-md-6 create" style="display:none;">
|
|
<label for="create-clientType">Client Type</label>
|
|
<select class="form-control status-select" id="create-clientType" required >
|
|
<option value="">Select a Type</option>
|
|
<option value="Direct" >Direct</option>
|
|
<option value="Mechanic" >Mechanic</option>
|
|
<option value="Exp" >Exp</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
<button type="button" class="btn btn-primary" id="saveVehcileBtn">Save Vehicle</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
/** ACTION */
|
|
var logged_user = <?php echo isset($logged_user_role) ? json_encode($logged_user_role) : '' ?>;
|
|
/***** APPEND DATA ONLY EDIT ( ONLY EDIT ACTION ) ******/
|
|
$(document).ready(async function() {
|
|
/** SERVICE */
|
|
var edit_service_data = <?php echo isset($editservicedata) ? json_encode($editservicedata) : 0 ?>;
|
|
var rework = <?php echo !isset($rework) ? 1 : 0 ?>;
|
|
if(edit_service_data.length > 0 && rework) {
|
|
for (const value of edit_service_data) {
|
|
servicearray = <?php echo isset($service_1) ? json_encode($service_1) : json_encode($service) ?>;
|
|
// console.log(servicearray);
|
|
var newRow = `<tr class="service_class"><td hidden>
|
|
<input type="number" class="form-control labour_cost" name="labour_cost" value="${value.labour_cost}"></td>
|
|
<td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;">`;
|
|
|
|
for (var i = 0; i < servicearray.length; i++)
|
|
{
|
|
var service = servicearray[i];
|
|
if(value.service_id == service.service_id)
|
|
newRow += '<option value="' + service.service_id + '" ' + (value.service_id == service.service_id ? "selected" : "") + '>' + service.service_name + '</option>';
|
|
}
|
|
|
|
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" value="'+value.amount+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>';
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
newRow += '<td><input hidden type="number" class="form-control issued-qty" min"0" max="'+value.qty+'" value="" name="issued-qty" /></td>';
|
|
<?php } ?>
|
|
newRow += '<td><input hidden type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></td>' +
|
|
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="service" name="item_type" hidden></td>';
|
|
<?php if(!isset($rework)) { ?>
|
|
newRow += '<td hidden><input name="id" value="'+value.job_card_service_id+'"></td></tr>';
|
|
<?php } else { ?>
|
|
newRow += '<td hidden><input name="id" value=""></td></tr>';
|
|
<?php } ?>
|
|
// console.log(value);
|
|
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');
|
|
}
|
|
}
|
|
|
|
/** COMPLAINT */
|
|
var edit_complaint_data = <?php echo isset($editcomplaintdata) ? json_encode($editcomplaintdata) : 0 ?>;
|
|
if(edit_complaint_data.length > 0 && rework) {
|
|
for (const value of edit_complaint_data) {
|
|
complaint = <?php echo json_encode($complaint) ?>;
|
|
// console.log(productarray);
|
|
var newRow = '<tr class="complaint_class"><td hidden> <input type="number" class="form-control labour_cost" name="labour_cost" value="'+value.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;">';
|
|
|
|
for (var i = 0; i < complaint.length; i++)
|
|
{
|
|
var complaints = complaint[i];
|
|
if(value.complaint_id == complaints.complaint_id)
|
|
newRow += '<option value="' + complaints.complaint_id + '" ' + (value.complaint_id == complaints.complaint_id ? "selected" : "") + '>' + complaints.name + '</option>';
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" value="'+value.amount+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>';
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
newRow += '<td><input hidden type="number" class="form-control"/></td>';
|
|
<?php } ?>
|
|
newRow += '<td><input hidden type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></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>';
|
|
<?php if(!isset($rework)) { ?>
|
|
newRow += '<td hidden><input name="id" value="'+value.job_card_complaint_id+'"></td></tr>';
|
|
<?php } else { ?>
|
|
newRow += '<td hidden><input name="id" value=""></td></tr>';
|
|
<?php } ?>
|
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
/** APPEND CHILD PRODUCT */
|
|
await edit_product_data(value.product);
|
|
editlabourcost(value,'complaint_lb')
|
|
}
|
|
}
|
|
|
|
/** OUTSOURCING */
|
|
var edit_os_data = <?php echo isset($editosdata) ? json_encode($editosdata) : 0 ?>;
|
|
if(edit_os_data.length > 0 && rework) {
|
|
for (const value of edit_os_data) {
|
|
os_data = <?php echo json_encode($os_data) ?>;
|
|
// console.log(productarray);
|
|
var newRow = '<tr class="os_class"><td hidden> <input type="text" class="form-control labour_cost" name="labour_cost" value="'+value.labour_cost+'"></td><td><select class="form-control book-select SelExample os" id="os_detail" name="os_details[]" required data-toggle="select2" style="width: 249px !important;">';
|
|
|
|
for (var i = 0; i < os_data.length; i++)
|
|
{
|
|
var os = os_data[i];
|
|
if(value.os_id == os.id)
|
|
newRow += '<option value="' + os.id + '" ' + (value.os_id == os.id ? "selected" : "") + '>' + os.name + '</option>';
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" value="'+value.amount+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>';
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
newRow += '<td><input hidden type="number" class="form-control"/></td>';
|
|
<?php } ?>
|
|
newRow += '<td><input hidden type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></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="os_detail" id="addProduct" title="Add Product">'+
|
|
'<i class="fa fa-plus" aria-hidden="true"></i>'+
|
|
'</a>'+
|
|
'</div>'+
|
|
'</td>';
|
|
<?php if(!isset($rework)) { ?>
|
|
newRow += '<td hidden><input name="id" value="'+value.job_card_os_id+'"></td></tr>';
|
|
<?php } else { ?>
|
|
newRow += '<td hidden><input name="id" value=""></td></tr>';
|
|
<?php } ?>
|
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
/** APPEND CHILD PRODUCT */
|
|
await edit_product_data(value.product);
|
|
editlabourcost(value,'os_lb')
|
|
}
|
|
}
|
|
|
|
/** CUSTOM COMPLAINT */
|
|
var edit_ccomplaint_data = <?php echo isset($editccomplaintdata) ? json_encode($editccomplaintdata) : 0 ?>;
|
|
if(edit_ccomplaint_data.length > 0) {
|
|
for (const value of edit_ccomplaint_data) {
|
|
var newRow = '<tr class="custom_complaint_class"><td hidden> <input type="number" class="form-control labour_cost" name="labour_cost" step="0.01" value="'+value.labour_cost+'"></td><td><textarea class="form-control custom-comp" id="custom_complaint_detail" rows="5">'+value.name+'</textarea></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" value="'+value.amount+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate1" value="'+value.amount+'" name="unit-price[]" /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" value="'+value.qty+'" name="quantity[]" readonly/></td>';
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
newRow += '<td><input hidden type="number" class="form-control"/></td>';
|
|
<?php } ?>
|
|
newRow += '<td><input hidden type="text" class="form-control item-tax" value="'+value.tax+'" name="item-tax[]" /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" value="'+value.amount+'" name="amount[]"/></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>';
|
|
<?php if(!isset($rework)) { ?>
|
|
newRow += '<td hidden><input name="id" value="'+value.job_card_cc_id+'"></td></tr>';
|
|
<?php } else { ?>
|
|
newRow += '<td hidden><input name="id" value=""></td></tr>';
|
|
<?php } ?>
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
/** APPEND CHILD PRODUCT */
|
|
await edit_product_data(value.product);
|
|
editlabourcost(value,'custom_complaint_lb')
|
|
}
|
|
}
|
|
|
|
function editlabourcost(data,cls) {
|
|
console.log(data.labour_cost,'data.labour_cost');
|
|
<?php if(isset($rework)) { ?> data.labour_cost = 0; <?php } ?>
|
|
total_wih_tax = Number(data.labour_cost) + (Number(data.labour_cost) * (18 / 100));
|
|
total_tax_amt = Number(data.labour_cost) * (18 / 100);
|
|
|
|
|
|
var newRow = '<tr class="'+cls+'"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fas fa-user-alt" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><input type="text" class="form-control labour_cost" readonly value="Labour Cost"></td>' +
|
|
'<td><input type="text" class="form-control rate-d-only" value="'+data.labour_cost+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate" name="unit-price[]" value="'+data.labour_cost +'" /></td>' +
|
|
'<td><input type="number" class="form-control item-quantity-'+cls+' item-quantity" min="0" name="quantity[]" value="1" readonly /></td>';
|
|
<?php if(isset($logged_user_role) && ( $logged_user_role == "Store Manager" ) ) { ?>
|
|
newRow += '<td><input type="text" readonly value="NIL" type="number" class="form-control"/></td>';
|
|
<?php } ?>
|
|
newRow += '<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="'+18+'" 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 lab_amt" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></td>' +
|
|
'<td hidden></td>' +
|
|
'<td hidden></td>' +
|
|
'</tr>';
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
}
|
|
|
|
function edit_product_data(products) {
|
|
for (const product of products) {
|
|
<?php if(isset($rework)) { ?> product.amount = 0; <?php } ?>
|
|
total_wih_tax =( Number(product.amount) + (Number(product.amount) * (product.tax / 100)) )* product.qty;
|
|
total_tax_amt = Number(product.amount) * (product.tax / 100);
|
|
|
|
var action;
|
|
if(logged_user == 'Store Manager')
|
|
{
|
|
action = `<center><input type="checkbox" class="checkbox-item" ${product.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="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 + '" selected>' + product.pname +'-'+ product.manufacturer_name + '</option>';
|
|
newRow += '</select></td>' +
|
|
'<td><input type="text" class="form-control rate-d-only" value="'+product.amount+'" readonly /></td>' +
|
|
'<td hidden><input hidden type="text" class="form-control item-rate" name="unit-price[]" value="' + product.amount * product.qty + '" readonly /></td>' +
|
|
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(product.qty_stock)+'" value="' + product.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="'+product.issued_qty+'" max="'+product.qty+'" value="'+product.issued_qty+'" name="issued-qty" /></td>';
|
|
<?php } ?>
|
|
newRow += '<td> <input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + product.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="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" readonly/></center></td>' +
|
|
'<td>'+
|
|
action+
|
|
'<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>';
|
|
<?php } else { ?>
|
|
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="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" 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);
|
|
initializeSelect2();
|
|
}
|
|
|
|
}
|
|
});
|
|
/********************************************************************** */
|
|
$(document).ready(function() {
|
|
if(logged_user == 'Store Manager') {
|
|
$('.job_card_basic_details').attr('disabled', 'true');
|
|
$('.fa-trash').addClass('disabled');
|
|
$('#addVehicleModalButton').addClass('disabled');
|
|
$('.item-quantity').attr('readonly', 'true');
|
|
$('.item-amount').attr('readonly', 'true');
|
|
$('#dt_amount').attr('readonly', 'true');
|
|
}
|
|
});
|
|
|
|
$(window).on('load', function() {
|
|
// This code will execute after the page has been reloaded
|
|
vehicle_id = localStorage.getItem('vehicle_id');
|
|
localStorage.removeItem('vehicle_id');
|
|
if(vehicle_id) {
|
|
fetch_data(vehicle_id);
|
|
var vehicleId = vehicle_id;
|
|
if (vehicleId !== '') {
|
|
// Find the selected client in the client data
|
|
var selectedClient = vehicles.find(function(vehicle) {
|
|
return vehicle.vehicle_id == vehicleId;
|
|
});
|
|
|
|
console.log(selectedClient);
|
|
|
|
$('input[name="client_id"]').val(selectedClient.client_name);
|
|
$('input[name="billing_address"]').val(selectedClient.address);
|
|
// $('input[name="billing_address"]').val(selectedClient.address);
|
|
$('input[name="city"]').val(selectedClient.city);
|
|
$('input[name="state"]').val(selectedClient.state);
|
|
$('input[name="country"]').val(selectedClient.country);
|
|
$('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
|
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
|
}
|
|
|
|
$('#vehicle_name').val(vehicle_id).trigger('change');
|
|
|
|
}
|
|
});
|
|
|
|
productarray = [];
|
|
servicearray = [];
|
|
$(document).ready(function() {
|
|
// Event listener for vehicle selection change
|
|
$('.vehicle-select').change(function() {
|
|
$('#productItemTable tbody').empty();
|
|
var vehicleId = $(this).val();
|
|
fetch_data(vehicleId)
|
|
});
|
|
|
|
if($('.vehicle-select').val()) {
|
|
fetch_data($('.vehicle-select').val())
|
|
}
|
|
});
|
|
|
|
function fetch_data(vehicleId) {
|
|
if (vehicleId !== '') {
|
|
// Find the selected vehicle
|
|
var selectedVehicle = vehicles.find(function(vehicle) {
|
|
return vehicle.vehicle_id == vehicleId;
|
|
});
|
|
|
|
// Extract makeId from the selected vehicle
|
|
var makeId = selectedVehicle.make;
|
|
var modelId = selectedVehicle.model;
|
|
// console.log(modelId);
|
|
|
|
// Make sure makeId exists
|
|
if (makeId !== undefined) {
|
|
// Perform AJAX request to fetch product information
|
|
$.ajax({
|
|
url: '<?php echo base_url().'getProducts'?>', // Replace with the actual backend endpoint
|
|
method: 'POST', // or 'GET' based on your server implementation
|
|
dataType: 'json',
|
|
data: {
|
|
make_id: makeId,
|
|
model_id:modelId,
|
|
vehicle_id: vehicleId
|
|
},
|
|
success: function(response) {
|
|
console.log(response);
|
|
productarray = response.product;
|
|
makeAndModel = response.makeName+' '+response.modelName;
|
|
$('#makeAndModel').val(makeAndModel);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error
|
|
console.error('Error fetching product information:', error);
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url().'getServices'?>', // Replace with the actual backend endpoint
|
|
method: 'POST', // or 'GET' based on your server implementation
|
|
dataType: 'json',
|
|
data: {
|
|
make_id: makeId,
|
|
model_id:modelId,
|
|
vehicle_id: vehicleId
|
|
},
|
|
success: function(response) {
|
|
console.log(response);
|
|
servicearray = response.service;
|
|
makeAndModel = response.makeName+' '+response.modelName;
|
|
// $('#makeAndModel').val(makeAndModel);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error
|
|
console.error('Error fetching product information:', error);
|
|
}
|
|
});
|
|
} else {
|
|
console.error('Make ID not found for the selected vehicle');
|
|
}
|
|
}
|
|
}
|
|
|
|
<?php
|
|
$product_json = isset($product_1) ? json_encode($product_1) : json_encode($product);
|
|
$service_json = isset($service_1) ? json_encode($service_1) : json_encode($service);
|
|
?>
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
function validateProductAdded() {
|
|
var rowCount = $('#itemTable tbody tr').length;
|
|
return true;
|
|
}
|
|
|
|
// Event listener for form submission
|
|
$('form').submit(function() {
|
|
return validateProductAdded();
|
|
});
|
|
|
|
$(document).on('keyup change', '.item-amount', function() {
|
|
amount = $(this).val();
|
|
tax = $(this).closest('tr').find('.item-tax').val();
|
|
actual_amount = Number(amount) / (1 + (Number(tax)/100));
|
|
className = $(this).closest('tr').attr('class');
|
|
if(className == 'service_lb') {
|
|
previousRow = $(this).closest('tr').prevAll(".service_class").first();
|
|
|
|
labour_rate = previousRow.find('.labour_cost');
|
|
labour_rate.val(actual_amount);
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount);
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount);
|
|
|
|
tax_amount = amount - actual_amount;
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount);
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount);
|
|
}
|
|
else if(className == 'complaint_lb') {
|
|
previousRow = $(this).closest('tr').prevAll(".complaint_class").first();
|
|
|
|
labour_rate = previousRow.find('.labour_cost');
|
|
labour_rate.val(actual_amount);
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount);
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount);
|
|
|
|
tax_amount = amount - actual_amount;
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount);
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount);
|
|
}
|
|
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));
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount.toFixed(2));
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount.toFixed(2));
|
|
|
|
tax_amount = Number(actual_amount) * (tax / 100);
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount.toFixed(2));
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount.toFixed(2));
|
|
}
|
|
// Calculate amount and update amount input field
|
|
updateCalculations();
|
|
});
|
|
|
|
function updateItemAmounts(discount) {
|
|
var amt = 0;
|
|
$('.lab_amt').each(function() {
|
|
amt = Number($(this).val());
|
|
if(discount > amt) {
|
|
discount = discount - amt;
|
|
$(this).val(0).change();
|
|
}
|
|
else {
|
|
amt = amt - discount;
|
|
$(this).val(amt).change();
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
|
|
var tableData;
|
|
// Update item amounts on change of discount
|
|
$('#applyDiscountBtn').on('click', function() {
|
|
|
|
if($('#dt_amount').val() != '' && $('#dt_amount').val() > 0 && $('#grandtotal').val() > 0) {
|
|
tableData = $('#productItemTable tbody').html();
|
|
|
|
var discount = parseFloat($('#dt_amount').val());
|
|
|
|
$('#refreshDiscountBtn').prop('disabled', false);
|
|
$('#dt_amount').prop('disabled', true);
|
|
$(this).prop('disabled', true);
|
|
updateItemAmounts(discount);
|
|
}
|
|
});
|
|
|
|
$('#refreshDiscountBtn').prop('disabled', true);
|
|
$('#refreshDiscountBtn').on('click', function() {
|
|
$('#productItemTable tbody').html('');
|
|
$('#productItemTable tbody').html(tableData);
|
|
|
|
$('#refreshDiscountBtn').prop('disabled', true);
|
|
$('#dt_amount').val(0);
|
|
$('#dt_amount').prop('disabled', false);
|
|
$('#applyDiscountBtn').prop('disabled', false);
|
|
|
|
// Calculate amount and update amount input field
|
|
updateCalculations();
|
|
});
|
|
|
|
$(document).on('keyup change', '#discout_amount', function() {
|
|
amount = $(this).val();
|
|
tax = $(this).closest('tr').find('.item-tax').val();
|
|
actual_amount = Number(amount) / (1 + (Number(tax)/100));
|
|
actual_amount = actual_amount;
|
|
className = $(this).closest('tr').attr('class');
|
|
if(className == 'service_lb') {
|
|
previousRow = $(this).closest('tr').prevAll(".service_class").first();
|
|
|
|
labour_rate = previousRow.find('.labour_cost');
|
|
labour_rate.val(actual_amount);
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount);
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount);
|
|
|
|
tax_amount = amount - actual_amount;
|
|
console.log(tax_amount,'tax_amount');
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount);
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount);
|
|
}
|
|
else if(className == 'complaint_lb') {
|
|
previousRow = $(this).closest('tr').prevAll(".complaint_class").first();
|
|
|
|
labour_rate = previousRow.find('.labour_cost');
|
|
labour_rate.val(actual_amount);
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount);
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount);
|
|
|
|
tax_amount = amount - actual_amount;
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount);
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount);
|
|
}
|
|
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);
|
|
|
|
item_rate = previousRow.find('.item-rate1');
|
|
item_rate.val(actual_amount);
|
|
|
|
item_rate = $(this).closest('tr').find('.item-rate');
|
|
item_rate.val(actual_amount);
|
|
|
|
tax_amount = amount - actual_amount;
|
|
tax_rate = $(this).closest('tr').find('.total-tax-amount');
|
|
tax_rate.val(tax_amount);
|
|
|
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
|
display_rate.val(actual_amount);
|
|
}
|
|
// 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': [], 'os': [] }];
|
|
|
|
// 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 firstTd = row.querySelector("td:nth-child(1)");
|
|
var secondTd = row.querySelector("td:nth-child(2)");
|
|
var thirdTd = row.querySelector("td:nth-child(5)");
|
|
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");
|
|
var selectElement = secondTd.querySelector("select, textarea");
|
|
var selectThirdElement = thirdTd.querySelector("input");
|
|
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
|
|
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;
|
|
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, 'name' : name, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]);
|
|
}
|
|
else if(mapTable == "complaint") {
|
|
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 }]);
|
|
}
|
|
else if(mapTable == "os") {
|
|
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";
|
|
dataMapArray[0].service.push({'id': id, 'labour_cost': labour_cost, 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
|
}
|
|
else if(className.includes("complaint"))
|
|
{
|
|
mapTable = "complaint";
|
|
dataMapArray[0].complaint.push({ 'id': id, 'labour_cost': labour_cost, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
|
}
|
|
else if(className.includes("custom-comp"))
|
|
{
|
|
mapTable = "custom-comp";
|
|
dataMapArray[0].custom_complaint.push({ 'id': id, 'labour_cost': labour_cost, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount });
|
|
}
|
|
else if(className.includes("os"))
|
|
{
|
|
mapTable = "os";
|
|
dataMapArray[0].os.push({ 'id': id, 'labour_cost': labour_cost, 'os_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');
|
|
}
|
|
|
|
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();
|
|
|
|
// Issued item
|
|
var product = [];
|
|
$('.checkbox-item:checked').each(function() {
|
|
var $closestTR = $(this).closest('tr');
|
|
var id = $closestTR.find('input[name="id"]').val();
|
|
var qty = $closestTR.find('.issued-qty').val();
|
|
product.push({ 'id': id, 'qty': qty}); // Push the id into the array
|
|
});
|
|
$("#issued_items").val(JSON.stringify(product));
|
|
|
|
// event.preventDefault();
|
|
if (isValid) {
|
|
data_contruction_for_save();
|
|
$("#delete_items").val(JSON.stringify(delete_items_id));
|
|
$('#form-submit').submit();
|
|
$('#submit-btn').prop('disabled', true);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Event listener for product selection
|
|
$(document).on('change', 'select[name="item_details[]"]', function() {
|
|
var productId = $(this).val();
|
|
// console.log(productId);
|
|
// Get class name of the select element
|
|
var className = $(this).attr('class');
|
|
// console.log(className);
|
|
var quantity = $(this).closest('tr').find('.item-quantity').val(1);
|
|
// console.log(quantity);
|
|
if (className.includes("product")) {
|
|
// Find product details from JSON
|
|
|
|
// var product = products.find(function(item) {
|
|
var product = productarray.find(function(item) {
|
|
// console.log(item);
|
|
return item.product_id == productId;
|
|
});
|
|
console.log(product,'product');
|
|
|
|
$(quantity).attr('max', product.qty_stock);
|
|
// 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('.rate-d-only').val(unitPrice);
|
|
$(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[]"]', async function() {
|
|
|
|
onchange_remove_subproduct($(this).closest('tr'));
|
|
|
|
// 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 = Number(service_data.labour_cost); // Convert to float if necessary
|
|
console.log(service_data);
|
|
$(this).closest('tr').find('.rate-d-only').val(unitPrice);
|
|
$(this).closest('tr').find('.item-rate1').val(unitPrice);
|
|
$(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_services(service_data,$(this).closest('tr'));
|
|
}
|
|
|
|
calculateAmount($(this).closest('tr'),className,'parent');
|
|
updateCalculations();
|
|
});
|
|
|
|
/*** REMOVE SUBPRODUCT ONCHANGE */
|
|
function onchange_remove_subproduct(tr)
|
|
{
|
|
var $closestTR = tr;
|
|
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;
|
|
}
|
|
// Remove the next row
|
|
$closestTR.next().remove();
|
|
}
|
|
}
|
|
// Event listener for product selection
|
|
$(document).on('change', 'select[name="complaint_details[]"]', async function() {
|
|
|
|
onchange_remove_subproduct($(this).closest('tr'));
|
|
|
|
// 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 = Number(complaint_data.labour_charge); // Convert to float if necessary
|
|
$(this).closest('tr').find('.rate-d-only').val(unitPrice);
|
|
$(this).closest('tr').find('.item-rate1').val(unitPrice);
|
|
$(this).closest('tr').find('.item-tax').val(Number(complaint_data.tax));
|
|
$(this).closest('tr').find('.labour_cost').val(parseInt(complaint_data.labour_charge));
|
|
await labourcost(complaint_data.labour_charge,complaint_data.tax,$(this).closest('tr'),'complaint_lb');
|
|
}
|
|
|
|
calculateAmount($(this).closest('tr'),'complaint','parent');
|
|
updateCalculations();
|
|
});
|
|
|
|
// Event listener for product selection
|
|
$(document).on('change', 'select[name="os_details[]"]', async function() {
|
|
|
|
onchange_remove_subproduct($(this).closest('tr'));
|
|
|
|
// 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("os")) {
|
|
var os = <?php echo json_encode($os_data) ?>;
|
|
// Find product details from JSON
|
|
var os_data = os.find(function(item) {
|
|
return item.id == productId;
|
|
});
|
|
|
|
// Access unit price from product and set it as rate
|
|
var unitPrice = Number(os_data.labour_cost); // Convert to float if necessary
|
|
$(this).closest('tr').find('.rate-d-only').val(unitPrice);
|
|
$(this).closest('tr').find('.item-rate1').val(unitPrice);
|
|
$(this).closest('tr').find('.item-tax').val(Number(os_data.tax));
|
|
$(this).closest('tr').find('.labour_cost').val(Number(os_data.labour_cost));
|
|
await labourcost(os_data.labour_cost,os_data.tax,$(this).closest('tr'),'os_lb');
|
|
}
|
|
|
|
calculateAmount($(this).closest('tr'),'os','parent');
|
|
updateCalculations();
|
|
});
|
|
|
|
// Function to calculate amount based on rate and quantity
|
|
function calculateAmount(row,type,action) {
|
|
console.log(type);
|
|
var rate = $(row).find('.item-rate').val();
|
|
var quantity = $(row).find('.item-quantity').val();
|
|
|
|
// Retrieve CGST and SGST values from the database for the selected product
|
|
var productId = $(row).find('select[name="item_details[]"]').val();
|
|
if (type.includes("product")) {
|
|
// var product = products.find(function(item) {
|
|
var product = productarray.find(function(item) {
|
|
return item.product_id == productId;
|
|
});
|
|
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(0));
|
|
finrate = Number(product.unit_price) * quantity;
|
|
$(row).find('.item-rate').val(finrate);
|
|
// rate = Number(product.unit_price);
|
|
rate = Number(product.total_amount);
|
|
var amount = rate * quantity;
|
|
total_tax_amt = amount - finrate;
|
|
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
|
|
$(row).find('.item-amount').val(amount.toFixed(2));
|
|
}
|
|
else if(type.includes("service")) {
|
|
if(action == 'parent') var $previousRow = row;
|
|
else var $previousRow = row.prevAll(".service_class").first();
|
|
|
|
var tax = $previousRow.find('.item-tax').val();
|
|
$(row).find('.item-tax').val(parseInt(tax).toFixed(2));
|
|
|
|
var $targetField = $previousRow.find('.item-rate1');
|
|
finrate = Number($targetField.val()) * quantity;
|
|
// rate = $targetField.val();
|
|
rate = $targetField.val();
|
|
$(row).find('.item-rate').val(finrate);
|
|
|
|
var amount = (Number(rate) + (Number(rate) * tax / 100)) *quantity;
|
|
total_tax_amt = amount - finrate;
|
|
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
|
|
$(row).find('.item-amount').val(Math.round(amount.toFixed(2)).toFixed(2));
|
|
}
|
|
else if(type.includes("complaint")) {
|
|
if(action == 'parent') var $previousRow = row;
|
|
else var $previousRow = row.prevAll(".complaint_class").first();
|
|
|
|
var tax = $previousRow.find('.item-tax').val();
|
|
$(row).find('.item-tax').val(Number(tax).toFixed(2));
|
|
|
|
var $targetField = $previousRow.find('.item-rate1');
|
|
finrate = Number($targetField.val()) * quantity;
|
|
$(row).find('.item-rate').val(finrate);
|
|
|
|
rate = $targetField.val();
|
|
var amount = (Number(rate) + (Number(rate) * tax / 100)) *quantity;
|
|
total_tax_amt = amount - finrate;
|
|
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
|
|
$(row).find('.item-amount').val(amount.toFixed(2));
|
|
}
|
|
else if(type.includes("os")) {
|
|
if(action == 'parent') var $previousRow = row;
|
|
else var $previousRow = row.prevAll(".os_class").first();
|
|
|
|
var tax = $previousRow.find('.item-tax').val();
|
|
$(row).find('.item-tax').val(Number(tax).toFixed(2));
|
|
|
|
var $targetField = $previousRow.find('.item-rate1');
|
|
finrate = Number($targetField.val()) * quantity;
|
|
$(row).find('.item-rate').val(finrate);
|
|
|
|
rate = $targetField.val();
|
|
var amount = (Number(rate) + (Number(rate) * tax / 100)) *quantity;
|
|
total_tax_amt = amount - finrate;
|
|
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
|
|
$(row).find('.item-amount').val(amount.toFixed(2));
|
|
}
|
|
|
|
}
|
|
|
|
const labourcost = async (cost,tax,tr,cls) => {
|
|
console.log(cost,tax,tr,cls);
|
|
console.log('cost,tax,tr,cls');
|
|
total_wih_tax = Number(cost) + (Number(cost) * (18 / 100));
|
|
total_tax_amt = Number(cost) * (18 / 100);
|
|
var newRow = '<tr class="'+cls+'"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fas fa-user-alt" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><input type="text" class="form-control labour_cost" readonly value="Labour Cost"></td>' +
|
|
'<td><input type="text" class="form-control rate-d-only" value="'+Number(cost)+'" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate" name="unit-price[]" value="'+Number(cost)+'" /></td>' +
|
|
'<td><input type="number" class="form-control item-quantity-'+cls+' item-quantity" min="0" name="quantity[]" value="'+1+'" /></td>' +
|
|
'<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="'+18+'" /></td>' +
|
|
'<td><input type="text" class="form-control total-tax-amount" value="'+Number(total_tax_amt).toFixed(2)+'" readonly /></td>' +
|
|
'<td><input type="text" class="form-control item-amount lab_amt" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></td>' +
|
|
'<td hidden></td>' +
|
|
'<td hidden></td>' +
|
|
'</tr>';
|
|
|
|
$(newRow).insertAfter(tr);
|
|
initializeSelect2();
|
|
}
|
|
|
|
const service_child_products = async (data,tr) => {
|
|
// 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-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 +'-'+ product.manufacturer_name + '</option>';
|
|
newRow += '</select></td>' +
|
|
'<td><input type="text" class="form-control rate-d-only" value="'+ Number(product.unit_price).toFixed(2) +'" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate" name="unit-price[]" value="' + product.unit_price + '" readonly /></td>' +
|
|
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(product.qty_stock)+'" 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="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" 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>';
|
|
|
|
|
|
// $('#productItemTable tbody').append(newRow);
|
|
$(newRow).insertAfter(tr);
|
|
initializeSelect2();
|
|
|
|
});
|
|
}
|
|
|
|
|
|
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="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" 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');
|
|
updateCalculations();
|
|
});
|
|
|
|
// Function to calculate subtotal
|
|
function calculateSubtotal() {
|
|
var subtotal = 0;
|
|
$('.item-rate').each(function() {
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
});
|
|
|
|
return subtotal;
|
|
}
|
|
|
|
// Function to calculate subtotal
|
|
function get_tax_percentage() {
|
|
var tax = 0;
|
|
$('.taxable-value').each(function(index) {
|
|
tax += parseFloat($(this).val()) || 0;
|
|
});
|
|
|
|
return tax;
|
|
}
|
|
|
|
// Function to calculate total tax
|
|
function calculateTax() {
|
|
var subtotal = 0;
|
|
$('.item-rate').each(function() {
|
|
subtotal += parseFloat($(this).val()) || 0;
|
|
});
|
|
|
|
var total = 0;
|
|
$('.item-amount').each(function() {
|
|
total += parseFloat($(this).val()) || 0;
|
|
});
|
|
return total - subtotal;
|
|
}
|
|
|
|
// Event listener for discount change
|
|
$(document).on('input', '#discount_amt', function() {
|
|
console.log(get_tax_percentage());
|
|
discount_amt = Number($(this).val());
|
|
sb_tot = calculateSubtotal() - discount_amt;
|
|
tot = sb_tot + calculateTax();
|
|
|
|
// console.log(get_tax_percentage());
|
|
|
|
$('#subtotal').val(sb_tot.toFixed(2));
|
|
$('#invoicetax').val(calculateTax().toFixed(2));
|
|
$('#grandtotal').val(Math.round(tot.toFixed(2)));
|
|
});
|
|
|
|
// Function to calculate total
|
|
function calculateTotal() {
|
|
var total = 0;
|
|
$('.item-amount').each(function() {
|
|
total += parseFloat($(this).val()) || 0;
|
|
});
|
|
// discount_percentage = Number($('#discount_amt').val());
|
|
// // Calculate the discount
|
|
// discount = total * (discount_percentage / 100);
|
|
// total_with_discount = total - discount;
|
|
return total;
|
|
}
|
|
|
|
// Update subtotal, tax, and total
|
|
function updateCalculations() {
|
|
maxValue = 0;
|
|
$('.lab_amt').each(function() {
|
|
maxValue += parseFloat($(this).val()) || 0;
|
|
});
|
|
|
|
<?php if(!isset($rework)) { ?>
|
|
$('#dt_amount').attr('max', maxValue);
|
|
<?php } ?>
|
|
|
|
if($('#discount_amt').val())
|
|
{
|
|
discount_amt = Number($('#discount_amt').val());
|
|
sb_tot = calculateSubtotal() - discount_amt;
|
|
tot = sb_tot + calculateTax();
|
|
$('#subtotal').val(sb_tot.toFixed(2));
|
|
$('#invoicetax').val(calculateTax().toFixed(2));
|
|
$('#grandtotal').val(Math.round(tot.toFixed(2)));
|
|
<?php if(isset($rework)) { ?>
|
|
$('#dt_amount').attr('readonly', true);
|
|
$('#dt_amount').val(tot.toFixed(2));
|
|
<?php } ?>
|
|
}
|
|
else
|
|
{
|
|
$('#subtotal').val(calculateSubtotal().toFixed(2));
|
|
$('#invoicetax').val(calculateTax().toFixed(2));
|
|
$('#grandtotal').val(Math.round(calculateTotal().toFixed(2)));
|
|
<?php if(isset($rework)) { ?>
|
|
$('#dt_amount').attr('readonly', true);
|
|
$('#dt_amount').val(calculateTotal().toFixed(2));
|
|
<?php } ?>
|
|
}
|
|
}
|
|
|
|
// Event listener for discount change
|
|
$(document).on('input', '.item-discount-amount, .item-discount-type', function() {
|
|
updateCalculations();
|
|
});
|
|
|
|
// Calculate initial values on page load
|
|
updateCalculations();
|
|
|
|
// Event listener for "Add More Item" button
|
|
$(document).on('click', '#addProduct', function() {
|
|
if(productarray.length == 0) {
|
|
productarray = <?php echo json_encode($product) ?>;
|
|
console.log(productarray);
|
|
}
|
|
|
|
selected_pr = [];
|
|
$('tr.product').each(function() {
|
|
var rowProductid = $(this).find('.product').val();
|
|
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-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];
|
|
if(!selected_pr.includes(product.product_id))
|
|
{
|
|
newRow += '<option value="' + product.product_id + '">' + product.product_name + '-' + product.manufacturer_name + '</option>';
|
|
}
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
|
|
'<td><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
|
|
'<td><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
|
'<td><input type="text" class="form-control total-tax-amount" value="" readonly /></td>' +
|
|
'<td><input type="text" class="form-control item-amount" name="amount[]" onblur="floatInput(event)" /></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);
|
|
$(newRow).insertAfter($(this).closest('tr'));
|
|
initializeSelect2();
|
|
});
|
|
|
|
$('#addService').click(function() {
|
|
|
|
if ($('#vehicle_name').val()) {
|
|
|
|
selected_pr = [];
|
|
$('tr.service_class').each(function() {
|
|
var rowProductid = $(this).find('.service').val();
|
|
selected_pr.push(rowProductid);
|
|
});
|
|
|
|
// if(servicearray.length == 0)
|
|
// {
|
|
// servicearray = <?php echo isset($service_1) ? json_encode($service_1) : json_encode($service) ?>;
|
|
// }
|
|
console.log(servicearray);
|
|
var newRow = '<tr class="service_class"><td hidden> <input type="text" 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++)
|
|
{
|
|
var service = servicearray[i];
|
|
if(!selected_pr.includes(service.service_id))
|
|
{
|
|
newRow += '<option value="' + service.service_id + '">' + service.service_name + '</option>';
|
|
}
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' +
|
|
'<td><input hidden type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" name="amount[]"/></td>' +
|
|
'<td><center><i class="fa fa-trash remove-item" id="remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
|
|
'<td hidden><input type="hidden" name="id"></td>' +
|
|
'</tr>';
|
|
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
}else{
|
|
toastr.warning("First Select Vehicle!");
|
|
}
|
|
});
|
|
|
|
/** To achieve this functionality where entering a value in one input field automatically populates another input field
|
|
* ONLY APPLICABLE IN COMPLAINT ONLY
|
|
*/
|
|
$(document).ready(function() {
|
|
/** TAX FIELD */
|
|
$(document).on('input change', '.item-quantity-service_lb', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".service_class").first();
|
|
var $targetField = $previousRow.find('.item-quantity');
|
|
$targetField.val(enteredValue);
|
|
});
|
|
});
|
|
|
|
$('#addcomplaint').click(function() {
|
|
if ($('#vehicle_name').val()) {
|
|
selected_pr = [];
|
|
$('tr.complaint_class').each(function() {
|
|
var rowProductid = $(this).find('.complaint').val();
|
|
selected_pr.push(rowProductid);
|
|
});
|
|
|
|
complaint = <?php echo json_encode($complaint) ?>;
|
|
var newRow = '<tr class="complaint_class"><td hidden> <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];
|
|
if(!selected_pr.includes(complaints.complaint_id))
|
|
{
|
|
newRow += '<option value="' + complaints.complaint_id + '">' + complaints.name + '</option>';
|
|
}
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' +
|
|
'<td><input hidden type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" name="amount[]"/></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>' +
|
|
'<td hidden><input type="hidden" name="id"></td>' +
|
|
'</tr>';
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
}else{
|
|
toastr.warning("First Select Vehicle!");
|
|
}
|
|
|
|
});
|
|
/** To achieve this functionality where entering a value in one input field automatically populates another input field
|
|
* ONLY APPLICABLE IN COMPLAINT ONLY
|
|
*/
|
|
$(document).ready(function() {
|
|
/** TAX FIELD */
|
|
$(document).on('input change', '.item-quantity-complaint_lb', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".complaint_class").first();
|
|
var $targetField = $previousRow.find('.item-quantity');
|
|
$targetField.val(enteredValue);
|
|
});
|
|
});
|
|
|
|
$('#addCustomComplaint').click(function() {
|
|
if ($('#vehicle_name').val()) {
|
|
complaint = <?php echo json_encode($complaint) ?>;
|
|
var newRow = '<tr class="custom_complaint_class"><td hidden> <input type="number" class="form-control labour_cost" step="0.01" name="labour_cost"></td><td><textarea class="form-control custom-comp" id="custom_complaint_detail" required rows="5"></textarea></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" value="1" name="quantity[]" readonly/></td>' +
|
|
'<td><input hidden type="text" class="form-control item-tax" name="item-tax[]" value="18" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" name="amount[]" required/></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></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>' +
|
|
'<td hidden><input type="hidden" name="id" value=""></td>' +
|
|
'</tr>';
|
|
|
|
newRow += '<tr class="custom_complaint_lb"><td hidden><input type="number" class="form-control labour_cost" name="labour_cost"></td><td style="padding-left: 40px !important;"><i class="fas fa-user-alt" style="font-size: 13px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><input type="text" class="form-control labour_cost" value="Labour Cost"></td>' +
|
|
'<td hidden><input type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td><input type="text" class="form-control item-rate item-rate_cc" name="unit-price[]" value="" readonly/></td>' +
|
|
'<td><input type="number" class="form-control item-quantity" min="0" name="quantity[]" value="'+1+'" readonly /></td>' +
|
|
'<td><input type="text" class="form-control taxable-value item-tax item-tax_cc" name="item-tax[]" value="'+18+'" readonly /></td>' +
|
|
'<td><input type="text" class="form-control total-tax-amount" value="" readonly /></td>' +
|
|
'<td><input type="text" class="form-control item-amount lab_amt item-amount_cc" name="amount1[]" onblur="floatInput(event)" value="" required /></td>' +
|
|
'<td hidden></td>' +
|
|
'<td hidden></td>' +
|
|
'</tr>';
|
|
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
}else{
|
|
toastr.warning("First Select Vehicle!");
|
|
}
|
|
});
|
|
|
|
/** To achieve this functionality where entering a value in one input field automatically populates another input field
|
|
* ONLY APPLICABLE IN CUSTOM COMPLAINT ONLY
|
|
*/
|
|
$(document).ready(function() {
|
|
/** RATE FIELD */
|
|
$(document).on('input change', '.item-rate_cc', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
|
|
var $targetField = $previousRow.find('.item-rate1');
|
|
$targetField.val(enteredValue);
|
|
var $targetField2 = $previousRow.find('.labour_cost');
|
|
$targetField2.val(enteredValue);
|
|
updateCalculations();
|
|
});
|
|
/** TAX FIELD */
|
|
$(document).on('input change', '.item-tax_cc', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
|
|
var $targetField = $previousRow.find('.item-tax');
|
|
$targetField.val(enteredValue);
|
|
updateCalculations();
|
|
});
|
|
/** AMOUNT FIELD */
|
|
$(document).on('input change', '.item-amount_cc', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
|
|
var $targetField = $previousRow.find('.item-amount1');
|
|
$targetField.val(enteredValue);
|
|
updateCalculations();
|
|
});
|
|
});
|
|
|
|
|
|
$(document).on('input', '.item_dummy', function() {
|
|
var row = $(this).closest('tr');
|
|
var labourCostInput = row.prevAll('.custom_complaint_class:first').find('.labour_cost');
|
|
var dummyValue = $(this).val();
|
|
labourCostInput.val(dummyValue);
|
|
});
|
|
|
|
$('#addOutsource').click(function() {
|
|
if ($('#vehicle_name').val()) {
|
|
selected_os = [];
|
|
$('tr.os_class').each(function() {
|
|
var rowProductid = $(this).find('.complaint').val();
|
|
selected_os.push(rowProductid);
|
|
});
|
|
|
|
os = <?php echo json_encode($os_data) ?>;
|
|
var newRow = '<tr class="os_class"><td hidden> <input type="text" class="form-control labour_cost" name="labour_cost"></td><td><select class="form-control book-select SelExample os" id="os_detail" name="os_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Outsource</option>';
|
|
|
|
for (var i = 0; i < os.length; i++)
|
|
{
|
|
var os_data = os[i];
|
|
if(!selected_os.includes(os_data.id))
|
|
{
|
|
newRow += '<option value="' + os_data.id + '">' + os_data.name + '</option>';
|
|
}
|
|
}
|
|
|
|
newRow += '</select></td>' +
|
|
'<td><input hidden type="text" class="form-control rate-d-only" readonly /></td>' +
|
|
'<td hidden><input type="text" class="form-control item-rate1" name="unit-price[]" readonly /></td>' +
|
|
'<td><input hidden type="number" class="form-control item-quantity" min="0" name="quantity[]" readonly/></td>' +
|
|
'<td><input hidden type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control total-tax-amount" readonly /></td>' +
|
|
'<td><input hidden type="text" class="form-control item-amount1" name="amount[]"/></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>' +
|
|
'<td hidden><input type="hidden" name="id"></td>' +
|
|
'</tr>';
|
|
$('#productItemTable tbody').append(newRow);
|
|
initializeSelect2();
|
|
}else{
|
|
toastr.warning("First Select Vehicle!");
|
|
}
|
|
});
|
|
/** To achieve this functionality where entering a value in one input field automatically populates another input field
|
|
* ONLY APPLICABLE IN COMPLAINT ONLY
|
|
*/
|
|
$(document).ready(function() {
|
|
/** TAX FIELD */
|
|
$(document).on('input change', '.item-quantity-os_lb', async function() {
|
|
var enteredValue = $(this).val();
|
|
var $previousRow = $(this).closest("tr").prevAll(".os_class").first();
|
|
var $targetField = $previousRow.find('.item-quantity');
|
|
$targetField.val(enteredValue);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* REMOVE ITEMS FROM THE TABLE
|
|
* **/
|
|
delete_items_id = [{ 'service': [], 'complaint': [] , 'sub_service': [], 'custom_complaint': [], 'os': [], 'product' : [] }];
|
|
$(document).on('click', '.remove-item', function() {
|
|
var $closestTR = $(this).closest('tr');
|
|
|
|
if($closestTR.attr('class') == "service_class")
|
|
{
|
|
id = $closestTR.find('input[name="id"]').val();
|
|
delete_items_id[0].service.push(id);
|
|
console.log(delete_items_id);
|
|
}
|
|
else if($closestTR.attr('class') == "complaint_class")
|
|
{
|
|
id = $closestTR.find('input[name="id"]').val();
|
|
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();
|
|
delete_items_id[0].custom_complaint.push(id);
|
|
console.log(delete_items_id);
|
|
}
|
|
else if($closestTR.attr('class') == "os_class")
|
|
{
|
|
id = $closestTR.find('input[name="id"]').val();
|
|
delete_items_id[0].os.push(id);
|
|
console.log(delete_items_id);
|
|
}
|
|
else if($closestTR.attr('class') == "product")
|
|
{
|
|
id = $closestTR.find('input[name="id"]').val();
|
|
delete_items_id[0].product.push(id);
|
|
console.log(delete_items_id);
|
|
}
|
|
|
|
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 clicked row
|
|
}
|
|
$closestTR.remove();
|
|
|
|
updateCalculations();
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
</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
|
|
// Event listener for removing item
|
|
$(document).on('click', '.remove-item', function() {
|
|
var salesOrderProductId = $(this).closest('tr').find('input[name="sales_order_product_id[]"]').val();
|
|
|
|
// AJAX request to delete the sales order product
|
|
$.ajax({
|
|
url: '<?php echo base_url()."delete_sales_product"?>',
|
|
method: 'POST',
|
|
data: { sales_order_product_id: salesOrderProductId },
|
|
success: function(response) {
|
|
// Check if the deletion was successful
|
|
if (response.success) {
|
|
// If successful, remove the row from the table
|
|
$(this).closest('tr').remove();
|
|
updateCalculations(); // Update calculations after removing the row
|
|
} else {
|
|
// If not successful, display an error message
|
|
// alert('Error occurred while deleting the item.');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error occurred while deleting the item:', error);
|
|
}
|
|
});
|
|
});
|
|
$(document).ready(function() {
|
|
// Event listener for customer selection change
|
|
$('.vehicle-select').change(function() {
|
|
|
|
$('tbody').empty();
|
|
var vehicleId = $(this).val();
|
|
if (vehicleId !== '') {
|
|
// Find the selected client in the client data
|
|
var selectedClient = vehicles.find(function(vehicle) {
|
|
return vehicle.vehicle_id == vehicleId;
|
|
});
|
|
|
|
console.log(selectedClient);
|
|
|
|
$('input[name="client_id"]').val(selectedClient.client_name);
|
|
$('input[name="billing_address"]').val(selectedClient.address);
|
|
$('input[name="billing_address"]').val(selectedClient.address);
|
|
$('input[name="city"]').val(selectedClient.city);
|
|
$('input[name="state"]').val(selectedClient.state);
|
|
$('input[name="country"]').val(selectedClient.country);
|
|
$('input[name="mobile_no"]').val(selectedClient.mobile_no);
|
|
$('input[name="postalcode"]').val(selectedClient.postal_code);
|
|
}
|
|
});
|
|
});
|
|
|
|
</script>
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Event listener for customer selection change
|
|
$('.cleint-select').change(function() {
|
|
|
|
var clientId = $(this).val();
|
|
// console.log(vehicleId);
|
|
if (clientId !== '') {
|
|
// Find the selected client in the client data
|
|
var selectedClients = clients.find(function(client) {
|
|
return client.client_id == clientId;
|
|
});
|
|
$('input[id="clientMobile"]').val(selectedClients.mobile_no);
|
|
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
<script>
|
|
// Define the clients array and populate it with data
|
|
var vehicles = <?php echo json_encode($vehicle); ?>;
|
|
var clients = <?php echo json_encode($client); ?>;
|
|
</script>
|
|
<script>
|
|
function onlyNumbers(event){
|
|
var charcode;
|
|
charcode = event.which || event.keyCode;
|
|
if(charcode>= 48 && charcode <= 57)return true;
|
|
return false;
|
|
}
|
|
</script>
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet">
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
|
|
|
<script>
|
|
$(document).ready(function(){
|
|
// Initialize select2
|
|
$(".SelExample").select2();
|
|
});
|
|
function initializeSelect2() {
|
|
$('.SelExample').select2({
|
|
width: '249px'
|
|
});
|
|
}
|
|
</script>
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
// AJAX request to save client
|
|
$('#saveVehcileBtn').click(function() {
|
|
|
|
var formType = $('#formType').val();
|
|
|
|
var reg_no = $('#reg_no').val();
|
|
var model = $('#model').val();
|
|
var make = $('#make').val();
|
|
|
|
var clientName = $('#clientName').val();
|
|
var clientMobile = $('#clientMobile').val();
|
|
|
|
var createclientName = $('#create-clientName').val();
|
|
var createclientMobile = $('#create-clientMobile').val();
|
|
var createclientType = $('#create-clientType').val();
|
|
|
|
if (formType == 'select')
|
|
{
|
|
var ifStatementCondition = "clientName !== '' && clientMobile !== '' && reg_no !== '' && model !== '' && make !== ''";
|
|
} else {
|
|
var ifStatementCondition = "createclientName !== '' && createclientMobile !== '' && createclientType !== '' && reg_no !== '' && model !== '' && make !== ''";
|
|
}
|
|
|
|
if(createclientMobile) {
|
|
var clientArray = <?php echo json_encode($client) ?>;
|
|
console.log(clientArray);
|
|
var mobileIdExists = clientArray.some(function(client) {
|
|
return client.mobile_no.trim() === createclientMobile.trim();
|
|
});
|
|
|
|
if(mobileIdExists) {
|
|
toastr.warning("Mobile Number Already Added!");
|
|
return;
|
|
}
|
|
}
|
|
if (reg_no) {
|
|
$('#saveVehcileBtn').prop('disabled', true);
|
|
$.ajax({
|
|
url: '<?= base_url("checkRegisterNo") ?>', // URL to your controller method for fetching models
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: { register_number: reg_no },
|
|
success: function(response) {console.log("1111111111");
|
|
console.log(response);
|
|
if (response) {
|
|
$('#reg_no').val("");
|
|
toastr.warning("Register Number Already Added!");
|
|
$('#saveVehcileBtn').prop('disabled', false);
|
|
}else{
|
|
if( eval(ifStatementCondition) ){
|
|
|
|
// Send AJAX request to save the client
|
|
$.ajax({
|
|
url: '<?php echo base_url().'save_vehicle'?>', // URL to your save_client method
|
|
method: 'POST',
|
|
data: {
|
|
client_id: clientName,
|
|
mobile_no: clientMobile,
|
|
reg_no:reg_no,
|
|
model:model,
|
|
make:make,
|
|
createclientName:createclientName,
|
|
createclientMobile:createclientMobile,
|
|
createclientType:createclientType,
|
|
formType:formType,
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$('#addVehicleModal').modal('hide');
|
|
toastr.success("Vehicle saved successfully!");
|
|
localStorage.setItem('vehicle_id',response.vehicle_id)
|
|
window.location.reload();
|
|
} else {
|
|
toastr.warning("Failed to save vehicle. Please try again");
|
|
$('#saveVehcileBtn').prop('disabled', false);
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error occurred while saving vehicle:', error);
|
|
toastr.warning("Failed to save vehicle. Please try again");
|
|
$('#saveVehcileBtn').prop('disabled', false);
|
|
}
|
|
});
|
|
}else{
|
|
toastr.warning("Please Fill All Data");
|
|
$('#saveVehcileBtn').prop('disabled', false);
|
|
}
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error); // Log any errors to the console
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
</script>
|
|
<script>
|
|
$(".SelExample").select2();
|
|
|
|
// Event listener for change in make select dropdown
|
|
$("#make").on('change', function() {
|
|
var selected_makes = $(this).val(); // Get an array of selected make IDs
|
|
// AJAX request to fetch models based on selected make IDs
|
|
$.ajax({
|
|
url: '<?= base_url("fetch_models") ?>', // URL to your controller method for fetching models
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: { selected_makes: [selected_makes] },
|
|
success: function(response) {
|
|
// Clear existing options in model select dropdown
|
|
$("#model").empty();
|
|
$("#model").append('<option value=""> Select a Model </option>');
|
|
// Populate model select dropdown with fetched models
|
|
$.each(response, function(index, model) {
|
|
$("#model").append('<option value="' + model.model_id + '">' + model.model_name + '</option>');
|
|
});
|
|
|
|
// Refresh select2 to reflect changes
|
|
$("#model").trigger('change');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error); // Log any errors to the console
|
|
}
|
|
});
|
|
});
|
|
|
|
document.getElementById('reg_no').addEventListener('input', function(event) {
|
|
var inputText = event.target.value;
|
|
event.target.value = inputText.toUpperCase();
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
<script>
|
|
$(document).on('click', '#createClient', function() {
|
|
$('.create').show();
|
|
$('.select').hide();
|
|
$('#formType').val('create');
|
|
|
|
$('#clientName').val('');
|
|
$('#clientMobile').val('');
|
|
|
|
|
|
});
|
|
$(document).on('click', '#selectClient', function() {
|
|
$('.select').show();
|
|
$('.create').hide();
|
|
$('#formType').val('select');
|
|
|
|
$('#create-clientName').val('');
|
|
$('#create-clientMobile').val('');
|
|
$('#create-clientType').val('');
|
|
});
|
|
|
|
$('.status_class_for_change').change(function (params) {
|
|
|
|
if($(this).val() === 'Paid'){
|
|
$('#mode_of_payment_parent_div_id').css('display','');
|
|
$('#mode_of_payment').prop('required','required');
|
|
}else{
|
|
$('#mode_of_payment_parent_div_id').css('display','none');
|
|
$('#mode_of_payment').removeAttr('required');
|
|
}
|
|
})
|
|
$(document).ready(function() {
|
|
var jobcardfiles = <?php echo isset($jobcardfiles) ? json_encode($jobcardfiles) : array() ?>;
|
|
if (jobcardfiles.length !== 0) {
|
|
$.each(jobcardfiles, function(i, item) {
|
|
appendExistingFilesFileds(item)
|
|
});
|
|
|
|
|
|
}
|
|
});
|
|
function appendExistingFilesFileds(data){
|
|
|
|
const base_url = '<?php echo base_url(); ?>';
|
|
var filePath = data != null && data != '' ? data.file_name : '';
|
|
var fileName = data != null && data != '' ? data.manual_file_name : '';
|
|
var fileId = data != null && data != '' ? data.file_id : '';
|
|
var downloadUrl = `${base_url}public/uploads/jobcardfiles/${filePath}`;
|
|
|
|
var newRowHtml = `<div class="form-row pad mb-2">
|
|
<div class="form-group col-md-4">
|
|
<label class="col-form-label">File name</label>
|
|
<input type="text" maxlength="255" class="form-control" value="${fileName}" readonly>
|
|
</div>
|
|
<div class="form-group col-md-8
|
|
" style="padding-top:37px;">
|
|
<a href="${downloadUrl}" download>
|
|
<i class="fa fa-download" aria-hidden="true" style="font-size: 25px;"></i>
|
|
</a>
|
|
<button type="button" class="btn btn-danger btn-sm a1" data-file-id="${fileId}" onclick="removeContact(this)">
|
|
Delete
|
|
</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
|
|
$('#existingContainer').append(newRowHtml);
|
|
}
|
|
|
|
function appendFilesFileds(data) {
|
|
var newRowHtml = `
|
|
<div class="form-row pad">
|
|
<div class="form-group col-md-4">
|
|
<label class="col-form-label">File name</label>
|
|
<input type="text" id="manual_file_name" name="manual_file_name[]" maxlength="255" class="form-control" value="${data != null && data != '' ? data.manual_file_name : ''}">
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label class="col-form-label">File</label>
|
|
<input type="file" id="file" name="file[]" class="form-control">
|
|
</div>
|
|
<div class="form-group col-md-4 p-4">
|
|
<button type="button" class="btn btn-danger btn-sm" onclick="removeContact(this)">Remove</button>
|
|
<button type="button" class="btn btn-primary btn-sm a1" onclick="appendFilesFileds()">Add File</button>
|
|
</div>
|
|
</div>`;
|
|
|
|
$('#filesContainer').append(newRowHtml);
|
|
$('#filesContainer .a1').hide();
|
|
$('#filesContainer .pad:last .a1').show();
|
|
|
|
var len = $('#filesContainer .pad:last .a1');
|
|
var length = (len.length == 0) ? $('#filebtn').show() : $('#filebtn').hide();
|
|
|
|
}
|
|
|
|
function removeContact(button) {
|
|
console.log(button.getAttribute('data-file-id'));
|
|
if (button.getAttribute('data-file-id') != '') {
|
|
$.ajax({
|
|
url: '<?= base_url("deleteJobCardFile") ?>', // URL to your controller method for fetching models
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: { file_id: [button.getAttribute('data-file-id')] },
|
|
success: function(response) {
|
|
if (response.success) {
|
|
toastr.success(response.message);
|
|
} else {
|
|
toastr.warning(response.message);
|
|
}
|
|
// return false;
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// toastr.warning("Failed to remove. Please try again");
|
|
console.error(error);
|
|
// return false;
|
|
}
|
|
|
|
});
|
|
}
|
|
$(button).closest('.pad').remove();
|
|
$('#filesContainer .a1').hide();
|
|
$('#filesContainer .pad:last .a1').show();
|
|
var len = $('#filesContainer .pad:last .a1')
|
|
var length = len.length;
|
|
if (length == 0) {
|
|
$('#filebtn').show()
|
|
} else {
|
|
$('#filebtn').hide()
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|