Beispiel #1
0
        protected void btnReport_Click(object sender, EventArgs e)
        {
            DateTime period               = pp1.SelectedPeriod;
            int      totalMonths          = Convert.ToInt32(txtNumMonths.Text);
            int      currentBillingTypeId = BillingTypes.Other;

            decimal totalRoomSum       = 0;
            decimal totalRoomPerUseSum = 0;
            decimal totalToolSum       = 0;

            decimal finalRoomSum       = 0;
            decimal finalToolSum       = 0;
            decimal finalFutureRoomSum = 0;
            decimal finalFutureToolSum = 0;

            //2008-11-04 For non Academics, we need to reduce the hour rate from current $77 to about $15 dollar, so the mutiplier ratio here is 15/77 = 0.19
            decimal nonAcFutureRoomMultiplier = 0.19M; //WTF IS THIS????

            DataTable dtAllUsers = new DataTable();

            dtAllUsers.Columns.Add("Name", typeof(string));
            dtAllUsers.Columns.Add("CurrentPayment", typeof(double));
            dtAllUsers.Columns.Add("FuturePayment", typeof(double));

            //we need a table that contains all the accounts associated with this manager
            //people like Ning belongs to more than 1 org, so we have to filter out the accounts that are not in this particular org
            DataTable dtAccount = ClientDA.GetAllAccountsByClientOrgID(Convert.ToInt32(ddlManager.SelectedValue));

            int[] billingTypesChargedByToolUsage          = { BillingTypes.ExtAc_Hour, BillingTypes.Int_Hour, BillingTypes.NonAc_Hour, BillingTypes.ExtAc_Tools, BillingTypes.Int_Tools, BillingTypes.NonAc_Tools };
            int[] specialBillingTypesForSomeUnknownReason = { BillingTypes.NonAc, BillingTypes.NonAc_Hour, BillingTypes.NonAc_Tools };

            if (ddlUser.SelectedValue == "0")
            {
                //We have to caluclate ALL users belong to this manager
                foreach (ListItem userItem in ddlUser.Items)
                {
                    if (userItem.Value != "0") //we must exclude the "All" listItem
                    {
                        DataRow  ndr = dtAllUsers.NewRow();
                        DateTime p   = period;
                        for (int i = 1; i <= totalMonths; i++)
                        {
                            totalRoomSum       = 0;
                            totalRoomPerUseSum = 0;
                            totalToolSum       = 0;

                            currentBillingTypeId = CalculateMonthlyFeePerUser(Convert.ToInt32(userItem.Value), p, currentBillingTypeId, dtAccount, ref totalRoomSum, ref totalRoomPerUseSum, ref totalToolSum);

                            finalRoomSum += totalRoomSum;

                            //addl tool cost for those users who are charged by tools usage now (hours and tools)
                            if (billingTypesChargedByToolUsage.Contains(currentBillingTypeId))
                            {
                                finalToolSum += totalToolSum;
                            }

                            if (specialBillingTypesForSomeUnknownReason.Contains(currentBillingTypeId))
                            {
                                //2008-11-04 For non Academics, we need to reduce the hour rate
                                totalRoomPerUseSum *= nonAcFutureRoomMultiplier;
                            }

                            finalFutureRoomSum += totalRoomPerUseSum;
                            finalFutureToolSum += totalToolSum;

                            ndr["Name"] = userItem.Text;

                            //for per usage types (such as xxx_hour or xxx_tool, we need to include the tool fee for current payment
                            int[] billingTypesForPerUsage = { BillingTypes.ExtAc_Hour, BillingTypes.Int_Hour, BillingTypes.NonAc_Hour, BillingTypes.ExtAc_Tools, BillingTypes.Int_Tools, BillingTypes.NonAc_Tools };
                            if (billingTypesForPerUsage.Contains(currentBillingTypeId))
                            {
                                ndr["CurrentPayment"] = Math.Round(totalRoomSum, 2) + Math.Round(totalToolSum, 2);
                            }
                            else
                            {
                                //the users are montly flat room billing type
                                ndr["CurrentPayment"] = Math.Round(totalRoomSum, 2);
                            }

                            ndr["FuturePayment"] = Math.Round((totalRoomPerUseSum + totalToolSum), 2);

                            //If there is no usage for this account, then don't show it
                            if (ndr.Field <double>("CurrentPayment") != 0 && ndr.Field <double>("FuturePayment") != 0)
                            {
                                dtAllUsers.Rows.Add(ndr);
                            }

                            //remember to add one month at the very end
                            p = p.AddMonths(1);
                        }
                    }
                }
            }
            else
            {
                DateTime p = period;
                for (int i = 1; i <= totalMonths; i++)
                {
                    totalRoomSum       = 0;
                    totalRoomPerUseSum = 0;
                    totalToolSum       = 0;

                    currentBillingTypeId = CalculateMonthlyFeePerUser(Convert.ToInt32(ddlUser.SelectedValue), p, currentBillingTypeId, dtAccount, ref totalRoomSum, ref totalRoomPerUseSum, ref totalToolSum);

                    finalRoomSum += totalRoomSum;

                    //addl tool cost for those users who are charged by tools usage now (hours and tools)
                    if (billingTypesChargedByToolUsage.Contains(currentBillingTypeId))
                    {
                        finalToolSum += totalToolSum;
                    }

                    if (specialBillingTypesForSomeUnknownReason.Contains(currentBillingTypeId))
                    {
                        //2008-11-04 For non Academics, we need to reduce the hour rate
                        totalRoomPerUseSum *= nonAcFutureRoomMultiplier;
                    }

                    finalFutureRoomSum += totalRoomPerUseSum;
                    finalFutureToolSum += totalToolSum;

                    //remember to add one month at the very end
                    p = p.AddMonths(1);
                }
            }

            lblRoomCost.Text        = string.Format("Current Room Cost (plus entry fee): {0:$#,##0.00}", finalRoomSum);
            lblToolCost.Text        = string.Format("Current Tool Cost (if applies): {0:$#,##0.00}", finalToolSum);
            lblCurrentRoomCost.Text = string.Format("Current payment: {0:$#,##0.00}", finalRoomSum + finalToolSum);

            lblPerUseRoomCost.Text = string.Format("Future Per Usage Room Cost: {0:$#,##0.00}", finalFutureRoomSum);
            lblPerUseToolCost.Text = string.Format("Future Per Usage Tool Cost: {0:$#,##0.00}", finalFutureToolSum);

            lblRealCost.Text = string.Format("Real Cost (Room + Tool): {0:$#,##0.00}", finalFutureRoomSum + finalFutureToolSum);

            gvAllUsers.DataSource = dtAllUsers;
            gvAllUsers.DataBind();
        }
 public static DataTable GetAllAccountsbyManager(int ManagerOrgID)
 {
     return(ClientDA.GetAllAccountsByClientOrgID(ManagerOrgID));
 }