merge GARY_XTUPLE/23254 into my issue23878
authorGil Moskowitz <gmoskowitz@xtuple.com>
Fri, 11 Jul 2014 18:29:32 +0000 (14:29 -0400)
committerGil Moskowitz <gmoskowitz@xtuple.com>
Fri, 11 Jul 2014 18:29:32 +0000 (14:29 -0400)
foundation-database/manifest.js
foundation-database/public/functions/postcashreceipt.sql
foundation-database/public/functions/postcheck.sql
foundation-database/public/tables/checkhead.sql [new file with mode: 0644]

index e1f8d8f..738dddb 100644 (file)
     "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",
index 5fe1b70..b6f20b2 100644 (file)
@@ -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
index 9a077d1..7765875 100644 (file)
@@ -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 (file)
index 0000000..20793d4
--- /dev/null
@@ -0,0 +1 @@
+select xt.add_column('checkhead','checkhead_alt_curr_rate', 'NUMERIC', NULL, 'public');
\ No newline at end of file