(SELECT sortkey FROM $table WHERE id = ?) AS sortkey2|;
my @values = ($form->{"id1"}, $form->{"id2"});
my @sortkeys = selectrow_query($form, $dbh, $query, @values);
+ $main::lxdebug->dump(0, "v", \@values);
+ $main::lxdebug->dump(0, "s", \@sortkeys);
$query = qq|UPDATE $table SET sortkey = ? WHERE id = ?|;
my $sth = $dbh->prepare($query);
# connect to database
my $dbh = $form->dbconnect($myconfig);
- my $query = qq|SELECT *
- FROM payment_terms
- ORDER BY id|;
+ my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
+ $form->{ALL} = [];
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
push @{ $form->{ALL} }, $ref;
}
# connect to database
my $dbh = $form->dbconnect($myconfig);
- my $query =
- qq|SELECT *
- FROM payment_terms
- WHERE id = $form->{id}|;
+ my $query = qq|SELECT * FROM payment_terms WHERE id = ?|;
my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
+ $sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})");
my $ref = $sth->fetchrow_hashref(NAME_lc);
- $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100));
-
map { $form->{$_} = $ref->{$_} } keys %$ref;
$sth->finish;
# connect to database
my $dbh = $form->dbconnect($myconfig);
- $form->{description} =~ s/\'/\'\'/g;
- $form->{description_long} =~ s/\'/\'\'/g;
- $percentskonto = $form->parse_amount($myconfig, $form->{percent_skonto}) /100;
- $form->{ranking} *= 1;
- $form->{terms_netto} *= 1;
- $form->{terms_skonto} *= 1;
- $form->{percent_skonto} *= 1;
-
-
+ my @values = ($form->{description}, $form->{description_long},
+ $form->{ranking} * 1,
+ $form->{terms_netto} * 1, $form->{terms_skonto} * 1,
+ $form->{percent_skonto} * 1);
+ my $query;
# id is the old record
if ($form->{id}) {
$query = qq|UPDATE payment_terms SET
- description = '$form->{description}',
- ranking = $form->{ranking},
- description_long = '$form->{description_long}',
- terms_netto = $form->{terms_netto},
- terms_skonto = $form->{terms_skonto},
- percent_skonto = $percentskonto
- WHERE id = $form->{id}|;
+ description = ?, description_long = ?,
+ ranking = ?,
+ terms_netto = ?, terms_skonto = ?,
+ percent_skonto = ?
+ WHERE id = ?|;
+ push(@values, $form->{"id"});
} else {
+ $query = qq|SELECT MAX(sortkey) + 1 FROM payment_terms|;
+ my ($sortkey) = selectrow_query($form, $dbh, $query);
$query = qq|INSERT INTO payment_terms
- (description, ranking, description_long, terms_netto, terms_skonto, percent_skonto)
- VALUES ('$form->{description}', $form->{ranking}, '$form->{description_long}', $form->{terms_netto}, $form->{terms_skonto}, $percentskonto)|;
+ (description, description_long, ranking,
+ terms_netto, terms_skonto, percent_skonto, sortkey)
+ VALUES (?, ?, ?, ?, ?, ?, ?)|;
+ push(@values, $sortkey);
}
- $dbh->do($query) || $form->dberror($query);
+ do_query($form, $dbh, $query, @values);
$dbh->disconnect;
# connect to database
my $dbh = $form->dbconnect($myconfig);
- $query = qq|DELETE FROM payment_terms
- WHERE id = $form->{id}|;
- $dbh->do($query) || $form->dberror($query);
+ my $query = qq|DELETE FROM payment_terms WHERE id = ?|;
+ do_query($form, $dbh, $query, $form->{"id"});
$dbh->disconnect;
# get payment terms
$query = qq|SELECT id, description
FROM payment_terms
- ORDER BY 1|;
+ ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
# get payment terms
$query = qq|SELECT id, description
FROM payment_terms
- ORDER BY 1|;
+ ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
# get payment terms
$query = qq|SELECT id, description
FROM payment_terms
- ORDER BY 1|;
+ ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
# get payment terms
$query = qq|SELECT id, description
FROM payment_terms
- ORDER BY 1|;
+ ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
# get payment terms
$query = qq|SELECT id, description
FROM payment_terms
- ORDER BY 1|;
+ ORDER BY sortkey|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
$form->{title} = "Edit";
AM->get_payment(\%myconfig, \%$form);
+ $form->{percent_skonto} =
+ $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
&payment_header;
AM->payment(\%myconfig, \%$form);
- $form->{callback} =
- "$form->{script}?action=list_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+ $form->{callback} = build_std_url("action=list_payment");
$callback = $form->escape($form->{callback});
$form->{title} = $locale->text('Payment Terms');
- @column_index = qw(description description_long terms_netto terms_skonto percent_skonto);
+ @column_index = qw(up down description description_long terms_netto
+ terms_skonto percent_skonto);
+ $column_header{up} =
+ qq|<th class="listheading" align="center" valign="center">|
+ . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
+ . qq|</th>|;
+ $column_header{down} =
+ qq|<th class="listheading" align="center" valign="center">|
+ . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
+ . qq|</th>|;
$column_header{description} =
qq|<th class=listheading>|
. $locale->text('Description')
</tr>
|;
+ my $swap_link = build_std_url("action=swap_payment_terms");
+
+ my $row = 0;
foreach $ref (@{ $form->{ALL} }) {
$i++;
<tr valign=top class=listrow$i>
|;
+ if ($row) {
+ my $pref = $form->{ALL}->[$row - 1];
+ $column_data{up} =
+ qq|<td align="center" valign="center">| .
+ qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
+ qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">| .
+ qq|</a></td>|;
+ } else {
+ $column_data{up} = qq|<td> </td>|;
+ }
+
+ if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
+ $column_data{down} = qq|<td> </td>|;
+ } else {
+ my $nref = $form->{ALL}->[$row + 1];
+ $column_data{down} =
+ qq|<td align="center" valign="center">| .
+ qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
+ qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">| .
+ qq|</a></td>|;
+ }
$column_data{description} =
- qq|<td><a href=$form->{script}?action=edit_payment&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
- $column_data{description_long} = qq|<td align=right>$ref->{description_long}</td>|;
+ qq|<td><a href="| .
+ build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
+ qq|">| . H($ref->{description}) . qq|</a></td>|;
+ $column_data{description_long} =
+ qq|<td align=right>| . H($ref->{description_long}) . qq|</td>|;
$column_data{terms_netto} =
qq|<td align=right>$ref->{terms_netto}</td>|;
$column_data{terms_skonto} =
qq|<td align=right>$ref->{terms_skonto}</td>|;
$column_data{percent_skonto} =
- qq|<td align=right>$ref->{percent_skonto} %</td>|;
+ qq|<td align=right>| .
+ $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
+ qq|%</td>|;
map { print "$column_data{$_}\n" } @column_index;
print qq|
</tr>
|;
+ $row++;
}
print qq|
sub save_payment {
$lxdebug->enter_sub();
- $form->isblank("description", $locale->text('Language missing!'));
+ $form->isblank("description", $locale->text('Description missing!'));
+ $form->{"percent_skonto"} =
+ $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
AM->save_payment(\%myconfig, \%$form);
$form->redirect($locale->text('Payment Terms saved!'));
$lxdebug->leave_sub();
}
+sub swap_payment_terms {
+ $lxdebug->enter_sub();
+
+ AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
+ list_payment();
+
+ $lxdebug->leave_sub();
+}
+
sub add_sic {
$lxdebug->enter_sub();
$lxdebug->leave_sub();
}
+sub build_std_url {
+ $lxdebug->enter_sub();
+
+ my $url = "$form->{script}?";
+ my $first = 1;
+ foreach my $key ((qw(login password path), @_)) {
+ next unless ($key);
+ $url .= "&" unless ($first);
+ $first = 0;
+
+ if ($key =~ /=/) {
+ $url .= $key;
+ } else {
+ $url .= "${key}=" . E($form->{$key});
+ }
+ }
+
+ $lxdebug->leave_sub();
+
+ return $url;
+}
+
sub select_employee {
$lxdebug->enter_sub();
return $form->quote($_[0]);
}
+sub E {
+ return $form->escape($_[0]);
+}
+
sub format_dates {
$lxdebug->enter_sub();
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'account_header' => 'account_header',
'audit_control' => 'audit_control',
'backup' => 'backup',
'buchungsgruppe_header' => 'buchungsgruppe_header',
+ 'build_std_url' => 'build_std_url',
'business_header' => 'business_header',
'calculate_qty' => 'calculate_qty',
'config' => 'config',
'set_unit_languages' => 'set_unit_languages',
'sic_header' => 'sic_header',
'swap_buchungsgruppen' => 'swap_buchungsgruppen',
+ 'swap_payment_terms' => 'swap_payment_terms',
'vendor_selection' => 'vendor_selection',
'warehouse_header' => 'warehouse_header',
'erfassen' => 'add',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'add_transaction' => 'add_transaction',
'ap_transaction' => 'ap_transaction',
'ar_transaction' => 'ar_transaction',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'check_name' => 'check_name',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'delivery_customer_selection' => 'delivery_customer_selection',
'employee_selection_internal' => 'employee_selection_internal',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'add_transaction' => 'add_transaction',
'ap_transaction' => 'ap_transaction',
'ar_transaction' => 'ar_transaction',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'check_name' => 'check_name',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'addtop100' => 'addtop100',
'assembly_row' => 'assembly_row',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'choice' => 'choice',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'customer_details' => 'customer_details',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'add_transaction' => 'add_transaction',
'ap_transaction' => 'ap_transaction',
'ar_transaction' => 'ar_transaction',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'check_name' => 'check_name',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'add_transaction' => 'add_transaction',
'ap_transaction' => 'ap_transaction',
'ar_transaction' => 'ar_transaction',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'check_name' => 'check_name',
};
$self->{subs} = {
+ 'E' => 'E',
'H' => 'H',
'Q' => 'Q',
'add' => 'add',
'ap_transaction' => 'ap_transaction',
'ar_transaction' => 'ar_transaction',
'backorder_exchangerate' => 'backorder_exchangerate',
+ 'build_std_url' => 'build_std_url',
'calculate_qty' => 'calculate_qty',
'check_form' => 'check_form',
'check_name' => 'check_name',
--- /dev/null
+-- @tag: payment_terms_sortkey
+-- @description: Neue Spalte für Sortierreihenfolge der Zahlungskonditionen
+-- @depends: release_2_4_1
+ALTER TABLE payment_terms ADD COLUMN sortkey integer;
+CREATE SEQUENCE tmp_counter;
+UPDATE payment_terms SET sortkey = nextval('tmp_counter');
+DROP SEQUENCE tmp_counter;
+ALTER TABLE payment_terms ALTER COLUMN sortkey SET NOT NULL;