CHANGE_RETURNORDER : AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-17 18:18:56 +05:30
parent aeff0b8367
commit c39e293484
6 changed files with 1072 additions and 63 deletions

View File

@ -44,10 +44,16 @@ class ReturnOrder extends BaseController
{
$ReturnModel = new ReturnModel();
$purchase = $ReturnModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
// echo "<pre>";
// print_r($product);die;
$data['purchase']=$purchase;
$return_orders = $ReturnModel->select('return_order.*, vendor.vendor_name as vendor_name, COUNT(return_order_child.return_order_id) AS return_count')
->join('vendor', 'vendor.vendor_id = return_order.vendor_id')
->join('return_order_child', 'return_order_child.return_order_id = return_order.return_order_id', 'left')
->where('return_order.branch_id', $this->session->get('logged_user_branch_id'))
->groupBy('return_order.return_order_id')
->orderBy('return_order.return_order_id','desc')
->findAll();
$data['return_order']=$return_orders;
// echo "<pre>";
// print_r($data);die;
@ -131,27 +137,22 @@ class ReturnOrder extends BaseController
if ($return) {
$quantity =$this->request->getPost('quantity');
$item_details =$this->request->getPost('item_details');
foreach ($item_details as $index => $item_detail) {
foreach ($return_order_child as $child) {
$quantity =$this->request->getPost('quantity');
if ($item_detail == $child['product_id']) {
// $changed_quantity =['qty'=> $child['qty'] - $quantity[$index]];
// $purchase_order_child_id = $child['purchase_order_child_id'];
$PurchaseOrderChildModel->update($purchase_order_child_id, $changed_quantity);
}
}
$product = $ProductModel->where('product_id',$item_detail)->first();
$changed_quantity = $product['qty_stock'] - $quantity[$index];
$product_id = $item_detail;
$changed_quantity_DB=['qty_stock'=>$changed_quantity];
$ProductModel->update($product_id, $changed_quantity_DB);
}
$ReturnModel->update($return_order_id, $return_data_update);
}
return redirect()->to('return_order');
} else {
$return_order_id = $this->request->getPost('return_order_id');
if (!empty($return_order_id)) {
@ -174,54 +175,52 @@ class ReturnOrder extends BaseController
$unitprice=$this->request->getPost('unit-price');
$selected_items=$this->request->getPost('return_selected_items');
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
// print_r($selected_items);die;
$status = $this->request->getPost('purchase_status');
foreach ($selected_items as $key => $product_id) {
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
$selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0;
// print_r($selected_item);die;
if ($status == 'Released' && $selected_item == 1) {
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
}
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
// print_r($discount_type);die;
$child_data = [
'return_order_id' => $return_order_id,
'product_id' => $product_id,
'qty' => $qty,
'net_price'=>$rate,
'tax'=>$tax,
'amount' => $amount,
'is_selected'=>$selected_item,
'isactive'=>1,
];
// if (!empty($purchase_order_child_id[$key])) {
// print_r("22222222222222222222222222");die;
$ReturnOrderChildModel = new ReturnOrderChildModel();
// print_r($purchase_order_child_id[$key]);die;
// $ReturnOrderChildModel->update($purchase_order_child_id[$key], $child_data);
// } else {
// print_r("11111111111111111111");die;
$qty = isset($quantities[$product_id]) ? $quantities[$product_id] : 0;
$selected_item= isset($selected_items[$key]) ? $selected_items[$key] : 0;
// print_r($selected_item);die;
if ($status == 'Released' && $selected_item == 1) {
$this->addBackProductQuantity($ProductModel, $product_id, $qty);
}
$ReturnOrderChildModel->insert($child_data);
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
// $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
// print_r($discount_type);die;
$child_data = [
'return_order_id' => $return_order_id,
'product_id' => $product_ids[$key],
'qty' => $qty,
'net_price'=>$rate,
'tax'=>$tax,
'amount' => $amount,
'is_selected'=>$selected_item,
'isactive'=>1,
];
// echo "<pre>";
// print_r($child_data);die;
$ReturnOrderChildModel = new ReturnOrderChildModel();
$ReturnOrderChildModel->insert($child_data);
// }
}
}
return redirect()->to('purchase_index');
return redirect()->to('return_order');
}

