CreditsAndRefunds Class
This global class allows callers perform the following actions:
- create a Credit Memo from a Billing
- create a Funding Credit Memo (negative Billing) from a Cash Receipt receipt and apply it to the Cash Receipt
- create a Refund Cash Receipt (negative Cash Receipt) from a Credit Memo (negative Billing) and apply it to the Credit Memo
- create a Refund for a Cash Receipt. Performs both steps 2 and 3 above
CreditsAndRefunds Methods
Global methods for the CreditsAndRefunds class.
getCreditMemoFromBilling(Id)
This method clones the passed in Billing and all associated Billing Lines into a new Billing which is returned but not committed to the database. The rate on the lines is multiplied by -1 to make the new Billing a Credit Memo.
Signature
global static BillingModel getCreditMemoFromBilling(Id BillingId)
Parameters
Type: [Id
]
Return Value
Type: [billingModel
]
Usage
BillingModel bm = CreditsAndRefunds.getCreditMemoFromBilling(billingId);
createAndApplyFundingCreditMemo(CreditsAndRefundsOptions)
This method is designed to work with a Cash Receipt defined in the options sourceRecordId parameter. It creates a funding Credit Memo with a single line equal to the the options.refundAmount * -1 to create a Credit Memo and creates a BillingCashReceipt record to apply the new funding Credit Memo to the Cash Receipt
Signature
global static ServiceResult createAndApplyFundingCreditMemo(CreditsAndRefundsOptions options)
Parameters
Type: CreditsAndRefundsOptions
** The following CreditsAndRefundsOptions are validated prior to processing:
- CreditsAndRefundsOptions.sourceRecordId must be a Cash Receipt record Id
- Cash Receipt balance must be greater than zero
- CreditsAndRefundsOptions.refundAmount must be greater than zero
- CreditsAndRefundsOptions.refundAmount must be less than the Cash Receipt balance
- The CreditsAndRefundsOptions.refundDate must be greater than the Cash Receipt Date
Return Value
Type: ServiceResult
** ServiceResult.data will contain the record Id of the newly created funding Credit Memo
Usage
Id cashReceiptId;
CreditsAndRefundsOptions options = new CreditsAndRefundsOptions(cashReceiptId);
options.memo = 'optional memo';
ServiceResult sr = new ServiceResult();
sr = CreditsAndRefunds.createAndApplyFundingCreditMemo(options);
createAndApplyRefundCashReceipt(CreditsAndRefundsOptions)
This method is designed to with a Credit Memo defined in the options sourceRecordId parameter. It creates a negative Cash Receipt equal to the options.refundAmount and creates a BillingCashReceipt record to apply the funding Credit Memo to the new negative Cash Receipt
Signature
global static ServiceResult createAndApplyRefundCashReceipt(CreditsAndRefundsOptions options)
Parameters
Type: CreditsAndRefundsOptions
** The following CreditsAndRefundsOptions are validated prior to processing:
- CreditsAndRefundsOptions.sourceRecordId must be a Billing (Credit Memo) record Id
- CreditsAndRefundsOptions.refundAmount must be less than the Credit Memo balance
- The CreditsAndRefundsOptions.bankAccount must be the id to a bank type GL Account record
Return Value
Type: ServiceResult
** ServiceResult.data will contain the record Id of the newly created Refund Cash Receipt
Usage
Id bankGLAccountId;
Id creditMemoId;
CreditsAndRefundsOptions options = new CreditsAndRefundsOptions(creditMemoId);
options.bankAccount = bankGLAccountId;
options.memo = 'optional memo';
ServiceResult sr = new ServiceResult();
sr = CreditsAndRefunds.createAndApplyRefundCashReceipt(options);
createRefundForCashReceipt(CreditsAndRefundsOptions)
This method is designed to work with Cash Receipt defined in the options sourceRecordId parameter. It creates a funding Credit Memo with a single line equal to the the options.refundAmount * -1 to create a Credit Memo and creates a BillingCashReceipt record to apply the new funding Credit Memo to the Cash Receipt.
It also creates a neagtive Cash Receipt equal to the options.refundAmount and creates
a BillingCashReceipt record to apply the new funding Credit Memo to the new negative Cash Receipt
Signature
global static ServiceResult createRefundForCashReceipt(CreditsAndRefundsOptions options)
Parameters
Type: CreditsAndRefundsOptions
** The following CreditsAndRefundsOptions are validated prior to processing:
- CreditsAndRefundsOptions.sourceRecordId must be a Cash Receipt record Id
- Cash Receipt balance must be greater than zero
- CreditsAndRefundsOptions.refundAmount must be greater than zero
- CreditsAndRefundsOptions.refundAmount must be less than the Cash Receipt balance
- The CreditsAndRefundsOptions.refundDate must be greater than the Cash Receipt Date
Return Value
Type: ServiceResult
** ServiceResult.data will contain the record Id of the newly created Refund Cash Receipt
Usage
Id cashReceiptId;
CreditsAndRefundsOptions options = new CreditsAndRefundsOptions(cashReceiptId);
options.memo = 'optional memo';
ServiceResult sr = new ServiceResult();
sr = CreditsAndRefunds.createRefundForCashReceipt(options);