# allocated >= 0
# add entry for inventory, this one is for the sold item
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?),
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= ?
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
(SELECT tax_id
FROM taxkeys
- WHERE chart_id= (SELECT id
- FROM chart
- WHERE accno = ?)
+ WHERE chart_id= ?
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
(SELECT chart_link FROM chart WHERE id = ?))|;
- @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate}, $ref->{inventory_accno_id});
+ @values = ($ref->{trans_id}, $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{transdate},
+ $ref->{inventory_accno_id});
do_query($form, $dbh, $query, @values);
# add expense
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?),
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= ?
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
(SELECT tax_id
FROM taxkeys
- WHERE chart_id= (SELECT id
- FROM chart
- WHERE accno = ?)
+ WHERE chart_id= ?
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
(SELECT chart_link FROM chart WHERE id = ?))|;
- @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate}, $ref->{expense_accno_id});
+ @values = ($ref->{trans_id}, $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate}, $ref->{expense_accno_id}, $ref->{transdate},
+ $ref->{expense_accno_id});
do_query($form, $dbh, $query, @values);
}
};
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT tax_id
FROM taxkeys
WHERE chart_id= (SELECT id
ORDER BY startdate DESC LIMIT 1),
(SELECT link FROM chart WHERE accno = ?))|;
@values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno},
- conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}), $accno);
+ conv_date($form->{invdate}), $accno, conv_date($form->{invdate}), $project_id, $accno, conv_date($form->{invdate}), $accno);
do_query($form, $dbh, $query, @values);
}
}
if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) {
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT tax_id
FROM taxkeys
WHERE chart_id= (SELECT id
ORDER BY startdate DESC LIMIT 1),
(SELECT link FROM chart WHERE accno = ?))|;
@values = (conv_i($form->{id}), $form->{AP}, $amount,
- $form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP});
+ $form->{"datepaid_$i"}, $form->{AP}, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP});
do_query($form, $dbh, $query, @values);
}
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id, chart_link)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT tax_id
FROM taxkeys
WHERE chart_id= (SELECT id
ORDER BY startdate DESC LIMIT 1),
(SELECT link FROM chart WHERE accno = ?))|;
@values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
- $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno);
+ $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($form->{"datepaid_$i"}), $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno);
do_query($form, $dbh, $query, @values);
$exchangerate = 0;
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id, chart_link)
VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?,
- (SELECT tax_id
- FROM taxkeys
- WHERE chart_id= (SELECT id
- FROM chart
- WHERE accno = ?)
- AND startdate <= ?
- ORDER BY startdate DESC LIMIT 1),
+ (SELECT id FROM tax WHERE taxkey=0 LIMIT 1),
(SELECT link FROM chart WHERE accno = ?))|;
- @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate}, $accno);
+ @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno);
do_query($form, $dbh, $query, @values);
}
}
WHERE accno = ?)
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT link FROM chart WHERE accno = ?))|;
- @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno);
+ @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno);
do_query($form, $dbh, $query, @values);
$form->{amount}{$trans_id}{$accno} = 0;
}
WHERE accno = ?)
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT link FROM chart WHERE accno = ?))|;
- @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno);
+ @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno);
do_query($form, $dbh, $query, @values);
}
}
WHERE accno = ?)
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT link FROM chart WHERE accno = ?))|;
- @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id, $form->{AR});
+ @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, conv_date($taxdate), $project_id, $form->{AR});
do_query($form, $dbh, $query, @values);
}
WHERE accno = ?)
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT link FROM chart WHERE accno = ?))|;
@values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
- $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id, $accno);
+ $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, conv_date($taxdate), $project_id, $accno);
do_query($form, $dbh, $query, @values);
# exchangerate difference
WHERE accno = ?)
AND startdate <= ?
ORDER BY startdate DESC LIMIT 1),
- (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
+ (SELECT taxkey_id
+ FROM taxkeys
+ WHERE chart_id= (SELECT id
+ FROM chart
+ WHERE accno = ?)
+ AND startdate <= ?
+ ORDER BY startdate DESC LIMIT 1),
+ ?,
(SELECT link FROM chart WHERE accno = ?))|;
- @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_i($project_id), $accno);
+ @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_date($taxdate), conv_i($project_id), $accno);
do_query($form, $dbh, $query, @values);
}
}