Esempio n. 1
0
        public void Load(Stream stream)
        {
            using (BinaryReader bw = new BinaryReader(stream)) {
                int count = bw.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    Employee employee = new Employee();
                    employee.Alias      = bw.ReadString();
                    employee.EmployeeId = bw.ReadInt32();
                    employee.Manager    = bw.ReadString();
                    employee.Name       = bw.ReadString();
                    Employees.Add(employee);
                }

                count = bw.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    ExpenseReport er = new ExpenseReport();
                    er.Amount     = bw.ReadInt64();
                    er.Approver   = bw.ReadString();
                    er.CostCenter = bw.ReadInt32();
                    long tickCount = bw.ReadInt64();
                    if (tickCount != 0)
                    {
                        er.DateResolved = new DateTime(tickCount);
                    }
                    tickCount = bw.ReadInt64();
                    if (tickCount != 0)
                    {
                        er.DateSaved = new DateTime(tickCount);
                    }
                    tickCount = bw.ReadInt64();
                    if (tickCount != 0)
                    {
                        er.DateSubmitted = new DateTime(tickCount);
                    }
                    er.EmployeeId       = bw.ReadInt32();
                    er.ExpenseReportId  = bw.ReadInt32();
                    er.Notes            = bw.ReadString();
                    er.OwedToCreditCard = bw.ReadInt64();
                    er.OwedToEmployee   = bw.ReadInt64();
                    er.Purpose          = bw.ReadString();
                    er.Status           = (ExpenseReportStatus)bw.ReadInt32();
                    ExpenseReports.Add(er);
                }
                count = bw.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    Charge charge = new Charge();
                    charge.AccountNumber = bw.ReadInt32();
                    charge.BilledAmount  = bw.ReadInt64();
                    charge.Category      = (CategoryType)bw.ReadInt32();
                    charge.ChargeId      = bw.ReadInt32();
                    charge.Description   = bw.ReadString();
                    charge.EmployeeId    = bw.ReadInt32();
                    charge.ExpenseDate   = new DateTime(bw.ReadInt64());
                    int value = bw.ReadInt32();
                    if (value != 0)
                    {
                        charge.ExpenseReportId = value;
                    }
                    charge.ExpenseType       = (ChargeType)bw.ReadInt32();
                    charge.Location          = bw.ReadString();
                    charge.Merchant          = bw.ReadString();
                    charge.Notes             = bw.ReadString();
                    charge.ReceiptRequired   = bw.ReadBoolean();
                    charge.TransactionAmount = bw.ReadInt64();
                    Charges.Add(charge);
                }
            }
        }
Esempio n. 2
0
        void AddCharges(int month, ExpenseReport expenseReport, Employee employee)
        {
            int amount1 = month == 1 ? 0 : month == 2 ? 40 : month == 3 ? 20 : month == 4 ? 40 : 80;
            int amount2 = month == 1 ? 10 : month == 2 ? 120 : month == 3 ? 40 : month == 4 ? 80 : 30;
            int amount3 = month == 1 ? 20 : month == 2 ? 40 : month == 3 ? 50 : month == 4 ? 22 : 90;
            int amount4 = month == 1 ? 120 : month == 2 ? 30 : month == 3 ? 40 : month == 4 ? 28 : 50;
            int amount5 = month == 1 ? 80 : month == 2 ? 20 : month == 3 ? 30 : month == 4 ? 14 : 13;
            int amount6 = month == 1 ? 40 : month == 2 ? 120 : month == 3 ? 200 : month == 4 ? 56 : 88;

            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount1 + random.Next(10),
                Category          = (int)CategoryType.AirFare,
                Description       = "Airfare to San Francisco",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-60),
                ExpenseType       = ChargeType.Business,
                Location          = "Chicago, IL",
                Merchant          = "Blue Yonder Airlines",
                Notes             = string.Empty,
                ReceiptRequired   = true,
                TransactionAmount = 350M,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount2 + random.Next(10),
                Category          = CategoryType.OtherTravelAndLodging,
                Description       = "Cab from airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount3 + random.Next(10),
                Category          = CategoryType.Mileage,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount4 + random.Next(10),
                Category          = CategoryType.Hotel,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount5 + random.Next(10),
                Category          = CategoryType.CarRental,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount5 + random.Next(10),
                Category          = CategoryType.ConferenceSeminar,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount6 + random.Next(10),
                Category          = CategoryType.Entertainment,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
            Charges.Add(new Charge()
            {
                ChargeId          = Charges.Count + 1,
                AccountNumber     = 723000,
                BilledAmount      = amount6 + random.Next(10),
                Category          = CategoryType.Gifts,
                Description       = "Cab to airport",
                EmployeeId        = employee.EmployeeId,
                ExpenseReportId   = expenseReport.ExpenseReportId,
                ExpenseDate       = DateTime.Today.AddDays(-45),
                ExpenseType       = ChargeType.Business,
                Location          = "San Francisco, CA",
                Merchant          = "Contoso Taxi",
                Notes             = string.Empty,
                ReceiptRequired   = false,
                TransactionAmount = 50,
            });
        }
