1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 ######################################################################
8 # Stuff that can be used from other modules
10 ######################################################################
18 $lxdebug->enter_sub();
20 my $old_form = YAML::Dump($form);
21 $old_form =~ s|!|!!|g;
22 $old_form =~ s|\n|!n|g;
23 $old_form =~ s|\r|!r|g;
25 $lxdebug->leave_sub();
31 $lxdebug->enter_sub();
33 my ($old_form, $no_delete) = @_;
35 map({ delete($form->{$_}); } keys(%{$form})) unless ($no_delete);
36 $old_form =~ s|!r|\r|g;
37 $old_form =~ s|!n|\n|g;
38 $old_form =~ s|!!|!|g;
39 my $new_form = YAML::Load($old_form);
40 map({ $form->{$_} = $new_form->{$_}; } keys(%{$new_form}));
42 $lxdebug->leave_sub();
46 $lxdebug->enter_sub();
48 my $script = $form->{script};
52 foreach my $key ((qw(login password), @_)) {
55 if ($key =~ /(.*?)=(.*)/) {
63 push @parts, "${key}=" . E($form->{$key});
67 my $url = "${script}?" . join('&', @parts);
69 $lxdebug->leave_sub();
75 $lxdebug->enter_sub();
77 my ($callback_sub, @employees) = @_;
79 if (0 == scalar(@employees)) {
80 @employees = SystemBrace->get_all_employees(\%myconfig, $form);
83 my $old_form = save_form();
86 print($form->parse_html_template("generic/select_employee",
87 { "EMPLOYEES" => \@employees,
88 "old_form" => $old_form,
89 "title" => $locale->text("Select an employee"),
90 "nextsub" => "select_employee_internal",
91 "callback_sub" => $callback_sub }));
93 $lxdebug->leave_sub();
96 sub select_employee_internal {
97 $lxdebug->enter_sub();
99 my ($new_id, $new_name, $callback_sub);
101 my $new_id = $form->{"new_id_" . $form->{"selection"}};
102 my $new_name = $form->{"new_name_" . $form->{"selection"}};
103 my $callback_sub = $form->{"callback_sub"};
105 restore_form($form->{"old_form"});
107 call_sub($callback_sub, $new_id, $new_name);
109 $lxdebug->leave_sub();
113 $lxdebug->enter_sub();
115 my ($callback_sub, @parts) = @_;
117 my $remap_parts_id = 0;
118 if (defined($parts[0]->{"parts_id"}) && !defined($parts[0]->{"id"})) {
120 map({ $_->{"id"} = $_->{"parts_id"}; } @parts);
123 my $remap_partnumber = 0;
124 if (defined($parts[0]->{"partnumber"}) && !defined($parts[0]->{"number"})) {
125 $remap_partnumber = 1;
126 map({ $_->{"number"} = $_->{"partnumber"}; } @parts);
130 if (defined($parts[0]->{"chargenumber"})) {
132 map({ $_->{"has_charge"} = 1; } @parts);
135 my $old_form = save_form();
138 print($form->parse_html_template("generic/select_part",
139 { "PARTS" => \@parts,
140 "old_form" => $old_form,
141 "title" => $locale->text("Select a part"),
142 "nextsub" => "select_part_internal",
143 "callback_sub" => $callback_sub,
144 "has_charge" => $has_charge,
145 "remap_parts_id" => $remap_parts_id,
146 "remap_partnumber" => $remap_partnumber }));
148 $lxdebug->leave_sub();
151 sub select_part_internal {
152 $lxdebug->enter_sub();
154 my ($new_item, $callback_sub);
156 my $re = "^new_.*_" . $form->{"selection"};
161 $new_item->{$key} = $form->{$_};
162 } grep(/$re/, keys(%{$form})));
164 if ($form->{"remap_parts_id"}) {
165 $new_item->{"parts_id"} = $new_item->{"id"};
166 delete($new_item->{"id"});
168 if ($form->{"remap_partnumber"}) {
169 $new_item->{"partnumber"} = $new_item->{"number"};
170 delete($new_item->{"number"});
173 my $callback_sub = $form->{"callback_sub"};
175 restore_form($form->{"old_form"});
177 call_sub($callback_sub, $new_item);
179 $lxdebug->leave_sub();
182 sub part_selection_internal {
183 $lxdebug->enter_sub();
185 $order_by = "description";
186 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
188 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
190 $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
191 map({ $parts->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$parts}));
192 if (0 == scalar(@{$parts})) {
193 $form->show_generic_information($locale->text("No part was found matching the search parameters."));
194 } elsif (1 == scalar(@{$parts})) {
195 $onload = "part_selected('1')";
198 my $callback = "$form->{script}?action=part_selection_internal&";
199 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
200 (qw(login path password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form)));
202 my @header_sort = qw(partnumber description);
203 my %header_title = ( "partnumber" => $locale->text("Part Number"),
204 "description" => $locale->text("Part description"),
208 map(+{ "column_title" => $header_title{$_},
210 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
214 $form->{"title"} = $locale->text("Select a part");
216 print($form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
218 "onload" => $onload }));
220 $lxdebug->leave_sub();
223 sub project_selection_internal {
224 $lxdebug->enter_sub();
226 $order_by = "description";
227 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
229 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
231 $projects = Common->retrieve_projects(\%myconfig, $form, $order_by, $order_dir);
232 map({ $projects->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$projects}));
233 if (0 == scalar(@{$projects})) {
234 $form->show_generic_information($locale->text("No project was found matching the search parameters."));
235 } elsif (1 == scalar(@{$projects})) {
236 $onload = "project_selected('1')";
239 my $callback = "$form->{script}?action=project_selection_internal&";
240 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
241 (qw(login path password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form)));
243 my @header_sort = qw(projectnumber description);
244 my %header_title = ( "projectnumber" => $locale->text("Project Number"),
245 "description" => $locale->text("Project description"),
249 map(+{ "column_title" => $header_title{$_},
251 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
255 $form->{"title"} = $locale->text("Select a project");
257 print($form->parse_html_template("generic/project_selection", { "HEADER" => \@header,
258 "PROJECTS" => $projects,
259 "onload" => $onload }));
261 $lxdebug->leave_sub();
264 sub employee_selection_internal {
265 $lxdebug->enter_sub();
268 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
270 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
272 $employees = Common->retrieve_employees(\%myconfig, $form, $order_by, $order_dir);
273 map({ $employees->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$employees}));
274 if (0 == scalar(@{$employees})) {
275 $form->show_generic_information($locale->text("No employee was found matching the search parameters."));
276 } elsif (1 == scalar(@{$employees})) {
277 $onload = "employee_selected('1')";
280 my $callback = "$form->{script}?action=employee_selection_internal&";
281 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
282 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
284 my @header_sort = qw(name);
285 my %header_title = ( "name" => $locale->text("Name"),
289 map(+{ "column_title" => $header_title{$_},
291 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
295 $form->{"title"} = $locale->text("Select an employee");
297 print($form->parse_html_template("generic/employee_selection", { "HEADER" => \@header,
298 "EMPLOYEES" => $employees,
299 "onload" => $onload }));
301 $lxdebug->leave_sub();
304 sub delivery_customer_selection {
305 $lxdebug->enter_sub();
308 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
310 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
312 $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
313 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
314 if (0 == scalar(@{$delivery})) {
315 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
316 } elsif (1 == scalar(@{$delivery})) {
317 $onload = "customer_selected('1')";
320 my $callback = "$form->{script}?action=delivery_customer_selection&";
321 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
322 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
324 my @header_sort = qw(name customernumber address);
325 my %header_title = ( "name" => $locale->text("Name"),
326 "customernumber" => $locale->text("Customer Number"),
327 "address" => $locale->text("Address"),
331 map(+{ "column_title" => $header_title{$_},
333 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
337 $form->{"title"} = $locale->text("Select a Customer");
339 print($form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
340 "DELIVERY" => $delivery,
341 "onload" => $onload }));
343 $lxdebug->leave_sub();
346 sub vendor_selection {
347 $lxdebug->enter_sub();
350 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
352 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
354 $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
355 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
356 if (0 == scalar(@{$vendor})) {
357 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
358 } elsif (1 == scalar(@{$vendor})) {
359 $onload = "vendor_selected('1')";
362 my $callback = "$form->{script}?action=vendor_selection&";
363 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
364 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
366 my @header_sort = qw(name customernumber address);
367 my %header_title = ( "name" => $locale->text("Name"),
368 "customernumber" => $locale->text("Customer Number"),
369 "address" => $locale->text("Address"),
373 map(+{ "column_title" => $header_title{$_},
375 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
379 $form->{"title"} = $locale->text("Select a Customer");
381 print($form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
383 "onload" => $onload }));
385 $lxdebug->leave_sub();
389 $lxdebug->enter_sub();
391 my @variable_sort = ();
392 my %variable_list = ();
394 $form->{formel} =~ s/\r\n//g;
396 my ($variable_string, $formel) = split /###/,$form->{formel};
399 split /;/, $variable_string;
401 my($name, $valueunit) = split /=/,$item;
402 my($value, $unit) = split / /, $valueunit;
404 push(@variable_sort, $value);
405 $variable_list{$value} = $name;
406 $unit_list{$value} = $unit;
409 my @header_sort = qw(variable value unit);
410 my %header_title = ( "variable" => $locale->text("Variable"),
411 "value" => $locale->text("Value"),
412 "unit" => $locale->text("Unit"),
415 my @variable = map(+{ "description" => $variable_list{$_},
417 "unit" => $unit_list{$_} }, @variable_sort);
420 map(+{ "column_title" => $header_title{$_},
424 $form->{formel} = $formel;
425 $form->{"title"} = $locale->text("Please enter values");
427 print($form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
428 "VARIABLES" => \@variable,
429 "onload" => $onload }));
431 $lxdebug->leave_sub();
434 sub set_longdescription {
435 $lxdebug->enter_sub();
438 my $callback = "$form->{script}?action=set_longdescription&";
439 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
440 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
442 $form->{"title"} = $locale->text("Enter longdescription");
444 print($form->parse_html_template("generic/set_longdescription"));
446 $lxdebug->leave_sub();
450 return $form->quote_html($_[0]);
454 return $form->quote($_[0]);
458 return $form->escape($_[0]);
464 $element =~ s/tabindex\s*=\s*"\d+"//;
469 $lxdebug->enter_sub();
471 my ($dateformat, $longformat, @indices) = @_;
473 $dateformat = $myconfig{"dateformat"} unless ($dateformat);
475 foreach my $idx (@indices) {
476 next unless (defined($form->{$idx}));
478 if (!ref($form->{$idx})) {
479 $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
480 $dateformat, $longformat);
482 } elsif (ref($form->{$idx}) eq "ARRAY") {
483 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
484 $form->{$idx}->[$i] =
485 $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
486 $dateformat, $longformat);
491 $lxdebug->leave_sub();
494 sub reformat_numbers {
495 $lxdebug->enter_sub();
497 my ($numberformat, $places, @indices) = @_;
499 return $lxdebug->leave_sub()
500 if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
502 foreach my $idx (@indices) {
503 next unless (defined($form->{$idx}));
505 if (!ref($form->{$idx})) {
506 $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
508 } elsif (ref($form->{$idx}) eq "ARRAY") {
509 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
510 $form->{$idx}->[$i] =
511 $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
516 my $saved_numberformat = $myconfig{"numberformat"};
517 $myconfig{"numberformat"} = $numberformat;
519 foreach my $idx (@indices) {
520 next unless (defined($form->{$idx}));
522 if (!ref($form->{$idx})) {
523 $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
525 } elsif (ref($form->{$idx}) eq "ARRAY") {
526 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
527 $form->{$idx}->[$i] =
528 $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
533 $myconfig{"numberformat"} = $saved_numberformat;
535 $lxdebug->leave_sub();
539 $lxdebug->enter_sub();
540 my $dbh = $form->dbconnect(\%myconfig);
541 my ($sort, $sortby) = split(/\-\-/, $form->{order});
542 $sort =~ s/.*\.(.*)/$1/;
544 $form->{title} = $locale->text("History");
546 print $form->parse_html_template( "common/show_history", {
547 "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}),
548 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
550 uc($sort)."BY" => $sortby
554 $lxdebug->leave_sub();
558 $lxdebug->enter_sub();
563 $form->error($locale->text("Trying to call a sub without a name"));
566 $name =~ s/[^a-zA-Z0-9_]//g;
568 if (!defined(&{ $name })) {
569 $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
574 $lxdebug->leave_sub();
577 sub show_vc_details {
578 $lxdebug->enter_sub();
580 $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
581 $form->isblank("vc_id",
582 $form->{vc} eq "customer" ?
583 $locale->text("No customer has been selected yet.") :
584 $locale->text("No vendor has been selected yet."));
586 Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
588 $form->{title} = $form->{vc} eq "customer" ?
589 $locale->text("Customer details") : $locale->text("Vendor details");
591 print($form->parse_html_template("common/show_vc_details",
592 { "is_customer" => $form->{vc} eq "customer" }));
594 $lxdebug->leave_sub();