예제 #1
0
        public string insertData(ref QuickbooksQueries quickbooksQueries, string listId, string value)
        {
            string msg = "";

            XmlDocument inputItemXMLDoc;
            XmlElement  qbXMLMsgsRq;

            QuickbooksUtils.BuildXMLQueryBase(out inputItemXMLDoc, out qbXMLMsgsRq);

            // Mark as query type
            XmlElement ItemsAddRq = inputItemXMLDoc.CreateElement("DataExtAddRq");

            qbXMLMsgsRq.AppendChild(ItemsAddRq);

            XmlElement itemXML = inputItemXMLDoc.CreateElement("DataExtAdd");

            ItemsAddRq.AppendChild(itemXML);

            XmlElement itemOwnerXML = inputItemXMLDoc.CreateElement("OwnerID");

            itemOwnerXML.InnerText = "0";
            itemXML.AppendChild(itemOwnerXML);

            XmlElement itemNameXML = inputItemXMLDoc.CreateElement("DataExtName");

            itemNameXML.InnerText = "CLAVEPROD";
            itemXML.AppendChild(itemNameXML);

            XmlElement itemtypeXML = inputItemXMLDoc.CreateElement("ListDataExtType");

            itemtypeXML.InnerText = "Item";
            itemXML.AppendChild(itemtypeXML);

            XmlElement itemobjXML = inputItemXMLDoc.CreateElement("ListObjRef");

            itemXML.AppendChild(itemobjXML);

            XmlElement itemListIdXML = inputItemXMLDoc.CreateElement("ListID");

            itemListIdXML.InnerText = listId;
            itemobjXML.AppendChild(itemListIdXML);

            XmlElement itemValueXML = inputItemXMLDoc.CreateElement("DataExtValue");

            itemValueXML.InnerText = value;
            itemXML.AppendChild(itemValueXML);

            string qbResponse;

            if (quickbooksQueries.QueryQB(inputItemXMLDoc.OuterXml, out qbResponse))
            {
                QuicbooksResponse qbResultQuery = new QuicbooksResponse(qbResponse, "DataExtAddRs");
                if (qbResultQuery.GetNumberOfResulst() > 0)
                {
                    if (qbResultQuery.success)
                    {
                        msg = null;
                    }
                    else
                    {
                        msg = "No se pudo agregar el item ";
                    }
                }
                else
                {
                    msg = "Quickbooks regresó una respuesta vacía al agregar item ";
                }
            }
            else
            {
                msg = "Se produjo un error al agregar insertar item ";
            }



            return(msg);
        }
