@extends('layouts.app')

@section('content')
<div class="row">
	<div class="col-12">
	<div class="card panel-default">
	<span class="d-none panel-title">{{ _lang('Sale Transcation') }} </span>
		 @php /*<span class="panel-title">{{ $contact->contact_name }} ({{$contact->company_name }} )</span> */@endphp  

	<div class="card-body">
	    <h4>Company Name : {{ $contact->company_name }} </h4><br>
		<form method="post" class="validate" autocomplete="off" action="{{ url('sale/sale_transcation_store/'.$id) }}" enctype="multipart/form-data">
			<div class="row">
		 
					{{ csrf_field() }}
					
					
				<!--	<div class="col-md-6">
					  	<div class="form-group">
							<label class="control-label">{{ _lang('Service Name') }}</label>						
					    <input type="text" class="form-control" name="service_name" value="{{ old('service_name') }}" required> 
					  	</div>
					</div>-->
					
				

					<!--<div class="col-md-12">-->
					<!--  <div class="form-group">-->
					<!--	<label class="control-label">{{ _lang('Email') }}</label>						-->
					<!--	<input type="email" class="form-control" name="email" value="{{ old('email') }}" required>-->
					<!--  </div>-->
					<!--</div>-->
						<div class="col-md-6">
				  <div class="form-group">
					<a href="{{ route('contact_groups.create') }}" data-reload="false" data-title="{{ _lang('Add Contact Group') }}" class="ajax-modal-2 select2-add"><i class="ti-plus"></i> {{ _lang('Add New') }}</a>
					<label class="control-label">{{ _lang('Type') }}</label>						
					<select class="form-control select2-ajax" data-value="id" data-display="name" data-table="contact_groups" data-where="1" name="group_id" required>
						<option value="">{{ _lang('- Select Type -') }}</option>
					</select>
				 </div>
				</div>
				
					<div class="col-md-6">
				  <div class="form-group">
					<label class="control-label">{{ _lang('Subscription frequescy') }}</label>						
					<select class="form-control select2" name="subscription_type" required>
						<option value="Yearly">{{ _lang('Yearly') }}</option>
						<option value="Half Yearly">{{ _lang('Half Yearly') }}</option>
							<option value="Half Yearly">{{ _lang('Half Yearly') }}</option>
							<option value="Quarterly">{{ _lang('Quarterly') }}</option>
								<option value="monthly">{{ _lang('monthly') }}</option>
								<option value="2 Yearly">{{ _lang('2 Yearly') }}</option>
								<option value="3 Yearly">{{ _lang('3 Yearly') }}</option>
					</select>
				  </div>
				</div>
				
					<div class="col-md-6">
				  <div class="form-group">
					<label class="control-label">{{ _lang('Amount') }}</label>						
					<input type="number" min="0" step="any" class="form-control" name="amount" required>
				  </div>
				</div>
					<div class="col-md-6">
					  	<div class="form-group">
							<label class="control-label">{{ _lang('Payment Mode') }}</label>						
							<select class="form-control" name="payment_mode" id="paymentmode" required>
							<option value="">Select Payment Mode</option>
							<option value="Credit Card">Credit Card</option>
							<option value="Cheque Payee">Cheque</option>
							</select>
					  	</div>
					</div>
				
	
				
									
					<div class="col-md-6 d-none">
					  <div class="form-group">
						<label class="control-label">{{ _lang('Payment status') }}</label>						
						<select class="form-control" data-selected="{{ old('dr_cr') }}" id="dr_cr" name="dr_cr" required>
						 <!-- <option value="Debit">Debit </option>-->
						  <option value="Credit" selected>Credit </option>
						 <!-- <option value="Refund">Refund </option>
						   <option value="Partial">Partial </option>
						    <option value="Full amount">Full amount </option>
						     <option value="Dispute amount">Dispute amount</option>-->
						</select>
					  </div>
					</div>	
					
					
					
					
					<div class="col-md-6">
					  	<div class="form-group">
							<label class="control-label">{{ _lang('Payment Date') }}</label>						
					    <input type="datetime-local" class="form-control" name="payment_date" value="{{ old('payment_date') }}" required> 
					  	</div>
					</div>
					
					
					
					<div class="col-md-6">
					  	<div class="form-group">
							<label class="control-label">{{ _lang('Payment Id') }}</label>						
					    <input type="text" class="form-control" name="payment_id" value="{{ old('payment_id') }}" > 
					  	</div>
					</div>	
					
					
				  <div class="col-md-12">
					  	<div class="form-group">
							<label class="control-label">{{ _lang('Notes') }}</label>						
					    <textarea class="form-control" name="notes" > </textarea>
					  	</div>
					</div>	
					
					
					
						<div class="col-md-6" style="display:none" id="payee_name">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('name on the card/cheque') }}</label>						
					      <input type="text" class="form-control" name="payee_name" value="{{ old('payee_name') }}"> 
					  	</div>
					</div>	
			<!-- card details -->
							<div class="col-md-6" style="display:none" id="card_number">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Card Number') }}</label>						
					      <input type="text" class="form-control"  name="card_number" value="{{ old('card_number') }}">
					  	</div>
					</div>	
					
						<div class="col-md-6" style="display:none" id="expiry_month">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Expiry Month') }}</label>						
					      <input type="text" class="form-control" name="expiry_month" value="{{ old('expiry_month') }}"> 
					  	</div>
					</div>	
						<div class="col-md-6" style="display:none" id="expiry_year">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Expiry Year') }}</label>						
					      <input type="text" class="form-control" name="expiry_year" value="{{ old('expiry_year') }}"> 
					  	</div>
					</div>	
				 
					<div class="col-md-6" style="display:none" id="cvv">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('CVV Number') }}</label>						
					      <input type="text" class="form-control" name="cvv" value="{{ old('cvv') }}"> 
					  	</div>
					</div>	
			 		
			 		<!-- UPI input -->
			 		
					<!--	<div class="col-md-6" style="display:none" id="aph">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('APH No.') }}</label>						
					      <input type="text" class="form-control" name="apbh" value="{{ old('aph') }}"> 
					  	</div>
					</div>-->	
					<!-- check input -->
						<div class="col-md-6" style="display:none" id="check_no">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Check Number') }}</label>						
					      <input type="text" class="form-control" name="check_no" value="{{ old('check_no') }}"> 
					  	</div>
					</div>
					<!--	<div class="col-md-6" style="display:none" id="check_date">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Check Date') }}</label>						
					      <input type="text" class="form-control" name="check_date" value="{{ old('check_date') }}"> 
					  	</div>
					</div>-->
					<!-- Account input -->
					

						<div class="col-md-6" style="display:none" id="route_name">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Routing Name') }}</label>						
					      <input type="text" class="form-control" name="route_name" value="{{ old('route_name') }}"> 
					  	</div>
					</div>
					
						<div class="col-md-6" style="display:none" id="bank_name">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Bank Name') }}</label>						
					      <input type="text" class="form-control" name="bank_name" value="{{ old('bank_name') }}"> 
					  	</div>
					</div>

						<div class="col-md-6" style="display:none" id="account_number">
					  	   <div class="form-group">
							<label class="control-label">{{ _lang('Account Number') }}</label>						
					      <input type="text" class="form-control" name="account_number" value="{{ old('account_number') }}"> 
					  	</div>
					</div>
					
					<div class="form-group">
					  <div class="col-md-12">
						<button type="submit" class="btn btn-primary">{{ _lang('Save') }}</button>
					  </div>
					</div>
					
				</div>
	 	
		</form>
	  
	</div>
  </div>
 </div>
