Skip to content

Instantly share code, notes, and snippets.

@esmeromichael
Created August 9, 2017 05:08
Show Gist options
  • Save esmeromichael/49732ca69282f4da87b710106d0a9dd0 to your computer and use it in GitHub Desktop.
Save esmeromichael/49732ca69282f4da87b710106d0a9dd0 to your computer and use it in GitHub Desktop.
@extends('layouts.accounting.header')
@section('content')
<style type="text/css">
.select2-container--default .select2-selection--single{
background-color: #faf2cc;
}
</style>
<section class="container main_section">
<br><br><br><br><br><br><br>
<div class="flash-message top-message">
@foreach (['danger', 'warning', 'success', 'info'] as $message)
@if(Session::has('alert-' . $message))
<p class="alert alert-{{ $message }}" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">{{ Session::get('alert-' . $message) }}</p>
@endif
@endforeach
</div>
@if(isset($id))
<div style="color: #666;font-weight: bold;"><i>Details for Petty Cash No. {{str_pad($id,8,"0",STR_PAD_LEFT)}}. Created by {{ $header->partner->name }}</i></div>
@endif
<div class="roworder" style="margin-top:2%;">
<form class="form-horizontal" autocomplete="off" role="form" id="wowee" method="POST" action="{{ url('/accounting/pettycash=create') }}" >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group" style="">
@if(Session::get('company') == "")
<label class="control-label col-sm-1">Transacting Branch</label>
<div class="col-sm-4">
<select class="form-control transact_branch" name="branch_company" readonly="" autofocus="">
</select>
</div>
@else
@if(Session::get('company') == "999")
<label class="control-label col-sm-1"><b>Transacting Branch</b></label>
<div class="col-sm-4">
@if(isset($id))
<select class="form-control transact_branch" name="branch_company" style="background-color: #faf2cc;">
<option value=""></option>
<option value="0" {{$header->cb == 0 ? 'selected' : ''}}>Head Office</option>
@foreach(App\PartnerBranch::branch() as $branch)
<option value="{{ $branch->id }}" {{$header->cb == $branch->id ? 'selected' : ''}}>{{$branch->name}}</option>
@endforeach
</select>
@else
<select class="form-control transact_branch" name="branch_company" style="background-color: #faf2cc;">
<option value=""></option>
<option value="0">Head Office</option>
@foreach(App\PartnerBranch::branch() as $branch)
<option value="{{ $branch->id }}">{{$branch->name}}</option>
@endforeach
</select>
@endif
</div>
@else
<label class="control-label col-sm-1">Transacting Branch</label>
<div class="col-sm-4">
<select class="form-control transact_branch" name="branch_company" readonly="" autofocus="">
@if(isset($id))
@if(Session::get('company') == "0")
<option value="0" {{$header->cb == 0 ? 'selected' : ''}}>Head Office</option>
@else
<option value="{{Session::get('company')}}" >{{App\PartnerBranch::getbranch( Session::get('company'))->name}}</option>
@endif
@else
@if(Session::get('company') == "0")
<option value="0" selected="">Head Office</option>
@else
<option value="{{Session::get('company')}}" selected="">{{App\PartnerBranch::getbranch( Session::get('company'))->name}}</option>
@endif
@endif
</select>
</div>
@endif
@endif
<label class="control-label col-sm-4" for=""></label>
<div class="col-sm-2">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-1" for="rrno"></label>
<div class="col-sm-4">
</div>
<label class="control-label col-sm-4" for="rrno">Petty Cash No. :</label>
<div class="col-sm-2">
<input type="text" name="pc_id" class="form-control pc_id" readonly="" value="{{isset($id) ? str_pad($header->id,8,"0",STR_PAD_LEFT) :'New'}}">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-1">Petty Cash Owner :</label>
<div class="col-sm-4">
@if(isset($id))
<input type="text" name="pc_name" value="{{App\User::name($header->createdby)->name}}" class="form-control" readonly="" style="background-color: #faf2cc;">
<input type="hidden" name="pc_user_id" value="{{App\User::name($header->createdby)->id}}">
@else
<input type="text" name="pc_name" value="{{App\User::name(Session::get('user'))->name}}" class="form-control" readonly="" style="background-color: #faf2cc;">
<input type="hidden" name="pc_user_id" value="{{App\User::name(Session::get('user'))->id}}">
@endif
</div>
<label class="control-label col-sm-4" for="">Petty Cash Date :</label>
<div class="col-sm-2">
<?php $date = date("Y-m-d"); ?>
<input type="text" class="form-control" id="datepicker1" name="pc_date" style="cursor:default" value="{{ isset($id) ? date('M-d-Y', strtotime($header->date)) : date('M-d-Y', strtotime($date)) }}" readonly>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-1" >Remarks:</label>
<div class="col-sm-10">
<textarea class="form-control remarks" rows="2" name="remarks" tabindex="4">{{isset($id) ? $header->remarks : ''}}</textarea>
</div>
</div>
<hr>
<h4>Petty Cash Details</h4>
<div class="" style="border:1.5px solid #989898;border-radius: 5px;margin-top: 1%;">
<div class="col-sm-12">
<legend></legend>
<table class="maintable table table-striped table-hover">
<thead>
<tr>
<th width="1%">&nbsp;</th>
<th width="14%">Partner</th>
<th width="7%">Date</th>
<th width="7%">Type</th>
<th width="7%">Reference</th>
<th width="14%">Details</th>
<th width="7%" style="text-align:center;">Amount</th>
<th width="6%" style="text-align:center;">Tax Type</th>
<th width="15%" style="text-align:center;">Account Title</th>
<th width="6%" style="text-align:right;">Debit&nbsp;&nbsp;</th>
<th width="6%" style="text-align:right;">Credit&nbsp;&nbsp;</th>
<th width="2%"></th>
</tr>
</thead>
<thead class="tofill">
<tr>
<td>&nbsp;</td>
<td>
<select class="partner form-control" data-width="100%" tabindex="1" style="background-color: #faf2cc;">
<option selected=""></option>
</select>
</td>
<td>
<input type="text" class="ddate form-control" id="datepicker2" value="" readonly="" style="cursor:default;background-color: #faf2cc;">
</td>
<td>
<select class="form-control type_payment">
<option value="Open">Open</option>
<option value="PO">PO</option>
</select>
</td>
<td>
<div class="ref-div-open">
<input type="text" class="reference form-control" id="reference-open" placeholder="" value="" style="background-color: #faf2cc;">
</div>
<div class="ref-div-po" style="display: none;">
<select class="reference form-control" id="reference-po" style="background-color: #faf2cc;">
</select>
</div>
<input type="hidden" name="refholder" class="refholder"/>
</td>
<td>
<input type="text" class="details form-control" style="width:100%">
</td>
<td>
<input type="text" onkeypress="return isNumberKey(event, this);" class="amount form-control" style="text-align:right;background-color: #faf2cc;" placeholder="0.00">
</td>
<td>
<select class="taxtype form-control">
@foreach(App\TaxType::all() as $taxtype)
@if($taxtype->name == 'VAT')
<option value="{{$taxtype->id}}" data-rate="{{App\VatRate::input()->rate}}">{{$taxtype->name}}</option>
@else
<option value="{{$taxtype->id}}" data-rate="{{$taxtype->rate}}">{{$taxtype->name}}</option>
@endif
@endforeach
</select>
</td>
<td>
<select class="account_title form-control" id="chart" tabindex="1" style="background-color: #faf2cc;">
<option value="" selected="selected">--Select One--</option>
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>
@endif
@endforeach
</select>
</td>
<td>
<input type="text" onkeypress="return isNumberKey(event, this);" class="debit form-control" placeholder="0.00" value="0.00" style="text-align: right;padding-right: 3px;" readonly>
</td>
<td>
<input type="text" onkeypress="return isNumberKey(event, this);" class="credit form-control" placeholder="0.00" value="0.00" style="text-align: right;padding-right: 3px;" readonly>
</td>
<td><a href="" id="add" class="add"><i class="fa fa-plus-circle fa-2x"></i></a></td>
</tr>
</thead>
<thead>
<tr>
<td></td><td></td>
<td>
<!-- <button class="btn btn-sm space " style="color:#ffffff; background-color:#4682B4;" type="button" id="expand">Collapse All</button> -->
</td>
<td></td><td></td><td></td><td></td><td> </td>
<td>
<?php $account_payable = App\AccountingDefault::where('id',1)->with('glAccount')->first();?>
<?php $account = App\AccountingDefault::where('id',2)->with('glAccount')->first();?>
<label style="text-align:center;"><b>{{ $account->glAccount->title }}</b></label>
</td>
<td></td>
<td>
<input type="hidden" class="fund" name="fund" value="{{isset($id) ? $header->fund : '0.00'}}">
<label style="text-align:right;font-weight:bold" class="fund-label">{{isset($id) ? number_format($header->fund,2) : '0.00'}}</label>
</td>
<td></td>
</tr>
</thead>
<tbody class="content">
@if(isset($id))
@include('accounting.pettycash.other_details')
@endif
</tbody>
<tfoot class="pctotal">
<tr>
<td><a href="#" id="btndelete-many" class="btndelete-many fa fa-trash-o fa-lg"></a></td>
<td>
</td>
<td></td><td></td><td></td><td></td><td></td><td></td>
<td>
<label style="text-align:right; font-weight:bold;">Total :</label>
</td>
<td>
<input type="hidden" class="gdebit" name="gdebit" value="{{isset($id) ? $header->debit : '0.00'}}">
<label style="text-align:right; font-weight:bold;" class="gdebit-label">{{isset($id) ? number_format($header->debit,2) : '0.00'}}</label>
</td>
<td>
<input type="hidden" class="gcredit" name="gcredit" value="{{isset($id) ? $header->credit : '0.00'}}">
<label style="text-align:right; font-weight:bold;" class="gcredit-label">{{isset($id) ? number_format($header->credit,2) : '0.00'}}</label>
</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
@if(isset($header))
@if($header->status == "Approved" || $header->status == "Printed")
<!-- for payment details -->
<br><br>
<fieldset class="form-horizontal">
<legend align="left"><b>Payment Details</b></legend>
<div>
<table class="table table-striped table-hovered" style="width:50%;">
<thead style="background-color:#333333;">
<tr>
<th width="20%" style="color:#FFFFFF;">Document Type</th>
<th width="25%" style="color:#FFFFFF;">Document No.</th>
<th width="23%" style="color:#FFFFFF;">Document Date</th>
<th width="25%" style="text-align:right;color:#FFFFFF;">Amount</th>
<th width="7%" style="text-align:right;color:#FFFFFF;"></th>
</tr>
</thead>
<tbody>
<?php $payDsum = 0;?>
@foreach($pt_details as $detail)
<tr>
<td><b>{{$detail->doc_type}}</b></td>
<td>
@if($detail->doc_type == "Check")
<a href="/accounting/disbursements/check={{$detail->doc_no}}"><?php echo sprintf("%08d", $detail->doc_no);?></a>
@else
<a href="/accounting/disbursements/electronic={{$detail->doc_no}}"><?php echo sprintf("%08d", $detail->doc_no);?></a>
@endif
</td>
<td>
{{date('M-d-Y', strtotime($detail->doc_date))}}
</td>
<td style="text-align: right;">
<?php echo number_format($detail->amount,2,'.',','); ?><?php $payDsum += $detail->amount;?>
</td>
<td>
<label class="control-label" style="margin-top:-3px;"><strong></strong></label>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<td><b style="font-size:13px;">Total</b></td>
<td></td>
<td></td>
<td style="text-align:right;">
<b style="font-size:13px;"><?php echo number_format($payDsum, 2, '.', ','); ?></b>
<input type="hidden" name="" class="" value="<?php echo number_format($payDsum, 2, '.', ''); ?>">
</td>
<td><label class="control-label" style="margin-top:-3px;"><strong></strong></label></td>
</tr>
</tfoot>
</table>
</div>
</fieldset>
<br><br><br><br><br><br>
<!-- end for payment details -->
@endif
@endif
<footer class="footer">
<nav class="navbar navbar-inverse navbar-fixed-bottom" style="background: #3A3A3A;">
@if(isset($id))
@if($header->status == 'New')
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,102))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,102)->status == "Yes")
<button class="save btn btn-lg btn-sm space forbuttons" type="submit" name="update" value="update"><img src="\images\update1.png">&nbsp;<font color="white">Update</font></button>
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,101))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,101)->status == "Yes")
<button class="finalize btn btn-lg btn-sm forbuttons" type="submit" name="finalize" id="finalize-button" value="finalize"><img src="\images\finalized1.png">&nbsp;<font color="white">Finalize</font></button>
@endif
@endif
@elseif($header->status == 'Finalized')
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,104))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,104)->status == "Yes")
<button class="reopen btn btn-lg btn-sm space forbuttons" type="submit" name="reopen" value="reopen" id="reopen-button"><img src="\images\reopen1.png">&nbsp;<font color="white">Re-Open</font></button>
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,103))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,103)->status == "Yes")
<button class="approve btn btn-lg btn-sm forbuttons" type="submit" id="approve-button" name="approve" value="approve"><img src="\images\approve1.png">&nbsp;<font color="white">Approve</font></button>
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,106))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,106)->status == "Yes")
<button class="void btn btn-lg btn-sm forbuttons" type="submit" id="void-button" name="void" value="void"><img src="\images\void1.png">&nbsp;<font color="white">Void</font></button>
@endif
@endif
@elseif($header->status == 'Approved')
@if($header->posted == 'Unposted')
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,104))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,104)->status == "Yes")
<button class="re-open btn btn-lg btn-sm space forbuttons" type="submit" name="reopen" value="reopen" id="reopen-button"><img src="\images\reopen1.png">&nbsp;<font color="white">Re-Open</font></button>
@endif
@endif
@if($postingcheck == 0)
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,107))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,107)->status == "Yes")
<button class="btn btn-lg btn-sm btn_posted" type="submit" name="posted" id="posted-button" value="Posted" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\posted.png">&nbsp;<font color="white">Post</font></button>
@endif
@endif
@endif
@else
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,108))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,108)->status == "Yes")
<button class="btn btn-lg btn-sm btn_unposted space" type="submit" name="unposted" id="unposted-button" value="Unposted" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\unposted.png">&nbsp;<font color="white">Unpost</font></button>
@endif
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,105))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,105)->status == "Yes")
<button class="btn btn-lg btn-sm print" type="submit" form="print-form" id="print-button" name="print" value="print" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\print1.png">&nbsp;<font color="white">Print</font></button>
@endif
@endif
@if($header->posted == 'Unposted')
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,106))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,106)->status == "Yes")
<button class="void btn btn-lg btn-sm forbuttons" type="submit" id="void-button" name="void" value="void"><img src="\images\void1.png">&nbsp;<font color="white">Void</font></button>
@endif
@endif
@endif
@elseif($header->status == 'Printed')
@if($header->posted == 'Unposted')
@if($postingcheck == 0)
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,104))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,104)->status == "Yes")
<button class="re-open btn btn-lg btn-sm space forbuttons" type="submit" name="reopen" value="reopen" id="reopen-button"><img src="\images\reopen1.png">&nbsp;<font color="white">Re-Open</font></button>
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,107))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,107)->status == "Yes")
<button class="btn btn-lg btn-sm btn_posted" type="submit" name="posted" id="posted-button" value="Posted" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\posted.png">&nbsp;<font color="white">Post</font></button>
@endif
@endif
@endif
@else
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,108))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,108)->status == "Yes")
<button class="btn btn-lg btn-sm btn_unposted" type="submit" name="unposted" id="unposted-button" value="Unposted" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\unposted.png">&nbsp;<font color="white">Unpost</font></button>
@endif
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,105))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,105)->status == "Yes")
<button class="btn btn-lg btn-sm print" form="print-form" type="submit" id="print-button" name="print" value="print" style="background-color:#1B1B1B;font-weight:200;border-radius:2px solid;border-color:white;"><img src="\images\print1.png">&nbsp;<font color="white">Print</font></button>
@endif
@endif
@endif
@else
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,100))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,100)->status == "Yes")
<button class="save btn btn-lg btn-sm space forbuttons" type="submit" name="save" value="save"><img src="\images\save1.png">&nbsp;<font color="white">Save</font></button>
@endif
@endif
@if(!App\RightDetail::btn_rights(Session::get('user'),7,0,101))
@else
@if(App\RightDetail::btn_rights(Session::get('user'),7,0,101)->status == "Yes")
<button class="finalize btn btn-lg btn-sm forbuttons" type="submit" name="finalize" id="finalize-button" value="finalize"><img src="\images\finalized1.png">&nbsp;<font color="white">Finalize</font></button>
@endif
@endif
@endif
</nav>
</footer>
</form>
<form id="print-form" target="_blank" method="post" action="{{ url('/accounting/pettycash=create') }}">
</form>
</div>
</section>
@if(isset($glpost))
<script src="{{ asset('/js/bootstrap.js') }}"></script>
@include('accounting.pettycash.posting')
@endif
<script src="{{ asset('/additional/js/calc.js') }}"></script>
<script type="text/javascript">
//////////////////////// Events ////////////////////////////////
$("#datepicker1").datepicker({ dateFormat: 'M-dd-yy' })
$("#datepicker2").datepicker({ dateFormat: 'M-dd-yy' })
// $.getJSON('/dev/api/payee', function(data){
// data = $.map(data, function(partner) {
// return {id: partner.id, text: partner.name };
// });
// $(".partner").select2({
// minimumInputLength: 1,
// multiple: false,
// width: 304,
// data: data
// });
// });
$(".partner").select2({
minimumInputLength : 1,
allowClear: false,
ajax : {
url : "/dev/api/payeePartners",
dataType : 'json',
data : function (params) {
return {
name: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
,
escapeMarkup: function (markup) { return markup; },
templateResult: function(repo) {
return repo.name;
},
templateSelection: function(repo){
return repo.name;
}
});
///////////////////////// posting of posting ////////////////
// $('.posting-btn').on('click',function(e){
// prevnext();
// var id = $(this).data('getid');
// e.preventDefault();
// $.ajax({
// url:'{{url("accounting/disbursements/pcf_checkposting")}}',
// type:'GET',
// data:{id:id},
// success: function(data){
// $('#postingmodal .modal-content').html(data);
// slider();
// }
// });
// });
//////////////////////// end posting of posting //////////////
$('.partner').on('change', function(){
var id = $('.partner option:selected').val();
var cb = $('.transact_branch').val();
$.getJSON('/dev/api/reference?cb='+ cb + '&id=' +id, function(data){
$('#reference-po').empty();
$('#reference-po').append('<option value="0">--Select--</option>');
$.each(data,function(index,value){
$('#reference-po').append('<option value="'+value.po_no+'">'+value.po_no+'</option>');
});
});
});
var tt_orig = $('.taxtype ').html();
var acctt_orig = $('.account_title').html();
$('.type_payment').on('change',function(){
var pay_type = $('option:selected', this).val();
if(pay_type == 'Open'){
$('.amount').val('');
$('#reference-po option').removeAttr('selected');
$('.ref-div-open').show();
$('.ref-div-po').hide();
$('.taxtype ').html(tt_orig);
$('.taxtype ').css('background-color','#fff');
$('.account_title ').html(acctt_orig);
$('.account_title ').css('background-color','#fff');
}
else{
$('.ref-div-po').show();
$('.ref-div-open').hide();
$('.taxtype ').html('<option value="0" data-rate="0.00">NA</option>');
$('.taxtype ').css('background-color','#eee');
$('.account_title ').html('<option value="{{$account_payable->account_id}}" >{{$account_payable->glAccount->title}}</option>');
$('.account_title ').css('background-color','#eee');
}
$('.refholder').val('');
});
$('.ref-div-po .reference').on('change', function(){
if($('.reference option:selected').val() != ""){
var po_id = $('option:selected', this).val();
$.getJSON('/dev/api/payables?id=' + po_id, function(data){
var amount = 0;
if(data.fwdd_status == 'No'){
amount = data.po_applied - data.applied;
}
else{
amount = data.amount - (data.amount - data.fwdd_applied);
}
$('.amount').val(amount.toFixed(2));
})
}
});
$('.ref-div-po .reference, .ref-div-open .reference').on('change', function(){
$('.refholder').val($(this).val());
});
$('form').submit(function(e){
var checktr = $('table.maintable tbody.content tr').length;
var fx = 0;
if(checktr == 0){
$('.flash-message').html('\
<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add items.</p>\
');
e.preventDefault();
}
else{
$('table.maintable tbody.content tr:even').each(function(){
var base_amount = $(this).find('.amount_editable').val();
var data_check = $(this).find('.amount_editable').data('base_check');
var subtotal = $('.trmove'+data_check).find('.debit_getsubtotal').val();
if(parseFloat(subtotal) > parseFloat(base_amount)){
fx++;
}
});
// if(fx > 0){
// alert('Debit total exceeds amount value.');
// e.preventDefault();
// }
}
});
@if(isset($id))
var trcounter = {{ count($detail) }};
var tr_inc = {{ count($detail) }};
@else
var trcounter = 0;
var tr_inc = 0;
@endif
$('a#add').on('click', function(e){
e.preventDefault();
if($('.partner').val() == ''){
$('.partner').select2('open');
return false;
}
else if($('.ddate').val() == ''){
$('.ddate').focus();
return false;
}
else if($('.refholder').val() == ''){
alert('Reference field is required.')
return false;
}
else if($('.amount').val() == ''){
$('.amount').focus();
return false;
}
else if($('.account_title').val() == ''){
$('.account_title').focus();
return false;
}
//var pname = $("#select2-ipzx-container").text();
var pname = $('.partner option:selected').text();
var pid = $('.partner option:selected').val();
var date = $('#datepicker2').val();
var tax_id = $('.taxtype option:selected').val();
var tax_name = $('.taxtype option:selected').text();
var details = $('.details').val();
var debit = $('.debit').val() == '' ? 0 : $('.debit').val();
var credit = $('.credit').val() == '' ? 0 : $('.credit').val();
var type_payment = $('.type_payment').val();
var refholder = $('.refholder').val();
var base_amount = $('.amount').val();
var account_title_val = $('.account_title option:selected').val();
var account_title_name = $('.account_title option:selected').text();
var header_taxrate = $('.taxtype option:selected').data('rate');
var debitsubtotal = parseFloat($('.amount').val()) + parseFloat(debit);
var withVat = 1 + parseFloat(header_taxrate) / 100;
var withAmount = parseFloat(base_amount) / parseFloat(withVat);
var withgetVat = parseFloat(base_amount) - parseFloat(withAmount);
var grand_debit = 0;
var grand_credit = 0;
if(debit > 0){
var displayTotal = parseFloat($('.amount').val()) + parseFloat(debit);
pcfCompute(displayTotal);
}
else if(credit > 0){
var displayTotal = parseFloat($('.amount').val()) - parseFloat(credit);
pcfCompute(displayTotal);
}
else{
var displayTotal = parseFloat($('.amount').val());
pcfCompute(displayTotal);
}
trcounter = trcounter +1;
tr_inc++;
$('table.maintable tbody.content').prepend('\
<tr>\
<td><input type="checkbox" name="checkpartner[]" value="'+tr_inc+'" id="checkme" class="checkme"/>\
<input type="hidden" value="'+tr_inc+'" name="header_id[]" />\
</td>\
<td>&nbsp;&nbsp;'+pname+'<input type="hidden" name="post_partnerid[]" value="'+pid+'"/></td>\
<td>'+date+'<input type="hidden" name="post_date[]" value="'+date+'"/></td>\
<td>&nbsp;&nbsp;&nbsp;&nbsp;'+type_payment+' <input type="hidden" id="ptp" name="post_type_payment[]" value="'+type_payment+'"></td>\
<td>&nbsp;&nbsp;'+refholder+'<input type="hidden" name="post_refholfer[]" value="'+refholder+'"/></td>\
<td>&nbsp;&nbsp;'+details+'<input type="hidden" name="post_details[]" value="'+details+'"/></td>\
<td style="text-align:right;line-height:0px"><input type="text" name="post_base_amount[]" style="text-align:right" class="amount_editable form-control" id="amount_editable" data-baseamt="'+base_amount+'" onkeypress="return isNumberKey(event, this);" data-base_check="'+tr_inc+'" data-vatpercent="'+header_taxrate+'" value="'+(parseFloat(base_amount).toFixed(2))+'"/></td>\
<td style="text-align:center" class="taxtype-display">\
'+tax_name+'\
<input type="hidden" name="post_taxType[]" value="'+tax_id+'"/>\
</td>\
<td style="text-align:center"><a href="#" class="account_target'+tr_inc+'" data-toggle="collapse" data-target="#'+tr_inc+'">'+(tax_id != 1 ? account_title_name.trim() : 'Multiple')+'</a></td>\
<td style="text-align:right" id="debit'+trcounter+'" >'+currencyFormat(parseFloat(debitsubtotal).toFixed(2))+'</td>\
<td style="text-align:right" id="credit'+trcounter+'">'+currencyFormat(parseFloat(credit).toFixed(2))+'</td>\
<td style="text-align:right">&nbsp;</td>\
</tr>\
<tr class="trmove'+tr_inc+'">\
<td colspan="6" style="padding:0px;"></td>\
<td colspan="6" style="padding:0px;">\
<div class="panel panel-primary collapse" id="'+tr_inc+'" style="margin-top:10px;margin-bottom:10px;">\
<div class="panel-heading" style="height:20px">\
<table width="100%">\
<thead>\
<tr>\
<th width="65%">Account Title</th>\
<th width="15%" style="text-align:right">Debit</th>\
<th width="15%" style="text-align:right">Credit</th>\
<th width="4%">&nbsp;</th>\
</tr>\
</thead>\
</table>\
</div>\
<div style="padding:0px;padding-top:2px;padding-bottom:2px;" class="mainbody panel-body">\
<table width="100%" class="table table-striped table-hover sub-table">\
<thead style="'+(type_payment == "PO" ? 'display:none' : '')+'">\
<tr>\
<td with="65%">\
<select class="sub_account_title form-control" id="chart_p" tabindex="1" style="background-color: #faf2cc;">\
<option value="" selected="selected">--Select One--</option>\
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)\
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@endif\
@endforeach\
</select>\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_debit form-control" placeholder="0.00" value="0.00" style="text-align: right;padding-right: 3px;">\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_credit form-control" placeholder="0.00" value="0.00" style="text-align: right;padding-right: 3px;">\
</td>\
<td width="4%">\
<a href="" id="sub-add" class="sub-add" data-filterid="'+tr_inc+'"><i class="fa fa-plus-circle fa-2x"></i></a>\
</td>\
</tr>\
</thead>\
<tbody class="account_body">\
'+(debit > 0 || credit > 0 ? '<tr>\
<td width="65%">\
<select class="form-control sub_account_title2" id="chart_p" name="post_account_title[]" tabindex="1">\
<option value="" selected="selected">--Select One--</option>\
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)\
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@endif\
@endforeach\
</select>\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_debit2 form-control" placeholder="0.00" value="'+parseFloat(debit).toFixed(2)+'" name="post_subdebit[]" style="text-align: right;padding-right: 3px;">\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_credit2 form-control" placeholder="0.00" value="'+parseFloat(credit).toFixed(2)+'" name="post_subcredit[]" style="text-align: right;padding-right: 3px;">\
</td>\
<td width="4%">\
<a href="" id="btndelete-single" class="btndelete-single fa fa-trash-o fa-lg" style=""></a>\
</td>\
</tr> ' : '')+'\
<tr>\
<td width="65%">\
<select class="form-control sub_account_title3" id="chart_p" name="post_account_title_with_vat[]" tabindex="1">\
<option value="" selected="selected">--Select One--</option>\
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)\
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@endif\
@endforeach\
</select>\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_debit2 form-control base_debit'+tr_inc+'" placeholder="0.00" value="'+parseFloat(withAmount).toFixed(2)+'" style="text-align: right;padding-right: 3px;background:#fff;" >\
<input type="hidden" name="post_amount_withvat[]" class="base_debit2'+tr_inc+'" value="'+parseFloat(withAmount).toFixed(2)+'">\
</td>\
<td width="15%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_credit2 form-control" placeholder="0.00" value="0.00" style="text-align: right;padding-right: 3px;background:#fff;">\
</td>\
<td width="4%">\
</td>\
</tr>\
'+(header_taxrate > 0.00 ? '<tr>\
<td style="text-align:right">Input '+tax_name+'</td>\
<td style="text-align:right"><input type="text" style="text-align:right;padding-right:3px;" name="withvatRate[]" value="'+withgetVat.toFixed(2)+'" class="form-control sub_debit2 base_tax'+tr_inc+'" onkeypress="return isNumberKey(event, this);"/></td>\
<td style="text-align:right"><input type="text" readonly style="text-align:right;padding-right:3px;" value="0.00" class="form-control" /></td>\
<td>&nbsp;</td>\
</tr' : '<input type="hidden" name="withvatRate[]" value="'+withgetVat.toFixed(2)+'"/>')+'\
</tbody>\
<tfoot>\
<tr>\
<td style="font-weight:bold;text-align:right">Subtotal</td>\
<td style="font-weight:bold;text-align:right" class="debit_subtotal" >'+currencyFormat(parseFloat(debitsubtotal).toFixed(2))+'</td>\
<td style="font-weight:bold;text-align:right" class="credit_subtotal">'+currencyFormat(parseFloat(credit).toFixed(2))+'\
<td>&nbsp;\
<input type="hidden" value="'+debitsubtotal+'" class="debit_getsubtotal" name="debit_getsubtotal[]" />\
<input type="hidden" value="'+credit+'" class="credit_getsubtotal" name="credit_getsubtotal[]" /></td>\
</td>\
</tr>\
</tfoot>\
</table>\
</div>\
</div>\
</td>\
</tr>\
');
grandtotal_debit(grand_debit);
grandtotal_credit(grand_credit);
base_amountFunc('#amount_editable');
$('#sub-add').on('click',function(e){
e.preventDefault();
var sub_accountTitle = $(this).closest('tr').find('.sub_account_title option:selected').val();
var sub_debit = $(this).closest('tr').find('.sub_debit').val();
var sub_credit = $(this).closest('tr').find('.sub_credit').val();
var compute_sub_debit = 0;
var compute_sub_credit = 0;
var filterid = $(this).data('filterid');
var count_sub_table = 0;
if(sub_accountTitle == ''){
alert('Please select account title.');
$(this).closest('tr').find('.sub_account_title').focus();
return false;
}
else if((sub_debit == '' || sub_debit == 0) && (sub_credit == '' || sub_credit == 0)){
alert('Please fill debit or credit field.');
$(this).closest('tr').find('.sub_debit').focus();
return false;
}
$(this).closest('table').find('tbody.account_body').prepend('\
<tr>\
<td width="55%">\
<input type="hidden" name="sub_header_id[]" value="'+filterid+'"/>\
<select class="form-control sub_account_title4" id="chart_p" name="post_account_title[]" tabindex="1">\
<option value="" selected="selected">--Select One--</option>\
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)\
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@endif\
@endforeach\
</select>\
</td>\
<td width="20%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_debit2 form-control" name="post_subdebit[]" placeholder="0.00" value="'+parseFloat(sub_debit).toFixed(2)+'" style="text-align: right;padding-right: 3px;background:#fff;" >\
</td>\
<td width="20%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_credit2 form-control" name="post_subcredit[]" placeholder="0.00" value="'+parseFloat(sub_credit).toFixed(2)+'" style="text-align: right;padding-right: 3px;background:#fff;">\
</td>\
<td>\
<a href="" id="btndelete-single" class="btndelete-single fa fa-trash-o fa-lg" style=""></a>\
</td>\
</tr>\
');
var el = $(this).closest('table').find('.sub_debit2');
var el2 = $(this).closest('table');
var el3 = $(this).closest('table').find('.sub_credit2');
var el4 = $(this).closest('table');
var bb = 0;
var aa = 0;
strictField('.sub_debit2','.sub_credit2');
strictField('.sub_credit2','.sub_debit2');
compute_sub_debitFunc(el,el2,compute_sub_debit,filterid);
compute_sub_creditFunc(el3,el4,compute_sub_credit,sub_credit,filterid);
grandtotal_debit(bb);
pcfCompute(sub_debit);
grandtotal_credit(aa);
$(this).closest('table').find('.sub_account_title4:first option[value='+sub_accountTitle+']').prop('selected','selected');
$(this).closest('tr').find('.sub_account_title').val('');
$(this).closest('tr').find('.sub_debit').val('');
$(this).closest('tr').find('.sub_credit').val('');
count_sub_table = $(this).closest('table').find('tbody.account_body tr').length;
if(count_sub_table >=2){
$('.account_target'+filterid).html('Multiple');
}
keyAction('.sub_debit2');
keyAction('.sub_credit2');
deleteButton();
});
strictField('.sub_debit','.sub_credit');
strictField('.sub_credit','.sub_debit');
strictField('.sub_debit2','.sub_credit2');
strictField('.sub_credit2','.sub_debit2');
keyAction('.sub_debit2');
keyAction('.sub_credit2');
deleteButton();
$('table.maintable tbody.content tr:first + tr').find('.sub_account_title2 option[value='+account_title_val+'], .sub_account_title3 option[value='+account_title_val+']').prop('selected','selected');
$('thead.tofill input').val('');
$('thead.tofill input.amount').val('0.00');
$('thead.tofill select').select2('val',null);
$('thead.tofill option:selected').removeAttr('selected');
$('.ref-div-open').show();
$('.ref-div-po').hide();
$('.taxtype ').html(tt_orig);
$('.taxtype ').css('background-color','#fff');
$('.account_title ').html(acctt_orig);
$('.account_title ').css('background-color','#fff');
});
$('.debit').on('keyup',function(){
var creditValue = $('.credit').val();
var debitValue = $('.debit').val();
debitAndCredit(debitValue,creditValue,'.credit');
});
$('.credit').on('keyup',function(){
var creditValue = $('.credit').val();
var debitValue = $('.debit').val();
debitAndCredit(creditValue,debitValue,'.debit');
});
///////////////////////////////////////////////////// Function Section /////////////////////////////////////////////////////
// function isNumberKey(evt, element){
// var charCode = (evt.which) ? evt.which : event.keyCode
// if ((charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
// (charCode < 48 || charCode > 57))
// return false;
// return true;
// }
function isNumberKey(evt, element){
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode != 46 && charCode != 40 && charCode != 41 && charCode != 42 && charCode != 43 && charCode != 45 && charCode != 47 ) && (charCode < 48 || charCode > 57))
return false;
return true;
}
function decimalValue(evt,element){
var el = $(element).val();
if(el.length > 0){
return $(element).val(parseFloat($(element).val()).toFixed(2))
}
else{
return '0.00';
}
}
function debitAndCredit(value1,value2,el){
if(value1 > 0){
$(el).val('0.00');
}
else{
$(el).val(value2);
}
}
function currencyFormat(value){
return (value + "").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
var pcf = 0;
function pcfCompute(amount){
pcf += parseFloat(amount);
$('.fund').val(pcf);
$('.fund-label').html(currencyFormat(pcf.toFixed(2)));
}
var debitTotal = 0;
function debitCompute(amount){
debitTotal += amount;
$('.gdebit').val(debitTotal);
$('.gdebit-label').html(currencyFormat(debitTotal.toFixed(2)));
}
var creditTotal = 0;
function creditCompute(amount){
creditTotal += amount;
$('.gcredit').val(creditTotal);
$('.gcredit-label').html(currencyFormat(creditTotal.toFixed(2)));
}
////////////////// base amount //////////////////////
function base_amountFunc(el){
$(el).on('keyup',function(){
var checker = $(this).data('base_check');
var vat = $(this).data('vatpercent');
var origamt = $(this).data('baseamt');
var base_amount = $(this).val();
var compute_sub_debit = 0;
var compute_sub_credit = 0;
var withVat = 1 + parseFloat(vat) / 100;
var withAmount = parseFloat(base_amount) / parseFloat(withVat);
var withgetVat = parseFloat(base_amount) - parseFloat(withAmount);
var ptp = $(this).closest('tr').find('#ptp').val();
if(base_amount.length < 1){
return false;
}
else if(base_amount > origamt){
if(ptp == 'PO'){
$(this).val(parseFloat(origamt).toFixed(2));
}
}
$('.trmove'+checker).find('.base_tax'+checker).val(withgetVat.toFixed(2));
$('.trmove'+checker).find('.base_debit'+checker).val(withAmount.toFixed(2));
$('.trmove'+checker).find('.base_debit2'+checker).val(withAmount.toFixed(2));
$('.trmove'+checker).find('.sub_debit2').each(function(){
var valholder = $(this).val();
compute_sub_debit += parseFloat(valholder);
});
$('.trmove'+checker).find('.debit_getsubtotal').val(compute_sub_debit);
$('.trmove'+checker).find('.debit_subtotal').html(currencyFormat(compute_sub_debit.toFixed(2)));
$('#debit'+checker).html(currencyFormat(compute_sub_debit.toFixed(2)));
$('.trmove'+checker).find('.sub_credit2').each(function(){
var valholder1 = $(this).val();
compute_sub_credit += parseFloat(valholder1);
});
$('.trmove'+checker).find('.credit_getsubtotal').val(compute_sub_credit);
$('.trmove'+checker).find('.credit_subtotal').html(currencyFormat(compute_sub_credit.toFixed(2)));
$('#credit'+checker).html(currencyFormat(compute_sub_credit.toFixed(2)));
grandtotal_debit(0);
grandtotal_credit(0);
});
}
///////////////// kung e press deretso ang debit and credit field //////////
function keyAction(el){
$(el).on('keyup',function(){
var el_val = $(this).val();
if(el_val.length < 1){
return false;
}
var el1 = $(this).closest('table').find('.sub_debit2');
var el2 = $(this).closest('table');
var el3 = $(this).closest('table').find('.sub_credit2');
var el4 = $(this).closest('table');
var bb = 0;
var aa = 0;
var compute_sub_debit = 0;
var compute_sub_credit = 0;
var sub_debit = 0;
var get_grandtotal_debit = 0;
var el3_val = el3.val();
var get_grandtotal_credit = 0;
var fund = 0;
var filterid = $(this).closest('table').find('#sub-add').data('filterid');
pcf = 0;
$(this).closest('td').find('.base_debit2'+filterid).val(el_val);
compute_sub_debitFunc(el1,el2,compute_sub_debit,filterid);
get_grandtotal_debit = grandtotal_debit(bb);
pcfCompute(get_grandtotal_debit);
if(el == '.sub_debit2'){
compute_sub_creditFunc(el3,el4,compute_sub_credit,el3_val,filterid);
}
else{
compute_sub_creditFunc(el3,el4,compute_sub_credit,el_val,filterid);
}
grandtotal_credit(aa);
$('table.maintable tbody.content').find('.credit_getsubtotal').each(function(){
get_grandtotal_credit += parseFloat($(this).val());
});
fund = parseFloat(get_grandtotal_debit) - parseFloat(get_grandtotal_credit);
$('.fund').val(fund);
$('.fund-label').html(currencyFormat(fund.toFixed(2)));
$('.gcredit').val(get_grandtotal_debit);
$('.gcredit-label').html(currencyFormat(get_grandtotal_debit.toFixed(2)));
});
}
///////////////////////////////// Delete Funtion Sub-table /////////////////////
function deleteButton(){
$('#btndelete-single').click(function(e){
e.preventDefault();
var debit_val = $(this).closest('tr').find('.sub_debit2').val();
var credit_val = $(this).closest('tr').find('.sub_credit2').val();
var filterid = $(this).closest('table').find('#sub-add').data('filterid');
var debit_subtotal = $(this).closest('table').find('.debit_getsubtotal').val();
var credit_subtotal = $(this).closest('table').find('.credit_getsubtotal').val();
var debit_grandtotal = $('.gdebit').val();
var fundcash = $('.fund').val();
var grandtotal = 0;
var fundtotal = 0;
debit_subtotal = parseFloat(debit_subtotal) - parseFloat(debit_val);
grandtotal = parseFloat(debit_grandtotal) - parseFloat(debit_val);
fundtotal = parseFloat(fundcash) - parseFloat(debit_val);
credit_subtotal = parseFloat(credit_subtotal) - parseFloat(credit_val);
fundtotal = parseFloat(fundtotal) + parseFloat(credit_val);
$(this).closest('table').find('.debit_getsubtotal').val(debit_subtotal);
$(this).closest('table').find('.debit_subtotal').html(currencyFormat(debit_subtotal.toFixed(2)));
$(this).closest('table').find('.credit_getsubtotal').val(credit_subtotal);
$(this).closest('table').find('.credit_subtotal').html(currencyFormat(credit_subtotal.toFixed(2)));
$('#debit'+filterid).html(currencyFormat(debit_subtotal.toFixed(2)));
$('#credit'+filterid).html(currencyFormat(credit_subtotal.toFixed(2)));
$('.gdebit, .gcredit').val(grandtotal);
$('.gdebit-label, .gcredit-label').html(currencyFormat(grandtotal.toFixed(2)));
$('.fund').val(fundtotal);
$('.fund-label').html(currencyFormat(fundtotal.toFixed(2)));
pcf = grandtotal;
$(this).parent().parent().remove();
});
}
////////////////////// Delete Selected Partner ////////////////////////
$('table.maintable tfoot.pctotal').on('click','#btndelete-many',function(e){
e.preventDefault();
var check = $('#checkme:checked').length;
if(check >=1){
$('table.maintable tbody.content').find('#checkme:checked').each(function(){
var getval = $(this).val();
var getdebit_total = $('.trmove'+getval).find('.debit_getsubtotal').val();
var getcredit_total = $('.trmove'+getval).find('.credit_getsubtotal').val();
var totalAllDebit = $('.gdebit').val();
var totalFund = $('.fund').val();
var newtotalFund = 0;
var grandtotalAll = 0;
grandtotalAll = parseFloat(totalAllDebit) - parseFloat(getdebit_total);
totalFund = parseFloat(totalFund) - parseFloat(getdebit_total);
newtotalFund = parseFloat(totalFund) + parseFloat(getcredit_total);
$('.gdebit, .gcredit').val(grandtotalAll);
$('.gdebit-label, .gcredit-label').html(currencyFormat(grandtotalAll.toFixed(2)));
$('.fund').val(newtotalFund);
$('.fund-label').html(currencyFormat(newtotalFund.toFixed(2)));
pcf = grandtotalAll;
$('.trmove'+getval).remove();
$(this).closest('tr').remove();
});
}
});
//////////////////////// validate debit field and credit field /////////////
function strictField(el,partner_el){
$(el).on('keyup',function(e){
if(e.which != 9){
$(this).closest('tr').find(partner_el).val('0.00');
}
});
$(el).on('change',function(){
var getval = $(this).val() == '' ? 0 : $(this).val();
$(this).val(parseFloat(getval).toFixed(2));
});
}
////////////////////////// Total Credit and Debit Below ///////////////////
function grandtotal_debit(grand_debit){
$('table.maintable tbody.content').find('.debit_getsubtotal').each(function(){
grand_debit += parseFloat($(this).val());
});
$('.gdebit').val(grand_debit);
$('.gdebit-label').html(currencyFormat(grand_debit.toFixed(2)));
return grand_debit;
}
function grandtotal_credit(grand_credit){
var getdebitGrandTotal = $('.gdebit').val();
$('table.maintable tbody.content').find('.credit_getsubtotal').each(function(){
grand_credit += parseFloat($(this).val());
});
var fundDisplay = parseFloat(getdebitGrandTotal) - parseFloat(grand_credit);
$('.fund').val(fundDisplay);
$('.fund-label').html(currencyFormat(fundDisplay.toFixed(2)));
$('.gcredit').val(getdebitGrandTotal);
$('.gcredit-label').html(currencyFormat(parseFloat(getdebitGrandTotal).toFixed(2)));
return getdebitGrandTotal;
}
////////////////// Debit and credit Subtotal /////////////////
function compute_sub_debitFunc(el,el2,compute_sub_debit,debit_inline){
el.each(function(){
var valholder = $(this).val();
compute_sub_debit += parseFloat(valholder);
});
el2.find('.debit_getsubtotal').val(compute_sub_debit);
el2.find('.debit_subtotal').html(currencyFormat(compute_sub_debit.toFixed(2)));
$('#debit'+debit_inline).html(currencyFormat(compute_sub_debit.toFixed(2)));
return compute_sub_debit;
}
function compute_sub_creditFunc(el,el2,compute_sub_credit,sub_credit,debit_inline){
el.each(function(){
var valholder = $(this).val();
compute_sub_credit += parseFloat(valholder);
});
pcf -= sub_credit;
el2.find('.credit_getsubtotal').val(compute_sub_credit);
el2.find('.credit_subtotal').html(currencyFormat(compute_sub_credit.toFixed(2)));
$('#credit'+debit_inline).html(currencyFormat(compute_sub_credit.toFixed(2)));
return compute_sub_credit;
}
//////////////////////// kung na geopen ang profile
@if(isset($id))
$('form').prop('action','{{url("accounting/pettycash=")}}{{$id}}');
strictField('.sub_debit','.sub_credit');
strictField('.sub_credit','.sub_debit');
strictField('.sub_debit2','.sub_credit2');
strictField('.sub_credit2','.sub_debit2');
keyAction('.sub_debit2');
keyAction('.sub_credit2');
base_amountFunc('.amount_editable');
@if($header->status == 'Finalized' || $header->status == 'Approved' || $header->status == 'Printed' || $header->status == 'Void')
$('table.maintable thead.tofill').remove();
$('table.sub-table thead').remove();
$('.sub_debit2,.sub_credit2, .sub_account_title3,#datepicker1').attr('disabled','disabled');
$('.btndelete-single,.btndelete-many,.checkme').remove();
$('input[type="text"],select').css('background','#fff');
@endif
$('.btndelete-single').click(function(e){
e.preventDefault();
var debit_val = $(this).closest('tr').find('.sub_debit2').val();
var credit_val = $(this).closest('tr').find('.sub_credit2').val();
var filterid = $(this).closest('table').find('#sub-add').data('filterid');
var debit_subtotal = $(this).closest('table').find('.debit_getsubtotal').val();
var credit_subtotal = $(this).closest('table').find('.credit_getsubtotal').val();
var debit_grandtotal = $('.gdebit').val();
var fundcash = $('.fund').val();
var grandtotal = 0;
var fundtotal = 0;
debit_subtotal = parseFloat(debit_subtotal) - parseFloat(debit_val);
grandtotal = parseFloat(debit_grandtotal) - parseFloat(debit_val);
fundtotal = parseFloat(fundcash) - parseFloat(debit_val);
credit_subtotal = parseFloat(credit_subtotal) - parseFloat(credit_val);
fundtotal = parseFloat(fundtotal) + parseFloat(credit_val);
$(this).closest('table').find('.debit_getsubtotal').val(debit_subtotal);
$(this).closest('table').find('.debit_subtotal').html(currencyFormat(debit_subtotal.toFixed(2)));
$(this).closest('table').find('.credit_getsubtotal').val(credit_subtotal);
$(this).closest('table').find('.credit_subtotal').html(currencyFormat(credit_subtotal.toFixed(2)));
$('#debit'+filterid).html(currencyFormat(debit_subtotal.toFixed(2)));
$('#credit'+filterid).html(currencyFormat(credit_subtotal.toFixed(2)));
$('.gdebit, .gcredit').val(grandtotal);
$('.gdebit-label, .gcredit-label').html(currencyFormat(grandtotal.toFixed(2)));
$('.fund').val(fundtotal);
$('.fund-label').html(currencyFormat(fundtotal.toFixed(2)));
pcf = grandtotal;
$(this).parent().parent().remove();
});
$('#sub-add').on('click',function(e){
e.preventDefault();
var sub_accountTitle = $(this).closest('tr').find('.sub_account_title option:selected').val();
var sub_debit = $(this).closest('tr').find('.sub_debit').val();
var sub_credit = $(this).closest('tr').find('.sub_credit').val();
var compute_sub_debit = 0;
var compute_sub_credit = 0;
var filterid = $(this).data('filterid');
var count_sub_table = 0;
if(sub_accountTitle == ''){
alert('Please select account title.');
$(this).closest('tr').find('.sub_account_title').focus();
return false;
}
else if((sub_debit == '' || sub_debit == 0) && (sub_credit == '' || sub_credit == 0)){
alert('Please fill debit or credit field.');
$(this).closest('tr').find('.sub_debit').focus();
return false;
}
$(this).closest('table').find('tbody.account_body').prepend('\
<tr>\
<td width="55%">\
<input type="hidden" name="sub_header_id[]" value="'+filterid+'"/>\
<select class="form-control sub_account_title4" id="chart_p" name="post_account_title[]" tabindex="1">\
<option value="" selected="selected">--Select One--</option>\
@foreach(App\GlAccount::with('ledger')->orderBy('f1','asc')->orderBy('f2','asc')->orderBy('f3','asc')->orderBy('f4','asc')->get() as $chartchart)\
@if($chartchart->f1 > 0 && $chartchart->f2 == 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}" style="font-weight: bold;">{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 == 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 == 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@elseif($chartchart->f1 > 0 && $chartchart->f2 > 0 && $chartchart->f3 > 0 && $chartchart->f4 > 0)\
<option value="{{$chartchart->id}}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$chartchart->title}}</option>\
@endif\
@endforeach\
</select>\
</td>\
<td width="20%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_debit2 form-control" name="post_subdebit[]" placeholder="0.00" value="'+parseFloat(sub_debit).toFixed(2)+'" style="text-align: right;padding-right: 3px;background:#fff;" >\
</td>\
<td width="20%">\
<input type="text" onkeypress="return isNumberKey(event, this);" class="sub_credit2 form-control" name="post_subcredit[]" placeholder="0.00" value="'+parseFloat(sub_credit).toFixed(2)+'" style="text-align: right;padding-right: 3px;background:#fff;">\
</td>\
<td>\
<a href="" id="btndelete-single" class="btndelete-single fa fa-trash-o fa-lg" style=""></a>\
</td>\
</tr>\
');
var el = $(this).closest('table').find('.sub_debit2');
var el2 = $(this).closest('table');
var el3 = $(this).closest('table').find('.sub_credit2');
var el4 = $(this).closest('table');
var bb = 0;
var aa = 0;
strictField('.sub_debit2','.sub_credit2');
strictField('.sub_credit2','.sub_debit2');
compute_sub_debitFunc(el,el2,compute_sub_debit,filterid);
compute_sub_creditFunc(el3,el4,compute_sub_credit,sub_credit,filterid);
grandtotal_debit(bb);
pcfCompute(sub_debit);
grandtotal_credit(aa);
$(this).closest('table').find('.sub_account_title4:first option[value='+sub_accountTitle+']').prop('selected','selected');
$(this).closest('tr').find('.sub_account_title').val('');
$(this).closest('tr').find('.sub_debit').val('');
$(this).closest('tr').find('.sub_credit').val('');
count_sub_table = $(this).closest('table').find('tbody.account_body tr').length;
if(count_sub_table >=2){
$('.account_target'+filterid).html('Multiple');
}
keyAction('.sub_debit2');
keyAction('.sub_credit2');
deleteButton();
});
@endif
$('.posting-btn').on('click',function(e){
var id = $(this).data('getid');
e.preventDefault();
$.ajax({
url:'{{url("accounting/disbursements/pcf_checkposting")}}',
type:'GET',
data:{id:id},
success: function(data){
$('#postingmodal .modal-content').html(data);
prevnext();
}
});
});
function slider(){
$(document).on('click','.next',function(){
var pela = $("#text").text();
var idss = parseFloat($.trim(pela));
$.ajax({
url:'{{url("accounting/disbursements/pcf_checkposting")}}',
type:'GET',
data:{id:idss},
contentType: false,
success: function(data){
$('#postingmodal .modal-content').html(data);
prevnext();
return true;
},
timeout: 1000
});
return true;
});
}
function prevnext(){
// https://codereview.stackexchange.com/questions/132397/prev-next-buttons-for-a-circular-list
var message = [];
$('table.maintable tbody.content tr a.posting-btn').each(function(){
var post_id = $(this).data('getid');
message.push(post_id);
})
pel = document.getElementById("text"),
idx = 0,
getNext = e => pel.innerText = e.target.id == "next" ? message[idx = ++idx%message.length]
: message[idx = (message.length - (message.length - --idx)%message.length)%message.length];
document.getElementById("next").onclick = getNext;
document.getElementById("prev").onclick = getNext;
slider();
return true;
}
</script>
@include('accounting.modalfunctions.pettycash_search')
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment