<% include( 'elements/edit.html', 'fields' => [ { field => 'vendornum', type => 'select-table', name_col => 'vendorname', table => 'did_vendor', disable_empty => 1, }, { field => 'vendor_order_id', type => 'hidden', }, { field => 'confirmed', type => 'hidden', }, { field => 'received', type => 'hidden', }, { field => 'submitted', type => 'hidden', }, { field => 'stock_or_customer', type => 'radio', options => [ 'Stock', 'Customer', ], onchange => 'stockcust_changed', curr_value_callback => $stock_or_customer, }, { field => 'custnum', type => 'search-cust_main', }, { type => 'tablebreak-tr-title', value => 'Order Items', }, { 'field' => 'orderitemnum', 'type' => 'did_order_item', 'o2m_table' => 'did_order_item', 'm2_label' => 'Item', 'm2_error_callback' => $m2_error_callback, }, ], 'labels' => { 'ordernum' => 'Order', 'vendornum' => 'Vendor', 'vendor_order_id' => 'Vendor Order #', 'custnum' => '', 'confirmed' => 'Confirmation Date', 'orderitemnum' => 'Item', }, 'viewall_dir' => 'browse', 'table' => 'did_order', 'name' => 'Bulk DID Order', 'field_callback' => $field_callback, 'html_bottom' => $javascript, 'body_etc' => 'onLoad="stockcust_changed()"', ) %> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); my $field_callback = sub { my ($cgi, $object, $field_hashref ) = @_; if ($object->ordernum) { $field_hashref->{type} = 'text' if $field_hashref->{field} eq 'vendor_order_id'; $field_hashref->{type} = 'input-date-field' if $field_hashref->{field} eq 'confirmed'; } }; my $m2_error_callback = sub { my($cgi, $object) = @_; #process_o2m fields in process/did_order.html my @fields = qw( msanum npa latanum ratecenternum state quantity ); my @gfields = ( '', map "_$_", @fields ); map { if ( /^orderitemnum(\d+)$/ ) { my $num = $1; if ( grep $cgi->param("orderitemnum$num$_"), @gfields ) { my $x = new FS::did_order_item { 'orderitemnum' => scalar($cgi->param("orderitemnum$num")), map { $_ => scalar($cgi->param("orderitemnum${num}_$_")) } @fields, }; $x; } else { (); } } else { (); } } $cgi->param; }; my $stock_or_customer = sub{ my($cgi,$object,$field) = @_; return 'Customer' if $object->custnum; 'Stock'; }; my $javascript = < function stockcust_changed() { var f = document.edit_topform; var custnum = f.custnum; var custnum_search = f.custnum_search; var custnum_select = f.custnum_select; if ( f.stock_or_customer_Stock.checked ) { custnum_search.disabled = true; custnum_select.disabled = true; custnum.value = ''; } else if ( f.stock_or_customer_Customer.checked ) { custnum_search.disabled = false; custnum_select.disabled = false; } } /* o2m or something else is broken, can't put this in the actual component because random JS and other crap is rendered onto the final output page */ function ratecenter_changed(rc) { var idbase = rc.id.substring(0,rc.id.indexOf('_')); var div = document.getElementById(idbase+'_rc_div'); var input = document.getElementById(idbase+'_rc_new'); if(rc.options[rc.selectedIndex].value == '0') { div.style.display = 'inline'; } else { div.style.display = 'none'; } input.value = ''; } END