Пример #1
0
        private void HandlePrepaidWaterPackages(Invoice newInvoice, InvoiceLineItem lineItem)
        {
            if ((lineItem.ProductCode).Contains("WAT PKG"))
            {
                if (newInvoice.AccountID != null)
                {
                    // check if the account has an existing prepaid bottle account
                    // if not, create a new one
                    int           bottleTypeID = ExtractBottleTypeID(lineItem.ProductCode);
                    PrepaidBottle p            = PrepaidBottleManager.GetPrepaidBottle(_accountID, bottleTypeID);

                    if (p == null) //create a new one
                    {
                        p                   = new PrepaidBottle();
                        p.AccountID         = _accountID;
                        p.PrepaidBottleType = bottleTypeID;
                        p.CreatedBy         = User.Identity.Name.ToString();
                        p.TopUpBalance(ProductManager.GetTopUpQty(lineItem.ProductCode) * lineItem.Quantity);
                        p.PrepaidBottleID = PrepaidBottleManager.Save(p);
                    }
                    else
                    {
                        p.TopUpBalance(ProductManager.GetTopUpQty(lineItem.ProductCode));
                        p.ModifiedBy = User.Identity.Name.ToString();
                        PrepaidBottleManager.Save(p);
                    }

                    // save the prepaid bottle transaction
                    PrepaidBottleTransaction pBTransaction = new PrepaidBottleTransaction();
                    pBTransaction.PrepaidBottleID    = p.PrepaidBottleID;
                    pBTransaction.TransactionType    = "topUp";
                    pBTransaction.TopUpQty           = ProductManager.GetTopUpQty(lineItem.ProductCode) * lineItem.Quantity;
                    pBTransaction.LastUpdatedBalance = p.Balance;
                    pBTransaction.CreatedBy          = User.Identity.Name.ToString();
                    pBTransaction.TransactionID      = PrepaidBottleTransactionManager.Save(pBTransaction);
                }
            }
        }