@extends('layouts.print')

@section('content')
<?php
	$total_asset 		= 0;
	$total_liability 	= 0;
	$total_equity 		= 0;
?>
<style>
    .report-capital.layout-print .table tr td {
        font-size: 16px !important;
    }
</style>
<div class="main-content-wrapper">
	<div class="main-box">
		<div class="main-content">
			<div class="container">
				<div class="page">
					<div class="row">
						<div class="report-capital layout-print">
							<div class="header">
								<div class="logo">
                                    <img src="{{asset('assets/images/logo.png')}}" alt="" width="200px">
                                </div>
                                <div style="text-align: center;font-family: 'Khmer OS Muol Light'">
                                    <h2>{{$branch->branch_kh}}</h2>
									<h2>{{$branch->branch_en}}</h2>
                                </div>
								<div class="title">
									<h3>Balance Sheet</h3>
								</div>
								<div class="clear"></div>
								<div class="border-bottom"></div>
								<div class="table">
									<table>
										<thead>
											<tr>
												<th>Account #</th>
												<th>Account Name</th>
												<th>Debit</th>
												<th>Credit</th>
											</tr>
										</thead>
										<tbody>
											@foreach($assets as $key => $asset)
												<?php
													$total_each_asset = 0;
												?>
												@if(count($account_assets) > 0)
													@foreach($account_assets as $key => $account)
														@if($asset->id == $account->acctype)
															<?php
															$total_each_asset += $account->balance;
															$balance = $account->balance;
															if($balance<0){
																$balance = "(".abs($balance).")";
															}
															?>
															<tr>
																<td>{{$account->id}}</td>
																<td>{{$account->acc_name}}</td>
																<td>{{$balance}}</td>
																<td></td>
															</tr>
														@endif
													@endforeach
													<tr>
														<th colspan="2">Total {{$asset->acc_name}}</th>
														<th>{{$total_each_asset}}</th>
														<th></th>
													</tr>
													<?php
													$total_asset+=$total_each_asset;
													?>
												@endif
											@endforeach
											@if(count($count_asset) > 0)
												<tr>
													<th colspan="2">Total Asset</th>
													<th>{{$total_asset}}</th>
													<th></th>
												</tr>
											@endif
											@foreach($liabilities as $liability)
											<?php
												$total_each_liability = 0;
											?>
											@if(count($account_liabilities) > 0)
												@foreach($account_liabilities as $account)
													@if($account->acctype == $liability->id)
														<?php
														$balance = $account->balance;
														$total_each_liability+=$balance;
														if($balance>0){
															$balance = "(".$balance.")";
														}else{
															$balance = abs($balance);
														}
														?>
														<tr>
															<td>{{$account->id}}</td>
															<td>{{$account->acc_name}}</td>
															<td></td>
															<td>{{$balance}}</td>
														</tr>
													@endif
												@endforeach
												<?php
												$total_each_liability = abs($total_each_liability);
												?>
											<tr>
												<th colspan="2">Total {{$liability->acc_name}}</th>
												<th></th>
												<th>{{$total_each_liability}}</th>
											</tr>
											<?php
												$total_liability +=$total_each_liability;
											?>
											@endif
											@endforeach
											@if(count($count_liability) > 0)
												<tr>
													<th colspan="2">Total Liability</th>
													<th></th>
													<th>{{$total_liability}}</th>
												</tr>
											@endif
											@foreach($equities as $key => $equity)
												@if(count($account_equities) > 0)
													@foreach($account_equities as $account)
														@if($account->acctype == $equity->id)
															<?php
															$balance = $account->balance;
															$total_equity +=$balance;
															if($balance>0){
																$balance = "(".$balance.")";
															}else{
																$balance = abs($balance);
															}
															?>
															<tr>
																<td>{{$account->id}}</td>
																<td>{{$account->acc_name}}</td>
																<td></td>
																<td>{{$balance}}</td>
															</tr>
														@endif
													@endforeach
												@endif
											@endforeach
											<?php
												$income_amount 	= $income->balance;
												$expense_amount = $expense->balance;
												$net_income 	= abs($income_amount)-abs($expense_amount);
												$total_equity = abs($total_equity)+$net_income;
												$liability_equity = $total_liability+$total_equity;
											?>
											@if(!empty($net_income))
												<tr>
													<td>31004</td>
													<td>Retained Earnings-current period</td>
													<td></td>
													<td>{{$net_income}}</td>
												</tr>
											@endif
											@if(!empty($total_equity))
												<tr>
													<th colspan="2"></th>
													<th></th>
													<th>{{$total_equity}}</th>
												</tr>
											@endif
											@if(!empty($liability_equity))
												<tr>
													<th colspan="2">Total Liability and Equity</th>
													<th></th>
													<th>{{$liability_equity}}</th>
												</tr>
											@endif
										</tbody>
										<tfoot>
											
										</tfoot>
									</table>
									<div class="make-date">
										<p>ធ្វើនៅ​ <strong>ភ្នំពេញ</strong> ថ្ងៃទី <strong>{{\Globals::date_khmers(date('d-m-Y'))}}</strong></p>
									</div>
									<div class="row">
										<div class="col-lg-12 col-sm-12 col-xs-12 tt">
											<div class="col-lg-4 col-sm-4 col-xs-4">
												<p>អ្នកធ្វើបញ្ជី</p>
												<p>ថាយ ម៉ាណែល</p>
											</div>
											<div class="col-lg-4 col-sm-4 col-xs-4">
												<p>អ្នកពិនិត្យ</p>
												<p>_________________</p>
											</div>
											<div class="col-lg-4 col-sm-4 col-xs-4">
												<p>ឯកភាព</p>
												<p>ស៊ីន មុំ យ៉ែន សុខលីន</p>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<style>
	.container {
		width: 420mm !important;
		margin-top: 10px;
	}

	@media print {

		html,
		body {
			width: 450mm !important;
			margin: 0mm 0 0 0 !important;
			background-color: #FFFFFF;
		}

	}
	@page {
		size:landscape !important;
	}
</style>
@endsection
