Ejemplo n.º 1
0
        private void DepartmentStockInExtra_Load(object sender, EventArgs e)
        {
            IList list = new ArrayList();
            list.Add(new StockDefectStatus { DefectStatusId = 4, DefectStatusName = "Xuất tạm để sửa hàng"});
            list.Add(new StockDefectStatus { DefectStatusId = 5, DefectStatusName = "Xuất trả về nhà sản xuất" });
            list.Add(new StockDefectStatus { DefectStatusId = 7, DefectStatusName = "Xuất đi cửa hàng khác ngoài hệ thống" });
            list.Add(new StockDefectStatus { DefectStatusId = 9, DefectStatusName = "Xuất hàng mẫu" });

            cbbStockOutType.DataSource = list;
            cbbStockOutType.DisplayMember = "DefectStatusName";

            stockOutDetailList = new StockOutDetailCollection(bdsStockIn);
            bdsStockIn.DataSource = stockOutDetailList;
            dgvDeptStockOut.DataError += new DataGridViewDataErrorEventHandler(dgvDeptStockIn_DataError);

            // create DepartmentStockIn
            if (stockOut == null)
            {
                stockOut = new StockOut();
                stockOut.CreateDate = DateTime.Now;
                stockOut.UpdateDate = DateTime.Now;
                stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                stockOut.ExclusiveKey = 0;
                CreateNewStockInDetail();
            //                btnBarcode.Visible = false;
            //                numericUpDownBarcode.Visible = false;
            //                btnPreview.Visible = false;
                // load products to extra combo box
                LoadProductMasterToComboBox();
                stockOutDetailList.RemoveAt(0);
                bdsStockIn.EndEdit();

            }
            else
            {
            //                btnBarcode.Visible = true;
            //                numericUpDownBarcode.Visible = true;
            //                btnPreview.Visible = true;
                IList deptStockInDetails = stockOut.StockOutDetails;
                foreach (StockOutDetail detail in deptStockInDetails)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO)
                    {
                        stockOutDetailList.Add(detail);
                        //detail.OldQuantity = detail.Quantity;
                    }
                }

                for (int i = 0; i < dgvDeptStockOut.Columns.Count; i++)
                {
                    dgvDeptStockOut.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                    if (i != QUANTITY_POS
                            && i != PRICE_POS
                            && i != SELL_PRICE_POS)
                    {
                        dgvDeptStockOut.Columns[i].ReadOnly = true;
                    }
                }
            //                txtDexcription.Text = stockOut.Description;
            }
            stockOut.StockOutDetails =
                    ObjectConverter.ConvertToNonGenericList<StockOutDetail>(stockOutDetailList);
        }
