@extends('layouts.report-print')
@section('css')
	<style type="text/css">
	/* size landscape for landscape paper */
		@page{
			size: landscape;
		}
	</style>
@endsection
@section('content')
	<div class="container-print">
		<div class="row">
			<div class="col-md-12">
				<div class="UpperTitle"><img src="{{asset('assets/images/resize')}}/{{$branch->branch_img}}" alt="Logo">
					<div class="title">
						<h2 class="com-name">{{$branch->branch_kh}}</h2>
						<h2>{{$branch->branch_en}}</h2>
						<h3>Report Purchase Order</h3>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<hr>
			</div>
		</div>
		<div class="row">
			@if(!empty($boq))
				@php
					$bo =  DB::table('nso007_boq_construction')->select(DB::raw("CONCAT(nso007_boq_construction.title,'( prepared by ',nso007_boq_construction.prepared_by,' )') as boq_title"),"id")->where('id', $boq)->first();	
				@endphp
				<div class="col-xs-4">BOQ : {{isset($bo->boq_title) ? $bo->boq_title : ''}}</div>
			@endif
			@if(!empty($project))
				@php
					$po = DB::table('nso007_project_stock')->select('project_name')->where('id', $project)->first();
				@endphp
				<div class="col-xs-4">Project Name : {{isset($po->project_name) ? $po->project_name : ''}}</div>
			@endif
			@if(!empty($product))
				@php
					$pro = DB::table('nso007_construction_product')->select('name')->where('id', $product)->first();
				@endphp
				<div class="col-xs-4">Product Name: {{isset($pro->name) ? $pro->name : ''}}</div>
			@endif
			@if(!empty($supplier))
				@php
					$su = DB::table('nso007_construction_suppliers')->select('name', 'phone')->where('id', $supplier)->first();
				@endphp
				<div class="col-xs-4">Supplier Name : {{isset($su->name) ? $su->name : ''}}</div>
				<div class="col-xs-4">Supplier Phone : {{isset($su->phone) ? $su->phone : ''}}</div>
			@endif
		</div>
		<div class="row">
			<div class="col-md-12">
				<table class="table table-print" width="100%">
					<tbody>
						<tr>
							<th>No</th>
							<th>Date</th>
							@if(empty($boq))
								<th>BOQ</th>
							@endif
							@if(empty($project))
								<th>Project Name</th>
							@endif
							@if(empty($supplier))
								<th>Supplier Name</th>
								<th>Supplier Phone</th>
							@endif
							<th>Request By</th>
							<th>Position</th>
							<th>Phone</th>
							@if(empty($product))
								<th>Product Name</th>
							@endif
							<th>Unit Name</th>
							<th>Category</th>
							<th>Sub Category</th>
							<th>Qty BOQ</th>
							<th>Qty P.O</th>
							<th>Qty Balance</th>
							<th>Unit Price</th>
							<th>Total Price</th>
							<th>Purpose and Location</th>
							{{-- <th>Status</th> --}}
						</tr>
						<?php $total_price = 0;$sum_total = 0; ?>
						@foreach($data as $key => $value)
						<?php $total_price += $value->product_price;$sum_total = $value->product_price*$value->product_qty; $balance = $value->qty_used_all_amount_of_house - $value->product_qty ;?>
						<tr>
							<td>{{ $key+1 }}</td>
							<td>{{date("d-m-Y",strtotime($value->date)) }}</td>
							@if(empty($boq))
								<td>{{ $value->boq_title }}</td>
							@endif
							@if(empty($project))
								<td>{{ $value->project_name }}</td>
							@endif
							@if(empty($supplier))
								<td>{{ $value->supplier_name }}</td>
								<td>{{ $value->supplier_phone }}</td>
							@endif
							<td>{{ $value->request_by }}</td>
							<td>{{ $value->stock_position }}</td>
							<td>{{ $value->phone_number }}</td>
							@if(empty($product))
								<td>{{ $value->product_name }}</td>
							@endif
							<td>{{ $value->unit_name }}</td>
							<td>{{ $value->category_name }}</td>
							<td>{{ $value->sub_category }}</td>
							<td>{{ $value->qty_used_all_amount_of_house }}</td>
							<td>{{ $value->product_qty }}</td>
							<td>
								<?php 
									if($balance==0) echo 0; 
									else if($balance<0) echo "";
									else if(empty($balance)) echo "";
									else echo $balance;
								?>
							</td>
							<td>${{ number_format($value->product_price,2) }}</td>
							<td>${{ number_format($value->product_price*$value->product_qty,2) }}</td>
							<td>{{ $value->purpose_and_location }}</td>
							
						</tr>
						@endforeach()
						<tr class="tr-right">
							@php
								$total 			= 0;
								$boq_total 		= 0;
								$project_total 	= 0;
								$supplier_total = 0;
								$product_total 	= 0;

								if(!empty($boq)){
									$boq_total = 1;
								}
								if(!empty($project)){
									$project_total = 1;
								}
								if(!empty($supplier)){
									$supplier_total = 2;
								}
								if(!empty($product)){
									$product_total = 1;
								}
								$total = $boq_total + $project_total + $supplier_total + $product_total;
								
							@endphp
							<td colspan="{{16-$total}}" class="text-right">Total :</td>
							<td>${{number_format($total_price,2)}}</td>
							<td>${{ number_format($sum_total,2) }}</td>
							<td></td>
							{{-- <td></td> --}}
						</tr>
					</tbody>
				</table>
			</div>	
		</div>
		<div class="row">
			<div class="col-md-12">
				<table width="100%"​ class="tb-sign">
					<tr align="right">
						<td>
							<p>ធ្វើនៅ​ <strong>ភ្នំពេញ</strong> ថ្ងៃទី <strong>{{\Globals::date_khmers(date('Y-m-d'))}}</strong></p>
							<p style="padding-bottom: 80px;padding-right:40px">ហត្ថលេខា</p>
							<p>______________________</p>
						</td>
					</tr>	
				</table>
			</div>
		</div>
	</div>
@endsection



