Created
September 1, 2023 13:58
-
-
Save isaiahbaca/fb099181e0685de2a36a150af1ea69ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A task to create a new supplier cost based on court zip code | |
| namespace :nevada_supplier_costs do | |
| desc "Create a new supplier cost based on provided zip codes" | |
| task create: :environment do | |
| PRODUCTS = { | |
| zone_1_standard: Product.find(3372829), | |
| zone_1_rush: Product.find(3372829), | |
| zone_2_standard: Product.find(3372829), | |
| zone_2_rush: Product.find(3372829), | |
| zone_3_standard: Product.find(3372829), | |
| zone_3_rush: Product.find(3372829), | |
| zone_4_standard: Product.find(3372829), | |
| zone_4_rush: Product.find(3372829), | |
| zone_5_standard: Product.find(3372829), | |
| zone_5_rush: Product.find(3372829), | |
| } | |
| mapped_zip_zones = {"88901"=>2, "88905"=>2, "89001"=>5, "89002"=>2, "89003"=>5, "89005"=>3, "89006"=>3, "89007"=>5, "89008"=>5, "89009"=>2, "89011"=>3, "89012"=>2, "89013"=>5, "89014"=>2, "89015"=>3, "89016"=>2, "89017"=>5, "89018"=>5, "89019"=>5, "89020"=>5, "89021"=>4, "89022"=>5, "89023"=>5, "89024"=>4, "89025"=>5, "89026"=>5, "89027"=>4, "89028"=>3, "89029"=>3, "89030"=>2, "89031"=>2, "89032"=>2, "89033"=>2, "89034"=>4, "89036"=>3, "89037"=>5, "89039"=>5, "89040"=>5, "89041"=>4, "89042"=>5, "89043"=>5, "89044"=>3, "89045"=>5, "89046"=>5, "89047"=>5, "89048"=>4, "89049"=>5, "89052"=>3, "89053"=>2, "89054"=>4, "89060"=>5, "89061"=>4, "89067"=>5, "89070"=>5, "89074"=>2, "89077"=>2, "89081"=>2, "89084"=>2, "89085"=>3, "89086"=>2, "89087"=>2, "89101"=>2, "89102"=>2, "89103"=>2, "89104"=>2, "89105"=>2, "89106"=>2, "89107"=>2, "89108"=>2, "89109"=>2, "89110"=>2, "89111"=>2, "89112"=>2, "89113"=>2, "89114"=>2, "89115"=>2, "89116"=>2, "89117"=>2, "89118"=>2, "89119"=>2, "89120"=>2, "89121"=>2, "89122"=>2, "89123"=>2, "89124"=>5, "89125"=>2, "89126"=>2, "89127"=>2, "89128"=>2, "89129"=>2, "89130"=>2, "89131"=>2, "89132"=>2, "89133"=>2, "89134"=>2, "89135"=>3, "89136"=>2, "89137"=>2, "89138"=>2, "89139"=>2, "89140"=>2, "89141"=>2, "89142"=>2, "89143"=>2, "89144"=>2, "89145"=>2, "89146"=>2, "89147"=>2, "89148"=>2, "89149"=>2, "89150"=>2, "89151"=>2, "89152"=>2, "89153"=>2, "89154"=>2, "89155"=>2, "89156"=>3, "89157"=>2, "89158"=>2, "89159"=>2, "89160"=>2, "89161"=>2, "89162"=>2, "89163"=>2, "89164"=>2, "89165"=>2, "89166"=>4, "89169"=>2, "89170"=>2, "89173"=>2, "89177"=>2, "89178"=>3, "89179"=>4, "89180"=>2, "89183"=>2, "89185"=>2, "89191"=>3, "89193"=>2, "89195"=>2, "89199"=>2, "89301"=>5, "89310"=>5, "89311"=>5, "89314"=>5, "89315"=>5, "89316"=>5, "89317"=>5, "89318"=>5, "89319"=>5, "89402"=>3, "89403"=>4, "89404"=>5, "89405"=>5, "89406"=>5, "89407"=>5, "89408"=>4, "89409"=>5, "89410"=>4, "89411"=>4, "89412"=>5, "89413"=>4, "89414"=>5, "89415"=>5, "89418"=>5, "89419"=>5, "89420"=>5, "89421"=>5, "89422"=>5, "89423"=>3, "89424"=>5, "89425"=>5, "89426"=>5, "89427"=>5, "89428"=>4, "89429"=>4, "89430"=>5, "89431"=>2, "89432"=>2, "89433"=>3, "89434"=>3, "89435"=>2, "89436"=>3, "89437"=>4, "89438"=>5, "89439"=>4, "89440"=>5, "89441"=>4, "89442"=>5, "89444"=>5, "89445"=>5, "89446"=>5, "89447"=>5, "89448"=>3, "89449"=>3, "89450"=>3, "89451"=>3, "89452"=>3, "89460"=>4, "89496"=>5, "89501"=>2, "89502"=>2, "89503"=>2, "89504"=>2, "89505"=>2, "89506"=>3, "89507"=>2, "89508"=>4, "89509"=>2, "89510"=>5, "89511"=>3, "89512"=>2, "89513"=>2, "89515"=>2, "89519"=>3, "89520"=>2, "89521"=>3, "89523"=>3, "89533"=>2, "89555"=>2, "89557"=>2, "89570"=>2, "89595"=>2, "89599"=>2, "89701"=>2, "89702"=>2, "89703"=>2, "89704"=>4, "89705"=>3, "89706"=>3, "89711"=>2, "89712"=>2, "89713"=>2, "89714"=>2, "89721"=>2, "89801"=>5, "89802"=>5, "89803"=>5, "89815"=>5, "89820"=>5, "89821"=>5, "89822"=>5, "89823"=>5, "89824"=>5, "89825"=>5, "89826"=>5, "89828"=>5, "89830"=>5, "89831"=>5, "89832"=>5, "89833"=>5, "89834"=>5, "89835"=>5, "89883"=>5} | |
| success_count = 0 | |
| mapped_zip_zones.each do |zip, zone| | |
| zipcode_record = Zipcode.find_by(zipcode: zip) | |
| if zipcode_record | |
| #Create Standard Supplier Cost | |
| standard_product = PRODUCTS["zone_#{zone}_standard".to_sym] | |
| if SupplierCost.create( | |
| zipcode_id: zipcode_record.id, | |
| sla_id: 1, | |
| job_type_id: 1, | |
| product_id: standard_product.id, | |
| amount: standard_product.price) | |
| success_count += 1 | |
| end | |
| #Create Rush Supplier Cost | |
| rush_product = PRODUCTS["zone_#{zone}_rush".to_sym] | |
| if SupplierCost.create( | |
| zipcode_id: zipcode_record.id, | |
| sla_id: 2, | |
| job_type_id: 1, | |
| product_id: rush_product.id, | |
| amount: rush_product.price) | |
| success_count += 1 | |
| end | |
| end | |
| end | |
| puts "Successfully added #{success_count} new supplier cost records." | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment