Exemplo n.º 1
0
        /// <summary>
        /// Lấy dữ liệu nhập xuất kho
        /// </summary>
        /// <param name="fromDate">ngày bắt đầu</param>
        /// <param name="toDate">ngày kết thúc</param>
        /// <param name="warehouseID">mã kho</param>
        /// <param name="isPhatSinh">chỉ lấy PS</param>
        /// <returns></returns>
        public List <GetTongHopKho> GetNhapXuatKho(DateTime fromDate, DateTime toDate, string warehouseID, bool isPhatSinh)
        {
            // Lấy dữ liệu phát sinh trong kỳ
            List <GetTongHopKho> psData = ReportDAO.GetTongHopKho(fromDate, toDate, warehouseID);

            // Lấy dữ liệu đầu kỳ
            List <GetWarehouseBalance> dauKyData = this.GetWarehouseBalances(fromDate, warehouseID);

            // Thêm đầu kỳ vào dữ liệu phát sinh
            var     dkNotPS         = new List <GetTongHopKho>();
            string  preItem         = string.Empty;
            decimal balanceQuantity = 0;
            decimal balanceAmount   = 0;

            foreach (var item in psData)
            {
                var find = dauKyData.Find(o => GetKey(o.ItemID, o.WarehouseListID) == GetKey(item.ItemID, item.WarehouseListID));
                if (find != null)
                {
                    balanceQuantity = find.Quantity;
                    balanceAmount   = find.Amount;
                }
                else
                {
                    balanceQuantity = 0;
                    balanceAmount   = 0;
                }

                item.LuongDK = balanceQuantity;
                item.TienDK  = balanceAmount;
            }

            if (!isPhatSinh)
            {
                // xử lý trường hợp có đầu kỳ nhưng lại không có phát sinh
                foreach (var item in dauKyData)
                {
                    if (psData.Find(o => GetKey(o.ItemID, o.WarehouseListID) == GetKey(item.ItemID, item.WarehouseListID)) == null)
                    {
                        psData.Add(new GetTongHopKho
                        {
                            ItemID          = item.ItemID,
                            WarehouseListID = item.WarehouseListID,
                            LuongDK         = item.Quantity,
                            TienDK          = item.Amount
                        });
                    }
                }
            }

            return(psData);
        }