Exemplo n.º 1
0
        // ------------------Hàm lấy chi tiết của 1 Receive_No.------------------------------------------------------------
        public async Task <List <ReceiveNoDetail> > ReceiveNoDetails(string receive_No)
        {
            var packingListDetail = await _repoPackingListDetail.FindAll(x => x.Receive_No.Trim() == receive_No.Trim()).ToListAsync();

            var listData = packingListDetail.Select(x => new ReceiveNoDetail()
            {
                Tool_Size    = x.Tool_Size,
                Order_Size   = x.Order_Size,
                Purchase_Qty = x.Purchase_Qty,
                Received_Qty = x.Received_Qty,
            }).OrderBy(x => decimal.Parse(x.Order_Size)).ToList();

            return(listData);
        }
Exemplo n.º 2
0
        public List <dynamic> GetMOQtyTransferForm(string collectTransNo)
        {
            var transationMain = _transactionMainRepo.FindAll();
            var packingList    = _packingListRepository.FindAll();
            var qrCodeMain     = _qRCodeMainRepository.FindAll();

            var transacNo = _transferFormRepository.FindAll(x => x.Collect_Trans_No == collectTransNo).Select(x => x.Transac_No).ToList();

            List <dynamic> packingListDetailTotal = new List <dynamic>();
            var            recieveNo = transacNo.Join(
                transationMain,
                x => x,
                y => y.Transac_No,
                (x, y) => new { x, TransationMain = y })
                                       .GroupJoin(
                qrCodeMain,
                x => new { QRCode_ID = x.TransationMain.QRCode_ID, QRCode_Version = x.TransationMain.QRCode_Version },
                y => new { QRCode_ID = y.QRCode_ID, QRCode_Version = y.QRCode_Version },
                (x, y) => new { TransactionMain = x, QrCodeMain = y })
                                       .SelectMany(
                x => x.QrCodeMain.DefaultIfEmpty(),
                (x, y) => new { TransactionMain = x.TransactionMain, QrCodeMain = y })
                                       .GroupJoin(
                packingList,
                x => x.QrCodeMain.Receive_No,
                y => y.Receive_No,
                (x, y) => new { TransactionMainQrCodeMain = x, PackingList = y })
                                       .SelectMany(
                x => x.PackingList.DefaultIfEmpty(),
                (x, y) => new
            {
                y.Receive_No
            }).ToList();

            foreach (var itemRecieveNo in recieveNo)
            {
                var packinglistDetail = _packingListDetailRepository.FindAll().Where(x => x.Receive_No.Trim() == itemRecieveNo.Receive_No.ToString().Trim()).Select(x => new { x.Tool_Size, x.Order_Size, x.MO_Qty }).OrderBy(x => x.Tool_Size).ToList();
                packingListDetailTotal.AddRange(packinglistDetail);
            }
            var packingListDetailResult = packingListDetailTotal.GroupBy(x => new { x.Tool_Size, x.Order_Size })
                                          .Select(x => new
            {
                Tool_Size  = x.Key.Tool_Size,
                Order_Size = x.Key.Order_Size,
                MO_Qty     = x.Sum(x => Convert.ToInt32(x.MO_Qty))
            }).ToList <dynamic>();

            return(packingListDetailResult);
        }
