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();
20 map({ $old_form .= "$_=" . $form->escape($form->{$_}) . '&'; } keys(%{$form}));
23 $lxdebug->leave_sub();
29 $lxdebug->enter_sub();
33 map({ delete($form->{$_}); } keys(%{$form}));
35 foreach my $pair (split('&', $old_form)) {
36 my ($key, $value) = split('=', $form->unescape($pair), 2);
37 $form->{$key} = $value;
40 $lxdebug->leave_sub();
44 $lxdebug->enter_sub();
46 my ($callback_sub, @employees) = @_;
48 if (0 == scalar(@employees)) {
49 @employees = SystemBrace->get_all_employees(\%myconfig, $form);
52 my $old_form = save_form();
55 print($form->parse_html_template("generic/select_employee",
56 { "EMPLOYEES" => \@employees,
57 "old_form" => $old_form,
58 "title" => $locale->text("Select an employee"),
59 "nextsub" => "select_employee_internal",
60 "callback_sub" => $callback_sub }));
62 $lxdebug->leave_sub();
65 sub select_employee_internal {
66 $lxdebug->enter_sub();
68 my ($new_id, $new_name, $callback_sub);
70 my $new_id = $form->{"new_id_" . $form->{"selection"}};
71 my $new_name = $form->{"new_name_" . $form->{"selection"}};
72 my $callback_sub = $form->{"callback_sub"};
74 restore_form($form->{"old_form"});
76 &{ $callback_sub }($new_id, $new_name);
78 $lxdebug->leave_sub();
82 $lxdebug->enter_sub();
84 my ($callback_sub, @parts) = @_;
86 my $remap_parts_id = 0;
87 if (defined($parts[0]->{"parts_id"}) && !defined($parts[0]->{"id"})) {
89 map({ $_->{"id"} = $_->{"parts_id"}; } @parts);
92 my $remap_partnumber = 0;
93 if (defined($parts[0]->{"partnumber"}) && !defined($parts[0]->{"number"})) {
94 $remap_partnumber = 1;
95 map({ $_->{"number"} = $_->{"partnumber"}; } @parts);
99 if (defined($parts[0]->{"chargenumber"})) {
101 map({ $_->{"has_charge"} = 1; } @parts);
104 my $old_form = save_form();
107 print($form->parse_html_template("generic/select_part",
108 { "PARTS" => \@parts,
109 "old_form" => $old_form,
110 "title" => $locale->text("Select a part"),
111 "nextsub" => "select_part_internal",
112 "callback_sub" => $callback_sub,
113 "has_charge" => $has_charge,
114 "remap_parts_id" => $remap_parts_id,
115 "remap_partnumber" => $remap_partnumber }));
117 $lxdebug->leave_sub();
120 sub select_part_internal {
121 $lxdebug->enter_sub();
123 my ($new_item, $callback_sub);
125 my $re = "^new_.*_" . $form->{"selection"};
130 $new_item->{$key} = $form->{$_};
131 } grep(/$re/, keys(%{$form})));
133 if ($form->{"remap_parts_id"}) {
134 $new_item->{"parts_id"} = $new_item->{"id"};
135 delete($new_item->{"id"});
137 if ($form->{"remap_partnumber"}) {
138 $new_item->{"partnumber"} = $new_item->{"number"};
139 delete($new_item->{"number"});
142 my $callback_sub = $form->{"callback_sub"};
144 restore_form($form->{"old_form"});
146 &{ $callback_sub }($new_item);
148 $lxdebug->leave_sub();
151 sub part_selection_internal {
152 $lxdebug->enter_sub();
154 $order_by = "description";
155 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
157 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
159 $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
160 map({ $parts->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$parts}));
161 if (0 == scalar(@{$parts})) {
162 $form->show_generic_information($locale->text("No part was found matching the search parameters."));
163 } elsif (1 == scalar(@{$parts})) {
164 $onload = "part_selected('1')";
167 my $callback = "$form->{script}?action=part_selection_internal&";
168 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
169 (qw(login path password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form)));
171 my @header_sort = qw(partnumber description);
172 my %header_title = ( "partnumber" => $locale->text("Part Number"),
173 "description" => $locale->text("Part description"),
177 map(+{ "column_title" => $header_title{$_},
179 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
183 $form->{"title"} = $locale->text("Select a part");
185 print($form->parse_html_template("generic/part_selection", { "HEADER" => \@header,
187 "onload" => $onload }));
189 $lxdebug->leave_sub();
192 sub project_selection_internal {
193 $lxdebug->enter_sub();
195 $order_by = "description";
196 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
198 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
200 $projects = Common->retrieve_projects(\%myconfig, $form, $order_by, $order_dir);
201 map({ $projects->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$projects}));
202 if (0 == scalar(@{$projects})) {
203 $form->show_generic_information($locale->text("No project was found matching the search parameters."));
204 } elsif (1 == scalar(@{$projects})) {
205 $onload = "project_selected('1')";
208 my $callback = "$form->{script}?action=project_selection_internal&";
209 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
210 (qw(login path password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form)));
212 my @header_sort = qw(projectnumber description);
213 my %header_title = ( "projectnumber" => $locale->text("Project Number"),
214 "description" => $locale->text("Project description"),
218 map(+{ "column_title" => $header_title{$_},
220 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
224 $form->{"title"} = $locale->text("Select a project");
226 print($form->parse_html_template("generic/project_selection", { "HEADER" => \@header,
227 "PROJECTS" => $projects,
228 "onload" => $onload }));
230 $lxdebug->leave_sub();
233 sub employee_selection_internal {
234 $lxdebug->enter_sub();
237 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
239 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
241 $employees = Common->retrieve_employees(\%myconfig, $form, $order_by, $order_dir);
242 map({ $employees->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$employees}));
243 if (0 == scalar(@{$employees})) {
244 $form->show_generic_information($locale->text("No employee was found matching the search parameters."));
245 } elsif (1 == scalar(@{$employees})) {
246 $onload = "employee_selected('1')";
249 my $callback = "$form->{script}?action=employee_selection_internal&";
250 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
251 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
253 my @header_sort = qw(name);
254 my %header_title = ( "name" => $locale->text("Name"),
258 map(+{ "column_title" => $header_title{$_},
260 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
264 $form->{"title"} = $locale->text("Select an employee");
266 print($form->parse_html_template("generic/employee_selection", { "HEADER" => \@header,
267 "EMPLOYEES" => $employees,
268 "onload" => $onload }));
270 $lxdebug->leave_sub();
273 sub delivery_customer_selection {
274 $lxdebug->enter_sub();
277 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
279 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
281 $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
282 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
283 if (0 == scalar(@{$delivery})) {
284 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
285 } elsif (1 == scalar(@{$delivery})) {
286 $onload = "customer_selected('1')";
289 my $callback = "$form->{script}?action=delivery_customer_selection&";
290 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
291 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
293 my @header_sort = qw(name customernumber address);
294 my %header_title = ( "name" => $locale->text("Name"),
295 "customernumber" => $locale->text("Customer Number"),
296 "address" => $locale->text("Address"),
300 map(+{ "column_title" => $header_title{$_},
302 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
306 $form->{"title"} = $locale->text("Select a Customer");
308 print($form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
309 "DELIVERY" => $delivery,
310 "onload" => $onload }));
312 $lxdebug->leave_sub();
315 sub vendor_selection {
316 $lxdebug->enter_sub();
319 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
321 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
323 $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
324 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
325 if (0 == scalar(@{$vendor})) {
326 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
327 } elsif (1 == scalar(@{$vendor})) {
328 $onload = "vendor_selected('1')";
331 my $callback = "$form->{script}?action=vendor_selection&";
332 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
333 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
335 my @header_sort = qw(name customernumber address);
336 my %header_title = ( "name" => $locale->text("Name"),
337 "customernumber" => $locale->text("Customer Number"),
338 "address" => $locale->text("Address"),
342 map(+{ "column_title" => $header_title{$_},
344 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
348 $form->{"title"} = $locale->text("Select a Customer");
350 print($form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
352 "onload" => $onload }));
354 $lxdebug->leave_sub();
358 $lxdebug->enter_sub();
360 my @variable_sort = ();
361 my %variable_list = ();
363 $form->{formel} =~ s/\r\n//g;
365 my ($variable_string, $formel) = split /###/,$form->{formel};
368 split /;/, $variable_string;
370 my($name, $valueunit) = split /=/,$item;
371 my($value, $unit) = split / /, $valueunit;
373 push(@variable_sort, $value);
374 $variable_list{$value} = $name;
375 $unit_list{$value} = $unit;
378 my @header_sort = qw(variable value unit);
379 my %header_title = ( "variable" => $locale->text("Variable"),
380 "value" => $locale->text("Value"),
381 "unit" => $locale->text("Unit"),
384 my @variable = map(+{ "description" => $variable_list{$_},
386 "unit" => $unit_list{$_} }, @variable_sort);
389 map(+{ "column_title" => $header_title{$_},
393 $form->{formel} = $formel;
394 $form->{"title"} = $locale->text("Please enter values");
396 print($form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
397 "VARIABLES" => \@variable,
398 "onload" => $onload }));
400 $lxdebug->leave_sub();
404 $lxdebug->enter_sub();
408 my ($length, $weight) = split /\r\n/,$form->{formel};
410 #print(STDERR "$form->{formel} Formel\n");
411 #print(STDERR "$form->{description} Description\n");
413 map({ $form->{$_} = "" } (qw(qty_alu price_alu total_alu qty_eloxal price_eloxal total_eloxal total)));
415 if ($form->{description} =~ /.*Alupreisberechnung.*/) {
416 $form->{description} =~ /.*Alupreisberechnung:\n(.*)kg Aluminiumprofil Einzelpreis: (.*) Gesamt: (.*)\n(.*)m Eloxal Einzelpreis: (.*) Gesamt: (.*)/;
417 $form->{qty_alu} = $1;
418 $form->{price_alu} = $2;
419 $form->{total_alu} = $3;
420 $form->{qty_eloxal} = $4;
421 $form->{price_eloxal} = $5;
422 $form->{total_eloxal} = $6;
423 $form->{total} = $form->format_amount(\%myconfig, ($form->parse_amount(\%myconfig, $form->{total_alu}) + $form->parse_amount(\%myconfig, $form->{total_eloxal})));
425 ($form->{description}, $null) = split /\nAlupreisberechnung/, $form->{description};
426 #map({ print(STDERR "$_ = $form->{$_}\n") } (qw(qty_alu price_alu total_alu qty_eloxal price_eloxal total_eloxal total)));
428 my $callback = "$form->{script}?action=vendor_selection&";
429 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
430 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
432 my @header_sort = qw(name customernumber address);
433 my %header_title = ( "name" => $locale->text("Name"),
434 "customernumber" => $locale->text("Customer Number"),
435 "address" => $locale->text("Address"),
437 ($null, $form->{weight}) = split / /, $weight;
438 ($null, $form->{length}) = split / /, $length;
440 $form->{calc_weight} = $form->parse_amount(\%myconfig, $form->{weight});
441 $form->{calc_length} = $form->parse_amount(\%myconfig, $form->{length});
445 map(+{ "column_title" => $header_title{$_},
450 $form->{"title"} = $locale->text("Enter values for aluminium calculation");
452 print($form->parse_html_template("generic/calculate_alu"));
454 $lxdebug->leave_sub();
458 sub set_longdescription {
459 $lxdebug->enter_sub();
462 my $callback = "$form->{script}?action=set_longdescription&";
463 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
464 (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
466 $form->{"title"} = $locale->text("Enter longdescription");
468 print($form->parse_html_template("generic/set_longdescription"));
470 $lxdebug->leave_sub();