the_mechanic/app/Views/reorder_level_form.php
2025-01-04 03:07:18 +00:00

221 lines
15 KiB
PHP
Executable File

<?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() . "reorder_level_index"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
<ol class="breadcrumb m-0">
</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=""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 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>
<th hidden></th>
<th></th>
</tr>
</thead>
<tbody>
<?php if (isset($products) && !empty($products)) :
foreach ($products as $product) { ?>
<?php if ($product['per'] == 'ml') {
$value_ml = ' ('.$product['ml'].$product['per'].')';
} else {
$value_ml = '';
}
?>
<tr>
<td style="width:30%;">
<select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" id="" style="width: 280px !important;">
<option value="">Select a Product</option>
<option value="<?= $product["product_id"] ?>" <?= isset($product['product_id']) ? 'selected' : '' ?>>
<?= $product["product_name"].$value_ml.' - '. $product['manufacturer_name']; ?>
</option>
</select>
</td>
<td style="width:5%;">
<input type="number" class="form-control item-quantity" name="quantity[]" min="1" value="<?= isset($product['reorder_level']) ? $product['reorder_level'] : '' ?>">
</td>
<td style="width:5%;">
<center><i class="fa fa-trash"></i></center>
</td>
</tr>
<?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>
<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>
<button type="submit" id="editaddbutton"class="btn btn-primary" style="float:right;">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" id="pr_data" value="<?= htmlspecialchars(json_encode($product_data)); ?>">
<?php include('layout/footer.php'); ?>
<script>
// Event listener for "Add More Item" button
$('#addItem').click(function() {
const productarray = JSON.parse($('#pr_data').val())
console.log($('#pr_data').val());
var newRow = '<tr>' +
'<td><select class="form-control book-select SelExample" name="item_details[]" required data-toggle="select2" style="width: 280px !important;"><option value="">Select a Product</option>';
for (var i = 0; i < productarray.length; i++) {
var product = productarray[i];
var value_ml ='';
if (product.per == 'ml') {
value_ml = "("+product.ml+product.per+")";
}
newRow += '<option value="' + product.product_id + '" >' + product.product_name + value_ml +" - " + product.manufacturer_name +
'</option>';
}
newRow += '</select></td>' +
'<td style="width:10%;"><input type="number" class="form-control item-quantity" min="1" max="" value="1" name="quantity[]"/></td>' +
'<td><center><i class="fa fa-trash remove-item"></i></center></td>' +
'</tr>';
$('#itemTable tbody').append(newRow);
});
$(document).on('click', '.remove-item', function() {
$(this).closest('tr').remove();
});
var productAll_json = <?php json_encode($products); ?>
var productAll = JSON.parse(productAll_json);
// 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(1);
console.log(productAll);
var product = productAll.find(function(item) {
return item.product_id == productId;
});
console.log(product);
});
</script>