<?php

function extractFirstWords($transactiontype)
{

    switch ($transactiontype) {
        case 'sales':
            $result = 'SL';
            break;
        case 'purchase':
            $result = 'PR';
            break;
        case 'journal':
            $result = 'J';
            break;
        case 'contra':
            $result = 'C';
            break;
        case 'payment':
            $result = 'P';
            break;
        case 'receipt':
            $result = 'R';
            break;

        default:
            $result = -1;
            break;
    }

    if ($result == -1) {
        return false;
    }
    return $result;
}

function getTransactionUniqueId($additional_transaction_prefix, $transaction_numbering_system, $unique_id, $transaction_type = null, $prefix_financial_year_bool = null, $transaction_date = null, $financial_year_startdate = null)
{
    if (in_array($transaction_type, $transaction_numbering_system['manual'])) {
        return $unique_id;
    } else {
        // automatic
        $final_uniqueid = '';
        if (!empty($additional_transaction_prefix) or $prefix_financial_year_bool == 1) {
            $final_uniqueid .= $additional_transaction_prefix;
            if ($prefix_financial_year_bool == 1) {
                $final_uniqueid .= getFinancialYear($transaction_date, $financial_year_startdate);
            }
            $final_uniqueid .= '/';
        }

        $final_uniqueid .= $unique_id . '' . extractFirstWords($transaction_type);
        return $final_uniqueid;
    }
}
