<!DOCTYPE html>
<html>
<head>
<?php include "comman/code_css.php"; ?>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <?php include "sidebar.php"; ?>
  <div class="content-wrapper">
    <section class="content-header">
      <h1><?= $page_title; ?> <small>Short / Over</small></h1>
      <ol class="breadcrumb">
        <li><a href="<?= $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="<?= $base_url; ?>cash_register">Cash Register</a></li>
        <li class="active"><?= $page_title; ?></li>
      </ol>
    </section>
    <section class="content">
      <div class="row">
        <div class="col-md-12">
          <div class="box box-primary">
            <div class="box-header with-border"><h3 class="box-title">Date range</h3></div>
            <form class="form-horizontal" id="report-form" onkeypress="return event.keyCode != 13;">
              <input type="hidden" name="<?= $this->security->get_csrf_token_name(); ?>" value="<?= $this->security->get_csrf_hash(); ?>">
              <input type="hidden" id="base_url" value="<?= $base_url; ?>">
              <div class="box-body">
                <div class="form-group">
                  <label for="from_date" class="col-sm-2 control-label">From date</label>
                  <div class="col-sm-3">
                    <input type="text" class="form-control datepicker" id="from_date" name="from_date" value="<?= show_date(date('d-m-Y', strtotime('-30 days'))); ?>">
                  </div>
                  <label for="to_date" class="col-sm-2 control-label">To date</label>
                  <div class="col-sm-3">
                    <input type="text" class="form-control datepicker" id="to_date" name="to_date" value="<?= show_date(date('d-m-Y')); ?>">
                  </div>
                </div>
              </div>
              <div class="box-footer">
                <button type="button" id="view" class="btn btn-success">Show</button>
                <a href="<?= $base_url; ?>cash_register" class="btn btn-default">Back to Cash Register</a>
              </div>
            </form>
          </div>
        </div>
        <div class="col-md-12">
          <div class="box">
            <div class="box-header"><h3 class="box-title">Closed sessions – variance (Short / Over)</h3></div>
            <div class="box-body table-responsive">
              <table class="table table-bordered table-hover" id="report-data">
                <thead>
                  <tr class="bg-blue">
                    <th>#</th>
                    <th>Closed date</th>
                    <th>User</th>
                    <th class="text-right">Drawer at start</th>
                    <th class="text-right">Cash from sales</th>
                    <th class="text-right">Expected</th>
                    <th class="text-right">Actual closing</th>
                    <th class="text-right">Variance</th>
                  </tr>
                </thead>
                <tbody id="tbodyid"></tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
  <?php include "footer.php"; ?>
  <div class="control-sidebar-bg"></div>
</div>
<?php include "comman/code_js_sound.php"; ?>
<?php include "comman/code_js.php"; ?>
<script>
$(function(){
  $("#view").on("click", function(){
    var from = $("#from_date").val(), to = $("#to_date").val();
    if (!from) { toastr["warning"]("Select From date"); return; }
    if (!to)   { toastr["warning"]("Select To date"); return; }
    $(".box").append('<div class="overlay"><i class="fa fa-refresh fa-spin"></i></div>');
    $.post("<?= $base_url; ?>cash_register/show_variance_report", {
      from_date: from,
      to_date: to,
      "<?= $this->security->get_csrf_token_name(); ?>": "<?= $this->security->get_csrf_hash(); ?>"
    }, function(html){
      $("#tbodyid").empty().append(html);
      $(".overlay").remove();
    });
  });
});
</script>
</body>
</html>
