1 CREATE OR REPLACE FUNCTION assessFinanceCharge(pAropenid INTEGER,
3 pAssessAmount NUMERIC) RETURNS INTEGER AS $$
4 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
5 -- See www.xtuple.com/CPAL for the full text of the software license.
13 -- cache some information
14 SELECT * INTO _fc FROM fincharg;
16 RAISE EXCEPTION 'assessFinanceCharge, configuration not set.';
19 SELECT * INTO _ar FROM aropen WHERE (aropen_id=pAropenid);
21 RAISE EXCEPTION 'assessFinanceCharge, aropen not found.';
24 -- create invoice head
39 invchead_billto_address1,
40 invchead_billto_address2,
41 invchead_billto_address3,
43 invchead_billto_state,
44 invchead_billto_zipcode,
45 invchead_billto_phone,
47 invchead_shipto_address1,
48 invchead_shipto_address2,
49 invchead_shipto_address3,
51 invchead_shipto_state,
52 invchead_shipto_zipcode,
53 invchead_shipto_phone,
59 invchead_misc_descrip,
60 invchead_misc_accnt_id,
64 invchead_billto_country,
65 invchead_shipto_country,
70 invchead_recurring_interval,
71 invchead_recurring_type,
72 invchead_recurring_until,
73 invchead_recurring_invchead_id,
78 invchead_shipzone_id )
93 invchead_billto_address1,
94 invchead_billto_address2,
95 invchead_billto_address3,
97 invchead_billto_state,
98 invchead_billto_zipcode,
99 invchead_billto_phone,
100 invchead_shipto_name,
101 invchead_shipto_address1,
102 invchead_shipto_address2,
103 invchead_shipto_address3,
104 invchead_shipto_city,
105 invchead_shipto_state,
106 invchead_shipto_zipcode,
107 invchead_shipto_phone,
108 invchead_salesrep_id,
118 invchead_billto_country,
119 invchead_shipto_country,
128 invchead_shipchrg_id,
131 invchead_saletype_id,
134 WHERE (invchead_invcnumber=_ar.aropen_docnumber)
135 RETURNING invchead_id INTO _invcheadid;
137 -- create invoice item
139 ( invcitem_invchead_id,
142 invcitem_warehous_id,
151 invcitem_salescat_id,
154 invcitem_qty_invuomratio,
155 invcitem_price_uom_id,
156 invcitem_price_invuomratio,
159 invcitem_rev_accnt_id )
166 _fc.fincharg_markoninvoice,
167 'Finance Charge Assessment',
173 _fc.fincharg_salescat_id,
181 _fc.fincharg_accnt_id );
184 UPDATE aropen SET aropen_fincharg_date = pAssessDate,
185 aropen_fincharg_amount = COALESCE(aropen_fincharg_amount, 0.0) + pAssessAmount
186 WHERE (aropen_id=pAropenid);
192 $$ LANGUAGE 'plpgsql';