コード例 #1
0
 public DepartmentPrice Add(DepartmentPrice data)
 {
     DepartmentPriceDAO.Add(data);
     return data;
 }
コード例 #2
0
 public void Delete(DepartmentPrice data)
 {
     DepartmentPriceDAO.Delete(data);
 }
コード例 #3
0
 /// <summary>
 /// Add DepartmentPrice to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public DepartmentPrice Add(DepartmentPrice data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
コード例 #4
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     string newPrice = txtSellPrice.Text;
     if (string.IsNullOrEmpty(newPrice))
     {
         errorProvider.SetError(txtSellPrice, "Giá niêm yết phải được nhập và lớn hơn 0");
     }
     else
     {
         long sellPrice = 0;
         if (!NumberUtility.CheckLong(newPrice.Replace(".", ""), out sellPrice))
         {
             errorProvider.SetError(txtSellPrice, "Giá niêm yết phải là số nguyên");
         }
         else
         {
             var eventArgs = new DepartmentStockDetailEventArgs();
             if (DepartmentPrice != null)
             {
                 DepartmentPrice.Price = sellPrice;
             }
             else
             {
                 eventArgs.IsNewPrice = true;
                 DepartmentPrice = new DepartmentPrice{DepartmentPricePK = new DepartmentPricePK{DepartmentId = 0, ProductMasterId = ProductMaster.ProductMasterId}, Price = sellPrice};
             }
             eventArgs.ProductPrice = DepartmentPrice;
             EventUtility.fireEvent(SaveDepartmentPriceEvent, this, eventArgs);
             MessageBox.Show("Lưu thành công");
         }
     }
 }
コード例 #5
0
ファイル: ServerService.cs プロジェクト: DelLitt/opmscoral
        public void MakeMultiDepartmentStockOut(Department department, DepartmentStockOut[] stockOutList, DepartmentPrice price)
        {
            ServerUtility.Log(logger, " Xuat hang di " + department.DepartmentId);
            _callbackList.ForEach(
                delegate(IDepartmentStockOutCallback callback)
                {
                    try
                    {
                        // dispatch stock-out to department
                        callback.NotifyNewMultiDepartmentStockOut(department, stockOutList, price);
                    }
                    catch (Exception)
                    {

                    }
                });
        }
コード例 #6
0
        private static object[] AddProductToDataGrid(DepartmentPrice stockInDetail)
        {
            var obj = new object[MAX_COLUMNS];
            obj[PRODUCT_ID_POS] = stockInDetail.ProductMaster.ProductMasterId;
            obj[PRODUCT_UPDATE_DATE_POS] = stockInDetail.UpdateDate.ToString("dd/MM/yyyy HH:mm:ss");
            obj[PRODUCT_OLD_PRICE_POS] = stockInDetail.Price.ToString("#,##", CultureInfo.CreateSpecificCulture("de-DE"));
            obj[PRODUCT_ID_POS] = stockInDetail.ProductMaster.ProductMasterId;
            obj[PRODUCT_NAME_POS] = stockInDetail.ProductMaster.ProductName;
            if (stockInDetail.ProductMaster.ProductType != null)
            {
                obj[PRODUCT_TYPE_POS] = stockInDetail.ProductMaster.ProductType.TypeName;
            }
            if (stockInDetail.ProductMaster.ProductSize != null)
            {
                obj[PRODUCT_SIZE_POS] = stockInDetail.ProductMaster.ProductSize.SizeName;
            }
            if (stockInDetail.ProductMaster.ProductColor != null)
            {
                obj[PRODUCT_COLOR_POS] = stockInDetail.ProductMaster.ProductColor.ColorName;
            }
            if (stockInDetail.ProductMaster.Country != null)
            {
                obj[PRODUCT_COUNTRY_POS] = stockInDetail.ProductMaster.Country.CountryName;
            }
            if (stockInDetail.ProductMaster.Manufacturer != null)
            {
                obj[PRODUCT_MANUFACTURER_POS] = stockInDetail.ProductMaster.Manufacturer.ManufacturerName;
            }
            if (stockInDetail.ProductMaster.Distributor != null)
            {
                obj[PRODUCT_SUPPLIER_POS] = stockInDetail.ProductMaster.Distributor.DistributorName;
            }

            return obj;
        }