Exemplo n.º 3
0
        public async Task <bool> AddListQRCode(List <string> listReceiveNo, string updateBy)
        {
            listReceiveNo = listReceiveNo.Select(x => x.Trim()).ToList();
            var packingLists = await _repoPacking.FindAll(x => listReceiveNo.Contains(x.Receive_No.Trim())).ToListAsync();

            var checkCreate = true;

            foreach (var item in listReceiveNo)
            {
                // Tạo QrCodeMain để thêm vào database
                var qrCodeDto = new QRCode_Main_Dto();
                var packing   = packingLists.Where(x => x.Receive_No.Trim() == item).FirstOrDefault();
                // Nếu Generated_QrCode khác Y thì mới Tạo QrCode
                if (packing.Generated_QRCode != "Y")
                {
                    packing.Generated_QRCode = "Y";
                    string qrCodeId = "";
                    if (packing.Sheet_Type.Trim() == "R" || packing.Sheet_Type.Trim() == "M")
                    {
                        do
                        {
                            var    po = packing.MO_No.Trim().Length == 9 ? packing.MO_No.Trim() + "Z" : packing.MO_No.Trim();
                            string so = CodeUtility.RandomNumber(3);
                            qrCodeId = "A" + po + so + CodeUtility.RandomStringUpper(1);
                        } while (await this.CheckQrCodeID(qrCodeId));
                    }
                    else if (packing.Sheet_Type.Trim() == "B")
                    {
                        do
                        {
                            var    po = packing.MO_No.Trim().Length == 9 ? packing.MO_No.Trim() + "Z" : packing.MO_No.Trim();
                            string so = CodeUtility.RandomNumber(3);
                            qrCodeId = "B" + po + so + CodeUtility.RandomStringUpper(1);
                        } while (await this.CheckQrCodeID(qrCodeId));
                    }
                    qrCodeDto.QRCode_ID      = qrCodeId;
                    qrCodeDto.Receive_No     = packing.Receive_No.Trim();
                    qrCodeDto.QRCode_Version = 1;
                    qrCodeDto.Valid_Status   = "Y";
                    qrCodeDto.Is_Scanned     = "N";
                    qrCodeDto.QRCode_Type    = packing.Sheet_Type.Trim();
                    qrCodeDto.Updated_By     = updateBy;
                    await _repoPacking.SaveAll();

                    var qrCodeMain = _mapper.Map <WMSB_QRCode_Main>(qrCodeDto);
                    _repoQrcode.Add(qrCodeMain);

                    // Tạo QrCodeDetail để thêm vào database
                    var listPackingDetail = await _repoPackingDetail.FindAll(x => x.Receive_No.Trim() == item).ToListAsync();

                    foreach (var packingItem in listPackingDetail)
                    {
                        var qrCodeDetailDto = new QRCode_Detail_Dto();
                        qrCodeDetailDto.QRCode_ID      = qrCodeId;
                        qrCodeDetailDto.QRCode_Version = 1;
                        qrCodeDetailDto.Order_Size     = packingItem.Order_Size;
                        qrCodeDetailDto.Model_Size     = packingItem.Model_Size;
                        qrCodeDetailDto.Tool_Size      = packingItem.Tool_Size;
                        qrCodeDetailDto.Spec_Size      = packingItem.Spec_Size;
                        qrCodeDetailDto.Qty            = packingItem.Received_Qty;
                        qrCodeDetailDto.Updated_By     = updateBy;
                        var qrCodeDetail = _mapper.Map <WMSB_QRCode_Detail>(qrCodeDetailDto);
                        _repoQrCodeDetail.Add(qrCodeDetail);
                        if (!await _repoQrCodeDetail.SaveAll())
                        {
                            checkCreate = false;
                            break;
                        }
                    }
                }
            }
            await _repoQrcode.SaveAll();

            return(checkCreate);
        }
Exemplo n.º 4
0
        public async Task <List <OutputPrintQrCode_Dto> > PrintByQRCodeIDAgain(List <QrCodeIDVersion> ListParamPrintQrCodeAgain)
        {
            List <OutputPrintQrCode_Dto> listResult = new List <OutputPrintQrCode_Dto>();

            foreach (var paramPrintQrCodeAgain in ListParamPrintQrCodeAgain)
            {
                // hàm lấy ra thông tin qrcode main, mấy thông tin chính
                var qrCodeModel = await GetQrCodeInfor(paramPrintQrCodeAgain.QRCode_ID, paramPrintQrCodeAgain.MO_Seq);

                // ở dưới là lấy ra thông tin chi tiết của qrcode đó
                var qrCodeMan = _repoQRCodeMain.FindSingle(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() &&
                                                           x.QRCode_Version == paramPrintQrCodeAgain.QRCode_Version);
                var transactionMainTypeR = await _repoTransactionMain.FindAll(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() &&
                                                                              x.QRCode_Version == paramPrintQrCodeAgain.QRCode_Version && x.Can_Move == "Y").FirstOrDefaultAsync();

                var transactionDetailsTypeR = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == transactionMainTypeR.Transac_No.Trim()).ToListAsync();

                var transactionMain = await _repoTransactionMain.FindAll(x => x.QRCode_ID.Trim() == paramPrintQrCodeAgain.QRCode_ID.Trim() &&
                                                                         x.Transac_Type == "I").FirstOrDefaultAsync();

                var transactionDetails = await _repoTransactionDetail
                                         .FindAll(x => x.Transac_No.Trim() == transactionMain.Transac_No.Trim()).ToListAsync();

                var listsPackingListDetail = await _repoPackingListDetail.FindAll()
                                             .Where(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).ToListAsync();

                //--------- phần xuất thêm giá trị đã output
                var transactionMainOutputs = await _repoTransactionMain.FindAll(x => x.Purchase_No.Trim() == transactionMain.Purchase_No.Trim() &&
                                                                                x.MO_No.Trim() == transactionMain.MO_No.Trim() && x.MO_Seq.Trim() == transactionMain.MO_Seq.Trim() &&
                                                                                x.Material_ID == transactionMain.Material_ID && x.Transac_Type.Trim() == "O").ToListAsync();

                List <WMSB_Transaction_Detail> transactionDetailOutputs = new List <WMSB_Transaction_Detail>();
                if (transactionMainOutputs.Count() > 0)
                {
                    foreach (var item in transactionMainOutputs)
                    {
                        var transactionDetailOutput = await _repoTransactionDetail.FindAll(x => x.Transac_No.Trim() == item.Transac_No.Trim()).ToListAsync();

                        transactionDetailOutputs.AddRange(transactionDetailOutput);
                    }
                }

                var transactionDetailOutputGroupBy = transactionDetailOutputs.GroupBy(x => new { x.Tool_Size, x.Order_Size }).Select(x => new
                {
                    OutQty     = x.Sum(y => y.Trans_Qty),
                    Tool_Size  = x.Key.Tool_Size,
                    Order_Size = x.Key.Order_Size
                }).ToList();
                //------------

                var packingListDetailModel = new List <PackingListDetailViewModel>();
                foreach (var item in listsPackingListDetail)
                {
                    var packingItem = new PackingListDetailViewModel();
                    packingItem.Receive_No   = item.Receive_No;
                    packingItem.Order_Size   = item.Order_Size;
                    packingItem.Model_Size   = item.Model_Size;
                    packingItem.Tool_Size    = item.Tool_Size;
                    packingItem.Spec_Size    = item.Spec_Size;
                    packingItem.MO_Qty       = item.MO_Qty;
                    packingItem.Purchase_Qty = item.Purchase_Qty;
                    foreach (var item1 in transactionDetails)
                    {
                        if (item1.Tool_Size.Trim() == item.Tool_Size.Trim() && item1.Order_Size.Trim() == item.Order_Size.Trim())
                        {
                            packingItem.Received_Qty = item1.Qty;
                            packingItem.Bal          = item1.Untransac_Qty;
                        }
                    }
                    foreach (var item3 in transactionDetailsTypeR)
                    {
                        if (item3.Tool_Size.Trim() == item.Tool_Size.Trim() && item3.Order_Size.Trim() == item.Order_Size.Trim())
                        {
                            packingItem.Act = item3.Instock_Qty;
                        }
                    }
                    if (transactionDetailOutputGroupBy.Count() > 0)
                    {
                        foreach (var item2 in transactionDetailOutputGroupBy)
                        {
                            if (item2.Tool_Size.Trim() == item.Tool_Size.Trim() && item2.Order_Size.Trim() == item.Order_Size.Trim())
                            {
                                packingItem.OutQty = item2.OutQty;
                            }
                        }
                    }
                    else
                    {
                        packingItem.OutQty = 0;
                    }
                    packingListDetailModel.Add(packingItem);
                }
                packingListDetailModel = packingListDetailModel.OrderBy(x => x.Tool_Size).ThenBy(x => x.Order_Size).ToList();
                // List các Tool Size mà có nhiều Order Size trong bảng Packing List Detail
                var toolSizeMoreOrderSize = packingListDetailModel.Where(x => x.Tool_Size.Trim() != x.Order_Size.Trim()).Select(x => x.Tool_Size).Distinct().ToList();
                if (toolSizeMoreOrderSize.Count() > 0)
                {
                    foreach (var itemToolSize in toolSizeMoreOrderSize)
                    {
                        var model1 = packingListDetailModel.Where(x => x.Tool_Size.Trim() == itemToolSize.Trim())
                                     .GroupBy(x => x.Tool_Size).Select(x => new
                        {
                            Purchase_Qty = x.Sum(cl => cl.Purchase_Qty),
                            Received_Qty = x.Sum(cl => cl.Received_Qty),
                            Act          = x.Sum(cl => cl.Act),
                            Bal          = x.Sum(cl => cl.Bal),
                            OutQty       = x.Sum(cl => cl.OutQty)
                        }).FirstOrDefault();
                        var packingListByToolSize = packingListDetailModel
                                                    .Where(x => x.Tool_Size.Trim() == itemToolSize.Trim()).ToList();
                        for (var i = 0; i < packingListByToolSize.Count; i++)
                        {
                            if (i != 0)
                            {
                                packingListByToolSize[i].Purchase_Qty = null;
                                packingListByToolSize[i].Received_Qty = null;
                                packingListByToolSize[i].Act          = null;
                                packingListByToolSize[i].Bal          = null;
                                packingListByToolSize[i].OutQty       = null;
                            }
                            else
                            {
                                packingListByToolSize[i].Purchase_Qty = model1.Purchase_Qty;
                                packingListByToolSize[i].Received_Qty = model1.Received_Qty;
                                packingListByToolSize[i].Act          = model1.Act;
                                packingListByToolSize[i].Bal          = model1.Bal;
                                packingListByToolSize[i].OutQty       = model1.OutQty;
                            }
                        }
                    }
                }

                OutputPrintQrCode_Dto result = new OutputPrintQrCode_Dto
                {
                    QrCodeModel       = qrCodeModel,
                    PackingListDetail = packingListDetailModel,
                    RackLocation      = transactionMainTypeR.Rack_Location
                };
                listResult.Add(result);
            }
            return(listResult);
        }
