@extends('layouts.app1')

@section('content')
<style>
    @media print {
        .non-printable {
            display: none;
        }
        

        .printable {
            display: block;
        }
    }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<link href="{{ asset('sweetalert2/dist/sweetalert2.min.css') }}" rel="stylesheet">
<script src="{{ asset('sweetalert2/dist/sweetalert2.all.min.js') }}"></script>
<!-- page content -->
<div class="right_col non-printable" role="main">
    @include('flashmessage')
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>BBPS Reports</h3>
              </div>
				@if (request()->role!="")
				  <div class="title_right">
					<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
					  
					  <!-- <a href="crecharge/create" class="btn btn-success pull-right">Recharge</a> -->
					</div>
				  </div>
				@endif 
				 
            </div>
            
            <div class="clearfix"></div>

            <div class="panel-body">
            
            </div>

            
                <form action="bbps-transactions" method="GET">  
                <div class="card-box table-responsive">                  
                    <table class="table table-bordered" style="background: #fff;">
                        <thead>
                            <tr>
                                <th>Transaction Id</th>
                                @if (request()->role=="")
                                <th>Member Id</th>
                                @endif
                                <th>Status</th>
                                <th>Customer Number</th>
                                <th>From Date</th>
                                <th>To Date</th>
                                <th>#</th>                           
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input value="" type="text" name="orderId" class="form-control"> </td>
                                @if (request()->role=="")
                                <td><input value="{{request()->input('loginId')}}" type="text" name="loginId" class="form-control"> </td>
                                @endif
                                <td><input value="" name="status" type="text" class="form-control"></td>
                                <td><input value="" name="contact" type="text" class="form-control"></td>
                                <td><input value="" class="form-control"
                                        name="from_date" type="date"></td>
                                <td><input value="" class="form-control" name="to_date"
                                        type="date"></td>
                                <td><button class="btn btn-success btn-xs"> Search </button></td>
                                
                            </tr>
                        </tbody>
                    </table> 
                </div>
                </form>
            <div class="row">
              <div class="col-md-12 col-sm-12 ">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>
                      All <small>Recharge</small> 
                      <?php 
                        $loginId = request()->query('loginId'); 
                        $orderId = request()->query('orderId'); 
                        $status = request()->query('status'); 
                        $contact = request()->query('contact'); 
                        $fromDate = request()->query('from_date'); 
                        $toDate = request()->query('to_date'); 
                      ?>
                      <div class="float-right">
                        <form method="post" action="/bbpsExport">
                          @csrf
                          <input type="hidden" name="loginId" value="<?php echo $loginId; ?>">
                          <input type="hidden" name="orderId" value="<?php echo $orderId; ?>">
                          <input type="hidden" name="status" value="<?php echo $status; ?>">
                          <input type="hidden" name="contact" value="<?php echo $contact; ?>">
                          <input type="hidden" name="from_date" value="<?php echo $fromDate; ?>">
                          <input type="hidden" name="to_date" value="<?php echo $toDate; ?>">
                          <input type="submit" class="btn btn-success" value="Export">
                        </form>
                      </div>
                    </h2>
                    
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                      <div class="row">
                          <div class="col-sm-12">
                            <div class="card-box table-responsive">
                    
					
                    <table id="datatable-responsive1" class="table table-bordered table-striped dataTable" cellspacing="0" width="100%" style="white-space: nowrap">
                      <thead>
                        <tr>
                            <th>SN</th>
                            <th>Transaction_id </th>
                            <th>Date</th>
                            <th>Member ID</th>     
                            <th>Member Name</th>                          
                            <th>Operator</th>
                            <th>Recharge Amount</th>
                            <th>Mobile</th>
                            <th>Status</th> 
                            <th>Print</th> 
							              <!-- <th>#</th> -->
                        </tr>
                      </thead>
                      <tbody>  
                      @foreach ($recharges as $key=> $recharge)

                            <tr>
                                <td>{{$key+1}}</td>
                                <td>{{$recharge->transaction_id}}</td>
                                <td>{{$recharge->created_at->format("d, M Y, H:i:s")}}</td>
                                <td>{{$recharge->user->loginId}}</td>
                                <td>{{$recharge->user->name}}</td>
                                <td>{{$recharge->operator}}</td>                                
                                <td>{{$recharge->amount}}</td>
                                <td>{{$recharge->user->contact}}</td>
                                <td>{{$recharge->statusC}}</td>  
                								<td>
                                  <i data-id="{{$recharge->id}}" onclick="openBBPSReciept(this)" class="fa fa-list" style="cursor:pointer;"></i>
                								</td>
                                <!-- <td>
                                   @if($recharge->statusC == 'Pending')
                                    <a href="/bbps/check-status/{{$recharge->id}}" class="btn btn-outline-primary btn-sm">Check Status</a>
                                  @endif
                                </td> -->
                            </tr>
                            @endforeach

                                             
                      </tbody>
					  <tfoot>
                            <tr>
                                <td colspan="9">
                                   <?php
									echo $recharges->appends($_GET)->links();
                                   ?>
                                </td>
                            </tr>
                        </tfoot>
                      

                    </table>
					
					
                  </div>
                </div>
              </div>
            </div>
            
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->
<style>
  .fade:not(.show){
    opacity: 1;
  }
  .dt-buttons .btn-default {
    padding: 5px 15px;
    border-radius: 0.25rem;
    background: #169F85;;
    color: #fff;
    margin-right: 5px;
}
</style>
<div class="modal printable" id="openRechargeReciept" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header non-printable">
                <h5 class="modal-title">BBPS Receipt <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button></h5>
                
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer non-printable">
                <button type="button" onclick="window.print()" class="btn btn-primary">Print</button>
				<button class="tst3 btn btn-success" type="button" data-toggle="modal" data-target="#emailPop"> <span><i class="fa fa-email"></i> <a href="javascript:" style="color:#fff !important;">Send Email</a></span> </button>

            </div>
        </div>
    </div>
