

<?php $__env->startSection('title', 'Condition Sale'); ?>

<?php $__env->startPush('css'); ?>
	<link rel="stylesheet" href="<?php echo e(asset('backend/plugins/select2.min.css')); ?>">
	<!-- date Calender-->
	<link rel="stylesheet" href="<?php echo e(asset('myfile/backend/assets/datepicker/zebra_datepicker.min.css')); ?>" type="text/css">
	<link rel="stylesheet" href="<?php echo e(asset('myfile/backend/assets/datepicker/examples.css')); ?>" type="text/css">
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
	<div class="right_col" role="main">
        <div class="">
            <div class="clearfix"></div>
            <?php if(Session::has('success')): ?>
                <div class="alert alert-success">
                    <?php echo e(Session::get('success')); ?>

                </div>
            <?php endif; ?>
            <?php if(Session::has('error')): ?>
                <div class="alert alert-danger">
                    <?php echo e(Session::get('error')); ?>

                </div>
            <?php endif; ?>
            <div class="row">
                <div class="col-md-8 col-sm-8 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>
								Condition Invoice
								<a href="<?php echo e(route('sales.condition_list')); ?>" class="btn btn-xs btn-primary">Condition 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">
								<div class="col-xs-3">
									Sale Date: <?php echo e(date('d-m-Y',strtotime($sale->sale_date))); ?>

								</div>
								<div class="col-xs-6">
									<h3><?php echo e($sale->customer->name); ?></h3> 
									<p><?php echo e($sale->customer->phone); ?></p>
									<p><?php echo e($sale->customer->email); ?></p>
									<p><?php echo e($sale->customer->address); ?></p>
								</div>
								<div class="col-xs-3">
									Invoice No: <?php echo e($sale->invoice_no); ?>

								</div>
							</div>
							<div class="table-content table-">
								<table id="" class="table table-bordered table-condensed" role="grid" aria-describedby="dynamic-table_info">
									<thead>
										<tr>
											<th>SL</th>
											<th>Product</th>
											<th>Code</th>
											<th>Quantity</th>
											<th>Unit Price</th>
											<th>Sub Total</th>
										</tr>
									</thead>
									<tbody>

										<?php 
											$due_total = 0;
										 ?>
										<?php $__currentLoopData = $sale->details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$pay): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
											<?php 
												$due_total = 0;
											 ?>
											<tr>
												<td><?php echo e($key + 1); ?></td>
												<td><?php echo e($pay->product->product_name); ?></td>
												<td><?php echo e($pay->code); ?></td>
												<td><?php echo e($pay->quantity); ?></td>
												<td><?php echo e($pay->unit_price); ?></td>
												<td><?php echo e($pay->quantity*$pay->unit_price); ?></td>
											</tr>
										<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
									</tbody>
									<tfoot>
										<tr>
											<th></th>
											<th></th>
											<th></th>
											<th></th>
											<th>
												Total:<br/>
												Payment:<br/>
												Due:<br/>
											</th>
											<th>
												<?php echo e($sale->grand_total_price); ?><br/>
												<?php echo e($sale->payment); ?><br/>
												<?php echo e($sale->due_amount); ?><br/>

											</th>
										</tr>
									</tfoot>
								</table>
								<div class="text-center">
									<form action="<?php echo e(route('sales.condition_update',$sale->id)); ?>"  class="form-horizontal" role="form" method="Post" autocomplete="off" >
										<?php echo e(csrf_field()); ?>

										<input type="hidden" name="customer_id" value="<?php echo e($sale->customer_id); ?>">
										<input type="hidden" id="total_due" name="due_amount" value="<?php echo e($sale->due_amount); ?>">
										<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="<?php echo e(date('d-m-Y')); ?>" placeholder="dd-mm-yyyy" >
												<p class="error-sms"><?php echo e($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">Invoice Status <span class='red'>*</span></label>
											<div class="col-sm-9">
												<select name="sale_type" id="sale_type" class="form-control" >
													<option value="Sold" >Sold</option>
													<option value="Cancel" >Cancel</option>
												</select>
												<p class="error-sms"><?php echo e($errors->first('sale_type')); ?></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-9">
												<input id="payment" type="text" name="payment"  class="form-control input-sm"  value="<?php echo e(old('amount')); ?>" placeholder="xxxx">
												<p class="error-sms"><?php echo e($errors->first('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="<?php echo e(old('note')); ?>" placeholder="Say somothing about payment">
												<p class="error-sms"><?php echo e($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-4 col-sm-4 col-xs-12">
					<div class="x_panel">
                        <div class="x_title">
                            <h2>Sales Invoice 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="<?php echo e(route('sales.condition_change')); ?>" method="POST" class="form-horizontal" role="form" >
                                <?php echo e(csrf_field()); ?>

                                <?php echo e(method_field('Get')); ?>

                                <div class="form-group">
                                    <label >Condition Invoice *</label>
									<select name="sale_id"  class="form-control select2">
										<option value="">- Select Customer -</option>
										<?php $__currentLoopData = $conditions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $con): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
											<option value="<?php echo e($con->id); ?>" <?php echo e($con->id == old('sale_id') ? 'selected' : ''); ?>><?php echo e($con->customer->name); ?> (<?php echo e($con->invoice_no); ?>)</option>
										<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
									</select> 
									<p class="error-sms"><?php echo e($errors->first('sale_id')); ?></p>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-7 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>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
	<script src="<?php echo e(asset('backend/plugins/select2.min.js')); ?>"></script>
	<!-- Jquery Plugin For Date Calender-->
	<script type="text/javascript" src="<?php echo e(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('keyup','#payment',function(){
			total_payment();
		})
		$(document).on('change','#sale_type',function(){
			if($(this).val() == 'Cancel'){
				$('#payment').val(0);
				$('#payment').prop('readonly', true);
			}else{
				$('#payment').prop('readonly', false);
			}
		})
		function total_payment(){
			var payment = parseFloat($('#payment').val()) || 0;
			var due = parseFloat($('#total_due').val()) || 0;
			if(payment > due){
				alert('Woops!! Payment amount is more than due');
				$('#payment').val(0);
			}
			//var discount = $('#discount_amount').val() || 0;
			//$('#total_payment').val(parseInt(payment)+parseInt(discount))
		}
	</script>
<?php $__env->stopPush(); ?>									
<?php echo $__env->make('backend.layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>