Exemplo n.º 1
0
        public async Task<bool> SubmitInput(InputSubmitModel data, string updateBy)
        {
            foreach (var item in data.TransactionList)
            {
                await CreateInput(item, updateBy);
            }

            var lists = data.InputNoList;
            if (lists.Count > 0)
            {
                string Transac_Sheet_No;
                do
                {
                    string num = CodeUtility.RandomNumber(3);
                    Transac_Sheet_No = "IB" + DateTime.Now.ToString("yyyyMMdd") + num;
                } while (await _repoTransactionMain.CheckTranSheetNo(Transac_Sheet_No));

                foreach (var item in lists)
                {
                    string Missing_No;
                    do
                    {
                        // Để Mising No khác nhau 
                        string num2 = CodeUtility.RandomNumber(3);
                        Missing_No = "BTM" + DateTime.Now.ToString("yyyyMMdd") + num2;
                    } while (await this.CheckMissingMo(Missing_No));

                    WMSB_Transaction_Main model = await _repoTransactionMain.GetByInputNo(item);
                    model.Can_Move = "Y";
                    model.Transac_Sheet_No = Transac_Sheet_No;
                    model.Is_Transfer_Form = "N";
                    model.Updated_By = updateBy;
                    model.Updated_Time = DateTime.Now;
                    if (model.Purchase_Qty > model.Transacted_Qty)
                    {
                        model.Missing_No = Missing_No;

                        //Tạo mới record và update status record cũ trong bảng QRCode_Main và QRCode_Detail
                        GenerateNewQrCode(model.QRCode_ID, model.QRCode_Version, item, updateBy);

                        //Update QrCode Version cho bảng Transaction_Main
                        model.QRCode_Version += 1;

                        // Tạo mới record trong bảng Missing
                        CreateMissing(model.Purchase_No, model.MO_No, model.MO_Seq, model.Material_ID, model.Transac_No, model.Missing_No, updateBy);
                    }
                    else
                    {
                        WMSB_QRCode_Main qrModel = await _repoQRCodeMain.GetByQRCodeID(model.QRCode_ID);
                        qrModel.Is_Scanned = "Y";
                        _repoQRCodeMain.Update(qrModel);
                    }

                    _repoTransactionMain.Update(model);
                }
                return await _repoTransactionMain.SaveAll();
            }
            return false;
        }
