Class: Rma::CodeMerger

Inherits:
BaseService show all
Defined in:
app/services/rma/code_merger.rb

Constant Summary collapse

CODE_MAP =
{
  'COI' => {
    merge: %w[BOI ACS AOI ZOI CCO CNP CIP DOI ICO LCO OOI POI ROI VCO XOI ZD3 CNP TEC GVO RVO PVO],
    name: "Customer Ordered Incorrectly",
    description: "No fault of WY. Customer ordered wrong size or item and will re-order the right product.  This could be a result of not providing a floor plan, an inaccurate floor plan provided/room changed, IP plan or dimensions NOT verified before ordering, or a product that is incompatible"
  },
  'SHE' => {
    merge: %w[GPS ZIC ZSE ZSV PMI CPS IIP IPS LPS PPS RPS VWS VWV AWQ],
    name: "Shipping Error",
    description: "WY warehouse error.  Item could be missing from shipment entirely or could have shipped wrong item/wrong size."
  },
  'DIS' => {
    merge: %w[TDE XDS ISD CSD DSH LIP LSD ODS PDT RDT UDS VDS ZDS ZIB],
    name: "Shipping Damage",
    description: "Item arrived damaged by carrier in transit - PHOTOS REQUIRED!  Photos of outer box damage and photos of prodcut damage also required."
  },
  'DOA' => {
    merge: %w[FLT],
    name: "Item Faulty or Defective",
    description: "Item faulty but not due to shipping, out of the box failure, or never worked"
  },
  'MIS' => {
    merge: %w[CMD],
    name: "Missed Delivery",
    description: "Customer missed delivery, package is being returned to WY Warehouse by the carrier"
  },
  'CSE' => {
    merge: %w[TSE],
    name: 'Customer or Tech Service Error',
    description: 'Order or quote processing error, not shipping related, misquoted, gave wrong information to customer resulting in incorrect order'
  },
  'WDE' => {
    merge: %w[DDE PDE RDE VEE VEV VOI VOE ZD2 DEEDDE ZD3 ZD1],
    name: 'WY Design Error / Misconfigured',
    description: 'WYI design or quote error (Missing power mods, one voltage drawn different voltage quoted, incorrect number of breakers, etc.)'
  },
  'LIT' => {
    name: 'Lost In Transit',
    description: %{When the shipping carrier cannot locate the packages, you should file an insurance claim to cover the lost packages' combined insured value and shipment cost. This requires the tracking number, proof of the value of the item, and proof of insurance.}
  },
  'DNW' => {
    merge: %w[BCS XCS ZCS CSA AUI CLD DNN],
    name: "Does Not Want/Buyer's Remorse",
    description: "Customer has buyers remorse, received as an unwanted gift or changed mind about the item but nothing is wrong with item and is in new & resaleable condition"
  },
  'IRJ' => {
    name: "Installer Rejection",
    description: "Installer does not want to install, or Inspector concerns. Either wrong product type, or installer works only with specific brands"
  },
  'CEX' => {
    merge: %w[CCS DCS ICS LCS OCS PCS RCS UCS VCS],
    name: "Customer Satisfaction",
    description: "Did not meet customer's expectation or satisfaction, e.g wrong color or finish, does not heat enough"
  },
  'IPD' => {
    merge: %w[ZRM MSL VML],
    name: "Incorrect Product Description or Mislabeled",
    description: "Product did not match the description, item is different than desctribed on the web site, out of date marketing information"
  },
  'BPE' => {
    name: "Better Price Elsewhere",
    description: "Customer found a better price elsewhere, could be same product but purchased on a different channel"
  },
  'DLY' => {
    name: "Arrived Too Late",
    description: "Item was expected earlier, Error made by WY sales rep on SQ/TQ or SO/TO, wrong shipping method selected"
  },
  'DDI' => {
    merge: %w[OTC OTM OSD AID CID IID LID OIO PIN RIN XID VDI WNI ZBC ZNW ZSH UPD],
    name: "Damaged During Installation",
    description: "Product was damaged during the installation process, return to inspect to confirm"
  },
  'XMH' => {
    merge: %w[AMI CHW IHW LHW XIM],
    name: "Incomplete Item",
    description: "Missing hardware or kit item, Hardware Incorrect/Missing"
  },
  'TRR' => {
    name: "Technical Rental Return",
    description: "Return of a rental product",
    merge: %w[TKR TCE SSR TCR]
  },
  'TBD' => {
    name: "To Be Determined / Unknown	To be determined and inspected by RMA dept tech.",
    description: "E-tailer returns for unknown reason"
  },
  'ITE' => {
    name: "IT Error",
    description: "A system bug caused this, perhaps an order that went out when it shouldn't have or a quote builder error"
  },
  'NRT' => {
    name: "Untested Item",
    description: "At customer's request, a replacement was sent for testing and possibly repair",
    merge: %w[XRT]
  },
  'REC' => {
    name: "Product Recall",
    description: "Product is on a list of recall",
    merge: %w[URC]
  },
  'CGF' => {
    name: "Custom order manufactured incorrectly",
    description: "Manufacturing not done up to specs, use for custom products"
  },
  'ZIA' => {
    name: "Tradeshow or training item returned",
    description: "Tradeshow Request",
    merge: %w[ZIE]
  },
  'ZWA' => {
    name: "Failed Factory Splice",
    description: "Failed Factory Splice",
    merge: %w[RFS]
  }
}
ADVANCED_CODES =
%{
  ABB,Bad Jbox,
  ABC,Bad Conduit,
  ANF,Non Documented Fault,CEN DNF IEN LEN NDF ONF RNF VEN XEN ZEN
  BAS,Bad Ambient / Air Sensor,OAS
  BBL,Backlight Button Does Not Respond,
  BCL,Child Lock Will Not Clear,
  BCP,Blank Faceplate,
  BSS,Bad Sensor,BE1 BFS OSS PSN RSN BE2
  BEO,Internal Failure Displayed,
  BFP,Bad Face plate,
  BG2,Non Resetting Gfci,
  BGF,Trip Issue Gfci,GFP
  BLC,Led Constant,
  BLD,OJ LCD Dim,
  BLF,Led Flashing Quickly,
  BLS,Led Flashing Slowly,
  BNT,Faceplate Pins,
  BPC,Bad Phone Controller,
  BSW,Bad Software,
  BWI,Wifi Will Not Connect,
  CBL,Faulty Line Connections,
  CBS,Bad Tcu,
  CBT,Bad Transformer,
  CDF,Unit Detached From Surface,
  CNH,No Heat,DNH INH LNH PNH RNH XNH
  COC,Open Element Circuit,
  DFL,Folding damage,
  DLC,Loose Connection,
  DMF,Buttons Do Not Respond,
  DMR,Damage To Mirror or Glass,IGF LGF PEN
  DOC,Open Circuit,
  DOR,Faceplate Door Damaged,
  DOV,Overheat,XOH
  DPH,Partial Heat,UNS VPH
  DTR,Torn,
  ERM,Error Message Won't Clear,
  FPD,Faceplate Damaged,
  GCF,Control Failure,OCE OCP PCF RCF
  GFB,Gfci Test Button Does Not Respond,
  GOH,Ohms Out Of Spec,
  GPF,Power Connect Failure,PPF
  IBA,Faulty LED Kit Component,
  IBS,Bad Switch,LBS XBS BTS
  IDF,Bad Finish or Cosmetic Issue,ITB LDF XDF OCD
  ILE,Bad Power Indicator/LED,LNL
  INP,Noisey,
  IOC,Open Circuit,LOC UNC XOC
  ITC,Towel Bar Not To Spec,
  LBA,Faulty Led Kit Component,
  LCK,Flashing Display & All Buttons Are Locked,
  LFC,Faulty Connection Customer,
  LFW,Faulty Internal Wiring Factory,
  LND,No Dim Function,
  MLT,Burnt Or Melted T Stat Wires,
  MOR,Megaohm Meter return,
  NPL,No Power To Load Side,
  OAF,SCA Failure,
  OCM,Mega-ohm reader out of spec,PMG RMG
  OCR,Cable Repair,
  OCT,Timer Control Failure,
  ODC,Sensor Corrosion Damage,
  OFB,Controller Fuse Blown,
  OFS,On/Off Switch Does Not Respond,
  OGF,Gfep Failure Will Not Reset,
  OIA,Asphalt Install Damage,
  OIC,Concrete Install Damage,
  OIP,Paver Install Damage,
  OIR,Switching Relay Inside Box Failure/Damage,
  OIW,Relay Internal Wiring Failure/Melting,
  OLD,Relay Clasp Lock Failure,
  OPC,Power Modulator Component Failure,
  OPM,Power Modulator Relay Failure,
  OSF,Controller Software Failure,
  OSP,Programming Malfunction,PMF
  OTP,Trouble Customer Supplied Parts,
  OVF,SCV Failure,
  OWI,Controller Water Ingress Failure,
  PFP,Cable Tripping,
  PFS,Factory Failure,
  POH,Ohms Out Of Spec,
  POL,Max Circuit Length Overload,ROL
  PPD,Post Install Physical Damage,RPD
  PSP,T Splice Failure,RSP
  RFP,Cable Tripping,
  RLY,Relay Frozen In On Position,
  ROH,Ohms Out Of Spec,
  RPF,Power Connect Failure,
  UBP,Bad Plug Connection,
  UBT,Burn Through,
  UDF,Damage To Floor,
  UDR,Damage To Rug,
  UFG,Faulty Gfi,
  UIS,Up In Smoke,
  UOH,Unit Ohms Not To Spec,
  VAC,Vacation Mode Will Not Clear,
  VDV,Damaged Wrong Voltage,
  VFS,Failed Lead Connection,
  VOL,Overlap Damage,
  VOO,Ohms Over Tolerance,
  VOP,No Ohms Reading,
  VOU,Ohms Under Tolerance,
  XBP,Bad Plug,
  XBW,Bad Welds,
  XLC,Bad Line Cord,
  XMB,Mounting Brackets Not To Spec,
  XNS,Unit Is Crooked / Not Square,
  XOF,Oil Still Present,
  XOX,Rust,
  XSC,Short Circuit,
  XSH,Slow Heat,
  XWD,Wires Damaged,
  ZHW,Heated Wire In Wall,
  ZOA,Ohms Over 15%,
  ZOB,Ohms Under 15%,
  ZWS,Rolls Wired In Series,
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.mergeObject



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'app/services/rma/code_merger.rb', line 276

def self.merge
  all_codes = []
  cm = Rma::CodeMerger.new
  CODE_MAP.each do |code, data|
    puts "Processing #{code}"
    all_codes << code
    cm.process code, data[:merge], name: data[:name], description: data[:description], advanced_reason_code: data[:advanced_reason_code].to_b
  end

  ADVANCED_CODES.split("\n").map{|row| row.split(',').map(&:squish).map(&:presence).compact.presence}.compact.each do |(code, description, merge)|
    puts "Processing #{code}"
    all_codes << code
    cm.process code, merge&.split(' '), name: description, advanced_reason_code: true
  end

  RmaReasonCode.where.not(code: all_codes)

end

Instance Method Details

#process(survivor_code, duplicate_codes = nil, params = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/rma/code_merger.rb', line 3

def process(survivor_code, duplicate_codes = nil, params = nil)
  params ||= {}
  duplicate_codes ||= []
  survivor = RmaReasonCode.find_by(code: survivor_code)
  if survivor.nil?
    survivor = RmaReasonCode.create!(code: survivor_code, **params)
  end
  raise "survivor_code #{survivor_code} is in the duplicate" if duplicate_codes.include?(survivor_code)

  product_line_ids = survivor.product_line_ids
  product_category_ids = survivor.product_category_ids
  duplicates = RmaReasonCode.none
  if duplicate_codes.present?
    duplicates = RmaReasonCode.where(code: duplicate_codes)

    if duplicates.size!= duplicate_codes.size
      missing_codes = duplicate_codes - duplicates.map(&:code)
      puts "!!! Not all supplied duplicate_codes are found, missing: #{missing_codes.inspect}, this might indicates a potential typo"
    end
  end

  RmaReasonCode.transaction do

    duplicates.each do |duplicate|
      duplicate.returned_rma_items.update_all(returned_reason: survivor_code)
      duplicate.restocked_rma_items.update_all(restocking_reason: survivor_code)
      product_line_ids += duplicate.product_line_ids
      product_category_ids += duplicate.product_category_ids
      duplicate.reload
      duplicate.destroy!
    end
    survivor.product_line_ids = product_line_ids.uniq
    survivor.product_category_ids = product_category_ids.uniq
    survivor.attributes = survivor.attributes.merge(params.stringify_keys)
    survivor.save!

  end
end