Ejemplo n.º 2
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            // create DepartmentStockIn
            if (stockOut == null)
            {
                stockOut = new StockOut();
            }
            stockOut.CreateDate = DateTime.Now;
            stockOut.UpdateDate = DateTime.Now;
            stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.ExclusiveKey = 0;
            //            int maxAddedItemsCount = int.Parse(numericUpDown.Text);
            //            for (int i = 0; i < maxAddedItemsCount; i++)
            //            {
            //                StockInDetail deptSIDet = CreateNewStockInDetail();
            //
            //            }

            stockOut.StockOutDetails =
                ObjectConverter.ConvertToNonGenericList<StockOutDetail>(stockOutDetailList);
            bdsStockIn.EndEdit();

            //            for (int j = 0; j < maxAddedItemsCount; j++)
            //            {
            //                for (int i = 0; i <= SELL_PRICE_POS; i++)
            //                {
            //                    dgvDeptStockOut[i, stockOutDetailList.Count - j - 1].ReadOnly = false;
            //                }
            //            }
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show(
                "Bạn hãy kiểm tra kỹ trước khi lưu số liệu bởi vì sau khi lưu sẽ không thay đổi được nữa. Bạn có chắc chắn muốn lưu ?", "Xác nhận",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            // first remove all blank row
            int count = 0;
            int length = stockOutDetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                StockOutDetail detail = stockOutDetailList[i];
                if (string.IsNullOrEmpty(detail.Product.ProductMaster.ProductMasterId)
                    && string.IsNullOrEmpty(detail.Product.ProductMaster.ProductName))
                {
                    stockOutDetailList.RemoveAt(i - count);
                    count++;
                }
            }

            if (stockOutDetailList.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào để nhập kho!!!!");
                return;
            }

            // validate quantity
            int line = 1;
            long StockDefectId = ((StockDefectStatus) cbbStockOutType.SelectedItem).DefectStatusId;
            foreach (StockOutDetail detail in stockOutDetailList)
            {
                foreach (Stock stock in stockList)
                {
                    if (detail.Product.ProductId.Equals(stock.Product.ProductId))
                    {
                        if(StockDefectId == 9)
                        {
                            if (detail.GoodQuantity < 0)
                            {
                                MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng Tốt phải là số dương ");
                                dgvDeptStockOut.CurrentCell = dgvDeptStockOut[3, Math.Max(0,line-1)];
                                return;
                            }
                        }
                        else
                        {
                            if (detail.GoodQuantity < 0 || detail.GoodQuantity > stock.GoodQuantity)
                            {
                                MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng Tốt phải là số dương nhỏ hơn hoặc bằng " + stock.GoodQuantity);
                                dgvDeptStockOut.CurrentCell = dgvDeptStockOut[3, Math.Max(0, line - 1)];
                                return;
                            }
                        }
                        if (detail.LostQuantity < 0 || detail.LostQuantity > stock.LostQuantity)
                        {
                            MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng Mất phải là số dương nhỏ hơn hoặc bằng " + stock.LostQuantity);
                            return;
                        }
                        if (detail.DamageQuantity < 0 || detail.DamageQuantity > stock.DamageQuantity)
                        {
                            MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng Lỗi phải là số dương nhỏ hơn hoặc bằng " + stock.DamageQuantity);
                            return;
                        }
                        if (detail.ErrorQuantity < 0 || detail.ErrorQuantity > stock.ErrorQuantity)
                        {
                            MessageBox.Show("Lỗi ở dòng " + line + " : Số lượng Hư phải là số dương nhỏ hơn hoặc bằng " + stock.ErrorQuantity);
                            return;
                        }
                    }
                }

                line++;
            }

            if (stockOut == null)
            {
                stockOut = new StockOut();
            }
            bool isNeedClearData = stockOut.StockoutId == 0;
            stockOut.StockOutDate = dtpImportDate.Value;
            stockOut.StockOutDetails = stockOutDetailList;
            stockOut.DefectStatus = (StockDefectStatus) cbbStockOutType.SelectedItem;
            if(stockOut.DefectStatus.DefectStatusId == 9)
            {
                stockOut.NotUpdateMainStock = true;
            }
            else
            {
                stockOut.NotUpdateMainStock = false;
            }
            //            stockOut.Description = txtDexcription.Text;
            var eventArgs = new MainStockOutEventArgs();
            eventArgs.StockOut = stockOut;
            EventUtility.fireEvent(SaveStockOutEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");

                if (isNeedClearData)
                {
                    stockOut = new StockOut();
                    stockOutDetailList.Clear();
            //                    txtDexcription.Text = "";
            //                    txtPriceIn.Text = "";
            //                    txtPriceOut.Text = "";
                    txtSumProduct.Text = "";
                    txtSumValue.Text = "";
                    ClearSelectionOnListBox(lstColor);
                    ClearSelectionOnListBox(lstSize);
                    //CreateNewStockInDetail();
                }
            }
            else
            {
                //MessageBox.Show("Có lỗi khi lưu");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Add StockOut to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public StockOut Add(StockOut data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Delete StockOut from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(StockOut data)
 {
     HibernateTemplate.Delete(data);
 }
Ejemplo n.º 6
0
        public void Update(StockOut stockOut)
        {
            int listCount = stockOut.StockOutDetails.Count;
            int delCount = 0;
            if(stockOut.ConfirmFlg == 1)
            {
                stockOut.NotUpdateMainStock = true;
            }
            var maxStockOutDetailIdStr = StockOutDetailDAO.SelectSpecificType(null, Projections.Max("StockOutDetailId"));
            long maxStockOutDetailId = maxStockOutDetailIdStr != null ? Int64.Parse(maxStockOutDetailIdStr.ToString()) : 0;
            maxStockOutDetailId = maxStockOutDetailId + 1;
            IList productIds = new ArrayList();
            foreach (StockOutDetail stockOutDetail in stockOut.StockOutDetails)
            {
                productIds.Add(stockOutDetail.Product.ProductId);
            }
            var criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            criteria.AddSearchInCriteria("Product.ProductId", productIds);

            IList stockList = StockDAO.FindAll(criteria);
            foreach (StockOutDetail stockOutDetail in stockOut.StockOutDetails)
            {
                if (stockOutDetail.StockOutDetailId != 0)
                {
                    // if delete then delete it
                    if(stockOutDetail.DelFlg == 1)
                    {
                        StockOutDetailDAO.Delete(stockOutDetail);
                        delCount++;
                        continue;
                    }
                    // check number
                    var objectCriteria = new ObjectCriteria();
                    objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    objectCriteria.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId);

                    Stock stock = GetStock(stockOutDetail.Product.ProductId, stockList);
                    if (stock == null)
                    {
                        throw new BusinessException("Mặt hàng " + stockOutDetail.Product.ProductId + ", " +
                                                    stockOutDetail.Product.ProductFullName + " không có trong kho");
                    }

                    stockOutDetail.LostQuantity = 0;
                    stockOutDetail.UnconfirmQuantity = 0;

                    // xuất ra cửa hàng khác
                    if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 7)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;

                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.DamageQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;

                    }// xuất tạm
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 4)
                    {
                        // check whether it's has temp stockout enough ?

                        long totaltempErrorStockOut = 0;
                        long totalReStockCount = 0;

                        ObjectCriteria crit = new ObjectCriteria();
                        crit.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId)
                            .AddEqCriteria("DefectStatus.DefectStatusId", (long) 4)
                            .AddEqCriteria("DelFlg", (long) 0);
                        IList tempStockedOutList = StockOutDetailDAO.FindAll(crit);
                        if (tempStockedOutList != null)
                        {

                            foreach (StockOutDetail outDetail in tempStockedOutList)
                            {
                                totaltempErrorStockOut += outDetail.Quantity;
                            }

                        }

                        IList reStockList = StockInDetailDAO.FindReStock(stockOutDetail.Product.ProductId);
                        if (reStockList != null)
                        {
                            foreach (StockInDetail stockInDetail in reStockList)
                            {
                                totalReStockCount += stockInDetail.Quantity;
                            }
                        }
                        totaltempErrorStockOut = totaltempErrorStockOut - totalReStockCount;
                        if (stockOutDetail.ErrorQuantity > stock.ErrorQuantity - totaltempErrorStockOut)
                        {
                            throw new BusinessException("Lỗi: Mặt hàng " + stockOutDetail.Product.ProductFullName +
                                                        ", mã vạch "
                                                        + stockOutDetail.Product.ProductId + " có tồn " +
                                                        stock.ErrorQuantity + ", đã xuất tạm " + totaltempErrorStockOut +
                                                        ", và đang xuất " + stockOutDetail.ErrorQuantity);
                        }

                        // update quantity
                        stockOutDetail.Quantity = stockOutDetail.ErrorQuantity;
                        //stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.GoodQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                        stockOutDetail.DamageQuantity = 0;
                    }
                        // xuất trả về cho nhà sản xuất
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 5)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity + stockOutDetail.ErrorQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;
                        stock.ErrorQuantity -= stockOutDetail.ErrorQuantity;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                    }
                        // xuất hàng mẫu
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 9)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                    }
                    else // xuat hang binh thuong
                    {
                        if(stockOutDetail.Quantity > 0
                            && (    stockOutDetail.GoodQuantity == 0
                                 && stockOutDetail.ErrorQuantity ==0
                                 && stockOutDetail.DamageQuantity == 0
                                 && stockOutDetail.LostQuantity == 0
                                 && stockOutDetail.UnconfirmQuantity == 0))
                        {
                            stockOutDetail.GoodQuantity = stockOutDetail.Quantity;
                        }
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;
                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;

                    }
                    // if need to update main stock
                    if (!stockOut.NotUpdateMainStock)
                    {
                        stock.GoodQuantity -= stockOutDetail.GoodQuantity;
                        stock.UpdateDate = DateTime.Now;
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        StockDAO.Update(stock);

                        // update stock out create date
                        stockOut.CreateDate = DateTime.Now;
                        stockOut.UpdateDate = DateTime.Now;

                        stockOutDetail.CreateDate = DateTime.Now;
                        stockOutDetail.UpdateDate = DateTime.Now;
                    }

                    StockOutDetailDAO.Update(stockOutDetail);
                }
                else
                {
                    // check number
                    var objectCriteria = new ObjectCriteria();
                    objectCriteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
                    objectCriteria.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId);

                    Stock stock = GetStock(stockOutDetail.Product.ProductId, stockList);
                    if (stock == null)
                    {
                        throw new BusinessException("Mặt hàng " + stockOutDetail.Product.ProductId + ", " +
                                                    stockOutDetail.Product.ProductFullName + " không có trong kho");
                    }
                    stockOutDetail.LostQuantity = 0;
                    stockOutDetail.UnconfirmQuantity = 0;
                    // xuất ra cửa hàng khác
                    if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 7)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;

                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.DamageQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;

                    }
                    // xuất tạm
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 4)
                    {
                        // check whether it's has temp stockout enough ?

                        long totaltempErrorStockOut = 0;
                        long totalReStockCount = 0;

                        ObjectCriteria crit = new ObjectCriteria();
                        crit.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId)
                            .AddEqCriteria("DefectStatus.DefectStatusId", (long)4)
                            .AddEqCriteria("DelFlg", (long)0);
                        IList tempStockedOutList = StockOutDetailDAO.FindAll(crit);
                        if (tempStockedOutList != null)
                        {

                            foreach (StockOutDetail outDetail in tempStockedOutList)
                            {
                                totaltempErrorStockOut += outDetail.Quantity;
                            }

                        }

                        IList reStockList = StockInDetailDAO.FindReStock(stockOutDetail.Product.ProductId);
                        if (reStockList != null)
                        {
                            foreach (StockInDetail stockInDetail in reStockList)
                            {
                                totalReStockCount += stockInDetail.Quantity;
                            }
                        }
                        totaltempErrorStockOut = totaltempErrorStockOut - totalReStockCount;
                        if (stockOutDetail.ErrorQuantity > stock.ErrorQuantity - totaltempErrorStockOut)
                        {
                            throw new BusinessException("Lỗi: Mặt hàng " + stockOutDetail.Product.ProductFullName +
                                                        ", mã vạch "
                                                        + stockOutDetail.Product.ProductId + " có tồn " +
                                                        stock.ErrorQuantity + ", đã xuất tạm " + totaltempErrorStockOut +
                                                        ", và đang xuất " + stockOutDetail.ErrorQuantity);
                        }

                        // update quantity
                        stockOutDetail.Quantity = stockOutDetail.ErrorQuantity;
                        //stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.GoodQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                        stockOutDetail.DamageQuantity = 0;
                    }
                    // xuất trả về cho nhà sản xuất
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 5)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity + stockOutDetail.ErrorQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;
                        stock.ErrorQuantity -= stockOutDetail.ErrorQuantity;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                    }
                    // xuất hàng mẫu
                    else if (stockOut.DefectStatus != null && stockOut.DefectStatus.DefectStatusId == 9)
                    {
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        //stock.Quantity -= stockOutDetail.Quantity;
                        //stock.ErrorQuantity -= stockOutDetail.ErrorQuantity;
                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                    }
                    // xuất hàng bình thường
                    else
                    {
                        if (stockOutDetail.Quantity > 0
                            && (stockOutDetail.GoodQuantity == 0
                                 && stockOutDetail.ErrorQuantity == 0
                                 && stockOutDetail.DamageQuantity == 0
                                 && stockOutDetail.LostQuantity == 0
                                 && stockOutDetail.UnconfirmQuantity == 0))
                        {
                            stockOutDetail.GoodQuantity = stockOutDetail.Quantity;
                        }
                        stockOutDetail.Quantity = stockOutDetail.GoodQuantity;
                        stock.Quantity -= stockOutDetail.Quantity;
                        stockOutDetail.ErrorQuantity = 0;
                        stockOutDetail.UnconfirmQuantity = 0;
                        stockOutDetail.LostQuantity = 0;
                    }
                    // if need to update main stock
                    if (!stockOut.NotUpdateMainStock)
                    {
                        stock.GoodQuantity -= stockOutDetail.GoodQuantity;
                        stock.UpdateDate = DateTime.Now;
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

                        StockDAO.Update(stock);

                        // update create date in order can get it when synchronizing
                        stockOut.CreateDate = DateTime.Now;
                        stockOut.UpdateDate = DateTime.Now;

                        stockOutDetail.CreateDate = DateTime.Now;
                        stockOutDetail.UpdateDate = DateTime.Now;

                    }

                    stockOutDetail.StockOut = stockOut;
                    stockOutDetail.StockOutDetailId = maxStockOutDetailId++;
                    stockOutDetail.StockOutId = stockOut.StockoutId;
                    stockOutDetail.ProductMaster = stockOutDetail.Product.ProductMaster;
                    StockOutDetailDAO.Add(stockOutDetail);
                }
            }

            if(delCount == listCount)
            {
                stockOut.DelFlg = 1;
            }

            if(stockOut.DelFlg!= 1)
            {
                StockOutDAO.Update(stockOut);
            }
            else
            {
                StockOutDAO.Delete(stockOut);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Update StockOut to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(StockOut data)
 {
     HibernateTemplate.Update(data);
 }
Ejemplo n.º 8
0
 public void Delete(StockOut data)
 {
     StockOutDAO.Delete(data);
 }
Ejemplo n.º 9
0
        public void ProcessErrorGoods(IList stockList, IList returnGoodsList, IList tempStockOutList, IList destroyGoodsList)
        {
            long maxId = FindMaxId();
            maxId += 1;

            object maxDetailObj = StockOutDetailDAO.SelectSpecificType(null, Projections.Max("StockOutDetailId"));
            long maxDetailId = maxDetailObj != null ? (long)maxDetailObj : 0;
            maxDetailId += 1;

            StockOut destroytSO = new StockOut();
            destroytSO.CreateDate = DateTime.Now;
            destroytSO.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            destroytSO.UpdateDate = DateTime.Now;
            destroytSO.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            destroytSO.StockOutDate = DateTime.Now;
            destroytSO.DefectStatus = new StockDefectStatus { DefectStatusId = 8, DefectStatusName = " Huỷ hàng hư và mất" };

            destroytSO.StockoutId = maxId++;
            destroytSO.ExclusiveKey = 1;
            if (destroyGoodsList.Count > 0)
            {
                foreach (StockOutDetail stockOutDetail in destroyGoodsList)
                {

                    stockOutDetail.GoodQuantity = 0;
                    stockOutDetail.ErrorQuantity = 0;
                    stockOutDetail.CreateDate = DateTime.Now;
                    stockOutDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.UpdateDate = DateTime.Now;
                    stockOutDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.StockOut = destroytSO;
                    stockOutDetail.StockOutId = destroytSO.StockoutId;
                    stockOutDetail.DelFlg = 0;
                    stockOutDetail.ExclusiveKey = 1;
                    stockOutDetail.Description = " Huỷ hàng hư và mất";

                    // update defect
                    // update quantity of stock
                    Stock defect = GetDefectFromStockOut(stockOutDetail, stockList);
                    if (defect == null)
                    {
                        throw new BusinessException("Hàng xuất không tồn tại trong cơ sở dữ liệu, mục hàng lỗi");
                    }
                    defect.LostQuantity -= stockOutDetail.LostQuantity;
                    defect.DamageQuantity -= stockOutDetail.DamageQuantity;
                    defect.Quantity -= stockOutDetail.Quantity;

                    StockDAO.Update(defect);
                }
                destroytSO.StockOutDetails = destroyGoodsList;
                StockOutDAO.Add(destroytSO);

                foreach (StockOutDetail detail in destroyGoodsList)
                {
                    detail.StockOutDetailId = maxDetailId++;
                    StockOutDetailDAO.Add(detail);
                }
            }
            // -------------- return to manufacturer ------------
            StockOut returnSO = new StockOut();
            returnSO.CreateDate = DateTime.Now;
            returnSO.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            returnSO.UpdateDate = DateTime.Now;
            returnSO.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            returnSO.StockOutDate = DateTime.Now;
            returnSO.DefectStatus = new StockDefectStatus { DefectStatusId = 5 };
            returnSO.StockoutId = maxId++;
            returnSO.ExclusiveKey = 1;

            if (returnGoodsList.Count > 0)
            {
                foreach (StockOutDetail stockOutDetail in returnGoodsList)
                {
                    stockOutDetail.Quantity = stockOutDetail.ErrorQuantity;
                    stockOutDetail.GoodQuantity = 0;
                    stockOutDetail.LostQuantity = 0;
                    stockOutDetail.DamageQuantity = 0;
                    stockOutDetail.CreateDate = DateTime.Now;
                    stockOutDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.UpdateDate = DateTime.Now;
                    stockOutDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.StockOut = returnSO;
                    stockOutDetail.StockOutId = returnSO.StockoutId;
                    stockOutDetail.DelFlg = 0;
                    stockOutDetail.ExclusiveKey = 1;
                    stockOutDetail.Description = " Trả hàng cho nhà sản xuất";

                    Stock defect = GetDefectFromStockOut(stockOutDetail, stockList);
                    if (defect == null)
                    {
                        throw new BusinessException("Hàng xuất không tồn tại trong cơ sở dữ liệu, mục hàng lỗi");
                    }
                    defect.ErrorQuantity -= stockOutDetail.ErrorQuantity;
                    defect.Quantity -= stockOutDetail.Quantity;
                    StockDAO.Update(defect);
                }
                returnSO.StockOutDetails = returnGoodsList;
                StockOutDAO.Add(returnSO);

                //maxDetailId += 1;
                foreach (StockOutDetail detail in returnGoodsList)
                {
                    detail.StockOutDetailId = maxDetailId++;
                    StockOutDetailDAO.Add(detail);
                }
            }
            // -------------- temporary stock out
            StockOut tempSO = new StockOut();
            tempSO.CreateDate = DateTime.Now;
            tempSO.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            tempSO.UpdateDate = DateTime.Now;
            tempSO.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            tempSO.StockOutDate = DateTime.Now;
            tempSO.DefectStatus = new StockDefectStatus { DefectStatusId = 4 };
            tempSO.StockoutId = maxId++;
            tempSO.ExclusiveKey = 1;
            if (tempStockOutList.Count > 0)
            {
                foreach (StockOutDetail stockOutDetail in tempStockOutList)
                {
                    stockOutDetail.Quantity = stockOutDetail.ErrorQuantity;
                    stockOutDetail.GoodQuantity = 0;
                    stockOutDetail.LostQuantity = 0;
                    stockOutDetail.DamageQuantity = 0;
                    stockOutDetail.CreateDate = DateTime.Now;
                    stockOutDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.UpdateDate = DateTime.Now;
                    stockOutDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    stockOutDetail.StockOut = tempSO;
                    stockOutDetail.StockOutId = tempSO.StockoutId;
                    stockOutDetail.DelFlg = 0;
                    stockOutDetail.ExclusiveKey = 1;
                    stockOutDetail.Description = " Tạm xuất để sửa hàng";

                    Stock stock = GetDefectFromStockOut(stockOutDetail, stockList);
                    if (stock == null)
                    {
                        throw new BusinessException("Hàng xuất không tồn tại trong cơ sở dữ liệu, mục hàng lỗi");
                    }

                    // check whether it's has temp stockout enough ?

                    long totaltempErrorStockOut = 0;
                    long totalReStockCount = 0;

                    ObjectCriteria crit = new ObjectCriteria();
                    crit.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId)
                        .AddEqCriteria("DefectStatus.DefectStatusId", (long)4)
                        .AddEqCriteria("DelFlg", (long)0);
                    IList tempStockedOutList = StockOutDetailDAO.FindAll(crit);
                    if (tempStockedOutList != null)
                    {

                        foreach (StockOutDetail outDetail in tempStockedOutList)
                        {
                            totaltempErrorStockOut += outDetail.Quantity;
                        }

                    }

                    IList reStockList = StockInDetailDAO.FindReStock(stockOutDetail.Product.ProductId);
                    if (reStockList != null)
                    {
                        foreach (StockInDetail stockInDetail in reStockList)
                        {
                            totalReStockCount += stockInDetail.Quantity;
                        }
                    }
                    totaltempErrorStockOut = totaltempErrorStockOut - totalReStockCount;
                    if (stockOutDetail.ErrorQuantity > stock.ErrorQuantity - totaltempErrorStockOut)
                    {
                        throw new BusinessException("Lỗi: Mặt hàng " + stockOutDetail.Product.ProductFullName + ", mã vạch "
                                       + stockOutDetail.Product.ProductId + " có tồn " + stock.ErrorQuantity + ", đã xuất tạm " + totaltempErrorStockOut +
                                       ", và đang xuất " + stockOutDetail.ErrorQuantity);
                    }

                    /*defect.ErrorQuantity -= stockOutDetail.ErrorQuantity;
                    defect.Quantity -= stockOutDetail.Quantity;
                    StockDAO.Update(defect);*/
                }
                tempSO.StockOutDetails = tempStockOutList;
                StockOutDAO.Add(tempSO);

                //maxDetailId += 1;
                foreach (StockOutDetail detail in tempStockOutList)
                {
                    detail.StockOutDetailId = maxDetailId++;
                    StockOutDetailDAO.Add(detail);
                }
            }
        }
