<?php 
	include('views/_header.tpl.php'); 
	if (isset($_GET['msg'])) {
		$msg = htmlentities(strip_tags($_GET['msg']));
	} 
?>

<style>
	#mmen { display:none; }
	.spacer { padding-top:50px; }
	.form .row-item .val { margin-bottom:10px; }
	.form .row-item .lbl { min-width:90px; font-size:12px; margin-top:5px; }
	.form .txt { font-weight:300; }
	.btn { padding: 15px 25px; font-size:15px;  font-weight:300; margin-right:10px; }
	
	.tinybutton { padding:3px 7px; background:#fff; width:65px;  min-width:65px;
        border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px; font-size:12px; }	
	
	.form .description-input {
		margin-left:95px; font-size:14px; color:#777;
	}

	.thumb { width:90px; height:90px; overflow:hidden; object-fit: cover;
	 -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px; float:left; margin-right:10px; }
	 
	.printbreak {
		page-break-before: always;
	}
	
	h2 { 
		font-weight:700;
		border-bottom:2px solid #ccc;
		padding-bottom:5px;
	}
</style>

 <div class="home-feature-category" style="background:none; border:none; padding-top:0px;">
     <?php if(isset($_GET['msg'])) : ?>
     <div style="background:#cd1000; color:#fff; font-weight:300; height:25px; line-height:25px; margin-top:0px; text-align:center; padding:5px 0;">
         Saved Successfully! <a href="/admin/?oid&edit=<?= $ordr['id'] ?>" class="tinybutton">Ok!</a>
     </div>
     <?php endif; ?> 
     
        <div class="container_12 clearfix">
        
		<h1 style="margin-bottom:0px;"><a href="/admin/orders">&laquo; Back</a> | <?php
        
        if ($ordr) {
            echo "View/Edit Order Details";
        } else {
            echo "Add New Order";
            $def = "/static/system/placeholder.jpg";
        }
        
        ?></h1>
        
        <form method="post" class="form form-profile" enctype="multipart/form-data" style="padding:25px 0px 0px;">
			<div class="grid_6 blockit" style="background:none;">
            <div class="row-item clearfix" style="padding-bottom:10px; font-size:17px; color:#000; font-weight:300;">
            
  <!--              When a person scans this QR Code it&rsquo;ll return <span style="font-weight:600;"><?= $ordr['code'] ?></span>
                <br /><br />
                <?php 
                    require_once '3rdparty/phpqrcode/qrlib.php';
                    
                    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'promocodes'.DIRECTORY_SEPARATOR;
                    $PNG_WEB_DIR = '3rdparty/phpqrcode/promocodes/';
                    $fname = 'promocodes_' . $ordr['code'] . '.png';
                    $filename2 = __DIR__ . '/../../3rdparty/phpqrcode/promocodes/' . $fname;
                    $filename = $PNG_TEMP_DIR.$fname;
                    
                    $qr_string = array(
                        'type' => 'promocode',
                        'code' => $ordr['code']
                    );
                    
                    $qrString = json_encode($qr_string);
                    
                    QRcode::png($qrString, $filename2);
                
                    echo '<img src="/'.$PNG_WEB_DIR.basename($filename).'" style="max-width:200px;" />';  
               ?>
                <br /><br /><br />   -->      
				
				<h2 style="margin-top:0px; padding-top:0px;">ORDERED ITEM(S)</h2>

				<?php
				foreach ($ordr['items'] as $item) { ?>

				<div class="thumb">
					<img src="<?= $item['images'] ?>" alt="Img" style="width:90px; height:90px; object-fit: cover;" />
				</div>
				
				<?= $item['name'] ?> x <?= $item['quantity'] ?><br />
				<div style="font-size:12px; line-height:15px;">
					Total: $<?= number_format(($item['amount']/100),2,".",",") ?><br />
					<?= $item['options'] ?><br />
					<?php if( $item['discount'] > 0 ){ echo "Discount: $" . $item['discount'] . "<br />"; } ?>
					Tax: $<?= $item['tax_amount'] ?><br />
				</div>
				<div class="clear"></div>
				<br />

				<?php } ?>   
				<br />
				
				<h2 style="margin-top:0px; padding-top:0px; margin-bottom:10px">SHIPPING INFO</h2>
				<div style="font-size:20px; line-height:27px">			
					<div style="font-weight:600; font-size:22px; line-height:29px; margin-bottom:5px;"><?= $ordr['customer_name'] ?></div>
					<?= $ordr['address1'] ?><br />
					<?= $ordr['address2'] ?><br />
					<?= $ordr['city'] ?>, <?= $ordr['state'] ?> <?= $ordr['zip'] ?><br />
					<br />
					
					<div style="width:80px; display:inline-block;">Type:</div> 
					<div style="width:270px; display:inline-block; font-weight:600"><?= $ordr['delivtype'] ?></div><br />
					
					<div style="width:80px; display:inline-block;">Status:</div>
					<div style="width:270px; display:inline-block; font-weight:600"><?php if($ordr['paid']==1){ ?>
						PAID
					<?php } else { ?>
						NOT PAID YET
					<?php } ?></div><br />	
					
					<div style="width:80px; display:inline-block;">Fufilled:</div>
					<div style="width:270px; display:inline-block; font-weight:600"><?php if($ordr['is_fulfilled']==1){ ?>
						YES 
					<?php } else { ?>
						 NO 
					<?php } ?></div><br />		
					
					<div style="width:80px; display:inline-block;">Phone:</div>
					<div style="width:270px; display:inline-block;"><?= $ordr['customer_phone'] ?></div><br />
					
					<div style="width:80px; display:inline-block;">Email:</div>
					<div style="width:270px; display:inline-block;"><?= $ordr['customer_email'] ?></div><br />												
										
				</div>
				<br /><br />
				
				
				<div class="printbreak">
        
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">ID:</label>
                <div class="val" style="margin-left:0px;">
                    <input class="txt" type="text" name="id" value="<?= $ordr['id'] ?>" readonly>
                    <p class="rs description-input"></p>
                </div>
                
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px; color:#ff0000">SysNote:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="system_note" value="<?= $ordr['system_note'] ?>" style="border:1px solid #ff0000;">
					<p class="rs description-input"></p>
				</div>                

                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Location:</label>
                <div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="location_id" value="<?= $ordr['location_id'] ?>">
                    <p class="rs description-input"></p>
                </div>
                
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">CustID:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="customer_id" value="<?= $ordr['customer_id'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Name:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="customer_name" value="<?= $ordr['customer_name'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Date:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="date" value="<?= $ordr['date'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Date:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="pickup_at" value="<?= $ordr['pickup_at'] ?>">
					<p class="rs description-input">pickup/deliv date</p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Fulfil:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="is_fulfilled" value="<?= $ordr['is_fulfilled'] ?>">
					<p class="rs description-input"></p>
				</div>				
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Note:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="note" value="<?= $ordr['note'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Total:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="amount" value="<?= $ordr['amount'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">IP:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="device_id" value="<?= $ordr['device_id'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Paid:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="paid" value="<?= $ordr['paid'] ?>">
					<p class="rs description-input"></p>
				</div>			
                                                  
                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px; margin-top:10px;">Status:</label>
                <div class="val" style="margin-left:0px; margin-top:10px;">
			       <select name="status" id="" class="txt" type="number" style="background:#fff;" <!--name="projectid"-->>
			           <option value="">Select Order Status</option>
			           <option value="1" <?php if($ordr['status'] == '1') echo "selected"; ?>>Order Received</option>
			           <option value="2" <?php if($ordr['status'] == '2') echo "selected"; ?>>Being Prepared</option>
			           <option value="3" <?php if($ordr['status'] == '3') echo "selected"; ?>>Ready for Pickup</option>
			           <option value="4" <?php if($ordr['status'] == '4') echo "selected"; ?>>Out for Delivery</option>     
			           <option value="5" <?php if($ordr['status'] == '5') echo "selected"; ?>>Cash Order</option>           
			       </select> 
                    <p class="rs description-input"><?= $squareuser['status'] ?></p>
                </div>  				
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Receipt:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="receipt_id" value="<?= $ordr['receipt_id'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Delivery:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="delivery" value="<?= $ordr['delivery'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Phone:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="customer_phone" value="<?= $ordr['customer_phone'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Email:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="customer_email" value="<?= $ordr['customer_email'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">PmtID:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="payment_id" value="<?= $ordr['payment_id'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Reserve:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="cashorder" value="<?= $ordr['cashorder'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">OrderType:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="ordertype" value="<?= $ordr['ordertype'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">PmtType:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="pmt_type" value="<?= $ordr['pmt_type'] ?>">
					<p class="rs description-input"></p>
				</div>  
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">PromoCode:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="promo_code" value="<?= $ordr['promo_code'] ?>">
					<p class="rs description-input"></p>
				</div>                      
                      
<!--                <label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Type:</label>
                <div class="val" style="margin-left:0px;">
			       <select name="type" id="" class="txt" type="number" style="background:#fff;">
			           <option value="">Select User Type</option>
			           <option value="1" <?php if($ordr['type'] == '1') echo "selected"; ?>>Percentage</option>
			           <option value="2" <?php if($ordr['type'] == '2') echo "selected"; ?>>Flat</option>     
			       </select>                 
                    <p class="rs description-input"></p>
                </div>-->
				</div><!-- PRINT BREAK -->
            </div><!-- ROW ITEM CLEARFIX -->
			</div><!-- END OF 6 GRID LEFT COLUMN -->
	
			<div class="grid_6 blockit" style="background:none;">
				<div class="row-item clearfix" style="padding-bottom:10px; font-size:17px; color:#000; font-weight:300;">
				
				<div class="printbreak">
				
				<h2 style="margin-top:0px; padding-top:0px;">SHIPPING INFO</h2>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Address1:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="address1" value="<?= $ordr['address1'] ?>">
					<p class="rs description-input"></p>
				</div> 
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Address2:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="address2" value="<?= $ordr['address2'] ?>">
					<p class="rs description-input"></p>
				</div> 
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">City:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="city" value="<?= $ordr['city'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">State:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="state" value="<?= $ordr['state'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">Zip:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="zip" value="<?= $ordr['zip'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<label class="lbl" for="txt_name1" style="text-align:left; width:auto; margin-right:5px;">DelivType:</label>
				<div class="val" style="margin-left:0px;">
					<input class="txt" type="text" name="delivtype" value="<?= $ordr['delivtype'] ?>">
					<p class="rs description-input"></p>
				</div>
				
				<br />
				

				
<!--				<?php echo "<pre>"; ?>
				<?php print_r($ordr['items']) ?>-->
				</div><!-- PRINT BREAK -->
				</div><!-- ROW-ITEM CLEARFIX -->
				
				<br /><br />
				
			</div>			
			<div class="clear"></div>
            <br />
            <input type="submit" style="font-weight:300" class="btn btn-black" /> 
            <input type="button" value="Cancel" class="btn btn-black" onclick="location = '/admin/orders'" />
            <br /><br />
        </form>        

        <!-- END OF 6 GRID LEFT COLUMN WAS HERE -->

    </div>
</div>

<?php

include('views/_footer.tpl.php');

?>