public static Result CreateDocument(DocumentProduction document, User user, bool cancellation) { var result = new Result(); FoodTransferDAO foodTransferDAO = new FoodTransferDAO(); var oStockExit = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oInventoryGenExit); //OIGE try { var task = Task.Factory.StartNew(() => { oStockExit.Series = foodTransferDAO.GetSeries(user.IsFoodPlant ? user.WhsCode : document.Lines[0].Whs, "60", "Series"); oStockExit.UserFields.Fields.Item("U_MQ_OrigenFol").Value = user.IsFoodPlant ? document.DocNum : (!cancellation ? String.Empty : document.DocNum); oStockExit.UserFields.Fields.Item("U_GLO_ObjType").Value = user.FormID; oStockExit.UserFields.Fields.Item("U_GLO_InMo").Value = !cancellation ? "S-PROD" : "S-PRODCANCEL"; oStockExit.DocDate = DateTime.Now; if (cancellation) { oStockExit.UserFields.Fields.Item("U_GLO_Status").Value = "C"; } }); var task2 = Task.Factory.StartNew(() => { foreach (var line in document.Lines.Where(l => l.Qty > 0 && l.Inventorial.Equals(0))) { if (!user.IsFoodPlant && line.Resource == 1) { continue; } oStockExit.Lines.ItemDescription = line.Desc; oStockExit.Lines.Quantity = (cancellation && !user.IsFoodPlant) ? line.Plan : line.Qty; oStockExit.Lines.CostingCode = user.Area; oStockExit.Lines.WarehouseCode = line.Whs; oStockExit.Lines.AccountCode = line.AccCode; oStockExit.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; if (user.IsFoodPlant && !cancellation) { oStockExit.Lines.BaseEntry = document.DocEntry; oStockExit.Lines.BaseLine = line.LineNum; oStockExit.Lines.BaseType = (int)BoObjectTypes.oProductionOrders; } else { oStockExit.Lines.ItemCode = line.Item; } oStockExit.Lines.Add(); } }); Task.WaitAll(task, task2); if (oStockExit.Add() != 0) { LogService.WriteError("TransferDI (Document) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.DocEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); oStockExit.GetByKey(result.DocEntry); result.Success = true; result.DocTotal = oStockExit.DocTotal; result.Message = String.Format("La salida de mercancia#{0} se realizó con éxito!", oStockExit.DocNum); } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; HandleException(ex, "StockExitDI.CreateDocument"); } finally { MemoryUtility.ReleaseComObject(oStockExit); } return(result); }
private void button4_Click(object sender, EventArgs e) { string test = "last"; Acte a = new Acte(); List <Acte> la = new List <Acte>(); // remplissage //premier acte a.ReferenceInterne = "referenceInterne"; a.Frais = 0; Repartition r1 = new Repartition(); r1.CodeISIN = "support01"; r1.TypeRepartition = "%"; r1.ValeurRepartition = 50; Repartition r2 = new Repartition(); r2.CodeISIN = "support02"; r2.TypeRepartition = "€"; r2.ValeurRepartition = 100000; a.ListeSupportDesinvestir = new List <Repartition>(); // à.completer. a.ListeSupportDesinvestir.Add(r1); // ............ a.ListeSupportInvestir = new List <Repartition>(); // ...par.la... a.ListeSupportInvestir.Add(r2); // ............ a.ListeDocument = new List <DocumentProduction>(); // ...suite.... a.Commentaire = "ceci est un commentaire"; DocumentProduction doc1 = new DocumentProduction(); DocumentProduction doc2 = new DocumentProduction(); doc1.ID_DocumentNortia = 325; doc2.ID_DocumentNortia = 477; a.ListeDocument.Add(doc1); a.ListeDocument.Add(doc2); //deuxiemmme acte Acte a2 = new Acte(); a2.ReferenceInterne = "referenceInterne"; a2.Frais = 0; Repartition r12 = new Repartition(); r12.CodeISIN = "support01"; r12.TypeRepartition = "%"; r12.ValeurRepartition = 50; Repartition r22 = new Repartition(); r22.CodeISIN = "support02"; r22.TypeRepartition = "€"; r22.ValeurRepartition = 100000; a2.ListeSupportDesinvestir = new List <Repartition>(); // à.completer. a2.ListeSupportDesinvestir.Add(r22); // ............ a2.ListeSupportInvestir = new List <Repartition>(); // ...par.la... a2.ListeSupportInvestir.Add(r22); // ............ a2.ListeDocument = new List <DocumentProduction>(); // ...suite.... a2.Commentaire = "ceci est un commentaire"; DocumentProduction doc11 = new DocumentProduction(); DocumentProduction doc22 = new DocumentProduction(); doc11.ID_DocumentNortia = 304; doc22.ID_DocumentNortia = 306; a2.ListeDocument.Add(doc11); a2.ListeDocument.Add(doc22); la.Add(a); la.Add(a2); // fin remplissage if (test.Equals("first")) { //serialisation JsonSerializerSettings jsonSetting = new JsonSerializerSettings { // ces options sont valable aussi pour les sous objets NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, ContractResolver = new ShouldSerializeContractResolver() }; // display json on messagebox string json = JsonConvert.SerializeObject(a, jsonSetting); MessageBox.Show(json); // write json to a file string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // (mes documents) using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\SpiricaJson.txt")) { outputFile.WriteLine(json); } } else // for a liste of Actes { //test with final class //Spirica spirica = new Spirica(la); // IActe acte = new Spirica(la); // string json = acte.genJSON(); string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // (mes documents) using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\SpiricaJson.txt")) { //outputFile.WriteLine(json); } //MessageBox.Show(json); //Definition.setProgressBar(progressBar1); //acte.sendProd(); } }
private void CreateDocuments(bool cancellation) { try { //Validations if (!ValidateColumn("Existence") || !ValidateColumn("Emision")) { return; } if (!cancellation && !ValidateColumn("BagBales")) { return; } //Setting the Bags/Bales values and Real Quantity SetBagsBalesAndRealQuantity(); //Transaction BeginTransaction(); LogService.WriteInfo("Begin " + (cancellation ? "cancellation" : "Production") + " Process"); //Invetory Exit var task = Task.Factory.StartNew(() => { var exit = new DocumentProduction(); exit.Lines = !cancellation ? components : new Component[1] { productionLine }; exit.DocEntry = docEntry; exit.DocNum = txtFolio.Value; return(StockExitDI.CreateDocument(exit, user, cancellation)); }); task.Wait(); if (!user.IsFoodPlant && !cancellation) { productionLine.LineTotal = task.Result.DocTotal; } //Inventory Entry var task2 = Task.Factory.StartNew(() => { if (!cancellation) { productionLine.Qty = components.Where(c => c.Prod.Equals(0)).Sum(s => s.Qty); } var entry = new DocumentProduction(); entry.Lines = !cancellation ? new Component[1] { productionLine } : components; entry.DocEntry = docEntry; entry.DocNum = txtFolio.Value; return(StockEntryDI.CreateDocument(entry, user, cancellation)); }); var task3 = Task.Factory.ContinueWhenAll(new[] { task, task2 }, _ => { var resultMessage = (!cancellation) ? new StringBuilder() .Append("Entrada de Producto Terminado: ").AppendLine(task2.Result.Message) .Append("Salida de Componentes: ").AppendLine(task.Result.Message) : new StringBuilder() .Append("Salida de Producto Terminado: ").AppendLine(task.Result.Message) .Append("Entrada de Componentes: ").AppendLine(task2.Result.Message); if (task.Result.Success && task2.Result.Success) { if (user.IsFoodPlant && !cancellation) { //Update Status to Closed for Production Order Document var result = ProductionOrderDI.CancelDocument(docEntry, task2.Result.DocEntry, task.Result.DocEntry); resultMessage.Append("Orden de Fabricación: ").AppendLine(result.Message); } if (cancellation) { var result = InventoryRevaluationDI.CreateDocument(productionLine, user, task.Result.DocEntry, docEntry); if (result.Success) { resultMessage.Append("Revalorización de Inventario: ").AppendLine(result.Message); } } if (StockEntryDI.UpdateDocument(task2.Result.DocEntry, task.Result.DocEntry, cancellation)) { Commit(); } else { RollBack(resultMessage.ToString()); } } else { RollBack(resultMessage.ToString()); } UIApplication.ShowMessageBox(resultMessage.ToString()); ClearMatrix(); if (user.IsFoodPlant && cancellation) { SAPChooseFromList.AddConditionValues(this.UIAPIRawForm.ChooseFromLists.Item("CFL_PO"), "DocNum", foodTransferDAO.GetCancelledOrders(user.WhsCode)); } else if (!user.IsFoodPlant && !cancellation) { txtFolio.Value = foodTransferDAO.GetSeries(user.WhsCode, "59", "NextNumber").ToString(); //OIGN } }); LogService.WriteInfo("Begin " + (cancellation ? "cancellation" : "Production") + " Process"); } catch (Exception ex) { SAPException.Handle(ex, "CreateDocuments"); } }
public static Result CreateDocument(DocumentProduction document, User user, bool cancellation) { var result = new Result(); FoodTransferDAO foodPlantDAO = new FoodTransferDAO(); Component[] itemCosts = null; var oStockEntry = (Documents)DIApplication.Company.GetBusinessObject(BoObjectTypes.oInventoryGenEntry); //OIGN try { var task = Task.Factory.StartNew(() => { oStockEntry.Series = foodPlantDAO.GetSeries(user.IsFoodPlant ? user.WhsCode : document.Lines[0].Whs, "59", "Series"); oStockEntry.UserFields.Fields.Item("U_GLO_ObjType").Value = user.FormID; oStockEntry.UserFields.Fields.Item("U_GLO_InMo").Value = !cancellation ? "E-PROD" : "E-PRODCANCEL"; oStockEntry.DocDate = DateTime.Now; if (!user.IsFoodPlant && cancellation) { oStockEntry.UserFields.Fields.Item("U_GLO_Status").Value = "C"; } }); //Line Item var task2 = Task.Factory.StartNew(() => { if (cancellation) { itemCosts = foodPlantDAO.GetComponentsExitCosts(document.DocEntry.ToString(), user.IsFoodPlant); } foreach (var line in document.Lines.Where(l => l.Resource == 0 && l.Qty > 0 && l.Inventorial == 0)) //exclude resource items { oStockEntry.Lines.ItemDescription = line.Desc; oStockEntry.Lines.Quantity = line.Qty; oStockEntry.Lines.CostingCode = user.Area; oStockEntry.Lines.WarehouseCode = line.Whs; oStockEntry.Lines.AccountCode = line.AccCode; oStockEntry.Lines.UserFields.Fields.Item("U_GLO_BagsBales").Value = line.Bags; if (cancellation) { oStockEntry.Lines.LineTotal = itemCosts.Single(i => i.Item == line.Item).LineTotal; oStockEntry.Lines.ItemCode = line.Item; } else if (user.IsFoodPlant && !cancellation) { oStockEntry.Lines.BaseEntry = document.DocEntry; oStockEntry.Lines.BaseType = (int)BoObjectTypes.oProductionOrders; } else if (!user.IsFoodPlant && !cancellation) { oStockEntry.Lines.LineTotal = line.LineTotal; oStockEntry.Lines.ItemCode = line.Item; } else { oStockEntry.Lines.ItemCode = line.Item; } oStockEntry.Lines.Add(); } }); Task.WaitAll(new Task[] { task, task2 }); if (oStockEntry.Add() != 0) { LogService.WriteError("TransferDI (Draft) " + DIApplication.Company.GetLastErrorDescription()); result.Success = false; result.Message = "Error: " + DIApplication.Company.GetLastErrorDescription(); } else { result.DocEntry = int.Parse(DIApplication.Company.GetNewObjectKey()); result.Success = true; oStockEntry.GetByKey(result.DocEntry); result.Message = String.Format("La entrada de mercancia#{0} se realizó con éxito!", oStockEntry.DocNum); if (!user.IsFoodPlant && cancellation) { CancelPreviousDocument(oStockEntry, document.DocEntry); } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; HandleException(ex, "StockEntryDI.CreateDocument"); } finally { MemoryUtility.ReleaseComObject(oStockEntry); } return(result); }