//protected void GridData_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    // Reservation ID, MaterialName,Quantity
        //    //ReservedDate,Note,UserName,
        //    //Paid,PaidAmount,ReservedStock,
        //    //StockOnHand,MaterialID,StoreID
        //    GridViewRow gv = GridData.SelectedRow;
        //    int ReservedID = Convert.ToInt32(gv.Cells[1].Text.ToString());
        //    var resmaterial = db.ReservedMaterials.Where(x => x.ID == ReservedID).FirstOrDefault();
        //    //string name = gv.Cells[2].Text;
        //    string name = resmaterial.MaterialInStock1.Material.MaterialName;

        //    //decimal QTY = Convert.ToDecimal(gv.Cells[3].Text);
        //    decimal QTY = Convert.ToDecimal(resmaterial.Quantity);
        //    string ReservationNote = resmaterial.Note;
        //    //string ReservationNote = gv.Cells[5].Text.ToString();
        //    decimal pai = Convert.ToDecimal(resmaterial.PaidAmount);

        //    //decimal pai = 0;
        //    if(gv.Cells[7].Text !=" ")
        //    {
        //        pai = Convert.ToDecimal(gv.Cells[8].Text);
        //    }


        //    //decimal reserved = Convert.ToDecimal(gv.Cells[9].Text);
        //    decimal reserved = Convert.ToDecimal(resmaterial.MaterialInStock1.ReservedStock);
        //    //decimal stock = Convert.ToDecimal(gv.Cells[10].Text);
        //    decimal stock = Convert.ToDecimal(resmaterial.MaterialInStock1.StockOnHand);
        //    //int materialid = Convert.ToInt32(gv.Cells[11].Text);
        //    int materialid = Convert.ToInt32(resmaterial.MaterialInStock1.MaterialID);
        //    //int storeid = Convert.ToInt32(gv.Cells[12].Text);
        //    int storeid = Convert.ToInt32(resmaterial.MaterialInStock1.StoreID);

        //    var item = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid ).FirstOrDefault();
        //    if (pai != 0)
        //    {
        //        decimal oldstock =  Convert.ToDecimal(item.StockOnHand);
        //        decimal newstock = oldstock + QTY;
        //        item.StockOnHand = newstock;
        //        LogSalesReservation(oldstock, newstock, item.ID, false);
        //    }

        //    item.ReservedStock = reserved - QTY;
        //    db.SaveChanges();

        //    //var materilainstock = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();

        //    StockLogger st = new StockLogger();
        //    st.MaterialInStock = item.ID;
        //    st.OldStock = stock;
        //    if (pai != 0 )
        //        st.NewStock = stock + reserved;
        //    else
        //        st.NewStock = stock;
        //    st.OldReservedStock = reserved;
        //    st.NewReservedStock = reserved - QTY;
        //    st.Notes = "Reservation Cancelled By " + User.Identity.Name;

        //    db.StockLoggers.Add(st);
        //    db.SaveChanges();

        //    //var resmaterial = db.ReservedMaterials.Where(x => x.MaterialInStock == item.ID && x.PaidAmount == pai && x.Quantity == QTY && x.Note == ReservationNote ).FirstOrDefault();

        //    resmaterial.IsDeleted = true;
        //    db.SaveChanges();

        //    Logger log = new Logger();
        //    log.Action ="Reservation of " + name + " in Store " + storeid.ToString() + " with Quantity "+ QTY.ToString()+" is cancelled ";
        //    log.ActionDate = DateTime.Now;
        //    log.UserName = User.Identity.Name;
        //    log.ActionType = "Cancel Reservation";
        //    db.Loggers.Add(log);
        //    db.SaveChanges();

        //    GridData.DataBind();
        //}

        protected void GridData_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow gv               = GridData.SelectedRow;
            int         ReservedID       = Convert.ToInt32(gv.Cells[1].Text.ToString());
            var         ReservedMaterial = db.ReservedMaterials.Where(x => x.ID == ReservedID).FirstOrDefault();
            string      name             = ReservedMaterial.MaterialInStock1.Material.MaterialName;
            decimal     QTY              = Convert.ToDecimal(ReservedMaterial.Quantity);
            string      ReservationNote  = ReservedMaterial.Note;
            decimal     PaidAmount       = Convert.ToDecimal(ReservedMaterial.PaidAmount);
            decimal     TotalReserved    = Convert.ToDecimal(ReservedMaterial.MaterialInStock1.ReservedStock);
            decimal     stock            = Convert.ToDecimal(ReservedMaterial.MaterialInStock1.StockOnHand);
            int         materialid       = Convert.ToInt32(ReservedMaterial.MaterialInStock1.MaterialID);
            int         storeid          = Convert.ToInt32(ReservedMaterial.MaterialInStock1.StoreID);

            var item = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();

            if (PaidAmount != 0)
            {
                decimal oldstock = Convert.ToDecimal(item.StockOnHand);
                decimal newstock = oldstock + QTY;
                item.StockOnHand = newstock;
                LogSalesReservation(oldstock, newstock, item.ID, false);
            }

            item.ReservedStock = TotalReserved - QTY;
            db.SaveChanges();

            StockLogger st = new StockLogger();

            st.MaterialInStock = item.ID;
            st.OldStock        = stock;
            if (PaidAmount != 0)
            {
                st.NewStock = stock + QTY;
            }
            else
            {
                st.NewStock = stock;
            }
            st.OldReservedStock = TotalReserved;
            st.NewReservedStock = TotalReserved - QTY;
            st.Notes            = "Cancel Reservation of Material ( " + item.Material.MaterialName.ToString() + " ) In Store ( " + item.Store.StoreName.ToString() + " ) Cancelled By " + User.Identity.Name;

            db.StockLoggers.Add(st);
            db.SaveChanges();

            ReservedMaterial.IsDeleted = true;
            db.SaveChanges();

            Logger log = new Logger();

            log.Action     = "Cancel Reservation of Material ( " + item.Material.MaterialName.ToString() + " ) in Store ( " + item.Store.StoreName.ToString() + " ) with Quantity " + QTY.ToString() + " is cancelled ";
            log.ActionDate = DateTime.Now;
            log.UserName   = User.Identity.Name;
            log.ActionType = "Cancel Reservation";
            db.Loggers.Add(log);
            db.SaveChanges();

            GridData.DataBind();
        }
