This commit is contained in:
Sampanna Rimal 2024-07-22 18:01:09 +05:45
parent c349ab3173
commit 78c76c2ef0
7 changed files with 81 additions and 25 deletions

View File

@ -122,10 +122,10 @@ function getTableSchema($tableName)
echo "</pre>"; echo "</pre>";
} }
function showEditButton($url, $text = "Edit") function showEditButton($url, $text = "Edit", $showtext="")
{ {
?> ?>
<a href="<?php echo site_url($url); ?>" class="btn btn-info btn-xs" title="<?php echo myLang($text); ?>"><i class="fas fa-edit"></i> <?php //echo myLang($text); <a href="<?php echo site_url($url); ?>" class="btn btn-info btn-xs" title="<?php echo myLang($text); ?>"><i class="fas fa-edit"></i> <?php echo myLang($showtext);
?></a> ?></a>
<?php <?php
} }

View File

@ -204,9 +204,9 @@
echo ($TableRow->cr_opening_balance > 0) ? myCurrency($TableRow->cr_opening_balance) : ""; ?></td> echo ($TableRow->cr_opening_balance > 0) ? myCurrency($TableRow->cr_opening_balance) : ""; ?></td>
<td class="text-center"> <td class="text-center">
<a onClick="javascript:showDetails(<?php echo $id; ?>);" class="btn btn-primary btn-xs"><i class="fas fa-copy"></i> </a> <a onClick="javascript:showDetails(<?php echo $id; ?>);" class="btn btn-primary btn-xs" title="View"><i class="fas fa-copy"></i> </a>
<a href="<?php echo site_url("accounts/accountheads/edit/$id"); ?>" class="btn btn-info btn-xs"><i class="fas fa-edit"></i> </a> <a href="<?php echo site_url("accounts/accountheads/edit/$id"); ?>" class="btn btn-info btn-xs" title="Edit"><i class="fas fa-edit"></i> </a>
<a onClick="javascript:doDelete(<?php echo $id; ?>);" class="btn btn-danger btn-xs"><i class="fas fa-trash"></i> </a> <a onClick="javascript:doDelete(<?php echo $id; ?>);" class="btn btn-danger btn-xs" title="Delete"><i class="fas fa-trash"></i> </a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>

View File

@ -59,7 +59,7 @@
<td><span class="inline-block" style="padding:0px 8px;border:1px solid <?php echo $TableRow->voucher_color; ?>;background:<?php echo $TableRow->voucher_color; ?>">&nbsp;</span> </td> <td><span class="inline-block" style="padding:0px 8px;border:1px solid <?php echo $TableRow->voucher_color; ?>;background:<?php echo $TableRow->voucher_color; ?>">&nbsp;</span> </td>
<td> <td>
<?php showEditButton($commandURL = "accounts/setup/editvouchertype/" . $TableRow->vouchertype_id); ?> <?php showEditButton($commandURL = "accounts/setup/editvouchertype/" . $TableRow->vouchertype_id , "Edit", "Edit"); ?>
</td> </td>
</tr> </tr>

View File