View File

@ -5,7 +5,7 @@
<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() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<a href="<?= base_url() . "return_order"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</ol>
</div>
@ -168,7 +168,7 @@
</textarea>
</div>
</div>
<?php if (!isset($purchase['status']) || $purchase['status'] !== 'Released') : ?>
<?php if ($return_order['status'] !== 'Returned') : ?>
<button type="submit" id="editaddbutton"class="btn btn-primary">Submit</button>
<?php endif; ?>
</form>

874
app/Views/job_card_form.php Normal file
View File

@ -0,0 +1,874 @@
<?php include('layout/header.php'); ?>
<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() . "sales_order_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</li>
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
<li class="breadcrumb-item active">Datatables</li> -->
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<form action="<?= base_url() . "add_jobs"; ?>" method="post">
<!-- <h4 class="header-title">Sales Order Details :</h4><br> -->
<div class="form-row">
<div class="form-group col-md-6">
<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" name="vehicle_id" <?= isset($sales['vehicle_id']) ? 'readonly' : 'required' ?>>
<?= 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-6">
<label for="inputPassword4" class="col-form-label">Make and Model</label>
<input type="text" class="form-control" id="makeAndModel" value="<?php echo isset($make_model) ? $make_model : ''; ?>" readonly>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Client Name<span class="text-danger"></span></label>
<input type="text" class="form-control" name="client_id" placeholder="Client"value="<?= isset($jobs['client_name']) ? $jobs['client_name'] : '' ?>" readonly>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Mobile No<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="mobile_no" placeholder="Mobile" value="<?= isset($jobs['client_mobile_no']) ? $jobs['client_mobile_no'] : '' ?>" maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" readonly>
</div>
<div class="form-group col-md-4">
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>(<?php echo isset($jobs['status']) ? $jobs['status'] : '' ?>)</label>
<select class="form-control status-select" name="status" required data-toggle="select2">
<?php if (isset($jobs['status'])): ?>
<?php if ($jobs['status'] === 'Cancelled'): ?>
<option value="Created" <?= $jobs['status'] === 'Created' ? 'selected' : '' ?>>Created</option>
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
<?php else: ?>
<option value="Paid" <?= $jobs['status'] === 'Paid' ? 'selected' : '' ?>>Paid</option>
<option value="Cancelled" <?= $jobs['status'] === 'Cancelled' ? 'selected' : '' ?>>Cancelled</option>
<?php endif; ?>
<?php else: ?>
<option value="Created" selected>Created</option>
<option value="Paid">Paid</option>
<?php endif; ?>
</select>
</div>
</div><br>
<h4 class="header-title">Billing Address Details :</h4><br>
<div class="form-row">
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">Address<span class="text-danger"></span></label>
<input type="text" class="form-control" name="billing_address" placeholder="Address"value="<?= isset($jobs['billing_address']) ? $jobs['billing_address'] : '' ?>" >
</div>
<input type="hidden" id="job_card_id" name="job_card_id" value="<?= isset($jobs['job_card_id']) ? $jobs['job_card_id'] : '' ?>"readonly>
<div class="form-group col-md-3">
<label for="inputPassword4" class="col-form-label">City<span class="text-danger"></span></label>
<input type="text" class="form-control" name="city" placeholder="City"value="<?= isset($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" 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" name="postalcode" placeholder="Pin Code"value="<?= isset($jobs['billing_postal_code']) ? $jobs['billing_postal_code'] : '' ?>" maxlength="6" minlength="6" >
</div>
</div>
<div class="form-row" id="itemTableContainer">
<div class="form-group col-md-12">
<h4>Item Details</h4>
<br />
<table class="table table-bordered" id="productItemTable">
<thead>
<tr>
<th>Item Details</th>
<th>Qty</th>
<th>Rate</th>
<th>Tax</th>
<!-- <th style="text-align: center !important" colspan="2">Discount</th> -->
<th>Amount</th>
<th hidden></th>
<th></th>
</tr>
</thead>
<tbody>
<!-- Dynamically add rows for item details -->
<?php if (isset($product) && !empty($product)) : ?>
<?php foreach ($product as $salechild) :
if ($salechild['isactive'] == 1) : ?>
<tr>
<td>
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
<option value="">Select a Product</option>
<?php foreach ($product as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["product_id"] ?>" <?= isset($salechild['product_id']) && $salechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
<?= $value["product_name"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</td>
<td style="width:10%;">
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($salechild['qty']) ? $salechild['qty'] : '' ?>">
</td>
<td style="width:10%;">
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($salechild['net_price']) ? $salechild['net_price'] : '' ?>">
</td>
<td style="width:10%;">
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>">
</td>
<!-- <td style="width:12%;">
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($salechild['discount']) ? $salechild['discount'] : '' ?>">
</td>
<td style="width:10%;">
<select class="form-control item-discount-type" name="discount_type[]">
<option value="" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
<option value="%" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
</select>
</td> -->
<td style="width:12%;">
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>">
</td>
<td hidden><input type="hidden" value="<?= isset($salechild['job_card_product_id']) ? $salechild['job_card_product_id'] : '' ?>"name="job_card_product_id[]"></td>
<td style="width:12%;">
<center><i class="fa fa-trash remove-item"></i></center>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<!-- You can add more rows as needed using JavaScript -->
</tbody>
</table>
<div class="form-group text-right m-b-0">
<!-- Show the "Add More Item" button only if invoice_type is not 1 -->
<a class="btn" id="addProduct">
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
</a>
<a class="btn" id="addService">
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Service</h4>
</a>
</div>
</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">Total</label>
<input type="text" class="form-control" id="grandtotal" name="grand_total" readonly value="<?= isset($sales['total']) ? $sales['total'] : '' ?>">
</div>
</div>
</div>
</div>
<h4 class="header-title">Terms & Condition :</h4><br>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputPassword4" class="col-form-label">Terms & Condition</label>
<textarea class="form-control" name="terms_condition" placeholder="Terms & Condition" >
<?= isset($sales['terms_condition']) ? $sales['terms_condition'] : 'Please check the products properly before purchase. Products once sold cannot be returned.' ?>
</textarea>
</div>
</div>
<?php if (!isset($sales['status']) || $sales['status'] !== 'Paid') : ?>
<button type="submit" 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">&times;</span>
</button>
</div>
<div class="modal-body">
<form >
<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" id="clientMobile" placeholder="Enter mobile number" maxlength="10" minlength="10"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="10" minlength="10"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>
productarray = [];
servicearray = [];
$(document).ready(function() {
// Event listener for vehicle selection change
$('.vehicle-select').change(function() {
var vehicleId = $(this).val();
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 = json_encode($product_1);
$service_json = json_encode($service_1);
?>
$(document).ready(function() {
function validateProductAdded() {
var rowCount = $('#itemTable tbody tr').length;
// if (rowCount < 1) {
// toastr.warning("Please add at least one product.");
// alert("Please add at least one product.");
// return false;
// }
return true;
}
// Event listener for form submission
$('form').submit(function() {
return validateProductAdded();
});
var products = <?php echo $product_json; ?>;
var services = <?php echo $service_json; ?>;
// Function to calculate amount based on rate and quantity
function calculateAmount(row) {
// console.log(row);
var rate = $(row).find('.item-rate').val();
var quantity = $(row).find('.item-quantity').val();
var amount = rate * quantity;
$(row).find('.item-amount').val(amount);
// Retrieve CGST and SGST values from the database for the selected product
var productId = $(row).find('select[name="item_details[]"]').val();
if (productId) {
var product = products.find(function(item) {
return item.product_id == productId;
});
console.log("22222222222");
console.log(product);
var cgst = parseFloat(product.cgst);
var sgst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
$(row).find('.item-tax').val(tax.toFixed(2));
} else {
var productId = $(row).find('select[name="item_details_service[]"]').val();
var product = services.find(function(item) {
return item.service_id == productId;
});
console.log("3333333");
console.log(product);
var cgst = parseFloat(product.cgst);
var igst = parseFloat(product.igst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + igst;
$(row).find('.item-tax-service').val(tax.toFixed(2));
}
}
// Event listener for product selection
$(document).on('change', 'select[name="item_details[]"]', function() {
console.log("111111111111");
var productId = $(this).val();
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
// Find product details from JSON
console.log(products);
var product = products.find(function(item) {
return item.product_id == productId;
});
// Access unit price from product and set it as rate
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
$(this).closest('tr').find('.item-rate').val(unitPrice);
// Calculate amount and update amount input field
calculateAmount($(this).closest('tr'));
});
// Event listener for quantity change
$(document).on('input', '.item-quantity', function() {
calculateAmount($(this).closest('tr'));
updateCalculations(); // Added for updating calculations when quantity changes
});
// Function to calculate subtotal
function calculateSubtotal() {
var subtotal = 0;
$('.item-amount').each(function() {
subtotal += parseFloat($(this).val()) || 0;
});
return subtotal;
}
// Function to calculate total tax
function calculateTax() {
var tax = 0;
$('.item-tax').each(function() {
var taxPercentage = parseFloat($(this).val()) || 0;
var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
tax += taxValue;
});
return tax;
}
// Function to calculate total discount
function calculateDiscount() {
var totalDiscount = 0;
$('.item-discount-amount').each(function(index, element) {
var discountAmount = parseFloat($(element).val()) || 0;
var discountType = $(element).closest('tr').find('.item-discount-type').val();
if (discountType === '%') {
var rate = $(element).closest('tr').find('.item-rate').val();
var quantity = $(element).closest('tr').find('.item-quantity').val();
var amount = rate * quantity;
discountAmount = amount * discountAmount / 100;
}
totalDiscount += discountAmount;
});
return totalDiscount;
}
// Function to calculate total
function calculateTotal() {
var subtotal = calculateSubtotal();
var tax = calculateTax();
var discount = calculateDiscount();
var total = subtotal + tax - discount;
// return total;
return Math.round(total);
}
// Update subtotal, tax, and total
function updateCalculations() {
$('#subtotal').val(calculateSubtotal().toFixed(2));
$('#invoicetax').val(calculateTax().toFixed(2));
$('#discount').val(calculateDiscount().toFixed(2));
$('#grandtotal').val(calculateTotal().toFixed(2));
}
// 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
$('#addProduct').click(function() {
// console.log(productarray);
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
for (var i = 0; i < productarray.length; i++)
{
var product = productarray[i];
newRow += '<option value="' + product.product_id + '">' + product.product_name + '</option>';
}
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
initializeSelect2();
});
$('#addService').click(function() {
// console.log(servicearray);
var newRow = '<tr>' + '<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Product</option>';
for (var i = 0; i < servicearray.length; i++)
{
var service = servicearray[i];
newRow += '<option value="' + service.service_id + '">' + service.service_name + '</option>';
}
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="0" name="quantity[]"/></td>' +
'<td style="width:10%;"><input type="text" class="form-control item-rate" name="unit-price[]" readonly /></td>' +
'<td style="width:8%;"><input type="text" class="form-control item-tax" name="item-tax[]" readonly /></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]"/></td>' +
'<td hidden><input type="hidden"></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="service" name="item_type" hidden></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
initializeSelect2();
});
// Event listener for removing item
$(document).on('click', '.remove-item', function() {
$(this).closest('tr').remove();
updateCalculations(); // Added for updating calculations when an item is removed
});
});
</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() {
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;
});
$('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;
});
// Populate the billing address, city, state, country, and postal code fields
$('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' // Adjust width as needed
});
}
</script>
<script>
$(document).ready(function() {
// AJAX request to save client
$('#saveVehcileBtn').click(function() {
var formType = $('#formType').val();
console.log(formType);
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 !== ''";
}
console.log(ifStatementCondition);
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!");
window.location.reload();
} else {
toastr.warning("Failed to save vehicle. Please try again");
}
},
error: function(xhr, status, error) {
console.error('Error occurred while saving vehicle:', error);
toastr.warning("Failed to save vehicle. Please try again");
}
});
}else{
toastr.warning("Please Fill All Data");
}
});
});
</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('');
});
</script>
<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>

