@extends('layouts.app')

@section('content')
<section class="page-header row">
	<h2> {{ $pageTitle }} </h2>
	<ol class="breadcrumb">
		<li><a href="{{ url('') }}"> Dashboard </a></li>
		<li><a href="{{ url('/manage/'.$pageModule) }}"> {{ $pageTitle }} </a></li>
		<li class="active"> Form  </li>		
	</ol>
</section>
<div class="page-content row">
	<div class="page-content-wrapper no-margin">
	
	{!! Form::open(array('url'=>'/manage/userreferralsaletransactions?return='.$return, 'class'=>'form-horizontal validated','files' => true )) !!}
	<input type="hidden" name="status_type" value="{{ $pageTitle }}" />
	
		<div class="sbox-title clearfix">
			<div class="sbox-tools pull-right" >
				<a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-times"></i></a> 
			</div>
			<div class="sbox-tools1 pull-left1" >
				<button name="apply" class="btn btn-sm btn-primary  "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
				<button name="save" class="btn btn-sm btn-success"  title="{{ __('core.btn_back') }}" ><i class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button> 
				<?php if($frontendSlug!='') {
				$fsconfig = explode('@',$frontendSlug);
				if( ($row[$fsconfig[1]]) ) 
				echo '<a  class="btn btn-sm btn-outline-primary" target="_blank"  title="FrontEnd" href="'. (config('website.cnf_appurl') .'/'.config('website.cnf_lang') . str_replace('//','/',('/'.$fsconfig[0].'/'.$row[$fsconfig[1]]))).'"><i class="fa  fa-desktop"></i> FrontEnd</a>';
				 } ?>
			</div>
		</div>	
		<div class="sbox1">
		<div class="sbox-content clearfix row">
		<div class="col-xs-12">
	<ul class="parsley-error-list">
		@foreach($errors->all() as $error)
			<li>{{ $error }}</li>
		@endforeach
	</ul>		

	<?php $curTime = time();?>

<div class="sbox1"><div class="col-md-12">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> User Referral Sale Transactions</legend>
				<?php if( !isset($row['id']))  $row['id'] = null;   ?>
		<input  type='hidden' name='id' id='id' value='{{$row['id']}}' />
									
									  <div class="form-group depen- wrap-sales_id  " >
										<label for="Sales Id" class=" control-label col-md-3 text-left"> Sales Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['sales_id']))  $row['sales_id'] = null;   ?>
		<input  type='text' name='sales_id' id='sales_id' value='{{ $row['sales_id'] }}' 
						       class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-user_id  " >
										<label for="User Id" class=" control-label col-md-3 text-left"> User Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['user_id']))  $row['user_id'] = null;   ?>
		 
					<?php $row['user_id'] = trim($row['user_id'],'[]'); ?>

					 <select name='user_id' rows='5' id='user_id' class='select2 '  data-placeholder='Select User Id'   placeholder='Select User Id'      ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-shopper_id  " >
										<label for="Shopper Id" class=" control-label col-md-3 text-left"> Shopper Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['shopper_id']))  $row['shopper_id'] = null;   ?>
		 
					<?php $row['shopper_id'] = trim($row['shopper_id'],'[]'); ?>

					 <select name='shopper_id' rows='5' id='shopper_id' class='select2 '  data-placeholder='Select Shopper Id'   placeholder='Select Shopper Id'      ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-order_amount  " >
										<label for="Order Amount" class=" control-label col-md-3 text-left"> Order Amount </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['order_amount']))  $row['order_amount'] = null;   ?>
		<input  type='text' name='order_amount' id='order_amount' value='{{ $row['order_amount'] }}' 
						   data-parsley-maxlength="10"    class='form-control is_decimal' onkeypress='return isNumberKey(event,this)'  /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-transaction_time  " >
										<label for="Transaction Time" class=" control-label col-md-3 text-left"> Transaction Time <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['transaction_time']))  $row['transaction_time'] = null;   ?>
		
				<div class="input-group m-b" style="width:150px !important;">
				
				<input  type='text' name='transaction_time' id='transaction_time' value='{{ $row['transaction_time'] }}' 
				required       class='form-control input-sm @if(trim('  ')!='readonly') datetime @endif ' />

					<span class="input-group-addon calwrap"><i class="fa fa-calendar"></i></span>
				</div>
				 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-store_id  " >
										<label for="Store Id" class=" control-label col-md-3 text-left"> Store Id </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['store_id']))  $row['store_id'] = null;   ?>
		 
					<?php $row['store_id'] = trim($row['store_id'],'[]'); ?>

					 <select name='store_id' rows='5' id='store_id' class='select2 '  data-placeholder='Select Store Id'   placeholder='Select Store Id'    data-parsley-maxlength=  ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-referral_amount  " >
										<label for="Referral Amount" class=" control-label col-md-3 text-left"> Referral Amount </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['referral_amount']))  $row['referral_amount'] = null;   ?>
		<input  type='text' name='referral_amount' id='referral_amount' value='{{ $row['referral_amount'] }}' 
						   data-parsley-maxlength="10"    class='form-control is_decimal' onkeypress='return isNumberKey(event,this)'  /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-currency  " >
										<label for="Currency" class=" control-label col-md-3 text-left"> Currency <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['currency']))  $row['currency'] = null;   ?>
		<input  type='text' name='currency' id='currency' value='{{ $row['currency'] }}' 
						required   data-parsley-maxlength="3"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-status  " >
										<label for="Status" class=" control-label col-md-3 text-left"> Status </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['status']))  $row['status'] = null;   ?>
		<?php $status = (isset($row['status'])) ? $row['status'] : null ; ?>
					
					<input type='radio' name='status' value ='pending'     @if( $status == 'pending') checked="checked" @endif class='minimal-red' > Pending 
					
					<input type='radio' name='status' value ='confirmed'     @if( $status == 'confirmed') checked="checked" @endif class='minimal-red' > Confirmed 
					
					<input type='radio' name='status' value ='declined'     @if( $status == 'declined') checked="checked" @endif class='minimal-red' > Declined  
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div></fieldset>
			</div>
			
			
		</div>
		
		