Ejemplo n.º 10
0
        public void Add(DepartmentStockIn data)
        {
            string deptStr = string.Format("{0:000}", data.DepartmentId);
            string dateStr = data.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("StockoutId", (long)0);

            var maxId = StockOutDAO.SelectSpecificType(criteria, Projections.Max("StockoutId"));
            var stockOutId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            //var stockInPk = new DepartmentStockInPK { DepartmentId = data.DepartmentId, StockInId = stockOutId + "" };

            //data.DepartmentStockInPK = stockInPk;
            data.CreateDate = DateTime.Now;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            data.CreateId = ClientInfo.getInstance().LoggedUser.Name;

            StockOut stockOut = new StockOut();
            stockOut.StockoutId = stockOutId;
            stockOut.CreateDate = DateTime.Now;
            stockOut.UpdateDate = DateTime.Now;
            stockOut.StockOutDate = DateTime.Now;
            stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.NotUpdateMainStock = false;
            stockOut.DefectStatus = new StockDefectStatus { DefectStatusId = 0};
            stockOut.DelFlg = 0;
            stockOut.DepartmentId = data.DepartmentId;

            // we will get the stock to get the data
            IList productMasterIds = new ArrayList();
            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                productMasterIds.Add(stockInDetail.Product.ProductMaster.ProductMasterId);
            }
            IList productIds = new ArrayList();
            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                productIds.Add(stockInDetail.Product.ProductId);
            }

            criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            criteria.AddGreaterCriteria("Quantity", (long)0);
            //criteria.AddSearchInCriteria("ProductMaster.ProductMasterId", productMasterIds);
            criteria.AddSearchInCriteria("Product.ProductId", productIds);
            //criteria.AddOrder("ProductMaster.ProductMasterId", true);
            criteria.AddOrder("Product.ProductId", true);
            IList stockList = StockDAO.FindAll(criteria);

            IList updateStockList = new ArrayList();
            IList stockOutDetailList = new ArrayList();

            var maxSODetailId = StockOutDetailDAO.SelectSpecificType(new ObjectCriteria(), Projections.Max("StockOutDetailId"));
            long stockOutDetailId = (maxSODetailId == null ? 1 : Int64.Parse(maxSODetailId.ToString()) + 1);

            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                long quantity = stockInDetail.Quantity;
                foreach (Stock stock in stockList)
                {
                    long stockInQty = 0;
                    //if (stock.ProductMaster.ProductMasterId.Equals(stockInDetail.Product.ProductMaster.ProductMasterId) && stock.Quantity > 0)
                    if (stock.Product.ProductId.Equals(stockInDetail.Product.ProductId) && stock.Quantity > 0)
                    {
                        if (quantity > stock.GoodQuantity)
                        {
                            throw new BusinessException("Mặt hàng: " + stock.ProductMaster.ProductName
                                + " - mã vạch: " + stock.Product.ProductId
                                + " không đủ hàng! Tồn: " + stockInDetail.StockQuantity + " , cần xuất: " + quantity);

                            stockInQty = stock.GoodQuantity;
                            quantity -= stock.GoodQuantity;
                            stock.GoodQuantity = 0;
                        }
                        else
                        {
                            stockInQty = quantity;
                            stock.GoodQuantity -= quantity;
                            quantity = 0;
                        }
                        stock.Quantity = stock.GoodQuantity + stock.ErrorQuantity + stock.DamageQuantity +
                                         stock.LostQuantity + stock.UnconfirmQuantity;
                        stock.UpdateDate = DateTime.Now;
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        updateStockList.Add(stock);

                        /*var pk = new StockOutDetailPK
                        {
                            //DepartmentId = data.DepartmentId,
                            ProductId = stock.Product.ProductId,
                            StockOutId = stockOutId
                        };*/

                        var detail = new StockOutDetail
                                         {
                                             //StockOutDetailPK = pk,
                            StockOutDetailId = stockOutDetailId++,
                            StockOutId = stockOutId,
                            StockOut = stockOut,
                            Product =  stock.Product,
                            ProductId = stock.Product.ProductId,
                            Price = stockInDetail.Price,
                            DelFlg = 0,
                            ExclusiveKey = 1,
                            Description = "Export goods",
                            DefectStatus = new StockDefectStatus { DefectStatusId = 0},
                            Quantity = stockInQty,
                            GoodQuantity = stockInQty,
                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                            UpdateId = ClientInfo.getInstance().LoggedUser.Name,
                            CreateId = ClientInfo.getInstance().LoggedUser.Name,
                            ProductMaster = stock.ProductMaster,

                        };
                        /*var deptStock = new DepartmentStock
                        {
                            DepartmentStockPK = new DepartmentStockPK
                            {
                                DepartmentId = data.DepartmentId,
                                ProductId = stock.Product.ProductId
                            },
                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                            UpdateId = ClientInfo.getInstance().LoggedUser.Name,
                            CreateId = ClientInfo.getInstance().LoggedUser.Name,
                            ProductMaster = stock.ProductMaster
                        };*/
                        stockOutDetailList.Add(detail);
                        if (quantity == 0)
                        {
                            break;
                        }
                    }
                }
                if (quantity > 0)
                {
                    if (data.DepartmentStockInPK != null)
                    {
                        data.DepartmentStockInPK.StockInId = null;
                    }
                    throw new BusinessException("Số lượng xuất kho lớn hơn số lượng trong kho : " + stockInDetail.Product.ProductId);
                }
            }
            // insert stock out and stockout detail
            stockOut.StockOutDetails = stockOutDetailList;
            if(ClientSetting.ExportConfirmation)
            {
                stockOut.ConfirmFlg = 1;
            }
            StockOutDAO.Add(stockOut);

            // Remove duplicate rows
            int count = 0;
            while (count < (stockOutDetailList.Count - 1))
            {
                StockOutDetail detail1 = (StockOutDetail)stockOutDetailList[count];
                detail1.CreateDate = DateTime.Now;
                detail1.UpdateDate = DateTime.Now;
                int maxCount = stockOutDetailList.Count - 1;
                while (maxCount > count)
                {
                    StockOutDetail detail2 = (StockOutDetail)stockOutDetailList[maxCount];

                    if (detail1.Product.ProductId.Equals(detail2.Product.ProductId))
                    {
                        detail1.Quantity += detail2.Quantity;
                        stockOutDetailList.RemoveAt(maxCount);
                    }
                    maxCount--;
                }
                count++;
            }

            foreach (StockOutDetail detail in stockOutDetailList)
            {
                StockOutDetailDAO.Add(detail);
            }

            if (!ClientSetting.ExportConfirmation)
            {
                // update stock
                foreach (Stock stock in updateStockList)
                {
                    StockDAO.Update(stock);
                }
            }
        }
