<?php
function validateTransactionTypeRecords($transaction_type, $balancetype, $ledgerhead)
{
    // this returns false if error encountered or true if no error
    if ($transaction_type == "receipt") {
        $allowed_ledgerhead = ['Cash-in-Hand', 'Bank Account', 'Bank OD A/C'];
        if ($balancetype === "dr") {
            if (!in_array($ledgerhead, $allowed_ledgerhead)) {
                errorreturn('Cash and Bank Accounts can only be debited in a receipt transaction.');
            } else {
                return true;
            }
        }
        if ($balancetype === 'cr') {
            if (in_array($ledgerhead, $allowed_ledgerhead)) {
                //errorreturn($ledgerhead);
                errorreturn('Cash and Bank Accounts cannot be credited in a receipt transaction.');
            } else {

                return true;
            }
        }
    } else if ($transaction_type == "contra") {
        $allowed_ledgerhead = ['Cash-in-Hand', 'Bank OD A/C', 'Bank Account'];
        if (!in_array($ledgerhead, $allowed_ledgerhead)) {
            errorreturn('You cannot use any other ledger than Cash or Bank Account in Contra transaction.');
        } else {
            return true;
        }
    } else if ($transaction_type == "payment") {
        if ($balancetype === "dr") {
            $allowed_ledgerhead = ['Cash-in-Hand', 'Bank OD A/C', 'Bank Account'];
            if (in_array($ledgerhead, $allowed_ledgerhead)) {
                errorreturn('Cash or Bank Accounts cannot be debited in a payment transaction.');
            } else {
                return true;
            }
        }
    }
}
