示例#1
0
        // GET: purchaseentries/Create
        public ActionResult Create()
        {
            ViewBag.Edit      = false;
            ViewBag.Suppliers = db.suppliers.ToList();
            ViewBag.ProductID = new SelectList(db.products, "ID", "Name");
            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem()
            {
                Text = "Invoice", Value = "Invoice"
            });
            items.Add(new SelectListItem()
            {
                Text = "Challan", Value = "Challan"
            });
            ViewBag.InvoiceChallan = items;

            PurchaseEntryVM purchaseEntryVM = new PurchaseEntryVM();

            purchaseEntryVM._orderDetail = new List <orderdetail> {
                new orderdetail()
            };
            purchaseEntryVM.purchaseEntry = new purchaseentry {
                CGST           = 5,
                SGST           = 5,
                DiscountAmount = 0
            };
            purchaseEntryVM.purchaseOrder = new purchaseorder();
            return(View(purchaseEntryVM));
        }
示例#2
0
        public JsonResult SavePurchase(PurchaseEntryVM p)
        {
            bool status = false;

            if (p != null)
            {
                //new purchase object using the data from the viewmodel : PurchaseEntryVM
                var purchase = new pharm.Models.Purchase
                {
                    Purchase_ID     = p.Purchase_ID,
                    Entry_Date      = p.Entry_Date,
                    Supplier_ID     = p.Supplier_ID,
                    Amount          = p.Amount,
                    Discount        = p.Discount,
                    Grand_Total     = p.Grand_Total,
                    IsPaid          = p.IsPaid,
                    Description     = p.Description,
                    Discount_Amount = p.Discount_Amount
                };

                var batchs = p.PurchaseItems.Select(i => new pharm.Models.Batch
                {
                    Batch_ID        = i.Batch_ID,
                    Quantity        = i.Quantity,
                    Cost_Price      = i.Cost_Price,
                    Sell_Price      = i.Sell_Price,
                    Production_Date = i.Production_Date,
                    Expire_Date     = i.Expire_Date,
                    Purchase_ID     = p.Purchase_ID,
                    Medicine_ID     = i.Medicine_ID
                }).ToList();

                //db.Purchases.Attach(purchase);
                db.Purchases.Add(purchase);

                foreach (var b in batchs)
                {
                    //db.Batches.Attach(b);
                    db.Batches.Add(b);
                }


                try
                {
                    db.SaveChanges();
                }
                catch
                {
                    Response.Write("<script>alert('Batch Number needs to be unqiue')</script>");
                }



                status = true;
            }
            // return the status in form of Json
            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#3
0
        // GET: purchaseentries/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //purchaseentry purchaseEntry = db.purchaseentries.Find(id);
            PurchaseEntryVM purchaseEntryVM = new PurchaseEntryVM();

            ViewBag.PurchaseEntryID       = id;
            purchaseEntryVM.purchaseEntry = db.purchaseentries.Where(x => x.ID == id).SingleOrDefault();
            purchaseEntryVM.purchaseOrder = db.purchaseorders.Where(x => x.ID == purchaseEntryVM.purchaseEntry.PurchaseOrderID).SingleOrDefault();
            purchaseEntryVM._orderDetail  = db.orderdetails.Where(x => x.PurchaseOrderID == purchaseEntryVM.purchaseEntry.PurchaseOrderID).ToList();

            // calculatet Due Amt
            double paidamt = (double)db.purchaseentrypayments.Where(x => x.PurchaseEntryID == id).Select(x => (int?)x.PaidAmount ?? 0)
                             .DefaultIfEmpty(0).Sum();

            purchaseEntryVM.purchaseEntry.DueAmount = purchaseEntryVM.purchaseEntry.TotalAmount - paidamt;

            ViewBag.PaymentHistory = db.purchaseentrypayments.Where(x => x.PurchaseEntryID == id).ToList();

            if (purchaseEntryVM == null)
            {
                return(HttpNotFound());
            }
            return(View(purchaseEntryVM));
        }
示例#4
0
        // GET: purchaseentries/Edit/5
        public ActionResult Edit(int?id, bool IsPurchaseOrder = false)
        {
            ViewBag.Edit      = true;
            ViewBag.Suppliers = db.suppliers.ToList();
            ViewBag.ProductID = new SelectList(db.products, "ID", "Name");

            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem()
            {
                Text = "Invoice", Value = "Invoice"
            });
            items.Add(new SelectListItem()
            {
                Text = "Delivery Challan", Value = "Delivery Challan"
            });
            ViewBag.InvoiceChallan = items;


            PurchaseEntryVM purchaseEntryVM = new PurchaseEntryVM();

            if (IsPurchaseOrder)
            {
                ViewBag.PurchaseEntryID       = 0;
                purchaseEntryVM.purchaseEntry = new purchaseentry {
                    CGST           = 5,
                    SGST           = 5,
                    DiscountAmount = 0
                };
                purchaseEntryVM.purchaseOrder = db.purchaseorders.Where(x => x.ID == id).SingleOrDefault();
                purchaseEntryVM._orderDetail  = db.orderdetails.Where(x => x.PurchaseOrderID == id).ToList();
            }
            else
            {
                ViewBag.PurchaseEntryID       = id;
                purchaseEntryVM.purchaseEntry = db.purchaseentries.Where(x => x.ID == id).SingleOrDefault();
                purchaseEntryVM.purchaseOrder = db.purchaseorders.Where(x => x.ID == purchaseEntryVM.purchaseEntry.PurchaseOrderID).SingleOrDefault();
                purchaseEntryVM._orderDetail  = db.orderdetails.Where(x => x.PurchaseOrderID == purchaseEntryVM.purchaseEntry.PurchaseOrderID).ToList();

                // calculatet Due Amt
                double paidamt = (double)db.purchaseentrypayments.Where(x => x.PurchaseEntryID == id).Select(x => (int?)x.PaidAmount ?? 0)
                                 .DefaultIfEmpty(0).Sum();
                purchaseEntryVM.purchaseEntry.DueAmount = purchaseEntryVM.purchaseEntry.TotalAmount - paidamt;
            }
            ViewBag.NoDue = (purchaseEntryVM.purchaseEntry.DueAmount <= 0) ? true :  false;
            purchaseEntryVM._orderDetail.Insert(0, new orderdetail {
            });
            return(View("Create", purchaseEntryVM));
        }
        public JsonResult SavePurchase(PurchaseEntryVM p)
        {
            bool status = false;

            if (p != null)
            {
                //new purchase object using the data from the viewmodel : PurchaseEntryVM
                Purchase purchase = new Purchase
                {
                    ID          = p.ID,
                    Date        = p.Date,
                    SupplierID  = p.SupplierID,
                    Amount      = p.Amount,
                    Discount    = p.Discount,
                    Tax         = p.Tax,
                    GrandTotal  = p.GrandTotal,
                    IsPaid      = p.IsPaid,
                    Description = p.Description,
                    LastUpdated = DateTime.Now
                };

                purchase.PurchaseItems = new List <PurchaseItem>();
                //populating the PurchaseItems from the PurchaseItems within ViewModel : PurchaseEntryVM
                foreach (var i in p.PurchaseItems)
                {
                    purchase.PurchaseItems.Add(i);
                }

                //add purchase
                // finally save changes.
                service.AddPurchaseAndPurchseItems(purchase);
                service.InsertOrUpdateInventory(p.PurchaseItems);

                //if everything is sucessful, set status to true.
                status = true;
            }
            // return the status in form of Json
            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#6
0
        public JsonResult SavePurchase(PurchaseEntryVM p)
        {
            bool status = false;

            if (p != null)
            {
                DataAccess.Purchase purchase = new DataAccess.Purchase
                {
                    ID          = p.ID,
                    Date        = p.Date,
                    SupplierID  = p.SupplierID,
                    Amount      = p.Amount,
                    Discount    = p.Discount,
                    Tax         = p.Tax,
                    GrandTotal  = p.GrandTotal,
                    IsPaid      = p.IsPaid,
                    Description = p.Description,
                    LastUpdated = DateTime.Now
                };

                purchase.PurchaseItems = new List <PurchaseItem>();
                foreach (var i in p.PurchaseItems)
                {
                    purchase.PurchaseItems.Add(i);
                }

                //add purchase
                Purcrep.Add(purchase);
                PurchaseEntryRepository pent = new PurchaseEntryRepository();
                foreach (var item in p.PurchaseItems)
                {
                    pent.InsertOrUpdateInventory(item);
                }

                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#7
0
        public ActionResult Create(PurchaseEntryVM purchaseEntryVM)
        {
            purchaseEntryVM._orderDetail.RemoveAt(0); // remove first template record from list

            purchaseentry purchaseEntry = purchaseEntryVM.purchaseEntry;
            float         totalAmt      = calculateTotal(purchaseEntryVM._orderDetail);

            purchaseEntry.TotalAmount = calculateGrandTotal(purchaseEntry.CGST, purchaseEntry.SGST, purchaseEntry.DiscountAmount, totalAmt);
            if (purchaseEntry.DueAmount == 0)
            {
                purchaseEntry.Status = true;
            }
            if (ModelState.IsValid)
            {
                purchaseorder po = new purchaseorder();
                po.SupplierID      = purchaseEntryVM.purchaseOrder.SupplierID;
                po.PurchaseOrderNo = purchaseEntryVM.purchaseOrder.PurchaseOrderNo;
                if (purchaseEntryVM.purchaseOrder.ID != 0)
                {
                    po.ID = purchaseEntryVM.purchaseOrder.ID;
                }
                po.IsPurcheseEntry = true; // set this is true for Purchase Entry
                foreach (var od in purchaseEntryVM._orderDetail)
                {
                    if (od.ProductID == 0)
                    {
                        continue;
                    }
                    if (db.orderdetails.Where(x => x.PurchaseOrderID == purchaseEntryVM.purchaseOrder.ID && x.ProductID == od.ProductID).ToList().Count > 0)
                    {
                        var orderDetail = db.orderdetails.Find(od.ID);
                        if (orderDetail != null)
                        {
                            orderDetail.CostPrice        = od.CostPrice;
                            orderDetail.PurchaseOrderID  = purchaseEntryVM.purchaseOrder.ID;
                            orderDetail.Quantity         = od.Quantity;
                            orderDetail.ReceivedQuantity = od.ReceivedQuantity;
                            db.orderdetails.Attach(orderDetail);
                            db.Entry(orderDetail).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        po.orderdetails.Add(od);
                    }

                    // Update inventory table with quantity
                    var objPI = db.productsinventories.Where(x => x.ProductID == od.ProductID).SingleOrDefault();
                    if (objPI != null)
                    {
                        objPI.Quantity = objPI.Quantity + (int)od.ReceivedQuantity;
                        db.productsinventories.Attach(objPI);
                        db.Entry(objPI).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        productsinventory PI = new productsinventory();
                        PI.ProductID = od.ProductID;
                        PI.Quantity  = (int)od.ReceivedQuantity;
                        db.productsinventories.Add(PI);
                    }
                }
                if (po.ID == 0)
                {
                    po.purchaseentries.Add(purchaseEntry);
                    db.purchaseorders.Add(po);
                }
                else
                {
                    purchaseEntry.PurchaseOrderID = po.ID;
                    db.purchaseentries.Add(purchaseEntry);
                }
                db.SaveChanges();

                // Once save is success update Products Inventory table
            }
            var purchaseEntries = db.purchaseentries.Include(p => p.purchaseorder);

            return(View("Index", purchaseEntries.ToList()));
        }
        // GET: PurchaseEntry
        /// <summary>
        /// Main page for entering new purchase records.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public ActionResult Index()
        {
            var vm = new PurchaseEntryVM();

            return(View(vm));
        }