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