<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php
if (env('HTTPS')) {
		$lnk= $html->url('/orders/userorderdetails/'.$odr["Order"]["id"]);
                $lnk = "http://".$_SERVER["HTTP_HOST"]. $lnk;
                header("Location:$lnk");
	}
?>
<script language="javascript" type="text/javascript">


function getrefund(id){
//var url='<?php echo $cnfg["sitebasefolder"];?>/refunds/requestrefund/';
window.location='../../refunds/requestrefund/'+id;
}
</script>

<div align="center">
	<h2 class="title text-center mainhd">My Orders</h2>
</div>
			
<?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#319502"><?php $session->flash(); ?></font></div><?php } ?>
<div align="left" id="item_details_admin">
    <div class="table-responsive">
    <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table" class="table">
  <tr>
    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td class="boxtopheader">Order Details </td>
      </tr>
    </table>
    <table width="100%"  border="0" cellspacing="1" cellpadding="6">
      <tr align="left" valign="middle" id="list_admin_top">
        <td width="18%">Order Number</td>
        <td width="30%">Order Status </td>
        <td width="15%">Order Date</td>
        <td width="24%">User Name</td>
        <td width="13%">Currency</td>
        </tr>
      <tr align="left" valign="middle" id="list_admin">
           <td><?php echo $odr["Order"]["id"];?></td>
        <td>
		<?php echo $odr["OrderStatus"]["name"]; ?>
		<!-- <form name="sts" id="sts" action="<?php echo '../change_status_user/'.$odr["Order"]["id"];?>" method="POST">
			<input type="hidden" name="order_status" id="order_status" value="3">
			<input type="submit" value ="Order Accepted">
			</form> --></td>
        <td><?php
			$dt	= strtotime($odr["Order"]['date']);
			$edt = strtotime($odr["Order"]['exp_time']);
			echo date("m-d-Y",$dt );
			 ?></td>
        <td><?php echo $odr["User"]["uname"]; ?></td>
        <td><?php echo $odr["Order"]["currency_type"]; ?></td>
        </tr>
    </table>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>
    </div>

