Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 820f3066

Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt

  • ID 820f3066c313c0538f7abdf90b3a8e12a28449e2
  • Vorgänger 1118dab9
  • Nachfolger 7dfa1c0a

Eine neue Funktion eingebaut, mit der eine einzelne Datenbankverbindung zum Abholen verschiedener Funktionen genutzt werden kann. Diese Datenbankverbindung wird erst beim Ende der Lebenszeit von $form wieder geschlossen. Momentan bauen fast alle Backendfunktionen eine eigene Datenbankverbindung auf. Hiermit ist das teilweise überflüssig.

Unterschiede anzeigen:

SL/Form.pm
49 49
use SL::Common;
50 50
use CGI;
51 51

  
52
my $standard_dbh;
53

  
54
sub DESTROY {
55
  if ($standard_dbh) {
56
    $standard_dbh->disconnect();
57
    undef $standard_dbh;
58
  }
59
}
60

  
52 61
sub _input_to_hash {
53 62
  $main::lxdebug->enter_sub(2);
54 63

  
......
1074 1083
  return $dbh;
1075 1084
}
1076 1085

  
1086
sub get_standard_dbh {
1087
  $main::lxdebug->enter_sub(2);
1088

  
1089
  my ($self, $myconfig) = @_;
1090

  
1091
  $standard_dbh ||= $self->dbconnect_noauto($myconfig);
1092

  
1093
  $main::lxdebug->leave_sub(2);
1094

  
1095
  return $standard_dbh;
1096
}
1097

  
1077 1098
sub update_balance {
1078 1099
  $main::lxdebug->enter_sub();
1079 1100

  
......
1208 1229

  
1209 1230
  my ($self, $myconfig, $transdate) = @_;
1210 1231

  
1211
  if ($self->{payment_id}) {
1232
  return $main::lxdebug->leave_sub() unless ($self->{payment_id});
1212 1233

  
1213
    my $dbh = $self->dbconnect($myconfig);
1234
  my $dbh = $self->get_standard_dbh($myconfig);
1214 1235

  
1215
    my $query =
1216
      qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1217
      qq|FROM payment_terms p | .
1218
      qq|WHERE p.id = ?|;
1236
  my $query =
1237
    qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1238
    qq|FROM payment_terms p | .
1239
    qq|WHERE p.id = ?|;
1219 1240

  
1220
    ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1221
     $self->{payment_terms}) =
1222
       selectrow_query($self, $dbh, $query, $self->{payment_id});
1241
  ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1242
   $self->{payment_terms}) =
1243
     selectrow_query($self, $dbh, $query, $self->{payment_id});
1223 1244

  
1224
    if ($transdate eq "") {
1225
      if ($self->{invdate}) {
1226
        $transdate = $self->{invdate};
1227
      } else {
1228
        $transdate = $self->{transdate};
1229
      }
1245
  if ($transdate eq "") {
1246
    if ($self->{invdate}) {
1247
      $transdate = $self->{invdate};
1248
    } else {
1249
      $transdate = $self->{transdate};
1230 1250
    }
1251
  }
1231 1252

  
1232
    $query =
1233
      qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1234
      qq|FROM payment_terms|;
1235
    ($self->{netto_date}, $self->{skonto_date}) =
1236
      selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1237

  
1238
    my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
1239
    my $skonto_amount = $self->parse_amount($myconfig, $total) *
1240
      $self->{percent_skonto};
1241

  
1242
    $self->{skonto_amount} =
1243
      $self->format_amount($myconfig, $skonto_amount, 2);
1244

  
1245
    if ($self->{"language_id"}) {
1246
      $query =
1247
        qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1248
        qq|FROM translation_payment_terms t | .
1249
        qq|LEFT JOIN language l ON t.language_id = l.id | .
1250
        qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1251
      my ($description_long, $output_numberformat, $output_dateformat,
1252
        $output_longdates) =
1253
        selectrow_query($self, $dbh, $query,
1254
                        $self->{"language_id"}, $self->{"payment_id"});
1255

  
1256
      $self->{payment_terms} = $description_long if ($description_long);
1257

  
1258
      if ($output_dateformat) {
1259
        foreach my $key (qw(netto_date skonto_date)) {
1260
          $self->{$key} =
1261
            $main::locale->reformat_date($myconfig, $self->{$key},
1262
                                         $output_dateformat,
1263
                                         $output_longdates);
1264
        }
1265
      }
1253
  $query =
1254
    qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1255
    qq|FROM payment_terms|;
1256
  ($self->{netto_date}, $self->{skonto_date}) =
1257
    selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1258

  
1259
  my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
1260
  my $skonto_amount = $self->parse_amount($myconfig, $total) *
1261
    $self->{percent_skonto};
1266 1262

  
1267
      if ($output_numberformat &&
1268
          ($output_numberformat ne $myconfig->{"numberformat"})) {
1269
        my $saved_numberformat = $myconfig->{"numberformat"};
1270
        $myconfig->{"numberformat"} = $output_numberformat;
1271
        $self->{skonto_amount} =
1272
          $self->format_amount($myconfig, $skonto_amount, 2);
1273
        $myconfig->{"numberformat"} = $saved_numberformat;
1263
  $self->{skonto_amount} =
1264
    $self->format_amount($myconfig, $skonto_amount, 2);
1265

  
1266
  if ($self->{"language_id"}) {
1267
    $query =
1268
      qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1269
      qq|FROM translation_payment_terms t | .
1270
      qq|LEFT JOIN language l ON t.language_id = l.id | .
1271
      qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1272
    my ($description_long, $output_numberformat, $output_dateformat,
1273
      $output_longdates) =
1274
      selectrow_query($self, $dbh, $query,
1275
                      $self->{"language_id"}, $self->{"payment_id"});
1276

  
1277
    $self->{payment_terms} = $description_long if ($description_long);
1278

  
1279
    if ($output_dateformat) {
1280
      foreach my $key (qw(netto_date skonto_date)) {
1281
        $self->{$key} =
1282
          $main::locale->reformat_date($myconfig, $self->{$key},
1283
                                       $output_dateformat,
1284
                                       $output_longdates);
1274 1285
      }
1275 1286
    }
1276 1287

  
1277
    $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1278
    $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1279
    $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
1280
    $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
1281
    $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
1282
    $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1283
    $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1284
    $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1285
    $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1286
    $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1287

  
1288
    $dbh->disconnect;
1288
    if ($output_numberformat &&
1289
        ($output_numberformat ne $myconfig->{"numberformat"})) {
1290
      my $saved_numberformat = $myconfig->{"numberformat"};
1291
      $myconfig->{"numberformat"} = $output_numberformat;
1292
      $self->{skonto_amount} =
1293
        $self->format_amount($myconfig, $skonto_amount, 2);
1294
      $myconfig->{"numberformat"} = $saved_numberformat;
1295
    }
1289 1296
  }
1290 1297

  
1298
  $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1299
  $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1300
  $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
1301
  $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
1302
  $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
1303
  $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1304
  $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1305
  $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1306
  $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1307
  $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1308

  
1291 1309
  $main::lxdebug->leave_sub();
1292 1310

  
1293 1311
}
......
1300 1318
  my $template_code = "";
1301 1319

  
1302 1320
  if ($self->{language_id}) {
1303
    my $dbh = $self->dbconnect($myconfig);
1321
    my $dbh = $self->get_standard_dbh($myconfig);
1304 1322
    my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1305 1323
    ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1306
    $dbh->disconnect;
1307 1324
  }
1308 1325

  
1309 1326
  $main::lxdebug->leave_sub();
......
1319 1336
  my $template_code = "";
1320 1337

  
1321 1338
  if ($self->{printer_id}) {
1322
    my $dbh = $self->dbconnect($myconfig);
1339
    my $dbh = $self->get_standard_dbh($myconfig);
1323 1340
    my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1324 1341
    ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1325
    $dbh->disconnect;
1326 1342
  }
1327 1343

  
1328 1344
  $main::lxdebug->leave_sub();
......
1338 1354
  my $template_code = "";
1339 1355

  
1340 1356
  if ($self->{shipto_id}) {
1341
    my $dbh = $self->dbconnect($myconfig);
1357
    my $dbh = $self->get_standard_dbh($myconfig);
1342 1358
    my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1343 1359
    my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1344 1360
    map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1345
    $dbh->disconnect;
1346 1361
  }
1347 1362

  
1348 1363
  $main::lxdebug->leave_sub();
......
1399 1414
                                 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
1400 1415
             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
1401 1416
        do_query($self, $dbh, $query, $id, @values, $module);
1402
     }
1417
      }
1403 1418
    }
1404 1419
  }
1405 1420

  
......
1425 1440

  
1426 1441
  $main::lxdebug->leave_sub() and return unless $salesman_id;
1427 1442

  
1428
  my $dbh = $self->dbconnect($myconfig);
1443
  my $dbh = $self->get_standard_dbh($myconfig);
1429 1444

  
1430 1445
  my ($login) =
1431 1446
    selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|,
......
1444 1459
    map({ $self->{"salesman_$_"} =~ s/\\n/\n/g; } qw(address company));
1445 1460
  }
1446 1461

  
1447
  $dbh->disconnect();
1448

  
1449 1462
  $main::lxdebug->leave_sub();
1450 1463
}
1451 1464

  
......
1454 1467

  
1455 1468
  my ($self, $myconfig) = @_;
1456 1469

  
1457
  my $dbh = $self->dbconnect($myconfig);
1470
  my $dbh = $self->get_standard_dbh($myconfig);
1458 1471
  my $query = qq|SELECT current_date + terms_netto FROM payment_terms WHERE id = ?|;
1459 1472
  ($self->{duedate}) = selectrow_query($self, $dbh, $query, $self->{payment_id});
1460
  $dbh->disconnect();
1461 1473

  
1462 1474
  $main::lxdebug->leave_sub();
1463 1475
}
......
1738 1750
  my $self = shift;
1739 1751
  my %params = @_;
1740 1752

  
1741
  my $dbh = $self->dbconnect(\%main::myconfig);
1753
  my $dbh = $self->get_standard_dbh(\%main::myconfig);
1742 1754
  my ($sth, $query, $ref);
1743 1755

  
1744 1756
  my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
......
1814 1826
    $self->_get_departments($dbh, $params{"departments"});
1815 1827
  }
1816 1828

  
1817
  $dbh->disconnect();
1818

  
1819 1829
  $main::lxdebug->leave_sub();
1820 1830
}
1821 1831

  
......
1826 1836
  my ($self, $myconfig, $table) = @_;
1827 1837

  
1828 1838
  # connect to database
1829
  my $dbh = $self->dbconnect($myconfig);
1839
  my $dbh = $self->get_standard_dbh($myconfig);
1830 1840

  
1831 1841
  $table = $table eq "customer" ? "customer" : "vendor";
1832 1842
  my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
......
1875 1885
  my ($self, $myconfig, $table, $module) = @_;
1876 1886

  
1877 1887
  my $ref;
1878
  my $dbh = $self->dbconnect($myconfig);
1888
  my $dbh = $self->get_standard_dbh($myconfig);
1879 1889

  
1880 1890
  $table = $table eq "customer" ? "customer" : "vendor";
1881 1891

  
......
1945 1955

  
1946 1956
  $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
1947 1957

  
1948
  $dbh->disconnect;
1949

  
1950 1958
  $main::lxdebug->leave_sub();
1951 1959
}
1952 1960

  
......
1955 1963

  
1956 1964
  my ($self, $myconfig) = @_;
1957 1965

  
1958
  my $dbh = $self->dbconnect($myconfig);
1966
  my $dbh = $self->get_standard_dbh($myconfig);
1959 1967
  # get languages
1960 1968
  my $query = qq|SELECT id, description
1961 1969
                 FROM language
......
1983 1991

  
1984 1992
  $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
1985 1993

  
1986
  $dbh->disconnect;
1987 1994
  $main::lxdebug->leave_sub();
1988 1995
}
1989 1996

  
......
1993 2000

  
1994 2001
  my ($self, $myconfig, $table) = @_;
1995 2002

  
1996
  my $dbh = $self->dbconnect($myconfig);
2003
  my $dbh = $self->get_standard_dbh($myconfig);
1997 2004
  my $where;
1998 2005

  
1999 2006
  if ($table eq 'customer') {
......
2008 2015

  
2009 2016
  delete($self->{all_departments}) unless (@{ $self->{all_departments} });
2010 2017

  
2011
  $dbh->disconnect;
2012

  
2013 2018
  $main::lxdebug->leave_sub();
2014 2019
}
2015 2020

  
......
2033 2038
  # get last customers or vendors
