From aa621305b7aedd630f48ddc7babe46b2628f036e Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Tue, 25 Feb 2014 16:13:00 +0100 Subject: [PATCH] MT#5879 Added schema class for invoice_template to make possible save/use customer templates --- lib/NGCP/Schema/Result/invoice_template.pm | 155 +++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 lib/NGCP/Schema/Result/invoice_template.pm diff --git a/lib/NGCP/Schema/Result/invoice_template.pm b/lib/NGCP/Schema/Result/invoice_template.pm new file mode 100644 index 00000000..2c020e92 --- /dev/null +++ b/lib/NGCP/Schema/Result/invoice_template.pm @@ -0,0 +1,155 @@ +package NGCP::Schema::Result::invoice_template; +use Scalar::Util qw(blessed); +use parent 'DBIx::Class::Core'; + +our $VERSION = '2.009'; + +__PACKAGE__->load_components("InflateColumn::DateTime", "Helper::Row::ToJSON"); + + +__PACKAGE__->table("billing.invoice_template"); + + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_auto_increment => 1, + is_nullable => 0, + }, + "reseller_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_foreign_key => 1, + is_nullable => 0, + }, + "type", + { + data_type => "enum", + default_value => "svg", + extra => { list => ["svg", "html"] }, + is_nullable => 0, + }, + "is_active", + { data_type => "tinyint", default_value => 0, is_nullable => 0 }, + "base64_saved", + { data_type => "mediumblob", is_nullable => 1 }, + "base64_previewed", + { data_type => "mediumblob", is_nullable => 1 }, +); + + +__PACKAGE__->set_primary_key("id"); + + +__PACKAGE__->add_unique_constraint( + "invoice_template_reseller_active_UNIQUE", + ["reseller_id", "is_active"], +); + + +__PACKAGE__->belongs_to( + "reseller", + "NGCP::Schema::Result::contacts", + { id => "reseller_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} +=encoding UTF-8 + +=head1 NAME + +NGCP::Schema::Result::invoice_template + +=head1 COMPONENTS LOADED + +=over 4 + +=item * L + +=item * L + +=back + +=head1 TABLE: C + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + extra: {unsigned => 1} + is_auto_increment: 1 + is_nullable: 0 + +=head2 reseller_id + + data_type: 'integer' + extra: {unsigned => 1} + is_foreign_key: 1 + is_nullable: 0 + +=head2 type + + data_type: 'enum' + default_value: 'svg' + extra: {list => ["svg","html"]} + is_nullable: 0 + +=head2 is_active + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + +=head2 base64_saved + + data_type: 'mediumblob' + is_nullable: 1 + +=head2 base64_previewed + + data_type: 'mediumblob' + is_nullable: 1 + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=item * L + +=back + +=head1 RELATIONS + +=head2 reseller + +Type: belongs_to + +Related object: L + +=cut + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +__PACKAGE__->meta->make_immutable; +1;