<?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">Raw Material</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="#">Raw Material</a>
                  </li>
                  <li class="breadcrumb-item active">Raw Material List
                  </li>
                </ol>
              </div>
            </div>
          </div>
        
        </div>
        <div class="content-body"><!-- Zero configuration table -->
<section id="configuration">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-content collapse show">
                    <div class="card-body card-dashboard">
                       <form method="post" autocomplete="off" action="<?php echo site_url('Master/searchAccCat/');?>" method="POST">
                        	<div class="row justify-content-md-left">
							
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="to_date"  id="to_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date">
									</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_name; ?>"><?php echo $row->branch_name; ?></option>
											<?php
												} 
											?>
										</select>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<select id="category_name" name="category_name" class="select2" >
											<option value="">Select Category</option>
											<?php  foreach($category as $row)
												{
											?>
												<option value="<?php echo $row->category_id; ?>"><?php echo $row->category_name; ?></option>
											<?php
												} 
											?>
										</select>
											<input type="hidden" name="cat_name" id="cat_name">
									</div>
								</div>
								<div class="col-md-3">
									<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 {
						?>
    				<?php		if($_POST['to_date']!="" && $_POST['branch']!="" && $_POST['category_name']==""){
					?>
					 <div class="row justify-content-md-left">
							
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="from_date"  id="uk_dp_1" value="<?php echo $_POST['to_date']; ?>" readonly >
									</div>
								</div>
								<div class="col-md-3">
								    <div class="form-group">
										<input class="form-control" type="text" name="branch_name1"  id="uk_dp_1" value="<?php echo $_POST['branch']; ?>" readonly >
									</div>
								</div>
								<div class="col-md-3">
    								<form method="post" action="<?php echo site_url('Master/exportCategoryReport/');?>">
            							<input type="hidden" name="to_date1" id="to_date1" value="<?php echo $_POST['to_date']?>" >
            							<input type="hidden" name="branches" id="branches" value="<?php echo $_POST['branch']?>" >
            							<input type="submit" name="export_category" class="btn btn-primary" value="Export">
            						</form>
            					</div>
							</div>
								<table class="table table-striped table-bordered dataex-html5-export">
									<thead>
										<tr>
											<th>Sl.No</th>
											<th>Category Name</th>
											<th>Product Name</th>
											<th>UOM</th>
											<th>Cls Stk</th>
											<th>Rate</th>
											<th>Tax</th>
											<th>Price</th>
											<th>Avg Price</th>
											<th>Vendor Name</th>
											<th>Value</th>
										</tr>
									</thead>
									<tbody>
										<?php
											
											$count = 1;
									
							if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
							foreach ($result_display as $data) { 
													$tax_a = ($data['item_price'] * $data['item_tax'])/100;
													$price = round(($data['item_price'] + $tax_a),2);
													$total = round(($data['closing_stock'] * $price),2);
												?>
												<tr>
													<td><?php echo $count ?></td>
													<td><?php echo $data['category_name']; ?></td>
													<td><?php echo $data['item_name']; ?></td>
													<td><?php echo $data['uom']; ?></td>
														<td><?php echo $data['closing_stock']; ?></td>
													<td><?php echo $data['item_price']; ?></td>
													<td><?php echo $data['item_tax']; ?></td>
													<td><?php echo $price; ?></td>
												<td><?php echo $data['avg_price']; ?></td>
													<td><?php echo $data['vendor_name']; ?></td>
												<td><?php echo $total; ?></td>
												</tr>
											<?php
									$count++;
									} ?>
									<?php else:
								?>
								<tr>
									<td colspan="8" align="center" >No Records Found..</td>
								</tr>
								<?php
									endif;
								?>
									</tbody>
								</table>
							</div>
						</div>
						
						<?php }
						else if($_POST['to_date']!="" && $_POST['branch']!="" && $_POST['category_name']!=""){
						?>
						<div class="row justify-content-md-left">
							
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="from_date"  id="uk_dp_1" value="<?php echo $_POST['to_date']; ?>" readonly >
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="branch_name1"  id="uk_dp_1" value="<?php echo $_POST['branch']; ?>" readonly >
								    </div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
									
										<input class="form-control" type="text" name="category_name1"  id="uk_dp_1" value="<?php echo $_POST['cat_name']; ?>" readonly >
									</div>
								</div>
								<div class="col-md-3">
								    <form method="post" action="<?php echo site_url('Master/exportCategory_Report/');?>">
            							<input type="hidden" name="to_date1" id="to_date1" value="<?php echo $_POST['to_date']; ?>" >
            							<input type="hidden" name="branch1" id="branch1" value="<?php echo $_POST['branch']; ?>" >
            							<input type="hidden" name="category" id="category" value="<?php echo $_POST['category_name']; ?>" >
            							<input type="hidden" name="cat" id="cat" value="<?php echo $_POST['cat_name']; ?>" >
            							<input type="submit" name="export_category" class="btn btn-primary" value="Export">
            						</form>
								</div>
							</div>
								<table class="table table-striped table-bordered dataex-html5-export">
									<thead>
										<tr>
											<th>Sl.No</th>
											<th>Category Name</th>
											<th>Product Name</th>
											<th>UOM</th>
											<th>Cls Stk</th>
											<th>Rate</th>
											<th>Tax</th>
											<th>Price</th>
											<th>Avg Price</th>
											<th>Value</th>
										</tr>
									</thead>
									<tbody>
										<?php
											//$userid=$_SESSION['userid'];
											//$branch_name=$_SESSION['branch_name'];
											$count = 1;
										if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
							foreach ($result_display as $data) { 	
													$tax_a = ($data['item_price'] * $data['item_tax'])/100;
													$price = round(($data['item_price'] + $tax_a),2);
													$total = round(($data['closing_stock'] * $price),2);
												?>
												<tr>
													<td><?php echo $count ?></td>
													<td><?php echo $data['category_name']; ?></td>
													<td><?php echo $data['item_name']; ?></td>
													<td><?php echo $data['uom']; ?></td>
														<td><?php echo $data['closing_stock']; ?></td>
													<td><?php echo $data['item_price']; ?></td>
													<td><?php echo $data['item_tax']; ?></td>
													<td><?php echo $price; ?></td>
													<td><?php echo $data['avg_price']; ?></td>
												<td><?php echo $total; ?></td>
												</tr>
											<?php
									$count++;
									} ?>
									<?php else:
								?>
								<tr>
									<td colspan="8" align="center" >No Records Found..</td>
								</tr>
								<?php
									endif;
								?>
									</tbody>
								</table>
							</div>
						</div>
						
						<?php }
							}
					}
					}else{ ?>
                            <table class="table table-striped table-bordered dataex-html5-export">
                                <thead>
                                    <tr>
                                        <th>Sl.No</th>
                                        <th>Category Name</th>
										<th>Product Name</th>
										<th>UOM</th>
										<th>Closing Stock</th>
										<th>Price</th>
										<th>Tax</th>
										<th>Average Price</th>
										<th>Vendor Name</th>
										<th>Edit</th>
								    </tr>
                                </thead>
                                <tbody>
								 <?php
									$count =1;
									foreach($rawItem as $record)
								{
								?>
                                    <tr>
                                        <td><?php echo $count;?></td>
                                        <td><?php echo $record->category_name; ?></td>
										<td> 
										
										<!--<a class="grid-form-dialog-btn btn btn-primary btn-sm" href="#medlist"  onclick="javascript:load_marks(<?php //echo $record['item_id']; ?>,<?php //echo $record['item_name']; ?>,<?php //echo $record['branchname']; ?>)" ><?php //echo $record['item_name'] ?></a>--> 
										
                            			<a class="grid-form-dialog-btn primary btn-sm" href="#medlist"  onclick="javascript:load_marks('<?php echo $record->item_id;?>','<?php echo $record->item_name;?>','<?php echo $record->br_name;?>')"><?php echo $record->item_name; ?><?php echo $record->branchname;?></a> 
										</td>
										
													<td><?php echo $record->uom; ?></td>
													<td><?php echo $record->stock_item; ?></td>
													<td><?php echo $record->item_price; ?></td>
													<td><?php echo $record->item_tax; ?></td>
													<td><?php echo $record->avg_price; ?></td>
													<td><?php echo $record->vendor_name; ?></td>
													<td>
										    <a href="<?php echo site_url('Master/itemCEOEdit/' . $record->item_id); ?>" class=""><i class="ft-eye"></i></a>
										</td>
									</tr>
                                    
                                   <?php
								  $count++;
								}
							  
							?>
                                </tbody>
                              
                            </table>
                            
                            	<?php 	
					} 
				 ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--/ Zero configuration table -->



