public UpdateClientBillingResult UpdateClientBilling(UpdateClientBillingCommand model)
 {
     using (DA.StartUnitOfWork())
     {
         return(ServiceProvider.Current.Billing.Process.UpdateClientBilling(model));
     }
 }
示例#2
0
        public UpdateClientBillingResult UpdateClientBilling(UpdateClientBillingCommand command)
        {
            if (command.Period == default)
            {
                throw new Exception("Missing parameter: Period");
            }

            if (command.Period.Day != 1)
            {
                throw new Exception("Period must be the first day of the month.");
            }

            using (var conn = NewConnection())
            {
                conn.Open();

                DateTime now = DateTime.Now;

                DateTime sd = command.Period;
                DateTime ed = command.Period.AddMonths(1);

                var toolDataClean = new WriteToolDataCleanProcess(new WriteToolDataCleanConfig {
                    Connection = conn, Context = "ProcessRepository.UpdateClientBilling", StartDate = sd, EndDate = ed, ClientID = command.ClientID
                });
                var toolData = new WriteToolDataProcess(WriteToolDataConfig.Create(conn, "ProcessRepository.UpdateClientBilling", sd, command.ClientID, 0, Cost.GetToolCosts(sd, 0)));

                var roomDataClean = new WriteRoomDataCleanProcess(new WriteRoomDataCleanConfig {
                    Connection = conn, Context = "ProcessRepository.UpdateClientBilling", StartDate = sd, EndDate = ed, ClientID = command.ClientID
                });
                var roomData = new WriteRoomDataProcess(new WriteRoomDataConfig {
                    Connection = conn, Context = "ProcessRepository.UpdateClientBilling", Period = sd, ClientID = command.ClientID, RoomID = 0
                });

                var pr1 = toolDataClean.Start();
                var pr2 = roomDataClean.Start();

                var pr3 = toolData.Start();
                var pr4 = roomData.Start();

                bool temp = DateTime.Now.FirstOfMonth() == command.Period;

                var step1 = new BillingDataProcessStep1(new Step1Config {
                    Connection = conn, Context = "ProcessRepository.UpdateClientBilling", Period = command.Period, Now = now, ClientID = command.ClientID, IsTemp = temp
                });

                var pr5 = step1.PopulateToolBilling();
                var pr6 = step1.PopulateRoomBilling();

                PopulateSubsidyBillingResult pr7 = null;

                if (!temp)
                {
                    var step4 = new BillingDataProcessStep4Subsidy(new Step4Config {
                        Connection = conn, Context = "ProcessRepository.UpdateClientBilling", Period = command.Period, ClientID = command.ClientID
                    });
                    pr7 = step4.PopulateSubsidyBilling();
                }

                var result = new UpdateClientBillingResult
                {
                    WriteToolDataCleanProcessResult     = pr1,
                    WriteRoomDataCleanProcessResult     = pr2,
                    WriteToolDataProcessResult          = pr3,
                    WriteRoomDataProcessResult          = pr4,
                    PopulateToolBillingProcessResult    = pr5,
                    PopulateRoomBillingProcessResult    = pr6,
                    PopulateSubsidyBillingProcessResult = pr7
                };

                conn.Close();

                return(result);
            }
        }
示例#3
0
 public UpdateClientBillingResult UpdateClientBilling(UpdateClientBillingCommand model)
 {
     return(Post <UpdateClientBillingResult>("webapi/billing/update-client", model));
 }