コード例 #1
0
ファイル: StockInLogicImpl.cs プロジェクト: DelLitt/opmscoral
        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;
        }
コード例 #2
0
        public void Delete(ProductMaster data)
        {
            long deptId = CurrentDepartment.Get().DepartmentId;
            // delete product master
            ProductMaster master = ProductMasterDAO.FindById(data.ProductMasterId);
            if (master != null)
            {
                master.UpdateDate = DateTime.Now;
                master.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                master.DelFlg = 1;
                ProductMasterDAO.Update(master);
            }

            // delete product
            var criteria = new ObjectCriteria();
            criteria.AddEqCriteria("ProductMaster.ProductMasterId", data.ProductMasterId);
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            IList products = ProductDAO.FindAll(criteria);
            IList productIds = new ArrayList();
            foreach (Product product in products)
            {
                product.UpdateDate = DateTime.Now;
                product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                product.DelFlg = 1;
                ProductDAO.Update(product);
                productIds.Add(product.ProductId);
            }

            if (productIds.Count > 0)
            {
                // delete stock in detail
                criteria = new ObjectCriteria();
                criteria.AddEqCriteria("DepartmentStockInDetailPK.DepartmentId", deptId);
                criteria.AddSearchInCriteria("DepartmentStockInDetailPK.ProductId", productIds);
                IList stockInDetails = DepartmentStockInDetailDAO.FindAll(criteria);
                IList stockInIds = new ArrayList();
                foreach (DepartmentStockInDetail detail in stockInDetails)
                {
                    detail.UpdateDate = DateTime.Now;
                    detail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    detail.DelFlg = 1;
                    DepartmentStockInDetailDAO.Update(detail);
                    stockInIds.Add(detail.DepartmentStockInDetailPK.StockInId);
                }

                // delete stock in
                if (stockInIds.Count > 0)
                {
                    criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("DepartmentStockInPK.DepartmentId", deptId);
                    criteria.AddSearchInCriteria("DepartmentStockInPK.StockInId", stockInIds);
                    IList stockIns = DepartmentStockInDAO.FindAll(criteria);
                    foreach (DepartmentStockIn stockIn in stockIns)
                    {
                        stockIn.UpdateDate = DateTime.Now;
                        stockIn.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockIn.DelFlg = 1;
                        DepartmentStockInDAO.Update(stockIn);
                    }
                }

                // delete stock
                criteria = new ObjectCriteria();
                criteria.AddEqCriteria("DepartmentStockPK.DepartmentId", deptId);
                criteria.AddSearchInCriteria("DepartmentStockPK.ProductId", productIds);
                IList stocks = DepartmentStockDAO.FindAll(criteria);
                foreach (DepartmentStock stock in stocks)
                {
                    stock.UpdateDate = DateTime.Now;
                    stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stock.DelFlg = 1;
                    DepartmentStockDAO.Update(stock);
                }

                // delete purchase order detail
                criteria = new ObjectCriteria();
                criteria.AddEqCriteria("PurchaseOrderDetailPK.DepartmentId", deptId);
                criteria.AddEqCriteria("ProductMaster.ProductMasterId", data.ProductMasterId);
                IList purchaseOrderDetails = PurchaseOrderDetailDAO.FindAll(criteria);
                IList purchaseOrderIds = new ArrayList();
                foreach (PurchaseOrderDetail detail in purchaseOrderDetails)
                {
                    detail.UpdateDate = DateTime.Now;
                    detail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    detail.DelFlg = 1;
                    PurchaseOrderDetailDAO.Update(detail);
                    purchaseOrderIds.Add(detail.PurchaseOrderDetailPK.PurchaseOrderId);
                }

                // delete purchase order
                if (purchaseOrderIds.Count > 0)
                {
                    criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("PurchaseOrderPK.DepartmentId", deptId);
                    criteria.AddSearchInCriteria("PurchaseOrderPK.PurchaseOrderId", purchaseOrderIds);
                    IList purchaseOrders = PurchaseOrderDAO.FindAll(criteria);
                    foreach (PurchaseOrder po in purchaseOrders)
                    {
                        po.UpdateDate = DateTime.Now;
                        po.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        po.DelFlg = 1;
                        PurchaseOrderDAO.Update(po);
                    }
                }
            }

            // delete price
            var pricePk = new DepartmentPricePK{DepartmentId = deptId, ProductMasterId = data.ProductMasterId};
            var deptPrice = DepartmentPriceDAO.FindById(pricePk);
            if (deptPrice != null)
            {
                deptPrice.UpdateDate = DateTime.Now;
                deptPrice.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                deptPrice.DelFlg = 1;
                DepartmentPriceDAO.Update(deptPrice);
            }
        }
