<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Sudila Printers</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<!-- text fonts -->
<link rel="stylesheet" href="assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
<![endif]-->
<style>
#preloader{
	background:#efefef4f url(assets/images/loading5.gif) no-repeat center center; height:100%;position:fixed;z-index:9999999;right:0;left:0;bottom:0;top:0;overflow-y:hidden;display:none
}
</style>
</head>
<body class="no-skin">
<div id="preloader"></div>
<?php include 'common/navbar.php'; ?>
<div class="main-container ace-save-state" id="main-container">
  <?php include 'common/sidebar.php'; ?>
  <div class="main-content">
    <div class="main-content-inner">
      <div class="breadcrumbs ace-save-state" id="breadcrumbs">
        <ul class="breadcrumb">
          <li> <i class="ace-icon fa fa-home home-icon"></i> <a href="home">Home</a> </li>
          <li class="active">Pending Bank Deposits </li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content">
        <div class="page-header">
          <h1>Pending Bank Deposits </h1>
        </div>
        <!-- /.page-header -->
        <div class="space-10"></div>
        <div class="row">
          <div class="col-xs-12">
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main">
                  <!-- div.table-responsive --> 
                  <!-- div.dataTables_borderWrap -->
                  <div class="table-responsive">
                    <table id="dynamic-table" class="table table-striped table-bordered table-hover">
                      <thead>
                        <tr>
						  <th>ID</th>
						  <th>Date</th>
						  <th>Order ID</th>
						  <th>Name</th>
						  <th>City</th>
						  <th>Contact No</th>
						  <th>Total Amount (Rs)</th>
						  <th>Accept/Reject</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
						$sql = mysqli_query($conn, "SELECT id, inv_no, f_name, l_name, tel_no, city, DATE_FORMAT(order_date, '%Y-%m-%d') AS date, grand_total FROM order_details WHERE pay_method = 3 AND order_status=0 AND payment_status=0 ORDER BY id DESC");
						$x = 0;
						while ($row = mysqli_fetch_array($sql)) {
							$x++;
						?>
                        <tr>
						  <td><?php echo $x; ?>.</td>
						  <td><?php echo $row['date']; ?></td>
						  <td><?php echo $row['inv_no']; ?></td>
						  <td><?php echo $row['f_name'] . " " . $row['l_name']; ?></td>
						  <td><?php echo $row['city']; ?></td>
						  <td><?php echo $row['tel_no']; ?></td>
						  <td align="right"><?php echo number_format($row['grand_total'], 2); ?></td>
						  <td align="center">
						  <div class="action-buttons">
						  <button value="<?php echo $row['id']; ?>" data-inv="<?php echo $row['inv_no']; ?>" class="btn btn-success btn-sm btn_accept" title="Accept"><i class="ace-icon fa fa-check"></i> </button> <button value="<?php echo $row['id']; ?>" class="btn btn-danger btn-sm btn_reject" title="Reject"><i class="ace-icon fa fa-times"></i> </button></td>
						  </div>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            <!-- PAGE CONTENT ENDS --> 
          </div>
          <!-- /.col --> 
        </div>
        <!-- /.row --> 
      </div>
      <!-- /.page-content --> 
    </div>
  </div>
  <!-- /.main-content -->
  <?php include 'common/footer.php'; ?>
</div>
<!-- /.main-container -->

<!-- basic scripts --> 
<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- <![endif]--> 
<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]--> 
<script type="text/javascript">
	if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script> 
<script src="assets/js/bootstrap.min.js"></script> 
<!-- page specific plugin scripts --> 
<!--[if lte IE 8]>
  <script src="assets/js/excanvas.min.js"></script>
<![endif]-->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>
<script src="assets/jquery.validate.min.js"></script>
<link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
<script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
<script src="assets/js/bootbox.js"></script>
<!-- inline scripts related to this page --> 
<script type="text/javascript">
jQuery(function ($) {
	//initiate dataTables plugin
	var myTable =
	$('#dynamic-table')
	//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
	.DataTable({
		bAutoWidth: false,
		"aaSorting": [],
	});
});

$(".btn_accept").on(ace.click_event, function() {
	 var row_id = $(this).val();
	 var inv = $(this).attr('data-inv');
	 var bb = bootbox.prompt({
		title: "Bank Deposit Details",
		placeholder: "Enter Slip No",
		inputType: 'text',
		onEscape: true,
		required : true,
		callback: function (result) {
            if (result === null) {
                return;
           
		    } else if (result === '') {
			    alert('Please Enter Slip No!');
                bb.find('.bootbox-input-text').addClass('input-validation-error');
                return false;
            
			} else {
				$("#preloader").fadeIn();
			  $.post('connection/online_order_conn', {'update_slip_no': 'data' , slip_no: result, inv : inv, oid : row_id}, function (data) {
				if(data.msgType === 1) {
					$("#preloader").fadeOut("slow");
				  swal({
					title: "",
					text: "Successfully Accepted!",
					type: "success",
					confirmButtonText: "OK"
					  },
					  function (isConfirm) {
					if (isConfirm) {
						location.reload();
					}
				  });
					
				} else if(data.msgType === 2) {
				  $("#preloader").fadeOut("slow");
				  swal("", "Slip No Already Exist. Please try again!", "warning");
				  return false;
				
				} else if(data.msgType === 3) {
				  $("#preloader").fadeOut("slow");
				  swal("", "Please Enter Slip No!", "warning");
				  return false;
					
				} else {
				  $("#preloader").fadeOut("slow");
				  swal("", "Something went wrong! Please Try Again!", "warning");
				}
				
			  }, "json");
			}
		}
	});
});

$(".btn_reject").click(function() {
  var row_id = $(this).val();
	swal({
	  title: "",
	  text: "Are you sure you want to reject this?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, Reject!",
	  cancelButtonText: "No, Cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$.post( "connection/online_order_conn", {reject_bank_deposit: "data", oid : row_id}, function( data ) {
			if (data.msgType === 1) {
			  swal({
				title: "",
				text: "Successfully Rejected!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					location.reload();
				}
			  });
			
			} else if (data.msgType === 4) {
			  swal("", "This order is already accepted!", "warning");
			  setTimeout(function () { location.reload(); }, 3000);
			
			} else{
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});
</script>
</body>
</html>