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();
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}));
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}));
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;
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 {
$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} : '';
# 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();
}
$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);
}
$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});
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});
$::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:
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();
$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
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
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_");
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();
<input type="hidden" name="type" value="[% HTML.escape(type) %]">
<input type="hidden" name="vc" value="[% HTML.escape(vc) %]">
<input type="hidden" name="lastmtime" value="[% HTML.escape(lastmtime) %]">
+[%- FOREACH row = HIDDENS %]
+ [% L.hidden_tag(row.name, row.value) %]
+[%- END %]
<p>
<table width="100%">
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 %]
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 %]
];
<td>[% HTML.escape(email) %]</td>
<td>[% L.input_tag("shiptoemail", shiptoemail, "size", "35") %]</td>
</tr>
+[% FOREACH var = cvars %]
+ <tr valign="top">
+ <th align="right" nowrap>[% HTML.escape(var.config.description) %]</th>
+ <td></td>
+ <td>[% INCLUDE 'common/render_cvar_input.html' cvar_name_prefix='shiptocvar_' %]</td>
+ </tr>
+[% END %]
</table>
<hr size="3" noshade>
<th align="right" valign="top">[% 'E-mail' | $T8 %]:</th>
<td valign="top">[% HTML.escape(CFDD_shiptoemail) %]</td>
</tr>
+
+[% FOREACH var = cvars %]
+ <tr valign="top">
+ <th align="right" nowrap>[% HTML.escape(var.config.description) %]</th>
+ <td>[% HTML.escape(var.value_as_text) %]</td>
+ </tr>
+[% END %]
</table>
</p>