OSDN Git Service

仕入先マスタ管理機能追加
[elecoma/elecoma.git] / app / models / supplier_search_form.rb
1 # -*- coding: utf-8 -*-\r
2 # 仕入先マスタ管理で検索条件を格納するフォーム\r
3 class SupplierSearchForm < SearchForm\r
4   set_field_names :supplier_id => '仕入先ID'\r
5   set_field_names :email => 'メールアドレス'\r
6   set_field_names :tel_no => '電話番号'\r
7   set_field_names :fax_no => 'ファックス'\r
8   set_field_names :name => '仕入先名'\r
9   set_field_names :contact_name => '担当者名'\r
10 \r
11   validates_numericality_of :supplier_id, :allow_blank=>true, :message => 'は半角数字のみを入力してください。'\r
12   validates_format_of :email, :with => /[\x1-\x7f]/, :allow_blank => true, :message => 'は半角英数字のみを入力してください。'\r
13   validates_numericality_of :tel_no, :only_integer => true, :allow_blank => true, :message => 'は半角数字のみを入力してください。'\r
14   validates_numericality_of :fax_no, :only_integer => true, :allow_blank => true, :message => 'は半角数字のみを入力してください。'\r
15 \r
16   def self.get_sql_select\r
17   <<-EOS\r
18   select s.*\r
19   EOS\r
20   end\r
21 \r
22   def self.get_sql_condition(condition)\r
23     conditions = []\r
24     sql_condition = <<-EOS\r
25 from\r
26 suppliers s\r
27 where\r
28 (s.deleted_at IS NULL OR s.deleted_at > '#{Time.now.gmtime.strftime("%Y-%m-%d %H:%M:%S")}')\r
29 #{unless condition.supplier_id.blank?\r
30     conditions << condition.supplier_id.to_i\r
31     "and s.id = ?"\r
32   end}\r
33 #{unless condition.name.blank?\r
34     conditions << "%#{condition.name}%"\r
35     "and s.name like ?"\r
36   end}\r
37 #{unless condition.contact_name.blank?\r
38     conditions << "%#{condition.contact_name}%"\r
39     "and s.contact_name like ?"\r
40   end}\r
41 #{unless condition.tel_no.blank?\r
42     conditions << "%#{condition.tel_no}%"\r
43     "and (s.tel01 || s.tel02 || s.tel03) like ? "\r
44   end}\r
45 #{unless condition.fax_no.blank?\r
46     conditions << "%#{condition.fax_no}%"\r
47     "and (s.fax01 || s.fax02 || s.fax03) like ? "\r
48   end}  \r
49 #{unless condition.email.blank?\r
50     conditions << "%#{condition.email}%"\r
51     "and s.email like ? "\r
52   end}\r
53 order by s.id\r
54 EOS\r
55   return [sql_condition, conditions] \r
56   end\r
57 \r
58 end\r