<?php echo $header; ?> 
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/stock-status.png" alt="" /> Billing Summary</h1>
	  
    </div>
    <div class="content">
      <form action="<?php echo $update; ?>" method="post" enctype="multipart/form-data" id="form">
            <?php if ($shippinges) {  ?>
			
            <?php 
			$prevCustomerCode = '';
			$prevCustomerTrackNum = '';
			$prevCustomerCodeAlignReset = 0;
			$prevCustomized = -1;
			foreach ($shippinges as $shipping) {
				//if($prevCustomerCode != $shipping['customercode']){
				  if($prevCustomerTrackNum != $shipping['data']['CustTrackingNum']){
			?>
			
		<table class="list" style="margin-bottom:10px;margin-top:10px;">
          <thead>
            <tr>
              <td class="left">
				<?php echo $shipping['customercode'] . ' ('. $shipping['storebillingshippingname'] . ')' ; ?><br>
				<?php echo $shipping['data']['membershipno']; ?><br>
				<?php echo $shipping['data']['CustTrackingNum']; $itemCount=0;$itemTotal=0;$GSTTotal=0; ?>
				<input type="hidden" name="TrackingNum" id="TrackingNum" value="<?php echo $shipping['data']['CustTrackingNum']; ?>" />
				<input type="hidden" name="customercode" id="customercode" value="<?php echo $shipping['customercode']; ?>" />
				<input type="hidden" name="customerparentcode" id="customerparentcode" value="<?php echo $shipping['customerparentcode']; ?>" />
				<input type="hidden" name="membershipno" id="membershipno" value="<?php echo $shipping['data']['membershipno']; ?>" />
			  </td>
            </tr>
          </thead><tbody></tbody>
		  <?php 
				//$prevCustomerCode = $shipping['customercode'];
				$prevCustomerTrackNum = $shipping['data']['CustTrackingNum'];
				$prevCustomerCodeAlignReset = 1;
			} ?>
          </table>
			
		<?php if($prevCustomerCodeAlignReset == 1 || $shipping['data']['Customized'] != $prevCustomized ) { ?>			
			<table class="list" style="margin-bottom:10px;">
				<thead><tr>		
					<td class="left" style="background-color:#FFFAFA; width:50%; "><?php if($shipping['data']['Customized']){ echo "Customized" ; } else { echo "ReStock";  } ?> </td>
					</tr>
				</thead>
				</table>
		<?php $prevCustomerCodeAlignReset = 0; $prevCustomized = $shipping['data']['Customized'] ; } ?>
		
		<table >
          <tbody><tr>		              
				<td style="text-align: center;">
					<input type="checkbox" name="selected[]" id="<?php echo $shipping['data']['order_id']; ?>"  value="<?php echo $shipping['data']['order_id']; ?>" checked />
                </td>
				<td class="left">				
			    <?php 
				
				$ProductDescr = trim(strstr($shipping['data']['descr'], "<br>", true), " ");
				$ItemType = trim($shipping['data']['itemtype'], " ");
				 switch ($ItemType)
				 {
					case 'R':
						$ItemTypeDescr = "Ring" ;
						break;
					case 'B':
						$ItemTypeDescr = "Bracelet" ;
						break;
					case 'E':
						$ItemTypeDescr = "Earrings" ;
						break;
					case 'N':
						$ItemTypeDescr = "Necklace" ;
						break;
					case 'S':
						$ItemTypeDescr = "Studs" ;
						break;
					default:
						$ItemTypeDescr = $ItemType ;
				}				
				//echo strstr($shipping['data']['descr'], "<br>", true);   
				echo $ProductDescr . " " . $ItemTypeDescr ; 
				//		echo strstr($shipping['data']['descr'], "<br>", true); 				
				
				$itemCount++; $GSTTotal = $GSTTotal + $shipping['data']['GST'];  $itemTotal = $itemTotal+ $shipping['data']['AJ_price']; ?><br>
				<?php if($shipping['data']['Customized']){ ?>
				<?php  echo date("d-M-Y", strtotime($shipping['data']['date_added'])) . " | #" .  $shipping['data']['order_id'] ; ?><br>
				<?php
					if($shipping['data']['M1'] != 0){ echo $metal[$shipping['data']['M1']] ; } 
					if($shipping['data']['M2'] != 0){ echo " | " . $metal[$shipping['data']['M2']] ; }					
					if($shipping['data']['G1'] != 0){ echo " | " . $gemstone[$shipping['data']['G1']] ; }
					if($shipping['data']['G2'] != 0){ echo " | " . $gemstone[$shipping['data']['G2']] ; }
					if($shipping['data']['G3'] != 0){ echo " | " . $gemstone[$shipping['data']['G3']] ; }
					if($shipping['data']['G4'] != 0){ echo " | " . $gemstone[$shipping['data']['G4']] ; }
					if($shipping['data']['G5'] != 0){ echo " | " . $gemstone[$shipping['data']['G5']] ; }				
				?><br><br>
				<?php  } ?>
			  </td> 
			   <td style="padding-left:20px;"> <?php echo   round($shipping['data']['AJ_price'],2)  ; ?></td>
			  
			  <!--	
			  <td class="left" id="<?php echo "TrackingNumDiv-".$shipping['data']['order_id']; ?>" style = "display:none;">
				<input type="text" name="<?php echo "TrackingNum-".$shipping['data']['order_id']; ?>" id="<?php echo "TrackingNum-".$shipping['data']['order_id']; ?>" value="" />
			  </td>
			  -->
            </tr>
			<tbody>
			</table>
			<br>
            <?php 
			
			} ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="3"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
		<table class="list" >
          <thead>
		  
		  	<input type="hidden" name="itemCount" id="itemCount" value="<?php echo $itemCount; ?>" />
		  	<input type="hidden" name="itemTotal" id="itemTotal" value="<?php echo $itemTotal; ?>" />
		  	<input type="hidden" name="GSTTotal" id="GSTTotal" value="<?php echo $GSTTotal; ?>" />

			<tr><td style="padding:10px;">Shipping <input type="text" name="shipping" id="shipping" value="" style="padding-right:20px;" /></td></tr>
			<tr><td style="padding:10px;">Other Costs <input type="text" name="others" id="others" value="" style="padding-right:20px;" />Descr<input type="text" name="descr" id="descr" value="" style="padding-right:20px;" /></td></tr>
			<tr><td style="padding:10px;"><div class="buttons"><a  onclick="$('#form').submit();" class="button">Bill Now</a></div></td></tr>
		  </thead>
		</table>
		
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>

<script type="text/javascript">
    //function ShowHideDiv(chkPassport,id) {
		//var dvPassport = document.getElementById("TrackingNumDiv-" + id);
        //dvPassport.style.display = chkPassport.checked ? "block" : "none";
    //}
</script>
<?php echo $footer; ?>