<?php session_start();
include('../accesscheck2.php');
require_once('../Connections/courier.php'); 
require_once '../functions/functions.php';
mysql_select_db($database_courier, $courier);

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;
}
}

  $process_claim_no = $_GET['id'];
  $dateInerface = $_GET['dateValue'];
  $dateValue = date('Y-m', strtotime($_GET['dateValue']));
  $itemID = $_GET['itemID'];
  if ($itemID == "All") {
    $report_qry = mysql_query("SELECT * FROM stocktaking WHERE `date` = '$dateValue'", $courier);
  }else{
    $report_qry = mysql_query("SELECT * FROM stocktaking WHERE item_id = '$itemID' AND `date` = '$dateValue'", $courier);
  }

  $total_count_patient = mysql_num_rows($report_qry);
  //$row_rsodest = mysql_fetch_assoc($report_qry);
  $report_type = 'dsr';

  

?>


<head>
    <meta charset="utf-8" />
    <title> Report Generation </title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=0" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" media="all" />
    <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all"/>
</head>
<style type="text/css" media="all">
    body{
        margin: 0;
    }
    .text-danger strong {
      color: #9f181c;
  }
  .text-danger {
      color: #9f181c;
  }
  .receipt-main {
     background: #ffffff none repeat scroll 0 0;
     /*border-bottom: 12px solid #333333;*/
     border-top: 12px solid #9f181c;
     /*margin-top: 50px;*/
     margin-bottom: 50px;
     padding: 40px 30px !important;
     position: relative;
     box-shadow: 0 1px 21px #acacac;
     color: #333333;
     font-family: open sans;
 }
 .receipt-main p {
     color: #333333;
     font-family: open sans;
     line-height: 1.42857;
 }
 .receipt-footer h1 {
     font-size: 15px;
     font-weight: 400 !important;
     margin: 0 !important;
 }
 .receipt-main::after {
     background: #414143 none repeat scroll 0 0;
     content: "";
     height: 5px;
     left: 0;
     position: absolute;
     right: 0;
     top: -13px;
 }
 .receipt-main thead {
     background: #414143 none repeat scroll 0 0;
 }
 .receipt-main thead th {
     color:#fff;
 }
 .receipt-main .amount {
    text-align: right
}
.receipt-right h5 {
 font-size: 16px;
 font-weight: bold;
 margin: 0 0 7px 0;
}
.receipt-right p {
 font-size: 12px;
 margin: 0px;
}
.receipt-right p i {
 text-align: center;
 width: 18px;
}
/*.receipt-main td {
 padding: 9px 20px !important;
}*/
/*.receipt-main th {
 padding: 12px 15px !important;
}*/
.receipt-main td {
 font-size: 13px;
 font-weight: initial !important;
}
.receipt-main td p:last-child {
 margin: 0;
 padding: 0;
}	
.receipt-main td h2 {
 font-size: 20px;
 font-weight: 900;
 margin: 0;
 text-transform: uppercase;
}
.receipt-header-mid .receipt-left h1 {
 font-weight: 100;
 margin: 34px 0 0;
 text-align: right;
 text-transform: uppercase;
}
.receipt-header-mid {
 margin: 24px 0;
 overflow: hidden;
}

#container {
 background-color: #dcdcdc;
}

/*tr:nth-child(even) {
   background-color: # !important;
}*/

.test{
   border-right: 2px solid #9f181c !important;
   text-align: center !important;
}
</style>



<div class="container-fluid">
	<div class="row">
        <div class="receipt-main col-xs-12 col-sm-12 col-md-12">
            <div class="row">
             <div class="receipt-header">
               <div class="col-xs-6 col-sm-6 col-md-6">
                  <div class="receipt-left">
                     <img class="img-responsive" src="../images/app_pics/rns_logo.jpeg" style="width: 71px;">
                 </div>
             </div>
             <div class="col-xs-6 col-sm-6 col-md-6 text-right">
              <div class="receipt-right">
                 <h5>ROBERT AND SONS LTD.</h5>
                 <p>+233034789/09678909 <i class="fa fa-phone"></i></p>
                 <p>INFO@ROBERTANDSON.COM <i class="fa fa-envelope-o"></i></p>
                 <p>ADABRAKA BRANCH <i class="fa fa-location-arrow"></i></p>
             </div>
         </div>
     </div>
 </div>

 <div class="row">
    <div class="receipt-header receipt-header-mid">
       <div class="col-xs-8 col-sm-8 col-md-8 text-left">
          <div class="receipt-right">
            <h3> <?php echo strtoupper('STOCK TAKING REPORT'); ?> </h3>
            <h4 class="text-danger"> DATE: <b><?php echo $newDate = date("F Y", strtotime($dateInerface));?></b> </h4>
            <!-- <h4 class="text-danger"> VISIT NO : <b><?php echo strtoupper($process_claim_no) ?></b> </h4>
            <h4 class="text-danger"> BRANCH : <b><?php echo strtoupper(branchName($row_rsodest['branch_id'], $courier)) ?></b> </h4>
            <h5 class="text-danger" style="display: none;"> PAYMENT MODE :  <?php if( $report_type == 'clov'){echo 'ALL MODES';}else{ echo strtoupper($payment_method_txt);} ?> </h5> -->
        </div>
    </div>
    <div class="col-xs-4 col-sm-4 col-md-4">
      <div class="receipt-left">
         <h1></h1>
     </div>
 </div>
