Revision c77e88d3
Von Jan Büren vor fast 6 Jahren hinzugefügt
SL/DB/BankTransactionAccTrans.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::BankTransactionAccTrans; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use SL::DB::MetaSetup::BankTransactionAccTrans; |
|
9 |
use SL::DB::Manager::BankTransactionAccTrans; |
|
10 |
|
|
11 |
__PACKAGE__->meta->initialize; |
|
12 |
|
|
13 |
1; |
SL/DB/Helper/Mappings.pm | ||
---|---|---|
105 | 105 |
ap => 'purchase_invoice', |
106 | 106 |
bank_accounts => 'bank_account', |
107 | 107 |
bank_transactions => 'bank_transaction', |
108 |
bank_transaction_acc_trans => 'bank_transaction_acc_trans', |
|
108 | 109 |
buchungsgruppen => 'buchungsgruppe', |
109 | 110 |
bin => 'bin', |
110 | 111 |
business => 'business', |
SL/DB/Manager/BankTransactionAccTrans.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::Manager::BankTransactionAccTrans; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use parent qw(SL::DB::Helper::Manager); |
|
9 |
|
|
10 |
sub object_class { 'SL::DB::BankTransactionAccTrans' } |
|
11 |
|
|
12 |
__PACKAGE__->make_manager_methods; |
|
13 |
|
|
14 |
1; |
SL/DB/MetaSetup/BankTransactionAccTrans.pm | ||
---|---|---|
1 |
# This file has been auto-generated. Do not modify it; it will be overwritten |
|
2 |
# by rose_auto_create_model.pl automatically. |
|
3 |
package SL::DB::BankTransactionAccTrans; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use parent qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->table('bank_transaction_acc_trans'); |
|
10 |
|
|
11 |
__PACKAGE__->meta->columns( |
|
12 |
acc_trans_id => { type => 'bigint', not_null => 1 }, |
|
13 |
ap_id => { type => 'integer' }, |
|
14 |
ar_id => { type => 'integer' }, |
|
15 |
bank_transaction_id => { type => 'integer', not_null => 1 }, |
|
16 |
gl_id => { type => 'integer' }, |
|
17 |
id => { type => 'serial', not_null => 1 }, |
|
18 |
itime => { type => 'timestamp', default => 'now()' }, |
|
19 |
mtime => { type => 'timestamp' }, |
|
20 |
); |
|
21 |
|
|
22 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
|
23 |
|
|
24 |
__PACKAGE__->meta->allow_inline_column_values(1); |
|
25 |
|
|
26 |
__PACKAGE__->meta->foreign_keys( |
|
27 |
acc_transaction => { |
|
28 |
class => 'SL::DB::AccTransaction', |
|
29 |
key_columns => { acc_trans_id => 'acc_trans_id' }, |
|
30 |
}, |
|
31 |
|
|
32 |
ap => { |
|
33 |
class => 'SL::DB::PurchaseInvoice', |
|
34 |
key_columns => { ap_id => 'id' }, |
|
35 |
}, |
|
36 |
|
|
37 |
ar => { |
|
38 |
class => 'SL::DB::Invoice', |
|
39 |
key_columns => { ar_id => 'id' }, |
|
40 |
}, |
|
41 |
|
|
42 |
bank_transaction => { |
|
43 |
class => 'SL::DB::BankTransaction', |
|
44 |
key_columns => { bank_transaction_id => 'id' }, |
|
45 |
}, |
|
46 |
|
|
47 |
gl => { |
|
48 |
class => 'SL::DB::GLTransaction', |
|
49 |
key_columns => { gl_id => 'id' }, |
|
50 |
}, |
|
51 |
); |
|
52 |
|
|
53 |
1; |
|
54 |
; |
sql/Pg-upgrade2/record_links_bt_acc_trans.pl | ||
---|---|---|
1 |
# @tag: record_links_bt_acc_trans |
|
2 |
# @description: RecordLinks von bt nach acc_trans |
|
3 |
# @depends: release_3_5_3 |
|
4 |
package SL::DBUpgrade2::record_links_bt_acc_trans; |
|
5 |
|
|
6 |
use strict; |
|
7 |
use utf8; |
|
8 |
|
|
9 |
use parent qw(SL::DBUpgrade2::Base); |
|
10 |
|
|
11 |
use SL::DBUtils; |
|
12 |
use SL::RecordLinks; |
|
13 |
|
|
14 |
|
|
15 |
sub run { |
|
16 |
my ($self) = @_; |
|
17 |
|
|
18 |
my $query_table = |
|
19 |
qq| |
|
20 |
|
|
21 |
CREATE SEQUENCE bank_transaction_acc_trans_id_seq; |
|
22 |
CREATE TABLE bank_transaction_acc_trans ( |
|
23 |
id integer NOT NULL DEFAULT nextval('bank_transaction_acc_trans_id_seq'), |
|
24 |
bank_transaction_id integer NOT NULL, |
|
25 |
acc_trans_id bigint NOT NULL, |
|
26 |
ar_id integer, |
|
27 |
ap_id integer, |
|
28 |
gl_id integer, |
|
29 |
itime TIMESTAMP DEFAULT now(), |
|
30 |
mtime TIMESTAMP, |
|
31 |
PRIMARY KEY (bank_transaction_id, acc_trans_id), |
|
32 |
FOREIGN KEY (bank_transaction_id) REFERENCES bank_transactions (id), |
|
33 |
FOREIGN KEY (acc_trans_id) REFERENCES acc_trans (acc_trans_id), |
|
34 |
FOREIGN KEY (ar_id) REFERENCES ar (id), |
|
35 |
FOREIGN KEY (ap_id) REFERENCES ap (id), |
|
36 |
FOREIGN KEY (gl_id) REFERENCES gl (id));|; |
|
37 |
|
|
38 |
$self->db_query($query_table); |
|
39 |
|
|
40 |
|
|
41 |
my $query = qq|SELECT to_id, itime, from_id, to_table |
|
42 |
FROM record_links |
|
43 |
WHERE from_table='bank_transactions'|; |
|
44 |
|
|
45 |
my $sth = $self->dbh->prepare($query); |
|
46 |
|
|
47 |
my $sql = <<SQL; |
|
48 |
SELECT |
|
49 |
acc_trans_id |
|
50 |
FROM acc_trans |
|
51 |
WHERE trans_id = ? |
|
52 |
AND itime = ? |
|
53 |
AND (chart_link='AR' OR chart_link='AP' OR chart_link ilike '%paid%'); |
|
54 |
SQL |
|
55 |
|
|
56 |
my $sth_acc_trans_ids = $self->dbh->prepare($sql) or die $self->dbh->errstr; |
|
57 |
|
|
58 |
my $sql_insert = <<SQL; |
|
59 |
INSERT INTO bank_transaction_acc_trans (bank_transaction_id, acc_trans_id, ar_id, ap_id, gl_id) |
|
60 |
VALUES ( ?, ?, ?, ?, ?); |
|
61 |
SQL |
|
62 |
|
|
63 |
my $sth_insert = $self->dbh->prepare($sql_insert) or die $self->dbh->errstr; |
|
64 |
|
|
65 |
|
|
66 |
# get all current record links from bank to arap |
|
67 |
$sth->execute() or die $self->dbh->errstr; |
|
68 |
|
|
69 |
while (my $rl_ref = $sth->fetchrow_hashref("NAME_lc")) { |
|
70 |
|
|
71 |
# get all concurrent acc_trans entries (payment) for this transaction |
|
72 |
$sth_acc_trans_ids->execute($rl_ref->{to_id}, $rl_ref->{itime}) or die $self->dbh->errstr; |
|
73 |
while (my $ac_ref = $sth_acc_trans_ids->fetchrow_hashref("NAME_lc")) { |
|
74 |
my $ar_id = $rl_ref->{to_table} eq 'ar' ? $rl_ref->{to_id} : undef; |
|
75 |
my $ap_id = $rl_ref->{to_table} eq 'ap' ? $rl_ref->{to_id} : undef; |
|
76 |
my $gl_id = $rl_ref->{to_table} eq 'gl' ? $rl_ref->{to_id} : undef; |
|
77 |
$sth_insert->execute($rl_ref->{from_id},$ac_ref->{acc_trans_id}, |
|
78 |
$ar_id, $ap_id, $gl_id) or die $self->dbh->errstr; |
|
79 |
} |
|
80 |
} |
|
81 |
return 1; |
|
82 |
} |
|
83 |
|
|
84 |
1; |
Auch abrufbar als: Unified diff
Neue Helper-Tabelle SL/DB/BankTransactionAccTrans.pm
Hintergrund: Verbuchte Bankbewegungen sind nur über
einen löschbaren RecordLink aktuell zuordenbar.
Das macht ein verlässliche Aussage über die Verbuchungen
der Bankbewegung schwierig. Besser wäre es eine
Tabelle reconciliation_links direkt bei der Verbuchung zu füllen
und die gesetzten Constraints so zu lassen (ER-Fehler mit
aussagekräftigerer Fehlerwarnung an den Nutzer) ....
Da die Bankverbuchungen seit 66d468b09 (2016) in einer
Transaktion laufen, wird über record_link und itime eine
Rekonstruktion der Zusammenhänge für die alten Einträge versucht herzustellen.
Wichtig: Dieser Commit ist Vorbedingung für das Neuverbuchen
von importierten Bankbewegungen. Zusätzlich beißt sich das mit
der Anforderung das Zahlungen manuell vom Anwender geändert werden
können (s.a. hierzu c923fff436).