diff -r -N -U 3 sl-base/SL/AA.pm sql-ledger-test/SL/AA.pm
--- sl-base/SL/AA.pm Thu Mar 9 17:00:45 2006
+++ sql-ledger-test/SL/AA.pm Thu Mar 9 18:03:36 2006
@@ -614,6 +614,10 @@
$var = $form->like(lc $form->{shipvia});
$where .= " AND lower(a.shipvia) LIKE '$var'";
}
+ if ($form->{partsid}){
+ $where .= " AND a.id IN (select trans_id FROM invoice
+ WHERE parts_id = $form->{partsid})";
+ }
if ($form->{notes}) {
$var = $form->like(lc $form->{notes});
$where .= " AND lower(a.notes) LIKE '$var'";
diff -r -N -U 3 sl-base/SL/RP.pm sql-ledger-test/SL/RP.pm
--- sl-base/SL/RP.pm Thu Mar 9 17:00:45 2006
+++ sql-ledger-test/SL/RP.pm Thu Mar 9 18:20:42 2006
@@ -29,6 +29,67 @@
package RP;
+sub inventory_activity {
+ my ($self, $myconfig, $form) = @_;
+ ($form->{fromdate}, $form->{todate}) = $form->from_to($form->{fromyear}, $form->{frommonth}, $form->{interval}) if $form->{fromyear} && $form->{frommonth};
+
+
+ unless ($form->{sort_col}){
+ $form->{sort_col} = 'partnumber';
+ }
+
+ my $dbh = $form->dbconnect($myconfig) || $form->dberror();
+
+ my $where = '';
+ if ($form->{fromdate}){
+ $where .= "AND coalesce(ar.duedate, ap.duedate) >= ".$dbh->quote($form->{fromdate});
+ }
+ if ($form->{todate}){
+ $where .= "AND coalesce(ar.duedate, ap.duedate) < ".$dbh->quote($form->{todate}). " ";
+ }
+ if ($form->{partnumber}){
+ $where .= qq|AND p.partnumber ILIKE '%|.$form->{partnumber}.qq|%' |;
+ }
+ if ($form->{description}){
+ $where .= q|AND p.description ILIKE '%|.$form->{description}.q|%' |;
+ }
+ $where =~ s/^AND/WHERE/;
+
+ my $query = qq|
+ SELECT min(p.description) AS description,
+ min(p.partnumber) AS partnumber, sum(
+ CASE WHEN i.qty > 0 THEN i.qty ELSE 0 END
+ ) AS sold, sum (
+ CASE WHEN i.qty > 0 THEN i.sellprice * i.qty ELSE 0 END
+ ) AS revenue, sum(
+ CASE WHEN i.qty < 0 THEN i.qty * -1 ELSE 0 END
+ ) AS received, sum(
+ CASE WHEN i.qty < 0 THEN i.sellprice * i.qty * -1
+ ELSE 0 END
+ ) as expenses, min(p.id) as id
+ FROM invoice i
+ INNER JOIN parts p ON (i.parts_id = p.id)
+ LEFT JOIN ar ON (ar.id = i.trans_id)
+ LEFT JOIN ap ON (ap.id = i.trans_id)
+ $where
+ GROUP BY i.parts_id
+ ORDER BY $form->{sort_col}
+ |;
+ my $sth = $dbh->prepare($query) || $form->dberror($query);
+ $sth->execute() || $form->dberror($query);
+ @cols = qw(description sold revenue partnumber received expense);
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ $ref->{net_income} = $ref->{revenue} - $ref->{expense};
+ map {$ref->{$_} =~ s/^\s*//} @cols;
+ map {$ref->{$_} =~ s/\s*$//} @cols;
+ push @{$form->{TB}}, $ref;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+
+}
+
+
sub yearend_statement {
my ($self, $myconfig, $form) = @_;
diff -r -N -U 3 sl-base/bin/js/rp.pl sql-ledger-test/bin/js/rp.pl
--- sl-base/bin/js/rp.pl Thu Mar 9 17:00:40 2006
+++ sql-ledger-test/bin/js/rp.pl Thu Mar 9 18:23:26 2006
@@ -90,6 +90,7 @@
receipts => { title => 'Receipts', vc => 'customer' },
payments => { title => 'Payments' },
projects => { title => 'Project Transactions' },
+ inv_activity => { title => 'Inventory Activity'},
);
$form->{title} = $locale->text($report{$form->{report}}->{title});
@@ -221,6 +222,36 @@
|;
}
+ if ($form->{report} eq "inv_activity"){
+ $gifi = '';
+ print qq|
+
+
+ | |.$locale->text('From').qq| |
+ {fromdate}> |
+ |.$locale->text('To').qq| |
+ |
+
+
+ | |.$locale->text('Period').qq| |
+
+
+
+ |.$locale->text('Current').qq|
+ |.$locale->text('Month').qq|
+ |.$locale->text('Quarter').qq|
+ |.$locale->text('Year').qq|
+ |
+
+
+
+
+ | |.$locale->text("Part Number").qq| |
+ |
+ |.$locale->text('Description').qq| |
+ |
+
|;
+ }
if ($form->{report} eq "income_statement") {
print qq|
@@ -747,6 +778,152 @@
sub continue { &{$form->{nextsub}} };
+sub generate_inv_activity {
+ $form->header;
+
+ RP->inventory_activity(\%myconfig, \%$form);
+
+ $title = $form->escape($form->{title});
+
+# if ($form->{department}) {
+# ($department) = split /--/, $form->{department};
+# $options = $locale->text('Department')." : $department
";
+# $department = $form->escape($form->{department});
+# }
+## if ($form->{projectnumber}) {
+# ($projectnumber) = split /--/, $form->{projectnumber};
+# $options .= $locale->text('Project Number')." : $projectnumber
";
+# $projectnumber = $form->escape($form->{projectnumber});
+# }
+
+ # if there are any dates
+ if ($form->{fromdate} || $form->{todate}) {
+ if ($form->{fromdate}) {
+ $fromdate = $locale->date(\%myconfig, $form->{fromdate}, 1);
+ }
+ if ($form->{todate}) {
+ $todate = $locale->date(\%myconfig, $form->{todate}, 1);
+ }
+
+ $form->{period} = "$fromdate - $todate";
+ } else {
+ $form->{period} = $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
+
+ }
+ $options .= $form->{period};
+
+ @column_index = qw(partnumber description sold revenue received expense);
+
+ $href = qq|rp.pl?path=$form->{path}&action=continue&accounttype=$form->{accounttype}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&l_heading=$form->{l_heading}&l_subtotal=$form->{l_subtotal}&department=$department&projectnumber=$projectnumber&project_id=$form->{project_id}&title=$title&nextsub=$form->{nextsub}|;
+
+ $column_header{partnumber} = qq|
+ |
+ .$locale->text('Part Number').qq| | |;
+ $column_header{description} = qq|
+ |
+ .$locale->text('Description').qq| | |;
+ $column_header{sold} = qq|
+ |
+ .$locale->text('Sold').qq| | |;
+ $column_header{revenue} = qq|
+ |
+ .$locale->text('Revenue').qq| | |;
+ $column_header{received} = qq|
+ |
+ .$locale->text('Received').qq| | |;
+ $column_header{expense} = qq|
+ |
+ .$locale->text('Expense').qq| | |;
+
+
+
+ print qq|
+
+
+
+
+ | $form->{title} |
+
+
+
+ | $options |
+
+
+
+
+ |;
+
+ map { print "$column_header{$_}\n" } @column_index;
+
+ print qq|
+
+|;
+
+
+
+ if ($form->{sort_col} eq 'qty' || $form->{sort_col} eq 'revenue'){
+ $form->{sort_type} = 'numeric';
+ }
+ $i = 0;
+ $cols = "l_transdate=Y&l_name=Y&l_invnumber=Y&summary=1";
+ $dates= "transdatefrom=$form->{fromdate}&transdateto=$form->{todate}&year=$form->{fromyear}&month=$form->{frommonth}&interval=$form->{interval}";
+ $base="path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
+
+ $form->{callback} = "rp.pl?action=continue&$base";
+ $form->{callback} = $form->escape($form->{callback});
+ $callback = "callback=$form->{callback}";
+ # sort the whole thing by account numbers and display
+ foreach $ref (@{ $form->{TB} }) {
+ $description = $form->escape($ref->{description});
+ $i = $i % 2;
+
+ $pnumhref="ic.pl?action=edit&id=$ref->{id}&$base&callback=$form->{callback}";
+ $soldhref="ar.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&$callback";
+ $rechref="ap.pl?action=transactions&partsid=$ref->{id}&$base&$cols&$dates&callback=$form->{callback}";
+
+ $ml = ($ref->{category} =~ /(A|E)/) ? -1 : 1;
+
+ $debit = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
+ $credit = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
+ $begbalance = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2, " ");
+ $endbalance = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2, " ");
+
+ $ref->{partnumber} = qq|$ref->{partnumber}|;
+ $ref->{sold} = qq|$ref->{sold}|;
+ $ref->{received} = qq|$ref->{received}|;
+ map { $column_data{$_} = " | " }
+ @column_index;
+
+
+
+ print qq|
+
+ |;
+ map { print "| $ref->{$_} | \n" } @column_index;
+
+ print qq|
+
+|;
+ ++$i;
+ }
+
+
+ print qq|
+
+
+ |
+
+
+
|
+
+
+
+
+