Пример #1
0
        // Call this function if period is between 2011-04-01 and 2011-06-01
        public static DataSet GetToolBillingDataByClientID20110401(HttpContextBase context, DateTime period, int clientId)
        {
            DataSet   ds = null;
            DataTable dt1, dt2, dt3;
            DateTime  CutOffDate20110401 = new DateTime(2011, 4, 1);

            if (period.Month == DateTime.Now.Month && period.Year == DateTime.Now.Year)
            {
                //Viewing current month data
                ds = ToolBillingDA.GetToolBillingTempDataByClientID(period, clientId);
            }
            else
            {
                ds = new DataSet();

                BillingTableType t1, t2, t3;
                if (period < CutOffDate20110401)
                {
                    t1 = BillingTableType.ToolBillingActivated;
                    t2 = BillingTableType.ToolBillingUncancelled;
                    t3 = BillingTableType.ToolBillingForgiven;
                }
                else
                {
                    t1 = BillingTableType.ToolBilling20110401Reservations;
                    t2 = BillingTableType.ToolBilling20110401Cancelled;
                    t3 = BillingTableType.ToolBilling20110401Forgiven;
                }

                dt1 = BillingTablesBL.GetMultipleTables(context, period.Year, period.Month, clientId, t1);
                dt2 = BillingTablesBL.GetMultipleTables(context, period.Year, period.Month, clientId, t2);
                dt3 = BillingTablesBL.GetMultipleTables(context, period.Year, period.Month, clientId, t3);
                ds.Tables.Add(dt1.Copy());
                ds.Tables.Add(dt2.Copy());
                ds.Tables.Add(dt3.Copy());
            }

            if (period < CutOffDate20110401)
            {
                //Part I : calculate the true Line Cost based on billing type, reservation status
                foreach (DataTable dt in ds.Tables)
                {
                    dt.Columns.Add("LineCost", typeof(double));
                    foreach (DataRow dr in dt.Rows)
                    {
                        int  billingTypeId = dr.Field <int>("BillingTypeID");
                        var  room          = Rooms.All().FirstOrDefault(x => x.RoomID == dr.Field <int>("RoomID"));
                        bool isStarted     = dr.Field <bool>("IsStarted");

                        if (BillingTypes.IsMonthlyUserBillingType(billingTypeId))
                        {
                            if (period >= new DateTime(2010, 7, 1))
                            {
                                //Monthly User, so we have flat fee for clean room
                                if (room == Rooms.CleanRoom)
                                {
                                    if (dr.Field <int>("ResourceID") == 56000)
                                    {
                                        if (isStarted)
                                        {
                                            dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                        }
                                        else
                                        {
                                            dr["LineCost"] = dr.Field <decimal>("UncancelledPenaltyFee") + dr.Field <decimal>("ReservationFee");
                                        }
                                    }
                                    else
                                    {
                                        dr["LineCost"] = 0;
                                    }
                                }
                                else
                                {
                                    if (isStarted)
                                    {
                                        dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                    }
                                    else
                                    {
                                        dr["LineCost"] = dr.Field <decimal>("UncancelledPenaltyFee") + dr.Field <decimal>("ReservationFee");
                                    }
                                }
                            }
                            else
                            {
                                //Monthly User, so we have flat fee for clean room
                                if (room == Rooms.CleanRoom)
                                {
                                    if (dr.Field <int>("ResourceID") == 56000)
                                    {
                                        if (isStarted)
                                        {
                                            dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                        }
                                        else
                                        {
                                            dr["LineCost"] = dr.Field <decimal>("UncancelledPenaltyFee") + dr.Field <decimal>("ReservationFee");
                                        }
                                    }
                                    else
                                    {
                                        dr["LineCost"] = 0;
                                    }
                                }
                                else
                                {
                                    if (isStarted)
                                    {
                                        dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                    }
                                    else
                                    {
                                        dr["LineCost"] = dr.Field <decimal>("UncancelledPenaltyFee") + dr.Field <decimal>("ReservationFee");
                                    }
                                }
                            }
                        }
                        else if (billingTypeId == BillingTypes.Other)
                        {
                            dr["LineCost"] = 0;
                        }
                        else
                        {
                            if (period >= new DateTime(2010, 7, 1))
                            {
                                //Per Use types
                                if (isStarted)
                                {
                                    dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                }
                                else
                                {
                                    dr["LineCost"] = dr["UncancelledPenaltyFee"];
                                }
                            }
                            else
                            {
                                if (isStarted)
                                {
                                    dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("ReservationFee");
                                }
                                else
                                {
                                    dr["LineCost"] = dr.Field <decimal>("UncancelledPenaltyFee") + dr.Field <decimal>("ReservationFee");
                                }
                            }
                        }

                        //if the tool rate is 0, then everything should be 0
                        bool hasPerUseRateColumn = dt.Columns.Contains("PerUseRate");
                        var  resourceRate        = dr.Field <decimal>("ResourceRate");
                        var  perUserRate         = hasPerUseRateColumn ? dr.Field <decimal>("PerUseRate") : 0M;

                        if (resourceRate + perUserRate == 0)
                        {
                            dr["LineCost"] = 0;
                        }
                    }
                }
            }
            else
            {
                //2011-04-01
                foreach (DataTable dt in ds.Tables)
                {
                    dt.Columns.Add("LineCost", typeof(double));
                    foreach (DataRow dr in dt.Rows)
                    {
                        int  billingTypeId = dr.Field <int>("BillingTypeID");
                        bool isCancelledBeforeAllowedTime = dr.Field <bool>("IsCancelledBeforeAllowedTime");

                        if (billingTypeId == BillingTypes.Other)
                        {
                            dr["LineCost"] = 0;
                        }
                        else
                        {
                            if (period >= new DateTime(2010, 7, 1))
                            {
                                //Per Use types
                                if (!isCancelledBeforeAllowedTime)
                                {
                                    dr["LineCost"] = dr.Field <decimal>("UsageFeeCharged") + dr.Field <decimal>("OverTimePenaltyFee") + dr.Field <decimal>("BookingFee");
                                }
                                else
                                {
                                    dr["LineCost"] = dr.Field <decimal>("BookingFee"); //Cancelled before two hours
                                }
                            }
                        }

                        //if the tool rate is 0, then everything should be 0
                        decimal rateTotal = dr.Field <decimal>("ResourceRate") + dr.Field <decimal>("PerUserRate");
                        if (rateTotal == 0)
                        {
                            dr["LineCost"] = 0;
                        }
                    }
                }
            }

            return(ds);
        }
Пример #2
0
 // Метод для перевірки наявності вільних номерів у готелі.
 public bool IsFull()
 {
     return(Rooms.All(x => x.Occupied == true));
 }