<!DOCTYPE html>
<html>
<head>
<!-- TABLES CSS CODE -->
<?php include"comman/code_css_form.php"; ?>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Left side column. contains the logo and sidebar -->
  
  <?php include"sidebar.php"; ?>
 <?php
	if(!isset($country)){
      $country=$q_id="";
  }
 ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Cash Summary
        
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Cash Summary</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- ********** ALERT MESSAGE START******* -->
        <?php include"comman/code_flashdata.php"; ?>
        <!-- ********** ALERT MESSAGE END******* -->
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header with-border">
              <h3 class="box-title">Cash Summary</h3>
              <?php if($CI->permissions('places_add')) { ?>
              <div class="box-tools">
              </div>
            <?php } ?>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            <form class="form-horizontal">
            <div class="row">
              <div class="form-group">
                <label for="formDate" class="col-sm-4 control-label">Date</label>
                  <div class="col-sm-2">
                    <input type="date" class="form-control" id="formDate" name="formDate" value="<?php $date = new DateTime("now", new DateTimeZone('Asia/Colombo')); echo $date->format('Y-m-d');?>">
                  </div>
              </div>
              
                <div class="col-xs-12" id="preview_data">
                    <table style="width: 40%; padding-left: 50px;">
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Date</label></td>
                        <td style="width: 50%; text-align: center;"><label id="selected_date" name="selected_date"></label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Opening Balance</label></td>
                        <td style="width: 50%; text-align: right;"><label id="open_balance" name="open_balance" style="text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Cash Sale</label></td>
                        <td style="text-align: right;"><label id="cash_sale" name="cash_sale" style="text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Credit Payment</label></td>
                        <td style="text-align: right;"><label id="credit_payment" name="credit_payment" style="text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Cash Return</label></td>
                        <td style="text-align: right; color: red;"><label id="cash_return" name="cash_return" style="border: none; text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Expenses</label></td>
                        <td style="text-align: right; color: red;"><label id="expenses" name="expenses" style="border: none; text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Bank Deposit</label></td>
                        <td style="text-align: right; color:red;"><label id="bank_deposit" name="bank_deposit" style="border: none; text-align:right;">0.00</label></td>
                      </tr>
                      <tr style="height:40px;">
                        <td style="text-align: right; width: 50%;"><label>Balance</label></td>
                        <td style="text-align: right;"><label id="balance" name="balance" style="border: none; text-align:right;">0.00</label></td>
                      </tr>
                    </table>
                </div>
              </div>
              <div class="row">
                <br>
                <br>
                <div class="col-xs-8">
                <button type="button" class="btn btn-success" name="print_statement" id="print_statement" style="float:right;">Print</button>
                </div>
              </div>
            </form>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include"footer.php"; ?>
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<!-- SOUND CODE -->
<?php include"comman/code_js_sound.php"; ?>
<!-- TABLES CODE -->
<?php include"comman/code_js_datatable.php"; ?>

<script src="<?php echo $theme_link; ?>js/country.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    fill_tbData();
});
$("#formDate").change(function(){
    fill_tbData();
});
</script>

<script>
  function fill_tbData(){
      var from_date    = $('#formDate').val();

      $.ajax({
        url:"<?php echo site_url('cash/cash_info_get')?>",
        type: 'post',
        data: {from_date:from_date},
        dataType: 'json',
        success: function (data) {

          var open_balance = 0;
          var cash_balance = 0;
          var cash_return = 0;
          var expenses = 0;
          var bank_deposit = 0;
          var pay_balance = 0;

          $('#open_balance').empty();
          $('#cash_sale').empty();
          $('#credit_payment').empty();
          $('#cash_return').empty();
          $('#expenses').empty();
          $('#bank_deposit').empty();
          $('#balance').empty();
          $('#selected_date').empty();
          $('#selected_date').append(from_date);
          

            $.each(data.open_balance_info, function(){
              open_balance += parseFloat(this['open_amt']);
              $('#open_balance').append(this['open_amt']);
            });

            $.each(data.cash_sale_info, function(){
              cash_balance += parseFloat(this['cash_sale']);
              $('#cash_sale').append(this['cash_sale']);
            });

            $.each(data.payment_info, function(){
              pay_balance += parseFloat(this['cash_payment']);
              $('#credit_payment').append(this['cash_payment']);
            });

            $.each(data.cash_return_info, function(){
              cash_return += parseFloat(this['cash_return']);
              $('#cash_return').append(this['cash_return']);
            });

            $.each(data.expenses_info, function(){
              expenses += parseFloat(this['expense_amt']);
              $('#expenses').append(this['expense_amt']);
            });

            $.each(data.bank_info, function(){
              bank_deposit += parseFloat(this['bank_amt']);
              $('#bank_deposit').append(this['bank_amt']);
            });

            var balance = ((open_balance+cash_balance+pay_balance)-(cash_return+expenses+bank_deposit));
            $('#balance').append(balance.toFixed(2));
        },
        error: function (xhr, ajaxOptions, thrownError) {
          console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
      });
  }
</script>
<script>
    /*Print Div*/
    $("#print_statement").click(function(event) {
            PrintMe("preview_data");
            
         });

         function PrintMe(DivID) {
            var disp_setting="toolbar=yes,location=no,";
            disp_setting+="directories=yes,menubar=yes,";
            disp_setting+="scrollbars=yes,width=800, height=600, left=100, top=25";
               var content_vlue = document.getElementById(DivID).innerHTML;
               var docprint=window.open("","",disp_setting);
               docprint.document.open();
               docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"');
               docprint.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
               docprint.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">');
               docprint.document.write('<head><title>My Title</title>');
               docprint.document.write('<style type="text/css">body{ margin:0px;');
               docprint.document.write('font-family:verdana,Arial;color:#000;');
               docprint.document.write('font-family:Verdana, Geneva, sans-serif; font-size:12px;}');
               docprint.document.write('a{color:#000;text-decoration:none;} </style>');
               docprint.document.write('</head><body onLoad="self.print()">');
               docprint.document.write(content_vlue);
               docprint.document.write('</body></html>');
               docprint.document.close();
               docprint.focus();
            }
      </script>
<script type="text/javascript">
$(document).ready(function () { setTimeout(function() {$( ".alert-dismissable" ).fadeOut( 1000, function() {});}, 3000); });
</script>
<!-- Make sidebar menu hughlighter/selector -->
<script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>
		
</body>
</html>