<div class="table-responsive">
 <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table" class="table">
  <tr>
    <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td class="boxtopheader">Items Details </td>
      </tr>
    </table>
    <table width="100%"  border="0" cellspacing="1" cellpadding="6">
      <tr align="left" valign="middle" id="list_admin_top">
        <td width="13%">Product Name</td>
        <td width="8%" align="center">SKU No.</td>
        <td width="14%" align="center">Combination</td>
        <td width="7%" align="center">Quantity</td>
        <td width="8%" align="center">Unit Price</td>
        <td width="9%" align="center">Additional Cost </td>
		 <td width="9%" align="center">Discount</td>
         <td width="9%" align="center">Price </td>    
		 <?php  if($ptype_flag == 'Digital') { ?> 
        <td width="13%">Download </td>      
        <td width="10%">Expiry Time</td>
		<?php } ?>
      </tr>

 <?php 
  $amt=0;
  $dis_str='';

  $odtp	=	"Non-digital";  
  if(count($odr["OrderDetail"])>0)
  {       
		
  foreach($odr["OrderDetail"] as $det){   
    $price=0;
	$dis_amnt=0;	
		
  	if($det["prodtype"] == "Digital"){
	 	$odtp	=	"Digital";		
	?>	
      <tr align="left" valign="middle" id="list_admin">
        <td align="center"><?php echo $det["Product"]; ?></td>
        <td align="center"><?php if(isset($det["skuno"])) echo $det["skuno"]; else echo "-"; ?> </td>
        <td align="center"><?php if(isset($det["combinations"])) echo $det["combinations"]; else echo "-";?></td>
        <td align="center"><?php echo $det["quantity"]; ?></td>
        <td align="center"><?php echo $curlogo;?><?php echo $det["product_price"]; ?></td>
        <td align="center"><?php echo $curlogo;?><?php echo $det["extra_price"]; ?></td>
		<td align="center">
                    <?php		
		if($det["discount_type"]=='per' && $det["discount"] > 0) {
                    $dis_amnt=(($det["product_price"] + $det["extra_price"])*$det["discount"])/100;
                } else if($det["discount_type"]=='amnt' && $det["discount"] > 0) {
                    $dis_amnt=$det["discount"];
                }
                
		$dis_amnt=($dis_amnt)*($det["quantity"]);               
		$curlogo.number_format($dis_amnt,2,'.','');
		?>
		</td>
        <td align="center">
				<?php		
		  $combined_price=$det['product_price']+$det['extra_price'];  
		  if($det["discount_type"]=='per')
			 {		
				  if($det['discount'] > 0 && $det['discount'] <> '')
					{
						$discounted_price=($combined_price-(($combined_price * $det['discount'])/100));
						$price=($discounted_price)*($det['quantity']);							
						$amt+= $price;	
					}
					else
					{
					  $amt+=($combined_price)*($det['quantity']);	
					  $price+=($combined_price)*($det['quantity']);	
					} 	
			 }
			 else if($det["discount_type"]=='amnt')
			 {
			   	 if($det['discount'] > 0 && $det['discount'] <> '')
					{
						$discounted_price=($combined_price-$det['discount']);
						$price=($discounted_price)*($det['quantity']);	
						$amt+= $price;	
					}	
					else
					{
					  $amt+=($combined_price)*($det['quantity']);	
					  $price+=($combined_price)*($det['quantity']);	
					} 						 
			 }		
			else
			{
				$price = ($combined_price)*($det['quantity']);
				$amt+= $price;	
			}      
		   echo $curlogo.number_format($price,2,'.','');		  
		  ?>
	</td>       
	
	    <?php if(trim($det["prodtype"]) == "Digital" && trim($det["type"]) <> 'G'){ $odtp	=	"Digital";?>
        <td align="center">		
		<a href='<?php echo FULL_BASE_URL. $cnfg["sitebasefolder"]."/Orders/pdctdownload/".$det["order_id"]."/".$det['product_id']."/" ;?> '>Download Now</a>		
		</td>       
        <td align="center"><?php echo date('m-d-Y H:i:s',$edt ); ?></td>
		<?php } else{?>
		 <td align="center">N/A</td>
		 <td align="center">N/A</td>
		<?php } ?>
      </tr>
        <?php }else{ ?>
		
      <tr align="left" valign="middle" id="list_admin">
	     
        <td><?php echo $det["Product"]; ?></td> 
		<td align="center" ><?php if(isset($det["skuno"])) echo $det["skuno"]; else echo "-"; ?> </td>  
        <td align="center"><?php if(isset($det["combinations"])) echo $det["combinations"]; else echo "-";?></td>     
        <td align="center"><?php echo $det["quantity"]; ?></td>
        <td align="center"><?php echo $curlogo;?><?php echo $det["product_price"]; ?></td>
        <td align="center"><?php echo $curlogo;?><?php echo $det["extra_price"]; ?></td>
		 <td align="center">
		 <?php 		
		if($det["discount_type"]=='per' && $det["discount"] > 0){
                    $dis_amnt=(($det["product_price"] + $det["extra_price"])*$det["discount"])/100;
                } else if($det["discount_type"]=='amnt' && $det["discount"] > 0) {
                    $dis_amnt=$det["discount"];
                }
		$dis_amnt=($dis_amnt)*($det["quantity"]);
		echo $curlogo.number_format($dis_amnt,2,'.','');
		?>
		 </td>
        <td align="center">
		<?php		
		  $combined_price=$det['product_price']+$det['extra_price'];  
		  if($det["discount_type"]=='per')
			 {		
				  if($det['discount'] > 0 && $det['discount'] <> '')
					{
						$discounted_price=($combined_price-(($combined_price * $det['discount'])/100));
						$price=($discounted_price)*($det['quantity']);							
						$amt+= $price;	
					}
					else
					{
					  $amt+=($combined_price)*($det['quantity']);	
					  $price+=($combined_price)*($det['quantity']);	
					} 			
			 }
			 else if($det["discount_type"]=='amnt')
			 {
			   	 if($det['discount'] > 0 && $det['discount'] <> '')
					{
						$discounted_price=($combined_price-$det['discount']);
						$price=($discounted_price)*($det['quantity']);	
						$amt+= $price;	
					}	
					else
					{
					  $amt+=($combined_price)*($det['quantity']);	
					  $price+=($combined_price)*($det['quantity']);	
					} 					 
			 }		
			else
			{
				$price = ($combined_price)*($det['quantity']);
				$amt+= $price;	
			}      
		   echo $curlogo.number_format($price,2,'.','');		  
		  ?>
		</td>   
		 <?php  if($ptype_flag == 'Digital') { ?>      
		<td align="center">N/A</td>     
        <td align="center">N/A</td>
		<?php } ?>
      </tr>
       <?php } } } else { ?>	 
	    <tr align="left" valign="middle" id="list_admin">
        <td colspan="10" align="center">No Details Found.</td>     
        </tr>
	   <?php } ?>
    </table>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>
