[set page_banner]Journal Entry[/set]
[set fm_class]Ledger[/set]
[set help_name]journal_entry[/set]
[set page_title]Journal Entry[/set]
[set icon_name]icon_stats.gif[/set]
@_FM_STD_HEAD_@
[seti batchnr][/seti][seti batchname][/seti][seti batchdate][/seti]
[scratchd description]
[value name=soa set=""]
[if value mv_action]
[if value select_batch]
[query list=1 sql="SELECT batchnr, name, posteddate, soa FROM gl_batch WHERE batch_id=[value select_batch]"]
[seti batchnr][sql-param batchnr][/seti]
[seti batchname][sql-param name][/seti]
[seti batchdate][sql-param posteddate][/seti]
[seti][value name=soa set="[sql-param soa]"][/seti]
[/query]
[else]
[set submit_value]Add[/set]
[/else]
[/if]
[seti submit_value][value mv_action][/seti]
[else]
[set submit_value]Add[/set]
[/else]
[/if]
[query list=1 sql="SELECT contact_id, periodfrom, periodto
FROM sy_ownercompany"]
[seti contact_id][sql-param contact_id][/seti]
[seti periodfrom][sql-param periodfrom][/seti]
[seti periodto][sql-param periodto][/seti]
[/query]
[perl tables="gl_journal"]
my ($acctinfo, $jdate, $description, $debit, $credit);
# Do we change a journal entry?
if ($Values->{journal_action}) {
$Scratch->{batchnr} = $Values->{batchnr};
$Scratch->{batchname} = $Values->{batchname};
$Scratch->{batchdate} = $Values->{batchdate};
my $i = $Values->{select_journal} || 0;
my $ref = $Scratch->{journals};
my ($ar, $nul, $names) = @$ref;
if ($Values->{journal_action} eq "Update") {
my @ary = @$ar;
my $ref = $ary[$i - 1];
my ($x, $journalnr, $jdate, $debit, $credit, $description, $acctinfo) = @$ref;
$acctinfo = $Values->{acctinfo} ;
$acctinfo = @$ar[$i - 1]->[6] if (@$ar && $i && !$acctinfo);
$journalnr = $Values->{journalnr} ;
$journalnr = @$ar[$i - 1]->[1] if (@$ar && $i && !$journalnr);
$jdate = $Values->{jdate};
$jdate = @$ar[$i - 1]->[2] if (@$ar && $i && !$jdate);
$description = $Values->{description};
$description = @$ar[$i - 1]->[5] if (@$ar && $i && !$description);
$debit = $Values->{debit};
$debit = @$ar[$i - 1]->[3] if (@$ar && $i && !$debit);
$debit = 0 if $debit == "-";
$credit = $Values->{credit};
$credit = @$ar[$i - 1]->[4] if (@$ar && $i && !$credit);
$credit = 0 if $credit == "-";
@ol = [$x, $journalnr, $jdate, $debit, $credit, $description, $acctinfo];
if ($i) {
@$ar[$i - 1] = (@ol);
} else {
push @$ar, (@ol);
};
} elsif ($Values->{journal_action} eq "Delete") {
splice (@$ar, $i - 1, 1);
};
# We'll find the existing journal entries for this batch
} else {
if ($Values->{select_batch}) {
my $db = $Db{gl_journal} or return "NO journal table?";
my $q = qq{
SELECT j.batch_id, j.journalnr, j.entrydate::date as entrydate,
j.entereddr, j.enteredcr, j.text,
(SELECT coa.number
WHERE coa.coa_id = ag.dim1 AND ag.dim2 IS NULL AND ag.dim3 IS NULL
UNION
SELECT coa.number||'/'||ag.dim2
WHERE coa.coa_id = ag.dim1 AND ag.dim2 IS NOT NULL AND ag.dim3 IS NULL
UNION
SELECT coa.number||'/'||ag.dim2||'/'||ag.dim3
WHERE coa.coa_id = ag.dim1 AND ag.dim2 IS NOT NULL AND ag.dim3 IS NOT NULL)
FROM gl_journal j, gl_acctgrid ag, gl_chartofaccount coa
WHERE j.batch_id = $Values->{select_batch}
AND j.ag_id = ag.ag_id
AND ag.dim1 = coa.coa_id
ORDER BY journalnr;
};
my @ary = $db->query($q) or die "query failed";
$Scratch->{journals} = \@ary;
} else {
my @ary = ( [ ]);
$Scratch->{journals} = \@ary;
}
};
delete $Values->{journal_action};
delete $Values->{select_journal};
return;
[/perl]
[if !scratch error]
|
[comment]Batch data[/comment]
|
[comment]Journal lines[/comment]
[comment]END Order lines END[/comment]
|
|
[else]
[scratch error]
[set error][/set]
[L]BACK[/L]
[/else]
[/if]
@_FM_STD_FOOTER_@