From: Moritz Bunkus Date: Fri, 17 Jun 2011 13:20:57 +0000 (+0200) Subject: Verwaltung von Kunden-/Lieferantentypen auf Controller umgestellt X-Git-Tag: release-2.7.0beta1~380 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=508801bbaf7b9c5e144bf7ab9763a342ab80f176;p=kivitendo-erp.git Verwaltung von Kunden-/Lieferantentypen auf Controller umgestellt --- diff --git a/SL/AM.pm b/SL/AM.pm index ff9fc46e2..1501b22e7 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -571,106 +571,6 @@ sub delete_lead { $main::lxdebug->leave_sub(); } -sub business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|SELECT id, description, discount, customernumberinit, salesman - FROM business - ORDER BY 2|; - - my $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { - push @{ $form->{ALL} }, $ref; - } - - $sth->finish; - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub get_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = - qq|SELECT b.description, b.discount, b.customernumberinit, b.salesman - FROM business b - WHERE b.id = ?|; - my $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); - - my $ref = $sth->fetchrow_hashref("NAME_lc"); - - map { $form->{$_} = $ref->{$_} } keys %$ref; - - $sth->finish; - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub save_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - my ($query); - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my @values = ($form->{description}, $form->{discount}, $form->{customernumberinit}, $form->{salesman} ? 't' : 'f'); - # id is the old record - if ($form->{id}) { - $query = qq|UPDATE business SET - description = ?, - discount = ?, - customernumberinit = ?, - salesman = ? - WHERE id = ?|; - push(@values, $form->{id}); - } else { - $query = qq|INSERT INTO business - (description, discount, customernumberinit, salesman) - VALUES (?, ?, ?, ?)|; - } - do_query($form, $dbh, $query, @values); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - -sub delete_business { - $main::lxdebug->enter_sub(); - - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my $query = qq|DELETE FROM business - WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - $dbh->disconnect; - - $main::lxdebug->leave_sub(); -} - - sub language { $main::lxdebug->enter_sub(); diff --git a/SL/Controller/Business.pm b/SL/Controller/Business.pm new file mode 100644 index 000000000..f7108bb33 --- /dev/null +++ b/SL/Controller/Business.pm @@ -0,0 +1,104 @@ +package SL::Controller::Business; + +use strict; + +use parent qw(SL::Controller::Base); + +use SL::DB::Business; +use SL::Helper::Flash; + +use Rose::Object::MakeMethods::Generic +( + scalar => [ qw(business) ], +); + +__PACKAGE__->run_before('check_auth'); +__PACKAGE__->run_before('load_business', only => [ qw(edit update destroy) ]); + +# +# actions +# + +sub action_list { + my ($self) = @_; + + $self->render('business/list', + title => $::locale->text('Businesses'), + BUSINESSS => SL::DB::Manager::Business->get_all_sorted); +} + +sub action_new { + my ($self) = @_; + + $self->{business} = SL::DB::Business->new; + $self->render('business/form', title => $::locale->text('Create a new business')); +} + +sub action_edit { + my ($self) = @_; + $self->render('business/form', title => $::locale->text('Edit business')); +} + +sub action_create { + my ($self) = @_; + + $self->{business} = SL::DB::Business->new; + $self->create_or_update; +} + +sub action_update { + my ($self) = @_; + $self->create_or_update; +} + +sub action_destroy { + my ($self) = @_; + + if (eval { $self->{business}->delete; 1; }) { + flash_later('info', $::locale->text('The business has been deleted.')); + } else { + flash_later('error', $::locale->text('The business is in use and cannot be deleted.')); + } + + $self->redirect_to(action => 'list'); +} + +# +# filters +# + +sub check_auth { + $::auth->assert('config'); +} + +# +# helpers +# + +sub create_or_update { + my $self = shift; + my $is_new = !$self->{business}->id; + my $params = delete($::form->{business}) || { }; + + $self->{business}->assign_attributes(%{ $params }); + + my @errors = $self->{business}->validate; + + if (@errors) { + flash('error', @errors); + $self->render('business/form', title => $is_new ? $::locale->text('Create a new business') : $::locale->text('Edit business')); + return; + } + + $self->{business}->save; + + flash_later('info', $is_new ? $::locale->text('The business has been created.') : $::locale->text('The business has been saved.')); + $self->redirect_to(action => 'list'); +} + +sub load_business { + my ($self) = @_; + $self->{business} = SL::DB::Business->new(id => $::form->{id})->load; +} + +1; diff --git a/SL/DB/Business.pm b/SL/DB/Business.pm index badd0b5b4..1fea0ef81 100644 --- a/SL/DB/Business.pm +++ b/SL/DB/Business.pm @@ -1,13 +1,19 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::Business; use strict; use SL::DB::MetaSetup::Business; +use SL::DB::Manager::Business; + +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The description is missing.') if !$self->description; + push @errors, $::locale->text('The discount must not be negative.') if $self->discount < 0; + push @errors, $::locale->text('The discount must be less than 100%.') if $self->discount >= 1; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; + return @errors; +} 1; diff --git a/SL/DB/Manager/Business.pm b/SL/DB/Manager/Business.pm new file mode 100644 index 000000000..8534d6a94 --- /dev/null +++ b/SL/DB/Manager/Business.pm @@ -0,0 +1,21 @@ +package SL::DB::Manager::Business; + +use strict; + +use SL::DB::Helper::Manager; +use base qw(SL::DB::Helper::Manager); + +use SL::DB::Helper::Sorted; + +sub object_class { 'SL::DB::Business' } + +__PACKAGE__->make_manager_methods; + +sub _sort_spec { + return ( default => [ 'description', 1 ], + columns => { SIMPLE => 'ALL', + map { ( $_ => "lower(business.$_)" ) } qw(description) + }); +} + +1; diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 0030eb51b..19bb23ab2 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -822,251 +822,6 @@ sub delete_lead { $main::lxdebug->leave_sub(); } -sub add_business { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - - $main::auth->assert('config'); - - $form->{title} = "Add"; - - $form->{callback} = "am.pl?action=add_business" unless $form->{callback}; - - &business_header; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub edit_business { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $form->{title} = "Edit"; - - AM->get_business(\%myconfig, \%$form); - - &business_header; - - $form->{orphaned} = 1; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub list_business { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - AM->business(\%myconfig, \%$form); - - $form->{callback} = "am.pl?action=list_business"; - - my $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Type of Business'); - - my @column_index = qw(description discount customernumberinit); - push @column_index, 'salesman' if $::lx_office_conf{features}->{vertreter}; - my %column_header; - $column_header{description} = - qq|| - . $locale->text('Description') - . qq||; - $column_header{discount} = - qq|| - . $locale->text('Discount') - . qq| %|; - $column_header{customernumberinit} = - qq|| - . $locale->text('Customernumberinit') - . qq||; - $column_header{salesman} = - qq|| - . $locale->text('Representative') - . qq||; - - $form->header; - - print qq| - - - - - - - - - - - - - -
$form->{title}
- - -|; - - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - - my ($i, %column_data); - foreach my $ref (@{ $form->{ALL} }) { - - $i++; - $i %= 2; - - print qq| - -|; - - my $discount = $form->format_amount(\%myconfig, $ref->{discount} * 100); - my $description = $ref->{description}; - $column_data{description} = qq||; - $column_data{discount} = qq||; - $column_data{customernumberinit} = - qq||; - $column_data{salesman} = ''; - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; - } - - print qq| -
$description$discount$ref->{customernumberinit}' . ($ref->{salesman} ? $::locale->text('Yes') : $::locale->text('No')) . '
-

