예제 #1
0
        public StockIn Add(StockIn data)
        {
            string dateStr = data.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("StockInId", dateStr + "00000");
            var maxId = StockInDAO.SelectSpecificType(criteria, Projections.Max("StockInId"));
            var stockInId = maxId == null ? dateStr + "00001" : string.Format("{0:00000000000}", (Int64.Parse(maxId.ToString()) + 1));

            data.StockInId = stockInId;
            criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("ProductId", dateStr + "000000");

            maxId = ProductDAO.SelectSpecificType(criteria, Projections.Max("ProductId"));
            var productId = (maxId == null)
                ? Int64.Parse(dateStr + "000001")
                : (Int64.Parse(maxId.ToString()) + 1);

            maxId = StockDAO.SelectSpecificType(null, Projections.Max("StockId"));
            var stockId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            data.CreateDate = DateTime.Now;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            data.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            StockInDAO.Add(data);

            foreach (StockInDetail stockInDetail in data.StockInDetails)
            {
                // add product
                Product product = stockInDetail.Product;
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    product.ProductId = string.Format("{0:000000000000}", productId++);
                    product.CreateDate = DateTime.Now;
                    product.UpdateDate = DateTime.Now;
                    product.Quantity = stockInDetail.Quantity;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    product.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    ProductDAO.Add(product);

                    criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    criteria.AddEqCriteria("ProductMaster.ProductMasterId", product.ProductMaster.ProductMasterId);
            //                    var sum = StockDAO.SelectSpecificType(criteria, Projections.Sum("Quantity"));

                    // add dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = stockInId};
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.CreateDate = DateTime.Now;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.ProductMaster = product.ProductMaster;
            //                    stockInDetail.CurrentStockQuantity = (sum == null) ? 0 : Int64.Parse(sum.ToString());
                    StockInDetailDAO.Add(stockInDetail);

                    // dept stock
                    var stock = new Stock
                    {
                        StockId = stockId++,
                        CreateDate = DateTime.Now,
                        UpdateDate = DateTime.Now,
                        Product = product,
                        Quantity = stockInDetail.Quantity,
                        GoodQuantity = stockInDetail.Quantity,
                        ProductMaster = product.ProductMaster
                    };
                    stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    StockDAO.Add(stock);

                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.SellPrice, UpdateDate = DateTime.Now, CreateDate = DateTime.Now };
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                    else
                    {
                        price.Price = stockInDetail.SellPrice;
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.UpdateDate = DateTime.Now;
                        DepartmentPriceDAO.Update(price);
                    }
                }
            }

            return data;
        }
        public void SyncToMain(SyncFromDepartmentToMain sync)
        {
            // insert department stock temp
            if(sync.DepartmentStockTempList!=null && sync.DepartmentStockTempList.Count > 0)
            {
                foreach (DepartmentStockTemp departmentStockTemp in sync.DepartmentStockTempList)
                {
                    bool failed = false;
                    if (departmentStockTemp != null)
                    {
                        DepartmentStockTemp curDeptTemp = DepartmentStockTempDAO.FindById(departmentStockTemp.DepartmentStockTempPK);
                        if (curDeptTemp == null)
                        {
                            DepartmentStockTempDAO.Add(departmentStockTemp);
                        }
                        else
                        {
                            if(departmentStockTemp.Fixed == 1 && departmentStockTemp.DelFlg == 1)
                            {
                                curDeptTemp.Fixed = 1;
                                curDeptTemp.DelFlg = 1;
                                DepartmentStockTempDAO.Update(curDeptTemp);
                            }
                        }
                    }
                }
            }
            // insert timeline
            if (sync.DepartmentTimelineList != null && sync.DepartmentTimelineList.Count > 0)
            {
                foreach (DepartmentTimeline timeline in sync.DepartmentTimelineList)
                {
                    bool failed = false;
                    if (timeline != null)
                    {
                        DepartmentTimeline curTimeline = DepartmentTimelineDAO.FindById(timeline.DepartmentTimelinePK);
                        if (curTimeline == null)
                        {
                            DepartmentTimelineDAO.Add(timeline);
                        }
                        else
                        {
                            // error
                            //failed = true;
                        }
                    }
                }
            }

            // insert PO, PO Detail
            if (sync.PurchaseOrderList != null && sync.PurchaseOrderList.Count > 0)
            {
                foreach (PurchaseOrder po in sync.PurchaseOrderList)
                {
                    PurchaseOrder poTemp = PurchaseOrderDAO.FindById(po.PurchaseOrderPK);
                    if (poTemp == null)
                    {
                        PurchaseOrderDAO.Add(po);
                        foreach (PurchaseOrderDetail detail in po.PurchaseOrderDetails)
                        {
                            PurchaseOrderDetailDAO.Add(detail);
                        }
                    }
                    else
                    {
                        // Error
                        //failed = true;
                    }
                }
            }

            // insert dept stock out
            if (sync.DepartmentStockOutList != null && sync.DepartmentStockOutList.Count > 0)
            {
                IList productIds = new ArrayList();
                foreach (DepartmentStockOut po in sync.DepartmentStockOutList)
                {
                    if (po.DefectStatus.DefectStatusId == StockDefectStatus.SEND_BACK_TO_MAIN)
                    {
                        foreach (DepartmentStockOutDetail detail in po.DepartmentStockOutDetails)
                        {
                            if (NotInList(productIds, detail.Product.ProductId))
                            {
                                productIds.Add(detail.Product.ProductId);
                            }
                        }
                    }
                }
                IList stockList = new ArrayList();
                ObjectCriteria criteria = new ObjectCriteria();
                criteria.AddSearchInCriteria("Product.ProductId", productIds);
                stockList = StockDAO.FindAll(criteria);

                StockOutMapper mapper = new StockOutMapper();
                StockOutDetailMapper detailMapper = new StockOutDetailMapper();
                DeptRetProdStockInMapper drpsiMapper = new DeptRetProdStockInMapper();
                DeptRetProdStockInDetailMapper drpsiDetMapper = new DeptRetProdStockInDetailMapper();

                // save to main.
                string dateStr = DateTime.Now.ToString("yyMMdd");
                var SICriteria = new ObjectCriteria();
                var maxId = StockInDAO.SelectSpecificType(SICriteria, Projections.Max("StockInId"));
                var stockInId = maxId == null ? dateStr + "00001" : string.Format("{0:00000000000}", (Int64.Parse(maxId.ToString()) + 1));

                foreach (DepartmentStockOut po in sync.DepartmentStockOutList)
                {

                    /*if (po.DefectStatus.DefectStatusId == StockDefectStatus.SEND_BACK_TO_MAIN)
                    {
                        foreach (DepartmentStockOutDetail detail in po.DepartmentStockOutDetails)
                        {
                            productIds.Add(detail.Product.ProductId);
                        }
                    }*/
                    DepartmentStockOut poTemp = DepartmentStockOutDAO.FindById(po.DepartmentStockOutPK);
                    if (poTemp == null)
                    {
                        // ++ Add code for add an empty stock in : 20090906

                        po.StockOutDate = DateTime.Now;
                        DepartmentStockOutDAO.Add(po);

                        StockIn stockIn = drpsiMapper.Convert(po);
                        stockIn.StockInDate = DateTime.Now;
                        if (po.DefectStatus.DefectStatusId == StockDefectStatus.SEND_BACK_TO_MAIN)
                        {
                            stockIn.StockInType = 3; // stock in for stock out to manufacturers
                        }
                        stockIn.StockInDetails = new ArrayList();

                        foreach (DepartmentStockOutDetail detail in po.DepartmentStockOutDetails)
                        {
                            DepartmentStockOutDetailDAO.Add(detail);

                            // update stock if it's a dept stock out return to main ( defectstatus = 6 )
                            if (po.DefectStatus.DefectStatusId == StockDefectStatus.SEND_BACK_TO_MAIN
                                && stockList!=null
                                && stockList.Count > 0)
                            {
                                Stock stock = GetStockOfProduct(detail.Product,stockList);
                                if(stock!=null)
                                {
                                    stock.Quantity += detail.GoodQuantity + detail.ErrorQuantity;
                                    stock.GoodQuantity += detail.GoodQuantity;
                                    stock.ErrorQuantity += detail.ErrorQuantity;
                                    StockDAO.Update(stock);
                                }

                                StockInDetail detailStockIn = drpsiDetMapper.Convert(detail);
                                stockIn.StockInDetails.Add(detailStockIn);
                            }
                        }
                        if(stockIn.StockInDetails != null && stockIn.StockInDetails.Count > 0)
                        {

                            // save to main.
                            stockIn.StockInId = stockInId;
                            StockInDAO.Add(stockIn);

                            foreach (StockInDetail stockInDetail in stockIn.StockInDetails)
                            {
                                // add dept stock in
                                var detailPK = new StockInDetailPK { ProductId = stockInDetail.Product.ProductId, StockInId = stockInId };
                                stockInDetail.StockInDetailPK = detailPK;
                                StockInDetailDAO.Add(stockInDetail);
                            }
                            // create new stockInId
                            stockInId = string.Format("{0:00000000000}", (Int64.Parse(stockInId.ToString()) + 1));
                        }
                        // -- Add code for add an empty stock in : 20090906
                    }
                    else
                    {
                        // Error
                        //failed = true;
                    }
                }
            }

            // insert Dept stock in
            if (sync.DepartmentStockInList != null && sync.DepartmentStockInList.Count > 0)
            {
                foreach (DepartmentStockIn po in sync.DepartmentStockInList)
                {
                    DepartmentStockIn poTemp = DepartmentStockInDAO.FindById(po.DepartmentStockInPK);
                    if (poTemp == null)
                    {
                        DepartmentStockInDAO.Add(po);
                        foreach (DepartmentStockInDetail detail in po.DepartmentStockInDetails)
                        {
                            DepartmentStockInDetailDAO.Add(detail);
                        }
                    }
                    else
                    {
                        // Error
                    }
                }
            }

            // insert return po
            if (sync.ReturnPoList != null && sync.ReturnPoList.Count > 0)
            {
                foreach (ReturnPo po in sync.ReturnPoList)
                {
                    ReturnPo poTemp = ReturnPoDAO.FindById(po.ReturnPoPK);
                    if (poTemp == null)
                    {
                        ReturnPoDAO.Add(po);
                    }
                    else
                    {
                        // Error
                    }
                }
            }

            // insert stock history
            if (sync.DepartmentStockHistoryList != null && sync.DepartmentStockHistoryList.Count > 0)
            {
                foreach (DepartmentStockHistory po in sync.DepartmentStockHistoryList)
                {
                    DepartmentStockHistory poTemp = DepartmentStockHistoryDAO.FindById(po.DepartmentStockHistoryPK);
                    if (poTemp == null)
                    {
                        DepartmentStockHistoryDAO.Add(po);
                    }
                    else
                    {
                        // Error
                    }
                }
            }

            // insert or update dept stock
            if (sync.DepartmentStockList != null && sync.DepartmentStockList.Count > 0)
            {
                /*if (!failed)
                {*/
                    foreach (DepartmentStock po in sync.DepartmentStockList)
                    {

                        try
                        {
                            DepartmentStock poTemp = DepartmentStockDAO.FindById(po.DepartmentStockPK);
                            if (poTemp == null)
                            {
                                DepartmentStockDAO.Add(po);
                            }
                            else
                            {
                                poTemp.Quantity = po.Quantity;
                                poTemp.GoodQuantity = po.GoodQuantity;
                                poTemp.LostQuantity = po.LostQuantity;
                                poTemp.ErrorQuantity = po.ErrorQuantity;
                                poTemp.DamageQuantity = po.DamageQuantity;
                                poTemp.OldDamageQuantity = po.OldDamageQuantity;
                                poTemp.OldErrorQuantity = po.OldErrorQuantity;
                                poTemp.OldGoodQuantity = po.OldGoodQuantity;
                                poTemp.OldLostQuantity = po.OldLostQuantity;
                                poTemp.OldUnconfirmQuantity = po.OldUnconfirmQuantity;
                                poTemp.UnconfirmQuantity = po.UnconfirmQuantity;
                                poTemp.UpdateDate = DateTime.Now;
                                DepartmentStockDAO.Update(poTemp);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                /*}*/
            }

            // sync dept cost
            if (sync.DepartmentCostList != null && sync.DepartmentCostList.Count > 0)
            {
                foreach (DepartmentCost departmentCost in sync.DepartmentCostList)
                {
                    DepartmentCost existDeptCost = DepartmentCostDAO.FindById(departmentCost.DepartmentCostPK);
                    if (existDeptCost == null)
                    {
                        DepartmentCostDAO.Add(departmentCost);
                    }
                }
            }

            // sync money
            if(sync.EmployeeMoneyList != null && sync.EmployeeMoneyList.Count > 0)
            {
                foreach (EmployeeMoney employeeMoney in sync.EmployeeMoneyList)
                {
                    EmployeeMoney existEmpMoney = EmployeeMoneyDAO.FindById(employeeMoney.EmployeeMoneyPK);
                    if (existEmpMoney == null)
                    {
                        EmployeeMoneyDAO.Add(employeeMoney);
                    }
                }
            }
        }
예제 #3
0
        public void Update(StockIn data)
        {
            string dateStr = data.StockInDate.ToString("yyMMdd");

            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("ProductId", dateStr + "000000");

            var maxId = ProductDAO.SelectSpecificType(criteria, Projections.Max("ProductId"));
            var productId = (maxId == null)
                ? Int64.Parse(dateStr + "000001")
                : (Int64.Parse(maxId.ToString()) + 1);

            maxId = StockDAO.SelectSpecificType(null, Projections.Max("StockId"));
            var stockId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            int delFlg = 0;
            foreach (StockInDetail stockInDetail in data.StockInDetails)
            {
                // add product
                Product product = stockInDetail.Product;
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    product.ProductId = string.Format("{0:000000000000}", productId++);
                    product.CreateDate = DateTime.Now;
                    product.UpdateDate = DateTime.Now;
                    product.Quantity = stockInDetail.Quantity;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    product.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    ProductDAO.Add(product);

                    // add dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = data.StockInId };
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.CreateDate = DateTime.Now;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.ProductMaster = product.ProductMaster;
                    StockInDetailDAO.Add(stockInDetail);

                    // dept stock
                    var departmentStock = new Stock
                    {
                        StockId = stockId++,
                        CreateDate = DateTime.Now,
                        UpdateDate = DateTime.Now,
                        Product = product,
                        ProductMaster = product.ProductMaster,
                        Quantity = stockInDetail.Quantity,
                        GoodQuantity = stockInDetail.Quantity
                    };
                    departmentStock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    departmentStock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    StockDAO.Add(departmentStock);

                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.SellPrice, UpdateDate = DateTime.Now, CreateDate = DateTime.Now };
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                }
                else
                {
                    var temProduct = ProductDAO.FindById(product.ProductId);
                    if (stockInDetail.DelFlg == 0)
                    {
                        temProduct.Quantity = product.Quantity;
                        temProduct.Price = product.Price;
                    }
                    else
                    {
                        temProduct.DelFlg = 1;
                        delFlg++;
                    }

                    temProduct.UpdateDate = DateTime.Now;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

                    ProductDAO.Update(temProduct);

                    // update dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = data.StockInId };
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    StockInDetailDAO.Update(stockInDetail);

                    // update stock
                    criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("Product.ProductId", product.ProductId);
                    criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    IList departmentStockList = StockDAO.FindAll(criteria);
                    if (departmentStockList.Count > 0)
                    {
                        Stock stock = (Stock) departmentStockList[0];
                        stock.UpdateDate = DateTime.Now;
                        if (stockInDetail.DelFlg == 0)
                        {

                            stock.GoodQuantity = stock.GoodQuantity -
                                                       (stockInDetail.OldQuantity - stockInDetail.Quantity);
                            stock.Quantity = stock.ErrorQuantity + stock.GoodQuantity + stock.DamageQuantity +
                                     stock.UnconfirmQuantity + stock.LostQuantity;
                        }
                        else
                        {
                            stock.DelFlg = 1;
                        }
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        StockDAO.Update(stock);

                    }

                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.SellPrice, UpdateDate = DateTime.Now, CreateDate = DateTime.Now };
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                }
            }

            if (delFlg == data.StockInDetails.Count)
            {
                data.DelFlg = 1;
            }
            StockInDAO.Update(data);
        }