Exemplo n.º 5
0
        // ---Phần in QrCodeId khi vào Menu 2.QrGenerate => Print (Material Form)-------//
        public async Task <object> FindByQrCodeID(QrCodeIDVersion data)
        {
            var qrCodeMan = _repoQrcode.FindSingle(x => x.QRCode_ID.Trim() == data.QRCode_ID.Trim() &&
                                                   x.QRCode_Version == data.QRCode_Version);

            // Tìm kiếm Purchase và Sheet_Type của qrcodeid với version đó.
            var packingListFind = _repoPackingList.FindSingle(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim());
            // Tìm List ReceiveNo tương ứng với Purchase và Sheet_Type ở trên
            var ReceiveNoList = await _repoPackingList.FindAll(x =>
                                                               x.Purchase_No.Trim() == packingListFind.Purchase_No.Trim() &&
                                                               x.Material_ID.Trim() == packingListFind.Material_ID.Trim() &&
                                                               x.Sheet_Type.Trim() == packingListFind.Sheet_Type.Trim() &&
                                                               x.MO_Seq == packingListFind.MO_Seq &&
                                                               x.MO_No.Trim() == data.MO_No.Trim() &&
                                                               x.Receive_Date <= packingListFind.Receive_Date)
                                .Select(x => x.Receive_No).ToListAsync();

            var packingDetailList = new List <WMSB_PackingList_Detail>();

            foreach (var item in ReceiveNoList)
            {
                var packingdetailitem = await _repoPackingListDetail.FindAll(x => x.Receive_No.Trim() == item.Trim()).ToListAsync();

                packingDetailList.AddRange(packingdetailitem);
            }

            // Gộp theo từng tool size và tính tổng Purchase, Received Qty theo tool size đó.
            var BalByToolSize = packingDetailList.GroupBy(x => x.Tool_Size).Select(x => new {
                Tool_Size = x.FirstOrDefault().Tool_Size,
                Bal       = x.Sum(cl => cl.Purchase_Qty) / (ReceiveNoList.Count()) - x.Sum(cl => cl.Received_Qty)
            });

            var     packingListDetailModel  = new List <PackingListDetailViewModel>();
            var     packingListDetailModel1 = new List <PackingListDetailViewModel>();
            var     packingListDetailModel2 = new List <PackingListDetailViewModel>();
            var     packingListDetailModel3 = new List <PackingListDetailViewModel>();
            decimal?totalPQty = 0;
            decimal?totalRQty = 0;

            var lists = await _repoPackingListDetail.FindAll(x => x.Receive_No.Trim() == qrCodeMan.Receive_No.Trim()).ToListAsync();

            foreach (var item in lists)
            {
                var packingItem1 = new PackingListDetailViewModel();
                packingItem1.Receive_No   = item.Receive_No;
                packingItem1.Order_Size   = item.Order_Size;
                packingItem1.Model_Size   = item.Model_Size;
                packingItem1.Tool_Size    = item.Tool_Size;
                packingItem1.Spec_Size    = item.Spec_Size;
                packingItem1.MO_Qty       = item.MO_Qty;
                packingItem1.Purchase_Qty = item.Purchase_Qty;
                packingItem1.Received_Qty = item.Received_Qty;
                packingItem1.Act          = 0;
                foreach (var itemByToolSize in BalByToolSize)
                {
                    if (itemByToolSize.Tool_Size.Trim() == item.Tool_Size.Trim())
                    {
                        packingItem1.Bal = itemByToolSize.Bal;
                    }
                }
                totalPQty = totalPQty + item.Purchase_Qty;
                totalRQty = totalRQty + item.Received_Qty;
                packingListDetailModel.Add(packingItem1);
            }

            //----------------- Xử lý mảng dữ liệu cho 1 số dòng cùng tool size.----------------//
            // List các Tool Size mà có nhiều Order Size trong bảng Packing List Detail
            var toolSizeMoreOrderSize = lists.Where(x => x.Tool_Size.Trim() != x.Order_Size.Trim()).Select(x => x.Tool_Size).Distinct().ToList();

            if (toolSizeMoreOrderSize.Count() > 0)
            {
                foreach (var itemToolSize in toolSizeMoreOrderSize)
                {
                    var model1 = packingListDetailModel.Where(x => x.Tool_Size.Trim() == itemToolSize.Trim())
                                 .GroupBy(x => x.Tool_Size).Select(x => new {
                        Purchase_Qty = x.Sum(cl => cl.Purchase_Qty),
                        Received_Qty = x.Sum(cl => cl.Received_Qty),
                        Act          = x.Sum(cl => cl.Act),
                        Bal          = x.First().Bal
                    }).FirstOrDefault();
                    var packingDetailByToolSize = packingListDetailModel
                                                  .Where(x => x.Tool_Size.Trim() == itemToolSize.Trim()).ToList();
                    for (var i = 0; i < packingDetailByToolSize.Count; i++)
                    {
                        if (i != 0)
                        {
                            packingDetailByToolSize[i].Purchase_Qty = null;
                            packingDetailByToolSize[i].Received_Qty = null;
                            packingDetailByToolSize[i].Act          = null;
                            packingDetailByToolSize[i].Bal          = null;
                        }
                        else
                        {
                            packingDetailByToolSize[i].Purchase_Qty = model1.Purchase_Qty;
                            packingDetailByToolSize[i].Received_Qty = model1.Received_Qty;
                            packingDetailByToolSize[i].Act          = model1.Act;
                            packingDetailByToolSize[i].Bal          = model1.Bal;
                        }
                    }
                }
            }

            // Sắp xếp lại theo Tool-Size và Order_Size theo thứ tự tăng dần.
            packingListDetailModel = packingListDetailModel
                                     .OrderBy(x => decimal.Parse(x.Tool_Size)).ThenBy(x => decimal.Parse(x.Order_Size)).ToList();

            var count = packingListDetailModel.Count();

            if (count > 0 && count <= 8)
            {
                packingListDetailModel1 = packingListDetailModel;
            }
            else if (count > 8 && count <= 16)
            {
                for (int i = 0; i < 8; i++)
                {
                    packingListDetailModel1.Add(packingListDetailModel[i]);
                }
                for (int i = 8; i < count; i++)
                {
                    packingListDetailModel2.Add(packingListDetailModel[i]);
                }
            }
            else if (count > 16)
            {
                for (int i = 0; i < 8; i++)
                {
                    packingListDetailModel1.Add(packingListDetailModel[i]);
                }
                for (int i = 8; i < 16; i++)
                {
                    packingListDetailModel2.Add(packingListDetailModel[i]);
                }
                for (int i = 16; i < count; i++)
                {
                    packingListDetailModel3.Add(packingListDetailModel[i]);
                }
            }

            var result = new {
                totalPQty,
                totalRQty,
                packingListDetailModel1,
                packingListDetailModel2,
                packingListDetailModel3,
            };

            return(result);
        }