Example #1
0
        public ActionResult Create()
        {
            if (Common.Props.LoginUser == null)
            {
                return(RedirectToAction("Login", "Users", new { ReturnUrl = "/SaleInvoice/Create" }));
            }
            else if (Common.Props.LoginUser != null && !(Common.Props.LoginUser.Role == Models.Users.eUserRoleID.Admin))
            {
                return(RedirectToAction("PermissionDenied", "Home"));
            }

            SaleInvoiceViewModel ViewModel = new SaleInvoiceViewModel();

            DAL.Product.ProductMasterDAL ProductDAL = new DAL.Product.ProductMasterDAL();
            ViewModel.InvoiceNo           = DALObj.GenerateNextInvoiceNo();
            ViewModel.InvoiceDate         = DateTime.Now.Date;
            ViewModel.SaleInvoiceStatusID = 1;
            ViewModel.SaleInvoiceStatus   = "PI Issued";

            ViewModel.Products = ProductDAL.GetList().Select <ProductMasterListViewModel, SaleInvoiceProducDetailViewModel>(r => new SaleInvoiceProducDetailViewModel()
            {
                ProductID      = r.ProductID,
                ScientificName = r.ScientificName,
                CommonName     = r.CommonName,
                Descr          = r.Descr,
                SizeName       = r.SizeName,
                //CultivationTypeName = r.CultivationTypeName,
                Rate = r.Rate,
                //CurrentStock = r.CurrentStock
                IsQtyReq = r.IsQtyReq
            }).ToList();

            ViewBag.NewSaleInvoiceCode = 0;
            return(View(ViewModel));
        }
Example #2
0
        public ActionResult Create(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("BadRequest", "Home"));
            }
            if (Common.Props.LoginUser == null)
            {
                return(RedirectToAction("Login", "Users", new { ReturnUrl = "/SaleInvoice/Create" }));
            }
            else if (Common.Props.LoginUser != null && !(Common.Props.LoginUser.Role == Models.Users.eUserRoleID.Admin))
            {
                return(RedirectToAction("PermissionDenied", "Home"));
            }

            SaleInvoiceDAL       SIDAL       = new SaleInvoiceDAL();
            SaleInvoiceViewModel SaleInvoice = SIDAL.FindByID(id.Value);

            if (SaleInvoice == null)
            {
                return(RedirectToAction("RecordNotFound", "Home"));
            }

            BoxListViewModel ViewModel = new BoxListViewModel()
            {
                SaleInvoiceID = SaleInvoice.SaleInvoiceID,

                BusinessName        = SaleInvoice.BusinessName,
                ContactName         = SaleInvoice.ContactName,
                Address             = SaleInvoice.Address,
                City                = SaleInvoice.City,
                Postcode            = SaleInvoice.Postcode,
                Country             = SaleInvoice.Country,
                IntPhoneNo          = SaleInvoice.IntPhoneNo,
                EMailContact        = SaleInvoice.EMailContact,
                AirportDestCity     = SaleInvoice.AirportDestCity,
                ShippingDate        = SaleInvoice.ShippingDate,
                ArrivalDate         = SaleInvoice.ArrivalDate,
                DomesticFlight      = SaleInvoice.DomesticFlight,
                InternationalFlight = SaleInvoice.InternationalFlight,

                BoxListDetails = new List <BoxListBoxDetailViewModel>()
                {
                    new BoxListBoxDetailViewModel()
                    {
                        BoxNo    = 1,
                        Products = new List <BoxListProductDetailViewModel>()
                        {
                            new BoxListProductDetailViewModel()
                            {
                            },
                        }
                    }
                }
            };

            return(View(ViewModel));
        }
