public async Task <bool> UpdateBilling(UpdateBillingCommand cmd)
        {
            bool isTemp = cmd.StartDate == DateTime.Now.FirstOfMonth();

            using (var bc = new BillingClient())
            {
                LNF.Models.Billing.Process.BillingProcessResult toolDataCleanResult = null;
                LNF.Models.Billing.Process.BillingProcessResult toolDataResult      = null;
                LNF.Models.Billing.Process.BillingProcessResult toolStep1Result     = null;
                LNF.Models.Billing.Process.BillingProcessResult roomDataCleanResult = null;
                LNF.Models.Billing.Process.BillingProcessResult roomDataResult      = null;
                LNF.Models.Billing.Process.BillingProcessResult roomStep1Result     = null;
                LNF.Models.Billing.Process.BillingProcessResult subsidyResult       = null;

                // Tool
                toolDataCleanResult = await bc.BillingProcessDataClean(LNF.Models.Billing.BillingCategory.Tool, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0);

                toolDataResult = await bc.BillingProcessData(LNF.Models.Billing.BillingCategory.Tool, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0);

                toolStep1Result = await bc.BillingProcessStep1(LNF.Models.Billing.BillingCategory.Tool, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0, isTemp, true);

                // Room
                roomDataCleanResult = await bc.BillingProcessDataClean(LNF.Models.Billing.BillingCategory.Room, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0);

                roomDataResult = await bc.BillingProcessData(LNF.Models.Billing.BillingCategory.Room, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0);

                roomStep1Result = await bc.BillingProcessStep1(LNF.Models.Billing.BillingCategory.Room, cmd.StartDate, cmd.EndDate, cmd.ClientID, 0, isTemp, true);

                // Subsidy
                if (!isTemp)
                {
                    subsidyResult = await bc.BillingProcessStep4("subsidy", cmd.StartDate, cmd.ClientID);
                }

                UpdateBillingResult updateResult = new UpdateBillingResult(toolDataCleanResult, toolDataResult, toolStep1Result, roomDataCleanResult, roomDataResult, roomStep1Result, subsidyResult);

                if (updateResult.HasError())
                {
                    throw new Exception(updateResult.GetErrorMessage());
                }

                return(true);
            }
        }
Example #2
0
        public async Task <bool> RunDailyTask(bool noEmail = false)
        {
            bool result = true;

            // Check client tool auths
            ResourceClientUtility.CheckExpiringClients(ResourceClientUtility.SelectExpiringClients(), ResourceClientUtility.SelectExpiringEveryone(), noEmail);
            ResourceClientUtility.CheckExpiredClients(ResourceClientUtility.SelectExpiredClients(), ResourceClientUtility.SelectExpiredEveryone(), noEmail);

            using (var bc = new BillingClient())
            {
                BillingProcessResult bpr;

                // Update Data and DataClean tables
                bpr = await bc.BillingProcessDataUpdate(BillingCategory.Tool, true);

                result = result && bpr.Success;

                bpr = await bc.BillingProcessDataUpdate(BillingCategory.Room, true);

                result = result && bpr.Success;

                bpr = await bc.BillingProcessDataUpdate(BillingCategory.Store, true);

                result = result && bpr.Success;

                //2009-08-01 Populate the Billing temp tables
                DateTime ed     = DateTime.Now.Date.AddDays(-1); //must be yesterday
                DateTime period = ed.FirstOfMonth();

                bpr = await bc.BillingProcessStep1(BillingCategory.Tool, period, period.AddMonths(1), 0, 0, true, true);

                result = result && bpr.Success;

                bpr = await bc.BillingProcessStep1(BillingCategory.Room, period, period.AddMonths(1), 0, 0, true, true);

                result = result && bpr.Success;

                bpr = await bc.BillingProcessStep1(BillingCategory.Store, period, period.AddMonths(1), 0, 0, true, true);

                result = result && bpr.Success;
            }

            return(result);
        }
Example #3
0
        public async Task <bool> RunMonthlyTask(bool noEmail = false)
        {
            try
            {
                bool result = true;

                // 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);

                using (var bc = new BillingClient())
                {
                    // This sends apportionment emails to clients
                    await bc.SendUserApportionmentReport(new UserApportionmentReportOptions()
                    {
                        Period  = period,
                        NoEmail = noEmail
                    });

                    // 2008-04-30
                    // Monthly financial report
                    await bc.SendFinancialManagerReport(new FinancialManagerReportOptions()
                    {
                        Period         = period,
                        IncludeManager = !noEmail
                    });

                    // This sends room expiration emails
                    RoomAccessExpirationCheck roomAccessExpirationCheck = new RoomAccessExpirationCheck();
                    int count = await roomAccessExpirationCheck.Run();

                    ////2009-08-01 Populate the BillingTables

                    //first day of last month
                    DateTime sd = period;
                    DateTime ed = period.AddMonths(1);

                    BillingProcessResult bpr;

                    bpr = await bc.BillingProcessStep1(BillingCategory.Tool, sd, ed, 0, 0, false, true);

                    result = result && bpr.Success;

                    bpr = await bc.BillingProcessStep1(BillingCategory.Room, sd, ed, 0, 0, false, true);

                    result = result && bpr.Success;

                    bpr = await bc.BillingProcessStep1(BillingCategory.Store, sd, ed, 0, 0, false, true);

                    result = result && bpr.Success;

                    bpr = await bc.BillingProcessStep4("subsidy", sd, 0);

                    result = result && bpr.Success;
                }

                return(result);
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                return(false);
            }
        }