3 -- void all the exist variance and add one for whole order-----------------
5 CREATE OR REPLACE FUNCTION x_fix_pohead_add_variance_all(i_pohead_number text)
11 v_purchprice_accnt_id INTEGER;
12 v_lb_accnt_id INTEGER;
17 v_gltrans_amount NUMERIC;
23 IF (NOT fetchMetricBool('RecordPPVonReceipt')) THEN -- If the 'Purchase Price Variance on Receipt' option is true
24 RAISE EXCEPTION 'Purchase Price Variance on Receipt option is FALSE';
28 costcat_purchprice_accnt_id,
29 costcat_liability_accnt_id
31 v_purchprice_accnt_id,
37 -- what's the poitem total value.
38 -- this should be at the recevicved date really..
45 -- date is when it was recived...
47 (SELECT max(recv_gldistdate) FROM
52 recvgrp_id = recv_recvgrp_id
54 recv_orderitem_id = poitem_id
60 ) * (poitem_qty_received - poitem_qty_returned))
68 pohead_id = poitem_pohead_id
70 WHERE pohead_number = i_pohead_number;
72 -- what's the posted value?
88 invhist_ordnumber LIKE i_pohead_number || '-%'
90 invhist_ordnumber = i_pohead_number
95 gltrans_accnt_id = v_lb_accnt_id;
106 pohead_number = i_pohead_number;
118 recvgrp_id = recv_recvgrp_id
120 (recvgrp_void = 0 OR recvgrp_void IS NULL)
122 recvgrp_pohead_id = _p.pohead_id;
125 -- void any existing purchase price variences..
127 PERFORM deleteGlSeries( gltrans_sequence, 'Fix Purchase Price Variance on ' || to_char(NOW(), 'Day Mon DD YYY') )
132 gltrans_accnt_id = v_purchprice_accnt_id
134 gltrans_doctype = 'PO'
136 gltrans_notes LIKE 'Purchase price variance adjusted for P/O ' || _p.pohead_number || '%'
138 gltrans_notes LIKE 'Void Purchase price variance adjusted for P/O ' || _p.pohead_number || '%'
143 v_value = v_base - v_diff;
146 IF (ABS(v_value) <> 0) THEN
147 SELECT insertGLTransaction( fetchJournalNumber('GL-MISC'),
148 'S/R', 'PO', _p.pohead_number,
149 'Purchase price variance adjusted for P/O ' || _p.pohead_number || ' on ' || v_date,
151 v_purchprice_accnt_id, -1,
153 v_date::DATE, true ) INTO v_result;
161 LANGUAGE plpgsql VOLATILE
164 ALTER FUNCTION x_fix_pohead_add_variance_all(text)