Files

309 lines
15 KiB
PHP
Executable File

@extends('layouts.main')
@push('styles')
<link href="{{ asset('/elite/bower_components/datatables/jquery.dataTables.min.css') }}" rel="stylesheet"
type="text/css" />
<link href="{{ asset('elite/tables/css/buttons.dataTables.min.css') }}" rel="stylesheet" type="text/css" />
@endpush
@section('content')
<div class="row bg-title">
<div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
<h4 class="page-title">{{ __('finance.budgets') }}</h4>
</div>
<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}"><i class="fa fa-home"></i> Home</a></li>
<li><a href="{{ route('finance') }}"><i class="fa fa-money"></i> Finance Home</a></li>
<li class="active"><i class="fa fa-file"></i> {{ __('finance.budgets') }}</li>
</ol>
</div>
</div>
@include('budgets::budgets.menu')
<div class="white-box">
{{ Form::open(['route' => 'budgets.search']) }}
<div class="row">
<div class="col-md-3">
<div class="form-group">
{{ Form::label('created_by', "Staff member") }}
{{ Form::select('created_by', $created_by, null, ['class' => 'form-control compulsory','required']) }}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::label('date_range', "Select the date") }}
<div class="input-group">
<select class="form-control compulsory required" id="dates" name="dates" required>
<option value="ALL">ALL DATES</option>
<option value="today">TODAY</option>
<option value="yesterday">YESTERDAY</option>
<option value="week">LAST 7 DAYS</option>
<option value="month">LAST 30 DAYS</option>
<option value="custom-date">CUSTOM DAY</option>
<option value="custom-range">DATE RANGE</option>
</select>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::label('active_state', "Select Active/Inactive Budgets") }}
<div class="input-group">
<select class="form-control" id="active_state" name="active_state">
<option value="active">ACTIVE</option>
<option value="inactive">INACTIVE</option>
</select>
</div>
</div>
</div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-3" style="display: none;" id="start-date-div">
<div class="form-group">
{{ Form::label('start_date', "Date From") }}
<div class="input-group">
{{ Form::text('start_date','',['class' => 'form-control compulsory',
'required','readonly','id'=>'datepicker-from']) }}
<span class="input-group-addon"><i class="icon-calender"></i></span>
</div>
</div>
</div>
<div class="col-md-3" style="display: none;" id="end-date-div">
<div class="form-group">
{{ Form::label('end_date', "Date To") }}
<div class="input-group">
{{ Form::text('end_date','',['class' => 'form-control compulsory',
'required','readonly','id'=>'datepicker-to']) }}
<span class="input-group-addon"><i class="icon-calender"></i></span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-11"></div>
<div class="col-md-1">
{{ Form::hidden('query_active', 'active') }}
{{ Form::button("Search", ['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10']) }}
</div>
</div>
{{ Form::close() }}
</div>
@include('flash::message')
<div class="row">
<div class="col-sm-12">
<div class="white-box">
<p class="text-muted m-b-30">{{ __('finance.export_data_to_copy_csv_pdf_print') }}</p>
{{-- <div class="table-responsive"> --}}
<table class="table table-striped table-responsive">
<thead>
<tr>
<th>Name</th>
<th>Budget Breakdown</th>
<th>Period</th>
<th>Income</th>
<th>Cost of Goods</th>
<th>Expense</th>
<th>Projected Net Income</th>
<th>Created By</th>
<th>Date Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@if(!empty($budgets))
@foreach($budgets as $budget)
@php
$period = "N/A";
$period_count = $budget->period_count;
$period_start = $budget->period_start;
$period_range = "N/A";
$arr3 = json_decode($budget->entries, true);
$income =[]; $expense=[]; $cost_of_goods =[];
$income_total=0;$expense_total=0;$cost_of_goods_total = 0;
foreach ($arr3 as $rkey => $resource){
if ($resource['type'] == 'Income') $income[] = $resource;
else if ($resource['type'] == 'Cost Of Goods') $cost_of_goods[] = $resource;
else $expense[] = $resource;
}
if(!empty($income)) {
for($counter =0; $counter < count($income); $counter++ ) if(!empty($income[$counter]['account_entries'])) $income_total +=array_sum($income[$counter]['account_entries']);
}
if(!empty($expense)) {
for($counter =0; $counter < count($expense); $counter++ ) if(!empty($expense[$counter]['account_entries'])) $expense_total +=array_sum($expense[$counter]['account_entries']);
}
if(!empty($cost_of_goods)) {
for($counter =0; $counter < count($cost_of_goods); $counter++ ) if(!empty($cost_of_goods[$counter]['account_entries'])) $cost_of_goods_total +=array_sum($cost_of_goods[$counter]['account_entries']);
}
$projection_total = $income_total - $expense_total - $cost_of_goods_total;
switch ($budget->period) {
case 'months':
$period = "Months";
$period_months = getMonthsList();
$budget_start_date = strtotime($budget->period_start);//y-m-d
$budget_end_date = date("Y-m-d", strtotime("+". $budget->period_count - 1 ." month", $budget_start_date));
$period_range = date("M-Y", $budget_start_date) . " to " . date("M-Y", strtotime($budget_end_date));
break;
case 'quarters':
$period = "Quarters";
$other_columns =[];$quarter_start_dates =['-01-01', '-04-01', '-07-01', '-10-01']; //m-d
$budget_start_date = $budget->period_start;//y-m-d
$budget_end_date = date("Y-m-d", strtotime("+". ($budget->period_count-1) * 3 ." month", strtotime('-1 day', strtotime($budget_start_date))));
$quarters_data = get_quarters($budget_start_date, $budget_end_date);
for($y =0; $y < count($quarters_data); $y++) $other_columns[] = $quarters_data[$y]->period;
$period_range = $other_columns[0] . " to " . $other_columns[count($other_columns)-1];
break;
case 'years':
$period = "Years";
$year=date('Y', strtotime($budget->period_start));
$sec = substr($year, -2);
$years_data = [$year.'/'. ++$sec];
for ($i = 1; $i <$budget->period_count; $i++) array_push($years_data, $year + $i .'/'. ++$sec);
$period_range = $years_data[0] . " to " . $years_data[count($years_data)-1];
break;
default:
break;
}
@endphp
<tr>
<td>{{ $budget->name }}</td>
<td>{{ $period }}</td>
<td>{{ $period_range }}</td>
<td>{{ ugandan_shillings($income_total) }}</td>
<td>{{ ugandan_shillings($cost_of_goods_total) }}</td>
<td>{{ ugandan_shillings($expense_total) }}</td>
<td>{{ ugandan_shillings($projection_total) }}</td>
{{-- <td>{{ get_full_name($budget->created_by, 'id', 'first_name', 'last_name', 'users') }}</td> --}}
<td>{{ $budget->user_by }}</td>
<td>{{ streamline_date_time_short($budget->created_at) }}</td>
<td>
@if( Auth::user()->can('budget-view'))
<a class="btn btn-sm btn-rounded btn-info"
href="{{ route('budgets.show',$budget->id) }}"><i class="fa fa-info-circle"></i> {{
__('budgets.view') }}</a>
@endif
@if( Auth::user()->can('budget-edit'))
<a class="btn btn-sm btn-warning btn-rounded"
href="{{ route('budgets.edit',$budget->id) }}"><i class="fa fa-pencil"></i> {{
__('budgets.edit') }}</a>
@endif
@if( Auth::user()->can('budget-delete'))
{{ Form::model($budget->id ,['method' => 'DELETE', 'route' => ['budgets.destroy',
$budget->id], 'style'=>'display:inline']) }}
<button type="submit" class="btn btn-sm btn-rounded btn-danger"
onclick="return confirm('<?php echo __('budgets.are_you_sure') ?>')"><i
class="fa fa-trash"></i> {{ __('budgets.delete') }}</button>
{{ Form::close() }}
@endif
</td>
</tr>
@endforeach
@endif
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Budget Breakdown</th>
<th>Period</th>
<th>Income</th>
<th>Cost of Goods</th>
<th>Expense</th>
<th>Projected Net Income</th>
<th>Created By</th>
<th>Date Created</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
{{-- </div> --}}
</div>
</div>
</div>
@endsection
@push('scripts')
<script src="{{ asset('elite/bower_components/datatables/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/dataTables.buttons.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.flash.min.js') }}"></script>
{{-- <script src="{{ asset('elite/tables/js/jszip.min.js') }}"></script> --}}
<script src="{{ asset('elite/tables/js/pdfmake.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/vfs_fonts.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.html5.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.print.min.js') }}"></script>
<script>
$('.table').DataTable({
responsive: true,
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
pageLength: 5,
order: [],
});
function show(id) {
if (document.getElementById(id).style.display === 'none') {
document.getElementById(id).style.display = '';
}
}
function hide(id) {
document.getElementById(id).style.display = 'none';
}
</script>
<script src="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.js') }}"></script>
<script type="text/javascript">
$('#datepicker-from, #datepicker-to').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd-mm-yyyy',
});
$('#dates').change(function() {
var val = $(this).val();
switch (val) {
case 'custom-date':
$('#end-date-div').hide();
$('#start-date-div').show();
break;
case 'custom-range':
$('#end-date-div').show();
$('#start-date-div').show();
break;
default:
$('#end-date-div').hide();
$('#start-date-div').hide();
break;
}
});
function clone_budget(data) {
var cell = data.getAttribute('data-href').split("_");
if (confirm(`Are you sure you want to clone ${cell[1]}?`) == true)
window.location.href = cell[2];
}
</script>
@endpush