@ -7,7 +7,7 @@
<!-- old code --> <!-- old code -->
<div class="card card-primary card-outline"> <div class="card card-primary card-outline">
<div class="card-header"> <div class="card-header">
<?php echo isset($item) ? 'Edit' : 'Add'; ?> <!-- <?php echo isset($item) ? 'Edit' : 'Create'; ?> -->
<h5 class="m-0">Create <?php echo $pageTitle; ?> <h5 class="m-0">Create <?php echo $pageTitle; ?>
<?php //showListButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/list","List ".$pageTitle); <?php //showListButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/list","List ".$pageTitle);
?> ?>
@ -80,8 +80,10 @@
<div class="col-9"> <div class="col-9">
<div class="card card-primary card-outline"> <div class="card card-primary card-outline">
<div class="card-header"> <div class="card-header">
<h5 class="m-0"><?php echo $pageTitle; ?> <h5 class="m-0">
Currently Selected Fiscal Year : <?php echo $this->session->userdata("FiscalYearID"); ?> Current Fiscal Year :
<?php $currentFiscalYear = showFiscalYear(); ?>
<?php //showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add","Create New ".$pageTitle); <?php //showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add","Create New ".$pageTitle);
?> ?>
</h5> </h5>
@ -117,7 +119,7 @@
<!-- <?php //showEditButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?> --> <!-- <?php //showEditButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?> -->
<a href="<?php echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?>" data-fiscalyear_id="<?php echo $id; ?>" class="editButton btn-info btn-xs"><i class="fas fa-edit"></i> Edit Modal</a> <a href="<?php echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?>" data-fiscalyear_id="<?php echo $id; ?>" class="btn btn-info btn-xs"><i class="fas fa-edit"></i> Edit</a>
<!-- <a href="<?php //echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?>" data-fiscalyear_id="<?php //echo $id; ?>" class="editButton btn-info btn-xs"><i class="fas fa-edit"></i> Edit Modal</a> --> <!-- <a href="<?php //echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/edit/$id"); ?>" data-fiscalyear_id="<?php //echo $id; ?>" class="editButton btn-info btn-xs"><i class="fas fa-edit"></i> Edit Modal</a> -->
<?php if ($TableRow->status == 0) : ?><a onClick="javascript:doSelect(<?php echo $id; ?>);" class="btn btn-success btn-xs"><i class="fas fa-check"></i> Select</a><?php endif; ?> <?php if ($TableRow->status == 0) : ?><a onClick="javascript:doSelect(<?php echo $id; ?>);" class="btn btn-success btn-xs"><i class="fas fa-check"></i> Select</a><?php endif; ?>
<a onClick="javascript:doDelete(<?php echo $id; ?>);" class="btn btn-danger btn-xs"><i class="fas fa-trash"></i> Delete</a> <a onClick="javascript:doDelete(<?php echo $id; ?>);" class="btn btn-danger btn-xs"><i class="fas fa-trash"></i> Delete</a>
@ -177,7 +179,7 @@
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Handle Edit Button Click // Handle Edit Button Click
$('.editButton').click(function(e) { $('.btn-info').click(function(e) {
e.preventDefault(); e.preventDefault();
var id = $(this).data('fiscalyear_id'); var id = $(this).data('fiscalyear_id');
$.ajax({ $.ajax({

View File

@ -47,7 +47,7 @@
<!--COL START--> <!--COL START-->
<div class="col"> <div class="col">
<div class="form-group"> <div class="form-group">
<?php fillComboWithValue("itemcategories_id", "Category", "itemcategories_id", "tbl_itemcategories", "title", "itemcategory_id", isset($item) ? $item->itemcategories_id : ''); ?> <?php fillComboWithValue("itemcategories_id", "Group", "itemcategories_id", "tbl_itemcategories", "title", "itemcategory_id", isset($item) ? $item->itemcategories_id : ''); ?>
</div> </div>
</div> </div>
<!--COL END--> <!--COL END-->
@ -121,7 +121,7 @@
<th width="25%"><?php myLang('Name'); ?></th> <th width="25%"><?php myLang('Name'); ?></th>
<th width="10%"><?php myLang('Code'); ?></th> <th width="10%"><?php myLang('Code'); ?></th>
<th width="10%"><?php myLang('Units'); ?></th> <th width="10%"><?php myLang('Units'); ?></th>
<th width="10%"><?php myLang('Category'); ?></th> <th width="10%"><?php myLang('Group'); ?></th>
<th width="10%" class="text-right"><?php myLang('Qty'); ?></th> <th width="10%" class="text-right"><?php myLang('Qty'); ?></th>
<th width="10%" class="text-right"><?php myLang('Rate'); ?></th> <th width="10%" class="text-right"><?php myLang('Rate'); ?></th>
<th width="10%" class="text-right"><?php myLang('Total'); ?></th> <th width="10%" class="text-right"><?php myLang('Total'); ?></th>

View File

@ -324,11 +324,14 @@
</div> </div>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
var counter = $('.purchase-detail').length;
// Clone purchase detail div // Clone purchase detail div
var purchaseDetailClone = $(".purchase-detail").clone().show(); var purchaseDetailClone = $(".purchase-detail").clone().show();
// Add Purchase Detail // Add Purchase Detail
$(document).on("click", ".addPurchaseDetail", function() { $(document).on("click", ".addPurchaseDetail", function() {
counter+=1;
var newPurchaseDetail = purchaseDetailClone.clone(); var newPurchaseDetail = purchaseDetailClone.clone();
newPurchaseDetail.find('.bbsn').text(counter);
$(".purchase-details-section").append(newPurchaseDetail); $(".purchase-details-section").append(newPurchaseDetail);
}); });
@ -361,6 +364,7 @@
// Remove Purchase Detail // Remove Purchase Detail
$(document).on("click", ".remove-purchase-detail", function() { $(document).on("click", ".remove-purchase-detail", function() {
$(this).closest(".purchase-detail").remove(); $(this).closest(".purchase-detail").remove();
updateSerialNumbers();
calculateTotals(); calculateTotals();
}); });
// Calculate totals on change of rate or quantity // Calculate totals on change of rate or quantity
@ -374,6 +378,17 @@
calculateTotals(); 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 // Calculate row total
function calculateRowTotal(row) { function calculateRowTotal(row) {
var quantity = parseFloat(row.find("input[name^='quantity']").val()) || 0; var quantity = parseFloat(row.find("input[name^='quantity']").val()) || 0;
@ -382,20 +397,32 @@
row.find("input[name^='total']").val(total.toFixed(2)); row.find("input[name^='total']").val(total.toFixed(2));
} }
// Calculate totals // Calculate totals
function calculateTotals() { function calculateTotals(type='') {
var subtotal = 0; var subtotal = 0;
$(".purchase-detail").each(function() { $(".purchase-detail").each(function() {
var total = parseFloat($(this).find("input[name^='total']").val()) || 0; var total = parseFloat($(this).find("input[name^='total']").val()) || 0;
subtotal += total; subtotal += total;
}); });
var discountpercent = parseFloat($("input[name=discountpercentage]").val());
var discountamount = subtotal * (discountpercent/100); 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 taxable = subtotal - discountamount;
var tax = taxable * 0.13; var tax = taxable * 0.13;
var grandTotal = taxable + tax; var grandTotal = taxable + tax;
$("#subtotal").val(subtotal.toFixed(2)); $("#subtotal").val(subtotal.toFixed(2));
$("#discount").val(discountamount.toFixed(2)); // $("#discount").val(discountamount.toFixed(2));
$("#taxable").val(taxable.toFixed(2)); $("#taxable").val(taxable.toFixed(2));
$("#tax").val(tax.toFixed(2)); $("#tax").val(tax.toFixed(2));
$("#grand_total").val(grandTotal.toFixed(2)); $("#grand_total").val(grandTotal.toFixed(2));

View File

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