Exemplo n.º 1
0
        public JsonResult UpdateTaxPrice(string userId, decimal price, int year)
        {
            using (var db = new WorktripEntities())
            {
                var curUserId = User.Identity.GetUserId();

                var link = db.UserToPreparers.FirstOrDefault(up => up.UserId == userId && up.Year == year);

                if (link == null)
                {
                    link = new UserToPreparer
                    {
                        UserId   = userId,
                        Year     = year,
                        StatusId = 1
                    };

                    db.UserToPreparers.Add(link);
                }

                link.Fee = price;

                db.SaveChanges();
                return(Json(new { status = 0 }));
            }

            return(Json(new { status = -1 }));
        }
Exemplo n.º 2
0
        public JsonResult SetInternationalLayovers(string userId, int year, bool isChecked)
        {
            using (var db = new WorktripEntities())
            {
                var miscTaxInfo = db.UserMiscTaxInfoes.FirstOrDefault(umt => umt.UserId == userId && umt.TaxYear == year);

                //If no record exists, create new in the db
                if (miscTaxInfo == null)
                {
                    miscTaxInfo = new UserMiscTaxInfo
                    {
                        UserId  = userId,
                        TaxYear = year,
                        InternationalLayovers = isChecked
                    };

                    db.UserMiscTaxInfoes.Add(miscTaxInfo);
                }
                else
                {
                    miscTaxInfo.InternationalLayovers = isChecked;
                }

                db.SaveChanges();
                return(Json(new { status = 0 }));
            }

            return(Json(new { status = -1 }));
        }
Exemplo n.º 3
0
        public JsonResult CalculatePerDiem(int taxYear, List <Layover> layovers, string userId)
        {
            var curUserId = userId == null?User.Identity.GetUserId() : userId;

            double total = 0;

            foreach (var layover in layovers)
            {
                if (WorktripInit.perDiemRates.ContainsKey(layover.AirportCode))
                {
                    total += WorktripInit.perDiemRates[layover.AirportCode] * layover.Days;
                }
            }

            using (var db = new WorktripEntities())
            {
                var userMiscInfo = UserInfoViewModel.GetOrCreateUserInfo(db, curUserId, taxYear);

                userMiscInfo.LayoversPerDiem = total;

                db.SaveChanges();
            }

            return(Json(new { status = 0, total }));
        }
Exemplo n.º 4
0
        public JsonResult UpdateTaxReturnAmount(string userId, decimal amount, int year)
        {
            using (var db = new WorktripEntities())
            {
                var info = UserInfoViewModel.GetOrCreateUserInfo(db, userId, year);

                info.TaxReturn = amount;

                db.SaveChanges();
                return(Json(new { status = 0 }));
            }

            return(Json(new { status = -1 }));
        }
Exemplo n.º 5
0
        public JsonResult UpdateTaxNotes(string userId, string notes, int year)
        {
            using (var db = new WorktripEntities())
            {
                var info = UserInfoViewModel.GetOrCreateUserInfo(db, userId, year);

                info.PreparerNotes = notes;

                db.SaveChanges();
                return(Json(new { status = 0 }));
            }

            return(Json(new { status = -1 }));
        }
Exemplo n.º 6
0
        public JsonResult SetFirstModified(string userId, int year)
        {
            using (var db = new WorktripEntities())
            {
                var user = db.UserToPreparers.FirstOrDefault(up => up.UserId == userId && up.Year == year);

                if (user != null && user.FirstModified == null)
                {
                    user.FirstModified = DateTime.Now;

                    db.SaveChanges();
                }
                return(Json(new { status = 0 }));
            }
        }
Exemplo n.º 7
0
        public JsonResult UpdateTaxStatus(string userId, string status, int year)
        {
            using (var db = new WorktripEntities())
            {
                var curUserId = User.Identity.GetUserId();

                var link = db.UserToPreparers.FirstOrDefault(up => up.UserId == userId && up.Year == year);

                var statusObj = db.Status.FirstOrDefault(s => s.Name == status);

                if (link != null && statusObj != null)
                {
                    link.StatusId = statusObj.Id;

                    db.SaveChanges();
                    return(Json(new { status = 0 }));
                }
            }

            return(Json(new { status = -1 }));
        }
