@extends('backend.layouts.master')

@section('title', 'Cash Closing')

@push('css')
	<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 type="text/css">
		label.col-sm-4.control-label.no-padding-right {
		    text-align: left;
		}
		#search-btn{
			margin-top:24px;
		}
	</style>
@endpush

@section('content')
	<div class="right_col" role="main">
		<div class="clearfix"></div>
            @if(Session::has('success'))
                <div class="alert alert-success">
                    {{ Session::get('success') }}
                </div>
            @endif
            @if(Session::has('error'))
                <div class="alert alert-danger">
                    {{ Session::get('error') }}
                </div>
            @endif
		<div class="row">
			<div class="col-sm-7">
				<div class="x_panel">
					<div class="x_title">
						<h2 class="widget-title">Cash Closing Balance</h2>
						<ul class="nav navbar-right panel_toolbox">
							<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="row">
						<div class="col-xs-12 col-sm-12">
							<form action="{{route('cash.closing_save')}}" method="post" class="form-horizontal" role="form" >
								{{ csrf_field() }}
								<input type="hidden" name="status" value="Credit">
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1">Closing Date <span class="red">*</span></label>
									<div class="col-sm-8">
										<input id="" type="text" name="closing_date"  class="form-control input-sm" readonly="" value="{{ date('d-m-Y',strtotime($closing_date))}}" placeholder="dd-mm-yyyy">
										<p class="error-sms">{{ $errors->first('closing_date') }}</p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1-1">Last Day Closing <span class="red">*</span></label>
									<div class="col-sm-8">
										<input type="text" id="form-field-1-1" name="lastday_balance" value="{{old('lastday_balance') ?? $lastday_cash != '' ? $lastday_cash->balance : '0' }}" readonly placeholder="Last Day Closing Balance" class="form-control input-sm">
										<p class="error-sms">{{ $errors->first('lastday_balance') }}</p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1-1">Total Receipt <span class="red">*</span></label>
									<div class="col-sm-8">
										<input type="text" id="form-field-1-1" name="receipt" value="{{old('receipt') ?? $receipt}}" readonly placeholder="Today's Total Receipt" class="form-control input-sm">
										<p class="error-sms">{{ $errors->first('receipt') }}</p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1-1">Total Payment <span class="red">*</span></label>
									<div class="col-sm-8">
										<input type="text" id="form-field-1-1" name="payment" value="{{old('payment') ?? $payment }}" readonly placeholder="Today's Total Payment" class="form-control input-sm">
										<p class="error-sms">{{ $errors->first('payment') }}</p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1-1">Balance </label>
									<div class="col-sm-8">
										<input type="text" id="form-field-1-1" name="current_balance" value="{{old('current_balance') ?? ($lastday_cash != '' ? $lastday_cash->balance : '0') + ($receipt - $payment)}}" readonly placeholder="Now Balance" class="form-control input-sm">
										<p class="error-sms">{{ $errors->first('current_balance') }}</p>
									</div>
								</div>
								<div class="form-group">
									<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-5">
									<button class="btn btn-warning" type="reset">Reset</button>
									<button type="submit" class="btn btn-primary">Save</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			<div class="col-sm-5">
				<div class="x_panel">
					<div class="x_title">
						<h2 class="widget-title">Search Closing</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">
						<form action="{{route('cash.closing_index')}}" method="Get" class="form-horizontal" role="form" >
							{{csrf_field()}}
							<input type="hidden" name="status" value="Search">
							<div class="form-group">
								<label class="col-sm-4 control-label no-padding-right" for="form-field-1">Closing Date <span class="red">*</span></label>
								<div class="col-sm-8">
									<input id="datepicker" type="text" name="closing_date"  class="datepicker form-control input-sm" data-zdp_readonly_element="false" value="{{ date('d-m-Y')}}" placeholder="dd-mm-yyyy">
									<p class="error-sms">{{ $errors->first('closing_date') }}</p>
								</div>
							</div>
							
							<div class="form-group">
								<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-5">
								<button class="btn btn-warning" type="reset">Reset</button>
								<button type="submit" class="btn btn-primary">Search</button>
								</div>
							</div>
						</form>
					</div>	
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<form id="demo-form2" action="{{ route('cash.closing_search')}}" method="post" data-parsley-validate class="form" enctype="multipart/form-data" >
					{{csrf_field()}}
					<div class="row">
						<div class="col-sm-2"></div>
						<div class="col-sm-3">
							<div class="form-group">
								<label>From</label>
								<input id="datepicker-range-start" type="text" name="from_date"  class="form-control" value="{{ date('d-m-Y', strtotime($from_date))}}" data-zdp_readonly_element="false" placeholder="yyyy-mm-dd">
							</div>
						</div>
						<div class="col-sm-3">
							<div class="form-group">
								<label>To</label>
								<input id="datepicker-range-end" type="text" name="to_date"  class="form-control"value="{{ date('d-m-Y', strtotime($to_date))}}" data-zdp_readonly_element="false" placeholder="yyyy-mm-dd">
							</div>
						</div>
						<div class="col-sm-2">
							<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-2">
							<!-- <a href="#" id="search-btn" class="btn btn-xs btn-info" onclick="printDiv('printableArea')">
								<i class="ace-icon fa fa-print fa-2x icon-only"></i>
							</a> -->
						</div>
					</div>
				</form>
				<hr/>
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>SL</th>
							<th>Date</th>
							<th>Lastday Balance</th>
							<th>Receipt</th>
							<th>Payment</th>
							<th>Balance</th>
						</tr>
					</thead>
					<tbody>
						@php
							$receipt = 0;
							$payment = 0;
						@endphp
					@foreach($cashs as $key=>$cs)
						@php
							$receipt = $receipt + $cs->receipt;
							$payment = $payment + $cs->payment;
						@endphp
						<tr>
							<td>{{ $key + 1}}</td>
							<td>{{ date("d-m-Y", strtotime($cs->closing_date))}}</td>
							<td>{{ $cs->lastday_balance}}</td>
							<td>{{ $cs->receipt}}</td>
							<td>{{ $cs->payment}}</td>
							<td>{{ $cs->balance}}</td>
						</tr>
					@endforeach
						<tr>
							<th colspan="2"></th>
							<th>Total=</th>
							<th>{{$receipt}}</th>
							<th>{{$payment}}</th>
							<th>{{$receipt - $payment}}</th>
						</tr>
					</tbody>
				</table>
			</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(){
		// calender section
		 $('#datepicker').Zebra_DatePicker({
			format: 'd-m-Y',
			direction:-1,
		});
		// $('#datepicker2').Zebra_DatePicker({
		// 	format: 'd-m-Y'
		// });
	})
	</script>
@endpush									