public static ResultDTO TransferPlant(DocumentTransfer transfer, bool switchWhs) { var result = new ResultDTO(); string transitWhs = String.Empty; var objectCode = BoObjectTypes.oStockTransfer; FoodPlantDAO foodPlantDAO = new FoodPlantDAO(); try { var oStockTransfer = (StockTransfer)DIApplication.Company.GetBusinessObject(objectCode); //ODRF oStockTransfer.FromWarehouse = (switchWhs) ? transfer.Document.FromWhs : transfer.Document.ToWhs; oStockTransfer.ToWarehouse = (switchWhs) ? transfer.Document.ToWhs : transfer.Document.FromWhs; oStockTransfer.UserFields.Fields.Item("U_GLO_Status").Value = "O"; foreach (var line in transfer.Lines) { oStockTransfer.Lines.ItemCode = line.Item; oStockTransfer.Lines.ItemDescription = line.Desc; oStockTransfer.Lines.Quantity = line.Quantity; oStockTransfer.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; oStockTransfer.Lines.FromWarehouseCode = (switchWhs) ? line.FromWhs : line.ToWhs; oStockTransfer.Lines.WarehouseCode = (switchWhs) ? oStockTransfer.ToWarehouse : oStockTransfer.FromWarehouse; oStockTransfer.Lines.Add(); } if (oStockTransfer.Add() != 0) { UIApplication.ShowMessageBox(string.Format("Exception: {0}", DIApplication.Company.GetLastErrorDescription())); QsLog.WriteError("TransferDI (Document) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.Success = true; result.Message = String.Format("El translado del almacen {0} al almacen {1} se realizó con éxito", oStockTransfer.FromWarehouse, oStockTransfer.ToWarehouse); } } catch (AggregateException ae) { ae.Handle(e => { HandleException(e, "TransferDI(Document)"); result.Message = "Error: " + e.Message; result.Success = false; return(true); }); } catch (Exception ex) { HandleException(ex, "TransferDI(Document)"); result.Message = "Error: " + ex.Message; result.Success = false; } return(result); }
private void CreateTransfer(bool isCancellation) { var transferDocument = new DocumentTransfer(); try { LogService.WriteInfo("Begin Create Transfer"); transferDocument.Document = pendingTransfers[selectedRow - 1]; transferDocument.Lines = transferItems; transferDocument.Series = seriesNumbers; if (!String.IsNullOrEmpty(txtComment.Value)) { transferDocument.Document.Comments = txtComment.Value; } Task.Factory.StartNew(() => { return(StockTransferDI.CreateTransfer(transferDocument, isCancellation)); }).ContinueWith(t => { if (t.Result.Success) { pendingTransfers = foodTransferDAO.GetPendingTransfers(); this.UIAPIRawForm.Freeze(true); SAPMatrix.Fill("DT0", dt0, mtx0, columns0.Keys.ToList(), pendingTransfers); this.UIAPIRawForm.Freeze(false); if (isCancellation) { AlertMessageDI.Create(new MessageDTO() { UserCode = foodTransferDAO.GetUserCode(transferDocument.Document.UserID.ToString()), Message = String.Format("Se ha rechazado la transferencia #{0} y se ha solicitado la trasnferencia de devolución #{1}", transferDocument.Document.Folio, t.Result.DocEntry) }); } SAPMatrix.ClearMtx(mtx1); transferItems = null; seriesNumbers = null; transferDocument = null; } UIApplication.ShowMessageBox(t.Result.Message); LogService.WriteInfo("End Create Transfer"); }); } catch (AggregateException ae) { ae.Handle(e => { SAPException.Handle(e, "CreateTransfer"); return(true); }); } }
private void CreatePlantTransfer(bool switchWhs) { var transferDocument = new DocumentTransfer(); transferDocument.Document = pendingTransfers[selectedRow - 1]; transferDocument.Lines = transferItems; if (!String.IsNullOrEmpty(txtComment.Value)) { transferDocument.Document.Comments = txtComment.Value; } UIApplication.ShowMessageBox(StockTransferDI.TransferPlant(transferDocument, switchWhs).Message); }
public static Result CreateTransfer(DocumentTransfer transfer, bool switchWhs) { var result = new Result(); var objectCode = (!switchWhs) ? BoObjectTypes.oStockTransfer : BoObjectTypes.oInventoryTransferRequest; LogService.WriteInfo(String.Format("Crear Transferencia Pendiente: {0}, {1}", transfer.Document.DocEntry, transfer.Document.Folio)); try { var oStockTransfer = (StockTransfer)DIApplication.Company.GetBusinessObject(objectCode); //OWTR var task = Task.Factory.StartNew(() => { oStockTransfer.ToWarehouse = (!switchWhs) ? transfer.Document.ToWhs : transfer.Document.FromWhs; oStockTransfer.FromWarehouse = (!switchWhs) ? transfer.Document.FromWhs : transfer.Document.ToWhs; oStockTransfer.UserFields.Fields.Item("U_GLO_Status").Value = "O"; oStockTransfer.UserFields.Fields.Item("U_MQ_OrigenFol").Value = transfer.Document.Folio; }); var task2 = Task.Factory.StartNew(() => { foreach (var line in transfer.Lines) { LogService.WriteInfo(String.Format("Transfiriendo Artículo: {0}, {1}", line.Item, line.Quantity)); LogService.WriteInfo(String.Format("De almancen {0} a almacen {1}", line.ToWhs, oStockTransfer.ToWarehouse)); oStockTransfer.Lines.ItemCode = line.Item; oStockTransfer.Lines.ItemDescription = line.Desc; oStockTransfer.Lines.Quantity = line.Quantity; oStockTransfer.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; oStockTransfer.Lines.FromWarehouseCode = line.ToWhs; oStockTransfer.Lines.WarehouseCode = oStockTransfer.ToWarehouse; if (!Object.ReferenceEquals(transfer.Series, null)) { var series = transfer.Series.Where(s => s.ItemCode == line.Item).AsParallel().ToList(); Parallel.For(0, series.Count - 1, row => { oStockTransfer.Lines.SerialNumbers.Add(); }); SerialNumbers serialNumber; Parallel.For(0, series.Count, i => { lock (padlock) { oStockTransfer.Lines.SerialNumbers.SetCurrentLine(i); serialNumber = oStockTransfer.Lines.SerialNumbers; } serialNumber.InternalSerialNumber = series[i].Number; serialNumber.SystemSerialNumber = series[i].SysNumber; serialNumber.Quantity = series[i].Quantity; }); } oStockTransfer.Lines.Add(); } }); Task.WaitAll(task, task2); if (oStockTransfer.Add() != 0) { LogService.WriteError("TransferDI (Create Document) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { if (switchWhs) { oStockTransfer.GetByKey(int.Parse(DIApplication.Company.GetNewObjectKey())); result.DocEntry = oStockTransfer.DocNum; } if (!UpdateTransferStatus(transfer.Document.DocEntry, BoObjectTypes.oStockTransfer)) { return(new Result() { Success = false, Message = String.Format("Error al actualizar el estado del documento #: {0}, {1} ", transfer.Document.DocEntry, DIApplication.Company.GetLastErrorDescription()) }); } result.Success = true; result.Message = "El translado del almacenes se realizó con éxito"; } } catch (AggregateException ae) { ae.Handle(e => { HandleException(e, "TransferDI(Document)", ref result); return(true); }); } catch (Exception ex) { HandleException(ex, "TransferDI(Document)", ref result); } return(result); }