Ejemplo n.º 2
0
        private void AddNewStock(int storeid, int materialid, decimal QTY)
        {
            try
            {
                var     MS = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();
                decimal oldstock, newstock;
                oldstock       = Convert.ToDecimal(MS.StockOnHand);
                newstock       = oldstock + QTY;
                MS.StockOnHand = newstock;
                db.SaveChanges();

                Logger log = new Logger();
                log.UserName   = User.Identity.Name;
                log.Action     = "Material " + MS.Material.MaterialName.ToString() + " Stock is now increased From " + oldstock.ToString() + " To " + newstock.ToString();
                log.ActionType = "Item Addition";
                log.ActionDate = DateTime.Now;
                db.Loggers.Add(log);
                db.SaveChanges();

                StockLogger stLog = new StockLogger();
                stLog.ActionDate      = DateTime.Now;
                stLog.MaterialInStock = MS.ID;
                stLog.NewStock        = newstock;
                stLog.OldStock        = oldstock;
                stLog.UserName        = User.Identity.Name;
                stLog.Notes           = "Material " + MS.Material.MaterialName.ToString() + " stock increased in Container " + txtContainerNumber.Value.ToString();
                db.StockLoggers.Add(stLog);
                db.SaveChanges();

                MaterialHistory MH = new MaterialHistory();
                MH.MaterialID      = materialid;
                MH.StoreID         = storeid;
                MH.NewStock        = newstock;
                MH.OldStock        = oldstock;
                MH.TransactionName = "Addition";
                MH.UserName        = User.Identity.Name;
                MH.ActionDate      = DateTime.Now;
                MH.Note            = "Material " + MS.Material.MaterialName.ToString() + " stock increased in Container " + txtContainerNumber.Value.ToString();
                db.MaterialHistories.Add(MH);
                db.SaveChanges();

                lblAddItemErr.Text      = "Item Entered Successfully";
                lblAddItemErr.Visible   = true;
                lblAddItemErr.ForeColor = Color.Green;
            }
            catch (Exception ex)
            {
                lblAddItemErr.Text      = "Error in new stock addition " + ex.InnerException.Message;
                lblAddItemErr.Visible   = true;
                lblAddItemErr.ForeColor = Color.Green;
            }
        }
        private void MaterialStock()
        {
            var MaterialID    = Convert.ToInt32(txtMaterialID.Value);
            var MaterialStore = Convert.ToInt32(txtStore.Value);
            var MaterialStock = Convert.ToDecimal(txtCurrentStock.Value);
            var newstock      = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value);
            var item          = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore).FirstOrDefault();

            item.StockOnHand -= Convert.ToDecimal(txtRequestedStock.Value);
            db.SaveChanges();

            var ss = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == MaterialStore).FirstOrDefault();

            StockLogger stlog = new StockLogger();

            stlog.MaterialInStock = ss.ID;
            stlog.OldStock        = MaterialStock;
            stlog.ActionDate      = DateTime.Now;
            stlog.UserName        = User.Identity.Name;
            stlog.NewStock        = MaterialStock - Convert.ToDecimal(txtRequestedStock.Value);
            stlog.Notes           = "Order Number " + LblOrderID.Text.ToString() + "   For Customer " + Customer.SelectedItem.ToString();

            db.StockLoggers.Add(stlog);
            db.SaveChanges();

            Logger log = new Logger();

            log.Action     = " Material Order (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from " + MaterialStock.ToString() + " to " + newstock.ToString() + " For Customer " + Customer.SelectedItem.ToString();
            log.ActionDate = DateTime.Now;
            log.ActionType = "Material Order";
            log.UserName   = User.Identity.Name;

            db.Loggers.Add(log);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.ActionDate      = DateTime.Now;
            MH.MaterialID      = MaterialID;
            MH.StoreID         = MaterialStore;
            MH.TransactionName = "Sales Material";
            MH.UserName        = User.Identity.Name;
            MH.NewStock        = newstock;
            MH.OldStock        = MaterialStock;
            MH.Note            = "Material " + item.Material.MaterialName.ToString() + " is now invoiced in Store " + MaterialStore.ToString() + " In order ID " + LblOrderID.Text.ToString();
            db.MaterialHistories.Add(MH);
            db.SaveChanges();
        }
        private void MaterialReturn(int materialid, string name, int orderid, decimal QTY, decimal height, decimal width, string store)
        {
            var st      = db.Stores.Where(x => x.StoreName == store).FirstOrDefault();
            int storeid = st.ID;
            var mat     = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();

            if (mat != null)
            {
                decimal oldstock = decimal.Parse(mat.StockOnHand.ToString());
                decimal newstock = oldstock + QTY;

                mat.StockOnHand = newstock;
                db.SaveChanges();

                StockLogger stlog = new StockLogger();
                stlog.ActionDate      = DateTime.Now;
                stlog.UserName        = User.Identity.Name;
                stlog.MaterialInStock = mat.ID;
                stlog.NewStock        = newstock;
                stlog.OldStock        = oldstock;
                stlog.Notes           = "Return of Good Material ( " + name + " ) In store ( " + store + " ) from Order  ( " + orderid + " )";

                db.StockLoggers.Add(stlog);
                db.SaveChanges();

                Logger log = new Logger();
                log.ActionType = "Material Return";
                log.ActionDate = DateTime.Now;
                log.UserName   = User.Identity.Name;
                log.Action     = "Return of Good List of Material ( " + name + " ) In store ( " + store + " ) from Order  ( " + orderid + " )";

                db.Loggers.Add(log);
                db.SaveChanges();

                MaterialHistory MH = new MaterialHistory();
                MH.ActionDate      = DateTime.Now;
                MH.MaterialID      = materialid;
                MH.StoreID         = storeid;
                MH.TransactionName = "Return Material";
                MH.UserName        = User.Identity.Name;
                MH.NewStock        = newstock;
                MH.OldStock        = oldstock;
                MH.Note            = "Material ( " + name + " ) is now returned in Store ( " + storeid.ToString() + " ) From order ( " + orderid + " ) ";
                db.MaterialHistories.Add(MH);
                db.SaveChanges();
            }
        }
        private void LogAction(decimal?oldstock, decimal?oldreserved, decimal?newstock, decimal?newreserved, int materialinstock)
        {
            try
            {
                StockLogger st = new StockLogger();
                st.MaterialInStock  = materialinstock;
                st.OldStock         = oldstock;
                st.NewStock         = newstock;
                st.OldReservedStock = oldreserved;
                st.NewReservedStock = newreserved;
                st.UserName         = User.Identity.Name;
                st.Notes            = txtNotes.Value;

                db.StockLoggers.Add(st);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                lblError.Text      = "Error in Stock Log " + ex.InnerException.InnerException.Message;
                lblError.ForeColor = Color.Red;
                lblError.Visible   = true;
            }
        }
        protected void btnUpdateMaterial_Click(object sender, EventArgs e)
        {
            var materialid = Convert.ToInt32(dsMaterials.SelectedValue);
            var storeid    = Convert.ToInt32(dsStores.SelectedValue);

            var     Ms             = db.MaterialInStocks.Where(x => x.MaterialID == materialid && x.StoreID == storeid).FirstOrDefault();
            decimal OldStock       = Convert.ToDecimal(Ms.StockOnHand.ToString());
            var     oldsafetystock = Ms.SafetyStock.ToString();
            var     oldreserved    = Ms.ReservedStock.ToString();
            decimal newstock       = Convert.ToDecimal(txtstock.Value);
            string  oldname        = Ms.Material.MaterialName.ToString();
            string  newname        = itemname.Value.ToString();
            int     oldtype        = Convert.ToInt32(Ms.Material.TypeID);
            string  oldtypename    = Ms.Material.SubCategory.SubCategoryName.ToString();
            int     newtype        = Convert.ToInt32(materialcategory.SelectedValue);

            try
            {
                Ms.ReservedStock = Convert.ToDecimal(txtReservedStock.Value);
                Ms.StockOnHand   = Convert.ToDecimal(txtstock.Value);
                Ms.SafetyStock   = Convert.ToDecimal(SafetyStock.Value);
                if (oldname != newname)
                {
                    Ms.Material.MaterialName = newname;
                }

                if (oldtype != newtype)
                {
                    Ms.Material.TypeID = newtype;
                }

                db.SaveChanges();
                dsMaterials.DataBind();
                lblError.Text      = "The Material Data Updated Successfully";
                lblError.Visible   = true;
                lblError.ForeColor = System.Drawing.Color.Green;

                StockLogger stLog = new StockLogger();
                stLog.OldStock = OldStock;
                stLog.NewStock = Convert.ToDecimal(txtstock.Value);

                stLog.OldSafetyStock = Convert.ToDecimal(oldsafetystock);
                stLog.newSafetyStock = Convert.ToDecimal(SafetyStock.Value);

                stLog.OldReservedStock = Convert.ToDecimal(oldreserved);
                stLog.NewReservedStock = Convert.ToDecimal(txtReservedStock.Value);

                stLog.UserName   = User.Identity.Name;
                stLog.ActionDate = DateTime.Now;

                stLog.MaterialInStock = Ms.ID;
                db.StockLoggers.Add(stLog);
                db.SaveChanges();


                Logger Log = new Logger();
                Log.ActionType = "Update Material";
                string Action = "Material ( " + Ms.Material.MaterialName + " ) Stock in Store ( " + Ms.Store.StoreName + " ) is ( " + txtstock.Value.ToString() + " ) And Safety Stock is ( " + SafetyStock.Value.ToString() + " ) ";
                if (oldname == newname)
                {
                    Log.Action = Action;
                }
                else
                {
                    Log.Action = Action + " and Material Name Changed From ( '" + oldname + "' ) To ( '" + newname + "' ) ";
                }

                if (oldtype != newtype)
                {
                    Log.Action += " and Category changed from ( '" + oldtypename + "' ) To ('" + materialcategory.SelectedItem.ToString() + "') )";
                }


                Log.UserName   = User.Identity.Name;
                Log.ActionDate = DateTime.Now;
                db.Loggers.Add(Log);
                db.SaveChanges();

                if (OldStock != newstock)
                {
                    MaterialHistory MH = new MaterialHistory();
                    MH.ActionDate      = DateTime.Now;
                    MH.MaterialID      = materialid;
                    MH.StoreID         = storeid;
                    MH.TransactionName = "Update Stock";
                    MH.UserName        = User.Identity.Name;
                    MH.NewStock        = Convert.ToDecimal(txtstock.Value);
                    MH.OldStock        = Convert.ToDecimal(OldStock);
                    MH.Note            = "Material ( " + Ms.Material.MaterialName + " ) Stock is now updated in Store " + Ms.Store.StoreName.ToString();
                    db.MaterialHistories.Add(MH);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                lblError.Text      = "Error in Update Material Data " + ex.Message;
                lblError.Visible   = true;
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
Ejemplo n.º 7
0
        private void MaterialStock()
        {
            var MaterialID    = Convert.ToInt32(txtMaterialID.Value);
            var StoreFrom     = Convert.ToInt32(FromStore.SelectedValue);
            var MaterialStock = Convert.ToDecimal(txtCurrentStock.Value);
            var store2        = Convert.ToInt32(ToStore.SelectedValue);
            //Update Current Stock Of From Store
            var item      = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == StoreFrom).FirstOrDefault();
            var stock1    = item.StockOnHand;
            var newstock1 = item.StockOnHand - Convert.ToDecimal(txtRequestedStock.Value);

            item.StockOnHand -= Convert.ToDecimal(txtRequestedStock.Value);
            db.SaveChanges();

            StockLogger stlog = new StockLogger();

            stlog.MaterialInStock = item.ID;
            stlog.OldStock        = stock1;
            stlog.NewStock        = newstock1;
            stlog.UserName        = User.Identity.Name;
            stlog.ActionDate      = DateTime.Now;
            stlog.Notes           = "Transfer Number " + LblTransferID.Text.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            db.StockLoggers.Add(stlog);

            Logger log2 = new Logger();

            log2.Action = "Transfer Number ( " + LblTransferID.Text + " ) of  Material (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from ( "
                          + stock1.ToString() + " ) to ( " + newstock1.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            log2.ActionDate = DateTime.Now;
            log2.ActionType = "Material Transfer";
            log2.UserName   = User.Identity.Name;

            db.Loggers.Add(log2);
            db.SaveChanges();

            MaterialHistory MH = new MaterialHistory();

            MH.MaterialID      = MaterialID;
            MH.StoreID         = Convert.ToInt32(FromStore.SelectedValue);
            MH.OldStock        = stock1;
            MH.NewStock        = newstock1;
            MH.ActionDate      = DateTime.Now;
            MH.UserName        = User.Identity.Name;
            MH.Note            = " Material Transfer No ( " + LblTransferID.Text.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            MH.TransactionName = "Material Transfer";
            db.MaterialHistories.Add(MH);
            db.SaveChanges();

            //To Store Actions

            var itemstore2  = db.MaterialInStocks.Where(x => x.MaterialID == MaterialID && x.StoreID == store2).FirstOrDefault();
            var storestock  = itemstore2.StockOnHand;
            var storestock2 = storestock + Convert.ToDecimal(txtRequestedStock.Value);

            itemstore2.StockOnHand = storestock2;
            db.SaveChanges();

            //stockLogger
            StockLogger stlog2 = new StockLogger();

            stlog2.MaterialInStock = itemstore2.ID;
            stlog2.OldStock        = storestock;
            stlog2.NewStock        = storestock2;
            stlog2.UserName        = User.Identity.Name;
            stlog2.ActionDate      = DateTime.Now;
            stlog2.Notes           = "Transfer Number " + LblTransferID.Text.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            db.StockLoggers.Add(stlog2);
            db.SaveChanges();


            //Insert Logger
            Logger log = new Logger();

            log.Action = "Transfer Number ( " + LblTransferID.Text + " ) of  Material (" + item.Material.MaterialName.ToString() + " ) , The Stock changed from "
                         + storestock.ToString() + " to " + storestock2.ToString() + " From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            log.ActionDate = DateTime.Now;
            log.ActionType = "Material Transfer";
            log.UserName   = User.Identity.Name;

            db.Loggers.Add(log);
            db.SaveChanges();


            MaterialHistory MH2 = new MaterialHistory();

            MH2.MaterialID      = MaterialID;
            MH2.StoreID         = Convert.ToInt32(ToStore.SelectedValue);
            MH2.OldStock        = storestock;
            MH2.NewStock        = storestock2;
            MH2.ActionDate      = DateTime.Now;
            MH2.UserName        = User.Identity.Name;
            MH2.Note            = " Material Transfer No ( " + LblTransferID.Text.ToString() + " ) From Store ( " + FromStore.SelectedItem.ToString() + " ) To Store ( " + ToStore.SelectedItem.ToString() + " )";
            MH2.TransactionName = "Material Transfer";
            db.MaterialHistories.Add(MH2);
            db.SaveChanges();
        }