static void Main() { Console.WriteLine("*************************************************************************"); Console.WriteLine("WebJobUsageDaily:Main starting. DateTimeUTC: {0}", DateTime.UtcNow); List<Subscription> abis = Commons.Utils.GetSubscriptions(); foreach (Subscription s in abis) { //Commons.Utils.UpdateSubscriptionStatus(s.Id, DataGenStatus.Pending, DateTime.UtcNow.AddYears(-3)); try { //DateTime sdt = DateTime.Now.AddYears(-3); DateTime sdt = DateTime.Now.AddDays(-2); DateTime edt = DateTime.Now; BillingRequest br = new BillingRequest(s.Id, s.OrganizationId, sdt, edt); // Insert into Azure Storage Queue var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString()); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue subscriptionsQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["ida:QueueBillingDataRequests"].ToString()); subscriptionsQueue.CreateIfNotExists(); var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(br)); subscriptionsQueue.AddMessageAsync(queueMessage); Console.WriteLine(String.Format("Sent id for daily billing log: {0}", s.Id)); Commons.Utils.UpdateSubscriptionStatus(s.Id, DataGenStatus.Pending, DateTime.UtcNow); } catch (Exception e) { Console.WriteLine("WebJobUsageDaily - SendQueue: " + e.Message); } } // foreach }
public async Task<ActionResult> ProcessSelectedIds(string[] selectedIDs) { try { foreach (string sid in selectedIDs) { Subscription subs = dm.subscriptionList[sid]; if (subs == null) continue; // Following sendToQueue and SaveToDB must be atomic DateTime sdt = DateTime.Now.AddYears(-3); DateTime edt = DateTime.Now.AddDays(-1); BillingRequest br = new BillingRequest(subs.Id, subs.OrganizationId, sdt, edt); var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString()); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue subscriptionsQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["ida:QueueBillingDataRequests"].ToString()); subscriptionsQueue.CreateIfNotExists(); var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(br)); await subscriptionsQueue.AddMessageAsync(queueMessage); Subscription s = db.Subscriptions.Find(sid); if (s != null) { s.DataGenDate = DateTime.UtcNow; s.DataGenStatus = DataGenStatus.Pending; db.Entry(s).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } catch (Exception e) { return RedirectToAction("Error", "Home", new {msg = e.Message }); } return RedirectToAction("Index", "Dashboard"); }
public ActionResult Connect([Bind(Include = "Id, OrganizationId, DisplayName")] Subscription subscription, string servicePrincipalObjectId, string displayTag) { if (ModelState.IsValid) { AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId); AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId); if (AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, subscription.OrganizationId)) { // Insert into SQL DB subscription.ConnectedBy = (System.Security.Claims.ClaimsPrincipal.Current).FindFirst(ClaimTypes.Name).Value; subscription.ConnectedOn = DateTime.Now; subscription.AzureAccessNeedsToBeRepaired = false; subscription.DisplayTag = displayTag; subscription.DataGenDate = DateTime.UtcNow; subscription.DataGenStatus = DataGenStatus.Pending; db.Subscriptions.Add(subscription); db.SaveChanges(); DateTime sdt = DateTime.Now.AddYears(-3); DateTime edt = DateTime.Now.AddDays(-1); BillingRequest br = new BillingRequest(subscription.Id, subscription.OrganizationId, sdt, edt); // Insert into Azure Storage Queue var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString()); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue subscriptionsQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["ida:QueueBillingDataRequests"].ToString()); subscriptionsQueue.CreateIfNotExists(); var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(br)); subscriptionsQueue.AddMessageAsync(queueMessage); } } return RedirectToAction("Index", "Home"); }
public ActionResult Connect([Bind(Include = "Id, OrganizationId, DisplayName")] Subscription subscription, string servicePrincipalObjectId, string displayTag) { if (ModelState.IsValid) { AzureResourceManagerUtil.RevokeRoleFromServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId); AzureResourceManagerUtil.GrantRoleToServicePrincipalOnSubscription(servicePrincipalObjectId, subscription.Id, subscription.OrganizationId); if (AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, subscription.OrganizationId)) { // Insert into SQL DB subscription.ConnectedBy = (ClaimsPrincipal.Current).FindFirst(ClaimTypes.Name).Value; subscription.ConnectedOn = DateTime.UtcNow; subscription.AzureAccessNeedsToBeRepaired = false; subscription.DisplayTag = displayTag; subscription.DataGenDate = DateTime.UtcNow; subscription.DataGenStatus = DataGenStatus.Pending; db.Subscriptions.Add(subscription); db.SaveChanges(); DateTime sdt = DateTime.UtcNow.Date.AddYears(-3); DateTime edt = DateTime.UtcNow.Date.AddDays(-1); BillingRequest br = new BillingRequest(subscription.Id, subscription.OrganizationId, sdt, edt); // Insert into Azure Storage Queue var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString()); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue subscriptionsQueue = queueClient.GetQueueReference(ConfigurationManager.AppSettings["ida:QueueBillingDataRequests"].ToString()); subscriptionsQueue.CreateIfNotExists(); var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(br)); subscriptionsQueue.AddMessageAsync(queueMessage); } } return(RedirectToAction("Index", "Home")); }
internal static void EnqueueBillingDownload(DateTime startDate, DateTime endDate) { List <Subscription> abis = Utils.GetSubscriptions(); foreach (Subscription s in abis) { try { BillingRequest billingRequest = new BillingRequest(s.Id, s.OrganizationId, startDate, endDate); // Insert into Azure Storage Queue var storageAccount = CloudStorageAccount.Parse(AzureWebJobsStorage); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue subscriptionsQueue = queueClient.GetQueueReference(QueueBillingDataRequests); subscriptionsQueue.CreateIfNotExists(); var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(billingRequest)); subscriptionsQueue.AddMessageAsync(queueMessage); Trace.TraceInformation($"Enqueued id for daily billing log: {s.Id}"); Utils.UpdateSubscriptionStatus(s.Id, DataGenStatus.Pending, DateTime.UtcNow); } catch (Exception e) { Trace.TraceError($"WebJobUsageDaily - SendQueue: {e.Message}"); } } // foreach }
public void ValidateRequest(BillingRequest dopplerBillingRequest) { if (dopplerBillingRequest.Id.Equals(default))
public static void ProcessQueueMessage([QueueTrigger("billingdatarequests")] BillingRequest br) { Console.WriteLine("Start webjob process. SubscriptionID: {0}", br.SubscriptionId); int retriesLeft = Convert.ToInt32(ConfigurationManager.AppSettings["ida:RetryCountToProcessMessage"].ToString()); while (retriesLeft > 0) { --retriesLeft; if (retriesLeft < 1) { Console.WriteLine("Finished internal retries, throwing exception. Time:{0}", DateTime.UtcNow.ToString()); throw new Exception(); } Console.WriteLine("Start time:{0} Retries Left: {1}", DateTime.UtcNow.ToString(), retriesLeft); try { //Fetch RateCard information First string rateCardURL = AzureResourceManagerUtil.GetRateCardRestApiCallURL(br.SubscriptionId, ConfigurationManager.AppSettings["ida:OfferCode"].ToString(), ConfigurationManager.AppSettings["ida:Currency"].ToString(), ConfigurationManager.AppSettings["ida:Locale"].ToString(), ConfigurationManager.AppSettings["ida:RegionInfo"].ToString()); Console.WriteLine("Request cost info from RateCard service."); RateCardPayload rateCardInfo = GetRateCardInfo(rateCardURL, br.OrganizationId); if (rateCardInfo == null) { Console.WriteLine("Problem receiving cost info occured - see log for details."); continue; } else { Console.WriteLine("Received cost info: " + rateCardInfo.ToString()); } // if granularity=hourly then report up to prev. hour, // if granularity=daily then report up to prev. day. Othervise will get 400 error //DateTime sdt = DateTime.Now.AddYears(-3); //DateTime edt = DateTime.Now.AddDays(-1); string restURL = AzureResourceManagerUtil.GetBillingRestApiCallURL(br.SubscriptionId, false, true, br.StartDate, br.EndDate); Console.WriteLine("Request usage data from Billing service."); List <UsageRecord> urs = GetUsageDetails(restURL, br.OrganizationId, rateCardInfo); Console.WriteLine("Received record count: {0}", urs.Count); Console.WriteLine("Insert usage data into SQL Server."); InsertIntoSQLDB(urs); break; } catch (Exception e) { Console.WriteLine("Exception: ProcessQueueMessage->e.Message: " + e.Message); if (retriesLeft == 0) { throw; } } Console.WriteLine("Sleeping in ProcessQueueMessage while loop for 5 min. DateTime: {0}", DateTime.Now.ToString()); Thread.Sleep(1000 * 60 * 5); } // while Commons.Utils.UpdateSubscriptionStatus(br.SubscriptionId, DataGenStatus.Completed, DateTime.UtcNow); Console.WriteLine("Complete webjob process. SubscriptionID: {0}", br.SubscriptionId); }
private void runRequestOrQueue(BillingRequest request) { mPendingRequests.Add(request); if (mService == null) { bindMarketBillingService(); } else { runPendingRequests(); } }
private void runRequest(BillingRequest request) { try { long requestId = request.run(mService); BillingController.onRequestSent(requestId, request); } catch (RemoteException e) { Log.Warn(typeof(BillingService).FullName, "Remote billing service crashed"); // TODO: Retry? } }
public SapSaleOrderModel MapDopplerBillingRequestToSapSaleOrder(BillingRequest billingRequest) { var sapSaleOrder = new SapSaleOrderModel { NumAtCard = billingRequest.PurchaseOrder ?? "", U_DPL_RECURRING_SERV = billingRequest.IsPlanUpgrade ? "N" : "Y", DocumentLines = new List <SapDocumentLineModel>(), DocDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"), DocDueDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"), TaxDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd") }; var currencyCode = Dictionary.CurrencyDictionary.TryGetValue(billingRequest.Currency, out var code) ? code : ""; var itemCode = _sapBillingItemsService.GetItemCode(billingRequest.PlanType, billingRequest.CreditsOrSubscribersQuantity, billingRequest.IsCustomPlan); var planItem = new SapDocumentLineModel { ItemCode = itemCode, UnitPrice = billingRequest.PlanFee, Currency = currencyCode, FreeText = $"{currencyCode} {billingRequest.PlanFee.ToString(CultureInfo.CurrentCulture)} + IMP", DiscountPercent = billingRequest.Discount ?? 0, CostingCode = _costingCode1, CostingCode2 = _costingCode2, CostingCode3 = _costingCode3, CostingCode4 = _costingCode4 }; var freeText = new { Amount = $"{currencyCode} {billingRequest.PlanFee.ToString(CultureInfo.CurrentCulture)} + IMP", Periodicity = billingRequest.Periodicity != null ? $"Plan {(Dictionary.PeriodicityDictionary.TryGetValue(billingRequest.Periodicity, out var outPeriodicity) ? outPeriodicity : string.Empty)}" : null, Discount = billingRequest.Discount > 0 ? $"Descuento {billingRequest.Discount}%" : null, Payment = $"Abono {billingRequest.PeriodMonth:00} {billingRequest.PeriodYear}", }; planItem.FreeText = string.Join(" - ", new string[] { freeText.Amount, freeText.Periodicity, freeText.Discount, freeText.Payment }.Where(s => !string.IsNullOrEmpty(s))); sapSaleOrder.DocumentLines.Add(planItem); if (billingRequest.ExtraEmails > 0) { var itemCodeSurplus = _sapBillingItemsService.GetItems(billingRequest.PlanType).Where(x => x.SurplusEmails.Value) .Select(x => x.ItemCode) .FirstOrDefault(); var extraEmailItem = new SapDocumentLineModel { ItemCode = itemCodeSurplus, UnitPrice = billingRequest.ExtraEmailsFee, Currency = currencyCode, FreeText = $"Email excedentes {billingRequest.ExtraEmails}", CostingCode = _costingCode1, CostingCode2 = _costingCode2, CostingCode3 = _costingCode3, CostingCode4 = _costingCode4 }; if (billingRequest.ExtraEmailsFee > 0) { extraEmailItem.FreeText += $" - {currencyCode} {billingRequest.ExtraEmailsFeePerUnit} + IMP"; } extraEmailItem.FreeText += $" - Período {billingRequest.ExtraEmailsPeriodMonth:00} {billingRequest.ExtraEmailsPeriodYear}"; sapSaleOrder.DocumentLines.Add(extraEmailItem); } sapSaleOrder.FiscalID = billingRequest.FiscalID; sapSaleOrder.UserId = billingRequest.Id; sapSaleOrder.PlanType = billingRequest.PlanType; sapSaleOrder.BillingSystemId = billingRequest.BillingSystemId; sapSaleOrder.TransactionApproved = billingRequest.TransactionApproved; return(sapSaleOrder); }
public SapSaleOrderModel MapDopplerBillingRequestToSapSaleOrder(BillingRequest billingRequest) { var sapSaleOrder = new SapSaleOrderModel { NumAtCard = billingRequest.PurchaseOrder ?? "", U_DPL_RECURRING_SERV = billingRequest.IsPlanUpgrade ? "N" : "Y", U_DPL_CARD_HOLDER = billingRequest.CardHolder, U_DPL_CARD_NUMBER = billingRequest.CardNumber, U_DPL_CARD_TYPE = billingRequest.CardType, U_DPL_CARD_ERROR_COD = billingRequest.CardErrorCode, U_DPL_CARD_ERROR_DET = billingRequest.CardErrorDetail, DocumentLines = new List <SapDocumentLineModel>(), DocDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"), DocDueDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"), TaxDate = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd") }; var itemCode = _sapBillingItemsService.GetItemCode(billingRequest.PlanType, billingRequest.CreditsOrSubscribersQuantity, billingRequest.IsCustomPlan); var planItem = new SapDocumentLineModel { TaxCode = _defaultTaxCode, ItemCode = itemCode, UnitPrice = billingRequest.PlanFee, Currency = _currencyCode, FreeText = $"{_currencyCode} {billingRequest.PlanFee.ToString(CultureInfo.CurrentCulture)} + TAX", DiscountPercent = billingRequest.Discount ?? 0, CostingCode = _costingCode1, CostingCode2 = _costingCode2, CostingCode3 = _costingCode3, CostingCode4 = _costingCode4 }; var freeText = new { Amount = $"{_currencyCode} {billingRequest.PlanFee.ToString(CultureInfo.CurrentCulture)} + TAX", Periodicity = billingRequest.Periodicity != null ? $" {(periodicities.TryGetValue(billingRequest.Periodicity, out var outPeriodicity2) ? outPeriodicity2 : string.Empty)} Plan " : null, Discount = billingRequest.Discount > 0 ? $"{billingRequest.Discount}% OFF" : null, Payment = $"Payment {billingRequest.PeriodMonth:00} {billingRequest.PeriodYear}", }; planItem.FreeText = string.Join(" - ", new string[] { freeText.Amount, freeText.Periodicity, freeText.Discount, freeText.Payment }.Where(s => !string.IsNullOrEmpty(s))); sapSaleOrder.DocumentLines.Add(planItem); if (billingRequest.ExtraEmails > 0) { var itemCodeSurplus = _sapBillingItemsService.GetItems(billingRequest.PlanType).Where(x => x.SurplusEmails.HasValue && x.SurplusEmails.Value) .Select(x => x.ItemCode) .FirstOrDefault(); var extraEmailItem = new SapDocumentLineModel { TaxCode = _defaultTaxCode, ItemCode = itemCodeSurplus, UnitPrice = billingRequest.ExtraEmailsFee, Currency = _currencyCode, FreeText = $"Excess emails {billingRequest.ExtraEmails}", CostingCode = _costingCode1, CostingCode2 = _costingCode2, CostingCode3 = _costingCode3, CostingCode4 = _costingCode4 }; var extraEmailsFreeText = new { ExcessEmails = $"Excess emails {billingRequest.ExtraEmails}", Amount = billingRequest.ExtraEmailsFee > 0 ? $"{_currencyCode} {billingRequest.ExtraEmailsFeePerUnit} + TAX" : null }; if (billingRequest.ExtraEmailsFee > 0) { extraEmailItem.FreeText += $" - {_currencyCode} {billingRequest.ExtraEmailsFeePerUnit} + TAX"; } extraEmailItem.FreeText += $" - Period {billingRequest.ExtraEmailsPeriodMonth:00} {billingRequest.ExtraEmailsPeriodYear}"; var test = string.Join(" - ", new string[] { extraEmailsFreeText.ExcessEmails, extraEmailsFreeText.Amount }.Where(s => !string.IsNullOrEmpty(s))); sapSaleOrder.DocumentLines.Add(extraEmailItem); } sapSaleOrder.FiscalID = billingRequest.FiscalID; sapSaleOrder.UserId = billingRequest.Id; sapSaleOrder.PlanType = billingRequest.PlanType; sapSaleOrder.BillingSystemId = billingRequest.BillingSystemId; sapSaleOrder.TransactionApproved = billingRequest.TransactionApproved; sapSaleOrder.TransferReference = billingRequest.TransferReference; return(sapSaleOrder); }
public static void ProcessQueueMessage([QueueTrigger("billingdatarequests")] BillingRequest billingRequest, TextWriter logWriter = null) { if (logWriter != null) { TextWriterTraceListener traceListener = new TextWriterTraceListener(logWriter, "LogWriter"); Trace.Listeners.Remove("LogWriter"); Trace.Listeners.Add(traceListener); Trace.TraceInformation("Azure WebJob Log Writer configured"); } Trace.TraceInformation($"WebJob process started. {nameof(billingRequest.SubscriptionId)}: {billingRequest.SubscriptionId}"); int retriesLeft = Convert.ToInt32(RetryCountToProcessMessage); Exception lastException = null; while (retriesLeft > 0) { --retriesLeft; if (retriesLeft < 1) { Trace.TraceInformation($"Finished internal retries, time:{DateTime.UtcNow}"); if (lastException != null) { throw lastException; } else { return; } } Trace.TraceInformation($"Start time:{DateTime.UtcNow}, retries Left: {retriesLeft}"); try { //Fetch RateCard information First string rateCardUrl = AzureResourceManagerUtil.GetRateCardRestApiCallURL(billingRequest.SubscriptionId, OfferCode, Currency, Locale, RegionInfo); Trace.TraceInformation("Request cost info from RateCard service."); RateCardPayload rateCardInfo = GetRateCardInfo(rateCardUrl, billingRequest.OrganizationId); if (rateCardInfo == null) { Trace.TraceWarning("Problem receiving cost info occured - see log for details."); continue; } else { Trace.TraceInformation("Received cost info: " + rateCardInfo.ToString()); } // if granularity=hourly then report up to prev. hour, // if granularity=daily then report up to prev. day. Othervise will get 400 error //DateTime sdt = DateTime.UtcNow.Date.AddYears(-3); //DateTime edt = DateTime.UtcNow.Date.AddDays(-1); // see: https://msdn.microsoft.com/en-us/library/azure/mt219004.aspx string restUrl = AzureResourceManagerUtil.GetBillingRestApiCallUrl(billingRequest.SubscriptionId, true, true, billingRequest.StartDate, billingRequest.EndDate); Trace.TraceInformation("Request usage data from Billing service."); var usageRecords = GetUsageDetails(restUrl, billingRequest.OrganizationId, rateCardInfo); Trace.TraceInformation($"Received record count: {usageRecords.Count}"); if (usageRecords.Count > 0) { Trace.TraceInformation("Inserting usage records into SQL database."); Task <int> task = InsertIntoSqlDbAsync(usageRecords, billingRequest.SubscriptionId, billingRequest.StartDate, billingRequest.EndDate); int recordCount = task.GetAwaiter().GetResult(); Trace.TraceInformation($"Total {recordCount} usage record(s) inserted."); } else { Trace.TraceInformation("No usage data found."); } break; } catch (Exception e) { Trace.TraceError($"Exception: {nameof(ProcessQueueMessage)} -> e.Message: " + e.Message); lastException = e; if (retriesLeft == 0) { throw; } } Trace.TraceInformation($"Sleeping in {nameof(ProcessQueueMessage)} while loop for 5 min. DateTime: {DateTime.UtcNow}"); Thread.Sleep(1000 * 60 * 5); } // while Utils.UpdateSubscriptionStatus(billingRequest.SubscriptionId, DataGenStatus.Completed, DateTime.UtcNow); Trace.TraceInformation($"WebJob process completed. SubscriptionId: {billingRequest.SubscriptionId}"); }
public static SapSaleOrderModel MapDopplerBillingRequestToSapSaleOrder(BillingRequest billingRequest) { var sapSaleOrder = new SapSaleOrderModel { NumAtCard = billingRequest.PurchaseOrder ?? "", U_DPL_RECURRING_SERV = billingRequest.IsPlanUpgrade ? "N" : "Y", DocumentLines = new List <SapDocumentLineModel>() }; var currencyCode = Dictionary.CurrencyDictionary.TryGetValue(billingRequest.Currency, out var code) ? code : ""; var jsonPath = Path.Combine(Environment.CurrentDirectory, @"Resources/SapBillingItems.json"); var itemsList = JsonConvert.DeserializeObject <List <SapBillingItemModel> >(File.ReadAllText(jsonPath)); var itemCodesList = itemsList.Where(x => x.PlanType == billingRequest.PlanType) .Select(x => x.PlanDescription) .First(); var itemCode = billingRequest.IsCustomPlan ? itemCodesList.Where(x => x.CustomPlan == true) .Select(x => x.ItemCode) .FirstOrDefault() : itemCodesList.Where(x => x.emailsQty == billingRequest.CreditsOrSubscribersQuantity || x.SubscriberQty == billingRequest.CreditsOrSubscribersQuantity) .Select(x => x.ItemCode) .FirstOrDefault(); var planItem = new SapDocumentLineModel { ItemCode = itemCode, UnitPrice = billingRequest.PlanFee, Currency = currencyCode, FreeText = $"{currencyCode} {billingRequest.PlanFee.ToString(CultureInfo.CurrentCulture)} + IMP", DiscountPercent = billingRequest.Discount ?? 0 }; if (billingRequest.Periodicity != null) { var periodicity = Dictionary.PeriodicityDictionary.TryGetValue(billingRequest.Periodicity, out var outPeriodicity) ? outPeriodicity : ""; planItem.FreeText += $" - Plan {periodicity} "; } planItem.FreeText += $" - Abono {billingRequest.PeriodMonth:00} {billingRequest.PeriodYear}"; if (billingRequest.Discount > 0) { planItem.FreeText += $" - Descuento {billingRequest.Discount}%"; } sapSaleOrder.DocumentLines.Add(planItem); if (billingRequest.ExtraEmails > 0) { var itemCodeSurplus = itemCodesList.Where(x => x.SurplusEmails == true) .Select(x => x.ItemCode) .FirstOrDefault(); var extraEmailItem = new SapDocumentLineModel { ItemCode = itemCodeSurplus, UnitPrice = billingRequest.ExtraEmailsFee, Currency = currencyCode, FreeText = $"Email excedentes {billingRequest.ExtraEmails}" }; if (billingRequest.ExtraEmailsFee > 0) { extraEmailItem.FreeText += $" - {currencyCode} {billingRequest.ExtraEmailsFeePerUnit} + IMP"; } extraEmailItem.FreeText += $" - Período {billingRequest.ExtraEmailsPeriodMonth:00} {billingRequest.ExtraEmailsPeriodYear}"; sapSaleOrder.DocumentLines.Add(extraEmailItem); } sapSaleOrder.FiscalID = billingRequest.FiscalID; sapSaleOrder.UserId = billingRequest.Id; sapSaleOrder.PlanType = billingRequest.PlanType; return(sapSaleOrder); }
private async Task <string> GetRateCardForOfferAsString(string offerId) { Customer.OfferId = Customer.OfferId ?? offerId; return(await BillingRequest.MakeRequest(Customer)); }