<!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" />
<link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" href="assets/css/daterangepicker.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>
@media print {
  body * {
    visibility: hidden;
  }
  #print{
    display: none;
  }
  #print_view, #print_view * {
    visibility: visible;
  }
  #print_view {
    position: relative;
    font-size: 14px;
  }
  #print_view .widget-main{
	padding-top:0;
  }#print_view .widget-title {
    margin-top: 0;
  }
	#print_view .hide_s {
		display: block;
	}
}
.hide_s{
	display:none
}
</style>
</head>
<body class="no-skin">
<?php include 'common/navbar.php';
	if(isset($_GET['date']) && !empty($_GET['date'])) {
		$daterange = htmlspecialchars(strip_tags(trim($_GET['date'])), ENT_QUOTES, 'UTF-8');
		$date1 = substr($daterange, 0, 10);
		$date2 = substr($daterange, 13, 23);

	} else {
		$daterange = '';
		$date1 = $date2 = $date;
	}
?>
<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">GRN Report</li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content">
        <div class="page-header">
          <h1> GRN Report </h1>
        </div>
        <!-- /.page-header -->
        <div class="row">
          <div class="col-xs-12"> 
            <!-- PAGE CONTENT BEGINS -->
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main"> <br>
                  <!-- Content -->
				  <form id="form_submit" method="get">
					  <div class="form-group">
						<label>Select Date-range:<sup class="red">*</sup></label>
						<div class="input-group">
							<span class="input-group-addon">
								<i class="fa fa-calendar bigger-110"></i>
							</span>
							<input class="form-control" type="text" name="date" value="<?php echo $date1.' '.'-'.' '.$date2;?>" required>
						</div>
						<span class="help-block"></span>
					  </div><br>
					  <div class="form-group">
						<button class="btn btn-danger btn-sm"> SEARCH</button>
					  </div>
				  </form>
                  <!-- End Content --> 
                </div>
              </div>
            </div>
            <!-- /End .widget-box --> 
          </div>
        </div>
        <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 class="table-header"> View GRN Items</div>
                  <!-- 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>Invoice No</th>
							<th>Supplier</th>
							<th>Order No</th>
							<th>View Items</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
						$sql = mysqli_query($conn, "SELECT
supplier.name,
stock_orders.p_order,
stock_orders.stock_date,
stock_orders.invoice,
stock_orders.ref,
stock_orders.supp_id
FROM
stock_orders
Inner Join supplier ON stock_orders.supp_id = supplier.id
WHERE stock_orders.type='GRN' AND
stock_orders.stock_date BETWEEN '$date1' AND '$date2' ORDER BY stock_orders.stock_date DESC");
						$x = 0;
						while ($row = mysqli_fetch_array($sql)) {
							$x++;
						?>
                        <tr>
                          <td><?php echo $x; ?>.</td>
                          <td><?php echo $row['stock_date']; ?></td>
                          <td><?php echo $row['invoice']; ?></td>
                          <td><?php echo $row['name']; ?></td>
                          <td><?php echo $row['p_order']; ?></td>
                          <td align="center"><div class="action-buttons">
						  <button title="View Report" class="btn btn-primary btn-sm btn_view" data-toggle="modal" data-target="#view_data" data-ref="<?php echo $row['ref']; ?>" data-supp="<?php echo $row['supp_id']; ?>"> <i class="ace-icon fa fa-file-text-o"></i> </button> </div>
						  </td>
                        </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 -->

<!-- Model -->
<div id="view_data" class="modal fade" tabindex="-1">
	<div class="modal-dialog modal-lg">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			<h4 class="smaller lighter blue no-margin">GRN Items</h4>
		</div>
		  <div class="widget-body" id="print_view">
			<div class="widget-main">
                <div class="row hide_s">
                    <div class="col-md-12">
                      <div class="widget-header-large1"> <img class="pull-right" src="../images/logo/logo.png" width=150>
                        <h4 class="widget-title"><u>Buddhist Books</u></h4>
                        <p>Reg. Address: <br>
                          Website: www.buddhistbooksonline.com<br>
                          Facebook: <br>
                          Contact No: (+94) 37 223 4446</p>
                      </div>
                    </div>
                  </div>
                <div class="hr hide_s"></div>
				<h4 class="hide_s center"><b><u>GRN Items</b></u></h4>
				<p style="font-size:15px;">
				Invoice No: <b id="inv_val" class="clr"></b><br>
				Date: <b id="date_val" class="clr"></b><br>
				Supplier: <b id="sup_val" class="clr"></b><br>
				Order ID: <b id="oid_val" class="clr"></b><br>
				</p><br>
				<table class="table table-bordered tbl_data">
					<thead><tr>
						<th width="4%">#</th>
						<th width="40%">Item Name</th>
						<th width="12%">Retail Price</th>
						<th width="12%">Discount (%)</th>
						<th width="12%">Unit Cost</th>
						<th width="8%">Qty</th>
						<th width="12%">Total (Rs)</th>
					</tr></thead>
					<tbody>
					</tbody>
				</table>
				<h5><b>Total Cost: Rs. <span id='tot_cost'></span></b></h5>
			  <!-- End Content --> 
			</div>
		  </div>
		<div class="modal-footer">
			<button class="btn btn-primary btn-xs" id="print" onclick="jQuery('#print_view').print();"><i class="fa fa-print"></i> &nbsp;Print&nbsp;</button>
			<button class="btn btn-xs btn-default pull-right" data-dismiss="modal"> <i class="ace-icon fa fa-times"></i> Close </button>
		</div>
	</div>
	<!-- /.modal-content --> 
	</div>
	<!-- /.modal-dialog --> 
</div>
<!-- // Model -->

<!-- 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/bootstrap-datepicker.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/daterangepicker.min.js"></script>
<script type="text/javascript" src = "assets/print_plugin.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": [],
	});
	
	$('input[name=date]').daterangepicker({
		'applyClass' : 'btn-xs btn-success',
		'cancelClass' : 'btn-xs btn-default',
		locale: {
			applyLabel: 'Apply',
			cancelLabel: 'Cancel',
			format: 'YYYY-MM-DD'
		},
	})
	.prev().on(ace.click_event, function(){
		$(this).next().focus();
	});
});

$(".btn_view").click(function(){
	var ref = $(this).attr('data-ref');
	var supp = $(this).attr('data-supp');
	get_grn_items(ref, supp);
});

function get_grn_items(ref, supp) {
	$('.clr').text('');
	var tableData = '';
	var x = 0;
	var tcost = 0;
	
	$.post('connection/grn_conn', {'get_grn_items': 'data', ref_id: ref, supp: supp}, function (data) {
		$("#oid_val").text(data[0].p_order);
		$("#sup_val").text(data[0].sup_name);
		$("#date_val").text(data[0].stock_date);
		$("#inv_val").text(data[0].invoice);

		$.each(data[1], function (index, data) { x++;
			var tot = data.unit_cost * data.dr_qty;
			tableData += "<tr><td>"+x+".</td><td>"+data.name+"</td><td align='right'>"+data.r_price+"</td><td align='right'>"+data.discount+"</td><td align='right'>"+data.unit_cost+"</td><td align='right'>"+data.dr_qty+"</td><td align='right'>"+parseFloat(tot).toFixed(2)+"</td></tr>";
			
			tcost += tot;
		});
		
		$('.tbl_data tbody').html('').append(tableData);
		$('#tot_cost').text(parseFloat(tcost).toFixed(2));
		
	}, 'json');	
}

//document.querySelector("#print").addEventListener("click", function() {
	//window.print();
//});
</script>
</body>
</html>