</div>

<div id="emailPop" class="modal fade second-modal-class" role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-md">
		  <div class="modal-content">
			<div class="modal-header non-printable">
                <h5 class="modal-title">Share This <button type="button" class="close second-modal-close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button></h5>
                
            </div>
		  
			 <div class="modal-body text-center">
				<div class="row">
					<div class="col-md-12" align="center">
						
						
						<div class="form-group col-md-9">
							<input type="hidden" name="emailTransId" id="emailTransId" />
							<input placeholder="Enter email comma seperated" type="text" class="form-control" name="emailshare" id="emailshare" style="width: 100%;padding-top:0;" required>
							<br /><br />
							<button type="button" class="btn btn-primary shareEmail" data-resultIndex="<?php //echo $orderid;?>" data-agentid="<?php //echo $agentid;?>" style="margin-left: 10px;">Send Email</button>
							
							
						</div>
					</div>
				</div>
			 </div>
		  </div>
		  <!-- /.modal-content -->
	   </div>
	   <!-- /.modal-dialog -->
	</div>
<script type="text/javascript">

function openBBPSReciept(e){
      $('#openRechargeReciept').modal('show');
	    $("#emailTransId").val($(e).data('id'));
      $.ajax({
          type: "GET",
          url: "/bbps/getBBPSReciept",
          data: {id:$(e).data('id')},
          
          success: function (response) {
           
      $('#openRechargeReciept').find('.modal-body').html(response);
         
          }
      });
  }
  
  $(document).ready(function() {
		$(".shareEmail").click(function() {
			$(".shareEmail").html('Sending...');
			 $('.shareEmail').prop('disabled', true);
			var orderid = $("#emailTransId").val();
			var emailcommaVal = $("#emailshare").val();
			if (emailcommaVal === '') {
				Swal.fire({
					type: 'error',
					title: 'Error',
					text: 'Email empty',
				})
			}
			else if(emailcommaVal!=''){ 
				if(validateMultipleEmailsCommaSeparated(emailcommaVal,',')){
					$.ajax({  
						type: "POST",
						url: "/crecharge/sendEmailReciept",
						dataType: "json",
						headers:{ 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
						data:{email:emailcommaVal,orderid:orderid},
						success: function(response){
							$(".shareEmail").html('Send Email');
							$('.shareEmail').prop('disabled', false);
							if(response.error=='1'){
								Swal.fire({
									title: "Error!",
									html: response.message,
									allowOutsideClick: true
							
								})
								return false;
							}
							else
							{
								Swal.fire({
									title: 'Success',
									html: response.message,
									allowOutsideClick: false
					
								}).then((result) => {
									if (result.value) {
										$('#emailPop').modal('toggle');
									}
									
								})
							}
						}
					}); 
				}
				else
				{
					Swal.fire({
							type: 'error',
							title: 'Error',
							text: 'Please enter valid email address'
						})
				}
				
				return false;
			}
		});

		function validateEmail(field) {
			var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/;
			return (regex.test(field)) ? true : false;
		}
		function validateMultipleEmailsCommaSeparated(value, seperator) {
			//var value = emailcntl.value;
			if (value != '') {
				var result = value.split(seperator);
				for (var i = 0; i < result.length; i++) {
					if (result[i] != '') {
						if (!validateEmail(result[i])) {
							//emailcntl.focus();
							//alert('Please check, `' + result[i] + '` email addresses not valid!');
							return false;
						}
					}
				}
			}
			return true;
		}
	});
</script>

@endsection