added ORM api and some tests
This commit is contained in:
34
TrsrDB/Account.pm
Normal file
34
TrsrDB/Account.pm
Normal file
@@ -0,0 +1,34 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::Account;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('Account');
|
||||
__PACKAGE__->add_columns(qw/ID type altId IBAN/);
|
||||
__PACKAGE__->set_primary_key('ID');
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
statement_rows => 'TrsrDB::ReconstructedBankStatement',
|
||||
{ 'foreign.account' => 'self.ID' }
|
||||
);
|
||||
__PACKAGE__->has_many(
|
||||
debts => 'TrsrDB::Debit',
|
||||
{ 'foreign.debtor' => 'self.ID' }
|
||||
);
|
||||
__PACKAGE__->has_many(
|
||||
current_debts => 'TrsrDB::CurrentDebts',
|
||||
{ 'foreign.debtor' => 'self.ID' }
|
||||
);
|
||||
__PACKAGE__->has_many(
|
||||
credits => 'TrsrDB::Credit',
|
||||
{ 'foreign.account' => 'self.ID' }
|
||||
);
|
||||
__PACKAGE__->has_many(
|
||||
available_credits => 'TrsrDB::AvailableCredits',
|
||||
{ 'foreign.account' => 'self.ID' }
|
||||
);
|
||||
__PACKAGE__->has_one(
|
||||
balance => 'TrsrDB::Balance', 'ID'
|
||||
);
|
||||
|
||||
1;
|
||||
19
TrsrDB/AvailableCredits.pm
Normal file
19
TrsrDB/AvailableCredits.pm
Normal file
@@ -0,0 +1,19 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::AvailableCredits;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('AvailableCredits');
|
||||
__PACKAGE__->add_columns(qw/ Id account date purpose difference /);
|
||||
__PACKAGE__->set_primary_key("Id");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
{ 'foreign.ID' => 'self.account' }
|
||||
);
|
||||
|
||||
__PACKAGE__->many_to_many(
|
||||
suggested_to_pay => account => 'current_debts'
|
||||
);
|
||||
|
||||
1;
|
||||
14
TrsrDB/Balance.pm
Normal file
14
TrsrDB/Balance.pm
Normal file
@@ -0,0 +1,14 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::Balance;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table("Balance");
|
||||
__PACKAGE__->add_columns(qw/ID credit promised debt/);
|
||||
__PACKAGE__->set_primary_key("ID");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account', 'ID'
|
||||
);
|
||||
|
||||
1;
|
||||
29
TrsrDB/Credit.pm
Normal file
29
TrsrDB/Credit.pm
Normal file
@@ -0,0 +1,29 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::Credit;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('Credit');
|
||||
__PACKAGE__->add_column("Id" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("account");
|
||||
__PACKAGE__->add_column("date" => { data_type => 'DATE' });
|
||||
__PACKAGE__->add_column("purpose");
|
||||
__PACKAGE__->add_column("value" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("spent" => { data_type => 'INTEGER', default => 0 });
|
||||
__PACKAGE__->set_primary_key("Id");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
{ 'foreign.ID' => 'self.account' }
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
outgoings => 'TrsrDB::Transfer',
|
||||
{ 'foreign.fromCredit' => 'self.Id' }
|
||||
);
|
||||
|
||||
__PACKAGE__->many_to_many(
|
||||
paid_bills => 'outgoings' => 'debit'
|
||||
);
|
||||
|
||||
1;
|
||||
19
TrsrDB/CurrentDebts.pm
Normal file
19
TrsrDB/CurrentDebts.pm
Normal file
@@ -0,0 +1,19 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::CurrentDebts;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('CurrentDebts');
|
||||
__PACKAGE__->add_columns(qw/billId debtor targetCredit date purpose difference/);
|
||||
__PACKAGE__->set_primary_key("billId");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
{ 'foreign.ID' => 'self.account' }
|
||||
);
|
||||
|
||||
__PACKAGE__->many_to_many(
|
||||
payable_with => account => 'available_credits'
|
||||
);
|
||||
|
||||
1;
|
||||
29
TrsrDB/Debit.pm
Normal file
29
TrsrDB/Debit.pm
Normal file
@@ -0,0 +1,29 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::Debit;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('Debit');
|
||||
__PACKAGE__->add_column("billId");
|
||||
__PACKAGE__->add_column("debtor");
|
||||
__PACKAGE__->add_column("targetCredit" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("date" => { data_type => 'DATE' });
|
||||
__PACKAGE__->add_column("purpose");
|
||||
__PACKAGE__->add_column("value" => { data_type => 'INTEGER' });
|
||||
__PACKAGE__->add_column("paid" => { data_type => 'INTEGER', default => 0 });
|
||||
__PACKAGE__->set_primary_key("billId");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
{ 'foreign.ID' => 'self.debtor' }
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
incomings => 'TrsrDB::Transfer', 'billId'
|
||||
);
|
||||
|
||||
__PACKAGE__->many_to_many(
|
||||
paid_with => incomings => 'credit'
|
||||
);
|
||||
|
||||
1;
|
||||
14
TrsrDB/History.pm
Normal file
14
TrsrDB/History.pm
Normal file
@@ -0,0 +1,14 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::History;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('History');
|
||||
__PACKAGE__->add_columns(qw/date purpose account credit debit contra billId/);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
account => 'TrsrDB::Account',
|
||||
{ 'foreign.ID' => 'self.account' }
|
||||
);
|
||||
|
||||
1;
|
||||
9
TrsrDB/ReconstructedBankStatement.pm
Normal file
9
TrsrDB/ReconstructedBankStatement.pm
Normal file
@@ -0,0 +1,9 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::ReconstructedBankStatement;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('ReconstructedBankStatement');
|
||||
__PACKAGE__->add_columns(qw/date purpose account credit debit/);
|
||||
|
||||
1;
|
||||
22
TrsrDB/Transfer.pm
Normal file
22
TrsrDB/Transfer.pm
Normal file
@@ -0,0 +1,22 @@
|
||||
use strict;
|
||||
|
||||
package TrsrDB::Transfer;
|
||||
use base qw/DBIx::Class::Core/;
|
||||
|
||||
__PACKAGE__->table('Transfer');
|
||||
__PACKAGE__->add_column("timestamp" => { data_type => 'TIMESTAMP' });
|
||||
__PACKAGE__->add_column("billId");
|
||||
__PACKAGE__->add_column("fromCredit");
|
||||
__PACKAGE__->add_column("amount" => { data_type => 'INTEGER', nullable => 1 });
|
||||
__PACKAGE__->set_primary_key("billId", "fromCredit");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
credit => 'TrsrDB::Credit',
|
||||
{ 'foreign.Id' => 'self.fromCredit' }
|
||||
);
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
debit => 'TrsrDB::Credit', 'billId'
|
||||
);
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user