Ejemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        DataTable         productList = (DataTable)Page.ViewState["ProductList"];
        Inventory         inv         = new Inventory();
        Product           prod        = new Product();
        Deposit           dep         = new Deposit();
        InventoryMoviment mov         = new InventoryMoviment();
        InventoryManager  iManager    = new InventoryManager(this);
        CompanyManager    cManager    = new CompanyManager(this);

        if (productList.Rows.Count < 1)
        {
            ShowError("Deve haver pelo menos uma linha com dados do produto.");
            return;
        }
        foreach (DataRow row in productList.Rows)
        {
            if (row.Table.Rows.IndexOf(row) != 0)
            {
                if (!CheckIfCanSale(Convert.ToInt16(row["ProductId"]), Convert.ToInt16(row["Quantity"])))
                {
                    ShowError("O estoque da linha <b>" + Convert.ToInt16((row.Table.Rows.IndexOf(row)) + 1).ToString() + "</b> não pode ficar negativo<br />");
                    return;
                }
            }
        }



        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);

        foreach (DataRow row in productList.Rows)
        {
            inv.CompanyId = Company.CompanyId;
            inv.DepositId = dep.DepositId;
            inv.ProductId = Convert.ToInt16(row["ProductId"]);
            inv.Quantity  = Convert.ToInt16(row["Quantity"]);

            mov.CompanyId            = inv.CompanyId;
            mov.DepositId            = inv.DepositId;
            mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
            mov.ModifiedDate         = DateTime.Now;
            mov.ProductId            = inv.ProductId;
            mov.Quantity             = inv.Quantity;

            iManager.InventoryDrop(inv, 0, (int)DropType.Transfer, null);
            iManager.InsertStockMovement(inv, mov, inv.Quantity, User.Identity.UserId);
        }
        InSuccess();
    }
    protected void grdReceive_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        InventoryManager invManager = new InventoryManager(this);
        InventoryMoviment movement = new InventoryMoviment();

        int movementId = Convert.ToInt16(grdReceive.DataKeys[e.RowIndex]["InventoryMovementId"]);
        int destinationCompanyId = Convert.ToInt16(grdReceive.DataKeys[e.RowIndex]["CompanyDestinationId"]);

        invManager.RefuseMovement(movementId);

        grdReceive.DataBind();
        e.Cancel = true;
    }
Ejemplo n.º 3
0
    protected void grdReceive_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        InventoryManager  invManager = new InventoryManager(this);
        InventoryMoviment movement   = new InventoryMoviment();

        int movementId           = Convert.ToInt16(grdReceive.DataKeys[e.RowIndex]["InventoryMovementId"]);
        int destinationCompanyId = Convert.ToInt16(grdReceive.DataKeys[e.RowIndex]["CompanyDestinationId"]);

        invManager.RefuseMovement(movementId);

        grdReceive.DataBind();
        e.Cancel = true;
    }
Ejemplo n.º 4
0
        /// <summary>
        /// this method execute all functions Necessary to Moviment a Product,
        /// the functions are InsertHistory(insert one row in InventoryHistory),InventoryDrop(Drop the product from inventory)
        ///  and InventoryMoviments(insert onr row in InventoryMoviments)
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="inventoryMoviment"></param>
        /// <param name="quantity"></param>
        public void InsertStockMovement(Inventory inventory, InventoryMoviment inventoryMoviment, Int32 quantity,
                                        Int32 userId)
        {
            Inventory inventoryData;

            //insert one row in InventoryHistory
            inventoryData = GetProductInventory(inventory.CompanyId, inventory.ProductId, inventory.DepositId);

            //drop the inventory(product and quantity)
            InventoryDrop(inventory, quantity, (int)DropType.Transfer, null);

            //insert the moviments
            DbContext.InventoryMoviments.InsertOnSubmit(inventoryMoviment);

            DbContext.SubmitChanges();
        }
    protected void btnReceive_Click(object sender, EventArgs e)
    {
        InventoryManager invManager = new InventoryManager(this);
        InventoryMoviment movement;

        foreach (GridViewRow row in grdReceive.Rows)
        {
            movement = new InventoryMoviment();
            int movementId = Convert.ToInt16(grdReceive.DataKeys[row.RowIndex]["InventoryMovementId"]);
            movement = invManager.RetrievePendingTransfers(movementId);
            invManager.TransferStockDeposit(movement, User.Identity.UserId);
        }

        cboCompany.DataBind();
        grdReceive.DataBind();
    }