</div>
    
    <div class="row userorderdetails">
        <div class="col-xs-12 col-sm-6">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
       <tr>
         <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
             <tr>
               <td class="boxtopheader">Order Details                    
               </td>
             </tr>
           </table>
             <table width="100%"  border="0" cellspacing="1" cellpadding="6">
               <?php if($odtp <> "Digital"){ ?>			   
			     <tr align="left" valign="middle" id="list_admin">
                 <td>Shipping Method </td>
                 <td><?php echo $odr["Order"]["shipping_method"]; ?></td>
               </tr>
               <tr align="left" valign="middle" id="list_admin_top">
                 <td>Shipping Service</td>
                 <td><?php echo html_entity_decode($odr["Order"]["shipping_service"]); ?></td>
               </tr>
			    <?php } ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Payment Method </td>
                 <td><?php echo $odr["Order"]["payment_method"]; ?></td>
               </tr>
               <?php if(isset($odr["Order"]["transaction_id"]) && $odr["Order"]["transaction_id"] <> 0 && $odr["Order"]["transaction_id"] <>'') { ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Transaction Id</td>
                 <td><?php  echo $odr["Order"]["transaction_id"]; ?></td>
               </tr>
			   <?php } ?>
			    <?php if(isset($odr["Coupon"]["id"]) && $odr["Coupon"]["id"] <> 0 && isset($odr["Coupon"]["code"]) && $odr["Coupon"]["code"] <> ''){ ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Promo Code </td>
                 <td><?php echo $odr["Coupon"]["code"]; ?></td>
               </tr>
			   <?php } ?>					
             </table>
             <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="admin_bottom">
               <tr>
                 <td>&nbsp;</td>
               </tr>
           </table></td>
       </tr>
     </table>
        </div>
        <?php if($odtp <> "Digital" && $odr["Order"]["ship_fname"] <> ''){ ?>
        <div class="col-xs-12 col-sm-6">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
         <tr>
           <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
               <tr>
                 <td class="boxtopheader">Shipping Address</td>
               </tr>
             </table>
               <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                 <tr align="left" valign="middle" id="list_admin">
                   <td><?php echo $odr["Order"]["ship_fname"]."&nbsp;&nbsp; ".$odr["Order"]["ship_lname"]; ?><br />
           <?php echo $odr["Order"]["ship_address"]; ?><br />
          <?php echo $odr["Order"]["ship_city"]."&nbsp;&nbsp;".$odr["Order"]["ship_state"]."&nbsp;&nbsp;".$odr["Order"]["ship_zip"]; ; ?><br />
           <?php echo $odr["Order"]["ship_country"]; ?><br />
           Phone &nbsp; : &nbsp;<?php echo $odr["Order"]["ship_phone"]; ?><br />
           Mobile &nbsp; : &nbsp;<?php echo $odr["Order"]["ship_mobile"]; ?><br />
          Fax &nbsp; : &nbsp;<?php echo $odr["Order"]["ship_fax"]; ?></td>
                 </tr>
               </table>
               <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
                 <tr>
                   <td>&nbsp;</td>
                 </tr>
             </table></td>
         </tr>
       </table>
        </div>
        <?php } ?>
        <?php if($odr["Order"]["comments"] <>'') { ?>
        <div class="col-xs-12 col-sm-6">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
         <tr>
           <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
               <tr>
                 <td class="boxtopheader">Note From Site Administrator</td>
               </tr>
             </table>
               <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                 <tr align="left" valign="middle" id="list_admin">
                   <td>
				   <?php echo $odr["Order"]["comments"];?>				   
				   </td>
                 </tr>
               </table>
               <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
                 <tr>
                   <td>&nbsp;</td>
                 </tr>
             </table></td>
         </tr>
       </table>
        </div>
        <?php } ?>
    </div>
    
    <div class="row userorderdetails">
        <div class="col-xs-12 col-sm-6">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
       <tr>
         <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">

             <tr>
               <td class="boxtopheader">Amount Paid</td>
             </tr>
           </table>
             <table width="100%"  border="0" cellspacing="1" cellpadding="6">

               <tr align="left" valign="middle" id="list_admin_top">
                 <td width="44%">Total Price</td>
                 <td width="56%"><?php echo $curlogo;?><?php echo number_format($amt,2,'.',''); ?></td>
               </tr>
			    <?php if($odtp <> "Digital"){ ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Shipping</td>
                 <td><?php echo $curlogo;?><?php echo $odr["Order"]["shipping_price"]; ?></td>
               </tr>
			   <?php } ?>
               <tr align="left" valign="middle" id="list_admin_top">
                 <td>Tax Name </td>
                 <td><?php echo $odr["Order"]["tax_name"]; ?></td>
               </tr>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Tax</td>
                 <td><?php echo $curlogo;?><?php echo $odr["Order"]["tax_price"]; ?></td>
               </tr>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Promo Code Discount</td>
                 <td><?php echo $curlogo;?>
				 <?php 
				 if($odr["Order"]["discount"] > $amt)				

				 echo number_format($amt,2,'.','');
				 else
				 echo number_format($odr["Order"]["discount"],2,'.',''); ?>
				 </td>
               </tr>
                <?php if($odr["Order"]["gift_card_discount"]>0) { ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td>Gift Card Discount</td>
                 <td><?php echo $curlogo;?>
				 <?php 
				 
				 echo number_format($odr["Order"]["gift_card_discount"],2,'.',''); ?>
				 </td>
               </tr>
               <?php } ?>
               <?php
                    if(!empty($specialsArr)){
                        foreach($specialsArr as $specials){
               ?>
               <tr align="left" valign="middle" id="list_admin">
                 <td><?php echo $specials->note; ?></td>
                 <td><?php echo $curlogo;?><?php echo number_format($specials->cost,2,'.',''); ?></td>
               </tr>
               <?php
                        }
                    }
                ?>
             </table>
             <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
               <tr>
                 <td width="44%">Grand Total</td>
                 <td width="55%" class="toplinks"><?php echo $curlogo;?><?php echo $odr["Order"]["total_price"]; ?></td>
               </tr>
           </table></td>
       </tr>
     </table>
        </div>
        <div class="col-xs-12 col-sm-6">
            <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="items_display_area_admin_table">
         <tr>
           <td align="left" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="5">
               <tr>
                 <td class="boxtopheader">Billing Address</td>
               </tr>
             </table>
               <table width="100%"  border="0" cellspacing="1" cellpadding="6">
                 <tr align="left" valign="middle" id="list_admin">
                   <td><?php echo $odr["Order"]["bill_fname"]."&nbsp;&nbsp;".$odr["Order"]["bill_lname"]; ?><br />
           <?php echo $odr["Order"]["bill_address"]; ?><br />
            <?php echo $odr["Order"]["bill_city"]."&nbsp;&nbsp;".$odr["Order"]["bill_state"]."&nbsp;&nbsp;".$odr["Order"]["bill_zip"];  ?><br />
            <?php echo $odr["Order"]["bill_country"]; ?><br />
           Mobile &nbsp; : &nbsp;<?php echo $odr["Order"]["bill_mobile"]; ?><br />
		   Phone &nbsp; : &nbsp;<?php echo $odr["Order"]["bill_phone"]; ?><br />
          Fax &nbsp; : &nbsp;<?php echo $odr["Order"]["bill_fax"]; ?>
          </td>
                 </tr>
               </table>
               <table width="100%"  border="0" cellspacing="0" cellpadding="3" id="admin_bottom">
                 <tr>
                   <td>&nbsp;</td>
                 </tr>
             </table></td>
         </tr>
       </table>
        </div>
    </div>

 
    