Example #3
0
        public SavingResult SaveRecord(SaleInvoiceViewModel ViewModel)
        {
            SavingResult res = new SavingResult();

            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                if (ViewModel.SaleInvoiceID != 0 && CheckDuplicate(ViewModel.SaleInvoiceID, ViewModel.InvoiceNo))
                {
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    res.ValidationError = "Can not accept duplicate values. The Cultivation Type name is already exists.";
                    return(res);
                }
                else
                {
                    //var x = from p in db.tblProducts
                    //        join ps in db.tblProductSizes on p.SizeID equals ps.ProductSizeID
                    //        join vm in ViewModel.Products on p.ProductID equals vm.ProductID
                    //        where (ps.QuanReq ?? false) == true && vm.Qty == 0
                    //        select new { count = 1 };
                    if (ViewModel.Products.Count(r => r.IsQtyReq && r.Qty == 0) > 0)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Please enter quantity in per plyp and per head size products.";
                        return(res);
                    }
                }

                tblSaleInvoice SaveModel = null;
                if (ViewModel.SaleInvoiceID == 0)
                {
                    SaveModel = new tblSaleInvoice()
                    {
                        InvoiceNo = GenerateNextInvoiceNo(db),
                        rcdt      = DateTime.Now,
                        rcuid     = Common.Props.LoginUser.UserID
                    };
                    db.tblSaleInvoices.Add(SaveModel);

                    //if((ViewModel.SaleOrderID ?? 0) != 0)
                    //{
                    //    tblSaleOrder SaleOrder = db.tblSaleOrders.Find(ViewModel.SaleOrderID);
                    //    SaleOrder.tblSaleInvoice = SaveModel;
                    //    db.tblSaleOrders.Attach(SaleOrder);
                    //    db.Entry(SaleOrder).State = System.Data.Entity.EntityState.Modified;
                    //}
                }
                else
                {
                    SaveModel = db.tblSaleInvoices.FirstOrDefault(r => r.SaleInvoiceID == ViewModel.SaleInvoiceID);
                    if (SaveModel == null)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Selected user has been deleted over network. Can not find user's details. Please retry.";
                        return(res);
                    }

                    SaveModel.redt  = DateTime.Now;
                    SaveModel.reuid = Common.Props.LoginUser.UserID;

                    db.tblSaleInvoices.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;

                    foreach (tblSaleInvoiceProductDetail SIPD in SaveModel.tblSaleInvoiceProductDetails)
                    {
                        tblProduct Product = db.tblProducts.Find(SIPD.ProductID);
                        if (Product != null)
                        {
                            Product.CurrentStock += SIPD.Quan;
                            db.tblProducts.Attach(Product);
                            db.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    db.tblSaleInvoiceProductDetails.RemoveRange(db.tblSaleInvoiceProductDetails.Where(r => r.SaleInvoiceID == ViewModel.SaleInvoiceID));
                }

                //SaveModel.SaleOrderID = ViewModel.SaleOrderID;
                SaveModel.InvoiceDate         = ViewModel.InvoiceDate;
                SaveModel.InvoiceNo           = ViewModel.InvoiceNo;
                SaveModel.SaleInvoiceStatusID = ViewModel.SaleInvoiceStatusID;
                SaveModel.CustomerID          = ViewModel.CustomerID;
                SaveModel.BusinessName        = ViewModel.BusinessName;
                SaveModel.ContactName         = ViewModel.ContactName;
                SaveModel.Address             = ViewModel.Address;
                SaveModel.City                = ViewModel.City;
                SaveModel.Postcode            = ViewModel.Postcode;
                SaveModel.Country             = ViewModel.Country;
                SaveModel.IntPhoneNo          = ViewModel.IntPhoneNo;
                SaveModel.EmailContact        = ViewModel.EMailContact;
                SaveModel.AirportDestCity     = ViewModel.AirportDestCity;
                SaveModel.ShippingDate        = ViewModel.ShippingDate;
                SaveModel.ArrivalDate         = ViewModel.ArrivalDate;
                SaveModel.DomesticFlight      = ViewModel.DomesticFlight;
                SaveModel.InternationalFlight = ViewModel.InternationalFlight;
                //SaveModel.EstDelDate = ViewModel.EstDelDate;
                //SaveModel.FreightAWBNo = ViewModel.AWBNo;
                //SaveModel.FreightAWBNo = ViewModel.AWBNo ?? "";
                //SaveModel.FreightFlight1 = ViewModel.Flight1 ?? "";
                //SaveModel.FreightFlight2 = ViewModel.Flight2 ?? "";
                SaveModel.TotalQuan = (ViewModel.Products.Sum(r => (decimal?)r.Qty) ?? 0);
                SaveModel.TotalGAmt = (ViewModel.Products.Sum(r => (decimal?)r.Amt) ?? 0);

                SaveModel.EstBoxes               = ViewModel.EstBoxes;
                SaveModel.BoxCharges             = ViewModel.BoxCharges;
                SaveModel.DomesticFreightCharges = ViewModel.DomesticFreightCharges;
                SaveModel.IntFreightCharges      = ViewModel.IntFreightCharges;
                SaveModel.TTFee           = ViewModel.TTFee;
                SaveModel.TotalFreight    = ViewModel.TotalFreight;
                SaveModel.PreviousCredit  = ViewModel.PreviousCredit;
                SaveModel.TotalPayableAmt = ViewModel.TotalPayableAmt;


                foreach (SaleInvoiceProducDetailViewModel rp in ViewModel.Products.Where(r => r.Qty != 0))
                {
                    SaveModel.tblSaleInvoiceProductDetails.Add(new tblSaleInvoiceProductDetail()
                    {
                        //tblSaleInvoice = SaveModel,
                        ProductID = rp.ProductID,
                        Rate      = rp.Rate,
                        Quan      = rp.Qty,
                        Amt       = rp.Amt
                    });

                    tblProduct Product = db.tblProducts.Find(rp.ProductID);
                    if (Product != null)
                    {
                        Product.CurrentStock -= rp.Qty;
                        db.tblProducts.Attach(Product);
                        db.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.SaleInvoiceID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    ex = Common.Functions.FindFinalError(ex);

                    res.ExecutionResult = eExecutionResult.ErrorWhileExecuting;
                    res.Exception       = ex;
                }
            }
            return(res);
        }
Example #4
0
        public SaleInvoiceViewModel FindByID(int ID)
        {
            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                var SaveModel = db.tblSaleInvoices.Find(ID);
                if (SaveModel == null)
                {
                    return(null);
                }
                else
                {
                    SaleInvoiceViewModel ViewModel = new SaleInvoiceViewModel()
                    {
                        SaleInvoiceID       = SaveModel.SaleInvoiceID,
                        InvoiceDate         = SaveModel.InvoiceDate,
                        InvoiceNo           = SaveModel.InvoiceNo,
                        SaleInvoiceStatusID = SaveModel.SaleInvoiceStatusID,
                        SaleInvoiceStatus   = (SaveModel.tblSaleInvoiceStatu != null ? SaveModel.tblSaleInvoiceStatu.SaleInvoiceStatusName : "None"),

                        CustomerID          = SaveModel.CustomerID,
                        BusinessName        = SaveModel.BusinessName,
                        ContactName         = SaveModel.ContactName,
                        Address             = SaveModel.Address,
                        City                = SaveModel.City,
                        Postcode            = SaveModel.Postcode,
                        Country             = SaveModel.Country,
                        IntPhoneNo          = SaveModel.IntPhoneNo,
                        EMailContact        = SaveModel.EmailContact,
                        AirportDestCity     = SaveModel.AirportDestCity,
                        ShippingDate        = SaveModel.ShippingDate,
                        ArrivalDate         = SaveModel.ArrivalDate,
                        DomesticFlight      = SaveModel.DomesticFlight,
                        InternationalFlight = SaveModel.InternationalFlight,

                        TotalQuan              = SaveModel.TotalQuan,
                        TotalGAmt              = SaveModel.TotalGAmt,
                        EstBoxes               = SaveModel.EstBoxes,
                        BoxCharges             = SaveModel.BoxCharges,
                        DomesticFreightCharges = SaveModel.DomesticFreightCharges,
                        IntFreightCharges      = SaveModel.IntFreightCharges,
                        TTFee           = SaveModel.TTFee,
                        TotalFreight    = SaveModel.TotalFreight,
                        PreviousCredit  = SaveModel.PreviousCredit,
                        TotalPayableAmt = SaveModel.TotalPayableAmt,

                        Products = SaveModel.tblSaleInvoiceProductDetails.Select <tblSaleInvoiceProductDetail, SaleInvoiceProducDetailViewModel>(rp => new SaleInvoiceProducDetailViewModel()
                        {
                            ProductID      = rp.ProductID,
                            ScientificName = rp.tblProduct.tblProductScientificName.ProductScientificName,
                            CommonName     = rp.tblProduct.tblProductCommonName.ProductCommonName,
                            Descr          = rp.tblProduct.Descr,
                            SizeName       = rp.tblProduct.tblProductSize.ProductSizeName,
                            //CultivationTypeName = rp.tblProduct.tblProductCultivationType.ProductCultivationTypeName,
                            Rate = rp.Rate,
                            //CurrentStock = rp.tblProduct.CurrentStock,
                            Qty = rp.Quan,
                            Amt = rp.Amt
                        }).ToList()
                    };

                    return(ViewModel);
                }
            }
        }
Example #5
0
        public SaleInvoiceViewModel FindByIDWithAllProducts(int ID)
        {
            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                var SaveModel = db.tblSaleInvoices.Find(ID);
                if (SaveModel == null)
                {
                    return(null);
                }
                else
                {
                    SaleInvoiceViewModel ViewModel = new SaleInvoiceViewModel()
                    {
                        SaleInvoiceID       = SaveModel.SaleInvoiceID,
                        InvoiceDate         = SaveModel.InvoiceDate,
                        InvoiceNo           = SaveModel.InvoiceNo,
                        SaleInvoiceStatusID = SaveModel.SaleInvoiceStatusID,
                        SaleInvoiceStatus   = (SaveModel.tblSaleInvoiceStatu != null ? SaveModel.tblSaleInvoiceStatu.SaleInvoiceStatusName : "None"),

                        CustomerID          = SaveModel.CustomerID,
                        BusinessName        = SaveModel.BusinessName,
                        ContactName         = SaveModel.ContactName,
                        Address             = SaveModel.Address,
                        City                = SaveModel.City,
                        Postcode            = SaveModel.Postcode,
                        Country             = SaveModel.Country,
                        IntPhoneNo          = SaveModel.IntPhoneNo,
                        EMailContact        = SaveModel.EmailContact,
                        AirportDestCity     = SaveModel.AirportDestCity,
                        ShippingDate        = SaveModel.ShippingDate,
                        ArrivalDate         = SaveModel.ArrivalDate,
                        DomesticFlight      = SaveModel.DomesticFlight,
                        InternationalFlight = SaveModel.InternationalFlight,

                        TotalQuan              = SaveModel.TotalQuan,
                        TotalGAmt              = SaveModel.TotalGAmt,
                        EstBoxes               = SaveModel.EstBoxes,
                        BoxCharges             = SaveModel.BoxCharges,
                        DomesticFreightCharges = SaveModel.DomesticFreightCharges,
                        IntFreightCharges      = SaveModel.IntFreightCharges,
                        TTFee           = SaveModel.TTFee,
                        TotalFreight    = SaveModel.TotalFreight,
                        PreviousCredit  = SaveModel.PreviousCredit,
                        TotalPayableAmt = SaveModel.TotalPayableAmt,
                    };

                    ViewModel.Products = (from r in db.tblProducts
                                          join sn in db.tblProductScientificNames on r.ScientificNameID equals sn.ProductScientificNameID into joinsn
                                          from rsn in joinsn.DefaultIfEmpty()
                                          join cn in db.tblProductCommonNames on r.CommonNameID equals cn.ProductCommonNameID into joincn
                                          from rcn in joincn.DefaultIfEmpty()
                                          join size in db.tblProductSizes on r.SizeID equals size.ProductSizeID into joinsize
                                          from rsize in joinsize.DefaultIfEmpty()
                                          join ct in db.tblProductCultivationTypes on r.CultivationTypeID equals ct.ProductCultivationTypeID into joinct
                                          from rct in joinct.DefaultIfEmpty()
                                          join sipd in
                                          (from saleinvprod in db.tblSaleInvoiceProductDetails where saleinvprod.SaleInvoiceID == ID select saleinvprod)
                                          on r.ProductID equals sipd.ProductID into joinsipd
                                          from rsipd in joinsipd.DefaultIfEmpty()

                                          select new SaleInvoiceProducDetailViewModel()
                    {
                        ProductID = r.ProductID,
                        ScientificName = (rct != null ? rsn.ProductScientificName : ""),
                        CommonName = (rcn != null ? rcn.ProductCommonName : ""),
                        Descr = r.Descr,
                        SizeName = (rsize != null ? rsize.ProductSizeName : ""),
                        //CultivationTypeName = (rct != null ? rct.ProductCultivationTypeName : ""),
                        //CurrentStock = (rsopd != null ? SaveModel.CurrentStock : 0),
                        Rate = (rsipd != null ? rsipd.Rate : 0),
                        Qty = (rsipd != null ? rsipd.Quan : 0),
                        Amt = (rsipd != null ? rsipd.Amt : 0),
                        IsQtyReq = rsize.QuanReq ?? false
                    }).ToList();

                    return(ViewModel);
                }
            }
        }