@extends('backend.layouts.master')

@section('title', 'Profit Loass Report')

@push('css')
<!-- bootstrap-datetimepicker -->
	<link rel="stylesheet" href="{{ asset('myfile/backend/assets/datepicker/zebra_datepicker.min.css') }}" type="text/css">
	<link rel="stylesheet" href="{{ asset('myfile/backend/assets/datepicker/examples.css') }}" type="text/css">
	<style>
		#search-btn{
			margin-top:24px;
		}
	</style>
@endpush
@section('content')
	<div class="right_col" role="main">
		<div class="x_panel">
			<div class="x_title">
				<h2 class="widget-title">Profit Loass Report</h2>
				<ul class="nav navbar-right panel_toolbox">
					<li><a class="collapse-link" onclick="printDiv('printableArea')" ><i class="fa fa-print"></i></a></li>
					<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
					<li class="dropdown">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
						<ul class="dropdown-menu" role="menu">
							<li><a href="#">Settings 1</a>
							</li>
							<li><a href="#">Settings 2</a>
							</li>
						</ul>
					</li>
					<li><a class="close-link"><i class="fa fa-close"></i></a>
					</li>
				</ul>
				<div class="clearfix"></div>
			</div>
			<div class="x_content" >
			    <div class="row">
			        <form action="{{route('ledger.profit_loss')}}" method="Post" >
			            {{ method_field('Get') }}
			            <div class="col-sm-2"></div>
			            <div class="col-sm-2">
						<div class="form-group">
							<label>From</label>
							<input id="datepicker-range-start" type="text" name="from_date"  class="form-control" data-zdp_readonly_element="false" value="{{date('d-m-Y',strtotime($from))}}">
						</div>
    					</div>
    					<div class="col-sm-2">
    						<div class="form-group">
    							<label>To</label>
    							<input id="datepicker-range-end" type="text" name="to_date"  class="form-control" data-zdp_readonly_element="false" value="{{date('d-m-Y',strtotime($to))}}">
    						</div>
    					</div>
		            	<div class="col-sm-1">
							<div class="form-group">
								<button class="btn btn-primary btn-xs" id="search-btn">
									<i class="ace-icon fa fa-search fa-2x icon-only"></i>
								</button>
							</div>
						</div>
						<div class="col-sm-1">
							<a href="#" id="search-btn" class="btn btn-primary btn-xs" onclick="printDiv('printableArea')">
								<i class="ace-icon fa fa-print fa-2x icon-only"></i>
							</a>
						</div>
				    </form>
			    </div>
			    <hr/>
				<div class="row" id="printableArea">
					<div class="col-xs-12 col-sm-12">
						<div class="row">
							<div class="col-xs-1"></div>
							<div class="col-xs-1">
								<img src="{{ asset('storage/about/'.about()->logo)}}" class="img-responsive img-thumbnail" alt="logo" width="85px" height="75px" >
							</div>
							<div class="col-xs-8">
								<div class="text-center">
									<h4>{{about()->english_name}}</h4>
									<p>Phone:  {{about()->phone}}, Email: {{about()->email}}</p>
									<p>Address: {{about()->address }} </p>
									<h4>Profit Loss Report</h4>
									<p>From:{{date('d-m-Y',strtotime($from)) }} - {{date('d-m-Y',strtotime($to)) }}</p>
								</div>
							</div>
							<div class="col-xs-2"></div>
						</div>
						<hr/>
						<table class="table table-bordered" >
							<thead style="text-align:center">
							    <tr class="bg-primary">
							        <th></th>
							        <th colspan="2">Income</th>
							        <th colspan="2">Expense</th>
							    </tr>
								<tr>
									<th>SL</th>
									<th>Description</th>
									<th>Amount</th>
									<th>Description</th>
									<th>Amount</th>
								</tr>
							</thead>
							<tbody>
								@php
									$total = 0;
									$ex_total = 0;
									$key = 1;
								@endphp
							@foreach($new as $sm)
								@php
									$total = $total + $sm['income'];
									$ex_total = $ex_total + $sm['expense'];
								@endphp
								<tr>
									<td>{{ $key++}}</td>
									<th>{{ $sm['income_description'] }}</th>
									<td>{{ $sm['income'] != '' ? $sm['income'] : 0}}</td>
									<th>{{ $sm['expense_description'] }}</th>
									<td>{{ $sm['expense'] != '' ? $sm['expense'] : 0}}</td>
								</tr>
							@endforeach
								<tr>
									<th colspan="2"></th>
									<th>Total  = </th>
									<th>{{$total}}</th>
									<th>{{$ex_total}}</th>
								</tr>
							</tbody>
						</table>
						<table class="table table-bordered table-condensed" style="max-width: 30%;float: right;">
							<tbody>
								<tr>
									<th>Total Receipt:</th>
									<th>{{ $total}}</th>
								</tr>
								<tr>
									<th>Total Payment:</th>
									<th>{{ $ex_total}}</th>
								</tr>
								<tr>
									<th>Last Day Balance:</th>
									<th></th>
								</tr>
								<tr>
									<th>Cash In Hand:</th>
									<th>{{ $total -  $ex_total}}</th>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
@endsection

@push('js')

<!-- Jquery Plugin For Date Calender-->
<script type="text/javascript" src="{{ asset('myfile/backend/assets/datepicker/zebra_datepicker.src.js') }}"></script>
<script type="text/javascript" src="{{ asset('myfile/backend/assets/datepicker/examples.js') }}"></script>
<script>
  $(document).ready(function() 
	{
		// select2 section

	});
  function printDiv(divName) {
		 var printContents = document.getElementById(divName).innerHTML;
		 var originalContents = document.body.innerHTML;
		 document.body.innerHTML = printContents;
		 window.print();
		 document.body.innerHTML = originalContents;
		}
</script>
@endpush
    
 