22july
This commit is contained in:
@ -45,7 +45,7 @@
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>S.No.</th>
|
||||
<th width=50%>Items <span class="text-danger">*</span></th>
|
||||
<th class="text-center" width=5%>Qty <span class="text-danger">*</span></th>
|
||||
<th class="text-center" width=5%>Units</th>
|
||||
@ -56,7 +56,7 @@
|
||||
</thead>
|
||||
<tbody id="salesDetails">
|
||||
<tr class="sales-detail-duplicator">
|
||||
|
||||
<td class="text-center bbsn">1</td>
|
||||
<td> <select name="item_id[]" class="form-control select_item" required>
|
||||
<option value="">Select Item</option>
|
||||
<?php foreach ($items as $item) : ?>
|
||||
@ -78,7 +78,7 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="3" rowspan="5">In words: </td>
|
||||
<td colspan="4" rowspan="5">In words: </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">
|
||||
@ -89,7 +89,7 @@
|
||||
<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" id="discount"></b></td>
|
||||
<td class="text-right"><b> <input type="text" class="form-control" name="discount" id="discount"></b></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -142,6 +142,7 @@
|
||||
$(document).on("click", ".remove-sales-detail", function() {
|
||||
if ($("#salesDetails tr").length > 1) {
|
||||
$(this).closest("tr").remove();
|
||||
updateSerialNumbers();
|
||||
calculateTotals();
|
||||
}
|
||||
|
||||
@ -156,6 +157,18 @@
|
||||
calculateTotals();
|
||||
});
|
||||
|
||||
$(document).on("change", "input[name=discount]", function() {
|
||||
calculateLineTotal($(this).closest("tr"));
|
||||
calculateTotals('amount');
|
||||
});
|
||||
|
||||
function updateSerialNumbers(){
|
||||
$('.purchase-detail').each(function(index){
|
||||
$(this).find('.bbsn').text(index + 1);
|
||||
})
|
||||
counter = $('.purchase-detail').length;
|
||||
}
|
||||
|
||||
function calculateLineTotal(row) {
|
||||
var quantity = parseFloat(row.find('input[name^="qty"]').val());
|
||||
var rate = parseFloat(row.find('input[name^="rate"]').val());
|
||||
@ -167,9 +180,12 @@
|
||||
|
||||
}
|
||||
$(document).ready(function() {
|
||||
var counter = $('.sales-detail-duplicator').length;
|
||||
var currentRow = $(".sales-detail-duplicator").clone().show();
|
||||
$(document).on("click", ".add-row", function() {
|
||||
counter+=1;
|
||||
var newRow = currentRow.clone();
|
||||
newRow.find('.bbsn').text(counter);
|
||||
$("#salesDetails").append(newRow);
|
||||
// newRow.find('.select2').select2();
|
||||
// calculateTotals();
|
||||
@ -213,7 +229,7 @@
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function calculateTotals() {
|
||||
function calculateTotals(type='') {
|
||||
var subtotal = 0;
|
||||
$(".sales-detail-duplicator").each(function() {
|
||||
var lineTotal = parseFloat($(this).find("input[name^='ltotal']").val());
|
||||
@ -221,14 +237,25 @@
|
||||
subtotal += lineTotal;
|
||||
}
|
||||
});
|
||||
var discountamount = 0;
|
||||
var discountpercent = 0;
|
||||
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 = taxable * 0.13;
|
||||
var grandTotal = taxable + tax;
|
||||
$('#subtotal').val(subtotal.toFixed(2));
|
||||
$("#discount").val(discountamount.toFixed(2));
|
||||
|
||||
$("#taxable").val(taxable.toFixed(2));
|
||||
$('#tax').val(tax.toFixed(2));
|
||||
$('#grandtotal').val(grandTotal.toFixed(2));
|
||||
|
Reference in New Issue
Block a user