aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_issue_credit_note
Parameters
Name
Type
Mode
paid_tran_id
integer
IN
ref_vat_id
bigint
IN
user_name
text
IN (DEFAULT NULL)
Definition
declare v_result json; v_invoice json; v_params jsonb; v_vat_info jsonb; v_metadata jsonb; v_ref_vat_id bigint; begin v_ref_vat_id := ref_vat_id; --(select vat_id from transactions t where t.id = paid_tran_id); -- v_result := rpc.salestax_get_issued_tax_invoices(null, jsonb_build_object('docid', v_ref_vat_id)); -- v_invoice := v_result->'result_data'->'items'->0; ---- raise notice 'v_invoice: %', jsonb_pretty(v_invoice::jsonb); -- -- v_vat_info := jsonb_build_object( -- 'header', jsonb_build_object( -- 'invoice_id', v_ref_vat_id, -- 'credit_note_date', fn_system_date(), -- 'credit_note_book_no', fn_intf_param('SALESTAX', 'BOOK_CREDIT_NOTE', '') -- ), -- 'interface', jsonb_build_object( -- 'interface_from', 'F', -- 'machine_no', null, -- 'document_reference', v_invoice->'interface'->>'document_reference', -- 'room_no', v_invoice->'interface'->>'room_no', -- 'guest_ref', v_invoice->'interface'->>'guest_ref', -- 'link_total', (v_invoice->>'invoice_balance')::t_money, -- 'calculate_vat', true -- ), -- 'payment_type', v_invoice->'payment_type' -- ); -- -- v_result := sp_call_accsys_api('/taxcontrol/outputtax_verify_cdn', jsonb_build_object('item', v_vat_info)); v_params := jsonb_build_object('payment_tran_ids', array[paid_tran_id], 'ref_vat_id', v_ref_vat_id); raise notice E'params: %\n', v_params; v_metadata := jsonb_build_object('user_name', coalesce(user_name, fn_current_user())); v_result := rpc.salestax_verify_credit_note(v_metadata, v_params); raise notice E'verify_credit_note: %\n', v_result; if is_result_success(v_result) then v_params := jsonb_build_object( 'issue_type' , 'credit_note', 'payment_tran_ids', array[paid_tran_id], 'invoice_data' , v_result->'result_data' ); raise notice E'Issue params: %\n', v_params; v_result := rpc.salestax_issue_credit_note(v_metadata, v_params); end if; return v_result; -- result_code := v_result->>'result_code'; -- result_msg := v_result->>'result_msg'; -- msg_code := v_result->>'msg_code'; end