Proc Subway CashReceiptBatchPosting Batch

Purpose
The purpose of this stored procedure is to post the cash receipt batches that are currently in the unposted tables, update the account balances, and create a matching record in the WeeklySummary table. This procedure also updates the collected amount field in the Invoice Posted table.

Method Signature
[dbo].[proc_Subway_CashReceiptBatchPosting_Batch] ( @CashReciptBatchNumbersXML               XML,  @UserStamp                               VARCHAR(50), )

Procedure Flow

 * 1) Create a temp table with all the CashReceiptBatchIds to process from the XML passed in, these are the selected cash receipt batches
 * 2) Lock the process by setting the Object Availability Indicator to false (0)
 * 3) Insert all the selected cash receipt batches from the CashReceiptBatchUnPosted to the CashReceiptBatchPosted table
 * 4) Insert all the selected cash receipt batches from the CashReceiptUnPosted to the CashReceiptPosted table
 * 5) Insert all the selected cash receipt batches from the CashReceiptItemUnPosted to the CashReceiptItemPosted table
 * 6) Determine if any of the cash receipts items have the balance type of Equipment Leasing, if so run the stored procedure ^^proc_Subway_CashReceiptBatchPosting_EquipmentLease_Batch^^ passing in only those cash receipt batches that have the balance type of Equipment Leasing
 * 7) All cash receipt items are saved to the WeeklySummary table using the stored procedure ^^proc_Subway_WeeklySummary_Save_Batch^^
 * 8) Only the cash receipts that have a Item Type with the flag Receivable set will be added to the Account Balance table. This update is done through the stored procedure ^^proc_Subway_AccountBalance_Save_Batch^^
 * 9) All the cash receipt items are group by EntityType, EntityId, and BalanceId and inserted into the ARSubLedger table.
 * 10) Determine if any of the cash receipts items have the balance type of Notes Receivable, if so run the stored procedure ^^proc_Subway_CashReceiptBatchPosting_DAAdjustment_Batch^^ passing in only those cash receipt batches that have the balance type of Notes Receivable
 * 11) Determine if any of the cash receipts items have the balance type of Royalty, Advertising, Notes Receivable, Shipping Center or Realty, if so run the stored procedure ^^proc_Subway_CashReceiptBatchPosting_NoteReceivable_Batch^^ passing in only those cash receipt batches.
 * 12) Group all the cash receipt items by EntityType, EntityId, BalanceId and AssociatedBalanceId summing up the cash receipt item amount. Then for all records call the stored procedure ^^proc_Subway_Invoice_UpdateCollectedAmount^^ which will update the collected amount in the Invoice Item Posted table.
 * 13) Delete all the selected cash receipt batches from the CashReceiptItemUnPosted table
 * 14) Delete all the selected cash receipt batches from the CashReceiptUnPosted table
 * 15) Delete all the selected cash receipt batches from the CashReceiptBatchUnPosted table
 * 16) Release the process by setting the Object Availability Indicator to true (1)