$dbh->do($query) || $form->dberror($query);
}
- my $query = qq| SELECT invnumber, ordnumber, customer_id, amount, netamount, ar.transdate, ar.duedate, paid, amount-paid AS open_amount, template AS formname, email_subject, email_body, email_attachment, da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate FROM ar LEFT JOIN dunning_config ON (dunning_config.id=ar.dunning_id) LEFT JOIN dunning da ON (ar.id=da.trans_id) where ar.id IN $form->{inv_ids}|;
+ my $query = qq| SELECT invnumber, ordnumber, customer_id, amount, netamount, ar.transdate, ar.duedate, paid, amount-paid AS open_amount, template AS formname, email_subject, email_body, email_attachment, da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate FROM ar LEFT JOIN dunning_config ON (dunning_config.id=ar.dunning_id) LEFT JOIN dunning da ON (ar.id=da.trans_id AND dunning_config.dunning_level=da.dunning_level) where ar.id IN $form->{inv_ids}|;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
my $first = 1;
FROM dunning_config dnn, ar a
JOIN customer ct ON (a.customer_id = ct.id)
LEFT JOIN dunning_config dn ON (dn.id = a.dunning_id)
- LEFT JOIN dunning da ON (da.trans_id=a.id)
+ LEFT JOIN dunning da ON (da.trans_id=a.id AND dunning_config.dunning_level=da.dunning_level)
$where|;
my $sth = $dbh->prepare($query);
$where .= " ORDER by $sortorder";
- $query = qq|SELECT a.id, a.ordnumber, a.transdate, a.invnumber,a.amount, ct.name AS customername, a.duedate,da.fee ,da.interest, dn.dunning_description, da.transdate AS dunning_date, da.duedate AS dunning_duedate, da.dunning_id
+ $query = qq|SELECT a.id, a.ordnumber,a.invoice, a.transdate, a.invnumber,a.amount, ct.name AS customername, a.duedate,da.fee ,da.interest, dn.dunning_description, da.transdate AS dunning_date, da.duedate AS dunning_duedate, da.dunning_id
FROM ar a
JOIN customer ct ON (a.customer_id = ct.id),
dunning da LEFT JOIN dunning_config dn ON (da.dunning_id=dn.id)
my $dbh = $form->dbconnect_noauto($myconfig);
- my $query = qq| SELECT invnumber, ordnumber, customer_id, amount, netamount, ar.transdate, ar.duedate, paid, amount-paid AS open_amount, template AS formname, email_subject, email_body, email_attachment, da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate FROM ar LEFT JOIN dunning_config ON (dunning_config.id=ar.dunning_id) LEFT JOIN dunning da ON (ar.id=da.trans_id) where ar.dunning_id=$dunning_id|;
+ my $query = qq| SELECT invnumber, ordnumber, customer_id, amount, netamount, ar.transdate, ar.duedate, paid, amount-paid AS open_amount, template AS formname, email_subject, email_body, email_attachment, da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate FROM ar LEFT JOIN dunning_config ON (dunning_config.id=ar.dunning_id) LEFT JOIN dunning da ON (ar.id=da.trans_id AND dunning_config.dunning_level=da.dunning_level) where ar.dunning_id=$dunning_id|;
my $sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
my $first = 1;
$dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|;
-
-
+ my $script = "";
+ if ($ref->{invoice}) {
+ $script = "is.pl";
+ } else {
+ $script = "ar.pl";
+ }
$column_data{dunning_description} = qq|<td><a href=dn.pl?action=print_dunning&dunning_id=$ref->{dunning_id}&format=pdf&media=screen&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{dunning_description}</a></td>|;
my $active = "checked";
$column_data{dunning_date} = qq|<td>$ref->{dunning_date}</td>|;
$column_data{inv_duedate} = qq|<td>$ref->{duedate}</td>|;
$column_data{invdate} = qq|<td>$ref->{transdate}</td>|;
- $column_data{invnumber} = qq|<td><a href=ar.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}</a></td>|;
+ $column_data{invnumber} = qq|<td><a href=$script?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}</a></td>|;
$column_data{customername} = qq|<td>$ref->{customername}</td>|;
$column_data{invamount} = qq|<td>$ref->{amount}</td>|;
$column_data{fee} = qq|<td>$ref->{fee}</td>|;