예제 #4
0
        public void AddReStock(StockIn data)
        {
            string dateStr = data.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("StockInId", dateStr + "00000");
            var maxId = StockInDAO.SelectSpecificType(criteria, Projections.Max("StockInId"));
            var stockInId = maxId == null ? dateStr + "00001" : string.Format("{0:00000000000}", (Int64.Parse(maxId.ToString()) + 1));

            data.CreateDate = DateTime.Now;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            data.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            data.StockInType = (long) 1;
            data.StockInId = stockInId;
            StockInDAO.Add(data);

            foreach (StockInDetail stockInDetail in data.StockInDetails)
            {
                // add dept stock in
                var detailPK = new StockInDetailPK { ProductId = stockInDetail.Product.ProductId, StockInId = stockInId };
                stockInDetail.StockInDetailPK = detailPK;
                stockInDetail.CreateDate = DateTime.Now;
                stockInDetail.UpdateDate = DateTime.Now;
                stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                stockInDetail.ProductMaster = stockInDetail.Product.ProductMaster;
                //                    stockInDetail.CurrentStockQuantity = (sum == null) ? 0 : Int64.Parse(sum.ToString());
                StockInDetailDAO.Add(stockInDetail);
                ObjectCriteria stockCriteria = new ObjectCriteria();
                stockCriteria.AddEqCriteria("Product.ProductId", stockInDetail.Product.ProductId);
                IList stockList = StockDAO.FindAll(stockCriteria);

                // decrease error and increase good
                if(stockList != null)
                {
                    Stock stock = (Stock)stockList[0];
                    stock.ErrorQuantity -= stockInDetail.Quantity;
                    stock.GoodQuantity += stockInDetail.Quantity;
                    stock.Quantity = stock.ErrorQuantity + stock.GoodQuantity + stock.DamageQuantity +
                                     stock.UnconfirmQuantity + stock.LostQuantity;
                    StockDAO.Update(stock);
                }
            }
        }
