@extends('layouts.print')

@section('content')
<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="title">
									<h3>{{$report}}</h3>
									<br>
									<h2><small>{{date('d-m-Y',strtotime($from))}} to {{date('d-m-Y',strtotime($to))}}</small></h2>
								</div>
								<div class="clear"></div>
								<div class="border-bottom"></div>
								<div class="table">
									<table>
										<thead>
											<tr>
												<th>Account Name</th>
												<th>Debit</th>
												<th>Credit</th>
											</tr>
										</thead>
										<tbody>
											@php
												$debit = 0;
												$credit = 0;
											@endphp
											@foreach($account_type as $key => $type)
											@if(count($trial_balance) > 0)
												<tr>
													<th colspan="3">{{$type->acc_name}}</th>
												</tr>
												@foreach($trial_balance as $index => $trial)
													@if($trial->acctype == $type->id)
														<?php
														$id = $trial->id;
														$id = (string) $id;
														$code = $id[0];
														$balance = 0;
														?>
														@if($code == 1 || $code == 5)
															@php
																$balance = $trial->debit - $trial->credit;
																$debit +=$balance;
																if($balance < 0)
																{
																	$balance = "(".abs($balance).")";
																}
															@endphp
															<tr>
																<td>{{$trial->acc_name}}</td>
																<td>{{$balance}}</td>
																<td></td>
															</tr>
														@else
															@php
																$balance = $trial->credit - $trial->debit;
																$credit +=$balance;
																if($balance < 0)
																{
																	$balance = "(".abs($balance).")";
																}
															@endphp
															<tr>
																<td>{{$trial->acc_name}}</td>
																<td></td>
																<td>{{$balance}}</td>
															</tr>
														@endif
													@endif
												@endforeach
											@endif
											@endforeach
										</tbody>
										@php
											if($debit < 0)
                                            {
                                                $debit = "(".abs($debit).")";
                                            }
                                            if($credit < 0)
                                            {
                                                $credit = "(".abs($credit).")";
                                            }
										@endphp
										@if(count($trial_balance) > 0)
											<tfoot>
											<tr>
												<th>Total</th>
												<th>{{$debit}}</th>
												<th>{{$credit}}</th>
											</tr>
											</tfoot>
										@endif
									</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>
                                                <br>
                                                <br>
												<p>_________________</p>
											</div>
											<div class="col-lg-4 col-sm-4 col-xs-4">
												<p>អ្នកពិនិត្យ</p>
                                                <br>
                                                <br>
												<p>_________________</p>
											</div>
											<div class="col-lg-4 col-sm-4 col-xs-4">
												<p>ឯកភាព</p>
                                                <br>
                                                <br>
												<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;
		}

	}
</style>
@endsection