</div>
</div>

<?php if($report_type=='dsr'){ ?>
    <table class="table table-bordered">
        <thead>
          <tr>
            <th colspan="2"></th>
            <th colspan="3" class="test">Stores</th>
            <th colspan="3" class="test">Adabraka</th>
            <th colspan="3" class="test">Kumasi</th>
            <th colspan="3" class="test">Adenta</th>
            <th colspan="3" class="test">Danquah</th>
            <th colspan="3" class="test">Weija</th>
            <th colspan="3" class="test">Tema</th>
            <th colspan="3" class="test">Mobile Unit</th>
            <th colspan="3" class="test">East Legon</th>
            <th colspan="3" class="test">Ahodwo</th>
          </tr>
            <tr style=" font-size: 9px">
                <th>SN</th>
                <th>ITEM NAME</th>
                <th> Qty Avail</th>
                <th>Qty Phy</th>
                <th class="test">Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy  (Kumasi)</th>
                <th class="test"> Qty Var</th>

                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                <th> Qty Avail</th>
                <th> Qty Phy</th>
                <th class="test"> Qty Var</th>
                
                
            </tr>
        </thead>
        <tbody>
            <?php 
            if($total_count_patient > 0){
                $i=1;
                while($row = mysql_fetch_assoc($report_qry)){ ?>
                    <tr>
                        <td class=""> <?php echo $i;?> </td>
                        <td class=""> <?php echo $row['item'] ?> </td>
                        <td class=""> <?php echo $row['quantity_onhand'];?> </td>
                        <td class=""> <?php echo $row['quantity_onhand_physical'];?> </td>
                        <td class="test"> <?php echo $row['quantity_onhand_variation'];?> </td>
                        
                        <td class=""> <?php echo $row['quantity_available_adabraka'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_adabraka'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_adabraka'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_kumasi'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_kumasi'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_kumasi'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_adenta'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_adenta'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_adenta'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_danquah'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_danquah'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_danquah'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_weija'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_weija'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_weija'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_tema'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_tema'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_tema'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_mobile_unit'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_mobile_unit'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_mobile_unit'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_east_legon'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_east_legon'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_east_legon'];?> </td>

                        <td class=""> <?php echo $row['quantity_available_ahodwo'];?> </td>
                        <td class=""> <?php echo $row['quantity_physical_ahodwo'];?> </td>
                        <td class="test"> <?php echo $row['quantity_variation_ahodwo'];?> </td>
                    </tr>
                    <?php $i++; }  ?>
                    
                <?php } else{ ?>
                    <tr><td colspan="32" style="text-align: center;">No Records Found</td></tr>
                <?php } ?>
            </tbody>
        </table>
    <?php } 

    if($report_type=='ssr'){ ?>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>SN</th>
                    <th>DATE TIME</th>
                    <th>ITEM NAME</th>
                    <th>ITEM TYPE</th>
                    <th class="amount">AMOUNT</th>
                    <th class="amount">VAT EXCL</th>
                    <th class="amount">VAT/NHIL</th>
                    <th class="amount">DISCOUNT</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                if($total_count > 0){
                    $i=1;
                    while($row = mysql_fetch_assoc($report_qry)){ ?>
                        <tr>
                            <td class=""> <?php echo $i;?> </td>
                            <td class=""> <?php echo date('d-m-Y g:ia',  strtotime($row['date_added']));?> </td>
                            <td class=""> <?php echo $row['sub_item_service_type'];?> </td>
                            <td class=""> <?php echo $row['item_service'];?> </td>
                            <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['total_amount'],2); $total_amount = $total_amount + ($row['total_amount']);?> </td>
                            <td class="amount"> <?php $vatnhil = 0.03*($row['total_amount']); $vatexl = ($row['total_amount'])-$vatnhil;  echo number_format($vatexl,2) ; $vatexcl_total = $vatexcl_total+$vatexl;?></td>
                            <td class="amount"> <?php echo number_format($vatnhil,2) ; $vatnhil_total = $vatnhil_total+$vatnhil;  ?> </td>
                            <td class="amount"><i class="fa fa-inr"></i> <?php 
                            $discount_info = getDiscountAllowed($row['process_claim_no'], $row['discount_id']);echo $discount_info; $discount_total=$discount_total+$discount_info;?></td>
                        </tr>
                        <?php $i++; }  ?>
                        <tr>
                            <td class="text-right" colspan="4"><h2><strong>Total </strong></h2></td>
                            <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($total_amount, 2); ?> </strong></h2></td>
                            <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($vatexcl_total, 2); ?> </strong></h2></td>
                            <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($vatnhil_total, 2); ?> </strong></h2></td>
                            <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($discount_total, 2); ?> </strong></h2></td>
                        </tr>
                    <?php } else{ ?>
                        <tr><td colspan="9" style="text-align: center;">No Records Found</td></tr>
                    <?php } ?>
                </tbody>
            </table>
        <?php }                

        else if($report_type=='ssrbonc'){ ?>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>SN</th>
                        <th>Patient No</th>
                        <th>Surname</th>
                        <th>First Name</th>
                        <th>Tel Number</th>
                        <th>Email</th>
                        <th class="amount">Total Amount</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                    if($total_count > 0){
                        $i=1;
                        while($row = mysql_fetch_assoc($report_qry)){ ?>
                            <tr>
                                <td class=""> <?php echo $i;?> </td>
                                <td class=""> <?php echo $row['card_number'];?> </td>
                                <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['surname']);?> </td>
                                <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['othernames']);?> </td>
                                <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['tel']);?> </td>
                                <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['email']);?> </td>
                                <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['total_amount'],2);  $total_amount = $total_amount + $row['total_amount'];?> </td>
                            </tr>
                            <?php $i++; }  ?>
                            <tr>
                                <td class="text-right" colspan="6"><h2><strong>Total </strong></h2></td>
                                <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($total_amount, 2); ?> </strong></h2></td>
                            </tr>
                        <?php }else{ ?>
                            <tr><td colspan="8" style="text-align: center;">No Records Found</td></tr>
                        <?php } ?>
                    </tbody>
                </table>
            <?php }
            else if($report_type=='ssrboncv' || $report_type == 'clov'){ ?>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>SN</th>
                            <th>Consultation Date</th>
                            <th>Patient No</th>
                            <th>Surname</th>
                            <th>First Name</th>
                            <th>Visit No.</th>
                            <th>Tel Number</th>
                            <th>Email</th>
                            <?php if($_SESSION['security'] != 'MEDICAL OFFICER'){ ?>
                                <th class="amount">Total Amount</th>
                            <?php } ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        if($total_count > 0){
                            $i=1;
                            while($row = mysql_fetch_assoc($report_qry)){ ?>
                                <tr>
                                    <td class=""> <?php echo $i;?> </td>
                                    <td class=""> <?php echo date('jS M,Y',  strtotime($row['date_of_consultation']));?> </td>
                                    <td class=""> <?php echo $row['card_number'];?> </td>
                                    <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['title']).' '. strtoupper($row['surname']);?> </td>
                                    <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['othernames']);?> </td>
                                    <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['process_claim_no']);?> </td>
                                    <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['tel']);?> </td>
                                    <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['email']);?> </td>
                                    <?php if($_SESSION['security'] != 'MEDICAL OFFICER'){ ?>
                                        <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['total_amount'],2);  $total_amount = $total_amount + $row['total_amount'];?> </td>
                                    <?php } ?>
                                </tr>
                                <?php $i++; }  ?>
                                <?php if($_SESSION['security'] != 'MEDICAL OFFICER'){ ?>
                                    <tr>
                                        <td class="text-right" colspan="8"><h2><strong>Total </strong></h2></td>
                                        <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($total_amount, 2); ?> </strong></h2></td>
                                    </tr>
                                <?php } ?>
                            <?php }else{ ?>
                                <tr><td colspan="8" style="text-align: center;">No Records Found</td></tr>
                            <?php } ?>
                        </tbody>
                    </table>
                <?php } 
                else if($report_type=='rpmm'){ ?>
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>SN</th>
                                <th>Consultation Date</th>
                                <th>Patient No</th>
                                <th>Full Name</th>
                                <th>Visit No.</th>
                                <th>Payment Mode</th>
                                <th>Item Name</th>
                                <th>Unit Price</th>
                                <th>Qty</th>
                                <th class="amount">Total Amount</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            if($total_count > 0){
                                $i=1;
                                while($row = mysql_fetch_assoc($report_qry)){ ?>
                                    <tr>
                                        <td class=""> <?php echo $i;?> </td>
                                        <td class=""> <?php echo date('jS M,Y',  strtotime($row['date_of_consultation']));?> </td>
                                        <td class=""> <?php echo $row['card_number'];?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['title']).' '. strtoupper($row['surname'].' '.$row['othernames']);?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['process_claim_no']);?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['pay_by']);?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['item']);?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['unit_price']);?> </td>
                                        <td><i class="fa fa-inr"></i> <?php echo strtoupper($row['qty']);?> </td>
                                        <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['total_amount'],2);  $total_amount = $total_amount + $row['total_amount'];?> </td>
                                    </tr>
                                    <?php $i++; }  ?>
                                    <tr>
                                        <td class="text-right" colspan="9"><h2><strong>Total </strong></h2></td>
                                        <td class="text-left text-danger amount"><h2><strong><i class="fa fa-inr"></i>  <?php echo number_format($total_amount, 2); ?> </strong></h2></td>
                                    </tr>
                                <?php }else{ ?>
                                    <tr><td colspan="8" style="text-align: center;">No Records Found</td></tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    <?php } ?>


                </div>    
            </div>
        </div>