コード例 #3
0
        private void SearchGoodsAndReturnsInRange(object sender, GoodsSaleListEventArgs args)
        {
            IList list = PurchaseOrderLogic.FindAll(args.PurchaseOrderSearchCriteria);
            IList collection = new ArrayList();
            foreach (PurchaseOrder order in list)
            {
                PurchaseOrderView view = new PurchaseOrderView();
                view.PurchaseOrder = order;
                view.PurchaseOrderId = order.PurchaseOrderPK.PurchaseOrderId;

                long SellAmount = 0;
                long SellQuantity = 0;
                string SellDescription = "";
                long RetAmount = 0;
                long RetQuantity = 0;
                string RetDescription = "";
                foreach (PurchaseOrderDetail detail in order.PurchaseOrderDetails)
                {
                    SellDescription += detail.Product.ProductMaster.ProductName + " ";
                    SellAmount += detail.Quantity*detail.Price;
                    SellQuantity += detail.Quantity;
                }

                ObjectCriteria criteria = new ObjectCriteria();
                criteria.AddEqCriteria("NextPurchaseOrderId", order.PurchaseOrderPK.PurchaseOrderId);
                criteria.AddEqCriteria("ReturnPoPK.DepartmentId", order.PurchaseOrderPK.DepartmentId);
                IList returnPOList = ReturnPoLogic.FindAll(criteria);
                foreach (ReturnPo returnPo in returnPOList)
                {
                    RetDescription += returnPo.Product.ProductMaster.ProductName + " ";
                    long retPrice = returnPo.Price;
                    if (retPrice == 0)
                    {
                        DepartmentPricePK deptPricePK = new DepartmentPricePK();
                        deptPricePK.DepartmentId = 0;
                        deptPricePK.ProductMasterId = returnPo.Product.ProductMaster.ProductMasterId;
                        DepartmentPrice price = DepartmentPriceLogic.FindById(deptPricePK);
                        if (price != null)
                        {
                            retPrice = price.Price;
                        }
                    }
                    RetAmount += returnPo.Quantity * retPrice;
                    RetQuantity += returnPo.Quantity;
                }

                view.ReturnPOList = returnPOList;
                view.SellDescription = SellDescription;
                view.SellAmount = SellAmount;
                view.SellQuantity = SellQuantity;
                view.ReturnAmount = RetAmount;
                view.ReturnDescription = RetDescription;
                view.ReturnQuantity = RetQuantity;
                view.IssueDate = order.CreateDate;
                collection.Add(view);
            }

            ObjectCriteria NAcriteria = new ObjectCriteria();
            NAcriteria.AddEqCriteria("ReturnPoPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
            NAcriteria.AddGreaterOrEqualsCriteria("ReturnPoPK.CreateDate", args.FromDate)
                .AddLesserOrEqualsCriteria("ReturnPoPK.CreateDate", args.ToDate);
            IList allReturnPOList = ReturnPoLogic.FindAll(NAcriteria);

            IList legalReturnPOList = new ArrayList();
            if(allReturnPOList!= null)
            {
                foreach (ReturnPo returnPo in allReturnPOList)
                {
                    if(string.IsNullOrEmpty(returnPo.NextPurchaseOrderId))
                            legalReturnPOList.Add(returnPo);

                }
            }

            string retNAPOId = "";
            PurchaseOrderView retNAView = new PurchaseOrderView();
            retNAView.ReturnPOList = new ArrayList();
            IList retNAList = new ArrayList();
            foreach (ReturnPo returnPo in legalReturnPOList)
            {
                if (!retNAPOId.Equals(returnPo.ReturnPoPK.PurchaseOrderId))
                {
                    if(!string.IsNullOrEmpty(retNAPOId))
                    {
                        collection.Add(retNAView);
                        retNAView = new PurchaseOrderView();
                        retNAView.ReturnPOList = new ArrayList();
                    }
                    retNAPOId = returnPo.ReturnPoPK.PurchaseOrderId;
                    retNAView.PurchaseOrderId = retNAPOId;
                    retNAView.IssueDate = returnPo.ReturnPoPK.CreateDate;
                }
                retNAView.ReturnDescription += returnPo.Product.ProductMaster.ProductName + " ";
                long retPrice = returnPo.Price;
                    if (retPrice == 0)
                    {
                        DepartmentPricePK deptPricePK = new DepartmentPricePK();
                        deptPricePK.DepartmentId = 0;
                        deptPricePK.ProductMasterId = returnPo.Product.ProductMaster.ProductMasterId;
                        DepartmentPrice price = DepartmentPriceLogic.FindById(deptPricePK);
                        if (price != null)
                        {
                            retPrice = price.Price;
                        }
                    }
                retNAView.ReturnAmount += returnPo.Quantity * retPrice;
                retNAView.ReturnQuantity += returnPo.Quantity;
                retNAView.ReturnPOList.Add(returnPo);
            }
            collection.Add(retNAView);

            GoodsSaleListEventArgs goodsSaleListEventArgs = new GoodsSaleListEventArgs();
            goodsSaleListEventArgs.PurchaseOrderViewList = collection;
            EventUtility.fireEvent(CompletedGoodsSaleListSearchEvent, this, goodsSaleListEventArgs);
        }
コード例 #4
0
ファイル: StockInLogicImpl.cs プロジェクト: DelLitt/opmscoral
        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);
        }
