use POSIX qw(strftime);
+use SL::DO;
use SL::FU;
use SL::OE;
use SL::IR;
set_headings("edit");
&order_links;
+
+ $form->{rowcount} = 0;
+ foreach $ref (@{ $form->{form_details} }) {
+ $form->{rowcount}++;
+ map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
+ }
+
&prepare_order;
+
if ($form->{print_and_save}) {
$form->{language_id} = $language_id;
$form->{printer_id} = $printer_id;
}
+
&display_form;
$lxdebug->leave_sub();
OE->retrieve(\%myconfig, \%$form);
- if ($form->{payment_id}) {
- $payment_id = $form->{payment_id};
- }
- if ($form->{language_id}) {
- $language_id = $form->{language_id};
- }
- if ($form->{taxzone_id}) {
- $taxzone_id = $form->{taxzone_id};
- }
-
- $salesman_id = $form->{salesman_id} if ($editing);
-
-
# if multiple rowcounts (== collective order) then check if the
# there were more than one customer (in that case OE::retrieve removes
# the content from the field)
- if ( $form->{rowcount}
- && $form->{type} eq 'sales_order'
- && defined $form->{customer}
- && $form->{customer} eq '') {
-
- # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
- $form->error(
- $locale->text(
- 'Collective Orders only work for orders from one customer!')
- );
- }
+ $form->error($locale->text('Collective Orders only work for orders from one customer!'))
+ if $form->{rowcount} && $form->{type} eq 'sales_order'
+ && defined $form->{customer} && $form->{customer} eq '';
- $taxincluded = $form->{taxincluded};
- $form->{shipto} = 1 if $form->{id};
-
- if ($form->{"all_$form->{vc}"}) {
- unless ($form->{"$form->{vc}_id"}) {
- $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
- }
- }
+ $form->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"};
- $cp_id = $form->{cp_id};
- $intnotes = $form->{intnotes};
+ $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes));
+ $form->{shipto} = 1 if $form->{id};
# get customer / vendor
- if ($form->{type} =~ /(purchase_order|request_quotation)/) {
- IR->get_vendor(\%myconfig, \%$form);
-
- #quote all_vendor Bug 133
- foreach $ref (@{ $form->{all_vendor} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
+ IR->get_vendor(\%myconfig, \%$form) if $form->{type} =~ /(purchase_order|request_quotation)/;
+ IS->get_customer(\%myconfig, \%$form) if $form->{type} =~ /sales_(order|quotation)/;
- }
- if ($form->{type} =~ /sales_(order|quotation)/) {
- IS->get_customer(\%myconfig, \%$form);
-
- #quote all_vendor Bug 133
- foreach $ref (@{ $form->{all_customer} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
+ $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id));
+ $form->restore_vars(qw(taxincluded)) if $form->{id};
+ $form->restore_vars(qw(salesman_id)) if $editing;
+ $form->{forex} = $form->{exchangerate};
+ $form->{employee} = "$form->{employee}--$form->{employee_id}";
- }
- $form->{cp_id} = $cp_id;
-
- if ($payment_id) {
- $form->{payment_id} = $payment_id;
- }
- if ($language_id) {
- $form->{language_id} = $language_id;
- }
- if ($taxzone_id) {
- $form->{taxzone_id} = $taxzone_id;
- }
- $form->{intnotes} = $intnotes if $intnotes;
- ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
- $form->{"old$form->{vc}"} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-
- # build the popup menus
+ # build vendor/customer drop down comatibility... don't ask
if (@{ $form->{"all_$form->{vc}"} }) {
- $form->{ $form->{vc} } =
- qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
- map { $form->{"select$form->{vc}"} .=
-"<option>$_->{name}--$_->{id}</option>\n" }
- (@{ $form->{"all_$form->{vc}"} });
+ $form->{"select$form->{vc}"} = 1;
+ $form->{$form->{vc}} = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
}
- $form->{taxincluded} = $taxincluded if ($form->{id});
-
- # departments
- if (@{ $form->{all_departments} }) {
- $form->{selectdepartment} = "<option>\n";
- $form->{department} = "$form->{department}--$form->{department_id}";
-
- map {
- $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}</option>\n"
- } @{ $form->{all_departments} };
- }
-
- $form->{employee} = "$form->{employee}--$form->{employee_id}";
-
- # forex
- $form->{forex} = $form->{exchangerate};
-
- $form->{salesman_id} = $salesman_id if ($editing);
+ $form->{"old$form->{vc}"} = $form->{$form->{vc}};
+ $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}| unless ($form->{"old$form->{vc}"} =~ m/--\d+$/);
$lxdebug->leave_sub();
}
check_oe_access();
- $form->{formname} = $form->{type} unless $form->{formname};
+ $form->{formname} ||= $form->{type};
- my $i = 0;
- foreach $ref (@{ $form->{form_details} }) {
- $form->{rowcount} = ++$i;
- map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
- }
for my $i (1 .. $form->{rowcount}) {
- $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
+ $form->{"reqdate_$i"} ||= $form->{"deliverydate_$i"};
$form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
$form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
$form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
- map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
}
$lxdebug->leave_sub();
# Container for template variables. Unfortunately this has to be visible in form_footer too, so not my.
our %TMPL_VAR = ();
- $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
- $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
-
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
"taxzones" => "ALL_TAXZONES",
"payments" => "ALL_PAYMENTS",
"currencies" => "ALL_CURRENCIES",
+ "departments" => "ALL_DEPARTMENTS",
$vc => { key => "ALL_" . uc($vc),
limit => $myconfig{vclimit} + 1 },
"price_factors" => "ALL_PRICE_FACTORS");
# label subs
$TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
- $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
- $TMPL_VAR{contact_labels} = sub { $_[0]->{"cp_name"} . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+ $TMPL_VAR{shipto_labels} = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
+ $TMPL_VAR{contact_labels} = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+ $TMPL_VAR{department_labels} = sub { "$_[0]->{description}--$_[0]->{id}" };
# vendor/customer
$TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
@values = map { $_ } @{ $form->{ALL_CURRENCIES} };
%labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
$form->{currency} = $form->{defaultcurrency} unless $form->{currency};
- $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency} && $form->{exchangerate};
+ $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
$TMPL_VAR{currencies} = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
'-values' => \@values, '-labels' => \%labels)) if scalar @values;
push @custom_hiddens, "forex";
max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
shiptocity shiptocountry shiptocontact shiptophone shiptofax
shiptodepartment_1 shiptodepartment_2 shiptoemail
- message email subject cc bcc taxpart taxservice taxaccounts),
+ message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus),
@custom_hiddens,
map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ]; # deleted: discount
is_pur_ord => scalar ($form->{type} =~ /purchase_order$/),
);
- print $form->parse_html_template("oe/orders_header", { %TMPL_VAR });
+ print $form->parse_html_template("oe/form_header", { %TMPL_VAR });
$lxdebug->leave_sub();
}
$form->{oldinvtotal} = $form->{invtotal};
- print $form->parse_html_template("oe/orders_footer", {
+ print $form->parse_html_template("oe/form_footer", {
%TMPL_VAR,
webdav => $webdav,
print_options => print_options(inline => 1),
$buysell = 'buy';
$buysell = 'sell' if ($form->{vc} eq 'vendor');
- $form->{exchangerate} = $exchangerate if
- $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+ $form->{forex} = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
$exchangerate = $form->{exchangerate} || 1;
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
-
$report->set_export_options('orders', @hidden_variables);
-
$report->set_sort_indicator($form->{sort}, 1);
my @options;
- if ($form->{customer}) {
- push @options, $locale->text('Customer') . " : $form->{customer}";
- }
- if ($form->{vendor}) {
- push @options, $locale->text('Vendor') . " : $form->{vendor}";
- }
- if ($form->{department}) {
- ($department) = split /--/, $form->{department};
- push @options, $locale->text('Department') . " : $department";
- }
- if ($form->{ordnumber}) {
- push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
- }
- if ($form->{notes}) {
- push @options, $locale->text('Notes') . " : $form->{notes}";
- }
- if ($form->{transaction_description}) {
- push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
- }
- if ($form->{transdatefrom}) {
- push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
- }
- if ($form->{transdateto}) {
- push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
- }
- if ($form->{open}) {
- push @options, $locale->text('Open');
- }
- if ($form->{closed}) {
- push @options, $locale->text('Closed');
- }
- if ($form->{delivered}) {
- push @options, $locale->text('Delivered');
- }
- if ($form->{notdelivered}) {
- push @options, $locale->text('Not delivered');
- }
+ my ($department) = split m/--/, $form->{department};
+
+ push @options, $locale->text('Customer') . " : $form->{customer}" if $form->{customer};
+ push @options, $locale->text('Vendor') . " : $form->{vendor}" if $form->{vendor};
+ push @options, $locale->text('Department') . " : $department" if $form->{department};
+ push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if $form->{ordnumber};
+ push @options, $locale->text('Notes') . " : $form->{notes}" if $form->{notes};
+ push @options, $locale->text('Transaction description') . " : $form->{transaction_description}" if $form->{transaction_description};
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1) if $form->{transdatefrom};
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1) if $form->{transdateto};
+ push @options, $locale->text('Open') if $form->{open};
+ push @options, $locale->text('Closed') if $form->{closed};
+ push @options, $locale->text('Delivered') if $form->{delivered};
+ push @options, $locale->text('Not delivered') if $form->{notdelivered};
$report->set_options('top_info_text' => join("\n", @options),
'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
OE->close_orders(\%myconfig, \%$form);
}
- $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
- $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+ $form->{convert_from_oe_ids} = $form->{id};
+ $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
+ $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
+ $form->{shipto} = 1;
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
- $form->{id} = '';
- $form->{closed} = 0;
+ delete @{$form}{qw(id closed)};
$form->{rowcount}--;
- $form->{shipto} = 1;
-
- $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
if ($form->{type} =~ /_order$/) {
$form->{exchangerate} = $exchangerate;
&invoice_links;
$form->{currency} = $currency;
- $form->{exchangerate} = "";
- $form->{forex} = "";
- $form->{exchangerate} = $exchangerate
- if (
- $form->{forex} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{invdate}, $buysell
- )));
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
+ $form->{exchangerate} = $form->{forex} || '';
$form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
$form->{cp_id} *= 1;
- $form->{title} = $locale->text('Add Sales Order');
- $form->{vc} = "customer";
- $form->{type} = "sales_order";
+ $form->{title} = $locale->text('Add Sales Order');
+ $form->{vc} = "customer";
+ $form->{type} = "sales_order";
&poso;
$form->{transdate} = $form->current_date(\%myconfig);
delete $form->{duedate};
- $form->{closed} = 0;
+ $form->{convert_from_oe_ids} = $form->{id};
+ $form->{closed} = 0;
- $form->{old_employee_id} = $form->{employee_id};
- $form->{old_salesman_id} = $form->{salesman_id};
+ $form->{old_employee_id} = $form->{employee_id};
+ $form->{old_salesman_id} = $form->{salesman_id};
# reset
- map { delete $form->{$_} }
- qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
+ map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered);
for $i (1 .. $form->{rowcount}) {
- map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
- $form->{"${_}_${i}"})
- if ($form->{"${_}_${i}"}) }
- qw(ship qty sellprice listprice basefactor));
+ map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
}
+ my %saved_vars = map { $_ => $form->{$_} } grep { $form->{$_} } qw(currency);
+
&order_links;
+ map { $form->{$_} = $saved_vars{$_} } keys %saved_vars;
+
&prepare_order;
# format amounts
for $i (1 .. $form->{rowcount} - 1) {
- map { $form->{"${_}_$i"} =~ s/\"/"/g }
- qw(partnumber description unit);
+ map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
}
&update;
$lxdebug->leave_sub();
}
+sub delivery_order {
+ $lxdebug->enter_sub();
+
+ if ($form->{type} =~ /^sales/) {
+ $auth->assert('sales_delivery_order_edit');
+
+ $form->{vc} = 'customer';
+ $form->{type} = 'sales_delivery_order';
+
+ } else {
+ $auth->assert('purchase_delivery_order_edit');
+
+ $form->{vc} = 'vendor';
+ $form->{type} = 'purchase_delivery_order';
+ }
+
+ require "bin/mozilla/do.pl";
+
+ $form->{cp_id} *= 1;
+ $form->{convert_from_oe_ids} = $form->{id};
+ $form->{transdate} = $form->current_date(\%myconfig);
+ delete $form->{duedate};
+
+ $form->{old_employee_id} = $form->{employee_id};
+ $form->{old_salesman_id} = $form->{salesman_id};
+
+ # reset
+ delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)};
+
+ for $i (1 .. $form->{rowcount}) {
+ map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
+ }
+
+ my %old_values = map { $_ => $form->{$_} } qw(customer_id oldcustomer customer vendor_id oldvendor vendor);
+
+ order_links();
+
+ prepare_order();
+
+ map { $form->{$_} = $old_values{$_} if ($old_values{$_}) } keys %old_values;
+
+ update();
+
+ $lxdebug->leave_sub();
+}
+
sub e_mail {
$lxdebug->enter_sub();
check_oe_access();
+ retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
+
$form->{"taxaccounts"} =~ s/\s*$//;
$form->{"taxaccounts"} =~ s/^\s*//;
foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {