예제 #1
0
        public ActionResult Edit(int Id)
        {
            try
            {
                ViewBag.CustomerList = new SelectList(from customers in db.Customer.ToList().Where(c => c.Status == true) select customers, "Id", "CustomerName", 0);

                var invoiceVm            = new InvoiceViewModel();
                var partForInvoiceVmList = new List <PartsForInvoiceViewModel>();
                var partForInvoiceVm     = new PartsForInvoiceViewModel();

                var invoice = db.Invoice.ToList().Find(inv => inv.Id == Id);

                if (invoice == null)
                {
                    return(RedirectToAction("Index"));
                }

                invoiceVm.Customer      = new Customer();
                invoiceVm.Customer      = db.Customer.ToList().Find(cus => cus.Id == invoice.CustomerId);
                invoiceVm.InvoiceDate   = invoice.InvoiceDate.ToString("dd/MM/yyyy");
                invoiceVm.InvoiceNumber = invoice.InvoiceNumber;
                invoiceVm.Status        = invoice.Status;

                return(View(invoiceVm));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, "Exception occurred in Invoice -> Edit[GET]: " + ex.Message);
                throw;
            }
        }
예제 #2
0
 public virtual ActionResult AddPartToInvoice()
 {
     try
     {
         ViewBag.CustomerList         = new SelectList(from customers in db.Customer.ToList().Where(c => c.Status == true) select customers, "Id", "CustomerName", 0);
         ViewBag.VendorList           = new SelectList(from vendors in db.Vendors.ToList().Where(v => v.Status == true) select vendors, "Id", "VenderName", 0);
         ViewBag.ItemTypeList         = new SelectList(from itemType in db.ItemType.ToList().Where(it => it.Status == true) select itemType, "Id", "ItemTypeName", 0);
         ViewBag.ExpirationPeriodList = new SelectList(from expirationPeriod in db.ExpirationPeriod.ToList().Where(ep => ep.Status == true) select expirationPeriod, "Id", "ExpirationPeriodName", 0);
         ViewBag.SupplierList         = new SelectList(from suppliers in db.Supplier.ToList().Where(s => s.Status == true) select suppliers, "Id", "SupplierName", 0);
         var partsForInvoice = new PartsForInvoiceViewModel();
         Session["InvoiceIdForPart"] = Session["InvoiceId"];
         return(View(partsForInvoice));
     }
     catch (Exception ex)
     {
         logger.Log(LogLevel.Error, "Exception occurred in Invoice -> AddPartToInvoice: " + ex.Message);
         throw;
     }
 }
예제 #3
0
        public ActionResult ListPartsForInvoice(int id)
        {
            try
            {
                var partsForInvoice = db.PartsForInvoice.ToList().Where(m => m.Invoice.Id == id && m.Status == true);

                var partsForInvoiceVmList = new List <PartsForInvoiceViewModel>();
                ViewBag.InvoiceId    = id;
                Session["InvoiceId"] = id;
                foreach (var item in partsForInvoice)
                {
                    var partsForInvoiceVm = new PartsForInvoiceViewModel();
                    partsForInvoiceVm.Description        = item.Description;
                    partsForInvoiceVm.EndDate            = item.EndDate.ToString("dd/MM/yyyy");
                    partsForInvoiceVm.ExpirationPeriod   = new ExpirationPeriod();
                    partsForInvoiceVm.ExpirationPeriodId = item.ExpirationPeriodId;
                    partsForInvoiceVm.ExpirationPeriod   = db.ExpirationPeriod.ToList().Find(m => m.Id == item.ExpirationPeriodId);
                    partsForInvoiceVm.InvoiceId          = id;
                    partsForInvoiceVm.ItemTypeId         = item.ItemTypeId;
                    partsForInvoiceVm.ItemType           = new ItemType();
                    partsForInvoiceVm.ItemType           = db.ItemType.ToList().Find(itm => itm.Id == item.ItemTypeId);
                    partsForInvoiceVm.PartNumber         = item.PartNumber;
                    partsForInvoiceVm.Quantity           = item.Quantity;
                    partsForInvoiceVm.SerialNumber       = item.SerialNumber;
                    partsForInvoiceVm.StartingDate       = item.StartingDate.ToString("dd/MM/yyyy");
                    partsForInvoiceVm.Status             = item.Status;
                    partsForInvoiceVm.SupplierId         = item.Supplier.Id;
                    partsForInvoiceVm.Supplier           = item.Supplier;
                    partsForInvoiceVm.VendorId           = item.VendorId;
                    partsForInvoiceVm.Vendor             = new Vendors();
                    partsForInvoiceVm.Vendor             = db.Vendors.ToList().Find(ven => ven.Id == item.VendorId);
                    partsForInvoiceVm.Id = item.Id;
                    partsForInvoiceVmList.Add(partsForInvoiceVm);
                }
                return(View(partsForInvoiceVmList));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, "Exception occurred in Invoice -> ListPartsForInvoice[GET]: " + ex.Message);
                throw;
            }
        }
예제 #4
0
        // GET: Report
        public ActionResult ExpiredParts()
        {
            var expiredParts = from prts in db.PartsForInvoice.ToList()
                               join inv in db.Invoice.ToList() on prts.Invoice_Id equals inv.Id
                               where (prts.EndDate <= DateTime.Now)
                               select prts;

            var partsForList = new List <PartsForInvoiceViewModel>();

            foreach (var item in expiredParts)
            {
                var partsForInvoice = new PartsForInvoiceViewModel();
                partsForInvoice.Invoice    = db.Invoice.Where(i => i.Id == item.Invoice_Id).FirstOrDefault();
                partsForInvoice.PartNumber = item.PartNumber;
                partsForInvoice.EndDate    = item.EndDate.ToString("dd/MM/yyyy");
                partsForList.Add(partsForInvoice);
            }

            return(View(partsForList));
        }
예제 #5
0
        public ActionResult EditPart(string id)
        {
            try
            {
                ViewBag.CustomerList         = new SelectList(from customers in db.Customer.ToList().Where(c => c.Status == true) select customers, "Id", "CustomerName", 0);
                ViewBag.VendorList           = new SelectList(from vendors in db.Vendors.ToList().Where(v => v.Status == true) select vendors, "Id", "VenderName", 0);
                ViewBag.ItemTypeList         = new SelectList(from itemType in db.ItemType.ToList().Where(it => it.Status == true) select itemType, "Id", "ItemTypeName", 0);
                ViewBag.ExpirationPeriodList = new SelectList(from expirationPeriod in db.ExpirationPeriod.ToList().Where(ep => ep.Status == true) select expirationPeriod, "Id", "ExpirationPeriodName", 0);
                ViewBag.SupplierList         = new SelectList(from suppliers in db.Supplier.ToList().Where(s => s.Status == true) select suppliers, "Id", "SupplierName", 0);

                var partsForInvoice   = db.PartsForInvoice.ToList().Where(m => m.Id == id).FirstOrDefault();
                var partsForInvoiceVm = new PartsForInvoiceViewModel();

                partsForInvoiceVm.Description        = partsForInvoice.Description;
                partsForInvoiceVm.EndDate            = partsForInvoice.EndDate.ToString("dd/MM/yyyy");
                partsForInvoiceVm.ExpirationPeriod   = new ExpirationPeriod();
                partsForInvoiceVm.ExpirationPeriodId = partsForInvoice.ExpirationPeriodId;
                partsForInvoiceVm.ExpirationPeriod   = db.ExpirationPeriod.ToList().Find(m => m.Id == partsForInvoice.ExpirationPeriodId);
                partsForInvoiceVm.InvoiceId          = partsForInvoice.Invoice.Id;
                partsForInvoiceVm.ItemTypeId         = partsForInvoice.ItemTypeId;
                partsForInvoiceVm.ItemType           = new ItemType();
                partsForInvoiceVm.ItemType           = db.ItemType.ToList().Find(itm => itm.Id == partsForInvoice.ItemTypeId);
                partsForInvoiceVm.PartNumber         = partsForInvoice.PartNumber;
                partsForInvoiceVm.Quantity           = partsForInvoice.Quantity;
                partsForInvoiceVm.SerialNumber       = partsForInvoice.SerialNumber;
                partsForInvoiceVm.StartingDate       = partsForInvoice.StartingDate.ToString("dd/MM/yyyy");
                partsForInvoiceVm.Status             = partsForInvoice.Status;
                partsForInvoiceVm.SupplierId         = partsForInvoice.Supplier.Id;
                partsForInvoiceVm.Supplier           = partsForInvoice.Supplier;
                partsForInvoiceVm.VendorId           = partsForInvoice.VendorId;
                partsForInvoiceVm.Vendor             = new Vendors();
                partsForInvoiceVm.Vendor             = db.Vendors.ToList().Find(ven => ven.Id == partsForInvoice.VendorId);
                partsForInvoiceVm.Id = partsForInvoice.Id;
                return(View(partsForInvoiceVm));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, "Exception occurred in Invoice -> EditPart[GET]: " + ex.Message);
                throw;
            }
        }
예제 #6
0
        public virtual ActionResult AddPartToInvoice(PartsForInvoiceViewModel partsForInvoiceVm)
        {
            try
            {
                var invoiceId       = Int32.Parse(Session["InvoiceIdForPart"].ToString());
                var invoiceToUpdate = db.Invoice.ToList().Find(inv => inv.Id == invoiceId);
                var partlist        = new List <PartsForInvoice>();
                var part            = new PartsForInvoice();
                part.Description        = partsForInvoiceVm.Description;
                part.EndDate            = DateTime.ParseExact(partsForInvoiceVm.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                part.ExpirationPeriodId = partsForInvoiceVm.ExpirationPeriod.Id;
                part.ItemTypeId         = partsForInvoiceVm.ItemType.Id;
                part.PartNumber         = partsForInvoiceVm.PartNumber;
                part.Quantity           = partsForInvoiceVm.Quantity;
                part.SerialNumber       = partsForInvoiceVm.SerialNumber;
                part.StartingDate       = DateTime.ParseExact(partsForInvoiceVm.StartingDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                part.Status             = partsForInvoiceVm.Status;
                part.SupplierId         = partsForInvoiceVm.Supplier.Id;
                part.UserName           = WebSecurity.CurrentUserName;
                part.VendorId           = partsForInvoiceVm.Vendor.Id;
                part.Id         = Guid.NewGuid().ToString();
                part.Invoice    = new Invoice();
                part.Invoice    = invoiceToUpdate;
                part.Invoice_Id = Int32.Parse(Session["InvoiceIdForPart"].ToString());
                //partlist.Add(part);
                //invoiceToUpdate.PartsForInvoice.Add(part);


                TryUpdateModel(part, "test", new string[] { "Invoice_Id,Description,EndDate,ExpirationPeriodId,ItemTypeId,PartNumber,Quantity,SerialNumber,StartingDate,Status,SupplierId,UserName,VendorId" }, new string[] { "Invoice" });
                db.PartsForInvoice.Add(part);
                db.Entry(invoiceToUpdate).State = System.Data.Entity.EntityState.Added;
                db.SaveChanges();
                return(RedirectToAction("ListPartsForInvoice", new { Id = partsForInvoiceVm.InvoiceId }));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, "Exception occurred in Invoice -> AddPartToInvoice[POST]: " + ex.Message);
                throw;
            }
        }
예제 #7
0
        public ActionResult EditPart(PartsForInvoiceViewModel partsForInvoiceVm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    TempData["Message"]     = "Failure in invoice edit action. Check for following issues." + string.Join(" , ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                    TempData["MessageType"] = "alert-danger";
                    return(RedirectToAction("Index"));
                }

                var part = new PartsForInvoice();
                part.Description        = partsForInvoiceVm.Description;
                part.EndDate            = DateTime.ParseExact(partsForInvoiceVm.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                part.ExpirationPeriodId = partsForInvoiceVm.ExpirationPeriod.Id;
                part.ItemTypeId         = partsForInvoiceVm.ItemType.Id;
                part.PartNumber         = partsForInvoiceVm.PartNumber;
                part.Quantity           = partsForInvoiceVm.Quantity;
                part.SerialNumber       = partsForInvoiceVm.SerialNumber;
                part.StartingDate       = DateTime.ParseExact(partsForInvoiceVm.StartingDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                part.Status             = partsForInvoiceVm.Status;
                part.SupplierId         = partsForInvoiceVm.Supplier.Id;
                part.UserName           = WebSecurity.CurrentUserName;
                part.VendorId           = partsForInvoiceVm.Vendor.Id;
                part.Id         = partsForInvoiceVm.Id;
                part.Invoice_Id = partsForInvoiceVm.InvoiceId;
                TryUpdateModel(part, "Description,EndDate,ExpirationPeriodId,ItemTypeId,PartNumber,Quantity,SerialNumber,StartingDate,Status,SupplierId,UserName,VendorId");
                db.PartsForInvoice.Add(part);
                db.Entry(part).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                TempData["Message"]     = "Parts details are updated successfully.";
                TempData["MessageType"] = "alert-success";
                return(RedirectToAction("ListPartsForInvoice", new { Id = partsForInvoiceVm.InvoiceId }));
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, "Exception occurred in Invoice -> EditPart[HttpPost]: " + ex.Message);
                throw;
            }
        }