@extends('backend.layouts.master')

@section('title', 'Payment')

@push('css')
	<link rel="stylesheet" href="{{asset('backend/plugins/select2.min.css')}}">
	<!-- date Calender-->
	<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">
@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-md-7 col-sm-7 col-xs-12">
                    <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 text-center">
								<h3>{{$cs->name}}</h3> 
								<p>{{$cs->phone}}</p>
								<p>{{$cs->email}}</p>
								<p>{{$cs->address}}</p>
							</div>
							<div class="table-content">
								<table id="" class="table table-bordered" role="grid" aria-describedby="dynamic-table_info">
									<thead>
										<tr>
											<th>SL</th>
											<th>Sale Date</th>
											<th>Invoice No</th>
											<th>Total</th>
											<th>Payment</th>
											<th>Due</th>
										</tr>
									</thead>
									<tbody>

										@php
											$due_total = 0;
										@endphp
										@foreach($sales as $key=>$pay)
											@php
												$due_total = $due_total + $pay->due_amount;
											@endphp
											<tr>
												<td>{{$key + 1}}</td>
												<td>{{date('d-m-Y',strtotime($pay->sale_date))}}</td>
												<td>{{$pay->invoice_no}}</td>
												<td>{{$pay->grand_total_price}}</td>
												<td>{{$pay->payment}}</td>
												<td>{{$pay->due_amount}}</td>
											</tr>
										@endforeach
									</tbody>
									<tfoot>
										<tr>
											<th></th>
											<th></th>
											<th></th>
											<th></th>
											<th>Total Due: </th>
											<th>{{$due_total}}</th>
										</tr>
									</tfoot>
								</table>
								<div class="text-center">
									<form action="{{route('account.cpstore')}}"  class="form-horizontal" role="form" method="Post">
										{{csrf_field() }}
										<input type="hidden" name="customer_id" value="{{$cs->id}}">
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-1">Payment Date <span class='red'>*</span></label>
											<div class="col-sm-9">
												<input id="datepicker" type="text" name="pay_date"  class="form-control input-sm" data-zdp_readonly_element="true" value="{{ date('d-m-Y')}}" placeholder="dd-mm-yyyy" >
												<p class="error-sms">{{ $errors->first('pay_date') }}</p>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-1">Payment Amount <span class='red'>*</span></label>
											<div class="col-sm-7">
												<input id="payment" type="text" name="payment"  class="form-control input-sm"  value="{{ old('amount')}}" placeholder="xxxx">
												<p class="error-sms">{{ $errors->first('payment') }}</p>
											</div>
											<div class="col-sm-2">
												<button type="button" id="discount" class="btn btn-xs btn-primary">Discount</button>
											</div>
										</div>
										<div class="form-group" id="dis_content" style="display: none">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-1">Discount </label>
											<div class="col-sm-4">
												<input id="discount_amount" type="text" name="discount"  class="form-control input-sm"  value="{{ old('discount')}}" placeholder="Discount Amount">
												<p class="error-sms">{{ $errors->first('discount') }}</p>
											</div>
											<div class="col-sm-5">
												<select name="type_name"  class="form-control input-sm select">
													<option value="">-Select Type-</option>
													@foreach($types as $ty)
														<option value="{{$ty->id}}" {{$ty->type_name == 'Customer Discount' ? 'selected' : ''}}>{{$ty->type_name}}</option>
													@endforeach
												</select> 
												<p class="error-sms">{{ $errors->first('type_name') }}</p>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-1">Total Payment <span class='red'>*</span></label>
											<div class="col-sm-9">
												<input id="total_payment" type="text" name="total_payment" class="form-control input-sm" readonly="" value="{{ old('total_payment')}}" placeholder="xxxx">
												<p class="error-sms">{{ $errors->first('total_payment') }}</p>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-3 control-label no-padding-right" for="form-field-1">Note </label>
											<div class="col-sm-9">
												<input id="" type="text" name="note"  class="form-control"  value="{{ old('note')}}" placeholder="Say somothing about payment">
												<p class="error-sms">{{ $errors->first('note') }}</p>
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-sm-3">SMS: </label>
                                            <div class="col-sm-2">
                                                <div class="checkbox">
                                                    <label><input type="checkbox" class="ch" name="sms"> Send </label>
                                                </div>
                                            </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>
				<div class="col-md-5 col-sm-5 col-xs-12">
					<div class="x_panel">
                        <div class="x_title">
                            <h2>Supplier Search </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">
							<form action="{{route('account.cpsearch')}}" method="post" class="form-horizontal" role="form" >
							{{ csrf_field() }}
								<div class="form-group">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1">Customer <span class='red'>*</span></label>
									<div class="col-sm-8">
										<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('supplier_name') }}</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>
	</div>
@endsection

@push('js')
	<script src="{{asset('backend/plugins/select2.min.js')}}"></script>
	<!-- Jquery Plugin For Date Calender-->
	<script type="text/javascript" src="{{ asset('myfile/backend/assets/datepicker/zebra_datepicker.src.js') }}"></script>
	<script>
		$(document).ready(function(){
			$('#datepicker').Zebra_DatePicker({
				format: 'd-m-Y',
				direction:<?php echo setting()->previous_date;?>,
			});
			// select2 section
			$('.select2').select2();
		})
		$(document).on('click','#discount',function(){
			$('#dis_content').toggle('show');
		})
		$(document).on('keyup','#payment',function(){

			total_payment();
		})
		$(document).on('keyup','#discount_amount',function(){
			//alert($(this).val())
			total_payment();
		})
		function total_payment(){
			var payment = $('#payment').val() || 0;
			var discount = $('#discount_amount').val() || 0;
			$('#total_payment').val(parseInt(payment)+parseInt(discount))
		}
	</script>
@endpush									