public CustomFieldRef[] GetCustomerFields(ContactDTO contact, LineDTO line, NetSuiteApi api)
 {
     return new CustomFieldRef[]
     {
         new StringCustomFieldRef
         {
             scriptId = "custentity_l54_tipo_documento",
             value = getDocumentType(contact, api)
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_l54_nombre_legal",
             value = contact.ContactPerson
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_l54_tipo_contribuyente",
             value = "1" // consumidor final
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_l54_cuit_entity",
             value = getVatRegNumber(contact) // el cuit de vuelta, igual que vatregnumber
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_clase_cuenta",
             value = "15" // consumidor final
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_canal",
             value = "3" // consumidor final
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_subcanal",
             value = "3" // mercadolibre
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_tipocliente",
             value = this.getTypeOfClient(line, api)
         },
         new StringCustomFieldRef
         {
             scriptId = "custentity_3k_usuarioweb",
             value = contact.Name
         },
     };
 }
        /// <summary>
        /// Builds the address of a contact or returns null if he doesn't have one.
        /// </summary>
        private Address buildAddress(ContactDTO contact)
        {
            var location = contact.Location;
            if (location == null) return null;

            var address = new Address
            {
                city = location.City,
                zip = location.ZipCode,
                addr1 = location.StreetName,
                addr2 = location.StreetNumber,
                attention = (location.AddressNotes ?? "").TrimAndLimit(100),
                addrPhone = new String(contact.PhoneNumber.Where(Char.IsDigit).ToArray())
            };

            this.api.Integration.TransformAddress(address, location, this.api);
            return address;
        }
 private string getVatRegNumber(ContactDTO contact)
 {
     var cleanTaxId = getCleanTaxId(contact);
     return cleanTaxId.Length == 0 ? "0" : cleanTaxId;
 }
        private string getDocumentType(ContactDTO contact, NetSuiteApi api)
        {
            var cleanTaxId = getCleanTaxId(contact);
            var dniTypeByCountry = getCountry(api).DocumentType;
            var isACUIT = cleanTaxId.Length == 11;
            var isFromArgentina = getCountry(api).GetType() == typeof(ArgentinaGrupoIkonoCountry);

            if (cleanTaxId.Length == 0)
                return "10";

            return isACUIT && isFromArgentina
                ? "2"
                : dniTypeByCountry;
        }
 private string getCleanTaxId(ContactDTO contact)
 {
     return contact.TaxId == null ? "" : new String(contact.TaxId.Where(Char.IsDigit).ToArray());
 }
 public void TransformCustomer(Customer netSuiteCustomer, ContactDTO contact, NetSuiteApi api)
 {
     netSuiteCustomer.firstName = contact.ContactPerson.ToUpper();
     netSuiteCustomer.lastName = ".";
     netSuiteCustomer.category = new RecordRef { internalId = "15" }; // consumidor final
     netSuiteCustomer.salesRep = new RecordRef { internalId = "10260" }; // vendedor e-commerce
     netSuiteCustomer.campaignCategory = new RecordRef { internalId = "-4" };
     netSuiteCustomer.subsidiary = new RecordRef { internalId = getCountry(api).Subsidiary };
     netSuiteCustomer.leadSource = new RecordRef { internalId = "4" }; // mercadolibre
     netSuiteCustomer.priceLevel = new RecordRef { internalId = "14" }; // precio base
     netSuiteCustomer.terms = new RecordRef { internalId = "22" }; //mercadopago
     netSuiteCustomer.vatRegNumber = this.getVatRegNumber(contact);
     // ^ es válido poner 0 acá si en el custentity_l54_tipo_documento es 10 ("sin identificar")
 }
 public CustomFieldRef[] GetCustomerFields(ContactDTO contact, LineDTO line, NetSuiteApi api)
 {
     return new CustomFieldRef[0];
 }
 public void TransformCustomer(Customer netSuiteCustomer, ContactDTO contact, NetSuiteApi api)
 {
     netSuiteCustomer.comments = contact.TaxId;
     netSuiteCustomer.receivablesAccount = new RecordRef {internalId = "1229"}; // MercadoLibre
 }
        /// <summary>
        /// Gets or create a customer. Returns its internal id.
        /// </summary>
        private Customer getOrCreateCustomer(ContactDTO contact, Address address, LineDTO line, out bool created)
        {
            if (contact.ContactPerson == null)
                throw new ApplicationException("The contact doesn't have a contact person");

            Func<Customer> getCustomer = () =>
                api.SearchOne(new CustomerSearch
                {
                    basic = new CustomerSearchBasic
                    {
                        email = new SearchStringField
                        {
                            @operator = SearchStringFieldOperator.@is,
                            operatorSpecified = true,
                            searchValue = contact.Mail.TrimAndLimit(100)
                        }
                    }
                }, true);

            try {
                created = false;
                return getCustomer();
            } catch (InvalidOperationException) {
                var customer = new Customer
                {
                    firstName = contact.Name.TrimAndLimit(32),
                    lastName = contact.ContactPerson.TrimAndLimit(32),
                    email = contact.Mail.TrimAndLimit(100),
                    phone = new String(contact.PhoneNumber.Where(Char.IsDigit).ToArray()),
                    isPerson = true,
                    isPersonSpecified = true,
                    addressbookList = new CustomerAddressbookList
                    {
                        addressbook = new[]
                            {
                                this.api.Integration.TransformAddressbook(new CustomerAddressbook
                                {
                                    addressbookAddress = address,
                                    defaultBilling = true,
                                    defaultBillingSpecified = true,
                                    isResidential = true,
                                    isResidentialSpecified = true
                                })
                            },
                        replaceAll = true
                    },
                    customFieldList = this.api.Integration.GetCustomerFields(contact, line, this.api)
                };
                this.api.Integration.TransformCustomer(customer, contact, this.api);

                api.Query<WriteResponse>(() =>
                    api.Service.add(customer)
                );

                created = true;
                return getCustomer();
            }
        }