| | |
| | | using MES.Service.DB; |
| | | using MES.Service.Dto.service; |
| | | using MES.Service.Modes; |
| | | using MES.Service.util; |
| | | using SqlSugar; |
| | | |
| | | namespace MES.Service.service.Warehouse; |
| | | |
| | | public class OpeningReceiptServer :RepositoryNoEntity |
| | | public class OpeningReceiptServer : RepositoryNoEntity |
| | | { |
| | | |
| | | private const string Factory = "1000"; |
| | | |
| | | private const string Company = "1000"; |
| | | |
| | | private const int billTypeId = 100; |
| | | |
| | | private const int transactionNo = 601; |
| | | |
| | | public MesInvItemBarcodes ScanInBarcodeQC(WarehouseQuery query) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(query.sectionCode)) |
| | | { |
| | | throw new Exception("请扫库位条码!"); |
| | | } |
| | | |
| | | var depotCode = GetDepotCode(query.sectionCode); |
| | | if (depotCode == null) |
| | | { |
| | | throw new Exception($"002[库位编码 {query.sectionCode} 不存在,请确认!"); |
| | | } |
| | | |
| | | int billTypeId = 100; |
| | | int transactionNo = 601; |
| | | |
| | | var checkBarcodeAlreadyReceived = |
| | | CheckBarcodeAlreadyReceived(query.barcode); |
| | | |
| | | if (checkBarcodeAlreadyReceived > 0) |
| | | { |
| | | throw new Exception("条码重复扫描,请核对!"); |
| | | } |
| | | if (checkBarcodeAlreadyReceived > 0) throw new Exception("条码重复扫描,请核对!"); |
| | | |
| | | if (CheckBarcodeInStock(query.barcode) > 0) |
| | | { |
| | | throw new Exception("条码已在库存中,请核对!"); |
| | | } |
| | | |
| | | var barcodeInfo = GetBarcodeInfo(query.barcode); |
| | | if (barcodeInfo == null || barcodeInfo.ComeFlg != 0) |
| | | { |
| | | throw new Exception("条码不是期初条码,无法用期初入库!"); |
| | | } |
| | | |
| | | var inventoryItemInId = GetOrCreateInventoryItemInId(barcodeInfo, |
| | | depotCode, query.userName, transactionNo, out string billNo); |
| | | depotCode, query.userName, out var billNo); |
| | | |
| | | UseTransaction(db => |
| | | { |
| | |
| | | return 1; |
| | | }); |
| | | |
| | | |
| | | return barcodeInfo; |
| | | } |
| | | |
| | | public PurchaseInventory GetForm(WarehouseQuery query) |
| | | { |
| | | var mesInvItemBarcodes = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(s => s.ItemBarcode == query.barcode).Count(); |
| | | |
| | | if (mesInvItemBarcodes <= 0) throw new Exception("条码不存在"); |
| | | |
| | | var mesInvItemInCDetails = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(s => s.ItemBarcode == query.barcode).Single(); |
| | | |
| | | var entity = new PurchaseInventory |
| | | { |
| | | ItemIns = GetMesInvItemIns(mesInvItemInCDetails.ItemInId), |
| | | InvItemInCDetails = |
| | | GetMesInvItemInCDetailsList(mesInvItemInCDetails.ItemInId), |
| | | ItemStocks = Db.Queryable<MesInvItemStocks>() |
| | | .Where(s => s.ItemBarcode == query.barcode).ToList() |
| | | }; |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | public MesInvItemIns GetMesInvItemIns(decimal id) |
| | | { |
| | | return Db.Queryable<MesInvItemIns>() |
| | | .Where(s => s.Id == id).Single(); |
| | | } |
| | | |
| | | public List<MesInvItemInCDetails> GetMesInvItemInCDetailsList(decimal id) |
| | | { |
| | | return Db.Queryable<MesInvItemInCDetails, MesUnit>((a, b) => |
| | | new JoinQueryInfos(JoinType.Inner, a.Unit == b.Id.ToString())) |
| | | .Where((a, b) => a.ItemInId == id) |
| | | .Select((a, b) => new MesInvItemInCDetails |
| | | { |
| | | ItemBarcode = a.ItemBarcode, |
| | | ItemNo = a.ItemNo, |
| | | ItemSname = a.ItemSname, |
| | | DepotSectionCode = a.DepotSectionCode, |
| | | Quantity = a.Quantity, |
| | | Unit = b.Fname, |
| | | Remark = a.Remark |
| | | }) |
| | | .ToList(); |
| | | } |
| | | |
| | | private void InsertInventoryDetails(decimal itemInId, string billNo, |
| | |
| | | TaskNo = barcodeInfo.TaskNo |
| | | }).ExecuteCommand(); |
| | | |
| | | if (executeCommand <= 0) |
| | | { |
| | | throw new Exception("写入失败"); |
| | | } |
| | | if (executeCommand <= 0) throw new Exception("写入失败"); |
| | | } |
| | | |
| | | private decimal GetOrCreateInventoryItemInId(MesInvItemBarcodes barcodeInfo, |
| | | string depotCode, string userName, int transactionNo, out string billNo) |
| | | string depotCode, string userName, out string billNo) |
| | | { |
| | | var inventory = Db.Queryable<MesInvItemIns>() |
| | | .Where(d => d.InsDate >= DateTime.Today && |
| | |
| | | d.SuppNo == barcodeInfo.SuppNo && |
| | | d.DepotsCode == depotCode) |
| | | .First(); |
| | | |
| | | if (inventory != null) |
| | | { |
| | | billNo = inventory.BillNo; |
| | |
| | | var executeReturnIdentity = Db.Insertable(new MesInvItemIns |
| | | { |
| | | BillNo = billNo, |
| | | BillTypeId = 100, |
| | | BillTypeId = billTypeId, |
| | | InsDate = DateTime.Now, |
| | | DepotsCode = depotCode, |
| | | TransctionNo = transactionNo.ToString(), |
| | |
| | | SuppNo = barcodeInfo.SuppNo |
| | | }).ExecuteCommand(); |
| | | |
| | | if (executeCommand <= 0) |
| | | { |
| | | throw new Exception("写入失败"); |
| | | } |
| | | if (executeCommand <= 0) throw new Exception("写入失败"); |
| | | } |
| | | |
| | | private void InsertBusinessRecord(MesInvItemBarcodes barcodeInfo, |
| | |
| | | var executeCommand = Db.Insertable(new MesInvBusiness2 |
| | | { |
| | | Status = 1, |
| | | BillTypeId = 100, |
| | | BillTypeId = billTypeId, |
| | | TransactionCode = "601", |
| | | BusinessType = 1, |
| | | ItemBarcode = barcodeInfo.ItemBarcode, |
| | |
| | | SuppNo = barcodeInfo.SuppNo |
| | | }).ExecuteCommand(); |
| | | |
| | | if (executeCommand <= 0) |
| | | { |
| | | throw new Exception("写入失败"); |
| | | } |
| | | if (executeCommand <= 0) throw new Exception("写入失败"); |
| | | } |
| | | } |