diff --git a/app/models/address.rb b/app/models/address.rb new file mode 100644 index 000000000..5ceadb097 --- /dev/null +++ b/app/models/address.rb @@ -0,0 +1,9 @@ +class Address < ApplicationRecord + belongs_to :country + belongs_to :geo_state, optional: true, foreign_key: 'state_id' + + validates :street_address, :country_id, :geo_lat, :geo_long, presence: true + + has_many :divisions + has_many :organizations +end diff --git a/app/models/country.rb b/app/models/country.rb index f3c125471..28d75b387 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -1,6 +1,9 @@ class Country < ApplicationRecord belongs_to :default_currency, class_name: 'Currency' + has_many :addresses + has_many :geo_states + def division Division.root # for permissions purposes, assume country model belongs to root division end diff --git a/app/models/division.rb b/app/models/division.rb index 47704c2ed..69f094666 100644 --- a/app/models/division.rb +++ b/app/models/division.rb @@ -38,6 +38,8 @@ class Division < ApplicationRecord belongs_to :organization # the organization which represents this loan agent division + belongs_to :address, optional: true + mount_uploader :logo, LogoUploader validate :parent_division_and_name diff --git a/app/models/geo_state.rb b/app/models/geo_state.rb new file mode 100644 index 000000000..4827fe0df --- /dev/null +++ b/app/models/geo_state.rb @@ -0,0 +1,8 @@ +class GeoState < ApplicationRecord + belongs_to :country + + has_many :addresses + + validates :country_id, presence: true + validates :name, presence: true +end diff --git a/app/models/organization.rb b/app/models/organization.rb index faa8fd7c1..9e453087a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -10,6 +10,7 @@ class Organization < ApplicationRecord belongs_to :division belongs_to :country belongs_to :primary_contact, class_name: 'Person' + belongs_to :address, optional: true has_many :loans, dependent: :destroy has_many :people, foreign_key: :primary_organization_id, dependent: :nullify diff --git a/db/migrate/20240517190510_create_geo_states.rb b/db/migrate/20240517190510_create_geo_states.rb new file mode 100644 index 000000000..52f8dd47a --- /dev/null +++ b/db/migrate/20240517190510_create_geo_states.rb @@ -0,0 +1,971 @@ +class CreateGeoStates < ActiveRecord::Migration[6.1] + def change + create_table :geo_states do |t| + t.integer :country_id, null: false + t.string :name, null: false + + t.timestamps + end + + add_foreign_key :geo_states, :countries, column: :country_id + + #Provincias de Argentina + GeoState.find_or_create_by(id: 1) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Ciudad autónoma de Buenos Aires' + end + + GeoState.find_or_create_by(id: 2) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Buenos Aires' + end + + GeoState.find_or_create_by(id: 3) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Catamarca' + end + + GeoState.find_or_create_by(id: 4) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Chaco' + end + + GeoState.find_or_create_by(id: 5) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Chubut' + end + + GeoState.find_or_create_by(id: 6) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Córdoba' + end + + GeoState.find_or_create_by(id: 7) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Corrientes' + end + + GeoState.find_or_create_by(id: 8) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Entre Ríos' + end + + GeoState.find_or_create_by(id: 9) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Formosa' + end + + GeoState.find_or_create_by(id: 10) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Jujuy' + end + + GeoState.find_or_create_by(id: 11) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'La Pampa' + end + + GeoState.find_or_create_by(id: 12) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'La Rioja' + end + + GeoState.find_or_create_by(id: 13) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Mendoza' + end + + GeoState.find_or_create_by(id: 14) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Misiones' + end + + GeoState.find_or_create_by(id: 15) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Neuquén' + end + + GeoState.find_or_create_by(id: 16) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Río Negro' + end + + GeoState.find_or_create_by(id: 17) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Salta' + end + + GeoState.find_or_create_by(id: 18) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'San Juan' + end + + GeoState.find_or_create_by(id: 19) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'San Luis' + end + + GeoState.find_or_create_by(id: 20) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Santa Cruz' + end + + GeoState.find_or_create_by(id: 21) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Santa Fe' + end + + GeoState.find_or_create_by(id: 22) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Santiago del Estero' + end + + GeoState.find_or_create_by(id: 23) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Tierra del Fuego' + end + + GeoState.find_or_create_by(id: 24) do |geo_state| + geo_state.country_id = 1 + geo_state.name = 'Tucumán' + end + + # Departamentos de Nicaragua + GeoState.find_or_create_by(id: 25) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Boaco' + end + + GeoState.find_or_create_by(id: 26) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Carazo' + end + + GeoState.find_or_create_by(id: 27) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Chinandega' + end + + GeoState.find_or_create_by(id: 28) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Chontales' + end + + GeoState.find_or_create_by(id: 29) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Costa Caribe Norte' + end + + GeoState.find_or_create_by(id: 30) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Costa Caribe Sur' + end + + GeoState.find_or_create_by(id: 31) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Estelí' + end + + GeoState.find_or_create_by(id: 32) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Granada' + end + + GeoState.find_or_create_by(id: 33) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Jinotega' + end + + GeoState.find_or_create_by(id: 34) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'León' + end + + GeoState.find_or_create_by(id: 35) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Madriz' + end + + GeoState.find_or_create_by(id: 36) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Managua' + end + + GeoState.find_or_create_by(id: 37) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Masaya' + end + + GeoState.find_or_create_by(id: 38) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Matagalpa' + end + + GeoState.find_or_create_by(id: 39) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Nueva Segovia' + end + + GeoState.find_or_create_by(id: 40) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Rivas' + end + + GeoState.find_or_create_by(id: 41) do |geo_state| + geo_state.country_id = 2 + geo_state.name = 'Río San Juan' + end + + # Estados de United States + GeoState.find_or_create_by(id: 42) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Alabama' + end + + GeoState.find_or_create_by(id: 43) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Alaska' + end + + GeoState.find_or_create_by(id: 44) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Arizona' + end + + GeoState.find_or_create_by(id: 45) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Arkansas' + end + + GeoState.find_or_create_by(id: 46) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'California' + end + + GeoState.find_or_create_by(id: 47) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Colorado' + end + + GeoState.find_or_create_by(id: 48) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Connecticut' + end + + GeoState.find_or_create_by(id: 49) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Delaware' + end + + GeoState.find_or_create_by(id: 50) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Florida' + end + + GeoState.find_or_create_by(id: 51) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Georgia' + end + + GeoState.find_or_create_by(id: 52) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Hawaii' + end + + GeoState.find_or_create_by(id: 53) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Idaho' + end + + GeoState.find_or_create_by(id: 54) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Illinois' + end + + GeoState.find_or_create_by(id: 55) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Indiana' + end + + GeoState.find_or_create_by(id: 56) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Iowa' + end + + GeoState.find_or_create_by(id: 57) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Kansas' + end + + GeoState.find_or_create_by(id: 58) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Kentucky' + end + + GeoState.find_or_create_by(id: 59) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Louisiana' + end + + GeoState.find_or_create_by(id: 60) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Maine' + end + + GeoState.find_or_create_by(id: 61) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Maryland' + end + + GeoState.find_or_create_by(id: 62) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Massachusetts' + end + + GeoState.find_or_create_by(id: 63) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Michigan' + end + + GeoState.find_or_create_by(id: 64) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Minnesota' + end + + GeoState.find_or_create_by(id: 65) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Mississippi' + end + + GeoState.find_or_create_by(id: 66) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Missouri' + end + + GeoState.find_or_create_by(id: 67) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Montana' + end + + GeoState.find_or_create_by(id: 68) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Nebraska' + end + + GeoState.find_or_create_by(id: 69) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Nevada' + end + + GeoState.find_or_create_by(id: 70) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'New Hampshire' + end + + GeoState.find_or_create_by(id: 71) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'New Jersey' + end + + GeoState.find_or_create_by(id: 72) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'New Mexico' + end + + GeoState.find_or_create_by(id: 73) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'New York' + end + + GeoState.find_or_create_by(id: 74) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'North Carolina' + end + + GeoState.find_or_create_by(id: 75) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'North Dakota' + end + + GeoState.find_or_create_by(id: 76) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Ohio' + end + + GeoState.find_or_create_by(id: 77) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Oklahoma' + end + + GeoState.find_or_create_by(id: 78) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Oregon' + end + + GeoState.find_or_create_by(id: 79) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Pennsylvania' + end + + GeoState.find_or_create_by(id: 80) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Rhode Island' + end + + GeoState.find_or_create_by(id: 81) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'South Carolina' + end + + GeoState.find_or_create_by(id: 82) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'South Dakota' + end + + GeoState.find_or_create_by(id: 83) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Tennessee' + end + + GeoState.find_or_create_by(id: 84) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Texas' + end + + GeoState.find_or_create_by(id: 85) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Utah' + end + + GeoState.find_or_create_by(id: 86) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Vermont' + end + + GeoState.find_or_create_by(id: 87) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Virginia' + end + + GeoState.find_or_create_by(id: 88) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Washington' + end + + GeoState.find_or_create_by(id: 89) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'West Virginia' + end + + GeoState.find_or_create_by(id: 90) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Wisconsin' + end + + GeoState.find_or_create_by(id: 91) do |geo_state| + geo_state.country_id = 3 + geo_state.name = 'Wyoming' + end + + # Estados de Mexico + GeoState.find_or_create_by(id: 92) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Aguascalientes' + end + + GeoState.find_or_create_by(id: 93) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Baja California' + end + + GeoState.find_or_create_by(id: 94) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Baja California Sur' + end + + GeoState.find_or_create_by(id: 95) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Campeche' + end + + GeoState.find_or_create_by(id: 96) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Chiapas' + end + + GeoState.find_or_create_by(id: 97) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Chihuahua' + end + + GeoState.find_or_create_by(id: 98) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Coahuila' + end + + GeoState.find_or_create_by(id: 99) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Colima' + end + + GeoState.find_or_create_by(id: 100) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Durango' + end + + GeoState.find_or_create_by(id: 101) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Guanajuato' + end + + GeoState.find_or_create_by(id: 102) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Guerrero' + end + + GeoState.find_or_create_by(id: 103) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Hidalgo' + end + + GeoState.find_or_create_by(id: 104) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Jalisco' + end + + GeoState.find_or_create_by(id: 105) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Mexico' + end + + GeoState.find_or_create_by(id: 106) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Mexico City' + end + + GeoState.find_or_create_by(id: 107) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Michoacán' + end + + GeoState.find_or_create_by(id: 108) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Morelos' + end + + GeoState.find_or_create_by(id: 109) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Nayarit' + end + + GeoState.find_or_create_by(id: 110) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Nuevo León' + end + + GeoState.find_or_create_by(id: 111) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Oaxaca' + end + + GeoState.find_or_create_by(id: 112) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Puebla' + end + + GeoState.find_or_create_by(id: 113) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Querétaro' + end + + GeoState.find_or_create_by(id: 114) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Quintana Roo' + end + + GeoState.find_or_create_by(id: 115) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'San Luis Potosí' + end + + GeoState.find_or_create_by(id: 116) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Sinaloa' + end + + GeoState.find_or_create_by(id: 117) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Sonora' + end + + GeoState.find_or_create_by(id: 118) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Tabasco' + end + + GeoState.find_or_create_by(id: 119) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Tamaulipas' + end + + GeoState.find_or_create_by(id: 120) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Tlaxcala' + end + + GeoState.find_or_create_by(id: 121) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Veracruz' + end + + GeoState.find_or_create_by(id: 122) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Yucatán' + end + + GeoState.find_or_create_by(id: 123) do |geo_state| + geo_state.country_id = 4 + geo_state.name = 'Zacatecas' + end + + # Departamentos de Guatemala + GeoState.find_or_create_by(id: 124) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Alta Verapaz' + end + + GeoState.find_or_create_by(id: 125) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Baja Verapaz' + end + + GeoState.find_or_create_by(id: 126) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Chimaltenango' + end + + GeoState.find_or_create_by(id: 127) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Chiquimula' + end + + GeoState.find_or_create_by(id: 128) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'El Progreso' + end + + GeoState.find_or_create_by(id: 129) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Escuintla' + end + + GeoState.find_or_create_by(id: 130) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Guatemala Department' + end + + GeoState.find_or_create_by(id: 131) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Huehuetenango' + end + + GeoState.find_or_create_by(id: 132) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Izabal' + end + + GeoState.find_or_create_by(id: 133) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Jalapa' + end + + GeoState.find_or_create_by(id: 134) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Jutiapa' + end + + GeoState.find_or_create_by(id: 135) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Petén' + end + + GeoState.find_or_create_by(id: 136) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Quetzaltenango' + end + + GeoState.find_or_create_by(id: 137) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Quiché' + end + + GeoState.find_or_create_by(id: 138) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Retalhuleu' + end + + GeoState.find_or_create_by(id: 139) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Sacatepéquez' + end + + GeoState.find_or_create_by(id: 140) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'San Marcos' + end + + GeoState.find_or_create_by(id: 141) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Santa Rosa' + end + + GeoState.find_or_create_by(id: 142) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Sololá' + end + + GeoState.find_or_create_by(id: 143) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Suchitepéquez' + end + + GeoState.find_or_create_by(id: 144) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Totonicapán' + end + + GeoState.find_or_create_by(id: 145) do |geo_state| + geo_state.country_id = 5 + geo_state.name = 'Zacapa' + end + + # Provincias de South Africa + GeoState.find_or_create_by(id: 146) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Eastern Cape' + end + + GeoState.find_or_create_by(id: 147) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Free State' + end + + GeoState.find_or_create_by(id: 148) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Gauteng' + end + + GeoState.find_or_create_by(id: 149) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'KwaZulu-Natal' + end + + GeoState.find_or_create_by(id: 150) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Limpopo' + end + + GeoState.find_or_create_by(id: 151) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Mpumalanga' + end + + GeoState.find_or_create_by(id: 152) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'North West' + end + + GeoState.find_or_create_by(id: 153) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Northern Cape' + end + + GeoState.find_or_create_by(id: 154) do |geo_state| + geo_state.country_id = 6 + geo_state.name = 'Western Cape' + end + + # Estados de India + GeoState.find_or_create_by(id: 155) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Andhra Pradesh' + end + + GeoState.find_or_create_by(id: 156) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Arunachal Pradesh' + end + + GeoState.find_or_create_by(id: 157) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Assam' + end + + GeoState.find_or_create_by(id: 158) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Bihar' + end + + GeoState.find_or_create_by(id: 159) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Chhattisgarh' + end + + GeoState.find_or_create_by(id: 160) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Goa' + end + + GeoState.find_or_create_by(id: 161) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Gujarat' + end + + GeoState.find_or_create_by(id: 162) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Haryana' + end + + GeoState.find_or_create_by(id: 163) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Himachal Pradesh' + end + + GeoState.find_or_create_by(id: 164) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Jharkhand' + end + + GeoState.find_or_create_by(id: 165) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Karnataka' + end + + GeoState.find_or_create_by(id: 166) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Kerala' + end + + GeoState.find_or_create_by(id: 167) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Madhya Pradesh' + end + + GeoState.find_or_create_by(id: 168) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Maharashtra' + end + + GeoState.find_or_create_by(id: 169) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Manipur' + end + + GeoState.find_or_create_by(id: 170) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Meghalaya' + end + + GeoState.find_or_create_by(id: 171) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Mizoram' + end + + GeoState.find_or_create_by(id: 172) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Nagaland' + end + + GeoState.find_or_create_by(id: 173) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Odisha' + end + + GeoState.find_or_create_by(id: 174) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Punjab' + end + + GeoState.find_or_create_by(id: 175) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Rajasthan' + end + + GeoState.find_or_create_by(id: 176) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Sikkim' + end + + GeoState.find_or_create_by(id: 177) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Tamil Nadu' + end + + GeoState.find_or_create_by(id: 178) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Telangana' + end + + GeoState.find_or_create_by(id: 179) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Tripura' + end + + GeoState.find_or_create_by(id: 180) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Uttar Pradesh' + end + + GeoState.find_or_create_by(id: 181) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Uttarakhand' + end + + GeoState.find_or_create_by(id: 182) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'West Bengal' + end + + # Territorios de la India + GeoState.find_or_create_by(id: 183) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Andaman and Nicobar Islands' + end + + GeoState.find_or_create_by(id: 184) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Chandigarh' + end + + GeoState.find_or_create_by(id: 185) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Dadra and Nagar Haveli and Daman and Diu' + end + + GeoState.find_or_create_by(id: 186) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Delhi' + end + + GeoState.find_or_create_by(id: 187) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Jammu and Kashmir' + end + + GeoState.find_or_create_by(id: 188) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Ladakh' + end + + GeoState.find_or_create_by(id: 189) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Lakshadweep' + end + + GeoState.find_or_create_by(id: 190) do |geo_state| + geo_state.country_id = 7 + geo_state.name = 'Puducherry' + end + + end +end diff --git a/db/migrate/20240517222839_create_addresses.rb b/db/migrate/20240517222839_create_addresses.rb new file mode 100644 index 000000000..8b9451cec --- /dev/null +++ b/db/migrate/20240517222839_create_addresses.rb @@ -0,0 +1,20 @@ +class CreateAddresses < ActiveRecord::Migration[6.1] + def change + create_table :addresses do |t| + t.string :street_address, null: false + t.string :city + t.integer :state_id + t.string :postal_code + t.integer :country_id, null: false + t.decimal :geo_lat, null: false + t.decimal :geo_long, null: false + t.integer :geo_labelx + t.integer :geo_labely + + t.timestamps + end + + add_foreign_key :addresses, :countries, column: :country_id + add_foreign_key :addresses, :geo_states, column: :state_id + end +end diff --git a/db/migrate/20240520203645_add_address_id_to_division.rb b/db/migrate/20240520203645_add_address_id_to_division.rb new file mode 100644 index 000000000..3a4453cc0 --- /dev/null +++ b/db/migrate/20240520203645_add_address_id_to_division.rb @@ -0,0 +1,6 @@ +class AddAddressIdToDivision < ActiveRecord::Migration[6.1] + def change + add_column :divisions, :address_id, :bigint + add_foreign_key :divisions, :addresses, column: :address_id + end +end diff --git a/db/migrate/20240520210320_add_address_id_to_organization.rb b/db/migrate/20240520210320_add_address_id_to_organization.rb new file mode 100644 index 000000000..d05ca993a --- /dev/null +++ b/db/migrate/20240520210320_add_address_id_to_organization.rb @@ -0,0 +1,6 @@ +class AddAddressIdToOrganization < ActiveRecord::Migration[6.1] + def change + add_column :organizations, :address_id, :bigint + add_foreign_key :organizations, :addresses, column: :address_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f450ad5e7..ae5a42c77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_01_30_223046) do +ActiveRecord::Schema.define(version: 2024_05_20_210320) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -123,6 +123,20 @@ t.index ["qb_object_type"], name: "index_accounting_transactions_on_qb_object_type" end + create_table "addresses", force: :cascade do |t| + t.string "city" + t.integer "country_id", null: false + t.datetime "created_at", precision: 6, null: false + t.integer "geo_labelx" + t.integer "geo_labely" + t.decimal "geo_lat", null: false + t.decimal "geo_long", null: false + t.string "postal_code" + t.integer "state_id" + t.string "street_address", null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "countries", id: :serial, force: :cascade do |t| t.datetime "created_at", null: false t.integer "default_currency_id", null: false @@ -165,6 +179,7 @@ create_table "divisions", id: :serial, force: :cascade do |t| t.string "accent_fg_color" t.string "accent_main_color" + t.bigint "address_id" t.string "banner_bg_color" t.string "banner_fg_color" t.date "closed_books_date" @@ -214,6 +229,13 @@ t.index ["html_identifier"], name: "index_documentations_on_html_identifier", unique: true end + create_table "geo_states", force: :cascade do |t| + t.integer "country_id", null: false + t.datetime "created_at", precision: 6, null: false + t.string "name", null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "loan_health_checks", id: :serial, force: :cascade do |t| t.datetime "created_at", null: false t.boolean "has_late_steps" @@ -282,6 +304,7 @@ end create_table "organizations", id: :serial, force: :cascade do |t| + t.bigint "address_id" t.string "alias" t.string "census_tract_code" t.string "city" @@ -541,18 +564,23 @@ add_foreign_key "accounting_transactions", "accounting_accounts" add_foreign_key "accounting_transactions", "currencies" add_foreign_key "accounting_transactions", "projects" + add_foreign_key "addresses", "countries" + add_foreign_key "addresses", "geo_states", column: "state_id" add_foreign_key "countries", "currencies", column: "default_currency_id" add_foreign_key "data_exports", "divisions" add_foreign_key "divisions", "accounting_accounts", column: "interest_income_account_id" add_foreign_key "divisions", "accounting_accounts", column: "interest_receivable_account_id" add_foreign_key "divisions", "accounting_accounts", column: "principal_account_id" + add_foreign_key "divisions", "addresses" add_foreign_key "divisions", "currencies" add_foreign_key "documentations", "divisions" + add_foreign_key "geo_states", "countries" add_foreign_key "loan_health_checks", "projects", column: "loan_id" add_foreign_key "loan_question_requirements", "questions" add_foreign_key "media", "people", column: "uploader_id" add_foreign_key "option_sets", "divisions" add_foreign_key "options", "option_sets" + add_foreign_key "organizations", "addresses" add_foreign_key "organizations", "countries" add_foreign_key "organizations", "divisions" add_foreign_key "organizations", "people", column: "primary_contact_id" diff --git a/spec/factories/addresses_factory.rb b/spec/factories/addresses_factory.rb new file mode 100644 index 000000000..669685169 --- /dev/null +++ b/spec/factories/addresses_factory.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :address do + + end +end diff --git a/spec/factories/geo_states_factory.rb b/spec/factories/geo_states_factory.rb new file mode 100644 index 000000000..be29dd750 --- /dev/null +++ b/spec/factories/geo_states_factory.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :geo_state do + + end +end diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb new file mode 100644 index 000000000..5531d0dcb --- /dev/null +++ b/spec/models/address_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Address, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/geo_state_spec.rb b/spec/models/geo_state_spec.rb new file mode 100644 index 000000000..ea17cb2ed --- /dev/null +++ b/spec/models/geo_state_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GeoState, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end