コード例 #5
0
        void deptStockOutView_DispatchDepartmentStockOut(object sender, DepartmentStockOutEventArgs e)
        {
            Department destDept = DepartmentLogic.FindById(e.DepartmentStockOut.OtherDepartmentId);
            if (destDept != null)
            {
                foreach (DepartmentStockOutDetail detail in e.DepartmentStockOut.DepartmentStockOutDetails)
                {
                    string prdMasterId = detail.Product.ProductMaster.ProductMasterId;
                    DepartmentPricePK pricePk = new DepartmentPricePK
                                                    {
                                                        DepartmentId = 0,
                                                        ProductMasterId = prdMasterId
                                                    };
                    detail.DepartmentPrice = DepartmentPriceLogic.FindById(pricePk);
                }

                SyncFromDeptToDept fromDeptToDept = new SyncFromDeptToDept
                                                        {
                                                            DestinationDept = destDept
                                                        };
                fromDeptToDept.DepartmentStockOutList = new ArrayList();
                fromDeptToDept.DepartmentStockOutList.Add(e.DepartmentStockOut);

                CopyToSyncFolder(fromDeptToDept);

                ServerServiceClient serverService = new ServerServiceClient(new InstanceContext(this), ClientSetting.ServiceBinding);
                serverService.MakeRawDepartmentStockOut(destDept,e.DepartmentStockOut,new DepartmentPrice());

            }
        }
コード例 #6
0
 void deptStockOutView_PrepareDepartmentStockOutForPrintEvent(object sender, DepartmentStockOutEventArgs e)
 {
     Department destDept = DepartmentLogic.FindById(e.DepartmentStockOut.OtherDepartmentId);
     if (destDept != null)
     {
         foreach (DepartmentStockOutDetail detail in e.DepartmentStockOut.DepartmentStockOutDetails)
         {
             string prdMasterId = detail.Product.ProductMaster.ProductMasterId;
             DepartmentPricePK pricePk = new DepartmentPricePK
             {
                 DepartmentId = 0,
                 ProductMasterId = prdMasterId
             };
             detail.DepartmentPrice = DepartmentPriceLogic.FindById(pricePk);
         }
     }
 }
