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 $url = "$form->{script}?";
50 foreach my $key ((qw(login password path), @_)) {
52 $url .= "&" unless ($first);
58 $url .= "${key}=" . E($form->{$key});
62 $lxdebug->leave_sub();
68 $lxdebug->enter_sub();
70 my ($callback_sub, @employees) = @_;
72 if (0 == scalar(@employees)) {
73 @employees = SystemBrace->get_all_employees(\%myconfig, $form);
76 my $old_form = save_form();
79 print($form->parse_html_template("generic/select_employee",
80 { "EMPLOYEES" => \@employees,
81 "old_form" => $old_form,
82 "title" => $locale->text("Select an employee"),
83 "nextsub" => "select_employee_internal",
84 "callback_sub" => $callback_sub }));
86 $lxdebug->leave_sub();
89 sub select_employee_internal {
90 $lxdebug->enter_sub();
92 my ($new_id, $new_name, $callback_sub);
94 my $new_id = $form->{"new_id_" . $form->{"selection"}};
95 my $new_name = $form->{"new_name_" . $form->{"selection"}};
96 my $callback_sub = $form->{"callback_sub"};
98 restore_form($form->{"old_form"});
100 &{ $callback_sub }($new_id, $new_name);
102 $lxdebug->leave_sub();
106 $lxdebug->enter_sub();
108 my ($callback_sub, @parts) = @_;
110 my $remap_parts_id = 0;
111 if (defined($parts[0]->{"parts_id"}) && !defined($parts[0]->{"id"})) {
113 map({ $_->{"id"} = $_->{"parts_id"}; } @parts);
116 my $remap_partnumber = 0;
117 if (defined($parts[0]->{"partnumber"}) && !defined($parts[0]->{"number"})) {
118 $remap_partnumber = 1;
119 map({ $_->{"number"} = $_->{"partnumber"}; } @parts);
123 if (defined($parts[0]->{"chargenumber"})) {
125 map({ $_->{"has_charge"} = 1; } @parts);
128 my $old_form = save_form();
131 print($form->parse_html_template("generic/select_part",
132 { "PARTS" => \@parts,
133 "old_form" => $old_form,
134 "title" => $locale->text("Select a part"),
135 "nextsub" => "select_part_internal",
136 "callback_sub" => $callback_sub,
137 "has_charge" => $has_charge,
138 "remap_parts_id" => $remap_parts_id,
139 "remap_partnumber" => $remap_partnumber }));
141 $lxdebug->leave_sub();
144 sub select_part_internal {
145 $lxdebug->enter_sub();
147 my ($new_item, $callback_sub);
149 my $re = "^new_.*_" . $form->{"selection"};
154 $new_item->{$key} = $form->{$_};
155 } grep(/$re/, keys(%{$form})));
157 if ($form->{"remap_parts_id"}) {
158 $new_item->{"parts_id"} = $new_item->{"id"};
159 delete($new_item->{"id"});
161 if ($form->{"remap_partnumber"}) {
162 $new_item->{"partnumber"} = $new_item->{"number"};
163 delete($new_item->{"number"});
166 my $callback_sub = $form->{"callback_sub"};
168 restore_form($form->{"old_form"});
170 &{ $callback_sub }($new_item);
172 $lxdebug->leave_sub();
175 sub part_selection_internal {
176 $lxdebug->enter_sub();
178 $order_by = "description";
179 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
181 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
183 $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
184 map({ $parts->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$parts}));
185 if (0 == scalar(@{$parts})) {
186 $form->show_generic_information($locale->text("No part was found matching the search parameters."));
187 } elsif (1 == scalar(@{$parts})) {
188 $onload = "part_selected('1')";
191 my $callback = "$form->{script}?action=part_selection_internal&";
192 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
193 (qw(login path password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form)));
195 my @header_sort = qw(partnumber description);
196 my %header_title = ( "partnumber" => $locale->text("Part Number"),
197 "description" => $locale->text("Part description"),
201 map(+{ "column_title" => $header_title{$_},
203 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
207 $form->{"title"} = $locale->text("Select a part");
209 print($form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
211 "onload" => $onload }));
213 $lxdebug->leave_sub();
216 sub project_selection_internal {
217 $lxdebug->enter_sub();
219 $order_by = "description";
220 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
222 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
224 $projects = Common->retrieve_projects(\%myconfig, $form, $order_by, $order_dir);
225 map({ $projects->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$projects}));
226 if (0 == scalar(@{$projects})) {
227 $form->show_generic_information($locale->text("No project was found matching the search parameters."));
228 } elsif (1 == scalar(@{$projects})) {
229 $onload = "project_selected('1')";
232 my $callback = "$form->{script}?action=project_selection_internal&";
233 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
234 (qw(login path password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form)));
236 my @header_sort = qw(projectnumber description);
237 my %header_title = ( "projectnumber" => $locale->text("Project Number"),
238 "description" => $locale->text("Project description"),
242 map(+{ "column_title" => $header_title{$_},
244 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
248 $form->{"title"} = $locale->text("Select a project");
250 print($form->parse_html_template("generic/project_selection", { "HEADER" => \@header,
251 "PROJECTS" => $projects,
252 "onload" => $onload }));
254 $lxdebug->leave_sub();
257 sub employee_selection_internal {
258 $lxdebug->enter_sub();
261 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
263 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
265 $employees = Common->retrieve_employees(\%myconfig, $form, $order_by, $order_dir);
266 map({ $employees->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$employees}));
267 if (0 == scalar(@{$employees})) {
268 $form->show_generic_information($locale->text("No employee was found matching the search parameters."));
269 } elsif (1 == scalar(@{$employees})) {
270 $onload = "employee_selected('1')";
273 my $callback = "$form->{script}?action=employee_selection_internal&";
274 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
275 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
277 my @header_sort = qw(name);
278 my %header_title = ( "name" => $locale->text("Name"),
282 map(+{ "column_title" => $header_title{$_},
284 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
288 $form->{"title"} = $locale->text("Select an employee");
290 print($form->parse_html_template("generic/employee_selection", { "HEADER" => \@header,
291 "EMPLOYEES" => $employees,
292 "onload" => $onload }));
294 $lxdebug->leave_sub();
297 sub delivery_customer_selection {
298 $lxdebug->enter_sub();
301 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
303 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
305 $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
306 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
307 if (0 == scalar(@{$delivery})) {
308 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
309 } elsif (1 == scalar(@{$delivery})) {
310 $onload = "customer_selected('1')";
313 my $callback = "$form->{script}?action=delivery_customer_selection&";
314 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
315 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
317 my @header_sort = qw(name customernumber address);
318 my %header_title = ( "name" => $locale->text("Name"),
319 "customernumber" => $locale->text("Customer Number"),
320 "address" => $locale->text("Address"),
324 map(+{ "column_title" => $header_title{$_},
326 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
330 $form->{"title"} = $locale->text("Select a Customer");
332 print($form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
333 "DELIVERY" => $delivery,
334 "onload" => $onload }));
336 $lxdebug->leave_sub();
339 sub vendor_selection {
340 $lxdebug->enter_sub();
343 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
345 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
347 $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
348 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
349 if (0 == scalar(@{$vendor})) {
350 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
351 } elsif (1 == scalar(@{$vendor})) {
352 $onload = "vendor_selected('1')";
355 my $callback = "$form->{script}?action=vendor_selection&";
356 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
357 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
359 my @header_sort = qw(name customernumber address);
360 my %header_title = ( "name" => $locale->text("Name"),
361 "customernumber" => $locale->text("Customer Number"),
362 "address" => $locale->text("Address"),
366 map(+{ "column_title" => $header_title{$_},
368 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
372 $form->{"title"} = $locale->text("Select a Customer");
374 print($form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
376 "onload" => $onload }));
378 $lxdebug->leave_sub();
382 $lxdebug->enter_sub();
384 my @variable_sort = ();
385 my %variable_list = ();
387 $form->{formel} =~ s/\r\n//g;
389 my ($variable_string, $formel) = split /###/,$form->{formel};
392 split /;/, $variable_string;
394 my($name, $valueunit) = split /=/,$item;
395 my($value, $unit) = split / /, $valueunit;
397 push(@variable_sort, $value);
398 $variable_list{$value} = $name;
399 $unit_list{$value} = $unit;
402 my @header_sort = qw(variable value unit);
403 my %header_title = ( "variable" => $locale->text("Variable"),
404 "value" => $locale->text("Value"),
405 "unit" => $locale->text("Unit"),
408 my @variable = map(+{ "description" => $variable_list{$_},
410 "unit" => $unit_list{$_} }, @variable_sort);
413 map(+{ "column_title" => $header_title{$_},
417 $form->{formel} = $formel;
418 $form->{"title"} = $locale->text("Please enter values");
420 print($form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
421 "VARIABLES" => \@variable,
422 "onload" => $onload }));
424 $lxdebug->leave_sub();
427 sub set_longdescription {
428 $lxdebug->enter_sub();
431 my $callback = "$form->{script}?action=set_longdescription&";
432 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
433 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
435 $form->{"title"} = $locale->text("Enter longdescription");
437 print($form->parse_html_template("generic/set_longdescription"));
439 $lxdebug->leave_sub();
443 return $form->quote_html($_[0]);
447 return $form->quote($_[0]);
451 return $form->escape($_[0]);
457 $element =~ s/tabindex\s*=\s*"\d+"//;
462 $lxdebug->enter_sub();
464 my ($dateformat, $longformat, @indices) = @_;
466 $dateformat = $myconfig{"dateformat"} unless ($dateformat);
468 foreach my $idx (@indices) {
469 next unless (defined($form->{$idx}));
471 if (!ref($form->{$idx})) {
472 $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
473 $dateformat, $longformat);
475 } elsif (ref($form->{$idx}) eq "ARRAY") {
476 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
477 $form->{$idx}->[$i] =
478 $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
479 $dateformat, $longformat);
484 $lxdebug->leave_sub();
487 sub reformat_numbers {
488 $lxdebug->enter_sub();
490 my ($numberformat, $places, @indices) = @_;
492 return $lxdebug->leave_sub()
493 if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
495 foreach my $idx (@indices) {
496 next unless (defined($form->{$idx}));
498 if (!ref($form->{$idx})) {
499 $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
501 } elsif (ref($form->{$idx}) eq "ARRAY") {
502 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
503 $form->{$idx}->[$i] =
504 $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
509 my $saved_numberformat = $myconfig{"numberformat"};
510 $myconfig{"numberformat"} = $numberformat;
512 foreach my $idx (@indices) {
513 next unless (defined($form->{$idx}));
515 if (!ref($form->{$idx})) {
516 $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
518 } elsif (ref($form->{$idx}) eq "ARRAY") {
519 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
520 $form->{$idx}->[$i] =
521 $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
526 $myconfig{"numberformat"} = $saved_numberformat;
528 $lxdebug->leave_sub();
532 $lxdebug->enter_sub();
533 my $dbh = $form->dbconnect(\%myconfig);
535 $form->{title} = $locale->text("History");
537 print $form->parse_html_template( "common/show_history", {
538 "DATEN" => $form->get_history($dbh,$form->{input_name}),
539 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0")
543 $lxdebug->leave_sub();