<?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 = mysql_real_escape_string($_POST['id']);
$searchtxt=$_POST["searchtext"];
$typesearch=$_POST["typesearch"];
$datatable_products_length = $_POST['datatable_products_length'];
if(empty($datatable_products_length)){$datatable_products_length = 50;}
if ($typesearch == 'item_category') {
 $searchtxt = $_POST["searchtext_2"];
}
$_SESSION['change_price']='no';

if ($searchtxt != '') {
    if ($typesearch == 'name') {
        $query_rsodest = "SELECT * FROM service_items WHERE item like '$searchtxt%' order by item";
    } if ($typesearch == 'price') {
        $query_rsodest = "SELECT * FROM service_items WHERE price = '$searchtxt' order by item";
    } if ($typesearch == 'qty_avail') {
        $query_rsodest = "SELECT * FROM service_items WHERE quantity_available = '$searchtxt' order by item";
    } if ($typesearch == 'item_category') {
        $query_rsodest = "SELECT * FROM service_items WHERE service = '$searchtxt' order by item";
    }
}

$row_rsodest = mysql_fetch_assoc(mysql_query("SELECT * FROM service_items WHERE id = '$id'"));

$companies = mysql_query("SELECT * FROM insurance_company ORDER BY type DESC,company_name");
while ($cn = mysql_fetch_assoc($companies)) {
    $all_companies.= '<option value=' . $cn['company_code'] . '>' . $cn['company_name'] . '</option>';
}
 $fetch = mysql_query("SELECT * FROM service_items_price WHERE provider_item_id = '".$row_rsodest['provider_item_id']."' ORDER BY id ASC");?>

<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="getpage('<?php echo $action?>','<?php echo ($pagenum); ?>','<?php echo $totalRows_rsodest; ?>','<?php echo $row_rsodest['id']; ?>','<?php echo $typesearch; ?>','<?php echo $searchtxt; ?>');">
                    <a href="#">
                        <i class="icon-refresh"></i> Refresh
                    </a>
                </li>
                <li onclick="getstep('list_of_all_items');">
                    <a href="#">
                        <i class="fa fa-search"></i> Search For Items
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
<form name="form" id="save_received_order" class="items_details_form">
<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"> UPDATE ITEM DETAIL FOR <b style="color:green;">[ <?php echo strtoupper($row_rsodest['item']); ?> ] </b> </span>
                </div>
                <div class="actions">
                <!-- <a class="btn green" onclick="saveInformation2('update_tems_details','<?php echo $row_rsodest['id']; ?>','form.items_details_form','#currentarea');return false;"> Update Item Details <i class="fa fa-check"></i> </a> -->
                </div>
            </div>
            <div class="portlet-body form">
                 
                
                <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"> Item Information </span>
                                        </div>
                                    </div>
                                    <div class="portlet-body form">
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left">Item Category</span></label>
                                            <label class="col-md-7 control-label"> 
                                                <?php if($_SESSION['change_price'] == 'yes') { ?>
                                                    <select name="category" id="category" class="form-control">
                                                    <option value="">Select Category</option>
                                            <?php $qry = mysql_query("SELECT DISTINCT service_type FROM service_items");
                                            while ($row = mysql_fetch_assoc($qry)){ ?>
                                            <option <?php if($row_rsodest['service_type'] == $row['service_type']){echo 'selected=""'; } ?> value="<?php echo $row['service_type'];?>"><?php echo $row['service_type'];?></option>
                                           <?php }?>
                                               </select>
                                                <?php }else {echo $row_rsodest['service']; } ?>
                                            </label>
                                        </div>
                                       
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Item Price </span> </label>
                                            <label class="col-md-7 control-label">  <?php if($_SESSION['change_price'] == 'yes') { ?>  <input type="text" name="price" id="price" class="form-control" value="<?php echo $row_rsodest['price_'.$_SESSION['name_code']];?>"><?php }else {echo number_format($row_rsodest['price_'.$_SESSION['name_code']],2); } ?></label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Insurance Price </span> </label>
                                            <label class="col-md-7 control-label"> <?php if($_SESSION['change_price'] == 'yes') { ?>  <input type="text" name="insurance_price" id="insurance_price" class="form-control" value="<?php echo $row_rsodest['price_insurance'];?>"><?php }else {echo number_format($row_rsodest['price_insurance'],2); } ?></label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Company Price </span> </label>
                                            <label class="col-md-7 control-label"> <?php if($_SESSION['change_price'] == 'yes') { ?>  <input type="text" name="company_price" id="company_price" class="form-control" value="<?php echo $row_rsodest['price_company'];?>"> <?php }else {echo number_format($row_rsodest['price_company'],2); } ?></label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Staff Price </span> </label>
                                            <label class="col-md-7 control-label"> <?php if($_SESSION['change_price'] == 'yes') { ?>  <input type="text" name="staff_price" id="staff_price" class="form-control" value="<?php echo $row_rsodest['price_staff'];?>"> <?php }else {echo number_format($row_rsodest['price_staff'],2); } ?></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"> Item Stocking Information </span>
                                        </div>
                                    </div>
                                    <div class="portlet-body form">
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Quantity Available </span></label>
                                            <label class="col-md-7 control-label"> <?php if(empty($row_rsodest['quantity_available_'.$_SESSION['name_code']])){ echo '&nbsp;';}else{ echo $row_rsodest['quantity_available_'.$_SESSION['name_code']];} ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Min Re-Order Quantity </span> </label>
                                            <label class="col-md-7 control-label"> <?php if(empty($row_rsodest['min_re_order_qty'])){ echo '&nbsp;';}else{ echo $row_rsodest['min_re_order_qty'];} ?> </label>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Re-Order Quantity </span> </label>
                                            <label class="col-md-7 control-label">  <?php if(empty($row_rsodest['re_order_qty'])){ echo '&nbsp;';}else{ echo $row_rsodest['re_order_qty'];}?> </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>
        </div>
    </div>
</div>
</form>

<div class="row" id="view_items_response_wrapper_2">
    <form name="form" class="items_details_form">
<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"> LIST OF INSURANCE & COMPANIES PRICING </span>
                </div>
                 <?php if($_SESSION['change_price'] == 'yes') { ?>
                <div class="actions">
                    <select name="total_selected" id="total_selected" class="form-control" onchange="getdisplay('company_id_', this.value, <?php echo mysql_num_rows($companies); ?>)">
                       <option value=""> Select </option>
                                                         <?php for ($index = 1; $index <= mysql_num_rows($companies); $index++) { ?>
                                                              <option <?php if(mysql_num_rows($fetch) == $index){ echo 'selected=""';} ?> value="<?php echo $index;?>"><?php echo $index;?></option>
                                                        <?php } ?>
                    </select>
                </div>
                  <?php } ?>
            </div>
            <div class="portlet-body form">
                <div class="row"  >
                    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
                        <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                    <th class="count">Insurance / Company Name</th>
                                                    <th>Agreed Price (GHS)</th>
                                                    <th>Check for Exclusion</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                 <?php 
                                                   $ix = 1; 
                                                  while($r = mysql_fetch_assoc($fetch)) {?>
                                                  <tr id="company_id_<?php echo $ix;?>" <?php if($ix>0){?>style="display:"<?php }?>>
                                                      <td>
                                                           <?php if($_SESSION['change_price'] == 'yes') { ?>
                                                          <select class="form-control" name="company_code_<?php echo $ix;?>" id="company_code_<?php echo $ix;?>">
                                                              <option value="">Select Company</option>
                                                               <?php 
                                                               $cos = mysql_query("SELECT * FROM insurance_company ORDER BY type DESC,company_name");
                                                               while($ro = mysql_fetch_assoc($cos)){ ?>
                                                              <option <?php if($ro['company_code'] == $r['ins_company']){ echo 'selected=""';} ?> value="<?php echo $ro['company_code'];?>"><?php echo $ro['company_name'];?></option>
                                                                 <?php } ?>
                                                          </select>
                                                           <?php }else { echo getinsurance($r['ins_company']); }  ?>
                                                      </td>
                                                      <td>
                                                           <?php if($_SESSION['change_price'] == 'yes') { ?>
                                                          <input class="form-control" value="<?php echo $r['price'];?>" placeholder="Enter Price" type="text" style="padding:2px;" name="company_pricing_<?php echo $ix;?>" id="company_pricing_<?php echo $ix;?>">
                                                           <?php }else{ echo number_format($r['price'],2); } ?>
                                                      </td>
                                                      <td>
                                                            <?php if($_SESSION['change_price'] == 'yes') { ?>
                                                          <label class="mt-checkbox"> Check to Exclude <input type="checkbox" value="yes" <?php if($r['exclusion'] == 'yes'){ echo 'checked=""';} ?> type="checkbox" name="exclusive_<?php echo $ix;?>" id="exclusive_<?php echo $ix;?>">
                                                                  <span></span>
                                                         </label>
                                                            <?php } else { if($r['exclusion'] == 'yes'){ echo 'Not Covered By '.getinsurance($r['ins_company']); } }?>
                                                      </td>
                                                  </tr>
                                                  <?php $ix++; } ?>
                                                  
                                                  <?php for ($x = mysql_num_rows($fetch)+1; $x <= mysql_num_rows($companies); $x++) { ?>
                                                  <tr id="company_id_<?php echo $x;?>" <?php if($x>0){ ?>style="display:none;"<?php }?>>
                                                      <td>
                                                          <select class="form-control"  name="company_code_<?php echo $x;?>" id="company_code_<?php echo $x;?>">
                                                              <option value="">Select Company</option>
                                                              <?php echo $all_companies;?>
                                                          </select>
                                                      </td>
                                                      <td><input class="form-control" placeholder="Enter Price" type="text" style="padding:2px;" name="company_pricing_<?php echo $x;?>" id="company_pricing_<?php echo $x;?>"></td>
                                                      <td>
                                                           <label class="mt-checkbox"> Check to Exclude <input type="checkbox" value="yes" type="checkbox" name="exclusive_<?php echo $x;?>" id="exclusive_<?php echo $x;?>">
                                                                  <span></span>
                                                              </label>
                                                      </td>
                                                  </tr>
                                                  <?php } ?>
                  </tbody>
                </table> 
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
</div>


<div class="row" id="">
<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 font-dark">Rx ITEM DETAILS </span>
                </div>
            </div>
            <div class="portlet-body form">
                <div class="row"  >
                    <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">Rx Item Name</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['item'])) {echo '&nbsp;';} echo $row_rsodest['item']; ?> </label>
                            </div>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">RxClaim Code</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['ins_item_code'])) {echo '&nbsp;';} echo $row_rsodest['ins_item_code']; ?> </label>
                            </div>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">RxClaim Category</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['service'])) {echo '&nbsp;';} echo $row_rsodest['service']; ?> </label>
                            </div>
                             <?php if($row_rsodest['service']=='Drugs'){?>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">Generic Name / Molecule </span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['generic_name'])) {echo '&nbsp;';} echo $row_rsodest['generic_name']; ?> </label>
                            </div>
                             <?php } ?>
                        </div>
                         <?php if($row_rsodest['service']=='Drugs'){?>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">ATC Code 4</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['atccode4'])) {echo '&nbsp;';} echo $row_rsodest['atccode4']; ?> </label>
                            </div>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">ATC Code 3</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['atccode3'])) {echo '&nbsp;';} echo $row_rsodest['atccode3']; ?> </label>
                            </div>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">ATC Code 2</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['atccode2'])) {echo '&nbsp;';} echo $row_rsodest['atccode2']; ?> </label>
                            </div>
                            <div class="form-group">
                                <label class="col-md-5 control-label"><span class="pull-left">ATC Code 1</span></label>
                                <label class="col-md-7 control-label bold"> <?php if (empty($row_rsodest['atccode1'])) {echo '&nbsp;';} echo $row_rsodest['atccode1']; ?> </label>
                            </div>
                        </div>
                         <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>