-sub update {
- $lxdebug->enter_sub();
-
- if ($form->{item} eq "assembly") {
- my $i = $form->{assembly_rows};
-
- # if last row is empty check the form otherwise retrieve item
- if ( ($form->{"partnumber_$i"} eq "")
- && ($form->{"description_$i"} eq "")
- && ($form->{"partsgroup_$i"} eq "")) {
-
- &check_form;
-
- } else {
-
- IC->assembly_item(\%myconfig, \%$form);
-
- my $rows = scalar @{ $form->{item_list} };
-
- if ($rows) {
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
- if ($rows > 1) {
- $form->{makemodel_rows}--;
- &select_item;
- exit;
- } else {
- map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
- qw(partnumber description unit partsgroup);
- map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
- keys %{ $form->{item_list}[0] };
- $form->{"runningnumber_$i"} = $form->{assembly_rows};
- $form->{assembly_rows}++;
-
- &check_form;
-
- }
-
- } else {
-
- $form->{rowcount} = $i;
- $form->{assembly_rows}++;
-
- &new_item;
-
- }
- }
-
- } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
- &check_form;
- }
-
- $lxdebug->leave_sub();
-}
-
-sub save {
- $lxdebug->enter_sub();
-
- $auth->assert('part_service_assembly_edit');
-
- my ($parts_id, %newform, $previousform, $amount, $callback);
-
- # check if there is a part number - commented out, cause there is an automatic allocation of numbers
- # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
-
- # check if there is a description
- $form->isblank("description", $locale->text("Part Description missing!"));
-
- if ($form->{obsolete}) {
- $form->error(
- $locale->text(
- "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
- ))
- if ($form->{onhand} * 1);
- }
-
- if (!$form->{buchungsgruppen_id}) {
- $form->error($locale->text("Parts must have an entry type.") . " " .
- $locale->text("If you see this message, you most likely just setup your LX-Office and haven't added any entry types. If this is the case, the option is accessible for administrators in the System menu.")
- );
- }
-
- $form->error($locale->text('Description must not be empty!')) unless $form->{description};
- $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
-
- # save part
- $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
- if (IC->save(\%myconfig, \%$form) == 3) {
- $form->error($locale->text('Partnumber not unique!'));
- }
- # saving the history
- if(!exists $form->{addition}) {
- $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
- $form->{addition} = "SAVED";
- $form->save_history($form->dbconnect(\%myconfig));
- }
- # /saving the history
- $parts_id = $form->{id};
-
- my $i;
- # load previous variables
- if ($form->{previousform}) {
-
- # save the new form variables before splitting previousform
- map { $newform{$_} = $form->{$_} } keys %$form;
-
- $previousform = $form->unescape($form->{previousform});
-
- # don't trample on previous variables
- map { delete $form->{$_} } keys %newform;
-
- # now take it apart and restore original values
- foreach my $item (split /&/, $previousform) {
- my ($key, $value) = split m/=/, $item, 2;
- $value =~ s/%26/&/g;
- $form->{$key} = $value;
- }
- $form->{taxaccounts} = $newform{taxaccount2};
-
- if ($form->{item} eq 'assembly') {
-
- # undo number formatting
- map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
- qw(weight listprice sellprice rop);
-
- $form->{assembly_rows}--;
- $i = $newform{rowcount};
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
- $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
- $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
-
- # change/add values for assembly item
- map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno price_factor_id);
-
- $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
- $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
-
- } else {
-
- # set values for last invoice/order item
- $i = $form->{rowcount};
- $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
-
- map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice lastcost price_factor_id);
-
- $form->{"longdescription_$i"} = $newform{notes};
-
- $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
-
- if ($form->{exchangerate} != 0) {
- $form->{"sellprice_$i"} /= $form->{exchangerate};
- }
-
- $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
-
- map { $form->{"taxaccounts_$i"} .= "$_ " } split / /, $newform{taxaccount};
- chop $form->{"taxaccounts_$i"};
- foreach my $item (qw(description rate taxnumber)) {
- my $index = $form->{"taxaccounts_$i"} . "_$item";
- $form->{$index} = $newform{$index};
- }
-
- # credit remaining calculation
- $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
-
- map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
- map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
-
- $form->{creditremaining} -= $amount;
-
- # redo number formatting, because invoice parse them!
- map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) } qw(weight listprice sellprice rop);
- }
-
- $form->{"id_$i"} = $parts_id;
-
- # Get the actual price factor (not just the ID) for the marge calculation.
- $form->get_lists('price_factors' => 'ALL_PRICE_FACTORS');
- foreach my $pfac (@{ $form->{ALL_PRICE_FACTORS} }) {
- next if ($pfac->{id} != $newform{price_factor_id});
- $form->{"marge_price_factor_$i"} = $pfac->{factor};
- last;
- }
- delete $form->{ALL_PRICE_FACTORS};
-
- delete $form->{action};
-
- # restore original callback
- $callback = $form->unescape($form->{callback});
- $form->{callback} = $form->unescape($form->{old_callback});
- delete $form->{old_callback};
-
- $form->{makemodel_rows}--;
-
- # put callback together
- foreach my $key (keys %$form) {
-
- # do single escape for Apache 2.0
- my $value = $form->escape($form->{$key}, 1);
- $callback .= qq|&$key=$value|;
- }
- $form->{callback} = $callback;
- }
- $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
-
- # redirect
- $form->redirect;
-
- $lxdebug->leave_sub();
-}
-
-sub save_as_new {
- $lxdebug->enter_sub();
-
- $auth->assert('part_service_assembly_edit');
-
- # saving the history
- if(!exists $form->{addition}) {
- $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
- $form->{addition} = "SAVED AS NEW";
- $form->save_history($form->dbconnect(\%myconfig));
- }
- # /saving the history
- $form->{id} = 0;
- if ($form->{"original_partnumber"} &&
- ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
- $form->{partnumber} = "";
- }
- &save;
- $lxdebug->leave_sub();
-}
-
-sub delete {
- $lxdebug->enter_sub();
-
- $auth->assert('part_service_assembly_edit');
-
- # saving the history
- if(!exists $form->{addition}) {
- $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
- $form->{addition} = "DELETED";
- $form->save_history($form->dbconnect(\%myconfig));
- }
- # /saving the history
- my $rc = IC->delete(\%myconfig, \%$form);
-
- # redirect
- $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
- $form->error($locale->text('Cannot delete item!'));
-
- $lxdebug->leave_sub();
-}
-
-sub price_row {
- $lxdebug->enter_sub();
-
- $auth->assert('part_service_assembly_edit');
-
- my ($numrows) = @_;
-
- my @PRICES = map +{
- pricegroup => $form->{"pricegroup_$_"},
- pricegroup_id => $form->{"pricegroup_id_$_"},
- price => $form->{"price_$_"},
- }, 1 .. $numrows;
-
- print $form->parse_html_template('ic/price_row', { PRICES => \@PRICES });
-
- $lxdebug->leave_sub();
-}
-
-sub parts_language_selection {
- $lxdebug->enter_sub();
-
- $auth->assert('part_service_assembly_edit');
-
- our ($onload);
-
- my $languages = IC->retrieve_languages(\%myconfig, $form);
-
- if ($form->{language_values} ne "") {
- foreach $item (split(/---\+\+\+---/, $form->{language_values})) {
- my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item);
-
- foreach my $language (@{ $languages }) {
- next unless ($language->{id} == $language_id);
-
- $language->{translation} = $translation;
- $language->{longdescription} = $longdescription;
- last;
- }
- }
- }
-
- my @header_sort = qw(name longdescription);
- my %header_title = ( "name" => $locale->text("Name"),
- "longdescription" => $locale->text("Long Description"),
- );
-
- my @header =
- map(+{ "column_title" => $header_title{$_},
- "column" => $_,
- "callback" => $callback,
- },
- @header_sort);