Ejemplo n.º 11
0
 public void AddFixedStockOut(StockOut stockOut)
 {
     StockOutDAO.Add(stockOut);
     foreach (StockOutDetail outDetail in stockOut.StockOutDetails)
     {
         StockOutDetailDAO.Add(outDetail);
     }
 }
        void _departmentStockAdhocProcessingView_ProcessAdhocStocksEvent(object sender, DepartmentStockAdhocProcessingEventArgs e)
        {
            try
            {

                long departmentId = -1;
                StockOut stockOut = null;
                StockIn stockIn = new StockIn();
                stockIn.CreateDate = DateTime.Now;
                stockIn.UpdateDate = DateTime.Now;
                stockIn.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                stockIn.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                stockIn.StockInDate = DateTime.Now;
                stockIn.StockInType = 2; // stock in for fixing department stock quantity
                stockIn.StockInId = StockInLogic.FindMaxId();
                stockIn.StockInDetails = new ArrayList();
                long stockOutDetailMaxId = StockOutDetailLogic.FindMaxId() + 1;
                long stockOutMaxId = StockOutLogic.FindMaxId()+1;
                for (int i=0; i< e.DeptStockProcessedList.Count;i++)
                {
                    DepartmentStockTemp stockTemp = (DepartmentStockTemp) e.DeptStockProcessedList[i];
                    if(stockTemp.DepartmentStockTempPK.DepartmentId != departmentId)
                    {
                        departmentId = stockTemp.DepartmentStockTempPK.DepartmentId;

                        if (stockOut != null)
                        {
                            StockOutLogic.AddFixedStockOut(stockOut);
                        }
                        stockOut = new StockOut();
                        stockOut.CreateDate = DateTime.Now;
                        stockOut.UpdateDate = DateTime.Now;
                        stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockOut.StockOutDate = DateTime.Now;
                        stockOut.StockOutDetails = new ArrayList();
                        stockOut.DepartmentId = departmentId;
                        stockOut.DefectStatus = new StockDefectStatus{ DefectStatusId = 0};

                        stockOut.StockoutId =  stockOutMaxId++;
                    }

                    stockTemp.Fixed = 1;
                    stockTemp.UpdateDate = DateTime.Now;
                    stockTemp.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    DepartmentStockTempLogic.Update(stockTemp);
                    long realQty = stockTemp.GoodQuantity + stockTemp.ErrorQuantity + stockTemp.DamageQuantity +
                                   stockTemp.LostQuantity + stockTemp.UnconfirmQuantity;
                    if(stockTemp.Quantity < realQty)
                    {
                        long stockInQty = realQty - stockTemp.Quantity;
                        StockOutDetail stockOutDetail = new StockOutDetail();
                        stockOutDetail.CreateDate = DateTime.Now;
                        stockOutDetail.UpdateDate = DateTime.Now;
                        stockOutDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockOutDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockOutDetail.Quantity = stockInQty;
                        stockOutDetail.Product = stockTemp.Product;
                        stockOutDetail.StockOutId = stockOut.StockoutId;
                        stockOutDetail.StockOut = stockOut;
                        stockOutDetail.DefectStatus = new StockDefectStatus{DefectStatusId = 0};
                        stockOutDetail.Description = "Export goods";
                        stockOutDetail.ProductMaster = stockTemp.ProductMaster;
                        stockOutDetail.StockOutDetailId = stockOutDetailMaxId++;
                        stockOut.StockOutDetails.Add(stockOutDetail);

                        StockInDetail stockInDetail = new StockInDetail();
                        stockInDetail.CreateDate = DateTime.Now;
                        stockInDetail.UpdateDate = DateTime.Now;
                        stockInDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockInDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        stockInDetail.StockInType = 0;
                        stockInDetail.StockIn = stockIn;

                        stockInDetail.Quantity = stockInQty;
                        stockInDetail.Product = stockTemp.Product;
                        stockInDetail.ProductMaster = stockTemp.ProductMaster;
                        stockInDetail.StockInDetailPK = new StockInDetailPK
                                                            {
                                                                ProductId = stockTemp.Product.ProductId,
                                                                StockInId = stockIn.StockInId
                                                            };
                        stockIn.StockInDetails.Add(stockInDetail);

                    }

                    if (i == e.DeptStockProcessedList.Count - 1) // last item
                    {
                        StockOutLogic.AddFixedStockOut(stockOut);
                    }
                }
                StockInLogic.AddFixedStockIn(stockIn);

            }
            catch (Exception)
            {
                e.HasErrors = true;
                throw;
            }
        }
