Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("TransactionId,ItemId,CustomerId,TotalCost,PurchaseDate,Quantity")] ItemPurchase itemPurchase)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(itemPurchase);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemPurchaseExists(itemPurchase.TransactionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (DbUpdateException) //catches trigger errors
                {
                    var _item = await _context.Items.FindAsync(itemPurchase.ItemId);

                    ViewData["Amount"] = _item.StockCount;
                    return(View("Error"));
                }
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "CustomerId", itemPurchase.CustomerId);
            ViewData["ItemId"]     = new SelectList(_context.Items, "ItemId", "Title", itemPurchase.ItemId);
            return(View(itemPurchase));
        }
        public IActionResult RegisterItemPurchase(long id, [FromQuery] string userType)
        {
            if (userType == null)
            {
                return(RemoveItem(id));
            }

            try
            {
                UserType type;

                try{
                    type = UserTypeConversionService.ToUserType(userType);
                }catch (ArgumentException invalidUserType) {
                    return(BadRequest(new ErrorModelView(invalidUserType.Message)));
                }

                Item item = this.factory.ItemRepository().Find(id);

                bool marked = item.markAsServed();

                if (!marked)
                {
                    return(BadRequest(new ErrorModelView("item was already served")));
                }

                this.factory.ItemRepository().Update(item);

                try{
                    ItemPurchase purchasedItem = new ItemPurchase(type, item.ItemId);

                    this.factory.ItemPurchaseRepository().Save(purchasedItem);

                    return(NoContent());
                }catch (Exception exception) {
                    if (exception is ArgumentException || exception is InvalidOperationException)
                    {
                        return(BadRequest(new ErrorModelView(exception.Message)));
                    }
                    else
                    {
                        return(StatusCode(500, null));
                    }
                }
            }
            catch (Exception e)
            {
                if (e is ArgumentException)
                {
                    return(NotFound());
                }

                return(StatusCode(500, null));
            }
        }
 public void CreateAddItemPurchase(Purchase purchase, List <int> itemIds, List <int> itemQtys)
 {
     for (int i = 0; i < itemIds.Count(); i++)
     {
         ItemPurchase itemPurchase = new ItemPurchase()
         {
             PurchasesPurchaseId = purchase.PurchaseId,
             Item1ItemId         = itemIds[i],
             ItemQty             = itemQtys[i],
         };
         _db.ItemPurchase.Add(itemPurchase);
         _db.SaveChanges();
     }
 }
        public ItemPurchase Save(ItemPurchase rootToSave)
        {
            try
            {
                Find(rootToSave.Id());
                throw new InvalidOperationException("item purchase with the same business identifier already exists");
            }
            catch (ArgumentException noItemPurchaseFound)
            {
                ctx.ItemPurchases.Add(rootToSave);

                ctx.SaveChanges();

                return(Find(rootToSave.Id()));
            }
        }
        public async Task <Order> Checkout(string userId)
        {
            var itemsInCart = _appDbContext.Items.Where(i => i.InUserCart == userId && !i.Sold).ToList();

            decimal total = 0;

            foreach (var item in itemsInCart)
            {
                item.InCart     = false;
                item.InUserCart = "";
                item.Sold       = true;

                total += item.Price;
                _appDbContext.Entry(item).State = EntityState.Modified;
            }

            var order = new Order
            {
                UserId          = userId,
                Total           = total,
                TransactionDate = DateTime.Now
            };

            await _appDbContext.Orders.AddAsync(order);

            await _appDbContext.SaveChangesAsync();

            foreach (var item in itemsInCart)
            {
                var itemPurchase = new ItemPurchase()
                {
                    ItemId  = item.Id,
                    OrderId = order.Id
                };

                await _appDbContext.ItemPurchases.AddAsync(itemPurchase);
            }

            await _appDbContext.SaveChangesAsync();

            return(order);
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("TransactionId,ItemId,CustomerId,TotalCost,PurchaseDate,Quantity")] ItemPurchase itemPurchase)
        {
            if (id != itemPurchase.TransactionId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ItemPurchase _itemPurchase = _context.ItemPurchase.Where(s => s.TransactionId == itemPurchase.TransactionId).First();
                    _itemPurchase.ItemId       = itemPurchase.ItemId;
                    _itemPurchase.CustomerId   = itemPurchase.CustomerId;
                    _itemPurchase.TotalCost    = itemPurchase.TotalCost;
                    _itemPurchase.PurchaseDate = itemPurchase.PurchaseDate;
                    _itemPurchase.Quantity     = itemPurchase.Quantity;
                    _context.Update(_itemPurchase);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemPurchaseExists(itemPurchase.TransactionId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "CustomerId", itemPurchase.CustomerId);
            ViewData["ItemId"]     = new SelectList(_context.Items, "ItemId", "Title", itemPurchase.ItemId);
            return(View(itemPurchase));
        }
Esempio n. 7
0
        protected override void Seed(CompanyPosDBContext context)
        {
            Company company = new Company()
            {
                Name   = "Company A",
                Stores = new List <Store>()
                {
                    new Store()
                    {
                        Name         = "Store 1"
                        , Categories = new List <Category>()
                        {
                            new Category()
                            {
                                Name    = "Category 1"
                                , Value = "Value 1"
                                , Items = new List <Item>()
                                {
                                    new Item()
                                    {
                                        Name             = "Item 1"
                                        , UnitPrice      = 1000
                                        , Description    = "Sample Item"
                                        , ItemAttributes = new List <ItemAttribute>()
                                        {
                                            new ItemAttribute()
                                            {
                                                Name     = "Color"
                                                , Value  = "Red"
                                                , Amount = 0
                                                , Price  = 1
                                            }
                                        }
                                    }
                                }
                            }
                        }, Users = new List <User> {
                            new User()
                            {
                                LastName = "Owner X", Username = "******", Password = "******", Type = "Owner", UserLevel = "admin"
                            }
                        }
                    },
                }
            };

            context.Companies.Add(company);
            context.SaveChanges();

            //Create Session
            Session session = new Session()
            {
                Created = DateTime.Now
                ,
                LastUpdate = DateTime.Now
                ,
                StoreID = context.Stores.First().ID
                ,
                UserID = context.Stores.First().Users.First().ID
                ,
                TokenID = "11554895561"
            };

            context.Sessions.Add(session);
            context.SaveChanges();
            Shift shift = new Shift()
            {
                Status = "OPEN"
                ,
                TimeEnd = DateTime.Now.AddYears(1)
                ,
                TimeStart = DateTime.Now.AddYears(-1)
                ,
                StoreID = context.Stores.First().ID
            };

            context.Shifts.Add(shift);
            context.SaveChanges();
            Sale sale = new Sale()
            {
                Title = "New Sale"
                ,
                Date = DateTime.Now
                ,
                DiscountAmount = 10
                ,
                DiscountRate = 0
                ,
                StoreID = context.Stores.First().ID
            };

            context.Sales.Add(sale);
            context.SaveChanges();
            ItemPurchase itemPurchase = new ItemPurchase()
            {
                Discount = "0"
                ,
                ItemID = context.Items.First().ID
                ,
                Quantity = 1
                ,
                StoreID = context.Stores.First().ID
                ,
                TotalPrice = "100"
                ,
                SaleID = context.Sales.First().ID
            };

            context.ItemPurchases.Add(itemPurchase);
            context.SaveChanges();
            base.Seed(context);
        }
Esempio n. 8
0
        public ActionResult EmployeeRecAdjustment(string date, int EmpId, int ItemId, decimal OldQty, decimal NewQty, string Remarks)
        {
            EmployeeAdjustment employeeAdjustment = new EmployeeAdjustment();
            DateTime?          EffDate            = Convert.ToDateTime(date);
            var      RecordInItemPurchase         = db.ItemPurchases.Where(i => DbFunctions.TruncateTime(i.EffectiveDate) == DbFunctions.TruncateTime(EffDate) && i.EmployeeId == EmpId && i.ItemId == ItemId).FirstOrDefault();
            int      CurrentDate   = DateTime.Now.Day;
            DateTime UserInputDate = Convert.ToDateTime(date);
            int      EffectiveDate = UserInputDate.Day;

            if (CurrentDate == EffectiveDate)
            {
                employeeAdjustment.EmployeeId        = EmpId;
                employeeAdjustment.ItemId            = ItemId;
                employeeAdjustment.CashierId         = RecordInItemPurchase.CashierId;
                employeeAdjustment.EnteredUserId     = Convert.ToInt32(Session["UserId"].ToString());
                employeeAdjustment.TransactionTypeId = 4;
                employeeAdjustment.FactoryId         = RecordInItemPurchase.FactoryId;
                employeeAdjustment.UnitPrice         = RecordInItemPurchase.UnitPrice;
                employeeAdjustment.Quantity          = NewQty;
                employeeAdjustment.EffectiveDate     = EffDate;
                employeeAdjustment.EnteredDate       = DateTime.Now;
                employeeAdjustment.Remarks           = Remarks;
                db.EmployeeAdjustments.Add(employeeAdjustment);
                db.SaveChanges();

                EmployeePayment employeePayment = new EmployeePayment(); //Add a plus value for EmployeeID & Effective Date
                employeePayment.EmployeeID    = EmpId;
                employeePayment.EffectiveDate = EffDate;
                employeePayment.Amount        = (RecordInItemPurchase.UnitPrice * (NewQty * -1));
                db.EmployeePayments.Add(employeePayment);
                db.SaveChanges();

                ItemPurchase itemPurchase = new ItemPurchase();//Add minues value for Unit Price & Quantity for EmpId & EffDate
                itemPurchase.EffectiveDate = EffDate;
                itemPurchase.EmployeeId    = EmpId;
                itemPurchase.ItemId        = ItemId;
                itemPurchase.UnitPrice     = (RecordInItemPurchase.UnitPrice * -1);
                itemPurchase.Quantity      = NewQty;
                itemPurchase.FactoryId     = RecordInItemPurchase.FactoryId;
                itemPurchase.CashierId     = RecordInItemPurchase.CashierId;
                db.ItemPurchases.Add(itemPurchase);
                db.SaveChanges();

                ItemTransaction itemTransaction1 = new ItemTransaction(); //If same date No plus value for transaction type 3, Add plus value for Trans Type 2
                itemTransaction1.ItemID            = ItemId;
                itemTransaction1.Quantity          = (NewQty * -1);
                itemTransaction1.TransactionTypeId = 2;
                itemTransaction1.EffectiveDate     = EffDate;
                db.ItemTransactions.Add(itemTransaction1);
                db.SaveChanges();

                var EmployeeDetails = db.Employees.Where(e => e.ID == EmpId).FirstOrDefault();//Reduce Credit Balance
                EmployeeDetails.CreditBalance   = (EmployeeDetails.CreditBalance + ((RecordInItemPurchase.UnitPrice * -1) * NewQty));
                db.Entry(EmployeeDetails).State = EntityState.Modified;
                db.SaveChanges();

                var     daySesslingQty = db.Items.Where(i => i.ID == ItemId).FirstOrDefault();
                decimal ReduceQty      = (OldQty + NewQty);//If same date reduce Item Day Selling qty
                daySesslingQty.DaySellingQty   = daySesslingQty.DaySellingQty + ReduceQty;
                db.Entry(daySesslingQty).State = EntityState.Modified;
                db.SaveChanges();

                success = "Adjustment Entered Succfully.";
            }
            else if (CurrentDate > EffectiveDate)
            {
                employeeAdjustment.EmployeeId        = EmpId;
                employeeAdjustment.ItemId            = ItemId;
                employeeAdjustment.CashierId         = RecordInItemPurchase.CashierId;
                employeeAdjustment.EnteredUserId     = Convert.ToInt32(Session["UserId"].ToString());
                employeeAdjustment.TransactionTypeId = 5;
                employeeAdjustment.FactoryId         = RecordInItemPurchase.FactoryId;
                employeeAdjustment.UnitPrice         = RecordInItemPurchase.UnitPrice;
                employeeAdjustment.Quantity          = NewQty;
                employeeAdjustment.EffectiveDate     = EffDate;
                employeeAdjustment.EnteredDate       = DateTime.Now;
                employeeAdjustment.Remarks           = Remarks;
                db.EmployeeAdjustments.Add(employeeAdjustment);
                db.SaveChanges();
                //employeeAdjustment.EmployeeId = EmpId;
                //employeeAdjustment.ItemId = ItemId;
                //employeeAdjustment.CashierId = RecordInItemPurchase.CashierId;
                //employeeAdjustment.EnteredUserId = Convert.ToInt32(Session["UserId"].ToString());
                //employeeAdjustment.TransactionTypeId = 3;
                //employeeAdjustment.FactoryId = RecordInItemPurchase.FactoryId;
                //employeeAdjustment.UnitPrice = RecordInItemPurchase.UnitPrice;
                //employeeAdjustment.Quantity = NewQty;
                //employeeAdjustment.EffectiveDate = EffDate;
                //employeeAdjustment.EnteredDate = DateTime.Now;
                //employeeAdjustment.Remarks = Remarks;
                //db.EmployeeAdjustments.Add(employeeAdjustment);
                //db.SaveChanges();

                EmployeePayment employeePayment = new EmployeePayment();
                employeePayment.EmployeeID    = EmpId;
                employeePayment.EffectiveDate = EffDate;
                employeePayment.Amount        = (RecordInItemPurchase.UnitPrice * (NewQty * -1));
                db.EmployeePayments.Add(employeePayment);
                db.SaveChanges();

                ItemPurchase itemPurchase = new ItemPurchase();
                itemPurchase.EffectiveDate = EffDate;
                itemPurchase.EmployeeId    = EmpId;
                itemPurchase.ItemId        = ItemId;
                itemPurchase.UnitPrice     = (RecordInItemPurchase.UnitPrice * -1);
                itemPurchase.Quantity      = NewQty;
                itemPurchase.FactoryId     = RecordInItemPurchase.FactoryId;
                itemPurchase.CashierId     = RecordInItemPurchase.CashierId;
                db.ItemPurchases.Add(itemPurchase);
                db.SaveChanges();

                ItemTransaction itemTransaction1 = new ItemTransaction();//If any other day- add plus value to transTyoe 2 and minus value to trans Type 3
                itemTransaction1.ItemID            = ItemId;
                itemTransaction1.Quantity          = (NewQty * -1);
                itemTransaction1.TransactionTypeId = 2;
                itemTransaction1.EffectiveDate     = EffDate;
                db.ItemTransactions.Add(itemTransaction1);
                db.SaveChanges();

                ItemTransaction itemTransaction2 = new ItemTransaction();
                itemTransaction2.ItemID            = ItemId;
                itemTransaction2.Quantity          = NewQty;
                itemTransaction2.TransactionTypeId = 3;
                itemTransaction2.EffectiveDate     = EffDate;
                db.ItemTransactions.Add(itemTransaction2);
                db.SaveChanges();

                var EmployeeDetails = db.Employees.Where(e => e.ID == EmpId).FirstOrDefault();
                EmployeeDetails.CreditBalance   = (EmployeeDetails.CreditBalance + ((RecordInItemPurchase.UnitPrice * -1) * NewQty));
                db.Entry(EmployeeDetails).State = EntityState.Modified;
                db.SaveChanges();

                success = "Adjustment Entered Succfully.";
            }
            else
            {
                error = "Error in Adjustment Entering. Please Start Again";
            }

            return(Json(new { error, success }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 9
0
    protected void grdprod_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataItem != null)
        {
            try
            {
                GridViewRow gr = e.Row;
                Label lblprodname = (Label)gr.FindControl("lblProdname");
                Label lblProdctg = (Label)gr.FindControl("lblProdctg");
                Label lblProdcomp = (Label)gr.FindControl("lblProdcomp");
                Label lblProdtype = (Label)gr.FindControl("lblProdtype");
                Label lblProdsupp = (Label)gr.FindControl("lblProdsupp");
                Label lblProdmedicinefor = (Label)gr.FindControl("lblProdmedicinefor");
                Label lblProdPcost = (Label)gr.FindControl("lblProdPcost");
                Label lblProdScost = (Label)gr.FindControl("lblProdScost");
                Label lblProdoffer = (Label)gr.FindControl("lblProdoffer");
                HiddenField HDFID = (HiddenField)gr.FindControl("HDFProdID");
                ImageButton IMGBTNcategoryisActive = (ImageButton)gr.FindControl("IMGBTNProdisActive");
                Image IMGProd = (Image)gr.FindControl("IMGProd");
                ProdTable u = e.Row.DataItem as ProdTable;
                objitem = null;
                objitem = ObjprodClass.GetItemsByID(Convert.ToInt32(u.ItemId));
                if (objitem != null)
                {
                    objitempurchase = ObjprodClass.GetItempurchaseByID(Convert.ToInt32(u.PurchaseId));
                    objitemsell = ObjprodClass.GetItemsellByID(Convert.ToInt32(u.SellId));
                    objprodctg = ObjprodClass.GetProdSubcategoryByID(Convert.ToInt32(u.CategoryId));
                    objprodtype = ObjprodClass.GetProdTypeByID(Convert.ToInt32(u.TypeId));
                    objprodsupple = ObjprodClass.GetProdsupplymentByID(Convert.ToInt32(u.SupplementId));
                    Objprodcomp = ObjprodClass.GetProdcompByID(Convert.ToInt32(u.CompanyId));
                    objmed = ObjprodClass.GetProdmedicineByID(Convert.ToInt32(u.MedicineForId));
                    objoffer = ObjprodClass.GetProdOfferByID(Convert.ToInt32(u.OfferId));
                    if (objitempurchase != null && objitemsell != null & objprodctg != null
                        && objprodtype != null & objprodsupple != null && Objprodcomp != null
                        & objmed != null && objoffer != null)
                    {
                        lblprodname.Text = objitem.ItemName.ToString().Trim();
                        lblProdctg.Text = objprodctg.SubCategoryName.ToString().Trim();
                        lblProdtype.Text = objprodtype.Name.ToString().Trim();
                        lblProdsupp.Text = objprodsupple.Name.ToString().Trim();
                        lblProdcomp.Text = Objprodcomp.CompanyName.ToString().Trim();
                        lblProdmedicinefor.Text = objmed.Name.ToString().Trim();
                        lblProdoffer.Text = objoffer.OfferPercent.ToString().Trim();
                        lblProdPcost.Text = objitempurchase.Cost.ToString().Trim();
                        lblProdScost.Text = objitemsell.Cost.ToString().Trim();
                        HDFID.Value = u.Id.ToString();
                        IMGProd.ImageUrl = u.ImageUrl;

                        if (u.IsActive == true)
                        {
                            IMGBTNcategoryisActive.ImageUrl = "~/images/tick.png";
                        }
                        else
                            IMGBTNcategoryisActive.ImageUrl = "~/images/close.jpg";
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }
Esempio n. 10
0
    protected void btnSubmitprod_Click(object sender, EventArgs e)
    {
        //objitem = null;
        //objitempurchase = null;
        //objitemsell = null;
        //objitem = null;
        switch (btnSubmitprod.Text)
        {
            case "Submit":
                if (file_upload.HasFile)
                {
                    objitem.ItemName = TXTprod.Text.ToString().Trim();
                    objitem.CreatedDate = DateTime.Now;
                    objitem.IsActive = true;
                    objitempurchase.Cost = Convert.ToInt64(txtitmpurchase.Text.Trim());
                    objitempurchase.IsActive = true;
                    objitempurchase.CreatedDate = DateTime.Now;
                    objitemsell.Cost = txtitmSell.Text.Trim();
                    objitemsell.Createdate = DateTime.Now;
                    objitemsell.CostVary = Convert.ToDecimal(Convert.ToInt32(txtitmSell.Text.Trim()) - Convert.ToInt32(txtitmpurchase.Text.Trim()));
                    //objprod.CategoryId = Convert.ToInt32(DrpCategory.SelectedItem.Value);
                    objprod.CategoryId = 10;
                    objprod.CompanyId = Convert.ToInt32(drpcompany.SelectedItem.Value);
                    objprod.TypeId = Convert.ToInt32(Drptype.SelectedItem.Value);
                    objprod.SupplementId = Convert.ToInt32(Drpsupplement.SelectedItem.Value);
                    objprod.MedicineForId = Convert.ToInt32(DrpmedicineFor.SelectedItem.Value);
                    if (DrpOffer.SelectedItem.Value == "0")
                    {
                        objprod.OfferId = 1;
                    }
                    else
                    {
                        objprod.OfferId = Convert.ToInt32(DrpOffer.SelectedItem.Value);
                    }
                    objprod.IsActive = true;
                    objprod.CreatedDate = DateTime.Now;
                    //Get Filename from fileupload control
                    string filename = Path.GetFileName(file_upload.PostedFile.FileName);
                    //Save images into Images folder
                    file_upload.SaveAs(Server.MapPath("~/images/Products/" + filename));
                    objprod.ImageUrl = "~/images/Products/" + filename;
                    Status = null;
                    Status = ObjprodClass.insertProd(objitem, objitempurchase, objitemsell, objprod);
                    if (Status == "Information Insert successfully.")
                    {
                        errorpopheaderprod.Visible = true;
                        errorpopheaderprod.Style.Add("display", "block");
                        errorpopheaderprod.Attributes.Add("class", "fk-msg-success");
                        errorpopheaderprod.InnerHtml = "ProductType Inserted successfully";
                        binddrpdowns();
                        BindProdGrid();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "aa", "jQuery(document).ready(function(){ShowPOPUPprodtable('false');});", true);
                    }
                    else
                    {
                        errorpopheaderprod.Visible = true;
                        errorpopheaderprod.Style.Add("display", "block");
                        errorpopheaderprod.Attributes.Add("class", "fk-err-all");
                        errorpopheaderprod.InnerHtml = Status;
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "aa", "jQuery(document).ready(function(){ShowPOPUPprodtable('true');});", true);
                    }


                }
                break;
            case "Update":
                if (ViewState["popupID"] != null && ViewState["popupID"] != "")
                {
                    objprod = null;
                    objitem = null;
                    objitempurchase = null;
                    objitemsell = null;
                    objprod = ObjprodClass.GetProdByID(Convert.ToInt32(ViewState["popupID"]));
                    objitem = ObjprodClass.GetItemsByID(Convert.ToInt32(objprod.ItemId));
                    objitempurchase = ObjprodClass.GetItempurchaseByID(Convert.ToInt32(objprod.PurchaseId));
                    objitemsell = ObjprodClass.GetItemsellByID(Convert.ToInt32(objprod.SellId));

                    objitem.ItemName = TXTprod.Text.ToString().Trim();
                    objitem.Modifieddate = DateTime.Now;
                    objitem.IsActive = true;
                    objitempurchase.Cost = Convert.ToInt64(txtitmpurchase.Text.Trim());
                    objitempurchase.IsActive = true;
                    objitempurchase.Modifieddate = DateTime.Now;
                    objitemsell.Cost = txtitmSell.Text.Trim();
                    objitemsell.ModifiedDate = DateTime.Now;
                    objitemsell.CostVary = Convert.ToDecimal(Convert.ToInt32(txtitmSell.Text.Trim()) - Convert.ToInt32(txtitmpurchase.Text.Trim()));
                    objprod.CategoryId = Convert.ToInt32(DrpCategory.SelectedItem.Value);
                    objprod.CompanyId = Convert.ToInt32(drpcompany.SelectedItem.Value);
                    objprod.TypeId = Convert.ToInt32(Drptype.SelectedItem.Value);
                    objprod.SupplementId = Convert.ToInt32(Drpsupplement.SelectedItem.Value);
                    objprod.MedicineForId = Convert.ToInt32(DrpmedicineFor.SelectedItem.Value);
                    if (DrpOffer.SelectedItem.Value == "0")
                    {
                        objprod.OfferId = 1;
                    }
                    else
                    {
                        objprod.OfferId = Convert.ToInt32(DrpOffer.SelectedItem.Value);
                    }
                    objprod.IsActive = true;
                    objprod.ModifiedDate = DateTime.Now;
                    //Get Filename from fileupload control
                    //string filename = Path.GetFileName(file_upload.PostedFile.FileName);
                    ////Save images into Images folder
                    
                    objprod.ImageUrl = "~/images/Products/" + TXTProdimg.Text;
                    file_upload.SaveAs(Server.MapPath("~/images/Products/" + TXTProdimg.Text));
                    Status = null;
                    Status = ObjprodClass.UpdateProd(objitem, objitempurchase, objitemsell, objprod);
                    if (Status == "Information Update successfully.")
                    {
                        errorpopheaderprod.Visible = true;
                        errorpopheaderprod.Style.Add("display", "block");
                        errorpopheaderprod.Attributes.Add("class", "fk-msg-success");
                        errorpopheaderprod.InnerHtml = "Product Updated successfully";
                        
                        BindProdGrid();
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "aa", "jQuery(document).ready(function(){ShowPOPUPupdateprodtable('true');});", true);
                    }
                    else
                    {
                        errorpopheaderprod.Visible = true;
                        errorpopheaderprod.Style.Add("display", "block");
                        errorpopheaderprod.Attributes.Add("class", "fk-err-all");
                        errorpopheaderprod.InnerHtml = Status;
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "aa", "jQuery(document).ready(function(){ShowPOPUPupdateprodtable('true');});", true);
                    }



                }
                break;
        }
    }
Esempio n. 11
0
        // PUT: api/ItemPurchase/5
        //UPDATE
        public HttpResponseMessage Put(int id, [FromBody] ItemPurchase ItemPurchase, string token)
        {
            try
            {
                using (CompanyPosDBContext database = new CompanyPosDBContext())
                {
                    SessionController sessionController = new SessionController();
                    Session           session           = sessionController.Autenticate(token);

                    if (session != null)
                    {
                        //Save last  update
                        session.LastUpdate = DateTime.Now;
                        var currentItemPurchase = database.ItemPurchases.ToList().FirstOrDefault(x => x.ID == id && (x.StoreID == session.StoreID));
                        if (currentItemPurchase != null)
                        {
                            currentItemPurchase.Quantity   = ItemPurchase.Quantity;
                            currentItemPurchase.TotalPrice = ItemPurchase.TotalPrice;
                            currentItemPurchase.Status     = ItemPurchase.Status ?? currentItemPurchase.Status;
                            currentItemPurchase.Notes      = ItemPurchase.Notes ?? currentItemPurchase.Notes;
                            //SAVE ACTIVITY
                            database.UserActivities.Add(new UserActivity()
                            {
                                StoreID = session.StoreID
                                ,
                                UserID = session.UserID
                                ,
                                Activity = "CREATE ItemPurchase",
                                Date     = DateTime.Now
                            });
                            database.SaveChanges();
                            var message = Request.CreateResponse(HttpStatusCode.OK, "Update Success");
                            return(message);
                        }
                        else
                        {
                            var message = Request.CreateResponse(HttpStatusCode.OK, "ItemPurchase Not found");
                            return(message);
                        }
                    }
                    else
                    {
                        var message = Request.CreateResponse(HttpStatusCode.MethodNotAllowed, "No asociated Session");
                        return(message);
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, dbEx));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Esempio n. 12
0
        public ActionResult SavePurchasedItems()
        {
            ItemPurchase    itemPurchase    = new ItemPurchase();
            ItemTransaction itemTransaction = new ItemTransaction();
            EmployeePayment employeePayment = new EmployeePayment();

            int     employeeId      = Convert.ToInt32(Session["EmployeeId"].ToString());
            var     employeeBalance = db.Employees.Where(e => e.ID == employeeId).FirstOrDefault();
            decimal?OrderAmount     = purchaseItems.Sum(i => (i.UnitPrice * i.ItemQty));
            decimal?EmployeeBalanceAfterPurchase = (employeeBalance.CreditBalance - OrderAmount);

            string ParamValue      = "0";
            string commonThreshold = "CommonThreshold";
            var    confTbl         = db.Configurations.Where(c => c.ParamName == commonThreshold).FirstOrDefault();

            if (confTbl.ParamValue == "True")
            {
                string minPayment = "MinPayment";
                var    min        = db.Configurations.Where(c => c.ParamName == minPayment).FirstOrDefault();
                ParamValue = min.ParamValue;
            }
            else
            {
                ParamValue = Session["EmployeeMinValue"].ToString();
            }

            if (EmployeeBalanceAfterPurchase > Convert.ToDecimal(ParamValue))
            {
                foreach (var ItemsSelectedToPurchase in purchaseItems)
                {
                    var itemBalance     = db.Items.Where(i => i.ID == ItemsSelectedToPurchase.ItemId).FirstOrDefault();
                    var selectedItemQty = purchaseItems.Where(i => i.ItemId == ItemsSelectedToPurchase.ItemId).Sum(i => i.ItemQty);

                    if (itemBalance.DaySellingQty >= selectedItemQty)
                    {
                        // Add record to Item Purchase Table
                        itemPurchase.EffectiveDate = DateTime.Now;
                        itemPurchase.EmployeeId    = employeeId;
                        itemPurchase.ItemId        = ItemsSelectedToPurchase.ItemId;
                        itemPurchase.UnitPrice     = ItemsSelectedToPurchase.UnitPrice;
                        itemPurchase.Quantity      = ItemsSelectedToPurchase.ItemQty;
                        itemPurchase.FactoryId     = Convert.ToInt32(Session["factoryId"].ToString());
                        itemPurchase.CashierId     = Convert.ToInt32(Session["UserId"].ToString());
                        db.ItemPurchases.Add(itemPurchase);
                        db.SaveChanges();

                        // Add records to Item Transaction Table
                        itemTransaction.ItemID            = ItemsSelectedToPurchase.ItemId;
                        itemTransaction.Quantity          = ((ItemsSelectedToPurchase.ItemQty) * -1);
                        itemTransaction.TransactionTypeId = 2;
                        itemTransaction.EffectiveDate     = DateTime.Now;
                        db.ItemTransactions.Add(itemTransaction);
                        db.SaveChanges();

                        //Add Records to Employee Payment Table
                        employeePayment.EmployeeID    = employeeId;
                        employeePayment.EffectiveDate = DateTime.Now;
                        employeePayment.Amount        = ((ItemsSelectedToPurchase.UnitPrice * ItemsSelectedToPurchase.ItemQty) * -1);
                        db.EmployeePayments.Add(employeePayment);
                        db.SaveChanges();

                        //Update Day Selling Quantity in Items Table
                        var changedRec = db.Items.Where(i => i.ID == ItemsSelectedToPurchase.ItemId).FirstOrDefault();
                        changedRec.DaySellingQty   = changedRec.DaySellingQty - ItemsSelectedToPurchase.ItemQty;
                        db.Entry(changedRec).State = EntityState.Modified;
                        db.SaveChanges();

                        //Reduce Balance from Employee Table
                        var reduceEmployeeBalance = db.Employees.Where(e => e.ID == employeeId).FirstOrDefault();
                        reduceEmployeeBalance.CreditBalance   = reduceEmployeeBalance.CreditBalance - ((ItemsSelectedToPurchase.UnitPrice * ItemsSelectedToPurchase.ItemQty));
                        db.Entry(reduceEmployeeBalance).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        var userId = Convert.ToInt32(Session["UserId"].ToString());
                        var items  = purchaseItems.Where(e => e.EmployeeID == userId).ToList();
                        items.Clear();
                        TempData["NoItems"]   = "NOT ENOUGH " + ItemsSelectedToPurchase.ItemName + " FOR SALE";
                        Session["OrderPrice"] = purchaseItems.Where(p => p.EmployeeID == userId).Sum(p => p.ItemTotal);
                        decimal existingBalance = Convert.ToDecimal(Session["EmployeeExistingBalance"].ToString());
                        decimal OrderPrice      = Convert.ToDecimal(Session["OrderPrice"].ToString());
                        Session["EmployeeBalance"] = existingBalance - OrderPrice;
                        ViewBag.SelectedItems      = purchaseItems;
                        return(PartialView("_getItemQtytoPurchase", ViewBag.SelectedItems));
                    }
                }
                purchaseItems.Clear();
                return(RedirectToAction("MPOS"));
            }
            else
            {
                purchaseItems.Clear();
                TempData["NoBalance"] = "BALANCE NOT ENOUGH TO PURCHASE THE ITEM";
                ViewBag.SelectedItems = purchaseItems;
                return(PartialView("_getItemQtytoPurchase", ViewBag.SelectedItems));
            }
        }
 protected void rptProdByctg_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         ProdTable Prod = e.Item.DataItem as ProdTable;
         LinkButton lnkprodName = (LinkButton)e.Item.FindControl("lnkprodName");
         Image prodImgCtg = (Image)e.Item.FindControl("prodImgCtg");
         Label lblitmsell = (Label)e.Item.FindControl("lblitmsell");
         Label lblitmpurchase = (Label)e.Item.FindControl("lblitmpurchase");
         objitem = null;
         objitem = ObjprodClass.GetItemsByID(Convert.ToInt32(Prod.ItemId));
         objitemsell = ObjprodClass.GetItemsellByID(Convert.ToInt32(Prod.SellId));
         objitempurchase = ObjprodClass.GetItempurchaseByID(Convert.ToInt32(Prod.PurchaseId));
         objbrandID.Add(Convert.ToInt32(Prod.CompanyId));
         lnkprodName.Text = objitem.ItemName;
         prodImgCtg.ImageUrl = Prod.ImageUrl;
         lblitmsell.Text = objitemsell.Cost;
         lblitmpurchase.Text = objitempurchase.Cost.ToString();
     }
 }
 public ItemPurchase Update(ItemPurchase rootToUpdate)
 {
     throw new System.NotImplementedException();
 }
 public void Delete(ItemPurchase rootToDelete)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 16
0
 protected void IMGBTNProdisActive_Click(object sender, ImageClickEventArgs e)
 {
     ImageButton lnk = (ImageButton)sender;
     int userid = Convert.ToInt32(lnk.CommandArgument);
     objitem = null;
     objprod = null;
     objprod = ObjprodClass.GetProdByID(userid);
     objitem = ObjprodClass.GetItemsByID(Convert.ToInt32(objprod.ItemId));
     objitempurchase = ObjprodClass.GetItempurchaseByID(Convert.ToInt32(objprod.PurchaseId));
     objitemsell = ObjprodClass.GetItemsellByID(Convert.ToInt32(objprod.SellId));
     if (objitem != null)
     {
         TXTprod.Text = objitem.ItemName;
         //DrpCategory.SelectedValue = objprod.CategoryId.ToString();
         drpcompany.SelectedValue = objprod.CompanyId.ToString();
         DrpmedicineFor.SelectedValue = objprod.MedicineForId.ToString();
         DrpOffer.SelectedValue = objprod.OfferId.ToString();
         Drpsupplement.SelectedValue = objprod.SupplementId.ToString();
         Drptype.SelectedValue = objprod.TypeId.ToString();
         txtitmpurchase.Text = objitempurchase.Cost.ToString();
         txtitmSell.Text = objitemsell.Cost.ToString();
         string url = objprod.ImageUrl.ToString().Trim();
         string[] spliturl = url.Split('/');
         TXTProdimg.Text = spliturl[2];
         errorpopheaderprod.Style.Add("display", "none");
         //DIVIsActive.Style.Add("display", "block");
         btnSubmitprod.Text = "Update";
         ViewState["popupID"] = userid.ToString();
         ScriptManager.RegisterStartupScript(this, typeof(Page), "aa", "jQuery(document).ready(function(){ShowPOPUPprodUpdate('true');});", true);
     }
 }
Esempio n. 17
0
        public async Task <ItemPurchaseResponseDTO> TryPurchaseItem(ItemPurchaseRequestDTO purchaseRequest)
        {
            var purchase = new ItemPurchase(purchaseRequest);

            do
            {
                if (purchaseRequest.Quantity <= 0)
                {
                    purchase.Result = GoldExpenseResult.BadRequest;
                    break;
                }

                var item = await _itemsRepo.GetItemAsync(purchaseRequest.ItemName);

                if (item == null || item.MaxQuantity == 0)
                {
                    purchase.Result = GoldExpenseResult.ItemNotFound;
                    break;
                }

                purchase.Item             = item;
                purchase.ExpenseRequested = item.Cost * purchase.RequestedQuantity;

                var character = await _characterRepo.GetCharacterItemsAsync(purchase.CharacterId);

                if (character == null)
                {
                    purchase.Result = GoldExpenseResult.CharacterNotFound;
                    break;
                }

                var characterItem = character.Items.FirstOrDefault(i => i.Item.Name == item.Name);

                if (item.MaxQuantity > 0 && purchase.RequestedQuantity + characterItem?.Quantity > item.MaxQuantity)
                {
                    purchase.Result = GoldExpenseResult.ReachedItemMaxQuantity;
                    break;
                }

                purchase = (ItemPurchase) await TryExpendGoldInternal(purchase, saveChanges : false);

                if (purchase.Result == GoldExpenseResult.Authorized)
                {
                    purchase.Item = item;
                    purchase.PurchasedQuantity = purchase.RequestedQuantity;

                    if (characterItem == null)
                    {
                        character.Items.Add(new InventoryItem(purchase.Item, purchase.PurchasedQuantity, false));
                    }
                    else
                    {
                        characterItem.Quantity += purchase.PurchasedQuantity;
                    }

                    await _characterRepo.SaveChangesAsync();
                }
            } while (false);

            return(_mapper.Map <ItemPurchaseResponseDTO>(purchase));
        }