Exemplo n.º 8
0
        public JsonResult UploadUserTaxReturn(int taxYear, string subFolder, string userId)
        {
            var curUserId = userId == null?User.Identity.GetUserId() : userId;

            bool   uploadedSuccessfully = false;
            string uploadedURI          = "";

            using (var db = new WorktripEntities())
            {
                try
                {
                    var user = db.Users.FirstOrDefault(u => u.Id == curUserId);

                    HttpPostedFileBase uploadedFile = Request.Files.Get(0);

                    var compressedStream = uploadedFile.InputStream;

                    if (uploadedFile.ContentType.StartsWith("image/"))
                    {
                        compressedStream = ResizePictureForBandwidth(uploadedFile);
                    }

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                        CloudConfigurationManager.GetSetting("StorageConnectionString"));

                    CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

                    CloudFileShare share = fileClient.GetShareReference("worktripdocs");

                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                    CloudFileDirectory userDir = rootDir.GetDirectoryReference(user.FirstName + " " + user.LastName + " " + user.PhoneNumber);

                    userDir.CreateIfNotExists();

                    if (!string.IsNullOrEmpty(subFolder))
                    {
                        userDir = userDir.GetDirectoryReference(subFolder);

                        userDir.CreateIfNotExists();
                    }

                    var newFileName   = uploadedFile.FileName;
                    var fileExtension = Path.GetExtension(newFileName);

                    CloudFile file = userDir.GetFileReference(newFileName);

                    int fileDuplicateCount = 1;

                    while (file.Exists())
                    {
                        //generate a file name that doesn't exist yet
                        newFileName = Path.GetFileNameWithoutExtension(newFileName) + "(" + (fileDuplicateCount++) + ")" + fileExtension;

                        file = userDir.GetFileReference(newFileName);;
                    }

                    file.Properties.ContentType = uploadedFile.ContentType;

                    file.UploadFromStream(compressedStream);

                    uploadedURI = file.Uri.ToString();

                    UserTaxReturn newReturn = new UserTaxReturn()
                    {
                        UserId = curUserId,
                        Date   = DateTime.UtcNow,
                        Path   = uploadedURI,
                        Year   = taxYear
                    };

                    db.UserTaxReturns.Add(newReturn);

                    db.SaveChanges();

                    uploadedSuccessfully = true;

                    UserInfoViewModel.UpdateUserActionsLog(curUserId, "uploaded " + taxYear + " " + (fileExtension == ".pdf" ? "tax return" : "tax form(s)"));
                }
                catch (Exception e)
                {
                    //Do some error logging here..
                    uploadedSuccessfully = false;
                }
            }

            if (uploadedSuccessfully)
            {
                return(Json(new { status = 0 }));
            }
            else
            {
                return(Json(new { status = -1, message = "Error in saving file" }));
            }
        }
Exemplo n.º 9
0
        public void PopulatePerDiem()
        {
            Excel.Application xlApp       = new Excel.Application();
            Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(@"C:\Users\David\Desktop\excels\Airport IRS Database2.xlsx");
            Excel._Worksheet  xlWorksheet = xlWorkbook.Sheets["Merge"];
            Excel.Range       xlRange     = xlWorksheet.UsedRange;

            Dictionary <string, PerDiem> perDiems = new Dictionary <string, PerDiem>();

            for (int i = 2; i < 1450; i++)
            {
                //for (int j = 1; j <= 12; j++)
                //{
                //    //new line
                //    if (j == 1)
                //        Console.Write("\r\n");

                //    //write the value to the console
                //    if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null)
                //    {
                //        var a = xlRange.Cells[i, j].Value2.ToString();

                //        Console.Write(a + "\t");
                //    }

                //    //add useful things here!
                //}

                if (xlWorksheet.Cells[i, "K"] == null || xlWorksheet.Cells[i, "K"].Value2 == null)
                {
                    continue;
                }


                string Country = xlWorksheet.Cells[i, "E"].Value2 != null ? xlWorksheet.Cells[i, "E"].Value2.ToString() : "US";
                string State   = xlWorksheet.Cells[i, "D"].Value2 != null ? xlWorksheet.Cells[i, "D"].Value2.ToString() : "N/A";
                string City    = xlWorksheet.Cells[i, "C"].Value2 != null ? xlWorksheet.Cells[i, "C"].Value2.ToString() : "N/A";
                string Airport = xlWorksheet.Cells[i, "G"].Value2 != null ? xlWorksheet.Cells[i, "G"].Value2.ToString() : "N/A";
                int    Rate    = 0;

                bool parsed = int.TryParse(xlWorksheet.Cells[i, "K"].Value2.ToString(), out Rate);

                if (!perDiems.ContainsKey(Airport))
                {
                    var perDiem = new PerDiem()
                    {
                        Country = Country,
                        State   = State,
                        City    = City,
                        Airport = Airport,
                        Rate    = Rate
                    };

                    perDiems.Add(Airport, perDiem);
                }
            }

            xlWorkbook  = xlApp.Workbooks.Open(@"C:\Users\David\Desktop\excels\FY2017-PerDiemRatesMasterFile2.xls");
            xlWorksheet = xlWorkbook.Sheets["FY2017"];

            for (int i = 4; i < 348; i++)
            {
                string state = xlWorksheet.Cells[i, "A"].Value2.ToString().ToLower();
                string city  = xlWorksheet.Cells[i, "B"].Value2.ToString().ToLower();
                int    rate  = 0;

                bool parsed = int.TryParse(xlWorksheet.Cells[i, "G"].Value2.ToString(), out rate);

                foreach (var kv in perDiems)
                {
                    if (kv.Value.State.ToLower() == state && kv.Value.City.ToLower() == city)
                    {
                        kv.Value.Rate = rate;
                    }
                }
            }

            using (var db = new WorktripEntities())
            {
                foreach (var kv in perDiems)
                {
                    PerDiemRate pdr = new PerDiemRate()
                    {
                        AirportCode = kv.Key,
                        Rate        = kv.Value.Rate
                    };

                    db.PerDiemRates.Add(pdr);
                }

                db.SaveChanges();
            }
        }