Ejemplo n.º 1
0
        public async Task <bool> ClosePurchase(MaterialMainViewModel model)
        {
            if (model.Missing_No == "")
            {
                var purchaseList = await _repoPurchase.FindAll(x => x.Purchase_No.Trim() == model.Purchase_No.Trim() &&
                                                               x.MO_No.Trim() == model.MO_No.Trim() &&
                                                               x.Biz_Tflag.Trim() != "D" &&
                                                               (x.MO_Qty != 0 || x.Purchase_Qty != 0)).ToListAsync();

                foreach (var item in purchaseList)
                {
                    item.Status = "Y";
                }
                return(await _repoPurchase.SaveAll());
            }
            else
            {
                var purchaseList = await _repoMissing.FindAll(x => x.Purchase_No.Trim() == model.Purchase_No.Trim() &&
                                                              x.MO_No.Trim() == model.MO_No.Trim()).ToListAsync();

                foreach (var item in purchaseList)
                {
                    item.Status = "Y";
                }
                return(await _repoMissing.SaveAll());
            }
        }
Ejemplo n.º 2
0
        public async Task <List <ReceiveNoMain> > UpdateMaterial(List <OrderSizeByBatch> data)
        {
            var Purchase_No = data[0].Purchase_No;

            // --------------------------------------------------------------------------------------------//
            if (data[0].Missing_No == "")
            {
                // --------Update lại Accumlated_In_Qty theo Purchase_No,Order_Size và Mo_Seq ở bảng Material_Purchase----//
                foreach (var item in data)
                {
                    foreach (var item1 in item.Purchase_Qty)
                    {
                        var materialItem = await _repoPurchase.FindAll()
                                           .Where(x => x.Purchase_No.Trim() == Purchase_No.Trim() &&
                                                  x.Order_Size == item1.Order_Size &&
                                                  x.MO_Seq == item.MO_Seq).FirstOrDefaultAsync();

                        // materialItem.Accumlated_In_Qty = item1.Accumlated_In_Qty;
                        // Số lượng bằng số lượng nhận hiện tại + số lượng vừa mới nhận vào.
                        materialItem.Accumlated_In_Qty = materialItem.Accumlated_In_Qty + item1.Received_Qty;
                        await _repoPurchase.SaveAll();
                    }
                }

                //------------------------- Update giá trị Status--------------------------------------------//
                foreach (var item in data)
                {
                    await this.UpdateStatusMaterial(item.Purchase_No, item.MO_Seq, item.Missing_No);
                }
                await _repoPurchase.SaveAll();
            }
            else
            {
                // Update lại Accumlated_In_Qty theo Purchase_No,Order_Size và Mo_Seq ở bảng Material_Missing
                foreach (var item in data)
                {
                    foreach (var item1 in item.Purchase_Qty)
                    {
                        var materialItem = await _repoMissing.FindAll()
                                           .Where(x => x.Purchase_No.Trim() == Purchase_No.Trim() &&
                                                  x.Order_Size == item1.Order_Size &&
                                                  x.MO_Seq == item.MO_Seq).FirstOrDefaultAsync();

                        materialItem.Accumlated_In_Qty = item1.Accumlated_In_Qty;
                    }
                }

                // Update lại Status
                foreach (var item in data)
                {
                    await this.UpdateStatusMaterial(item.Purchase_No, item.MO_Seq, item.Missing_No);
                }

                await _repoMissing.SaveAll();
            }

            //------------------------Thêm vào 2 bảng Packing_List và Packing_List_Detail------------------//
            var ReceiveNoMain = new List <ReceiveNoMain>();

            foreach (var item in data)
            {
                // Check xem có tiến hành thêm hay ko
                var checkAdd = false;
                foreach (var item1 in item.Purchase_Qty)
                {
                    // Kiểm tra nếu tồn tại Received_Qty lớn hơn 0,có nghĩa là tồn tại 1 Order_Size trong batch đó có nhận hàng
                    if (item1.Received_Qty > 0)
                    {
                        checkAdd = true;
                        break;
                    }
                }
                // Tiến hành thêm vào bảng Packing_List và Packing_List_Detail
                if (checkAdd == true)
                {
                    var packing_List = new Packing_List_Dto();
                    if (item.Missing_No == string.Empty)
                    {
                        packing_List.Sheet_Type = "R";
                    }
                    else
                    {
                        packing_List.Sheet_Type = "M";
                    }
                    packing_List.Missing_No       = item.Missing_No;
                    packing_List.Supplier_ID      = item.Supplier_ID;
                    packing_List.Supplier_Name    = item.Supplier_Name;
                    packing_List.MO_No            = item.MO_No;
                    packing_List.Purchase_No      = item.Purchase_No;
                    packing_List.MO_Seq           = item.MO_Seq;
                    packing_List.Delivery_No      = item.Delivery_No;
                    packing_List.Material_ID      = item.Material_ID;
                    packing_List.Material_Name    = item.Material_Name;
                    packing_List.Model_No         = item.Model_No;
                    packing_List.Model_Name       = item.Model_Name;
                    packing_List.Article          = item.Article;
                    packing_List.Subcon_ID        = item.Subcon_No;
                    packing_List.Subcon_Name      = item.Subcon_Name;
                    packing_List.T3_Supplier      = item.T3_Supplier;
                    packing_List.T3_Supplier_Name = item.T3_Supplier_Name;
                    packing_List.Generated_QRCode = "N";
                    packing_List.Receive_Date     = DateTime.Now;
                    packing_List.Updated_By       = "Phi Long";
                    packing_List.Receive_No       = this.RandomString(2);

                    // Tạo ra thông tin của 1 Receive No
                    var ReceiveNoItem = new ReceiveNoMain();
                    ReceiveNoItem.MO_No         = item.MO_No;
                    ReceiveNoItem.Purchase_No   = item.Purchase_No;
                    ReceiveNoItem.Receive_No    = packing_List.Receive_No;
                    ReceiveNoItem.MO_Seq        = item.MO_Seq;
                    ReceiveNoItem.Receive_Date  = packing_List.Receive_Date;
                    ReceiveNoItem.Sheet_Type    = packing_List.Sheet_Type;
                    ReceiveNoItem.Updated_By    = packing_List.Updated_By;
                    ReceiveNoItem.Purchase_Qty  = 0;
                    ReceiveNoItem.Accumated_Qty = 0;
                    await _packingListService.Add(packing_List);

                    foreach (var item2 in item.Purchase_Qty)
                    {
                        var packing_List_detail = new Packing_List_Detail_Dto();
                        packing_List_detail.Receive_No   = packing_List.Receive_No;
                        packing_List_detail.Order_Size   = item2.Order_Size;
                        packing_List_detail.Model_Size   = item2.Model_Size;
                        packing_List_detail.Tool_Size    = item2.Tool_Size;
                        packing_List_detail.Spec_Size    = item2.Spec_Size;
                        packing_List_detail.MO_Qty       = item2.MO_Qty;
                        packing_List_detail.Purchase_Qty = item2.Purchase_Qty_Const;
                        packing_List_detail.Received_Qty = item2.Received_Qty;
                        packing_List_detail.Updated_Time = DateTime.Now;
                        packing_List_detail.Updated_By   = "Phi Long";

                        ReceiveNoItem.Purchase_Qty  = ReceiveNoItem.Purchase_Qty + item2.Purchase_Qty_Const;
                        ReceiveNoItem.Accumated_Qty = ReceiveNoItem.Accumated_Qty + item2.Received_Qty;
                        await _packingListDetailService.Add(packing_List_detail);
                    }
                    ReceiveNoMain.Add(ReceiveNoItem);
                }
            }
            return(ReceiveNoMain);
        }