From: Gil Moskowitz Date: Fri, 11 Jul 2014 18:29:32 +0000 (-0400) Subject: merge GARY_XTUPLE/23254 into my issue23878 X-Git-Tag: v4.6.0-beta~13^2~5 X-Git-Url: http://git.roojs.org/?a=commitdiff_plain;h=8b26eab45b7bd6b176666f3643c4fe99ea9e528b;p=xtuple merge GARY_XTUPLE/23254 into my issue23878 --- diff --git a/foundation-database/manifest.js b/foundation-database/manifest.js index e1f8d8f67..738dddbc0 100644 --- a/foundation-database/manifest.js +++ b/foundation-database/manifest.js @@ -1015,6 +1015,7 @@ "public/tables/bankrecitem.sql", "public/tables/cashrcpt.sql", "public/tables/ccpay.sql", + "public/tables/checkhead.sql", "public/tables/metric.sql", "public/tables/payco.sql", "public/tables/priv.sql", diff --git a/foundation-database/public/functions/postcashreceipt.sql b/foundation-database/public/functions/postcashreceipt.sql index 5fe1b70bf..b6f20b2ae 100644 --- a/foundation-database/public/functions/postcashreceipt.sql +++ b/foundation-database/public/functions/postcashreceipt.sql @@ -46,17 +46,14 @@ BEGIN END IF; END IF; - SELECT cashrcpt_cust_id, (cust_number||'-'||cust_name) AS custnote, - cashrcpt_fundstype, cashrcpt_number, cashrcpt_docnumber, - cashrcpt_distdate, cashrcpt_amount, cashrcpt_discount, + SELECT cashrcpt.*, + (cust_number||'-'||cust_name) AS custnote, (cashrcpt_amount / cashrcpt_curr_rate) AS cashrcpt_amount_base, - (cashrcpt_discount / cashrcpt_curr_rate) AS cashrcpt_discount_base, - cashrcpt_notes, + (cashrcpt_discount / cashrcpt_curr_rate) AS cashrcpt_discount_base, cashrcpt_bankaccnt_id AS bankaccnt_id, accnt_id AS prepaid_accnt_id, - cashrcpt_usecustdeposit, - COALESCE(cashrcpt_applydate, cashrcpt_distdate) AS applydate, - cashrcpt_curr_id, cashrcpt_curr_rate, cashrcpt_posted, cashrcpt_void INTO _p + COALESCE(cashrcpt_applydate, cashrcpt_distdate) AS applydate + INTO _p FROM cashrcpt LEFT OUTER JOIN custinfo ON (cashrcpt_cust_id=cust_id) LEFT OUTER JOIN accnt ON (accnt_id=findPrepaidAccount(cashrcpt_cust_id)) WHERE ( (findPrepaidAccount(cashrcpt_cust_id)=0 OR accnt_id > 0) -- G/L interface might be disabled @@ -337,6 +334,23 @@ BEGIN _p.cashrcpt_distdate, _p.custnote, pCashrcptid ); + -- Post any gain/loss from the alternate currency exchange rate + IF (COALESCE(_p.cashrcpt_alt_curr_rate, 0.0) <> 0.0) THEN + _exchGain := ROUND((_p.cashrcpt_curr_rate - _p.cashrcpt_alt_curr_rate) * _p.cashrcpt_amount_base, 2); + + IF (_exchGain <> 0) THEN + PERFORM insertIntoGLSeries( _sequence, 'A/R', 'CR', + (_p.cashrcpt_fundstype || '-' || _p.cashrcpt_docnumber), + _debitAccntid, (_exchGain * -1.0), + _p.cashrcpt_distdate, _p.custnote, pCashrcptid ); + + PERFORM insertIntoGLSeries( _sequence, 'A/R', 'CR', + (_p.cashrcpt_fundstype || '-' || _p.cashrcpt_docnumber), + getGainLossAccntId(_debitAccntid), _exchGain, + _p.cashrcpt_distdate, _p.custnote, pCashrcptid ); + END IF; + END IF; + PERFORM postGLSeries(_sequence, pJournalNumber); -- convert the cashrcptitem records to applications against the cm/cd if we are _predist diff --git a/foundation-database/public/functions/postcheck.sql b/foundation-database/public/functions/postcheck.sql index 9a077d1da..77658758f 100644 --- a/foundation-database/public/functions/postcheck.sql +++ b/foundation-database/public/functions/postcheck.sql @@ -270,6 +270,23 @@ BEGIN round(_p.checkhead_amount_base, 2), _p.checkhead_checkdate, _gltransNote, pcheckid ); + -- Post any gain/loss from the alternate currency exchange rate + IF (COALESCE(_p.checkhead_alt_curr_rate, 0.0) <> 0.0) THEN + _exchGain := ROUND((_p.checkhead_curr_rate - _p.checkhead_alt_curr_rate) * _p.checkhead_amount_base, 2); + + IF (_exchGain <> 0) THEN + PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source, 'CK', + CAST(_p.checkhead_number AS TEXT), + _p.bankaccntid, (_exchGain * -1.0), + _p.checkhead_checkdate, _gltransNote, pcheckid ); + + PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source, 'CK', + CAST(_p.checkhead_number AS TEXT), + getGainLossAccntId(_p.bankaccntid), _exchGain, + _p.checkhead_checkdate, _gltransNote, pcheckid ); + END IF; + END IF; + PERFORM postGLSeries(_sequence, _journalNumber); UPDATE checkhead diff --git a/foundation-database/public/tables/checkhead.sql b/foundation-database/public/tables/checkhead.sql new file mode 100644 index 000000000..20793d4e5 --- /dev/null +++ b/foundation-database/public/tables/checkhead.sql @@ -0,0 +1 @@ +select xt.add_column('checkhead','checkhead_alt_curr_rate', 'NUMERIC', NULL, 'public'); \ No newline at end of file