my ($query, $sth);
my $dbh = $self->dbconnect($myconfig);
-
my %xkeyref = ();
- # now get the account numbers
- $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id
- FROM chart c
- WHERE c.link LIKE '%$module%'
- ORDER BY c.accno|;
-
- $sth = $dbh->prepare($query);
- $sth->execute || $self->dberror($query);
-
- $self->{accounts} = "";
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ if (!$self->{id}) {
- foreach my $key (split /:/, $ref->{link}) {
- if ($key =~ /$module/) {
-
- # cross reference for keys
- $xkeyref{ $ref->{accno} } = $key;
-
- push @{ $self->{"${module}_links"}{$key} },
- { accno => $ref->{accno},
- description => $ref->{description},
- taxkey => $ref->{taxkey_id} };
-
- $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
+ my $transdate = "current_date";
+ if ($self->{transdate}) {
+ $transdate = qq|'$self->{transdate}'|;
+ }
+
+ # now get the account numbers
+ $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
+ FROM chart c, taxkeys tk
+ WHERE c.link LIKE '%$module%' AND c.id=tk.chart_id AND tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1)
+ ORDER BY c.accno|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ $self->{accounts} = "";
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+
+ foreach my $key (split /:/, $ref->{link}) {
+ if ($key =~ /$module/) {
+
+ # cross reference for keys
+ $xkeyref{ $ref->{accno} } = $key;
+
+ push @{ $self->{"${module}_links"}{$key} },
+ { accno => $ref->{accno},
+ description => $ref->{description},
+ taxkey => $ref->{taxkey_id},
+ tax_id => $ref->{tax_id} };
+
+ $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
+ }
}
}
}
- $sth->finish;
# get taxkeys and description
- $query = qq|SELECT taxkey, taxdescription
+ $query = qq|SELECT id, taxkey, taxdescription
FROM tax|;
$sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
}
$sth->finish;
+
+ my $transdate = "current_date";
+ if ($self->{transdate}) {
+ $transdate = qq|'$self->{transdate}'|;
+ }
+
+ # now get the account numbers
+ $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
+ FROM chart c, taxkeys tk
+ WHERE c.link LIKE '%$module%' AND (((tk.chart_id=c.id) AND NOT(c.link like '%_tax%')) OR (NOT(tk.chart_id=c.id) AND (c.link like '%_tax%'))) AND (((tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1)) AND NOT(c.link like '%_tax%')) OR (c.link like '%_tax%'))
+ ORDER BY c.accno|;
+
+ $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ $self->{accounts} = "";
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+
+ foreach my $key (split /:/, $ref->{link}) {
+ if ($key =~ /$module/) {
+
+ # cross reference for keys
+ $xkeyref{ $ref->{accno} } = $key;
+
+ push @{ $self->{"${module}_links"}{$key} },
+ { accno => $ref->{accno},
+ description => $ref->{description},
+ taxkey => $ref->{taxkey_id},
+ tax_id => $ref->{tax_id} };
+
+ $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
+ }
+ }
+ }
+
+
# get amounts from individual entries
$query = qq|SELECT c.accno, c.description, a.source, a.amount, a.memo,
- a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate
+ a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate, t.id
FROM acc_trans a
JOIN chart c ON (c.id = a.chart_id)
LEFT JOIN project p ON (p.id = a.project_id)
- LEFT Join tax t ON (a.taxkey = t.taxkey)
- WHERE a.trans_id = $self->{id}
+ LEFT JOIN tax t ON (t.id=(SELECT tk.tax_id from taxkeys tk WHERE (tk.taxkey_id=a.taxkey) AND ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id=a.taxkey) THEN tk.chart_id=a.chart_id ELSE 1=1 END) OR (c.link='%tax%')) AND startdate <=a.transdate ORDER BY startdate DESC LIMIT 1))
+ WHERE a.trans_id = $self->{id}
AND a.fx_transaction = '0'
ORDER BY a.oid,a.transdate|;
$sth = $dbh->prepare($query);
push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
}
- $sth->finish;
+ $sth->finish;
$query = qq|SELECT d.curr AS currencies, d.closedto, d.revtrans,
(SELECT c.accno FROM chart c
WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
}
+ $sth->finish;
+
$dbh->disconnect;
$main::lxdebug->leave_sub();
$duedate = $form->{duedate};
IR->get_vendor(\%myconfig, \%$form);
-
+ $form->{taxincluded} = $taxincluded;
$form->{duedate} = $duedate if $duedate;
$form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
$form->{rowcount} = 1;
map {
$tax .=
- qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |
+ qq|<option value=\"$_->{id}--$_->{rate}\">$_->{taxdescription} |
. ($_->{rate} * 100) . qq| %|
} @{ $form->{TAX} };
$form->{taxchart} = $tax;
"<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
} else {
$form->{"select$key"} .=
- "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
+ "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
}
}
if ($akey eq 'amount') {
$form->{"taxchart_$k"} = $form->{taxchart};
$form->{"taxchart_$k"} =~
- /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^\"]*)/;
+ /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{id}--[^\"]*)/;
$form->{"taxchart_$k"} = $1;
}
}
s/option value=\"$form->{"AP_paid_$i"}\">/option value=\"$form->{"AP_paid_$i"}\" selected>/;
# format amounts
- $form->{"paid_$i"} =
+ if ($form->{"paid_$i"}) {
+ $form->{"paid_$i"} =
$form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ }
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
$duedate = $form->{duedate};
$taxincluded = $form->{taxincluded};
-
+ my $id = $form->{id};
IS->get_customer(\%myconfig, \%$form);
+ $form->{taxincluded} = $taxincluded;
+ $form->{id} = $id;
$form->{duedate} = $duedate if $duedate;
$form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
map {
$tax .=
- qq|<option value=\"$_->{taxkey}--$_->{rate}\">$_->{taxdescription} |
+ qq|<option value=\"$_->{id}--$_->{rate}\">$_->{taxdescription} |
. ($_->{rate} * 100) . qq| %|
} @{ $form->{TAX} };
$form->{taxchart} = $tax;
"<option value=\"$ref->{accno}\">$ref->{accno}--$ref->{description}</option>\n";
} else {
$form->{"select$key"} .=
- "<option value=\"$ref->{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}</option>\n";
+ "<option value=\"$ref->{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}</option>\n";
}
}
if ($akey eq 'amount') {
$form->{"taxchart_$k"} = $form->{taxchart};
$form->{"taxchart_$k"} =~
- /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{taxkey}--[^\"]*)/;
+ /<option value=\"($form->{acc_trans}{$key}->[$i-1]->{id}--[^\"]*)/;
$form->{"taxchart_$k"} = $1;
}
}
s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/;
# format amounts
- $form->{"paid_$i"} =
- $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ if ($form->{"paid_$i"}) {
+ $form->{"paid_$i"} =
+ $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
+ }
$form->{"exchangerate_$i"} =
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});