</div>
</div>
</div>
@include('/manage/'.$pageModule.'/subform')

		
		
		<div class="sbox-title clearfix">
			<div class="sbox-tools pull-right" >
				<a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-times"></i></a> 
			</div>
			<div class="sbox-tools pull-left" >
				<button name="apply" class=" btn btn-sm btn-primary  "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
				<button name="save" class=" btn btn-sm btn-success"  title="{{ __('core.btn_back') }}" ><i class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button> 
			</div>
		</div>	
		
	
	
	<input type="hidden" name="action_task" value="save" />
	{!! Form::close() !!}
	</div>
</div>		

	
		 
   <script type="text/javascript">
	$(document).ready(function() { 
		
		
		
		$("#user_id").select2({
			ajax: {
				url: "{{url('/manage/userreferralsaletransactions/ajaxselect?filter=users:user_id:first_name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.user_id,
								text: selctToJson(item,'first_name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

		@if( strlen($row["user_id"]) > 0  )
		// Fetch the preselected item, and add to the control
			var user_idSelect = $('#user_id');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/userreferralsaletransactions/ajaxselect?filter=users:user_id:first_name&values='.urlencode($row["user_id"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'first_name'), item.user_id, true, true);
											user_idSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				user_idSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			user_idSelect.select2_sortable();
			@endif

		
		$("#shopper_id").select2({
			ajax: {
				url: "{{url('/manage/userreferralsaletransactions/ajaxselect?filter=users:user_id:first_name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.user_id,
								text: selctToJson(item,'first_name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

		@if( strlen($row["shopper_id"]) > 0  )
		// Fetch the preselected item, and add to the control
			var shopper_idSelect = $('#shopper_id');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/userreferralsaletransactions/ajaxselect?filter=users:user_id:first_name&values='.urlencode($row["shopper_id"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'first_name'), item.user_id, true, true);
											shopper_idSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				shopper_idSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			shopper_idSelect.select2_sortable();
			@endif

		
		$("#store_id").select2({
			ajax: {
				url: "{{url('/manage/userreferralsaletransactions/ajaxselect?filter=stores:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

		@if( strlen($row["store_id"]) > 0  )
		// Fetch the preselected item, and add to the control
			var store_idSelect = $('#store_id');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/userreferralsaletransactions/ajaxselect?filter=stores:id:name&values='.urlencode($row["store_id"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											store_idSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				store_idSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			store_idSelect.select2_sortable();
			@endif

		 		 

		$('.removeMultiFiles').on('click',function(){
			var removeUrl = '{{ url("userreferralsaletransactions/removefiles?file=")}}'+$(this).attr('url');
			$(this).parent().remove();
			$.get(removeUrl,function(response){});
			$(this).parent('div').empty();	
			return false;
		});		
		
	});
	</script>		 
@stop