Ejemplo n.º 6
0
    protected void btnReceive_Click(object sender, EventArgs e)
    {
        InventoryManager  invManager = new InventoryManager(this);
        InventoryMoviment movement;

        foreach (GridViewRow row in grdReceive.Rows)
        {
            movement = new InventoryMoviment();
            int movementId = Convert.ToInt16(grdReceive.DataKeys[row.RowIndex]["InventoryMovementId"]);
            movement = invManager.RetrievePendingTransfers(movementId);
            invManager.TransferStockDeposit(movement, User.Identity.UserId);
        }

        cboCompany.DataBind();
        grdReceive.DataBind();
    }
Ejemplo n.º 7
0
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        Inventory         inventory = new Inventory();
        InventoryMoviment movement  = new InventoryMoviment();
        InventoryHistory  history   = new InventoryHistory();
        InventoryManager  manager   = new InventoryManager(this);
        DropDownList      cboDropType;

        foreach (GridViewRow row in grdRefused.Rows)
        {
            cboDropType = row.FindControl("cboDropType") as DropDownList;
            //
            //if selected value not null or empty, then delete iventory moviment and
            //insert a history
            //
            if (!String.IsNullOrEmpty(cboDropType.SelectedValue))
            {
                int movementId = Convert.ToInt16(grdRefused.DataKeys[row.RowIndex]["InventoryMovementId"]);

                movement  = manager.RetrievePendingTransfers(movementId);
                inventory = manager.GetProductInventory(Company.CompanyId, movement.ProductId, movement.DepositId);

                history.CompanyId           = Company.CompanyId;
                history.CurrencyRateId      = inventory.CurrencyRateId;
                history.DepositId           = movement.DepositId;
                history.FiscalNumber        = inventory.FiscalNumber;
                history.InventoryDropTypeId = Convert.ToInt16(cboDropType.SelectedValue);
                history.Localization        = inventory.Localization;
                history.LogDate             = DateTime.Now;
                history.MinimumRequired     = inventory.MinimumRequired;
                history.ProductId           = movement.ProductId;
                history.Profit     = inventory.Profit;
                history.Quantity   = movement.Quantity;
                history.RealCost   = inventory.RealCost;
                history.SupplierId = inventory.SupplierId;
                history.UnitPrice  = inventory.UnitPrice;
                history.UserId     = User.Identity.UserId;

                manager.InsertHistory(history);
                manager.DeleteMovement(movement);

                grdRefused.DataBind();
            }
        }
    }
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        Inventory inventory = new Inventory();
        InventoryMoviment movement = new InventoryMoviment();
        InventoryHistory history = new InventoryHistory();
        InventoryManager manager = new InventoryManager(this);
        DropDownList cboDropType;

        foreach (GridViewRow row in grdRefused.Rows)
        {
            cboDropType = row.FindControl("cboDropType") as DropDownList;
            //
            //if selected value not null or empty, then delete iventory moviment and
            //insert a history
            //
            if (!String.IsNullOrEmpty(cboDropType.SelectedValue))
            {
                int movementId = Convert.ToInt16(grdRefused.DataKeys[row.RowIndex]["InventoryMovementId"]);

                movement = manager.RetrievePendingTransfers(movementId);
                inventory = manager.GetProductInventory(Company.CompanyId, movement.ProductId, movement.DepositId);

                history.CompanyId = Company.CompanyId;
                history.CurrencyRateId = inventory.CurrencyRateId;
                history.DepositId = movement.DepositId;
                history.FiscalNumber = inventory.FiscalNumber;
                history.InventoryDropTypeId = Convert.ToInt16(cboDropType.SelectedValue);
                history.Localization = inventory.Localization;
                history.LogDate = DateTime.Now;
                history.MinimumRequired = inventory.MinimumRequired;
                history.ProductId = movement.ProductId;
                history.Profit = inventory.Profit;
                history.Quantity = movement.Quantity;
                history.RealCost = inventory.RealCost;
                history.SupplierId = inventory.SupplierId;
                history.UnitPrice = inventory.UnitPrice;
                history.UserId = User.Identity.UserId;

                manager.InsertHistory(history);
                manager.DeleteMovement(movement);

                grdRefused.DataBind();
            }
        }
    }
