my %accnos;
map { ($accnos{$_}) = split(m/--/, $form->{$_}) } qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno ar_paid_accno);
- $form->{curr} =~ s/ //g;
- my @currencies = grep { $_ ne '' } split m/:/, $form->{curr};
- my $currency = join ':', @currencies;
-
# these defaults are database wide
my $query =
assemblynumber = ?,
sdonumber = ?,
pdonumber = ?,
- curr = ?,
businessnumber = ?,
weightunit = ?,
language_id = ?|;
$form->{articlenumber}, $form->{servicenumber},
$form->{assemblynumber},
$form->{sdonumber}, $form->{pdonumber},
- $currency,
$form->{businessnumber}, $form->{weightunit},
conv_i($form->{language_id}));
do_query($form, $dbh, $query, @values);
+ $main::lxdebug->message(0, "es gibt rowcount: " . $form->{rowcount});
+
+ for my $i (1..$form->{rowcount}) {
+ if ($form->{"curr_$i"} ne $form->{"old_curr_$i"}) {
+ $query = qq|UPDATE currencies SET name = ? WHERE name = ?|;
+ do_query($form, $dbh, $query, $form->{"curr_$i"}, $form->{"old_curr_$i"});
+ }
+ }
+
+ if (length($form->{new_curr}) > 0) {
+ $query = qq|INSERT INTO currencies (name) VALUES (?)|;
+ do_query($form, $dbh, $query, $form->{new_curr});
+ }
+
$dbh->commit();
$main::lxdebug->leave_sub();
my $dbh = $form->get_standard_dbh($myconfig);
- my ($currency, $businessnumber) = selectrow_query($form, $dbh, qq|SELECT curr, businessnumber FROM defaults|);
+ my ($businessnumber) = selectrow_query($form, $dbh, qq|SELECT businessnumber FROM defaults|);
# update name
my $query = qq|UPDATE employee SET name = ? WHERE login = ?|;
my $rc = $dbh->commit();
- # save first currency in myconfig
- $currency =~ s/:.*//;
- $form->{currency} = $currency;
-
$form->{businessnumber} = $businessnumber;
$myconfig = User->new(login => $form->{login});
}
$sth->finish;
+
+ #Get currencies:
+ $query = qq|SELECT name AS curr FROM currencies ORDER BY id|;
+ $form->{CURRENCIES} = selectall_hashref_query($form, $dbh, $query);
+
+ #Which of them is the default currency?
+ $query = qq|SELECT name AS defaultcurrency FROM currencies WHERE id = (SELECT currency_id FROM defaults LIMIT 1);|;
+ ($form->{defaultcurrency}) = selectrow_query($form, $dbh, $query);
+
$dbh->disconnect;
$main::lxdebug->leave_sub();
my $exchangerate = 0;
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
- delete $form->{currency} unless $form->{defaultcurrency};
($null, $form->{department_id}) = split(/--/, $form->{department});
$query = qq|UPDATE ap SET
invnumber = ?, transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
amount = ?, duedate = ?, paid = ?, netamount = ?,
- curr = ?, notes = ?, department_id = ?, storno = ?, storno_id = ?,
+ currency_id = (SELECT id FROM currencies WHERE name = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
globalproject_id = ?, direct_debit = ?
WHERE id = ?|;
@values = ($form->{invnumber}, conv_date($form->{transdate}),
$form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
- delete $form->{currency} unless $form->{defaultcurrency};
# Get the AP accno.
$query =
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
- delete $form->{currency} unless $form->{defaultcurrency};
# set exchangerate
$form->{exchangerate} = ($form->{currency} eq $form->{defaultcurrency}) ? 1 :
} else {
$query = qq|SELECT nextval('glid')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|;
- do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
+ $query = qq|INSERT INTO ar (id, invnumber, employee_id, currency_id) VALUES (?, 'dummy', ?, (SELECT id FROM currencies WHERE name=?))|;
+ do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}, $form->{currency});
$form->{invnumber} = $form->update_defaults($myconfig, "invnumber", $dbh) unless $form->{invnumber};
}
}
qq|UPDATE ar set
invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?,
taxincluded = ?, amount = ?, duedate = ?, paid = ?,
- netamount = ?, curr = ?, notes = ?, department_id = ?,
+ netamount = ?, notes = ?, department_id = ?,
employee_id = ?, storno = ?, storno_id = ?, globalproject_id = ?,
direct_debit = ?
WHERE id = ?|;
my @values = ($form->{invnumber}, $form->{ordnumber}, conv_date($form->{transdate}), conv_i($form->{customer_id}), $form->{taxincluded} ? 't' : 'f', $form->{amount},
- conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{currency}, $form->{notes}, conv_i($form->{department_id}),
+ conv_date($form->{duedate}), $form->{paid}, $form->{netamount}, $form->{notes}, conv_i($form->{department_id}),
conv_i($form->{employee_id}), $form->{storno} ? 't' : 'f', $form->{storno_id},
conv_i($form->{globalproject_id}), $form->{direct_debit} ? 't' : 'f', conv_i($form->{id}));
do_query($form, $dbh, $query, @values);
$form->{exchangerate} = $form->format_amount($myconfig, $form->{exchangerate});
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
- delete $form->{currency} unless $form->{defaultcurrency};
# Get the AR accno (which is normally done by Form::create_links()).
$query =
}
$sth->finish;
- # get currencies and closedto
- $query = qq|SELECT curr, closedto FROM defaults|;
- ($form->{currencies}, $form->{closedto}) =
- selectrow_query($form, $dbh, $query);
+ # get closedto
+ $query = qq|SELECT closedto FROM defaults|;
+ ($form->{closedto}) = selectrow_query($form, $dbh, $query);
$dbh->disconnect;
my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
my $query =
- qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, a.curr | .
+ qq|SELECT a.id, a.invnumber, a.transdate, a.amount, a.paid, cu.name AS curr | .
qq|FROM $arap a | .
- qq|WHERE (a.${vc}_id = ?) AND (COALESCE(a.curr, '') = ?) AND NOT (a.amount = a.paid)| .
+ qq|LEFT JOIN currencies cu ON (cu.id=a.currency_id)| .
+ qq|WHERE (a.${vc}_id = ?) AND cu.name = ? AND NOT (a.amount = a.paid)| .
qq|ORDER BY a.id|;
my $sth = prepare_execute_query($form, $dbh, $query,
conv_i($form->{"${vc}_id"}),
SELECT COUNT(*)
FROM $arap
WHERE (${vc}_id = ?)
- AND (COALESCE(curr, '') <> ?)
+ AND ((SELECT cu.name FROM currencies cu WHERE cu.id=${arap}.currency_id) <> ?)
AND (amount <> paid)
SQL
($form->{openinvoices_other_currencies}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{"${vc}_id"}), "$form->{currency}");
qq|SELECT $buysell | .
qq|FROM exchangerate e | .
qq|JOIN ${arap} a ON (a.transdate = e.transdate) | .
- qq|WHERE (e.curr = ?) AND (a.id = ?)|;
+ qq|WHERE (e.currency_id = (SELECT id FROM currencies WHERE name = ?)) AND (a.id = ?)|;
my ($exchangerate) =
selectrow_query($form, $dbh, $query,
$form->{currency}, $form->{"id_$i"});
my $ref = $sth->fetchrow_hashref("NAME_lc");
map { $form->{$_} = $ref->{$_} } keys %$ref;
+ $sth->finish;
- # remove any trailing whitespace
- $form->{curr} =~ s/\s*$//;
+ #get name of currency instead of id:
+ $query = qq|SELECT name AS curr FROM currencies WHERE id=?|;
+ ($form->{curr}) = selectrow_query($form, $dbh, $query, conv_i($form->{currency_id}));
- $sth->finish;
if ( $form->{salesman_id} ) {
my $query =
qq|SELECT ct.name AS salesman | .
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO customer (id, name) VALUES (?, '')|;
+ $query = qq|INSERT INTO customer (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
do_query($form, $dbh, $query, $form->{id});
}
qq|user_password = ?, | .
qq|c_vendor_id = ?, | .
qq|klass = ?, | .
- qq|curr = ?, | .
+ qq|currency_id = (SELECT id FROM currencies WHERE name = ?), | .
qq|taxincluded_checked = ? | .
qq|WHERE id = ?|;
my @values = (
$form->{user_password},
$form->{c_vendor_id},
conv_i($form->{klass}),
- substr($form->{currency}, 0, 3),
+ $form->{currency},
$form->{taxincluded_checked} ne '' ? $form->{taxincluded_checked} : undef,
$form->{id}
);
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO vendor (id, name) VALUES (?, '')|;
+ $query = qq|INSERT INTO vendor (id, name, currency_id) VALUES (?, '', (SELECT currency_id FROM defaults))|;
do_query($form, $dbh, $query, $form->{id});
my $vendornumber = SL::TransNumber->new(type => 'vendor',
qq| username = ?, | .
qq| user_password = ?, | .
qq| v_customer_id = ?, | .
- qq| curr = ? | .
+ qq| currency_id = (SELECT id FROM currencies WHERE name = ?) | .
qq|WHERE id = ?|;
my @values = (
$form->{vendornumber},
$form->{username},
$form->{user_password},
$form->{v_customer_id},
- substr($form->{currency}, 0, 3),
+ $form->{currency},
$form->{id}
);
do_query($form, $dbh, $query, @values);
--- /dev/null
+# 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::Currency;
+
+use strict;
+
+use SL::DB::MetaSetup::Currency;
+
+# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
+__PACKAGE__->meta->make_manager_class;
+
+1;
sub get_default_currency {
my $self = shift->get;
- my @currencies = grep { $_ } split(/:/, $self->curr || '');
- return $currencies[0] || '';
+ return $self->currency->name || '' if $self->currency_id;
+ return '';
}
sub get {
use SL::DB::Contact;
use SL::DB::CsvImportProfile;
use SL::DB::CsvImportProfileSetting;
+use SL::DB::Currency;
use SL::DB::CustomVariable;
use SL::DB::CustomVariableConfig;
use SL::DB::CustomVariableValidity;
my $vc = $self->can('customer_id') && $self->customer_id ? 'customer' : 'vendor';
- _copy($self, $form, '', '', 0, qw(id type taxzone_id ordnumber quonumber invnumber donumber cusordnumber taxincluded shippingpoint shipvia notes intnotes curr cp_id
+ _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));
- $form->{currency} = $form->{curr}; # curr is called currency in almost all forms
+ $form->{currency} = $form->{curr} = $self->currency_id ? $self->currency->name || '' : '';
if (_has($self, 'transdate')) {
my $transdate_idx = ref($self) eq 'SL::DB::Order' ? ($self->quotation ? 'quodate' : 'orddate')
csv_import_reports => 'csv_import_report',
csv_import_report_rows => 'csv_import_report_row',
csv_import_report_status => 'csv_import_report_status',
+ currencies => 'currency',
custom_variable_configs => 'custom_variable_config',
custom_variables => 'custom_variable',
custom_variables_validity => 'custom_variable_validity',
sub _get_exchangerate {
my ($self, $data, %params) = @_;
- if (($self->curr || '') ne SL::DB::Default->get_default_currency) {
- $data->{exchangerate} = $::form->check_exchangerate(\%::myconfig, $self->curr, $self->transdate, $data->{is_sales} ? 'buy' : 'sell');
+ my $currency = $self->currency_id ? $self->currency->name || '' : '';
+ if ($currency ne SL::DB::Default->get_default_currency) {
+ $data->{exchangerate} = $::form->check_exchangerate(\%::myconfig, $currency, $self->transdate, $data->{is_sales} ? 'buy' : 'sell');
$data->{exchangerate} ||= $params{exchangerate};
}
$data->{exchangerate} ||= 1;
my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
- my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes curr salesman_id cusordnumber ordnumber quonumber
+ 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)),
+ globalproject_id transaction_description currency_id)),
transdate => DateTime->today_local,
gldate => DateTime->today_local,
duedate => DateTime->today_local->add(days => $terms * 1),
--- /dev/null
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::Currency;
+
+use strict;
+
+use base qw(SL::DB::Object);
+
+__PACKAGE__->meta->setup(
+ table => 'currencies',
+
+ columns => [
+ id => { type => 'serial', not_null => 1 },
+ name => { type => 'text', not_null => 1 },
+ ],
+
+ primary_key_columns => [ 'id' ],
+
+ unique_key => [ 'name' ],
+);
+
+1;
+;
iban => { type => 'varchar', length => 100 },
bic => { type => 'varchar', length => 100 },
direct_debit => { type => 'boolean', default => 'false' },
- curr => { type => 'text' },
taxincluded_checked => { type => 'boolean' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { business_id => 'id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
language_obj => {
class => 'SL::DB::Language',
key_columns => { language_id => 'id' },
weightunit => { type => 'varchar', length => 5 },
businessnumber => { type => 'text' },
version => { type => 'varchar', length => 8 },
- curr => { type => 'text' },
closedto => { type => 'date' },
revtrans => { type => 'boolean', default => 'false' },
ponumber => { type => 'text' },
ar_show_mark_as_paid => { type => 'boolean', default => 'true' },
ap_show_mark_as_paid => { type => 'boolean', default => 'true' },
assemblynumber => { type => 'text' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
+
+ allow_inline_column_values => 1,
+
+ foreign_keys => [
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+ ],
);
1;
taxzone_id => { type => 'integer' },
taxincluded => { type => 'boolean' },
terms => { type => 'integer' },
- curr => { type => 'text' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { cp_id => 'cp_id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
customer => {
class => 'SL::DB::Customer',
key_columns => { customer_id => 'id' },
table => 'exchangerate',
columns => [
- curr => { type => 'text' },
- transdate => { type => 'date' },
- buy => { type => 'numeric', precision => 5, scale => 15 },
- sell => { type => 'numeric', precision => 5, scale => 15 },
- itime => { type => 'timestamp', default => 'now()' },
- mtime => { type => 'timestamp' },
- id => { type => 'serial', not_null => 1 },
+ transdate => { type => 'date' },
+ buy => { type => 'numeric', precision => 5, scale => 15 },
+ sell => { type => 'numeric', precision => 5, scale => 15 },
+ itime => { type => 'timestamp', default => 'now()' },
+ mtime => { type => 'timestamp' },
+ id => { type => 'serial', not_null => 1 },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
allow_inline_column_values => 1,
+
+ foreign_keys => [
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+ ],
);
1;
shippingpoint => { type => 'text' },
terms => { type => 'integer', default => '0' },
notes => { type => 'text' },
- curr => { type => 'text' },
ordnumber => { type => 'text' },
employee_id => { type => 'integer' },
quonumber => { type => 'text' },
donumber => { type => 'text' },
invnumber_for_credit_note => { type => 'text' },
direct_debit => { type => 'boolean', default => 'false' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { cp_id => 'cp_id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
customer => {
class => 'SL::DB::Customer',
key_columns => { customer_id => 'id' },
taxincluded => { type => 'boolean' },
shippingpoint => { type => 'text' },
notes => { type => 'text' },
- curr => { type => 'character', length => 3 },
employee_id => { type => 'integer' },
closed => { type => 'boolean', default => 'false' },
quotation => { type => 'boolean', default => 'false' },
delivered => { type => 'boolean', default => 'false' },
globalproject_id => { type => 'integer' },
salesman_id => { type => 'integer' },
- transaction_description => { type => 'text' },
marge_total => { type => 'numeric', precision => 5, scale => 15 },
marge_percent => { type => 'numeric', precision => 5, scale => 15 },
+ transaction_description => { type => 'text' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { cp_id => 'cp_id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
customer => {
class => 'SL::DB::Customer',
key_columns => { customer_id => 'id' },
duedate => { type => 'date' },
invoice => { type => 'boolean', default => 'false' },
ordnumber => { type => 'text' },
- curr => { type => 'text' },
notes => { type => 'text' },
employee_id => { type => 'integer' },
quonumber => { type => 'text' },
transaction_description => { type => 'text' },
storno_id => { type => 'integer' },
direct_debit => { type => 'boolean', default => 'false' },
+ deliverydate => { type => 'date' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { cp_id => 'cp_id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
department => {
class => 'SL::DB::Department',
key_columns => { department_id => 'id' },
iban => { type => 'varchar', length => 100 },
bic => { type => 'varchar', length => 100 },
direct_debit => { type => 'boolean', default => 'false' },
- curr => { type => 'text' },
+ currency_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
key_columns => { business_id => 'id' },
},
+ currency => {
+ class => 'SL::DB::Currency',
+ key_columns => { currency_id => 'id' },
+ },
+
language_obj => {
class => 'SL::DB::Language',
key_columns => { language_id => 'id' },
$query = <<SQL;
SELECT o.amount,
(SELECT e.buy FROM exchangerate e
- WHERE e.curr = o.curr
+ WHERE e.currency_id = o.currency_id
AND e.transdate = o.transdate)
FROM oe o
WHERE (o.${type}_id = ?)
$query =
qq|INSERT INTO ar (id, invnumber, transdate, gldate, customer_id,
taxincluded, amount, netamount, paid, duedate,
- invoice, curr, notes,
+ invoice, currency_id, notes,
employee_id)
VALUES (
?, -- id
-- duedate:
(SELECT duedate FROM dunning WHERE dunning_id = ? LIMIT 1),
'f', -- invoice
- ?, -- curr
+ (SELECT id FROM currencies WHERE name = ?), -- curr
?, -- notes
-- employee_id:
(SELECT id FROM employee WHERE login = ?)
ar.transdate, ar.duedate, ar.customer_id,
ar.invnumber, ar.ordnumber, ar.cp_id,
ar.amount, ar.netamount, ar.paid,
- ar.curr,
+ (SELECT cu.name FROM currencies cu WHERE cu.id=ar.currency_id) AS curr,
ar.amount - ar.paid AS open_amount,
ar.amount - ar.paid + da.fee + da.interest AS linetotal
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO delivery_orders (id, donumber, employee_id) VALUES (?, '', ?)|;
+ $query = qq|INSERT INTO delivery_orders (id, donumber, employee_id, currency_id) VALUES (?, '', ?, (SELECT currency_id FROM defaults LIMIT 1))|;
do_query($form, $dbh, $query, $form->{id}, conv_i($form->{employee_id}));
}
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 = ?, curr = ?
+ is_sales = ?, taxzone_id = ?, taxincluded = ?, terms = ?, currency_id = (SELECT id FROM currencies WHERE name = ?)
WHERE id = ?|;
@values = ($form->{donumber}, $form->{ordnumber},
conv_i($form->{salesman_id}), conv_i($form->{cp_id}),
$form->{transaction_description},
$form->{type} =~ /^sales/ ? 't' : 'f',
- conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), substr($form->{currency}, 0, 3),
+ conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), $form->{currency},
conv_i($form->{id}));
do_query($form, $dbh, $query, @values);
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, dord.curr AS currency
+ dord.taxzone_id, dord.taxincluded, dord.terms, (SELECT cu.name FROM currencies cu WHERE cu.id=dord.currency_id) AS currency
FROM delivery_orders dord
JOIN ${vc} cv ON (dord.${vc}_id = cv.id)
LEFT JOIN employee e ON (dord.employee_id = e.id)
}
$sth->finish();
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$//;
-
$form->{donumber_array} =~ s/\s*$//g;
$form->{saved_donumber} = $form->{donumber};
$main::lxdebug->leave_sub();
return;
}
- $query = qq|SELECT curr FROM defaults|;
-
- my ($currency) = selectrow_query($self, $dbh, $query);
- my ($defaultcurrency) = split m/:/, $currency;
+ $query = qq|SELECT name AS curr FROM currencies WHERE id=(SELECT currency_id FROM defaults)|;
+ my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
if ($curr eq $defaultcurrency) {
$main::lxdebug->leave_sub();
return;
}
- $query = qq|SELECT e.curr FROM exchangerate e
- WHERE e.curr = ? AND e.transdate = ?
+ $query = qq|SELECT e.currency_id FROM exchangerate e
+ WHERE e.currency_id = (SELECT cu.id FROM currencies cu WHERE cu.name=?) AND e.transdate = ?
FOR UPDATE|;
my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
if ($sth->fetchrow_array) {
$query = qq|UPDATE exchangerate
SET $set
- WHERE curr = ?
+ WHERE currency_id = (SELECT id FROM currencies WHERE name = ?)
AND transdate = ?|;
} else {
- $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
- VALUES (?, $buy, $sell, ?)|;
+ $query = qq|INSERT INTO exchangerate (currency_id, buy, sell, transdate)
+ VALUES ((SELECT id FROM currencies WHERE name = ?), $buy, $sell, ?)|;
}
$sth->finish;
do_query($self, $dbh, $query, $curr, $transdate);
return 1;
}
- $query = qq|SELECT curr FROM defaults|;
+ $query = qq|SELECT name AS curr FROM currencies WHERE id = (SELECT currency_id FROM defaults)|;
- my ($currency) = selectrow_query($self, $dbh, $query);
- my ($defaultcurrency) = split m/:/, $currency;
+ my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
- if ($currency eq $defaultcurrency) {
+ if ($curr eq $defaultcurrency) {
$main::lxdebug->leave_sub();
return 1;
}
$query = qq|SELECT e.$fld FROM exchangerate e
- WHERE e.curr = ? AND e.transdate = ?|;
+ WHERE e.currency_id = (SELECT id FROM currencies WHERE name = ?) AND e.transdate = ?|;
my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
my $dbh = $self->get_standard_dbh($myconfig);
my $query = qq|SELECT e.$fld FROM exchangerate e
- WHERE e.curr = ? AND e.transdate = ?|;
+ WHERE e.currency_id = (SELECT id FROM currencies WHERE name = ?) AND e.transdate = ?|;
my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
my $self = shift;
my $myconfig = shift || \%::myconfig;
my $dbh = $self->get_standard_dbh($myconfig);
+ my @currencies =();
- my $query = qq|SELECT curr FROM defaults|;
-
- my ($curr) = selectrow_query($self, $dbh, $query);
- my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
+ my $query = qq|SELECT name FROM currencies|;
+ my @currencies = map { $_->{name} } selectall_hashref_query($self, $dbh, $query);
$main::lxdebug->leave_sub();
$main::lxdebug->enter_sub();
my ($self, $myconfig) = @_;
- my @currencies = $self->get_all_currencies($myconfig);
+ my $dbh = $self->get_standard_dbh($myconfig);
+ my $query = qq|SELECT name AS curr FROM currencies WHERE id = (SELECT currency_id FROM defaults)|;
+
+ my ($defaultcurrency) = selectrow_query($self, $dbh, $query);
$main::lxdebug->leave_sub();
- return $currencies[0];
+ return $defaultcurrency;
}
sub set_payment_options {
$key = "all_currencies" unless ($key);
- my $query = qq|SELECT curr AS currency FROM defaults|;
-
- $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
+ $self->{$key} = [$self->get_all_currencies()];
$main::lxdebug->leave_sub();
}
$query =
qq|SELECT
a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
- a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
+ a.duedate, a.ordnumber, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.notes,
a.intnotes, a.department_id, a.amount AS oldinvtotal,
a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
a.globalproject_id, ${extra_columns}
$self->{$key} = $ref->{$key};
}
- # remove any trailing whitespace
- $self->{currency} =~ s/\s*$//;
-
my $transdate = "current_date";
if ($self->{transdate}) {
$transdate = $dbh->quote($self->{transdate});
}
$sth->finish;
+ #check das:
$query =
qq|SELECT
- d.curr AS currencies, d.closedto, d.revtrans,
+ d.closedto, d.revtrans,
+ (SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
(SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
FROM defaults d|;
# get date
$query =
qq|SELECT
- current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
+ current_date AS transdate, d.closedto, d.revtrans,
+ (SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
(SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
FROM defaults d|;
if ($self->{"$self->{vc}_id"}) {
# only setup currency
- ($self->{currency}) = split(/:/, $self->{currencies}) if !$self->{currency};
+ ($self->{currency}) = $self->{defaultcurrency} if !$self->{currency};
} else {
my ($arap, $where);
$table = $table eq "customer" ? "customer" : "vendor";
- my %column_map = ("a.curr" => "currency",
- "a.${table}_id" => "${table}_id",
+ my %column_map = ("a.${table}_id" => "${table}_id",
"a.department_id" => "department_id",
"d.description" => "department",
"ct.name" => $table,
- "ct.curr" => "cv_curr",
+ "cu.name" => "currency",
"current_date + ct.terms" => "duedate",
);
if ($self->{type} =~ /delivery_order/) {
$arap = 'delivery_orders';
- delete $column_map{"a.curr"};
- delete $column_map{"ct.curr"};
+ delete $column_map{"cu.currency"};
} elsif ($self->{type} =~ /_order/) {
$arap = 'oe';
FROM $arap a
LEFT JOIN $table ct ON (a.${table}_id = ct.id)
LEFT JOIN department d ON (a.department_id = d.id)
+ LEFT JOIN currencies cu ON (cu.id=ct.currency_id)
WHERE a.id = ?|;
my $ref = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
map { $self->{$_} = $ref->{$_} } values %column_map;
- # remove any trailing whitespace
- $self->{currency} =~ s/\s*$// if $self->{currency};
- $self->{cv_curr} =~ s/\s*$// if $self->{cv_curr};
-
- # if customer/vendor currency is set use this
- $self->{currency} = $self->{cv_curr} if $self->{cv_curr};
-
$main::lxdebug->leave_sub();
}
# connect to database, turn off autocommit
my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ my $defaultcurrency = $form->{defaultcurrency};
my $ic_cvar_configs = CVar->get_configs(module => 'IC',
dbh => $dbh);
my $all_units = AM->retrieve_units($myconfig, $form);
+#markierung
if (!$payments_only) {
if ($form->{id}) {
&reverse_invoice($dbh, $form);
} else {
($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
- do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber) VALUES (?, '')|, $form->{id});
+ do_query($form, $dbh, qq|INSERT INTO ap (id, invnumber, currency_id) VALUES (?, '', (SELECT id FROM currencies WHERE name=?))|, $form->{id}, $form->{currency});
}
}
- my ($currencies) = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
- my $defaultcurrency = (split m/:/, $currencies)[0];
-
if ($form->{currency} eq $defaultcurrency) {
$form->{exchangerate} = 1;
} else {
orddate = ?, quodate = ?, vendor_id = ?, amount = ?,
netamount = ?, paid = ?, duedate = ?,
invoice = ?, taxzone_id = ?, notes = ?, taxincluded = ?,
- intnotes = ?, curr = ?, storno_id = ?, storno = ?,
+ intnotes = ?, storno_id = ?, storno = ?,
cp_id = ?, employee_id = ?, department_id = ?,
globalproject_id = ?, direct_debit = ?
WHERE id = ?|;
conv_date($form->{orddate}), conv_date($form->{quodate}), conv_i($form->{vendor_id}), $amount,
$netamount, $form->{paid}, conv_date($form->{duedate}),
'1', $taxzone_id, $form->{notes}, $form->{taxincluded} ? 't' : 'f',
- $form->{intnotes}, $form->{currency}, conv_i($form->{storno_id}), $form->{storno} ? '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->{globalproject_id}),
$form->{direct_debit} ? 't' : 'f',
(SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id) AS income_accno,
(SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id) AS expense_accno,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
- d.curr AS currencies
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
$q_invdate
FROM defaults d|;
$ref = selectfirst_hashref_query($form, $dbh, $query);
$query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate,
orddate, quodate, globalproject_id,
ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate,
- intnotes, curr AS currency, direct_debit
+ intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit
FROM ap
WHERE id = ?|;
$ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$//;
-
$form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell");
# get shipto
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.street, v.zipcode, v.city, v.country, v.taxzone_id, v.curr, v.direct_debit,
+ 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
FROM vendor v
LEFT JOIN business b ON (b.id = v.business_id)
LEFT JOIN payment_terms pt ON (v.payment_id = pt.id)
+ LEFT JOIN currencies cu ON (v.currency_id = cu.id)
WHERE 1=1 $where|;
my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
map { $params->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{curr} =~ s/\s*$//;
-
- # use vendor currency if not empty
- $form->{currency} = $form->{curr} if $form->{curr};
+ # use vendor currency
+ $form->{currency} = $form->{curr};
$params->{creditremaining} = $params->{creditlimit};
$query = qq|SELECT o.amount,
(SELECT e.sell
FROM exchangerate e
- WHERE (e.curr = o.curr)
+ WHERE (e.currency_id = o.currency_id)
AND (e.transdate = o.transdate)) AS exch
FROM oe o
WHERE (o.vendor_id = ?) AND (o.quotation = '0') AND (o.closed = '0')|;
# fax and phone and email as vendor*
my $query =
qq|SELECT ct.*, cp.*, ct.notes as vendornotes, phone as vendorphone, fax as vendorfax, email as vendoremail,
- ct.curr AS currency
+ cu.name AS currency
FROM vendor ct
LEFT JOIN contacts cp ON (ct.id = cp.cp_cv_id)
+ LEFT JOIN currencies cu ON (ct.currency_id = cu.id)
WHERE (ct.id = ?) $contact
ORDER BY cp.cp_id
LIMIT 1|;
}
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$// if ($form->{currency});
my $custom_variables = CVar->get_custom_variables('dbh' => $dbh,
'module' => 'CT',
my $query =
qq|SELECT ct.*, cp.*, ct.notes as customernotes,
ct.phone AS customerphone, ct.fax AS customerfax, ct.email AS customeremail,
- ct.curr AS currency
+ cu.name AS currency
FROM customer ct
LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
+ LEFT JOIN currencies cu ON (ct.currency_id = cu.id)
WHERE (ct.id = ?) $where
ORDER BY cp.cp_id
LIMIT 1|;
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$// if ($form->{currency});
-
if ($form->{delivery_customer_id}) {
$query =
qq|SELECT *, notes as customernotes
}
$form->{defaultcurrency} = $form->get_default_currency($myconfig);
+ my $defaultcurrency = $form->{defaultcurrency};
+
# Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
# korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
# Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011
$query = qq|SELECT nextval('glid')|;
($form->{"id"}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO ar (id, invnumber) VALUES (?, ?)|;
- do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"});
+ $query = qq|INSERT INTO ar (id, invnumber, currency_id) VALUES (?, ?, (SELECT id FROM currencies WHERE name=?))|;
+ do_query($form, $dbh, $query, $form->{"id"}, $form->{"id"}, $form->{currency});
if (!$form->{invnumber}) {
$form->{invnumber} =
my ($netamount, $invoicediff) = (0, 0);
my ($amount, $linetotal, $lastincomeaccno);
- my ($currencies) = selectfirst_array_query($form, $dbh, qq|SELECT curr FROM defaults|);
- my $defaultcurrency = (split m/:/, $currencies)[0];
-
if ($form->{currency} eq $defaultcurrency) {
$form->{exchangerate} = 1;
} else {
amount = ?, netamount = ?, paid = ?,
duedate = ?, deliverydate = ?, invoice = ?, shippingpoint = ?,
shipvia = ?, terms = ?, notes = ?, intnotes = ?,
- curr = ?, department_id = ?, payment_id = ?, taxincluded = ?,
+ currency_id = (SELECT id FROM currencies WHERE name = ?),
+ department_id = ?, payment_id = ?, taxincluded = ?,
type = ?, language_id = ?, taxzone_id = ?, shipto_id = ?,
employee_id = ?, salesman_id = ?, storno_id = ?, storno = ?,
cp_id = ?, marge_total = ?, marge_percent = ?,
(SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id) AS income_accno,
(SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id) AS expense_accno,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
- d.curr AS currencies
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
${query_transdate}
FROM defaults d|;
a.orddate, a.quodate, a.globalproject_id,
a.transdate AS invdate, a.deliverydate, a.paid, a.storno, a.gldate,
a.shippingpoint, a.shipvia, a.terms, a.notes, a.intnotes, a.taxzone_id,
- a.duedate, a.taxincluded, a.curr AS currency, a.shipto_id, a.cp_id,
+ a.duedate, a.taxincluded, (SELECT cu.name FROM currencies cu WHERE cu.id=a.currency_id) AS currency, a.shipto_id, a.cp_id,
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,
$ref = selectfirst_hashref_query($form, $dbh, $query, $id);
map { $form->{$_} = $ref->{$_} } keys %{ $ref };
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$//;
-
$form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "buy");
# get shipto
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.street, c.zipcode, c.city, c.country,
- c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id, c.curr,
+ 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,
$duedate + COALESCE(pt.terms_netto, 0) AS duedate,
b.discount AS tradediscount, b.description AS business
FROM customer c
LEFT JOIN business b ON (b.id = c.business_id)
LEFT JOIN payment_terms pt ON ($payment_id (c.payment_id = pt.id))
+ LEFT JOIN currencies cu ON (c.currency_id=cu.id)
WHERE c.id = ?|;
push @values, $cid;
$ref = selectfirst_hashref_query($form, $dbh, $query, @values);
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{curr} =~ s/\s*$//;
-
- # use customer currency if not empty
- $form->{currency} = $form->{curr} if $form->{curr};
+ # use customer currency
+ $form->{currency} = $form->{curr};
$query =
qq|SELECT sum(amount - paid) AS dunning_amount
$query =
qq|SELECT o.amount,
(SELECT e.buy FROM exchangerate e
- WHERE e.curr = o.curr
+ WHERE e.currency_id = o.currency_id
AND e.transdate = o.transdate)
FROM oe o
WHERE o.customer_id = ?
$self->{data} = selectfirst_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT * FROM defaults|);
- my $curr = $self->{data}->{curr} || '';
- $curr =~ s/\s+//g;
- $self->{currencies} = [ split m/:/, $curr ];
+ #To get all currencies and the default currency:
+ ($self->{data}->{curr}) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT name AS curr FROM currencies WHERE id = (SELECT currency_id FROM defaults)|);
+ $self->{currencies} = [ map { $_->{name} } selectall_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT name FROM currencies ORDER BY id|) ];
return $self;
}
sub get_default_currency {
my ($self) = @_;
- return ($self->get_currencies)[0];
+ return $self->{data}->{curr};
}
sub get_currencies {
my ($self) = @_;
- return $self->{currencies} ? @{ $self->{currencies} } : ();
+ return @{ $self->{currencies} };
}
sub get_accounting_method {
qq|JOIN $vc ct ON (o.${vc}_id = ct.id) | .
qq|LEFT JOIN employee e ON (o.employee_id = e.id) | .
qq|LEFT JOIN employee s ON (o.salesman_id = s.id) | .
- qq|LEFT JOIN exchangerate ex ON (ex.curr = o.curr | .
+ qq|LEFT JOIN exchangerate ex ON (ex.currency_id = o.currency_id | .
qq| AND ex.transdate = o.transdate) | .
qq|LEFT JOIN project pr ON (o.globalproject_id = pr.id) | .
qq|$periodic_invoices_joins | .
$query = qq|SELECT nextval('id')|;
($form->{id}) = selectrow_query($form, $dbh, $query);
- $query = qq|INSERT INTO oe (id, ordnumber, employee_id) VALUES (?, '', ?)|;
+ $query = qq|INSERT INTO oe (id, ordnumber, employee_id, currency_id) VALUES (?, '', ?, (SELECT currency_id FROM defaults))|;
do_query($form, $dbh, $query, $form->{id}, $form->{employee_id});
}
qq|UPDATE oe SET
ordnumber = ?, quonumber = ?, cusordnumber = ?, transdate = ?, vendor_id = ?,
customer_id = ?, amount = ?, netamount = ?, reqdate = ?, taxincluded = ?,
- shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = ?, closed = ?,
+ 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 = ?,
globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ?
$amount, $netamount, conv_date($reqdate),
$form->{taxincluded} ? 't' : 'f', $form->{shippingpoint},
$form->{shipvia}, $form->{notes}, $form->{intnotes},
- substr($form->{currency}, 0, 3), $form->{closed} ? 't' : 'f',
+ $form->{currency}, $form->{closed} ? 't' : 'f',
$form->{delivered} ? "t" : "f", $form->{proforma} ? 't' : 'f',
$quotation, conv_i($form->{department_id}),
conv_i($form->{language_id}), conv_i($form->{taxzone_id}),
(SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id) AS income_accno,
(SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id) AS expense_accno,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
- d.curr AS currencies
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
$query_add
FROM defaults d|;
my $ref = selectfirst_hashref_query($form, $dbh, $query);
map { $form->{$_} = $ref->{$_} } keys %$ref;
- ($form->{currency}) = split(/:/, $form->{currencies}) unless ($form->{currency});
+ $form->{currency} = $form->get_default_currency($myconfig);
# set reqdate if this is an invoice->order conversion. If someone knows a better check to ensure
# we come from invoices, feel free.
$query =
qq|SELECT o.cp_id, o.ordnumber, o.transdate, o.reqdate,
o.taxincluded, o.shippingpoint, o.shipvia, o.notes, o.intnotes,
- o.curr AS currency, e.name AS employee, o.employee_id, o.salesman_id,
+ (SELECT cu.name FROM currencies cu WHERE cu.id=o.currency_id) AS currency, e.name AS employee, o.employee_id, o.salesman_id,
o.${vc}_id, cv.name AS ${vc}, o.amount AS invtotal,
o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
if ($ref) {
map { $form->{$_} = $ref->{$_} } keys %$ref;
- # remove any trailing whitespace
- $form->{currency} =~ s/\s*$//;
-
$form->{saved_xyznumber} = $form->{$form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber"};
# set all entries for multiple ids blank that yield different information
"duedate", invoice, ${arap}.id, date_part('days', now() - duedate) as overduedays,
(SELECT $buysell
FROM exchangerate
- WHERE (${arap}.curr = exchangerate.curr)
+ WHERE (${arap}.currency_id = exchangerate.currency_id)
AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
FROM ${arap}, ${ct}
WHERE ((paid != amount) OR (datepaid > (date $todate) AND datepaid is not null))
do_query($form, $dbh, $query, $form->{profit_determination});
$query = "UPDATE defaults SET inventory_system = ?";
do_query($form, $dbh, $query, $form->{inventory_system});
+ $query = "UPDATE defaults SET curr = ?";
+ do_query($form, $dbh, $query, $form->{defaultcurrency});
$dbh->disconnect;
my $locale = $main::locale;
$form->isblank("db", $locale->text('Dataset missing!'));
+ $form->isblank("defaultcurrency", $locale->text('Default currency missing!'));
User->dbcreate(\%$form);
# geben und hier reinparsen, oder besser multibox oder html auslagern?
# Antwort: form->currency wird mit oldcurrency oder curr[0] überschrieben
# Wofür macht das Sinn?
- @curr = split(/:/, $form->{currencies});
- chomp $curr[0];
+ @curr = $form->get_all_currencies();
$form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} =
- $curr[0];
+ $form->get_default_currency(\%myconfig);
# Entsprechend präventiv die Auswahlliste für Währungen
# auch mit value= zusammenbauen (s.a. oben bugfix 1771)
IC->create_links("IC", \%myconfig, \%$form);
# currencies
- map({ $form->{selectcurrency} .= "<option>$_\n" }
- split(/:/, $form->{currencies}));
+ map({ $form->{selectcurrency} .= "<option>$_\n" } $::form->get_all_currencies());
# parts and assemblies have the same links
my $item = $form->{item};
$form->{currency} = $currency;
}
- my @curr = split(/:/, $form->{currencies}); #seems to be missing
+ my @curr = $form->get_all_currencies();
map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
$form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
'#1 h' => '#1 h',
'#1 of #2 importable objects were imported.' => '#1 von #2 importierbaren Objekten wurden importiert.',
'#1 prices were updated.' => '#1 Preise wurden aktualisiert.',
+ '(recommended) Insert the used currencies in the system. You can simply change the name of the currencies by editing the textfields above. Do not use a name of a currency that is already in use.' => '(empfohlen) Fügen Sie die verwaisten Währungen in Ihr System ein. Sie können den Namen der Währung einfach ändern, indem Sie die Felder oben bearbeiten. Benutzen Sie keine Namen von Währungen, die Sie bereits benutzen.',
'* there are restrictions for the perpetual method, look at chapter "Bemerkungen zu Bestandsmethode" in' => ' für die Bestandsmethode gibt es Einschränkungen, siehe Kapitel "Bemerkungen zu Bestandsmethode" in',
'*) Since version 2.7 these parameters ares set in the client database and not in the configuration file, details in chapter:' => '*) Seit 2.7 werden Gewinnermittlungsart, Versteuerungsart und Warenbuchungsmethode in der Mandanten-DB gesteuert und nicht mehr in der Konfigurationsdatei, Umstellungs-Details:',
'*/' => '*/',
'Both' => 'Beide',
'Bottom' => 'Unten',
'Bought' => 'Gekauft',
+ 'Break up the update and contact a service provider.' => 'Diese Option bricht das Update ab. Bitte kontaktieren Sie Ihren Administrator oder beauftragen einen Dienstleister.',
'Buchungsdatum' => 'Buchungsdatum',
'Buchungsgruppe' => 'Buchungsgruppe',
'Buchungsgruppe (database ID)' => 'Buchungsgruppe (Datenbank-ID)',
'Default Customer/Vendor Language' => 'Standard-Kunden-/Lieferantensprache',
'Default Warehouse' => '',
'Default buchungsgruppe' => 'Standardbuchungsgruppe',
+ 'Default currency' => 'Standardwährung',
+ 'Default currency missing!' => 'Standardwährung fehlt!',
'Default output medium' => 'Standardausgabekanal',
'Default printer' => 'Standarddrucker',
'Default template format' => 'Standardvorlagenformat',
'End date' => 'Enddatum',
'Enter a description for this new draft.' => 'Geben Sie eine Beschreibung für diesen Entwurf ein.',
'Enter longdescription' => 'Langtext eingeben',
- 'Enter the abbreviations separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' => 'Geben Sie Ihre und weitere Währungen als Abkürzungen durch Doppelpunkte getrennt ein (z.B. EUR:USD:CAD)',
'Enter the requested execution date or leave empty for the quickest possible execution:' => 'Geben Sie das jeweils gewünschte Ausführungsdatum an, oder lassen Sie das Feld leer für die schnellstmögliche Ausführung:',
'Entries for which automatic conversion failed:' => 'Einträge, für die die automatische Umstellung fehlschlug:',
'Entries for which automatic conversion succeeded:' => 'Einträge, für die die automatische Umstellung erfolgreich war:',
'Fristsetzung' => 'Fristsetzung',
'From' => 'Von',
'From Date' => 'Von',
+ 'From this version on it is necessary to name a default value.' => 'Ab dieser Version benötigt kivitendo eine Standardwährung.',
'From this version on a new feature is available.' => 'Ab dieser Version ist ein neues Feature verfügbar.',
'From this version on the partnumber of services, articles and assemblies have to be unique.' => 'Ab dieser Version müssen Artikelnummern eindeutig vergeben werden.',
'From this version on the taxkey 0 must have a tax rate of 0 (for DATEV compatibility).' => 'Ab dieser Version muss der Steuerschlüssel 0 einen Steuersatz von 0% haben (auf Grund der DATEV-Kompatibilität).',
'ID-Nummer' => 'ID-Nummer (intern)',
'II' => 'II',
'III' => 'III',
- 'IMPORTANT NOTE: You cannot safely change currencies, IF you have already booking entries!' => 'WICHTIGER HINWEIS: Falls schon Buchungen im Mandanten vorhanden sind, kann man nicht mehr UNKRITISCH neue oder andere Währungen konfigurieren!',
'IV' => 'IV',
'If checked the taxkey will not be exported in the DATEV Export, but only IF chart taxkeys differ from general ledger taxkeys' => 'Falls angehakt wird der DATEV-Steuerschlüssel bei Buchungen auf dieses Konto nicht beim DATEV-Export mitexportiert, allerdings nur wenn zusätzlich der Konto-Steuerschlüssel vom Buchungs (Hauptbuch) Steuerschlüssel abweicht',
'If the article type is set to \'mixed\' then a column called \'type\' must be present.' => 'Falls der Artikeltyp auf \'gemischt\' gestellt wird, muss eine Spalte namens \'type\' vorhanden sein.',
'No data was found.' => 'Es wurden keine Daten gefunden.',
'No databases have been found on this server.' => 'Auf diesem Server wurden keine Datenbanken gefunden.',
'No datasets have been selected.' => 'Es wurden keine Datenbanken ausgewählt.',
+ 'No default currency' => 'Keine Standardwährung',
'No department has been created yet.' => 'Es wurde noch keine Abteilung erfasst.',
'No dunnings have been selected for printing.' => 'Es wurden keine Mahnungen zum Drucken ausgewählt.',
'No entries were found which had no unit assigned to them.' => 'Es wurden keine Einträge gefunden, denen keine Einheit zugeordnet war.',
'Orders / Delivery Orders deleteable' => 'Aufträge / Lieferscheine löschbar',
'Orientation' => 'Seitenformat',
'Orphaned' => 'Nie benutzt',
+ 'Orphaned currencies' => 'Verwaiste Währungen',
'Other users\' follow-ups' => 'Wiedervorlagen anderer Benutzer',
'Other values are ignored.' => 'Andere Eingaben werden ignoriert.',
'Others' => 'Andere',
'Please contact your administrator.' => 'Bitte wenden Sie sich an Ihren Administrator.',
'Please define a taxkey for the following taxes and run the update again:' => 'Bitte definieren Sie einen Steuerschlüssel für die folgenden Steuern und starten Sie dann das Update erneut:',
'Please enter a profile name.' => 'Bitte geben Sie einen Profilnamen an.',
+ 'Please enter the currency you are working with.' => 'Bitte geben Sie die Währung an, mit der Sie arbeiten.',
'Please enter the login for the new user.' => 'Bitte geben Sie das Login für den neuen Benutzer ein.',
'Please enter the name of the database that will be used as the template for the new database:' => 'Bitte geben Sie den Namen der Datenbank an, die als Vorlage für die neue Datenbank benutzt wird:',
'Please enter the name of the dataset you want to restore the backup in.' => 'Bitte geben Sie den Namen der Datenbank ein, in der Sie die Sicherung wiederherstellen wollen.',
'Removed spoolfiles!' => 'Druckdateien entfernt!',
'Removing marked entries from queue ...' => 'Markierte Einträge werden von der Warteschlange entfernt ...',
'Rename the group' => 'Gruppe umbenennen',
+ 'Replace the orphaned currencies by other not orphaned currencies. To do so, please delete the currency in the textfields above and replace it by another currency. You could loose or change unintentionally exchangerates. Go on very carefully since you could destroy transactions.' => 'Ersetze die Währungen durch andere gültige Währungen. Wenn Sie sich hierfür entscheiden, ersetzen Sie bitte alle Währungen, die oben angegeben sind, durch Währungen, die in Ihrem System ordnungsgemäß eingetragen sind. Alle eingetragenen Wechselkurse für die verwaiste Währung werden dabei gelöscht. Bitte gehen Sie sehr vorsichtig vor, denn die betroffenen Buchungen können unter Umständen kaputt gehen.',
'Report Positions' => 'Berichte',
'Report about warehouse contents' => 'Lagerbestand anzeigen',
'Report about warehouse transactions' => 'Lagerbuchungen anzeigen',
'Text variables: \'MAXLENGTH=n\' sets the maximum entry length to \'n\'.' => 'Textzeilen: \'MAXLENGTH=n\' setzt eine Maximallänge von n Zeichen.',
'Text, text field and number variables: The default value will be used as-is.' => 'Textzeilen, Textfelder und Zahlenvariablen: Der Standardwert wird so wie er ist übernommen.',
'That export does not exist.' => 'Dieser Export existiert nicht.',
+ 'That is why kivitendo could not find a default currency.' => 'Daher konnte kivitendo keine Standardwährung finden.',
'The \'tag\' field must only consist of alphanumeric characters or the carachters - _ ( )' => 'Das Feld \'tag\' darf nur aus alphanumerischen Zeichen und den Zeichen - _ ( ) bestehen.',
'The AP transaction #1 has been deleted.' => 'Die Kreditorenbuchung #1 wurde gelöscht.',
'The AR transaction #1 has been deleted.' => 'Die Debitorenbuchung #1 wurde gelöscht.',
'The follow-up date is missing.' => 'Das Wiedervorlagedatum fehlt.',
'The following Buchungsgruppen have already been created:' => 'Die folgenden Buchungsgruppen wurden bereits angelegt:',
'The following Datasets need to be updated' => 'Folgende Datenbanken müssen aktualisiert werden',
+ 'The following currencies have been used, but they are not defined:' => 'Die folgenden Währungen wurden benutzt, sind aber nicht ordnungsgemäß in der Datenbank eingetragen:',
'The following drafts have been saved and can be loaded.' => 'Die folgenden Entwürfe wurden gespeichert und können geladen werden.',
'The following old files whose settings have to be merged manually into the new configuration file "config/kivitendo.conf" still exist:' => 'Es existieren noch die folgenden alten Dateien, deren Einstellungen manuell in die neue Konfiguratsdatei "config/kivitendo.conf" migriert werden müssen:',
'The following transaction contains wrong taxes:' => 'Die folgende Buchung enthält falsche Steuern:',
'There are no entries in the background job history.' => 'Es gibt keine Einträge im Hintergrund-Job-Verlauf.',
'There are no items in stock.' => 'Dieser Artikel ist nicht eingelagert.',
'There are no items on your TODO list at the moment.' => 'Ihre Aufgabenliste enthält momentan keine Einträge.',
+ 'There are several options you can handle this problem, please select one:' => 'Bitte wählen Sie eine der folgenden Optionen, um mit dem Problem umzugehen:',
'There are still entries in the database for which no unit has been assigned.' => 'Es gibt noch Einträge in der Datenbank, für die keine Einheit zugeordnet ist.',
'There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?' => 'Einige der Lagerbewegungen sind nicht vollständig und Lagerbewegungen können nachträglich nicht mehr verändert werden. Wollen Sie wirklich fortfahren?',
+ 'There are undefined currencies in your system.' => 'In Ihrer Datenbank wurden Währungen benutzt, die nicht ordnungsgemäß in den Währungen eingetragen wurden.',
'There are usually three ways to install Perl modules.' => 'Es gibt normalerweise drei Arten, ein Perlmodul zu installieren.',
'There is already a taxkey 0 with tax rate not 0.' => 'Es existiert bereits ein Steuerschlüssel mit Steuersatz ungleich 0%.',
'There is an inconsistancy in your database.' => 'In Ihrer Datenbank sind Unstimmigkeiten vorhanden.',
'You cannot create an invoice for delivery orders from different vendors.' => 'Sie können keine Rechnung aus Lieferscheinen von verschiedenen Lieferanten erstellen.',
'You do not have the permissions to access this function.' => 'Sie verfügen nicht über die notwendigen Rechte, um auf diese Funktion zuzugreifen.',
'You have entered or selected the following shipping address for this customer:' => 'Sie haben die folgende Lieferadresse eingegeben oder ausgewählt:',
+ 'You have never worked with currencies.' => 'Sie haben noch nie mit Währungen gearbeitet.',
'You have not added bank accounts yet.' => 'Sie haben noch keine Bankkonten angelegt.',
'You have not selected any delivery order.' => 'Sie haben keinen Lieferschein ausgewählt.',
'You have not selected any export.' => 'Sie haben keinen Export ausgewählt.',
--- /dev/null
+# @tag: currencies
+# @description: Erstellt neue Tabelle currencies. Währungen können dann einfacher eingegeben und unkritisch geändert werden.
+# @depends: release_3_0_0 rm_whitespaces
+
+package SL::DBUpgrade2::currencies;
+
+use utf8;
+use strict;
+
+use parent qw(SL::DBUpgrade2::Base);
+
+
+sub run {
+ my ($self) = @_;
+ #Check wheather default currency exists
+ my $query = qq|SELECT curr FROM defaults|;
+ my ($currencies) = $self->dbh->selectrow_array($query);
+
+ if (length($currencies) == 0 and length($main::form->{defaultcurrency}) == 0){
+ print_no_default_currency();
+ return 2;
+ } else {
+ if (length($main::form->{defaultcurrency}) == 0){
+ $main::form->{defaultcurrency} = (split m/:/, $currencies)[0];
+ }
+ }
+ my @currency_array = grep {$_ ne '' } split m/:/, $currencies;
+
+ $query = qq|SELECT DISTINCT curr FROM ar
+ UNION
+ SELECT DISTINCT curr FROM ap
+ UNION
+ SELECT DISTINCT curr FROM oe
+ UNION
+ SELECT DISTINCT curr FROM customer
+ UNION
+ SELECT DISTINCT curr FROM delivery_orders
+ UNION
+ SELECT DISTINCT curr FROM exchangerate
+ UNION
+ SELECT DISTINCT curr FROM vendor|;
+
+ my $sth = $self->dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ $main::form->{ORPHANED_CURRENCIES} = [];
+ my $is_orphaned;
+ my $rowcount = 0;
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+ next unless length($ref->{curr}) > 0;
+ $is_orphaned = 1;
+ foreach my $key (split(/:/, $currencies)) {
+ if ($ref->{curr} eq $key) {
+ $is_orphaned = 0;
+ last;
+ }
+ }
+ if ($is_orphaned) {
+ push @{ $main::form->{ORPHANED_CURRENCIES} }, $ref;
+ $main::form->{ORPHANED_CURRENCIES}[$rowcount]->{name} = "curr_$rowcount";
+ $rowcount++;
+ }
+ }
+
+ $sth->finish;
+
+ if (scalar @{ $main::form->{ORPHANED_CURRENCIES} } > 0 and not ($main::form->{continue_options})) {
+ print_orphaned_currencies();
+ return 2;
+ }
+
+ if ($main::form->{continue_options} eq 'break_up') {
+ return 0;
+ }
+
+ if ($main::form->{continue_options} eq 'insert') {
+ for my $i (0..($rowcount-1)){
+ push @currency_array, $main::form->{"curr_$i"};
+ }
+ create_and_fill_table($self, @currency_array);
+ return 1;
+ }
+
+ my $still_orphaned;
+ if ($main::form->{continue_options} eq 'replace') {
+ for my $i (0..($rowcount - 1)){
+ $still_orphaned = 1;
+ for my $item (@currency_array){
+ if ($main::form->{"curr_$i"} eq $item){
+ $still_orphaned = 0;
+ $query = qq|DELETE FROM exchangerate WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE ap SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE ar SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE oe SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE customer SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE delivery_orders SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ $query = qq|UPDATE vendor SET curr = '| . $main::form->{"curr_$i"} . qq|' WHERE curr = '| . $main::form->{"old_curr_$i"} . qq|'|;
+ $self->db_query($query);
+ last;
+ }
+ }
+ if ($still_orphaned){
+ $main::form->{continue_options} = '';
+ return do_update();
+ }
+ }
+ create_and_fill_table($self, @currency_array);
+ return 1;
+ }
+
+ #No orphaned currencies, so create table:
+ create_and_fill_table($self, @currency_array);
+ return 1;
+}; # end do_update
+
+sub create_and_fill_table {
+ my $self = shift;
+ #Create an fill table currencies:
+ my $query = qq|CREATE TABLE currencies (id SERIAL PRIMARY KEY,
+ name TEXT NOT NULL UNIQUE)|;
+ $self->db_query($query);
+ foreach my $item ( @_ ) {
+ $query = qq|INSERT INTO currencies (name) VALUES ('| . $item . qq|')|;
+ $self->db_query($query);
+ }
+
+ #Set default currency if no currency was chosen:
+ $query = qq|UPDATE ap SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|UPDATE ar SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|UPDATE oe SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|UPDATE customer SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|UPDATE delivery_orders SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|UPDATE vendor SET curr = '| . $main::form->{"defaultcurrency"} . qq|' WHERE curr IS NULL or curr='';|;
+ $query .= qq|DELETE FROM exchangerate WHERE curr IS NULL or curr='';|;
+ $self->db_query($query);
+
+ #Check wheather defaultcurrency is already in table currencies:
+ $query = qq|SELECT name FROM currencies WHERE name = '| . $main::form->{defaultcurrency} . qq|'|;
+ my ($insert_default) = $self->dbh->selectrow_array($query);
+
+ if (!$insert_default) {
+ $query = qq|INSERT INTO currencies (name) VALUES ('| . $main::form->{defaultcurrency} . qq|')|;
+ $self->db_query($query);
+ }
+
+ #Create a new columns currency_id and update with curr.id:
+ $query = qq|ALTER TABLE ap ADD currency_id INTEGER;
+ ALTER TABLE ar ADD currency_id INTEGER;
+ ALTER TABLE oe ADD currency_id INTEGER;
+ ALTER TABLE customer ADD currency_id INTEGER;
+ ALTER TABLE delivery_orders ADD currency_id INTEGER;
+ ALTER TABLE exchangerate ADD currency_id INTEGER;
+ ALTER TABLE vendor ADD currency_id INTEGER;
+ ALTER TABLE defaults ADD currency_id INTEGER;|;
+ $self->db_query($query);
+ #Set defaultcurrency:
+ $query = qq|UPDATE defaults SET currency_id= (SELECT id FROM currencies WHERE name = '| . $main::form->{defaultcurrency} . qq|')|;
+ $self->db_query($query);
+ $query = qq|UPDATE ap SET currency_id = (SELECT id FROM currencies c WHERE c.name = ap.curr);
+ UPDATE ar SET currency_id = (SELECT id FROM currencies c WHERE c.name = ar.curr);
+ UPDATE oe SET currency_id = (SELECT id FROM currencies c WHERE c.name = oe.curr);
+ UPDATE customer SET currency_id = (SELECT id FROM currencies c WHERE c.name = customer.curr);
+ UPDATE delivery_orders SET currency_id = (SELECT id FROM currencies c WHERE c.name = delivery_orders.curr);
+ UPDATE exchangerate SET currency_id = (SELECT id FROM currencies c WHERE c.name = exchangerate.curr);
+ UPDATE vendor SET currency_id = (SELECT id FROM currencies c WHERE c.name = vendor.curr);|;
+ $self->db_query($query);
+
+ #Drop column 'curr':
+ $query = qq|ALTER TABLE ap DROP COLUMN curr;
+ ALTER TABLE ar DROP COLUMN curr;
+ ALTER TABLE oe DROP COLUMN curr;
+ ALTER TABLE customer DROP COLUMN curr;
+ ALTER TABLE delivery_orders DROP COLUMN curr;
+ ALTER TABLE exchangerate DROP COLUMN curr;
+ ALTER TABLE vendor DROP COLUMN curr;
+ ALTER TABLE defaults DROP COLUMN curr;|;
+ $self->db_query($query);
+
+ #Set NOT NULL constraints:
+ $query = qq|ALTER TABLE ap ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE ar ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE oe ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE customer ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE delivery_orders ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE exchangerate ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE vendor ALTER COLUMN currency_id SET NOT NULL;
+ ALTER TABLE defaults ALTER COLUMN currency_id SET NOT NULL;|;
+ $self->db_query($query);
+
+ #Set foreign keys:
+ $query = qq|ALTER TABLE ap ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE ar ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE oe ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE customer ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE delivery_orders ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE exchangerate ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE vendor ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);
+ ALTER TABLE defaults ADD FOREIGN KEY (currency_id) REFERENCES currencies(id);|;
+ $self->db_query($query);
+
+};
+
+sub print_no_default_currency {
+ print $main::form->parse_html_template("dbupgrade/no_default_currency");
+};
+
+sub print_orphaned_currencies {
+ print $main::form->parse_html_template("dbupgrade/orphaned_currencies");
+};
+
+1;
--- /dev/null
+# @tag: rm_whitespaces
+# @description: Entfernt mögliche Leerzeichen am Anfang und Ende jeder Währung
+# @depends: release_3_0_0
+
+package SL::DBUpgrade2::rm_whitespaces;
+
+use parent qw(SL::DBUpgrade2::Base);
+
+use utf8;
+use strict;
+
+sub run {
+ my ($self) = @_;
+
+ my $query;
+
+ foreach my $table (qw(ar ap oe customer delivery_orders exchangerate vendor)){
+ $self->db_query(qq|UPDATE ${table} SET curr=BTRIM(curr)|)
+ }
+
+ $query = qq|SELECT curr FROM defaults|;
+ my ($curr) = $self->dbh->selectrow_array($query);
+
+ $curr =~ s/ //g;
+
+ $query = qq|UPDATE defaults SET curr = '$curr'|;
+ $self->db_query($query);
+ return 1;
+};
+
+1;
</td>
</tr>
+ <tr>
+ <th align="right" nowrap>[% 'Default currency' | $T8 %]</th>
+ <td><input name="defaultcurrency" value="EUR"></td>
+ </td>
+ </tr>
+
<tr>
<th valign="top" align="right" nowrap>[% 'Create Chart of Accounts' | $T8 %]</th>
<td>
</tr>
<tr>
- <th align="right">[% 'Currencies' | $T8 %] <sup>(1)</sup></th>
- <td colspan="3"><input name="curr" size="20" value="[% HTML.escape(defaults_curr) %]"></td>
+ <th align="right">[% 'Default currency' | $T8 %]</th>
+ <td colspan="3">[% HTML.escape(defaultcurrency) %]</td>
+ </tr>
+
+ <tr>
+ <input type="hidden" name="rowcount" value="[% CURRENCIES.size %]">
+ <th align="right">[% 'Currencies' | $T8 %]</th>
+ <td colspan="3">[% FOREACH row = CURRENCIES %]<input name="curr_[% loop.count %]" size="3" value="[% HTML.escape(row.curr) %]">
+ <input type=hidden name="old_curr_[% loop.count %]" value="[% HTML.escape(row.curr) %]">
+ [% END %]
+ <input name="new_curr" size="3" value="">
+ </td>
</tr>
<tr>
<hr height="3" noshade>
- <p>
- (1) [% 'Enter the abbreviations separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' | $T8 %]
- [% 'IMPORTANT NOTE: You cannot safely change currencies, IF you have already booking entries!' | $T8 %]
</p>
</form>
<td>[% L.input_tag('bic', bic, maxlength=100, size=30) %]</td>
[%- IF ALL_CURRENCIES.size %]
<th align="right">[% 'Currency' | $T8 %]</th>
- <td>[% L.select_tag('currency', ALL_CURRENCIES, default = currency, with_empty = 1) %]</td>
+ <td>[% L.select_tag('currency', ALL_CURRENCIES, default = currency) %]</td>
[%- END %]
</tr>
--- /dev/null
+[%- USE T8 %]
+[% USE HTML %]<div class="listtop">[% 'No default currency' | $T8 %]</div>
+
+<form name="Form" method="post" action="login.pl">
+<input type="hidden" name="action" value="login">
+
+<p>[% 'You have never worked with currencies.' | $T8 %]</p>
+<p>[% 'That is why kivitendo could not find a default currency.' | $T8 %]</p>
+<p>[% 'From this version on it is necessary to name a default value.' | $T8 %]</p>
+<p>[% 'Please enter the currency you are working with.' | $T8 %]</p>
+
+<input name="defaultcurrency" value="EUR">
+<input type="submit" value="[% 'Continue' | $T8 %]">
+
+</form>
+
--- /dev/null
+[%- USE T8 %]
+[%- USE L %]
+[% USE HTML %]<div class="listtop">[% 'Orphaned currencies' | $T8 %]</div>
+
+<form name="Form" method="post" action="login.pl">
+<input type="hidden" name="action" value="login">
+<input type="hidden" name="defaultcurrency" value="[% HTML.escape(defaultcurrency) %]">
+
+<p>[% 'There are undefined currencies in your system.' | $T8 %]</p>
+<p>[% 'The following currencies have been used, but they are not defined:' | $T8 %]</p>
+[% FOREACH row = ORPHANED_CURRENCIES %]
+<input name="[% row.name %]" value="[% HTML.escape(row.curr) %]"><br>
+<input type="hidden" name="old_[% row.name %]" value="[% HTML.escape(row.curr) %]">
+[% END %]
+<p>[% 'There are several options you can handle this problem, please select one:' | $T8 %]</p>
+
+<table width="100%">
+
+<tr>
+<td>
+[% L.radio_button_tag('continue_options',
+ value => 'insert',
+ disabled => 0,
+ checked => 0) %]
+ [% '(recommended) Insert the used currencies in the system. You can simply change the name of the currencies by editing the textfields above. Do not use a name of a currency that is already in use.' | $T8 %] <br>
+[% L.radio_button_tag('continue_options',
+ value => 'replace',
+ disabled => 0,
+ checked => 0) %]
+ [% 'Replace the orphaned currencies by other not orphaned currencies. To do so, please delete the currency in the textfields above and replace it by another currency. You could loose or change unintentionally exchangerates. Go on very carefully since you could destroy transactions.' | $T8 %] <br>
+[% L.radio_button_tag('continue_options',
+ value => 'break_up',
+ disabled => 0,
+ checked => 0) %]
+ [% 'Break up the update and contact a service provider.' | $T8 %]
+</tr>
+</td>
+</table>
+
+<input type="submit" value="[% 'Continue' | $T8 %]">
+
+</form>
+