<?php
	include('common/header.php'); 
?>
<div class="row">
	<div class="col-xs-12">
        <section class="panel panel-default">
             <div class="panel-body bs-example form-horizontal">
		<div class="table-header">
			
		</div>
		<form class="form-horizontal" method="post" action="<?php echo base_url();?>index.php/gc/master_sale_data_report/excel_sale">
            <input type="hidden" name="excel_branch_id" value="<?php echo $this->_page_data['excel_branch_id']; ?>">
            <input type="hidden" name="excel_from" value="<?php echo $this->_page_data['excel_from']; ?>">
             <input type="hidden" name="excel_customer_id" value="<?php echo $this->_page_data['excel_customer_id']; ?>">
            <input type="hidden" name="excel_to" value="<?php echo $this->_page_data['excel_to']; ?>">
            <input type="hidden" name="excel_sale" value="<?php echo $this->_page_data['excel_sale']; ?>">
            <input type="hidden" name="excel_product_name_dispenser" value="<?php echo $this->_page_data['excel_product_name_dispenser']; ?>">
            <input type="hidden" name="excel_export" value="<?php echo 1; ?>">

            <input type="hidden" name="company_branch_name" value="<?php echo $company_branch_names; ?>">
            <input type="hidden" name="from" value="<?php echo $from; ?>">
            <input type="hidden" name="to" value="<?php echo $to; ?>">
            <input type="hidden" name="get_sale_person_firstname" value="<?php echo $get_sale_person_firstname; ?>">
            <input type="hidden" name="get_sale_person_lastname" value="<?php echo $get_sale_person_lastname; ?>">
            <input type="hidden" name="get_dispenser" value="<?php echo $get_dispenser; ?>">
            <input type="hidden" name="customer_id" value="<?php echo $customer_id; ?>">
           
                                <div class="">
                                    <!-- PAGE CONTENT BEGINS -->
                                    <?php if($company_branch_names!=""){?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Branch Name';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">                                       
                                         <?php echo $company_branch_names;?>
                                        </div>
                                        
                                    </div>
                                     <?php }?>
                                     <?php if($customer_id!=""){?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Customer Name';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">                                       
                                         <?php echo $customer_id;?>
                                        </div>
                                        
                                    </div>
                                    <?php }
                                     if($from!=""){
                                    ?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'From';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">  
                                            <?php echo $from?>
                                        </div>
                                    </div>
                                    <?php }
                                     if($to!=""){
                                    ?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'To';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">  
                                            <?php echo $to?>
                                        </div>
                                    </div>  
                                    <?php }
                                     if($get_sale_person_firstname!="" and $get_sale_person_lastname!=""){
                                    ?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Sale Person Name ';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">  
                                            <?php echo $get_sale_person_firstname." ".$get_sale_person_lastname;?>
                                        </div>
                                    </div>
                                    <?php }
                                     if($get_dispenser!=""){
                                    ?>
                                    <div class="form-group">  
                                        <label class="col-sm-5 control-label" for="form-field-2" ><?php echo 'Dispenser';?> :</label>
                                        <div class="col-sm-7" style="padding: 4px;">  
                                          <?php echo $get_dispenser;?>
                                        </div>
                                    </div>
                                <?php } ?>
                                     
                                </div>
								
		<div class="modal fade" id="exampleModal"  role="dialog">
		  <div class="modal-dialog" >
			<div class="modal-content">
			  <div class="modal-header">
			  </div>
			  <div class="modal-body">
				  <div class="form-group">
					<label for="recipient-name" class="col-form-label">Tracking Numbers:</label>
						<div id="tracking_div"></div>
				  </div>				 
			
			  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
			  </div>
			</div>
		  </div>
		</div>
		<div class="table-responsive">
		<table  id="example" cellspacing="0" width="100%" class="table table-bordered table-condensed">
            <thead>
                <tr>
                    <th class="text-center">Sr no</th>
                   <!--  <th class="text-center">Customer Name</th>
                    <th class="text-center">Address</th>
                    <th class="text-center">City</th>
                    <th class="text-center">Branch</th>
                    <th class="text-center">Sales Person Name</th>
                    <th class="text-center">Product Name</th>
                    <th class="text-center">Product Type</th>
                    <th class="text-center">Installation Date</th>
                    <th class="text-center">Price</th>
                    <th class="text-center">Sales Type</th>
                    <th class="text-center">Quantity</th>
                    <th class="text-center">Location</th>
                    <th class="text-center">Comments</th> -->

                      <?php foreach($fields as $field_name => $field_display): ?>
            <th <?php if ($sort_by == $field_name) echo "class=\"sorting_$sort_order\"" ?>>
            <?php echo anchor("gc/master_sale_data_report/master_sales_data_report_list/$get_customer_id/$query_id/$field_name/".
            (($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc'),
            $field_display); ?>     </th>
          <?php endforeach; ?>
                </tr>   
            </thead>
            <tbody>
                <?php 
                 $icnt=0;
                $count=count($sale_report);
            if ($count>0) {
                foreach ($sale_report as $value) {
                    
                    //$dispenser_sales_id=$value->dispenser_sales_id;
                    $customer_name=$value->customer_name;
                    $address=$value->address_line1." ".$value->address_line2;
                    $city_name=$value->city_name;
                    $company_branch_name=$value->company_branch_name;
                    $name=$value->first_name." ".$value->last_name;
                    $product_name=$value->product_name;
                    $product_type=$value->product_type;
                    $total=$value->total;
                    $sales_type=$value->sales_type;
                    $stock_quantity=$value->stock_quantity;
                    $refill_location=$value->refill_location;
                    $comments=$value->comments;
                    $dispenser_sales_id=$value->dispenser_sales_id;
                   // $dispenser_sales_id_search = $this->encrypt->encode($dispenser_sales_id);
                    $dispenser_refill_details_id=$value->dispenser_refill_details_id;
                    $installation_date= $value->installation_date;
                    //$product_id=$this->encrypt->encode($value->product_id);
                    //$c_id=$this->encrypt->encode($value->customer_id);
					
					$dispenser_sales_id_search=encrypt_decrypt_parameters($dispenser_sales_id,'encrypt');
					$product_id=encrypt_decrypt_parameters($value->product_id,'encrypt');
					$c_id=encrypt_decrypt_parameters($value->customer_id,'encrypt');
                    $icnt++;
                    $sr=$offset+$icnt;

                    

                    ?>        
                <tr>
                    <td class="text-center"><?php echo $sr; ?></td>
                    <td class="text-center"><?php echo $customer_name;?></td>
                    <td class="text-center"><?php echo $address;?></td>
                    <td class="text-center"><?php echo $city_name;?></td>
                    <td class="text-center"><?php echo $company_branch_name;?></td>
                    <td class="text-center"><?php echo $name;?></td>
                    <td class="text-center"><?php echo $product_name;?></td>
                    <?php if ($product_type=='Dispenser-FTU' || $product_type=='Dispenser' || $product_type=='Diffuser' || $product_type=='SANIPOD') {?>
                        <td class="text-center"><u><a href="<?php echo base_url();?>index.php/gc/master_sale_data_report/refill_sale_data_report/<?php echo $product_id;?>/<?php echo $c_id; ?>/<?php echo $dispenser_sales_id_search; ?>"><?php echo $product_type;?></a></u></td>
                   <?php }else{?>
                   <td class="text-center"><?php echo $product_type;?></td><?php } ?>                       
                    <?php 
                     if ($installation_date=='0000-00-00') {?>
                    <td><?php echo $installation_date; ?></td><?php }else{?>
                    <td><?php echo get_date_dmy_format_wo_time($installation_date); ?></td>
                    <?php } ?>
                    <td class="text-center"><?php echo $total;?></td>
                    <td class="text-center"><?php echo $sales_type;?></td>
					<?php if ($product_type=='Dispenser-FTU' || $product_type=='Diffuser' || $product_type=='SANIPOD') {?>
                    <td class="text-center" style="text-decoration: underline;cursor:pointer" data-toggle="modal" data-target="#exampleModal"  data-whatever="<?php echo $dispenser_refill_details_id?>"><?php echo $stock_quantity;?></td>
					<?php } else {?>
					 <td class="text-center"><?php echo $stock_quantity;?></td>
					<?php } ?>
                    <td class="text-center"><?php echo $refill_location;?></td>
                    <td class="text-center"><?php echo $comments;?></td>
                </tr> 
               <?php 
                //$srno=$srno+1;
                }
            }else{?>
                    <td colspan="14" class="text-center">no data found</td>
         <?php } ?>

        </tbody>
        </table>
		<?php
         if($num_results > 0)   { ?>
           
                <div class="clearfix">
                <div class="row">
                    <?php 
                        if (strlen($pagination)): 
                            $label_disp="sale reports";
                            $data['label_disp']=$label_disp;
                            $data['count']=$count;
                            $this->load->view('pagination_view.php',$data);
                        endif; ?>
                </div>
                </div>
                <div class="block"> </div>
            <?php } ?>
        </div>
</div>
   
    
</section>
          
		<div class="clearfix form-actions">
		  <div class="col-md-offset-5 col-md-5">
            <button class="btn btn-info" type="button" onclick="javascript:window.history.back();" >
                Back
            </button>			
            <button class="btn btn-info" type="submit">
                Export to Excel
            </button>
		  </div>
	</div>
    </form>
	</div>
</div>
<div>
	<!-- /.page-row -->
    <!-- /.page-content --> 
</div>
<!-- /.main-content --> 
</div>
<!-- /#ace-settings-container --> 
</div>
<!-- /.main-container-inner --> 
<?php
	include('common/footer.php');
?>
<script type="text/javascript">

$('#exampleModal').on('show.bs.modal', function (event) {
	$('#tracking_div').html("Loading....");
  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('whatever') // Extract info from data-* attributes
  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
  var modal = $(this)
	
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/master_sale_data_report/get_tacking_numbers",
    method:"POST",
    data:{
      dispenser_refill_details_id:recipient
    },
    success:function(data)
    {
     $('#tracking_div').html(data);
    }
   });
  modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body input').val(recipient)
})


</script>