Ejemplo n.º 9
0
 /// <summary>
 /// Método para apagar um registro da tabela de movimento, ou seja retirá-lo do status "em trânsito"
 /// </summary>
 /// <param name="entity"></param>
 public void DeleteMovement(InventoryMoviment entity)
 {
     //DbContext.InventoryMoviments.Attach(entity);
     DbContext.InventoryMoviments.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// this method transfer a product Between two deposit
        /// </summary>
        /// <param name="moviment"></param>
        public void TransferStockDeposit(InventoryMoviment moviment, Int32 userId)
        {
            //company Source Inventory Moviment
            InventoryMoviment sourceInventoryMoviment = RetrievePendingTransfers(moviment.InventoryMovementId);

            //company Souce Inventory
            Inventory sourceInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId, moviment.DepositId);

            //company targeting Inventory
            Inventory destinationInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId,
                                                                 moviment.DepositDestinationId);

            //insert Inventory History
            var history = new InventoryHistory();

            history.Quantity             = sourceInventory.Quantity;
            history.CurrencyRateId       = sourceInventory.CurrencyRateId;
            history.FiscalNumber         = sourceInventory.FiscalNumber;
            history.Localization         = sourceInventory.Localization;
            history.MinimumRequired      = sourceInventory.MinimumRequired;
            history.ProductId            = sourceInventory.ProductId;
            history.Profit               = sourceInventory.Profit;
            history.RealCost             = sourceInventory.RealCost;
            history.SupplierId           = sourceInventory.SupplierId;
            history.UnitPrice            = sourceInventory.UnitPrice;
            history.CompanyId            = moviment.CompanyId;
            history.DepositId            = sourceInventory.DepositId;
            history.DestinationDepositId = moviment.DepositDestinationId;
            history.InventoryEntryTypeId = (int)EntryType.Transfer;
            history.LogDate              = DateTime.Now;
            history.UserId               = userId;
            //insert History
            InsertHistory(history);

            if (destinationInventory != null)
            {
                //set the new AverageCost
                destinationInventory.AverageCosts =
                    ((destinationInventory.Quantity * destinationInventory.UnitPrice
                      + sourceInventoryMoviment.Quantity * sourceInventory.UnitPrice) /
                     (sourceInventoryMoviment.Quantity + destinationInventory.Quantity));

                //set the new Quantity
                destinationInventory.Quantity += sourceInventoryMoviment.Quantity;
            }
            else
            {
                //insert a Inventory if the product not exists in the target inventory
                //set the new depositId and companyId
                var newInventory = new Inventory();
                newInventory.CopyPropertiesFrom(sourceInventory);
                newInventory.DepositId = moviment.DepositDestinationId;
                newInventory.CompanyId = moviment.CompanyId;
                Insert(newInventory);
            }


            //delete Moviment
            DeleteMovement(moviment);

            //submit changes
            DbContext.SubmitChanges();
        }
