如果客户订的EVF比送的REDONE多,而且那些EVF还没有全部送货

lines = ERP::SalesLine.find(:all, 
:conditions => ['item_id =  ? OR item_id = ?', '301001', '101001'],
:joins => 'JOIN erp_sales_orders ON erp_sales_orders.id = erp_sales_lines.erp_sales_order_id 
JOIN erp_customers ON erp_customers.id = erp_sales_orders.erp_customer_id'
)

result = {}

lines.each do |line| 

  unless result.key?(  account  = line.sales_order.customer.account_num)
    result.merge!( account => { :red_one => 0, :evf => 0, :remain_sales_physical => 0 } )
  end
  s = result[account]  

  if line.item_id == '101001'
    unless line.invoiced_in_total.blank?
      s[:red_one] += 1
    end
  elsif line.item_id = '301001'
    s[:remain_sales_physical] += line.remain_sales_physical
    s[:evf] += 1
  end
end





accounts = []
result.each do |key,value|
  if (value[:red_one] > 0 and value[:red_one] >= value[:evf] and value[:remain_sales_physical] > 0)
    accounts << (key)
    a = ERP::Customer.find_by_account_num(key)
    open("#{RAILS_ROOT}/log/accountn_numbers.log", "a+") { |file| file << "#{key} #{}n" }
      
  end
end

转载请注明:韦旭红的点点滴滴 » 查询订单demo