Exemplo n.º 2
0
        public async Task <bool> GenerateTransferForm(List <Transfer_Form_Generate_Dto> generateTransferForm, string updateBy)
        {
            DateTime timeNow = DateTime.Now;
            var      generateTransferFormGroupBy = generateTransferForm.GroupBy(x => new { x.MO_No, x.MO_Seq, x.Material_ID });

            foreach (var itemGroup in generateTransferFormGroupBy)
            {
                string collectTransNo;
                do
                {
                    string num = CodeUtility.RandomNumber(3);
                    // Mã xưởng+T+mã nhà cc T3+yymmdd(ngày mà sản sinh ra mã chuyển giao)+3 số random
                    // VD: CTV057200922001
                    // Nếu T3 là = null: Mã xưởng+T+ZZZZ+yymmdd(ngày mà sản sinh ra mã chuyển giao)+3 số random
                    var t3_Supplier = itemGroup.FirstOrDefault().T3_Supplier.Trim() == "" ? "ZZZZ" : itemGroup.FirstOrDefault().T3_Supplier.Trim();
                    collectTransNo = itemGroup.FirstOrDefault().Factory_ID.Trim() + "T" + t3_Supplier + DateTime.Now.ToString("yyyyMMdd") + num;
                } while (await _transferFormRepository.CheckCollectTransNo(collectTransNo));
                foreach (var item in itemGroup.ToList())
                {
                    WMSB_Transfer_Form transferForm = new WMSB_Transfer_Form();
                    transferForm.Collect_Trans_No = collectTransNo;
                    transferForm.Transac_No       = item.Transac_No;
                    transferForm.Generate_Time    = timeNow;
                    transferForm.T3_Supplier      = item.T3_Supplier;
                    transferForm.T3_Supplier_Name = item.T3_Supplier_Name;
                    transferForm.Is_Release       = "N";
                    transferForm.Release_By       = null;
                    transferForm.Release_Time     = null;
                    transferForm.Update_By        = updateBy;
                    transferForm.Update_Time      = timeNow;
                    transferForm.MO_No            = item.MO_No;
                    transferForm.MO_Seq           = item.MO_Seq;
                    transferForm.Material_ID      = item.Material_ID;
                    transferForm.Material_Name    = item.Material_Name;

                    _transferFormRepository.Add(transferForm);

                    var transactionMain = _transactionMainRepo.FindSingle(x => x.Transac_No.Trim() == item.Transac_No.Trim());
                    transactionMain.Is_Transfer_Form = "Y";

                    _transactionMainRepo.Update(transactionMain);
                }
                await _transferFormRepository.SaveAll();
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task<bool> IntegrationInputSubmit(List<IntegrationInputModel> data, string user)
        {
            data = data.Where(x => !string.IsNullOrEmpty(x.Rack_Location)).ToList();
            foreach (var item in data)
            {
                // Update Table WMSB_QRCode_Main
                var qrCodeModels = await _repoQRCodeMain.FindAll(x => x.QRCode_ID.Trim() == item.QRCode_ID.Trim() &&
                                                    x.Is_Scanned.Trim() == "N" &&
                                                    x.Receive_No.Trim() == item.Receive_No.Trim()).FirstOrDefaultAsync();
                if (qrCodeModels != null)
                {
                    qrCodeModels.Is_Scanned = "Y";
                }


                //---------------------------- Check TransactionMain-------------------------------//
                var transationMainCheck = await _repoTransactionMain.FindAll(x => x.QRCode_ID.Trim() == item.QRCode_ID.Trim() &&
                                                x.MO_No.Trim() == item.MO_No.Trim() &&
                                                x.Purchase_No.Trim() == item.Purchase_No.Trim() &&
                                                x.Material_ID.Trim() == item.Material_ID.Trim()).FirstOrDefaultAsync();
                if (transationMainCheck == null)
                {
                    string Transac_Sheet_No, Transac_No;
                    do
                    {
                        string num = CodeUtility.RandomNumber(3);
                        Transac_Sheet_No = "IB" + DateTime.Now.ToString("yyyyMMdd") + num;
                    } while (await _repoTransactionMain.CheckTranSheetNo(Transac_Sheet_No));
                    do
                    {
                        string num1 = CodeUtility.RandomNumber(3);
                        Transac_No = "IB" + item.MO_No.Trim() + num1;
                    } while (await _repoTransactionMain.CheckTransacNo(Transac_No));

                    // Tạo New Model để Add vào Table WMSB_Transaction_Main
                    var transactionMainModel = new WMSB_Transaction_Main();
                    transactionMainModel.Transac_Type = "I";
                    transactionMainModel.Transac_No = Transac_No;
                    transactionMainModel.Transac_Sheet_No = Transac_Sheet_No;
                    transactionMainModel.Can_Move = "Y";
                    transactionMainModel.Transac_Time = DateTime.Now;
                    transactionMainModel.QRCode_ID = item.QRCode_ID;
                    transactionMainModel.QRCode_Version = item.QRCode_Version;
                    transactionMainModel.MO_No = item.MO_No.Trim();
                    transactionMainModel.Purchase_No = item.Purchase_No.Trim();
                    transactionMainModel.MO_Seq = item.MO_Seq;
                    transactionMainModel.Material_ID = item.Material_ID.Trim();
                    transactionMainModel.Material_Name = item.Material_Name.Trim();
                    transactionMainModel.Purchase_Qty = item.Receive_Qty;
                    transactionMainModel.Transacted_Qty = item.Receive_Qty;
                    transactionMainModel.Rack_Location = item.Rack_Location;
                    transactionMainModel.Is_Transfer_Form = "N";
                    transactionMainModel.Updated_Time = DateTime.Now;
                    transactionMainModel.Updated_By = user;
                    _repoTransactionMain.Add(transactionMainModel);

                    // Add vào table WMSB_Transaction_Detail             
                    foreach (var item1 in item.PackingListDetailItem)
                    {
                        var transactionDetailModel = new WMSB_Transaction_Detail();
                        transactionDetailModel.Transac_No = Transac_No.Trim();
                        transactionDetailModel.Tool_Size = item1.Tool_Size;
                        transactionDetailModel.Order_Size = item1.Order_Size;
                        transactionDetailModel.Model_Size = item1.Model_Size;
                        transactionDetailModel.Spec_Size = item1.Spec_Size;
                        transactionDetailModel.Qty = item1.Received_Qty;
                        transactionDetailModel.Trans_Qty = item1.Received_Qty;
                        transactionDetailModel.Instock_Qty = item1.Received_Qty;
                        transactionDetailModel.Untransac_Qty = 0;
                        transactionDetailModel.Updated_Time = DateTime.Now;
                        transactionDetailModel.Updated_By = user;
                        _repoTransactionDetail.Add(transactionDetailModel);
                    }
                }
            }
            return await _repoTransactionDetail.SaveAll();
        }
Exemplo n.º 4
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.º 5
0
        public async Task <bool> SaveListOutput(List <OutputParam> outputParam, string updateBy)
        {
            DateTime timeNow = DateTime.Now;
            string   outputSheetNo;

            do
            {
                string num = CodeUtility.RandomNumber(3);
                outputSheetNo = "OB" + DateTime.Now.ToString("yyyyMMdd") + num;// OB + 20200421 + 001
            } while (await _repoTransactionMain.CheckTranSheetNo(outputSheetNo));

            foreach (var itemt in outputParam)
            {
                // Tìm ra TransactionMain theo id
                var transactionMain = _repoTransactionMain.FindSingle(x => x.ID == itemt.output.Id);
                transactionMain.Can_Move = "N"; // update transaction main cũ: Can_Move thành N
                _repoTransactionMain.Update(transactionMain);

                // thêm transaction main type O
                WMSB_Transaction_Main modelTypeO = new WMSB_Transaction_Main();
                modelTypeO.Transac_Type = "O";
                modelTypeO.Can_Move     = "N";
                // modelTypeO.Is_Transfer_Form = "N";
                modelTypeO.Transac_No       = itemt.output.TransacNo;
                modelTypeO.Transac_Sheet_No = outputSheetNo;
                modelTypeO.Transacted_Qty   = itemt.output.TransOutQty;
                modelTypeO.Pickup_No        = itemt.output.PickupNo;
                modelTypeO.Transac_Time     = timeNow;
                modelTypeO.Updated_Time     = timeNow;
                modelTypeO.Updated_By       = updateBy;
                modelTypeO.Missing_No       = transactionMain.Missing_No;
                modelTypeO.Material_ID      = transactionMain.Material_ID;
                modelTypeO.Material_Name    = transactionMain.Material_Name;
                modelTypeO.Purchase_No      = transactionMain.Purchase_No;
                modelTypeO.Rack_Location    = null;// type O: racklocation rỗng
                modelTypeO.Purchase_Qty     = transactionMain.Purchase_Qty;
                modelTypeO.QRCode_Version   = transactionMain.QRCode_Version;
                modelTypeO.QRCode_ID        = transactionMain.QRCode_ID;
                modelTypeO.MO_No            = transactionMain.MO_No;
                modelTypeO.MO_Seq           = transactionMain.MO_Seq;
                _repoTransactionMain.Add(modelTypeO);

                // Thêm transaction detail mới theo type = o, dựa vào transaction detail của transaction main cũ
                foreach (var item in itemt.transactionDetail)
                {
                    item.ID           = 0;// ID trong db là tự tăng: dựa vào transaction detail cũ nên thêm mới gán id bằng 0, không cần phải new hết thuộc tính của đổi tượng ra
                    item.Transac_No   = itemt.output.TransacNo;
                    item.Updated_By   = updateBy;
                    item.Updated_Time = timeNow;
                    var itemModel = _mapper.Map <WMSB_Transaction_Detail>(item);
                    _repoTransactionDetail.Add(itemModel);
                }

                // Nếu output ra chưa hết thì thêm transaction main type R, và transaction detail, thêm qrcode mới và update version lên
                if (itemt.output.RemainingQty > 0)
                {
                    //  thêm type R
                    var tmpQrcodeVersion             = transactionMain.QRCode_Version + 1;
                    WMSB_Transaction_Main modelTypeR = new WMSB_Transaction_Main();
                    modelTypeR.Transac_Type     = "R";
                    modelTypeR.Transac_No       = "R" + transactionMain.Transac_No;
                    modelTypeR.Transac_Sheet_No = "R" + transactionMain.Transac_Sheet_No;
                    modelTypeR.Transacted_Qty   = itemt.output.TransOutQty;
                    modelTypeR.Updated_By       = updateBy;
                    modelTypeR.Updated_Time     = timeNow;
                    modelTypeR.Missing_No       = transactionMain.Missing_No;
                    modelTypeR.Material_ID      = transactionMain.Material_ID;
                    modelTypeR.Material_Name    = transactionMain.Material_Name;
                    modelTypeR.Purchase_No      = transactionMain.Purchase_No;
                    modelTypeR.Rack_Location    = transactionMain.Rack_Location;
                    modelTypeR.Purchase_Qty     = transactionMain.Purchase_Qty;
                    modelTypeR.QRCode_Version   = tmpQrcodeVersion;
                    modelTypeR.QRCode_ID        = transactionMain.QRCode_ID;
                    modelTypeR.MO_No            = transactionMain.MO_No;
                    modelTypeR.MO_Seq           = transactionMain.MO_Seq;
                    modelTypeR.Can_Move         = "Y";
                    // modelTypeR.Is_Transfer_Form = "N";
                    modelTypeR.Transac_Time = timeNow;
                    _repoTransactionMain.Add(modelTypeR);

                    // thêm transaction main cũng phải thêm transaction detail
                    foreach (var itemTypeR in itemt.transactionDetail)
                    {
                        itemTypeR.ID           = 0;// ID trong db là tự tăng: dựa vào transaction detail cũ nên thêm mới gán id bằng 0, không cần phải new hết thuộc tính của đổi tượng ra
                        itemTypeR.Transac_No   = modelTypeR.Transac_No;
                        itemTypeR.Updated_By   = updateBy;
                        itemTypeR.Updated_Time = timeNow;
                        itemTypeR.Qty          = itemTypeR.Instock_Qty;
                        itemTypeR.Trans_Qty    = itemTypeR.Instock_Qty;
                        var itemModel = _mapper.Map <WMSB_Transaction_Detail>(itemTypeR);
                        _repoTransactionDetail.Add(itemModel);
                    }

                    // thêm qrcode mới, nếu output ra chưa hết thì thêm qrcode main mới dựa vào cái cũ và update version lên
                    var qrCodeMain = await _repoQRCodeMain.FindAll(x => x.QRCode_ID.Trim() == itemt.output.QrCodeId.Trim()).OrderByDescending(x => x.QRCode_Version).FirstOrDefaultAsync();

                    WMSB_QRCode_Main modelQrCodeMain = new WMSB_QRCode_Main();
                    modelQrCodeMain.QRCode_ID      = qrCodeMain.QRCode_ID;
                    modelQrCodeMain.QRCode_Type    = qrCodeMain.QRCode_Type;
                    modelQrCodeMain.Receive_No     = qrCodeMain.Receive_No;
                    modelQrCodeMain.Valid_Status   = "Y";
                    modelQrCodeMain.Is_Scanned     = "Y";
                    modelQrCodeMain.Invalid_Date   = qrCodeMain.Invalid_Date;
                    modelQrCodeMain.QRCode_Version = qrCodeMain.QRCode_Version + 1;
                    modelQrCodeMain.Updated_Time   = timeNow;
                    modelQrCodeMain.Updated_By     = updateBy;
                    _repoQRCodeMain.Add(modelQrCodeMain);

                    // Update cho QRCode cũ, Valid_Status =N, Invalid_Date = Ngày mà tạo ra version mới
                    qrCodeMain.Valid_Status = "N";
                    qrCodeMain.Invalid_Date = timeNow;
                    _repoQRCodeMain.Update(qrCodeMain);

                    // thêm qrcodedetail của qrcode mới: thêm qrcode main cũng phải thêm qrcode detail
                    var qrCodeDetails = await _repoQRCodeDetail.FindAll(x => x.QRCode_ID.Trim() == qrCodeMain.QRCode_ID.Trim() && x.QRCode_Version == qrCodeMain.QRCode_Version).ToListAsync();

                    foreach (var itemQrCodeDetail in qrCodeDetails)
                    {
                        itemQrCodeDetail.QID            = 0;
                        itemQrCodeDetail.Updated_By     = updateBy;
                        itemQrCodeDetail.Updated_Time   = timeNow;
                        itemQrCodeDetail.QRCode_Version = modelQrCodeMain.QRCode_Version;
                        itemQrCodeDetail.Qty            = itemt.transactionDetail.Where(x => x.Tool_Size == itemQrCodeDetail.Tool_Size && x.Order_Size == itemQrCodeDetail.Order_Size && x.Model_Size == itemQrCodeDetail.Model_Size).FirstOrDefault().Instock_Qty;
                        _repoQRCodeDetail.Add(itemQrCodeDetail);
                    }
                }
                // Nếu QRCode đã out hết số lượng, cần update cho nó không còn hiệu lực
                // ( Ở bảng WMSB_QRCode_Main: UPDATE trường Valid_Status =’N”, Invalid_Date là ngày Output hết số lượng,
                // đồng thời cũng update trường Update_Time & Update_By)
                else
                {
                    var qrCodeMain = await _repoQRCodeMain.FindAll(x => x.QRCode_ID.Trim() == itemt.output.QrCodeId.Trim()).OrderByDescending(x => x.QRCode_Version).FirstOrDefaultAsync();

                    qrCodeMain.Valid_Status = "N";
                    qrCodeMain.Invalid_Date = timeNow;
                    qrCodeMain.Updated_Time = timeNow;
                    qrCodeMain.Updated_By   = updateBy;
                    _repoQRCodeMain.Update(qrCodeMain);
                }
            }

            // lưu Db
            return(await _repoTransactionMain.SaveAll());
        }