<?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']);
$change_price = 'yes';
?>

<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_procurement');">
                    <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"> ADD NEW ITEM DETAILS </b> </span>
                    </div>
                    <div class="actions">
                        <a class="btn green" onclick="saveInformation2('save_tems_details_procurement','<?php echo $row_rsodest['id']; ?>','form.items_details_form','#currentarea');return false;"> Save Item Details <i class="fa fa-check"></i> </a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <div class="table-container">
                        <div id="datatable_products_wrapper" class="dataTables_wrapper dataTables_extended_wrapper no-footer">
                          <div class="row">
                            <div class="col-md-7 col-sm-12">
                                <div class="dataTables_paginate paging_bootstrap_extended" id="datatable_products_paginate">
                                    <div class="pagination-panel"> Page 
                                        <a onClick="getpage('<?php echo $action?>','1','<?php echo $totalRows_rsodest; ?>','<?php echo $row_rsodest['id']; ?>','<?php echo $typesearch; ?>','<?php echo $searchtxt; ?>')" href="#" class="btn btn-sm default prev" title="First"><i class="fa fa-angle-double-left"></i></a>
                                        <a onClick="getpage('<?php echo $action?>','<?php echo ($pagenum-1); ?>','<?php echo $totalRows_rsodest; ?>','<?php echo $row_rsodest['id']; ?>','<?php echo $typesearch; ?>','<?php echo $searchtxt; ?>')" href="#" class="btn btn-sm default prev" title="Prev"><i class="fa fa-angle-left"></i></a>
                                        <input readonly="" value="<?php echo $pagenum; ?>" type="text" class="pagination-panel-input form-control input-mini input-inline input-sm" maxlenght="5" style="text-align:center; margin: 0 5px;">
                                        <a onClick="getpage('<?php echo $action?>','<?php echo ($pagenum+1); ?>','<?php echo $totalRows_rsodest; ?>','<?php echo $row_rsodest['id']; ?>','<?php echo $typesearch; ?>','<?php echo $searchtxt; ?>')" href="#" class="btn btn-sm default next" title="Next"><i class="fa fa-angle-right"></i></a> 
                                        <a onClick="getpage('<?php echo $action?>','<?php echo $total_pages; ?>','<?php echo $totalRows_rsodest; ?>','<?php echo $row_rsodest['id']; ?>','<?php echo $typesearch; ?>','<?php echo $searchtxt; ?>')" href="#" class="btn btn-sm default next" title="Next"><i class="fa fa-angle-double-right"></i></a> 
                                        of <span class="pagination-panel-total"><?php echo $total_pages;?></span>
                                    </div>
                                </div>
                                <div class="dataTables_length" id="datatable_products_length">
                                    <label> 
                                        <span class="seperator">|</span>View By 
                                        <select onchange="getstep('<?php echo $action; ?>');" name="datatable_products_length" id="datatable_products_length" aria-controls="datatable_products" class="form-control input-xsmall input-sm input-inline">
                                            <option <?php if($pagerows == 10){echo 'selected=""';} ?> value="10">10</option>
                                            <option <?php if($pagerows == 20){echo 'selected=""';} ?> value="20">20</option>
                                            <option <?php if($pagerows == 50){echo 'selected=""';} ?> value="50">50</option>
                                            <option <?php if($pagerows == 100){echo 'selected=""';} ?> value="100">100</option>
                                            <option <?php if($pagerows == 150){echo 'selected=""';} ?> value="150">150</option>
                                        </select> 
                                    records</label>
                                    <span class="seperator">|</span> Found : <b><?php echo $totalRows_rsodest; ?> records </b> 
                                </div>
                            </div>
                            <div class="col-md-5 col-sm-12">

                            </div>
                        </div>
                        <hr>

                        <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 Name </span> </label>
                                                    <label class="col-md-7 control-label"> <input type="text" name="item_name" id="item_name" class="form-control"/> </label>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-5 control-label"><span class="pull-left">Item/Service</span></label>
                                                    <label class="col-md-7 control-label"> 
                                                        <?php if($change_price == 'yes') { ?>
                                                            <select name="category_item_service" id="category_item_service" class="form-control">
                                                               <option value="">Select Option</option>
                                                               <option value="Optical Service">Optical Service</option>
                                                               <option value="Optical Item">Optical Item</option>
                                                           </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 Category</span></label>
                                                <label class="col-md-7 control-label"> 
                                                    <?php if($change_price == 'yes') { ?>
                                                        <select name="category" id="category" class="form-control">
                                                           <option value="">Select Category</option>
                                                           <?php $qry = mysql_query("SELECT * FROM item_categories ORDER BY category_name ASC");
                                                           while ($row = mysql_fetch_assoc($qry)){ ?>
                                                               <option <?php if($row_rsodest['group_id'] == $row['id']){echo 'selected=""'; } ?> value="<?php echo $row['id'];?>"><?php echo $row['category_name'];?></option>
                                                           <?php }?>
                                                       </select>
                                                   <?php }else {echo $row_rsodest['service_type']; } ?>
                                               </label>
                                           </div>

                                           <div class="form-group">
                                            <label class="col-md-5 control-label"><span class="pull-left"> Cost Price </span> </label>
                                            <label class="col-md-7 control-label">  <?php if($change_price == 'yes') { ?>  <input type="text" name="cost_price" id="cost_price" class="form-control" value="<?php echo $row_rsodest['cost_price'];?>"><?php }else {echo number_format($row_rsodest['cost_price'],2); } ?></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($change_price == 'yes') { ?>  <input onchange="$('.same_price_all').val(this.value);" type="text" name="price" id="price" class="form-control" value="<?php echo $row_rsodest['price'];?>"><?php }else {echo number_format($row_rsodest['price'],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($change_price == 'yes') { ?>  <input readonly type="text" name="insurance_price" id="insurance_price" class="form-control same_price_all" 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($change_price == 'yes') { ?>  <input readonly type="text" name="company_price" id="company_price" class="form-control same_price_all" 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($change_price == 'yes') { ?>  <input readonly type="text" name="staff_price" id="staff_price" class="form-control same_price_all" value="<?php echo $row_rsodest['price_staff'];?>"> <?php }else {echo number_format($row_rsodest['price_staff'],2); } ?></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"> <input type="text" name="rxclaim_code" id="rxclaim_code" class="form-control" value="<?php echo $row_rsodest['ins_item_code'];?>"></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"> <input type="text" name="quantity_available" id="quantity_available" class="form-control" value="<?php echo $row_rsodest['quantity_available']; ?>"> </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"> <input type="text" name="min_re_order_qty" id="min_re_order_qty" class="form-control" value="<?php 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">  <input type="text" name="re_order_qty" id="re_order_qty" class="form-control" value="<?php 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" style="display: none;">
    <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($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($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($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($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>