Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saved AR/AP items in vouchers can't be saved again #7809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions old/bin/aa.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,6 @@ sub on_hold {
# }

sub edit_and_save {
$form->call_procedure(funcname=>'draft_delete', args => [ $form->{id} ]);
delete $form->{id};
AA->post_transaction( \%myconfig, \%$form );

if ($form->{workflow_id}) {
Expand Down
2 changes: 0 additions & 2 deletions old/bin/ir.pl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ sub copy_to_new{

sub edit_and_save {
$form->{ARAP} = 'AP';
$form->call_procedure(funcname=>'draft_delete', args => [ $form->{id} ]);
delete $form->{id};
IR->post_invoice( \%myconfig, \%$form );

if ($form->{workflow_id}) {
Expand Down
2 changes: 0 additions & 2 deletions old/bin/is.pl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ sub copy_to_new{

sub edit_and_save {
$form->{ARAP} = 'AR';
$form->call_procedure(funcname=>'draft_delete', args => [ $form->{id} ]);
delete $form->{id};
IS->post_invoice( \%myconfig, \%$form );

if ($form->{workflow_id}) {
Expand Down
117 changes: 71 additions & 46 deletions old/lib/LedgerSMB/AA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -277,65 +277,94 @@ sub post_transaction {

# check if id really exists
if ( $form->{id} ) {
my $id = $dbh->quote( $form->{id} );
$keepcleared = 1;
$query = qq|
SELECT id
FROM $table
WHERE id = $id|;
my ($exists) = $dbh->selectrow_array($query);
if ($exists and $form->{batch_id}) {
if ($form->{batch_id}) {
$query = "SELECT voucher__delete(id)
FROM voucher
where trans_id = ? and batch_class in (1, 2)";
$dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
} elsif ($exists) {

# delete detail records
delete $form->{id};
}
else {
# delete detail records
$query = qq|SELECT draft_delete(?)|;
$dbh->do($query, {}, $form->{id}) || $form->dberror($query);
delete $form->{id};
}
}

$dbh->do($query) || $form->dberror($query);
$query = qq|
DELETE FROM ac_tax_form
WHERE entry_id IN
(SELECT entry_id FROM acc_trans
WHERE trans_id = $id)|;
if (not $form->{id}) {
# note that the previous section may have removed $form->{id}, so this can't be an 'else' statement
my $uid = localtime;
$uid .= "$$";

$dbh->do($query) || $form->dberror($query);
$query = qq|
INSERT INTO ar (invnumber, person_id, entity_credit_account)
VALUES ('$uid', ?, ?)|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{employee_id}, $form->{customer_id}) || $form->dberror($query);

$query = qq|
DELETE FROM acc_trans
WHERE trans_id = $id|;
$query = qq|SELECT id FROM ar WHERE invnumber = '$uid'|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);

$dbh->do($query) || $form->dberror($query);
$dbh->do("DELETE FROM $table where id = $id");
}
( $form->{id} ) = $sth->fetchrow_array;

$query = q|UPDATE transactions SET workflow_id = ?, reversing = ? WHERE id = ? AND workflow_id IS NULL|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{workflow_id}, $form->{reversing}, $form->{id} )
|| $form->dberror($query);
}


if ($table eq 'ar') {
$query = qq|
INSERT INTO ar
(invnumber, description, ordnumber, transdate, taxincluded,
amount_bc, netamount_bc, curr, amount_tc, netamount_tc, duedate,
notes, intnotes, ponumber, crdate, reverse,
person_id, entity_credit_account, approved,
setting_sequence
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id
UPDATE ar
SET invnumber = ?,
description = ?,
ordnumber = ?,
transdate = ?,
taxincluded = ?,
amount_bc = ?,
netamount_bc = ?,
curr = ?,
amount_tc = ?,
netamount_tc = ?,
duedate = ?,
notes = ?,
intnotes = ?,
ponumber = ?,
crdate = ?,
reverse = ?,
person_id = ?,
entity_credit_account = ?,
approved = ?,
setting_sequence = ?
WHERE id = ?
|;
}
else {
$query = qq|
INSERT INTO $table
(invnumber, description, ordnumber, transdate, taxincluded,
amount_bc, netamount_bc, curr, amount_tc, netamount_tc, duedate,
notes, intnotes, ponumber, crdate, reverse,
person_id, entity_credit_account, approved
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id
UPDATE $table
SET invnumber = ?,
description = ?,
ordnumber = ?,
transdate = ?,
taxincluded = ?,
amount_bc = ?,
netamount_bc = ?,
curr = ?,
amount_tc = ?,
netamount_tc = ?,
duedate = ?,
notes = ?,
intnotes = ?,
ponumber = ?,
crdate = ?,
reverse = ?,
person_id = ?,
entity_credit_account = ?,
approved = ?
WHERE id = ?
|;
}

Expand All @@ -362,14 +391,10 @@ sub post_transaction {
if ($table eq 'ar') {
push @queryargs, $form->{setting_sequence}
}
push @queryargs, $form->{id};

$sth = $dbh->prepare($query) or $form->dberror($query);
$sth->execute(@queryargs) or $form->dberror($query);
($form->{id}) = $sth->fetchrow_array() or $form->dberror($query);
$query = q|UPDATE transactions SET workflow_id = ?, reversing = ? WHERE id = ? AND workflow_id IS NULL|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{workflow_id}, $form->{reversing}, $form->{id} )
|| $form->dberror($query);

if (defined $form->{approved}) {
if (!$form->{approved} && $form->{batch_id}){
Expand Down
34 changes: 22 additions & 12 deletions old/lib/LedgerSMB/IR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ sub post_invoice {
delete $form->{reverse} unless $form->{reverse};

$form->all_business_units;
if ($form->{id}){
delete_invoice($self, $myconfig, $form);
}

my $dbh = $form->{dbh};
$form->{invnumber} = $form->update_defaults( $myconfig, "vinumber", $dbh )
if $form->should_update_defaults('invnumber');
Expand Down Expand Up @@ -134,27 +132,40 @@ sub post_invoice {

my %updparts = ();

# check if id really exists
if ( $form->{id} ) {
$form->error("Can't re-post invoice!");
if ($form->{batch_id}) {
$query = "SELECT voucher__delete(id)
FROM voucher
where trans_id = ? and batch_class in (1, 2)";
$dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
delete $form->{id};
}
else {
# delete detail records
$query = qq|SELECT draft_delete(?)|;
$dbh->do($query, {}, $form->{id}) || $form->dberror($query);
delete $form->{id};
}
}

my $uid = localtime;
$uid .= "$$";

if ( !$form->{id} ) {
if (not $form->{id}) {
# note that the previous section may have removed $form->{id}, so this can't be an 'else' statement
my $uid = localtime;
$uid .= "$$";

$query = qq|
INSERT INTO ap (invnumber, person_id, entity_credit_account)
VALUES ('$uid', person__get_my_entity_id(), ?)|;
VALUES ('$uid', ?, ?)|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{vendor_id} )
|| $form->dberror($query);
$sth->execute( $form->{employee_id}, $form->{vendor_id}) || $form->dberror($query);

$query = qq|SELECT id FROM ap WHERE invnumber = '$uid'|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);

( $form->{id} ) = $sth->fetchrow_array;

$query = q|UPDATE transactions SET workflow_id = ?, reversing = ? WHERE id = ? AND workflow_id IS NULL|;
$sth = $dbh->prepare($query);
$sth->execute( $form->{workflow_id}, $form->{reversing}, $form->{id} )
Expand All @@ -172,7 +183,6 @@ sub post_invoice {
else {
$exchangerate = "";
}

$form->{exchangerate} = $form->parse_amount( $myconfig, $form->{exchangerate} );


Expand Down
31 changes: 21 additions & 10 deletions old/lib/LedgerSMB/IS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,6 @@ sub post_invoice {

$form->{acc_trans} = ();

if ($form->{id}){
delete_invoice($self, $myconfig, $form);
}

( $null, $form->{employee_id} ) = split /--/, $form->{employee};
unless ( $form->{employee_id} ) {
( $form->{employee}, $form->{employee_id} ) = $form->get_employee;
Expand All @@ -738,14 +734,27 @@ sub post_invoice {
my $pth = $dbh->prepare($query) || $form->dberror($query);
$form->{is_return} ||= 0;

# check if id really exists
if ( $form->{id} ) {
$form->error("Can't re-post invoices.");
if ($form->{batch_id}) {
$query = "SELECT voucher__delete(id)
FROM voucher
where trans_id = ? and batch_class in (1, 2)";
$dbh->prepare($query)->execute($form->{id}) || $form->dberror($query);
delete $form->{id};
}
else {
# delete detail records
$query = qq|SELECT draft_delete(?)|;
$dbh->do($query, {}, $form->{id}) || $form->dberror($query);
delete $form->{id};
}
}

my $uid = localtime;
$uid .= "$$";

if ( !$form->{id} ) {
if (not $form->{id}) {
# note that the previous section may have removed $form->{id}, so this can't be an 'else' statement
my $uid = localtime;
$uid .= "$$";

$query = qq|
INSERT INTO ar (invnumber, person_id, entity_credit_account)
Expand All @@ -768,7 +777,9 @@ sub post_invoice {
if ( $form->{currency} eq $form->{defaultcurrency} ) {
$form->{exchangerate} = 1;
}

else {
$exchangerate = "";
}
$form->{exchangerate} = $form->parse_amount( $myconfig, $form->{exchangerate} );

my $return_cid = 0;
Expand Down
Loading