Esempio n. 1
0
        //public TransactionMakeInvoice(string strcon, string nin, string nout, string hin, string hout, string fil, string srv, string datab,string itbms)
        //{
        //    file = fil;
        //    fname = file.Split('\\').Last().Split('/').Last().Replace(nin, "");
        //    server = "10.1.92.203"; // srv;
        //    db = datab;

        //    GenerateDocument();
        //}


        private void GenerateDocument()
        {
            //DataSet data = parseXML(file);
            //<add name="TSGVLEntities" connectionString="metadata=res://*/ModelTShirt.csdl|res://*/ModelTShirt.ssdl|res://*/ModelTShirt.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.1.92.203;initial catalog=TSGVL;user id=applegreen;password=galapago;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
            string eConnectConnectionString = string.Format("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TSGVL;Data Source=10.1.92.203;user id=applegreen;password=galapago");

            string DOCID = "FAC";


            //Now we create the eConnect XML Document
            XmlDocument eConnectXMLDocument = new XmlDocument();
            XmlNode     NodeeConnect;
            XmlNode     NodeSchema;
            XmlNode     taSopHdrNode;
            XmlNode     taSopLine_ItemsNode;
            XmlNode     taSopLineNode;
            XmlNode     taCreateSopPaymentInsertRecord_Items;
            XmlNode     taCreateSopPaymentInsertRecord;

            XmlNode NodeElement;

            //if (data.Tables["HEADER"].Rows.Count > 0 && data.Tables["LINES"].Rows.Count > 0)
            //{

            //DataRow header = data.Tables["HEADER"].Rows[0];


            //if (header["DOCID"].ToString().Length <= 0)
            //{
            //    DOCID = "NC"; //CHANGED GPHelper.returnDOCID(this.StringConnection).Trim();
            //}
            //else
            //{
            //    DOCID = "NC"; //CHANGED header["DOCID"].ToString();
            //}

            //if (header["DOCNUMBE"].ToString() == "")
            //{

            //    header["DOCNUMBE"] = "";
            //}
            NodeeConnect = eConnectXMLDocument.CreateElement("eConnect");
            NodeSchema   = eConnectXMLDocument.CreateElement("SOPTransactionType");

            //Header
            taSopHdrNode = eConnectXMLDocument.CreateElement("taSopHdrIvcInsert");

            NodeElement           = eConnectXMLDocument.CreateElement("SOPTYPE");
            NodeElement.InnerText = "3";     // INVOICE
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("DOCID");
            NodeElement.InnerText = DOCID;
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("DEFPRICING");
            NodeElement.InnerText = "1";
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("CREATETAXES");
            NodeElement.InnerText = "1";
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("DEFTAXSCHDS");
            NodeElement.InnerText = "1";
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("BACHNUMB");
            NodeElement.InnerText = DOCID + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("SOPNUMBE");
            NodeElement.InnerText = "1023";     //CHANGED header["DOCNUMBE"].ToString();
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("ORIGNUMB");
            NodeElement.InnerText = "1024";     //CHANGED header["ORIGNUMB"].ToString();
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("ORIGTYPE");
            NodeElement.InnerText = "1025";     //CHANGED header["ORIGTYPE"].ToString();
            taSopHdrNode.AppendChild(NodeElement);

            //if (header["TAXSCHID"].ToString().Length <= 0)
            //{
            //    NodeElement = eConnectXMLDocument.CreateElement("TAXSCHID");
            //    NodeElement.InnerText = "1024"; //CHANGED this.ITBMS;
            //    taSopHdrNode.AppendChild(NodeElement);
            //}
            //else
            //{
            NodeElement           = eConnectXMLDocument.CreateElement("TAXSCHID");
            NodeElement.InnerText = "1024";         //CHANGED header["TAXSCHID"].ToString();
            taSopHdrNode.AppendChild(NodeElement);
            //}



            #region Lines
            // Details

            taSopLine_ItemsNode = eConnectXMLDocument.CreateElement("taSopLineIvcInsert_Items");

            //foreach (DataRow item in data.Tables["LINES"].Rows)
            //{
            taSopLineNode         = eConnectXMLDocument.CreateElement("taSopLineIvcInsert");
            NodeElement           = eConnectXMLDocument.CreateElement("SOPTYPE");
            NodeElement.InnerText = "3";         //return
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("DEFPRICING");
            NodeElement.InnerText = "1";
            taSopHdrNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("SOPNUMBE");
            NodeElement.InnerText = "1010";         //CHANGED header["DOCNUMBE"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("CUSTNMBR");
            NodeElement.InnerText = "1";         //CHANGED header["CUSTOMER"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("DOCDATE");
            NodeElement.InnerText = "2017-08-02";
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("LOCNCODE");
            NodeElement.InnerText = "1";         //CHANGED item["LOCNCODE"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("ITEMNMBR");
            NodeElement.InnerText = "1";         //CHANGEDitem["ITEMNMBR"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("UNITPRCE");
            NodeElement.InnerText = "1";         //CHANGED item["UNITPRCE"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("XTNDPRCE");
            NodeElement.InnerText = "25";
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("QUANTITY");
            NodeElement.InnerText = "23";         //CHANGED item["QUANTITY"].ToString();
            taSopLineNode.AppendChild(NodeElement);


            NodeElement           = eConnectXMLDocument.CreateElement("MRKDNAMT");
            NodeElement.InnerText = "1";         //CHANGED item["MRKDNAMT"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("UOFM");
            NodeElement.InnerText = "0";         //CHANGED item["UOFM"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("USERDEF1");
            NodeElement.InnerText = "1";         //CHANGED item["USERDEF1"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("USERDEF2");
            NodeElement.InnerText = "2";         //CHANGED item["USERDEF2"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("USERDEF3");
            NodeElement.InnerText = "3";         //CHANGED item["USERDEF3"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("USERDEF4");
            NodeElement.InnerText = "4";         //CHANGED item["USERDEF4"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            NodeElement           = eConnectXMLDocument.CreateElement("USERDEF5");
            NodeElement.InnerText = "5";         //CHANGED item["USERDEF5"].ToString();
            taSopLineNode.AppendChild(NodeElement);

            taSopLine_ItemsNode.AppendChild(taSopLineNode);
            //}
            #endregion
            // Payments
            // Details
            Decimal totalPaid = 0;

            //taCreateSopPaymentInsertRecord_Items = eConnectXMLDocument.CreateElement("taCreateSopPaymentInsertRecord_Items");

            //foreach (DataRow item in data.Tables["PAYMENTS"].Rows)
            //{
            //    taCreateSopPaymentInsertRecord = eConnectXMLDocument.CreateElement("taCreateSopPaymentInsertRecord");
            //    NodeElement = eConnectXMLDocument.CreateElement("SOPTYPE");
            //    NodeElement.InnerText = "3"; //return
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("SOPNUMBE");
            //    NodeElement.InnerText = header["DOCNUMBE"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("CUSTNMBR");
            //    NodeElement.InnerText = header["CUSTOMER"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);


            //    NodeElement = eConnectXMLDocument.CreateElement("DOCDATE");
            //    NodeElement.InnerText = DateTime.Parse(item["DOCDATE"].ToString()).ToString("yyyy-MM-dd");
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("DOCAMNT");
            //    NodeElement.InnerText = item["DOCAMNT"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    totalPaid += (Decimal)item["DOCAMNT"];

            //    NodeElement = eConnectXMLDocument.CreateElement("CHEKBKID");
            //    NodeElement.InnerText = item["CHEKBKID"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("CARDNAME");
            //    NodeElement.InnerText = item["CARDNAME"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("CHEKNMBR");
            //    NodeElement.InnerText = item["CHEKNMBR"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("RCTNCCRD");
            //    NodeElement.InnerText = item["RCTNCCRD"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("AUTHCODE");
            //    NodeElement.InnerText = item["AUTHCODE"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("EXPNDATE");
            //    NodeElement.InnerText = ((DateTime)item["EXPNDATE"]).ToString("yyyy-MM-dd");
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("PYMTTYPE");
            //    NodeElement.InnerText = item["PYMTTYPE"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("DOCNUMBR");
            //    NodeElement.InnerText = item["DOCNUMBR"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("USRDEFND1");
            //    NodeElement.InnerText = item["USERDEF1"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("USERDEF2");
            //    NodeElement.InnerText = item["USERDEF2"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("USERDEF3");
            //    NodeElement.InnerText = item["USERDEF3"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("USERDEF4");
            //    NodeElement.InnerText = item["USERDEF4"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    NodeElement = eConnectXMLDocument.CreateElement("USERDEF5");
            //    NodeElement.InnerText = item["USERDEF5"].ToString();
            //    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

            //    taCreateSopPaymentInsertRecord_Items.AppendChild(taCreateSopPaymentInsertRecord);
            //}

            //NodeElement = eConnectXMLDocument.CreateElement("PYMTRCVD");
            //NodeElement.InnerText = totalPaid.ToString().Replace(",",".").Replace(".",".");
            //taSopHdrNode.AppendChild(NodeElement);

            //NodeSchema.AppendChild(taSopLine_ItemsNode);
            //NodeSchema.AppendChild(taCreateSopPaymentInsertRecord_Items);
            //NodeSchema.AppendChild(taSopHdrNode);

            // Document
            NodeeConnect.AppendChild(NodeSchema);
            eConnectXMLDocument.AppendChild(NodeeConnect);



            if (!GPHelper.eConnectSendToGP(eConnectXMLDocument.OuterXml, eConnectConnectionString))
            {
                Console.WriteLine("Se detectó un error en la transacción e connect, se procederá con el rollback de la transación");
            }
            else
            {
                Console.WriteLine("La transacción culminó satisfactoriament");

                //if (File.Exists(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", "")))
                //{
                //    File.Delete(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));
                //}
                //File.Move(this.file, this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));
            }

            //}
        }
        private void GenerateDocument()
        {
            DataSet data = parseXML(file);

            string eConnectConnectionString = string.Format("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog={1};Data Source={0};", this.server, this.db);

            string DOCID = GPHelper.InvoiceDOCID(this.StringConnection).Trim();


            //Now we create the eConnect XML Document
            XmlDocument eConnectXMLDocument = new XmlDocument();
            XmlNode     NodeeConnect;
            XmlNode     NodeSchema;
            XmlNode     taSopHdrNode;
            XmlNode     taSopLine_ItemsNode;
            XmlNode     taSopLineNode;
            XmlNode     taCreateSopPaymentInsertRecord_Items;
            XmlNode     taCreateSopPaymentInsertRecord;

            XmlNode NodeElement;

            if (data.Tables["HEADER"].Rows.Count > 0 && data.Tables["LINES"].Rows.Count > 0)
            {
                DataRow header = data.Tables["HEADER"].Rows[0];


                if (header["DOCID"].ToString().Length <= 0)
                {
                    DOCID = GPHelper.returnDOCID(this.StringConnection).Trim();
                }
                else
                {
                    DOCID = header["DOCID"].ToString();
                }

                if (header["DOCNUMBE"].ToString() == "")
                {
                    IEvent w = new WarningEvent("", "", "El documento no posee código, se intentará generar uno para proceder con el mismo.");
                    w.Publish();


                    header["DOCNUMBE"] = "";
                }
                NodeeConnect = eConnectXMLDocument.CreateElement("eConnect");
                NodeSchema   = eConnectXMLDocument.CreateElement("SOPTransactionType");

                //Header
                taSopHdrNode = eConnectXMLDocument.CreateElement("taSopHdrIvcInsert");

                NodeElement           = eConnectXMLDocument.CreateElement("SOPTYPE");
                NodeElement.InnerText = "3"; // INVOICE
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("DOCID");
                NodeElement.InnerText = DOCID;
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("DEFPRICING");
                NodeElement.InnerText = "1";
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("CREATETAXES");
                NodeElement.InnerText = "1";
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("DEFTAXSCHDS");
                NodeElement.InnerText = "1";
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("BACHNUMB");
                NodeElement.InnerText = DOCID + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("SOPNUMBE");
                NodeElement.InnerText = header["DOCNUMBE"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("ORIGNUMB");
                NodeElement.InnerText = header["ORIGNUMB"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("ORIGTYPE");
                NodeElement.InnerText = header["ORIGTYPE"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                if (header["TAXSCHID"].ToString().Length <= 0)
                {
                    NodeElement           = eConnectXMLDocument.CreateElement("TAXSCHID");
                    NodeElement.InnerText = this.ITBMS;
                    taSopHdrNode.AppendChild(NodeElement);
                }
                else
                {
                    NodeElement           = eConnectXMLDocument.CreateElement("TAXSCHID");
                    NodeElement.InnerText = header["TAXSCHID"].ToString();
                    taSopHdrNode.AppendChild(NodeElement);
                }


                NodeElement           = eConnectXMLDocument.CreateElement("FRTSCHID");
                NodeElement.InnerText = header["FRTSCHID"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("MSCSCHID");
                NodeElement.InnerText = header["MSCSCHID"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("SHIPMTHD");
                NodeElement.InnerText = header["SHIPMTHD"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                //if ((Decimal)header["TAXAMNT"] > 0)
                //{
                //    NodeElement = eConnectXMLDocument.CreateElement("TAXAMNT");
                //    NodeElement.InnerText = header["TAXAMNT"].ToString();
                //    taSopHdrNode.AppendChild(NodeElement);
                //}


                NodeElement           = eConnectXMLDocument.CreateElement("LOCNCODE");
                NodeElement.InnerText = header["LOCNCODE"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("DOCDATE");
                NodeElement.InnerText = DateTime.Parse(header["DOCDATE"].ToString()).Year + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Month + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Day;
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("FREIGHT");
                NodeElement.InnerText = header["FREIGHT"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("MISCAMNT");
                NodeElement.InnerText = header["MISCAMNT"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("TRDISAMT");
                NodeElement.InnerText = header["TRDISAMT"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("CUSTNMBR");
                NodeElement.InnerText = header["CUSTOMER"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("CSTPONBR");
                NodeElement.InnerText = header["CSTPONBR"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("SUBTOTAL");
                NodeElement.InnerText = header["SUBTOTAL"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("DOCAMNT");
                NodeElement.InnerText = header["DOCAMNT"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("SALSTERR");
                NodeElement.InnerText = header["SALSTERR"].ToString();
                taSopHdrNode.AppendChild(NodeElement);

                NodeElement           = eConnectXMLDocument.CreateElement("SLPRSNID");
                NodeElement.InnerText = header["SLPRSNID"].ToString();
                taSopHdrNode.AppendChild(NodeElement);


                #region Lines
                // Details

                taSopLine_ItemsNode = eConnectXMLDocument.CreateElement("taSopLineIvcInsert_Items");

                foreach (DataRow item in data.Tables["LINES"].Rows)
                {
                    taSopLineNode         = eConnectXMLDocument.CreateElement("taSopLineIvcInsert");
                    NodeElement           = eConnectXMLDocument.CreateElement("SOPTYPE");
                    NodeElement.InnerText = "3"; //return
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("DEFPRICING");
                    NodeElement.InnerText = "1";
                    taSopHdrNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("SOPNUMBE");
                    NodeElement.InnerText = header["DOCNUMBE"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("CUSTNMBR");
                    NodeElement.InnerText = header["CUSTOMER"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("DOCDATE");
                    NodeElement.InnerText = DateTime.Parse(header["DOCDATE"].ToString()).Year + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Month + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Day;
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("LOCNCODE");
                    NodeElement.InnerText = item["LOCNCODE"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("ITEMNMBR");
                    NodeElement.InnerText = item["ITEMNMBR"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("UNITPRCE");
                    NodeElement.InnerText = item["UNITPRCE"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("XTNDPRCE");
                    NodeElement.InnerText = item["XTNDPRCE"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("QUANTITY");
                    NodeElement.InnerText = item["QUANTITY"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    //NodeElement = eConnectXMLDocument.CreateElement("QTYONHND");
                    //NodeElement.InnerText = item["QUANTITY"].ToString();
                    //taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("MRKDNAMT");
                    NodeElement.InnerText = item["MRKDNAMT"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("UOFM");
                    NodeElement.InnerText = item["UOFM"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF1");
                    NodeElement.InnerText = item["USERDEF1"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF2");
                    NodeElement.InnerText = item["USERDEF2"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF3");
                    NodeElement.InnerText = item["USERDEF3"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF4");
                    NodeElement.InnerText = item["USERDEF4"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF5");
                    NodeElement.InnerText = item["USERDEF5"].ToString();
                    taSopLineNode.AppendChild(NodeElement);

                    taSopLine_ItemsNode.AppendChild(taSopLineNode);
                }
                #endregion
                // Payments
                // Details
                Decimal totalPaid = 0;

                taCreateSopPaymentInsertRecord_Items = eConnectXMLDocument.CreateElement("taCreateSopPaymentInsertRecord_Items");

                foreach (DataRow item in data.Tables["PAYMENTS"].Rows)
                {
                    taCreateSopPaymentInsertRecord = eConnectXMLDocument.CreateElement("taCreateSopPaymentInsertRecord");
                    NodeElement           = eConnectXMLDocument.CreateElement("SOPTYPE");
                    NodeElement.InnerText = "3"; //return
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("SOPNUMBE");
                    NodeElement.InnerText = header["DOCNUMBE"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("CUSTNMBR");
                    NodeElement.InnerText = header["CUSTOMER"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);


                    NodeElement           = eConnectXMLDocument.CreateElement("DOCDATE");
                    NodeElement.InnerText = DateTime.Parse(item["DOCDATE"].ToString()).Year + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Month + "-" + DateTime.Parse(header["DOCDATE"].ToString()).Day;
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("DOCAMNT");
                    NodeElement.InnerText = item["DOCAMNT"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    totalPaid += (Decimal)item["DOCAMNT"];

                    NodeElement           = eConnectXMLDocument.CreateElement("CHEKBKID");
                    NodeElement.InnerText = item["CHEKBKID"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("CARDNAME");
                    NodeElement.InnerText = item["CARDNAME"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("CHEKNMBR");
                    NodeElement.InnerText = item["CHEKNMBR"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("RCTNCCRD");
                    NodeElement.InnerText = item["RCTNCCRD"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    //NodeElement = eConnectXMLDocument.CreateElement("QTYONHND");
                    //NodeElement.InnerText = item["QUANTITY"].ToString();
                    //taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("AUTHCODE");
                    NodeElement.InnerText = item["AUTHCODE"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("EXPNDATE");
                    NodeElement.InnerText = ((DateTime)item["EXPNDATE"]).ToString("yyyy-MM-dd");
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("PYMTTYPE");
                    NodeElement.InnerText = item["PYMTTYPE"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("DOCNUMBR");
                    NodeElement.InnerText = item["DOCNUMBR"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USRDEFND1");
                    NodeElement.InnerText = item["USERDEF1"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF2");
                    NodeElement.InnerText = item["USERDEF2"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF3");
                    NodeElement.InnerText = item["USERDEF3"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF4");
                    NodeElement.InnerText = item["USERDEF4"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    NodeElement           = eConnectXMLDocument.CreateElement("USERDEF5");
                    NodeElement.InnerText = item["USERDEF5"].ToString();
                    taCreateSopPaymentInsertRecord.AppendChild(NodeElement);

                    taCreateSopPaymentInsertRecord_Items.AppendChild(taCreateSopPaymentInsertRecord);
                }

                NodeElement           = eConnectXMLDocument.CreateElement("PYMTRCVD");
                NodeElement.InnerText = totalPaid.ToString().Replace(",", ".").Replace(".", ".");
                taSopHdrNode.AppendChild(NodeElement);

                NodeSchema.AppendChild(taSopLine_ItemsNode);
                NodeSchema.AppendChild(taCreateSopPaymentInsertRecord_Items);
                NodeSchema.AppendChild(taSopHdrNode);

                // Document
                NodeeConnect.AppendChild(NodeSchema);
                eConnectXMLDocument.AppendChild(NodeeConnect);

                //Dim eConnectXMLDocString As String = eConnectXMLDocument.OuterXml;
                //MsgBox(eConnectXMLDocString)


                if (!GPHelper.eConnectSendToGP(eConnectXMLDocument.OuterXml, eConnectConnectionString))
                {
                    ((IEvent)(new ErrorEvent("", "", "Se detectó un error en la transacción e connect, se procederá con el rollback de la transación."))).Publish();
                    if (File.Exists(this.HistPathIn + "\\ERR_" + this.fname.Replace("\\", "")))
                    {
                        File.Delete(this.HistPathIn + "\\ERR_" + this.fname.Replace("\\", ""));
                    }
                    File.Move(this.file, this.HistPathIn + "\\ERR_" + this.fname.Replace("\\", ""));
                }
                else
                {
                    ((IEvent)(new InfoEvent("", "", "La transacción culminó satisfactoriamente."))).Publish();
                    if (File.Exists(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", "")))
                    {
                        File.Delete(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));
                    }
                    File.Move(this.file, this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));

                    /* FALTA AHCER LA CONSULTA PARA AÑADIR LA INFORMACIÓN FISCAL */
                    GPHelper.insertFiscalInfo(header["DOCNUMBE"].ToString(),
                                              header["COO"].ToString(),
                                              header["DATEGEN"].ToString(),
                                              header["SERIALPRINTER"].ToString(),
                                              StringConnection);
                    /* FALTA AHCER LA CONSULTA PARA AÑADIR LA INFORMACIÓN FISCAL */
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// ESQUEMA PARA GENERAR UNA TRANSACCIÓN EN INVENTARIO (AJUSTE)
        /// </summary>
        /// <param name="document"></param>
        public void GenerateDocument()
        {
            string eConnectConnectionString = string.Format("Initial Catalog=TSGVL;Data Source=10.1.92.203;Trusted_Connection=True");

            string queryXML = "<eConenct>";

            queryXML += "<IVInventoryTransactionType>";
            queryXML += "<taIVTransactionHeaderInsert>";
            queryXML += "<BACHNUMB>LOTEGR</BACHNUMB>";
            queryXML += "<IVDOCNBR>2</IVDOCNBR>";
            queryXML += "<IVDOCTYP>2</IVDOCTYP>";
            queryXML += "<DOCDATE>2017-08-04 21:41:09</DOCDATE>";
            queryXML += "<POSTTOGL></POSTTOGL>";
            queryXML += "<MDFUSRID></MDFUSRID>";
            queryXML += "<PTDUSRID></PTDUSRID>";
            queryXML += "<POSTEDDT></POSTEDDT>";
            queryXML += "<NOTETEXT></NOTETEXT>";
            queryXML += "<USRDEFND1>PRUEBA MIGUEL PATIÑO</USRDEFND1>";
            queryXML += "<USRDEFND2></USRDEFND2>";
            queryXML += "<USRDEFND3></USRDEFND3>";
            queryXML += "<USRDEFND4></USRDEFND4>";
            queryXML += "<USRDEFND5></USRDEFND5>";
            queryXML += "</taIVTransactionHeaderInsert>";
            queryXML += "<taIVTransactionLineInsert_Items>";
            queryXML += "<taIVTransactionLineInsert>";
            queryXML += "<IVDOCNBR>2</IVDOCNBR>";
            queryXML += "<IVDOCTYP></IVDOCTYP>";
            queryXML += "<ITEMNMBR>TTC3700C01</ITEMNMBR>";
            queryXML += "<Reason_Code></Reason_Code>";
            queryXML += "<LNSEQNBR></LNSEQNBR>";
            queryXML += "<UOFM></UOFM>";
            queryXML += "<TRXQTY>23</TRXQTY>";
            queryXML += "<UNITCOST></UNITCOST>";
            queryXML += "<TRXLOCTN></TRXLOCTN>";
            queryXML += "<IVIVINDX></IVIVINDX>";
            queryXML += "<InventoryAccount></InventoryAccount>";
            queryXML += "<IVIVOFIX></IVIVOFIX>";
            queryXML += "<InventoryAccountOffSet></InventoryAccountOffSet>";
            queryXML += "</taIVTransactionLineInsert>";
            queryXML += "<taIVTransactionLineInsert>";
            queryXML += "<IVDOCNBR>2</IVDOCNBR>";
            queryXML += "<IVDOCTYP></IVDOCTYP>";
            queryXML += "<ITEMNMBR>TTC3700C0110A62</ITEMNMBR>";
            queryXML += "<Reason_Code></Reason_Code>";
            queryXML += "<LNSEQNBR></LNSEQNBR>";
            queryXML += "<UOFM></UOFM>";
            queryXML += "<TRXQTY>23</TRXQTY>";
            queryXML += "<UNITCOST></UNITCOST>";
            queryXML += "<TRXLOCTN></TRXLOCTN>";
            queryXML += "<IVIVINDX></IVIVINDX>";
            queryXML += "<InventoryAccount></InventoryAccount>";
            queryXML += "<IVIVOFIX></IVIVOFIX>";
            queryXML += "<InventoryAccountOffSet></InventoryAccountOffSet>";
            queryXML += "</taIVTransactionLineInsert>";
            queryXML += "</taIVTransactionLineInsert_Items>";
            queryXML += "</IVInventoryTransactionType>";
            queryXML += "</eConenct>";



//            XDocument doc = new XDocument(new XElement("eConenct",
//               new XElement("IVInventoryTransactionType",
//                  new XElement("taIVTransactionHeaderInsert",
//                     new XElement("BACHNUMB", "LOTEGR"),
//                     new XElement("IVDOCNBR", document.Id),
//                     new XElement("IVDOCTYP", 2),
//                     new XElement("DOCDATE", "2017-08-04 21:41:09"),
//                     new XElement("POSTTOGL", string.Empty),
//                     new XElement("MDFUSRID", string.Empty),
//                     new XElement("PTDUSRID", string.Empty),
//                     new XElement("POSTEDDT", string.Empty),
//                     new XElement("NOTETEXT", string.Empty),
//                     new XElement("USRDEFND1", string.Empty),
//                     new XElement("USRDEFND2", string.Empty),
//                     new XElement("USRDEFND3", string.Empty),
//                     new XElement("USRDEFND4", string.Empty),
//                     new XElement("USRDEFND5", string.Empty)),
//                  new XElement("taIVTransactionLineInsert_Items", from c in document.Details
//                                                                  select
//new XElement("taIVTransactionLineInsert",
//new XElement("IVDOCNBR", c.DocumentId),
//new XElement("IVDOCTYP", string.Empty),
//new XElement("ITEMNMBR", c.ProductCode),
//new XElement("Reason_Code", string.Empty),
//new XElement("LNSEQNBR", string.Empty),
//new XElement("UOFM", string.Empty),
//new XElement("TRXQTY", string.Empty),
//new XElement("UNITCOST", string.Empty),
//new XElement("TRXLOCTN", string.Empty),
//new XElement("IVIVINDX", string.Empty),
//new XElement("InventoryAccount", string.Empty),
//new XElement("IVIVOFIX", string.Empty),
//new XElement("InventoryAccountOffSet", string.Empty)
//)))));


            if (!GPHelper.eConnectSendToGP(queryXML, eConnectConnectionString))
            {
                Console.WriteLine("Se detectó un error en la transacción e connect, se procederá con el rollback de la transación");
            }
            else
            {
                Console.WriteLine("La transacción culminó satisfactoriament");

                //if (File.Exists(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", "")))
                //{
                //    File.Delete(this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));
                //}
                //File.Move(this.file, this.HistPathIn + "\\OK_" + this.fname.Replace("\\", ""));
            }
        }