2034 2039
  my ($query, $sth, $ref);
2035 2040

  
2036
  my $dbh = $provided_dbh ? $provided_dbh : $self->dbconnect($myconfig);
2041
  my $dbh = $provided_dbh ? $provided_dbh : $self->get_standard_dbh($myconfig);
2037 2042
  my %xkeyref = ();
2038 2043

  
2039 2044
  if (!$self->{id}) {
......
2227 2232

  
2228 2233
  }
2229 2234

  
2230
  $dbh->disconnect() unless $provided_dbh;
2231

  
2232 2235
  $main::lxdebug->leave_sub();
2233 2236
}
2234 2237

  
......
2276 2279

  
2277 2280
  my ($self, $myconfig, $thisdate, $days) = @_;
2278 2281

  
2279
  my $dbh = $self->dbconnect($myconfig);
2282
  my $dbh = $self->get_standard_dbh($myconfig);
2280 2283
  my $query;
2281 2284

  
2282 2285
  $days *= 1;
......
2291 2294

  
2292 2295
  ($thisdate) = selectrow_query($self, $dbh, $query);
2293 2296

  
2294
  $dbh->disconnect;
2295

  
2296 2297
  $main::lxdebug->leave_sub();
2297 2298

  
2298 2299
  return $thisdate;
......
2486 2487
    &get_employee($self, $dbh);
2487 2488
  }
2488 2489

  
2489
my $query =
2490
  my $query =
2490 2491
   qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
2491 2492
   qq|VALUES (?, (SELECT id FROM employee WHERE login = ?), ?, ?, ?)|;
2492
 my @values = (conv_i($self->{id}), $self->{login},
2493
               $self->{addition}, $self->{what_done}, "$self->{snumbers}");
2494
 do_query($self, $dbh, $query, @values);
2493
  my @values = (conv_i($self->{id}), $self->{login},
2494
                $self->{addition}, $self->{what_done}, "$self->{snumbers}");
2495
  do_query($self, $dbh, $query, @values);
2495 2496

  
2496 2497
  $main::lxdebug->leave_sub();
2497 2498
}
......
2602 2603

  
2603 2604
  my ($self, $myconfig, $p) = @_;
2604 2605

  
2605
  my $dbh = $self->dbconnect($myconfig);
2606
  my $dbh = $self->get_standard_dbh($myconfig);
2606 2607

  
2607 2608
  my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
2608 2609
                 FROM partsgroup pg
......
2641 2642

  
2642 2643
  $self->{all_partsgroup} = selectall_hashref_query($self, $dbh, $query, @values);
2643 2644

  
2644
  $dbh->disconnect;
2645 2645
  $main::lxdebug->leave_sub();
2646 2646
}
2647 2647

  
......
2650 2650

  
2651 2651
  my ($self, $myconfig, $p) = @_;
2652 2652

  
2653
  my $dbh = $self->dbconnect($myconfig);
2653
  my $dbh = $self->get_standard_dbh($myconfig);
2654 2654

  
2655 2655
  my $query = qq|SELECT p.id, p.pricegroup
2656 2656
                 FROM pricegroup p|;
......
2664 2664

  
2665 2665
  $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
2666 2666

  
2667
  $dbh->disconnect;
2668

  
2669 2667
  $main::lxdebug->leave_sub();
2670 2668
}
2671 2669

  
......
2678 2676

  
2679 2677
  my ($self, $myconfig, $dbh) = @_;
2680 2678

  
2681
  my $disconnect = 0;
2682
  if (! $dbh) {
2683
    $dbh = $self->dbconnect($myconfig);
2684
    $disconnect = 1;
2685
  }
2679
  $dbh ||= $self->get_standard_dbh($myconfig);
2686 2680

  
2687 2681
  # get years
2688 2682
  my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
......
2707 2701
    push @all_years, $enddate--;
2708 2702
  }
2709 2703

  
2710
  $dbh->disconnect if $disconnect;
2711

  
2712 2704
  return @all_years;
2713 2705

  
2714 2706
  $main::lxdebug->leave_sub();
2715 2707
}
2716 2708

  
2717

  
2718 2709
1;

Auch abrufbar als: Unified diff