@@ -749,24 +792,15 @@ sub form_header {
|
$taxincluded
@@ -1021,14 +1060,12 @@ sub form_footer {
print $webdav_list;
}
- print qq|
-{jscalendar}>
-|;
+
print qq|
|
|;
- &print_options;
+ print_options();
print qq|
|
@@ -1123,7 +1160,6 @@ sub form_footer {
-{path}>
{login}>
{password}>
@@ -1143,9 +1179,17 @@ sub update {
map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
qw(exchangerate creditlimit creditremaining);
$form->{update} = 1;
-
+
+ if($form->{payment_id}) {
+ $payment_id = $form->{payment_id};
+ }
+
&check_name($form->{vc});
-
+
+ if($form->{payment_id} eq "") {
+ $form->{payment_id} = $payment_id;
+ }
+
$buysell = 'buy';
$buysell = 'sell' if ($form->{vc} eq 'vendor');
$form->{exchangerate} = $exchangerate
@@ -1312,27 +1356,13 @@ sub search {
$form->all_vc(\%myconfig, $form->{vc},
($form->{vc} eq 'customer') ? "AR" : "AP");
- map { $vc .= "\n";
map {
$form->{selectdepartment} .=
- "$_->{description}--$_->{id}\n"
+ "$_->{description}--$_->{id}\n"
} (@{ $form->{all_departments} });
}
@@ -1357,37 +1387,31 @@ sub search {
}
# use JavaScript Calendar or not
- $form->{jsscript} = $jscalendar;
+ $form->{jsscript} = 1;
$jsscript = "";
- if ($form->{jsscript}) {
-
- # with JavaScript Calendar
- $button1 = qq|
-
- text('button') . qq|> |
- |;
- $button2 = qq|
-
- text('button') . qq|> |
- |;
-
- #write Trigger
- $jsscript =
- Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
- "transdateto", "BL", "trigger4");
- } else {
- # without JavaScript Calendar
- $button1 = qq|
- | |;
- $button2 = qq|
- | |;
- }
+ $button1 = qq|
+
+ text('button') . qq|> |
+ |;
+ $button2 = qq|
+
+ text('button') . qq|> |
+ |;
+
+ #write Trigger
+ $jsscript =
+ Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
+ "transdateto", "BL", "trigger4");
+
+ my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
$form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 1 });
+ "all" => 1 },
+ "employees" => "ALL_EMPLOYEES",
+ $vc => "ALL_" . uc($vc));
my %labels = ();
my @values = ("");
@@ -1399,6 +1423,41 @@ sub search {
NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
'-labels' => \%labels));
+ #employees
+ %labels = ();
+ @values = ("");
+ foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
+ push(@values, $item->{"id"});
+ $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
+ }
+
+ my $employee_block = qq|
+
+ | . $locale->text('Employee') . qq| |
+ | .
+ NTI($cgi->popup_menu('-name' => 'employee_id',
+ '-values' => \@values,
+ '-labels' => \%labels)) . qq|
+ |
+
|;
+
+ %labels = ();
+ @values = ("");
+
+ foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
+ push(@values, $item->{name}.qq|--|.$item->{"id"});
+ $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
+ }
+
+ my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
+ $vc =
+ $myconfig{vclimit} <= scalar(@values)
+ ? qq|{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
+ : NTI($cgi->popup_menu('-name' => "$form->{vc}",
+ '-default' => $form->{"old$form->{vc}"},
+ '-onChange' => 'document.getElementById(\'update_button\').click();',
+ '-values' => \@values,
+ '-labels' => \%labels));
$form->header;
print qq|
@@ -1415,7 +1474,7 @@ sub search {
- $vclabel |
+ $vc_label |
$vc |
$department
@@ -1423,6 +1482,11 @@ sub search {
$ordlabel |
|
+ $employee_block
+
+ | . $locale->text('Transaction description') . qq| |
+ |
+
| . $locale->text("Project Number") . qq| |
$projectnumber |
@@ -1455,7 +1519,7 @@ sub search {
. $locale->text('Required by') . qq|
- $vclabel |
+ $vc_label |
$employee |
|
. $locale->text('Ship via') . qq| |
@@ -1468,8 +1532,12 @@ sub search {
. $locale->text('Tax') . qq|
|
. $locale->text('Total') . qq| |
+
+
|
. $locale->text('Project Number') . qq| |
+ |
+ . $locale->text('Transaction description') . qq| |
|
@@ -1488,7 +1556,6 @@ $jsscript
-{path}>
{login}>
{password}>
{vc}>
@@ -1505,366 +1572,259 @@ $jsscript
$lxdebug->leave_sub();
}
-sub orders {
+sub create_subtotal_row {
$lxdebug->enter_sub();
- # split vendor / customer
- ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
- split(/--/, $form->{ $form->{vc} });
+ my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
- OE->transactions(\%myconfig, \%$form);
+ my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
- $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
+ map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
- $number = $form->escape($form->{$ordnumber});
- $name = $form->escape($form->{ $form->{vc} });
- $department = $form->escape($form->{department});
+ $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
- # construct href
- $href =
- "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
+ map { $totals->{$_} = 0 } @{ $subtotal_columns };
- # construct callback
- $number = $form->escape($form->{$ordnumber}, 1);
- $name = $form->escape($form->{ $form->{vc} }, 1);
- $department = $form->escape($form->{department}, 1);
+ $lxdebug->leave_sub();
- $callback =
- "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
+ return $row;
+}
+
+sub orders {
+ $lxdebug->enter_sub();
- @columns =
- $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
- "name", "netamount", "tax", "amount",
- "curr", "employee", "shipvia", "globalprojectnumber",
- "open", "closed", "delivered");
+ $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
- $form->{l_open} = $form->{l_closed} = "Y"
- if ($form->{open} && $form->{closed});
+ ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
- $form->{"l_delivered"} = "Y"
- if ($form->{"delivered"} && $form->{"notdelivered"});
+ $form->{sort} ||= 'transdate';
- foreach $item (@columns) {
- if ($form->{"l_$item"} eq "Y") {
- push @column_index, $item;
+ OE->transactions(\%myconfig, \%$form);
- # add column to href and callback
- $callback .= "&l_$item=Y";
- $href .= "&l_$item=Y";
- }
- }
+ $form->{rowcount} = scalar @{ $form->{OE} };
+
+ my @columns = (
+ "transdate", "reqdate",
+ "id", $ordnumber,
+ "name", "netamount",
+ "tax", "amount",
+ "curr", "employee",
+ "shipvia", "globalprojectnumber",
+ "transaction_description", "open",
+ "delivered"
+ );
# only show checkboxes if gotten here via sales_order form.
- if ($form->{type} =~ /sales_order/) {
- unshift @column_index, "ids";
+ my $allow_multiple_orders = $form->{type} eq 'sales_order';
+ if ($allow_multiple_orders) {
+ unshift @columns, "ids";
}
- if ($form->{l_subtotal} eq 'Y') {
- $callback .= "&l_subtotal=Y";
- $href .= "&l_subtotal=Y";
- }
+ $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
+ $form->{l_delivered} = "Y" if ($form->{delivered} && $form->{notdelivered});
+ my $attachment_basename;
if ($form->{vc} eq 'vendor') {
if ($form->{type} eq 'purchase_order') {
- $form->{title} = $locale->text('Purchase Orders');
+ $form->{title} = $locale->text('Purchase Orders');
+ $attachment_basename = $locale->text('purchase_order_list');
} else {
- $form->{title} = $locale->text('Request for Quotations');
+ $form->{title} = $locale->text('Request for Quotations');
+ $attachment_basename = $locale->text('rfq_list');
}
- $name = $locale->text('Vendor');
- $employee = $locale->text('Employee');
- }
- if ($form->{vc} eq 'customer') {
+
+ } else {
if ($form->{type} eq 'sales_order') {
- $form->{title} = $locale->text('Sales Orders');
+ $form->{title} = $locale->text('Sales Orders');
+ $attachment_basename = $locale->text('sales_order_list');
} else {
- $form->{title} = $locale->text('Quotations');
+ $form->{title} = $locale->text('Quotations');
+ $attachment_basename = $locale->text('quotation_list');
}
- $employee = $locale->text('Employee');
- $name = $locale->text('Customer');
- }
-
- $column_header{id} =
- qq| | |
- . $locale->text('ID')
- . qq| | |;
- $column_header{transdate} =
- qq||
- . $locale->text('Date')
- . qq| | |;
- $column_header{reqdate} =
- qq||
- . $locale->text('Required by')
- . qq| | |;
- $column_header{ordnumber} =
- qq||
- . $locale->text('Order')
- . qq| | |;
- $column_header{quonumber} =
- qq||
- . ($form->{"type"} eq "request_quotation" ?
- $locale->text('RFQ') :
- $locale->text('Quotation'))
- . qq| | |;
- $column_header{name} =
- qq|$name | |;
- $column_header{netamount} =
- qq|| . $locale->text('Amount') . qq| | |;
- $column_header{tax} =
- qq|| . $locale->text('Tax') . qq| | |;
- $column_header{amount} =
- qq|| . $locale->text('Total') . qq| | |;
- $column_header{curr} =
- qq|| . $locale->text('Curr') . qq| | |;
- $column_header{shipvia} =
- qq||
- . $locale->text('Ship via')
- . qq| | |;
- $column_header{globalprojectnumber} =
- qq|| . $locale->text('Project Number') . qq| | |;
- $column_header{open} =
- qq|| . $locale->text('O') . qq| | |;
- $column_header{closed} =
- qq|| . $locale->text('C') . qq| | |;
- $column_header{"delivered"} =
- qq|| . $locale->text("Delivered") . qq| | |;
-
- $column_header{employee} =
- qq|$employee | |;
-
- $column_header{ids} = qq| | |;
-
- if ($form->{ $form->{vc} }) {
- $option = $locale->text(ucfirst $form->{vc});
- $option .= " : $form->{$form->{vc}}";
+ }
+
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
+
+ my @hidden_variables = map { "l_${_}" } @columns;
+ push @hidden_variables, "l_subtotal", $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered ordnumber quonumber
+ transaction_description transdatefrom transdateto type vc employee_id);
+
+ my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
+
+ my %column_defs = (
+ 'ids' => { 'text' => '', },
+ 'transdate' => { 'text' => $locale->text('Date'), },
+ 'reqdate' => { 'text' => $locale->text('Required by'), },
+ 'id' => { 'text' => $locale->text('ID'), },
+ 'ordnumber' => { 'text' => $locale->text('Order'), },
+ 'quonumber' => { 'text' => $form->{type} eq "request_quotation" ? $locale->text('RFQ') : $locale->text('Quotation'), },
+ 'name' => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
+ 'netamount' => { 'text' => $locale->text('Amount'), },
+ 'tax' => { 'text' => $locale->text('Tax'), },
+ 'amount' => { 'text' => $locale->text('Total'), },
+ 'curr' => { 'text' => $locale->text('Curr'), },
+ 'employee' => { 'text' => $locale->text('Salesperson'), },
+ 'shipvia' => { 'text' => $locale->text('Ship via'), },
+ 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
+ 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
+ 'open' => { 'text' => $locale->text('Open'), },
+ 'delivered' => { 'text' => $locale->text('Delivered'), },
+ );
+
+ foreach my $name (qw(id transdate reqdate quonumber ordnumber name employee shipvia)) {
+ $column_defs{$name}->{link} = $href . "&sort=$name";
+ }
+
+ my %column_alignment = map { $_ => 'right' } qw(netamount tax amount curr);
+
+ $form->{"l_type"} = "Y";
+ map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
+ $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
+
+ $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}) {
- $option .= "\n " if ($option);
($department) = split /--/, $form->{department};
- $option .= $locale->text('Department') . " : $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}) {
- $option .= "\n "
- . $locale->text('From') . " "
- . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
}
if ($form->{transdateto}) {
- $option .= "\n "
- . $locale->text('Bis') . " "
- . $locale->date(\%myconfig, $form->{transdateto}, 1);
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
}
if ($form->{open}) {
- $option .= "\n " if ($option);
- $option .= $locale->text('Open');
+ push @options, $locale->text('Open');
}
if ($form->{closed}) {
- $option .= "\n " if ($option);
- $option .= $locale->text('Closed');
+ push @options, $locale->text('Closed');
+ }
+ if ($form->{delivered}) {
+ push @options, $locale->text('Delivered');
+ }
+ if ($form->{notdelivered}) {
+ push @options, $locale->text('Not delivered');
}
- $form->header;
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
+ 'raw_bottom_info_text' => $form->parse_html_template('oe/orders_bottom', { 'SHOW_CONTINUE_BUTTON' => $allow_multiple_orders }),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
- print qq|
-
+ # add sort and escape callback, this one we use for the add sub
+ $form->{callback} = $href .= "&sort=$form->{sort}";
-
+ $report->add_separator();
+ $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
-
-
-
-
-
-|;
+ $report->generate_with_headers();
$lxdebug->leave_sub();
}
-sub subtotal {
+sub check_delivered_flag {
$lxdebug->enter_sub();
- map { $column_data{$_} = " | " } @column_index;
+ if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
+ return $lxdebug->leave_sub();
+ }
- $column_data{netamount} =
- ""
- . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
- . " | ";
- $column_data{tax} = ""
- . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
- 2, " ")
- . "";
- $column_data{amount} =
- " | "
- . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . " | ";
+ my $all_delivered = 0;
- $subtotalnetamount = 0;
- $subtotalamount = 0;
+ foreach my $i (1 .. $form->{rowcount}) {
+ next if (!$form->{"id_$i"});
- print "
-
-";
+ if ($form->parse_amount(\%myconfig, $form->{"qty_$i"}) == $form->parse_amount(\%myconfig, $form->{"ship_$i"})) {
+ $all_delivered = 1;
+ next;
+ }
- map { print "\n$column_data{$_}" } @column_index;
+ $all_delivered = 0;
+ last;
+ }
- print qq|
-
-|;
+ $form->{delivered} = 1 if $all_delivered;
$lxdebug->leave_sub();
}
@@ -1872,12 +1832,18 @@ sub subtotal {
sub save_and_close {
$lxdebug->enter_sub();
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
if ($form->{type} =~ /_order$/) {
$form->isblank("transdate", $locale->text('Order Date missing!'));
} else {
$form->isblank("transdate", $locale->text('Quotation Date missing!'));
}
+ my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
+ $form->{$idx} =~ s/^\s*//g;
+ $form->{$idx} =~ s/\s*$//g;
+
$msg = ucfirst $form->{vc};
$form->isblank($form->{vc}, $locale->text($msg . " missing!"));
@@ -1888,9 +1854,16 @@ sub save_and_close {
if ($form->{currency} ne $form->{defaultcurrency});
&validate_items;
-
+
+ if($form->{payment_id}) {
+ $payment_id = $form->{payment_id};
+ }
+
# if the name changed get new values
if (&check_name($form->{vc})) {
+ if($form->{payment_id} eq "") {
+ $form->{payment_id} = $payment_id;
+ }
&update;
exit;
}
@@ -1913,6 +1886,8 @@ sub save_and_close {
$err = $locale->text('Cannot save order!');
+ check_delivered_flag();
+
} else {
if ($form->{type} eq 'sales_quotation') {
$form->{label} = $locale->text('Quotation');
@@ -1941,6 +1916,7 @@ sub save_and_close {
# saving the history
if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
$form->{addition} = "SAVED";
$form->save_history($form->dbconnect(\%myconfig));
}
@@ -1955,12 +1931,19 @@ sub save_and_close {
sub save {
$lxdebug->enter_sub();
+ $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+
+
if ($form->{type} =~ /_order$/) {
$form->isblank("transdate", $locale->text('Order Date missing!'));
} else {
$form->isblank("transdate", $locale->text('Quotation Date missing!'));
}
+ my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
+ $form->{$idx} =~ s/^\s*//g;
+ $form->{$idx} =~ s/\s*$//g;
+
$msg = ucfirst $form->{vc};
$form->isblank($form->{vc}, $locale->text($msg . " missing!"));
@@ -1971,9 +1954,16 @@ sub save {
if ($form->{currency} ne $form->{defaultcurrency});
&validate_items;
-
+
+ if($form->{payment_id}) {
+ $payment_id = $form->{payment_id};
+ }
+
# if the name changed get new values
if (&check_name($form->{vc})) {
+ if($form->{payment_id} eq "") {
+ $form->{payment_id} = $payment_id;
+ }
&update;
exit;
}
@@ -1996,6 +1986,8 @@ sub save {
$err = $locale->text('Cannot save order!');
+ check_delivered_flag();
+
} else {
if ($form->{type} eq 'sales_quotation') {
$form->{label} = $locale->text('Quotation');
@@ -2022,6 +2014,7 @@ sub save {
# saving the history
if(!exists $form->{addition}) {
+ $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
$form->{addition} = "SAVED";
$form->save_history($form->dbconnect(\%myconfig));
}
@@ -2068,8 +2061,11 @@ sub delete {
$msg $form->{$ordnumber}
+
+
|