@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="logo">
									<img src="{{asset('assets/images/resize')}}/{{$branch->branch_img}}" alt="" width="200px">
								</div>
								<div class="title">
									<h2>{{$branch->branch_kh}}</h2>
									<h2>{{$branch->branch_en}}</h2>
									<h3>របាយការណ៏ដកកម្រៃជើងសារពីក្រុមហ៊ុន {{$branch_name->branch_kh}}</h3>
								</div>
								<div class="clear"></div>
								<div class="border-bottom"></div>
								<div class="table">
									<table>
										<thead>
											<tr>
												<th>No</th>
												<th>Date Contract</th>
												<th>Project Name</th>
												<th>Client Name</th>
												<th>Item Name</th>
												<th>Item Price</th>
												<th>Commission</th>
												<th>Commission Discount</th>
												<th>Total Commission</th>
												<th>Commission Receive</th>
												<th>Commission Balance</th>
											</tr>
										</thead>
										<tbody>
											<?php

											use App\SaleStockModel;

											$sale_amount 			= 0;
											$commission_amount 		= 0;
											$discount_commis 		= 0;
											$commission_received 	= 0;
											$commission_balance 	= 0;
											?>
											@foreach($commission as $key => $value)
											<?php
											$itemhouse 			= SaleStockModel::find($value->id)->itemhouse();
											$sale_amount 		+= $value->sale_amount;
											$commission_amount 	+= $value->commission_amount;
											$discount_commis 	+= $value->discount_commis;
											$commission_received+= $value->commission_received;
											$commission_balance += $value->commission_balance;
											?>
											<tr>
												<td>{{$key+1}}</td>
												<td>{{date('d-m-Y',strtotime($value->created_at))}}</td>
												<td>{{$value->project_name}}</td>
												<td>{{$value->client_fullname}}</td>
												<td>{{$itemhouse}}</td>
												<td class="right">$ {{number_format($value->sale_amount,2)}}</td>
												<td class="right">$ {{number_format($value->commission_amount,2)}}</td>
												<td class="right">$ {{number_format($value->discount_commis,2)}}</td>
												<td class="right">$ {{number_format($value->commission_amount-$value->discount_commis,2)}}</td>
												<td class="right">$ {{number_format($value->commission_received,2)}}</td>
												<td class="right">$ {{number_format($value->commission_balance,2)}}</td>
											</tr>
											@endforeach()
										</tbody>
										<tfoot>
											<tr>
												<th colspan="5">Total</th>
												<th class="right">$ {{number_format($sale_amount,2)}}</th>
												<th class="right">$ {{number_format($commission_amount,2)}}</th>
												<th class="right">$ {{number_format($discount_commis,2)}}</th>
												<th class="right">$ {{number_format($commission_received,2)}}</th>
												<th class="right">$ {{number_format($commission_received,2)}}</th>
												<th class="right">$ {{number_format($commission_balance,2)}}</th>
											</tr>
										</tfoot>
									</table>
									<div class="make-date">
										<p>ធ្វើនៅ​ <strong>ភ្នំពេញ</strong> ថ្ងៃទី <strong>{{\Globals::date_khmers(date('Y-m-d'))}}</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: 330mm !important;
		margin-top: 10px;
	}

	@media print {

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

	}
</style>
@endsection