Exemplo n.º 1
0
        public async Task <bool> Add(Packing_List_Detail_Dto model)
        {
            var data = _mapper.Map <WMSB_PackingList_Detail>(model);

            _repoPackingListDetail.Add(data);
            return(await _repoPackingListDetail.SaveAll());
        }
Exemplo n.º 2
0
        public async Task <List <ReceiveAfterSubmit> > SubmitData(List <ReceivingMaterialMainModel> data, string updateBy)
        {
            var receiveAfterSubmit = new List <ReceiveAfterSubmit>();

            foreach (var itemData in data)
            {
                // Update ở bảng WMSB_Material_Purchase
                var materialPurchaseByPurchase = await _repoPurchase.FindAll(x => x.Biz_Tflag.Trim() != "D" &&
                                                                             (x.MO_Qty != 0 || x.Purchase_Qty != 0) &&
                                                                             x.Purchase_No.Trim() == itemData.Purchase_No.Trim() &&
                                                                             x.MO_No.Trim() == itemData.MO_No.Trim() &&
                                                                             x.Material_ID.Trim() == itemData.Material_ID.Trim()).ToListAsync();

                materialPurchaseByPurchase.ForEach(item => {
                    item.Status            = "Y";
                    item.Accumlated_In_Qty = item.Purchase_Qty;
                });

                // Tính toán có bao nhiêu batch
                var countBath = materialPurchaseByPurchase.Select(x => x.MO_Seq).ToList();
                countBath = countBath.Distinct().ToList();
                if (countBath.Count > 0)
                {
                    foreach (var itemBatch in countBath)
                    {
                        //Thêm ở bảng PackingList
                        var packingListModel = new WMSB_Packing_List();
                        packingListModel.Sheet_Type       = "B";
                        packingListModel.Missing_No       = "";
                        packingListModel.Delivery_No      = "";
                        packingListModel.Supplier_ID      = itemData.Supplier_ID;
                        packingListModel.Supplier_Name    = itemData.Supplier_Name;
                        packingListModel.Receive_Date     = DateTime.Now;
                        packingListModel.MO_No            = itemData.MO_No;
                        packingListModel.Purchase_No      = itemData.Purchase_No;
                        packingListModel.MO_Seq           = itemBatch;
                        packingListModel.Receive_No       = CodeUtility.RandomReceiveNo("RW", 2);
                        packingListModel.Material_ID      = itemData.Material_ID;
                        packingListModel.Material_Name    = itemData.Material_Name;
                        packingListModel.Article          = itemData.Article;
                        packingListModel.Model_No         = itemData.Model_No;
                        packingListModel.Model_Name       = itemData.Model_Name;
                        packingListModel.Subcon_ID        = itemData.Subcon_No;
                        packingListModel.Subcon_Name      = itemData.Subcon_Name;
                        packingListModel.T3_Supplier      = itemData.T3_Supplier;
                        packingListModel.T3_Supplier_Name = itemData.T3_Supplier_Name;
                        packingListModel.Generated_QRCode = "N";
                        packingListModel.Updated_Time     = DateTime.Now;
                        packingListModel.Updated_By       = updateBy;
                        _repoPackingList.Add(packingListModel);

                        // Tạo ra record để show ngoài màn hình sau khi submit
                        var receiveAfterSubmitItem = new ReceiveAfterSubmit();
                        var sumAccumlatedQty       = materialPurchaseByPurchase
                                                     .Where(x => x.MO_Seq == itemBatch).Sum(x => x.Purchase_Qty);
                        receiveAfterSubmitItem.MO_No         = packingListModel.MO_No;
                        receiveAfterSubmitItem.Purchase_No   = packingListModel.Purchase_No;
                        receiveAfterSubmitItem.Receive_No    = packingListModel.Receive_No;
                        receiveAfterSubmitItem.MO_Seq        = itemBatch;
                        receiveAfterSubmitItem.Material_ID   = packingListModel.Material_ID;
                        receiveAfterSubmitItem.Material_Name = packingListModel.Material_Name;
                        receiveAfterSubmitItem.Receive_Time  = packingListModel.Receive_Date;
                        receiveAfterSubmitItem.Purchase_Qty  = sumAccumlatedQty;
                        receiveAfterSubmitItem.Type          = "R";
                        receiveAfterSubmitItem.Update_By     = packingListModel.Updated_By;
                        receiveAfterSubmit.Add(receiveAfterSubmitItem);

                        // Thêm ở bảng PackingListDetail
                        var materialPurchaseForBatchs = materialPurchaseByPurchase.Where(x => x.MO_Seq == itemBatch).ToList();
                        foreach (var materialForBatchItem in materialPurchaseForBatchs)
                        {
                            var packingListDetailModel = new WMSB_PackingList_Detail();
                            packingListDetailModel.Receive_No   = packingListModel.Receive_No;
                            packingListDetailModel.Order_Size   = materialForBatchItem.Order_Size;
                            packingListDetailModel.Model_Size   = materialForBatchItem.Model_Size;
                            packingListDetailModel.Tool_Size    = materialForBatchItem.Tool_Size;
                            packingListDetailModel.Spec_Size    = materialForBatchItem.Spec_Size;
                            packingListDetailModel.MO_Qty       = materialForBatchItem.MO_Qty;
                            packingListDetailModel.Purchase_Qty = materialForBatchItem.Purchase_Qty;
                            packingListDetailModel.Received_Qty = materialForBatchItem.Purchase_Qty;
                            packingListDetailModel.Updated_Time = DateTime.Now;
                            packingListDetailModel.Updated_By   = updateBy;
                            _repoPackingListDetail.Add(packingListDetailModel);
                        }
                    }
                }
            }
            await _repoPackingListDetail.SaveAll();

            return(receiveAfterSubmit);
        }