payment posting styled inside customer
[freeside.git] / httemplate / edit / did_order.html
1 <% include( 'elements/edit.html',
2               'fields' => [
3                             { field => 'vendornum',
4                               type => 'select-table',
5                               name_col => 'vendorname',
6                               table => 'did_vendor',
7                               disable_empty => 1,
8                             },
9                             { field => 'vendor_order_id',
10                               type => 'hidden',
11                             },
12                             { field => 'confirmed',
13                               type => 'hidden',
14                             },
15                             { field => 'received',
16                               type => 'hidden',
17                             },
18                             { field => 'submitted',
19                               type => 'hidden',
20                             },
21                             { field => 'stock_or_customer',
22                               type => 'radio',
23                               options => [ 'Stock', 'Customer', ],
24                               onchange => 'stockcust_changed',
25                               curr_value_callback => $stock_or_customer,
26                             },
27                             { field => 'custnum',
28                               type => 'search-cust_main',
29                             },
30                             { type => 'tablebreak-tr-title',
31                               value => 'Order Items',
32                             },
33                             { 'field' => 'orderitemnum',
34                               'type' => 'did_order_item',
35                               'o2m_table' => 'did_order_item',
36                               'm2_label' => 'Item',
37                               'm2_error_callback' => $m2_error_callback,
38                             },
39                         ],
40               'labels' => { 
41                             'ordernum'        => 'Order',
42                             'vendornum'       => 'Vendor',
43                             'vendor_order_id' => 'Vendor Order #',
44                             'custnum'         => '',
45                             'confirmed'       => 'Confirmation Date',
46                             'orderitemnum'     => 'Item',
47                           },
48               'viewall_dir' => 'browse',
49               'table' => 'did_order',
50               'name' => 'Bulk DID Order',
51               'field_callback' => $field_callback,
52               'html_bottom' => $javascript,
53               'body_etc'        => 'onLoad="stockcust_changed()"',
54            )
55 %>
56 <%init>
57
58 die "access denied"
59   unless $FS::CurrentUser::CurrentUser->access_right('Import');
60
61 my $field_callback = sub {
62   my ($cgi, $object, $field_hashref ) = @_;
63   if ($object->ordernum) {
64     $field_hashref->{type} = 'text'
65         if $field_hashref->{field} eq 'vendor_order_id';
66     $field_hashref->{type} = 'input-date-field'
67         if $field_hashref->{field} eq 'confirmed';
68   }
69 };
70
71 my $m2_error_callback = sub {
72   my($cgi, $object) = @_;
73
74   #process_o2m fields in process/did_order.html
75   my @fields = qw( msanum npa latanum ratecenternum state quantity );
76   my @gfields = ( '', map "_$_", @fields );
77
78   map {
79         if ( /^orderitemnum(\d+)$/ ) {
80           my $num = $1;
81           if ( grep $cgi->param("orderitemnum$num$_"), @gfields ) {
82             my $x = new FS::did_order_item {
83               'orderitemnum' => scalar($cgi->param("orderitemnum$num")),
84               map { $_ => scalar($cgi->param("orderitemnum${num}_$_")) } @fields,
85             };
86             $x;
87           } else {
88             ();
89           }
90         } else {
91           ();
92         }
93       }
94       $cgi->param;
95 };
96
97 my $stock_or_customer = sub{
98     my($cgi,$object,$field) = @_;
99     return 'Customer' if $object->custnum;
100     'Stock';
101 };
102
103 my $javascript = <<END;
104     <SCRIPT TYPE="text/javascript">
105         function stockcust_changed() {
106             var f = document.edit_topform;
107             var custnum = f.custnum;
108             var custnum_search = f.custnum_search;
109             var custnum_select = f.custnum_select;
110             if ( f.stock_or_customer_Stock.checked ) {
111                 custnum_search.disabled = true;
112                 custnum_select.disabled = true;
113                 custnum.value = '';
114             }
115             else if ( f.stock_or_customer_Customer.checked ) {
116                 custnum_search.disabled = false;
117                 custnum_select.disabled = false;
118             }
119         }
120
121         /* o2m or something else is broken, can't put this in the actual
122             component because random JS and other crap is rendered 
123             onto the final output page */
124         function ratecenter_changed(rc) {
125             var idbase = rc.id.substring(0,rc.id.indexOf('_'));
126             var div = document.getElementById(idbase+'_rc_div');
127             var input = document.getElementById(idbase+'_rc_new');
128             if(rc.options[rc.selectedIndex].value == '0') {
129                 div.style.display = 'inline';
130             }
131             else {
132                 div.style.display = 'none';
133             }
134             input.value = '';
135         }
136     </SCRIPT>
137 END
138
139 </%init>