コード例 #1
0
 private long GetSpecificQuantity(StockOutDetail searchDetail,IList details, int specificCount)
 {
     foreach (StockOutDetail detail in details)
     {
         if ( detail.Product.ProductId == searchDetail.Product.ProductId &&
             detail.DefectStatus.DefectStatusId == specificCount)
         {
             return detail.Quantity;
         }
     }
     return 0;
 }
コード例 #2
0
 private bool HasCreatedView(StockOutDetail detail)
 {
     foreach (StockOutDetailView outDetailView in stockOutDetailViewList)
     {
         if(outDetailView.StockOutDetail.Product.ProductId == detail.Product.ProductId
            && outDetailView.StockOutDetail.StockOut.StockoutId == detail.StockOut.StockoutId )
         {
             return true;
         }
     }
     return false;
 }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        public void mainStockOutView_LoadStockStatusEvent(object sender, MainStockOutEventArgs e)
        {
            IList productMasterIds = new ArrayList();
            foreach (ProductMaster master in e.SelectedProductMasterList)
            {
                productMasterIds.Add(master.ProductMasterId);
            }
            var criteria = new ObjectCriteria();
            criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO);
            criteria.AddSearchInCriteria("ProductMaster.ProductMasterId", productMasterIds);
            IList list = StockLogic.FindAll(criteria);
            if (list.Count == 0)
            {
                return;
            }
            e.StockList = new ArrayList();
            e.FoundStockOutDetailList = new ArrayList();
            foreach (Stock stock in list)
            {
                StockOutDetail detail = new StockOutDetail();
                detail.Product = stock.Product;
                detail.GoodQuantity = stock.GoodQuantity;
                detail.ErrorQuantity = stock.ErrorQuantity;
                detail.LostQuantity = stock.LostQuantity;
                detail.DamageQuantity = stock.DamageQuantity;
                detail.UnconfirmQuantity = stock.UnconfirmQuantity;
                detail.Quantity = stock.Quantity;
                e.StockList.Add(stock);

                e.FoundStockOutDetailList.Add(detail);
            }
        }
コード例 #5
0
 private void LockField(int rowIndex, StockOutDetail stockOutDetail)
 {
     stockOutDetail.DefectStatus = cbbStockOutType.SelectedItem as StockDefectStatus;
     // Xuat tam de sua hang
     if (cbbStockOutType.SelectedIndex == 0)
     {
         for (int i = 0; i < dgvDeptStockOut.ColumnCount; i++)
         {
             if (i != 8 && i != 7 ) // for shoes
             {
                 dgvDeptStockOut[i, rowIndex].ReadOnly = true;
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Gray;
             }
             else
             {
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Black;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.LightYellow;
             }
         }
     }
     // Xuất trả về nhà sản xuất
     else if (cbbStockOutType.SelectedIndex == 1)
     {
         for (int i = 0; i < dgvDeptStockOut.ColumnCount; i++)
         {
             if (i != 8 && i != 7 && i != 9)
             {
                 dgvDeptStockOut[i, rowIndex].ReadOnly = true;
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Gray;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.White;
             }
             else
             {
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Black;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.LightGreen;
             }
         }
     }
     //Xuất đi cửa hàng khác
     else if (cbbStockOutType.SelectedIndex == 2)
     {
         for (int i = 0; i < dgvDeptStockOut.ColumnCount; i++)
         {
             if (i != 7)
             {
                 dgvDeptStockOut[i, rowIndex].ReadOnly = true;
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Gray;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.White;
             }
             else
             {
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Black;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.LightGreen;
             }
         }
     }
     else if (cbbStockOutType.SelectedIndex == 3) // xuất hàng mẫu
     {
         for (int i = 0; i < dgvDeptStockOut.ColumnCount; i++)
         {
             if (i != 7)
             {
                 dgvDeptStockOut[i, rowIndex].ReadOnly = true;
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Gray;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.White;
             }
             else
             {
                 dgvDeptStockOut[i, rowIndex].Style.ForeColor = Color.Black;
                 dgvDeptStockOut[i, rowIndex].Style.BackColor = Color.LightGreen;
             }
         }
     }
 }
コード例 #6
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (dgvStockDefect.SelectedRows.Count == 0)
     {
         return;
     }
     DataGridViewSelectedRowCollection selection = dgvStockDefect.SelectedRows;
     if (!DepartmentProcessing)
     {
         foreach (DataGridViewRow row in selection)
         {
             Stock defect = stockDefectList[row.Index];
             StockOutDetail detail = new StockOutDetail();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.ErrorQuantity = defect.ErrorQuantity;
             detail.Quantity = detail.ErrorQuantity;
             detail.DefectStatus = new StockDefectStatus { DefectStatusId = 4 }; // trả về nhà sản xuất
             tempStockOutList.Add(detail);
         }
     }
     else
     {
         foreach (DataGridViewRow row in selection)
         {
             DepartmentStock defect = deptStockDefectList[row.Index];
             DepartmentStockOutDetail detail = new DepartmentStockOutDetail();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.ErrorQuantity = defect.ErrorQuantity;
             detail.Quantity = detail.ErrorQuantity;
             detail.DefectStatus = new StockDefectStatus { DefectStatusId = 4 }; // trả về nhà sản xuất
             deptTempStockOutList.Add(detail);
         }
     }
     bdsTempStockOut.EndEdit();
     dgvTempStockOut.Refresh();
     dgvTempStockOut.Invalidate();
 }
コード例 #7
0
 /// <summary>
 /// Delete StockOutDetail from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(StockOutDetail data)
 {
     HibernateTemplate.Delete(data);
 }
コード例 #8
0
        private DepartmentStockIn SaveDeptStockIn(bool isNeedSync)
        {
            // check for department
            var dept = cbbDept.SelectedItem as Department;
            if (dept == null)
            {
                MessageBox.Show("Không có cửa hàng nào để xuất hàng");
                return null;
            }

            // first remove all blank row
            int count = 0;
            int length = deptSIDetailList.Count;
            for (int i = 0; i < length - count; i++)
            {
                DepartmentStockInDetail detail = deptSIDetailList[i];
                if (string.IsNullOrEmpty(detail.Product.ProductMaster.ProductMasterId)
                    && string.IsNullOrEmpty(detail.Product.ProductMaster.ProductName))
                {
                    deptSIDetailList.RemoveAt(i - count);
                    count++;
                }
            }

            if (deptSIDetailList.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào để xuất!!!!");
                return null;
            }

            // validate quantity
            StringBuilder errMsg = new StringBuilder();
            int line = 1;
            if(chkRemoveZero.Checked)
            {
                RemoveZeroLines();
            }
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                if (detail.Quantity == 0)
                {
                    errMsg.Append(" " + line + " ");
                }
                line++;
            }
            if (errMsg.Length > 0)
            {
                MessageBox.Show("Lỗi ở dòng " + errMsg.ToString() + " : Số lượng phải lớn hơn 0");
                return null;
            }

            /*count = 0;
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                line = 0;
                foreach (DepartmentStockInDetail detail2 in deptSIDetailList)
                {
                    if (detail.DelFlg == CommonConstants.DEL_FLG_NO
                        && detail.Product.ProductId.Equals(detail2.Product.ProductId))
                    {
                        if(count!=line)
                        {
                            MessageBox.Show("Lỗi : Mã vạch " + detail.Product.ProductId + " nhập 2 lần");
                            dgvDeptStockIn.CurrentCell = dgvDeptStockIn[3, line];
                            return null;
                        }
                    }
                    line++;
                }
                count++;
            }*/

            RemoveDuplicateRows();

            if (deptSI == null)
            {
                deptSI = new DepartmentStockIn();
            }

            deptSI.StockInDate = dtpImportDate.Value;
            deptSI.DepartmentId = dept.DepartmentId;
            deptSI.Description = txtDexcription.Text;
            deptSI.DepartmentStockInDetails = deptSIDetailList;

            var eventArgs = new DepartmentStockInEventArgs();
            eventArgs.IsForSync = isNeedSync;
            eventArgs.DepartmentStockIn = deptSI;
            eventArgs.ExportGoodsToDepartment = true;
            // update stock out
            foreach (DepartmentStockInDetail detail in deptSIDetailList)
            {
                bool newRow = true;
                foreach (StockOutDetail outDetail in StockOut.StockOutDetails)
                {
                    if(outDetail.Product.ProductId == detail.Product.ProductId)
                    {
                        newRow = false;
                        outDetail.Quantity = detail.Quantity;
                        outDetail.GoodQuantity = detail.Quantity;
                        outDetail.DelFlg = detail.DelFlg;
                        break;
                    }
                }
                if(newRow)
                {
                    StockOutDetail outDetail = new StockOutDetail();
                    outDetail.Product = detail.Product;
                    outDetail.CreateDate = detail.CreateDate;
                    outDetail.CreateId = detail.CreateId;
                    outDetail.UpdateDate = detail.UpdateDate;
                    outDetail.Price = detail.Price;
                    outDetail.StockOutId = StockOut.StockoutId;
                    outDetail.Quantity = detail.Quantity;
                    outDetail.GoodQuantity = detail.Quantity;
                    outDetail.ProductMaster = detail.Product.ProductMaster;
                    outDetail.StockOut = StockOut;
                    StockOut.StockOutDetails.Add(outDetail);
                }
            }
            eventArgs.UpdateStockOut = StockOut;
            EventUtility.fireEvent(UpdateStockOutEvent, this, eventArgs);
            if (eventArgs.EventResult != null)
            {
                MessageBox.Show("Lưu thành công");
                txtDexcription.Text = "";
                txtQuantity.Text = "";
                txtSumValue.Text = "";
                txtSumProduct.Text = "";
                ClearSelectionOnListBox(lstColor);
                ClearSelectionOnListBox(lstSize);
                return eventArgs.DepartmentStockIn;
            }
            else
            {
                return null;
            }
        }