136
app/Views/jobs_list.php Normal file
View File

@ -0,0 +1,136 @@
<?php include('layout/header.php'); ?>
<style>
.dataTables_wrapper button{
background: #f1f5f7;
color: #343a40;
border-width: 0;
}
.dataTables_wrapper .dt-buttons{
float:left;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Job Card List</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class=""> <a href="<?= base_url() . "new_jobcard/0"; ?>" class="btn btn-primary waves-effect"> <i class="ri-add-line"></i></a>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<!-- <h4 class="header-title">Business List</h4> -->
<table id="datatable-buttons2" class="table table-striped dt-responsive nowrap w-100"
style="width:100% !important;">
<thead>
<tr>
<th>Order Number</th>
<th>Reg No</th>
<th>Client Name</th>
<th>Client Mobile</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Tax</th>
<th>Total</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($jobs as $value) : if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['order_number']; ?></td>
<td><?= $value['reg_no']; ?></td>
<td><?= $value['client_name']; ?></td>
<td><?= $value['client_mobile_no']; ?></td>
<td><?= $value['product_count']; ?></td>
<td><?= $value['subtotal']; ?></td>
<td><?= $value['tax']; ?></td>
<td><?= $value['total']; ?></td>
<td><?= $value['status']; ?></td>
<td>
<a href="<?= "new_jobcard/" . $value['job_card_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
<a href="<?= "download_invoice/" . $value['job_card_id']; ?>" class="edit-button"><i class="ri-file-download-line"></i></a>
<a href="<?= "delete_jobcard/" . $value['job_card_id']; ?>" class="delete-button"><i class="ri-delete-bin-line"></i></a>
</td>
<?php endif?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div> <!-- end table-responsive-->
</div>
</div> <!-- end card -->
</div> <!-- end col -->
</div>
<?php include('layout/footer.php'); ?>
<script>
$(document).ready(function() {
$('#datatable-buttons2').DataTable({
"order": [[2, 'desc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [ {
extend: 'pdfHtml5',
title: 'Transaction', // Set your custom PDF title here
text: 'PDF',
customize: function(doc) {
// You can further customize the PDF here if needed
// doc.content[1].table.body.forEach(function(row) {
// row.splice(0, 1); // Remove the first column (ID column)
// });
}
},
{
extend: 'print',
title: 'Transaction', // Set your custom print title here
text: 'Print',
customize: function(win) {
// You can further customize the print output here if needed
// $(win.document.body).find('table').find('th:first-child, td:first-child').remove();
}
},
{
extend: 'copy',
text: 'Copy', // Set the title for the Copy button
titleAttr: 'Copy', // Set the tooltip for the Copy button
exportOptions: {
// columns: ':not(:first-child)' // Exclude the first column (ID column)
}
},
{
extend: 'csv',
text: 'CSV', // Set the title for the CSV button
title: 'Transaction', // Set your custom print title here
exportOptions: {
// columns: ':not(:first-child)' // Exclude the first column (ID column)
}
}], // Enable export options
"language": {
"search": "Search: " // Customize search label
},
"ordering": false
});
});
</script>

View File

@ -62,15 +62,15 @@
</thead>
<tbody>
<?php foreach ($purchase as $value) : ?>
<?php foreach ($return_order as $value) : ?>
<tr>
<td><?= $value['order_number']; ?></td>
<td></td>
<td><?= $value['vendor_name']; ?></td>
<td><?= $value['order_date']; ?></td>
<td><?= $value['contact_person_name']; ?><br>
<?= $value['contact_person_mobile']; ?>
</td>
<td></td>
<td><?= $value['return_count']; ?></td>
<td><?= $value['status']; ?></td>
<td>
<a href="<?= "edit_return_order/" . $value['return_order_id']; ?>" class="edit-button" title="Return"><i class="ri-pencil-line" style="font-size: 20px;"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

View File

@ -5,7 +5,7 @@
<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() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<a href="<?= base_url() . "return_order_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</li>
@ -132,7 +132,7 @@
<!-- Dynamically add rows for item details -->
<?php if (isset($purchase_product) && !empty($purchase_product)) : ?>
<?php foreach ($purchase_product as $purchasechild) :
<?php foreach ($purchase_product as $key=> $purchasechild) :
if ($purchasechild['isactive'] == 1) : ?>
<tr>
<td style="width:10%;">
@ -152,7 +152,7 @@
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
</td>
<td style="width:7%;">
<input type="checkbox" class="form-control-check-input" name="return_selected_items[]" value="<?= $purchasechild['product_id'] ?>">
<input type="checkbox" class="form-control-check-input" name="return_selected_items[]" value="<?= $key; ?>">
</td>