<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	$sidenav_file=APPPATH.'views/include/sidenav.php';
	require($sidenav_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">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">Product DC Report
                      </li>
                    </ol>
                  </div>
                </div>
              </div>
            </div>
            <div class="content-body"><!-- Basic form layout section start -->
                <section id="basic-form-layouts">
                    <div class="row justify-content-md-center">
                        <div class="col-md-12">
                            <div class="card">
                                <!--/* search_issueReport*/exportIssueReport-->
                                <div class="card-content collapse show">
                                    <div class="card-body">
                                        <form method="post" autocomplete="off" action="<?php echo site_url('ExcelReport/search_issueDCReportPrev');?>" method="POST">
                                            <div class="row justify-content-md-center">
                                                <?php $umane = $_SESSION['username']; ?>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="from_date"  id="from_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date" >
                                                    </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="to_date"  id="to_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="To Date">
                                                        <input class="form-control " type="hidden" name="report_type"  id="report_type"  value="product_dc">
                                                    
                                                    </div>
                                                </div>
                                                <!--<div class="col-md-2">
                                                    <div class="form-group">
                                                        <select id="report_type" name="report_type" class="select2" >
                                                            <option value="">Select</option>
                                                            <option value="product_dc">Product DC Report</option>
                                                            <option value="product_tax">Product Tax Report</option>
                                                            <option value="item_dc">Item DC Report</option>
                                                            <option value="item_tax">Item Tax Report</option>
                                                        </select>
                                                    </div>
                                                </div>-->
                                                <div class="col-md-2">
                                                    <div class="form-group">
                                                        <select id="branch" name="branch" class="form-control select2" >
                                                            <option value="">Branch</option>
                                                            <option value="All">All</option>
                                                            <?php  foreach($outlet as $row)
                                                            {
                                                            ?>
                                                            <option value="<?php echo $row->outlet; ?>"><?php echo $row->outlet; ?></option>
                                                            <?php
                                                            } 
                                                            ?>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-2">
                                                    <div class="form-group">
                                                        <select name="item_name" id="item_name" class="form-control select2" >
                                                            <option value="">Select Item</option>
                                                            <option value="All">All</option>
                                                            <?php  foreach($items as $row1)
                                                            {
                                                            ?>
                                                            <option value="<?php echo $row1->rname ?>"><?php echo $row1->rname ?></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="col-sm-12">
                                            <div class="table-responsive">
                                                <?php
                                                if(isset($_POST['submit'])) {
                                                ?>
                                
<?php
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-sm-2">
                                        <input type="text" name="from_date" id="from_date" class="form-control" readonly value="<?php echo $_POST['from_date']; ?>">
                                    </div>
                                    <div class="col-sm-2">	
                                        <input type="text" name="to_date" id="to_date" class="form-control" readonly value="<?php echo $_POST['to_date']; ?>">
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="text" name="outlet_name" id="outlet_name1" class="form-control" readonly value="<?php echo $report_type; ?>">
                                    </div>
                                    <div class="col-sm-3">
                                        <input type="text" name="outlet_name" id="outlet_name1" class="form-control" readonly value="<?php echo $branch; ?>">
                                    </div>
                                    <div class="col-sm-3">
                                        <input type="text" name="outlet_name" id="outlet_name1" class="form-control" readonly value="<?php echo $item_name; ?>">
                                    </div>
                                </div>
        <?php
        
        if(isset($report_type) == 'product_dc')
        {
			//echo $report_type;
			//if($_POST['branch'] == 'All' && $_POST['item_name'] != 'All')
			//{
    			if($branch == 'All' && $item_name == '')
    			{
    				//$query = $this->db->query("SELECT P.`issue_id`,  P.`issue_no`,  P.`invoice_no`,  P.`vehicle_name`, P.`issue_date`,  P.`issue_time`, P.`outlet`, P.`branchname`,  P.`total_amount` FROM product_issues_creation P where P.issue_date between '$f_date' AND '$t_date' and P.invoice_type='DC_invoice23'");
    			//<h1>1t</h1>
    			
    			?>
    			
    			<table class="table table-striped table-bordered dataex-html5-export">
					<thead class="thead-dark">
						<tr>
						    <th>Sl No</th>
							<th>Issue No</th>
							<th>Dc No</th>
							<th>Issue Date</th>
							<th>Outlet</th>
							<th>Total Amount</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$i=1;
						foreach ($result_display as $record) { 
						?>
						<tr >
							<td><span ><?php echo $i; ?></span></td>
							<td><span ><?php echo $record['issue_no'] ?></span></td>
							<td ><span ><?php echo $record['invoice_no']; ?></span></td>
							<td ><span ><?php echo date('d-m-Y',strtotime($record['issue_date'])); ?></span></td>
						    <td ><span ><?php //echo $record['outlet'];
						    $oname=$record['outlet'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
						    ?></span></td>
							<td ><span ><?php 
						echo number_format((float)$record['total_amount'], 2, '.', '');
						//	echo round($record['total_amount'],2); ?></span></td>
						</tr>
							<?php
								$i++;
							} ?>
					</tbody>
				</table>	    
    			<?php    
    			}
    			else if($branch == 'All' && $item_name != '')
    			{
    				//$query = $this->db->query("SELECT ANY_VALUE(PI.issue_item_name) as product_name,ANY_VALUE(P.outlet) as outlet_name,ANY_VALUE(sum(PI.issued_qty)) as quantity,ANY_VALUE(sum(PI.issued_qty)*PI.total_price) as total FROM product_issues_creation P inner join product_issues_item PI on P.issue_id=PI.issue_id where P.issue_date between '$f_date' AND '$t_date' and PI.issue_item_name='$product_name' and P.invoice_type='DC_invoice23' group by P.outlet");
    			    //<h1>2nd</h1> 
    			?>
    			   
    			    <table class="table table-striped table-bordered dataex-html5-export">
						<thead class="thead-dark">
							<tr>
							    <th>Sl No</th>
								<th>Product Name</th>
								<th>Outlet</th>
								<th>Quantity</th>
								<th>Total</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$i=1;
							foreach ($result_display as $record) { 
							?>
								<tr >
									<td><span ><?php echo $i; ?></span></td>
									<td><span ><?php echo $record['product_name'] ?></span></td>
									<td ><span ><?php //echo $record['outlet_name'];
									$oname=$record['outlet_name'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
									?></span></td>
									<td ><span ><?php echo $record['quantity']; ?></span></td>
								    <td ><span ><?php 
								    echo number_format((float)$record['total'], 2, '.', '');
								    //echo round($record['total'],2); ?></span></td>
								</tr>
								<?php
									$i++;
								} ?>
						</tbody>
					</table>	    
    			<?php
    			}
    		//}		
    		else if($branch != 'All' && $item_name == 'All')
    		{
    			//$query = $this->db->query("SELECT ANY_VALUE(PI.`issue_item_name`) as product_name,ANY_VALUE(P.outlet) as outlet_name,ANY_VALUE(sum(PI.`issued_qty`)) as quantity,ANY_VALUE(sum(PI.`total_price`)) as total FROM product_issues_creation P inner join product_issues_item PI on P.issue_id=PI.issue_id where P.issue_date between '$f_date' AND '$t_date' and P.outlet='$outlet_name' and P.invoice_type='DC_invoice23' group by PI.issue_item_name");
    		    //<h1>3rd</h1>
    		    ?>
    		    
    			 <table class="table table-striped table-bordered dataex-html5-export">
						<thead class="thead-dark">
							<tr>
							    <th>Sl No</th>
								<th>Product Name</th>
								<th>Outlet</th>
								<th>Quantity</th>
								<th>Total</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$i=1;
							foreach ($result_display as $record) { 
							?>
								<tr >
									<td><span ><?php echo $i; ?></span></td>
									<td><span ><?php echo $record['product_name'] ?></span></td>
									<td ><span ><?php //echo $record['outlet_name']; 
									$oname=$record['outlet_name'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
									?></span></td>
									<td ><span ><?php echo $record['quantity']; ?></span></td>
								    <td ><span ><?php 
								    echo number_format((float)$record['total'], 2, '.', '');
								    //echo round($record['total'],2); ?></span></td>
								</tr>
								<?php
									$i++;
								} ?>
						</tbody>
					</table>
    			<?php
    		}
    		//else if($_POST['branch'] != 'All' && $_POST['item_name'] != 'All')
    		//{
    		else if($branch != 'All' && $item_name == '')
    			{
    				//$query = $this->db->query("SELECT `issue_id`,  `issue_no`,  `invoice_no`,  `vehicle_name`, `issue_date`,  `issue_time`, `outlet`, `branchname`,  `total_amount` FROM product_issues_creation  where outlet='$outlet_name' and issue_date between '$f_date' AND '$t_date' and invoice_type='DC_invoice23'");
    			    //<h1>4th</h1>
    			    ?>
    			    
    			    <table class="table table-striped table-bordered dataex-html5-export">
					<thead class="thead-dark">
						<tr>
						    <th>Sl No</th>
							<th>Issue No</th>
							<th>Dc No</th>
							<th>Issue Date</th>
							<th>Outlet</th>
							<th>Total Amount</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$i=1;
						foreach ($result_display as $record) { 
						?>
						<tr >
							<td><span ><?php echo $i; ?></span></td>
							<td><span ><?php echo $record['issue_no'] ?></span></td>
							<td ><span ><?php echo $record['invoice_no']; ?></span></td>
							<td ><span ><?php echo date('d-m-Y',strtotime($record['issue_date'])); //echo $record['issue_date']; ?></span></td>
						    <td ><span ><?php //echo $record['outlet'];
						    $oname=$record['outlet'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
						    ?></span></td>
							<td ><span ><?php //echo round($record['total_amount'],2); 
							echo number_format((float)$record['total_amount'], 2, '.', '');
							?></span></td>
						</tr>
							<?php
								$i++;
							} ?>
					</tbody>
				</table>	    
    			<?php
    			}
    			else if($branch != 'All' && $item_name != '')
    			{
    				//$query = $this->db->query("SELECT ANY_VALUE(PI.issue_item_name) as product_name,ANY_VALUE(P.outlet_name) as outlet_name,ANY_VALUE(sum(PI.`issued_qty`)) as quantity,ANY_VALUE(sum(PI.`issued_qty`)*PI.`total_price`) as total FROM product_issues_creation P inner join product_issues_item PI on P.issue_id=PI.issue_id where P.issue_date between '$f_date' AND '$t_date' and P.outlet='$outlet_name' and PI.issue_item_name='$product_name' and P.invoice_type='DC_invoice23' group by PI.issue_item_name");
    			//<h1>5th</h1>
    			?>
    			
    			<table class="table table-striped table-bordered dataex-html5-export">
						<thead class="thead-dark">
							<tr>
							    <th>Sl No</th>
								<th>Product Name</th>
								<th>Outlet</th>
								<th>Quantity</th>
								<th>Total</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$i=1;
							foreach ($result_display as $record) { 
							?>
								<tr >
									<td><span ><?php echo $i; ?></span></td>
									<td><span ><?php echo $record['product_name'] ?></span></td>
									<td ><span ><?php //echo $record['outlet_name'];
									$oname=$record['outlet_name'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
									?></span></td>
									<td ><span ><?php echo $record['quantity']; ?></span></td>
								    <td ><span ><?php //echo round($record['total'],2); 
								    echo number_format((float)$record['total'], 2, '.', '');
								    ?></span></td>
								</tr>
								<?php
									$i++;
								} ?>
						</tbody>
					</table>
    			<?php
    			}
    		//}
    		else if($branch == 'All' && $item_name == 'All')
    		{
    			//$query=$this->db->query("SELECT P.`invoice_no` as DC_NO,P.issue_date,sum(PI.basic_price) as basic_price,P.`outlet`,sum(PI.total_price) as total_price,P.issue_id FROM product_issues_creation P inner join product_issues_item PI on P.issue_id=PI.issue_id where P.`entry_date` between '$f_date' AND '$t_date' and P.invoice_type='DC_invoice23'  group by P.`issue_id`");
    			//and P.issue_status!='Cancel'
    			//<h1>6th</h1>
    			?>
    			
    			<table class="table table-striped table-bordered dataex-html5-export">
					<thead class="thead-dark">
						<tr>
						    <th>Sl No</th>
							<th>Invoice No</th>
							<th>Issue Date</th>
							<th>Outlet</th>
							<th>Basic Price</th>
							<th>Total Amount</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$i=1;
						foreach ($result_display as $record) { 
						?>
						<tr >
							<td><span ><?php echo $i; ?></span></td>
							<td><span ><?php echo $record['DC_NO'] ?></span></td>
						    <td ><span ><?php echo date('d-m-Y',strtotime($record['issue_date']));//echo $record['issue_date']; ?></span></td>
						    <td ><span ><?php //echo $record['outlet'];
						    $oname=$record['outlet'];
						    	$query = $this->db->query("select * from address where outlet='$oname'");
        						foreach($query->result_array() as $row)
        						$org_names=$row['org_name'];
        						echo $org_names;
						    ?></span></td>
						    <td ><span ><?php //echo round($record['basic_price'],2); 
						    echo number_format((float)$record['basic_price'], 2, '.', '');
						    ?></span></td>
							<td ><span ><?php //echo round($record['total_price'],2);
							echo number_format((float)$record['total_price'], 2, '.', '');
							?></span></td>
						</tr>
							<?php
								$i++;
							} ?>
					</tbody>
				</table>
    			<?php
    		}
			
		}
        ?>		
                            	
						<!--		<div class="row">
									<div class="col-sm-3">
										<input type="text" name="from_date" id="from_date" class="form-control" readonly value="<?php echo $_POST['from_date']; ?>">
									</div>
									<div class="col-sm-3">	
										<input type="text" name="to_date" id="to_date" class="form-control" readonly value="<?php echo $_POST['to_date']; ?>">
									</div>
									<div class="col-sm-3">
										<input type="text" name="outlet_name" id="outlet_name1" class="form-control" readonly value="<?php //echo $_POST['outlet_name']; ?>">
									</div>
								
								</div>
										<br/>
							 <table class="table table-striped table-bordered dataex-html5-export">
							<thead class="thead-dark">
								<tr>
									<th>Product</th>
    								<th>HSN/SAC</th>
    								<th>Qty</th>
    								<th>Product Price</th>
    								<th>Nill Rate Tax</th>
    								<th>Basic(5%)</th>
    								<th>Basic(12%)</th>
    								<th>Basic(18%)</th>
    								<th>Tax(5%)</th>
    								<th>Tax(12%)</th>
    								<th>Tax(18%)</th>
    								<th>Amt</th>
								</tr>
							</thead>
							<tbody>
								<?php
								/*$i=0;
									$total_price = 0;
								$zbasic = 0;
								$fbasic = 0;
								$tbasic = 0;
								$ebasic = 0;
								$ftax = 0;
								$ttax = 0;
								$etax = 0;
									//if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
										foreach ($result_display as $record) { 
										    
										    $total_price = $total_price + $record['total_amount'];
									if($record['tax'] == '0') {
									    $zbasic = $zbasic + round(($record['total_amount'] - $record['Tax_0']),2);
									   // $sd_ftax = $sd_ftax + round($sd_report->sd_item_tax_amt,2);
									}
									if($record['tax'] == '5') {
									    $fbasic = $fbasic + round(($record['total_amount'] - $record['Tax_5']),2);
									   // echo $fbasic;echo "<br/>";
									    
									    $ftax = $ftax + ($record['qty']*$record['Tax_5']);
									    //echo $record['Tax_5']; echo "<br/>";
									    //echo $ftax;echo "<br/>";
									}
									if($record['tax'] == '12') {
									    $tbasic = $tbasic + round(($record['total_amount'] - $record['Tax_12']),2);
									    $ttax = $ttax + ($record['qty']*$record['Tax_12']);
									    // echo $record['Tax_12']; echo "<br/>";
									    //echo $ttax;
									}
									if($record['tax'] == '18') {
									    $ebasic = $ebasic + round(($record['total_amount'] - $record['Tax_18']),2);
									    $etax = $etax + ($record['qty']*$record['Tax_18']); 
									    // echo $record['Tax_18']; echo "<br/>";
									    //echo $etax;echo "<br/>";
									}
									?>
									<tr >
										
										<td>
											<span ><?php echo $record['issue_item_name'] ?></span>
										</td>
										<td >
											<span ><?php echo $record['hsn_code']; ?></span>
										</td>
										<td >
											<span ><?php echo $record['qty']; ?></span>
										</td>
									
										<td >
											<span ><?php echo $record['price']; ?></span>
										</td>
											<td>
										    <span >0</span>
										    <?php if($record['tax']=='0'){
											?>
											<input type="hidden" id="" class="z_basic" value="<?php echo round($record['qty']*$record['price'],2) ?>">
										    <?php } ?>
										</td>
										<td>
											<?php if($record['tax']=='5'){
											?> <span ><?php
											$basic=round($record['price']/1.05,2);
											echo $record['qty']*$basic ?></span><input type="hidden" id="" class="f_basic" value="<?php echo $record['qty']*$basic ; ?>">
											<?php }else { echo "0"; } ?>
										</td>
										<td>
											<?php if($record['tax']=='12'){
											?> <span ><?php 
											$basic=round($record['price']/1.12,2);
											echo $record['qty']*$basic ?></span><input type="hidden" id="" class="t_basic" value="<?php echo $record['qty']*$basic ; ?>">
											<?php }else { echo "0"; } ?>
										</td>
										<td>
											<?php if($record['tax']=='18'){
											?> <span ><?php 
											$basic=round($record['price']/1.18,2);
											echo $record['qty']*$basic ?></span><input type="hidden" id="" class="e_basic" value="<?php echo $record['qty']*$basic; ?>">
											<?php }else { echo "0"; } ?>
										</td>
										
										<td>
											<span ><?php echo $record['qty']*$record['Tax_5']; ?></span><input type="hidden" id="" class="f_tax" value="<?php echo $record['qty']*$record['Tax_5'] ; ?>">
										</td>
										<td>
											<span ><?php echo $record['qty']*$record['Tax_12']; ?></span><input type="hidden" id="" class="t_tax" value="<?php echo $record['qty']*$record['Tax_12'] ; ?>">
										</td>
										<td>
											<span ><?php echo $record['qty']*$record['Tax_18']; ?></span>
											<input type="hidden" id="" class="e_tax" value="<?php echo $record['qty']*$record['Tax_18'] ; ?>">
										</td>
										<td >
											<span ><?php echo $record['total_amount'] ?></span><input type="hidden" id="" class="total" value="<?php echo $record['total_amount']; ?>">
										</td>
										
									</tr>
									<?php
										$i++;
									} ?>
									
							</tbody>
						 	<tfoot>
							   <tr>
        								<td><strong>Total</strong></td>
        								<td></td>
        								<td></td>
        								<td></td>
        								<td id=""><strong><?php //echo $zbasic; ?></strong></td>
        								<td id="fbasic"><strong><?php //echo $fbasic; ?></strong></td>
        								<td id="tbasic"><strong><?php //echo $tbasic; ?></strong></td>
        								<td id="ebasic"><strong><?php //echo $ebasic; ?></strong></td>
        								<td id="ftax"><strong><?php //echo $ftax; ?></strong></td>
        								<td id="ttax"><strong><?php //echo $ttax; ?></strong></td>
        								<td id="etax"><strong><?php //echo $etax; ?></strong></td>
        								<td id="total_amt"><strong><?php //echo round($total_price);*/ ?></strong></td>
							
							        </tr>
							</tfoot>
						</table>-->
							
								<?php
									
								}
							}		
						} else { ?>	
						
					<?php } ?>
					<br/>
				 </div>
                    </div>
					</div>
				</div>
			</div>
		</div>
	</div>

</section>
<!-- // Basic form layout section end -->
        </div>
      </div>
    </div>
    <?php //require('include/theme_customizer.php');?>

   <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>

	</body>
</html>