コード例 #9
0
 /// <summary>
 /// Update StockOutDetail to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(StockOutDetail data)
 {
     HibernateTemplate.Update(data);
 }
コード例 #10
0
 /// <summary>
 /// Add StockOutDetail to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public StockOutDetail Add(StockOutDetail data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
コード例 #11
0
 private void btnError_Click(object sender, EventArgs e)
 {
     if( dgvStockDefect.SelectedRows.Count == 0)
     {
         return;
     }
     DataGridViewSelectedRowCollection selection = dgvStockDefect.SelectedRows;
     if (!DepartmentProcessing)
     {
         foreach (DataGridViewRow row in selection)
         {
             Stock defect = stockDefectList[row.Index];
             StockOutDetail detail = new StockOutDetail();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.Quantity = defect.ErrorQuantity;
             detail.ErrorQuantity = defect.ErrorQuantity;
             //detail.DamageQuantity = defect.DamageQuantity;
             detail.DefectStatus = new StockDefectStatus{ DefectStatusId = 5}; // trả về nhà sản xuất
             returnGoodsList.Add(detail);
         }
     }
     else
     {
         foreach (DataGridViewRow row in selection)
         {
             DepartmentStock defect = deptStockDefectList[row.Index];
             DepartmentStockOutDetail detail = new DepartmentStockOutDetail();
             detail.DepartmentStockOutDetailPK = new DepartmentStockOutDetailPK();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.Quantity = defect.ErrorQuantity;
             detail.ErrorQuantity = defect.ErrorQuantity;
             //detail.DamageQuantity = defect.DamageQuantity;
             detail.DefectStatus = new StockDefectStatus { DefectStatusId = 6 }; // trả về kho chính
             deptReturnGoodsList.Add(detail);
         }
     }
     bdsReturnGoods.EndEdit();
     dgvReturnStockOut.Refresh();
     dgvReturnStockOut.Invalidate();
 }