Ejemplo n.º 11
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Manager
        InventoryManager iManager = new InventoryManager(this);
        CompanyManager   cManager = new CompanyManager(this);

        //these Objects are Initialized in loop because its necessary provide the Insert with new objects
        Inventory         inv;
        InventoryMoviment mov;
        InventoryHistory  his;

        DataTable productList   = (DataTable)Page.ViewState["ProductList"];
        Inventory inventoryData = new Inventory();
        Product   prod          = new Product();
        Deposit   dep           = new Deposit();

        if (productList.Rows.Count <= 1)
        {
            ShowError(Resources.Exception.SelectProduct);
            return;
        }

        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);
        try
        {
            foreach (DataRow row in productList.Rows)
            {
                inv = new Inventory();

                if (Deposit != null)
                {
                    inv.DepositId = dep.DepositId;
                }

                inv.CompanyId = Company.CompanyId;
                inv.ProductId = Convert.ToInt16(row["ProductId"]);
                inv.Quantity  = Convert.ToInt16(row["Quantity"]);

                mov                      = new InventoryMoviment();
                mov.CompanyId            = inv.CompanyId;
                mov.DepositId            = inv.DepositId;
                mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
                mov.ModifiedDate         = DateTime.Now;
                mov.ProductId            = inv.ProductId;
                mov.Quantity             = inv.Quantity;
                mov.CompanyDestinationId = Convert.ToInt16(cboCompany.SelectedValue);
                mov.Refused              = false;

                if (Deposit != null)
                {
                    iManager.InsertStockMovement(inv, mov, Convert.ToInt32(row["Quantity"]), User.Identity.UserId);
                }
                else
                {
                    ShowError("O usuário não está vinculado a nenhum inventário!");
                    return;
                }

                Session["CompanySender"] = Company.CompanyId;
            }
        }
        catch (InvalidOperationException ex)
        {
            ShowError(Resources.Exception.InvalidStockQuantity);
            return;
        }
        InSuccess();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Manager
        InventoryManager iManager = new InventoryManager(this);
        CompanyManager cManager = new CompanyManager(this);

        //these Objects are Initialized in loop because its necessary provide the Insert with new objects
        Inventory inv;
        InventoryMoviment mov;
        InventoryHistory his;

        DataTable productList = (DataTable)Page.ViewState["ProductList"];
        Inventory inventoryData = new Inventory();
        Product prod = new Product();
        Deposit dep = new Deposit();

        if (productList.Rows.Count <= 1)
        {
            ShowError(Resources.Exception.SelectProduct);
            return;
        }

        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);
        try
        {
            foreach (DataRow row in productList.Rows)
            {
                inv = new Inventory();

                if (Deposit != null)
                    inv.DepositId = dep.DepositId;

                inv.CompanyId = Company.CompanyId;
                inv.ProductId = Convert.ToInt16(row["ProductId"]);
                inv.Quantity = Convert.ToInt16(row["Quantity"]);

                mov = new InventoryMoviment();
                mov.CompanyId = inv.CompanyId;
                mov.DepositId = inv.DepositId;
                mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
                mov.ModifiedDate = DateTime.Now;
                mov.ProductId = inv.ProductId;
                mov.Quantity = inv.Quantity;
                mov.CompanyDestinationId = Convert.ToInt16(cboCompany.SelectedValue);
                mov.Refused = false;

                if (Deposit != null)
                {
                    iManager.InsertStockMovement(inv, mov, Convert.ToInt32(row["Quantity"]), User.Identity.UserId);
                }
                else
                {
                    ShowError("O usuário não está vinculado a nenhum inventário!");
                    return;
                }

                Session["CompanySender"] = Company.CompanyId;
            }
        }
        catch (InvalidOperationException ex)
        {
            ShowError(Resources.Exception.InvalidStockQuantity);
            return;
        }
        InSuccess();
    }
 /// <summary>
 /// Método para apagar um registro da tabela de movimento, ou seja retirá-lo do status "em trânsito"
 /// </summary>
 /// <param name="entity"></param>
 public void DeleteMovement(InventoryMoviment entity)
 {
     //DbContext.InventoryMoviments.Attach(entity);
     DbContext.InventoryMoviments.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
        /// <summary>
        /// this method transfer a product Between two deposit
        /// </summary>
        /// <param name="moviment"></param>
        public void TransferStockDeposit(InventoryMoviment moviment, Int32 userId)
        {
            //company Source Inventory Moviment
            InventoryMoviment sourceInventoryMoviment = RetrievePendingTransfers(moviment.InventoryMovementId);

            //company Souce Inventory
            Inventory sourceInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId, moviment.DepositId);

            //company targeting Inventory
            Inventory destinationInventory = GetProductInventory(moviment.CompanyId, moviment.ProductId,
                                                                 moviment.DepositDestinationId);

            //insert Inventory History
            var history = new InventoryHistory();
            history.Quantity = sourceInventory.Quantity;
            history.CurrencyRateId = sourceInventory.CurrencyRateId;
            history.FiscalNumber = sourceInventory.FiscalNumber;
            history.Localization = sourceInventory.Localization;
            history.MinimumRequired = sourceInventory.MinimumRequired;
            history.ProductId = sourceInventory.ProductId;
            history.Profit = sourceInventory.Profit;
            history.RealCost = sourceInventory.RealCost;
            history.SupplierId = sourceInventory.SupplierId;
            history.UnitPrice = sourceInventory.UnitPrice;
            history.CompanyId = moviment.CompanyId;
            history.DepositId = sourceInventory.DepositId;
            history.DestinationDepositId = moviment.DepositDestinationId;
            history.InventoryEntryTypeId = (int)EntryType.Transfer;
            history.LogDate = DateTime.Now;
            history.UserId = userId;
            //insert History
            InsertHistory(history);

            if (destinationInventory != null)
            {
                //set the new AverageCost
                destinationInventory.AverageCosts =
                    ((destinationInventory.Quantity * destinationInventory.UnitPrice
                      + sourceInventoryMoviment.Quantity * sourceInventory.UnitPrice) /
                     (sourceInventoryMoviment.Quantity + destinationInventory.Quantity));

                //set the new Quantity
                destinationInventory.Quantity += sourceInventoryMoviment.Quantity;
            }
            else
            {
                //insert a Inventory if the product not exists in the target inventory
                //set the new depositId and companyId
                var newInventory = new Inventory();
                newInventory.CopyPropertiesFrom(sourceInventory);
                newInventory.DepositId = moviment.DepositDestinationId;
                newInventory.CompanyId = moviment.CompanyId;
                Insert(newInventory);
            }


            //delete Moviment
            DeleteMovement(moviment);

            //submit changes
            DbContext.SubmitChanges();
        }
        /// <summary>
        /// this method execute all functions Necessary to Moviment a Product,
        /// the functions are InsertHistory(insert one row in InventoryHistory),InventoryDrop(Drop the product from inventory)
        ///  and InventoryMoviments(insert onr row in InventoryMoviments)
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="inventoryMoviment"></param>
        /// <param name="quantity"></param>
        public void InsertStockMovement(Inventory inventory, InventoryMoviment inventoryMoviment, Int32 quantity,
                                        Int32 userId)
        {
            Inventory inventoryData;

            //insert one row in InventoryHistory
            inventoryData = GetProductInventory(inventory.CompanyId, inventory.ProductId, inventory.DepositId);

            //drop the inventory(product and quantity)
            InventoryDrop(inventory, quantity, (int)DropType.Transfer, null);

            //insert the moviments
            DbContext.InventoryMoviments.InsertOnSubmit(inventoryMoviment);

            DbContext.SubmitChanges();
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        DataTable productList = (DataTable)Page.ViewState["ProductList"];
        Inventory inv = new Inventory();
        Product prod = new Product();
        Deposit dep = new Deposit();
        InventoryMoviment mov = new InventoryMoviment();
        InventoryManager iManager = new InventoryManager(this);
        CompanyManager cManager = new CompanyManager(this);

        if (productList.Rows.Count < 1)
        {
            ShowError("Deve haver pelo menos uma linha com dados do produto.");
            return;
        }
        foreach (DataRow row in productList.Rows)
        {
            if (row.Table.Rows.IndexOf(row) != 0)
            {
                if (!CheckIfCanSale(Convert.ToInt16(row["ProductId"]), Convert.ToInt16(row["Quantity"])))
                {
                    ShowError("O estoque da linha <b>" + Convert.ToInt16((row.Table.Rows.IndexOf(row)) + 1).ToString() + "</b> não pode ficar negativo<br />");
                    return;
                }
            }
        }




        productList.Rows.RemoveAt(0);

        dep = cManager.GetCurrentDeposit(User.Identity.UserId, Company.CompanyId);

        foreach (DataRow row in productList.Rows)
        {
            inv.CompanyId = Company.CompanyId;
            inv.DepositId = dep.DepositId;
            inv.ProductId = Convert.ToInt16(row["ProductId"]);
            inv.Quantity = Convert.ToInt16(row["Quantity"]);

            mov.CompanyId = inv.CompanyId;
            mov.DepositId = inv.DepositId;
            mov.DepositDestinationId = Convert.ToInt16(cboDeposit.SelectedValue);
            mov.ModifiedDate = DateTime.Now;
            mov.ProductId = inv.ProductId;
            mov.Quantity = inv.Quantity;

            iManager.InventoryDrop(inv, 0, (int)DropType.Transfer, null);
            iManager.InsertStockMovement(inv, mov, inv.Quantity, User.Identity.UserId);
        }
        InSuccess();
    }