Ejemplo n.º 13
0
 private void button3_Click(object sender, EventArgs e)
 {
     stockOut = new StockOut();
     stockOutDetailList.Clear();
     //            txtDexcription.Text = "";
     //            txtPriceIn.Text = "";
     //            txtPriceOut.Text = "";
     txtSumProduct.Text = "";
     txtSumValue.Text = "";
     ClearSelectionOnListBox(lstColor);
     ClearSelectionOnListBox(lstSize);
     cboProductMasters.Text = "";
 }
Ejemplo n.º 14
0
        void baseStockOutView_SaveTempStockOut(object sender, BaseStockOutEventArgs e)
        {
            StockOut stockOut = new StockOut();
            stockOut.CreateDate = DateTime.Now;
            stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.UpdateDate = DateTime.Now;
            stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

            stockOut.DelFlg = 0;
            stockOut.StockOutDate = DateTime.Now;
            stockOut.StockOutDetails = e.SaveStockOutList;
            long maxStockOutId = StockOutLogic.FindMaxId();
            maxStockOutId = maxStockOutId + 1;

            stockOut.StockoutId = maxStockOutId;
            StockOutLogic.Add(stockOut);

            long maxStockOutDetailId = StockOutDetailLogic.FindMaxId();
            maxStockOutDetailId  = maxStockOutDetailId +1;
            foreach (StockOutDetail stockOutDetail in e.SaveStockOutList)
            {
                // check number
                ObjectCriteria objectCriteria = new ObjectCriteria();
                objectCriteria.AddEqCriteria("Product.ProductId", stockOutDetail.Product.ProductId);
                IList stockedOutList = StockOutDetailLogic.FindAll(objectCriteria);
                long quantity = CalculateQuantitiesWhichStockedOut(stockedOutList);
                long errorCount = GetErrorCount(stockOutDetail.Product.ProductId, e.SaveStockDefectList);
                if(stockOutDetail.Quantity > errorCount - quantity)
                {
                    MessageBox.Show("Số lượng hàng lỗi không đủ để xuất. Số lượng lỗi hiện có là " +
                                    errorCount.ToString() + ", số lượng đã xuất là " + quantity.ToString());
                    return;
                }

                stockOutDetail.StockOut = stockOut;
                stockOutDetail.StockOutDetailId = maxStockOutDetailId++;
                stockOutDetail.StockOutId = stockOut.StockoutId;
                StockOutDetailLogic.Add(stockOutDetail);
            }
        }