コード例 #7
0
        public void Sync(SyncFromMainToDepartment syncFromMainToDepartment)
        {
            IList prdMasterUpdateList = new ArrayList();
            IList needUpdateStocks = new ArrayList();
            IList needAddNewStocks = new ArrayList();
            // fix departmentStock first

            IList deptStockTemps = syncFromMainToDepartment.DepartmentStockTemps;
            if (deptStockTemps != null && deptStockTemps.Count > 0)
            {
                DepartmentStockOut deptStockOut = new DepartmentStockOut();
                object maxDSOId = DepartmentStockOutDAO.SelectSpecificType(null,
                                                                           Projections.Max(
                                                                               "DepartmentStockOutPK.StockOutId"));
                long maxDeptStockOutId = (maxDSOId != null ? (long) maxDSOId + 1 : 1);

                object maxDetId = DepartmentStockOutDetailDAO.SelectSpecificType(null,
                                                                                 Projections.Max("DepartmentStockOutDetailPK.StockOutDetailId"));
                long maxDeptStockOutDetId = (maxDetId != null ? (long) maxDetId + 1 : 1);
                deptStockOut.DepartmentStockOutPK = new DepartmentStockOutPK
                                                        {
                                                            DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                            StockOutId = maxDeptStockOutId

                                                        };
                deptStockOut.DefectStatus = new StockDefectStatus {DefectStatusId = 5}; // xuat tra ve nha san xuat
                deptStockOut.ConfirmFlg = 1; // can xac nhan tu kho chinh

                deptStockOut.StockOutDate = DateTime.Now;
                deptStockOut.CreateDate = DateTime.Now;
                deptStockOut.UpdateDate = DateTime.Now;
                deptStockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                deptStockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                deptStockOut.DepartmentStockOutDetails = new ArrayList();
                foreach (DepartmentStockTemp deptStockTemp in deptStockTemps)
                {

                    // find the stock checking
                    DepartmentStockTemp processedDeptStockTemp =
                    DepartmentStockTempDAO.FindById(deptStockTemp.DepartmentStockTempPK);

                    // if exist, then check whether was it processed.
                    if(processedDeptStockTemp!=null)
                    {
                        // if processed
                        if(processedDeptStockTemp.Fixed == 1)
                        {
                            continue; // process to next stock checking row
                        }
                    }
                    else // not exist, maybe error ..
                    {
                        continue; // process to next stock checking row
                    }

                    long realQty = deptStockTemp.GoodQuantity + deptStockTemp.ErrorQuantity +
                                   deptStockTemp.DamageQuantity +
                                   deptStockTemp.LostQuantity + deptStockTemp.UnconfirmQuantity;
                    if (realQty < deptStockTemp.Quantity)
                    {
                        long returnToStockQty = deptStockTemp.Quantity - realQty;
                        DepartmentStockOutDetail deptSODet = new DepartmentStockOutDetail();
                        deptSODet.DepartmentStockOutDetailPK = new DepartmentStockOutDetailPK();
                        deptSODet.DepartmentStockOutDetailPK.DepartmentId = CurrentDepartment.Get().DepartmentId;
                        deptSODet.DepartmentStockOutDetailPK.StockOutDetailId = maxDeptStockOutDetId++;
                        /*deptSODet.StockOutDetailId = maxDeptStockOutDetId++;*/
                        deptSODet.Product = deptStockTemp.Product;
                        deptSODet.ProductMaster = deptStockTemp.ProductMaster;
                        deptSODet.DepartmentStockOut = deptStockOut;
                        deptSODet.Description = "Số liệu dư được xuất về nhà sản xuất hủy";
                        deptSODet.CreateDate = DateTime.Now;
                        deptSODet.UpdateDate = DateTime.Now;
                        deptSODet.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        deptSODet.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        deptSODet.StockOutId = deptStockOut.DepartmentStockOutPK.StockOutId;
                        deptSODet.DepartmentId = deptStockOut.DepartmentStockOutPK.DepartmentId;

                        deptSODet.GoodQuantity = returnToStockQty;
                        deptSODet.Quantity = returnToStockQty;
                        deptSODet.DefectStatus = new StockDefectStatus {DefectStatusId = 5}; // xuat tra ve nha san xuat
                        deptStockOut.DepartmentStockOutDetails.Add(deptSODet);
                    }
                    DepartmentStockPK stockPk = new DepartmentStockPK
                                                    {
                                                        DepartmentId = deptStockTemp.DepartmentStockTempPK.DepartmentId,
                                                        ProductId = deptStockTemp.DepartmentStockTempPK.ProductId
                                                    };
                    DepartmentStock stock = DepartmentStockDAO.FindById(stockPk);

                    if (stock != null)
                    {
                        prdMasterUpdateList.Add(stock.Product.ProductMaster);
                        long differGoodQty = stock.Quantity - deptStockTemp.Quantity;
                        stock.GoodQuantity = deptStockTemp.GoodQuantity + differGoodQty;
                        if(deptStockTemp.GoodQuantity > deptStockTemp.Quantity) // stock them vo
                        {
                            // lay so luong nguyen thuy de co the cong them khi stock in vao cua hang
                            stock.GoodQuantity = stock.Quantity;
                        }
                        stock.ErrorQuantity = deptStockTemp.ErrorQuantity;
                        stock.LostQuantity = deptStockTemp.LostQuantity;
                        stock.DamageQuantity = deptStockTemp.DamageQuantity;
                        stock.UnconfirmQuantity = deptStockTemp.UnconfirmQuantity;
                        stock.Quantity = stock.GoodQuantity + stock.ErrorQuantity + stock.LostQuantity +
                                         stock.DamageQuantity + stock.UnconfirmQuantity;
                        needUpdateStocks.Add(stock);
                    }

                    deptStockTemp.DelFlg = 1;
                    processedDeptStockTemp.Fixed = 1;
                    processedDeptStockTemp.DelFlg = 1;
                    DepartmentStockTempDAO.Update(processedDeptStockTemp);
                }
                if (deptStockOut.DepartmentStockOutDetails.Count > 0)
                {
                    DepartmentStockOutDAO.Add(deptStockOut);
                    foreach (DepartmentStockOutDetail detail in deptStockOut.DepartmentStockOutDetails)
                    {
                        DepartmentStockOutDetailDAO.Add(detail);
                    }
                }
            }

            IList stockOutList = syncFromMainToDepartment.StockOutList;
            long deptId = syncFromMainToDepartment.Department.DepartmentId;
            string deptStr = "000";
            if(deptId > 9999)
            {
                deptStr = deptId.ToString();
            }
            else
            {
               deptStr = string.Format("{0:000}", deptId);
            }

            string dateStr = DateTime.Now.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            if(deptId > 9999)
            {
                criteria.AddGreaterCriteria("DepartmentStockInPK.StockInId", dateStr + deptStr + "000");
            }
            else
            {
                criteria.AddGreaterCriteria("DepartmentStockInPK.StockInId", dateStr + deptStr + "00000");
            }

            var maxId = DepartmentStockInDAO.SelectSpecificType(criteria, Projections.Max("DepartmentStockInPK.StockInId"));

            var stockInId ="";
            if(deptId > 9999)
            {
                stockInId = maxId == null ? dateStr + deptStr + "001" : string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
            }
            else
            {
                stockInId = maxId == null ? dateStr + deptStr + "00001" : string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
            }

            long nextDeptStockInId = Int64.Parse(stockInId);
            foreach (StockOut stockOut in stockOutList)
            {
                // convert stock out to department stock in
                DepartmentStockInMapper mapper = new DepartmentStockInMapper();
                DepartmentStockIn data = mapper.Convert(stockOut);
                data.Department = syncFromMainToDepartment.Department;
                // sync department stock in
                data.DepartmentStockInPK.StockInId = string.Format("{0:00000000000000}",nextDeptStockInId++);
                /*DepartmentStockIn DepartmentStockIn = DepartmentStockInDAO.FindById(data.DepartmentStockInPK);
                if (DepartmentStockIn == null)
                {
                    DepartmentStockInDAO.Add(data);
                }*/
                StockOut oldStockOut = StockOutDAO.FindById(stockOut.StockoutId);
                if (oldStockOut == null)
                {
                    StockOutDAO.Add(stockOut);
                    DepartmentStockInDAO.Add(data);
                }
                else
                {
                    //ObjectCriteria criteria = new ObjectCriteria();

                    // currently we do not accept update stock in
                    continue;
                    // amend for debug
                    //DepartmentStockInDAO.Update(data);
                }

                // sync department stock in detail
                IList productMasterIds = new ArrayList();
                IList productIds = new ArrayList();
                IList priceList = new ArrayList();
                IList whosalePriceList = new ArrayList();
                IList quantityList = new ArrayList();

                // put master data first
                foreach (DepartmentStockInDetail detail in data.DepartmentStockInDetails)
                {
                    detail.DepartmentStockInDetailPK.StockInId = data.DepartmentStockInPK.StockInId;
                    if (detail.Product.ProductMaster.ProductColor != null)
                    {
                        ProductColor color = ProductColorDAO.FindById(detail.Product.ProductMaster.ProductColor.ColorId);
                        if (color == null)
                        {
                            ProductColorDAO.Add(detail.Product.ProductMaster.ProductColor);
                        }
                    }
                    if (detail.Product.ProductMaster.ProductSize != null)
                    {
                        ProductSize size = ProductSizeDAO.FindById(detail.Product.ProductMaster.ProductSize.SizeId);
                        if (size == null)
                        {
                            ProductSizeDAO.Add(detail.Product.ProductMaster.ProductSize);
                        }
                    }
                    ProductType Type = ProductTypeDAO.FindById(detail.Product.ProductMaster.ProductType.TypeId);
                    if (detail.Product.ProductMaster.ProductType != null)
                    {
                        if (Type == null)
                        {
                            ProductTypeDAO.Add(detail.Product.ProductMaster.ProductType);
                        }
                    }
                    if (detail.Product.ProductMaster.Country != null)
                    {
                        Country Country = CountryDAO.FindById(detail.Product.ProductMaster.Country.CountryId);
                        if (Country == null)
                        {
                            CountryDAO.Add(detail.Product.ProductMaster.Country);
                        }
                    }
                    if (detail.Product.ProductMaster.Distributor != null)
                    {
                        Distributor Distributor =
                            DistributorDAO.FindById(detail.Product.ProductMaster.Distributor.DistributorId);
                        if (Distributor == null)
                        {
                            DistributorDAO.Add(detail.Product.ProductMaster.Distributor);
                        }
                    }
                    if (detail.Product.ProductMaster.Packager != null)
                    {
                        Packager Packager = PackagerDAO.FindById(detail.Product.ProductMaster.Packager.PackagerId);
                        if (Packager == null)
                        {
                            PackagerDAO.Add(detail.Product.ProductMaster.Packager);
                        }
                    }
                    if (detail.Product.ProductMaster.Manufacturer != null)
                    {
                        Manufacturer Manufacturer =
                            ManufacturerDAO.FindById(detail.Product.ProductMaster.Manufacturer.ManufacturerId);
                        if (Manufacturer == null)
                        {
                            ManufacturerDAO.Add(detail.Product.ProductMaster.Manufacturer);
                        }
                    }

                    //ProductMaster ProductMaster = ProductMasterDAO.FindById(detail.Product.ProductMaster.ProductMasterId);
                    ProductMaster ProductMaster = GetProductMaster(detail.Product.ProductMaster,prdMasterUpdateList);
                    if (ProductMaster == null)
                    {
                        ProductMasterDAO.Add(detail.Product.ProductMaster);
                    }
                    else
                    {

                        ProductMaster.Country = detail.Product.ProductMaster.Country;
                        ProductMaster.Packager = detail.Product.ProductMaster.Packager;
                        ProductMaster.ProductColor = detail.Product.ProductMaster.ProductColor;
                        ProductMaster.ProductFullName = detail.Product.ProductMaster.ProductFullName;
                        ProductMaster.ProductName = detail.Product.ProductMaster.ProductName;
                        ProductMaster.ProductSize = detail.Product.ProductMaster.ProductSize;
                        ProductMaster.ProductType = detail.Product.ProductMaster.ProductType;
                        ProductMaster.UpdateDate = detail.Product.ProductMaster.UpdateDate;
                        ProductMaster.UpdateId = detail.Product.ProductMaster.UpdateId;
                        ProductMaster.CreateDate = detail.Product.ProductMaster.CreateDate;
                        ProductMaster.CreateId = detail.Product.ProductMaster.CreateId;
                        ProductMaster.Distributor = detail.Product.ProductMaster.Distributor;
                        ProductMaster.Manufacturer = detail.Product.ProductMaster.Manufacturer;
                        ProductMaster.ImagePath = detail.Product.ProductMaster.ImagePath;
                        ProductMaster.ExclusiveKey = detail.Product.ProductMaster.ExclusiveKey;
                        ProductMasterDAO.Update(ProductMaster);
                    }
                    if (!productMasterIds.Contains(detail.Product.ProductMaster.ProductMasterId))
                    {
                        productMasterIds.Add(detail.Product.ProductMaster.ProductMasterId);
                        priceList.Add(detail.Price);
                        whosalePriceList.Add(detail.OnStorePrice);
                    }

                    Product Product = ProductDAO.FindById(detail.Product.ProductId);
                    if (Product == null)
                    {
                        ProductDAO.Add(detail.Product);
                    }
                    else
                    {
                        Product.UpdateDate = detail.Product.UpdateDate;
                        Product.UpdateId = detail.Product.UpdateId;
                        Product.CreateDate = detail.Product.CreateDate;
                        Product.CreateId = detail.Product.CreateId;
                        Product.ProductMaster = detail.Product.ProductMaster;
                        Product.Quantity = detail.Product.Quantity;
                        Product.Price = detail.Product.Price;
                        ProductDAO.Update(Product);
                    }

                    if (!productIds.Contains(detail.Product.ProductId))
                    {
                        productIds.Add(detail.Product.ProductId);
                        quantityList.Add(detail.Quantity);
                    }

                    DepartmentStockInDetail DepartmentStockInDetail =
                        DepartmentStockInDetailDAO.FindById(detail.DepartmentStockInDetailPK);
                    if (DepartmentStockInDetail == null)
                    {
                        DepartmentStockInDetailDAO.Add(detail);
                    }
                    else
                    {
                        DepartmentStockInDetail.UpdateDate = detail.UpdateDate;
                        DepartmentStockInDetail.UpdateId = detail.UpdateId;
                        DepartmentStockInDetail.CreateDate = detail.CreateDate;
                        DepartmentStockInDetail.CreateId = detail.CreateId;
                        DepartmentStockInDetail.Quantity = DepartmentStockInDetail.Quantity;
                        DepartmentStockInDetail.Price = DepartmentStockInDetail.Price;

                        DepartmentStockInDetailDAO.Update(DepartmentStockInDetail);
                    }
                }

                // update price
                if (productMasterIds.Count > 0)
                {
                    /*IList NotDupPMList = new ArrayList();
                    NotDupPMList = CreateNotDuplicateList(productMasterIds);*/
                    var objectCriteria = new ObjectCriteria();
                    objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    objectCriteria.AddEqCriteria("DepartmentPricePK.DepartmentId", (long)0);
                    objectCriteria.AddSearchInCriteria("DepartmentPricePK.ProductMasterId", productMasterIds);
                    IList deptPriceList = DepartmentPriceDAO.FindAll(objectCriteria);
                    int i = 0;
                    IList newPriceList = new ArrayList();
                    foreach (string productMasterId in productMasterIds)
                    {
                        DepartmentPrice price = null;
                        bool found = false;
                        foreach (DepartmentPrice price1 in deptPriceList)
                        {
                            if (price1.DepartmentPricePK.ProductMasterId.Equals(productMasterId))
                            {
                                //price = price1;
                                found = true;
                                price1.Price = (Int64)priceList[i];
                                price1.WholeSalePrice = (Int64) whosalePriceList[i];
                                break;
                            }
                        }
                        if (!found)
                        {
                            foreach (DepartmentPrice price1 in newPriceList)
                            {
                                if (price1.DepartmentPricePK.ProductMasterId.Equals(productMasterId))
                                {
                                    //price = price1;
                                    found = true;
                                    price1.Price = (Int64) priceList[i];
                                    price1.WholeSalePrice = (Int64) whosalePriceList[i];
                                    break;
                                }
                            }
                        }
                        //if (price == null)
                        if (!found)
                        {
                            price = new DepartmentPrice
                            {
                                DepartmentPricePK = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = productMasterId },
                                Price = (Int64)priceList[i],
                                WholeSalePrice = (Int64)whosalePriceList[i],
                                CreateDate = DateTime.Now,
                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                UpdateDate = DateTime.Now,
                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                            };
                            newPriceList.Add(price);
                            //DepartmentPriceDAO.Add(price);
                        }
                        /*else
                        {
                            price.UpdateDate = DateTime.Now;
                            price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            DepartmentPriceDAO.Update(price);
                        }*/
                        i++;
                    }
                    // patch for update stock
                        try
                        {
                            foreach (DepartmentPrice price in deptPriceList)
                            {
                                DepartmentPriceDAO.Update(price);
                            }
                            foreach (DepartmentPrice price in newPriceList)
                            {
                                DepartmentPriceDAO.Add(price);
                            }
                        }
                        catch (Exception)
                        {

                        }
                }

                // mix 2 lists
                // find lack productIds
                IList lackProductIds = new ArrayList();
                if(productIds.Count > 0)
                {
                    foreach (string productId in productIds)
                    {
                        bool hasFound = false;
                        foreach (DepartmentStock departmentStock in needUpdateStocks)
                        {
                            if(productId.Equals(departmentStock.DepartmentStockPK.ProductId))
                            {
                                hasFound = true;
                                break;
                            }
                        }
                        if(!hasFound)
                        {
                            lackProductIds.Add(productId);
                        }
                    }
                /*}

                if (productIds.Count > 0)
                {*/
                    if (lackProductIds.Count > 0)
                    {
                        var objectCrit1 = new ObjectCriteria();
                        objectCrit1.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                        objectCrit1.AddEqCriteria("DepartmentStockPK.DepartmentId",
                                                  data.DepartmentStockInPK.DepartmentId);

                        objectCrit1.AddSearchInCriteria("DepartmentStockPK.ProductId", lackProductIds);
                        IList stockList = DepartmentStockDAO.FindAll(objectCrit1);
                        if(stockList!= null && stockList.Count > 0)
                        {
                            foreach (DepartmentStock departmentStock in stockList)
                            {
                                needUpdateStocks.Add(departmentStock);
                            }
                        }
                    }
                    int i = 0;
                    foreach (string productId in productIds)
                    {
                        DepartmentStock stock = null;
                        foreach (DepartmentStock needUpdateStock in needUpdateStocks)
                        {
                            if (needUpdateStock.DepartmentStockPK.ProductId.Equals(productId))
                            {
                                stock = needUpdateStock;
                                //stock.Quantity += (Int64)quantityList[i];
                                needUpdateStock.GoodQuantity += (Int64)quantityList[i];
                                needUpdateStock.Quantity += (Int64)quantityList[i];
                                break;
                            }
                        }
                        if (stock == null)
                        {
                            // check in add new stock
                            foreach (DepartmentStock newStock in needAddNewStocks)
                            {
                                if(newStock.DepartmentStockPK.ProductId.Equals(productId))
                                {
                                    stock = newStock;
                                    //stock.Quantity += (Int64)quantityList[i];
                                    newStock.GoodQuantity += (Int64)quantityList[i];
                                    newStock.Quantity += (Int64)quantityList[i];
                                    break;
                                }
                            }
                            // if not found in addnewStock so we create new stock
                            if (stock == null)
                            {
                                stock = new DepartmentStock
                                            {
                                                DepartmentStockPK =
                                                    new DepartmentStockPK
                                                        {
                                                            DepartmentId = data.DepartmentStockInPK.DepartmentId,
                                                            ProductId = productId
                                                        },
                                                Quantity = (Int64) quantityList[i],
                                                GoodQuantity = (Int64) quantityList[i],
                                                CreateDate = DateTime.Now,
                                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                                UpdateDate = DateTime.Now,
                                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                                            };
                                needAddNewStocks.Add(stock);
                            }
                            /*try
                            {
                                stock = new DepartmentStock
                                {
                                    DepartmentStockPK = new DepartmentStockPK { DepartmentId = data.DepartmentStockInPK.DepartmentId, ProductId = productId },
                                    Quantity = (Int64)quantityList[i],
                                    GoodQuantity = (Int64)quantityList[i],
                                    CreateDate = DateTime.Now,
                                    CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                    UpdateDate = DateTime.Now,
                                    UpdateId = ClientInfo.getInstance().LoggedUser.Name
                                };
                                DepartmentStockDAO.Add(stock);
                            }
                            catch (Exception)
                            {

                            }*/

                        }
                        /*else
                        {
                            stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            stock.UpdateDate = DateTime.Now;
                            DepartmentStockDAO.Update(stock);
                        }*/
                        i++;
                    }
                }

            }

            // update stock
            foreach (DepartmentStock stock in needUpdateStocks)
            {
                    stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stock.UpdateDate = DateTime.Now;
                    DepartmentStockDAO.Update(stock);
            }
            // add new stock
            foreach (DepartmentStock addNewStock in needAddNewStocks)
            {
                DepartmentStockDAO.Add(addNewStock);
            }

            // update common data

            if (syncFromMainToDepartment.Department != null)
            {
                Department dept = DepartmentDAO.FindById(syncFromMainToDepartment.Department.DepartmentId);
                if (dept == null)
                {
                    DepartmentDAO.Add(syncFromMainToDepartment.Department);
                }
                else
                {
                    //dept.Active = data.Department.Active;
                    dept.Address = syncFromMainToDepartment.Department.Address;
                    dept.DepartmentName = syncFromMainToDepartment.Department.DepartmentName;
                    dept.ManagerId = syncFromMainToDepartment.Department.ManagerId;
                    dept.StartDate = syncFromMainToDepartment.Department.StartDate;
                    DepartmentDAO.Update(dept);
                }
                foreach (Employee employee in syncFromMainToDepartment.Department.Employees)
                {
                    Employee emp = EmployeeDAO.FindById(employee.EmployeePK);
                    if (emp == null)
                    {
                        EmployeeDAO.Add(employee);
                        if (employee.EmployeeInfo != null)
                        {
                            EmployeeDetailDAO.Add(employee.EmployeeInfo);
                        }
                    }
                    else
                    {
                        emp.DelFlg = employee.DelFlg;
                        EmployeeDAO.Update(emp);
                        if (employee.EmployeeInfo != null)
                        {
                            EmployeeDetailDAO.Update(employee.EmployeeInfo);
                        }
                    }
                }
            }

            if(syncFromMainToDepartment.UserInfoList!=null && syncFromMainToDepartment.UserInfoList.Count > 0)
            {
                IList needCreateRoleList = new ArrayList();
                IList needCheckRoleList = new ArrayList();
                IList roleList = RoleDAO.FindAll();

                foreach (LoginModel model in syncFromMainToDepartment.UserInfoList)
                {
                    foreach (RoleModel role in model.Roles)
                    {
                        needCheckRoleList.Add(role);
                    }
                }

                // check role
                foreach (RoleModel roleModel in needCheckRoleList)
                {
                    bool hasFound = false;
                    foreach (RoleModel existRole in roleList)
                    {
                        if (existRole.Id == roleModel.Id)
                        {
                            if (!existRole.Name.Equals(roleModel.Name)) existRole.Name = roleModel.Name;
                            hasFound = true;
                            break;
                        }
                    }

                    if (!hasFound)
                        {
                            bool addedToCreateList = false;
                            foreach (RoleModel needCreateRole in needCreateRoleList)
                            {
                                if(roleModel.Id == needCreateRole.Id)
                                {
                                    addedToCreateList = true;
                                    break;
                                }
                            }
                            if (!addedToCreateList) needCreateRoleList.Add(roleModel);
                        }

                }
                foreach (RoleModel model in roleList)
                {
                    RoleDAO.Update(model);
                }
                foreach (RoleModel model in needCreateRoleList)
                {
                    RoleDAO.Add(model);
                }
                foreach (LoginModel model in syncFromMainToDepartment.UserInfoList)
                {

                    LoginModel dbUserModel = LoginDAO.FindById(model.Username);
                    if (dbUserModel != null)
                    {
                        dbUserModel.Username = model.Username;
                        if (!dbUserModel.Password.Equals(model.Password))
                        {
                            if (DateTime.Compare(dbUserModel.UpdateDate, model.UpdateDate) < 0)
                            {
                                dbUserModel.Password = model.Password;
                            }
                        }
                        dbUserModel.Roles = model.Roles;
                        dbUserModel.EmployeeInfo = model.EmployeeInfo;
                        dbUserModel.Suspended = model.Suspended;
                        dbUserModel.Deleted = model.Deleted;

                        LoginDAO.Update(dbUserModel);
                    }
                    else
                    {
                        LoginDAO.Add(model);
                    }
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        public void Sync(DepartmentStockIn data)
        {
            DepartmentStockIn DepartmentStockIn = DepartmentStockInDAO.FindById(data.DepartmentStockInPK);
            if (DepartmentStockIn == null)
            {
                DepartmentStockInDAO.Add(data);
            }
            else
            {
                ObjectCriteria criteria = new ObjectCriteria();

                // currently we do not accept update stock in
                //return;
                // amend for debug
                DepartmentStockInDAO.Update(data);
            }

            IList productMasterIds = new ArrayList();
            IList productIds = new ArrayList();
            IList priceList = new ArrayList();
            IList quantityList = new ArrayList();

            // put master data first
            foreach (DepartmentStockInDetail detail in data.DepartmentStockInDetails)
            {
                if (detail.Product.ProductMaster.ProductColor != null)
                {
                    ProductColor color = ProductColorDAO.FindById(detail.Product.ProductMaster.ProductColor.ColorId);
                    if (color == null)
                    {
                        ProductColorDAO.Add(detail.Product.ProductMaster.ProductColor);
                    }
                }
                if (detail.Product.ProductMaster.ProductSize != null)
                {
                    ProductSize Size = ProductSizeDAO.FindById(detail.Product.ProductMaster.ProductSize.SizeId);
                    if (Size == null)
                    {
                        ProductSizeDAO.Add(detail.Product.ProductMaster.ProductSize);
                    }
                }
                if (detail.Product.ProductMaster.ProductType != null)
                {
                    ProductType Type = ProductTypeDAO.FindById(detail.Product.ProductMaster.ProductType.TypeId);
                    if (Type == null)
                    {
                        ProductTypeDAO.Add(detail.Product.ProductMaster.ProductType);
                    }
                }
                if (detail.Product.ProductMaster.Country != null)
                {
                    Country Country = CountryDAO.FindById(detail.Product.ProductMaster.Country.CountryId);
                    if (Country == null)
                    {
                        CountryDAO.Add(detail.Product.ProductMaster.Country);
                    }
                }
                if (detail.Product.ProductMaster.Distributor != null)
                {
                    Distributor Distributor =
                        DistributorDAO.FindById(detail.Product.ProductMaster.Distributor.DistributorId);
                    if (Distributor == null)
                    {
                        DistributorDAO.Add(detail.Product.ProductMaster.Distributor);
                    }
                }
                if (detail.Product.ProductMaster.Packager != null)
                {
                    Packager Packager = PackagerDAO.FindById(detail.Product.ProductMaster.Packager.PackagerId);
                    if (Packager == null)
                    {
                        PackagerDAO.Add(detail.Product.ProductMaster.Packager);
                    }
                }
                if (detail.Product.ProductMaster.Manufacturer != null)
                {
                    Manufacturer Manufacturer =
                        ManufacturerDAO.FindById(detail.Product.ProductMaster.Manufacturer.ManufacturerId);
                    if (Manufacturer == null)
                    {
                        ManufacturerDAO.Add(detail.Product.ProductMaster.Manufacturer);
                    }
                }

                ProductMaster ProductMaster = ProductMasterDAO.FindById(detail.Product.ProductMaster.ProductMasterId);
                if (ProductMaster == null)
                {
                    ProductMasterDAO.Add(detail.Product.ProductMaster);
                }
                else
                {
                    ProductMaster.Country = detail.Product.ProductMaster.Country;
                    ProductMaster.Packager = detail.Product.ProductMaster.Packager;
                    ProductMaster.ProductColor = detail.Product.ProductMaster.ProductColor;
                    ProductMaster.ProductFullName = detail.Product.ProductMaster.ProductFullName;
                    ProductMaster.ProductName = detail.Product.ProductMaster.ProductName;
                    ProductMaster.ProductSize = detail.Product.ProductMaster.ProductSize;
                    ProductMaster.ProductType = detail.Product.ProductMaster.ProductType;
                    ProductMaster.UpdateDate = detail.Product.ProductMaster.UpdateDate;
                    ProductMaster.UpdateId = detail.Product.ProductMaster.UpdateId;
                    ProductMaster.CreateDate = detail.Product.ProductMaster.CreateDate;
                    ProductMaster.CreateId = detail.Product.ProductMaster.CreateId;
                    ProductMaster.Distributor = detail.Product.ProductMaster.Distributor;
                    ProductMaster.Manufacturer = detail.Product.ProductMaster.Manufacturer;
                    ProductMaster.ImagePath = detail.Product.ProductMaster.ImagePath;
                    ProductMaster.ExclusiveKey = detail.Product.ProductMaster.ExclusiveKey;

                    ProductMasterDAO.Update(ProductMaster);
                }
                if (!productMasterIds.Contains(detail.Product.ProductMaster.ProductMasterId))
                {
                    productMasterIds.Add(detail.Product.ProductMaster.ProductMasterId);
                    priceList.Add(detail.Price);
                }

                Product Product = ProductDAO.FindById(detail.Product.ProductId);
                if (Product == null)
                {
                    ProductDAO.Add(detail.Product);
                }
                else
                {
                    Product.UpdateDate = detail.Product.UpdateDate;
                    Product.UpdateId = detail.Product.UpdateId;
                    Product.CreateDate = detail.Product.CreateDate;
                    Product.CreateId = detail.Product.CreateId;
                    Product.ProductMaster = detail.Product.ProductMaster;
                    Product.Quantity = detail.Product.Quantity;
                    Product.Price = detail.Product.Price;
                    ProductDAO.Update(Product);
                }

                if (!productIds.Contains(detail.Product.ProductId))
                {
                    productIds.Add(detail.Product.ProductId);
                    quantityList.Add(detail.Quantity);
                }

                DepartmentStockInDetail DepartmentStockInDetail =
                    DepartmentStockInDetailDAO.FindById(detail.DepartmentStockInDetailPK);
                if (DepartmentStockInDetail == null)
                {
                    DepartmentStockInDetailDAO.Add(detail);
                }
                else
                {
                    DepartmentStockInDetail.UpdateDate = detail.UpdateDate;
                    DepartmentStockInDetail.UpdateId = detail.UpdateId;
                    DepartmentStockInDetail.CreateDate = detail.CreateDate;
                    DepartmentStockInDetail.CreateId = detail.CreateId;
                    DepartmentStockInDetail.Quantity = DepartmentStockInDetail.Quantity;
                    DepartmentStockInDetail.Price = DepartmentStockInDetail.Price;

                    DepartmentStockInDetailDAO.Update(DepartmentStockInDetail);
                }
            }

            // update price
            if (productMasterIds.Count > 0)
            {
                var criteria = new ObjectCriteria();
                criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                criteria.AddEqCriteria("DepartmentPricePK.DepartmentId", (long)0);
                criteria.AddSearchInCriteria("DepartmentPricePK.ProductMasterId", productMasterIds);
                IList deptPriceList = DepartmentPriceDAO.FindAll(criteria);
                int i = 0;
                foreach (string productMasterId in productMasterIds)
                {
                    DepartmentPrice price = null;
                    foreach (DepartmentPrice price1 in deptPriceList)
                    {
                        if (price1.DepartmentPricePK.ProductMasterId.Equals(productMasterId))
                        {
                            price = price1;
                            price.Price = (Int64)priceList[i];
                            break;
                        }
                    }
                    if (price == null)
                    {
                        price = new DepartmentPrice
                                    {
                                        DepartmentPricePK = new DepartmentPricePK{DepartmentId = 0, ProductMasterId = productMasterId},
                                        Price = (Int64)priceList[i],
                                        CreateDate = DateTime.Now,
                                        CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                        UpdateDate = DateTime.Now,
                                        UpdateId = ClientInfo.getInstance().LoggedUser.Name
                                    };
                        DepartmentPriceDAO.Add(price);
                    }
                    else
                    {
                        price.UpdateDate = DateTime.Now;
                        price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentPriceDAO.Update(price);
                    }
                    i++;
                }
            }

            if (productIds.Count > 0)
            {
                var criteria = new ObjectCriteria();
                criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                criteria.AddEqCriteria("DepartmentStockPK.DepartmentId", data.DepartmentStockInPK.DepartmentId);
                criteria.AddSearchInCriteria("DepartmentStockPK.ProductId", productIds);
                IList stockList = DepartmentStockDAO.FindAll(criteria);
                int i = 0;
                foreach (string productId in productIds)
                {
                    DepartmentStock stock = null;
                    foreach (DepartmentStock price1 in stockList)
                    {
                        if (price1.DepartmentStockPK.ProductId.Equals(productId))
                        {
                            stock = price1;
                            //stock.Quantity += (Int64)quantityList[i];
                            stock.GoodQuantity += (Int64)quantityList[i];
                            stock.Quantity += (Int64) quantityList[i];
                            break;
                        }
                    }
                    if (stock == null)
                    {
                        stock = new DepartmentStock
                                    {
                                        DepartmentStockPK = new DepartmentStockPK { DepartmentId = data.DepartmentStockInPK.DepartmentId, ProductId = productId },
                                        Quantity = (Int64)quantityList[i],
                                        GoodQuantity = (Int64)quantityList[i],
                                        CreateDate = DateTime.Now,
                                        CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                        UpdateDate = DateTime.Now,
                                        UpdateId = ClientInfo.getInstance().LoggedUser.Name
                                    };
                        DepartmentStockDAO.Add(stock);
                    }
                    else
                    {
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stock.UpdateDate = DateTime.Now;
                        DepartmentStockDAO.Update(stock);
                    }
                    i++;
                }
            }

            if (data.Department != null)
            {
                Department dept = DepartmentDAO.FindById(data.Department.DepartmentId);
                if (dept == null)
                {
                    DepartmentDAO.Add(data.Department);
                }
                else
                {
                    //dept.Active = data.Department.Active;
                    dept.Address = data.Department.Address;
                    dept.DepartmentName = data.Department.DepartmentName;
                    dept.ManagerId = data.Department.ManagerId;
                    dept.StartDate = data.Department.StartDate;
                    DepartmentDAO.Update(dept);
                }
                foreach (Employee employee in data.Department.Employees)
                {
                    Employee emp = EmployeeDAO.FindById(employee.EmployeePK);
                    if (emp == null)
                    {
                        EmployeeDAO.Add(employee);
                        if (employee.EmployeeInfo != null)
                        {
                            EmployeeDetailDAO.Add(employee.EmployeeInfo);
                        }
                    }
                    else
                    {
                        emp.DelFlg = employee.DelFlg;
                        EmployeeDAO.Update(emp);
                        if (employee.EmployeeInfo != null)
                        {
                            EmployeeDetailDAO.Update(employee.EmployeeInfo);
                        }
                    }
                }
            }
        }
コード例 #11
0
        public LogicResult SyncFromSubStock(DepartmentStockIn stockIn)
        {
            LogicResult result = new LogicResult();
            result.HasError = false;
            string deptStr = string.Format("{0:000}", stockIn.DepartmentStockInPK.DepartmentId);
            string dateStr = stockIn.StockInDate.ToString("yyMMdd");
            var crit = new ObjectCriteria();
            crit.AddGreaterCriteria("DepartmentStockInPK.StockInId", dateStr + deptStr + "00000");
            var maxId = DepartmentStockInDAO.SelectSpecificType(crit, Projections.Max("DepartmentStockInPK.StockInId"));
            var stockInId = maxId == null ? dateStr + deptStr + "00001" : string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));

            var stockInPk = new DepartmentStockInPK
                                                    { DepartmentId = stockIn.DepartmentStockInPK.DepartmentId,
                                                      StockInId = stockInId + ""
                                                    };
            stockIn.DepartmentStockInPK = stockInPk;

            IList productMasterIds = new ArrayList();
            IList productIds = new ArrayList();
            IList priceList = new ArrayList();
            IList quantityList = new ArrayList();

            if(stockIn.DepartmentStockInDetails== null || stockIn.DepartmentStockInDetails.Count == 0)
            {
                result.HasError = true;
                result.Messages = new ArrayList();
                result.Messages.Add("Stock-in do not have details ?!?!");
                return result;
            }
            try
            {
                DepartmentStockIn DepartmentStockIn = DepartmentStockInDAO.FindById(stockIn.DepartmentStockInPK);
                if (DepartmentStockIn == null)
                {
                    DepartmentStockInDAO.Add(stockIn);
                }
                else
                {
                    ObjectCriteria criteria = new ObjectCriteria();

                    // currently we do not accept update department-stock-in in
                    //return;
                    // amend for debug
                    return result;
                }
                // put master data first
                foreach (DepartmentStockInDetail detail in stockIn.DepartmentStockInDetails)
                {
                    detail.DepartmentStockInDetailPK.StockInId = stockInId;
                    if (detail.Product.ProductMaster.ProductColor != null)
                    {
                        ProductColor color = ProductColorDAO.FindById(detail.Product.ProductMaster.ProductColor.ColorId);
                        if (color == null)
                        {
                            ProductColorDAO.Add(detail.Product.ProductMaster.ProductColor);
                        }
                    }
                    if (detail.Product.ProductMaster.ProductSize != null)
                    {
                        ProductSize Size = ProductSizeDAO.FindById(detail.Product.ProductMaster.ProductSize.SizeId);
                        if (Size == null)
                        {
                            ProductSizeDAO.Add(detail.Product.ProductMaster.ProductSize);
                        }
                    }
                    if (detail.Product.ProductMaster.ProductType != null)
                    {
                        ProductType Type = ProductTypeDAO.FindById(detail.Product.ProductMaster.ProductType.TypeId);
                        if (Type == null)
                        {
                            ProductTypeDAO.Add(detail.Product.ProductMaster.ProductType);
                        }
                    }
                    if (detail.Product.ProductMaster.Country != null)
                    {
                        Country Country = CountryDAO.FindById(detail.Product.ProductMaster.Country.CountryId);
                        if (Country == null)
                        {
                            CountryDAO.Add(detail.Product.ProductMaster.Country);
                        }
                    }
                    if (detail.Product.ProductMaster.Distributor != null)
                    {
                        Distributor Distributor =
                            DistributorDAO.FindById(detail.Product.ProductMaster.Distributor.DistributorId);
                        if (Distributor == null)
                        {
                            DistributorDAO.Add(detail.Product.ProductMaster.Distributor);
                        }
                    }
                    if (detail.Product.ProductMaster.Packager != null)
                    {
                        Packager Packager = PackagerDAO.FindById(detail.Product.ProductMaster.Packager.PackagerId);
                        if (Packager == null)
                        {
                            PackagerDAO.Add(detail.Product.ProductMaster.Packager);
                        }
                    }
                    if (detail.Product.ProductMaster.Manufacturer != null)
                    {
                        Manufacturer Manufacturer =
                            ManufacturerDAO.FindById(detail.Product.ProductMaster.Manufacturer.ManufacturerId);
                        if (Manufacturer == null)
                        {
                            ManufacturerDAO.Add(detail.Product.ProductMaster.Manufacturer);
                        }
                    }

                    ProductMaster ProductMaster = ProductMasterDAO.FindById(detail.Product.ProductMaster.ProductMasterId);
                    if (ProductMaster == null)
                    {
                        ProductMasterDAO.Add(detail.Product.ProductMaster);
                    }
                    else
                    {
                        /*ProductMaster.Country = detail.Product.ProductMaster.Country;
                        ProductMaster.Packager = detail.Product.ProductMaster.Packager;
                        ProductMaster.ProductColor = detail.Product.ProductMaster.ProductColor;
                        ProductMaster.ProductFullName = detail.Product.ProductMaster.ProductFullName;
                        ProductMaster.ProductName = detail.Product.ProductMaster.ProductName;
                        ProductMaster.ProductSize = detail.Product.ProductMaster.ProductSize;
                        ProductMaster.ProductType = detail.Product.ProductMaster.ProductType;
                        ProductMaster.UpdateDate = detail.Product.ProductMaster.UpdateDate;
                        ProductMaster.UpdateId = detail.Product.ProductMaster.UpdateId;
                        ProductMaster.CreateDate = detail.Product.ProductMaster.CreateDate;
                        ProductMaster.CreateId = detail.Product.ProductMaster.CreateId;
                        ProductMaster.Distributor = detail.Product.ProductMaster.Distributor;
                        ProductMaster.Manufacturer = detail.Product.ProductMaster.Manufacturer;
                        ProductMaster.ImagePath = detail.Product.ProductMaster.ImagePath;
                        ProductMaster.ExclusiveKey = detail.Product.ProductMaster.ExclusiveKey;

                        ProductMasterDAO.Update(ProductMaster);*/
                    }
                    if (!productMasterIds.Contains(detail.Product.ProductMaster.ProductMasterId))
                    {
                        productMasterIds.Add(detail.Product.ProductMaster.ProductMasterId);
                        priceList.Add(detail.Price);
                    }

                    Product Product = ProductDAO.FindById(detail.Product.ProductId);
                    if (Product == null)
                    {
                        ProductDAO.Add(detail.Product);
                    }
                    else
                    {
                        /*Product.UpdateDate = detail.Product.UpdateDate;
                        Product.UpdateId = detail.Product.UpdateId;
                        Product.CreateDate = detail.Product.CreateDate;
                        Product.CreateId = detail.Product.CreateId;
                        Product.ProductMaster = detail.Product.ProductMaster;
                        Product.Quantity = detail.Product.Quantity;
                        Product.Price = detail.Product.Price;
                        ProductDAO.Update(Product);*/
                    }

                    if (!productIds.Contains(detail.Product.ProductId))
                    {
                        productIds.Add(detail.Product.ProductId);
                        quantityList.Add(detail.Quantity);
                    }

                    DepartmentStockInDetail DepartmentStockInDetail =
                        DepartmentStockInDetailDAO.FindById(detail.DepartmentStockInDetailPK);
                    if (DepartmentStockInDetail == null)
                    {
                        DepartmentStockInDetailDAO.Add(detail);
                    }
                    else
                    {
                        /*DepartmentStockInDetail.UpdateDate = detail.UpdateDate;
                        DepartmentStockInDetail.UpdateId = detail.UpdateId;
                        DepartmentStockInDetail.CreateDate = detail.CreateDate;
                        DepartmentStockInDetail.CreateId = detail.CreateId;
                        DepartmentStockInDetail.Quantity = DepartmentStockInDetail.Quantity;
                        DepartmentStockInDetail.Price = DepartmentStockInDetail.Price;
                        DepartmentStockInDetailDAO.Update(DepartmentStockInDetail);*/
                    }
                }

                // update price
                if (productMasterIds.Count > 0)
                {
                    var criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    criteria.AddEqCriteria("DepartmentPricePK.DepartmentId", (long)0);
                    criteria.AddSearchInCriteria("DepartmentPricePK.ProductMasterId", productMasterIds);
                    IList deptPriceList = DepartmentPriceDAO.FindAll(criteria);
                    int i = 0;
                    foreach (string productMasterId in productMasterIds)
                    {
                        DepartmentPrice price = null;
                        foreach (DepartmentPrice price1 in deptPriceList)
                        {
                            if (price1.DepartmentPricePK.ProductMasterId.Equals(productMasterId))
                            {
                                price = price1;
                                price.Price = (Int64)priceList[i];
                                break;
                            }
                        }
                        if (price == null)
                        {
                            price = new DepartmentPrice
                            {
                                DepartmentPricePK = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = productMasterId },
                                Price = (Int64)priceList[i],
                                CreateDate = DateTime.Now,
                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                UpdateDate = DateTime.Now,
                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                            };
                            DepartmentPriceDAO.Add(price);
                        }
                        else
                        {
                            price.UpdateDate = DateTime.Now;
                            price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            DepartmentPriceDAO.Update(price);
                        }
                        i++;
                    }
                }

                if (productIds.Count > 0)
                {
                    var criteria = new ObjectCriteria();
                    criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    criteria.AddEqCriteria("DepartmentStockPK.DepartmentId", stockIn.DepartmentStockInPK.DepartmentId);
                    criteria.AddSearchInCriteria("DepartmentStockPK.ProductId", productIds);
                    IList stockList = DepartmentStockDAO.FindAll(criteria);
                    int i = 0;
                    foreach (string productId in productIds)
                    {
                        DepartmentStock stock = null;
                        foreach (DepartmentStock price1 in stockList)
                        {
                            if (price1.DepartmentStockPK.ProductId.Equals(productId))
                            {
                                stock = price1;
                                //stock.Quantity += (Int64)quantityList[i];
                                stock.GoodQuantity += (Int64)quantityList[i];
                                stock.Quantity += (Int64)quantityList[i];
                                break;
                            }
                        }
                        if (stock == null)
                        {
                            stock = new DepartmentStock
                            {
                                DepartmentStockPK = new DepartmentStockPK { DepartmentId = stockIn.DepartmentStockInPK.DepartmentId, ProductId = productId },
                                Quantity = (Int64)quantityList[i],
                                GoodQuantity = (Int64)quantityList[i],
                                CreateDate = DateTime.Now,
                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                UpdateDate = DateTime.Now,
                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                            };
                            DepartmentStockDAO.Add(stock);
                        }
                        else
                        {
                            stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            stock.UpdateDate = DateTime.Now;
                            DepartmentStockDAO.Update(stock);
                        }
                        i++;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Messages = new ArrayList();
                result.Messages.Add(ex.Message);
                return result;
            }
        }
コード例 #12
0
        public void Sync(SyncFromMainToDepartment syncFromMainToDepartment)
        {
            IList prdMasterUpdateList = new ArrayList();
            IList needUpdateStocks = new ArrayList();
            // fix departmentStock first

            IList deptStockTemps = syncFromMainToDepartment.DepartmentStockTemps;
            if (deptStockTemps != null && deptStockTemps.Count > 0)
            {
                DepartmentStockOut deptStockOut = new DepartmentStockOut();
                object maxDSOId = DepartmentStockOutDAO.SelectSpecificType(null,
                                                                           Projections.Max(
                                                                               "DepartmentStockOutPK.StockOutId"));
                long maxDeptStockOutId = (maxDSOId != null ? (long) maxDSOId + 1 : 1);

                object maxDetId = DepartmentStockOutDetailDAO.SelectSpecificType(null,
                                                                                 Projections.Max("StockOutDetailId"));
                long maxDeptStockOutDetId = (maxDetId != null ? (long) maxDetId + 1 : 1);
                deptStockOut.DepartmentStockOutPK = new DepartmentStockOutPK
                                                        {
                                                            DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                            StockOutId = maxDeptStockOutId

                                                        };
                deptStockOut.DefectStatus = new StockDefectStatus {DefectStatusId = 5}; // xuat tra ve nha san xuat
                deptStockOut.ConfirmFlg = 1; // can xac nhan tu kho chinh

                deptStockOut.StockOutDate = DateTime.Now;
                deptStockOut.CreateDate = DateTime.Now;
                deptStockOut.UpdateDate = DateTime.Now;
                deptStockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                deptStockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                deptStockOut.DepartmentStockOutDetails = new ArrayList();
                foreach (DepartmentStockTemp deptStockTemp in deptStockTemps)
                {
                    long realQty = deptStockTemp.GoodQuantity + deptStockTemp.ErrorQuantity +
                                   deptStockTemp.DamageQuantity +
                                   deptStockTemp.LostQuantity + deptStockTemp.UnconfirmQuantity;
                    if (realQty < deptStockTemp.Quantity)
                    {
                        long returnToStockQty = deptStockTemp.Quantity - realQty;
                        DepartmentStockOutDetail deptSODet = new DepartmentStockOutDetail();
                        deptSODet.StockOutDetailId = maxDeptStockOutDetId++;
                        deptSODet.Product = deptStockTemp.Product;
                        deptSODet.ProductMaster = deptStockTemp.ProductMaster;
                        deptSODet.DepartmentStockOut = deptStockOut;
                        deptSODet.Description = "Số liệu dư được xuất về nhà sản xuất hủy";
                        deptSODet.CreateDate = DateTime.Now;
                        deptSODet.UpdateDate = DateTime.Now;
                        deptSODet.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        deptSODet.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        deptSODet.StockOutId = deptStockOut.DepartmentStockOutPK.StockOutId;
                        deptSODet.DepartmentId = deptStockOut.DepartmentStockOutPK.DepartmentId;

                        deptSODet.GoodQuantity = returnToStockQty;
                        deptSODet.Quantity = returnToStockQty;
                        deptSODet.DefectStatus = new StockDefectStatus {DefectStatusId = 5}; // xuat tra ve nha san xuat
                        deptStockOut.DepartmentStockOutDetails.Add(deptSODet);
                    }
                    DepartmentStockPK stockPk = new DepartmentStockPK
                                                    {
                                                        DepartmentId = deptStockTemp.DepartmentStockTempPK.DepartmentId,
                                                        ProductId = deptStockTemp.DepartmentStockTempPK.ProductId
                                                    };
                    DepartmentStock stock = DepartmentStockDAO.FindById(stockPk);

                    if (stock != null)
                    {
                        prdMasterUpdateList.Add(stock.Product.ProductMaster);
                        long differGoodQty = stock.Quantity - deptStockTemp.Quantity;
                        stock.GoodQuantity = deptStockTemp.GoodQuantity + differGoodQty;
                        if(deptStockTemp.GoodQuantity > deptStockTemp.Quantity) // stock them vo
                        {
                            // lay so luong nguyen thuy de co the cong them khi stock in vao cua hang
                            stock.GoodQuantity = stock.Quantity;
                        }
                        stock.ErrorQuantity = deptStockTemp.ErrorQuantity;
                        stock.LostQuantity = deptStockTemp.LostQuantity;
                        stock.DamageQuantity = deptStockTemp.DamageQuantity;
                        stock.UnconfirmQuantity = deptStockTemp.UnconfirmQuantity;
                        stock.Quantity = stock.GoodQuantity + stock.ErrorQuantity + stock.LostQuantity +
                                         stock.DamageQuantity + stock.UnconfirmQuantity;
                        needUpdateStocks.Add(stock);
                    }
                    deptStockTemp.DelFlg = 1;
                    DepartmentStockTempDAO.Update(deptStockTemp);
                }
                if (deptStockOut.DepartmentStockOutDetails.Count > 0)
                {
                    DepartmentStockOutDAO.Add(deptStockOut);
                    foreach (DepartmentStockOutDetail detail in deptStockOut.DepartmentStockOutDetails)
                    {
                        DepartmentStockOutDetailDAO.Add(detail);
                    }
                }
            }

            IList stockOutList = syncFromMainToDepartment.StockOutList;

            string deptStr = string.Format("{0:000}", syncFromMainToDepartment.Department.DepartmentId);
            string dateStr = DateTime.Now.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("DepartmentStockInPK.StockInId", dateStr + deptStr + "00000");
            var maxId = DepartmentStockInDAO.SelectSpecificType(criteria, Projections.Max("DepartmentStockInPK.StockInId"));

            var stockInId = maxId == null ? dateStr + deptStr + "00001" : string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
            long nextDeptStockInId = Int64.Parse(stockInId);
            foreach (StockOut stockOut in stockOutList)
            {
                // convert stock out to department stock in
                DepartmentStockInMapper mapper = new DepartmentStockInMapper();
                DepartmentStockIn data = mapper.Convert(stockOut);
                data.Department = syncFromMainToDepartment.Department;
                // sync department stock in
                data.DepartmentStockInPK.StockInId = string.Format("{0:00000000000000}",nextDeptStockInId++);
                /*DepartmentStockIn DepartmentStockIn = DepartmentStockInDAO.FindById(data.DepartmentStockInPK);
                if (DepartmentStockIn == null)
                {
                    DepartmentStockInDAO.Add(data);
                }*/
                StockOut oldStockOut = StockOutDAO.FindById(stockOut.StockoutId);
                if (oldStockOut == null)
                {
                    StockOutDAO.Add(stockOut);
                    DepartmentStockInDAO.Add(data);
                }
                else
                {
                    //ObjectCriteria criteria = new ObjectCriteria();

                    // currently we do not accept update stock in
                    continue;
                    // amend for debug
                    //DepartmentStockInDAO.Update(data);
                }

                // sync department stock in detail
                IList productMasterIds = new ArrayList();
                IList productIds = new ArrayList();
                IList priceList = new ArrayList();
                IList quantityList = new ArrayList();

                // put master data first
                foreach (DepartmentStockInDetail detail in data.DepartmentStockInDetails)
                {
                    detail.DepartmentStockInDetailPK.StockInId = data.DepartmentStockInPK.StockInId;
                    if (detail.Product.ProductMaster.ProductColor != null)
                    {
                        ProductColor color = ProductColorDAO.FindById(detail.Product.ProductMaster.ProductColor.ColorId);
                        if (color == null)
                        {
                            ProductColorDAO.Add(detail.Product.ProductMaster.ProductColor);
                        }
                    }
                    if (detail.Product.ProductMaster.ProductSize != null)
                    {
                        ProductSize Size = ProductSizeDAO.FindById(detail.Product.ProductMaster.ProductSize.SizeId);
                        if (Size == null)
                        {
                            ProductSizeDAO.Add(detail.Product.ProductMaster.ProductSize);
                        }
                    }
                    if (detail.Product.ProductMaster.ProductType != null)
                    {
                        ProductType Type = ProductTypeDAO.FindById(detail.Product.ProductMaster.ProductType.TypeId);
                        if (Type == null)
                        {
                            ProductTypeDAO.Add(detail.Product.ProductMaster.ProductType);
                        }
                    }
                    if (detail.Product.ProductMaster.Country != null)
                    {
                        Country Country = CountryDAO.FindById(detail.Product.ProductMaster.Country.CountryId);
                        if (Country == null)
                        {
                            CountryDAO.Add(detail.Product.ProductMaster.Country);
                        }
                    }
                    if (detail.Product.ProductMaster.Distributor != null)
                    {
                        Distributor Distributor =
                            DistributorDAO.FindById(detail.Product.ProductMaster.Distributor.DistributorId);
                        if (Distributor == null)
                        {
                            DistributorDAO.Add(detail.Product.ProductMaster.Distributor);
                        }
                    }
                    if (detail.Product.ProductMaster.Packager != null)
                    {
                        Packager Packager = PackagerDAO.FindById(detail.Product.ProductMaster.Packager.PackagerId);
                        if (Packager == null)
                        {
                            PackagerDAO.Add(detail.Product.ProductMaster.Packager);
                        }
                    }
                    if (detail.Product.ProductMaster.Manufacturer != null)
                    {
                        Manufacturer Manufacturer =
                            ManufacturerDAO.FindById(detail.Product.ProductMaster.Manufacturer.ManufacturerId);
                        if (Manufacturer == null)
                        {
                            ManufacturerDAO.Add(detail.Product.ProductMaster.Manufacturer);
                        }
                    }

                    //ProductMaster ProductMaster = ProductMasterDAO.FindById(detail.Product.ProductMaster.ProductMasterId);
                    ProductMaster ProductMaster = GetProductMaster(detail.Product.ProductMaster,prdMasterUpdateList);
                    if (ProductMaster == null)
                    {
                        ProductMasterDAO.Add(detail.Product.ProductMaster);
                    }
                    else
                    {

                        ProductMaster.Country = detail.Product.ProductMaster.Country;
                        ProductMaster.Packager = detail.Product.ProductMaster.Packager;
                        ProductMaster.ProductColor = detail.Product.ProductMaster.ProductColor;
                        ProductMaster.ProductFullName = detail.Product.ProductMaster.ProductFullName;
                        ProductMaster.ProductName = detail.Product.ProductMaster.ProductName;
                        ProductMaster.ProductSize = detail.Product.ProductMaster.ProductSize;
                        ProductMaster.ProductType = detail.Product.ProductMaster.ProductType;
                        ProductMaster.UpdateDate = detail.Product.ProductMaster.UpdateDate;
                        ProductMaster.UpdateId = detail.Product.ProductMaster.UpdateId;
                        ProductMaster.CreateDate = detail.Product.ProductMaster.CreateDate;
                        ProductMaster.CreateId = detail.Product.ProductMaster.CreateId;
                        ProductMaster.Distributor = detail.Product.ProductMaster.Distributor;
                        ProductMaster.Manufacturer = detail.Product.ProductMaster.Manufacturer;
                        ProductMaster.ImagePath = detail.Product.ProductMaster.ImagePath;
                        ProductMaster.ExclusiveKey = detail.Product.ProductMaster.ExclusiveKey;
                        ProductMasterDAO.Update(ProductMaster);
                    }
                    if (!productMasterIds.Contains(detail.Product.ProductMaster.ProductMasterId))
                    {
                        productMasterIds.Add(detail.Product.ProductMaster.ProductMasterId);
                        priceList.Add(detail.Price);
                    }

                    Product Product = ProductDAO.FindById(detail.Product.ProductId);
                    if (Product == null)
                    {
                        ProductDAO.Add(detail.Product);
                    }
                    else
                    {
                        Product.UpdateDate = detail.Product.UpdateDate;
                        Product.UpdateId = detail.Product.UpdateId;
                        Product.CreateDate = detail.Product.CreateDate;
                        Product.CreateId = detail.Product.CreateId;
                        Product.ProductMaster = detail.Product.ProductMaster;
                        Product.Quantity = detail.Product.Quantity;
                        Product.Price = detail.Product.Price;
                        ProductDAO.Update(Product);
                    }

                    if (!productIds.Contains(detail.Product.ProductId))
                    {
                        productIds.Add(detail.Product.ProductId);
                        quantityList.Add(detail.Quantity);
                    }

                    DepartmentStockInDetail DepartmentStockInDetail =
                        DepartmentStockInDetailDAO.FindById(detail.DepartmentStockInDetailPK);
                    if (DepartmentStockInDetail == null)
                    {
                        DepartmentStockInDetailDAO.Add(detail);
                    }
                    else
                    {
                        DepartmentStockInDetail.UpdateDate = detail.UpdateDate;
                        DepartmentStockInDetail.UpdateId = detail.UpdateId;
                        DepartmentStockInDetail.CreateDate = detail.CreateDate;
                        DepartmentStockInDetail.CreateId = detail.CreateId;
                        DepartmentStockInDetail.Quantity = DepartmentStockInDetail.Quantity;
                        DepartmentStockInDetail.Price = DepartmentStockInDetail.Price;

                        DepartmentStockInDetailDAO.Update(DepartmentStockInDetail);
                    }
                }

                // update price
                if (productMasterIds.Count > 0)
                {
                    var objectCriteria = new ObjectCriteria();
                    objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    objectCriteria.AddEqCriteria("DepartmentPricePK.DepartmentId", (long)0);
                    objectCriteria.AddSearchInCriteria("DepartmentPricePK.ProductMasterId", productMasterIds);
                    IList deptPriceList = DepartmentPriceDAO.FindAll(objectCriteria);
                    int i = 0;
                    foreach (string productMasterId in productMasterIds)
                    {
                        DepartmentPrice price = null;
                        foreach (DepartmentPrice price1 in deptPriceList)
                        {
                            if (price1.DepartmentPricePK.ProductMasterId.Equals(productMasterId))
                            {
                                price = price1;
                                price.Price = (Int64)priceList[i];
                                break;
                            }
                        }
                        if (price == null)
                        {
                            price = new DepartmentPrice
                            {
                                DepartmentPricePK = new DepartmentPricePK { DepartmentId = 0, ProductMasterId = productMasterId },
                                Price = (Int64)priceList[i],
                                CreateDate = DateTime.Now,
                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                UpdateDate = DateTime.Now,
                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                            };
                            DepartmentPriceDAO.Add(price);
                        }
                        else
                        {
                            price.UpdateDate = DateTime.Now;
                            price.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            DepartmentPriceDAO.Update(price);
                        }
                        i++;
                    }
                }

                // mix 2 lists
                // find lack productIds
                IList lackProductIds = new ArrayList();
                if(productIds.Count > 0)
                {
                    foreach (string productId in productIds)
                    {
                        bool hasFound = false;
                        foreach (DepartmentStock departmentStock in needUpdateStocks)
                        {
                            if(productId.Equals(departmentStock.DepartmentStockPK.ProductId))
                            {
                                hasFound = true;
                                break;
                            }
                        }
                        if(!hasFound)
                        {
                            lackProductIds.Add(productId);
                        }
                    }
                }

                if (productIds.Count > 0)
                {
                    if (lackProductIds.Count > 0)
                    {
                        var objectCrit1 = new ObjectCriteria();
                        objectCrit1.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                        objectCrit1.AddEqCriteria("DepartmentStockPK.DepartmentId",
                                                  data.DepartmentStockInPK.DepartmentId);

                        objectCrit1.AddSearchInCriteria("DepartmentStockPK.ProductId", productIds);
                        IList stockList = DepartmentStockDAO.FindAll(objectCrit1);
                        if(stockList!= null && stockList.Count > 0)
                        {
                            foreach (DepartmentStock departmentStock in stockList)
                            {
                                needUpdateStocks.Add(departmentStock);
                            }
                        }
                    }
                    int i = 0;
                    foreach (string productId in productIds)
                    {
                        DepartmentStock stock = null;
                        foreach (DepartmentStock needUpdateStock in needUpdateStocks)
                        {
                            if (needUpdateStock.DepartmentStockPK.ProductId.Equals(productId))
                            {
                                stock = needUpdateStock;
                                //stock.Quantity += (Int64)quantityList[i];
                                stock.GoodQuantity += (Int64)quantityList[i];
                                stock.Quantity += (Int64)quantityList[i];
                                break;
                            }
                        }
                        if (stock == null)
                        {
                            stock = new DepartmentStock
                            {
                                DepartmentStockPK = new DepartmentStockPK { DepartmentId = data.DepartmentStockInPK.DepartmentId, ProductId = productId },
                                Quantity = (Int64)quantityList[i],
                                GoodQuantity = (Int64)quantityList[i],
                                CreateDate = DateTime.Now,
                                CreateId = ClientInfo.getInstance().LoggedUser.Name,
                                UpdateDate = DateTime.Now,
                                UpdateId = ClientInfo.getInstance().LoggedUser.Name
                            };
                            DepartmentStockDAO.Add(stock);
                        }
                        /*else
                        {
                            stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                            stock.UpdateDate = DateTime.Now;
                            DepartmentStockDAO.Update(stock);
                        }*/
                        i++;
                    }
                }
                // update stock
                foreach (DepartmentStock stock in needUpdateStocks)
                {
                    stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stock.UpdateDate = DateTime.Now;
                    DepartmentStockDAO.Update(stock);
                }

                if (data.Department != null)
                {
                    Department dept = DepartmentDAO.FindById(data.Department.DepartmentId);
                    if (dept == null)
                    {
                        DepartmentDAO.Add(data.Department);
                    }
                    else
                    {
                        //dept.Active = data.Department.Active;
                        dept.Address = data.Department.Address;
                        dept.DepartmentName = data.Department.DepartmentName;
                        dept.ManagerId = data.Department.ManagerId;
                        dept.StartDate = data.Department.StartDate;
                        DepartmentDAO.Update(dept);
                    }
                    foreach (Employee employee in data.Department.Employees)
                    {
                        Employee emp = EmployeeDAO.FindById(employee.EmployeePK);
                        if (emp == null)
                        {
                            EmployeeDAO.Add(employee);
                            if (employee.EmployeeInfo != null)
                            {
                                EmployeeDetailDAO.Add(employee.EmployeeInfo);
                            }
                        }
                        else
                        {
                            emp.DelFlg = employee.DelFlg;
                            EmployeeDAO.Update(emp);
                            if (employee.EmployeeInfo != null)
                            {
                                EmployeeDetailDAO.Update(employee.EmployeeInfo);
                            }
                        }
                    }
                }

            }
        }
コード例 #13
0
        public void NotifyNewMultiDepartmentStockOut(Department department, DepartmentStockOut[] list, DepartmentPrice price)
        {
            if (CurrentDepartment.Get().DepartmentId != department.DepartmentId)
            {
                return;
            }

            IsDoingStockOut = true;
            ((MainForm)GlobalCache.Instance().MainForm).ServiceStatus.Text = " Đang nhận thông tin ...";

                ClientUtility.Log(logger, department.DepartmentId + " dang nhan hang.");
                foreach (DepartmentStockOut stockOut in list)
                {
                    try
                    {
                    DepartmentStockInHistoryPK departmentStockInHistoryPk = new DepartmentStockInHistoryPK
                    {
                        SourceDepartmentId = stockOut.DepartmentStockOutPK.DepartmentId,
                        DestDepartmentId = CurrentDepartment.Get().DepartmentId,
                        StockOutId = stockOut.DepartmentStockOutPK.StockOutId
                    };

                    ObjectCriteria deptHistCrit = new ObjectCriteria();
                    deptHistCrit.AddEqCriteria("DepartmentStockInHistoryPK.SourceDepartmentId", stockOut.DepartmentStockOutPK.DepartmentId);
                    deptHistCrit.AddEqCriteria("DepartmentStockInHistoryPK.StockOutId", stockOut.DepartmentStockOutPK.StockOutId);
                    deptHistCrit.AddEqCriteria("DepartmentStockInHistoryPK.DestDepartmentId", department.DepartmentId);

                    IList deptHistList = DepartmentStockInHistoryLogic.FindAll(deptHistCrit);
                    // if it has exist in history so don't need to continue
                    if (deptHistList != null && deptHistList.Count > 0)
                    {
                        continue;
                    }

                    DepartmentStockIn stockIn;
                    // convert from stock out to stock in
                    stockIn = new FastDepartmentStockInMapper().Convert(stockOut);
                    // call method to sync
                    LogicResult logicResult = DepartmentStockInLogic.SyncFromSubStock(stockIn);
                    if (logicResult.HasError)
                    {
                        if (logicResult.Messages != null)
                        {
                            foreach (string message in logicResult.Messages)
                            {
                                ClientUtility.Log(logger, message);
                            }
                        }
                        serverService.InformDepartmentStockOutFail(stockOut.DepartmentStockOutPK.DepartmentId,
                                                                      stockOut.OtherDepartmentId,
                                                                      stockOut.DepartmentStockOutPK.StockOutId);
                    }
                    else
                    {
                        ClientUtility.Log(logger,
                                          " Hoan tat va phan hoi ... " +
                                          stockOut.DepartmentStockOutPK.DepartmentId.ToString());

                        // add to stock in history for avoiding duplicate
                        departmentStockInHistoryPk.StockInId = stockIn.DepartmentStockInPK.StockInId;
                        DepartmentStockInHistory departmentStockInHistory = new DepartmentStockInHistory();
                        departmentStockInHistory.DepartmentStockInHistoryPK = departmentStockInHistoryPk;
                        departmentStockInHistory.Description = stockIn.ToString();
                        departmentStockInHistory.CreateDate = DateTime.Now;
                        departmentStockInHistory.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        departmentStockInHistory.UpdateDate = DateTime.Now;
                        departmentStockInHistory.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        DepartmentStockInHistoryLogic.Add(departmentStockInHistory);

                        serverService.InformDepartmentStockOutSuccess(stockOut.DepartmentStockOutPK.DepartmentId,
                                                                      stockOut.OtherDepartmentId,
                                                                      stockOut.DepartmentStockOutPK.StockOutId);
                        ((MainForm) GlobalCache.Instance().MainForm).ServiceStatus.Text = " Hoàn tất ! ";
                        ClientUtility.Log(logger, " Hoan tat!");
                    }
                    }
                    catch (Exception exp)
                    {
                        ClientUtility.Log(logger, exp.Message);
                    }
                }
            IsDoingStockOut = false;
        }
コード例 #14
0
 public void NotifyNewDepartmentStockOut(Department department, DepartmentStockOut stockOut, DepartmentPrice price)
 {
     // do nothing
     //MessageBox.Show("Send back OK !");
 }
コード例 #15
0
ファイル: SubStockConsumer.cs プロジェクト: DelLitt/opmscoral
 public void NotifyNewDepartmentStockOut(Department department, DepartmentStockOut stockOut, DepartmentPrice price)
 {
     // don't need to implement
 }
コード例 #16
0
 public void NotifyNewMultiDepartmentStockOut(Department department, object[] list, DepartmentPrice price)
 {
 }
コード例 #17
0
ファイル: SubStockConsumer.cs プロジェクト: DelLitt/opmscoral
 public void NotifyNewMultiDepartmentStockOut(Department department, DepartmentStockOut[] list, DepartmentPrice price)
 {
     // do not implement
 }
コード例 #18
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;
        }
