aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_get_vat_info_js
Parameters
Name
Type
Mode
payment_tran_ids
int4[]
IN (DEFAULT NULL)
folio_item
integer
IN (DEFAULT NULL)
Definition
DECLARE vat record; addr record; vat_info jsonb; v_book_no text; v_item_desc text = fn_intf_param('SALESTAX', 'ITEM_DESC', 'Accommodation'); v_issue_type text; BEGIN /*{ "TAX": { "VAT_RATE":"7", "ISSUE_TAX":false, "FORCE_ISSUE_TAX":true, "VAT_ISSUE_ON_PAYMENT":true, "VAT_ITEM_DESCRIPTION":"Accomodations" }*/ -- if v_book_no = '' then -- -- auto create book if not exists -- -- end if; if folio_item is not null then select * from sp_get_vat_info(i_folio_item := $2) into vat; else select * from sp_get_vat_info(payment_tran_ids) into vat; end if; select * from sp_get_vat_address(vat.folio_id) into addr; v_book_no := fn_intf_param('SALESTAX', IIF(vat.is_credit_note,'BOOK_CREDIT_NOTE','BOOK_TAX_INVOICE'), ''); v_issue_type := case when coalesce(vat.vatable,0) = 0 then 'no_vat' when vat.is_credit_note then 'credit_note' else 'tax_invoice' end; vat_info := jsonb_build_object( 'issue_type', v_issue_type, 'header', jsonb_build_object( 'id', null, 'invoice_no', null, 'invoice_book_no', v_book_no, 'invoice_date', fn_system_date(), 'invoice_remark', vat.remark, 'money_text_id', 2 ), 'customer', jsonb_build_object( 'cust_name', addr.customer_name, 'cust_address', addr.customer_address, 'cust_tax_id', addr.customer_tax_id, 'cust_branch_type', addr.address_type, 'cust_branch_no', addr.customer_branch, 'country_code', addr.country_code, 'cust_mobile', addr.customer_mobile, 'cust_phone', addr.customer_phone, 'e_mail', addr.customer_email, 'buyer_type', addr.buyer_type ), 'interface', jsonb_build_object( 'interface_from', 'F', 'machine_no', null, 'document_reference', vat.folio_id::text||'/'||vat.folio_seq::text, 'room_no', vat.room_number, 'guest_ref', addr.customer_id, 'link_total', vat.total_amt, 'calculate_vat', true ), 'summary', jsonb_build_object( 'total', vat.total_amt, 'nonvat', vat.non_vat, 'zerovat', 0.00, 'vatable', vat.vatable, 'valueaddtax', vat.vat_amt, 'localvat', 0.00 ), 'payment_type', jsonb_build_object( 'paycash', vat.paycash_amt <> 0.0, 'paycash_amt', vat.paycash_amt, 'paycash_desc', vat.paycard_desc, 'paycard', vat.paycard_amt <> 0.0, 'paycard_amt', vat.paycard_amt, 'paycard_desc', vat.paycard_desc, 'paybank', vat.paybank_amt <> 0.0, 'paybank_amt', vat.paybank_amt, 'paybank_desc', vat.paybank_desc, 'payother', vat.payother_amt <> 0.0, 'payother_amt', vat.payother_amt, 'payother_desc', vat.payother_desc ), 'detail', array[ jsonb_build_object( 'revenue_desc', v_item_desc, 'remark', '', 'qty', 1, 'cost', vat.total_amt, 'amount',vat.total_amt, 'vattype', 'VAT', 'isroom', false ) ] ); RETURN vat_info; END