Revision 4ee71121
Von Rolf Fluehmann vor etwa 6 Jahren hinzugefügt
SL/DB/Manager/Piece.pm | ||
---|---|---|
1 |
package SL::DB::Manager::Piece; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use base qw(SL::DB::Helper::Manager); |
|
6 |
|
|
7 |
sub object_class { 'SL::DB::Piece' } |
|
8 |
|
|
9 |
__PACKAGE__->make_manager_methods; |
|
10 |
|
|
11 |
1; |
SL/DB/MetaSetup/Piece.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::Piece; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use parent qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->table('pieces'); |
|
10 |
|
|
11 |
__PACKAGE__->meta->columns( |
|
12 |
batch_id => { type => 'integer' }, |
|
13 |
bin_id => { type => 'integer' }, |
|
14 |
deleted => { type => 'boolean', not_null => 1, default => 'false' }, |
|
15 |
delivery_in_id => { type => 'integer' }, |
|
16 |
delivery_out_id => { type => 'integer' }, |
|
17 |
employee_id => { type => 'integer' }, |
|
18 |
id => { type => 'integer', not_null => 1, sequence => 'id' }, |
|
19 |
itime => { type => 'timestamp', not_null => 1, default => 'now()' }, |
|
20 |
mtime => { type => 'timestamp' }, |
|
21 |
notes => { type => 'text' }, |
|
22 |
serialnumber => { type => 'text', not_null => 1 }, |
|
23 |
part_id => { type => 'integer', not_null => 1 }, |
|
24 |
producer_id => { type => 'integer', not_null => 1 }, |
|
25 |
weight => { type => 'numeric', precision => 15, scale => 5 }, |
|
26 |
); |
|
27 |
|
|
28 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
|
29 |
|
|
30 |
__PACKAGE__->meta->add_unique_key( Rose::DB::Object::Metadata::UniqueKey->new( |
|
31 |
columns => [ 'producer_id', 'part_id', 'batch_id', 'serialnumber' ] |
|
32 |
)); |
|
33 |
|
|
34 |
__PACKAGE__->meta->allow_inline_column_values(1); |
|
35 |
|
|
36 |
__PACKAGE__->meta->foreign_keys( |
|
37 |
bin => { |
|
38 |
class => 'SL::DB::Bin', |
|
39 |
key_columns => { bin_id => 'id' }, |
|
40 |
}, |
|
41 |
batch => { |
|
42 |
class => 'SL::DB::Batch', |
|
43 |
key_columns => { batch_id => 'id' }, |
|
44 |
}, |
|
45 |
delivery_in => { |
|
46 |
class => 'SL::DB::DeliveryOrder', |
|
47 |
key_columns => { delivery_in_id => 'id' }, |
|
48 |
}, |
|
49 |
delivery_out => { |
|
50 |
class => 'SL::DB::DeliveryOrder', |
|
51 |
key_columns => { delivery_out_id => 'id' }, |
|
52 |
}, |
|
53 |
employee => { |
|
54 |
class => 'SL::DB::Employee', |
|
55 |
key_columns => { employee_id => 'id' }, |
|
56 |
}, |
|
57 |
part => { |
|
58 |
class => 'SL::DB::Part', |
|
59 |
key_columns => { part_id => 'id' }, |
|
60 |
}, |
|
61 |
producer => { |
|
62 |
class => 'SL::DB::Vendor', |
|
63 |
key_columns => { producer_id => 'id' }, |
|
64 |
}, |
|
65 |
); |
|
66 |
|
|
67 |
1; |
|
68 |
; |
SL/DB/Piece.pm | ||
---|---|---|
1 |
package SL::DB::Piece; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::DB::MetaSetup::Piece; |
|
6 |
use SL::DB::Manager::Piece; |
|
7 |
|
|
8 |
__PACKAGE__->meta->initialize; |
|
9 |
__PACKAGE__->before_save('_before_save_set_serialnumber'); |
|
10 |
|
|
11 |
sub _before_save_set_serialnumber { |
|
12 |
my $self = shift; |
|
13 |
$self->create_trans_number if !$self->serialnumber; |
|
14 |
return 1; |
|
15 |
} |
|
16 |
|
|
17 |
sub displayable_name { |
|
18 |
my $self = shift; |
|
19 |
return $self->batch_id |
|
20 |
? join '/', grep $_, $self->producer->displayable_name, $self->part->displayable_name, $self->batch->batchnumber, $self->serialnumber |
|
21 |
: join '/', grep $_, $self->producer->displayable_name, $self->part->displayable_name, $self->serialnumber |
|
22 |
; |
|
23 |
} |
|
24 |
|
|
25 |
sub last_modification { |
|
26 |
my ($self) = @_; |
|
27 |
return $self->mtime // $self->itime; |
|
28 |
} |
|
29 |
|
|
30 |
sub validate { |
|
31 |
my( $self, $locale ) = ( shift, $::locale ); |
|
32 |
my @errors = (); |
|
33 |
$self->producer_id || push @errors, $locale->text( 'The producer is missing.' ); |
|
34 |
$self->part_id || push @errors, $locale->text( 'The part is missing.' ); |
|
35 |
$self->serialnumber || push @errors, $locale->text( 'The serial number is missing.' ); |
|
36 |
scalar @errors && return @errors; |
|
37 |
SL::DB::Manager::Vendor->get_all_count( where => [ id => $self->producer_id ] ) || push @errors, $locale->text( "This producer dosn't exist." ); |
|
38 |
SL::DB::Manager::Part->get_all_count( where => [ id => $self->part_id ] ) || push @errors, $locale->text( "This part dosn't exist." ); |
|
39 |
if( $self->batch_id ) { |
|
40 |
SL::DB::Manager::Batch->get_all_count( where => [ id => $self->batch_id ] ) || push @errors, $locale->text( "This batch dosn't exist." ); |
|
41 |
SL::DB::Manager::Batch->get_all_count( where => [ |
|
42 |
id => $self->batch_id, |
|
43 |
producer_id => $self->producer_id, |
|
44 |
part_id => $self->part_id |
|
45 |
] |
|
46 |
) || push @errors, $locale->text( "This producer/part/batch doesn't exist." ); |
|
47 |
} |
|
48 |
scalar @errors && return @errors; |
|
49 |
unless( $self->id ) { |
|
50 |
unless( $self->batch_id ) { |
|
51 |
SL::DB::Manager::Piece->get_all_count( |
|
52 |
where => [ |
|
53 |
producer_id => $self->producer_id, |
|
54 |
part_id => $self->part_id, |
|
55 |
serialnumber => $self->serialnumber |
|
56 |
] |
|
57 |
) && push @errors, $locale->text( 'This producer/part/batch/serial number already does exist.' ); |
|
58 |
} else { |
|
59 |
SL::DB::Manager::Piece->get_all_count( |
|
60 |
where => [ |
|
61 |
producer_id => $self->producer_id, |
|
62 |
part_id => $self->part_id, |
|
63 |
batch_id => $self->batch_id, |
|
64 |
serialnumber => $self->serialnumber |
|
65 |
] |
|
66 |
) && push @errors, $locale->text( 'This producer/part/batch/serial number already does exist.' ); |
|
67 |
} |
|
68 |
} else { |
|
69 |
unless( $self->batch_id ) { |
|
70 |
SL::DB::Manager::Piece->get_all_count( |
|
71 |
where => [ |
|
72 |
id => { ne => $self->id }, |
|
73 |
producer_id => $self->producer_id, |
|
74 |
part_id => $self->part_id, |
|
75 |
serialnumber => $self->serialnumber |
|
76 |
] |
|
77 |
) && push @errors, $locale->text( 'This producer/part/batch/serial number already does exist.' ); |
|
78 |
} else { |
|
79 |
SL::DB::Manager::Piece->get_all_count( |
|
80 |
where => [ |
|
81 |
id => { ne => $self->id }, |
|
82 |
producer_id => $self->producer_id, |
|
83 |
part_id => $self->part_id, |
|
84 |
batch_id => $self->batch_id, |
|
85 |
serialnumber => $self->serialnumber |
|
86 |
] |
|
87 |
) && push @errors, $locale->text( 'This producer/part/batch/serial number already does exist.' ); |
|
88 |
} |
|
89 |
} |
|
90 |
return @errors; |
|
91 |
} |
|
92 |
|
|
93 |
sub undefine { |
|
94 |
my $self = shift; |
|
95 |
$self->batch_id || $self->batch_id( undef ); |
|
96 |
$self->weight || $self->weight( undef ); |
|
97 |
$self->delivery_in_id || $self->delivery_in_id( undef ); |
|
98 |
$self->bin_id || $self->bin_id( undef ); |
|
99 |
$self->delivery_out_id || $self->delivery_out_id( undef ); |
|
100 |
} |
|
101 |
|
|
102 |
1; |
|
103 |
|
|
104 |
__END__ |
|
105 |
|
|
106 |
=pod |
|
107 |
|
|
108 |
=encoding utf-8 |
|
109 |
|
|
110 |
=head1 NAME |
|
111 |
|
|
112 |
SL::DB::Piece: Model for the table 'pieces' |
|
113 |
|
|
114 |
=head1 SYNOPSIS |
|
115 |
|
|
116 |
This is a standard Rose::DB::Object based model and can be used as one. |
|
117 |
|
|
118 |
=head1 TYPES |
|
119 |
|
|
120 |
None |
|
121 |
|
|
122 |
=head1 FUNCTIONS |
|
123 |
|
|
124 |
=over 4 |
|
125 |
|
|
126 |
=item C<displayable_name> |
|
127 |
|
|
128 |
Returns the composed unique name to display. |
|
129 |
|
|
130 |
=item C<last_modification> |
|
131 |
|
|
132 |
Returns the datetime of the last modification. |
|
133 |
|
|
134 |
=item C<undefine> |
|
135 |
|
|
136 |
Sets the empty strings of numeric fields to undefine. |
|
137 |
|
|
138 |
=item C<validate> |
|
139 |
|
|
140 |
Returns the error messages if this batch doesn,t fullfill the constrains. |
|
141 |
|
|
142 |
=back |
|
143 |
|
|
144 |
=head1 AUTHORS |
|
145 |
|
|
146 |
Rolf Flühmann E<lt>rolf.fluehmann@revamp-it.chE<gt>, |
|
147 |
ROlf Flühmann E<lt>rolf_fluehmann@gmx.chE<gt> |
|
148 |
|
|
149 |
=cut |
sql/Pg-upgrade2/create_pieces.sql | ||
---|---|---|
1 |
-- @tag: create_pieces |
|
2 |
-- @description: neue Tabelle für Exemplare einer Produktionseinheit |
|
3 |
-- @depends: release_3_5_0 defaults_add_feature_production create_batches |
|
4 |
|
|
5 |
CREATE TABLE pieces ( |
|
6 |
id SERIAL PRIMARY KEY, |
|
7 |
itime TIMESTAMP NOT NULL DEFAULT now(), |
|
8 |
mtime TIMESTAMP, |
|
9 |
deleted BOOLEAN NOT NULL DEFAULT FALSE, |
|
10 |
serialnumber TEXT NOT NULL, |
|
11 |
weight REAL, |
|
12 |
notes TEXT, |
|
13 |
|
|
14 |
producer_id integer NOT NULL REFERENCES vendor (id) ON DELETE RESTRICT, |
|
15 |
part_id integer NOT NULL REFERENCES parts (id) ON DELETE RESTRICT, |
|
16 |
batch_id integer REFERENCES batches (id) ON DELETE RESTRICT, |
|
17 |
delivery_in_id integer REFERENCES delivery_orders (id) ON DELETE RESTRICT, |
|
18 |
delivery_out_id integer REFERENCES delivery_orders (id) ON DELETE RESTRICT, |
|
19 |
bin_id integer REFERENCES bin (id) ON DELETE RESTRICT, |
|
20 |
employee_id integer REFERENCES employee (id) ON DELETE SET NULL, |
|
21 |
|
|
22 |
UNIQUE (producer_id, part_id, batch_id, serialnumber) |
|
23 |
); |
|
24 |
|
|
25 |
CREATE TRIGGER mtime_pieces BEFORE UPDATE ON pieces FOR EACH ROW EXECUTE PROCEDURE set_mtime(); |
Auch abrufbar als: Unified diff
new model for production piece management