use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(rows) ],
- 'scalar --get_set_init' => [ qw(query queries parameters today) ],
+ 'scalar --get_set_init' => [ qw(query queries parameters) ],
);
__PACKAGE__->run_before('check_auth');
sub init_query { $::form->{id} ? SL::DB::CustomDataExportQuery->new(id => $::form->{id})->load : SL::DB::CustomDataExportQuery->new }
sub init_parameters { [ sort_by { lc $_->name } @{ $_[0]->query->parameters // [] } ] }
-sub init_today { DateTime->today_local }
sub init_queries {
my %rights_map = %{ $::auth->load_rights_for_user($::form->{login}) };
}
sub setup_javascripts {
- $::request->layout->add_javascripts('kivi.Validator.js');
+ $::request->layout->add_javascripts('kivi.Validator.js', 'kivi.CustomDataExportDesigner.js');
}
#
my %used_parameter_names = map { ($_ => 1) } $self->query->used_parameter_names;
my @existing_parameters = grep { $used_parameter_names{$_->name} } @{ $self->query->parameters // [] };
my %parameters_by_name = map { ($_->name => $_) } @existing_parameters;
- $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text') for keys %used_parameter_names;
+ $parameters_by_name{$_} //= SL::DB::CustomDataExportQueryParameter->new(name => $_, parameter_type => 'text', default_value_type => 'none') for keys %used_parameter_names;
foreach my $parameter_data (@{ $::form->{parameters} // [] }) {
my $parameter_obj = $parameters_by_name{ $parameter_data->{name} };
next unless $parameter_obj;
- $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description);
+ $parameter_obj->$_($parameter_data->{$_}) for qw(parameter_type description default_value_type default_value);
}
return sort_by { lc $_->name } values %parameters_by_name;
-# 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::CustomDataExportQueryParameter;
use strict;
__PACKAGE__->meta->initialize;
+sub _default_value_type_fixed_value { $_[0]->default_value }
+sub _default_value_type_current_user_login { $::myconfig{login} }
+
+sub _default_value_type_sql_query {
+ my ($self) = @_;
+
+ return '' if !$self->default_value;
+
+ my @result = $self->db->dbh->selectrow_array($self->default_value);
+ $::form->dberror if !@result;
+
+ return $result[0];
+}
+
+sub calculate_default_value {
+ my ($self) = @_;
+
+ my $method = "_default_value_type_" . ($self->default_value_type // '');
+ return $self->can($method) ? $self->$method : '';
+}
+
1;
__PACKAGE__->meta->table('custom_data_export_query_parameters');
__PACKAGE__->meta->columns(
- description => { type => 'text' },
- id => { type => 'serial', not_null => 1 },
- itime => { type => 'timestamp', default => 'now()', not_null => 1 },
- mtime => { type => 'timestamp', default => 'now()', not_null => 1 },
- name => { type => 'text', not_null => 1 },
- parameter_type => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 },
- query_id => { type => 'integer', not_null => 1 },
+ default_value => { type => 'text' },
+ default_value_type => { type => 'enum', check_in => [ 'none', 'current_user_login', 'sql_query', 'fixed_value' ], db_type => 'custom_data_export_query_parameter_default_value_type_enum', not_null => 1 },
+ description => { type => 'text' },
+ id => { type => 'serial', not_null => 1 },
+ itime => { type => 'timestamp', default => 'now()', not_null => 1 },
+ mtime => { type => 'timestamp', default => 'now()', not_null => 1 },
+ name => { type => 'text', not_null => 1 },
+ parameter_type => { type => 'enum', check_in => [ 'text', 'number', 'date', 'timestamp' ], db_type => 'custom_data_export_query_parameter_type_enum', not_null => 1 },
+ query_id => { type => 'integer', not_null => 1 },
);
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
--- /dev/null
+namespace('kivi.CustomDataExportDesigner', function(ns){
+ 'use strict';
+
+ ns.enable_default_value = function() {
+ var count = $(this).prop('id').replace("default_value_type_", "");
+ var type = $(this).val();
+ $('#default_value_' + count).prop('disabled', (type === 'none') || (type === 'current_user_login'));
+ };
+});
+
+$(function() {
+ $('[id^="default_value_type_"]').change(kivi.CustomDataExportDesigner.enable_default_value);
+});
'Current profile' => 'Aktuelles Profil',
'Current status' => 'Aktueller Status',
'Current status:' => 'Aktueller Status:',
+ 'Current user\'s login' => 'Login der aktuellen BenutzerIn',
'Current value:' => 'Aktueller Wert:',
'Current version' => 'Aktuelle Version',
'Current year' => 'Aktuelles Jahr',
'Firstname' => 'Vorname',
'Fix transaction' => 'Buchung korrigieren',
'Fix transactions' => 'Buchungen korrigieren',
+ 'Fixed value' => 'Fester Wert',
'Focus position after update' => 'Eingabe-Fokus-Position nach Erneuern',
'Folgekonto' => 'Folgekonto',
'Follow-Up' => 'Wiedervorlage',
'No customer has been selected yet.' => 'Es wurde noch kein Kunde ausgewählt.',
'No data was found.' => 'Es wurden keine Daten gefunden.',
'No default currency' => 'Keine Standardwährung',
+ 'No default value' => 'Kein Standardwert',
'No delivery orders have been selected.' => 'Es wurden keine Lieferscheine ausgewählt.',
'No delivery term has been created yet.' => 'Es wurden noch keine Lieferbedingungen angelegt',
'No dunnings have been selected for printing.' => 'Es wurden keine Mahnungen zum Drucken ausgewählt.',
'Requirement specs' => 'Pflichtenhefte',
'Reset' => 'Zurücksetzen',
'Result' => 'Ergebnis',
+ 'Result of SQL query' => 'Ergebnis einer SQL-Abfrage',
'Revenue' => 'Erlöskonto',
'Revenue Account' => 'Erlöskonto',
'Reversal invoices cannot be canceled.' => 'Stornorechnungen können nicht storniert werden.',
--- /dev/null
+-- @tag: custom_data_export_default_values_for_parameters
+-- @description: Bentuzerdefinierter Datenexport: Vorgabewerte für Parameter
+-- @depends: custom_data_export
+CREATE TYPE custom_data_export_query_parameter_default_value_type_enum AS ENUM ('none', 'current_user_login', 'sql_query', 'fixed_value');
+
+ALTER TABLE custom_data_export_query_parameters
+ADD COLUMN default_value_type custom_data_export_query_parameter_default_value_type_enum,
+ADD COLUMN default_value TEXT;
+
+UPDATE custom_data_export_query_parameters
+SET default_value_type = 'none';
+
+ALTER TABLE custom_data_export_query_parameters
+ALTER COLUMN default_value_type
+SET NOT NULL;
[% HTML.escape(parameter.name) %]
</td>
+ [% SET value = parameter.calculate_default_value %]
+
[% IF parameter.parameter_type == "number" %]
<td>[% LxERP.t8("Number") %]</td>
- <td>[% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %]</td>
+ <td>[% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
[% ELSIF parameter.parameter_type == "date" %]
<td>[% LxERP.t8("Date") %]</td>
- <td>[% L.date_tag("parameters." _ parameter.name, SELF.today.to_kivitendo, style="width: 300px", "data-validate"="required") %]</td>
+ <td>[% L.date_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
[% ELSE %]
<td>[% LxERP.t8("Text") %]</td>
- <td>[% L.input_tag("parameters." _ parameter.name, "", style="width: 300px", "data-validate"="required") %]</td>
+ <td>[% L.input_tag("parameters." _ parameter.name, value, style="width: 300px", "data-validate"="required") %]</td>
[% END %]
<td>[% HTML.escape(parameter.description) %]</td>
<th>[% LxERP.t8("Variable Name") %]</th>
<th>[% LxERP.t8("Type") %]</th>
<th>[% LxERP.t8("Description") %]</th>
+ <th colspan="2">[% LxERP.t8("Default value") %]</th>
</tr>
</thead>
<tbody>
[% FOREACH parameter = PARAMETERS %]
<tr class="listrow">
- <td>
+ <td valign="top">
[% L.hidden_tag("parameters[+].name", parameter.name) %]
[% HTML.escape(parameter.name) %]
</td>
- <td>
+ <td valign="top">
[% L.select_tag("parameters[].parameter_type", [ [ "text", LxERP.t8("Text") ], [ "number", LxERP.t8("Number") ], [ "date", LxERP.t8("Date") ] ], default=parameter.parameter_type) %]
</td>
- <td>[% L.input_tag("parameters[].description", parameter.description, size=100) %]</td>
+ <td valign="top">[% L.input_tag("parameters[].description", parameter.description, size=100) %]</td>
+ <td valign="top">
+ [% L.select_tag("parameters[].default_value_type",
+ [ [ "none", LxERP.t8("No default value") ], [ "current_user_login", LxERP.t8("Current user's login") ], [ "sql_query", LxERP.t8("Result of SQL query") ],
+ [ "fixed_value", LxERP.t8("Fixed value") ] ],
+ default=parameter.default_value_type,
+ id="default_value_type_" _ loop.count) %]
+ </td>
+ <td valign="top">
+ [% SET disabled = (parameter.default_value_type == "none") || (parameter.default_value_type == "current_user_login") ? "disabled" : "" %]
+ [% L.textarea_tag("parameters[].default_value", parameter.default_value, id="default_value_" _ loop.count, cols=80, rows=3, disabled=disabled) %]
+ </td>
</tr>
[% END %]
</tbody>