예제 #1
0
        public async Task <PrintPreProductNameItem> SearchRecordsForPrintingExternal()
        {
            // Find all tx51
            var productShelfStatuss = _unitOfWork.ProductShelfStatusRepository.GetAll();

            // Find all tx53
            var outSidePreShelfStocks = _unitOfWork.OutSidePrePdtStkRepository.GetAll();

            // Get all tm03.
            var preProducts = _unitOfWork.PreProductRepository.GetAll();

            // Record which should be printed.
            var printPreProductNameItem = new PrintPreProductNameItem();

            var condition1 = Constants.F51_ShelfStatus.TX51_ShfSts_ExtPrePdt;
            var condition2 = Constants.F51_ShelfType.Normal.ToString("D");


            // Find Pre Product Name item.
            var preProductNameItems = from preProduct in preProducts
                                      join outSidePreShelfStock in outSidePreShelfStocks on preProduct.F03_PreProductCode equals outSidePreShelfStock.F53_OutSidePrePdtCode
                                      join productShelfStatus in productShelfStatuss on outSidePreShelfStock.F53_PalletNo equals productShelfStatus.F51_PalletNo
                                      where productShelfStatus.F51_ShelfStatus.Trim().Equals(condition1) &&
                                      productShelfStatus.F51_ShelfType.Trim().Equals(condition2)
                                      orderby new
            {
                outSidePreShelfStock.F53_OutSidePrePdtCode,
                outSidePreShelfStock.F53_OutSidePrePdtLotNo
            }
            select new FindPrintPreProductNameItem
            {
                OutsidePreProductCode = outSidePreShelfStock.F53_OutSidePrePdtCode,
                PreProductName        = preProduct.F03_PreProductName,
                PalletNo = outSidePreShelfStock.F53_PalletNo,
                OutsidePreProductLotNo = outSidePreShelfStock.F53_OutSidePrePdtLotNo,
                ShelfNo = productShelfStatus.F51_ShelfRow + "-" + productShelfStatus.F51_ShelfBay + "-" + productShelfStatus.F51_ShelfLevel,
                Amount  = outSidePreShelfStock.F53_Amount,
            };



            if (!preProductNameItems.Any())
            {
                return(null);
            }

            var groups = preProductNameItems.GroupBy(a => new { a.OutsidePreProductCode })
                         .Select(g1 => new
            {
                OutsidePreProductCode = g1.Key.OutsidePreProductCode,
                PreProductTotal       = g1.Sum(c => c.Amount),
                Groups = g1
                         .GroupBy(b => new { b.OutsidePreProductCode, b.OutsidePreProductLotNo })
                         .Select(g2 => new
                {
                    OutsidePreProductCode  = g2.Key.OutsidePreProductCode,
                    OutsidePreProductLotNo = g2.Key.OutsidePreProductLotNo,
                    LotTotal = g2.Sum(d => d.Amount),
                    Group2   = g2.Select(g3 => new FindPrintPreProductNameItem()
                    {
                        OutsidePreProductCode = g3.OutsidePreProductCode,
                        PreProductName        = g3.PreProductName,
                        PalletNo = g3.PalletNo,
                        OutsidePreProductLotNo = g3.OutsidePreProductLotNo,
                        ShelfNo = g3.ShelfNo,
                        Amount  = g3.Amount
                    })
                })
            });



            foreach (var groupA in groups.ToList())
            {
                var printPreProductNameGroup = new PrintPreProductNameGroup();
                foreach (var groupB in groupA.Groups.ToList())
                {
                    PrintPreProductNameGroupItem printPreProductNameGroupItem = new PrintPreProductNameGroupItem();
                    foreach (var groupC in groupB.Group2.ToList())
                    {
                        printPreProductNameGroupItem.FindPrintPreProductNameItem.Add(groupC);
                    }
                    printPreProductNameGroupItem.LotTotal       = groupB.LotTotal;
                    printPreProductNameGroupItem.LotTotalString = String.Format("{0:#,##0.00}", groupB.LotTotal);
                    printPreProductNameGroup.PrintPreProductNameGroupItem.Add(printPreProductNameGroupItem);
                }
                printPreProductNameGroup.PreproductTotal       = groupA.PreProductTotal;
                printPreProductNameGroup.PreproductTotalString = String.Format("{0:#,##0.00}", groupA.PreProductTotal);
                printPreProductNameItem.PrintPreProductNameGroup.Add(printPreProductNameGroup);
            }



            await _unitOfWork.CommitAsync();

            //printPreProductNameItem.FindPrintPreProductNameItem = await preProductNameItems.ToListAsync();

            return(printPreProductNameItem);
        }
예제 #2
0
        /// <summary>
        ///     This function is for exporting data from kneading command database to list.
        /// </summary>
        /// <returns></returns>
        public async Task <PrintPreProductNameItem> SearchRecordsForPrintingNormal()
        {
            //Get all record tx37
            var preProductShelfStatuss = _unitOfWork.PreProductShelfStatusRepository.GetAll();
            //Get all record tx49
            var preProductShelfStocks = _unitOfWork.PreProductShelfStockRepository.GetAll();

            // Get all tm03.
            var preProducts = _unitOfWork.PreProductRepository.GetAll();

            var condition1 = Constants.F49_ShelfStatus.TX49_StkFlg_Stk;

            // Record which should be printed.
            var printPreProductNameItem = new PrintPreProductNameItem();


            // Find Pre Product Name item.
            var preProductNameItems = from preProduct in preProducts
                                      join preProductShelfStock in preProductShelfStocks on preProduct.F03_PreProductCode equals preProductShelfStock.F49_PreProductCode
                                      join preProductShelfStatus in preProductShelfStatuss on preProductShelfStock.F49_ContainerCode equals preProductShelfStatus.F37_ContainerCode
                                      where preProductShelfStock.F49_ShelfStatus.Trim().Equals(condition1)
                                      //group materialShelfStock by materialShelfStock.F33_MaterialCode into grp
                                      orderby new
            {
                preProductShelfStock.F49_PreProductCode,
                preProductShelfStock.F49_PreProductLotNo,
                preProductShelfStock.F49_ContainerCode
            }

            select new FindPrintPreProductNameItem()
            {
                PreProductCode  = preProductShelfStock.F49_PreProductCode,
                PreProductName  = preProduct.F03_PreProductName,
                ContainerCode   = preProductShelfStock.F49_ContainerCode,
                PreProductLotNo = preProductShelfStock.F49_PreProductLotNo,
                ShelfNo         = preProductShelfStatus.F37_ShelfRow + "-" + preProductShelfStatus.F37_ShelfBay + "-" + preProductShelfStatus.F37_ShelfLevel,
                Amount          = preProductShelfStock.F49_Amount,
            };

            if (!preProductNameItems.Any())
            {
                return(null);
            }


            var groups = preProductNameItems.GroupBy(a => new { a.PreProductCode })
                         .Select(g1 => new
            {
                PreProductCode  = g1.Key.PreProductCode,
                PreProductTotal = g1.Sum(c => c.Amount),
                Groups          = g1
                                  .GroupBy(b => new{ b.PreProductCode, b.PreProductLotNo })
                                  .Select(g2 => new
                {
                    PreProductCode  = g2.Key.PreProductCode,
                    PreProductLotNo = g2.Key.PreProductLotNo,
                    LotTotal        = g2.Sum(d => d.Amount),
                    Group2          = g2.Select(g3 => new FindPrintPreProductNameItem()
                    {
                        PreProductCode  = g3.PreProductCode,
                        PreProductName  = g3.PreProductName,
                        ContainerCode   = g3.ContainerCode,
                        PreProductLotNo = g3.PreProductLotNo,
                        ShelfNo         = g3.ShelfNo,
                        Amount          = g3.Amount,
                    })
                })
            });



            foreach (var groupA in groups.ToList())
            {
                var printPreProductNameGroup = new PrintPreProductNameGroup();
                foreach (var groupB in groupA.Groups.ToList())
                {
                    PrintPreProductNameGroupItem printPreProductNameGroupItem = new PrintPreProductNameGroupItem();
                    foreach (var groupC in groupB.Group2.ToList())
                    {
                        printPreProductNameGroupItem.FindPrintPreProductNameItem.Add(groupC);
                    }
                    printPreProductNameGroupItem.LotTotal       = groupB.LotTotal;
                    printPreProductNameGroupItem.LotTotalString = String.Format("{0:#,##0.00}", groupB.LotTotal);
                    printPreProductNameGroup.PrintPreProductNameGroupItem.Add(printPreProductNameGroupItem);
                }
                printPreProductNameGroup.PreproductTotal       = groupA.PreProductTotal;
                printPreProductNameGroup.PreproductTotalString = String.Format("{0:#,##0.00}", groupA.PreProductTotal);
                printPreProductNameItem.PrintPreProductNameGroup.Add(printPreProductNameGroup);
            }


            await _unitOfWork.CommitAsync();

            //printPreProductNameItem.FindPrintPreProductNameItem = await preProductNameItems.ToListAsync();

            return(printPreProductNameItem);
        }