X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/cb2abccdef0236f43a1712cb2b39db4ce57a2d40..4f6a2fa1d46212e189bc46a04fce62a77120e02f:/bin/mozilla/ct.pl diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index b47d8e262..dbf8cdd82 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -288,7 +288,7 @@ sub edit { # format discount $form->{discount} *= 100; # format uri - $form->{homepage} = 'http://' . $form->{homepage} unless $form->{homepage} =~ m|^https?://|; + $form->{homepage} = 'http://' . $form->{homepage} unless ((!$form->{homepage}) || $form->{homepage} =~ m|^https?://|); &form_header; &form_footer; @@ -314,17 +314,17 @@ sub form_header { my %myconfig = %main::myconfig; my $locale = $main::locale; - $form->get_lists(employees => "ALL_EMPLOYEES", - taxzones => "ALL_TAXZONES", + $form->get_lists(taxzones => "ALL_TAXZONES", currencies => "ALL_CURRENCIES"); $form->get_pricegroup(\%myconfig, { all => 1 }); $form->get_lists(customers => { key => "ALL_SALESMAN_CUSTOMERS", business_is_salesman => 1 }) if $::lx_office_conf{features}->{vertreter}; + $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{FU_created_for_user}, deleted => 0 ] ]); + $form->{ALL_SALESMEN} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{salesman_id}, deleted => 0 ] ]); + $form->{USER} = SL::DB::Manager::Employee->current; - $form->{ALL_SALESMEN} = $form->{ALL_EMPLOYEES}; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $form->{is_customer} = $form->{db} eq 'customer'; - $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} }; $form->{shipto_label} = \&_shipto_label; $form->{contacts_label} = \&_contacts_label; $form->{taxzone_id} = 0 if !$form->{id}; @@ -353,9 +353,18 @@ sub form_header { $form->{currency} = $form->{curr}; } - $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'CT', 'trans_id' => $form->{id}); + $::form->{CUSTOM_VARIABLES} = { }; + my %specs = ( CT => { field => 'id', name_prefix => '', }, + Contacts => { field => 'cp_id', name_prefix => 'cp', }, + ); - CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} }); + for my $module (keys %specs) { + my $spec = $specs{$module}; + + $::form->{CUSTOM_VARIABLES}->{$module} = CVar->get_custom_variables(module => $module, trans_id => $::form->{ $spec->{field} }); + CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}->{$module}, name_prefix => $spec->{name_prefix}) + if scalar @{ $::form->{CUSTOM_VARIABLES}->{$module} }; + } $form->header; print $form->parse_html_template('ct/form_header'); @@ -672,6 +681,10 @@ sub get_contact { CT->query_titles_and_greetings(\%::myconfig, $::form); CT->get_contact(\%::myconfig, $::form) if $::form->{cp_id}; + $::form->{CUSTOM_VARIABLES}{Contacts} = CVar->get_custom_variables(module => 'Contacts', trans_id => $::form->{cp_id}); + CVar->render_inputs(variables => $::form->{CUSTOM_VARIABLES}{Contacts}, name_prefix => 'cp') + if scalar @{ $::form->{CUSTOM_VARIABLES}->{Contacts} }; + $::form->{contacts_label} = \&_contacts_label; print $::form->ajax_response_header(), $::form->parse_html_template('ct/_contact'); @@ -711,41 +724,53 @@ sub get_delivery { } sub delete_shipto { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('customer_vendor_edit'); - $main::auth->assert('customer_vendor_edit'); + if (!$::form->{shipto_id}) { + flash('error', $::locale->text('No shipto selected to delete')); + } else { - my $form = $main::form; - my %myconfig = %main::myconfig; + CT->get_shipto(\%::myconfig, $::form); - CT->get_shipto(\%myconfig, \%$form); + my $shipto = SL::DB::Manager::Shipto->find_by(shipto_id => $::form->{shipto_id}); - unless ($form->{shiptoused}) { - CT->delete_shipto($form->{shipto_id}); - @$form{ grep /^shipto/, keys %$form } = undef; + if ($shipto->used) { + $shipto->detach->save; + flash('info', $::locale->text('Shipto is in use and was flagged invalid.')); + } else { + $shipto->delete; + flash('info', $::locale->text('Shipto deleted.')); + } + delete $::form->{$_} for grep /^shipto/, keys %$::form; } edit(); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub delete_contact { $::lxdebug->enter_sub; $::auth->assert('customer_vendor_edit'); - CT->get_contact(\%::myconfig, $::form); + if (!$::form->{cp_id}) { + flash('error', $::locale->text('No contact selected to delete')); + } else { - my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id}); + CT->get_contact(\%::myconfig, $::form); - if ($contact->used) { - $contact->detach; - flash('info', $::locale->text('Contact is in use and was flagged invalid.')); - } else { - $contact->delete; - flash('info', $::locale->text('Contact deleted.')); + my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{cp_id}); + + if ($contact->used) { + $contact->detach->save; + flash('info', $::locale->text('Contact is in use and was flagged invalid.')); + } else { + $contact->delete; + flash('info', $::locale->text('Contact deleted.')); + } + delete $::form->{$_} for grep /^cp_/, keys %$::form; } - delete $::form->{$_} for grep /^cp_/, keys %$::form; edit();