From 85049c3ccc1fbebf62753151ed3b4634607b4b23 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Mon, 9 Jun 2014 14:07:11 +0200 Subject: [PATCH] MT#5879 Rework invoice-relevant tables. --- lib/NGCP/Schema/Result/billing_profiles.pm | 4 ---- lib/NGCP/Schema/Result/contracts.pm | 11 +++++++++ lib/NGCP/Schema/Result/invoices.pm | 26 ++++++++++++++++++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/NGCP/Schema/Result/billing_profiles.pm b/lib/NGCP/Schema/Result/billing_profiles.pm index e93133f5..122acd06 100644 --- a/lib/NGCP/Schema/Result/billing_profiles.pm +++ b/lib/NGCP/Schema/Result/billing_profiles.pm @@ -63,10 +63,6 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 1, size => 255 }, "currency", { data_type => "varchar", is_nullable => 1, size => 31 }, - "vat_rate", - { data_type => "tinyint", extra => { unsigned => 1 }, is_nullable => 1 }, - "vat_included", - { data_type => "tinyint", default_value => 1, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); diff --git a/lib/NGCP/Schema/Result/contracts.pm b/lib/NGCP/Schema/Result/contracts.pm index 18e7089d..2eb02fb0 100644 --- a/lib/NGCP/Schema/Result/contracts.pm +++ b/lib/NGCP/Schema/Result/contracts.pm @@ -92,6 +92,10 @@ __PACKAGE__->add_columns( extra => { unsigned => 1 }, is_nullable => 1, }, + "vat_rate", + { data_type => "tinyint", extra => { unsigned => 1 }, default_value => 0, is_nullable => 0 }, + "add_vat", + { data_type => "tinyint", extra => { unsigned => 1 }, default_value => 0, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); @@ -195,6 +199,13 @@ __PACKAGE__->belongs_to( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "invoices", + "NGCP::Schema::Result::invoices", + { "foreign.contract_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/invoices.pm b/lib/NGCP/Schema/Result/invoices.pm index 3c97eb79..38c69480 100644 --- a/lib/NGCP/Schema/Result/invoices.pm +++ b/lib/NGCP/Schema/Result/invoices.pm @@ -16,12 +16,27 @@ __PACKAGE__->add_columns( is_auto_increment => 1, is_nullable => 0, }, + "contract_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 0, + }, "serial", { data_type => "varchar", is_nullable => 0, size => 32 }, "period_start", - { data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0 }, + { + data_type => "datetime", + datetime_undef_if_invalid => 1, + is_nullable => 0, + }, "period_end", - { data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0 }, + { + data_type => "datetime", + datetime_undef_if_invalid => 1, + is_nullable => 0, + }, "amount_net", { data_type => "double precision", default_value => 0, is_nullable => 0 }, "amount_vat", @@ -36,6 +51,13 @@ __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("serial_idx", ["serial"]); +__PACKAGE__->belongs_to( + "contract", + "NGCP::Schema::Result::contracts", + { id => "contract_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + sub TO_JSON { my ($self) = @_; return {