Exemplo n.º 1
0
        public HttpResponseMessage GetInventoryByID(HttpRequestMessage request, int ID)
        {
            Context             ctx           = new Context();
            InventoryRepository inventoryRepo = new InventoryRepository(ctx);
            tbInventory         result        = inventoryRepo.GetDataSet().Where(a => a.IsDeleted != true && a.ID == ID).FirstOrDefault();

            return(request.CreateResponse <tbInventory>(HttpStatusCode.OK, result));
        }
Exemplo n.º 2
0
        //UpSertInventory
        public async Task <ActionResult> UpSertInventory(tbInventory tbInventory)
        {
            var         url    = "api/Inventory/UpsertInventory";
            tbInventory result = await APIRequest <tbInventory> .Post(url, tbInventory);

            if (result != null)
            {
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Fail", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage UpsertInventory(HttpRequestMessage request, tbInventory tbInventory)
        {
            Context             ctx           = new Context();
            InventoryRepository inventoryRepo = new InventoryRepository(ctx);
            StockRepository     stockRepo     = new StockRepository(ctx);
            tbInventory         UpdatedEntity = null;

            //if (tbInventory.ID > 0)
            //{
            //    UpdatedEntity = inventoryRepo.update(tbInventory);
            //}
            if (tbInventory.TransactionType == "2") //Transaction Type : Justifity
            {
                tbStock tbStock = stockRepo.GetDataSet().Where(a => a.IsDeleted != true && a.ItemGUID == tbInventory.ItemGUID).FirstOrDefault();
                if (tbStock.StockQty >= tbInventory.Qty)// Check the given quantity is enough or not in the stock table.
                {
                    tbInventory.FlowType       = "Justify";
                    tbInventory.Accesstime     = DateTime.UtcNow.ToLocalTime();
                    tbInventory.IsDeleted      = false;
                    tbInventory.UniqueID       = Guid.NewGuid();
                    tbInventory.TotalItemPrice = Convert.ToDecimal(tbInventory.ItemPrice * tbInventory.Qty);
                    UpdatedEntity = inventoryRepo.Add(tbInventory);

                    tbStock tbStock1 = stockRepo.GetDataSet().Where(a => a.IsDeleted != true && a.ItemGUID == tbInventory.ItemGUID).FirstOrDefault();
                    tbStock1.StockQty -= tbInventory.Qty;
                    stockRepo.update(tbStock1);
                }
                else
                {
                    return(request.CreateResponse <tbInventory>(HttpStatusCode.OK, UpdatedEntity));;
                }
            }
            else
            {
                tbInventory.FlowType       = "StockIn";
                tbInventory.Accesstime     = DateTime.UtcNow.ToLocalTime();
                tbInventory.IsDeleted      = false;
                tbInventory.UniqueID       = Guid.NewGuid();
                tbInventory.TotalItemPrice = Convert.ToDecimal(tbInventory.ItemPrice * tbInventory.Qty);

                UpdatedEntity = inventoryRepo.Add(tbInventory);
                tbStock tbStock = stockRepo.GetDataSet().Where(a => a.IsDeleted != true && a.ItemGUID == tbInventory.ItemGUID).FirstOrDefault();
                tbStock.StockQty += tbInventory.Qty;
                stockRepo.update(tbStock);
            }

            return(request.CreateResponse <tbInventory>(HttpStatusCode.OK, UpdatedEntity));
        }
Exemplo n.º 4
0
        //_InventoryForm
        public async Task <ActionResult> _InventoryForm(string FormType, int ID)
        {
            tbInventory tbInventory = new tbInventory();

            if (FormType == "Add")
            {
                return(PartialView("_InventoryForm", tbInventory));
            }

            else
            {
                string      url    = string.Format("api/Inventory/GetInventoryByID?ID={0}", ID);
                tbInventory result = await APIRequest <tbInventory> .Get(url);

                return(PartialView("_InventoryForm", result));
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage UpsertOrderDetail(HttpRequestMessage request, string items)
        {
            #region Instances

            Context ctx = new Context();

            ItemRepository        itemRepo        = new ItemRepository(ctx);
            StockRepository       stockRepo       = new StockRepository(ctx);
            OrderRepository       orderRepo       = new OrderRepository(ctx);
            OrderDetailRepository orderDetailRepo = new OrderDetailRepository(ctx);
            InventoryRepository   inventoryRepo   = new InventoryRepository(ctx);

            tbItem        tbItem        = new tbItem();
            tbStock       tbStock       = new tbStock();
            tbInventory   tbInventory   = new tbInventory();
            tbOrder       tbOrder       = new tbOrder();
            tbOrderDetail tbOrderDetail = new tbOrderDetail();
            tbOrder       UpdatedOrder  = null;
            tbOrderDetail UpdatedEntity = null;
            decimal       totalPrice    = 0;
            string        voucherCode   = Guid.NewGuid().ToString();

            #endregion

            #region insert order table

            tbOrder.StaffGUID      = "Default";
            tbOrder.StaffName      = "Default";
            tbOrder.CinemaId       = 1;
            tbOrder.CinemaName     = "";
            tbOrder.VoucherCode    = voucherCode;
            tbOrder.Accesstime     = DateTime.UtcNow.ToLocalTime();
            tbOrder.IsDeleted      = false;
            tbOrder.TotalPrice     = totalPrice;
            tbOrder.CreatedAt      = DateTime.UtcNow.ToLocalTime();
            tbOrder.Status         = "Default";
            tbOrder.ServiceFees    = 0;
            tbOrder.SubTotalPrice  = tbOrder.TotalPrice;
            tbOrder.TotalTax       = 0;
            tbOrder.TaxIncluded    = false;
            tbOrder.Currency       = "";
            tbOrder.TotalDiscounts = 0;
            tbOrder.TotalItemPrice = tbOrder.TotalPrice;
            tbOrder.DiscountCode   = "";
            tbOrder.Remark         = "";
            UpdatedOrder           = orderRepo.Add(tbOrder);

            #endregion

            List <string> itemList = items.Split(',').ToList();
            foreach (string item in itemList)
            {
                string[] idVal    = item.Split('|').ToArray();
                string   itemGUID = idVal[0];
                int      qty      = Convert.ToInt32(idVal[1]);
                tbItem = itemRepo.GetDataSet().Where(a => a.IsDeleted != true && a.UniqueID.ToString() == itemGUID).FirstOrDefault();

                //if(tbStock.StockQty>=qty)
                //{ }
                #region Add order detail.

                tbOrderDetail.ItemID     = tbItem.ID;
                tbOrderDetail.ItemName   = tbItem.Item;
                tbOrderDetail.ItemPrice  = tbItem.SellingPrice;
                tbOrderDetail.ItemQty    = qty;
                tbOrderDetail.TotalPrice = tbOrderDetail.ItemPrice * qty;
                totalPrice += Convert.ToDecimal(tbOrderDetail.TotalPrice);
                tbOrderDetail.VoucherCode = voucherCode;
                tbOrderDetail.OrderID     = UpdatedOrder.ID;
                tbOrderDetail.CinemaID    = tbOrder.CinemaId;
                tbOrderDetail.CinemaName  = tbOrder.CinemaName;
                tbOrderDetail.IsDeleted   = false;
                UpdatedEntity             = orderDetailRepo.Add(tbOrderDetail);

                #endregion

                #region update stock table.

                tbStock            = stockRepo.GetDataSet().Where(s => s.IsDeleted != true && s.ItemGUID.ToString() == itemGUID && s.CinemaID == tbOrder.CinemaId).FirstOrDefault();
                tbStock.StockQty   = tbStock.StockQty - qty;
                tbStock.Accesstime = DateTime.UtcNow.ToLocalTime();
                stockRepo.update(tbStock);

                #endregion

                #region update inventory table.

                tbInventory.FlowType        = "StockOut";
                tbInventory.ItemPrice       = tbItem.SellingPrice;
                tbInventory.TotalItemPrice  = totalPrice;
                tbInventory.IsDeleted       = false;
                tbInventory.Accesstime      = DateTime.UtcNow.ToLocalTime();
                tbInventory.UniqueID        = Guid.NewGuid();
                tbInventory.ItemGUID        = tbItem.UniqueID;
                tbInventory.ItemName        = tbItem.Item;
                tbInventory.TransactionType = "3"; //TransactionType:3 (StockOut)
                tbInventory.CinemaID        = tbOrder.CinemaId;
                tbInventory.Qty             = qty;
                inventoryRepo.Add(tbInventory);

                #endregion
            }

            #region update total price to order table

            tbOrder                = orderRepo.GetDataSet().Where(x => x.IsDeleted != true && x.VoucherCode == voucherCode).FirstOrDefault();
            tbOrder.TotalPrice     = totalPrice;
            tbOrder.TotalItemPrice = totalPrice;
            orderRepo.update(tbOrder);

            #endregion

            return(request.CreateResponse <tbOrderDetail>(HttpStatusCode.OK, UpdatedEntity));
        }