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 -- - enhance data shown in the item description for the invoice line to indicate which invoice is affected
168 -- - Feature Request 23344
169 -- 'Finance Charge Assessment',
170 'Finance Charge Assessment - Invoice Number ' || _ar.aropen_docnumber || ' - Past Due Balance ' || (_ar.aropen_amount - _ar.aropen_paid) || ' Due Date - ' || _ar.aropen_duedate,
176 _fc.fincharg_salescat_id,
184 _fc.fincharg_accnt_id );
187 UPDATE aropen SET aropen_fincharg_date = pAssessDate,
188 aropen_fincharg_amount = COALESCE(aropen_fincharg_amount, 0.0) + pAssessAmount
189 WHERE (aropen_id=pAropenid);
195 $$ LANGUAGE 'plpgsql';