<?php echo $header; ?>

<style> 
input[type=text] {
  font-size:11px;
  height:20px;
  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=GemCounts] {
  width: 30px;
  text-align:center;
  padding-left:2px;
  padding-right:2px;
}
select{
    box-sizing: border-box;
    margin: 0;
    height:20px;
    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="" />Gemstone Purchases  </h1>
      
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form"  onsubmit="return validateForm()">
        <table class="list">
          <thead>
            <tr class="center">
   			  <td class="center">Date</td>
              <td class="center">Gem</td>
              <td class="center">Shape</td>
              <td class="center">Size</td>
              <td class="center">Count</td>
              <td class="center" style="width:20px;">Carat Weight</td>
              <td class="center">Total Cost</td>
              <td class="center">Currency</td>
			  <td class="center">Supplier Name</td>			  
			  <td class="center">Action</td>			  
            </tr>
          </thead>
		  


          <tbody>
            <tr class="newProduct"> 
              <td class="center" style="height:100px; " >
				<input type="text" name="transaction_date" value="" class="date" />
			  </td>			  
			  <td class="center">
					<select name="gemstone_id"  >
						<option value="0" selected="selected"><?php echo $text_none; ?></option>
						<?php foreach ($gemCodes as $gemCode) { ?>
								<option value="<?php echo $gemCode['gemstone_id']; ?>"><?php echo $gemCode['gemname']; ?></option>
						<?php } ?>
					</select><br><br>
			  </td>	
			  <td class="center">
					<select name="shape_id">
						<option value="0" selected="selected"><?php echo $text_none; ?></option>
						<?php foreach ($shapes as $shape) { ?>
								<option value="<?php echo $shape['shape_id']; ?>"><?php echo $shape['shape']; ?></option>
						<?php } ?>
					</select>
			  </td>	
			  <td class="center">
					<select name="size_id">
						<option value="0" selected="selected"><?php echo $text_none; ?></option>
						<?php foreach ($gemSizes as $gemsize) { ?>
								<option value="<?php echo $gemsize['size_id']; ?>"><?php echo $gemsize['size_code']; ?></option>
						<?php } ?>
					</select>
			  </td>	
			  <td><input type="text" name="count" value="" class="GemCounts" /></td>
			  <td ><input type="text" name="carat_weight" value="" class="currency" /></td>	
			  <td><input type="text" name="total_cost" value="" class="currency" /></td>			  
			  <td class="center">
					<select name="currency">
						<option value="0" selected="selected"><?php echo $text_none; ?></option>
						<?php foreach ($currencies as $currency) { ?>
						<?php if( $currency['code'] == 'INR' ){ ?>
								<option value="<?php echo $currency['code']; ?>" SELECTED><?php echo $currency['code']; ?></option>
						<?php }else{ ?>
								<option value="<?php echo $currency['code']; ?>"><?php echo $currency['code']; ?></option>
						<?php } ?>
						<?php } ?>
					</select>
			  </td>	
			  <td><input type="text" name="supplier_name" value="" class="currency" /></td>		
			  <td>
				<div class="buttons" id="newProductButton">	  
					<a onclick="$('#form').submit();" class="button">Save</a>
				</div>
			  </td>		
            </tr>
            
			
			
            <?php foreach ($orders as $order) { ?>
             <tr class="center">	
              <td ><?php echo date_format(date_create($order['transaction_date']),"d-M-Y"); ?></td>
			  <td><?php echo $order['gemstone']; ?></td>
			  <td><?php echo $order['shape']; ?></td>	
			  <td><?php echo $order['size']; ?></td>
			  <td><?php echo $order['count']; ?></td>	
			  <td><?php echo $order['carat_weight']; ?></td>			  
			  <td><?php echo $order['total_cost']; ?></td>	
			  <td><?php echo $order['currency']; ?></td>		
			  <td colspan=2><?php echo $order['supplier_name']; ?></td>	
			  
            </tr>	
			<?php } ?>			
			
			
          </tbody>
        </table>
		
		
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--

function newproductshow(){
  $(".newProduct").show();
  $(".oldProduct").hide();
  $("#newProductButton").hide();  
  $("#oldProductButton").show();  
}
function oldproductshow(){
  $(".newProduct").hide();
  $(".oldProduct").show();
  $("#oldProductButton").hide();  
  $("#newProductButton").show();  
}

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>
function validateForm() {
	
  var x = document.forms["form"]["transaction_date"].value;
  if (x == "") {
    alert("Transaction Date must be filled out");
    return false;
  }
  
	
  var x = document.forms["form"]["gemstone_id"].value;
  if (x == 0) {
    alert("Gemstone must be selected");
    return false;
  }
  var x = document.forms["form"]["shape_id"].value;
  if (x == 0) {
    alert("Shape must be selected");
    return false;
  }
  var x = document.forms["form"]["size_id"].value;
  if (x == 0) {
    alert("Size must be selected");
    return false;
  }
  var x = document.forms["form"]["count"].value;
  if (x == "") {
    alert("Count must be filled out");
    return false;
  }
  var x = document.forms["form"]["carat_weight"].value;
  if (x == "") {
    alert("Carat weight must be filled out");
    return false;
  }

  var x = document.forms["form"]["total_cost"].value;
  if (x == "") {
    alert("Total Cost must be filled out");
    return false;
  }
  
  var x = document.forms["form"]["supplier_name"].value;
  if (x == "") {
    alert("Supplier Name must be filled out");
    return false;
  }
}
</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);
		});
	}
});
//--></script> 
<?php echo $footer; ?>