@extends('backend.layouts.master')

@section('title', 'Payment')

@push('css')
	<link rel="stylesheet" href="{{asset('backend/plugins/select2.min.css')}}">
@endpush

@section('content')
	<div class="right_col" role="main">
        <div class="">
            <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-9">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>
								Customer Payment
								<a href="{{route('customer.list')}}" class="btn btn-xs btn-primary">Customer List</a>
							</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="x_content">
							<div class="row search-section">
								<form action="{{route('account.cpi')}}" id="searchForm" method="Get">
									<div class="col-sm-3">
										<select class="form-control" name="show" id="show">
											<option value="{{$payments->count()}}">{{$payments->count()}}</option>
											@foreach(explode(",",setting()->pdl) as $d)
											<option value="{{$d}}">{{$d}}</option>
											@endforeach
										</select>
									</div>
									<div class="col-sm-5"></div>
									<div class="col-sm-4">
										<div class="input-group">
											<input type="text" id="myInput" class="form-control" placeholder="Search">
											<span class="input-group-btn">
												<button type="button" class="btn btn-primary">
												<span class="ace-icon fa fa-search icon-on-right bigger-110"></span></button>
											</span>
										</div>
									</div>
								</form> 
							</div>
							<div class="table-content">
								<table id="" class="table table-bordered table-condensed" role="grid" aria-describedby="dynamic-table_info">
									<thead>
										<tr class="bg-primary">
											<th>SL</th>
                                            <th>Pay Date</th>
    										<th>Customer Name</th>
    										<th>Tr:Type</th>
    										<th>Invoice No</th>
    										<th>Sales</th>
    										<th>Payment</th>
    										<th>Balance</th>
    										<th>Note</th>
    										<th>Print</th>
										</tr>
									</thead>
									<tbody>
										@foreach($payments as $key=>$pay)
											<tr>
    											<td>{{ $key + 1}}</td>
                                                <td>{{ date("d-m-Y", strtotime($pay->transaction_date))}}</td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Payment'}}" target="_blank">{{ $pay->customer->name}}</a></td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Record'}}" target="_blank">{{ $pay->transaction_type}}</a></td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Invoice'}}" target="_blank">{{ $pay->invoice_no}}</a></td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Product'}}" target="_blank">{{ $pay->sale_amount}}</a></td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Statement'}}" target="_blank">{{ $pay->payment_amount}}</a></td>
                                                <td><a href="{{url('csrs').'?customer_id='.$pay->customer_id.'&report_type=Sales_Due'}}" target="_blank">{{ $pay->current_balance}}</a></td>
                                                <td>{{ $pay->note}}</td>
                                                <td><a  href="{{route('account.cpprint',$pay->id)}}" class="printPage" target="_blank" title="Print Sale Information"><i class="ace-icon fa fa-2x fa-print bigger-130"></i></a></td>
    										</tr>
										@endforeach
									</tbody>
								</table>
								<div class="text-center">
									{{$payments->links()}}
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="col-sm-3">
					<div class="x_panel">
                        <div class="x_title">
                            <h5>Customer Search </h5>
                            <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="x_content">
						<form action="{{route('account.cpsearch')}}" method="POST" class="form-" role="form" >
							{{ csrf_field() }}
							<div class="form-group">
								    <label>Customer Name</label>
									<select name="customer_name"  class="form-control select2" required>
										<option value="">- Select Customer -</option>
										@foreach($customers as $cus)
											<option value="{{$cus->id}}" {{$cus->id == old('customer_name') ? 'selected' : ''}}>{{$cus->customer_name}} ({{$cus->total_due}})</option>
										@endforeach
									</select> 
									<p class="error-sms">{{ $errors->first('customer_name') }}</p>
							
							</div>
							<div class="form-group">
								<div class="col-sm-12 ">
								  <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>
	</div>
@endsection

@push('js')
	<script src="{{asset('backend/plugins/select2.min.js')}}"></script>
	<!-- Print Memo Section-->
	<script src="{{asset('myfile/backend/assets/js/print-page.js')}}"></script>
<script>
	$(document).ready(function(){
		// select2 section
		$('.select2').select2()	;
		$('.printPage').printPage();
	})
	</script>
@endpush