# Database routines used throughout
sub dbconnect {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $myconfig) = @_;
$dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
}
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return $dbh;
}
}
# get contacts for id, if no contact return {"","","","",""}
-sub get_contacts {
+sub _get_contacts {
$main::lxdebug->enter_sub();
my ($self, $dbh, $id, $key) = @_;
$main::lxdebug->leave_sub();
}
-sub get_projects {
+sub _get_projects {
$main::lxdebug->enter_sub();
my ($self, $dbh, $key) = @_;
$main::lxdebug->leave_sub();
}
+sub _get_shipto {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $vc_id, $key) = @_;
+
+ $key = "all_shipto" unless ($key);
+ $self->{$key} = [];
+
+ # get shipping addresses
+ my $query =
+ qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
+ qq|FROM shipto s | .
+ qq|WHERE s.trans_id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_printers {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_printers" unless ($key);
+ $self->{$key} = [];
+
+ my $query = qq|SELECT id, printer_description, printer_command FROM printers|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_charts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $params) = @_;
+
+ $key = $params->{key};
+ $key = "all_charts" unless ($key);
+ $self->{$key} = [];
+
+ my $transdate = quote_db_date($params->{transdate});
+
+ my $query =
+ qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
+ qq|FROM chart c | .
+ qq|LEFT JOIN taxkeys tk ON | .
+ qq|(tk.id = (SELECT id FROM taxkeys | .
+ qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
+ qq| ORDER BY startdate DESC LIMIT 1)) | .
+ qq|ORDER BY c.accno|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_taxcharts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_taxcharts" unless ($key);
+ $self->{$key} = [];
+
+ my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
sub get_lists {
$main::lxdebug->enter_sub();
my $vc_id = $self->{"${vc}_id"};
if ($params{"contacts"}) {
- $self->get_contacts($dbh, $vc_id, $params{"contacts"});
+ $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
}
if ($params{"shipto"}) {
- # get shipping addresses
- $query =
- qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
- qq|FROM shipto s | .
- qq|WHERE s.trans_id = ?|;
- $sth = $dbh->prepare($query);
- $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
-
- $self->{$params{"shipto"}} = [];
- while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
- push(@{ $self->{$params{"shipto"}} }, $ref);
- }
- $sth->finish;
+ $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
}
if ($params{"projects"} || $params{"all_projects"}) {
- $self->get_projects($dbh, $params{"all_projects"} ?
- $params{"all_projects"} : $params{"projects"},
- $params{"all_projects"} ? 1 : 0);
+ $self->_get_projects($dbh, $params{"all_projects"} ?
+ $params{"all_projects"} : $params{"projects"},
+ $params{"all_projects"} ? 1 : 0);
+ }
+
+ if ($params{"printers"}) {
+ $self->_get_printers($dbh, $params{"printers"});
+ }
+
+ if ($params{"charts"}) {
+ $self->_get_charts($dbh, $params{"charts"});
+ }
+
+ if ($params{"taxcharts"}) {
+ $self->_get_taxcharts($dbh, $params{"taxcharts"});
}
$dbh->disconnect();
&get_employee($self, $dbh);
}
- my $query = qq|INSERT INTO status (trans_id, employee_id, addition, what_done)
- VALUES ($self->{id}, $self->{employee_id}, '$self->{addition}', '$self->{what_done}')|;
- $dbh->do($query) || $self->dberror($query);
+ my $query =
+ qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done) | .
+ qq|VALUES (?, ?, ?, ?)|;
+ my @values = (conv_i($self->{id}), conv_i($self->{employee_id}),
+ $self->{addition}, $self->{what_done});
+ do_query($self, $dbh, $query, @values);
$main::lxdebug->leave_sub();
}
my $restriction = shift();
my @tempArray;
my $i = 0;
- if($trans_id ne ""){
- my $query = qq|SELECT st.employee_id, st.itime, st.addition, st.what_done, emp.name
- FROM status st
- LEFT JOIN employee emp
- ON emp.id = st.employee_id
- WHERE trans_id = $trans_id|
- . $restriction;
+ if ($trans_id ne "") {
+ my $query =
+ qq|SELECT h.employee_id, h.itime::timestamp(0) AS itime, h.addition, h.what_done, emp.name | .
+ qq|FROM history_erp h | .
+ qq|LEFT JOIN employee emp | .
+ qq|ON emp.id = h.employee_id | .
+ qq|WHERE trans_id = ? |
+ . $restriction;
my $sth = $dbh->prepare($query) || $self->dberror($query);
- $sth->execute() || $self->dberror($query);
+ $sth->execute($trans_id) || $self->dberror("$query ($trans_id)");
while(my $hash_ref = $sth->fetchrow_hashref()) {
$hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
$hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
$tempArray[$i++] = $hash_ref;
}
- return \@tempArray if ($i > 0 && $tempArray[0] ne "");
+ $main::lxdebug->leave_sub() and return \@tempArray
+ if ($i > 0 && $tempArray[0] ne "");
}
- return 0;
$main::lxdebug->leave_sub();
+ return 0;
}
sub save_status {
sub update_defaults {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $fld) = @_;
+ my ($self, $myconfig, $fld, $provided_dbh) = @_;
- my $dbh = $self->dbconnect_noauto($myconfig);
+ my $dbh;
+ if ($provided_dbh) {
+ $dbh = $provided_dbh;
+ } else {
+ $dbh = $self->dbconnect_noauto($myconfig);
+ }
my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
my $sth = $dbh->prepare($query);
SET $fld = '$var'|;
$dbh->do($query) || $self->dberror($query);
- $dbh->commit;
- $dbh->disconnect;
+ if (!$provided_dbh) {
+ $dbh->commit;
+ $dbh->disconnect;
+ }
$main::lxdebug->leave_sub();