use SL::DB::History;
use SL::DB::Helper::ValidateAssembly qw(validate_assembly);
use SL::CVar;
+use SL::MoreCommon qw(save_form);
use Carp;
use Rose::Object::MakeMethods::Generic (
$self->add;
};
+sub action_add_from_record {
+ my ($self) = @_;
+
+ check_has_valid_part_type($::form->{part}{part_type});
+
+ $self->parse_form;
+ $self->add;
+}
+
sub action_add {
my ($self) = @_;
flash_later('info', $is_new ? t8('The item has been created.') . " " . $self->part->displayable_name : t8('The item has been saved.'));
if ( $::form->{callback} ) {
- $self->redirect_to($::form->unescape($::form->{callback}));
+ $self->redirect_to($::form->unescape($::form->{callback}) . '&new_parts_id=' . $self->part->id);
+
} else {
# default behaviour after save: reload item, this also resets last_modification!
$self->redirect_to(controller => 'Part', action => 'edit', 'part.id' => $self->part->id);
}
sub new_item {
- $main::lxdebug->enter_sub();
+ _check_io_auth();
- my $form = $main::form;
- my %myconfig = %main::myconfig;
+ my $price = $::form->{vc} eq 'customer' ? 'sellprice_as_number' : 'lastcost_as_number';
+ my $previousform = $::auth->save_form_in_session;
+ my $callback = build_std_url("action=return_from_new_item", "previousform=$previousform");
+ my $i = $::form->{rowcount};
- _check_io_auth();
+ my @HIDDENS;
+ push @HIDDENS, { 'name' => 'callback', 'value' => $callback };
+ push @HIDDENS, map +{ 'name' => $_, 'value' => $::form->{$_} }, qw(rowcount vc);
+ push @HIDDENS, map +{ 'name' => "part.$_", 'value' => $::form->{"${_}_$i"} }, qw(partnumber description unit price_factor_id);
+ push @HIDDENS, { 'name' => "part.$price", 'value' => $::form->{"sellprice_$i"} };
+ push @HIDDENS, { 'name' => "part.notes", 'value' => $::form->{"longdescription_$i"} };
- my $price_key = ($form->{type} =~ m/request_quotation|purchase_order/) || ($form->{script} eq 'ir.pl') ? 'lastcost' : 'sellprice';
+ $::form->header;
+ print $::form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
+}
- # change callback
- $form->{old_callback} = $form->escape($form->{callback}, 1);
- $form->{callback} = $form->escape("$form->{script}?action=display_form", 1);
+sub return_from_new_item {
+ _check_io_auth();
- # save all form variables except action in the session and keep the key in the previousform variable
- my $previousform = $::auth->save_form_in_session(skip_keys => [ qw(action) ]);
+ my $part = SL::DB::Manager::Part->find_by(id => delete $::form->{new_parts_id}) or die 'can not find part that was just saved!';
- my @HIDDENS;
- push @HIDDENS, { 'name' => 'previousform', 'value' => $previousform };
- push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(rowcount vc);
- push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit);
- push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} };
- push @HIDDENS, { 'name' => $price_key, 'value' => $form->parse_amount(\%myconfig, $form->{"sellprice_$form->{rowcount}"}) };
- push @HIDDENS, { 'name' => 'notes', 'value' => $form->{"longdescription_$form->{rowcount}"} };
+ $::auth->restore_form_from_session(delete $::form->{previousform}, form => $::form);
- $form->header();
- print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
+ $::form->{"id_$::form->{rowcount}"} = $part->id;
- $main::lxdebug->leave_sub();
+ my $url = build_std_url("script=$::form->{script}", "RESTORE_FORM_FROM_SESSION_ID=" . $::auth->save_form_in_session);
+ print $::request->{cgi}->redirect($url);
}
sub check_form {
<p>
- <input class="radio" type="radio" name="part_type" value="part" checked> [% 'Part' | $T8 %]<br>
- <input class="radio" type="radio" name="part_type" value="assembly"> [% 'Assembly' | $T8 %]<br>
- <input class="radio" type="radio" name="part_type" value="service"> [% 'Service' | $T8 %]<br>
- <input class="radio" type="radio" name="part_type" value="assortment"> [% 'Assortment' | $T8 %]
+ <input class="radio" type="radio" name="part.part_type" value="part" checked> [% 'Part' | $T8 %]<br>
+ <input class="radio" type="radio" name="part.part_type" value="assembly"> [% 'Assembly' | $T8 %]<br>
+ <input class="radio" type="radio" name="part.part_type" value="service"> [% 'Service' | $T8 %]<br>
+ <input class="radio" type="radio" name="part.part_type" value="assortment"> [% 'Assortment' | $T8 %]
<p>
[%- FOREACH var = HIDDENS %]
</p>
<input type="hidden" name="action" value="Part/dispatch">
- <input class="submit" type="submit" name="action_add" value="[% 'Continue' | $T8 %]">
+ <input class="submit" type="submit" name="action_add_from_record" value="[% 'Continue' | $T8 %]">
[%- ELSE %]
</h4>
[%- END %]