public QuoteInvoiceCollection GetQuoteByCustomerId(String username_ad, String password_ad, int id) { Authentication_class var_auth = new Authentication_class(); AuthenticationHeader ah = var_auth.getAuthHeader(username_ad, password_ad); AsmRepository.SetServiceLocationUrl(var_auth.var_service_location_url); var billingService = AsmRepository.GetServiceProxyCachedOrDefault <IBillingEngineService>(ah); var financeService = AsmRepository.GetServiceProxyCachedOrDefault <IFinanceService>(ah); var agreementManagementService = AsmRepository.GetServiceProxyCachedOrDefault <IAgreementManagementService>(ah); #region Step 1 //First, get Pending quotes to check their QuoteDates. //Instantiate a class for the request. BaseQueryRequest req = new BaseQueryRequest(); req.FilterCriteria = new CriteriaCollection(); //Define the selection criteria. //Replace 73948 with the CustomerId of the customer you want. req.FilterCriteria.Add("CustomerId", id); //Get the customer's QuoteInvoices. QuoteInvoiceCollection qts = billingService.FindQuoteInvoices(req); if (qts != null && qts.Items.Count > 0) { return(qts); //foreach (var q in qts) //{ // Console.WriteLine("Customer ID {0}: QuoteDate = {1} QuoteInvoice ID = {2}", // q.CustomerId, q.QuoteDate, q.Id); // Console.WriteLine("Quote amount = {0} Quote type = {1}", // q.TotalAmount, q.QuoteType); // //If the QuoteDate < Today, then regenerate the quote. // if (q.QuoteDate < System.DateTime.Today) // { // QuoteInvoiceRequest request = new QuoteInvoiceRequest(); // request.QuoteId = q.Id; // //If Save = True, ICC saves the QuoteInvoice. // //To get the quote info but not commit it to the database, // //set the flag to False. This is useful when // //you only want to know what the customer would pay next // //period, but you don't want to create the quote. // request.Save = true; // //Regenerate the quote to save Today's quote info. // QuoteInvoiceResponse response = billingService.RegenerateQuoteInvoice(request); // Console.WriteLine("New quote generated. ID = {0}; Amount = {1}", // response.NewQuoteInvoice.Id, response.NewQuoteInvoice.TotalAmount); // } // else // { // Console.WriteLine("Customer's quotes are up-to-date."); // } //} } else { return(null); } #endregion step 1 }
public List <QuoteInvoiceCollection> GetPendingQuote(String username_ad, String password_ad) { Authentication_class var_auth = new Authentication_class(); AuthenticationHeader ah = var_auth.getAuthHeader(username_ad, password_ad); AsmRepository.SetServiceLocationUrl(var_auth.var_service_location_url); var billService = AsmRepository.GetServiceProxy <IBillingEngineService>(ah); var finService = AsmRepository.AllServices.GetFinanceService(ah); QuoteInvoiceCollection quotes = null; decimal total_amount = 0; ArrayList falist = new ArrayList(); long new_max_quote_id = 1; int total_record = 0; List <QuoteInvoiceCollection> the_items = new List <QuoteInvoiceCollection>(); for (int i = 1; i < 10000; i++) { quotes = billService.FindQuoteInvoices(new BaseQueryRequest() { FilterCriteria = Op.Eq("QuoteStatusId", "1") & Op.Gt("Id", 1), PageCriteria = new PageCriteria() { Page = i, PageSize = 300 }, SortCriteria = new SortCriteriaCollection() { new SortCriteria() { SortDirection = SortDirections.Ascending, Key = "Id" } }, DeepLoad = true }); //Console.WriteLine("Loop " + i + " Times!"); if (quotes.TotalCount == 0) { //Console.WriteLine("End Loop ...... "); break; } // set the new max quote id for next run int count = quotes.TotalCount - 1; new_max_quote_id = quotes.Items[count].Id.Value; foreach (var quote in quotes.Items) { // Avoid duplicate records if (falist.Contains(quote.FinancialAccountId)) { continue; } else { falist.Add(quote.FinancialAccountId); } total_amount = 0; total_amount = quote.TotalAmount.Value; var fa = finService.GetFinancialAccount(quote.FinancialAccountId.Value); // search all pending quote for same financial account and count total // Why : Customer may have multiple pending quote if he request more products or upgrade in different time, so you need count all of them. foreach (var quotet in quotes.Items) { if (quotet.FinancialAccountId == quote.FinancialAccountId && quote.Id != quotet.Id) { total_amount = total_amount + quotet.TotalAmount.Value; total_record++; //Console.WriteLine("quotet.TotalAmount.Value " + quotet.TotalAmount.Value); } } // Add the account debit like payment fee, downgrade fee...etc. so you need to add account balance total_amount = total_amount + fa.Balance.Value; //Console.WriteLine("Customer Id : " + quote.CustomerId.Value + " FA ID : " + fa.Id.Value + " , unpaid quote amount : " + total_amount); //if (quote.LineItems.TotalCount > 0) //{ // Console.WriteLine("From " + quote.LineItems.Items[0].StartDate + " To " + quote.LineItems.Items[0].EndDate); //} total_record++; } the_items.Add(new QuoteInvoiceCollection(quotes)); quotes = null; } //Console.WriteLine("Total " + total_record + " pending quotes"); //Console.Read(); //return new_max_quote_id; return(the_items); }