BBnepal-Accounts/account/application/views/inventory/purchases/create.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

377 lines
21 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 nepaliDatePicker" id="purchase_date" value="<?php echo NepaliDate(); ?>" 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>
<!-- 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"); ?></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" 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="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" /></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() {
// Clone purchase detail div
var purchaseDetailClone = $(".purchase-detail").clone().show();
// Add Purchase Detail
$(document).on("click", ".addPurchaseDetail", function() {
var newPurchaseDetail = purchaseDetailClone.clone();
$(".purchase-details-section").append(newPurchaseDetail);
});
// Remove Purchase Detail
$(document).on("click", ".remove-purchase-detail", function() {
$(this).closest(".purchase-detail").remove();
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();
});
// 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() {
var subtotal = 0;
$(".purchase-detail").each(function() {
var total = parseFloat($(this).find("input[name^='total']").val()) || 0;
subtotal += total;
});
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));
$("#grand_total").val(grandTotal.toFixed(2));
}
});
</script>