<!-- Content Wrapper. Contains page content -->
<?php
$userRol = $_SESSION['USERS_DATA']['userType'];
$userId = $_SESSION['USERS_DATA']['userId'];
if($userRol==1){
    $userName = "Wholesaler Name";
}else{
    $userName ="Customer Name";
}
?>
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header mb_6">
		<h1>Orders History</h1> </section>
	<section class="content-header">
		<div class="cutomer_info">
			<?php if(!empty($customersName)){ ?>
				<h4>Customer Name : <?php echo $customersName ?></h4>
				<h4>Customer Mobile : <?php echo $customersnumber ?></h4>
				<?php } ?>
		</div>
		<div class="date_filter">
			<form id="flight" class="datefilter" method="post" action="directsales/orders_history">
				<input type="hidden" id="customer_id" value="<?php if(!empty($customer_id)){echo $customer_id;} ?>">
				<input type="hidden" id="customerRol" value="<?php if(!empty($cancelCustomer)){echo 'customer';} ?>" >
				<label> Form date
					<br/>
					<input type="text" class="form_date form-control hasDatepicker" name="arrival" value="<?php if(!empty($from)){echo $from;} ?>" /> </label>
				<label> To date
					<br/>
					<input type="text" name="departure" class="to_date form-control hasDatepicker" value="<?php if(!empty($to)){echo $to;} ?>" /> </label>
				<label>
					<br/>
					<input class="btn btn-primary" type="submit" value="submit" /> </label>
			</form>
		</div>
	</section>
	<!-- Main content -->
	<section class="content">
		<div class="row">
			<div class="col-lg-12">
				<div class="box wholeSaleWrapper">
					<div class="box-body">
						<div class="table-responsive">
							<table id="hdlOrderPending" class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>No.</th>
										<th>Order No.</th>
										<th>Order Date</th>
										<th><?php echo $userName; ?></th>
										<th>Total Amount</th>
										<th>View</th>
										<th>Status</th>
									</tr>
								</thead>
                                    <tbody id="invoice_list">
                                    <?php  $total_amount = 0; if(!empty($allsales_invoice)){ 
                                        $countsales = count($allsales_invoice);
                                        $i = $countsales;
                                        $a =1;
                                        
                                        foreach($allsales_invoice as $sales_invoice){ 
                                            ?>
                                            <tr>
                                                <td>
                                                    <?php if(!empty($sales_invoice['id'])){ echo $a; }?>
                                                </td>
                                                <td>
                                                    <?php if(!empty($sales_invoice['id'])){ echo $sales_invoice['id']; }?>
                                                </td>
                                                <td>
                                                    <?php if(!empty($sales_invoice['saleDate'])){ 
                                                    $date = $sales_invoice['saleDate'];
                                                    $rdate = str_replace("/","-",$date);
                                                    $datem =date_create($rdate);
                                                    echo date_format($datem,"d-M-Y");
                                                    
                                                    } ?>
                                                </td>
                                                <td>
                                                    <?php if(!empty($userRol) && $userRol==1){ echo $sales_invoice['userName']; }else{ echo $sales_invoice['customerName']; }?>
                                                </td>
                                                <td>
                                                    <?php if(!empty($sales_invoice['totalAmount'])){ echo $sales_invoice['totalAmount']; }?>
                                                </td>
                                                <td>
                                                    <button class="btn-success icon_btn wholesales_InvoiceViewbtn" data-saleinvoiceid="<?php echo $sales_invoice['id']; ?>" title="View"><i class="fa fa-eye"></i></button>
                                                </td>
                                                <td>
                                                    <?php if($userRol !=1){ ?>
                                                    <select class="deliveryStatus form-control" data-deliveryStatus="<?php echo $sales_invoice['id'];?>" name="deliveryStatus">
                                					      <option value="2" <?php if($sales_invoice['deliveryStatus']==2){echo "selected";}?> >Cancel</option>
                                					      <option value="1" <?php if($sales_invoice['deliveryStatus']==1){echo "selected";}?>>Delivered</option>
                                					      <option value="0"  <?php if($sales_invoice['deliveryStatus']==0){echo "selected";}?>  >Pending</option>
                                					
                                					</select> 
                                                    <?php 
                                                    }else{
                                                         if($sales_invoice['deliveryStatus']==2){echo "Cancel";}
                                                         if($sales_invoice['deliveryStatus']==1){echo "Delivered";}
                                                         if($sales_invoice['deliveryStatus']==0){echo "Pending";}
                                                         if($sales_invoice['deliveryStatus']==3){echo "Customer Cancel";}
                                                         if($sales_invoice['deliveryStatus']==4){echo "Payment Refund";}
                                                        }
                                                         ?>
                                                </td>
                                            </tr>
                                            <?php 
                                            $a++;
                                            $i--;  
                                        }
                                        ?>
                                        <?php
                                        
                                    } 
                                    
                                    ?>
                                    </tbody>
								<tfoot>
									<tr>
										<th>No.</th>
										<th>Order No.</th>
										<th>Order Date</th>
										<th><?php echo $userName; ?></th>
										<th>Total Amount</th>
										<th>View</th>
										<th>Status</th>
									</tr>
								</tfoot>
							</table>
							<input type="hidden" value="<?php echo $total_amount; ?>" name="total_subtotal"> </div>
					</div>
					<!-- /.box-body -->
				</div>
				<!-- /.box -->
			</div>
			<!-------------------------- Sale Invoice Table End------------------------------->
	</section>
	<!-- /.content -->
	</div>
	<!-- /.content-wrapper -->
	<!---------------------- View Invoice Popup ---------------->
	<div class="modal fade" id="mfw_wholesales_invoice">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close mfwPopUpClose" id="mfw_salepartyclose" data-dismiss="modal" aria-label="Close"> <i class="fa fa-remove" class="remover"></i></button>
					<h4 class="modal-title">Customer Invoice</h4> </div>
				<div class="box-footer">
					<button class="btn btn-primary pull-right" onclick="printDiv()" id="mfwGenerateInvoice">Print</button>
				</div>
				<div class="modal-body" id="purchase_report_modal"> </div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!---------------------- View Invoice Popup ---------------->