From 4493d1eb7845b7eba868f0a16ec2e623dcf1d591 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 5 Apr 2016 16:22:01 +0200 Subject: [PATCH] =?utf8?q?CVars:=20Lieferadressen-CVars=20bei=20Ein-/Verka?= =?utf8?q?ufsbelegen=20benutzen=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Common.pm | 7 + SL/DO.pm | 14 ++ SL/Form.pm | 126 +++++++++++------- SL/IS.pm | 20 +++ SL/OE.pm | 14 ++ bin/mozilla/do.pl | 5 + bin/mozilla/io.pl | 6 +- bin/mozilla/is.pl | 2 + bin/mozilla/oe.pl | 9 +- templates/webpages/do/form_header.html | 3 + templates/webpages/io/ship_to.html | 13 ++ .../oe/check_for_direct_delivery.html | 7 + 12 files changed, 174 insertions(+), 52 deletions(-) diff --git a/SL/Common.pm b/SL/Common.pm index bcaeb62c1..dfdf3c5d4 100644 --- a/SL/Common.pm +++ b/SL/Common.pm @@ -447,6 +447,13 @@ sub get_shipto_by_id { map { $form->{"${prefix}${_}"} = $ref->{$_} } keys %{ $ref } if $ref; + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $shipto_id, + ); + $form->{"${prefix}shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; + $dbh->disconnect(); $main::lxdebug->leave_sub(); diff --git a/SL/DO.pm b/SL/DO.pm index b098f71e0..e3ffc2f31 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -263,6 +263,11 @@ sub save { if ($form->{id}) { # only delete shipto complete + $query = qq|DELETE FROM custom_variables + WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE (module = 'ShipTo'))) + AND (trans_id IN (SELECT shipto_id FROM shipto WHERE (module = 'DO') AND (trans_id = ?)))|; + do_query($form, $dbh, $query, $form->{id}); + $query = qq|DELETE FROM shipto WHERE trans_id = ? AND module = 'DO'|; do_query($form, $dbh, $query, conv_i($form->{id})); @@ -748,6 +753,15 @@ sub retrieve { map { $form->{$_} = $ref->{$_} } keys %$ref; $sth->finish(); + if ($form->{shipto_id}) { + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $form->{shipto_id}, + ); + $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; + } + # get printed, emailed and queued $query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname FROM status s WHERE s.trans_id = ?|; $sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); diff --git a/SL/Form.pm b/SL/Form.pm index 98bb4dbe2..266d3e5ea 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1848,14 +1848,19 @@ sub get_shipto { my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|; my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id}); map({ $self->{$_} = $ref->{$_} } keys(%$ref)); + + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $self->{shipto_id}, + ); + $self->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; } $main::lxdebug->leave_sub(); } sub add_shipto { - $main::lxdebug->enter_sub(); - my ($self, $dbh, $id, $module) = @_; my $shipto; @@ -1869,54 +1874,68 @@ sub add_shipto { push(@values, $self->{"shipto${item}"}); } - if ($shipto) { - if ($self->{shipto_id}) { - my $query = qq|UPDATE shipto set - shiptoname = ?, - shiptodepartment_1 = ?, - shiptodepartment_2 = ?, - shiptostreet = ?, - shiptozipcode = ?, - shiptocity = ?, - shiptocountry = ?, - shiptogln = ?, - shiptocontact = ?, - shiptocp_gender = ?, - shiptophone = ?, - shiptofax = ?, - shiptoemail = ? - WHERE shipto_id = ?|; - do_query($self, $dbh, $query, @values, $self->{shipto_id}); - } else { - my $query = qq|SELECT * FROM shipto - WHERE shiptoname = ? AND - shiptodepartment_1 = ? AND - shiptodepartment_2 = ? AND - shiptostreet = ? AND - shiptozipcode = ? AND - shiptocity = ? AND - shiptocountry = ? AND - shiptogln = ? AND - shiptocontact = ? AND - shiptocp_gender = ? AND - shiptophone = ? AND - shiptofax = ? AND - shiptoemail = ? AND - module = ? AND - trans_id = ?|; - my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id); - if(!$insert_check){ - $query = - qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, - shiptostreet, shiptozipcode, shiptocity, shiptocountry, shiptogln, - shiptocontact, shiptocp_gender, shiptophone, shiptofax, shiptoemail, module) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; - do_query($self, $dbh, $query, $id, @values, $module); - } + return if !$shipto; + + my $shipto_id = $self->{shipto_id}; + + if ($self->{shipto_id}) { + my $query = qq|UPDATE shipto set + shiptoname = ?, + shiptodepartment_1 = ?, + shiptodepartment_2 = ?, + shiptostreet = ?, + shiptozipcode = ?, + shiptocity = ?, + shiptocountry = ?, + shiptogln = ?, + shiptocontact = ?, + shiptocp_gender = ?, + shiptophone = ?, + shiptofax = ?, + shiptoemail = ? + WHERE shipto_id = ?|; + do_query($self, $dbh, $query, @values, $self->{shipto_id}); + } else { + my $query = qq|SELECT * FROM shipto + WHERE shiptoname = ? AND + shiptodepartment_1 = ? AND + shiptodepartment_2 = ? AND + shiptostreet = ? AND + shiptozipcode = ? AND + shiptocity = ? AND + shiptocountry = ? AND + shiptogln = ? AND + shiptocontact = ? AND + shiptocp_gender = ? AND + shiptophone = ? AND + shiptofax = ? AND + shiptoemail = ? AND + module = ? AND + trans_id = ?|; + my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id); + if(!$insert_check){ + my $insert_query = + qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, + shiptostreet, shiptozipcode, shiptocity, shiptocountry, shiptogln, + shiptocontact, shiptocp_gender, shiptophone, shiptofax, shiptoemail, module) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|; + do_query($self, $dbh, $insert_query, $id, @values, $module); + + $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id); } + + $shipto_id = $insert_check->{shipto_id}; } - $main::lxdebug->leave_sub(); + return unless $shipto_id; + + CVar->save_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $shipto_id, + variables => $self, + name_prefix => 'shipto', + ); } sub get_employee { @@ -3375,10 +3394,17 @@ sub prepare_for_printing { $self->{"employee_${_}"} = $defaults->$_ for qw(address businessnumber co_ustid company duns sepa_creditor_id taxnumber); } - # Load shipping address from database if shipto_id is set. - if ($self->{shipto_id}) { - my $shipto = SL::DB::Shipto->new(shipto_id => $self->{shipto_id})->load; + # Load shipping address from database. If shipto_id is set then it's + # one from the customer's/vendor's master data. Otherwise look an a + # customized address linking back to the current record. + my $shipto_module = $self->{type} =~ /_delivery_order$/ ? 'DO' + : $self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order/ ? 'OE' + : 'AR'; + my $shipto = $self->{shipto_id} ? SL::DB::Shipto->new(shipto_id => $self->{shipto_id})->load + : SL::DB::Manager::Shipto->get_first(where => [ module => $shipto_module, trans_id => $self->{id} ]); + if ($shipto) { $self->{$_} = $shipto->$_ for grep { m{^shipto} } map { $_->name } @{ $shipto->meta->columns }; + $self->{"shiptocvar_" . $_->config->name} = $_->value_as_text for @{ $shipto->cvars_by_config }; } my $language = $self->{language} ? '_' . $self->{language} : ''; diff --git a/SL/IS.pm b/SL/IS.pm index 7d6413094..566d1546b 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1818,6 +1818,11 @@ sub reverse_invoice { # delete acc_trans my @values = (conv_i($form->{id})); do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values); + + $query = qq|DELETE FROM custom_variables + WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE (module = 'ShipTo'))) + AND (trans_id IN (SELECT shipto_id FROM shipto WHERE (module = 'AR') AND (trans_id = ?)))|; + do_query($form, $dbh, $query, @values); do_query($form, $dbh, qq|DELETE FROM shipto WHERE (trans_id = ?) AND (module = 'AR')|, @values); $main::lxdebug->leave_sub(); @@ -2049,6 +2054,21 @@ sub retrieve_invoice { } $sth->finish; + # Fetch shipping address. + $query = qq|SELECT s.* FROM shipto s WHERE s.trans_id = ? AND s.module = 'AR'|; + $ref = selectfirst_hashref_query($form, $dbh, $query, $form->{id}); + + $form->{$_} = $ref->{$_} for grep { $_ ne 'id' } keys %$ref; + + if ($form->{shipto_id}) { + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $form->{shipto_id}, + ); + $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; + } + Common::webdav_folder($form); } diff --git a/SL/OE.pm b/SL/OE.pm index 079b14b13..149a6cf1a 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -421,6 +421,11 @@ sub save { $form->{$number_field} ||= $trans_number->create_unique; # set $form->{ordnumber} or $form->{quonumber} if ($form->{id}) { + $query = qq|DELETE FROM custom_variables + WHERE (config_id IN (SELECT id FROM custom_variable_configs WHERE (module = 'ShipTo'))) + AND (trans_id IN (SELECT shipto_id FROM shipto WHERE (module = 'OE') AND (trans_id = ?)))|; + do_query($form, $dbh, $query, $form->{id}); + $query = qq|DELETE FROM shipto | . qq|WHERE trans_id = ? AND module = 'OE'|; do_query($form, $dbh, $query, $form->{id}); @@ -1011,6 +1016,15 @@ sub retrieve { map { $form->{$_} = $ref->{$_} } keys %$ref; $sth->finish; + if ($form->{shipto_id}) { + my $cvars = CVar->get_custom_variables( + dbh => $dbh, + module => 'ShipTo', + trans_id => $form->{shipto_id}, + ); + $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars }; + } + # get printed, emailed and queued $query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname FROM status s WHERE s.trans_id = ?|; $sth = prepare_execute_query($form, $dbh, $query, $form->{id}); diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index ea96bcae9..51986b0b7 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -327,6 +327,11 @@ sub form_header { $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part)); + my @custom_hidden; + push @custom_hidden, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) }; + + $::form->{HIDDENS} = [ map { +{ name => $_, value => $::form->{$_} } } (@custom_hidden) ]; + $form->header(); # Fix für Bug 1082 Erwartet wird: 'abteilungsNAME--abteilungsID' # und Erweiterung für Bug 1760: diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index c3ab47e28..1dc7a64d1 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1648,18 +1648,22 @@ sub ship_to { call_sub($::form->{vc} . "_details", qw(name department_1 department_2 street zipcode city country gln contact email phone fax), $::form->{vc} . "number"); $::form->{rowcount}--; + my $cvars = SL::DB::Shipto->new->cvars_by_config; my @shipto_vars = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptocp_gender shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2); - my $previous_form = $::auth->save_form_in_session(skip_keys => [ @shipto_vars, qw(header shipto_id) ]); + my $previous_form = $::auth->save_form_in_session(skip_keys => [ @shipto_vars, qw(header shipto_id), map { "shiptocvar_" . $_->config->name } @{ $cvars } ]); $::form->{title} = $::locale->text('Ship to'); $::form->header; my $vc_obj = ($::form->{vc} eq 'customer' ? "SL::DB::Customer" : "SL::DB::Vendor")->new(id => $::form->{$::form->{vc} . "_id"})->load; + $_->value($::form->{"shiptocvar_" . $_->config->name}) for @{ $cvars }; + print $::form->parse_html_template('io/ship_to', { previousform => $previous_form, nextsub => $::form->{display_form} || 'display_form', vc_obj => $vc_obj, + cvars => $cvars, }); $main::lxdebug->leave_sub(); diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 9af6b210f..aa9a9a861 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -380,6 +380,8 @@ sub form_header { $TMPL_VAR{dateformat} = $myconfig{dateformat}; $TMPL_VAR{numberformat} = $myconfig{numberformat}; + push @custom_hiddens, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) }; + # hiddens $TMPL_VAR{HIDDENS} = [qw( id action type media format queued printed emailed title vc discount diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index ed13848c2..8f68f4d38 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -473,6 +473,9 @@ sub form_header { if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) { $form->{shipto_id} = $form->{CFDD_shipto_id}; } + + push @custom_hiddens, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) }; + $TMPL_VAR{HIDDENS} = [ map { name => $_, value => $form->{$_} }, qw(id action type vc formname media format proforma queued printed emailed title creditlimit creditremaining tradediscount business @@ -1731,6 +1734,8 @@ sub check_for_direct_delivery { return; } + my $cvars = SL::DB::Shipto->new->cvars_by_config; + if ($form->{shipto_id}) { Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_"); @@ -1738,11 +1743,13 @@ sub check_for_direct_delivery { map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form }; } + $_->value($::form->{"CFDD_shiptocvar_" . $_->config->name}) for @{ $cvars }; + delete $form->{action}; $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ($_ ne 'login') && ($_ ne 'password') && (ref $_ eq "") } keys %{ $form } ]; $form->header(); - print $form->parse_html_template("oe/check_for_direct_delivery"); + print $form->parse_html_template("oe/check_for_direct_delivery", { cvars => $cvars }); $main::lxdebug->leave_sub(); diff --git a/templates/webpages/do/form_header.html b/templates/webpages/do/form_header.html index 012c3d30c..334c94b95 100644 --- a/templates/webpages/do/form_header.html +++ b/templates/webpages/do/form_header.html @@ -110,6 +110,9 @@ +[%- FOREACH row = HIDDENS %] + [% L.hidden_tag(row.name, row.value) %] +[%- END %]

