$_SESSION['DefaultCashPoint'] = $_POST['BankAccount'];
            exit;
        } elseif (isset($_POST['SubmitInsurance'])) {
            prnMsg(_('The transaction has been successfully posted'), 'success');
            echo '<br /><div class="centre"><a href="' . $_SERVER['PHP_SELF'] . '?New=True">' . _('Enter another receipt') . '</a>';
            DB_Txn_Commit($db);
            include 'includes/footer.inc';
            exit;
        }
    }
}
if (!isset($Patient)) {
    ShowCustomerSearchFields($rootpath, $theme, $db);
}
if (isset($_POST['Search']) or isset($_POST['Go1']) or isset($_POST['Go2']) or isset($_POST['Next']) or isset($_POST['Previous'])) {
    $PatientResult = CustomerSearchSQL($db);
    if (DB_num_rows($PatientResult) == 0) {
        prnMsg(_('No patient records contain the selected text') . ' - ' . _('please alter your search criteria and try again'), 'info');
        echo '<br />';
    }
}
//end of if search
if (isset($PatientResult)) {
    ShowReturnedCustomers($PatientResult);
}
if (isset($Patient)) {
    $sql = "SELECT name,\n\t\t\t\tclientsince,\n\t\t\t\tsalestype,\n\t\t\t\tphoneno\n\t\t\t\tFROM debtorsmaster\n\t\t\t\tLEFT JOIN custbranch\n\t\t\t\tON debtorsmaster.debtorno=custbranch.debtorno\n\t\t\t\tWHERE debtorsmaster.debtorno='" . $Patient[0] . "'\n\t\t\t\tAND branchcode='" . $Patient[1] . "'";
    $result = DB_query($sql, $db);
    $mydebtorrow = DB_fetch_array($result);
    if ($_SESSION['Care2xDatabase'] != 'None' and $_SESSION['Items']['Lines'] == 0) {
        $Care2xSQL = "SELECT " . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription.article_item_number,\n\t\t\t\t\t\t\t" . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription.nr,\n\t\t\t\t\t\t\tpartcode,\n\t\t\t\t\t\t\ttotal_dosage,\n\t\t\t\t\t\t\tprescribe_date\n\t\t\t\t\t\tFROM " . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription\n\t\t\t\t\t\tLEFT JOIN " . $_SESSION['Care2xDatabase'] . ".care_tz_drugsandservices\n\t\t\t\t\t\tON " . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription.article_item_number=" . $_SESSION['Care2xDatabase'] . ".care_tz_drugsandservices.item_id\n\t\t\t\t\t\tLEFT JOIN stockmaster\n\t\t\t\t\t\tON " . $_SESSION['Care2xDatabase'] . ".care_tz_drugsandservices.partcode=stockmaster.stockid\n\t\t\t\t\t\tLEFT JOIN stockcategory\n\t\t\t\t\t\tON stockmaster.categoryid=stockcategory.categoryid\n\t\t\t\t\t\tLEFT JOIN " . $_SESSION['Care2xDatabase'] . ".care_encounter\n\t\t\t\t\t\tON " . $_SESSION['Care2xDatabase'] . ".care_encounter.encounter_nr=" . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription.encounter_nr\n\t\t\t\t\t\tAND stockcategory.stocktype='X'\n\t\t\t\t\t\tWHERE " . $_SESSION['Care2xDatabase'] . ".care_encounter.pid='" . $Patient[0] . "'\n\t\t\t\t\t\tAND " . $_SESSION['Care2xDatabase'] . ".care_encounter_prescription.bill_number=''";
        	 has been selected for the order or not the session variable CustomerID holds the customer code
        	 already as determined from user id /password entry  */
        $_SESSION['RequireCustomerSelection'] = 1;
    } else {
        $_SESSION['RequireCustomerSelection'] = 0;
    }
}
if (isset($_POST['ChangeCustomer']) and $_POST['ChangeCustomer'] != '') {
    if ($_SESSION['Items' . $identifier]->Any_Already_Delivered() == 0) {
        $_SESSION['RequireCustomerSelection'] = 1;
    } else {
        prnMsg(_('The customer the order is for cannot be modified once some of the order has been invoiced'), 'warn');
    }
}
if (isset($_POST['Search']) and $_SESSION['RequireCustomerSelection'] == 1 and in_array(2, $_SESSION['AllowedPageSecurityTokens'])) {
    $result_CustSelect = CustomerSearchSQL($db);
}
/*end of if search for customer codes/names */
/*Need to figure out the number of the form variable that the user clicked on */
if (!isset($_POST['Select'])) {
    for ($i = 0; $i < count($_POST); $i++) {
        //loop through the returned customers
        if (isset($_POST['SubmitCustomerSelection' . $i])) {
            break;
        }
    }
    if ($i != count($_POST)) {
        $_POST['Select'] = $_POST['SelectedCustomer' . $i];
        $_SESSION['Items' . $identifier]->Branch = $_POST['SelectedBranch' . $i];
        unset($_POST['Search']);
    }
    $_SESSION['RequireCustomerSelection'] = 1;
}
if (isset($_POST['Quick'])) {
    unset($_POST['PartSearch']);
}
if (isset($_POST['CancelCredit'])) {
    unset($_SESSION['CreditItems' . $identifier]->LineItems);
    unset($_SESSION['CreditItems' . $identifier]);
    $_SESSION['CreditItems' . $identifier] = new cart();
    $_SESSION['RequireCustomerSelection'] = 1;
}
if (isset($_POST['Customer'])) {
    $_SESSION['RequireCustomerSelection'] = 0;
}
/* if the change customer button hit or the customer has not already been selected */
$result = CustomerSearchSQL($db);
if (!isset($_POST['Search']) and !isset($_POST['Next']) and !isset($_POST['Previous']) and !isset($_POST['Go1']) and !isset($_POST['Go2']) and isset($_POST['JustSelectedACustomer']) and empty($_SESSION['CustomerID'])) {
    /*Need to figure out the number of the form variable that the user clicked on */
    for ($i = 0; $i < count($_POST); $i++) {
        //loop through the returned customers
        if (isset($_POST['SubmitCustomerSelection' . $i])) {
            break;
        }
    }
    if ($i == count($_POST)) {
        prnMsg(_('Unable to identify the selected customer'), 'error');
    } else {
        $_POST['Customer'] = $_POST['SelectedCustomer' . $i];
        $_POST['Branch'] = $_POST['SelectedBranch' . $i];
        unset($_POST['Search']);
    }