<?php $__env->startSection('title', 'تحويل من خزنة إلي بنك'); ?>
 <?php $__env->startSection('content'); ?>
  <!-- BEGIN: Content-->
  <div class="app-content content ">
    <div class="content-overlay"></div>
    <div class="header-navbar-shadow"></div>
    <div class="content-wrapper container-xxl p-0">
      <div class="content-header row">
        <div class="content-header-left col-md-9 col-12 mb-2">
          <div class="row breadcrumbs-top">
            <div class="col-12">
              <h2 class="content-header-title float-start mb-0">
               تحويل من خزنة إلي بنك
              </h2>
              <div class="breadcrumb-wrapper">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="<?php echo e(route('client.home')); ?>">لوحة التحكم</a>
                  </li>
                  <li class="breadcrumb-item"><a href="<?php echo e(route('client.safes.index')); ?>">الخزن</a>
                  </li>
                  <li class="breadcrumb-item active"><?php echo e($safes->safe_name); ?>

                  </li>
                  <li class="breadcrumb-item active">التحويلات
                </li>
                <li class="breadcrumb-item active">البنوك
                </li>
                </ol>
              </div>
            </div>
          </div>
        </div>
        <div class="content-header-right text-md-end col-md-3 col-12 d-md-block d-none">
            <div class="mb-1 breadcrumb-right">
                <div class="dropdown">
                    <a  href="<?php echo e(route('client.banks.index')); ?>">
                        <button class="btn-icon btn btn-primary" type="button"><i data-feather='eye'> </i></button>
                    </a>
                </div>
              </div>
        </div>
      </div>
      <div class="content-body">
        <!-- Basic Horizontal form layout section start -->
        <!-- Basic multiple Column Form section start -->
<section id="multiple-column-form">
<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">البيانات الاساسية</h4>
      </div>
      <div class="card-body">
        <form class="form" id="addForm" action="#">
            <input type="hidden" name="company_id" value="<?php echo e($company_id); ?>">

            <?php echo csrf_field(); ?>
          <div class="row">
            <div class="col-md-6 col-12">
                <div class="mb-1">
                <b class="form-label"> الخزنة المحول منها </b>
                <select  class="form-control " readonly name="safe_id">
                        <option value="<?php echo e($safes->id); ?>"><?php echo e($safes->safe_name); ?> - <?php echo e($safes->balance); ?> <?php echo e($company->currency); ?> </option>
                </select>
             </div>
            </div>

            <div class="col-md-6 col-12">
                <div class="mb-1">
                <b class="form-label"> البنك المحول إليه </b>
                <select  class="form-control "  name="bank_id">
                    <option value="">إختر البنك المحول إلية</option>
                    <?php $__currentLoopData = $banks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($bank->id); ?>"  ><?php echo e($bank->bank_name); ?> - <?php echo e($bank->bank_balance); ?> <?php echo e($company->currency); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
             </div>
            </div>

            <div class="col-md-6 col-12">
                <div class="mb-1">
                <b class="form-label"> المبلغ </b>
                <input  class="form-control" name="amount" type="number" step="any" placeholder="مبلغ العملية">
            </div>
        </div>


            <div class="col-md-6 col-12">
                <div class="mb-1">
                <b class="form-label"> سبب العملية </b>
                <input  class="form-control" name="reason" type="text" placeholder="سبب العملية">
             </div>
            </div>

            <div class="col-12" align="center">
            <br>
              <button type="submit" class="btn btn-success me-1">إضافة</button>
              <button type="button" class="btn btn-outline-danger" onclick="window.history.back()">رجوع</button>
            </div>
          </div>
          
        </form>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">
            عمليات التحويل من ( <?php echo e($safes->safe_name); ?> ) إلي البنوك
        </h4>
      </div>
      <div class="card-body">
        <div class="table-responsive">
            <table id="example2" class="datatables-basic table dataTable no-footer dtr-column collapsed" aria-describedby="example2_info">

                <thead>
                    <tr>
                        <th >تحكم</th>
                        <th> الخزنة </th>
                        <th> البنك </th>
                        <th> المبلغ</th>
                        <th>السبب</th>
                        <th>المسؤول</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $__currentLoopData = $safe_bank_transfer; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transfer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr id="id-<?php echo e($transfer->id); ?>">
                            <td>
                                <a class="pe-1 dropdown-toggle -arrow text-primary" data-bs-toggle="dropdown">
                                  <i data-feather='more-vertical'style="width: 20;height: 20;"></i>
                                </a>
                                   <div class="dropdown-menu dropdown-menu-end">
                                    
                                   <a onclick="deleteRow(<?php echo e($transfer->id); ?>)" class="dropdown-item"><b> تراجع <i data-feather='rotate-cw'></b></i></a>
                                   </div>                       
                              </td>
                              <td><?php echo e($transfer->safe->safe_name); ?></td>
                              <td><?php echo e($transfer->bank->bank_name); ?></td>
                              <td>
                                  <?php echo e(floatval($transfer->amount)); ?>

                              </td>
                              <td><?php echo e($transfer->reason); ?></td>
                              <td><?php echo e($transfer->client->name); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
            </table>
        </div>
      </div>
    </div>
  </div>