예제 #5
0
        public void AddForStockOutToProducer(StockIn stockIn)
        {
            string dateStr = stockIn.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            var maxId = StockInDAO.SelectSpecificType(criteria, Projections.Max("StockInId"));
            var stockInId = maxId == null ? dateStr + "00001" : string.Format("{0:00000000000}", (Int64.Parse(maxId.ToString()) + 1));
            stockIn.StockInId = stockInId;
            StockInDAO.Add(stockIn);

            foreach (StockInDetail stockInDetail in stockIn.StockInDetails)
            {
                // add dept stock in
                var detailPK = new StockInDetailPK { ProductId = stockInDetail.Product.ProductId, StockInId = stockInId };
                stockInDetail.StockInDetailPK = detailPK;
                StockInDetailDAO.Add(stockInDetail);

                ObjectCriteria stockCriteria = new ObjectCriteria();
                stockCriteria.AddEqCriteria("Product.ProductId", stockInDetail.Product.ProductId);
                IList stockList = StockDAO.FindAll(stockCriteria);
                // increase good
                if (stockList != null)
                {
                    Stock stock = (Stock)stockList[0];
                    stock.GoodQuantity += stockInDetail.Quantity;
                    stock.Quantity = stock.ErrorQuantity + stock.GoodQuantity + stock.DamageQuantity +
                                     stock.UnconfirmQuantity + stock.LostQuantity;
                    StockDAO.Update(stock);
                }
            }
        }
