Issue #23459 Use new ccpay_card_type column.
authorBen Thompson <ben@xtuple.com>
Thu, 19 Jun 2014 02:09:52 +0000 (22:09 -0400)
committerBen Thompson <ben@xtuple.com>
Thu, 19 Jun 2014 02:09:52 +0000 (22:09 -0400)
foundation-database/public/functions/postcccashreceipt.sql
foundation-database/public/functions/postcccredit.sql

index 5569839..e981a58 100644 (file)
@@ -9,7 +9,6 @@ DECLARE
   _aropenid     INTEGER;
   _bankaccnt_id INTEGER;
   _c            RECORD;
-  _cardType     TEXT;
   _ccOrderDesc  TEXT;
   _journal      INTEGER;
   _realaccnt    INTEGER;
@@ -19,7 +18,6 @@ BEGIN
   SELECT * INTO _c
      FROM ccpay
      JOIN custinfo ON ccpay_cust_id = cust_id
-     LEFT OUTER JOIN ccard ON ccpay_ccard_id = ccard_id
      WHERE (ccpay_id = pCCpay);
 
   IF (NOT FOUND) THEN
@@ -31,29 +29,17 @@ BEGIN
     _c.ccpay_amount = pamount;
   END IF;
 
-  IF (_c.ccard_type IS NOT NULL) THEN
-    _cardType = _c.ccard_type;
-  ELSIF (_c.ccpay_card_type IS NOT NULL) THEN
-    -- Support External Pre-Auths where the Card Type is pushed into ccpay.
-    -- There is no ccpay_ccard_id to join ccard on and get ccard_type.
-    _cardType = _c.ccpay_card_type;
-  ELSE
-    -- TODO: Where is the other half of these -n error codes???
-    RAISE EXCEPTION 'Cannot find the Credit Card type [xtuple: postCCcashReceipt, -2, %, %, %]',
-                    pCCpay, pdocid, pdoctype;
-  END IF;
-
   SELECT bankaccnt_id, bankaccnt_accnt_id INTO _bankaccnt_id, _realaccnt
   FROM ccbank
   JOIN bankaccnt ON (ccbank_bankaccnt_id=bankaccnt_id)
-  WHERE (ccbank_ccard_type=_cardType);
+  WHERE (ccbank_ccard_type=_c.ccpay_card_type);
 
   IF (_bankaccnt_id IS NULL) THEN
     RAISE EXCEPTION 'Cannot find the default Bank Account for this Credit Card [xtuple: postCCcredit, -1, %]',
-                    _cardType;
+                    _c.ccpay_card_type;
   END IF;
 
-  _ccOrderDesc := (_cardType || '-' || _c.ccpay_order_number::TEXT ||
+  _ccOrderDesc := (_c.ccpay_card_type || '-' || _c.ccpay_order_number::TEXT ||
                   '-' || _c.ccpay_order_number_seq::TEXT);
 
   _journal := fetchJournalNumber('C/R');
@@ -67,7 +53,7 @@ BEGIN
         cashrcpt_usecustdeposit
       ) VALUES (
         _c.ccpay_cust_id,   _c.ccpay_amount,     _c.ccpay_curr_id,
-        _cardType,      _c.ccpay_r_ordernum, _ccOrderDesc,
+        _c.ccpay_card_type,      _c.ccpay_r_ordernum, _ccOrderDesc,
         CURRENT_DATE,       _bankaccnt_id,
         fetchMetricBool('EnableCustomerDeposits'))
       RETURNING cashrcpt_id INTO _return;
@@ -76,7 +62,7 @@ BEGIN
       SET cashrcpt_cust_id=_c.ccpay_cust_id,
           cashrcpt_amount=_c.ccpay_amount,
           cashrcpt_curr_id=_c.ccpay_curr_id,
-          cashrcpt_fundstype=_cardType,
+          cashrcpt_fundstype=_c.ccpay_card_type,
           cashrcpt_docnumber=_c.ccpay_r_ordernum,
           cashrcpt_notes=_ccOrderDesc,
           cashrcpt_distdate=CURRENT_DATE,
index 2e48211..48a7697 100644 (file)
@@ -6,7 +6,6 @@ DECLARE
   preftype      ALIAS FOR $2;
   prefid        ALIAS FOR $3;
   _c                   RECORD;
-  _cardType     TEXT;
   _ccOrderDesc TEXT;
   _cglaccnt     INTEGER;
   _dglaccnt        INTEGER;
@@ -36,7 +35,6 @@ BEGIN
 
   SELECT * INTO _c
      FROM ccpay
-     LEFT OUTER JOIN ccard ON ccpay_ccard_id = ccard_id
      WHERE (ccpay_id = pCCpay);
 
   IF (NOT FOUND) THEN
@@ -50,22 +48,10 @@ BEGIN
     _dglaccnt := findARAccount(_c.ccpay_cust_id);
   END IF;
 
-  IF (_c.ccard_type IS NOT NULL) THEN
-    _cardType = _c.ccard_type;
-  ELSIF (_c.ccpay_card_type IS NOT NULL) THEN
-    -- Support External Pre-Auths where the Card Type is pushed into ccpay.
-    -- There is no ccpay_ccard_id to join ccard on and get ccard_type.
-    _cardType = _c.ccpay_card_type;
-  ELSE
-    -- TODO: Where is the other half of these -n error codes???
-    RAISE EXCEPTION 'Cannot find the Credit Card type [xtuple: postCCcredit, -5, %, %, %]',
-                    pCCpay, preftype, prefid;
-  END IF;
-
   SELECT bankaccnt_accnt_id INTO _cglaccnt
   FROM ccbank
   JOIN bankaccnt ON (ccbank_bankaccnt_id=bankaccnt_id)
-  WHERE (ccbank_ccard_type=_cardType);
+  WHERE (ccbank_ccard_type=_c.ccpay_card_type);
 
   IF (NOT FOUND) THEN
     RAISE EXCEPTION 'Cannot find the default Bank Account for this Credit Card [xtuple: postCCcredit, -1, %]',
@@ -80,9 +66,9 @@ BEGIN
   _sequence := fetchGLSequence();
 
   IF (_c.ccpay_r_ref IS NOT NULL) THEN
-    _ccOrderDesc := (_cardType || '-' || _c.ccpay_r_ref);
+    _ccOrderDesc := (_c.ccpay_card_type || '-' || _c.ccpay_r_ref);
   ELSE
-    _ccOrderDesc := (_cardType || '-' || _c.ccpay_order_number::TEXT ||
+    _ccOrderDesc := (_c.ccpay_card_type || '-' || _c.ccpay_order_number::TEXT ||
                     '-' || COALESCE(_c.ccpay_order_number_seq::TEXT, ''));
   END IF;