예제 #2
0
        public string InsertBill(ref QuickbooksQueries quickbooksQueries, Bill bill)
        {
            XmlDocument inputXMLDoc;
            XmlElement  qbXMLMsgsRq;

            QuickbooksUtils.BuildXMLQueryBase(out inputXMLDoc, out qbXMLMsgsRq);

            // Mark as query type
            XmlElement InvoicesAddRq = inputXMLDoc.CreateElement("BillAddRq");

            qbXMLMsgsRq.AppendChild(InvoicesAddRq);
            XmlElement invoiceXML = inputXMLDoc.CreateElement("BillAdd");

            InvoicesAddRq.AppendChild(invoiceXML);

            XmlElement vendorRef    = inputXMLDoc.CreateElement("VendorRef");
            XmlElement vendorListID = inputXMLDoc.CreateElement("ListID");

            vendorListID.InnerText = vendor.listId;
            vendorRef.AppendChild(vendorListID);
            invoiceXML.AppendChild(vendorRef);

            XmlElement txnDate  = inputXMLDoc.CreateElement("TxnDate");
            string     billDate = bill.fecha.ToString("yyyy-MM-dd");

            txnDate.InnerText = billDate;
            invoiceXML.AppendChild(txnDate);


            bool billExists = quickbooksQueries.QueryExistingBill(billDate, bill.uuid);

            if (billExists)
            {
                return("La factura ya existe");
            }
            else
            {
                XmlElement refNumber      = inputXMLDoc.CreateElement("RefNumber");
                string     folioAndSeries = bill.serie.Trim() + bill.folio.Trim();
                refNumber.InnerText = folioAndSeries.Substring(0, Math.Min(19, folioAndSeries.Length));
                invoiceXML.AppendChild(refNumber);

                XmlElement memo = inputXMLDoc.CreateElement("Memo");
                memo.InnerText = bill.uuid;
                invoiceXML.AppendChild(memo);

                if (bill.moneda != "mxn")
                {
                    XmlElement exchangeRate = inputXMLDoc.CreateElement("ExchangeRate");
                    exchangeRate.InnerText = bill.tipoCambio.ToString();
                    invoiceXML.AppendChild(exchangeRate);
                }

                foreach (BillLineItem billLineItem in bill.conceptos)
                {
                    invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.Concepto, billLineItem.importe, ref quickbooksQueries, billLineItem.claveprodserv, billLineItem.descripcion, billLineItem.cantidad));
                }



                // Agregar cada tipo de impuesto

                /*
                 * string claveprodserv = "0";
                 * if (bill.descuento != 0)
                 * {
                 *  invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.Descuentos, -bill.descuento, ref quickbooksQueries, claveprodserv, "Descuento"));
                 * }
                 */
                string claveprodserv;
                if (bill.retencionesIVA != 0)
                {
                    claveprodserv = "IMPUESTOS002BR";
                    invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.RetencionesIVA, -bill.retencionesIVA, ref quickbooksQueries, claveprodserv, "Retenciones IVA", 1));
                }
                if (bill.retencionesISR != 0)
                {
                    claveprodserv = "IMPUESTOS001BR";
                    invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.RetencionesISR, -bill.retencionesISR, ref quickbooksQueries, claveprodserv, "Retenciones ISR", 1));
                }
                if (bill.trasladosIVA != 0)
                {
                    claveprodserv = "IMPUESTOS002IT";
                    invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.TrasladosIVA, bill.trasladosIVA, ref quickbooksQueries, claveprodserv, "Traslados IVA", 1));
                }
                if (bill.trasladosIEPS != 0)
                {
                    claveprodserv = "IMPUESTOS003BT";
                    invoiceXML.AppendChild(CreateBillLine(ref inputXMLDoc, BillLineItemType.TrasladosIEPS, bill.trasladosIEPS, ref quickbooksQueries, claveprodserv, "Traslados IEPS", 1));
                }

                string updateResponse;
                if (quickbooksQueries.QueryQB(inputXMLDoc.OuterXml, out updateResponse))
                {
                    QuicbooksResponse qbResultUpdateInvoice = new QuicbooksResponse(updateResponse, "BillAddRs");
                    if (qbResultUpdateInvoice.GetNumberOfResulst() > 0)
                    {
                        if (qbResultUpdateInvoice.success)
                        {
                            return(null);
                        }
                        else
                        {
                            return("No se puedo agregar bill " + bill.uuid + " proveedor " + vendor.nombre);
                        }
                    }
                    else
                    {
                        return("Quickbooks regresó una respuesta vacía al agregar bill " + bill.uuid + " proveedor " + vendor.nombre);
                    }
                }
                else
                {
                    return("Se produjo un error al agregar insertar bill " + bill.uuid + " proveedor " + vendor.nombre + ": " + quickbooksQueries.lastError);
                }
            }
        }
예제 #3
0
        public string InsertUom(ref QuickbooksQueries quickbooksQueries, ref BillLineItem item)
        {
            XmlDocument inputXMLDoc;
            XmlElement  qbXMLMsgsRq;

            QuickbooksUtils.BuildXMLQueryBase(out inputXMLDoc, out qbXMLMsgsRq);

            // Mark as query type
            XmlElement InvoicesAddRq = inputXMLDoc.CreateElement("UnitOfMeasureSetAddRq");

            qbXMLMsgsRq.AppendChild(InvoicesAddRq);
            XmlElement invoiceXML = inputXMLDoc.CreateElement("UnitOfMeasureSetAdd");

            InvoicesAddRq.AppendChild(invoiceXML);

            XmlElement name = inputXMLDoc.CreateElement("Name");

            name.InnerText = item.unidad.Substring(0, Math.Min(30, item.unidad.Length));
            invoiceXML.AppendChild(name);

            XmlElement unitType = inputXMLDoc.CreateElement("UnitOfMeasureType");

            unitType.InnerText = "Other";
            invoiceXML.AppendChild(unitType);

            XmlElement baseUnit = inputXMLDoc.CreateElement("BaseUnit");

            invoiceXML.AppendChild(baseUnit);

            XmlElement baseUnitName = inputXMLDoc.CreateElement("Name");

            baseUnitName.InnerText = item.unidad.Substring(0, Math.Min(30, item.unidad.Length));
            baseUnit.AppendChild(baseUnitName);

            XmlElement abbr = inputXMLDoc.CreateElement("Abbreviation");

            abbr.InnerText = item.claveunidad;
            baseUnit.AppendChild(abbr);

            string   updateResponse;
            UomAdder uomAdder = new UomAdder();

            if (quickbooksQueries.QueryQB(inputXMLDoc.OuterXml, out updateResponse))
            {
                QuicbooksResponse qbResultUpdateInvoice = new QuicbooksResponse(updateResponse, "UnitOfMeasureSetAddRs");
                if (qbResultUpdateInvoice.GetNumberOfResulst() > 0)
                {
                    if (qbResultUpdateInvoice.success)
                    {
                        // Grab the ListID for the new vendor
                        //XmlNode ClientNode = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes.Item(0);
                        //msg = "Item created";
                        XmlNodeList responseNodeList = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes;
                        foreach (XmlNode responseNode in responseNodeList)
                        {
                            UnitMeasure newUom = new UnitMeasure();

                            //Here is some weird behavior
                            foreach (XmlNode childNode in responseNode.ChildNodes)
                            {
                                if (childNode.Name == "ListID")
                                {
                                    newUom.listId = childNode.InnerText;
                                }
                                if (childNode.Name == "Name")
                                {
                                    newUom.name = childNode.InnerText;
                                }
                            }


                            if (responseNode["BaseUnit"] != null)
                            {
                                foreach (XmlNode DataRowNode in responseNode["BaseUnit"])
                                {
                                    if (DataRowNode.Name == "Name")
                                    {
                                        newUom.baseUnitName = DataRowNode.InnerText;
                                    }
                                    if (DataRowNode.Name == "Abbreviation")
                                    {
                                        newUom.abbreviation = DataRowNode.InnerText;
                                    }
                                }
                            }

                            if (!String.IsNullOrEmpty(newUom.abbreviation))
                            {
                                //itemlistId = new_item.listId;
                                //Items[new_item.productKey] = new_item;
                                quickbooksQueries.Uoms[newUom.abbreviation] = newUom;
                                return(null);
                            }
                            else
                            {
                                return("Item no tiene List id " + newUom.name);
                            }
                        }
                    }
                    else
                    {
                        //Random rnd = new Random();
                        //Makes recursive insertion tries 5 times // Misssing loop of 5 :/
                        //client.nombre = client.nombre + " - " + rnd.ToString();
                        //string clientAdderResult = clientAdder.InsertClient(ref quickbooksQueries, ref client);
                        //string msg = "No se puede agregar proveedor " + ;
                        //string msg; msg = "Agregado " + vendor.nombre;
                        return("No se puede agregar unit");
                    }
                }
                else
                {
                    return("Quickbooks regresó una respuesta vacía al agregar " + item.descripcion);
                }
            }
            else
            {
                return("Se produjo un error al agregar insertar " + item.descripcion + ": " + quickbooksQueries.lastError);
            }
            return("ERror");
        }
