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 =~ /(.*?)=(.*)/) {
37 } elsif ($1 eq 'fragment') {
45 foreach my $var ($form->flatten_variables($key)) {
46 push @parts, E($var->{key}) . '=' . E($var->{value});
51 my $url = "${script}?" . join('&', @parts) . (defined $fragment ? "#$fragment" : '');
53 $main::lxdebug->leave_sub(2);
58 # -------------------------------------------------------------------------
60 sub delivery_customer_selection {
61 $main::lxdebug->enter_sub();
63 my $form = $main::form;
64 my %myconfig = %main::myconfig;
65 my $locale = $main::locale;
67 my $order_by = "name";
68 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
70 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
72 my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
73 map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
75 if (0 == scalar(@{$delivery})) {
76 $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
77 } elsif (1 == scalar(@{$delivery})) {
78 $::request->{layout}->add_javascripts_inline("customer_selected('1')");
81 my $callback = "$form->{script}?action=delivery_customer_selection&";
82 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
83 (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
85 my @header_sort = qw(name customernumber address);
86 my %header_title = ( "name" => $locale->text("Name"),
87 "customernumber" => $locale->text("Customer Number"),
88 "address" => $locale->text("Address"),
92 map(+{ "column_title" => $header_title{$_},
94 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
98 $form->{"title"} = $locale->text("Select a Customer");
99 $form->header(no_layout => 1);
100 print $form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header,
101 "DELIVERY" => $delivery, });
103 $main::lxdebug->leave_sub();
106 # -------------------------------------------------------------------------
108 sub vendor_selection {
109 $main::lxdebug->enter_sub();
111 my $form = $main::form;
112 my %myconfig = %main::myconfig;
113 my $locale = $main::locale;
115 my $order_by = "name";
116 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
118 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
120 my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
121 map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
123 if (0 == scalar(@{$vendor})) {
124 $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
125 } elsif (1 == scalar(@{$vendor})) {
126 $::request->{layout}->add_javascripts_inline("vendor_selected('1')");
129 my $callback = "$form->{script}?action=vendor_selection&";
130 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
131 (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
133 my @header_sort = qw(name customernumber address);
134 my %header_title = ( "name" => $locale->text("Name"),
135 "customernumber" => $locale->text("Customer Number"),
136 "address" => $locale->text("Address"),
140 map(+{ "column_title" => $header_title{$_},
142 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
146 $form->{"title"} = $locale->text("Select a Customer");
147 $form->header(no_layout => 1);
148 print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header,
149 "VENDOR" => $vendor, });
151 $main::lxdebug->leave_sub();
154 # -------------------------------------------------------------------------
157 $main::lxdebug->enter_sub();
159 my $form = $main::form;
160 my $locale = $main::locale;
162 $form->{formel} =~ s/\r\n//g;
164 my ($variable_string, $formel) = split /###/,$form->{formel};
167 foreach my $item (split m/;/, $variable_string) {
168 next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
176 my @header_sort = qw(variable value unit);
178 variable => $locale->text("Variable"),
179 value => $locale->text("Value"),
180 unit => $locale->text("Unit"),
183 column_title => $header_title{$_},
187 $form->{formel} = $formel;
188 my $html = $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
189 "VARIABLES" => \@variable, });
190 print $::form->ajax_response_header, $html;
192 $main::lxdebug->leave_sub();
195 # -------------------------------------------------------------------------
198 return $main::locale->quote_special_chars('HTML', $_[0]);
202 return $main::locale->quote_special_chars('URL@HTML', $_[0]);
206 return $main::form->escape($_[0]);
212 $element =~ s/tabindex\s*=\s*"\d+"//;
217 return $::form->format_dates(@_);
220 sub reformat_numbers {
221 return $::form->reformat_numbers(@_);
224 # -------------------------------------------------------------------------
227 $main::lxdebug->enter_sub();
229 my $form = $main::form;
230 my %myconfig = %main::myconfig;
231 my $locale = $main::locale;
233 my $dbh = $form->dbconnect(\%myconfig);
234 my ($sort, $sortby) = split(/\-\-/, $form->{order});
235 $sort =~ s/.*\.(.*)/$1/;
237 $form->{title} = $locale->text("History");
238 $form->header(no_layout => 1);
240 my $callback = build_std_url(qw(action longdescription trans_id_type input_name));
242 if ( $form->{trans_id_type} eq 'glid' ) { # for invoices
243 $restriction = "AND ( snumbers LIKE 'invnumber%' OR what_done LIKE '%Buchungsnummer%' OR snumbers LIKE 'gltransaction%' OR (snumbers LIKE 'emailjournal%' AND what_done ~ 'invoice|credit_note') ) ";
244 } elsif ( $form->{trans_id_type} eq 'id' ) { # for non invoices
245 $restriction = " AND ( snumbers NOT LIKE 'invnumber_%' AND snumbers NOT LIKE 'gltransaction%' AND (what_done NOT LIKE '%Buchungsnummer%' AND what_done NOT LIKE '%invoice%' OR what_done IS null))";
250 print $form->parse_html_template( "common/show_history", {
251 "DATEN" => $form->get_history($dbh,$form->{input_name},$restriction,$form->{order}),
252 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
254 uc($sort)."BY" => $sortby,
255 callback => $callback,
259 $main::lxdebug->leave_sub();
262 # -------------------------------------------------------------------------
265 $main::lxdebug->enter_sub();
269 my $form = $main::form;
270 my $locale = $main::locale;
273 $form->error($locale->text("Trying to call a sub without a name"));
276 $name =~ s/[^a-zA-Z0-9_]//g;
278 if (!defined(&{ $name })) {
279 $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
287 $main::lxdebug->leave_sub();
290 # -------------------------------------------------------------------------
292 sub show_vc_details {
293 $main::lxdebug->enter_sub();
295 my $form = $main::form;
296 my %myconfig = %main::myconfig;
297 my $locale = $main::locale;
299 $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
300 $form->isblank("vc_id",
301 $form->{vc} eq "customer" ?
302 $locale->text("No customer has been selected yet.") :
303 $locale->text("No vendor has been selected yet."));
305 Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
306 $form->{discount_as_percent} = $form->format_amount(\%::myconfig, $form->parse_amount(\%::myconfig, $form->{discount}) * 100, 2);
308 $form->{title} = $form->{vc} eq "customer" ?
309 $locale->text("Customer details") : $locale->text("Vendor details");
310 $form->header(no_layout => 1);
311 print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
313 $main::lxdebug->leave_sub();
316 # -------------------------------------------------------------------------
318 sub retrieve_partunits {
319 $main::lxdebug->enter_sub();
321 my $form = $main::form;
323 my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
326 my %partunits = IO->retrieve_partunits('part_ids' => \@part_ids);
328 foreach my $i (1..$form->{rowcount}) {
329 next unless ($form->{"id_${i}"});
330 $form->{"partunit_${i}"} = $partunits{$form->{"id_${i}"}};
334 $main::lxdebug->leave_sub();
337 # -------------------------------------------------------------------------
342 # Functions to call add routines beneath different reports
345 $main::lxdebug->enter_sub();
347 print $::form->redirect_header('is.pl?action=add&type=invoice');
349 $main::lxdebug->leave_sub();
353 $main::lxdebug->enter_sub();
355 print $::form->redirect_header('ar.pl?action=add');
357 $main::lxdebug->leave_sub();
361 $main::lxdebug->enter_sub();
363 print $::form->redirect_header('ir.pl?action=add&type=invoice');
365 $main::lxdebug->leave_sub();
369 $main::lxdebug->enter_sub();
371 print $::form->redirect_header('ap.pl?action=add');
373 $main::lxdebug->leave_sub();
377 $main::lxdebug->enter_sub();
379 print $::form->redirect_header('gl.pl?action=add');
381 $main::lxdebug->leave_sub();
385 goto &SL::DB::Helper::Mappings::db;
388 sub continue { call_sub($::form->{nextsub}); }