public async Task<IdResponse> WarehouseReceiptAddGrn(WarehouseReceiptAddGRNCommand addGrn) { var c = Config.Init(); IWarehouseReceiptClient wrc = WarehouseReceiptClientFactory.Create(c.WREndPoint, c.VAOKey); var newGrn = await wrc.WarehouseReceiptClient.AddGrn(addGrn, EAGCLoginDetails.TokenId,true); if (newGrn != null) { return newGrn; } return null; }
private async void GenerateReceipt() { if (string.IsNullOrEmpty(EAGCLoginDetails.TokenId)) { Login(); using (var c = NestedContainer) { var depositor = await Using<IEagcServiceProxy>(c).GetCommodityOwnerById(SelectedCommodityOwner.Id.ToString()); if (depositor.Result != null) { //Get CommodityOwner CommodityOwnerId = depositor.Result.Id; //Get Warehouse var warehouse = await Using<IEagcServiceProxy>(c).GetWarehouseByExtKey( SelectedCommoditySupplier.ParentCostCentre.Id.ToString()); if (warehouse.Result.Id == null) { MessageBox.Show("Warehouse Not Found!", "Trading Platform", MessageBoxButton.OKCancel, MessageBoxImage.Error); LoadUnassignedGrn(SelectedCommoditySupplier.Id); return; } DocumentReceipientCostCentre = SelectedCommoditySupplier; var selectedCrns = UnassignedWarehouseGrnListItem.Where(p => p.IsSelected); var grnDtoList = new List<GRNDto>(); foreach (var item in selectedCrns) { var grnLineItemsDto = new List<GRNDto.GRNLineItem>(); var availableCom = await Using<IEagcServiceProxy>(c).GetCommodityByExternalKey(item.CommodityId); if (availableCom.Result != null) { grnLineItemsDto.Add(await MapLineItem(item)); if (CommodityId == null) { return; } } else { MessageBox.Show("Commodity Not Found!", "Trading Platform", MessageBoxButton.OKCancel, MessageBoxImage.Error); LoadUnassignedGrn(SelectedCommoditySupplier.Id); return; } grnDtoList.Add(MapGrnDto(item, grnLineItemsDto)); } //Create Receipt if (string.IsNullOrEmpty(EAGCLoginDetails.TokenId)) { Login(); } else { var wRDto = new WarehouseReceiptCreateNewCommand(CommodityOwnerId, warehouse.Result.Id); if (wRDto != null) { var newWr = await Using<IEagcServiceProxy>(c).CreateNewWr(wRDto); if (newWr.Result.Id == null) { MessageBox.Show("Warehouse Receipt Creation Failed !", "Trading Platform", MessageBoxButton.OKCancel, MessageBoxImage.Error); LoadUnassignedGrn(SelectedCommoditySupplier.Id); return; } } } //Add GRNs to Warehouse Receipt string newReceiptNo; foreach (var grnDto in grnDtoList) { try { var response1 = new ResponseBool(); if (EAGCLoginDetails.WrId != null) { string receiptNo = grnDto.ReceiptNo; if (receiptNo.Length >= 50) { int toCut = receiptNo.Length - 50; newReceiptNo = receiptNo.Substring(0, receiptNo.Length - toCut); } else { newReceiptNo = receiptNo; } var grns = new WarehouseReceiptAddGRNCommand(EAGCLoginDetails.WrId, new GRNDto(newReceiptNo, grnDto.ReceiptDate, grnDto.LineItems)); var grnCreation = await Using<IEagcServiceProxy>(c).WarehouseReceiptAddGrn(grns); if (grnCreation.Result.Id == null) { MessageBox.Show("GRN Addition Failed !", "Trading Platform", MessageBoxButton.OKCancel, MessageBoxImage.Error); LoadUnassignedGrn(SelectedCommoditySupplier.Id); return; } } response1.Success = true; if (response1.Success) { } } catch (Exception ex) { } } //Update as Receipt Generated var warehouseWfManager = Using<ICommodityWarehouseStorageWFManager>(c); var selectedCrnsId = selectedCrns.Select(p => p.DocumentId).ToList(); foreach (var crnId in selectedCrnsId) { var document = Using<ICommodityWarehouseStorageRepository>(c).GetById(crnId) as CommodityWarehouseStorageNote; if (document != null) { document.GenerateReceipt(); warehouseWfManager.SubmitChanges(document); } } MessageBox.Show("Warehouse Receipt Successfully Created!", "Trading Platform", MessageBoxButton.OK, MessageBoxImage.Information); AssignedWarehouseGrnListItem.Clear(); LoadUnassignedGrn(Guid.Empty); UnassignedWarehouseGrnListItem.Clear(); SelectedCommoditySupplierName = "--Select Account---"; // AddLogEntry("Warehouse Receipt Creation", "Created warehouse Receipt " + DocumentReference); } else { MessageBox.Show("Commodity Owner Not Found!", "Trading Platform", MessageBoxButton.OKCancel, MessageBoxImage.Error); LoadUnassignedGrn(SelectedCommoditySupplier.Id); return; } } return; } }