예제 #4
0
        public string InsertVendor(ref QuickbooksQueries quickbooksQueries, ref Vendor vendor, int recursive_int = 1)
        {
            XmlDocument inputXMLDoc;
            XmlElement  qbXMLMsgsRq;

            QuickbooksUtils.BuildXMLQueryBase(out inputXMLDoc, out qbXMLMsgsRq);

            // Mark as query type
            XmlElement InvoicesAddRq = inputXMLDoc.CreateElement("VendorAddRq");

            qbXMLMsgsRq.AppendChild(InvoicesAddRq);
            XmlElement invoiceXML = inputXMLDoc.CreateElement("VendorAdd");

            InvoicesAddRq.AppendChild(invoiceXML);

            XmlElement companyName = inputXMLDoc.CreateElement("Name");

            companyName.InnerText = vendor.nombre.Substring(0, Math.Min(40, vendor.nombre.Length));
            invoiceXML.AppendChild(companyName);

            XmlElement vendorAddress = inputXMLDoc.CreateElement("VendorAddress");

            if (!String.IsNullOrWhiteSpace(vendor.calle + vendor.noInterior + vendor.noExterior))
            {
                XmlElement addr1     = inputXMLDoc.CreateElement("Addr1");
                string     addr1Full = ((vendor.calle.Trim() + " " + vendor.noInterior).Trim() + " " + vendor.noExterior).Trim();
                addr1.InnerText = addr1Full.Substring(0, Math.Min(40, addr1Full.Length));
                vendorAddress.AppendChild(addr1);
            }

            if (!String.IsNullOrWhiteSpace(vendor.colonia))
            {
                XmlElement addr2     = inputXMLDoc.CreateElement("Addr2");
                string     addr2Full = vendor.colonia.Trim();
                addr2.InnerText = addr2Full.Substring(0, Math.Min(40, addr2Full.Length));
                vendorAddress.AppendChild(addr2);
            }

            if (!String.IsNullOrWhiteSpace(vendor.municipio))
            {
                XmlElement city = inputXMLDoc.CreateElement("City");
                city.InnerText = vendor.municipio.Substring(0, Math.Min(30, vendor.municipio.Length));;
                vendorAddress.AppendChild(city);
            }

            if (!String.IsNullOrWhiteSpace(vendor.estado))
            {
                XmlElement state = inputXMLDoc.CreateElement("State");
                state.InnerText = vendor.estado.Substring(0, Math.Min(30, vendor.estado.Length));;
                vendorAddress.AppendChild(state);
            }

            if (!String.IsNullOrWhiteSpace(vendor.codigoPostal))
            {
                XmlElement postalCode = inputXMLDoc.CreateElement("PostalCode");
                postalCode.InnerText = vendor.codigoPostal.Substring(0, Math.Min(10, vendor.codigoPostal.Length));
                vendorAddress.AppendChild(postalCode);
            }

            invoiceXML.AppendChild(vendorAddress);

            XmlElement accountNumber = inputXMLDoc.CreateElement("AccountNumber");

            accountNumber.InnerText = vendor.rfc;
            invoiceXML.AppendChild(accountNumber);

            /*aqui puede ser*/


            if (vendor.rfc.Contains("XEXX010101000"))
            {
                XmlElement currencyRef   = inputXMLDoc.CreateElement("CurrencyRef");
                XmlElement currencyRefId = inputXMLDoc.CreateElement("ListID");
                currencyRefId.InnerText = quickbooksQueries.Currencies["US Dollar"].listId;
                /*currencyRefId.InnerText = quickbooksQueries.Currencies["Mexican Peso"].listId;*/
                currencyRef.AppendChild(currencyRefId);
                invoiceXML.AppendChild(currencyRef);
            }



            string      updateResponse;
            VendorAdder vendorAdder = new VendorAdder();

            if (quickbooksQueries.QueryQB(inputXMLDoc.OuterXml, out updateResponse))
            {
                QuicbooksResponse qbResultUpdateInvoice = new QuicbooksResponse(updateResponse, "VendorAddRs");
                if (qbResultUpdateInvoice.GetNumberOfResulst() > 0)
                {
                    if (qbResultUpdateInvoice.success)
                    {
                        // Grab the ListID for the new vendor
                        XmlNode VendorNode = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes.Item(0);
                        if (VendorNode["ListID"] != null)
                        {
                            vendor.listId = VendorNode["ListID"].InnerText;
                            return(null);
                        }
                        else
                        {
                            return("Vendor no tiene ListID: " + vendor.nombre);
                        }
                    }
                    else
                    {
                        if (recursive_int < 7)
                        {
                            ++recursive_int;
                            vendor.nombre = vendor.nombre + " - " + recursive_int.ToString();
                            string vendorAdderResult = vendorAdder.InsertVendor(ref quickbooksQueries, ref vendor, recursive_int);
                            //string msg = "No se puede agregar proveedor " + ;
                            //string msg; msg = "Agregado " + vendor.nombre;

                            return(vendorAdderResult);
                        }
                        else
                        {
                            return("No se puede agregar Proveedor " + vendor.nombre);
                        }
                    }
                }
                else
                {
                    return("Quickbooks regresó una respuesta vacía al agregar " + vendor.nombre);
                }
            }
            else
            {
                return("Se produjo un error al agregar insertar " + vendor.nombre + ": " + quickbooksQueries.lastError);
            }
        }