Esempio n. 3
0
        void AddApprovedReports(string managerAlias, Employee employee)
        {
            DateTime today             = DateTime.Today;
            DateTime currentMonthStart = new DateTime(today.Year, today.Month, 1);

            for (DateTime monthStart = currentMonthStart.AddMonths(-2); monthStart > today.AddYears(-3); monthStart = monthStart.AddMonths(-1))
            {
                int           daysInMonth   = (int)(monthStart.AddMonths(1) - monthStart).TotalDays;
                int           b1            = 250 + random.Next(100);
                int           b2            = 100 + random.Next(20);
                int           b3            = 100 + random.Next(10);
                int           b4            = 310 + random.Next(90);
                ExpenseReport expenseReport = new ExpenseReport()
                {
                    ExpenseReportId  = ExpenseReports.Count + 1,
                    EmployeeId       = employee.EmployeeId,
                    Amount           = b1 + b2 + b3 + b4,
                    Approver         = managerAlias,
                    CostCenter       = 50992,
                    DateSubmitted    = monthStart.AddDays((today.Day - 5 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    DateResolved     = monthStart.AddDays((today.Day + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    Notes            = "Visit to Tailspin Toys",
                    OwedToCreditCard = 850M,
                    OwedToEmployee   = 0M,
                    Purpose          = "Customer visit",
                    Status           = ExpenseReportStatus.Approved
                };
                ExpenseReports.Add(expenseReport);
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 723000,
                    BilledAmount      = b1,
                    Category          = (int)CategoryType.AirFare,
                    Description       = "Airfare to Chicago",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 15 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Business,
                    Location          = "Chicago, IL",
                    Merchant          = "Blue Yonder Airlines",
                    Notes             = string.Empty,
                    ReceiptRequired   = true,
                    TransactionAmount = 350M,
                });
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 723000,
                    BilledAmount      = b2,
                    Category          = CategoryType.OtherTravelAndLodging,
                    Description       = "Cab from airport",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 5 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Business,
                    Location          = "Chicago, IL",
                    Merchant          = "Contoso Taxi",
                    Notes             = string.Empty,
                    ReceiptRequired   = false,
                    TransactionAmount = 50M,
                });
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 723000,
                    BilledAmount      = b3,
                    Category          = CategoryType.TEMeals,
                    Description       = "Cab to airport",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 3 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Business,
                    Location          = "Chicago, IL",
                    Merchant          = "Contoso Taxi",
                    Notes             = string.Empty,
                    ReceiptRequired   = false,
                    TransactionAmount = 50M,
                });
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 723000,
                    BilledAmount      = b4,
                    Category          = CategoryType.Hotel,
                    Description       = "2 nights hotel",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 3 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Business,
                    Location          = "Chicago, IL",
                    Merchant          = "Northwind Inn",
                    Notes             = string.Empty,
                    ReceiptRequired   = true,
                    TransactionAmount = 400M,
                });
                int c1 = 330 + random.Next(120);
                int c2 = 120 + random.Next(10);
                expenseReport = new ExpenseReport()
                {
                    ExpenseReportId  = ExpenseReports.Count + 1,
                    Amount           = c1,
                    Approver         = managerAlias,
                    CostCenter       = 50992,
                    DateSubmitted    = monthStart.AddDays((today.Day - 5 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    DateResolved     = monthStart.AddDays((today.Day + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    Notes            = "",
                    OwedToCreditCard = 0,
                    OwedToEmployee   = 50M,
                    Purpose          = "Last month's cell phone",
                    Status           = ExpenseReportStatus.Approved,
                };
                ExpenseReports.Add(expenseReport);
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 742000,
                    BilledAmount      = b3,
                    Category          = CategoryType.Entertainment,
                    Description       = "Cell phone bill",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 10 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Personal,
                    Location          = "Seattle, WA",
                    Merchant          = "The Phone Company",
                    Notes             = string.Empty,
                    ReceiptRequired   = true,
                    TransactionAmount = 50M,
                });
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 742000,
                    BilledAmount      = c2,
                    Category          = CategoryType.Mileage,
                    Description       = "Cell phone bill",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 10 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Personal,
                    Location          = "Seattle, WA",
                    Merchant          = "The Phone Company",
                    Notes             = string.Empty,
                    ReceiptRequired   = true,
                    TransactionAmount = 50M,
                });
                Charges.Add(new Charge()
                {
                    ChargeId          = Charges.Count + 1,
                    AccountNumber     = 742000,
                    BilledAmount      = b4,
                    Category          = CategoryType.Hotel,
                    Description       = "Cell phone bill",
                    EmployeeId        = employee.EmployeeId,
                    ExpenseReportId   = expenseReport.ExpenseReportId,
                    ExpenseDate       = monthStart.AddDays((today.Day - 10 + daysInMonth - 1) % (daysInMonth - 1) + 1),
                    ExpenseType       = ChargeType.Personal,
                    Location          = "Seattle, WA",
                    Merchant          = "The Phone Company",
                    Notes             = string.Empty,
                    ReceiptRequired   = true,
                    TransactionAmount = 50M,
                });
            }
        }
        public async Task SaveAsync()
        {
            // TODO: We should change how this works. Right now it's just ported to use the new
            // API, although the workflow needs to be fixed.

            await this.ViewService.ExecuteBusyActionAsync(
                async () =>
                {
                    ExpenseReport expenseReport = new ExpenseReport();
                    expenseReport.Amount = this.Amount;
                    expenseReport.Approver = this.Approver;
                    expenseReport.CostCenter = this.CostCenter;
                    expenseReport.DateResolved = this.DateResolved;
                    expenseReport.DateSaved = DateTime.Now;
                    expenseReport.DateSubmitted = this.DateSubmitted;
                    expenseReport.EmployeeId = this.EmployeeId;
                    expenseReport.ExpenseReportId = this.ExpenseReportId;
                    expenseReport.Notes = this.Notes;
                    expenseReport.OwedToCreditCard = this.OwedToCreditCard;
                    expenseReport.OwedToEmployee = this.OwedToEmployee;
                    expenseReport.Purpose = this.Purpose;
                    expenseReport.Status = this.Status;

                    int reportId = await this._repository.SaveExpenseReportAsync(expenseReport);
                    await this.LoadAsync(reportId);
                });
        }
        private void Load(ExpenseReport expenseReport)
        {
            this.Amount = expenseReport.Amount;
            this.Approver = expenseReport.Approver;
            this.CostCenter = expenseReport.CostCenter;
            this.DateResolved = expenseReport.DateResolved;
            this.DateSaved = expenseReport.DateSaved;
            this.DateSubmitted = expenseReport.DateSubmitted;
            this.EmployeeId = expenseReport.EmployeeId;
            this.ExpenseReportId = expenseReport.ExpenseReportId;
            this.Notes = expenseReport.Notes;
            this.OwedToCreditCard = expenseReport.OwedToCreditCard;
            this.OwedToEmployee = expenseReport.OwedToEmployee;
            this.Purpose = expenseReport.Purpose;
            this.Status = expenseReport.Status;

            switch (this.Status)
            {
                case ExpenseReportStatus.Saved: this.DisplayDate = this.DateSaved.GetValueOrDefault(); break;
                case ExpenseReportStatus.Pending: this.DisplayDate = this.DateSubmitted.GetValueOrDefault(); break;
                case ExpenseReportStatus.Approved: this.DisplayDate = this.DateResolved.GetValueOrDefault(); break;
                case ExpenseReportStatus.Canceled: this.DisplayDate = this.DateResolved.GetValueOrDefault(); break;
                case ExpenseReportStatus.Rejected: this.DisplayDate = this.DateResolved.GetValueOrDefault(); break;
            }
        }
 internal ExpenseReportViewModel(ExpenseReport expenseReport)
     : this()
 {
     this.Load(expenseReport);
 }