<?php error_reporting(E_ALL); ?>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/inventory_purchase_receive.js"></script>
<form action="<?php echo $form_action;?>" method="post" name="purchase_form" class="form-horizontal edit_form" enctype="multipart/form-data" method="post">    
<input type="hidden" name="hidden_id" value="<?php echo $purchase->id;?>" />  
<div class="col-md-12">
  <div class="form-group">
    <div class="col-md-4">
      	<label>Supplier Name: </label>        
        <?php $supName = $this->purchase_management_model->get_supplier_name($purchase->supplier_id); ?>
        <input type="text" class="form-control" value="<?php echo $supName; ?>" readonly="readonly" />
        <input type="hidden" name="supplier_id" class="form-control" value="<?php echo $purchase->supplier_id; ?>" readonly="readonly" />
    </div>
    <div class="col-md-4">
    	<label>Purchase Ref No: </label>
        <input type="text" class="form-control" name="purchase_ref_no" placeholder="Purchase Ref No" title="Purchase Ref No" alt="Purchase Ref No" value="<?php echo $purchase->purchase_ref_no; ?>" readonly="readonly" />
    </div>
  </div>
  <div class="form-group">
    <div class="col-md-4">
      <label>Invoice No: </label>
      <input type="text" class="form-control" name="invoice_no" placeholder="Invoice No" value="<?php echo $purchase->invoice_no;?>" readonly="readonly"/>
    </div>
    <div class="col-md-4">
      <div class="input-group">
      	<label>Invoice Date: </label>
        <div class="input-group">
            <input type="text" class="form-control" name="invoice_date" placeholder="Invoice Date" value="<?php echo date('d-m-Y',strtotime($purchase->invoice_date));?>" readonly="readonly"/>
            <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
        </div>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-md-4">
    	<label>Purchase for: </label>
      	<input type="text" class="form-control" name="purchase_for" placeholder="Purchase for" value="<?php echo $purchase->purchase_for;?>" readonly="readonly"/>
    </div>
    <div class="col-md-4">
      <div class="input-group">
      	<label>Receivable Date: </label>
        <div class="input-group">
            <input type="text" class="form-control" name="receivable_date" placeholder="Receivable Date" value="<?php echo date('d-m-Y',strtotime($purchase->receivable_date));?>" readonly="readonly"/>
            <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="col-xs-12">
    <div class="col-md-6" style="padding-left:0px;">
        <h4 class="major_txt_color">Item Details<span class="required">*</span></h4>
    </div>
</div> 
<div class="col-xs-12">
    <div class="row">
    	<div class="col-xs-12">        
            <div class=" float-clear">
                <div>
                    <div class="col-md-3">
                        <div class="form-group"><label>Category Name</label></div>
                    </div> 
                    
                    <div class="col-md-3">
                        <div class="form-group"><label>Item Name</label></div>
                    </div>
                    
                    <div class="col-md-1">
                        <div class="form-group"><label>UOM</label></div>
                    </div>
                    
                    <div class="col-md-2">
                        <div class="form-group"><label>Received Qty</label></div>
                    </div>
                    
                    <div class="col-md-2">
                        <div class="form-group"><label>Receive Qty</label></div>
                    </div>            
                </div>
            </div>
        </div>
    </div>
</div>

<div class="col-xs-12 item_container">
    <?php $length = count($po_items); ?>
    <?php foreach($po_items as $k=> $items) { //echo "<pre>"; print_r($items); echo "</pre>";?>
        <input type="hidden" class="edit_item_id" name="edit_item_id[<?php echo $k;?>]" value="<?php echo $items->id;?>"/>
        <input type="hidden" name="inv_item_ids[<?php echo $k; ?>]" value="<?php echo $items->item_id; ?>" />
        <input type="hidden" name="old_qty[<?php echo $items->id;?>]" value="<?php echo $items->quantity;?>">
        
        <div class="item float-clear">
            <div class="item_details">
                <input type="hidden" name="poi_id[<?php echo $k;?>]" class="poi_id" value="<?php echo $items->id;?>" />
                <div class="col-md-3">
                    <div class="form-group">
                    	<?php $catName = $this->purchase_management_model->get_category_name($items->category_id); ?>
                       	<input type="text" placeholder="Category Name" value="<?php echo $catName;?>" readonly="readonly"/>                          
                        <input type="hidden" class="form-control cls-w-70 category_id" name="category_id[<?php echo $k;?>]" placeholder="Category Name" value="<?php echo $items->category_id;?>" readonly="readonly"/>
                    </div>
                </div> 
                
                <div class="col-md-3">
                    <div class="form-group">
                        <?php $itmName = $this->purchase_management_model->get_item_name($items->item_id); ?>
                        <input type="text" placeholder="Item Name" value="<?php echo $itmName;?>" readonly="readonly"/>
                        <input type="hidden" class="form-control cls-w-70 item_id" name="item_id[<?php echo $k;?>]" placeholder="Item Name" value="<?php echo $items->item_id;?>" readonly="readonly"/>
                    </div>
                </div>
                
                <div class="col-md-1">
                    <div class="form-group">
                        <input type="text" class="form-control cls-w-70 qty integer_value" name="qty[<?php echo $k;?>]" placeholder="Qty" onkeyup="calculate_amount_by_qty(this)" value="<?php echo $items->quantity;?>" readonly="readonly" />
                        
                        <?php if(!empty($items->unit_name)) { ?><span class="uom" style="color:#0B45B3;"><b>UOM:<?php echo $items->unit_name;?></b></span><?php } ?>
                        <input type="hidden" class="form-control hidden_uom" name="hidden_uom[<?php echo $k;?>]" value="<?php echo $items->uom;?>" />
                    </div>
                </div>
                
                <div class="col-md-2">
                    <div class="form-group">
                        <div class="input-group cls-w-100">
                            <!--<div class="input-group-addon">$</div>-->
                            <!--<input type="text" class="form-control float_value cls-w-100 price" name="price[<?php echo $k;?>]" placeholder="Price" onkeyup="calculate_amount_by_price(this);" value="<?php echo $items->unit_price;?>" <?php echo $readonly;?> />-->
                            <input type="text" class="form-control cls-w-70 received_qty integer_value received_qty" name="received_qty[<?php echo $k;?>]" placeholder="Received Qty" value="<?php echo ($items->received_qty) ? $items->received_qty: 0;?>" readonly="readonly"/>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-2">
                    <div class="form-group">
                        <div class="input-group cls-w-100">                            
                            <input type="text" class="form-control cls-w-70 receive_qty integer_value" name="receive_qty[<?php echo $k;?>]" placeholder="Receive Qty" <?php if($items->quantity == $items->received_qty){ ?> readonly="readonly"<?php } ?>/>
                        </div>
                    </div>
                </div>
                
            </div>
           <!-- <div class="add_row_action">
                <label class="">
                    <?php if ($length == ($k + 1)) {?>
                        <i class="fa fa-2x fa-plus-circle add-row addRow_color"></i>
                    <?php }?>
                    <?php if ($length > 1) {?>
                        <i class="fa fa-2x fa-minus-circle remove-row addRow_color"></i>
                    <?php }?>
                </label>
            </div>-->
        </div>
    <?php } ?>
</div> <br/>

<div class="col-md-12">
    <div class="col-md-4">
        <label>Received Date: </label>
        <div class="input-group">
            <input type="text" class="form-control datepicker" name="received_date" placeholder="DD-MM-YYYY"/>
            <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
        </div>
    </div>
</div>

<!--<div class="col-md-12" style="margin-top:2%;">              
  <div class="col-md-4">                              
    <div class="form-group">
      <div class="input-group cls-w-100">
        <div class="input-group-addon">$</div>
        <input type="text" class="form-control" name="total" placeholder="Total Amount" value="<?php echo $purchase->total_amount;?>" readonly />
      </div>
    </div>
    <div class="form-group">
      <select name="payment" class="form-control select2">
        <option value="">Select Payment Status</option>
        <option value="1" <?php echo ($purchase->payment == 1) ? 'selected' : '';?>>Unpaid</option>
        <option value="2" <?php echo ($purchase->payment == 2) ? 'selected' : '';?>>Paid</option>
      </select>
    </div>
  </div>
  <div class="col-md-6">
    <div class="form-group">
      <textarea class="form-control" name="desc" style="min-width: 100%; height:85px;" placeholder="Description"><?php echo $purchase->desc; ?></textarea>
    </div>
  </div>
</div>-->
<div class="form-actions float-clear">
    <input type="submit" name="submit" value="Update" class="btn btn-primary" style="padding: 5px 50px;"/>
    <input class="btn btn-primary reset" type="reset" value="Reset" style="padding: 5px 50px;"/>
</div>
</form>