+ # delete detail records
+ $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
+ do_query($form, $dbh, $query, $form->{id});
+
+ } else {
+
+ ($form->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('glid')|);
+
+ $query =
+ qq|INSERT INTO ap (id, invnumber, employee_id,currency_id, taxzone_id) | .
+ qq|VALUES (?, ?, (SELECT e.id FROM employee e WHERE e.login = ?),
+ (SELECT id FROM currencies WHERE name = ?), (SELECT taxzone_id FROM vendor WHERE id = ?) )|;
+ do_query($form, $dbh, $query, $form->{id}, $form->{invnumber}, $::myconfig{login}, $form->{currency}, $form->{vendor_id});
+
+ }
+
+ $query = qq|UPDATE ap SET invnumber = ?,
+ transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
+ amount = ?, duedate = ?, paid = ?, netamount = ?,
+ currency_id = (SELECT id FROM currencies WHERE name = ?), notes = ?, department_id = ?, storno = ?, storno_id = ?,
+ globalproject_id = ?, direct_debit = ?
+ WHERE id = ?|;
+ @values = ($form->{invnumber}, conv_date($form->{transdate}),
+ $form->{ordnumber}, conv_i($form->{vendor_id}),
+ $form->{taxincluded} ? 't' : 'f', $form->{invtotal},
+ conv_date($form->{duedate}), $form->{invpaid},
+ $form->{netamount},
+ $form->{currency}, $form->{notes},
+ conv_i($form->{department_id}), $form->{storno},
+ $form->{storno_id}, conv_i($form->{globalproject_id}),
+ $form->{direct_debit} ? 't' : 'f',
+ $form->{id});
+ do_query($form, $dbh, $query, @values);
+
+ $form->new_lastmtime('ap');
+
+ # add individual transactions
+ for my $i (1 .. $form->{rowcount}) {
+ if ($form->{"amount_$i"} != 0) {
+ my $project_id;
+ $project_id = conv_i($form->{"project_id_$i"});