invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / edit / cust_payby.html
1 %# #based on / some false laziness w/ cust_main-contacts.html
2 <& elements/edit.html,
3      'name_singular'   => 'payment methods', #"customer payment methods" ?
4      'table'           => 'cust_main',
5      'post_url'        => popurl(1). 'process/cust_payby.html',
6      'no_pkey_display' => 1,
7      'labels'          => {
8                             'custpaybynum'  => ' ', #'Payment method',
9                             #'locationnum' => '&nbsp;',
10                           },
11      'fields'          => [
12        { field                 => 'custpaybynum',
13          type                  => 'selectlayers',
14          options               => [ '',
15                                     grep { ! /^(DCRD|DCHK)$/ }
16                                       FS::payby->cust_payby
17                                   ],
18          labels                => { '' => 'Select payment method',
19                                     FS::payby->payby2shortname
20                                   },
21          layer_fields          => \%payby_fields,
22          layer_values_callback => $payby_layer_values,
23          m2m_method            => 'cust_payby',
24          m2m_dstcol            => 'custpaybynum',   
25          m2_label              => ' ', #'Payment method',
26          m2_error_callback     => $m2_error_callback,
27        },
28      ],
29      #'new_callback'    => $new_callback,
30      #'edit_callback'   => $edit_callback,
31      #'error_callback'  => $error_callback,
32      'agent_virt'      => 1,
33      'menubar'         => [], #remove "view all" link
34
35      #XXX it would be nice if this could instead be after the error but before
36      # the table
37      'html_init'       => include('/elements/small_custview.html',
38                                     $custnum,
39                                     $conf->config('countrydefault') || 'US',
40                                     1, #no balance
41                                  ).
42                           '<BR>',
43 &>
44 <%init>
45
46 my $curuser = $FS::CurrentUser::CurrentUser;
47 my $conf = new FS::Conf;
48
49 my $custnum;
50 if ( $cgi->param('error') ) {
51   $custnum = scalar($cgi->param('custnum'));
52
53   die "access denied"
54     unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #payment methods?
55
56 } elsif ( $cgi->keywords ) { #editing
57   $custnum = ($cgi->keywords)[0];
58
59   die "access denied"
60     unless $curuser->access_right('Edit customer');
61
62 } else { #new customer
63
64   #this doesn't really work here, we're an edit only
65   die "guru meditation #53";
66
67   die "access denied"
68     unless $curuser->access_right('New customer');
69
70 }
71
72
73 #XXX
74 my %payby_fields = (
75   'CARD' => [ 'CARD_payinfo' => mt('Card number'),
76               'CARD_exp'     => {
77                                   label => 'Expiration',
78                                   type  => 'select-month_year',
79                                   #XXX prefix?
80                                 },
81               'CARD_paycvv'  => 'CVV2', #XXX help popup
82               'CARD_payname' => mt('Exact name on card'),
83               'CARD_payauto' => { label => mt('Charge future payments to this credit card automatically'),
84                                   type  => 'checkbox',
85                                 },
86             ],
87   'CHEK' => [ 'CHEK_payinfo1'  => mt('Account number'),
88               'CHEK_paytype'   => { label => 'Type',
89                                     #XXX select values
90                                     #@FS::cust_main::paytypes #??
91                                   },
92               'CHEK_payinfo2'  => mt('ABA/Routing number'), #XXX help popup
93               'CHEK_exp_month' => { type  => 'hidden',
94                                     value => 12,
95                                   },
96               'CHEK_exp_year'  => { type  => 'hidden',
97                                     value => 2037,
98                                   },
99               'CHEK_payname'   => mt('Bank name'),
100               #'CHEK_paystate'  => { label => $paystate_label,
101               #                      type  => 'select-state',
102               #                    },
103               'CHEK_payauto' => { label => mt('Charge future payments to this electronic check automatically'),
104                                   type  => 'checkbox',
105                                 },
106             ],
107   #'LECB'
108   'BILL' => [ 'BILL_payinfo' => mt('P.O.'),
109               'BILL_exp_month' => { type  => 'hidden',
110                                     value => 12,
111                                   },
112               'BILL_exp_year'  => { type  => 'hidden',
113                                     value => 2037,
114                                   },
115               'BILL_payname'   => mt('Attention'),
116             ],
117   'COMP' => [
118               'COMP_payinfo' => mt('Approved by'),
119             ],
120
121 );
122
123 #XXX
124 my $payby_layer_values = sub {
125   my ( $cgi, $cust_payby, $switches ) = @_;
126   +{
127 #     #map { $_ => { $part_event_condition->options } }
128 #     #    keys %condition_fields
129 #     map { my $conditionname = $_;
130 #           my %opts = $switches->{'mode'} eq 'error'
131 #                      ? %{ $cgi_conditions{$conditionname} || {} }
132 #                      : $part_event_condition->options;
133 #           %opts = (
134 #             map { ( "$conditionname.$_" => $opts{$_} ); }
135 #                 keys %opts
136 #           );
137 #           ( $conditionname => \%opts );
138 #         }
139 #         keys %condition_fields
140   };
141 };
142
143
144 #my $new_callback = sub {
145 #  my( $cgi, $cust_main, $fields_listref, $opt_hashref ) = @_;
146 #};
147
148 #my $edit_callback = sub {
149 # my( $cgi, $cust_main, $fields_listref, $opt_hashref ) = @_;
150 #};
151
152 #my $error_callback = sub {
153 #  my( $cgi, $cust_main, $fields_listref, $opt_hashref ) = @_;
154 #};
155
156 my $m2_error_callback = sub {
157   my($cgi, $object) = @_;
158
159   #XXX
160
161   #process_o2m fields in process/cust_main-contacts.html
162   my @fields = qw( first last title comment );
163   my @gfields = ( '', map "_$_", @fields );
164
165   map {
166         if ( /^contactnum(\d+)$/ ) {
167           my $num = $1;
168           if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
169             my $x = new FS::contact {
170               'contactnum' => scalar($cgi->param("contactnum$num")),
171               map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
172             };
173             $x;
174           } else {
175             ();
176           }
177         } else {
178           ();
179         }
180       }
181       $cgi->param;
182 };
183
184 </%init>