コード例 #12
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (dgvStockDefect.SelectedRows.Count == 0)
     {
         return;
     }
     DataGridViewSelectedRowCollection selection = dgvStockDefect.SelectedRows;
     if (!DepartmentProcessing)
     {
         foreach (DataGridViewRow row in selection)
         {
             Stock defect = stockDefectList[row.Index];
             StockOutDetail detail = new StockOutDetail();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.LostQuantity = defect.LostQuantity;
             detail.DamageQuantity = defect.DamageQuantity;
             detail.Quantity = detail.LostQuantity + detail.DamageQuantity;
             detail.DefectStatus = new StockDefectStatus { DefectStatusId = 8 }; // hủy hàng
             destroyGoodsList.Add(detail);
         }
     }
     else
     {
         foreach (DataGridViewRow row in selection)
         {
             DepartmentStock defect = deptStockDefectList[row.Index];
             DepartmentStockOutDetail detail = new DepartmentStockOutDetail();
             detail.DepartmentStockOutDetailPK = new DepartmentStockOutDetailPK();
             detail.Product = defect.Product;
             detail.ProductMaster = defect.ProductMaster;
             detail.LostQuantity = defect.LostQuantity;
             detail.DamageQuantity = defect.DamageQuantity;
             detail.Quantity = detail.LostQuantity + detail.DamageQuantity;
             detail.DefectStatus = new StockDefectStatus { DefectStatusId = 8 }; // hủy hàng
             deptDestroyGoodsList.Add(detail);
         }
     }
     bdsDestroyGoods.EndEdit();
     dgvGoodsDestroy.Refresh();
     dgvGoodsDestroy.Invalidate();
 }
コード例 #13
0
        void mainStockOutView_FindByStockInIdEvent(object sender, MainStockOutEventArgs e)
        {
            if (e.SelectedStockInIds.Count > 0)
            {
                ObjectCriteria objectCriteria = new ObjectCriteria();
                objectCriteria.AddSearchInCriteria("StockInDetailPK.StockInId", e.SelectedStockInIds);
                IList list = StockInDetailLogic.FindAll(objectCriteria);
                IList stockOutList = new ArrayList();
                foreach (StockInDetail inDetail in list)
                {
                    StockOutDetail deptDetail = new StockOutDetail();
                    deptDetail.CreateDate = DateTime.Now;
                    deptDetail.UpdateDate = DateTime.Now;
                    deptDetail.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    deptDetail.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    //deptDetail. = new DepartmentStockInDetailPK();
                    deptDetail.Product = inDetail.Product;
                    deptDetail.ProductMaster = inDetail.Product.ProductMaster;
                    deptDetail.Quantity = inDetail.Quantity;
                    deptDetail.GoodQuantity = inDetail.Quantity;
                    stockOutList.Add(deptDetail);
                }
                GetRemainStockNumber(stockOutList);

                e.SelectedStockOutDetails = stockOutList;
            }
            EventUtility.fireEvent(CompletedFindByStockInEvent, this, e);
        }
コード例 #14
0
 private Stock GetDefectFromStockOut(StockOutDetail detail, IList list)
 {
     foreach (Stock stockDefect in list)
     {
         if(stockDefect.Product.ProductId == detail.Product.ProductId)
         {
             return stockDefect;
         }
     }
     return null;
 }
コード例 #15
0
 public void Update(StockOutDetail data)
 {
     StockOutDetailDAO.Update(data);
 }
コード例 #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);
            }
            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);
                }
            }
        }
コード例 #17
0
 public StockOutDetail Add(StockOutDetail data)
 {
     StockOutDetailDAO.Add(data);
     return data;
 }
コード例 #18
0
 private bool IsInList(StockOutDetailCollection collection, StockOutDetail detail)
 {
     foreach (StockOutDetail outDetail in collection)
     {
         if (detail.Product.ProductId.Equals(outDetail.Product.ProductId))
         {
             return true;
         }
     }
     return false;
 }
コード例 #19
0
 public void Delete(StockOutDetail data)
 {
     StockOutDetailDAO.Delete(data);
 }
コード例 #20
0
 private bool HasCreatedView(StockOutDetail detail)
 {
     foreach (StockOutDetailView outDetailView in deptStockOutDetailList)
     {
         if (outDetailView.StockOutDetail.Product.ProductId == detail.Product.ProductId
             && outDetailView.StockOutDetail.StockOutDetailId == detail.StockOutDetailId)
             //&& outDetailView.StockOutDetail.DepartmentId == detail.DepartmentStockOut.DepartmentStockOutPK.DepartmentId)
         {
             return true;
         }
     }
     return false;
 }
コード例 #21
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);
            }
        }