diff --git a/templates/webpages/io/ship_to.html b/templates/webpages/io/ship_to.html index 2ffed371f..e3e6500ba 100644 --- a/templates/webpages/io/ship_to.html +++ b/templates/webpages/io/ship_to.html @@ -15,6 +15,9 @@ shiptophone: "[% JavaScript.escape(vc_obj.phone) %]", shiptofax: "[% JavaScript.escape(vc_obj.fax) %]", shiptoemail: "[% JavaScript.escape(vc_obj.email) %]" +[% FOREACH var = cvars %] + , "shiptocvar_[% JavaScript.escape(var.config.name) %]": "" +[% END %] } [% FOREACH shipto = vc_obj.shipto %] @@ -32,6 +35,9 @@ shiptophone: "[% JavaScript.escape(shipto.shiptophone) %]", shiptofax: "[% JavaScript.escape(shipto.shiptofax) %]", shiptoemail: "[% JavaScript.escape(shipto.shiptoemail) %]" + [% FOREACH var = shipto.cvars_by_config %] + , "shiptocvar_[% JavaScript.escape(var.config.name) %]": "[% JavaScript.escape(var.value_as_text) %]" + [% END %] } [% END %] ]; @@ -156,6 +162,13 @@ +[% FOREACH var = cvars %] + + + + + +[% END %]
[% HTML.escape(email) %] [% L.input_tag("shiptoemail", shiptoemail, "size", "35") %]
[% HTML.escape(var.config.description) %][% INCLUDE 'common/render_cvar_input.html' cvar_name_prefix='shiptocvar_' %]


diff --git a/templates/webpages/oe/check_for_direct_delivery.html b/templates/webpages/oe/check_for_direct_delivery.html index 9070cab42..8160188c5 100644 --- a/templates/webpages/oe/check_for_direct_delivery.html +++ b/templates/webpages/oe/check_for_direct_delivery.html @@ -65,6 +65,13 @@ [% 'E-mail' | $T8 %]: [% HTML.escape(CFDD_shiptoemail) %] + +[% FOREACH var = cvars %] + + [% HTML.escape(var.config.description) %] + [% HTML.escape(var.value_as_text) %] + +[% END %]

-- 2.20.1