コード例 #1
0
        public ActionResult AddCustomerCredit(AddCreditAmountViewModel acavm)
        {
            if (Session["UserId"] != null)
            {
                int UserId = int.Parse(Session["UserId"].ToString());
                acavm.UserId = UserId;
                if (acavm.Amount != 0.0)
                {
                    if (acavm.customerId != 0)
                    {
                        PragatiEntities db = new PragatiEntities();
                        CustomerPayableAmount cpa = db.CustomerPayableAmounts.Where(a => a.CustomerId == acavm.customerId && a.UserId == acavm.UserId).FirstOrDefault();
                        if (cpa == null)
                        {
                            CustomerPayableAmount cpab = new CustomerPayableAmount();
                            cpab.CustomerId = acavm.customerId;
                            cpab.UserId = acavm.UserId;
                            cpab.Amount = (float)acavm.Amount;
                            db.CustomerPayableAmounts.Add(cpab);
                            try
                            {
                                db.SaveChanges();
                            }
                            catch
                            {
                                @ViewBag.Message = "Error Occured While adding credit into Customer Account...Please try again";
                                return View();
                            }
                            return RedirectToAction("CustomerPayment");

                        }
                        else
                        {
                            cpa.Amount = cpa.Amount + (float)acavm.Amount;
                            cpa.CustomerId = acavm.customerId;
                            cpa.UserId = acavm.UserId;
                            try
                            {
                                db.SaveChanges();
                            }
                            catch
                            {
                                @ViewBag.Message = "Error Occured While adding credit into Customer Account...Please try again";
                                return View();
                            }
                            return RedirectToAction("CustomerPayment");
                        }
                        //if (num == 1)
                        //{

                        //    return RedirectToAction("CustomerPayment");
                        //}
                        //else
                        //{
                        //    @ViewBag.Message = "Error Occured While adding credit into Customer Account...Please try again";
                        //    return View();
                        //}
                    }
                    else
                    {
                        @ViewBag.Message = "Please Select Customer";
                        return View();
                    }
                }
                else
                {
                    @ViewBag.Message = "Please Enter Valid Amount";
                    return View();
                }

            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
コード例 #2
0
        public ActionResult EditMaterial(EditMaterialViewModel emvm, HttpPostedFileBase MaterialImage)
        {
            if (Session["UserId"] != null)
            {
                PragatiEntities db = new PragatiEntities();

                string text = MaterialImage.FileName;
                text = text.Substring(text.LastIndexOf("."));
                if (text == ".jpg" || text == ".jpeg" || text == ".png" || text == ".JPG" || text == ".JPEG" || text == ".PNG")
                {
                    string text2 = Path.GetFileName(MaterialImage.FileName);
                    string fileName = MaterialImage.FileName;
                    text2 = text2.Substring(0, text2.LastIndexOf(".") - 1);
                    text2 = text2 + DateTime.Now.Ticks.ToString() + text;
                    string filename = Path.Combine(Server.MapPath("~/MaterialImage/"), text2);
                    MaterialImage.SaveAs(filename);
                    string materialImagePath = "~/MaterialImage/" + text2;
                    emvm.MaterialImagePath = materialImagePath;

                    AllMaterial allMaterial = db.AllMaterials.Where(a => a.MaterialId == emvm.MaterialId).FirstOrDefault();
                    allMaterial.MaterialCode = emvm.MaterialCode;
                    allMaterial.Datetime = new DateTime?(DateTime.Now);
                    allMaterial.MaterialId = emvm.MaterialId;
                    if (emvm.MaterialImage != null)
                    {

                        allMaterial.MaterialImagePath = emvm.MaterialImagePath;
                    }
                    try
                    {
                        db.SaveChanges();
                        ViewBag.success = "Material Updated Successfully";
                        return View(emvm);
                    }
                    catch
                    {
                        ViewBag.Message = "Error occured Please try Again";
                        return View(emvm);
                    }

                }
                else
                {

                    ViewBag.Message = "Invalid Image.";
                    return View(emvm);
                }

            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
コード例 #3
0
        public ActionResult MonthlyChalan(int CustomerId, int UserId, string Fromdate, string ToDate)
        {
            if (Session["UserId"] != null)
            {
                PragatiEntities pragatiEntities = new PragatiEntities();
                MonthlyInvoiceViewModel monthlyInvoiceViewModel = new MonthlyInvoiceViewModel();
                List<ChalansViewModel> list = new List<ChalansViewModel>();
                List<MonthlyInvoice_Down_ViewModel> lst_sub_down = new List<MonthlyInvoice_Down_ViewModel>();
                List<MonthlyInvoice_Down_ReturnViewModel> lst_sub_return_down = new List<MonthlyInvoice_Down_ReturnViewModel>();

                Customer customer = (
                    from a in pragatiEntities.Customers
                    where a.CustomerId == CustomerId
                    select a).FirstOrDefault<Customer>();
                DateTime t = DateTime.Parse(Fromdate);
                DateTime t2 = DateTime.Parse(ToDate);
                monthlyInvoiceViewModel.CustomerName = customer.CustomerName + " " + customer.CustomerSurname;
                monthlyInvoiceViewModel.CustomerFirmName = customer.CustomerFirmname;
                monthlyInvoiceViewModel.FromDate = t.ToString("dd/MM/yyyy");
                monthlyInvoiceViewModel.ToDate = t2.ToString("dd/MM/yyyy");

                List<Invoice> list2 = (
                    from a in pragatiEntities.Invoices
                    where a.CustomerId == (int?)CustomerId && a.UserId == (int?)UserId
                    select a).ToList<Invoice>();

                float num = 0f;
                foreach (Invoice current in list2)
                {
                    DateTime dateTime = DateTime.Parse(current.DateTime);
                    if (t <= dateTime && dateTime <= t2)
                    {
                        ChalansViewModel chalansViewModel = new ChalansViewModel();
                        chalansViewModel.ChalanId = current.InvoiceId;
                        chalansViewModel.Date = DateTime.Parse(current.DateTime).ToString("dd/MM/yyyy");
                        chalansViewModel.Amount = current.TotalAmount.Value;
                        num += current.TotalAmount.Value;

                        foreach (var current_sub in current.Sales)
                        {
                            var submatid = (from m in pragatiEntities.Stocks where m.StockId == (int)current_sub.StockId select m).FirstOrDefault();

                            if (current_sub.ReturnPiece == "No")
                            {
                                // foreach (var item in lst_sub_down)
                                // {
                                MonthlyInvoice_Down_ViewModel sub_down = new MonthlyInvoice_Down_ViewModel();

                                var subname = (from m in pragatiEntities.SubMaterialTypes where m.SubMaterialTypeId == submatid.SubMaterialTypeId select m).FirstOrDefault();
                                var mainname = (from m in pragatiEntities.MaterialTypes where m.MaterialTypeId == submatid.MaterialTypeId select m).FirstOrDefault();
                                if (subname != null)
                                {
                                    // subname.Name = "";
                                    //total number of thread based on item
                                    if (lst_sub_down.Count == 0)
                                    {
                                        sub_down.Matname = mainname.MaterialName + "-" + subname.Name;
                                        if (current_sub.Nos_Of_Piece != 0)
                                        {
                                            sub_down.Piece = (int)current_sub.Nos_Of_Piece;

                                            lst_sub_down.Add(sub_down);
                                        }
                                    }
                                    else
                                    {
                                        foreach (var itemss in lst_sub_down)
                                        {
                                            if (itemss.Matname == mainname.MaterialName + "-" + subname.Name)
                                            {
                                                if (current_sub.Nos_Of_Piece != 0)
                                                {

                                                    itemss.Piece = itemss.Piece + (int)current_sub.Nos_Of_Piece;

                                                    //sub_down.Piece += (int)current_sub.Nos_Of_Piece;
                                                }
                                            }
                                            else
                                            {
                                                sub_down.Matname = mainname.MaterialName + "-" + subname.Name;
                                                if (current_sub.Nos_Of_Piece != 0)
                                                {
                                                    sub_down.Piece = (int)current_sub.Nos_Of_Piece;

                                                    lst_sub_down.Add(sub_down);
                                                }
                                            }
                                        }
                                    }

                                }
                                // }
                            }
                            else if (current_sub.ReturnPiece == "Yes")
                            {
                                MonthlyInvoice_Down_ReturnViewModel sub_returndown = new MonthlyInvoice_Down_ReturnViewModel();

                                var subname = (from m in pragatiEntities.SubMaterialTypes where m.SubMaterialTypeId == submatid.SubMaterialTypeId select m).FirstOrDefault();
                                var mainname = (from m in pragatiEntities.MaterialTypes where m.MaterialTypeId == submatid.MaterialTypeId select m).FirstOrDefault();
                                if (subname != null)
                                {
                                    // subname.Name = "";
                                    //total number of thread based on item
                                    if (lst_sub_return_down.Count == 0)
                                    {
                                        sub_returndown.ReturnMatname = mainname.MaterialName + "-" + subname.Name;
                                        if (current_sub.Nos_Of_Piece != 0)
                                        {
                                            sub_returndown.ReturnPiece = (int)current_sub.Nos_Of_Piece;

                                            lst_sub_return_down.Add(sub_returndown);
                                        }
                                    }
                                    else
                                    {
                                        foreach (var itemss in lst_sub_return_down)
                                        {
                                            if (itemss.ReturnMatname == mainname.MaterialName + "-" + subname.Name)
                                            {
                                                if (current_sub.Nos_Of_Piece != 0)
                                                {

                                                    itemss.ReturnPiece = itemss.ReturnPiece + (int)current_sub.Nos_Of_Piece;

                                                    //sub_down.Piece += (int)current_sub.Nos_Of_Piece;
                                                }
                                            }
                                            else
                                            {
                                                sub_returndown.ReturnMatname = mainname.MaterialName + "-" + subname.Name;
                                                if (current_sub.Nos_Of_Piece != 0)
                                                {
                                                    sub_returndown.ReturnPiece = (int)current_sub.Nos_Of_Piece;

                                                    lst_sub_return_down.Add(sub_returndown);
                                                }
                                            }
                                        }
                                    }

                                }
                            }

                        }

                        list.Add(chalansViewModel);
                    }
                }
                monthlyInvoiceViewModel.TotalAmount = num;
                monthlyInvoiceViewModel.lstChalans = list;
                monthlyInvoiceViewModel.lst_totaldownItems = lst_sub_down;
                monthlyInvoiceViewModel.lst_totalReturndownItems = lst_sub_return_down;
                MonthlyInvoice monthlyInvoice = (
                    from a in pragatiEntities.MonthlyInvoices
                    where a.CustomerId == (int?)CustomerId && a.UserId == (int?)UserId && a.FromDateTime == Fromdate && a.ToDateTime == ToDate
                    select a).FirstOrDefault<MonthlyInvoice>();
                if (monthlyInvoice == null)
                {
                    MonthlyInvoice monthlyInvoice2 = new MonthlyInvoice();
                    monthlyInvoice2.CustomerId = new int?(CustomerId);
                    monthlyInvoice2.FromDateTime = Fromdate;
                    monthlyInvoice2.ToDateTime = ToDate;
                    monthlyInvoice2.TotalAmount = new float?(num);
                    monthlyInvoice2.UserId = new int?(UserId);
                    pragatiEntities.MonthlyInvoices.Add(monthlyInvoice2);
                    pragatiEntities.SaveChanges();
                }
                MonthlyInvoice monthlyInvoice3 = (
                    from a in pragatiEntities.MonthlyInvoices
                    where a.CustomerId == (int?)CustomerId && a.UserId == (int?)UserId && a.FromDateTime == Fromdate && a.ToDateTime == ToDate
                    select a).FirstOrDefault<MonthlyInvoice>();
                monthlyInvoiceViewModel.BillId = monthlyInvoice3.MonthlyInvoiceId;
                return View(monthlyInvoiceViewModel);
            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }
コード例 #4
0
        public ActionResult DeleteMaterial(int id)
        {
            if (Session["UserId"] != null)
            {
                PragatiEntities pragatiEntities = new PragatiEntities();
                Stock stock = (
                    from a in pragatiEntities.Stocks
                    where a.MaterialId == (int?)id
                    select a).FirstOrDefault<Stock>();
                if (stock == null)
                {
                    AllMaterial allMaterial = (
                        from a in pragatiEntities.AllMaterials
                        where a.MaterialId == id
                        select a).FirstOrDefault<AllMaterial>();
                    string path = Server.MapPath(allMaterial.MaterialImagePath);
                    // File.Delete(path);
                    //try
                    //{
                    //    FileInfo fifo = new FileInfo(path);
                    //    fifo.Delete();
                    //}
                    pragatiEntities.AllMaterials.Remove(allMaterial);
                    try
                    {
                        pragatiEntities.SaveChanges();
                        return RedirectToAction("ViewMaterials", new
                        {
                            id = 1
                        });

                    }
                    catch
                    {
                        return RedirectToAction("ViewMaterials", new
                        {
                            id = -1
                        });

                    }
                }
                return RedirectToAction("ViewMaterials", new
                {
                    id = -2
                });
            }
            else
            {
                return RedirectToAction("LogIn");
            }
        }