<?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">Monthly Costing</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">Costing 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">
                                    <div class="card-content collapse show constrain-movement-container">
											<div class="card-body">								
												<div class="jqueryui-ele-container">
													<div class="tabs-default">
														<ul>
															<li>
																<a href="#finished_prdct" class="tab-col"> Finished Product</a>
															</li>
														</ul>
														
														<div id="finished_prdct">
												<?php
												$mon1 = date('F', strtotime('-6 month', time()));
												$mon2 = date('F', strtotime('-5 month', time()));
												$mon3 = date('F', strtotime('-4 month', time()));
												$mon4 = date('F', strtotime('-3 month', time()));
												$mon5 = date('F', strtotime('-2 month', time()));
												$mon6 = date('F', strtotime('-1 month', time()));
												?>
												<?php foreach($pcat as $pcrow)
												{
											?>
														    <a style="width: 100%;text-align:left;" href="#demo<?php echo $pcrow->pr_cat_id; ?>" class="btn btn-primary category_list" data-toggle="collapse"><?php echo $pcrow->pr_cat_name; ?></a>
														    <div id="demo<?php echo $pcrow->pr_cat_id; ?>" class="collapse">
														        <?php
												    $pc_id = $pcrow->pr_cat_id;
												    $prq = $this->db->query("select * from recipe where pr_cat_id='$pc_id' and branchname='CW_CHF' order by rname asc");
												    $items = $prq->result_array();
										foreach($items as $irow)
    								    {
    								        $costm1 = 0;
											$costm2 = 0;
											$costm3 = 0;
											$costm4 = 0;
											$costm5 = 0;
											$costm6 = 0;
											$rc_id = $irow['recipe_id'];
    								        $rc_yeild = $irow['yeild'];
    								        $sel_price = $irow['total_price'];
    								        $prq1 = $this->db->query("select B.item_name,B.qty as qty,A.$mon1 as rmon1,A.$mon2 as rmon2,A.$mon3 as rmon3,A.$mon4 as rmon4,A.$mon5 as rmon5,A.$mon6 as rmon6,(A.$mon1*B.qty) as mon1,(A.$mon2*B.qty) as mon2,(A.$mon3*B.qty) as mon3,(A.$mon4*B.qty) as mon4,(A.$mon5*B.qty) as mon5,(A.$mon6*B.qty) as mon6 from item_avg_price A inner join recipe_item B on A.item_id=B.item_id where B.recipe_id='$rc_id' order by B.item_name asc");
    								    $mcost = $prq1->result_array();
    								    
    								    $prq2 = $this->db->query("select B.item_name,B.qty as qty,A.$mon1 as rmon1,A.$mon2 as rmon2,A.$mon3 as rmon3,A.$mon4 as rmon4,A.$mon5 as rmon5,A.$mon6 as rmon6,(A.$mon1*B.qty) as mon1,(A.$mon2*B.qty) as mon2,(A.$mon3*B.qty) as mon3,(A.$mon4*B.qty) as mon4,(A.$mon5*B.qty) as mon5,(A.$mon6*B.qty) as mon6 from recipe_avg_cost A inner join sub_recipe_item B on A.recipe_id=B.sub_recipe_id where B.recipe_id='$rc_id' order by B.item_name asc");
    								    $mcost2 = $prq2->result_array();
    								    
    								    foreach($mcost as $mcosts)
    								    {
    								        $costm1 = $costm1 + $mcosts['mon1'];
        								    $costm2 = $costm2 + $mcosts['mon2'];
        								    $costm3 = $costm3 + $mcosts['mon3'];
        								    $costm4 = $costm4 + $mcosts['mon4'];
        								    $costm5 = $costm5 + $mcosts['mon5'];
        								    $costm6 = $costm6 + $mcosts['mon6'];
    								    }
    								    foreach($mcost2 as $mcosts2)
    								    {
    								        $costm1 = $costm1 + $mcosts2['mon1'];
        								    $costm2 = $costm2 + $mcosts2['mon2'];
        								    $costm3 = $costm3 + $mcosts2['mon3'];
        								    $costm4 = $costm4 + $mcosts2['mon4'];
        								    $costm5 = $costm5 + $mcosts2['mon5'];
        								    $costm6 = $costm6 + $mcosts2['mon6'];
    								    }
    								    ?>
    								    <a style="width: 100%;text-align:center;background-color:#7a3ae1!important;" href="#demo<?php echo $rc_id; ?>" class="btn btn-primary category_list" data-toggle="collapse"><?php echo $irow['rname']; ?></a>
    								    
    								    <div id="demo<?php echo $rc_id; ?>" class="collapse">
    								        
								        <table border="1" class="uk-table">
								            <tr style="text-align:center;">
												<th></th>
												<th>Selling Price</th>
												<th colspan="12">Cost</th>
											</tr>
											<tr style="text-align:center;">
												<th></th>
												<th></th>
												<th colspan="2"><?php echo $mon1; ?></th>
												<th colspan="2"><?php echo $mon2; ?></th>
												<th colspan="2"><?php echo $mon3; ?></th>
												<th colspan="2"><?php echo $mon4; ?></th>
												<th colspan="2"><?php echo $mon5; ?></th>
												<th colspan="2"><?php echo $mon6; ?></th>
											</tr>
								            <tr style="text-align:right;">
												<th style="text-align:center;">Item Name</th>
												<th style="text-align:center;"><?php echo $sel_price; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm1/$rc_yeild),2) : 000; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm2/$rc_yeild),2) : 000; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm3/$rc_yeild),2) : 000; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm4/$rc_yeild),2) : 000; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm5/$rc_yeild),2) : 000; ?></th>
												<th></th>
												<th><?php echo $rc_yeild != 0 ? number_format(($costm6/$rc_yeild),2) : 000; ?></th>
											</tr>
								            
											<tr style="text-align:right;">
												<th></th>
												<th>Qty</th>
												<th>Rate</th>
												<th>Value</th>
												<th>Rate</th>
												<th>Value</th>
												<th>Rate</th>
												<th>Value</th>
												<th>Rate</th>
												<th>Value</th>
												<th>Rate</th>
												<th>Value</th>
												<th>Rate</th>
												<th>Value</th>
											</tr>
											<?php 
											
    								    foreach($mcost as $mcosts)
    								    {
    								    ?>
    								    <tr style="text-align:right;">
											<td style="text-align:left;"><?php echo $mcosts['item_name']; ?></td>
											<td><?php echo number_format($mcosts['qty'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon1'],2); ?></td>
											<td><?php echo number_format($mcosts['mon1'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon2'],2); ?></td>
											<td><?php echo number_format($mcosts['mon2'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon3'],2); ?></td>
											<td><?php echo number_format($mcosts['mon3'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon4'],2); ?></td>
											<td><?php echo number_format($mcosts['mon4'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon5'],2); ?></td>
											<td><?php echo number_format($mcosts['mon5'],2); ?></td>
											<td><?php echo number_format($mcosts['rmon6'],2); ?></td>
											<td><?php echo number_format($mcosts['mon6'],2); ?></td>
										</tr>
										<?php } ?>
										<?php
										foreach($mcost2 as $mcosts2)
    								    {
    								    ?>
    								    <tr style="text-align:right;">
											<td style="text-align:left;"><?php echo $mcosts2['item_name']; ?></td>
											<td><?php echo number_format($mcosts2['qty'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon1'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon1'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon2'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon2'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon3'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon3'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon4'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon4'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon5'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon5'],2); ?></td>
											<td><?php echo number_format($mcosts2['rmon6'],2); ?></td>
											<td><?php echo number_format($mcosts2['mon6'],2); ?></td>
										</tr>
										<?php } ?>
										
										<tr style="text-align:center;">
											<td><strong>Output</strong></td>
											<td><strong><?php echo $rc_yeild; ?></strong></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										</tr>
										<tr style="text-align:right;">
											<td style="text-align:center;"><strong>Total Cost</strong></td>
											<td></td>
											<td></td>
											<td><strong><?php echo number_format(($costm1),2); ?></strong></td>
											<td></td>
											<td><strong><?php echo number_format(($costm2),2); ?></strong></td>
											<td></td>
											<td><strong><?php echo number_format(($costm3),2); ?></strong></td>
											<td></td>
											<td><strong><?php echo number_format(($costm4),2); ?></strong></td>
											<td></td>
											<td><strong><?php echo number_format(($costm5),2); ?></strong></td>
											<td></td>
											<td><strong><?php echo number_format(($costm6),2); ?></strong></td>
										</tr>
								        </table>
    								        
    								        </div>
    								    <?php } ?>
														       
														       
														 </div>
										<?php } ?>
														</div>
													
													</div>
												</div>
											</div>
										</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>