Exemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            sal_SalesCart sal_SalesCart = await db.sal_SalesCart.FindAsync(id);

            db.sal_SalesCart.Remove(sal_SalesCart);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "SalesCartID,ItemID,ItemName,ItemQuantity,ItemPrice,TotalItemsPrice,SourceID,SourceName,SalesCartType,SalesCartDate")] sal_SalesCart sal_SalesCart)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sal_SalesCart).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(sal_SalesCart));
        }
Exemplo n.º 3
0
        // GET: CustomerFromInventoryCart/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            sal_SalesCart sal_SalesCart = await db.sal_SalesCart.FindAsync(id);

            if (sal_SalesCart == null)
            {
                return(HttpNotFound());
            }
            return(View(sal_SalesCart));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> DeleteCartItem(int id)
        {
            int status = 0;


            try
            {
                sal_SalesCart SaleCartitem = db.sal_SalesCart.Find(id);


                //  Old item


                var SaleItem = db.sal_SaleItems.Where(I => I.ItemID == SaleCartitem.ItemID).FirstOrDefault();

                var OldQuantity = SaleItem.SaleItemsQuantity;

                SaleItem.SaleItemsQuantity = OldQuantity + SaleCartitem.ItemQuantity;
                await db.SaveChangesAsync();

                //  Old item

                // remove from cart
                db.sal_SalesCart.Remove(SaleCartitem);
                await db.SaveChangesAsync();

                // remove from cart

                status = 1;
            }
            catch (Exception)
            {
                status = 4;
                throw;
            }

            return(new JsonResult {
                Data = new { status = status }
            });;
        }
Exemplo n.º 5
0
        // GET: SalesCart/Details/5

        public async Task <JsonResult> InsertSalesCart(sal_SalesCart SalesCart, int?SalesCartType)
        {
            int status = 0;

            try
            {
                // Get item details from items table
                var PointOfSale   = Session["PointOfSaleID"].ToString();
                int PointOfSaleID = int.Parse(PointOfSale);

                var Item = db.sal_SaleItems.Where(I => I.ItemID == SalesCart.ItemID && I.PointOfSaleID == PointOfSaleID).FirstOrDefault();
                var ItemInventoryOldQuantity = Item.SaleItemsQuantity;
                // Get item details from items table

                // Salse Cart Item
                var v = db.sal_SalesCart.Where(I => I.ItemID == SalesCart.ItemID && I.SalesCartType == SalesCartType).FirstOrDefault();
                // Salse Cart Item

                var newQnatity = SalesCart.ItemQuantity;

                if ((ItemInventoryOldQuantity - newQnatity) >= 0)
                {
                    // Update item in sales cart
                    if (v != null)
                    {
                        var cartOldQuantity = v.ItemQuantity;
                        if (cartOldQuantity + SalesCart.ItemQuantity <= Item.SaleItemsQuantity)
                        {
                            v.ItemQuantity = cartOldQuantity + SalesCart.ItemQuantity;
                            var TotalItemsPrice = (cartOldQuantity + SalesCart.ItemQuantity) * Item.ItemSalePrice;
                            v.TotalItemsPrice = TotalItemsPrice;
                            db.SaveChanges();
                            status = 1;          // success
                        }

                        else
                        {
                            status = 3;         //Quantity error
                        }
                    }

                    // insert new item in sales cart
                    else
                    {
                        if (SalesCart.ItemQuantity <= Item.SaleItemsQuantity)
                        {
                            SalesCart.ItemPrice       = Item.ItemSalePrice;
                            SalesCart.TotalItemsPrice = SalesCart.ItemQuantity * Item.ItemSalePrice;

                            SalesCart.SalesCartType = SalesCartType;

                            db.sal_SalesCart.Add(SalesCart);
                            await db.SaveChangesAsync();

                            status = 1;     // success
                        }
                        else
                        {
                            status = 3;     //Quantity error
                        }
                    }
                }


                // New Quantity > inventory Quantity
                else
                {
                    status = 3;      // errror
                }
            }
            catch (Exception)
            {
                status = 4;
                throw;
            }

            return(new JsonResult {
                Data = new { status = status }
            });

            //return Json(SalesCart);
        }
Exemplo n.º 6
0
        public async Task <JsonResult> UpdatetSalesCart(sal_SalesCart SalesCart, string TotalItemsPrice, int?SalesCartType)
        {
            int status = 0;

            try
            {
                var v = db.sal_SalesCart.Where(I => I.ItemID == SalesCart.ItemID && I.SalesCartType == SalesCartType).FirstOrDefault();

                // Get item details from items table

                var PointOfSale   = Session["PointOfSaleID"].ToString();
                int PointOfSaleID = int.Parse(PointOfSale);

                var SaleItem = db.sal_SaleItems.Where(I => I.ItemID == SalesCart.ItemID && I.PointOfSaleID == PointOfSaleID).FirstOrDefault();

                var ItemInventoryQuantity = SaleItem.SaleItemsQuantity;
                var CartOldQuantity       = v.ItemQuantity;
                // Get item details from items table


                // Depet (+) Update

                if (SalesCart.ItemQuantity > CartOldQuantity)
                {
                    var newQuantity = SalesCart.ItemQuantity + CartOldQuantity;

                    // Check Item Quantity in Point Of Sale
                    if (ItemInventoryQuantity - newQuantity >= 0)
                    {
                        v.ItemQuantity    = SalesCart.ItemQuantity;
                        v.TotalItemsPrice = SalesCart.TotalItemsPrice;
                        db.SaveChanges();

                        // SaleItem.SaleItemsQuantity = ItemInventoryQuantity - newQuantity;
                        //await db.SaveChangesAsync();

                        status = 1;
                    }

                    // Cart Quantity > Item Quantity
                    else
                    {
                        status = 3;
                    }
                }

                // Cart quantity > new quantity (-)
                else if (CartOldQuantity > SalesCart.ItemQuantity)
                {
                    var newQuantity = CartOldQuantity - SalesCart.ItemQuantity;
                    if (ItemInventoryQuantity - newQuantity >= 0)
                    {
                        v.ItemQuantity    = SalesCart.ItemQuantity;
                        v.TotalItemsPrice = SalesCart.TotalItemsPrice;
                        await db.SaveChangesAsync();

                        status = 1;
                    }

                    else
                    {
                        status = 3;
                    }
                }

                else      // not (+) and not (-)
                {
                    status = 1;
                }
            }
            catch (Exception e)
            {
                status = 4;
            }


            return(new JsonResult {
                Data = new { status = status }
            });

            //return Json(SalesCart);
        }