예제 #5
0
        public string InsertClient(ref QuickbooksQueries quickbooksQueries, ref Client client, int recursive_int = 1, string moneda = "mxn")
        {
            XmlDocument inputXMLDoc;
            XmlElement  qbXMLMsgsRq;

            QuickbooksUtils.BuildXMLQueryBase(out inputXMLDoc, out qbXMLMsgsRq);

            // Mark as query type
            XmlElement InvoicesAddRq = inputXMLDoc.CreateElement("CustomerAddRq");

            qbXMLMsgsRq.AppendChild(InvoicesAddRq);
            XmlElement invoiceXML = inputXMLDoc.CreateElement("CustomerAdd");

            InvoicesAddRq.AppendChild(invoiceXML);

            XmlElement companyName = inputXMLDoc.CreateElement("Name");

            companyName.InnerText = client.nombre.Substring(0, Math.Min(40, client.nombre.Length));
            invoiceXML.AppendChild(companyName);

            XmlElement accountNumber = inputXMLDoc.CreateElement("AccountNumber");

            accountNumber.InnerText = client.rfc;
            invoiceXML.AppendChild(accountNumber);
            /*aqui puede ser*/
            /*Aqui tambien agrega*/

            /*if (client.rfc.Contains("XEXX010101000"))*/
            if (moneda != "mxn")
            {
                XmlElement currencyRef   = inputXMLDoc.CreateElement("CurrencyRef");
                XmlElement currencyRefId = inputXMLDoc.CreateElement("ListID");
                /* currencyRefId.InnerText = quickbooksQueries.Currencies["Mexican Peso"].listId;*/
                currencyRefId.InnerText = quickbooksQueries.Currencies["US Dollar"].listId;
                currencyRef.AppendChild(currencyRefId);
                invoiceXML.AppendChild(currencyRef);
            }

            string      updateResponse;
            ClientAdder clientAdder = new ClientAdder();

            if (quickbooksQueries.QueryQB(inputXMLDoc.OuterXml, out updateResponse))
            {
                QuicbooksResponse qbResultUpdateInvoice = new QuicbooksResponse(updateResponse, "CustomerAddRs");
                if (qbResultUpdateInvoice.GetNumberOfResulst() > 0)
                {
                    if (qbResultUpdateInvoice.success)
                    {
                        // Grab the ListID for the new vendor
                        XmlNode ClientNode = qbResultUpdateInvoice.GetXmlNodeList().Item(0).ChildNodes.Item(0);
                        if (ClientNode["ListID"] != null)
                        {
                            client.listId = ClientNode["ListID"].InnerText;
                            return(null);
                        }
                        else
                        {
                            return("Customer no tiene ListID: " + client.nombre);
                        }
                    }
                    else
                    {
                        if (recursive_int < 7)
                        {
                            ++recursive_int;
                            client.nombre = client.nombre + " - " + recursive_int.ToString();
                            string clientAdderResult = clientAdder.InsertClient(ref quickbooksQueries, ref client, recursive_int);

                            return(clientAdderResult);
                        }
                        else
                        {
                            return("No se puede agregar cliente " + client.nombre);
                        }
                    }
                }
                else
                {
                    return("Quickbooks regresó una respuesta vacía al agregar " + client.nombre);
                }
            }
            else
            {
                return("Se produjo un error al agregar insertar " + client.nombre + ": " + quickbooksQueries.lastError);
            }
        }