# get contact id, set it if nessessary
$form->{cp_id} *= 1;
- my @values;
+ my @values = (conv_i($form->{customer_id}));
my $where = "";
if ($form->{cp_id}) {
WHERE (ct.id = ?) $where
ORDER BY cp.cp_id
LIMIT 1|;
- push(@values, conv_i($form->{customer_id}));
my $ref = selectfirst_hashref_query($form, $dbh, $query, @values);
# remove id and taxincluded before copy back
my ($query, $sth, $null, $project_id, $deliverydate, @values);
my $exchangerate = 0;
- ($null, $form->{employee_id}) = split(/--/, $form->{employee});
- unless ($form->{employee_id}) {
+ if (!$form->{employee_id}) {
$form->get_employee($dbh);
}
conv_i($form->{"cp_id"}), $form->{transaction_description},
conv_i($form->{"id"}));
do_query($form, $dbh, $query, @values);
-
+
+ if($form->{"formname"} eq "credit_note") {
+ for my $i (1 .. $form->{paidaccounts}) {
+ $query = qq|UPDATE parts SET onhand = onhand - ? WHERE id = ?|;
+ @values = (conv_i($form->{"qty_$i"}), conv_i($form->{"id_$i"}));
+ do_query($form, $dbh, $query, @values);
+ }
+ }
+
if ($form->{storno}) {
$query =
qq!UPDATE ar SET
(SELECT tk.tax_id
FROM taxkeys tk
WHERE tk.chart_id = (SELECT id FROM chart WHERE accno = ?)
- AND startdate <= $transdate
+ AND startdate <= date($transdate)
ORDER BY startdate DESC
LIMIT 1)
ORDER BY c.accno|;
qq|SELECT tk.tax_id, t.rate
FROM taxkeys tk
LEFT JOIN tax t ON tk.tax_id = t.id
- WHERE (tk.chart_id = ?) AND (startdate <= ?)
+ WHERE (tk.chart_id = ?) AND (startdate <= date(?))
ORDER BY tk.startdate DESC
LIMIT 1|;
my ($tax_id, $rate) =
ORDER BY startdate DESC
LIMIT 1)
ORDER BY c.accno|;
- @values = ($accno_id, $transdate);
+ @values = ($accno_id, $transdate eq "current_date" ? "now" : $transdate);
$stw = $dbh->prepare($query);
$stw->execute(@values) || $form->dberror($query);
my $dbh = $form->dbconnect($myconfig);
+ my $query = qq|SELECT storno FROM $table WHERE storno_id = ?|;
+ my ($result) = selectrow_query($form, $dbh, $query, $form->{id});
+
+ $dbh->disconnect();
+
+ $main::lxdebug->leave_sub();
+
+ return $result;
+}
+
+sub is_storno {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form, $table) = @_;
+
+ $main::lxdebug->leave_sub() and return 0 unless ($form->{id});
+
+ # make sure there's no funny stuff in $table
+ # ToDO: die when this happens and throw an error
+ $main::lxdebug->leave_sub() and return 0 if ($table =~ /\W/);
+
+ my $dbh = $form->dbconnect($myconfig);
+
my $query = qq|SELECT storno FROM $table WHERE id = ?|;
my ($result) = selectrow_query($form, $dbh, $query, $form->{id});