</div>


<style>
    .tbl-dt{ font-size: 15px; line-height: 32px; color: #444; margin-bottom: 0; BORDER: 1px solid;  padding: 5px;}
</style>


<!-- Data list show-->

<div class="card mt-2">
			<span class="panel-title d-none">{{ _lang('List Contact') }}</span>
			<div class="card-body">
			<table id="contacts-table" class="table table-bordered">
			<thead>
			  <tr>
				<th>{{ _lang('Type') }}</th>
					<th>{{ _lang('Subscription frequescy') }}</th>
					<th>{{ _lang('Amount') }}</th>
				<th>{{ _lang('Payment Mode') }}</th>
				<th>{{ _lang('Payment status') }}</th>
				<th>{{ _lang('Payment Date') }}</th>
				<th>{{ _lang('Status') }}</th>
				<th class="text-center">{{ _lang('Action') }}</th>
				
			  </tr>
			</thead>
			<tbody>
			    
			    
			    @foreach($datas as $key=>$data) 
			    
			    <?php
			      $ccNum          = $data->card_number??0;
   // function getTruncatedCCNumber($ccNum){
       // $last4Digits    = preg_replace( "#(.*?)(\d{4})$# ", "$2", $ccNum);
       // $firstDigits    = preg_replace( "#(.*?)(\d{4})$# ", "$1", $ccNum);
      ////  $firstDigits1    = preg_replace( "#(.*?)(\d{15})$# ", "$1", $ccNum);
    // $fvcard1=  preg_replace("#(\d)# ", "*", $firstDigits) . $last4Digits;
   //  $fvcard=$firstDigits1.$fvcard1;
    //}
						$last4= substr(str_replace(['-',' '],'',$ccNum), -4);
						$fvcard1= str_pad($last4, 16, '*', STR_PAD_LEFT);
						$first_digit=substr($ccNum, 0, 1);
    
      if(Auth::user()->role_id!=0){
     $fvcard=$first_digit.$fvcard1;
     }else{
         if(Auth::user()->card_show==1){
            $fvcard=$first_digit.$fvcard1;
         }else{
        $fvcard= $ccNum;
         }
     }
//$fvcard=   getTruncatedCCNumber($ccNum);
			    ?>
			    <tr>
			    <td>{{$data->group->name??'' }}</td>
			     <td>{{$data->subscription_type }}</td>
					@if(($data->refund_type == 'Full amount' or $data->refund_type == 'Partial' or $data->refund_type == 'Dispute') && ($data->parent_id!=0 or $data->refundable_amount>0))
			    <td>{{$data->refundable_amount }}</td>
					@else
						<td>{{$data->amount }}</td>
					@endif
			    <td>{{$data->payment_mode }}</td>
					@if(($data->refund_type == 'Full amount' or $data->refund_type == 'Partial' or $data->refund_type == 'Dispute') && ($data->parent_id!=0 or $data->refundable_amount>0))
			    <td>{{$data->refund_type }}</td>
					@else
						<td>{{$data->dr_cr }}</td>
					@endif
			    <td>{{$data->payment_date }}</td>
			   @if(empty($data->refund_type))
			    <td>Credit</td>
			    @else
			     <td>{{$data->refund_type??'NA'}} Refund</td>
			    @endif
			   <td><button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-default{{$key}}">
View All Details
</button>
<!--<button type="button" class="btn btn-info" onclick="window.location.href='refund-payment'">-->
<!--    Refund-->
<!--</button>-->
@if(empty($data->refund_type))
					   <a href="{{url('sale/sale_transaction-edit/'.$data->id)}}" class="btn btn-primary">Edit</a>
<a href="{{url('sale/refund-payment/'.$data->id)}}" class="btn btn-info">Refund</a>

 <form method="POST" action="{{ url('sale/refund-payment/dispute/'.$data->id) }}" style="display: inline;">
    @csrf
    <button type="submit" class="btn btn-warning" onclick="return confirm('Do you want to dispute or not?')">Dispute</button>
</form>

					   <form method="POST" action="{{ url('sale/sale_transaction-delete/'.$data->id) }}" style="display: inline;">
						   @csrf
						   <button type="submit" class="btn btn-danger" onclick="return confirm('Do you want to Delete or not?')">Delete</button>
					   </form>



@endif

</td></tr>
			   

<div class="modal fade" id="modal-default{{$key}}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Details</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
    
<div class="row"> 

<div class="col-md-6">
    <p class="tbl-dt"><b>Type:-</b> {{$data->group->name??'' }}</p>
<p class="tbl-dt"><b>Amount:-</b> {{$data->amount }}</p>
<p class="tbl-dt"><b>Payment Id:-</b> {{$data->payment_id }}</p>
<p class="tbl-dt"><b>Payment Mode:-</b> {{$data->payment_mode }}</p>
<p class="tbl-dt"><b>Payment frequescy:-</b> {{$data->subscription_type }}</p>
<p class="tbl-dt"><b>Account Number:-</b> {{$data->account_number??'NA' }}</p>
<p class="tbl-dt"><b>Routing No:-</b> {{$data->route_name??'NA' }}</p>
<p class="tbl-dt"><b>Bank Name:-</b> {{$data->bank_name??'NA' }}</p>
<p class="tbl-dt"><b>Card Number:-</b> {{$fvcard??'NA' }}</p>
</div>


<div class="col-md-6">
<p class="tbl-dt"><b>Payment Date:-</b> {{$data->payment_date }}</p>
<p class="tbl-dt"><b>Type:-</b> {{$data->dr_cr }}</p>
<p class="tbl-dt"><b>Payee Name:-</b> {{$data->payee_name }}</p>
<p class="tbl-dt"><b>Expiry Month:-</b> {{$data->expiry_month??'NA' }}</p>

<p class="tbl-dt"><b>Expiry Year:-</b> {{$data->expiry_year??'NA' }}</p>
<p class="tbl-dt"><b>Cvv:-</b> {{$data->cvv??'NA' }}</p>
<p class="tbl-dt"><b>Cheque no:-</b> {{$data->check_no??'NA' }}</p>
<p class="tbl-dt"><b>Cheque Date:-</b>  {{$data->check_date??'NA' }}</p>

@if($data->refund_type=='Full amount' || $data->refund_type=='Partial')

<p class="tbl-dt"><b>Refund Amount:-</b> {{ $data->refundable_amount}}</p>
@endif

 

@if($data->refund_type=='Dispute')

<p class="tbl-dt"><b>Dispute Amount:-</b> {{ $data->amount}}</p>
@endif



@if($data->refund_payment_id)

<p class="tbl-dt"><b>Refund payment Id :-</b> {{ $data->refund_payment_id }}</p>
@endif

</div>


</div>

</div>
<div class="modal-footer justify-content-between d-none">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>

</div>   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			    
			  @endforeach
			</tbody>
		  </table>
			</div>
		</div>



@endsection

@section('js-script')

<script src="https://crm.digitalhubsolution.com/backend/assets/js/vendor/jquery-2.2.4.min.js"></script>

<script>
(function($) {
	"use strict";

	document.title = $(".panel-title").html();
	$("#trans_type").val("{{ isset($dr_cr) ? $dr_cr : 'all' }}");
	
})(jQuery);
</script>

<script type="text/javascript">
// $('#mySelect').bind('onchange',function(){
//     alert("test");
// if (this.value==='Credit Card')
// {
//     alert("cc");
// //this.myform['other'].style.visibility='visible'
// document.getElementById("element").style.display = "none";
// }
// else {
// this.myform['other'].style.visibility='hidden'};
// }


$(document).ready(function () {
        $('#paymentmode').change(function () {
         
            if ($('#paymentmode').val() == 'Credit Card') {
        
                document.getElementById("payee_name").style.display = "block";
                document.getElementById("card_number").style.display = "block";
                document.getElementById("expiry_month").style.display = "block";
                document.getElementById("expiry_year").style.display = "block";
                document.getElementById("cvv").style.display = "block";
                document.getElementById("bank_name").style.display = "block";

                 document.getElementById("account_number").style.display = "none";
              document.getElementById("route_name").style.display = "none";
               document.getElementById("check_no").style.display = "none"; 

               /* document.getElementsByName("payee_name")[0].setAttribute('required', '');
                document.getElementsByName("card_number")[0].setAttribute('required', '');
                document.getElementsByName("expiry_month")[0].setAttribute('required', '');
                document.getElementsByName("expiry_year")[0].setAttribute('required', '');
                document.getElementsByName("cvv")[0].setAttribute('required', '');

                document.getElementsByName("account_number")[0].setAttribute('', '');
                document.getElementsByName("route_name")[0].setAttribute('', '');
                document.getElementsByName("check_no")[0].setAttribute('', '');
*/
                          
                
             //   $('#other').show();
            }else if($('#paymentmode').val() == 'Debit Card'){
                   document.getElementById("payee_name").style.display = "block";
                document.getElementById("card_number").style.display = "block";
                document.getElementById("expiry_month").style.display = "block";
                document.getElementById("expiry_year").style.display = "block";
                document.getElementById("cvv").style.display = "block";
                
                document.getElementById("upi_id").style.display = "none";
                 document.getElementById("account_number").style.display = "none";
              document.getElementById("ifsc_code").style.display = "none";
              document.getElementById("bank_name").style.display = "none";
               document.getElementById("check_no").style.display = "none"; 
                       document.getElementById("check_date").style.display = "none"; 
                       
                       
            //   style     
              /*  document.getElementsByName("payee_name")[0].setAttribute('required', '');
                document.getElementsByName("card_number")[0].setAttribute('required', '');
                document.getElementsByName("expiry_month")[0].setAttribute('required', '');
                document.getElementsByName("expiry_year")[0].setAttribute('required', '');

                document.getElementsByName("cvv")[0].setAttribute('required', '');
                document.getElementsByName("upi_id")[0].setAttribute('', '');
                document.getElementsByName("account_number")[0].setAttribute('', '');
                document.getElementsByName("ifsc_code")[0].setAttribute('', '');
                document.getElementsByName("check_no")[0].setAttribute('', '');
                document.getElementsByName("check_date")[0].setAttribute('', ''); */
                       
                       
                       
            }else if($('#paymentmode').val() == 'UPI'){
                   document.getElementById("payee_name").style.display = "block";
                      document.getElementById("upi_id").style.display = "block";
                      
                     
                document.getElementById("card_number").style.display = "none";
                document.getElementById("expiry_month").style.display = "none";
                document.getElementById("expiry_year").style.display = "none";
                document.getElementById("cvv").style.display = "none";
                 document.getElementById("account_number").style.display = "none";
              document.getElementById("ifsc_code").style.display = "none";
              document.getElementById("bank_name").style.display = "none";
              document.getElementById("check_no").style.display = "none"; 
                       document.getElementById("check_date").style.display = "none"; 
                       
            //  style
            /*
                    document.getElementsByName("payee_name")[0].setAttribute('required', '');
                    document.getElementsByName("upi_id")[0].setAttribute('required', '');
                document.getElementsByName("card_number")[0].setAttribute('', '');
                document.getElementsByName("expiry_month")[0].setAttribute('', '');
                document.getElementsByName("expiry_year")[0].setAttribute('', '');
                document.getElementsByName("cvv")[0].setAttribute('', '');
                
                document.getElementsByName("account_number")[0].setAttribute('', '');
                document.getElementsByName("ifsc_code")[0].setAttribute('', '');
                document.getElementsByName("check_no")[0].setAttribute('', '');
                document.getElementsByName("check_date")[0].setAttribute('', '');
                       */
                       
                       
            }else if($('#paymentmode').val() == 'Cheque Payee'){
               document.getElementById("payee_name").style.display = "block";
                             document.getElementById("route_name").style.display = "block";
                      document.getElementById("check_no").style.display = "block"; 
                        document.getElementById("account_number").style.display = "block";
                  document.getElementById("bank_name").style.display = "block";
                        document.getElementById("card_number").style.display = "none";
                document.getElementById("expiry_month").style.display = "none";
                document.getElementById("expiry_year").style.display = "none";
                document.getElementById("cvv").style.display = "none";
                
               
               
                          //  style
            /*
                    document.getElementsByName("payee_name")[0].setAttribute('required', '');
                                   document.getElementsByName("check_no")[0].setAttribute('required', '');
                                     document.getElementsByName("account_number")[0].setAttribute('required', '');
                document.getElementsByName("route_name")[0].setAttribute('required', '');
                document.getElementsByName("card_number")[0].setAttribute('', '');
                document.getElementsByName("expiry_month")[0].setAttribute('', '');
                document.getElementsByName("expiry_year")[0].setAttribute('', '');
                document.getElementsByName("cvv")[0].setAttribute('', '');
                */
              

               
               
               
               
            }else if($('#paymentmode').val() == 'Account Payee'){
              document.getElementById("payee_name").style.display = "block";
              document.getElementById("account_number").style.display = "block";
              document.getElementById("ifsc_code").style.display = "block";
              document.getElementById("bank_name").style.display = "block";
              
               document.getElementById("card_number").style.display = "none";
                document.getElementById("expiry_month").style.display = "none";
                document.getElementById("expiry_year").style.display = "none";
                document.getElementById("cvv").style.display = "none";
                  document.getElementById("upi_id").style.display = "none";
                      document.getElementById("check_no").style.display = "none"; 
                       document.getElementById("check_date").style.display = "none"; 
                       
                       
                       
                       
                                           //  style
            
               /*  document.getElementsByName("payee_name")[0].setAttribute('required', '');
                document.getElementsByName("account_number")[0].setAttribute('required', '');
                document.getElementsByName("ifsc_code")[0].setAttribute('required', '');

                    document.getElementsByName("upi_id")[0].setAttribute('', '');
                document.getElementsByName("card_number")[0].setAttribute('', '');
                document.getElementsByName("expiry_month")[0].setAttribute('', '');
                document.getElementsByName("expiry_year")[0].setAttribute('', '');
                document.getElementsByName("cvv")[0].setAttribute('', '');
        
                document.getElementsByName("check_no")[0].setAttribute('', '');
                document.getElementsByName("check_date")[0].setAttribute('', '');       
                       */
                       
                       
                       
                       
            }
            else {
             //   $('#other').hide();
            }
        });
    });



//btn alert

 function confirmation() {
swal({
  title: "Are you sure?",
  text: "Once deleted, you will not be able to recover this imaginary file!",
  icon: "warning",
  buttons: true,
  dangerMode: true,
})
.then((willDelete) => {
  if (willDelete) {
    swal("Poof! Your imaginary file has been deleted!", {
      icon: "success",
    });
  } else {
    swal("Your imaginary file is safe!");
  }
});
}

</script>






@endsection


