3616a4eeec07164c48b320b9e65b50070b077c94
[kivitendo-erp.git] / SL / CT.pm
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #  Contributors:
16 #
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #======================================================================
30 #
31 # backend code for customers and vendors
32 #
33 # CHANGE LOG:
34 #   DS. 2000-07-04  Created
35 #
36 #======================================================================
37
38 package CT;
39
40 sub get_tuple {
41   $main::lxdebug->enter_sub();
42
43   my ($self, $myconfig, $form) = @_;
44
45   my $dbh   = $form->dbconnect($myconfig);
46   my $query = qq|SELECT ct.*, b.id AS business, s.*, cp.*
47                  FROM $form->{db} ct
48                  LEFT JOIN business b on ct.business_id = b.id
49                  LEFT JOIN shipto s on ct.id = s.trans_id
50                  LEFT JOIN contacts cp on ct.id = cp.cp_cv_id
51                  WHERE ct.id = $form->{id}  order by cp.cp_id limit 1|;
52   my $sth = $dbh->prepare($query);
53   $sth->execute || $form->dberror($query);
54
55   my $ref = $sth->fetchrow_hashref(NAME_lc);
56
57   map { $form->{$_} = $ref->{$_} } keys %$ref;
58
59   $sth->finish;
60   if ($form->{salesman_id}) {
61     my $query = qq|SELECT ct.name AS salesman
62                   FROM $form->{db} ct
63                   WHERE ct.id = $form->{salesman_id}|;
64     my $sth = $dbh->prepare($query);
65     $sth->execute || $form->dberror($query);
66
67     my ($ref) = $sth->fetchrow_array();
68
69     $form->{salesman} = $ref;
70
71     $sth->finish;
72   }
73
74   # check if it is orphaned
75   my $arap = ($form->{db} eq 'customer') ? "ar" : "ap";
76   $query = qq|SELECT a.id
77               FROM $arap a
78               JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
79               WHERE ct.id = $form->{id}
80             UNION
81               SELECT a.id
82               FROM oe a
83               JOIN $form->{db} ct ON (a.$form->{db}_id = ct.id)
84               WHERE ct.id = $form->{id}|;
85   $sth = $dbh->prepare($query);
86   $sth->execute || $form->dberror($query);
87
88   unless ($sth->fetchrow_array) {
89     $form->{status} = "orphaned";
90   }
91   $sth->finish;
92
93   # get tax labels
94   $query = qq|SELECT c.accno, c.description
95               FROM chart c
96               JOIN tax t ON (t.chart_id = c.id)
97               WHERE c.link LIKE '%CT_tax%'
98               ORDER BY c.accno|;
99   $sth = $dbh->prepare($query);
100   $sth->execute || $form->dberror($query);
101
102   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
103     $form->{taxaccounts} .= "$ref->{accno} ";
104     $form->{tax}{ $ref->{accno} }{description} = $ref->{description};
105   }
106   $sth->finish;
107   chop $form->{taxaccounts};
108
109   # get taxes for customer/vendor
110   $query = qq|SELECT c.accno
111               FROM chart c
112               JOIN $form->{db}tax t ON (t.chart_id = c.id)
113               WHERE t.$form->{db}_id = $form->{id}|;
114   $sth = $dbh->prepare($query);
115   $sth->execute || $form->dberror($query);
116
117   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
118     $form->{tax}{ $ref->{accno} }{taxable} = 1;
119   }
120   $sth->finish;
121
122   # get business types
123   $query = qq|SELECT id, description
124               FROM business
125               ORDER BY 1|;
126   $sth = $dbh->prepare($query);
127   $sth->execute || $form->dberror($query);
128
129   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
130     push @{ $form->{all_business} }, $ref;
131   }
132   $sth->finish;
133
134   $dbh->disconnect;
135
136   $main::lxdebug->leave_sub();
137 }
138
139 ## LINET
140 sub query_titles_and_greetings {
141   $main::lxdebug->enter_sub();
142
143   my ($self, $myconfig, $form) = @_;
144   my (%tmp,  $ref);
145
146   my $dbh = $form->dbconnect($myconfig);
147
148   $query =
149     "SELECT DISTINCT(c.cp_greeting) FROM contacts c WHERE c.cp_greeting LIKE '%'";
150   $sth = $dbh->prepare($query);
151   $sth->execute() || $form->dberror($query);
152   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
153     next unless ($ref->{cp_greeting} =~ /[a-zA-Z]/);
154     $tmp{ $ref->{cp_greeting} } = 1;
155   }
156   $sth->finish();
157
158   @{ $form->{GREETINGS} } = sort(keys(%tmp));
159
160   %tmp = ();
161
162   $query =
163     "SELECT DISTINCT(c.cp_title) FROM contacts c WHERE c.cp_title LIKE '%'";
164   $sth = $dbh->prepare($query);
165   $sth->execute() || $form->dberror($query);
166   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
167     next unless ($ref->{cp_title} =~ /[a-zA-Z]/);
168     $tmp{ $ref->{cp_title} } = 1;
169   }
170   $sth->finish();
171
172   @{ $form->{TITLES} } = sort(keys(%tmp));
173
174   $dbh->disconnect();
175   $main::lxdebug->leave_sub();
176 }
177 ## /LINET
178
179 sub taxaccounts {
180   $main::lxdebug->enter_sub();
181
182   my ($self, $myconfig, $form) = @_;
183
184   my $dbh = $form->dbconnect($myconfig);
185
186   # get tax labels
187   my $query = qq|SELECT accno, description
188                  FROM chart c, tax t
189                  WHERE c.link LIKE '%CT_tax%'
190                  AND c.id = t.chart_id
191                  ORDER BY accno|;
192   $sth = $dbh->prepare($query);
193   $sth->execute || $form->dberror($query);
194
195   my $ref = ();
196   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
197     $form->{taxaccounts} .= "$ref->{accno} ";
198     $form->{tax}{ $ref->{accno} }{description} = $ref->{description};
199   }
200   $sth->finish;
201   chop $form->{taxaccounts};
202
203   # this is just for the selection for type of business
204   $query = qq|SELECT id, description
205               FROM business|;
206   $sth = $dbh->prepare($query);
207   $sth->execute || $form->dberror($query);
208
209   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
210     push @{ $form->{all_business} }, $ref;
211   }
212   $sth->finish;
213
214   $dbh->disconnect;
215
216   $main::lxdebug->leave_sub();
217 }
218
219 sub save_customer {
220   $main::lxdebug->enter_sub();
221
222   my ($self, $myconfig, $form) = @_;
223
224   # set pricegroup to default
225   if ($form->{klass}) { }
226   else { $form->{klass} = 0; }
227
228   # connect to database
229   my $dbh = $form->dbconnect($myconfig);
230 ##LINET
231   map({
232       $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
233         if ($form->{"selected_cp_${_}"});
234   } qw(title greeting));
235
236   #
237   # escape '
238   map { $form->{$_} =~ s/\'/\'\'/g }
239     qw(customernumber name street zipcode city country homepage contact notes cp_title cp_greeting language pricegroup);
240 ##/LINET
241   # assign value discount, terms, creditlimit
242   $form->{discount} = $form->parse_amount($myconfig, $form->{discount});
243   $form->{discount} /= 100;
244   $form->{terms}       *= 1;
245   $form->{taxincluded} *= 1;
246   $form->{obsolete}    *= 1;
247   $form->{business}    *= 1;
248   $form->{salesman_id} *= 1;
249   $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
250
251   my ($query, $sth, $f_id);
252
253   if ($form->{id}) {
254
255     $query = qq|SELECT id FROM customer
256                 WHERE customernumber = '$form->{customernumber}'|;
257     $sth = $dbh->prepare($query);
258     $sth->execute || $form->dberror($query);
259     (${f_id}) = $sth->fetchrow_array;
260     $sth->finish;
261     if ((${f_id} ne $form->{id}) and (${f_id} ne "")) {
262
263       $main::lxdebug->leave_sub();
264       return 3;
265     }
266     $query = qq|DELETE FROM customertax
267                 WHERE customer_id = $form->{id}|;
268     $dbh->do($query) || $form->dberror($query);
269
270     $query = qq|DELETE FROM shipto
271                 WHERE trans_id = $form->{id}|;
272     $dbh->do($query) || $form->dberror($query);
273   } else {
274
275     my $uid = rand() . time;
276
277     $uid .= $form->{login};
278
279     $uid = substr($uid, 2, 75);
280     if (!$form->{customernumber} && $form->{business}) {
281       $form->{customernumber} =
282         $form->update_business($myconfig, $form->{business});
283     }
284     if (!$form->{customernumber}) {
285       $form->{customernumber} =
286         $form->update_defaults($myconfig, "customernumber");
287     }
288
289     $query = qq|SELECT c.id FROM customer c
290                 WHERE c.customernumber = '$form->{customernumber}'|;
291     $sth = $dbh->prepare($query);
292     $sth->execute || $form->dberror($query);
293     (${f_id}) = $sth->fetchrow_array;
294     $sth->finish;
295     if (${f_id} ne "") {
296       $main::lxdebug->leave_sub();
297       return 3;
298     }
299
300     $query = qq|INSERT INTO customer (name)
301                 VALUES ('$uid')|;
302     $dbh->do($query) || $form->dberror($query);
303
304     $query = qq|SELECT c.id FROM customer c
305                 WHERE c.name = '$uid'|;
306     $sth = $dbh->prepare($query);
307     $sth->execute || $form->dberror($query);
308
309     ($form->{id}) = $sth->fetchrow_array;
310     $sth->finish;
311   }
312   $query = qq|UPDATE customer SET
313               customernumber = '$form->{customernumber}',
314               name = '$form->{name}',
315               department_1 = '$form->{department_1}',
316               department_2 = '$form->{department_2}',
317               street = '$form->{street}',
318               zipcode = '$form->{zipcode}',
319               city = '$form->{city}',
320               country = '$form->{country}',
321               homepage = '$form->{homepage}',
322               contact = '$form->{contact}',
323               phone = '$form->{phone}',
324               fax = '$form->{fax}',
325               email = '$form->{email}',
326               cc = '$form->{cc}',
327               bcc = '$form->{bcc}',
328               notes = '$form->{notes}',
329               discount = $form->{discount},
330               creditlimit = $form->{creditlimit},
331               terms = $form->{terms},
332               taxincluded = '$form->{taxincluded}',
333               business_id = $form->{business},
334               taxnumber = '$form->{taxnumber}',
335               sic_code = '$form->{sic}',
336               language = '$form->{language}',
337               account_number = '$form->{account_number}',
338               bank_code = '$form->{bank_code}',
339               bank = '$form->{bank}',
340               obsolete = '$form->{obsolete}',
341               ustid = '$form->{ustid}',
342               username = '$form->{username}',
343               salesman_id = '$form->{salesman_id}',
344               user_password = | . $dbh->quote($form->{user_password}) . qq|,
345               c_vendor_id = '$form->{c_vendor_id}',
346               klass = '$form->{klass}'
347               WHERE id = $form->{id}|;
348   $dbh->do($query) || $form->dberror($query);
349
350   if ($form->{cp_id}) {
351     $query = qq|UPDATE contacts SET
352                 cp_greeting = '$form->{cp_greeting}',
353                 cp_title = '$form->{cp_title}',
354                 cp_givenname = '$form->{cp_givenname}',
355                 cp_name = '$form->{cp_name}',
356                 cp_email = '$form->{cp_email}',
357                 cp_phone1 = '$form->{cp_phone1}',
358                 cp_phone2 = '$form->{cp_phone2}'
359                 WHERE cp_id = $form->{cp_id}|;
360   } elsif ($form->{cp_name} || $form->{cp_givenname}) {
361     $query =
362       qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, cp_name, cp_email, cp_phone1, cp_phone2)
363                   VALUES ($form->{id}, '$form->{cp_greeting}','$form->{cp_title}','$form->{cp_givenname}','$form->{cp_name}','$form->{cp_email}','$form->{cp_phone1}','$form->{cp_phone2}')|;
364   }
365   $dbh->do($query) || $form->dberror($query);
366
367   # save taxes
368   foreach $item (split / /, $form->{taxaccounts}) {
369     if ($form->{"tax_$item"}) {
370       $query = qq|INSERT INTO customertax (customer_id, chart_id)
371                   VALUES ($form->{id}, (SELECT c.id
372                                         FROM chart c
373                                         WHERE c.accno = '$item'))|;
374       $dbh->do($query) || $form->dberror($query);
375     }
376   }
377
378   # add shipto
379   $form->add_shipto($dbh, $form->{id});
380
381   $rc = $dbh->disconnect;
382
383   $main::lxdebug->leave_sub();
384   return $rc;
385 }
386
387 sub save_vendor {
388   $main::lxdebug->enter_sub();
389
390   my ($self, $myconfig, $form) = @_;
391
392   # connect to database
393   my $dbh = $form->dbconnect($myconfig);
394 ##LINET
395   map({
396       $form->{"cp_${_}"} = $form->{"selected_cp_${_}"}
397         if ($form->{"selected_cp_${_}"});
398   } qw(title greeting));
399
400   # escape '
401   map { $form->{$_} =~ s/\'/\'\'/g }
402     qw(vendornumber name street zipcode city country homepage contact notes cp_title cp_greeting language);
403 ##/LINET
404   $form->{discount} = $form->parse_amount($myconfig, $form->{discount});
405   $form->{discount} /= 100;
406   $form->{terms}       *= 1;
407   $form->{taxincluded} *= 1;
408   $form->{obsolete}    *= 1;
409   $form->{business}    *= 1;
410   $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit});
411
412   my $query;
413
414   if ($form->{id}) {
415     $query = qq|DELETE FROM vendortax
416                 WHERE vendor_id = $form->{id}|;
417     $dbh->do($query) || $form->dberror($query);
418
419     $query = qq|DELETE FROM shipto
420                 WHERE trans_id = $form->{id}|;
421     $dbh->do($query) || $form->dberror($query);
422   } else {
423     my $uid = time;
424     $uid .= $form->{login};
425     my $uid = rand() . time;
426     $uid .= $form->{login};
427     $uid = substr($uid, 2, 75);
428     $query = qq|INSERT INTO vendor (name)
429                 VALUES ('$uid')|;
430     $dbh->do($query) || $form->dberror($query);
431
432     $query = qq|SELECT v.id FROM vendor v
433                 WHERE v.name = '$uid'|;
434     $sth = $dbh->prepare($query);
435     $sth->execute || $form->dberror($query);
436
437     ($form->{id}) = $sth->fetchrow_array;
438     $sth->finish;
439     if (!$form->{vendornumber}) {
440       $form->{vendornumber} =
441         $form->update_defaults($myconfig, "vendornumber");
442     }
443
444   }
445
446 ##LINET
447   $query = qq|UPDATE vendor SET
448               vendornumber = '$form->{vendornumber}',
449               name = '$form->{name}',
450               department_1 = '$form->{department_1}',
451               department_2 = '$form->{department_2}',
452               street = '$form->{street}',
453               zipcode = '$form->{zipcode}',
454               city = '$form->{city}',
455               country = '$form->{country}',
456               homepage = '$form->{homepage}',
457               contact = '$form->{contact}',
458               phone = '$form->{phone}',
459               fax = '$form->{fax}',
460               email = '$form->{email}',
461               cc = '$form->{cc}',
462               bcc = '$form->{bcc}',
463               notes = '$form->{notes}',
464               terms = $form->{terms},
465               discount = $form->{discount},
466               creditlimit = $form->{creditlimit},
467               taxincluded = '$form->{taxincluded}',
468               gifi_accno = '$form->{gifi_accno}',
469               business_id = $form->{business},
470               taxnumber = '$form->{taxnumber}',
471               sic_code = '$form->{sic}',
472               language = '$form->{language}',
473               account_number = '$form->{account_number}',
474               bank_code = '$form->{bank_code}',
475               bank = '$form->{bank}',
476               obsolete = '$form->{obsolete}',
477               ustid = '$form->{ustid}',
478               username = '$form->{username}',
479               user_password = '$form->{user_password}',
480               v_customer_id = '$form->{v_customer_id}'
481               WHERE id = $form->{id}|;
482   $dbh->do($query) || $form->dberror($query);
483
484   if ($form->{cp_id}) {
485     $query = qq|UPDATE contacts SET
486                 cp_greeting = '$form->{cp_greeting}',
487                 cp_title = '$form->{cp_title}',
488                 cp_givenname = '$form->{cp_givenname}',
489                 cp_name = '$form->{cp_name}',
490                 cp_email = '$form->{cp_email}',
491                 cp_phone1 = '$form->{cp_phone1}',
492                 cp_phone2 = '$form->{cp_phone2}'
493                 WHERE cp_id = $form->{cp_id}|;
494   } elsif ($form->{cp_name} || $form->{cp_givenname}) {
495     $query =
496       qq|INSERT INTO contacts ( cp_cv_id, cp_greeting, cp_title, cp_givenname, cp_name, cp_email, cp_phone1, cp_phone2)
497                   VALUES ($form->{id}, '$form->{cp_greeting}','$form->{cp_title}','$form->{cp_givenname}','$form->{cp_name}','$form->{cp_email}','$form->{cp_phone1}','$form->{cp_phone2}')|;
498   }
499   $dbh->do($query) || $form->dberror($query);
500
501   # save taxes
502   foreach $item (split / /, $form->{taxaccounts}) {
503     if ($form->{"tax_$item"}) {
504       $query = qq|INSERT INTO vendortax (vendor_id, chart_id)
505                   VALUES ($form->{id}, (SELECT c.id
506                                         FROM chart c
507                                         WHERE c.accno = '$item'))|;
508       $dbh->do($query) || $form->dberror($query);
509     }
510   }
511
512   # add shipto
513   $form->add_shipto($dbh, $form->{id});
514
515   $rc = $dbh->disconnect;
516
517   $main::lxdebug->leave_sub();
518   return $rc;
519 }
520
521 sub delete {
522   $main::lxdebug->enter_sub();
523
524   my ($self, $myconfig, $form) = @_;
525
526   # connect to database
527   my $dbh = $form->dbconnect($myconfig);
528
529   # delete vendor
530   my $query = qq|DELETE FROM $form->{db}
531                  WHERE id = $form->{id}|;
532   $dbh->do($query) || $form->dberror($query);
533
534   $dbh->disconnect;
535
536   $main::lxdebug->leave_sub();
537 }
538
539 sub search {
540   $main::lxdebug->enter_sub();
541
542   my ($self, $myconfig, $form) = @_;
543
544   # connect to database
545   my $dbh = $form->dbconnect($myconfig);
546
547   my $where = "1 = 1";
548   $form->{sort} = "name" unless ($form->{sort});
549
550   if ($form->{"$form->{db}number"}) {
551     my $companynumber = $form->like(lc $form->{"$form->{db}number"});
552     $where .= " AND lower(ct.$form->{db}number) LIKE '$companynumber'";
553   }
554   if ($form->{name}) {
555     my $name = $form->like(lc $form->{name});
556     $where .= " AND lower(ct.name) LIKE '$name'";
557   }
558   if ($form->{contact}) {
559     my $contact = $form->like(lc $form->{contact});
560     $where .= " AND lower(ct.contact) LIKE '$contact'";
561   }
562   if ($form->{email}) {
563     my $email = $form->like(lc $form->{email});
564     $where .= " AND lower(ct.email) LIKE '$email'";
565   }
566
567   if ($form->{status} eq 'orphaned') {
568     $where .= qq| AND ct.id NOT IN (SELECT o.$form->{db}_id
569                                     FROM oe o, $form->{db} cv
570                                     WHERE cv.id = o.$form->{db}_id)|;
571     if ($form->{db} eq 'customer') {
572       $where .= qq| AND ct.id NOT IN (SELECT a.customer_id
573                                       FROM ar a, customer cv
574                                       WHERE cv.id = a.customer_id)|;
575     }
576     if ($form->{db} eq 'vendor') {
577       $where .= qq| AND ct.id NOT IN (SELECT a.vendor_id
578                                       FROM ap a, vendor cv
579                                       WHERE cv.id = a.vendor_id)|;
580     }
581     $form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = "";
582   }
583
584   my $query = qq|SELECT ct.*, b.description AS business
585                  FROM $form->{db} ct
586               LEFT JOIN business b ON (ct.business_id = b.id)
587                  WHERE $where|;
588
589   # redo for invoices, orders and quotations
590   if ($form->{l_invnumber} || $form->{l_ordnumber} || $form->{l_quonumber}) {
591
592     my ($ar, $union, $module);
593     $query = "";
594
595     if ($form->{l_invnumber}) {
596       $ar     = ($form->{db} eq 'customer') ? 'ar' : 'ap';
597       $module = ($ar         eq 'ar')       ? 'is' : 'ir';
598
599       $query = qq|SELECT ct.*, b.description AS business,
600                   a.invnumber, a.ordnumber, a.quonumber, a.id AS invid,
601                   '$module' AS module, 'invoice' AS formtype,
602                   (a.amount = a.paid) AS closed
603                   FROM $form->{db} ct
604                 JOIN $ar a ON (a.$form->{db}_id = ct.id)
605                 LEFT JOIN business b ON (ct.business_id = b.id)
606                   WHERE $where
607                   AND a.invoice = '1'|;
608
609       $union = qq|
610               UNION|;
611
612     }
613
614     if ($form->{l_ordnumber}) {
615       $query .= qq|$union
616                   SELECT ct.*, b.description AS business,
617                   ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid,
618                   'oe' AS module, 'order' AS formtype,
619                   o.closed
620                   FROM $form->{db} ct
621                 JOIN oe o ON (o.$form->{db}_id = ct.id)
622                 LEFT JOIN business b ON (ct.business_id = b.id)
623                   WHERE $where
624                   AND o.quotation = '0'|;
625
626       $union = qq|
627               UNION|;
628     }
629
630     if ($form->{l_quonumber}) {
631       $query .= qq|$union
632                   SELECT ct.*, b.description AS business,
633                   ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid,
634                   'oe' AS module, 'quotation' AS formtype,
635                   o.closed
636                   FROM $form->{db} ct
637                 JOIN oe o ON (o.$form->{db}_id = ct.id)
638                 LEFT JOIN business b ON (ct.business_id = b.id)
639                   WHERE $where
640                   AND o.quotation = '1'|;
641
642     }
643   }
644
645   $query .= qq|
646                  ORDER BY $form->{sort}|;
647
648   my $sth = $dbh->prepare($query);
649   $sth->execute || $form->dberror($query);
650 ##LINET
651   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
652     $ref->{address} = "";
653     map { $ref->{address} .= "$ref->{$_} "; } qw(street zipcode city country);
654     push @{ $form->{CT} }, $ref;
655   }
656 ##/LINET
657   $sth->finish;
658   $dbh->disconnect;
659
660   $main::lxdebug->leave_sub();
661 }
662
663 1;
664