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 ######################################################################
13 use SL::DB::Helper::Mappings;
15 use SL::DBUtils qw(do_query);
17 use SL::MoreCommon qw(restore_form save_form);
22 $main::lxdebug->enter_sub(2);
24 my $form = $main::form;
26 my $script = $form->{script};
30 foreach my $key (@_) {
33 if ($key =~ /(.*?)=(.*)/) {
41 foreach my $var ($form->flatten_variables($key)) {
42 push @parts, E($var->{key}) . '=' . E($var->{value});
47 my $url = "${script}?" . join('&', @parts);
49 $main::lxdebug->leave_sub(2);
54 # -------------------------------------------------------------------------
56 sub delivery_customer_selection {
57 $main::lxdebug->enter_sub();
59 my $form = $main::form;
60 my %myconfig = %main::myconfig;
61 my $locale = $main::locale;
63 my $order_by = "name";
64 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
66 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
68 my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
69 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
71 if (0 == scalar(@{$delivery})) {
72 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
73 } elsif (1 == scalar(@{$delivery})) {
74 $::request->{layout}->add_javascripts_inline("customer_selected('1')");
77 my $callback = "$form->{script}?action=delivery_customer_selection&";
78 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
79 (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
81 my @header_sort = qw(name customernumber address);
82 my %header_title = ( "name" => $locale->text("Name"),
83 "customernumber" => $locale->text("Customer Number"),
84 "address" => $locale->text("Address"),
88 map(+{ "column_title" => $header_title{$_},
90 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
94 $form->{"title"} = $locale->text("Select a Customer");
95 $form->header(no_layout => 1);
96 print $form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
97 "DELIVERY" => $delivery, });
99 $main::lxdebug->leave_sub();
102 # -------------------------------------------------------------------------
104 sub vendor_selection {
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my %myconfig = %main::myconfig;
109 my $locale = $main::locale;
111 my $order_by = "name";
112 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
114 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
116 my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
117 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
119 if (0 == scalar(@{$vendor})) {
120 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
121 } elsif (1 == scalar(@{$vendor})) {
122 $::request->{layout}->add_javascripts_inline("vendor_selected('1')");
125 my $callback = "$form->{script}?action=vendor_selection&";
126 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
127 (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
129 my @header_sort = qw(name customernumber address);
130 my %header_title = ( "name" => $locale->text("Name"),
131 "customernumber" => $locale->text("Customer Number"),
132 "address" => $locale->text("Address"),
136 map(+{ "column_title" => $header_title{$_},
138 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
142 $form->{"title"} = $locale->text("Select a Customer");
143 $form->header(no_layout => 1);
144 print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
145 "VENDOR" => $vendor, });
147 $main::lxdebug->leave_sub();
150 # -------------------------------------------------------------------------
153 $main::lxdebug->enter_sub();
155 my $form = $main::form;
156 my $locale = $main::locale;
158 $form->{formel} =~ s/\r\n//g;
160 my ($variable_string, $formel) = split /###/,$form->{formel};
163 foreach my $item (split m/;/, $variable_string) {
164 next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
172 my @header_sort = qw(variable value unit);
174 variable => $locale->text("Variable"),
175 value => $locale->text("Value"),
176 unit => $locale->text("Unit"),
179 column_title => $header_title{$_},
183 $form->{formel} = $formel;
184 my $html = $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
185 "VARIABLES" => \@variable, });
186 print $::form->ajax_response_header, $html;
188 $main::lxdebug->leave_sub();
191 # -------------------------------------------------------------------------
194 return $main::locale->quote_special_chars('HTML', $_[0]);
198 return $main::locale->quote_special_chars('URL@HTML', $_[0]);
202 return $main::form->escape($_[0]);
208 $element =~ s/tabindex\s*=\s*"\d+"//;
213 return $::form->format_dates(@_);
216 sub reformat_numbers {
217 return $::form->reformat_numbers(@_);
220 # -------------------------------------------------------------------------
223 $main::lxdebug->enter_sub();
225 my $form = $main::form;
226 my %myconfig = %main::myconfig;
227 my $locale = $main::locale;
229 my $dbh = $form->dbconnect(\%myconfig);
230 my ($sort, $sortby) = split(/\-\-/, $form->{order});
231 $sort =~ s/.*\.(.*)/$1/;
233 $form->{title} = $locale->text("History");
234 $form->header(no_layout => 1);
236 my $callback = build_std_url(qw(action longdescription trans_id_type input_name));
238 if ( $form->{trans_id_type} eq 'glid' ) {
239 $restriction = "AND ( snumbers LIKE 'invnumber%' OR what_done LIKE '%Buchungsnummer%' OR snumbers LIKE 'gltransaction%' OR snumbers LIKE 'emailjournal%' ) ";
240 } elsif ( $form->{trans_id_type} eq 'id' ) {
241 $restriction = " AND ( snumbers NOT LIKE 'invnumber_%' AND snumbers NOT LIKE 'gltransaction%' AND snumbers NOT LIKE 'emailjournal%' AND (what_done NOT LIKE '%Buchungsnummer%' OR what_done IS null))";
246 print $form->parse_html_template( "common/show_history", {
247 "DATEN" => $form->get_history($dbh,$form->{input_name},$restriction,$form->{order}),
248 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
250 uc($sort)."BY" => $sortby,
251 callback => $callback,
255 $main::lxdebug->leave_sub();
258 # -------------------------------------------------------------------------
261 $main::lxdebug->enter_sub();
265 my $form = $main::form;
266 my $locale = $main::locale;
269 $form->error($locale->text("Trying to call a sub without a name"));
272 $name =~ s/[^a-zA-Z0-9_]//g;
274 if (!defined(&{ $name })) {
275 $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
283 $main::lxdebug->leave_sub();
286 # -------------------------------------------------------------------------
288 sub show_vc_details {
289 $main::lxdebug->enter_sub();
291 my $form = $main::form;
292 my %myconfig = %main::myconfig;
293 my $locale = $main::locale;
295 $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
296 $form->isblank("vc_id",
297 $form->{vc} eq "customer" ?
298 $locale->text("No customer has been selected yet.") :
299 $locale->text("No vendor has been selected yet."));
301 Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
302 $form->{discount_as_percent} = $form->format_amount(\%::myconfig, $form->parse_amount(\%::myconfig, $form->{discount}) * 100, 2);
304 $form->{title} = $form->{vc} eq "customer" ?
305 $locale->text("Customer details") : $locale->text("Vendor details");
306 $form->header(no_layout => 1);
307 print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
309 $main::lxdebug->leave_sub();
312 # -------------------------------------------------------------------------
314 sub retrieve_partunits {
315 $main::lxdebug->enter_sub();
317 my $form = $main::form;
319 my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
322 my %partunits = IO->retrieve_partunits('part_ids' => \@part_ids);
324 foreach my $i (1..$form->{rowcount}) {
325 next unless ($form->{"id_${i}"});
326 $form->{"partunit_${i}"} = $partunits{$form->{"id_${i}"}};
330 $main::lxdebug->leave_sub();
333 # -------------------------------------------------------------------------
338 # Functions to call add routines beneath different reports
341 $main::lxdebug->enter_sub();
343 print $::form->redirect_header('is.pl?action=add&type=invoice');
345 $main::lxdebug->leave_sub();
349 $main::lxdebug->enter_sub();
351 print $::form->redirect_header('ar.pl?action=add');
353 $main::lxdebug->leave_sub();
357 $main::lxdebug->enter_sub();
359 print $::form->redirect_header('ir.pl?action=add&type=invoice');
361 $main::lxdebug->leave_sub();
365 $main::lxdebug->enter_sub();
367 print $::form->redirect_header('ap.pl?action=add');
369 $main::lxdebug->leave_sub();
373 $main::lxdebug->enter_sub();
375 print $::form->redirect_header('gl.pl?action=add');
377 $main::lxdebug->leave_sub();
381 goto &SL::DB::Helper::Mappings::db;
384 sub continue { call_sub($::form->{nextsub}); }