public string RunUpdateBilling(string[] args) { ParseArgs(args, out DateTime period, out int clientId, out string billingCategories); var bc = (BillingCategory)Enum.Parse(typeof(BillingCategory), billingCategories, true); if (bc == 0) { throw new Exception("At least one billing category is required."); } var mgr = new BillingManager(_provider, period, clientId); return(mgr.UpdateBilling(bc)); }
public string RunMonthlyTask(bool noEmail) { DateTime now = DateTime.Now; string message = string.Empty; ProcessResult result; // This is run at midnight on the 1st of the month. So the period should be the 1st of the previous month. DateTime period = DateTime.Now.FirstOfMonth().AddMonths(-1); message += $"Period: {period:yyyy-MM-dd HH:mm:ss}"; var autoSend = new Dictionary <string, string> { ["ApportionmentReminder_AutoSendMonthlyEmail"] = GlobalSettings.Current.GetGlobalSetting("ApportionmentReminder_AutoSendMonthlyEmail"), ["FinancialManagerReport_AutoSendMonthlyEmail"] = GlobalSettings.Current.GetGlobalSetting("FinancialManagerReport_AutoSendMonthlyEmail"), ["ExpiringCardsReminder_AutoSendMonthlyEmail"] = GlobalSettings.Current.GetGlobalSetting("ExpiringCardsReminder_AutoSendMonthlyEmail") }; // This sends apportionment emails to clients if (autoSend.Any(x => x.Key == "ApportionmentReminder_AutoSendMonthlyEmail" && x.Value == "true")) { result = _provider.Billing.Report.SendUserApportionmentReport(new UserApportionmentReportOptions { Period = period, Message = null, NoEmail = noEmail }); message += Environment.NewLine + Environment.NewLine + result.LogText; } else { message += Environment.NewLine + Environment.NewLine + "ApportionmentReminder_AutoSendMonthlyEmail == false"; } // 2008-04-30 // Monthly financial report if (autoSend.Any(x => x.Key == "FinancialManagerReport_AutoSendMonthlyEmail" && x.Value == "true")) { var fm = new FinancialManagers(_provider.Billing.Report); result = fm.SendMonthlyUserUsageEmails(new FinancialManagerReportOptions() { Period = period, ClientID = 0, ManagerOrgID = 0, IncludeManager = !noEmail }); message += Environment.NewLine + Environment.NewLine + result.LogText; } else { message += Environment.NewLine + Environment.NewLine + "FinancialManagerReport_AutoSendMonthlyEmail == false"; } // This sends room expiration emails if (autoSend.Any(x => x.Key == "ExpiringCardsReminder_AutoSendMonthlyEmail" && x.Value == "true")) { var cardExpirationResult = _provider.Billing.Report.SendCardExpirationReport(); var expirationEmailsSent = cardExpirationResult.TotalEmailsSent; message += Environment.NewLine + Environment.NewLine + $"ExpirationEmailsSent: {expirationEmailsSent}"; } else { message += Environment.NewLine + Environment.NewLine + "ExpiringCardsReminder_AutoSendMonthlyEmail == false"; } // 2009-08-01 Populate the BillingTables BillingManager bm = new BillingManager(_provider, period, 0); message += Environment.NewLine + Environment.NewLine + bm.UpdateBilling(BillingCategory.Tool | BillingCategory.Room | BillingCategory.Store); var sendMonthlyTaskEmail = GlobalSettings.Current.GetGlobalSetting("SendMonthlyTaskEmail"); if (!string.IsNullOrEmpty(sendMonthlyTaskEmail)) { // send an email SendEmail.SendSystemEmail("OnlineServicesWorker.TaskManager.RunMonthlyTask", $"MonthlyTask result [{now:yyyy-MM-dd HH:mm:ss}]", message, sendMonthlyTaskEmail.Split(','), false); } return(message); }