Ejemplo n.º 15
0
 public void Update(StockOut data)
 {
     StockOutDAO.Update(data);
 }
Ejemplo n.º 16
0
        public void Add(DepartmentStockIn data)
        {
            string deptStr = string.Format("{0:000}", data.DepartmentId);
            string dateStr = data.StockInDate.ToString("yyMMdd");
            var criteria = new ObjectCriteria();
            criteria.AddGreaterCriteria("StockoutId", (long)0);

            var maxId = StockOutDAO.SelectSpecificType(criteria, Projections.Max("StockoutId"));
            var stockOutId = maxId == null ? 1 : Int64.Parse(maxId.ToString()) + 1;

            //var stockInPk = new DepartmentStockInPK { DepartmentId = data.DepartmentId, StockInId = stockOutId + "" };

            //data.DepartmentStockInPK = stockInPk;
            data.CreateDate = DateTime.Now;
            data.UpdateDate = DateTime.Now;
            data.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            data.CreateId = ClientInfo.getInstance().LoggedUser.Name;

            StockOut stockOut = new StockOut();
            stockOut.StockoutId = stockOutId;
            stockOut.CreateDate = DateTime.Now;
            stockOut.UpdateDate = DateTime.Now;
            stockOut.StockOutDate = DateTime.Now;
            stockOut.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            stockOut.NotUpdateMainStock = false;
            stockOut.DefectStatus = new StockDefectStatus { DefectStatusId = 0};
            stockOut.DelFlg = 0;
            stockOut.DepartmentId = data.DepartmentId;

            // we will get the stock to get the data
            IList productMasterIds = new ArrayList();
            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                productMasterIds.Add(stockInDetail.Product.ProductMaster.ProductMasterId);
            }

            criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            criteria.AddGreaterCriteria("Quantity", (long)0);
            criteria.AddSearchInCriteria("ProductMaster.ProductMasterId", productMasterIds);
            criteria.AddOrder("ProductMaster.ProductMasterId", true);
            criteria.AddOrder("Product.ProductId", true);
            IList stockList = StockDAO.FindAll(criteria);

            IList updateStockList = new ArrayList();
            IList stockOutDetailList = new ArrayList();

            var maxSODetailId = StockOutDetailDAO.SelectSpecificType(new ObjectCriteria(), Projections.Max("StockOutDetailId"));
            long stockOutDetailId = (maxSODetailId == null ? 1 : Int64.Parse(maxSODetailId.ToString()) + 1);

            /*if(stockOutIds!= null && ((long)stockOutIds) > 0)
            {
                stockOutDetailId = (long) stockOutIds + 1;
            }
            MessageBox.Show(stockOutDetailId)*/
            /*if (stockOutIds != null && 1 == ((IList)stockOutIds).Count)
            {
                stockOutDetailId = (long)((IList)stockOutIds)[0] + 1;
            }*/

            foreach (DepartmentStockInDetail stockInDetail in data.DepartmentStockInDetails)
            {
                long quantity = stockInDetail.Quantity;
                foreach (Stock stock in stockList)
                {
                    long stockInQty = 0;
                    if (stock.ProductMaster.ProductMasterId.Equals(stockInDetail.Product.ProductMaster.ProductMasterId) && stock.Quantity > 0)
                    {
                        if (quantity >= stock.GoodQuantity)
                        {
                            stockInQty = stock.GoodQuantity;
                            quantity -= stock.GoodQuantity;
                            stock.GoodQuantity = 0;
                        }
                        else
                        {
                            stockInQty = quantity;
                            stock.GoodQuantity -= quantity;
                            quantity = 0;
                        }
                        stock.Quantity = stock.GoodQuantity + stock.ErrorQuantity + stock.DamageQuantity +
                                         stock.LostQuantity + stock.UnconfirmQuantity;
                        stock.UpdateDate = DateTime.Now;
                        stock.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        updateStockList.Add(stock);

                        /*var pk = new StockOutDetailPK
                        {
                            //DepartmentId = data.DepartmentId,
                            ProductId = stock.Product.ProductId,
                            StockOutId = stockOutId
                        };*/

                        var detail = new StockOutDetail
                                         {
                                             //StockOutDetailPK = pk,
                            StockOutDetailId = stockOutDetailId++,
                            StockOutId = stockOutId,
                            StockOut = stockOut,
                            Product =  stock.Product,
                            ProductId = stock.Product.ProductId,
                            Price = stockInDetail.Price,
                            DelFlg = 0,
                            ExclusiveKey = 1,
                            Description = "Export goods",
                            DefectStatus = new StockDefectStatus { DefectStatusId = 0},
                            Quantity = stockInQty,
                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                            UpdateId = ClientInfo.getInstance().LoggedUser.Name,
                            CreateId = ClientInfo.getInstance().LoggedUser.Name,
                            ProductMaster = stock.ProductMaster,

                        };
                        /*var deptStock = new DepartmentStock
                        {
                            DepartmentStockPK = new DepartmentStockPK
                            {
                                DepartmentId = data.DepartmentId,
                                ProductId = stock.Product.ProductId
                            },
                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                            UpdateId = ClientInfo.getInstance().LoggedUser.Name,
                            CreateId = ClientInfo.getInstance().LoggedUser.Name,
                            ProductMaster = stock.ProductMaster
                        };*/
                        stockOutDetailList.Add(detail);
                        if (quantity == 0)
                        {
                            break;
                        }
                    }
                }
                if (quantity > 0)
                {
                    data.DepartmentStockInPK.StockInId = null;
                    throw new BusinessException("Số lượng xuất kho lớn hơn số lượng trong kho");
                }
            }
            // insert stock out and stockout detail
            stockOut.StockOutDetails = stockOutDetailList;
            StockOutDAO.Add(stockOut);
            foreach (StockOutDetail detail in stockOutDetailList)
            {
                StockOutDetailDAO.Add(detail);
            }

            // update stock
            foreach (Stock stock in updateStockList)
            {
                StockDAO.Update(stock);
            }
        }