コード例 #7
0
        void mainStockInView_DispatchDepartmentStockOut(object sender, DepartmentStockOutEventArgs e)
        {
            Department destDept = DepartmentLogic.FindById(e.DepartmentStockOut.OtherDepartmentId);
            if (destDept != null)
            {
                foreach (DepartmentStockOutDetail detail in e.DepartmentStockOut.DepartmentStockOutDetails)
                {
                    string prdMasterId = detail.Product.ProductMaster.ProductMasterId;
                    DepartmentPricePK pricePk = new DepartmentPricePK
                                                    {
                                                        DepartmentId = 0,
                                                        ProductMasterId = prdMasterId
                                                    };
                    detail.DepartmentPrice = DepartmentPriceLogic.FindById(pricePk);
                }

                ServerServiceClient serverService = new ServerServiceClient(new InstanceContext(this), ClientSetting.ServiceBinding);
                serverService.MakeRawDepartmentStockOut(destDept,e.DepartmentStockOut,new DepartmentPrice());
            }
        }
コード例 #8
0
        public void _departmentStockOutView_SaveStockOutEvent(object sender, DepartmentStockOutEventArgs e)
        {
            if (e.DepartmentStockOut.DepartmentStockOutPK == null || e.DepartmentStockOut.DepartmentStockOutPK.StockOutId == 0)
            {
                if(e.DepartmentStockOut.DepartmentStockOutDetails!= null && e.DepartmentStockOut.DepartmentStockOutDetails.Count > 0)
                {
                    foreach (DepartmentStockOutDetail detail in e.DepartmentStockOut.DepartmentStockOutDetails)
                    {
                        string prdMasterId = detail.Product.ProductMaster.ProductMasterId;
                        DepartmentPricePK pricePk = new DepartmentPricePK
                        {
                            DepartmentId = 0,
                            ProductMasterId = prdMasterId
                        };
                        detail.DepartmentPrice = DepartmentPriceLogic.FindById(pricePk);
                        if (detail.DepartmentPrice != null)
                        {
                            if ("1".Equals(detail.Description)) // if ban si
                            {
                                if(detail.DepartmentPrice.WholeSalePrice == 0 )
                                {
                                    e.EventResult = " Error !";
                                    throw new BusinessException(" Giá sỉ của " + detail.Product.ProductMaster.ProductName + " là 0 ?!");
                                }
                                detail.Description = detail.DepartmentPrice.WholeSalePrice.ToString();
                            }
                            else
                            {
                                if (ClientSetting.IsSubStock())
                                {
                                    if (detail.DepartmentPrice.Price == 0)
                                    {
                                        e.EventResult = null;
                                        throw new BusinessException(" Giá lẻ của " +
                                                                    detail.Product.ProductMaster.ProductName +
                                                                    " là 0 ?!");
                                    }
                                }
                                detail.Description = detail.DepartmentPrice.Price.ToString();
                            }
                        }
                    }
                }

                DepartmentStockOutLogic.Add(e.DepartmentStockOut);
                ClientUtility.Log(logger, e.DepartmentStockOut.ToString(), "Lưu xuất kho cửa hàng");
                e.EventResult = "Success";
            }
        }
コード例 #9
0
ファイル: StockInLogicImpl.cs プロジェクト: DelLitt/opmscoral
        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;
        }
