Revision 0e7a8b0c
Von Jan Büren vor etwa 2 Jahren hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
@{ CVar->get_configs() };
|
||
|
||
$::form->{"cvar_" . $_->{name} . "_valid"} = 1 for @default_valid_configs;
|
||
} else {
|
||
$::form->{lastcost_modified} = $self->check_lastcost_modified;
|
||
}
|
||
|
||
# $self->part has been loaded, parsed and validated without errors and is ready to be saved
|
||
... | ... | |
|
||
}
|
||
|
||
sub check_lastcost_modified {
|
||
my ($self) = @_;
|
||
|
||
return abs($self->part->lastcost - $self->part->last_price_update->lastcost) < 0.009 ? undef : 1;
|
||
}
|
||
|
||
sub parse_form {
|
||
my ($self, %params) = @_;
|
||
|
SL/DB/Part.pm | ||
---|---|---|
|
||
__PACKAGE__->before_save('_before_save_set_partnumber');
|
||
__PACKAGE__->before_save('_before_save_set_assembly_weight');
|
||
__PACKAGE__->after_save('_set_lastcost_assemblies_and_assortiments');
|
||
|
||
sub _before_save_set_partnumber {
|
||
my ($self) = @_;
|
||
... | ... | |
sum map { $_->linetotal_weight} @{$self->items};
|
||
};
|
||
|
||
sub _set_lastcost_assemblies_and_assortiments {
|
||
my ($self) = @_;
|
||
|
||
return 1 unless $self->lastcost; # not saved yet
|
||
return 1 unless $::form->{lastcost_modified};
|
||
|
||
# 1. check all
|
||
my $assortments = SL::DB::Manager::AssortmentItem->get_all(where => [parts_id => $self->id ]);
|
||
my $assemblies = SL::DB::Manager::Assembly->get_all( where => [parts_id => $self->id ]);
|
||
|
||
foreach my $assembly (@{ $assemblies }) {
|
||
next unless ref $assembly eq 'SL::DB::Assembly';
|
||
my $a = SL::DB::Part->load_cached($assembly->id);
|
||
$a->update_attributes(lastcost => $a->items_lastcost_sum);
|
||
}
|
||
foreach my $assortment (@{ $assortments }) {
|
||
next unless ref $assortment eq 'SL::DB::AssortmentItem';
|
||
my $a = SL::DB::Part->load_cached($assortment->assortment_id);
|
||
$a->update_attributes(lastcost => $a->items_lastcost_sum);
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
1;
|
||
|
||
__END__
|
SL/IR.pm | ||
---|---|---|
# update parts table by setting lastcost to current price, don't allow negative values by using abs
|
||
# maybe allow only 2 decimal places -> rounding error with fx can be too huge for datev checks
|
||
# @values = ($form->round_amount(abs($fxsellprice * $form->{exchangerate} / $basefactor), 2), conv_i($form->{"id_$i"}));
|
||
$query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
|
||
@values = (abs($fxsellprice * $form->{exchangerate} / $basefactor), conv_i($form->{"id_$i"}));
|
||
do_query($form, $dbh, $query, @values);
|
||
#$query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
|
||
#@values = (abs($fxsellprice * $form->{exchangerate} / $basefactor), conv_i($form->{"id_$i"}));
|
||
#do_query($form, $dbh, $query, @values);
|
||
# after_save hook changes lastcost for all assemblies and assortments recursively
|
||
$::form->{lastcost_modified} = 1;
|
||
my $a = SL::DB::Part->load_cached(conv_i($form->{"id_$i"}));
|
||
$a->update_attributes(lastcost => abs($fxsellprice * $form->{exchangerate} / $basefactor));
|
||
|
||
|
||
# check if we sold the item already and
|
||
# make an entry for the expense and inventory
|
Auch abrufbar als: Unified diff
Einkaufspreis von Erzeugnissen/Sortimententen aktualisieren (rekursiv)
Falls sich ein einzelner Bestandteil verändert. Läuft über alle
weiter verbauten Teile durch Aufruf von Parts::after_save.
Benötigt einen boolean Parameter in $::form->{lastcost_modified}, damit
nicht bei jedem Speichern des Artikels ohne Veränderung des EK-Preises
die Rekursion losgetreten wird. Beachtet auch die Veränderungsroutine
innerhalb des EK-Rechnungscodes.