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 ######################################################################
17 $lxdebug->enter_sub(2);
19 my $script = $form->{script};
23 foreach my $key ((qw(login password), @_)) {
26 if ($key =~ /(.*?)=(.*)/) {
34 push @parts, "${key}=" . E($form->{$key});
38 my $url = "${script}?" . join('&', @parts);
40 $lxdebug->leave_sub(2);
46 $lxdebug->enter_sub();
48 my ($callback_sub, @employees) = @_;
50 if (0 == scalar(@employees)) {
51 @employees = SystemBrace->get_all_employees(\%myconfig, $form);
54 my $old_form = save_form();
57 print($form->parse_html_template("generic/select_employee",
58 { "EMPLOYEES" => \@employees,
59 "old_form" => $old_form,
60 "title" => $locale->text("Select an employee"),
61 "nextsub" => "select_employee_internal",
62 "callback_sub" => $callback_sub }));
64 $lxdebug->leave_sub();
67 sub select_employee_internal {
68 $lxdebug->enter_sub();
70 my ($new_id, $new_name, $callback_sub);
72 my $new_id = $form->{"new_id_" . $form->{"selection"}};
73 my $new_name = $form->{"new_name_" . $form->{"selection"}};
74 my $callback_sub = $form->{"callback_sub"};
76 restore_form($form->{"old_form"});
78 call_sub($callback_sub, $new_id, $new_name);
80 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 my ($callback_sub, @parts) = @_;
88 my $remap_parts_id = 0;
89 if (defined($parts[0]->{"parts_id"}) && !defined($parts[0]->{"id"})) {
91 map({ $_->{"id"} = $_->{"parts_id"}; } @parts);
94 my $remap_partnumber = 0;
95 if (defined($parts[0]->{"partnumber"}) && !defined($parts[0]->{"number"})) {
96 $remap_partnumber = 1;
97 map({ $_->{"number"} = $_->{"partnumber"}; } @parts);
101 if (defined($parts[0]->{"chargenumber"})) {
103 map({ $_->{"has_charge"} = 1; } @parts);
106 my $old_form = save_form();
109 print($form->parse_html_template("generic/select_part",
110 { "PARTS" => \@parts,
111 "old_form" => $old_form,
112 "title" => $locale->text("Select a part"),
113 "nextsub" => "select_part_internal",
114 "callback_sub" => $callback_sub,
115 "has_charge" => $has_charge,
116 "remap_parts_id" => $remap_parts_id,
117 "remap_partnumber" => $remap_partnumber }));
119 $lxdebug->leave_sub();
122 sub select_part_internal {
123 $lxdebug->enter_sub();
125 my ($new_item, $callback_sub);
127 my $re = "^new_.*_" . $form->{"selection"};
132 $new_item->{$key} = $form->{$_};
133 } grep(/$re/, keys(%{$form})));
135 if ($form->{"remap_parts_id"}) {
136 $new_item->{"parts_id"} = $new_item->{"id"};
137 delete($new_item->{"id"});
139 if ($form->{"remap_partnumber"}) {
140 $new_item->{"partnumber"} = $new_item->{"number"};
141 delete($new_item->{"number"});
144 my $callback_sub = $form->{"callback_sub"};
146 restore_form($form->{"old_form"});
148 call_sub($callback_sub, $new_item);
150 $lxdebug->leave_sub();
153 sub part_selection_internal {
154 $lxdebug->enter_sub();
156 $order_by = "description";
157 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
159 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
161 $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
162 map({ $parts->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$parts}));
163 if (0 == scalar(@{$parts})) {
164 $form->show_generic_information($locale->text("No part was found matching the search parameters."));
165 } elsif (1 == scalar(@{$parts})) {
166 $onload = "part_selected('1')";
169 my $callback = "$form->{script}?action=part_selection_internal&";
170 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
171 (qw(login password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form)));
173 my @header_sort = qw(partnumber description);
174 my %header_title = ( "partnumber" => $locale->text("Part Number"),
175 "description" => $locale->text("Part description"),
179 map(+{ "column_title" => $header_title{$_},
181 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
185 $form->{"title"} = $locale->text("Select a part");
187 print($form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
189 "onload" => $onload }));
191 $lxdebug->leave_sub();
194 sub project_selection_internal {
195 $lxdebug->enter_sub();
197 $order_by = "description";
198 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
200 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
202 $projects = Common->retrieve_projects(\%myconfig, $form, $order_by, $order_dir);
203 map({ $projects->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$projects}));
204 if (0 == scalar(@{$projects})) {
205 $form->show_generic_information($locale->text("No project was found matching the search parameters."));
206 } elsif (1 == scalar(@{$projects})) {
207 $onload = "project_selected('1')";
210 my $callback = "$form->{script}?action=project_selection_internal&";
211 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
212 (qw(login password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form)));
214 my @header_sort = qw(projectnumber description);
215 my %header_title = ( "projectnumber" => $locale->text("Project Number"),
216 "description" => $locale->text("Project description"),
220 map(+{ "column_title" => $header_title{$_},
222 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
226 $form->{"title"} = $locale->text("Select a project");
228 print($form->parse_html_template("generic/project_selection", { "HEADER" => \@header,
229 "PROJECTS" => $projects,
230 "onload" => $onload }));
232 $lxdebug->leave_sub();
235 sub employee_selection_internal {
236 $lxdebug->enter_sub();
239 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
241 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
243 $employees = Common->retrieve_employees(\%myconfig, $form, $order_by, $order_dir);
244 map({ $employees->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$employees}));
245 if (0 == scalar(@{$employees})) {
246 $form->show_generic_information($locale->text("No employee was found matching the search parameters."));
247 } elsif (1 == scalar(@{$employees})) {
248 $onload = "employee_selected('1')";
251 my $callback = "$form->{script}?action=employee_selection_internal&";
252 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
253 (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
255 my @header_sort = qw(name);
256 my %header_title = ( "name" => $locale->text("Name"),
260 map(+{ "column_title" => $header_title{$_},
262 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
266 $form->{"title"} = $locale->text("Select an employee");
268 print($form->parse_html_template("generic/employee_selection", { "HEADER" => \@header,
269 "EMPLOYEES" => $employees,
270 "onload" => $onload }));
272 $lxdebug->leave_sub();
275 sub delivery_customer_selection {
276 $lxdebug->enter_sub();
279 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
281 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
283 $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
284 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
285 if (0 == scalar(@{$delivery})) {
286 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
287 } elsif (1 == scalar(@{$delivery})) {
288 $onload = "customer_selected('1')";
291 my $callback = "$form->{script}?action=delivery_customer_selection&";
292 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
293 (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
295 my @header_sort = qw(name customernumber address);
296 my %header_title = ( "name" => $locale->text("Name"),
297 "customernumber" => $locale->text("Customer Number"),
298 "address" => $locale->text("Address"),
302 map(+{ "column_title" => $header_title{$_},
304 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
308 $form->{"title"} = $locale->text("Select a Customer");
310 print $form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
311 "DELIVERY" => $delivery,
312 "onload" => $onload });
314 $lxdebug->leave_sub();
317 sub vendor_selection {
318 $lxdebug->enter_sub();
321 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
323 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
325 $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
326 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
327 if (0 == scalar(@{$vendor})) {
328 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
329 } elsif (1 == scalar(@{$vendor})) {
330 $onload = "vendor_selected('1')";
333 my $callback = "$form->{script}?action=vendor_selection&";
334 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
335 (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
337 my @header_sort = qw(name customernumber address);
338 my %header_title = ( "name" => $locale->text("Name"),
339 "customernumber" => $locale->text("Customer Number"),
340 "address" => $locale->text("Address"),
344 map(+{ "column_title" => $header_title{$_},
346 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
350 $form->{"title"} = $locale->text("Select a Customer");
352 print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
354 "onload" => $onload });
356 $lxdebug->leave_sub();
360 $lxdebug->enter_sub();
362 my @variable_sort = ();
363 my %variable_list = ();
365 $form->{formel} =~ s/\r\n//g;
367 my ($variable_string, $formel) = split /###/,$form->{formel};
370 split /;/, $variable_string;
372 my($name, $valueunit) = split /=/,$item;
373 my($value, $unit) = split / /, $valueunit;
375 push(@variable_sort, $value);
376 $variable_list{$value} = $name;
377 $unit_list{$value} = $unit;
380 my @header_sort = qw(variable value unit);
381 my %header_title = ( "variable" => $locale->text("Variable"),
382 "value" => $locale->text("Value"),
383 "unit" => $locale->text("Unit"),
386 my @variable = map(+{ "description" => $variable_list{$_},
388 "unit" => $unit_list{$_} }, @variable_sort);
391 map(+{ "column_title" => $header_title{$_},
395 $form->{formel} = $formel;
396 $form->{"title"} = $locale->text("Please enter values");
398 print($form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
399 "VARIABLES" => \@variable,
400 "onload" => $onload }));
402 $lxdebug->leave_sub();
405 sub set_longdescription {
406 $lxdebug->enter_sub();
408 $form->{title} = $locale->text("Enter longdescription");
410 print $form->parse_html_template("generic/set_longdescription");
412 $lxdebug->leave_sub();
416 return $form->quote_html($_[0]);
420 return $form->quote($_[0]);
424 return $form->escape($_[0]);
430 $element =~ s/tabindex\s*=\s*"\d+"//;
435 $lxdebug->enter_sub();
437 my ($dateformat, $longformat, @indices) = @_;
439 $dateformat = $myconfig{"dateformat"} unless ($dateformat);
441 foreach my $idx (@indices) {
442 next unless (defined($form->{$idx}));
444 if (!ref($form->{$idx})) {
445 $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
446 $dateformat, $longformat);
448 } elsif (ref($form->{$idx}) eq "ARRAY") {
449 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
450 $form->{$idx}->[$i] =
451 $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
452 $dateformat, $longformat);
457 $lxdebug->leave_sub();
460 sub reformat_numbers {
461 $lxdebug->enter_sub();
463 my ($numberformat, $places, @indices) = @_;
465 return $lxdebug->leave_sub()
466 if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
468 foreach my $idx (@indices) {
469 next unless (defined($form->{$idx}));
471 if (!ref($form->{$idx})) {
472 $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
474 } elsif (ref($form->{$idx}) eq "ARRAY") {
475 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
476 $form->{$idx}->[$i] =
477 $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
482 my $saved_numberformat = $myconfig{"numberformat"};
483 $myconfig{"numberformat"} = $numberformat;
485 foreach my $idx (@indices) {
486 next unless (defined($form->{$idx}));
488 if (!ref($form->{$idx})) {
489 $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
491 } elsif (ref($form->{$idx}) eq "ARRAY") {
492 for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
493 $form->{$idx}->[$i] =
494 $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
499 $myconfig{"numberformat"} = $saved_numberformat;
501 $lxdebug->leave_sub();
505 $lxdebug->enter_sub();
506 my $dbh = $form->dbconnect(\%myconfig);
507 my ($sort, $sortby) = split(/\-\-/, $form->{order});
508 $sort =~ s/.*\.(.*)/$1/;
510 $form->{title} = $locale->text("History");
512 print $form->parse_html_template( "common/show_history", {
513 "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}),
514 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
516 uc($sort)."BY" => $sortby
520 $lxdebug->leave_sub();
524 $lxdebug->enter_sub();
529 $form->error($locale->text("Trying to call a sub without a name"));
532 $name =~ s/[^a-zA-Z0-9_]//g;
534 if (!defined(&{ $name })) {
535 $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
540 $lxdebug->leave_sub();
543 sub show_vc_details {
544 $lxdebug->enter_sub();
546 $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
547 $form->isblank("vc_id",
548 $form->{vc} eq "customer" ?
549 $locale->text("No customer has been selected yet.") :
550 $locale->text("No vendor has been selected yet."));
552 Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
554 $form->{title} = $form->{vc} eq "customer" ?
555 $locale->text("Customer details") : $locale->text("Vendor details");
557 print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
559 $lxdebug->leave_sub();
562 sub mark_as_paid_common {
563 $lxdebug->enter_sub();
565 my ($myconfig, $db_name) = @_;
567 if($form->{mark_as_paid}) {
568 my $dbh ||= $form->get_standard_dbh($myconfig);
569 my $query = qq|UPDATE $db_name SET paid = amount WHERE id = ?|;
570 do_query($form, $dbh, $query, $form->{id});
572 $form->redirect($locale->text("Marked as paid"));
575 my $referer = $ENV{HTTP_REFERER};
576 my $login = $form->escape($form->{login});
577 my $password = $form->escape($form->{password});
578 my $id = $form->escape($form->{id});
579 $referer =~ s/^(.*)action\=.*\&(.*)$/$1action\=mark_as_paid\&mark_as_paid\=1\&login\=$login\&password\=$password\&id\=$id\&$2/;
582 print qq|<p><b>|.$locale->text('Mark as paid?').qq|</b></p>|;
583 print qq|<input type="button" value="|.$locale->text('yes').qq|" onclick="document.location.href='|.$referer.qq|'"> |;
584 print qq|<input type="button" value="|.$locale->text('no').qq|" onclick="javascript:history.back();">|;
585 print qq|</body></html>|;
588 $lxdebug->leave_sub();