Ruby On Rails Mail Routine Not sending -


i have ror if statement supposed record , send emails based on login can tell me wrong in syntax?

this working there 2 test cases return activerecord::recordnotfound (couldn't find signon userw1 = xxx@example.com): app/models/order.rb:219:in `submit_order'

        class order < activerecord::base  # note: ensure setup methods here include , filter on # query_account_number security measure.  establish_connection "web_#{rails_env}" has_many :order_details, :dependent => :destroy, :order => 'id desc'  def self.delete_item query_account_number, login, id     order = order.first(:conditions => {:account_number => query_account_number, :login => login})     detail = order.order_details.first(:conditions => {:id => id})     detail.destroy if detail     # here delete order, have chosen leave not have     # questionable gaps in ids. end  def self.verify_upc1 upc_rule, upc1     "invalid upc prefix" unless item.first(:conditions => ["rul31c = ? , concat(trim(comi1c), 'a') = ?", upc_rule, upc1 + "a"],         :select => "style") end  def self.verify_upc2 upc_rule, upc1, upc2     "invalid upc prefix or subnumber" unless item.first(:conditions => ["rul31c = ? , concat(trim(comi1c), concat(trim(arsb1c), 'a')) = ?", upc_rule, upc1 + upc2 + "a"],         :select => "style") end  def self.verify_style upc_rule, style     "invalid style" unless item.first(:conditions => ["rul31c = ? , concat(trim(style), 'a') = ?", upc_rule, style + "a"],         :select => "style") end  def self.update_quantity query_account_number, login, id, quantity     if quantity.to_i > 0         order = order.first(:conditions => {:account_number => query_account_number, :login => login})         detail = order.order_details.first(:conditions => {:id => id})         if detail             detail.quantity = quantity.to_i             detail.save         end     end end  def self.update_order_note query_account_number, login, order_note     order = order.first(:conditions => {:account_number => query_account_number, :login => login})     order.note = order_note     order.save end  def self.update_order_item_note query_account_number, login, id, note     order = order.first(:conditions => {:account_number => query_account_number, :login => login})     detail = order.order_details.first(:conditions => {:id => id})     if detail         detail.note = note         detail.save     end end  def self.add_item query_account_number, login, quantity, upc1, upc2, price_code, upc_rule     if quantity.to_i > 0         order = order.first(:conditions => {:account_number => query_account_number, :login => login})         order = order.add_order_header(query_account_number, login) if order.blank?         if order             item = item.first(:conditions => ["rul31c = ? , concat(trim(comi1c), concat(trim(arsb1c), 'a')) = ?", upc_rule, upc1 + upc2 + "a"],                                                   :select => "style, color, size, pnum35, cono35, comi1c, arsb1c, ptyp35")             price = price.first(:conditions => {:catnwp => item.pnum35, :conowp => item.cono35, :listwp => price_code}, :select => "prcewp") unless item.blank?             if item , price                 order_detail = orderdetail.new(:style => item.style,                                                                              :order_id => order.id,                                                                              :quantity => quantity,                                                                              :color => item.color,                                                                              :size => item.size)                 order_detail.save                  # return cart item hash                 cart_contents = []                 cart_contents << {:style => item.style,                                                     :color => item.color,                                                     :size => item.size,                                                     :quantity => quantity,                                                     :name => proitem.short_description(item.style),                                                     :price => price.prcewp,                                                     :type => item.ptyp35,                                                     :upc => item.comi1c + item.arsb1c,                                                     :id => order_detail.id}              end         end     end end  def self.order_info_update query_account_number, login, info     order = order.first(:conditions => {:account_number => query_account_number, :login => login})     if order         if info.has_key?("name")             order.name = info[:name]             order.address1 = info[:address1]             order.address2 = info[:address2]             order.address3 = info[:address3]             order.city = info[:city]             order.state = info[:state]             order.zip = info[:zip]         end         if info.has_key?("po_number")             order.po_number = info[:po_number]         end         order.save         # po number go???     end end  def self.mailing_address query_account_number, login     o = order.first(:conditions => {:account_number => query_account_number, :login => login})     {:name => o.name, :address1 => o.address1, :address2 => o.address2, :address3 => o.address3, :city => o.city, :state => o.state, :zip => o.zip} if o end  def self.order_note query_account_number, login     o = order.first(:conditions => {:account_number => query_account_number, :login => login}, :select => "note")     o.note if o end  def self.cart_contents query_account_number, login, price_code, upc_rule     # todo: if item changed since put in cart?     # perhaps expire cart after while, but, still not perfect solution.     # ideally here go through each style, make sure still valid customer, ,     # check color/size well.     order_items = order.first(:conditions => {:account_number => query_account_number, :login => login} )      if order_items         cart_contents = []         order_items.order_details.each |oi|              as400_item = item.first(:conditions => {:rul31c => upc_rule, :style => oi.style.ljust(9), :color => oi.color, :size => oi.size },                                                 :select => "pnum35, cono35, ptyp35, comi1c, arsb1c")             price = price.first(:conditions => {:catnwp => as400_item.pnum35, :conowp => as400_item.cono35, :listwp => price_code}, :select => "prcewp") unless as400_item.blank?              cart_contents << {:style => oi.style,                                                 :color => oi.color,                                                 :size => oi.size,                                                 :quantity => oi.quantity,                                                 :name => proitem.short_description(oi.style),                                                 :price => price.prcewp,                                                 :type => as400_item.ptyp35,                                                 :note => oi.note,                                                 :upc => as400_item.comi1c + as400_item.arsb1c,                                                 :id => oi.id} if as400_item , price         end unless order_items.blank?         cart_contents     end end  def self.cart_contents_count query_account_number, login     order_items = order.first(:conditions => {:account_number => query_account_number, :login => login} )     count = 0     order_items.order_details.each {|oi| count += oi.quantity } if order_items     count end  def self.cart_contents_total query_account_number, login, price_code, upc_rule     order_items = order.first(:conditions => {:account_number => query_account_number, :login => login} )     total = 0     order_items.order_details.each |oi|         as400_item = item.first(:conditions => {:rul31c => upc_rule, :style => oi.style.ljust(9), :color => oi.color, :size => oi.size },             :select => "pnum35, cono35, ptyp35")         price = 0         if !as400_item.blank?             price = price.first(:conditions => {:catnwp => as400_item.pnum35, :conowp => as400_item.cono35, :listwp => price_code}, :select => "prcewp")             total += (oi.quantity * price.prcewp.to_f)         end     end if order_items     total end  def self.add_order_details query_account_number, login, items, notes = hash.new     result = false     if items          # if there not order record, create one.         # allow 1 open order per login @ time, , if there         # 1 already, continue append order_detail records it.         order = order.first(:conditions => {:account_number => query_account_number, :login => login.upcase})         order = order.add_order_header(query_account_number, login) if order.blank?          items.each |key, value|             if value.to_i > 0                 result = true                 style = key[0..8]                 color = key[9..11]                 size = key[12..14]                  order_detail = orderdetail.new(:style => style,                                                                              :order_id => order.id,                                                                              :quantity => value,                                                                              :color => color,                                                                              :size => size,                                                                              :note => (notes ? notes[key] : ''))                 order_detail.save             end         end if order     end     result end  def self.submit_order query_account_number, login, price_code, distributor_number     o = order.first(:conditions => {:account_number => query_account_number, :login => login})      # todo: transaction or error handling     if o          # find associated records need.         customer = customer.first(:conditions => {:cusn05 => query_account_number}, :select => "cono05, cgp405, slmn05, list20" )         sign_on = signon.first(:conditions => {:userw1 => login.upcase},                                                                                       :select => "idnow1, bsnamw1, accntw1, prfdstw1, cntacw1, bsadd1w1, bsadd2w1, bsadd3w1, bscityw1, bsstcdw1, bszipw1, acctypw1")         distributor = distributor.first(:conditions => {:cusnp1 => distributor_number}, :select => "cnam05, emailp1")             if sign_on.acctypw1.strip == "ds"                    rec = signon.find_by_userw1!(login)                         webid = rec.prfdstw1                     elsif sign_on.acctypw1.strip == "dsd"                 rec = signon.find_by_userw1!(login)                         webid = rec.prfdstw1           end          #cnt = weboel23.count(:all,:conditions => {:act223 => mp})         weboel23 = weboel23.first(:conditions => {:act223 => webid}, :select => "emal23")            #cnt=weboel23.count               approval0=weboel23.get_email_by_account0(webid)         approval1=weboel23.get_email_by_account1(webid)         approval2=weboel23.get_email_by_account2(webid)         approval3=weboel23.get_email_by_account3(webid)         approval4=weboel23.get_email_by_account4(webid)             # weboel23 = weboel23.each(:conditions => {:act223 => mp}, :select => "emal23")         #approval = weboel23.emal23          #f=file.open("/var/www/onlineordering.coastalpet.com/log/debug3.txt")         #establish_connection "as400_#{rails_env}"                   #f.puts "prfdstw1"          #f.puts rec = signon.find_by_userw1!(login)          #f.puts "type="+elephant          #f.puts "email="+approval0          #f.close                          # s = find_by_sql ["select emal23 emal23 weboel23 act223 = ?", distributor_number]                    # d << { :id => s[0].emal23 } unless s.blank?           if customer , sign_on              as400_order_id = "wb" + o.id.to_s.rjust(8, "0")              total = 0             count = 0             line = 1 # start @ 1 per ron hoopes 2/14/2011             o.order_details.each |oi|                  item = item.first(:conditions => {:rul31c => customer.cgp405, :style => oi.style.ljust(9), :color => oi.color, :size => oi.size },                                                    :select => "comi1c, arsb1c, chdt1c, pnum35, cono35, pdes35")                 price = price.first(:conditions => {:catnwp => item.pnum35, :conowp => item.cono35, :listwp => price_code}, :select => "prcewp") unless item.blank?                  if item , price                     weborderdetail.create(:conowd => customer.cono05,                                                                 :uniqwd => as400_order_id,                                                                 :linewd => line,                                                                 :itemwd => oi.style.ljust(9) + oi.color + oi.size,                                                                 :barcwd => item.comi1c.strip + item.arsb1c.strip + item.chdt1c.strip,                                                                 :altiwd => "",                                                                 :itmdwd => item.pdes35,                                                                 :qtywd => oi.quantity,                                                                 :uprcwd => price.prcewp.to_f.round_to(2),                                                                 :listwd => customer.list20,                                                                 :dtdrwd => "0",                                                                 :dcd1wd => "",                                                                 :dsc1wd => "0",                                                                 :dcd2wd => "",                                                                 :dsc2wd => "0")                      # create order item notes.                     unless oi.note.blank?                         oi.note.scan(/.{1,70}/).each_with_index |note, index|                             webordernote.create(:conown => customer.cono05,                                                                     :textwn => note,                                                                     :uniqwn => as400_order_id,                                                                     :linewn => line,                                                                     :seqwn => index)                         end                     end                      count += oi.quantity.to_i                     total += oi.quantity.to_i * price.prcewp.to_f.round_to(2)                     line += 1                 end             end              # create order notes.             unless o.note.blank?                 o.note.scan(/.{1,70}/).each_with_index |note, index|                     webordernote.create(:conown => customer.cono05,                                                             :textwn => note,                                                             :uniqwn => as400_order_id,                                                             :linewn => 0,                                                             :seqwn => index)                 end             end              # coastal's definition current century off one, hence math date.             as400_order_header = weborder.new(:conowc => customer.cono05,                                                                                 :uniqwc => as400_order_id,                                                                                 :idnowc => sign_on.idnow1,                                                                                 :namewc => o.name,                                                                                 :addr1wc => o.address1,                                                                                 :addr2wc => o.address2,                                                                                 :addr3wc => o.address3,                                                                                 :citywc => o.city,                                                                                 :statewc => o.state,                                                                                 :zipcdwc => o.zip,                                                                                 :cusnwc => query_account_number,                                                                                 :dtordwc => utilities.to_db2_date(date.today),                                                                                 :shpdtwc => utilities.to_db2_date(date.today),                                                                                 :cusowc => o.po_number.blank? ? as400_order_id : o.po_number,                                                                                 :slmnwc => customer.slmn05,                                                                                 :rulewc => customer.cgp405,                                                                                 :listwc => customer.list20,                                                                                 :valuewc => total.to_f.round_to(2),                                                                                 :statwc => "")              if as400_order_header.save                  # sent confirmation email, if required. send users chose distributor,                 # whether had choose 1 or not. determine looking @ account number                 # in sign_on , comparing order number using order. if                 # different, indicates chose distributor.                  # these used in email body, key hash replacement tags, capitalized, &                 # prepended , appended  '##', e.g. ##name## - , underlines replaced space                 email_details = {"name" => sign_on.bsnamw1,                                                  "order_number" => as400_order_id,                                                  "order_total" => format('$%.2f', total),                                                  "order_count" => count.to_s,                                                  "order_date" => date.today.to_s,                                                  "distributor_name" => (distributor ? distributor.cnam05 : ""),                                                  "distributor_contact" => "unknown",                                                  "customer_name" => sign_on.bsnamw1,                                                  "customer_address" => sign_on.bsadd1w1.strip + (!sign_on.bsadd2w1.blank? ? "<br>" + sign_on.bsadd2w1.strip : "") + (!sign_on.bsadd3w1.blank? ? "<br>" + sign_on.bsadd3w1.strip : ""),                                                  "customer_city" => sign_on.bscityw1,                                                  "customer_state" => sign_on.bsstcdw1,                                                  "customer_zip" => sign_on.bszipw1,                                                  "customer_contact" => sign_on.cntacw1}                       mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                 # per dana 6/30/2012, ds                  if sign_on.acctypw1.strip == "ds" or sign_on.acctypw1.strip == "dsd"                      # if there no distributor email address, mailer model substitute in admin's email settings                     mailer.deliver_order_distributor_approval_email(distributor ? distributor.emailp1 : "", "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation  #{approval0} #{approval1}", email_details)                     if approval0!=""                           mailer.deliver_order_confirmation_email(login, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                         mailer.deliver_order_distributor_approval_email(approval0, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation ", email_details)                         mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                         end                                      if approval1!=""                             mailer.deliver_order_confirmation_email(login, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                             mailer.deliver_order_distributor_approval_email(approval1, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation  ", email_details)                             mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                             end                         if approval2!=""                             mailer.deliver_order_confirmation_email(login, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                                mailer.deliver_order_distributor_approval_email(approval2, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation ", email_details)                             mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                             end                         if approval3!=""                              mailer.deliver_order_confirmation_email(login, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                                mailer.deliver_order_distributor_approval_email(approval3, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation  ", email_details)                                 mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                             end                         if approval4!=""                              mailer.deliver_order_confirmation_email(login, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                                mailer.deliver_order_distributor_approval_email(approval4, "coastal pet online ordering<noreply@coastalpet.com>", "order confirmation ", email_details)                             mailer.deliver_order_coastal_notify_email("coastal pet online ordering<noreply@coastalpet.com>", "order confirmation", email_details)                             end                                        mailer.deliver_order_distributor_approval_email(weboel23 ? weboel23.emal23: "", "coastal pet online ordering<noreply@coastalpet.com>", "*order confirmation", email_details)                      mailer.deliver_order_distributor_approval_email("robert.kendall@coastalpet.com", "coastal pet online ordering<noreply@coastalpet.com>", "*order confirmation", email_details)                      end                  # al ways notify coastal staff                  # update last ordered date (used reminders)                 user.update_last_order_date(login)                  o.destroy                 as400_order_id             end         end     end end  def self.count_user_orders query_account_number, login     count = order.first(:conditions => {:account_number => query_account_number, :login => login})     count.order_details.count unless count.blank? or count == 0 end  def self.reorder(order_number, login, query_account_number, upc_rule, price_code, mode)     warnings = ""      # if not in check mode, blank out cart     self.empty_cart(query_account_number, login) if mode != "check"      # previous order     oo = weborder.get_previous_order(order_number, login)      # go through each line item     oo.each |ooi|          # verify still exists in as400 , same price         # note reports -1 if cannot find         # same style+color+size option, otherwise reports         # price if finds it.         current_price = item.check_item_exists(query_account_number, ooi[:style], ooi[:color], ooi[:size], upc_rule, price_code)          # if item not found, can't add it.         # spend more time determine if color, or size, or         # style not available, seems reasonable enough         # present way. should not doing "presentation" in         # model, don't have views setup ajax have give         # controller text want rendered.         if current_price == -1             warnings += "sku "+ ooi[:style].to_s + ooi[:color].to_s + ooi[:size].to_s + " no longer available<br />"         else             # if price did not match, append list of warnings             if current_price.to_f.round_to(2) != ooi[:price].to_f.round_to(2)                 warnings += "sku "+ ooi[:style].to_s + ooi[:color].to_s + ooi[:size].to_s + " price " +                     actioncontroller::base.helpers.number_to_currency(current_price) + " , " +                     actioncontroller::base.helpers.number_to_currency(ooi[:price]) + "<br />"             end             # if not in check mode, add item cart             # in case, don't care price did             # not match, still add it.             populate_cart(query_account_number, login, ooi[:style], ooi[:color], ooi[:size], ooi[:quantity], ooi[:line_item_note], ooi[:order_note]) if mode != "check"         end     end     mode == "check" ? warnings : "" end  def self.empty_cart query_account_number, login     order = order.first(:conditions => {:account_number => query_account_number, :login => login})     order.destroy if order end  def self.populate_cart query_account_number, login, style, color, size, quantity, note, order_note      # if there not order record, create one.     # allow 1 open order per login @ time, , if there     # 1 already, continue append order_detail records it.     order = order.first(:conditions => {:account_number => query_account_number, :login => login.upcase})     order = order.add_order_header(query_account_number, login) if order.blank?      # these can null kits, , don't nulls in database     color = "" if color.blank?     size = "" if size.blank?      if order         order.note = order_note # yeah each time while inefficient works         order.save         order_detail = orderdetail.new(:style => style,                                                                      :order_id => order.id,                                                                      :quantity => quantity,                                                                      :color => color,                                                                      :size => size,                                                                      :note => note)         order_detail.save     end  end  private     def self.add_order_header query_account_number, login         # default address info sign_on         sign_on = signon.first(:conditions => {:userw1 => login.upcase}, :select => "bsnamw1, bsadd1w1, bsadd2w1, bsadd3w1, bscityw1, bsstcdw1, bszipw1")          if sign_on             order = order.new(:login => login,                                                 :account_number => query_account_number,                                                 :name => sign_on.bsnamw1,                                                 :address1 => sign_on.bsadd1w1,                                                 :address2 => sign_on.bsadd2w1,                                                 :address3 => sign_on.bsadd3w1,                                                 :city => sign_on.bscityw1,                                                 :state => sign_on.bsstcdw1,                                                 :zip => sign_on.bszipw1)             order.save             order         end     end 

end


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -