483 lines
26 KiB
PHP
483 lines
26 KiB
PHP
<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>
|
|
|
|
<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>
|
|
<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">
|
|
</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>
|
|
|
|
<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>
|
|
|
|
<!-- <div class="mt-3">
|
|
<label for="vatToggle">VAT</label>
|
|
<input type="checkbox" id="vatToggle" checked>
|
|
</div>
|
|
<input type="hidden" id="vatToggleValue" name="vatToggleValue" value="1"> -->
|
|
<!-- 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>
|
|
<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>
|
|
<td width=40%> <?php fillComboWithValue("item_id[]", "", "", "tbl_items", "title", "item_id", "", "select_item"); ?></td>
|
|
<td width=10%> <input type="text" class="form-control input-group-sm" name="quantity[]"></td>
|
|
<td width=5%><input type="text" class="form-control item_unit" name="pcs/dozen/kgs" required> </td>
|
|
<td width=15%><input type="text" class="form-control" name="rate[]"></td>
|
|
<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>
|
|
<td colspan="3" rowspan="5">In words: </td>
|
|
<td class="text-right" colspan="1" rowspan="5">
|
|
<br>
|
|
<br>
|
|
<br>
|
|
<br>
|
|
|
|
<label for="vatToggle">VAT</label>
|
|
<input type="checkbox" id="vatToggle" checked>
|
|
<input type="hidden" id="vatToggleValue" name="vatToggleValue" value="1">
|
|
</td>
|
|
<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>
|
|
|
|
<td class="text-right "><b>13% VAT</b></td>
|
|
<td class="text-right">
|
|
<input type="text" class="form-control" name="tax" id="tax" />
|
|
</td>
|
|
<td></td>
|
|
</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>
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
$(document).ready(function() {
|
|
var counter = $('.purchase-detail').length;
|
|
// Clone purchase detail div
|
|
var purchaseDetailClone = $(".purchase-detail").clone().show();
|
|
|
|
$("#vatToggle").change(function() {
|
|
if (this.checked) {
|
|
$('#vatToggleValue').val('0');
|
|
$("tfoot tr:nth-child(4)").show();
|
|
$("tfoot tr:nth-child(3)").show();
|
|
|
|
} else {
|
|
//1 because it will be applied for conditions where past data may be altered by this
|
|
$('#vatToggleValue').val('1');
|
|
$("tfoot tr:nth-child(4)").hide();
|
|
$("tfoot tr:nth-child(3)").hide();
|
|
|
|
}
|
|
calculateTotals();
|
|
});
|
|
// Add Purchase Detail
|
|
$(document).on("click", ".addPurchaseDetail", function() {
|
|
counter+=1;
|
|
var newPurchaseDetail = purchaseDetailClone.clone();
|
|
newPurchaseDetail.find('.bbsn').text(counter);
|
|
$(".purchase-details-section").append(newPurchaseDetail);
|
|
});
|
|
|
|
$(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.");
|
|
}
|
|
});
|
|
// Remove Purchase Detail
|
|
$(document).on("click", ".remove-purchase-detail", function() {
|
|
$(this).closest(".purchase-detail").remove();
|
|
updateSerialNumbers();
|
|
calculateTotals();
|
|
});
|
|
// Calculate totals on change of rate or quantity
|
|
$(document).on("change", ".purchase-detail input[name^='quantity'], .purchase-detail input[name^='rate']", function() {
|
|
calculateRowTotal($(this).closest(".purchase-detail"));
|
|
calculateTotals();
|
|
});
|
|
|
|
$(document).on("change", "input[name=discountpercentage]", function() {
|
|
calculateRowTotal($(this).closest(".purchase-detail"));
|
|
calculateTotals();
|
|
});
|
|
|
|
$(document).on("change", "input[name=discount]", function() {
|
|
calculateRowTotal($(this).closest(".purchase-detail"));
|
|
calculateTotals('amount');
|
|
});
|
|
|
|
function updateSerialNumbers(){
|
|
$('.purchase-detail').each(function(index){
|
|
$(this).find('.bbsn').text(index + 1);
|
|
})
|
|
counter = $('.purchase-detail').length;
|
|
}
|
|
// 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;
|
|
var total = quantity * rate;
|
|
row.find("input[name^='total']").val(total.toFixed(2));
|
|
}
|
|
// Calculate totals
|
|
function calculateTotals(type='') {
|
|
var subtotal = 0;
|
|
$(".purchase-detail").each(function() {
|
|
var total = parseFloat($(this).find("input[name^='total']").val()) || 0;
|
|
subtotal += total;
|
|
});
|
|
|
|
if(type=='amount'){
|
|
alert("amount");
|
|
discountamount = parseFloat($("input[name='discount']").val());
|
|
discountpercent = (discountamount * 100) / subtotal;
|
|
alert(discountamount);
|
|
$("#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);
|
|
var taxable = subtotal - discountamount;
|
|
var tax = 0;
|
|
if ($('#vatToggle').is(':checked')) {
|
|
tax = taxable * 0.13; // Include 13% VAT if checkbox is checked
|
|
}
|
|
var grandTotal = taxable + tax;
|
|
|
|
$("#subtotal").val(subtotal.toFixed(2));
|
|
// $("#discount").val(discountamount.toFixed(2));
|
|
$("#taxable").val(taxable.toFixed(2));
|
|
$("#tax").val(tax.toFixed(2));
|
|
$("#grand_total").val(grandTotal.toFixed(2));
|
|
}
|
|
});
|
|
</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 } ?>
|