<!--/ Language - Comma decimal place table -->

        </div>
      </div>
    </div>
    <!-- END: Content-->

   <?php //require('include/theme_customizer.php');?>
 <?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> 
<script>
$("#category_name").change(function(){
	var cid = $('#category_name').val();
	//alert(i_name);
	//alert(brname);
	$.ajax({
		type :'POST',
		dataType:'json',
		data : { cat_id : cid },
		url: "<?php echo site_url('Master/getCatname');?>",
		//url : 'get_category_name.php',
		success: function(data) {
			//alert(data.price);
			$('#cat_name').val(data.category_name);
		}
	});
});
</script>
<script>
function load_marks(item_id,item_name,branchname)
{
//	alert(item_id);
	//alert(item_name);
	//alert(branchname);
  $.ajax({
      type: "POST",
      data : { item_id : item_id,item_name : item_name,branchname:branchname },
      url: "<?php echo site_url('Master/single_rawItem');?>",
      //data: "item_id="+item_id+"item_name="+mid+"branchname="+branchname,
      success: function (response) {
         //alert(response);
         console.log(response);
        $(".grid-form-dialog").html(response);
        }
     });
  }
</script>
<div class="grid-form-dialog" id="" title="">
<?php 
$f_file=APPPATH.'views/master/Itemsingle_view.php';
	//require($header_file);
include($f_file); ?>
</div>