function StoreLaboratoryItemToBill($pid, $labtest_nr, $batch_nr, $bill_number, $insurance, $pricelist_no)
 {
     global $db, $root_path;
     global $user_id, $sid, $local_user;
     $this->debug = false;
     if ($this->debug) {
         echo "<b>class_tz_billing::StoreLaboratoryItemToBill(pid: {$pid}, batch_nr: {$batch_nr}, bill_number: {$bill_number})</b><br>";
     }
     $this->debug ? $db->debug = TRUE : ($db->debug = FALSE);
     require_once $root_path . 'include/care_api_classes/class_tz_insurance.php';
     $insurance_tz = new Insurance_tz();
     $contract = $insurance_tz->CheckForValidContract($pid);
     // do we have pending issues of prescriptions?
     // read all items out of the prescription table
     if (empty($contract['id']) or $contract['id'] = '') {
         $contract['id'] = 0;
     }
     $user_id = $_SESSION['sess_user_name'];
     // old code
     //    $this->sql = "select
     //                          encounter_nr,
     //                          parameters
     //                  FROM $this->tbl_lab_requests
     //                  WHERE batch_nr=".$batch_nr;
     $this->sql = "select care_test_request_chemlabor.*, care_test_request_chemlabor_sub.sub_id AS prescrip_nr,\r\n\t\tcare_test_request_chemlabor_sub.item_id AS p_item_id,\r\n\t\tcare_tz_drugsandservices.item_description\r\n\r\n\t\tFROM care_test_request_chemlabor_sub\r\n\t\tINNER JOIN care_test_request_chemlabor\r\n\t\tON care_test_request_chemlabor.batch_nr=care_test_request_chemlabor_sub.batch_nr\r\n\t\tINNER JOIN care_tz_drugsandservices\r\n\t\tON care_test_request_chemlabor_sub.item_id = care_tz_drugsandservices.item_id\r\n\t\tWHERE care_test_request_chemlabor_sub.sub_id=" . $labtest_nr;
     if ($this->debug) {
         echo $this->sql;
     }
     $result = $db->Execute($this->sql);
     //echo $result;
     //echo $batch_nr;
     require_once $root_path . 'include/care_api_classes/class_prescription.php';
     $drg_obj = new Prescription();
     while ($row = $result->FetchRow()) {
         //echo $this->records['paramater_name'];
         //$this->chemlab_testname = $this->GetNameOfLAboratoryFromID($this->records['item_number']);
         //$this->price = $this->GetPriceOfLAboratoryItemFromID($this->records['id']);
         $price = $this->getPrice($row['p_item_id'], $pricelist_no);
         $name = $drg_obj->GetNameOfItem($row['p_item_id']);
         if ($this->debug) {
             echo 'Testname: ' . $row['item_description'] . '<br>';
         }
         if ($this->debug) {
             echo 'Encounter_nr:    ' . $row['encounter_nr'] . '<br>';
         }
         if ($this->debug) {
             echo 'Prescription_nr:    ' . $row['prescrip_nr'] . '<br>';
         }
         if ($this->debug) {
             echo 'labtest_nr:    ' . $row['sub_id'] . '=' . $batch_nr . '<br>';
         }
         if ($this->debug) {
             echo 'contract id : ' . $contract['id'] . '<br>';
         }
         $this->chemlab_amount = 1;
         $this->sql = "\r\n\t\t\tINSERT INTO {$this->tbl_bill_elements}  " . "\t(" . "\t\tnr, " . "\t\tdate_change, " . "\t\tis_labtest, " . "\t\tis_medicine, " . "\t\tis_radio_test, " . "\t\tis_comment, " . "\t\tis_paid, " . "\t\tamount, " . "\t\tamount_doc, " . "\t\ttimes_per_day, " . "\t\tdays, " . "\t\tprice, " . "\t\tdescription, " . "\t\tnotes, " . "\t\titem_number, " . "\t\tbalanced_insurance, " . "\t\tinsurance_id, " . "               prescriptions_nr, " . "\t\tUser_Id)" . "\r\n\t\t\tVALUES (" . $bill_number . ", '" . time() . "', 1, 0, 0, 0, 1, 1, 1, 0, 0, " . $price . ", '" . $row['item_description'] . "', 0, " . $row['p_item_id'] . ", '" . $insurance . "', '" . $contract['id'] . "', '" . $row['prescrip_nr'] . "','" . $user_id . "')";
         if ($this->debug) {
             echo $this->sql;
         }
         $db->Execute($this->sql);
         $this->sql = "UPDATE {$this->tbl_lab_requests_sub} SET bill_number=" . $bill_number . "\r\n\t\t \tWHERE batch_nr= {$batch_nr}\r\n\t\t \tAND item_id=" . $row[p_item_id];
         if ($this->debug) {
             echo $this->sql;
         }
         $db->Execute($this->sql);
         // Mark these lines in the table prescription as "still billed". We can do this
         // in that way: Insert the billing number where we can find this article again...
         //herausfinden, was geändert wird, damit Rechnung als billed gekennzeichnet wird
         //$this->sql="UPDATE $this->tbl_lab_requests SET bill_number='".$bill_number."', bill_status='pending' WHERE batch_nr=".$pid;
         //if ($this->debug) echo $this->sql;
         //$db->Execute($this->sql);
     }
     // end while
     //    $this->parameters = $db->Execute($this->sql);
     //    while ($this->records=$this->parameters->FetchRow()) {
     //      if ($this->debug) echo $this->records['parameters']."<br>";
     //      parse_str($this->records['parameters'],$this->parameter_array);
     //      while(list($this->index,$this->chemlab_amount) = each($this->parameter_array)) {
     //  				//Strip the string baggage off to get the task id
     //  				$this->chemlab_testindex = substr($this->index,5,strlen($this->index)-6);
     //
     //          $this->chemlab_testname = $this->GetNameOfLAboratoryFromID($this->chemlab_testindex);
     //
     //          $this->price = $this->GetPriceOfLAboratoryItemFromID($this->chemlab_testindex);
     //          if ($this->debug) echo "the name of chemlab is:".$this->chemlab_testname." with a amount of ".$this->chemlab_amount." and a price of ".$this->price."<br>";
     //          require_once($root_path.'include/care_api_classes/class_tz_insurance.php');
     //		  $insurance_tz = New Insurance_tz();
     //		  $contract = $insurance_tz->CheckForValidContract($pid);
     //          // we have it all... now we store it into the billing-elements-table
     //          $this->sql ="INSERT INTO $this->tbl_bill_elements (nr, date_change, is_labtest, is_medicine, amount, price, balanced_insurance, insurance_id, description)
     //								 			VALUES (".$bill_number.",".time().",1,0,".$this->chemlab_amount.",'".$this->price."','".$insurance."','".$contract['id']."','".$this->chemlab_testname."')";
     //				  if ($this->debug) echo $this->sql;
     //				  $db->Execute($this->sql);
     //				  $insurance=0;
     //			  }
     //    }
     //    // Mark these lines in the table prescription as "still billed". We can do this
     //    // in that way: Insert the billing number where we can find this article again...
     //    $this->sql="UPDATE $this->tbl_lab_requests SET bill_number='".$bill_number."' , bill_status='pending' WHERE batch_nr=".$batch_nr;
     //    $db->Execute($this->sql);
 }
            if (!$prescriptionitem['total_dosage']) {
                $prescriptionitem['total_dosage'] = 1;
            }
        } else {
            if ($class == 'service') {
                $caption_dosage = 'Amount/Items';
            } else {
                $caption_dosage = 'Total Amount/Items';
            }
        }
        $nexttime = true;
    }
    ?>

<font class="adm_div"><?php 
    echo $pres_obj->GetNameOfItem($item_array[$i]);
    ?>
</font>
 <table border=0 cellpadding=2 width=100%>

   <tr bgcolor="#f6f6f6">
     <td><FONT SIZE=-1  FACE="Arial" color="#000066"><?php 
    echo $caption_dosage;
    ?>
</td> 
     <td>
	<?php 
    //select "dosage"
    if ($caption_dosage == 'Single dose(per intake)') {
        if ($sub_class == 'tabs' || $sub_class == 'caps') {
            echo '<select id="dosage' . $i . '" name="arr_dosage[' . $i . ']" onChange=reCalculate(total_dosage' . $i . ',dosage' . $i . ',timesperday' . $i . ',days' . $i . ')> ';