<?php echo $header; ?>

<style> 
input[type=text] {
  width: 50px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: white;
  background-image: url('searchicon.png');
  background-position: 2px 2px; 
  background-repeat: no-repeat;
  padding: 2px;
  -webkit-transition: width 0.4s ease-in-out;
  transition: width 0.4s ease-in-out;
}

input[type=text]:focus {
  width: 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="" /> <?php echo $heading_title; ?> - Stocks </h1>
      <div class="buttons">	  
		<!-- <a onclick="$('#form').attr('action', '<?php echo $delete; ?>'); $('#form').attr('target', '_self'); $('#form').submit();" class="button"><?php echo $button_delete; ?></a> -->
	  </div>
    </div>
    <div class="content">
      <form action="" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <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="left"><?php if ($sort == 'customer') { ?>
                <a href="<?php echo $sort_customer; ?>" class="<?php echo strtolower($order); ?>">Product</a>
                <?php } else { ?>
                <a href="<?php echo $sort_customer; ?>">Product</a>
                <?php } ?></td>
				
              <td class="left">M1</td>
              <td class="left">M2</td>
              <td class="left">G1</td>
              <td class="left">G2</td>
              <td class="left">G3</td>
              <td class="left">G4</td>
              <td class="left">G5</td>
              <td class="left">M1 Wt</td>
              <td class="left">M2 Wt</td>
              <td class="left">G1 #</td>
              <td class="left">G1 Wt</td>
              <td class="left">G1 Size</td>
              <td class="left">G2 #</td>
              <td class="left">G2 Wt</td>
              <td class="left">G2 Size</td>
              <td class="left">G3 #</td>
              <td class="left">G3 Wt</td>
              <td class="left">G3 Size</td>
              <td class="left">G4 #</td>
              <td class="left">G4 Wt</td>
              <td class="left">G4 Size</td>
              <td class="left">G5 #</td>
              <td class="left">G5 Wt</td>
              <td class="left">G5 Size</td>
			  
			  <td class="left">Sett</td>
			  <td class="left">FilPol</td>
			  <td class="left">Rhod</td>
			  <td class="left">Cast</td>
			  <td class="left">Plat</td>
			  <td class="left">Oth</td>
			  <td class="left">Ship Ready</td>	
			  
            </tr>
          </thead>
          <tbody>
		  <!--
            <tr class="filter">
              <td></td>
              <td align="right"><input type="text" name="filter_order_id" value="<?php echo $filter_order_id; ?>" size="4" style="text-align: right;" /></td>
              <td><input type="text" name="filter_customer" value="<?php echo $filter_customer; ?>" /></td>              
              <td align="right"><input type="text" name="filter_total" value="<?php echo $filter_total; ?>" size="4" style="text-align: right;" /></td>
              <td><input type="text" name="filter_date_added" value="<?php echo $filter_date_added; ?>" size="12" class="date" /></td>
			  <td colspan=4></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $button_filter; ?></a></td>
			  
            </tr>
			-->
            <?php if ($orders) { ?>
            <?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="right"><?php echo $order['order_id']; ?></td> -->
              <td class="left"><?php echo $order['name']; ?></td>
			  
			  <td class="left"><?php echo $order['M1']; ?></td>
			  <td class="left"><?php echo $order['M2']; ?></td>
			  <td class="left"><?php echo $order['G1']; ?></td>
			  <td class="left"><?php echo $order['G2']; ?></td>
			  <td class="left"><?php echo $order['G3']; ?></td>
			  <td class="left"><?php echo $order['G4']; ?></td>
			  <td class="left"><?php echo $order['G5']; ?></td>
			  
			  <td class="left">
				<?php if($order['M1'] != "" ){ ?> 				
					<input type="text" name="<?php echo $order['order_id']; ?>M1" value="<?php echo $order['M1Wt']; ?>" style="" />
				<?php } ?>
			  </td>			  
			  <td class="left">
				<?php if($order['M2'] != "" ){ ?> 				
					<input type="text" name="<?php echo $order['order_id']; ?>M2" value="<?php echo $order['M2Wt']; ?>" style="" />
				<?php } ?>
			  </td>
			  
			  <?php if($order['G1'] != "" ){ ?> 								
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G1Wt" value="<?php echo $order['G1Wt']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G1#" value="<?php echo $order['G1#']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G1SizeId" value="<?php echo $order['G1SizeId']; ?>" style="" /></td>
			  <?php }else{ ?>
					<td></td><td></td><td></td>
			  <?php } ?>
			  
			  <?php if($order['G2'] != "" ){ ?> 								
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G2Wt" value="<?php echo $order['G2Wt']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G2#" value="<?php echo $order['G2#']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G2SizeId" value="<?php echo $order['G2SizeId']; ?>" style="" /></td>
			  <?php }else{ ?>
					<td></td><td></td><td></td>
			  <?php } ?>
			  <?php if($order['G3'] != "" ){ ?> 								
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G3Wt" value="<?php echo $order['G3Wt']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G3#" value="<?php echo $order['G3#']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G3SizeId" value="<?php echo $order['G3SizeId']; ?>" style="" /></td>
			  <?php }else{ ?>
					<td></td><td></td><td></td>
			  <?php } ?>
			  <?php if($order['G4'] != "" ){ ?> 								
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G4Wt" value="<?php echo $order['G4Wt']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G4#" value="<?php echo $order['G4#']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G4SizeId" value="<?php echo $order['G4SizeId']; ?>" style="" /></td>
			  <?php }else{ ?>
					<td></td><td></td><td></td>
			  <?php } ?>
			  <?php if($order['G5'] != "" ){ ?> 								
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G5Wt" value="<?php echo $order['G5Wt']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G5#" value="<?php echo $order['G5#']; ?>" style="" /></td>
					<td class="left"><input type="text" name="<?php echo $order['order_id']; ?>G5SizeId" value="<?php echo $order['G5SizeId']; ?>" style="" /></td>
			  <?php }else{ ?>
					<td></td><td></td><td></td>
			  <?php } ?>

			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>Setting" value="<?php echo $order['Setting']; ?>" style="" /></td>
			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>FilingPolishing" value="<?php echo $order['FilingPolishing']; ?>" style="" /></td>
			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>Rhodium" value="<?php echo $order['Rhodium']; ?>" style="" /></td>
			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>Casting" value="<?php echo $order['Casting']; ?>" style="" /></td>
			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>Plating" value="<?php echo $order['Plating']; ?>" style="" /></td>
			  <td class="left"><input type="text" name="<?php echo $order['order_id']; ?>OtherCost" value="<?php echo $order['OtherCost']; ?>" style="" /></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 } ?></td>
				
			<!--
              <td class="right"><?php foreach ($order['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>">
				Edit</a> ]
                <?php } ?></td> -->
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="7"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=sale/orderstockist&token=<?php echo $token; ?>';
	
	var filter_order_id = $('input[name=\'filter_order_id\']').attr('value');
	
	if (filter_order_id) {
		url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
	}
	
	var filter_customer = $('input[name=\'filter_customer\']').attr('value');
	
	if (filter_customer) {
		url += '&filter_customer=' + encodeURIComponent(filter_customer);
	}
	
	var filter_order_status_id = $('select[name=\'filter_order_status_id\']').attr('value');
	
	if (filter_order_status_id != '*') {
		url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
	}	

	var filter_total = $('input[name=\'filter_total\']').attr('value');

	if (filter_total) {
		url += '&filter_total=' + encodeURIComponent(filter_total);
	}	
	
	var filter_date_added = $('input[name=\'filter_date_added\']').attr('value');
	
	if (filter_date_added) {
		url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
	}
	
	var filter_date_modified = $('input[name=\'filter_date_modified\']').attr('value');
	
	if (filter_date_modified) {
		url += '&filter_date_modified=' + encodeURIComponent(filter_date_modified);
	}
				
	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> 
<?php echo $footer; ?>