- -
-
- - - - - - - -
- - - -|; - - $main::lxdebug->leave_sub(); -} - -sub business_header { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - $form->{title} = $locale->text("$form->{title} Business"); - - # $locale->text('Add Business') - # $locale->text('Edit Business') - - $form->{description} =~ s/\"/"/g; - $form->{discount} = - $form->format_amount(\%myconfig, $form->{discount} * 100); - - my $salesman_code; - if ($::lx_office_conf{features}->{vertreter}) { - $salesman_code = qq| - - | . $locale->text('Representative') . qq| - | . $::cgi->checkbox(-name => "salesman", -value => 1, -label => '', 'checked' => $form->{salesman} ? 1 : 0) . qq| - -|; - } else { - $salesman_code = $::cgi->hidden(-name => 'salesman', -value => $form->{salesman} ? 1 : 0); - } - - $form->header; - - print qq| - - -
- -{id}> - - - - - - - - - - - - - - - - - - - -$salesman_code - - -
$form->{title}
| . $locale->text('Type of Business') . qq|
| . $locale->text('Discount') . qq| %{discount}>
| . $locale->text('Customernumberinit') . qq|{customernumberinit}>

-|; - - $main::lxdebug->leave_sub(); -} - -sub save_business { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - $form->isblank("description", $locale->text('Description missing!')); - $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100; - AM->save_business(\%myconfig, \%$form); - $form->redirect($locale->text('Business saved!')); - - $main::lxdebug->leave_sub(); -} - -sub delete_business { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - AM->delete_business(\%myconfig, \%$form); - $form->redirect($locale->text('Business deleted!')); - - $main::lxdebug->leave_sub(); -} - sub add_language { $main::lxdebug->enter_sub(); diff --git a/locale/de/all b/locale/de/all index b89e04c2c..38a9eaefe 100644 --- a/locale/de/all +++ b/locale/de/all @@ -196,6 +196,7 @@ $self->{texts} = { 'Are you sure you want to delete Order Number' => 'Soll der Auftrag mit folgender Nummer wirklich gelöscht werden:', 'Are you sure you want to delete Quotation Number' => 'Sind Sie sicher, dass Angebotnummer gelöscht werden soll?', 'Are you sure you want to delete Transaction' => 'Buchung wirklich löschen?', + 'Are you sure you want to delete this business?' => 'Sind Sie sicher, dass Sie diesen Kunden-/Lieferantentyp löschen wollen?', 'Are you sure you want to delete this department?' => 'Sind Sie sicher, dass Sie diese Abteilung löschen wollen?', 'Are you sure you want to delete this payment term?' => 'Wollen Sie diese Zahlungsbedingungen wirklich löschen?', 'Are you sure you want to remove the marked entries from the queue?' => 'Sind Sie sicher, dass die markierten Einträge von der Warteschlange gelöscht werden sollen?', @@ -302,11 +303,10 @@ $self->{texts} = { 'Buchungsnummer' => 'Buchungsnummer', 'Business Number' => 'Firmennummer', 'Business Volume' => 'Geschäftsvolumen', - 'Business deleted!' => 'Firma gelöscht.', 'Business evaluation' => 'Betriebswirtschaftliche Auswertung', - 'Business saved!' => 'Firma gespeichert.', 'Business type (database ID)' => 'Kunden-/Lieferantentyp (Datenbank-ID)', 'Business type (name)' => 'Kunden-/Lieferantentyp (Name)', + 'Businesses' => 'Kunden-/Lieferantentypen', 'CANCELED' => 'Storniert', 'CB Transaction' => 'SB-Buchung', 'CR' => 'H', @@ -431,6 +431,7 @@ $self->{texts} = { 'Create Chart of Accounts' => 'Zu verwendender Kontenplan', 'Create Dataset' => 'Neue Datenbank anlegen', 'Create Date' => 'Erstelldatum', + 'Create a new business' => 'Einen neuen Kunden-/Lieferantentyp erfassen', 'Create a new department' => 'Eine neue Abteilung erfassen', 'Create a new payment term' => 'Neue Zahlungsbedingungen anlegen', 'Create a standard group' => 'Eine Standard-Benutzergruppe anlegen', @@ -452,6 +453,7 @@ $self->{texts} = { 'Create bank transfer via SEPA XML' => 'Überweisung via SEPA XML erzeugen', 'Create invoice?' => 'Rechnung erstellen?', 'Create new' => 'Neu erfassen', + 'Create new business' => 'Kunden-/Lieferantentyp erfassen', 'Create new department' => 'Neue Abteilung erfassen', 'Create new payment term' => 'Neue Zahlungsbedingung anlegen', 'Create tables' => 'Tabellen anlegen', @@ -670,7 +672,6 @@ $self->{texts} = { 'Edit Assembly' => 'Erzeugnis bearbeiten', 'Edit Bins' => 'Lagerplätze bearbeiten', 'Edit Buchungsgruppe' => 'Buchungsgruppe bearbeiten', - 'Edit Business' => 'Kunden-/Lieferantentyp bearbeiten', 'Edit Credit Note' => 'Gutschrift bearbeiten', 'Edit Customer' => 'Kunde editieren', 'Edit Dunning' => 'Mahnungen konfigurieren', @@ -704,6 +705,7 @@ $self->{texts} = { 'Edit Warehouse' => 'Lager bearbeiten', 'Edit and delete a group' => 'Gruppen bearbeiten und löschen', 'Edit bank account' => 'Bankkonto bearbeiten', + 'Edit business' => 'Kunden-/Lieferantentyp bearbeiten', 'Edit custom variable' => 'Benutzerdefinierte Variable bearbeiten', 'Edit department' => 'Abteilung bearbeiten', 'Edit file' => 'Datei bearbeiten', @@ -1158,6 +1160,7 @@ $self->{texts} = { 'No bank information has been entered in this customer\'s master data entry. You cannot create bank collections unless you enter bank information.' => 'Für diesen Kunden wurden in seinen Stammdaten keine Kontodaten hinterlegt. Solange dies nicht geschehen ist, können Sie keine Überweisungen für den Lieferanten anlegen.', 'No bank information has been entered in this vendor\'s master data entry. You cannot create bank transfers unless you enter bank information.' => 'Für diesen Lieferanten wurden in seinen Stammdaten keine Kontodaten hinterlegt. Solange dies nicht geschehen ist, können Sie keine Überweisungen für den Lieferanten anlegen.', 'No bins have been added to this warehouse yet.' => 'Es wurden zu diesem Lager noch keine Lagerplätze angelegt.', + 'No business has been created yet.' => 'Es wurden noch kein Kunden-/Lieferantentyp erfasst.', 'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.', 'No data was found.' => 'Es wurden keine Daten gefunden.', 'No databases have been found on this server.' => 'Auf diesem Server wurden keine Datenbanken gefunden.', @@ -1727,6 +1730,10 @@ $self->{texts} = { 'The base unit does not exist or it is about to be deleted in row %d.' => 'Die Basiseinheit in Zeile %d existiert nicht oder soll gelöscht werden.', 'The base unit does not exist.' => 'Die Basiseinheit existiert nicht.', 'The base unit relations must not contain loops (e.g. by saying that unit A\'s base unit is B, B\'s base unit is C and C\'s base unit is A) in row %d.' => 'Die Beziehungen der Einheiten dürfen keine Schleifen beinhalten (z.B. wenn gesagt wird, dass Einheit As Basiseinheit B, Bs Basiseinheit C und Cs Basiseinheit A ist) in Zeile %d.', + 'The business has been created.' => 'Der Kunden-/Lieferantentyp wurde erfasst.', + 'The business has been deleted.' => 'Der Kunden-/Lieferantentyp wurde gelöscht.', + 'The business has been saved.' => 'Der Kunden-/Lieferantentyp wurde gespeichert.', + 'The business is in use and cannot be deleted.' => 'Der Kunden-/Lieferantentyp wird benutzt und kann nicht gelöscht werden.', 'The columns "Dunning Duedate", "Total Fees" and "Interest" show data for the previous dunning created for this invoice.' => 'Die Spalten "Zahlbar bis", "Kumulierte Gebühren" und "Zinsen" zeigen Daten der letzten für diese Rechnung erzeugten Mahnung.', 'The connection to the LDAP server cannot be encrypted (SSL/TLS startup failure). Please check config/lx_office.conf.' => 'Die Verbindung zum LDAP-Server kann nicht verschlüsselt werden (Fehler bei SSL/TLS-Initialisierung). Bitte überprüfen Sie die Angaben in config/lx_office.conf.', 'The connection to the authentication database failed:' => 'Die Verbindung zur Authentifizierungsdatenbank schlug fehl:', @@ -1757,6 +1764,8 @@ $self->{texts} = { 'The directory "%s" could not be created:\n%s' => 'Das Verzeichnis "%s" konnte nicht erstellt werden:\n%s', 'The directory %s does not exist.' => 'Das Verzeichnis %s existiert nicht.', 'The discount in percent' => 'Der prozentuale Rabatt', + 'The discount must be less than 100%.' => 'Der Rabatt muss kleiner als 100% sein.', + 'The discount must not be negative.' => 'Der Rabatt darf nicht negativ sein.', 'The dunning process started' => 'Der Mahnprozess ist gestartet.', 'The dunnings have been printed.' => 'Die Mahnung(en) wurden gedruckt.', 'The email address is missing.' => 'Die Emailadresse fehlt.', diff --git a/menu.ini b/menu.ini index 46292a0e7..347ae23a1 100644 --- a/menu.ini +++ b/menu.ini @@ -647,12 +647,12 @@ target=acc_menu submenu=1 [System--Type of Business--Add Business] -module=am.pl -action=add_business +module=controller.pl +action=Business/new [System--Type of Business--List Businesses] -module=am.pl -action=list_business +module=controller.pl +action=Business/list [System--Lead] module=menu.pl diff --git a/templates/webpages/business/form.html b/templates/webpages/business/form.html new file mode 100644 index 000000000..01d5726bc --- /dev/null +++ b/templates/webpages/business/form.html @@ -0,0 +1,44 @@ +[% USE HTML %][% USE L %][% USE LxERP %] + + + +
[% FORM.title %]
+ +[%- INCLUDE 'common/flash.html' %] + + + + + + + + + + + + + + + + + + [%- IF LXCONFIG.features.vertreter %] + + + + + [%- END %] +
[%- LxERP.t8('Description') %][% L.input_tag("business.description", SELF.business.description, "size", 30) %]
[%- LxERP.t8('Discount') %][% L.input_tag("business.discount_as_percent", SELF.business.discount_as_percent, "size", 5) %]%
[%- LxERP.t8('Customernumberinit') %][% L.input_tag("business.customernumberinit", SELF.business.customernumberinit, "size", 10) %]
[%- LxERP.t8('Representative') %][% L.checkbox_tag("business.salesman", "value", 1, "checked", SELF.business.salesman) %]
+ +

+ [% L.hidden_tag("id", SELF.business.id) %] + [% L.hidden_tag("action", "Business/dispatch") %] + [% L.submit_tag("action_" _ (SELF.business.id ? "update" : "create"), LxERP.t8('Save')) %] + [%- IF SELF.business.id %] + [% L.submit_tag("action_destroy", LxERP.t8("Delete"), "confirm", LxERP.t8("Are you sure you want to delete this business?")) %] + [%- END %] + [%- LxERP.t8('Abort') %] +

+
+ + diff --git a/templates/webpages/business/list.html b/templates/webpages/business/list.html new file mode 100644 index 000000000..80bfed719 --- /dev/null +++ b/templates/webpages/business/list.html @@ -0,0 +1,53 @@ +[% USE HTML %][% USE L %][% USE LxERP %] + + +
[% FORM.title %]
+ +[%- INCLUDE 'common/flash.html' %] + +
+ [% IF !BUSINESSS.size %] +

+ [%- LxERP.t8('No business has been created yet.') %] +

+ + [%- ELSE %] + + + + + + + [%- IF LXCONFIG.features.vertreter %] + + [%- END %] + + + + + [%- FOREACH business = BUSINESSS %] + + + + + [%- IF LXCONFIG.features.vertreter %] + + [%- END %] + + [%- END %] + +
[%- LxERP.t8('Description') %][%- LxERP.t8('Discount') %][%- LxERP.t8('Customernumberinit') %][%- LxERP.t8('Representative') %]
+ + [%- HTML.escape(business.description) %] + + [% LxERP.format_amount(business.discount * 100) %] %[%- HTML.escape(business.customernumberinit) %][%- IF business.salesman %][%- LxERP.t8('Yes') %][%- ELSE %][%- LxERP.t8('No') %][%- END %]
+ [%- END %] + +
+ +

+ [%- LxERP.t8('Create new business') %] +

+
+ +