BBnepal-Accounts/account/application/views/inventory/purchases/create.php

498 lines
26 KiB
PHP
Raw Normal View History

2024-07-10 12:43:19 +00:00
<style>
table tr td {
border: 1px solid #ddd;
}
thead tr th {
border: 1px solid #ddd;
}
.form-control {
display: block;
width: 100%;
height: calc(1.80rem + 2px);
padding: .375rem .75rem;
font-size: .9rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
box-shadow: inset 0 0 0 transparent;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
text-align: left;
}
.form-control1 {
display: inline-block;
width: 25%;
height: calc(1.80rem + 2px);
/* padding: .375rem .75rem; */
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
box-shadow: inset 0 0 0 transparent;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.form-control2 {
display: block;
width: 100%;
/* height: calc(1.80rem + 2px); */
padding: .375rem .75rem;
font-size: .9rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
box-shadow: inset 0 0 0 transparent;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.select2-container .select2-selection--single {
height: calc(1.80rem + 2px);
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
color: #444;
line-height: 18px
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
margin-top: 0px !important;
}
.bbsn {
left: 50%;
top: 50%;
}
.br0 {
border: 0px;
}
</style>
2024-07-26 07:05:15 +00:00
2024-07-10 12:43:19 +00:00
<div class="content-wrapper">
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="card card-primary card-outline">
<!-- <div class="card-header">
<h5 class="m-0">Create <?php //echo $pageTitle;
?> <a href="<?php // echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/list");
?>" class="btn btn-sm btn-primary float-right">List <?php //echo $pageTitle;
?></a></h5>
</div> -->
<div class="card-body">
<form method="POST" action="<?php echo site_url("inventory/purchases/create"); ?>" enctype="multipart/form-data" name="tbl_purchases">
<div class="row mb-2">
<div class="col-2">
<fieldset>
2024-07-26 07:05:15 +00:00
<legend>Transaction Date</legend><input type="text" class="form-control2" id="purchase_date" value="<?php echo NepaliDate(); ?>" data-start="<?php echo $fiscalStart;?>" data-end="<?php echo $fiscalEnd;?>" name="purchase_date">
2024-07-10 12:43:19 +00:00
</fieldset>
</div>
<div class="col-8">
<h1 class="text-center"><?php echo $pageTitle; ?> Voucher</h1>
<!-- <fieldset>
<legend><span id="selectedAccountName"></span> Balance</legend><span id="selectedAccountBalance" style="padding: 6px 0px; display: inline-block; text-align: right; width: 100%;">Choose A/C First</span>
</fieldset> -->
</div>
2024-08-06 07:03:20 +00:00
2024-07-10 12:43:19 +00:00
<div class="col-2">
<fieldset>
<legend> Voucher No. #</legend><input type="text" readonly class="form-control2" id="voucher_no" value="<?php echo generateVoucherNo(); ?>" name="voucher_no">
</fieldset>
</div>
</div>
<fieldset>
<legend> Enter Transaction</legend>
<div class="row ">
<!--COL START-->
<div class="col-1">
<div class="form-group">
<label for="purchase_ref"><?php myLang('Ref. No.'); ?></label>
<input type="text" class="form-control DatePicker" id="purchase_ref" value="" name="purchase_ref">
</div>
</div>
<div class="col-5">
<?php $this->myaccounts->showAccountsCombo("accounts_id", "Account", "accounts_id", "accategory_id=30"); ?>
</div>
<div class="col-3">
</div>
<div class="col-2 mt-1">
<button type="button" class="btn btn-primary mt-4 addPurchaseDetail" id="addPurchaseDetail">Add Purchase</button>
</div>
<!--COL END-->
</div>
</fieldset>
2024-08-06 07:03:20 +00:00
2024-08-08 06:31:46 +00:00
<!-- <div class="mt-3">
2024-08-06 07:03:20 +00:00
<label for="vatToggle">VAT</label>
<input type="checkbox" id="vatToggle" checked>
</div>
2024-08-08 06:31:46 +00:00
<input type="hidden" id="vatToggleValue" name="vatToggleValue" value="1"> -->
2024-07-10 12:43:19 +00:00
<!-- Purchase Details Section -->
<div class="col-12 table-responsive p-0 mt-3">
<table class="table table-striped">
<thead>
<tr>
<th>S.No.</th>
<th>Items</th>
<th class="text-right">Qty</th>
<th class="text-right">Units</th>
<th class="text-right">Rate</th>
2024-10-08 10:02:07 +00:00
<th class="text-right" width=13%>VAT<span class="text-danger">*</span></th>
2024-07-10 12:43:19 +00:00
<th class="text-right">Amount</th>
<th></th>
</tr>
</thead>
<tbody class="purchase-details-section">
<tr class="purchase-detail">
<td class="text-center bbsn">1</td>
2024-07-16 06:58:55 +00:00
<td width=40%> <?php fillComboWithValue("item_id[]", "", "", "tbl_items", "title", "item_id", "", "select_item"); ?></td>
2024-07-10 12:43:19 +00:00
<td width=10%> <input type="text" class="form-control input-group-sm" name="quantity[]"></td>
2024-07-16 06:58:55 +00:00
<td width=5%><input type="text" class="form-control item_unit" name="pcs/dozen/kgs" required> </td>
2024-07-10 12:43:19 +00:00
<td width=15%><input type="text" class="form-control" name="rate[]"></td>
2024-10-08 10:02:07 +00:00
<td><input type="number" name="vat[]" class="form-control vat" required></td>
2024-07-10 12:43:19 +00:00
<td width=15%><input type="text" class="form-control" name="total[]"></td>
<td width="5%">
<button type="button" class="btn btn-primary btn-xs addPurchaseDetail" id="addPurchaseDetail">
<i class="fa fa-plus"></i></button>
<button type="button" class="btn btn-danger btn-xs remove-purchase-detail">
<i class="fa fa-minus"></i>
</button>
<!-- <button type="button" class="btn btn-danger btn-sm remove-purchase-detail"></button></td> -->
</tr>
</tbody>
<tfoot>
<tr>
2024-08-08 06:31:46 +00:00
<td colspan="3" rowspan="5">In words: </td>
<td class="text-right" colspan="1" rowspan="5">
<br>
<br>
<br>
<br>
2024-10-08 10:02:07 +00:00
<label for="vatToggle" class="d-none">VAT</label>
<input class="d-none" type="checkbox" id="vatToggle" checked>
<input type="hidden" class="d-none" id="vatToggleValue" name="vatToggleValue" value="1">
2024-08-08 06:31:46 +00:00
</td>
2024-07-10 12:43:19 +00:00
<td class="text-right "><b>Total Amount</b></td>
<td class="text-right">
<b><input type="text" class="form-control" name="subtotal" id="subtotal" /></b>
</td>
<td></td>
</tr>
<tr>
<td class="text-right">
<input class="form-control1" type="text" name="discountpercentage" id="discountpercentage" value="0" width="2%">
<b>% Discount</b></td>
<td class="text-right"><b><input type="text" class="form-control" name="discount" id="discount" /></b></td>
<td></td>
</tr>
<tr>
<td class="text-right "><b>Taxable Amount</b></td>
<td class="text-right"><b><input type="text" class="form-control" name="taxable" id="taxable" /></b></td>
<td></td>
</tr>
<tr>
2024-08-06 07:03:20 +00:00
2024-10-08 10:02:07 +00:00
<td class="text-right d-none "><b>13% VAT</b></td>
<td class="text-right d-none">
2024-07-10 12:43:19 +00:00
<input type="text" class="form-control" name="tax" id="tax" />
</td>
2024-10-08 10:02:07 +00:00
<td>
<input type="hidden" name="vat_checkbox_value" id="vat_checkbox_value" value="0">
</td>
2024-07-10 12:43:19 +00:00
</tr>
<tr>
<td class="text-right "><b>Grand Total Amount</b></td>
<td class="text-right">
<input type="text" class="form-control" name="grand_total" id="grand_total" />
</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
<div class="row mb-3">
<div class="col">
<textarea class="form-control2" rows="3" name="narration" id="narration" placeholder="Narration:"></textarea>
<!-- <input type="text" name="narration" id="narration" class="form-control" /> -->
</div>
</div>
<!-- <div class="col">
<div class="purchase-details-section">
<div class="">
<div class="row">
<div class="col">
Item
</div>
<div class="col">
Qty
</div>
<div class="col">
Rate
</div>
<div class="col">
Total
</div>
<div class="col">
</div>
</div>
</div>
<div class="purchase-detail">
<div class="row">
<div class="col">
<?php //fillComboWithValue("item_id[]", "", "", "tbl_items", "title", "item_id");
?>
</div>
<div class="col">
<div class="form-group">
<input type="text" class="form-control" name="quantity[]">
</div>
</div>
<div class="col">
<div class="form-group">
<input type="text" class="form-control" name="rate[]">
</div>
</div>
<div class="col">
<div class="form-group">
<input type="text" class="form-control" name="total[]">
</div>
</div>
<div class="col">
<button type="button" class="btn btn-danger remove-purchase-detail">Remove</button>
</div>
</div>
</div>
</div>
<div class="">
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
Total: <input type="text" class="form-control" name="subtotal" id="subtotal" />
</div>
<div class="col">
</div>
</div>
</div>
<div class="">
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
13% VAT: <input type="text" class="form-control" name="tax" id="tax" />
</div>
<div class="col">
</div>
</div>
</div>
<div class="">
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
Discount: <input type="text" class="form-control" name="discount" id="discount" />
</div>
<div class="col">
</div>
</div>
</div>
<div class="">
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
Grand Total <input type="text" class="form-control" name="grand_total" id="grand_total" />
</div>
<div class="col">
</div>
</div>
</div>
</div> -->
<!-- End Purchase Details Section -->
<div class="float-right">
<!-- <button type="reset" class="btn btn-default">Reset</button> -->
<button class="btn btn-primary" type="submit" name="submit">Save</button>
</div>
2024-08-06 07:03:20 +00:00
2024-07-10 12:43:19 +00:00
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
2024-07-22 12:16:09 +00:00
var counter = $('.purchase-detail').length;
2024-07-10 12:43:19 +00:00
// Clone purchase detail div
var purchaseDetailClone = $(".purchase-detail").clone().show();
2024-08-06 07:03:20 +00:00
$("#vatToggle").change(function() {
if (this.checked) {
$('#vatToggleValue').val('0');
$("tfoot tr:nth-child(4)").show();
2024-08-08 06:31:46 +00:00
$("tfoot tr:nth-child(3)").show();
2024-08-06 07:03:20 +00:00
} else {
2024-08-08 06:31:46 +00:00
//1 because it will be applied for conditions where past data may be altered by this
2024-08-06 07:03:20 +00:00
$('#vatToggleValue').val('1');
$("tfoot tr:nth-child(4)").hide();
2024-08-08 06:31:46 +00:00
$("tfoot tr:nth-child(3)").hide();
2024-08-06 07:03:20 +00:00
}
calculateTotals();
});
2024-07-10 12:43:19 +00:00
// Add Purchase Detail
$(document).on("click", ".addPurchaseDetail", function() {
2024-07-22 12:16:09 +00:00
counter+=1;
2024-07-10 12:43:19 +00:00
var newPurchaseDetail = purchaseDetailClone.clone();
2024-07-22 12:16:09 +00:00
newPurchaseDetail.find('.bbsn').text(counter);
2024-07-10 12:43:19 +00:00
$(".purchase-details-section").append(newPurchaseDetail);
});
2024-07-16 06:58:55 +00:00
$(document).on('change', '.select_item', function(){
var selectedOption = $(this).find(':selected');
var selectedValue = selectedOption.val();
var unitInput = $(this).closest('.purchase-detail').find('.item_unit');
if (selectedValue) {
$.ajax({
url: "<?php echo site_url("inventory/Purchases/getunitbyitem/"); ?>" + selectedValue,
async: true,
dataType:"json",
method: 'POST',
success: function(response) {
console.log(response);
var unitName = response.title;
unitInput.val(unitName);
},
error: function() {
console.log(error);
alert("Error retrieving unit data.");
}
});
} else {
unitInput.val('');
alert("No item selected.");
}
});
2024-07-10 12:43:19 +00:00
// Remove Purchase Detail
$(document).on("click", ".remove-purchase-detail", function() {
$(this).closest(".purchase-detail").remove();
2024-07-22 12:16:09 +00:00
updateSerialNumbers();
2024-07-10 12:43:19 +00:00
calculateTotals();
});
// Calculate totals on change of rate or quantity
2024-10-08 10:02:07 +00:00
$(document).on("change", ".purchase-detail input[name^='quantity'], .purchase-detail input[name^='rate'],.purchase-detail input[name^='vat']", function() {
2024-07-10 12:43:19 +00:00
calculateRowTotal($(this).closest(".purchase-detail"));
calculateTotals();
});
$(document).on("change", "input[name=discountpercentage]", function() {
calculateRowTotal($(this).closest(".purchase-detail"));
calculateTotals();
});
2024-07-22 12:16:09 +00:00
$(document).on("change", "input[name=discount]", function() {
calculateRowTotal($(this).closest(".purchase-detail"));
calculateTotals('amount');
});
2024-10-08 10:02:07 +00:00
});
2024-07-22 12:16:09 +00:00
function updateSerialNumbers(){
$('.purchase-detail').each(function(index){
$(this).find('.bbsn').text(index + 1);
})
counter = $('.purchase-detail').length;
}
2024-07-10 12:43:19 +00:00
// Calculate row total
function calculateRowTotal(row) {
var quantity = parseFloat(row.find("input[name^='quantity']").val()) || 0;
var rate = parseFloat(row.find("input[name^='rate']").val()) || 0;
2024-10-08 10:02:07 +00:00
var vat = parseFloat(row.find('input[name^="vat"]').val()) || 0;
//
var lineTotal = quantity * rate;
var vat_amt =(vat/100)*lineTotal;
var total =lineTotal + vat_amt ;
//
// var total = quantity * rate;
2024-07-10 12:43:19 +00:00
row.find("input[name^='total']").val(total.toFixed(2));
}
// Calculate totals
2024-07-22 12:16:09 +00:00
function calculateTotals(type='') {
2024-07-10 12:43:19 +00:00
var subtotal = 0;
$(".purchase-detail").each(function() {
var total = parseFloat($(this).find("input[name^='total']").val()) || 0;
subtotal += total;
});
2024-07-22 12:16:09 +00:00
if(type=='amount'){
discountamount = parseFloat($("input[name='discount']").val());
discountpercent = (discountamount * 100) / subtotal;
$("#discountpercentage").val(discountpercent.toFixed(2));
}else{
discountpercent = parseFloat($("input[name='discountpercentage']").val());
discountamount = subtotal * (discountpercent/100);
$("#discount").val(discountamount.toFixed(2));
}
// var discountpercent = parseFloat($("input[name=discountpercentage]").val());
// var discountamount = subtotal * (discountpercent/100);
2024-07-10 12:43:19 +00:00
var taxable = subtotal - discountamount;
2024-08-06 07:03:20 +00:00
var tax = 0;
2024-10-08 10:02:07 +00:00
// if ($('#vatToggle').is(':checked')) {
// tax = taxable * 0.13; // Include 13% VAT if checkbox is checked
// }
// var grandTotal = taxable + tax;
var grandTotal = taxable;
2024-07-10 12:43:19 +00:00
$("#subtotal").val(subtotal.toFixed(2));
2024-07-22 12:16:09 +00:00
// $("#discount").val(discountamount.toFixed(2));
2024-07-10 12:43:19 +00:00
$("#taxable").val(taxable.toFixed(2));
$("#tax").val(tax.toFixed(2));
$("#grand_total").val(grandTotal.toFixed(2));
2024-10-08 10:02:07 +00:00
};
2024-07-26 07:05:15 +00:00
</script>
<?php function footerFunctions()
{ ?>
<script>
$("#purchase_date").nepaliDatePicker({
dateFormat: "%y-%m-%d",
closeOnDateSelect: true,
minDate: $('#purchase_date').data('start'),
maxDate: $('#purchase_date').data('end'),
});
</script>
<?php } ?>