<?php 
$header_file=APPPATH.'views/include/header.php';
require($header_file);
?>
<!-- BEGIN: Content-->
<div class="app-content content">
    <div class="content-overlay"></div>
    <div class="content-wrapper">
        <div class="content-header row">
            <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
                <h3 class="content-header-title mb-0 d-inline-block">Top 10 Purchase Report</h3>
                <div class="row breadcrumbs-top d-inline-block">
                    <div class="breadcrumb-wrapper col-12">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="#">Home</a>
                            </li>
                            <li class="breadcrumb-item">
                                <a href="#">Report</a>
                            </li>
                            <li class="breadcrumb-item active">Top 10 Purchase Report
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-body"><!-- Zero configuration table -->
            <section id="configuration">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-content collapse show">
                                <div class="card-body card-dashboard">
                                    	<form autocomplete="off" method="POST" action="<?php echo site_url('ExcelReport/searchPurchaseVolume/');?>">
					            <div class="row">
							
								<div class="col-md-2">
									<div class="form-group">
										<select id="branch" name="branch" class="form-control select2" >
											<option value="">Branch</option>
											<?php  foreach($branch as $row)
												{
											?>
												<option value="<?php echo $row->branch_name; ?>"><?php echo $row->branch_name; ?></option>
											<?php
												} 
											?>
										</select>
									</div>
								</div>
							
								<div class="col-md-1">
									<div class="form-group">
										<input type="submit" name="submit" class="btn btn-primary " value="Search">
									</div>
								</div>
							</div>
						</form>
                                    <div class="table-responsive">
                                        	<?php
				if(isset($_POST['submit'])) {
					 
					if (isset($result_display)) {
						//echo "<p><u>Result</u></p>";
						if ($result_display == 'No record found !') {
							echo $result_display;
							} else {
						?>
						
						<table class="table table-striped table-bordered dataex-html5-export">
                                            <thead>
                                                <tr>
                                                    <th rowspan="2">Sl No</th>
                                                    <th rowspan="2">Category Name</th>
                                                    <th rowspan="2">Item Name</th>
                                                    <th rowspan="2">UOM</th>
                                                    <th colspan="2">
                                                        <?php echo date('M-Y', strtotime(date('Y-m')." -1 month")); ?></th>
                                                    <th colspan="2"><?php echo date('M-Y'); ?></th>
                                                </tr>
                                                <tr>
                                                    <th>Qty</th>
                                                    <th>Volume</th>
                                                    <th>Qty</th>
                                                    <th>Volume</th>
                                                </tr>
                                            </thead>
                                        <tbody>
                                            <?php
                                            $branch=$_POST['branch'];
                                                if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
						                    	foreach ($result_display as $data) {
                                            ?>
                                            <tr>
                                                <td><?php echo $i; ?></td>
                                                <td><?php echo $data['category_name']; ?></td>
                                                <td><?php echo $data['item_name']; ?></td>
                                                <td><?php echo $data['uom']; ?></td>
                                                <td><?php 
                                                    $month= date('m', strtotime(date('Y-m')." -1 month"));
                                                    $year=  date('Y', strtotime(date('Y-m')." -1 month"));
                                                    $litem_name=$data['item_name'];
                                                    $q=$this->db->query("select c.category_id,sum(a.grn_grand) as grn_grand,p.category_name,c.branchname,c.grn_price,MONTH(c.grn_date) as grn_date,MONTHNAME(c.grn_date) as grn_month,c.item_name,c.uom,c.itm_id, a.grn_item_qty, a.rejected_qty,sum(a.grn_item_qty-a.rejected_qty) as qty from grn_price c inner join purchase_order_grn a on c.purchase_grn_id = a.purchase_grn_id inner join add_category p on c.category_id=p.category_id where c.branchname='$branch' and MONTH(c.grn_date)='$month' and YEAR(c.grn_date)='$year' and c.item_name='$litem_name'");
                                                    foreach($q->result_array() as $row2)
                                                        $lqty = $row2['qty'];
                                                        $lvolume = $row2['grn_grand'];
                                                        echo $lqty;
                                                    ?></td>
                                                <td><?php echo number_format(round($lvolume)); ?></td>
                                                <td><?php echo $data['qty']; ?></td>
                                                <td><?php echo number_format(round($data['grn_grand'])); ?></td>
                                            </tr>
                                            	<?php
									$i++;
									} ?>
									<?php else:
								?>
								<tr>
									<td colspan="3" align="center" >No Records Found..</td>
								</tr>
								<?php
									endif;
								?>
                                            </tbody>
                                        </table>
						
						<?php }
					}
				}else{ ?>
                                        <table class="table table-striped table-bordered dataex-html5-export">
                                            <thead>
                                                <tr>
                                                    <th rowspan="2">Sl No</th>
                                                    <th rowspan="2">Category Name</th>
                                                    <th rowspan="2">Item Name</th>
                                                    <th rowspan="2">UOM</th>
                                                    <th colspan="2">
                                                        <?php echo date('M-Y', strtotime(date('Y-m')." -1 month")); ?></th>
                                                    <th colspan="2"><?php echo date('M-Y'); ?></th>
                                                </tr>
                                                <tr>
                                                    <th>Qty</th>
                                                    <th>Volume</th>
                                                    <th>Qty</th>
                                                    <th>Volume</th>
                                                </tr>
                                            </thead>
                                        <tbody>
                                            <?php
                                                $count =1;
                                                foreach($pvolume as $pv)
                                                {
                                            ?>
                                            <tr>
                                                <td><?php echo $count; ?></td>
                                                <td><?php echo $pv->category_name; ?></td>
                                                <td><?php echo $pv->item_name; ?></td>
                                                 <td><?php echo $pv->uom; ?></td>
                                                <td><?php 
                                                    $month= date('m', strtotime(date('Y-m')." -1 month"));
                                                    $year=  date('Y', strtotime(date('Y-m')." -1 month"));
                                                    $litem_name=$pv->item_name;
                                                    $q=$this->db->query("select c.category_id,sum(a.grn_grand) as grn_grand,p.category_name,c.branchname,c.grn_price,MONTH(c.grn_date) as grn_date,MONTHNAME(c.grn_date) as grn_month,c.item_name,c.uom,c.itm_id, a.grn_item_qty, a.rejected_qty,sum(a.grn_item_qty-a.rejected_qty) as qty from grn_price c inner join purchase_order_grn a on c.purchase_grn_id = a.purchase_grn_id inner join add_category p on c.category_id=p.category_id where c.branchname='CW' and MONTH(c.grn_date)='$month' and YEAR(c.grn_date)='$year' and c.item_name='$litem_name'");
                                                    foreach($q->result_array() as $row2)
                                                        $lqty = $row2['qty'];
                                                        $lvolume = $row2['grn_grand'];
                                                        echo $lqty;
                                                    ?></td>
                                                <td><?php echo number_format(round($lvolume)); ?></td>
                                                <td><?php echo $pv->qty; ?></td>
                                                <td><?php echo number_format(round($pv->grn_grand)); ?></td>
                                            </tr>
                                            <?php
                                                $count++;
                                                }
                                            ?>
                                            </tbody>
                                        </table>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<?php 
    $footer_file=APPPATH.'views/include/footer.php';
    require($footer_file);
?>
<script>
    $('.param_check').each(function() { $(this).on( {'click contextmenu': function() {
        //contextmenu
        var i = $(this).data('value');
        var anchor = $("a");
        var anchorTarget = $(this).parent().find('.parmetre').val();
        var submodid = $(this).parent().find('.submod_id').val();
        var link = $(this).attr('href');
        $(this).attr("href", link + submodid +'/'+anchorTarget);
        location.reload();
        }
        })
    })
</script>  
</body>
<!-- END: Body-->

<!-- Mirrored from pixinvent.com/modern-admin-clean-bootstrap-4-dashboard-html-template/html/ltr/vertical-modern-menu-template/form-layout-basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Apr 2020 09:38:02 GMT -->
</html>