public String CreatePurchaseOrder(Document document) { string Flag = ""; if (document.DocumentLines == null || document.DocumentLines.Count <= 0) { throw new Exception("Purchase order does not contains lines."); } try { string POPNumber; //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear // Next consecutive for a P.O. Flag = "PO Sequence"; GetNextDocNumbers nextPopNumber = new GetNextDocNumbers(); POPNumber = nextPopNumber.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, CurCompany.ErpConnection.CnnString); taPoLine_ItemsTaPoLine[] docLines = new taPoLine_ItemsTaPoLine[document.DocumentLines.Count]; //Create an object that holds XML node object taPoLine_ItemsTaPoLine curLine; int i = 1; // Next consecutive for a Purchase Receipt foreach (DocumentLine dr in document.DocumentLines) { //Debe ser active, para garantizar que no es Misc, o service Item if (dr.Product.Status.StatusID == EntityStatus.Active) { curLine = new taPoLine_ItemsTaPoLine(); //Validate Item/Vendor, GP requires that the Vendor has assigned the ItemNumber ValidateItemAndVendor(document.Vendor.AccountCode, dr.Product.ProductCode); //Validate Item/Location, GP requires that the Location has assigned the ItemNumber ValidateItemAndLocation(document.Location.ErpCode, dr.Product.ProductCode); // Populate Lines Flag = "Line Info"; curLine.PONUMBER = POPNumber; curLine.POTYPE = GP_DocType.PO_Standard; curLine.VENDORID = document.Vendor.AccountCode; curLine.QUANTITY = (decimal)dr.Quantity; curLine.QUANTITYSpecified = true; curLine.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); curLine.ITEMNMBR = dr.Product.ProductCode; curLine.LOCNCODE = document.Location.ErpCode; curLine.ORD = i; curLine.UOFM = dr.Unit.ErpCode; curLine.POLNESTA = 1; //NEW docLines[i - 1] = curLine; i++; } } //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty POPTransactionType docType = new POPTransactionType(); //Adicionado Track Lists docType.taPoLine_Items = docLines; //Create a taSopHdrIvcInsert XML node object taPoHdr docHdr = new taPoHdr(); //Populate Header Flag = "Header Info"; docHdr.PONUMBER = POPNumber; docHdr.POSTATUS = 1; //NEW docHdr.POTYPE = GP_DocType.PO_Standard; docHdr.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); docHdr.VENDORID = document.Vendor.AccountCode; docHdr.NOTETEXT = document.Comment; docType.taPoHdr = docHdr; POPTransactionType[] docTypeArray = new POPTransactionType[1]; docTypeArray[0] = docType; //Create an eConnect XML document object and populate its docType property with //the docType schema object Flag = "eConnect"; eConnectType eConnect = new eConnectType(); eConnect.POPTransactionType = docTypeArray; //Serialize the XML document to the file XmlSerializer serializer = new XmlSerializer(typeof(eConnectType)); StringWriter writer = new StringWriter(); serializer.Serialize(writer, eConnect); DynamicsGP_ec.SendData(writer.ToString()); return(POPNumber); } catch (Exception ex) { //ExceptionMngr.WriteEvent("CreatePurchaseOrder: ", ListValues.EventType.Error, ex, null, // ListValues.ErrorCategory.ErpConnection); throw new Exception(Flag + ". " + WriteLog.GetTechMessage(ex)); } }
public String CreatePurchaseOrder(Document document) { string Flag = ""; if (document.DocumentLines == null || document.DocumentLines.Count <= 0) throw new Exception("Purchase order does not contains lines."); try { string POPNumber; //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear // Next consecutive for a P.O. Flag = "PO Sequence"; GetNextDocNumbers nextPopNumber = new GetNextDocNumbers(); POPNumber = nextPopNumber.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, CurCompany.ErpConnection.CnnString); taPoLine_ItemsTaPoLine[] docLines = new taPoLine_ItemsTaPoLine[document.DocumentLines.Count]; //Create an object that holds XML node object taPoLine_ItemsTaPoLine curLine; int i = 1; // Next consecutive for a Purchase Receipt foreach (DocumentLine dr in document.DocumentLines) { //Debe ser active, para garantizar que no es Misc, o service Item if (dr.Product.Status.StatusID == EntityStatus.Active) { curLine = new taPoLine_ItemsTaPoLine(); //Validate Item/Vendor, GP requires that the Vendor has assigned the ItemNumber ValidateItemAndVendor(document.Vendor.AccountCode, dr.Product.ProductCode); //Validate Item/Location, GP requires that the Location has assigned the ItemNumber ValidateItemAndLocation(document.Location.ErpCode, dr.Product.ProductCode); // Populate Lines Flag = "Line Info"; curLine.PONUMBER = POPNumber; curLine.POTYPE = GP_DocType.PO_Standard; curLine.VENDORID = document.Vendor.AccountCode; curLine.QUANTITY = (decimal)dr.Quantity; curLine.QUANTITYSpecified = true; curLine.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); curLine.ITEMNMBR = dr.Product.ProductCode; curLine.LOCNCODE = document.Location.ErpCode; curLine.ORD = i; curLine.UOFM = dr.Unit.ErpCode; curLine.POLNESTA = 1; //NEW docLines[i - 1] = curLine; i++; } } //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty POPTransactionType docType = new POPTransactionType(); //Adicionado Track Lists docType.taPoLine_Items = docLines; //Create a taSopHdrIvcInsert XML node object taPoHdr docHdr = new taPoHdr(); //Populate Header Flag = "Header Info"; docHdr.PONUMBER = POPNumber; docHdr.POSTATUS = 1; //NEW docHdr.POTYPE = GP_DocType.PO_Standard; docHdr.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); docHdr.VENDORID = document.Vendor.AccountCode; docHdr.NOTETEXT = document.Comment; docType.taPoHdr = docHdr; POPTransactionType[] docTypeArray = new POPTransactionType[1]; docTypeArray[0] = docType; //Create an eConnect XML document object and populate its docType property with //the docType schema object Flag = "eConnect"; eConnectType eConnect = new eConnectType(); eConnect.POPTransactionType = docTypeArray; //Serialize the XML document to the file XmlSerializer serializer = new XmlSerializer(typeof(eConnectType)); StringWriter writer = new StringWriter(); serializer.Serialize(writer, eConnect); DynamicsGP_ec.SendData(writer.ToString()); return POPNumber; } catch (Exception ex) { //ExceptionMngr.WriteEvent("CreatePurchaseOrder: ", ListValues.EventType.Error, ex, null, // ListValues.ErrorCategory.ErpConnection); throw new Exception(Flag + ". " + WriteLog.GetTechMessage(ex)); } }
/// <summary> /// save new vendor order /// </summary> /// <param name="order"></param> /// <param name="orderLines"></param> /// <returns></returns> public OperationResult SaveVendorOrder(POP10100_PurchaseOrder_Work order, List <POP10110_PurchaseOrderLine_Work> orderLines) { var operationResult = new OperationResult(); logger.Debug("Vendor Order is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { if (orderLines != null && orderLines.Count > 0) { taPoLine_ItemsTaPoLine[] lineItems = new taPoLine_ItemsTaPoLine[orderLines.Count]; var orderLineNumber = 16384; var lineNumber = 0; foreach (var orderLine in orderLines) { // Instantiate a taUpdateCreateItemRcd XML node object taPoLine_ItemsTaPoLine orderLineItem = new taPoLine_ItemsTaPoLine(); //Populate elements of the taUpdateCreateItemRcd XML node object orderLineItem.PONUMBER = orderLine.PONUMBER; orderLineItem.VENDORID = orderLine.VENDORID; orderLineItem.DOCDATE = orderLine.DOCDATE; orderLineItem.LOCNCODE = orderLine.LOCNCODE; orderLineItem.VNDITNUM = orderLine.VNDITNUM; orderLineItem.ITEMNMBR = orderLine.ITEMNMBR; orderLineItem.QUANTITY = orderLine.QUANTITY; //DUE DATE orderLineItem.PRMDATE = orderLine.PRMDATE; //SHIP DATE orderLineItem.PRMSHPDTE = orderLine.PRMSHPDTE; orderLineItem.UpdateIfExists = 0; lineItems[lineNumber] = orderLineItem; orderLineNumber = orderLineNumber * 2; lineNumber++; } // Instantiate a taUpdateCreateItemRcd XML node object taPoHdr orderHeader = new taPoHdr(); //Populate elements of the taUpdateCreateItemRcd XML node object orderHeader.POTYPE = order.POTYPE; orderHeader.PONUMBER = order.PONUMBER; orderHeader.VENDORID = order.VENDORID; orderHeader.SUBTOTAL = order.SUBTOTAL; orderHeader.UpdateIfExists = 0; // Instantiate a IVItemMasterType schema object POPTransactionType ordertype = new POPTransactionType(); // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node ordertype.taPoLine_Items = lineItems; ordertype.taPoHdr = orderHeader; POPTransactionType[] orderEntry = { ordertype }; // Instantiate an eConnectType schema object eConnectType eConnect = new eConnectType(); // Instantiate a Memory Stream object MemoryStream memoryStream = new MemoryStream(); // Create an XML serializer object XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); // Populate the eConnectType object with the IVItemMasterType schema object eConnect.POPTransactionType = orderEntry; /////////////////////////////////////////////////////////////////////////////// // Serialize the eConnectType. serializer.Serialize(memoryStream, eConnect); // Reset the position of the memory stream to the start. memoryStream.Position = 0; // Create an XmlDocument from the serialized eConnectType in memory. XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); memoryStream.Close(); ///////////////////////////////////////////////////////////////////////////////// //string xmldocument; //SerializeReceiptHeaderObject("C:\\receipt.xml", receipt, receiptLines); ////Use an XML document to create a string representation of the customer //XmlDocument xmldoc = new XmlDocument(); //xmldoc.Load("C:\\receipt.xml"); //xmldocument = xmldoc.OuterXml; ////Call eConnect to process the xmldocument. //e.CreateEntity(_dynamicsConnection, xmldocument); ////////////////////////////////////////////////////////////////////////////////// // Call eConnect to process the XmlDocument. e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml); operationResult.Success = true; operationResult.Message = "Success"; } else { operationResult.Success = false; operationResult.Message = "No items are attached to receive."; } } // The eConnectException class will catch eConnect business logic errors. // display the error message on the console catch (eConnectException exc) { Console.Write(exc.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new receipt: {0} ", exc.ToString()); } // Catch any system error that might occurr. // display the error message on the console catch (System.Exception ex) { Console.Write(ex.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new receipt: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement return(operationResult); }