コード例 #10
0
        private void PopulateGridByProductMaster(IList colorList, IList sizeList)
        {
            foreach (ProductColor color in colorList)
                {
                    foreach (ProductSize size in sizeList)
                    {
                        foreach (ProductMaster productMaster in productMasterList)
                        {

                        // do not allow duplicate
                        bool goOut = false;
                        foreach (StockInDetail detail in deptSIDetailList)
                        {
                            if (detail.Product != null
                                && detail.Product.ProductMaster != null
                                && productMaster.ProductMasterId.Equals(detail.Product.ProductMaster.ProductMasterId))
                            {
                                goOut = true;
                            }
                        }
                        if (goOut)
                        {
                            continue;
                        }

                        if (productMaster.ProductColor != null
                            && productMaster.ProductColor.ColorId == color.ColorId
                            && productMaster.ProductSize != null
                            && productMaster.ProductSize.SizeId == size.SizeId)
                        {
                            StockInDetail stockInDetail = deptSIDetailList.AddNew();
                            stockInDetail.Price = NumberUtility.ParseLong(txtPriceIn.Text);
                            stockInDetail.SellPrice = NumberUtility.ParseLong(txtPriceOut.Text);
                            stockInDetail.StockInDetailPK = new StockInDetailPK();
                            if (stockInDetail.Product == null)
                            {
                                stockInDetail.Product = new Product();
                            }
                            stockInDetail.Product.ProductMaster = productMaster;
                            if (stockInDetail.DepartmentPrice == null)
                            {
                                stockInDetail.DepartmentPrice = new DepartmentPrice();
                                DepartmentPricePK pricePk = new DepartmentPricePK
                                                                {
                                                                    ProductMasterId =
                                                                        stockInDetail.Product.ProductMaster.
                                                                        ProductMasterId,
                                                                    DepartmentId = 0
                                                                };
                                stockInDetail.DepartmentPrice.DepartmentPricePK = pricePk;
                            }
                            stockInDetail.DepartmentPrice.Price = NumberUtility.ParseLong(txtPriceOut.Text);
                            stockInDetail.DepartmentPrice.WholeSalePrice =
                                    NumberUtility.ParseLong(txtWSPriceOut.Text);
                            stockInDetail.WholeSalePrice = NumberUtility.ParseLong(txtWSPriceOut.Text);
                            deptSIDetailList.EndNew(deptSIDetailList.Count - 1);
                        }
                    }
                }

            }
            bdsStockIn.ResetBindings(false);
            dgvDeptStockIn.Refresh();
            dgvDeptStockIn.Invalidate();
        }
コード例 #11
0
ファイル: StockInLogicImpl.cs プロジェクト: DelLitt/opmscoral
        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;
            }
        }
コード例 #12
0
ファイル: SubStockConsumer.cs プロジェクト: DelLitt/opmscoral
        public void NotifyRequestDepartmentStockOut(long departmentId)
        {
            //ClientUtility.Log(logger, departmentId + " requesting stock-out information.");
            if(serverService == null)
            {
                return;
            }
            ((MainForm)GlobalCache.Instance().MainForm).ServiceStatus.Text = " Đang nhận thông tin ...";
            ObjectCriteria objectCriteria = new ObjectCriteria();
            objectCriteria.AddEqCriteria("OtherDepartmentId", departmentId);
            objectCriteria.AddEqCriteria("ConfirmFlg", (long)3);

            IList list = DepartmentStockOutLogic.FindAll(objectCriteria);
            Department destDept  = new Department
                                       {
                                           DepartmentId = departmentId
                                       } ;
            if(list!= null && list.Count > 0 )
            {
                ClientUtility.Log(logger, " Co " + list.Count + " phieu xuat hang ve " + departmentId);
                ((MainForm)GlobalCache.Instance().MainForm).ServiceStatus.Text = " Gửi thông tin ...";
                foreach (DepartmentStockOut departmentStockOut in list)
                {
                    foreach (DepartmentStockOutDetail detail in departmentStockOut.DepartmentStockOutDetails)
                    {
                        string prdMasterId = detail.Product.ProductMaster.ProductMasterId;
                        DepartmentPricePK pricePk = new DepartmentPricePK
                        {
                            DepartmentId = 0,
                            ProductMasterId = prdMasterId
                        };
                        detail.DepartmentPrice = DepartmentPriceLogic.FindById(pricePk);
                    }
                }
                DepartmentStockOut[] array = new DepartmentStockOut[list.Count];
                int i = 0;
                foreach (DepartmentStockOut @out in list)
                {
                    array[i] = @out;
                    i++;
                }
                serverService.MakeMultiDepartmentStockOut(destDept,array, new DepartmentPrice());
                ClientUtility.Log(logger, departmentId + " da duoc gui thong tin xuat hang.");
            }
        }
