Revision a462dc9c
Von Rolf Fluehmann vor mehr als 6 Jahren hinzugefügt
SL/Controller/Piece.pm | ||
---|---|---|
7 | 7 |
use SL::DB::Piece; |
8 | 8 |
use SL::Helper::Flash; |
9 | 9 |
|
10 |
use Rose::DateTime::Util qw(:all); |
|
10 | 11 |
use Rose::Object::MakeMethods::Generic ( |
11 | 12 |
'scalar --get_set_init' => [ qw( batch bin delivery_orders employee part piece vendor ) ], |
12 | 13 |
); |
13 | 14 |
|
14 | 15 |
my $may_edit = 1; |
16 |
Rose::DateTime::Util->european_dates( 1 ); |
|
15 | 17 |
|
16 | 18 |
__PACKAGE__->run_before( '_create', except => [ 'search', 'list' ] ); |
17 | 19 |
__PACKAGE__->run_before( '_load', only => [ 'delete', 'edit', 'save', 'save_and_close' ] ); |
... | ... | |
38 | 40 |
sub action_delete { |
39 | 41 |
my( $self, $form, $locale ) = ( shift, $::form, $::locale ); |
40 | 42 |
my( $action, @errors ) = ( '', () ); |
41 |
@errors = $self->piece->delete || push( @errors, $self->piece->db->error );
|
|
43 |
$self->piece->delete || push( @errors, $self->piece->db->error ); |
|
42 | 44 |
if( scalar @errors ) { |
43 | 45 |
flash_later( 'error', @errors ); |
44 | 46 |
$action = 'edit'; |
... | ... | |
66 | 68 |
$form->{ filter_rows }->{ producer_id } && $self->vendor( SL::DB::Vendor->new( id => $form->{ filter_rows }->{ producer_id } )->load ); |
67 | 69 |
$form->{ filter_rows }->{ part_id } && $self->part( SL::DB::Part->new( id => $form->{ filter_rows }->{ part_id } )->load ); |
68 | 70 |
$form->{ filter_rows }->{ batch_id } && $self->batch( SL::DB::Batch->new( id => $form->{ filter_rows }->{ batch_id } )->load ); |
69 |
$form->{ filter_rows }->{ employee_id_id } && $self->employee( SL::DB::Employee->new( id => $form->{ filter_rows }->{ employee_in_id } )->load ); |
|
70 |
$form->{ filter_rows }->{ employee_out_id } && $self->employee( SL::DB::Employee->new( id => $form->{ filter_rows }->{ employee_out_id } )->load ); |
|
71 |
$form->{ filter_rows }->{ delivery_in_id } && $self->delivery_orders( SL::DB::DeliveryOrder->new( id => $form->{ filter_rows }->{ delivery_in_id } )->load ); |
|
72 |
$form->{ filter_rows }->{ delivery_out_id } && $self->delivery_orders( SL::DB::DeliveryOrder->new( id => $form->{ filter_rows }->{ delivery_out_id } )->load ); |
|
73 |
$form->{ filter_rows }->{ employee_id } && $self->employee( SL::DB::Employee->new( id => $form->{ filter_rows }->{ employee_id } )->load ); |
|
71 | 74 |
|
72 | 75 |
$self->{ columns } = [ |
73 | 76 |
{ key => 'producer' , label => 'Producer' }, |
... | ... | |
86 | 89 |
$self->{ filter } = join( '&', |
87 | 90 |
map {'filter_columns.' . $_ . '=' . $self->{ filter_columns }->{ $_ } } keys %{ $self->{ filter_columns } } |
88 | 91 |
); |
89 |
my @filter = $self->_filter; |
|
92 |
my @filter = map { $_ = 'itime' if $_ eq 'insertdate'; $_ = 'mtime' if $_ eq 'changedate'; $_ } $self->_filter;
|
|
90 | 93 |
@{ $self->{ all_pieces } } = @{ SL::DB::Manager::Piece->get_all( where => \@filter ) } |
91 | 94 |
and $self->_sort( $self->{ sort_column } ); |
92 | 95 |
|
... | ... | |
101 | 104 |
sub action_save { |
102 | 105 |
my $self = shift; |
103 | 106 |
$self->_save; |
104 |
$self->_redirect_to( $self->{ callback } ne 'add' ? 'edit' : 'add' );
|
|
107 |
$self->_redirect_to( 'edit' );
|
|
105 | 108 |
} |
106 | 109 |
|
107 | 110 |
# save a new or edited piece and close the frame |
... | ... | |
119 | 122 |
%{ $self->{ filter_columns } } = (); |
120 | 123 |
%{ $self->{ filter_rows } } = (); |
121 | 124 |
$self->{ all_employees } = SL::DB::Manager::Employee->get_all( sort_by => 'name' ); |
125 |
$self->{ all_batches } = SL::DB::Manager::Batch->get_all( sort_by => 'batchnumber' ); |
|
126 |
$self->{ all_bins } = SL::DB::Manager::Bin->get_all( sort_by => 'description' ); |
|
127 |
$self->{ all_deliveries_in } = SL::DB::Manager::DeliveryOrder->get_all( where => [ vendor_id => { ne => 0 } ], sort_by => 'donumber' ); |
|
128 |
$self->{ all_deliveries_out } = SL::DB::Manager::DeliveryOrder->get_all( where => [ customer_id => { ne => 0 } ], sort_by => 'donumber' ); |
|
122 | 129 |
$self->_setup_search_action_bar; |
123 | 130 |
$self->render( |
124 | 131 |
'piece/search', |
... | ... | |
145 | 152 |
sub _filter { |
146 | 153 |
my( $self, $form ) = ( shift, $::form ); |
147 | 154 |
my @filter = ( deleted => 'false' ); |
155 |
my $filter_row = ''; |
|
148 | 156 |
foreach( keys %{ $self->{ filter_rows } } ) { |
149 |
if( $self->{ filter_rows }->{ $_ } ) { |
|
150 |
$_ =~ m/^.*?_from$/ and $_ =~ s/^(.*?)_from$/$1/ |
|
151 |
and push( @filter, ( $_ => { ge => $self->{ filter_rows }->{ $_ . '_from' } } ) ) |
|
152 |
and $self->{ filter } .= '&filter_rows.' . $_ . '_from' . '=' . $form->escape( $self->{ filter_rows }->{ $_ . '_from' } ) |
|
153 |
or $_ =~ m/^.*?_to$/ and $_ =~ s/^(.*?)_to$/$1/ |
|
154 |
and push( @filter, ( $_ => { le => $self->{ filter_rows }->{ $_ . '_to' } } ) ) |
|
157 |
$filter_row = $self->{ filter_rows }->{ $_ }; |
|
158 |
if( $filter_row ) { |
|
159 |
$_ =~ /^.*?_from$/ and $_ =~ s/^(.*?)_from$/$1/ |
|
160 |
and ( $_ =~ /^.*?date$/ and $filter_row = parse_date( $filter_row ) or 1 ) |
|
161 |
and push( @filter, ( $_ => { ge => $filter_row } ) ) |
|
162 |
and $self->{ filter } .= '&filter_rows.' . $_ . '_from' . '=' . $form->escape( $self->{ filter_rows }->{ $_ . '_from' } ) |
|
163 |
or $_ =~ /^.*?_to$/ and $_ =~ s/^(.*?)_to$/$1/ |
|
164 |
and ( $_ =~ /^.*?date$/ and $filter_row = parse_date( $filter_row )->add( days => 1 )->subtract( seconds => 1 ) or 1 ) |
|
165 |
and push( @filter, ( $_ => { le => $filter_row } ) ) |
|
155 | 166 |
and $self->{ filter } .= '&filter_rows.' . $_ . '_to' . '=' . $form->escape( $self->{ filter_rows }->{ $_ . '_to' } ) |
156 |
or $_ =~ m/^.*?_id$/
|
|
157 |
and push( @filter, ( $_ => $self->{ filter_rows }->{ $_ } ) )
|
|
158 |
and $self->{ filter } .= '&filter_rows.' . $_ . '=' . $form->escape( $self->{ filter_rows }->{ $_ } )
|
|
159 |
or push( @filter, ( $_ => { like => $self->{ filter_rows }->{ $_ } } ) )
|
|
160 |
and $self->{ filter } .= '&filter_rows.' . $_ . '=' . $form->escape( $self->{ filter_rows }->{ $_ } )
|
|
167 |
or $_ =~ /^.*?_id$/ |
|
168 |
and push( @filter, ( $_ => $filter_row ) )
|
|
169 |
and $self->{ filter } .= '&filter_rows.' . $_ . '=' . $form->escape( $filter_row )
|
|
170 |
or push( @filter, ( $_ => { like => $filter_row } ) )
|
|
171 |
and $self->{ filter } .= '&filter_rows.' . $_ . '=' . $form->escape( $filter_row )
|
|
161 | 172 |
; |
162 | 173 |
} |
163 | 174 |
} |
... | ... | |
194 | 205 |
] ], |
195 | 206 |
sort_by => 'batchnumber' |
196 | 207 |
); |
197 |
unshift( $self->{ all_batches }, undef ); |
|
208 |
@{ $self->{ all_batches } } = sort { |
|
209 |
$a->producer->name cmp $b->producer->name |
|
210 |
|| $a->part->partnumber cmp $b->part->partnumber |
|
211 |
|| $a->batchnumber cmp $b->batchnumber |
|
212 |
} @{ $self->{ all_batches } }; |
|
213 |
unshift( @{ $self->{ all_batches } }, undef ); |
|
198 | 214 |
$self->{ all_bins } = SL::DB::Manager::Bin->get_all( sort_by => 'description' ); |
199 |
unshift( $self->{ all_bins }, undef ); |
|
200 |
$self->{ all_deliveries } = SL::DB::Manager::DeliveryOrder->get_all( sort_by => 'donumber' ); |
|
215 |
unshift( @{ $self->{ all_bins } }, undef ); |
|
216 |
$self->{ all_deliveries_in } = SL::DB::Manager::DeliveryOrder->get_all(where => [ vendor_id => { ne => 0 } ], sort_by => 'donumber' ); |
|
217 |
unshift( @{ $self->{ all_deliveries_in } }, undef ); |
|
218 |
$self->{ all_deliveries_out } = SL::DB::Manager::DeliveryOrder->get_all(where => [ customer_id => { ne => 0 } ], sort_by => 'donumber' ); |
|
219 |
unshift( @{ $self->{ all_deliveries_out } }, undef ); |
|
201 | 220 |
$self->{ all_employees } = SL::DB::Manager::Employee->get_all( |
202 | 221 |
where => [ or => [ |
203 | 222 |
id => $self->piece->employee_id, |
... | ... | |
205 | 224 |
] ], |
206 | 225 |
sort_by => 'name' |
207 | 226 |
); |
227 |
$self->{current_employee_id} = SL::DB::Manager::Employee->current->id; |
|
208 | 228 |
} |
209 | 229 |
|
210 | 230 |
sub _redirect_to { |
... | ... | |
258 | 278 |
$a->weight cmp $b->weight |
259 | 279 |
} @{ $self->{ all_pieces } } |
260 | 280 |
or $column eq 'delivery_in' and @{ $self->{ all_pieces } } = sort { |
261 |
$a->delivery->donumber cmp $b->delivery_orders->donumber
|
|
281 |
$a->delivery_in->donumber cmp $b->delivery_in->donumber
|
|
262 | 282 |
} @{ $self->{ all_pieces } } |
263 | 283 |
or $column eq 'bin' and @{ $self->{ all_pieces } } = sort { |
264 | 284 |
$a->bin->description cmp $b->bin->description |
265 | 285 |
} @{ $self->{ all_pieces } } |
286 |
or $column eq 'delivery_out' and @{ $self->{ all_pieces } } = sort { |
|
287 |
$a->delivery_out->donumber cmp $b->delivery_out->donumber |
|
288 |
} @{ $self->{ all_pieces } } |
|
266 | 289 |
or $column eq 'insertdate' and @{ $self->{ all_pieces } } = sort { |
267 | 290 |
$a->itime cmp $b->itime |
268 | 291 |
|| $a->mtime cmp $b->mtime |
Auch abrufbar als: Unified diff
Anpassungen Datumsformat, Unterscheidung eingehende und ausgehende Lieferscheine, kleinere Anpassungen fuer die Chargen- und Exemplarverwaltung