예제 #6
0
        public StockIn Add(StockIn data)
        {
            string dateStr = data.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("StockInId", dateStr + "00000");
            var maxId = StockInDAO.SelectSpecificType(criteria, Projections.Max("StockInId"));
            var stockInId = maxId == null ? dateStr + "00001" : string.Format("{0:00000000000}", (Int64.Parse(maxId.ToString()) + 1));

            data.StockInId = stockInId;
            /*criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("ProductId", dateStr + "000000");

            maxId = ProductDAO.SelectSpecificType(criteria, Projections.Max("ProductId"));
            var productId = (maxId == null)
                ? Int64.Parse(dateStr + "000001")
                : (Int64.Parse(maxId.ToString()) + 1);*/

            maxId = StockDAO.SelectSpecificType(null, Projections.Max("StockId"));
            var stockId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            data.CreateDate = DateTime.Now;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            data.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            StockInDAO.Add(data);
            IDictionary<string, string> maxPrdIdList = new Dictionary<string, string>();
            foreach (StockInDetail stockInDetail in data.StockInDetails)
            {
                // add product
                Product product = stockInDetail.Product;
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    // find master ID
                    string masterId = product.ProductMaster.ProductMasterId;
                    masterId = masterId.Substring(6);
                    // search in product table to get latest number
                    string nextPrdId = GetProductIdFromList(maxPrdIdList,masterId);
                    if (nextPrdId == null)
                    {
                        string shortDate = StringUtility.ConvertDateToFourChar(DateTime.Now);
                        ObjectCriteria prdCrit = new ObjectCriteria();
                        prdCrit.AddLikeCriteria("ProductId", masterId + shortDate + "%");
                        var maxIPrdId = ProductDAO.SelectSpecificType(prdCrit, Projections.Max("ProductId"));
                        string productId = (maxIPrdId == null)
                                            ? masterId + shortDate + "01"
                                            : IncreaseMaxProductId(maxIPrdId.ToString());

                        nextPrdId = productId;
                        maxPrdIdList[masterId] = nextPrdId;
                    }
                    product.ProductId = nextPrdId;
                    // increase product id and grant to the dictionary
                    nextPrdId = IncreaseMaxProductId(nextPrdId);
                    maxPrdIdList[masterId] = nextPrdId;
                    product.CreateDate = DateTime.Now;
                    product.UpdateDate = DateTime.Now;
                    product.Quantity = stockInDetail.Quantity;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    product.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    ProductDAO.Add(product);

                    criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    criteria.AddEqCriteria("ProductMaster.ProductMasterId", product.ProductMaster.ProductMasterId);
            //                    var sum = StockDAO.SelectSpecificType(criteria, Projections.Sum("Quantity"));

                    // add dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = stockInId};
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.CreateDate = DateTime.Now;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.ProductMaster = product.ProductMaster;
            //                    stockInDetail.CurrentStockQuantity = (sum == null) ? 0 : Int64.Parse(sum.ToString());
                    StockInDetailDAO.Add(stockInDetail);

                    // if do not needs to confirm then update stock.
                    if (data.ConfirmFlg != 1)
                    {
                        // add stock
                        var stock = new Stock
                                        {
                                            StockId = stockId++,
                                            CreateDate = DateTime.Now,
                                            UpdateDate = DateTime.Now,
                                            Product = product,
                                            Quantity = stockInDetail.Quantity,
                                            GoodQuantity = stockInDetail.Quantity,
                                            ProductMaster = product.ProductMaster
                                        };
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        StockDAO.Add(stock);
                    }

                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice
                                    {
                                        DepartmentPricePK = pricePk,
                                        Price = stockInDetail.SellPrice,
                                        WholeSalePrice = stockInDetail.WholeSalePrice,
                                        UpdateDate = DateTime.Now,
                                        CreateDate = DateTime.Now
                                    };
                        if(stockInDetail.DepartmentPrice!=null)
                        {
                            price.WholeSalePrice = stockInDetail.DepartmentPrice.WholeSalePrice;
                        }
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                    else
                    {
                        // don't need to update price
                        //price.Price = stockInDetail.SellPrice;

                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.UpdateDate = DateTime.Now;
                        //DepartmentPriceDAO.Update(price);
                    }
                }
            }

            return data;
        }
