Files
streamline-emr/docker/statistics/Modules/Budgets/Resources/views/budgets/show.blade.php
T
2025-03-31 03:46:05 +03:00

353 lines
24 KiB
PHP
Executable File

@extends('layouts.main')
@push('styles')
<link href="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.css') }}" rel="stylesheet"
type="text/css" />
<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" />
<style type="text/css">
td {
min-width: 130px;
}
</style>
@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')
@include('flash::message')
<div class="row">
<div class="col-md-12">
<div class="white-box">
<div class="row">
<div class='col-md-2'>
<div id="divCloneBudget" style='margin-top: 20px;'>
<a id="add_item" title='Create a new budget from this one'
href="{{ route('budgets.clone',$budget->id) }}" class='btn btn-rounded btn-success'><span
class="glyphicon glyphicon-copy"></span> Clone Budget</a>
</div>
</div>
<div class='col-md-2'>
<div id="editBudget" style='margin-top: 20px;'>
<a id="edit_item" title='Edit this Budget' href="{{ route('budgets.edit',$budget->id) }}"
class='btn btn-rounded btn-warning'><span class="glyphicon glyphicon-edit"></span> Edit
Budget</a>
</div>
</div>
<div class="col-md-2">
<div style="margin-top: 20px;">
<a href="#" onclick="download_table_as_csv('table', '<?php echo ucfirst($budget->name);?>');"
title="Download CSV of budget" class="btn btn-success btn-rounded"><span
class="glyphicon glyphicon-download"></span> Download CSV</a>
</div>
</div>
{{-- <div class="col-md-2">
<div style="margin-top: 20px;">
<a href="#" onclick="print_div('divToPrint')" title="Print to Pdf"
class="btn btn-success btn-rounded"> <span class="glyphicon glyphicon-print"></span> Web
Print</a>
</div>
</div> --}}
<div class='col-md-2'>
<div id="divPrintBudget" style='margin-top: 20px;'>
<a title='Print this Budget to pdf' target="_blank"
href="{{ route('budgets.print',$budget->id) }}" class='btn btn-rounded btn-success'><span
class="glyphicon glyphicon-print"></span> Print Budget</a>
</div>
</div>
@php
$period_months = getMonthsList();
$second_col = "Account"; $end_col = "Budget Total";
switch ($budget->period)
{
case 'months':
$period = "Months";
$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));
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod(new DateTime($budget->period_start), $interval, new DateTime(date("Y-m-d", strtotime("+". $budget->period_count ." month", $budget_start_date))));
foreach ($period as $dt) $months_data[] = $dt->format("M-Y");
$column_1 = [$second_col];
$columns = array_merge($column_1, $months_data);
array_push($columns, $end_col);
$collength = count($columns);
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];
$column_1 = [$second_col];
$columns = array_merge($column_1, $other_columns);
array_push($columns, $end_col);
$collength = count($columns);
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];
$column_1 = [$second_col];
$columns = array_merge($column_1, $years_data);
array_push($columns, $end_col);
$collength = count($columns);
break;
default:
break;
}
@endphp
<div class='col-md-4'></div>
</div>
<div id='divToPrint'>
<div class='row'>
<div class='col-md-12'>
<hr />
<div class="row text-center m-t-10">
<div class="col-md-12">
<p>
<h4>{{ __('budgets.budget_name') . ": " . $budget->name }}</h4>
</p>
<p>
<h4>{{ "Period(" .ucfirst($budget->period) . "): " . $period_range }}</h4>
</p>
</div>
</div>
</div>
</div>
<div class="row table-responsive">
<table class="table color-bordered-table success-bordered-table" id="table">
<thead>
<tr style='display:none;'>
<td colspan='<?php echo count($columns); ?>'>
Budget Name: {{ ucfirst($budget->name) .' - Period('. ucfirst($budget->period) .'): '.$period_range }}
</td>
</tr>
<tr>
@php
for ($i = 0; $i < count($columns); $i++) echo '<th>' .$columns[$i].'</th>';
$totals_budgets = $sub_accounts = $totals_budgets_colums = $income_column_totals = $expense_column_totals = $cost_of_goods_column_totals = [];
$sub_account_total= 0;
@endphp
</tr>
</thead>
<tbody>
@foreach ($options as $option)
<tr>
<td colspan='<?php echo $collength; ?>'>
<h5><strong>{{ $option['section_header'] }}</strong></h5>
</td>
</tr>
{{-- @foreach ($option['sub_accounts'] as $keyid => $sub_account) --}}
{{-- <tr>
<td class='other' data-section='{{ 'other-rows-'.$keyid }}' onclick='toggler(this);' colspan='<?php echo $collength; ?>'>
<h5>{{ get_name($keyid, 'id', 'name','chart_of_accounts') }} <span id={{ 'other-rows-'.$keyid }}>-</span></h5>
</td>
</tr> --}}
{{-- @foreach ($sub_account as $sub_account_entry)
<tr class={{ 'other-rows-'.$keyid }}>
@php
for ($i =0; $i < $collength; $i++) {
$sum=0;
for ($j=0; $j < count($sub_account_entry['account_entries']); $j++) $sum +=(int)$sub_account_entry['account_entries'][$j];
if ($i==0) echo '<td>' .$sub_account_entry['name']. '</td>' ;
else if ($i==$collength - 1) echo "<td style='background-color: #34394D !important; color: #fff !important;'>" . ugandan_shillings($sum) . "</td>" ;
else echo "<td>" .ugandan_shillings($sub_account_entry['account_entries'][$i - 1]). "</td>" ;
}
@endphp
</tr>
@endforeach --}}
{{-- Sub Account Section column Totals --}}
{{-- <tr class={{ 'other-rows-'.$keyid }} style='background-color: rgba(0, 0, 0, 0.075) !important;'>
@php
for ($i =0; $i < $collength; $i++) {
$sub_account_total_section = $sub_account_columnTotal_section=0; $keys = array_keys($option['sub_accounts']);
if ($i==0) echo '<td>'. get_name($keyid, 'id', 'name','chart_of_accounts') . ' Total</td>' ;
else if ($i==$collength - 1){ //Sub account totals
for($k=0; $k < $budget->period_count; $k++){
$columnTotal = 0;
for ($m = 0; $m < count($option['sub_accounts'][$keyid]); $m++) {
$columnTotal +=(int)($option['sub_accounts'][$keyid][$m]['account_entries'][$k]);
}
$sub_account_total_section += $columnTotal;
}
echo "<td>" .ugandan_shillings($sub_account_total_section) . "</td>" ;
} else {
for ($b=0; $b < count($option['sub_accounts'][$keyid]); $b++) {
$sub_account_columnTotal_section +=(int)($option['sub_accounts'][$keyid][$b]['account_entries'][$i - 1]);
}
echo "<td>" .ugandan_shillings($sub_account_columnTotal_section). "</td>" ;
}
}
@endphp
</tr> --}}
{{-- @endforeach
@if (!empty($option['sub_accounts']))
<tr>
<td class='other' data-section='{{ 'other-rows-'.$option['section_header'] }}' onclick='toggler(this);' colspan='<?php echo $collength; ?>'>
<h5>{{ 'Other '. $option['section_header'] }} <span id={{ 'other-rows-'.$option['section_header'] }}>-</span></h5>
</td>
</tr>
@endif --}}
@foreach ($option['entries'] as $entry )
<tr class={{ 'other-rows-'.$option['section_header'] }}>
@php
for ($i =0; $i < $collength; $i++) {
$sum=0;
for ($j=0; $j < count($entry['account_entries']); $j++) $sum +=(int)$entry['account_entries'][$j];
$total=ugandan_shillings($sum);
if ($i==0) echo '<td>' .$entry['name']. '</td>' ;
else if ($i==$collength - 1) echo "<td style='background-color: #34394D !important; color: #fff !important;'>" .$total. "</td>" ;
else echo "<td>" .ugandan_shillings($entry['account_entries'][$i - 1]). "</td>" ;
}
@endphp
</tr>
@endforeach
{{-- Other income Section column Totals --}}
{{-- @if (!empty($option['sub_accounts']))
<tr class={{ 'other-rows-'.$option['section_header'] }} style='background-color: rgba(0, 0, 0, 0.075) !important;'>
@php
for ($i =0; $i < $collength; $i++) {
$budget_total_section=0; $columnTotal_section=0;
if ($i==0) echo '<td> Other '.$option['section_header']. ' total</td>' ;
else if ($i==$collength - 1){ //Budget totals for
for($k=0; $k < $budget->period_count; $k++){
$columnTotal = 0;
for ($m = 0; $m < count($option['entries']); $m++) {
$columnTotal +=(int)($option['entries'][$m]['account_entries'][$k]);
}
$budget_total_section +=$columnTotal;
}
echo "<td>" .ugandan_shillings($budget_total_section) . "</td>" ;
}
else {
for ($b=0; $b < count($option['entries']); $b++) {
$columnTotal_section +=(int)($option['entries'][$b]['account_entries'][$i - 1]);
}
echo "<td>" .ugandan_shillings($columnTotal_section). "</td>" ;
}
}
@endphp
</tr>
@endif --}}
{{-- Operating Budget Section Totals --}}
<tr style='background-color: #34394D !important; color: #fff !important;'>
@php
for ($i =0; $i < $collength; $i++) {
$budget_total_section=0; $columnTotal_section=0;
if ($i==0) echo '<td class="font-weight-bold">'.$option['total_header']. '</td>' ;
else if ($i==$collength - 1){ //Budget totals for
for($k=0; $k < $budget->period_count; $k++){
$columnTotal = 0;
for ($m = 0; $m < count($option['entries']); $m++) {
$columnTotal +=(int)($option['entries'][$m]['account_entries'][$k]);
}
$budget_total_section +=$columnTotal;
}
array_push($totals_budgets, $budget_total_section);
echo "<td>" .ugandan_shillings($budget_total_section) . "</td>" ;
} else {
for ($b=0; $b < count($option['entries']); $b++) {
$columnTotal_section +=(int)($option['entries'][$b]['account_entries'][$i - 1]);
}
//Push to column total arrays
if($entry['type'] == 'Income') array_push($income_column_totals, $columnTotal_section);
else if($entry['type'] == 'Expense') array_push($expense_column_totals, $columnTotal_section);
else array_push($cost_of_goods_column_totals, $columnTotal_section);
echo "<td>" .ugandan_shillings($columnTotal_section). "</td>" ;
}
}
@endphp
</tr>
@endforeach
{{-- Budget Projections --}}
<tr style='background-color: #34394D !important; color: #fff !important;'>
@php
for ($i =0; $i < $collength; $i++) {
if ($i==0) echo '<td class="font-weight-bold">Projected Net Income</td>' ;
else if ($i==$collength - 1){ //Budget Totals
$overall_projection = $totals_budgets[0] - $totals_budgets[1] - $totals_budgets[2];
echo "<td>" . ugandan_shillings($overall_projection) . "</td>" ;
} else {
$columnTotal_projection=$income_column_totals[$i-1] - $expense_column_totals[$i-1] - $cost_of_goods_column_totals[$i-1];
echo "<td>".ugandan_shillings($columnTotal_projection). "</td>" ;
}
}
@endphp
</tr>
<tbody>
<tfoot>
<tr>
@php
for ($i = 0; $i < count($columns); $i++) echo '<th>' .$columns[$i].'</th>';
@endphp
</tr>
</tfoot>
</table>
</div>
</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/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 src="{{ asset('js/streamline_functions.js') }}"></script>
<script type="text/javascript">
function toggler(data){
let section = data.getAttribute('data-section'); console.log(section);
$('#'+section).text(function(_, value){return value=='-'?'+':'-'});
$('.' + section).toggle(1000);
}
</script>
@endpush