CHANGE_REOREDER_LEVEL : AADHAVAN
This commit is contained in:
parent
b0d802ed22
commit
a7aeee5096
@ -85,16 +85,16 @@ class Purchase extends BaseController
|
||||
$data['vendor'] = $vendor;
|
||||
|
||||
$data['vendor_id'] = $purchase['vendor_id'];
|
||||
// print_r($vendor);die;
|
||||
// print_r($vendor);die;
|
||||
$vendorId=$purchase['vendor_id'];
|
||||
$encodedVendorId = json_encode([$vendorId]);
|
||||
$productModel = new ProductModel();
|
||||
|
||||
// Query the database to find the product based on make_id and model_id
|
||||
$product = $productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
|
||||
->findAll();
|
||||
$data['product']=$product;
|
||||
// print_r($product);die;
|
||||
// Query the database to find the product based on make_id and model_id
|
||||
$product = $productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
|
||||
->findAll();
|
||||
$data['product']=$product;
|
||||
// print_r($product);die;
|
||||
|
||||
|
||||
|
||||
@ -198,6 +198,7 @@ class Purchase extends BaseController
|
||||
$PurchaseOrderChildModel->update($purchase_order_child_id[$key], $child_data);
|
||||
|
||||
} else {
|
||||
|
||||
$PurchaseOrderChildModel->insert($child_data);
|
||||
|
||||
}
|
||||
|
||||
@ -4,9 +4,11 @@ namespace App\Controllers;
|
||||
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\VendorModel;
|
||||
use App\Models\PurchaseOrderModel;
|
||||
use App\Models\PurchaseOrderChildModel;
|
||||
|
||||
|
||||
class Reorderlevel extends BaseController
|
||||
class Reorderlevel extends BaseController
|
||||
{
|
||||
|
||||
public $session;
|
||||
@ -26,18 +28,28 @@ class Reorderlevel extends BaseController
|
||||
|
||||
// print_r($reorder);die;
|
||||
$data['reorder']=$reorder;
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($data);die;
|
||||
return view('reorder_level_list',$data);
|
||||
}
|
||||
public function rise_order($product_id)
|
||||
{
|
||||
$data['page_name']="Rise Order";
|
||||
$ProductModel = new ProductModel();
|
||||
$products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
|
||||
$data['products']=$products;
|
||||
$vendorid= $products['prefered_vendor'];
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor=$VendorModel->where('vendor_id',$vendorid)->findAll();
|
||||
print_r($vendor);die;
|
||||
// echo "<pre>";
|
||||
// print_r($products);die;
|
||||
$vendorid= $products['prefered_vendor'];
|
||||
$VendorModel = new VendorModel();
|
||||
$vendor=$VendorModel->where('vendor_id',$vendorid)->findAll();
|
||||
$data['vendor']=$vendor;
|
||||
|
||||
$PurchaseOrderModel = new PurchaseOrderModel();
|
||||
$purchase=$PurchaseOrderModel->where('vendor_id',$vendorid)->first();
|
||||
|
||||
$data['purchase']=$purchase;
|
||||
return view('reorder_level_form',$data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,716 +1,165 @@
|
||||
<?php include('layout/header.php'); ?>
|
||||
|
||||
<div class="row">
|
||||
<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() . "purchase_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
||||
<a href="<?= base_url() . "reorder_level_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">
|
||||
<h4 class="header-title"></h4>
|
||||
<form action="<?= base_url() . "add_purchase"; ?>" method="post">
|
||||
<input type="hidden" id="purchase_order_id" name="purchase_order_id" value="<?= isset($purchase['purchase_order_id']) ? $purchase['purchase_order_id'] : '' ?>"readonly>
|
||||
<h4 class="header-title">Purchase Details :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control vendor-select" name="vendor_id" id="vendor_id">
|
||||
<option value="0">Select Vendor</option>
|
||||
<?php foreach ($vendor as $item): ?>
|
||||
<option value="<?= $item['vendor_id'] ?>" <?= isset($item['vendor_id']) && $vendor_id == $item['vendor_id'] ? 'selected' : '' ?>>
|
||||
<?= $item['vendor_name'] ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_name" class="col-form-label">Contact Person Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_name" id="contact_person_name" placeholder="Contact Person Name.."value="<?= isset($purchase['contact_person_name']) ? $purchase['contact_person_name'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_mobile" class="col-form-label">Contact Person Mobile<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_mobile" id="contact_person_mobile" placeholder="Contact Person Mobile" value="<?= isset($purchase['contact_person_mobile']) ? $purchase['contact_person_mobile'] : '' ?>"maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="purchase_status" class="col-form-label">Purchase Status<span class="text-danger">*</span></label>
|
||||
<select name="purchase_status" id="purchase_status" class="form-control">
|
||||
<option value="Draft" <?= isset($purchase['status']) && $purchase['status'] == 'Draft' ? 'selected' : '' ?>>Draft</option>
|
||||
<option value="Cancel" <?= isset($purchase['status']) && $purchase['status'] == 'Cancel' ? 'selected' : '' ?>>Cancel</option>
|
||||
<option value="Released" <?= isset($purchase['status']) && $purchase['status'] == 'Released' ? 'selected' : '' ?>>Released</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Order Date</label>
|
||||
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= empty($purchase['order_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['order_date'])) ?>" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="header-title">Billing Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="billing_address" class="col-form-label">Billing Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_address" id="billing_address" placeholder="Billing Addresss"value="<?= isset($business['address']) ? $business['address'] : (isset($purchase['billing_address']) ? $purchase['billing_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="billing_state" class="col-form-label">Billing State</label>
|
||||
<input type="text" class="form-control" name="billing_state" id="billing_state" placeholder="Billing State"value="<?= isset($business['state']) ? $business['state'] : (isset($purchase['billing_state']) ? $purchase['billing_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing City" class="col-form-label">Billing City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_city" id="billing_city" placeholder="Billing City"value="<?= isset($business['city']) ? $business['city'] : (isset($purchase['billing_city']) ? $purchase['billing_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing Postal Code" class="col-form-label">Billing Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_postal_code" id="billing_postal_code" placeholder="Billing Pin Code"value="<?= isset($business['postal_code']) ? $business['postal_code'] : (isset($purchase['billing_postal_code']) ? $purchase['billing_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
|
||||
</div><br>
|
||||
<h4 class="header-title">Shipping Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="shipping_address" class="col-form-label">Shipping Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_address" id="shipping_address" placeholder="Shipping Addresss"value="<?= isset($branch['address']) ? $branch['address'] : (isset($purchase['shipping_address']) ? $purchase['shipping_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="shipping_state" class="col-form-label">Shipping State</label>
|
||||
<input type="text" class="form-control" name="shipping_state" id="shipping_state" placeholder="Shipping State"value="<?= isset($branch['state']) ? $branch['state'] : (isset($purchase['shipping_state']) ? $purchase['shipping_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping City" class="col-form-label">Shipping City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_city" id="shipping_city" placeholder="Shipping City"value="<?= isset($branch['city']) ? $branch['city'] : (isset($purchase['shipping_city']) ? $purchase['shipping_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping Postal Code" class="col-form-label">Shipping Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_postal_code" id="shipping_postal_code" placeholder="Shipping Pin Code"value="<?= isset($branch['postal_code']) ? $branch['postal_code'] : (isset($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
</div><br>
|
||||
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
<br />
|
||||
|
||||
<table class="table table-bordered" id="itemTable">
|
||||
<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($purchase_product) && !empty($purchase_product)) : ?>
|
||||
<?php foreach ($purchase_product as $purchasechild) :
|
||||
if ($purchasechild['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($purchasechild['product_id']) && $purchasechild['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($purchasechild['qty']) ? $purchasechild['qty'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($purchasechild['net_price']) ? $purchasechild['net_price'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($purchasechild['tax']) ? $purchasechild['tax'] : '' ?>">
|
||||
</td>
|
||||
<!-- <td style="width:12%;">
|
||||
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($purchasechild['discount']) ? $purchasechild['discount'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<select class="form-control item-discount-type" name="discount_type[]">
|
||||
<option value="₹" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
|
||||
<option value="%" <?= isset($purchasechild['discount_type']) && $purchasechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
|
||||
</select>
|
||||
</td> -->
|
||||
<td style="width:12%;">
|
||||
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($purchasechild['amount']) ? $purchasechild['amount'] : '' ?>">
|
||||
</td>
|
||||
<td hidden><input type="hidden" value="<?= isset($purchasechild['purchase_order_child_id']) ? $purchasechild['purchase_order_child_id'] : '' ?>"name="purchase_order_child_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="addItem">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"></h4>
|
||||
<form action="<?= base_url() . "add_purchase"; ?>" method="post">
|
||||
<input type="hidden" id="purchase_order_id" name="purchase_order_id" value=""readonly>
|
||||
<h4 class="header-title">Purchase Details :</h4><br>
|
||||
<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="invoice_tax" readonly value="<?= isset($sales['tax']) ? $sales['tax'] : '' ?>">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="make" class="col-form-label">Vendor<span class="text-danger">*</span></label>
|
||||
<select class="form-control vendor-select SelExample" name="vendor_id" id="vendor_id" >
|
||||
<option value="0">Select Vendor</option>
|
||||
<?php foreach ($vendor as $item): ?>
|
||||
<option value="<?= $item['vendor_id'] ?>" <?= isset($item['vendor_id']) && $item['vendor_id'] ? 'selected' : '' ?>>
|
||||
<?= $item['vendor_name'] ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_name" class="col-form-label">Contact Person Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_name" id="contact_person_name" placeholder="Contact Person Name.."value="<?= isset($purchase['contact_person_name']) ? $purchase['contact_person_name'] : '' ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="contact_person_mobile" class="col-form-label">Contact Person Mobile<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="contact_person_mobile" id="contact_person_mobile" placeholder="Contact Person Mobile" value="<?= isset($purchase['contact_person_mobile']) ? $purchase['contact_person_mobile'] : '' ?>"maxlength="10" minlength="10" onkeypress = "return onlyNumbers(event)" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="order_date" class="col-form-label">Order Date</label>
|
||||
<input type="date" class="form-control" name="order_date" id="order_date" value="<?= empty($purchase['order_date']) ? date('Y-m-d') : date('Y-m-d', strtotime($purchase['order_date'])) ?>" readonly>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="inputPassword4" class="col-form-label">Status<span class="text-danger">*</span>
|
||||
<?php if (isset($purchase['status']) && $purchase['status'] !== ''): ?>
|
||||
(<?= $purchase['status'] ?>)
|
||||
<?php endif; ?></label>
|
||||
<select class="form-control status-select" name="purchase_status" required data-toggle="select2">
|
||||
|
||||
<option value="PO Issued" selected>PO Issued</option>
|
||||
<!-- <option value="Paid">Paid</option> -->
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="header-title">Billing Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="billing_address" class="col-form-label">Billing Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_address" id="billing_address" placeholder="Billing Addresss"value="<?= isset($business['address']) ? $business['address'] : (isset($purchase['billing_address']) ? $purchase['billing_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="billing_state" class="col-form-label">Billing State</label>
|
||||
<input type="text" class="form-control" name="billing_state" id="billing_state" placeholder="Billing State"value="<?= isset($business['state']) ? $business['state'] : (isset($purchase['billing_state']) ? $purchase['billing_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing City" class="col-form-label">Billing City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_city" id="billing_city" placeholder="Billing City"value="<?= isset($business['city']) ? $business['city'] : (isset($purchase['billing_city']) ? $purchase['billing_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Billing Postal Code" class="col-form-label">Billing Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="billing_postal_code" id="billing_postal_code" placeholder="Billing Pin Code"value="<?= isset($business['postal_code']) ? $business['postal_code'] : (isset($purchase['billing_postal_code']) ? $purchase['billing_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
</div><br>
|
||||
<h4 class="header-title">Shipping Addresss :</h4><br>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="shipping_address" class="col-form-label">Shipping Addresss<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_address" id="shipping_address" placeholder="Shipping Addresss"value="<?= isset($branch['address']) ? $branch['address'] : (isset($purchase['shipping_address']) ? $purchase['shipping_address'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" >
|
||||
<label for="shipping_state" class="col-form-label">Shipping State</label>
|
||||
<input type="text" class="form-control" name="shipping_state" id="shipping_state" placeholder="Shipping State"value="<?= isset($branch['state']) ? $branch['state'] : (isset($purchase['shipping_state']) ? $purchase['shipping_state'] : '') ?>" >
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping City" class="col-form-label">Shipping City<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_city" id="shipping_city" placeholder="Shipping City"value="<?= isset($branch['city']) ? $branch['city'] : (isset($purchase['shipping_city']) ? $purchase['shipping_city'] : '') ?>" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="Shipping Postal Code" class="col-form-label">Shipping Pin Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="shipping_postal_code" id="shipping_postal_code" placeholder="Shipping Pin Code"value="<?= isset($branch['postal_code']) ? $branch['postal_code'] : (isset($purchase['shipping_postal_code']) ? $purchase['shipping_postal_code'] : '') ?>" required>
|
||||
</div>
|
||||
</div><br>
|
||||
<div class="form-row" id="itemTableContainer">
|
||||
<div class="form-group col-md-12">
|
||||
<h4>Item Details</h4>
|
||||
<br />
|
||||
<table class="table table-bordered" id="itemTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item Details</th>
|
||||
<th>Qty</th>
|
||||
|
||||
<!-- <div class="form-group">
|
||||
<label for="discount">Discount Amount</label>
|
||||
<input type="number" class="form-control" id="discount" name="discount" onchange="calculateGrandTotal(this.value)" min="0" readonly value="<?= isset($sales['discount']) ? $sales['discount'] : '' ?>" >
|
||||
</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>
|
||||
|
||||
|
||||
<th hidden></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (isset($products) && !empty($products)) : ?>
|
||||
<tr>
|
||||
<td style="width:10%;">
|
||||
<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>
|
||||
<option value="<?= $products["product_id"] ?>" <?= isset($products['product_id']) ? 'selected' : '' ?>>
|
||||
<?= $products["product_name"]; ?>
|
||||
</option>
|
||||
</select>
|
||||
</td>
|
||||
<td style="width:5%;">
|
||||
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($products['reorder_level']) ? $products['reorder_level'] : '' ?>">
|
||||
</td>
|
||||
<td style="width:5%;">
|
||||
<center><i class="fa fa-trash remove-item"></i></center>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<!-- You can add more rows as needed using JavaScript -->
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (empty($purchase["status"])): ?>
|
||||
<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="addItem">
|
||||
<h4><i class="fa fa-plus" aria-hidden="true"></i> Add Product</h4>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</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>
|
||||
</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>
|
||||
<?php if (!isset($purchase['status']) || $purchase['status'] !== 'Received') : ?>
|
||||
<button type="submit" id="editaddbutton"class="btn btn-primary">Submit</button>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php include('layout/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
productarray = [];
|
||||
$(document).ready(function() {
|
||||
// Event listener for vehicle selection change
|
||||
$('.vendor-select').change(function() {
|
||||
var vendorId = $(this).val();
|
||||
|
||||
if (vendorId !== '') {
|
||||
// Find the selected vehicle
|
||||
var selectedVehicle = vendors.find(function(vendor) {
|
||||
return vendor.vendor_id == vendorId;
|
||||
});
|
||||
|
||||
// Extract makeId from the selected vehicle
|
||||
|
||||
|
||||
// Make sure makeId exists
|
||||
if (vendorId !== undefined) {
|
||||
// Perform AJAX request to fetch product information
|
||||
$.ajax({
|
||||
url: '<?php echo base_url().'getVendorProducts'?>', // Replace with the actual backend endpoint
|
||||
method: 'POST', // or 'GET' based on your server implementation
|
||||
dataType: 'json',
|
||||
data: {
|
||||
|
||||
vendor_id: vendorId
|
||||
},
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
productarray = response.product;
|
||||
|
||||
},
|
||||
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);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
$(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; ?>;
|
||||
|
||||
// Function to calculate amount based on rate and quantity
|
||||
function calculateAmount(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();
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
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));
|
||||
}
|
||||
|
||||
// Event listener for product selection
|
||||
$(document).on('change', 'select[name="item_details[]"]', function() {
|
||||
var productId = $(this).val();
|
||||
var quantity = $(this).closest('tr').find('.item-quantity').val(0);
|
||||
|
||||
// Find product details from JSON
|
||||
var product = products.find(function(item) {
|
||||
return item.product_id == productId;
|
||||
});
|
||||
|
||||
// Access unit price from product and set it as rate
|
||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
||||
|
||||
// Calculate amount and update amount input field
|
||||
calculateAmount($(this).closest('tr'));
|
||||
});
|
||||
|
||||
// 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
|
||||
$('#addItem').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></td>' +
|
||||
'</tr>';
|
||||
|
||||
|
||||
$('#itemTable 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 purchase_order_child_id = $(this).closest('tr').find('input[name="purchase_order_child_id[]"]').val();
|
||||
|
||||
// AJAX request to delete the sales order product
|
||||
$.ajax({
|
||||
url: '<?php echo base_url()."delete_purchase_product"?>',
|
||||
method: 'POST',
|
||||
data: { purchase_order_child_id: purchase_order_child_id },
|
||||
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 vendors = <?php echo json_encode($vendor); ?>;
|
||||
|
||||
</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 .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>
|
||||
@ -49,7 +49,7 @@
|
||||
<td><?= $value['purchase_order_level']; ?></td>
|
||||
<td><?= $value['reorder_level']; ?></td>
|
||||
<td>
|
||||
<a href="<?= "rise_order/" . $value['product_id']; ?>" class="edit-button"><i class="ri-arrow-up-circle-fill"></i>Rise</a>
|
||||
<a href="<?= "rise_order/" . $value['product_id']; ?>" class="edit-button"><i class="ri-arrow-up-circle-fill"></i>Rise</a>
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user