3 * Component for creating a batch of transactions reflecting GST for the period specified
5 * @subpackage period_gst
6 * @author Andrew McMillan <andrew@mcmillan.net.nz>
7 * @copyright Morphoss Ltd <http://www.morphoss.com/>
8 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
11 param_to_global('companycode', 'int' );
12 param_to_global('period_start', 'int' );
13 param_to_global('period_end', 'int' );
15 get_office_accounts( 'GST-BAD', 'GST-IN', 'GST-OUT', 'GST-SUSPENSE' );
17 $gst_bad_ac = $office_accounts['GST-BAD']->accountcode
;
18 $gst_in_ac = $office_accounts['GST-IN']->accountcode
;
19 $gst_out_ac = $office_accounts['GST-OUT']->accountcode
;
21 $gst_washup = $office_accounts['GST-SUSPENSE']->accountcode
;
23 require_once( "transaction_helpers.php" );
25 $qry = new AwlQuery("SELECT min(startdate), max(enddate) FROM month WHERE monthcode >= ? AND monthcode <= ?", $period_start, $period_end);
26 if ( $qry->Exec("period_gst") && $qry->rows() > 0 ) {
27 $period = $qry->Fetch();
30 $c->messages
[] = "Unable to find period start/end";
35 SELECT accountcode, sum(balance) AS sum
37 WHERE monthcode >= ? AND monthcode <= ?
38 AND entitytype = 'L' AND entitycode = ?
39 AND accountcode IN ( ?, ?, ? )
43 $qry = new AwlQuery( $sql, intval($period_start), intval($period_end), intval($companycode), $gst_bad_ac, $gst_in_ac, $gst_out_ac );
44 if ( $qry->Exec("period_gst") && $qry->rows() > 0 ) {
46 $batch = new NewBatch( 'AUTO', 0, "Period GST from $period->min to $period->max");
47 $batch->newDocument( "Period GST from $period->min to $period->max", 'Period GST', 'JRNL' );
50 while( $account_balance = $qry->Fetch() ) {
51 if ( $account_balance->sum
!= 0.0 ) {
53 switch( $account_balance->accountcode
) {
54 case $gst_out_ac: $activity = 'collected '; break;
55 case $gst_in_ac: $activity = 'paid out '; break;
56 case $gst_bad_ac: $activity = 'on bad debt written off '; break;
58 $description = sprintf( 'GST %sfrom %s to %s', $activity, $period->min
, $period->max
);
59 $batch->newTransaction( 'L', $companycode, $account_balance->accountcode
, $period->max
, - $account_balance->sum
, $description );
60 $journal_total +
= $account_balance->sum
;
63 $description = sprintf( 'GST %sdue for the period %s to %s', ($journal_total > 0 ?
'refund ' : ''), $period->min
, $period->max
);
64 $batch->newTransaction( 'L', $companycode, $gst_washup, $period->max
, $journal_total, $description );
66 $c->messages
[] = sprintf( "GST batch %s created.", $batch->getCode());
69 $c->messages
[] = "No GST batch to create.";