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 $form->{title} = $locale->text("Please enter values");
185 $form->header(no_layout => 1);
186 print $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header,
187 "VARIABLES" => \@variable, });
189 $main::lxdebug->leave_sub();
192 # -------------------------------------------------------------------------
195 return $main::locale->quote_special_chars('HTML', $_[0]);
199 return $main::locale->quote_special_chars('URL@HTML', $_[0]);
203 return $main::form->escape($_[0]);
209 $element =~ s/tabindex\s*=\s*"\d+"//;
214 return $::form->format_dates(@_);
217 sub reformat_numbers {
218 return $::form->reformat_numbers(@_);
221 # -------------------------------------------------------------------------
224 $main::lxdebug->enter_sub();
226 my $form = $main::form;
227 my %myconfig = %main::myconfig;
228 my $locale = $main::locale;
230 my $dbh = $form->dbconnect(\%myconfig);
231 my ($sort, $sortby) = split(/\-\-/, $form->{order});
232 $sort =~ s/.*\.(.*)/$1/;
234 $form->{title} = $locale->text("History");
235 $form->header(no_layout => 1);
237 my $callback = build_std_url(qw(action longdescription trans_id_type input_name));
239 if ( $form->{trans_id_type} eq 'glid' ) {
240 $restriction = "AND ( snumbers LIKE 'invnumber%' OR what_done LIKE '%Buchungsnummer%' OR snumbers LIKE 'gltransaction%' ) ";
241 } elsif ( $form->{trans_id_type} eq 'id' ) {
242 $restriction = " AND ( snumbers NOT LIKE 'invnumber_%' AND snumbers NOT LIKE 'gltransaction%' AND (what_done NOT LIKE '%Buchungsnummer%' OR what_done IS null))";
247 print $form->parse_html_template( "common/show_history", {
248 "DATEN" => $form->get_history($dbh,$form->{input_name},$restriction,$form->{order}),
249 "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"),
251 uc($sort)."BY" => $sortby,
252 callback => $callback,
256 $main::lxdebug->leave_sub();
259 # -------------------------------------------------------------------------
262 $main::lxdebug->enter_sub();
266 my $form = $main::form;
267 my $locale = $main::locale;
270 $form->error($locale->text("Trying to call a sub without a name"));
273 $name =~ s/[^a-zA-Z0-9_]//g;
275 if (!defined(&{ $name })) {
276 $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
284 $main::lxdebug->leave_sub();
287 # -------------------------------------------------------------------------
289 sub show_vc_details {
290 $main::lxdebug->enter_sub();
292 my $form = $main::form;
293 my %myconfig = %main::myconfig;
294 my $locale = $main::locale;
296 $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
297 $form->isblank("vc_id",
298 $form->{vc} eq "customer" ?
299 $locale->text("No customer has been selected yet.") :
300 $locale->text("No vendor has been selected yet."));
302 Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id});
303 $form->{discount_as_percent} = $form->format_amount(\%::myconfig, $form->parse_amount(\%::myconfig, $form->{discount}) * 100, 2);
305 $form->{title} = $form->{vc} eq "customer" ?
306 $locale->text("Customer details") : $locale->text("Vendor details");
307 $form->header(no_layout => 1);
308 print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
310 $main::lxdebug->leave_sub();
313 # -------------------------------------------------------------------------
315 sub retrieve_partunits {
316 $main::lxdebug->enter_sub();
318 my $form = $main::form;
320 my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
323 my %partunits = IO->retrieve_partunits('part_ids' => \@part_ids);
325 foreach my $i (1..$form->{rowcount}) {
326 next unless ($form->{"id_${i}"});
327 $form->{"partunit_${i}"} = $partunits{$form->{"id_${i}"}};
331 $main::lxdebug->leave_sub();
334 # -------------------------------------------------------------------------
336 sub cov_selection_internal {
337 $main::lxdebug->enter_sub();
339 my $form = $main::form;
340 my %myconfig = %main::myconfig;
341 my $locale = $main::locale;
343 my $order_by = "name";
344 $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
346 $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
348 my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
350 my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
351 map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
353 if (0 == scalar(@{$covs})) {
354 $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
355 } elsif (1 == scalar(@{$covs})) {
356 $::request->{layout}->add_javascripts_inline("cov_selected('1')");
359 my $callback = "$form->{script}?action=cov_selection_internal&";
360 map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
361 (qw(name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
363 my @header_sort = qw(name address contact);
364 my %header_title = ( "name" => $locale->text("Name"),
365 "address" => $locale->text("Address"),
366 "contact" => $locale->text("Contact"),
370 map(+{ "column_title" => $header_title{$_},
372 "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
376 foreach my $cov (@{ $covs }) {
377 $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
378 $cov->{address} =~ s{^,}{}x;
379 $cov->{address} =~ s{\ +}{\ }gx;
381 $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_gender cp_title cp_givenname cp_name);
382 $cov->{contact} =~ s{\ +}{\ }gx;
385 $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");
387 print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
388 "COVS" => $covs, }));
390 $main::lxdebug->leave_sub();
394 # Functions to call add routines beneath different reports
397 $main::lxdebug->enter_sub();
399 print $::form->redirect_header('is.pl?action=add&type=invoice');
401 $main::lxdebug->leave_sub();
405 $main::lxdebug->enter_sub();
407 print $::form->redirect_header('ar.pl?action=add');
409 $main::lxdebug->leave_sub();
413 $main::lxdebug->enter_sub();
415 print $::form->redirect_header('ir.pl?action=add&type=invoice');
417 $main::lxdebug->leave_sub();
421 $main::lxdebug->enter_sub();
423 print $::form->redirect_header('ap.pl?action=add');
425 $main::lxdebug->leave_sub();
429 $main::lxdebug->enter_sub();
431 print $::form->redirect_header('gl.pl?action=add');
433 $main::lxdebug->leave_sub();
437 goto &SL::DB::Helper::Mappings::db;
440 sub continue { call_sub($::form->{nextsub}); }