@extends('layouts.print')

@section('content')
<style>
    .report-capital.layout-print .table tr td {
        font-size: 16px !important;
    }
    @page {
		size:landscape !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 centers">
                                    @php
                                        $from   = date('d-m-Y',strtotime($from));
                                        $to     = date('d-m-Y',strtotime($to));
                                    @endphp
                                    <h3>Income Statement Report</h3>
                                    <br>
                                    <h3><small>{{$from}} to {{$to}}</small></h3>
                                </div>
                                <div class="clear"></div>
                                <div class="border-bottom"></div>
                                <div class="table">
                                    <table>
                                        <thead>
                                            <tr>
                                                <th>No</th>
                                                <th>Account Name</th>
                                                <th>Total</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                $index          = 0;
                                                $total_income   = 0;
                                                $total_expense  = 0;
                                                $net_income     = 0;
                                            ?>
                                            @if(count($journal_income) > 0)
                                                <tr>
                                                    <th colspan="3">Income</th>
                                                </tr>
                                                @foreach($journal_income as $key => $ji)
                                                    @php
                                                        $total_income += $ji->balance;
                                                        if($ji->balance < 0)
                                                        {
                                                            $ji->balance="(".abs($ji->balance).")";
                                                        }
                                                        if($total_income<0)
                                                        {
                                                            $total_income="(".abs($total_income).")";
                                                        }

                                                        $index++
                                                    @endphp
                                                    <tr>
                                                        <td>{{$index}}</td>
                                                        <td>{{$ji->id}} {{$ji->acc_name}}</td>
                                                        <td>{{$ji->balance}}</td>
                                                    </tr>
                                                @endforeach
                                                <tr class="total-section">
                                                    <th colspan="2">Total Income</th>
                                                    <th>{{$total_income}}</th>
                                                </tr>
                                                <tr class="total-section">
                                                    <th colspan="3">Expense</th>
                                                </tr>
                                            @endif
                                            @if(count($journal_expense) > 0)
                                                @foreach($journal_expense as $key => $je)
                                                    @php
                                                        $balance = abs($je->balance);
                                                        $total_expense +=$balance;
                                                        $index++
                                                    @endphp
                                                    <tr>
                                                        <td>{{$index}}</td>
                                                        <td>{{$je->id}} {{$je->acc_name}}</td>
                                                        <td>{{$je->balance}}</td>
                                                    </tr>
                                                @endforeach
                                                <tr class="total-section">
                                                    <th colspan="2">Total Expense</th>
                                                    <th>{{$total_expense}}</th>
                                                </tr>
                                            @endif
                                            @php
                                                $net_income = $total_income-$total_expense;
                                            @endphp
                                            @if(!empty($net_income))
                                                <tr class="total-section">
                                                    <th colspan="2">Net Profit/Loss</th>
                                                    <th>{{$net_income}}</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;
        }
    }
    .total-section{
        border-top: 1px solid black !important;
    }
</style>
@endsection