<?php
/*if(isset($labelimage)){
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="5">
    <tr>
        <td class="boxtopheader">Shipping Label</td>
    </tr>
    <tr>
        <td align="left">
            <?php echo $html->image($labelimage,array("height"=>400,"width"=>800,"id"=>"labelid"));?></td>
    </tr>
    <tr>
        <td>
            <input type="button" name="printlabel" id="printlabel" value="Print" class="btn-usr01" onclick="printLable('<?php echo FULL_BASE_URL . $cnfg["sitebasefolder"] . "/app/webroot/".$labelimage;?>')">
        </td>
    </tr>
</table>
 <?php
}*/
?>
 <table width="100%"  border="0" cellspacing="0" cellpadding="0">
   <tr>
     <td align="left">
	 <!--<input type="button" value="Back" onClick="window.location.href='<?php echo $sitebase.$sitefolder;?>/orders/myorder'" class="btn-gry01">-->
</td>
 <?php if($cnfg["allow_rma"] == "Y"){?>
	<td align="right">
	<input type="button" value="Back" onClick="window.location.href='<?php echo $sitebase.$sitefolder;?>/orders/myorder'" class="btn-gry01">
<?php
    $pos = strpos($det["Product"], "Gift Card");
    if ($pos == false) {
    ?>
        <input type="button" value="Refund" onClick="javascript:getrefund(<?php echo $odr['Order']['id'];?>)" class="btn-usr01">
<?php 
    }
} ?>
        </td>
			
   </tr>
 </table>
 <br /></div>
<div align="left" class="float_clear1"></div>
</form>

<script type="text/javascript">

    function printLable(trial){
       
         var mywindow = window.open('', 'basicmodalcontent', 'height=400,width=600'); 
        mywindow.document.write('<html><head><title>print</title></head>');
        mywindow.document.write('<body >'); 
        mywindow.document.write("<img src='"+trial+"' rel='stylesheet' type='text/css' />") 
        mywindow.document.write('</body></html>'); 
        mywindow.document.close(); 
        mywindow.print(); 
        return true; 
    }

</script>