Esempio n. 1
0
        /// <summary>
        /// Jul 28, 2011 : Lemu
        //  - Remove the adding/subtracting and SynchronizeQuantity in clsProductVariationsMatrix,
        //    already included in the new AddQuantity and SubtractQuantity.
        /// </summary>
        /// <param name="Details"></param>
        /// <param name="StockDirection"></param>
        /// <returns></returns>
        public Int64 AddItem(int BranchID, string TransactionNo, string CreatedBy, StockItemDetails Details, StockDirections StockDirection)
        {
            try
            {
                StockItem clsStockItem = new StockItem(base.Connection, base.Transaction);
                Int64     StockItemID  = clsStockItem.Insert(Details);

                ProductUnit clsProductUnit = new ProductUnit(base.Connection, base.Transaction);
                decimal     Quantity       = clsProductUnit.GetBaseUnitValue(Details.ProductID, Details.ProductUnitID, Details.Quantity);
                string      strRemarks     = string.Empty;

                Products clsProduct = new Products(base.Connection, base.Transaction);
                if (StockDirection == StockDirections.Decrement)
                {
                    strRemarks = Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.DEDUCT_STOCK_INVENTORY) + " " + Details.Remarks;
                    clsProduct.SubtractQuantity(BranchID, Details.ProductID, Details.VariationMatrixID, Quantity, strRemarks, Details.StockDate, TransactionNo, CreatedBy);
                }
                else
                {
                    strRemarks = Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.ADD_STOCK_INVENTORY) + " " + Details.Remarks;
                    clsProduct.AddQuantity(BranchID, Details.ProductID, Details.VariationMatrixID, Quantity, strRemarks, Details.StockDate, TransactionNo, CreatedBy);
                }

                // Removed
                //ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(base.Connection, base.Transaction);
                //if (Details.VariationMatrixID != 0)
                //{
                //    if (StockDirection == StockDirections.Decrement)
                //    {	clsProductVariationsMatrix.SubtractQuantity(Details.VariationMatrixID, Quantity);	}
                //    else
                //    {	clsProductVariationsMatrix.AddQuantity(Details.VariationMatrixID, Quantity);	}

                //    clsProductVariationsMatrix.SynchronizeQuantity(Details.ProductID);
                //}

                return(StockItemID);
            }

            catch (Exception ex)
            {
                throw base.ThrowException(ex);
            }
        }
Esempio n. 2
0
        private void AddItemToInventory(long WBranchTransferID)
        {
            WBranchTransferDetails clsWBranchTransferDetails = Details(WBranchTransferID);
            ERPConfig        clsERPConfig        = new ERPConfig(base.Connection, base.Transaction);
            ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details();

            WBranchTransferItem clsWBranchTransferItem = new WBranchTransferItem(base.Connection, base.Transaction);
            ProductUnit         clsProductUnit         = new ProductUnit(base.Connection, base.Transaction);
            Products            clsProduct             = new Products(base.Connection, base.Transaction);

            Inventory        clsInventory = new Inventory(base.Connection, base.Transaction);
            InventoryDetails clsInventoryDetails;

            System.Data.DataTable dt = clsWBranchTransferItem.ListAsDataTable(WBranchTransferID, "WBranchTransferItemID", SortOption.Ascending);

            foreach (System.Data.DataRow dr in dt.Rows)
            {
                long lngProductID     = Int64.Parse(dr["ProductID"].ToString());
                int  intProductUnitID = Int16.Parse(dr["ProductUnitID"].ToString());

                decimal decItemQuantity = decimal.Parse(dr["Quantity"].ToString());
                decimal decQuantity     = clsProductUnit.GetBaseUnitValue(lngProductID, intProductUnitID, decItemQuantity);

                long    lngVariationMatrixID = Int64.Parse(dr["VariationMatrixID"].ToString());
                string  strMatrixDescription = "" + dr["MatrixDescription"].ToString();
                string  strProductCode       = "" + dr["ProductCode"].ToString();
                string  strProductUnitCode   = "" + dr["ProductUnitCode"].ToString();
                decimal decUnitCost          = decimal.Parse(dr["UnitCost"].ToString());
                decimal decItemCost          = decimal.Parse(dr["Amount"].ToString());
                decimal decVAT = decimal.Parse(dr["VAT"].ToString());

                /*******************************************
                 * Subtract BranchIDFrom then Add to BranchIDTo -- Inventory
                 * ****************************************/
                clsProduct.SubtractQuantity(clsWBranchTransferDetails.BranchIDFrom, lngProductID, lngVariationMatrixID, decQuantity, Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.DEDUCT_BRANCH_TRANSFER_FROM) + " " + clsWBranchTransferDetails.BranchCodeFrom + " @ " + decUnitCost.ToString("#,##0.#0") + "/" + strProductUnitCode, DateTime.Now, clsWBranchTransferDetails.WBranchTransferNo, clsWBranchTransferDetails.TransferrerName);
                clsProduct.AddQuantity(clsWBranchTransferDetails.BranchIDTo, lngProductID, lngVariationMatrixID, decQuantity, Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.ADD_BRANCH_TRANSFER_TO) + " " + clsWBranchTransferDetails.BranchCodeTo + " @ " + decUnitCost.ToString("#,##0.#0") + "/" + strProductUnitCode, DateTime.Now, clsWBranchTransferDetails.WBranchTransferNo, clsWBranchTransferDetails.TransferrerName);

                /*******************************************
                 * Add to Inventory Analysis
                 * ****************************************/
                clsInventoryDetails = new InventoryDetails();
                clsInventoryDetails.PostingDateFrom   = clsERPConfigDetails.PostingDateFrom;
                clsInventoryDetails.PostingDateTo     = clsERPConfigDetails.PostingDateTo;
                clsInventoryDetails.PostingDate       = clsWBranchTransferDetails.DeliveryDate;
                clsInventoryDetails.ReferenceNo       = clsWBranchTransferDetails.WBranchTransferNo;
                clsInventoryDetails.ContactID         = Constants.C_RETAILPLUS_SUPPLIERID;
                clsInventoryDetails.ContactCode       = Constants.C_RETAILPLUS_SUPPLIER;
                clsInventoryDetails.ProductID         = lngProductID;
                clsInventoryDetails.ProductCode       = strProductCode;
                clsInventoryDetails.VariationMatrixID = lngVariationMatrixID;
                clsInventoryDetails.MatrixDescription = strMatrixDescription;

                clsInventoryDetails.PurchaseCost = decItemCost - decVAT;
                clsInventoryDetails.PurchaseVAT  = decItemCost; // Purchase Cost with VAT

                // insert into branchid from with minus quantity
                clsInventoryDetails.BranchID         = clsWBranchTransferDetails.BranchIDFrom;
                clsInventoryDetails.PurchaseQuantity = -decQuantity;
                clsInventory.Insert(clsInventoryDetails);

                // insert into branchid to with add quantity
                clsInventoryDetails.BranchID         = clsWBranchTransferDetails.BranchIDTo;
                clsInventoryDetails.PurchaseQuantity = decQuantity;
                clsInventory.Insert(clsInventoryDetails);
            }
        }