function StoreLaboratoryItemToBill($pid, $batch_nr, $bill_number, $insurance)
 {
     global $db, $root_path;
     $this->debug = FALSE;
     if ($this->debug) {
         echo "<b>class_tz_billing::LaboratoryItemToBill(pid: {$pid}, batch_nr: {$batch_nr}, bill_number: {$bill_number}, insurance: {$insurance})</b><br>";
     }
     $this->debug ? $db->debug = TRUE : ($db->debug = FALSE);
     // do we have pending issues of prescriptions?
     // read all items out of the prescription table
     // old code
     //    $this->sql = "select
     //                          encounter_nr,
     //                          parameters
     //                  FROM $this->tbl_lab_requests
     //                  WHERE batch_nr=".$batch_nr;
     $this->sql = "select *\n\n                  FROM care_test_request_chemlabor_sub c_sub, care_tz_laboratory_param c_param\n                  WHERE c_sub.sub_id=" . $batch_nr . " AND c_sub.paramater_name=c_param.id";
     $result = $db->Execute($this->sql);
     while ($row = $result->FetchRow()) {
         //echo $this->records['paramater_name'];
         //$this->chemlab_testname = $this->GetNameOfLAboratoryFromID($this->records['id']);
         //$this->price = $this->GetPriceOfLAboratoryItemFromID($this->records['id']);
         if ($this->debug) {
             echo 'id      : ' . $row['id'] . '<br>';
         }
         if ($this->debug) {
             echo 'Testname: ' . $row['name'] . '<br>';
         }
         if ($this->debug) {
             echo 'Price:    ' . $row['price'] . '<br>';
         }
         $insurance_tz = new Insurance_tz();
         $contract = $insurance_tz->CheckForValidContract($pid);
         if ($this->debug) {
             echo 'contract id :    ' . $contract['id'] . '<br>';
         }
         //$contract['id'] = 12;
         $this->chemlab_amount = 1;
         $this->sql = "INSERT INTO {$this->tbl_bill_elements} (nr, date_change, is_labtest, is_medicine, amount, price, balanced_insurance, insurance_id, description)\n\t\t\tVALUES (" . $bill_number . "," . time() . ",1,0," . $this->chemlab_amount . ",'" . $row['price'] . "','" . $insurance . "','" . $contract['id'] . "','" . $row['name'] . "')";
         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 sub_id=" . $batch_nr;
     if ($this->debug) {
         echo $this->sql;
     }
     $db->Execute($this->sql);
     //    $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);
 }
 function StoreRadiologyItemToBill($pid, $batch_nr, $bill_number, $insurance, $pricelist_no)
 {
     global $db, $root_path;
     global $user_id, $sid, $local_user;
     $this->debug = false;
     $this->debug ? $db->debug = TRUE : ($db->debug = FALSE);
     if ($this->debug) {
         echo "<b>class_tz_billing::StoreRadiologyItemToBill(pid: {$pid}, batch_nr: {$batch_nr}, bill_number: {$bill_number}, insurance: {$insurance})</b><br>";
     }
     // do we have pending issues of prescriptions?
     // read all items out of the prescription table
     // old code
     //    $this->sql = "select
     //                          encounter_nr,
     //                          parameters
     //                  FROM $this->tbl_lab_requests
     //                  WHERE batch_nr=".$batch_nr;
     require_once $root_path . 'include/care_api_classes/class_prescription.php';
     $drg_obj = new Prescription();
     $user_id = $_SESSION['sess_user_name'];
     $this->sql = "select care_test_request_radio.*,\r\n\t\tcare_tz_drugsandservices.item_id,care_tz_drugsandservices.item_description\r\n\r\n\t\tFROM {$this->tbl_rad_requests}\r\n\t\tINNER JOIN care_tz_drugsandservices\r\n\t\tON care_tz_drugsandservices.item_id = care_test_request_radio.test_request\r\n\r\n\t\tWHERE batch_nr=" . $batch_nr;
     $result = $db->Execute($this->sql);
     if ($this->debug) {
         echo $result;
     }
     //echo $result;
     //echo $batch_nr;
     while ($row = $result->FetchRow()) {
         $price = $this->getPrice($row['item_id'], $pricelist_no);
         if ($this->debug) {
             echo 'Testname: ' . $row['test_request'] . '<br>';
         }
         if ($this->debug) {
             echo 'Encounter_nr:    ' . $row['encounter_nr'] . '<br>';
         }
         if ($this->debug) {
             echo 'radtest_nr:    ' . $row['batch_nr'] . '=' . $batch_nr . '<br>';
         }
         require_once $root_path . 'include/care_api_classes/class_tz_insurance.php';
         $insurance_tz = new Insurance_tz();
         $contract = $insurance_tz->CheckForValidContract($pid);
         if ($this->debug) {
             echo 'contract id : ' . $contract['id'] . '<br>';
         }
         //$contract['id'] = 12;
         $radio_amount = $row[number_of_tests];
         $this->sql = "\r\n                        INSERT INTO {$this->tbl_bill_elements}  " . "       (" . "               nr, " . "               date_change, " . "               is_labtest, " . "               is_medicine, " . "               is_radio_test, " . "               is_comment, " . "               is_paid, " . "               amount, " . "               amount_doc, " . "               times_per_day, " . "               days, " . "               price, " . "               description, " . "               item_number, " . "               balanced_insurance, " . "               insurance_id, " . "               prescriptions_nr, " . "               User_Id)" . "\r\n                        VALUES (" . $bill_number . ", '" . time() . "', 0, 0, 1, 0, 1, " . $radio_amount . ", " . $radio_amount . ", 0, 0, " . $price . ",\r\n '" . $row['item_description'] . "', " . $row['item_id'] . ", '" . $insurance . "', '" . $contract['id'] . "', " . $row['batch_nr'] . ",'" . $user_id . "')";
         if ($this->debug) {
             echo $this->sql;
         }
         $db->Execute($this->sql);
         $this->sql = "UPDATE {$this->tbl_rad_requests} SET bill_number=" . $bill_number . ", bill_status='pending'\r\n\t\t\tWHERE batch_nr= " . $row['batch_nr'];
         if ($this->debug) {
             echo $this->sql;
         }
         $db->Execute($this->sql);
     }
     // end while
 }
*
* See the file "copy_notice.txt" for the licence notice
*/
//define('NO_2LEVEL_CHK',1);
$thisfile = basename($_SERVER['PHP_SELF']);
$lang_tables[] = 'billing.php';
$lang_tables[] = 'aufnahme.php';
require_once $root_path . 'include/inc_front_chain_lang.php';
require_once $root_path . 'include/care_api_classes/class_person.php';
$person_obj = new Person();
require_once $root_path . 'include/care_api_classes/class_tz_insurance.php';
$insurance_tz = new Insurance_tz();
//echo "todo is $todo <br>"; //if dodo==finish, let the user go out of that screen!
//echo "mode is set to $mode <br>"; //if mode==update, make the updates to the datasets and let the user see what he has done/changed
if ($mode == 'update') {
    if ($insurance) {
        $insurance_tz->UpdateContractsArray($_POST);
        header("location: insurance_members_tz.php?company_id=" . $insurance);
    }
}
if (is_array($item_no)) {
    $counter = 0;
    while (list($x, $v) = each($item_no)) {
        echo $counter;
        $contract = $insurance_tz->CheckForValidContract($v, 0, $company_id);
        $contract_array[$counter]['PID'] = $v;
        $contract_array[$counter]['Contract'] = $contract;
        $counter++;
    }
}
require "gui/gui_insurance_members_tz_contracts.php";