</div>
</section>
<!-- Basic Floating Label Form section end -->

      </div>
    </div>
  </div>
  <!-- END: Content-->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
<script src="<?php echo e(asset('app-assets/js/jquery.dataTables.min.js')); ?>"></script>
<script src="<?php echo e(asset('app-assets/js/dataTables.bootstrap5.min.js')); ?>"></script>
<script src="<?php echo e(asset('app-assets/js/sweetalert.min.js')); ?>"></script>
<script>
       

    $(function () {
      $("#example2").DataTable();
     
    });
   $('#example2').DataTable({"language": { "url": "<?php echo e(asset('app-assets/data/locales/Arabic.json')); ?>"}}); 

   
   
        var selectForm = $('#addForm');

if (selectForm) {
    selectForm.validate({

        rules: {
      'bank_id': {
        required: true,
      },
      'safe_id': {
        required: true
      },
      'amount': {
        required: true
      }
      ,
      'reason': {
        required: true
      }
    
    
    }
  });
}

$("#addForm").on('submit',(function(e) {

e.preventDefault();

$.ajax({

  url: "<?php echo e(route('client.safe.bank.transfer.store')); ?>",

  type: "POST",

  data:  new FormData(this),

  dataType:  'json',

  contentType: false,

  cache: false,

  processData:false,
  
  beforeSend : function (){var ifConnected = window.navigator.onLine;if (!ifConnected) {toastr.info("يتم الآن إعادة الإتصال","لا يوجد إتصال بالإنترنت",{positionClass: "toast-top-right",tapToDismiss: !1,timeOut: 2e3,rtl: $("html").attr("data-textdirection")});}},

  success: function(response) {

    if(response.status){

            toastr.success("",response.message,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });      
            document.getElementById("addForm").reset();

    }else{
        toastr.warning("",response.message,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });   
    } 

  },
  error: function(response){
          $.each(response.responseJSON.errors, function (key, item) 
          {
            toastr.error("",item,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });

          });
  },

 });

}));

function deleteRow(id){

swal({

title: "هل أنت متأكد من التراجع عن هذه العملية؟",

type: "warning",

showCancelButton: true,

confirmButtonColor: "#DD6B55",

confirmButtonText: "تأكيد",

cancelButtonText: "إلغاء",

closeOnConfirm: false

}, function (isConfirm) {

if (!isConfirm) return;

$.ajax({

 url: "<?php echo e(route('client.safe.bank.transfer.destroy')); ?>",

   type: "post",

   data: {

       id: id,
       '_token':'<?php echo e(csrf_token()); ?>'
   },

   dataType: "html",
   beforeSend : function (){var ifConnected = window.navigator.onLine;if (!ifConnected) {toastr.info("يتم الآن إعادة الإتصال","لا يوجد إتصال بالإنترنت",{positionClass: "toast-top-right",tapToDismiss: !1,timeOut: 2e3,rtl: $("html").attr("data-textdirection")});}},

   success: function () {

       swal("تم الحذف بنجاح", "", "success");

         $("#id-" +id).remove()

   },

   error: function (xhr, ajaxOptions, thrownError) {

       swal("خطأ في الحذف ", "الرجاء المحاولة مرة آخري", "error");

   }

});

});
}
        </script>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('client.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/barasys/public_html/resources/views/client/banks/safe_bank_transfer.blade.php ENDPATH**/ ?>