예제 #7
0
        public void UpdateDetail(StockIn data)
        {
            string dateStr = data.StockInDate.ToString("yyMMdd");

            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("ProductId", dateStr + "000000");

            //var maxId = ProductDAO.SelectSpecificType(criteria, Projections.Max("ProductId"));
            /*var productId = (maxId == null)
                ? Int64.Parse(dateStr + "000001")
                : (Int64.Parse(maxId.ToString()) + 1);*/

            var maxId = StockDAO.SelectSpecificType(null, Projections.Max("StockId"));
            var stockId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            int delFlg = 0;
            IDictionary<string, string> maxPrdIdList = new Dictionary<string, string>();
            foreach (StockInDetail stockInDetail in data.StockInDetails)
            {
                // add product
                Product product = stockInDetail.Product;
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    //product.ProductId = string.Format("{0:000000000000}", productId++);
                    // find master ID
                    string masterId = product.ProductMaster.ProductMasterId;
                    masterId = masterId.Substring(6);
                    // search in product table to get latest number
                    string nextPrdId = GetProductIdFromList(maxPrdIdList, masterId);
                    if (nextPrdId == null)
                    {
                        string shortDate = StringUtility.ConvertDateToFourChar(DateTime.Now);
                        ObjectCriteria prdCrit = new ObjectCriteria();
                        prdCrit.AddLikeCriteria("ProductId", masterId + shortDate + "%");
                        var maxIPrdId = ProductDAO.SelectSpecificType(prdCrit, Projections.Max("ProductId"));
                        string productId = (maxIPrdId == null)
                                            ? masterId + shortDate + "01"
                                            : IncreaseMaxProductId(maxIPrdId.ToString());

                        nextPrdId = productId;
                        maxPrdIdList[masterId] = nextPrdId;
                    }
                    product.ProductId = nextPrdId;
                    // increase product id and grant to the dictionary
                    nextPrdId = IncreaseMaxProductId(nextPrdId);
                    maxPrdIdList[masterId] = nextPrdId;

                    product.CreateDate = DateTime.Now;
                    product.UpdateDate = DateTime.Now;
                    product.Quantity = stockInDetail.Quantity;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    product.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    ProductDAO.Add(product);

                    // add dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = data.StockInId };
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.CreateDate = DateTime.Now;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockInDetail.ProductMaster = product.ProductMaster;
                    StockInDetailDAO.Add(stockInDetail);

                    if (!ClientSetting.ImportConfirmation)
                    {
                        // dept stock
                        var stock = new Stock
                        {
                            StockId = stockId++,
                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                            Product = product,
                            ProductMaster = product.ProductMaster,
                            Quantity = stockInDetail.Quantity,
                            GoodQuantity = stockInDetail.Quantity
                        };
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        StockDAO.Add(stock);
                    }
                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.SellPrice, UpdateDate = DateTime.Now, CreateDate = DateTime.Now };
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                }
                else
                {
                    var temProduct = ProductDAO.FindById(product.ProductId);
                    if (stockInDetail.DelFlg == 0)
                    {
                        temProduct.Quantity = product.Quantity;
                        temProduct.Price = product.Price;
                    }
                    else
                    {
                        temProduct.DelFlg = 1;
                        delFlg++;
                    }

                    temProduct.UpdateDate = DateTime.Now;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

                    ProductDAO.Update(temProduct);

                    // update dept stock in
                    var detailPK = new StockInDetailPK { ProductId = product.ProductId, StockInId = data.StockInId };
                    stockInDetail.StockInDetailPK = detailPK;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    StockInDetailDAO.Update(stockInDetail);

                    // if do not need to confirm then update stock
                    if (data.ConfirmFlg != 1)
                    {
                        // update stock
                        criteria = new ObjectCriteria();
                        criteria.AddEqCriteria("Product.ProductId", product.ProductId);
                        criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                        IList stockList = StockDAO.FindAll(criteria);
                        if (stockList.Count > 0)
                        {
                            Stock stock = (Stock)stockList[0];
                            stock.UpdateDate = DateTime.Now;
                            if (stockInDetail.DelFlg == 0)
                            {

                                stock.GoodQuantity = stock.GoodQuantity -
                                                     (stockInDetail.OldQuantity - stockInDetail.Quantity);
                                stock.Quantity = stock.ErrorQuantity + stock.GoodQuantity + stock.DamageQuantity +
                                                 stock.UnconfirmQuantity + stock.LostQuantity;
                            }
                            else
                            {
                                stock.DelFlg = 1;
                            }
                            stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                            StockDAO.Update(stock);

                        }
                        else
                        {
                            // in case confirmation so stock in has been confirmed to update
                            if (ClientSetting.ImportConfirmation)
                            {
                                // dept stock
                                var stock = new Stock
                                {
                                    StockId = stockId++,
                                    CreateDate = DateTime.Now,
                                    UpdateDate = DateTime.Now,
                                    Product = product,
                                    ProductMaster = product.ProductMaster,
                                    Quantity = stockInDetail.Quantity,
                                    GoodQuantity = stockInDetail.Quantity
                                };
                                stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                                stock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                                StockDAO.Add(stock);
                            }
                        }
                    }

                    var pricePk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = product.ProductMaster.ProductMasterId };

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.SellPrice, UpdateDate = DateTime.Now, CreateDate = DateTime.Now };
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        price.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Add(price);
                    }
                }
            }

            if (delFlg == data.StockInDetails.Count)
            {
                data.DelFlg = 1;
            }
        }