Esempio n. 1
0
        // 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());
            }
        }
Esempio n. 2
0
        public string getNum(int metodo)
        {
            GetNextDocNumbers myDocNumbers = new GetNextDocNumbers();
            GetSopNumber      mySopNumber  = new GetSopNumber();

            //n.Add(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
            if (metodo == 1)
            {
                return(myDocNumbers.GetPMNextVoucherNumber(GetNextDocNumbers.IncrementDecrement.Increment, connectionString));
            }
            else
            if (metodo == 2)
            {
                return(myDocNumbers.GetNextPOPReceiptNumber(GetNextDocNumbers.IncrementDecrement.Increment, connectionString));
            }
            else
            {
                return(null);
            }
        }
        public String CreateSalesOrder(Document document, string docPrefix, string batch)
        {

            if (document.DocumentLines == null || document.DocumentLines.Count <= 0)
                throw new Exception("Sales order does not contains lines.");

            string SOPNumber;
            //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes
            //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear

            try
            {

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] salesLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[document.DocumentLines.Count];
                //Create an object that holds XML node object
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert LineItem; // = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                int lineSeq = 0;
                Decimal subTotal = 0;

                // Next consecutive for a S.O.
                GetSopNumber mySopNumber = new GetSopNumber();
                SOPNumber = mySopNumber.GetNextSopNumber(2, docPrefix, CurCompany.ErpConnection.CnnString);


                Console.WriteLine("1");

                foreach (DocumentLine dl in document.DocumentLines)
                {
                    LineItem = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();

                    // Populate            
                    LineItem.CUSTNMBR = dl.Document.Customer.AccountCode;
                    LineItem.SOPNUMBE = SOPNumber;
                    LineItem.SOPTYPE = 2;
                    LineItem.DOCID = docPrefix;   // SWEB   STDORD
                    LineItem.ITEMNMBR = dl.Product.ProductCode;
                    LineItem.UOFM = dl.Unit.ErpCode;
                    LineItem.UNITPRCE = (decimal)dl.UnitPrice;
                    LineItem.XTNDPRCE = (decimal)dl.ExtendedPrice;
                    LineItem.LOCNCODE = document.Location.ErpCode;
                    LineItem.DOCDATE = DateTime.Now.ToShortDateString();
                    LineItem.PRCLEVEL = "STANDARD";

                    // quantities
                    LineItem.QUANTITY = (decimal)dl.Quantity;

                    salesLine[lineSeq++] = LineItem;
                    subTotal += (decimal)dl.ExtendedPrice;
                }


                //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty
                SOPTransactionType salesOrder = new SOPTransactionType();
                salesOrder.taSopLineIvcInsert_Items = salesLine;

                //Create a taSopHdrIvcInsert XML node object
                taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();

                //Populate the properties of the taSopHdrIvcInsert XML node object           

                salesHdr.SOPTYPE = 2;
                salesHdr.SOPNUMBE = SOPNumber;
                salesHdr.DOCID = docPrefix;
                salesHdr.BACHNUMB = batch; // "B2BSO";
                salesHdr.LOCNCODE = document.Location.ErpCode;
                salesHdr.DOCDATE = DateTime.Now.ToShortDateString();
                salesHdr.SUBTOTAL = subTotal;
                salesHdr.DOCAMNT = subTotal;
                
                salesHdr.CUSTNMBR = document.Customer.AccountCode;
                salesHdr.CUSTNAME = document.Customer.Name;

                //if (document.ErpMaster > 0)
                    //salesHdr.MSTRNUMB = document.ErpMaster;

                //BILLING
                try { salesHdr.PRBTADCD = document.Customer.AccountAddresses[0].ErpCode; }
                catch
                {
                    salesHdr.PRBTADCD = document.DocumentAddresses
                        .Where(f => f.AddressType == AddressType.Billing).First().ErpCode;
                }

                //SHIPPING
                try { salesHdr.PRSTADCD = document.Customer.AccountAddresses[0].ErpCode; }
                catch
                {
                    salesHdr.PRBTADCD = document.DocumentAddresses
                        .Where(f => f.AddressType == AddressType.Shipping).First().ErpCode;
                }

                salesHdr.CSTPONBR = document.CustPONumber;

                salesOrder.taSopHdrIvcInsert = salesHdr;

                SOPTransactionType[] salesOrderArray = new SOPTransactionType[1];
                salesOrderArray[0] = salesOrder;

                //Create an eConnect XML document object and populate its SOPTransactionType property with
                //the SOPTransactionType schema object
                eConnectType eConnect = new eConnectType();
                eConnect.SOPTransactionType = salesOrderArray;

                //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());

                //mySopNumber.Dispose();

                return SOPNumber;

            }
            
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("CreateSalesOrder", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                throw;
            }
        }