コード例 #19
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;
            }
        }
コード例 #20
0
ファイル: ServerService.cs プロジェクト: DelLitt/opmscoral
        public void MakeRawDepartmentStockOut(Department department, DepartmentStockOut stockOut, DepartmentPrice price)
        {
            DataAccessLayer dalSubStock = new DataAccessLayer(Properties.Settings.Default.SubStockDB);
            DataAccessLayer dalSalePoint = new DataAccessLayer(Properties.Settings.Default.SalePointDB);

            //DataAccessLayer dalSalePoint = new DataAccessLayer("achay");

            /*try
            {*/

            try
            {

                DepartmentStockIn stockIn = new FastDepartmentStockInMapper().Convert(stockOut);
                // get max stock in id
                string deptStr = "";
                string extraZero = "";
                string startNum = "";

                if(department.DepartmentId > 999)
                {
                    deptStr = department.DepartmentId.ToString();
                    extraZero = "000";
                    startNum = "001";
                }
                else
                {
                    deptStr = string.Format("{0:000}", department.DepartmentId);
                    extraZero = "00000";
                    startNum = "00001";
                }

                string dateStr = DateTime.Now.ToString("yyMMdd");
                var selectMaxIdSQL = " select max(stock_in_id) from department_stock_in where stock_in_id > '" + dateStr + deptStr + extraZero + "'";

                ServerUtility.Log(logger, selectMaxIdSQL);
                //var maxId = dalSalePoint.GetSingleValue(selectMaxIdSQL);
                var maxId = dalSalePoint.GetSingleValue(selectMaxIdSQL);
                string stockInId = "";
                if(maxId == null || maxId.ToString() == string.Empty)
                {
                    stockInId = dateStr + deptStr + startNum;
                }
                else
                {
                    stockInId = string.Format("{0:00000000000000}", (Int64.Parse(maxId.ToString()) + 1));
                }

                // search in department_stock_in_history
                string selectHistory = " select stock_in_id from department_stock_in_history "
                                       + " where SOURCE_DEPARTMENT_ID = " + stockOut.DepartmentStockOutPK.DepartmentId
                                       + " and stock_out_id = " + stockOut.DepartmentStockOutPK.StockOutId;
                ServerUtility.Log(logger, selectHistory);
                var existStockInId = dalSalePoint.GetSingleValue(selectHistory);
                if (existStockInId == null || existStockInId.ToString() == string.Empty)
                {
                    string insertHistory = " insert into department_stock_in_history(stock_out_id,source_department_id,stock_in_id,dest_department_id,description,create_id,create_date,update_id,update_date ) values( "
                                           + stockOut.DepartmentStockOutPK.StockOutId + ","
                                           + stockOut.DepartmentStockOutPK.DepartmentId + ",'"
                                           + stockInId + "',"
                                           + stockIn.DepartmentStockInPK.DepartmentId + ",'"
                                           + " Xuat hang xuong cua hang " + "',"
                                           + "'admin'" + ","
                                           + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',"
                                           + "'admin'" + ","
                                           + "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
                    ServerUtility.Log(logger, insertHistory);
                    dalSalePoint.ExecuteQuery(insertHistory);
                }
                else
                {
                    InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, true,
                    stockOut.DepartmentStockOutPK.StockOutId + " đã đến " + stockOut.OtherDepartmentId + " trước đó. Không thể truyền lại !");
                    return;
                }

                DoStockIn(dalSalePoint, department, stockIn, true);
                InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, false,
                    stockOut.DepartmentStockOutPK.DepartmentId +  " đã truyền "+ stockOut.DepartmentStockOutPK.StockOutId +" xuống " + stockOut.OtherDepartmentId + " thành công !");
            }
            catch (Exception exception)
            {
                ServerUtility.Log(logger,exception.Message);
                ServerUtility.Log(logger, exception.StackTrace);
                InformMessage(stockOut.DepartmentStockOutPK.StockOutId,SUBTODEPT, true,
                    stockOut.DepartmentStockOutPK.DepartmentId + " đã truyền " + stockOut.DepartmentStockOutPK.StockOutId + " xuống " + stockOut.OtherDepartmentId + " thất bại !");
            }
        }
コード例 #21
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;
        }
コード例 #22
0
 /// <summary>
 /// Update DepartmentPrice to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(DepartmentPrice data)
 {
     HibernateTemplate.Update(data);
 }
コード例 #23
0
 public void Update(DepartmentPrice data)
 {
     DepartmentPriceDAO.Update(data);
 }
コード例 #24
0
 /// <summary>
 /// Delete DepartmentPrice from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(DepartmentPrice data)
 {
     HibernateTemplate.Delete(data);
 }
コード例 #25
0
 public void NotifyNewDepartmentStockOut(Department department, DepartmentStockOut stockOut, DepartmentPrice price)
 {
 }