<?php 
$header_file=APPPATH.'views/include/header.php';
require($header_file);
$this->db2 = $this->load->database('otherdb', TRUE);
?>
<!-- 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">Raw Material Consumption</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">Raw Material Consumption
                            </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/searchRawConsumption/');?>">
					            <div class="row">
							<div class="col-md-3">
									<div class="form-group">
										<!--<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="fmonth"  id="fmonth" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date">-->
									<input type="text" name="fmonth" id="fmonth" class="form-control date-picker">
									<?php 
                                    //$my_string = "Hello World!";//echo json_encode($my_string);
									?>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<!--<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="tmonth"  id="tmonth" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="To Date">-->
										<input type="text" name="tmonth" id="tmonth" class="form-control date-picker">
									</div>
								</div>
								<div class="col-md-3">
									<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_id; ?>"><?php echo $row->username; ?></option>
											<?php
												} 
											?>
										</select>
										<input type="hidden" name="bcode" id="bcode" class="form-control" >
									</div>
								</div>
							<!--	<div class="col-md-2">
									<div class="form-group">
										<select id="pcategory" name="pcategory" class="form-control select2" >
											<option value="">Category</option>
											<?php /* foreach($pcat as $pcrow)
												{
											?>
												<option value="<?php echo $pcrow->category_id; ?>"><?php echo $pcrow->category_name; ?></option>
											<?php
												} */
											?>
										</select>
										<input type="hidden" name="pcat" id="pcat" class="form-control" >
									</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'])) {
				    $fmonth = $_POST['fmonth'];
				    $tmonth = $_POST['tmonth'];
				    $branch_id = $_POST['branch'];
					 
					if (isset($result_display)) {
						//echo "<p><u>Result</u></p>";
						if ($result_display == 'No record found !') {
							echo $result_display;
							} else {
						?>
						
						<div class="row">
						    <div class="col-md-3">
						        <div class="form-group">
						            <input type="text" name="dept" id="dept" class="form-control" value="<?php echo $_POST['bcode']; ?>" readonly >
						        </div>
						    </div>
						 <!--   <div class="col-md-3">
						        <div class="form-group">
						            <input type="text" name="prcat" id="prcat" class="form-control" value="<?php //echo $_POST['pcat']; ?>" readonly >
						        </div>
						    </div>-->
						</div>
						<button onclick="method(btn)" class="btn btn-info pull-left" style="margin-bottom: 10px;">Export</button>
						<a href="<?php echo site_url('ExcelReport/consumptionAnalyze/'.$fmonth."/".$tmonth."/".$branch_id); ?>" target="_blank" id="view" name="view" class="btn btn-sm btn-info md-btn-success pull-right">Analyze BOM</a>
						<a href="<?php echo site_url('ExcelReport/rawconsumptionAnalyze/'.$fmonth."/".$tmonth."/".$branch_id); ?>" target="_blank" id="view" name="view" class="btn btn-sm btn-info md-btn-success pull-right" style="margin-right: 15px;">Analyze Raw Item</a>
						<table  id="tableID" border="1" style="border:1px solid!important;" class="table">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th colspan="5">Quantity Consumption Analysis</th>
                                                    <th>Rate</th>
                                                    <th colspan="3">Value Analysis</th>
                                                </tr>
                                                <tr>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th colspan="3">Actual Consumption Qty</th>
                                                    <th>Qty based on Production Update</th>
                                                    <th>Difference</th>
                                                    <th></th>
                                                    <th>Actual Consumption</th>
                                                    <th>BOM Consumption</th>
                                                    <th>Difference</th>
                                                </tr>
                                                <tr>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th colspan="3">Qty</th>
                                                    <th>Qty</th>
                                                    <th>Qty</th>
                                                    <th>Rate</th>
                                                    <th>Value</th>
                                                    <th>Value</th>
                                                    <th>Value</th>
                                                </tr>
                                                
                                            <tr>
                                                    <th>Category</th>
                                                    <th>Item</th>
                                                    <th>UOM</th>
                                                    <th>Consumption</br>(OP+IN-WST-CL)</th>
                                                    <th>Wastage</th>
                                                    <th>Total</br>(Con+Wst)</th>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                                    <th></th>
                                            </tr>
                                            </thead>
                                            
                                        <tbody>
                                           
                                            <?php
                                            //total
                                            $opttl = 0;
                                            $inttl = 0;
                                            $trinttl = 0;
                                            $troutttl = 0;
                                            $slttl = 0;
                                            $wstttl = 0;
                                            $clsttl = 0;
                                            $diffttl = 0;
                                            
                                            $br_id = $_POST['branch'];
                                            $fdate = date('Y-m-d',strtotime($_POST['fmonth']));
                                            $tdate = date('Y-m-d',strtotime($_POST['tmonth']));
                                                if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
						                    	foreach ($result_display as $data) {
						                    	   // if($data['cons_qty']!='0') { 
						                    	    $iname = $data['item_name'];
						                    	    $opttl = $opttl + $data['opening_stock'];
                                                    $inttl = $inttl + $data['tinward'];
                                                    $trinttl = $trinttl + $data['Transfer_in'];
                                                    $troutttl = $troutttl + $data['Transfer_out'];
                                                    $wstttl = $wstttl + $data['Wastage'];
                                                    $clsttl = $clsttl + $data['closing_stock'];
                                                    $cons = round(($data['opening_stock'] + $data['tinward']-$data['Wastage']-$data['closing_stock']),2);
                                                    $totalcon = $cons + $data['Wastage'];
                                                    $cons_diff = round(($totalcon - $data['cons_qty']),2);
                                                    
                                        $q2 = $this->db->query("select uom,item_price,item_tax from item_creation where item_name='$iname' and branchname='CW'");
						                $q2row = $q2->row_array();
						                $item_price = $q2row['item_price'];
						                $item_tax = $q2row['item_tax'];
						                $tax_amt = ($item_price*$item_tax)/100;
						                $item_rate = round(($item_price + $tax_amt),2);
						                $cons_value = round(($totalcon * $item_rate),2);
            		                    $bom_value = round(($data['cons_qty'] * $item_rate),2);	
            		                    $diff_value = round(($cons_value - $bom_value),2);
            		               ?>
                                            <tr>
                                                <td><?php echo $data['category_name']; ?></td>
                                                <td><?php echo $data['item_name']; ?></td>
                                                <td><?php echo $q2row['uom']; ?></td>
                                                <td><?php echo $cons; ?></td>
                                                <td><?php echo $data['Wastage']; ?></td>
                                               <td><?php echo $totalcon; ?></td>
                                               <td><?php echo round($data['cons_qty'],2); ?></td>
                                               <td><?php echo $cons_diff; ?></td>
                                               <td><?php echo $item_rate; ?></td>
                                               <td><?php echo $cons_value; ?></td>
                                               <td><?php echo $bom_value; ?></td>
                                               <td><?php echo $diff_value; ?></td>
                                           </tr>
                                           <?php
						                    //	}
									$i++;
									} ?>
									
									<?php 
								/*	foreach ($rcconsumption as $rcdata) {
									    $rciname = $rcdata['item_name'];
						                $rccons = $rcdata['opening_stock'] + $rcdata['tinward']-$rcdata['Wastage']-$rcdata['closing_stock'];
                                        $rctotalcon = $rccons + $rcdata['Wastage'];
                                        $rccons_diff = round(($rctotalcon - $rcdata['cons_qty']),2);
                                                    
                                        $q2 = $this->db->query("select uom,recipe_price from recipe where rname='$rciname' and branch_id='$br_id'");
						                $q2row = $q2->row_array();
						                $recipe_rate = $q2row['recipe_price'];
						                $rccons_value = round(($rctotalcon * $recipe_rate),2);
            		                    $rcbom_value = round(($rcdata['cons_qty'] * $recipe_rate),2);	
            		                    $rcdiff_value = round(($rccons_value - $rcbom_value),2);
									?>
									<tr>
                                        <td><?php echo $rcdata['category_name']; ?></td>
                                                <td align="left"><?php echo $rcdata['item_name']; ?></td>
                                                <td style="text-align:left!important;"><?php echo $q2row['uom']; ?></td>
                                               <td><?php echo $rccons; ?></td>
                                               <td><?php echo $rcdata['Wastage']; ?></td>
                                               <td><?php echo $rctotalcon; ?></td>
                                               <td><?php echo round($rcdata['cons_qty'],2); ?></td>
                                               <td><?php echo $rccons_diff; ?></td>
                                               <td><?php echo $recipe_rate; ?></td>
                                               <td><?php echo $rccons_value; ?></td>
                                               <td><?php echo $rcbom_value; ?></td>
                                               <td><?php echo $rcdiff_value; ?></td>
                                    </tr>
									<?php } */ ?>
									<?php else:
								?>
								
								<tr>
									<td colspan="3" align="center" >No Records Found..</td>
								</tr>
								<?php
									endif;
								?>
							        </tbody>
                                        </table>
						
						<?php }
					}
				}else{ ?>
                                        
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<?php 
    $footer_file=APPPATH.'views/include/footer.php';
    require($footer_file);
?>
<script type="text/javascript">
	$(function() {
		$('.date-picker').datepicker({
			changeMonth: true,
			changeYear: true,
			showButtonPanel: true,
		//	dateFormat: 'MM yy',
		    dateFormat: 'dd-mm-yy',
		/*	onClose: function(dateText, inst) { 
				$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
			}*/
		});
	});	
</script>
<script>
    $("#branch").change(function (){
		var branch_code = $(this).find("option:selected").text();
		$("#bcode").val(branch_code);
	});
	
	$("#pcategory").change(function (){
		var pcat = $(this).find("option:selected").text();
		$("#pcat").val(pcat);
	});
</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>