コード例 #13
0
 void _departmentStockInView_LoadGoodsByNameEvent(object sender, MainStockInEventArgs e)
 {
     StockInDetail detail = e.SelectedStockInDetail;
     ObjectCriteria objectCriteria = new ObjectCriteria();
     objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
     objectCriteria.AddEqCriteria("ProductName", detail.Product.ProductMaster.ProductName);
     IList list  = ProductMasterLogic.FindAll(objectCriteria);
     e.FoundProductMasterList = list;
     if (list == null || list.Count == 0)
     {
         return;
     }
     ProductMaster prodMaster = list[0] as ProductMaster;
     detail.Product.ProductMaster = prodMaster;
     e.SelectedStockInDetail = detail;
     ObjectCriteria priceCrit = new ObjectCriteria();
     DepartmentPricePK pricePk = new DepartmentPricePK
                                     {
                                         ProductMasterId = prodMaster.ProductMasterId,
                                         DepartmentId = 0
                                     };
     DepartmentPrice price = DepartmentPriceLogic.FindById(pricePk);
     e.DepartmentPrice = price;
 }
コード例 #14
0
 void _departmentStockInView_GetPriceEvent(object sender, MainStockInEventArgs e)
 {
     var pk = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = e.ProductMasterIdForPrice };
     e.DepartmentPrice = DepartmentPriceLogic.FindById(pk);
 }
コード例 #15
0
        public void Update(DepartmentStockIn data)
        {
            data.DepartmentId = CurrentDepartment.Get().DepartmentId;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            int delFlg = 0;
            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                // add product
                Product product = stockInDetail.Product;
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    // TODO product.ProductId = productId++;
                    product.CreateDate = DateTime.Now;
                    product.UpdateDate = DateTime.Now;
                    product.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    product.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    ProductDAO.Add(product);

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

                    // dept stock
                    var stockPk = new DepartmentStockPK { DepartmentId = data.DepartmentId, ProductId = product.ProductId };
                    var departmentStock = new DepartmentStock
                    {
                        DepartmentStockPK = stockPk,
                        CreateDate = DateTime.Now,
                        UpdateDate = DateTime.Now,
                        Product = product,
                        /*Quantity = product.Quantity,
                        GoodQuantity =product.Quantity,*/
                        Quantity = stockInDetail.Quantity,
                        GoodQuantity =stockInDetail.Quantity,
                        OnStorePrice = stockInDetail.OnStorePrice
                    };
                    departmentStock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    departmentStock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    DepartmentStockDAO.Add(departmentStock);

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

                    var price = DepartmentPriceDAO.FindById(pricePk);
                    if (price == null)
                    {
                        price = new DepartmentPrice { DepartmentPricePK = pricePk, Price = stockInDetail.OnStorePrice, 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 DepartmentStockInDetailPK { DepartmentId = data.DepartmentId, ProductId = product.ProductId, StockInId = data.DepartmentStockInPK.StockInId};
                    stockInDetail.DepartmentStockInDetailPK = detailPK;
                    stockInDetail.UpdateDate = DateTime.Now;
                    stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    DepartmentStockInDetailDAO.Update(stockInDetail);

                    // update stock
                    var stockPk = new DepartmentStockPK { DepartmentId = data.DepartmentId, ProductId = product.ProductId};
                    var departmentStock = DepartmentStockDAO.FindById(stockPk);
                    departmentStock.UpdateDate = DateTime.Now;
                    if (stockInDetail.DelFlg == 0)
                    {
                        /*departmentStock.Quantity = departmentStock.Quantity -
                                                   (stockInDetail.OldQuantity - stockInDetail.Quantity);*/
                        departmentStock.GoodQuantity = departmentStock.GoodQuantity -
                                                   (stockInDetail.OldQuantity - stockInDetail.Quantity);
                        departmentStock.Quantity = departmentStock.GoodQuantity + departmentStock.ErrorQuantity +
                                                   departmentStock.LostQuantity + departmentStock.DamageQuantity +
                                                   departmentStock.UnconfirmQuantity;
                    }
                    else
                    {
                        departmentStock.DelFlg = 1;
                    }
                    departmentStock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    departmentStock.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    DepartmentStockDAO.Update(departmentStock);

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

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

            if (delFlg == data.DepartmentStockInDetails.Count)
            {
                data.DelFlg = 1;
            }
            DepartmentStockInDAO.Update(data);
        }