	<?php echo $header; ?>

<style> 
input[type=text] {
  width: 60px;
  font-size:11px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: white;
  background-image: url('searchicon.png');
  background-position: 2px 2px; 
  background-repeat: no-repeat;
  padding-top: 1px;
  padding-bottom: 1px;
}


.list .left{
  text-align:left;
  padding:2px;
}

input[class=currency] {
  text-align:right;
}

input[class=filterDate]{
  width: 80px;
}
input[class=GemCounts] {
  width: 20px;
  text-align:center;
  padding-left:2px;
  padding-right:2px;
}
select{
    box-sizing: border-box;
    margin: 0;
    border: 1px solid #aaa;
    box-shadow: 0 1px 0 1px rgba(0,0,0,.04);
    border-radius: .5em;
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
    background-color: #fff;
    background-position: right .7em top 50%, 0 0;
    background-size: .65em auto, 100%;
}
</style>

<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/order.png" alt="" /> Shipment History </h1>
      <div class="buttons" id="newProductButton">	  
			<a onclick="$('#form').attr('action', '<?php echo $costReady; ?>');  $('#form').submit();"  value="Update"  id="Update"  name="Update" class="button">Cost Ready</a>
	  </div>
      <div class="buttons" id="filter">	  
			<a onclick="$('#form').attr('action', '<?php echo $filter; ?>&filter_date=' +  $('#filter_date').val() + '&filter_date_to=' +  $('#filter_date_to').val());  $('#form').submit();"  value="filter"  id="filter"  name="filter" class="button">Filter</a>
	  </div>
	  <h1 style="float:right;">To Date:<input type="text" name="filter_date_to" id="filter_date_to" value="<?php echo $filter_date_to; ?>" size="12" size=12 class="date filterDate" style="width:60px;" />&nbsp;&nbsp;&nbsp;</h1>
	  <h1 style="float:right;">Ship From Date:<input type="text" name="filter_date" id="filter_date" value="<?php echo $filter_date; ?>" size="12" size=12 class="date filterDate" style="width:60px;" />&nbsp;&nbsp;&nbsp;</h1>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form" >
		<?php if ($orders) { ?>
        <table class="list oldProduct" >
          <thead>
            <tr>
              <!-- <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td> 
              <td class="right"><?php if ($sort == 'o.order_id') { ?>
                <a href="<?php echo $sort_order; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_order_id; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_order; ?>"><?php echo $column_order_id; ?></a>
                <?php } ?></td>   -->
				<td class="center">Order ID  <br> Product</td>
				
              <td class="center">M1</td>
              <td class="center">M2</td>
              <td class="center">G1</td>
              <td class="center">G2</td>
              <td class="center">G3</td>
              <td class="center">G4</td>
              <td class="center">G5</td>			  
			  <td class="center oldProduct">Sett</td>
			  <td class="center oldProduct">FilPol</td>
			  <td class="center oldProduct">Rhod</td>
			  <td class="center oldProduct">Cast</td>
			  <td class="center oldProduct">Plat</td>
			  <td class="center oldProduct">Oth Codes /<br>Cost</td>
			  <td class="center oldProduct">ShipQty</td>	
			  <td class="center oldProduct">Shipping Date</td>	
			  
            </tr>
          </thead>
          <tbody>			
			
            <?php foreach ($orders as $order) { ?>
            <tr > <!--
              <td style="text-align: center;"><?php if ($order['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" />
                <?php } ?></td> -->
              <td class="center"><?php echo $order['order_id']; ?><br><?php echo $order['name']; ?></td>
			  
			  <td class="center">
				<?php echo $order['M1']; ?><br><?php printf("%.2f", round($order['M1Wt'],2)); ?>
				<?php if($order['M1CostingError'] !="" ){ echo "<br>Error: ".$order['M1CostingError']; } ?>
				
			  </td>				  
			  <td class="left">
				<?php echo $order['M2']; ?><br><?php printf("%.2f", round($order['M2Wt'],2)); ?>
				<?php if($order['M2CostingError'] !="" ){ echo "<br>Error: ".$order['M2CostingError']; } ?>
			  </td>
			  
			  <?php if($order['G1'] != "" ){ ?>
			  <td class="center">
					<?php echo $order['G1'] . "<br>Count#: ". round($order['G1#'],2) . "<br>Weight: " ; ?> <?php echo printf("%.2f", round($order['G1Wt'],2)) . "<br>Size:" .  $order['G1SizeId'] . "<br>Shape:" ; ?>
						<?php foreach ($gemShapes as $gemShape) { ?>
							<?php if ($gemShape['shape_id'] == $order['G1ShapeId']) { ?><?php echo $gemShape['shape']; ?>
							<?php } ?>
						<?php } ?>
						<?php if($order['G1CostingError'] !="" ){ echo "<br>Error: ".$order['G1CostingError']; } ?>
			  </td>
			  <?php }else{ ?>
					<td></td>
			  <?php } ?>
			  <?php if($order['G2'] != "" ){ ?>
			  <td class="center">
					<?php echo $order['G2'] . "<br>Count#: ". round($order['G2#'],2) . "<br>Weight: " ; ?> <?php echo printf("%.2f", round($order['G2Wt'],2)) . "<br>Size:" .  $order['G2SizeId'] . "<br>Shape:" ; ?>
						<?php foreach ($gemShapes as $gemShape) { ?>
							<?php if ($gemShape['shape_id'] == $order['G2ShapeId']) { ?><?php echo $gemShape['shape']; ?>
							<?php } ?>
						<?php } ?>
						<?php if($order['G2CostingError'] !="" ){ echo "<br>Error: ".$order['G2CostingError']; } ?>
			  </td>
			  <?php }else{ ?>
					<td></td>
			  <?php } ?>
			  <?php if($order['G3'] != "" ){ ?>
			  <td class="center">
					<?php echo $order['G3'] . "<br>Count#: ". round($order['G3#'],2) . "<br>Weight: " ; ?> <?php echo printf("%.2f", round($order['G3Wt'],2)) . "<br>Size:" .  $order['G3SizeId'] . "<br>Shape:" ; ?>
						<?php foreach ($gemShapes as $gemShape) { ?>
							<?php if ($gemShape['shape_id'] == $order['G3ShapeId']) { ?><?php echo $gemShape['shape']; ?>
							<?php } ?>
						<?php } ?>
						<?php if($order['G3CostingError'] !="" ){ echo "<br>Error: ".$order['G3CostingError']; } ?>
			  </td>
			  <?php }else{ ?>
					<td></td>
			  <?php } ?>
			  <?php if($order['G4'] != "" ){ ?>
			  <td class="center">
					<?php echo $order['G4'] . "<br>Count#: ". round($order['G4#'],2) . "<br>Weight: " ; ?> <?php echo printf("%.2f", round($order['G4Wt'],2)) . "<br>Size:" .  $order['G4SizeId'] . "<br>Shape:" ; ?>
						<?php foreach ($gemShapes as $gemShape) { ?>
							<?php if ($gemShape['shape_id'] == $order['G4ShapeId']) { ?><?php echo $gemShape['shape']; ?>
							<?php } ?>
						<?php } ?>
						<?php if($order['G4CostingError'] !="" ){ echo "<br>Error: ".$order['G4CostingError']; } ?>
			  </td>
			  <?php }else{ ?>
					<td></td>
			  <?php } ?>
			  <?php if($order['G5'] != "" ){ ?>
			  <td class="center">
					<?php echo $order['G5'] . "<br>Count#: ". round($order['G5#'],2) . "<br>Weight: " ; ?> <?php echo printf("%.2f", round($order['G5Wt'],2)) . "<br>Size:" .  $order['G5SizeId'] . "<br>Shape:" ; ?>
						<?php foreach ($gemShapes as $gemShape) { ?>
							<?php if ($gemShape['shape_id'] == $order['G5ShapeId']) { ?><?php echo $gemShape['shape']; ?>
							<?php } ?>
						<?php } ?>
						<?php if($order['G5CostingError'] !="" ){ echo "<br>Error: ".$order['G5CostingError']; } ?>
			  </td>
			  <?php }else{ ?>
					<td></td>
			  <?php } ?>

			  <!-- <td class="right"><input type="text" name="<?php echo $order['order_id']; ?>Setting" value="<?php  printf("%.2f", round($order['Setting'],2)); ?>" class="currency" /></td> -->
			  <td class="center">
                  <?php foreach ($settingCodes as $settingCode) { if ($settingCode['Id'] == $order['Setting']) {  echo $settingCode['Code']; } } ?>
                </select>
			  </td>
			  <td class="right"><?php printf("%.2f",  round($order['FilingPolishing'],2)); ?> </td>
			  <td class="center">
                  <?php foreach ($rhodiumCodes as $rhodiumCode) {  if ($rhodiumCode['Id'] == $order['Rhodium']) {  echo $rhodiumCode['Code']; } } ?>
			  </td>
			  <td class="center">
                  <?php foreach ($castingCodes as $castingCode) {  if ($castingCode['Id'] == $order['Casting']) { echo $castingCode['Code']; } }  ?>
                </select>
			  </td>	
			  <td class="center">
                  <?php foreach ($platingCodes as $platingCode) {  if ($platingCode['Id'] == $order['Plating']) { echo $platingCode['Code'];  } } ?>
                </select>
			  </td>		  
			  <td class="center">
                  <?php foreach ($otherCodes as $otherCode) {  if ($otherCode['Id'] == $order['otherCode']) { echo $otherCode['Code'];  } } ?>
				  <br>Other Cost : <?php printf("%.2f",  round($order['OtherCost'],2)); ?>
			  </td>
			  
			  <td class="center"><?php echo $order['ShipQty']; ?></td>
			  <td class="center"><?php echo $order['ProdShippingDate']; ?></td>
<!--			  
			  <td style="text-align: center;">
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" checked="checked" />
			  </td>

              <td style="text-align: center;"><?php if ($order['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" />
                <?php } ?>				

			    <div class="buttons">	  
					<a onclick="SetUpdate('Update','<?php echo $order['order_id']; ?>' );$('#form').submit();"  value="Update"  id="Update"  name="Update" class="button">Update</a>
				</div>
				
			  </td>	
			  -->
            </tr>
            <?php } ?>
			
            <?php } else { ?>
            <tr>
              <td class="center" colspan="15"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>			
			
          </tbody>
        </table>
		   <input type="hidden" name="InsertUpdateFlag" value="Update" />
		   <input type="hidden" name="processOrderId" value="Update" />

      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>

  </div>
</div>
<script type="text/javascript"><!--

function SetUpdate(action,order_id){
	document.forms["form"]["InsertUpdateFlag"].value =  action;
	document.forms["form"]["processOrderId"].value =  order_id;
	
}
function newproductshow(){  
  
}

function filter() {
	url = 'index.php?route=sale/stocks&control=shipementHistory&token=<?php echo $token; ?>';
	
	
	var filter_date = $('input[name=\'filter_date\']').attr('value');
	
	if (filter_date) {
		url += '&filter_date=' + encodeURIComponent(filter_date);
	}
	
	location = url;
}
//--></script>  
<script type="text/javascript"><!--
$(document).ready(function() {
	$('.date').datepicker({dateFormat: 'yy-mm-dd'});
});
//--></script> 
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script> 
<script type="text/javascript"><!--
$.widget('custom.catcomplete', $.ui.autocomplete, {
	_renderMenu: function(ul, items) {
		var self = this, currentCategory = '';
		
		$.each(items, function(index, item) {
			if (item.category != currentCategory) {
				ul.append('<li class="ui-autocomplete-category">' + item.category + '</li>');
				
				currentCategory = item.category;
			}
			
			self._renderItem(ul, item);
		});
	}
});

$('input[name=\'filter_customer\']').catcomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/customer/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						category: item.customer_group,
						label: item.name,
						value: item.customer_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'filter_customer\']').val(ui.item.label);
						
		return false;
	}
});
//--></script> 
<script>
function validateForm() {

  formAction = $('input[name=\'InsertUpdateFlag\']').attr('value');
  OrderId = document.forms["form"]["processOrderId"].value ;
	  
	  
	// Update Section

  var M1Weight = document.forms["form"]["M1Weight"+OrderId].value;
  if (M1Weight == "") {
    alert("Metal 1 - Weight must be filled out");
    return false;
  } 
  
  if (document.contains(document.getElementById("M2Weight"+OrderId))) {
		var M2Weight = document.forms["form"]["M2Weight"+OrderId].value;
		if (M2Weight == "") {
			alert("Metal 2 - Weight must be filled out");
			return false;
		}
  }

  
  if (document.contains(document.getElementById("G1ShapeId"+OrderId))) {
   
		var G1ShapeId = document.forms["form"]["G1ShapeId"+OrderId].value;
		if (G1ShapeId == 0) {
			alert("Gem 1 Shape must be selected");
			return false;
		}	 
		var G1SizeId = document.forms["form"]["G1SizeId"+OrderId].value;
		if (G1SizeId == 0) {
			alert("Gem 1 Size must be selected");
			return false;
		}
		var G1Count = document.forms["form"]["G1Count"+OrderId].value;
		if (G1Count == "") {
			alert("Gem 1 Count must be filled out");
			return false;
		}	
		var G1Wt = document.forms["form"]["G1Wt"+OrderId].value;
		if (G1Wt == "") {
			alert("Gem 1 Weight must be filled out");
			return false;
		}	  
	}
	
	if (document.contains(document.getElementById("G2ShapeId"+OrderId))) {
  
   
		var G2ShapeId = document.forms["form"]["G2ShapeId"+OrderId].value;
		if (G2ShapeId == 0) {
			alert("Gem 1 Shape must be selected");
			return false;
		}	 
		var G2SizeId = document.forms["form"]["G2SizeId"+OrderId].value;
		if (G2SizeId == 0) {
			alert("Gem 1 Size must be selected");
			return false;
		}
		var G2Count = document.forms["form"]["G2Count"+OrderId].value;
		if (G2Count == "") {
			alert("Gem 1 Count must be filled out");
			return false;
		}	
		var G2Wt = document.forms["form"]["G2Wt"+OrderId].value;
		if (G2Wt == "") {
			alert("Gem 1 Weight must be filled out");
			return false;
		}		  
	}
	
	if (document.contains(document.getElementById("G3ShapeId"+OrderId))) {
   
		var G3ShapeId = document.forms["form"]["G3ShapeId"+OrderId].value;
		if (G3ShapeId == 0) {
			alert("Gem 1 Shape must be selected");
			return false;
		}	 
		var G3SizeId = document.forms["form"]["G3SizeId"+OrderId].value;
		if (G3SizeId == 0) {
			alert("Gem 1 Size must be selected");
			return false;
		}
		var G3Count = document.forms["form"]["G3Count"+OrderId].value;
		if (G3Count == "") {
			alert("Gem 1 Count must be filled out");
			return false;
		}	
		var G3Wt = document.forms["form"]["G3Wt"+OrderId].value;
		if (G3Wt == "") {
			alert("Gem 1 Weight must be filled out");
			return false;
		}	  
	}
	
	if (document.contains(document.getElementById("G4ShapeId"+OrderId))) {
   
		var G4ShapeId = document.forms["form"]["G4ShapeId"+OrderId].value;
		if (G4ShapeId == 0) {
			alert("Gem 1 Shape must be selected");
			return false;
		}	 
		var G4SizeId = document.forms["form"]["G4SizeId"+OrderId].value;
		if (G4SizeId == 0) {
			alert("Gem 1 Size must be selected");
			return false;
		}
		var G4Count = document.forms["form"]["G4Count"+OrderId].value;
		if (G4Count == "") {
			alert("Gem 1 Count must be filled out");
			return false;
		}	
		var G4Wt = document.forms["form"]["G4Wt"+OrderId].value;
		if (G4Wt == "") {
			alert("Gem 1 Weight must be filled out");
			return false;
		}	  
	}
	
	if (document.contains(document.getElementById("G5ShapeId"+OrderId))) {
 
		var G5ShapeId = document.forms["form"]["G5ShapeId"+OrderId].value;
		if (G5ShapeId == 0) {
			alert("Gem 1 Shape must be selected");
			return false;
		}	 
		var G5SizeId = document.forms["form"]["G5SizeId"+OrderId].value;
		if (G5SizeId == 0) {
			alert("Gem 1 Size must be selected");
			return false;
		}
		var G5Count = document.forms["form"]["G5Count"+OrderId].value;
		if (G5Count == "") {
			alert("Gem 1 Count must be filled out");
			return false;
		}	
		var G5Wt = document.forms["form"]["G5Wt"+OrderId].value;
		if (G5Wt == "") {
			alert("Gem 1 Weight must be filled out");
			return false;
		}	  
  }
         
  var Setting = document.forms["form"]["Setting"+OrderId].value;
  if (Setting == 0) {   
    alert("Setting must be selected");
    return false;
  } 
  var Casting = document.forms["form"]["Casting"+OrderId].value;
  if (Casting == 0) {   
    alert("Casting must be selected");
    return false;
  }
  var Rhodium = document.forms["form"]["Rhodium"+OrderId].value;
  if (Rhodium == 0) {   
    alert("Rhodium must be selected");
    return false;
  }
  var OtherCode = document.forms["form"]["OtherCode"+OrderId].value;
  if (OtherCode == 0) {   
    alert("OtherCode must be selected");
    return false;
  }
  var Plating = document.forms["form"]["Plating"+OrderId].value;
  if (Plating == 0) {   
    alert("Plating must be selected");
    return false;
  }
  var FilingPolishing = document.forms["form"]["FilingPolishing"+OrderId].value;
  if (FilingPolishing == "") {
    alert("Filing Polishing must be filled out");
    return false;
  }

  var OtherCost = document.forms["form"]["OtherCost"+OrderId].value;
  if (OtherCost == "") {
    alert("Other Cost must be filled out");
    return false;
  }  
	  
	
  
}
  
</script>
<?php echo $footer; ?>