From: Bernd Bleßmann Date: Mon, 27 May 2013 09:48:09 +0000 (+0200) Subject: Lieferbedingungen analog zu Zahlungsbedingungen eingeführt. X-Git-Tag: release-3.1.0beta1~22^2~102^2^2~7 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=03d3d025ea4c8bea085fc7cdf1fe7be0b513eb63;p=kivitendo-erp.git Lieferbedingungen analog zu Zahlungsbedingungen eingeführt. Sie können angelegt werden, beim Benutzer voreingestellt werden und in allen Ein- und Verkaufsmasken gesetzt werden. --- diff --git a/SL/CT.pm b/SL/CT.pm index cae50f0fb..8ceab3aa6 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -322,7 +322,8 @@ sub save_customer { qq|c_vendor_id = ?, | . qq|klass = ?, | . qq|currency_id = (SELECT id FROM currencies WHERE name = ?), | . - qq|taxincluded_checked = ? | . + qq|taxincluded_checked = ?, | . + qq|delivery_term_id = ? | . qq|WHERE id = ?|; my @values = ( $form->{customernumber}, @@ -366,6 +367,7 @@ sub save_customer { conv_i($form->{klass}), $form->{currency}, $form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef, + conv_i($form->{delivery_term_id}), $form->{id} ); do_query( $form, $dbh, $query, @values ); @@ -473,7 +475,8 @@ sub save_vendor { qq| username = ?, | . qq| user_password = ?, | . qq| v_customer_id = ?, | . - qq| currency_id = (SELECT id FROM currencies WHERE name = ?) | . + qq| currency_id = (SELECT id FROM currencies WHERE name = ?), | . + qq| delivery_term_id = ? | . qq|WHERE id = ?|; my @values = ( $form->{vendornumber}, @@ -514,6 +517,7 @@ sub save_vendor { $form->{user_password}, $form->{v_customer_id}, $form->{currency}, + conv_i($form->{delivery_term_id}), $form->{id} ); do_query($form, $dbh, $query, @values); diff --git a/SL/Common.pm b/SL/Common.pm index d6260251e..127209a7f 100644 --- a/SL/Common.pm +++ b/SL/Common.pm @@ -397,11 +397,13 @@ sub get_vc_details { vc.*, pt.description AS payment_terms, b.description AS business, - l.description AS language + l.description AS language, + dt.description AS delivery_terms FROM ${vc} vc LEFT JOIN payment_terms pt ON (vc.payment_id = pt.id) LEFT JOIN business b ON (vc.business_id = b.id) LEFT JOIN language l ON (vc.language_id = l.id) + LEFT JOIN delivery_terms dt ON (vc.delivery_term_id = dt.id) WHERE vc.id = ?|; my $ref = selectfirst_hashref_query($form, $dbh, $query, $vc_id); diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index a74acb66b..f8e9b591c 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -8,6 +8,7 @@ use SL::Helper::Csv; use SL::DB::Customer; use SL::DB::Language; use SL::DB::PaymentTerm; +use SL::DB::DeliveryTerm; use SL::DB::Vendor; use SL::DB::Contact; use SL::DB::History; @@ -17,7 +18,7 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(controller file csv test_run save_with_cascade) ], - 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ], + 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by delivery_terms_by all_vc vc_by) ], ); sub run { @@ -146,6 +147,13 @@ sub init_payment_terms_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_payment_terms } } ) } qw(id description) }; } +sub init_delivery_terms_by { + my ($self) = @_; + + my $all_delivery_terms = SL::DB::Manager::DeliveryTerm->get_all; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_delivery_terms } } ) } qw(id description) }; +} + sub init_all_vc { my ($self) = @_; @@ -382,6 +390,32 @@ sub check_payment { return 1; } +sub check_delivery_term { + my ($self, $entry) = @_; + + my $object = $entry->{object}; + + # Check whether or not delivery term ID is valid. + if ($object->delivery_term_id && !$self->delivery_terms_by->{id}->{ $object->delivery_term_id }) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid delivery terms'); + return 0; + } + + # Map name to ID if given. + if (!$object->delivery_term_id && $entry->{raw_data}->{delivery_term}) { + my $terms = $self->delivery_terms_by->{description}->{ $entry->{raw_data}->{delivery_term} }; + + if (!$terms) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid delivery terms'); + return 0; + } + + $object->delivery_term_id($terms->id); + } + + return 1; +} + sub save_objects { my ($self, %params) = @_; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index 9e0c4d5a0..14b67305f 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -66,6 +66,7 @@ sub check_objects { $self->check_language($entry); $self->check_business($entry); $self->check_payment($entry); + $self->check_delivery_term($entry); $self->check_currency($entry, take_default => 1); $self->handle_cvars($entry); @@ -99,7 +100,7 @@ sub check_objects { $i++; } - $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment)); + $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment delivery_term)); $self->add_cvar_raw_data_columns; } @@ -231,7 +232,7 @@ sub init_profile { my ($self) = @_; my $profile = $self->SUPER::init_profile; - delete @{$profile}{qw(business datevexport language payment salesman salesman_id taxincluded terms)}; + delete @{$profile}{qw(business datevexport language payment delivery_term salesman salesman_id taxincluded terms)}; return $profile; } @@ -260,6 +261,8 @@ sub setup_displayable_columns { { name => 'customernumber', description => $::locale->text('Customer Number') }, { name => 'department_1', description => $::locale->text('Department 1') }, { name => 'department_2', description => $::locale->text('Department 2') }, + { name => 'delivery_term_id', description => $::locale->text('Delivery terms (database ID)') }, + { name => 'delivery_term', description => $::locale->text('Delivery terms (name)') }, { name => 'direct_debit', description => $::locale->text('direct debit') }, { name => 'discount', description => $::locale->text('Discount') }, { name => 'email', description => $::locale->text('E-mail') }, diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 7577ef047..fe7301936 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -102,6 +102,8 @@ sub setup_displayable_columns { { name => 'currency_id', description => $::locale->text('Currency (database ID)') }, { name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, { name => 'delivered', description => $::locale->text('Delivered') }, + { name => 'delivery_term_id', description => $::locale->text('Delivery terms (database ID)') }, + { name => 'delivery_term', description => $::locale->text('Delivery terms (name)') }, { name => 'employee_id', description => $::locale->text('Employee (database ID)') }, { name => 'intnotes', description => $::locale->text('Internal Notes') }, { name => 'marge_percent', description => $::locale->text('Margepercent') }, @@ -270,7 +272,7 @@ sub check_objects { { header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); # Todo: access via ->[0] ok? Better: search first order column and use this $self->add_columns($self->_order_column, - map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp currency)); + map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment delivery_term language department globalproject taxzone cp currency)); $self->add_columns($self->_order_column, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber}; $self->add_columns($self->_order_column, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact}; @@ -321,6 +323,7 @@ sub handle_order { $self->check_contact($entry); $self->check_language($entry); $self->check_payment($entry); + $self->check_delivery_term($entry); $self->check_department($entry); $self->check_project($entry, global => 1); $self->check_ct_shipto($entry); diff --git a/SL/Controller/CustomerVendor.pm b/SL/Controller/CustomerVendor.pm index 0ffa2f589..e81e387d3 100644 --- a/SL/Controller/CustomerVendor.pm +++ b/SL/Controller/CustomerVendor.pm @@ -810,6 +810,8 @@ sub _pre_render { $self->{all_payment_terms} = SL::DB::Manager::PaymentTerm->get_all(); + $self->{all_delivery_terms} = SL::DB::Manager::DeliveryTerm->get_all(); + $self->{all_pricegroups} = SL::DB::Manager::Pricegroup->get_all(); $query = diff --git a/SL/Controller/DeliveryTerm.pm b/SL/Controller/DeliveryTerm.pm new file mode 100644 index 000000000..3c4d44a9f --- /dev/null +++ b/SL/Controller/DeliveryTerm.pm @@ -0,0 +1,116 @@ +package SL::Controller::DeliveryTerm; + +use strict; + +use parent qw(SL::Controller::Base); + +use SL::DB::DeliveryTerm; +use SL::Helper::Flash; + +use Rose::Object::MakeMethods::Generic +( + scalar => [ qw(delivery_term) ], +); + +__PACKAGE__->run_before('check_auth'); +__PACKAGE__->run_before('load_delivery_term', only => [ qw(edit update destroy) ]); + + +# +# actions +# + +sub action_list { + my ($self) = @_; + + $self->render('delivery_term/list', + title => $::locale->text('Delivery terms'), + DELIVERY_TERMS => SL::DB::Manager::DeliveryTerm->get_all_sorted); +} + +sub action_new { + my ($self) = @_; + + $self->{delivery_term} = SL::DB::DeliveryTerm->new; + $self->render('delivery_term/form', title => $::locale->text('Create a new delivery term')); +} + +sub action_edit { + my ($self) = @_; + $self->render('delivery_term/form', title => $::locale->text('Edit delivery term')); +} + +sub action_create { + my ($self) = @_; + + $self->{delivery_term} = SL::DB::DeliveryTerm->new; + $self->create_or_update; +} + +sub action_update { + my ($self) = @_; + $self->create_or_update; +} + +sub action_destroy { + my ($self) = @_; + + if (eval { $self->{delivery_term}->delete; 1; }) { + flash_later('info', $::locale->text('The delivery term has been deleted.')); + } else { + flash_later('error', $::locale->text('The delivery term is in use and cannot be deleted.')); + } + + $self->redirect_to(action => 'list'); +} + +sub action_reorder { + my ($self) = @_; + + SL::DB::DeliveryTerm->reorder_list(@{ $::form->{delivery_term_id} || [] }); + + $self->render(\'', { type => 'json' }); # ' make Emacs happy +} + +# +# filters +# + +sub check_auth { + $::auth->assert('config'); +} + +# +# helpers +# + +sub create_or_update { + my $self = shift; + my $is_new = !$self->{delivery_term}->id; + my $params = delete($::form->{delivery_term}) || { }; + + $self->{delivery_term}->assign_attributes(%{ $params }); + + my @errors = $self->{delivery_term}->validate; + + if (@errors) { + flash('error', @errors); + $self->render('delivery_term/form', title => $is_new ? $::locale->text('Create a new delivery term') : $::locale->text('Edit delivery term')); + return; + } + + $self->{delivery_term}->save; + foreach my $language (@{ $self->{languages} }) { + $self->{delivery_term}->save_attribute_translation('description_long', $language, $::form->{"translation_" . $language->id}); + } + + flash_later('info', $is_new ? $::locale->text('The delivery term has been created.') : $::locale->text('The delivery term has been saved.')); + $self->redirect_to(action => 'list'); +} + +sub load_delivery_term { + my ($self) = @_; + $self->{delivery_term} = SL::DB::DeliveryTerm->new(id => $::form->{id})->load; +} + +1; diff --git a/SL/DB/DeliveryTerm.pm b/SL/DB/DeliveryTerm.pm new file mode 100644 index 000000000..c315e9bfd --- /dev/null +++ b/SL/DB/DeliveryTerm.pm @@ -0,0 +1,23 @@ +# 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::DeliveryTerm; + +use strict; + +use SL::DB::MetaSetup::DeliveryTerm; +use SL::DB::Manager::DeliveryTerm; +use SL::DB::Helper::ActsAsList; + + +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The description is missing.') if !$self->description; + push @errors, $::locale->text('The long description is missing.') if !$self->description_long; + + return @errors; +} + +1; diff --git a/SL/DB/Helper/ALL.pm b/SL/DB/Helper/ALL.pm index 325a96cc2..446356775 100644 --- a/SL/DB/Helper/ALL.pm +++ b/SL/DB/Helper/ALL.pm @@ -36,6 +36,7 @@ use SL::DB::Default; use SL::DB::DeliveryOrder; use SL::DB::DeliveryOrderItem; use SL::DB::DeliveryOrderItemsStock; +use SL::DB::DeliveryTerm; use SL::DB::Department; use SL::DB::Draft; use SL::DB::Dunning; diff --git a/SL/DB/Helper/FlattenToForm.pm b/SL/DB/Helper/FlattenToForm.pm index 95152593b..105cf020f 100644 --- a/SL/DB/Helper/FlattenToForm.pm +++ b/SL/DB/Helper/FlattenToForm.pm @@ -17,7 +17,7 @@ sub flatten_to_form { _copy($self, $form, '', '', 0, qw(id type taxzone_id ordnumber quonumber invnumber donumber cusordnumber taxincluded shippingpoint shipvia notes intnotes cp_id employee_id salesman_id closed department_id language_id payment_id delivery_customer_id delivery_vendor_id shipto_id proforma globalproject_id delivered transaction_description container_type accepted_by_customer invoice terms storno storno_id dunning_config_id - orddate quodate reqdate gldate duedate deliverydate datepaid transdate)); + orddate quodate reqdate gldate duedate deliverydate datepaid transdate delivery_term_id)); $form->{currency} = $form->{curr} = $self->currency_id ? $self->currency->name || '' : ''; if (_has($self, 'transdate')) { diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 3842af6e7..7f7269923 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -117,7 +117,7 @@ sub new_from { my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber quonumber department_id cp_id language_id payment_id delivery_customer_id delivery_vendor_id taxzone_id shipto_id - globalproject_id transaction_description currency_id)), + globalproject_id transaction_description currency_id delivery_term_id)), transdate => DateTime->today_local, gldate => DateTime->today_local, duedate => DateTime->today_local->add(days => $terms * 1), diff --git a/SL/DB/Manager/DeliveryTerm.pm b/SL/DB/Manager/DeliveryTerm.pm new file mode 100644 index 000000000..6ac2f0a38 --- /dev/null +++ b/SL/DB/Manager/DeliveryTerm.pm @@ -0,0 +1,21 @@ +package SL::DB::Manager::DeliveryTerm; + +use strict; + +use SL::DB::Helper::Manager; +use base qw(SL::DB::Helper::Manager); + +use SL::DB::Helper::Sorted; + +sub object_class { 'SL::DB::DeliveryTerm' } + +__PACKAGE__->make_manager_methods; + +sub _sort_spec { + return ( default => [ 'sortkey', 1 ], + columns => { SIMPLE => 'ALL', + map { ( $_ => "lower(delivery_terms.${_})" ) } qw(description description_long), + }); +} + +1; diff --git a/SL/DB/MetaSetup/Customer.pm b/SL/DB/MetaSetup/Customer.pm index 1752d2a16..2d5a155b9 100644 --- a/SL/DB/MetaSetup/Customer.pm +++ b/SL/DB/MetaSetup/Customer.pm @@ -23,6 +23,7 @@ __PACKAGE__->meta->columns( creditlimit => { type => 'numeric', default => '0', precision => 5, scale => 15 }, currency_id => { type => 'integer', not_null => 1 }, customernumber => { type => 'text' }, + delivery_term_id => { type => 'integer' }, department_1 => { type => 'varchar', length => 75 }, department_2 => { type => 'varchar', length => 75 }, direct_debit => { type => 'boolean', default => 'false' }, @@ -71,6 +72,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { currency_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + language_obj => { class => 'SL::DB::Language', key_columns => { language_id => 'id' }, diff --git a/SL/DB/MetaSetup/DeliveryOrder.pm b/SL/DB/MetaSetup/DeliveryOrder.pm index 92d45ae14..a1efe9a84 100644 --- a/SL/DB/MetaSetup/DeliveryOrder.pm +++ b/SL/DB/MetaSetup/DeliveryOrder.pm @@ -15,6 +15,7 @@ __PACKAGE__->meta->columns( cusordnumber => { type => 'text' }, customer_id => { type => 'integer' }, delivered => { type => 'boolean', default => 'false' }, + delivery_term_id => { type => 'integer' }, department_id => { type => 'integer' }, donumber => { type => 'text', not_null => 1 }, employee_id => { type => 'integer' }, @@ -61,6 +62,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { customer_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + department => { class => 'SL::DB::Department', key_columns => { department_id => 'id' }, diff --git a/SL/DB/MetaSetup/DeliveryTerm.pm b/SL/DB/MetaSetup/DeliveryTerm.pm new file mode 100644 index 000000000..ebcc7eaf1 --- /dev/null +++ b/SL/DB/MetaSetup/DeliveryTerm.pm @@ -0,0 +1,27 @@ +# This file has been auto-generated. Do not modify it; it will be overwritten +# by rose_auto_create_model.pl automatically. +package SL::DB::DeliveryTerm; + +use strict; + +use base qw(SL::DB::Object); + +__PACKAGE__->meta->setup( + table => 'delivery_terms', + + columns => [ + id => { type => 'integer', not_null => 1, sequence => 'id' }, + description => { type => 'text' }, + description_long => { type => 'text' }, + sortkey => { type => 'integer', not_null => 1 }, + itime => { type => 'timestamp', default => 'now()' }, + mtime => { type => 'timestamp' }, + ], + + primary_key_columns => [ 'id' ], + + allow_inline_column_values => 1, +); + +1; +; diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index eedecb4ad..1a8d1f00d 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -16,6 +16,7 @@ __PACKAGE__->meta->columns( customer_id => { type => 'integer' }, datepaid => { type => 'date' }, delivery_customer_id => { type => 'integer' }, + delivery_term_id => { type => 'integer' }, delivery_vendor_id => { type => 'integer' }, deliverydate => { type => 'date' }, department_id => { type => 'integer' }, @@ -78,6 +79,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { customer_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + department => { class => 'SL::DB::Department', key_columns => { department_id => 'id' }, diff --git a/SL/DB/MetaSetup/Order.pm b/SL/DB/MetaSetup/Order.pm index 249ea62fc..3e4a3102f 100644 --- a/SL/DB/MetaSetup/Order.pm +++ b/SL/DB/MetaSetup/Order.pm @@ -17,6 +17,7 @@ __PACKAGE__->meta->columns( customer_id => { type => 'integer' }, delivered => { type => 'boolean', default => 'false' }, delivery_customer_id => { type => 'integer' }, + delivery_term_id => { type => 'integer' }, delivery_vendor_id => { type => 'integer' }, department_id => { type => 'integer' }, employee_id => { type => 'integer' }, @@ -72,6 +73,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { delivery_customer_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + delivery_vendor => { class => 'SL::DB::Vendor', key_columns => { delivery_vendor_id => 'id' }, diff --git a/SL/DB/MetaSetup/PurchaseInvoice.pm b/SL/DB/MetaSetup/PurchaseInvoice.pm index 4b89dca76..5aa278566 100644 --- a/SL/DB/MetaSetup/PurchaseInvoice.pm +++ b/SL/DB/MetaSetup/PurchaseInvoice.pm @@ -13,6 +13,7 @@ __PACKAGE__->meta->columns( cp_id => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, datepaid => { type => 'date' }, + delivery_term_id => { type => 'integer' }, deliverydate => { type => 'date' }, department_id => { type => 'integer' }, direct_debit => { type => 'boolean', default => 'false' }, @@ -61,6 +62,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { currency_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + department => { class => 'SL::DB::Department', key_columns => { department_id => 'id' }, diff --git a/SL/DB/MetaSetup/Vendor.pm b/SL/DB/MetaSetup/Vendor.pm index 1a691ff6d..f2988ad74 100644 --- a/SL/DB/MetaSetup/Vendor.pm +++ b/SL/DB/MetaSetup/Vendor.pm @@ -9,49 +9,50 @@ use base qw(SL::DB::Object); __PACKAGE__->meta->table('vendor'); __PACKAGE__->meta->columns( - account_number => { type => 'varchar', length => 15 }, - bank => { type => 'text' }, - bank_code => { type => 'varchar', length => 10 }, - bcc => { type => 'text' }, - bic => { type => 'varchar', length => 100 }, - business_id => { type => 'integer' }, - cc => { type => 'text' }, - city => { type => 'varchar', length => 75 }, - contact => { type => 'varchar', length => 75 }, - country => { type => 'varchar', length => 75 }, - creditlimit => { type => 'numeric', precision => 5, scale => 15 }, - currency_id => { type => 'integer', not_null => 1 }, - department_1 => { type => 'varchar', length => 75 }, - department_2 => { type => 'varchar', length => 75 }, - direct_debit => { type => 'boolean', default => 'false' }, - discount => { type => 'float', precision => 4 }, - email => { type => 'text' }, - fax => { type => 'varchar', length => 30 }, - greeting => { type => 'text' }, - homepage => { type => 'text' }, - iban => { type => 'varchar', length => 100 }, - id => { type => 'integer', not_null => 1, sequence => 'id' }, - itime => { type => 'timestamp', default => 'now()' }, - language => { type => 'varchar', length => 5 }, - language_id => { type => 'integer' }, - mtime => { type => 'timestamp' }, - name => { type => 'varchar', length => 75, not_null => 1 }, - notes => { type => 'text' }, - obsolete => { type => 'boolean', default => 'false' }, - payment_id => { type => 'integer' }, - phone => { type => 'text' }, - salesman_id => { type => 'integer' }, - street => { type => 'varchar', length => 75 }, - taxincluded => { type => 'boolean' }, - taxnumber => { type => 'text' }, - taxzone_id => { type => 'integer', default => '0', not_null => 1 }, - terms => { type => 'integer', default => '0' }, - user_password => { type => 'varchar', length => 12 }, - username => { type => 'varchar', length => 50 }, - ustid => { type => 'varchar', length => 14 }, - v_customer_id => { type => 'text' }, - vendornumber => { type => 'text' }, - zipcode => { type => 'varchar', length => 10 }, + account_number => { type => 'varchar', length => 15 }, + bank => { type => 'text' }, + bank_code => { type => 'varchar', length => 10 }, + bcc => { type => 'text' }, + bic => { type => 'varchar', length => 100 }, + business_id => { type => 'integer' }, + cc => { type => 'text' }, + city => { type => 'varchar', length => 75 }, + contact => { type => 'varchar', length => 75 }, + country => { type => 'varchar', length => 75 }, + creditlimit => { type => 'numeric', precision => 5, scale => 15 }, + currency_id => { type => 'integer', not_null => 1 }, + delivery_term_id => { type => 'integer' }, + department_1 => { type => 'varchar', length => 75 }, + department_2 => { type => 'varchar', length => 75 }, + direct_debit => { type => 'boolean', default => 'false' }, + discount => { type => 'float', precision => 4 }, + email => { type => 'text' }, + fax => { type => 'varchar', length => 30 }, + greeting => { type => 'text' }, + homepage => { type => 'text' }, + iban => { type => 'varchar', length => 100 }, + id => { type => 'integer', not_null => 1, sequence => 'id' }, + itime => { type => 'timestamp', default => 'now()' }, + language => { type => 'varchar', length => 5 }, + language_id => { type => 'integer' }, + mtime => { type => 'timestamp' }, + name => { type => 'varchar', length => 75, not_null => 1 }, + notes => { type => 'text' }, + obsolete => { type => 'boolean', default => 'false' }, + payment_id => { type => 'integer' }, + phone => { type => 'text' }, + salesman_id => { type => 'integer' }, + street => { type => 'varchar', length => 75 }, + taxincluded => { type => 'boolean' }, + taxnumber => { type => 'text' }, + taxzone_id => { type => 'integer', default => '0', not_null => 1 }, + terms => { type => 'integer', default => '0' }, + user_password => { type => 'varchar', length => 12 }, + username => { type => 'varchar', length => 50 }, + ustid => { type => 'varchar', length => 14 }, + v_customer_id => { type => 'text' }, + vendornumber => { type => 'text' }, + zipcode => { type => 'varchar', length => 10 }, ); __PACKAGE__->meta->primary_key_columns([ 'id' ]); @@ -69,6 +70,11 @@ __PACKAGE__->meta->foreign_keys( key_columns => { currency_id => 'id' }, }, + delivery_term => { + class => 'SL::DB::DeliveryTerm', + key_columns => { delivery_term_id => 'id' }, + }, + language_obj => { class => 'SL::DB::Language', key_columns => { language_id => 'id' }, diff --git a/SL/DO.pm b/SL/DO.pm index 21f93d813..cec2e9b5d 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -367,7 +367,8 @@ sub save { shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, closed = ?, delivered = ?, department_id = ?, language_id = ?, shipto_id = ?, globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, - is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, currency_id = (SELECT id FROM currencies WHERE name = ?) + is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, currency_id = (SELECT id FROM currencies WHERE name = ?), + delivery_term_id = ? WHERE id = ?|; @values = ($form->{donumber}, $form->{ordnumber}, @@ -382,6 +383,7 @@ sub save { $form->{transaction_description}, $form->{type} =~ /^sales/ ? 't' : 'f', conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), $form->{currency}, + conv_i($form->{delivery_term_id}), conv_i($form->{id})); do_query($form, $dbh, $query, @values); @@ -592,7 +594,8 @@ sub retrieve { d.description AS department, dord.language_id, dord.shipto_id, dord.globalproject_id, dord.delivered, dord.transaction_description, - dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) AS currency + dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) AS currency, + dord.delivery_term_id FROM delivery_orders dord JOIN ${vc} cv ON (dord.${vc}_id = cv.id) LEFT JOIN employee e ON (dord.employee_id = e.id) @@ -891,6 +894,8 @@ sub order_details { $h_pg->finish(); $h_bin_wh->finish(); + $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); + $form->{username} = $myconfig->{name}; $main::lxdebug->leave_sub(); diff --git a/SL/IR.pm b/SL/IR.pm index 36f105ebd..84ce10a17 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -686,7 +686,7 @@ sub post_invoice { netamount = ?, paid = ?, duedate = ?, invoice = ?, taxzone_id = ?, notes = ?, taxincluded = ?, intnotes = ?, storno_id = ?, storno = ?, - cp_id = ?, employee_id = ?, department_id = ?, + cp_id = ?, employee_id = ?, department_id = ?, delivery_term_id = ?, globalproject_id = ?, direct_debit = ? WHERE id = ?|; @values = ( @@ -695,7 +695,7 @@ sub post_invoice { $netamount, $form->{paid}, conv_date($form->{duedate}), '1', $taxzone_id, $form->{notes}, $form->{taxincluded} ? 't' : 'f', $form->{intnotes}, conv_i($form->{storno_id}), $form->{storno} ? 't' : 'f', - conv_i($form->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}), + conv_i($form->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}), conv_i($form->{delivery_term_id}), conv_i($form->{globalproject_id}), $form->{direct_debit} ? 't' : 'f', conv_i($form->{id}) @@ -941,7 +941,8 @@ sub retrieve_invoice { $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate, orddate, quodate, globalproject_id, ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate, - intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit + intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit, + delivery_term_id FROM ap WHERE id = ?|; $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id})); @@ -1087,7 +1088,7 @@ sub get_vendor { qq|SELECT v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount, v.creditlimit, v.terms, v.notes AS intnotes, - v.email, v.cc, v.bcc, v.language_id, v.payment_id, + v.email, v.cc, v.bcc, v.language_id, v.payment_id, v.delivery_term_id, v.street, v.zipcode, v.city, v.country, v.taxzone_id, cu.name AS curr, v.direct_debit, $duedate + COALESCE(pt.terms_netto, 0) AS duedate, b.description AS business diff --git a/SL/IS.pm b/SL/IS.pm index cfaf730e8..b9c3e0aeb 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -429,6 +429,8 @@ sub invoice_details { $form->set_payment_options($myconfig, $form->{invdate}); + $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); + $form->{username} = $myconfig->{name}; $main::lxdebug->leave_sub(); @@ -1104,7 +1106,8 @@ sub post_invoice { cp_id = ?, marge_total = ?, marge_percent = ?, globalproject_id = ?, delivery_customer_id = ?, transaction_description = ?, delivery_vendor_id = ?, - donumber = ?, invnumber_for_credit_note = ?, direct_debit = ? + donumber = ?, invnumber_for_credit_note = ?, direct_debit = ?, + delivery_term_id = ? WHERE id = ?|; @values = ( $form->{"invnumber"}, $form->{"ordnumber"}, $form->{"quonumber"}, $form->{"cusordnumber"}, conv_date($form->{"invdate"}), conv_date($form->{"orddate"}), conv_date($form->{"quodate"}), conv_i($form->{"customer_id"}), @@ -1118,6 +1121,7 @@ sub post_invoice { conv_i($form->{"globalproject_id"}), conv_i($form->{"delivery_customer_id"}), $form->{transaction_description}, conv_i($form->{"delivery_vendor_id"}), $form->{"donumber"}, $form->{"invnumber_for_credit_note"}, $form->{direct_debit} ? 't' : 'f', + conv_i($form->{delivery_term_id}), conv_i($form->{"id"})); do_query($form, $dbh, $query, @values); @@ -1593,7 +1597,7 @@ sub retrieve_invoice { a.employee_id, a.salesman_id, a.payment_id, a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type, a.transaction_description, a.donumber, a.invnumber_for_credit_note, - a.marge_total, a.marge_percent, a.direct_debit, + a.marge_total, a.marge_percent, a.direct_debit, a.delivery_term_id, e.name AS employee FROM ar a LEFT JOIN employee e ON (e.id = a.employee_id) @@ -1763,7 +1767,7 @@ sub get_customer { $query = qq|SELECT c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, c.terms, - c.email, c.cc, c.bcc, c.language_id, c.payment_id, + c.email, c.cc, c.bcc, c.language_id, c.payment_id, c.delivery_term_id, c.street, c.zipcode, c.city, c.country, c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, cu.name AS curr, c.taxincluded_checked, c.direct_debit, diff --git a/SL/OE.pm b/SL/OE.pm index aaf0faece..2d124723c 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -518,7 +518,7 @@ sub save { customer_id = ?, amount = ?, netamount = ?, reqdate = ?, taxincluded = ?, shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, currency_id = (SELECT id FROM currencies WHERE name=?), closed = ?, delivered = ?, proforma = ?, quotation = ?, department_id = ?, language_id = ?, - taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?, + taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?,delivery_term_id = ?, globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ? WHERE id = ?|; @@ -535,6 +535,7 @@ sub save { conv_i($form->{shipto_id}), conv_i($form->{payment_id}), conv_i($form->{delivery_vendor_id}), conv_i($form->{delivery_customer_id}), + conv_i($form->{delivery_term_id}), conv_i($form->{globalproject_id}), conv_i($form->{employee_id}), conv_i($form->{salesman_id}), conv_i($form->{cp_id}), $form->{transaction_description}, @@ -768,7 +769,7 @@ sub retrieve { o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber, d.description AS department, o.payment_id, o.language_id, o.taxzone_id, o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id, - o.globalproject_id, o.delivered, o.transaction_description + o.globalproject_id, o.delivered, o.transaction_description, o.delivery_term_id FROM oe o JOIN ${vc} cv ON (o.${vc}_id = cv.id) LEFT JOIN employee e ON (o.employee_id = e.id) @@ -1334,6 +1335,8 @@ sub order_details { $dbh->disconnect; + $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); + $main::lxdebug->leave_sub(); } diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index f3a90ae3d..15d922dde 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -52,6 +52,7 @@ use SL::CVar; use SL::Request qw(flatten); use SL::DB::Business; use SL::DB::Default; +use SL::DB::DeliveryTerm; use SL::Helper::Flash; use SL::ReportGenerator; use SL::MoreCommon qw(uri_encode); @@ -466,6 +467,8 @@ sub form_header { $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_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted(); + $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $form->{is_customer} = $form->{db} eq 'customer'; $form->{shipto_label} = \&_shipto_label; diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index 06b4c4ef1..3e54c1ed8 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -172,7 +172,7 @@ sub order_links { DO->retrieve('vc' => $form->{vc}, 'ids' => $form->{id}); - $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes currency)); + $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes delivery_term_id currency)); $form->{shipto} = 1 if $form->{id} || $form->{convert_from_oe_ids}; # get customer / vendor @@ -184,7 +184,7 @@ sub order_links { $form->{discount} = $form->{customer_discount}; } - $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id)); + $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id delivery_term_id)); $form->restore_vars(qw(currency)) if ($form->{id} || $form->{convert_from_oe_ids}); $form->restore_vars(qw(taxincluded)) if $form->{id}; $form->restore_vars(qw(salesman_id)) if $editing; @@ -335,6 +335,7 @@ sub form_footer { my $form = $main::form; $form->{PRINT_OPTIONS} = print_options('inline' => 1); + $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted(); print $form->parse_html_template('do/form_footer', {transfer_default => ($::instance_conf->get_transfer_default)}); diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 075644801..c1bc77032 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1365,6 +1365,7 @@ sub print_form { my $language_saved = $form->{language_id}; my $payment_id_saved = $form->{payment_id}; + my $delivery_term_id_saved = $form->{delivery_term_id}; my $salesman_id_saved = $form->{salesman_id}; my $cp_id_saved = $form->{cp_id}; my $taxzone_id_saved = $form->{taxzone_id}; @@ -1374,6 +1375,7 @@ sub print_form { $form->{language_id} = $language_saved; $form->{payment_id} = $payment_id_saved; + $form->{delivery_term_id} = $delivery_term_id_saved; $form->{taxzone_id} = $taxzone_id_saved; $form->{currency} = $currency_saved; diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 3653891f9..30124cf64 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -116,7 +116,7 @@ sub invoice_links { } } - my ($payment_id, $language_id, $taxzone_id, $currency); + my ($payment_id, $language_id, $taxzone_id, $currency, $delivery_term_id); if ($form->{payment_id}) { $payment_id = $form->{payment_id}; } @@ -129,6 +129,9 @@ sub invoice_links { if ($form->{currency}) { $currency = $form->{currency}; } + if ($form->{delivery_term_id}) { + $delivery_term_id = $form->{delivery_term_id}; + } my $cp_id = $form->{cp_id}; IR->get_vendor(\%myconfig, \%$form); @@ -147,6 +150,9 @@ sub invoice_links { if ($currency) { $form->{currency} = $currency; } + if ($delivery_term_id) { + $form->{delivery_term_id} = $delivery_term_id; + } my @curr = $form->get_all_currencies(); map { $form->{selectcurrency} .= "