<?php
include('accesscheck2.php');
require_once('Connections/courier.php');
require_once 'functions/functions.php';


if (!function_exists("GetSQLValueString")) {

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
        if (PHP_VERSION < 6) {
            $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        }

        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

        switch ($theType) {
            case "text":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "long":
            case "int":
                $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                break;
            case "double":
                $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                break;
            case "date":
                $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
                break;
            case "defined":
                $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
                break;
        }
        return $theValue;
    }

}

mysql_select_db($database_courier, $courier);
$id = $_POST['id'];
$sql = mysql_query("SELECT *, date_format(date_of_order,'%a, %e %M %Y') as purchase_order_date, date_format(expected_date,'%e %M %Y') as purchase_expected_date FROM requisition_orders WHERE purchase_order_no = '$id'", $courier) or die(mysql_error());
$patient_row = mysql_fetch_assoc($sql);?>


<div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <i class="icon-home"></i>
            <a href="index.html">Home</a>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span>Dashboard</span>
        </li>
    </ul>
    <div class="page-toolbar">
        <div class="btn-group pull-right">
            <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> Actions
                <i class="fa fa-angle-down"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li onclick="getstep('<?php echo $action; ?>','<?php echo $id; ?>');">
                    <a href="#">
                        <i class="icon-refresh"></i> Refresh
                    </a>
                </li>
                <li>
                    <a href="#" onclick="delInformtion('delete_requisition_order', '#currentarea', '<?php echo $id; ?>', 'Requisition Order No <?php echo $id; ?> ?', 'You are about to Delete Requisition Order No. <?php echo $id; ?> from the List of Requisition Orders.', 'Requisition Order No. <?php echo $id; ?> Deleted Successfully !');"> <i id="trash_<?php echo $id; ?>" class="icon-trash" style="color:red;"></i> <i style="display: none;" id="spin_refresh_<?php echo $id; ?>" class="fa fa-refresh fa-spin fa-fw"></i> Delete Requisition Order </a>
                </li>
                <li onclick="getstep('list_requisition_orders');">
                    <a href="#">
                        <i class="fa fa-search"></i> Search Requisition Orders
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
<form name="form" id="save_requisition_order">
<div class="row">
    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
        <div class="portlet light ">
            <div class="portlet-title">
                <div class="caption">
                    <span class="caption-subject bold uppercase font-dark">  REQUISITION ORDER DETAILS </span>
                </div>
                <div class="actions uppercase">
                    <span>  <b>Order Date:</strong> <span style="color:red; font-weight:bold;"><?php echo $patient_row['purchase_order_date']; ?></span></b> <b style="color:green;"> [ ORDER NO : <?php echo $patient_row['purchase_order_no'];?> ]</b></span> &nbsp;&nbsp; 
                     <?php if($patient_row['order_status']=='Approved'){?>
                         <a class="btn green" onclick="receiveSupplyQuantity('save_supply_requisition_order', '#currentarea', '<?php echo $id; ?>', 'Yes, Supply Order Now!', 'Supply Requisition Order ?', 'You are about to Supply Requisition Order No. <?php echo $id; ?> from the List of approved Requisition Orders. Please Note that your Quantity Available will reduced immediatley after this action', 'form#save_requisition_order');return false;"> Supply Order <i class="fa fa-check"></i> </a>
                     <?php } ?>
                </div>
            </div>
            <div class="portlet-body form">
               <?php
               $supplier_id = $patient_row['supplier'];
               $rsodest_supplier = mysql_query("SELECT * FROM departments where id='$supplier_id'");
               $row_rsodest_supplier = mysql_fetch_assoc($rsodest_supplier);?>
                
                <div class="row"  >
                    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
                        <div class="col-md-6">
                            <div class="row">
                                <div class="portlet light ">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <span class="caption-subject font-dark"> Supplier's Information </span>
                                        </div>
                                    </div>
                                    <div class="portlet-body form">
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Supplier's Name</span></label>
                                            <label class="col-md-7 control-label bold"> 
                                                <?php if(empty($row_rsodest_supplier['department_name'])){ echo '&nbsp;'; } echo $row_rsodest_supplier['department_name']; ?>
                                            </label>
                                            <input type="hidden" id="supplier_id" name="supplier_id" value="<?php echo $patient_row['supplier'];?>">
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Supplier's Address</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['supplier_address'])){ echo '&nbsp;'; } echo $patient_row['supplier_address']; ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Memo</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['memo'])){ echo '&nbsp;'; } echo $patient_row['memo']; ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Supply Date </span> </label>
                                            <label class="col-md-7 control-label bold">  <?php if($patient_row['order_status']=='Received'){ if(empty($patient_row['bill_date'])){ echo '&nbsp;'; } echo date('D, jS F, Y',  strtotime($patient_row['bill_date'])); }else{?> <input type="text" name="supplied_date" id="supplied_date" class="date_time_picker"><?php } ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Requisition Ref </span> </label>
                                            <label class="col-md-7 control-label bold">  <?php if($patient_row['order_status']=='Received'){ if(empty($patient_row['bill_ref'])){ echo '&nbsp;'; }echo $patient_row['bill_ref']; }else{?> <input type="text" name="bill_ref" id="bill_ref"> <?php } ?> </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="row">
                                <div class="portlet light ">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <span class="caption-subject font-dark"> Delivery Branch Information </span>
                                        </div>
                                    </div>
                                    <div class="portlet-body form">
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Deliver To</span></label>
                                            <label class="col-md-7 control-label bold"> 
                                             <?php 
                                                  $store_id=$patient_row['delivery_location'];
                                                  $rsodest_supplier = mysql_query("SELECT * FROM branches where id='$store_id'");
                                                  $row_rsodest_supplier = mysql_fetch_assoc($rsodest_supplier);
                                                 if(empty($row_rsodest_supplier['branch_name'])){ echo '&nbsp;'; } echo $row_rsodest_supplier['branch_name'];
                                               ?>
                                            </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Delivery Address</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['delivery_address'])){ echo '&nbsp;'; } echo $patient_row['delivery_address']; ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Due Date</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['purchase_expected_date'])){ echo '&nbsp;'; } echo $patient_row['purchase_expected_date']; ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Delivery Memo </span> </label>
                                            <label class="col-md-7 control-label bold">  <?php if($patient_row['order_status']=='Received'){ if(empty($patient_row['delivery_memo'])){ echo '&nbsp;'; } echo $patient_row['delivery_memo']; }else{?> <input type="text" name="delivery_memo" id="delivery_memo"> <?php } ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Requisition Raised By</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['user_name'])){ echo '&nbsp;'; } echo $patient_row['user_name']; ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Approved By</span></label>
                                            <label class="col-md-7 control-label bold"> <?php if(empty($patient_row['approved_by_user_name'])){ echo '&nbsp;'; } echo $patient_row['approved_by_user_name']; ?> </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

<div class="row" id="view_items_response_wrapper_2">
   <?php
       $purchase_id = $patient_row['purchase_order_no'];  
       include 'list_approved_requisitions_items.php';
   ?>
</div>