// Use the button's click event to retrieve the next available document // numbers for Microsoft Dynamics GP documents. private void btnGetNextNumber_Click(object sender, System.EventArgs e) { try { // Instantiate a GetNextDocNumbers object GetNextDocNumbers myDocNumbers = new GetNextDocNumbers(); // Instantiate a GetSopNumber object GetSopNumber mySopNumber = new GetSopNumber(); // Create a string that specifies the Microsoft Dynamics GP server and database // The server name and database will use the values supplied by the user through the UI textboxes. string connString = string.Empty; connString = "data source=" + txtSqlServer.Text + ";" + "initial catalog=" + txtDataBase.Text + ";" + "Integrated Security=SSPI;"; // Use the GetNextSopNumber method of the GetSopNumber object to retrieve the next // number for a Microsoft Dynamics GP invoice document lblSOPNUMBER.Text = mySopNumber.GetNextSopNumber(3, "STDINV", connString); // Use each method of the GetNextDocNumber object to retrieve the next document number // for the available Microsoft Dynamics GP document types lblPMNUMBER.Text = myDocNumbers.GetNextPMPaymentNumber(GetNextDocNumbers.IncrementDecrement.Increment, connString); lblSOPPAYMENT.Text = myDocNumbers.GetNextRMNumber(GetNextDocNumbers.IncrementDecrement.Increment, GetNextDocNumbers.RMPaymentType.RMPayments, connString); lblIVDOCNUMBER.Text = myDocNumbers.GetNextIVNumber(GetNextDocNumbers.IncrementDecrement.Increment, GetNextDocNumbers.IVDocType.IVAdjustment, connString); lblPONUMBER.Text = myDocNumbers.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, connString); } catch (Exception ex) { // If an error occurs, diplay the error information to the user MessageBox.Show(ex.ToString()); } }
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)); } }