I am trying to build an update manager, where we pay our commissions to our members. Some members have multiple accounts that earn commissions, but here in the USA, they have to pay taxes so our Check Processor, ADP, combines those checks for those members into one check, so the result may look something like this:
-----------------------------------------------------
|MemberId|ADPID|PayoutAmount|status|statuschanged|t
-----------------------------------------------------
|1 |101 |401.67 |Preissued|1206583466|2008-03-26 13:34:48
-----------------------------------------------------
|3 |101 |308.21 |Preissued|1206583466|2008-03-26 13:34:48
-----------------------------------------------------
|5 |101 |904.34 |Preissued|1206583466|2008-03-26 13:34:48
-----------------------------------------------------
|8 |101 |603.98 |Preissued|1206583466|2008-03-26 13:34:48
-----------------------------------------------------
So when ADP sends their checks to them and we download the check reconciliation, it would show this:
File #, Amount, Check Number, Pay Date
101, 2218.20, 10108, 03/26/2008
So, what we need to do is if they had checks spaning two pay out dates, the amount may not equal all the preissued checks it may be less so I need the automated programming to find those that equal the amount of the check they sent, for example if that adp file said this instead:
File #, Amount, Check Number, Pay Date
101, 1313.86, 10108, 03/26/2008
so it would not equal all the preissued checks, therefore, I need to find a way for Perl to find only those that have a sum of 1313.86, that are preissued and belong to that member only.
Here is how I handle it right now:
# Wrote right now, not a copy and paste, so not exact...
open(FILE, "/path/to/apd/file.csv") or die "could not open file: $!";
my @_FILE = <FILE>;
close(FILE);
foreach my $_line (@_FILE) {
$_line =~ s/\s+//g;
my @_fileparts = split(/,/, $_line);
my $sth = $dbh->prepare(qq{SELECT * FROM `payouts` WHERE `status` =
+"Preissue" AND `adp_id` = ?});
$sth->execute($_fileparts[0]);
while(my $_pay = $sth->fetchrow_hashref()) {
# See this will not work because it may include the one record not
+included in this file record that I split, so I cannot update this ch
+eck ID
}
$sth->finish();
}
Anyhow, I hope I made it clear what I need to do. I need to update records that may not include all of their preissued checks but find the ones that are included in the amount of the check.
Do you know of a way I can do this? I tried doing this:
$sth = $dbh->prepare(qq{ select * from payouts where SUM(amount) = ?})
+;
$sth->execute($_fileparts[2]);
But that gives me an error saying illegal grouping.
So I would appreiciate any advice you can offer, or any where you can point me.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.