Odyssey
GetTrans.prg
1 <?php
2 require_once("$admLibrary/ck_aticket.i");
3 
4 $localzone="US/Mountain";
5 
6 $dms_ok=array('action'=>'string','batch'=>'string','count'=>'string',
7 'tranfmt'=>'digits','looktx'=>'digits','os'=>'digits','manualonly'=>'digits');
8 dms_import($dms_ok);
9 
10 $action = (empty($action) ? "" : $action);
11 $qstring = $_SERVER['QUERY_STRING'];
12 $qstring = preg_replace("/action=[^&]*\&?/","",$qstring);
13 $qstring = preg_replace("/batch=[^&]*\&?/","",$qstring);
14 $qstring = preg_replace("/count=[^&]*\&?/","",$qstring);
15 $qstring = preg_replace("/tranfmt=[^&]*\&?/","",$qstring);
16 $qstring = preg_replace("/looktx=[^&]*\&?/","",$qstring);
17 $qstring = preg_replace("/\&$/","",$qstring);
18 
19 $self = $_SERVER['PHP_SELF'] . "?" . $qstring;
20 
21 $main_url = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . "?" . $qstring;
22 
23 #
24 # Get the list of default descriptions
25 #
26  $codelist=array();
27  $sql = "select trim(trancode), trim(trandesc)
28  from cutrans";
29  $sth = db_query($sql,$dbh);
30  for ($row=0; list($tc,$desc) = db_fetch_array($sth,$row); $row++) {
31  $codelist["$tc"]="$desc";
32  }
33 
34  $codelist['AT']="Transfer";
35  $codelist['CW']="Check Withdrawal";
36 #
37 # Override descriptions with any customized descriptions
38 #
39 
40  $sql = "select trim(trancode), trim(cudesc)
41  from cuhavetrans where cu = '$Cu'";
42  $sth = db_query($sql,$dbh);
43  for ($row=0; list($tc,$desc) = db_fetch_array($sth,$row); $row++) {
44  if ($desc > '') { $codelist["$tc"]="$desc"; }
45  }
46 if (trim($tranfmt) == '') {
47  $sql = "select tranformat from cuadmin where cu='$Cu'";
48  $sth = db_query($sql,$dbh);
49  if($sth) { list($tranfmt) = db_fetch_array($sth,0); }
50 }
51 
52 # use default format #6 if nothing set in the monitor
53  $tranfmt = (intval($tranfmt) == 0 ? '6' : intval($tranfmt));
54 
55 #
56 # build array of features for download format
57 #
58  $noxa="";
59  $achwhere = "";
60  $tcwhere = "";
61  $cwshareonly = "";
62  $tfmt=array();
63  switch ($tranfmt) {
64  case 2:
65  $tfmt=array('ACH','AT','LP');
66  $tcwhere="('AT','LP') ";
67  break;
68  case 3:
69  $tfmt=array('ACH','AT','LP','LA');
70  $tcwhere="('AT','LP','LA') ";
71  break;
72  case 4:
73  $tfmt=array('AT','LP','LA','CW','LC');
74  $tcwhere= "('AT','LP','LA','CW','LC') ";
75  break;
76  case 5:
77  case 6:
78  $tfmt=array();
79  $tfmt=array_keys($codelist);
80  if (in_array('ED',$tfmt)) {
81  $t = array_search('ED', $tfmt);
82  unset($tfmt[$t]);
83  }
84  $tcwhere= "(";
85  $d="";
86  foreach (array_keys($codelist) as $t) {
87  if ("$t" <> 'ED') $tcwhere .= "$d '$t' ";
88  $d=",";
89  }
90  $tcwhere .= ") ";
91  break;
92  case 7:
93  $tfmt=array('ACH','AT','LP','LA');
94  $tcwhere="('AT','LP','LA') ";
95  break;
96  case 8:
97  $tfmt=array('ACH','AT','LP','LA');
98  $tcwhere="('AT','LP','LA') ";
99  break;
100  case 9:
101  $tfmt=array('ACH','AT','LP','LA');
102  $tcwhere="('AT','LP','LA') ";
103  break;
104  case 10:
105  $tfmt=array('AT','LP');
106  $noxa=" and memberto = accountnumber ";
107  $tcwhere= "('AT','LP') ";
108  break;
109  case 11:
110  $tfmt=array('ACH','AT','LP','LA');
111  $tcwhere="('AT','LP','LA') ";
112  break;
113  case 12:
114  $tfmt=array('ACH','AT','LP','LA');
115  $tcwhere="('AT','LP','LA') ";
116  break;
117  case 13:
118  $tfmt=array('ACH','AT');
119  $tcwhere="('AT') ";
120  $achlist = ($Cu == 'LBCU' ? "('A','0')" : "('A','X')");
121  $achwhere = " and trim(tr.reference1) in $achlist and trim(tr.reference2) in $achlist ";
122  break;
123  case 14:
124  $tfmt=array('ACH','AT','LP');
125  $tcwhere="('AT','LP') ";
126  $achlist = ($Cu == 'LBCU' ? "A0" : "AX");
127  break;
128  case 15:
129  $tfmt=array('ACH','AT','LP','LA');
130  $tcwhere="('AT','LP','LA') ";
131  break;
132  case 16:
133  $tfmt=array('ACH','AT','LP');
134  $tcwhere="('AT','LP') ";
135  break;
136  case 17:
137  $tfmt=array('ACH','AT','LP','LA');
138  $tcwhere="('AT','LP','LA') ";
139  break;
140  case 18:
141  $tfmt=array('ACH','AT','LP');
142  $tcwhere="('AT','LP') ";
143  $achlist = ($Cu == 'LBCU' ? "A0" : "AX");
144  break;
145  case 19:
146  $tfmt=array('ACH','AT','LP');
147  $tcwhere="('AT','LP') ";
148  break;
149  case 20:
150  $tfmt=array('ACH','AT');
151  $tcwhere="('AT') ";
152  break;
153  case 21:
154  $tfmt=array('AT','LP','LA','CW','LC');
155  $tcwhere= "('AT','LP','LA','CW','LC') ";
156  $cwshareonly = " and not (transactioncode = 'CW' and substring(reference1,1,1) <> 'S') ";
157 
158  break;
159  default:
160 # tranfmt not found -- refuse to play
161  }
162 
163 switch ($Cu) {
164 
165  case "FEDSTARCU":
166  $tabfile="$home_path/sslforms/FEDSTA.tab";
167  $zipfile="$home_path/sslforms/FEDSTAtr.zip";
168  $tfile="FEDSTA.tab";
169  $zfile="FEDSTAtr.zip";
170  break;
171  case "FRANKLIN":
172  $tabfile="$home_path/sslforms/FRANKL.tab";
173  $zipfile="$home_path/sslforms/FRANKLtr.zip";
174  $tfile="FRANKL.tab";
175  $zfile="FRANKLtr.zip";
176  break;
177  case "IRSBFCU":
178  $tabfile="$home_path/sslforms/IRBFCU.tab";
179  $zipfile="$home_path/sslforms/IRBFCUtr.zip";
180  $tfile="IRBFCU.tab";
181  $zfile="IRBFCUtr.zip";
182  break;
183  default:
184  $tabfile="$home_path/sslforms/${Cu}.tab";
185  $zipfile="$home_path/sslforms/${Cu}tr.zip";
186  $tfile="${Cu}.tab";
187  $zfile="${Cu}tr.zip";
188 }
189 if ($action == "CREATE") {
190  $batch = (empty($batch) ? "new" : $batch);
191  $msg="";
192  if ((!preg_match("/^new$/i",$batch)) && (!preg_match("/^[0-9]*$/",$batch))) {
193  $batch=0;
194  }
195  #
196  # get batch number and identity column
197  #
198  list($batch, $identity) = getbatch($dbh,$Cu,$batch);
199  if (!$identity) {
200  if (preg_match("/^new$/i", $batch)) {
201  $msg = "An error occurred creating your batch, ".
202  "contact HomeCU support.";
203  }else{
204  $msg ="Batch number $batch does not exist.";
205  }
206  $action = "";
207  } else {
208  $sql = "select trim(tz), trim(rt), tranfldsep, traneol
209  from cuadmin where cu='$Cu'";
210  $sth = db_query($sql,$dbh);
211  if($sth) { list($tz, $rt, $t_fls, $t_eol) = db_fetch_array($sth,0); }
212  $tz = ("$tz" == "" ? "Mountain" : $tz);
213  if (strpos("$tz","/") === false) $tz = "US/$tz";
214  $rt = (substr('000000000' . $rt,-9));
215 
216  switch ($t_fls) {
217  case 1: # space
218  $TFLS = " ";
219  break;
220  case 0:
221  default: # standard tab
222  $TFLS = "\t";
223  }
224 
225  switch ($t_eol) {
226  case 1: # nothing
227  $TEOL = "";
228  $zipcmd="zip -qlj";
229  break;
230  case 2: # carriage return, linefeed
231  $TEOL = chr(13).chr(10);
232  $zipcmd="zip -qj";
233  break;
234  case 0:
235  default: # standard newline
236  $TEOL = "\n";
237  $zipcmd="zip -qlj";
238  }
239 
240 
241  if (in_array("ACH",$tfmt)) {
242  $u = "";
243  $sql2 = "select to_char(date,'YYMMDD') from ${Cu}transaction
244  where id = $identity";
245  $sth = db_query($sql2,$dbh);
246  if($sth) { list($tdate) = db_fetch_array($sth,0); }
247  $tdate = ("$tdate" == "" ? strftime('%y%m%d') : $tdate);
248  $sql = "set time zone '$tz'; ";
249  if (in_array("AT",$tfmt) ){
250  $sql.="select tr.id, trim(tr.accountnumber) as fmember,
251  trim(tr.reference1) as facct,
252  upper(f.deposittype) as ftype,
253  trim(coalesce(tr.memberto, tr.accountnumber)) as tmember,
254  trim(tr.reference2) as tacct,
255  upper(t.deposittype) as ttype,
256  tr.transactioncode as tcode,
257  tr.amount as xamount,
258  tr.date as xdate,
259  tr.id as txid,
260  tr.reference5 as rptid
261  from ${Cu}transaction tr,
262  ${Cu}accountbalance f,
263  ${Cu}accountbalance t
264  where id <$identity and id > ALL (select MAX(id)
265  from ${Cu}transaction where id <$identity and
266  accountnumber='CHECKPOINT')
267  and tr.accountnumber <> 'demo'
268  and tr.accountnumber = f.accountnumber
269  and tr.reference1=f.accounttype
270  and (tr.memberto = t.accountnumber or
271  (tr.memberto is null and tr.accountnumber = t.accountnumber))
272  and tr.reference2=t.accounttype
273  and upper(f.deposittype) in ('Y','N','S')
274  and upper(t.deposittype) in ('Y','N','S')
275  $achwhere
276  and tr.transactioncode in ('AT') ";
277  $u = " UNION ALL ";
278  }
279  if (in_array("LP",$tfmt) ){
280  $sql .= "$u select tr.id, trim(tr.accountnumber) as fmember,
281  trim(tr.reference1) as facct,
282  upper(f.deposittype) as ftype,
283  trim(coalesce(tr.memberto, tr.accountnumber)) as tmember,
284  trim(tr.reference2) as tacct,
285  'L' as ttype,
286  tr.transactioncode as tcode,
287  tr.amount as xamount,
288  tr.date as xdate,
289  tr.id as txid,
290  tr.reference5 as rptid
291  from ${Cu}transaction tr,
292  ${Cu}accountbalance f,
293  ${Cu}loanbalance t
294  where id <$identity and id > ALL (select MAX(id)
295  from ${Cu}transaction where id <$identity and
296  accountnumber='CHECKPOINT')
297  and tr.accountnumber <> 'demo'
298  and tr.accountnumber = f.accountnumber
299  and tr.reference1=f.accounttype
300  and (tr.memberto = t.accountnumber or
301  (tr.memberto is null and tr.accountnumber = t.accountnumber))
302  and tr.reference2=t.loannumber
303  and upper(f.deposittype) in ('Y','N','S')
304  and tr.transactioncode in ('LP') ";
305  $u = " UNION ALL ";
306  }
307  if (in_array("LA",$tfmt) ){
308  $sql .= "$u select tr.id, trim(tr.accountnumber) as fmember,
309  trim(tr.reference1) as facct,
310  'L' as ftype,
311  trim(coalesce(tr.memberto, tr.accountnumber)) as tmember,
312  trim(tr.reference2) as tacct,
313  upper(t.deposittype) as ttype,
314  tr.transactioncode as tcode,
315  tr.amount as xamount,
316  tr.date as xdate,
317  tr.id as txid,
318  tr.reference5 as rptid
319  from ${Cu}transaction tr,
320  ${Cu}loanbalance f,
321  ${Cu}accountbalance t
322  where id <$identity and id > ALL (select MAX(id)
323  from ${Cu}transaction where id <$identity and
324  accountnumber='CHECKPOINT')
325  and tr.accountnumber <> 'demo'
326  and tr.accountnumber=f.accountnumber
327  and tr.reference1=f.loannumber
328  and (tr.memberto = t.accountnumber or
329  (tr.memberto is null and tr.accountnumber = t.accountnumber))
330  and tr.reference2=t.accounttype
331  and upper(t.deposittype) in ('Y','N','S')
332  and tr.transactioncode in ('LA')";
333  }
334  } else {
335  $sql = "set time zone '$tz'; ";
336  $sql .= "select id,
337  accountnumber,
338  transactioncode,
339  reference1,
340  reference2,
341  reference3,
342  amount,
343  date,
344  memberto,
345  id as txid,
346  reference5 as rptid
347  from ${Cu}transaction
348  where id <$identity and id > ALL (select MAX(id)
349  from ${Cu}transaction where id < $identity and
350  accountnumber='CHECKPOINT') and accountnumber <> 'demo'
351  and transactioncode in $tcwhere
352  $noxa
353  $cwshareonly ";
354  }
355 
356  $sql .= " order by 1 ";
357  $sth = db_query($sql,$dbh);
358  $sth1 = db_query("set time zone '$localzone'",$dbh);
359  db_free_result($sth1);
360  if(!$sth) {
361  mailerror($sql, pg_last_error(), __LINE__, __FILE__);
362  }
363  if ($msg) {
364 print <<<EOF
365  <div align=center><br><form action="main.prg?ft=21">
366  <table width=80% cellspacing=0 cellpadding=4 border=0>
367  <tr><td class="bar" align=center>Download $Cu Transactions</td></tr>
368  <tr><td class="dtl" align=center>$msg</td></tr>
369  <tr><td class="hdr" align=center><hr>
370  <input type=submit name="action" value="OK">
371  </td></tr></table></form></div>
372 EOF;
373  }else{
374 # DOCUMENT ROOT is not right on Falcon......but it is on Leopard
375 # also, had to chmod 777 the directory to get write permission. Waaaay uncool.
376 #
377  $TRANS=fopen("$tabfile","w");
378  $count=0;
379  switch ($tranfmt) {
380  case 7: # CUC ACH format (no newlines anywhere)
381 
382 # revised 11/2002 to use traneol defined in cuadmin,
383 # which makes the header same as format 8.
384 
385  case 2: # CUSA ACH format (10-digit member + 2 digit trailer)
386  case 3: # Reliance ACH format (3-digit loan squished into 2 char)
387  case 8: # Sharetec ACH format
388  case 9: # Data Systems of Texas ACH format
389  case 11: # Sharetec 4/10 format (4 char acct/loan + 10 char member)
390  case 12: # BSDC Sharetec 4/10 format w/ modified field 8
391  case 15: # DSOT 4/10 format (4 chr acct/4 digit loan + 10 digit member)
392  case 16: # Data Systems of Texas ACH format , no LA
393  case 17: # FedComp 4/10 format (4 chr acct/loan + 10 digit member)
394  case 19: # Cruise ACH format , no LA
395  case 20: # GBS Sharetec 4/10 format w/ modified field 8 AT only
396  $batch = sprintf("%05d",$batch);
397  $tstub = "${batch}${tdate}";
398  $DFI = substr($rt,0,8);
399 # ACH File Header Record
400  fwrite($TRANS,
401  "101 ${rt} ${rt}" . strftime("%y%m%d%H%M") . "0094101" .
402  str_pad("${Cu}",23) . str_pad("DMS HomeCU",31) . "${TEOL}");
403 # ACH Batch Header Record
404  fwrite($TRANS,
405  "5200" . str_pad("Website Transfer",36) .
406  "9 MTEWEB TRANSF" .
407  strftime("%y%m%d") . strftime("%y%m%d") .
408  strftime("%j") . "1${DFI}0000001${TEOL}");
409  $btotal = 0;
410  $bhash = 0;
411  $bcount=0;
412  break;
413  case 13: # CUSA ACH DFI member only; w/ modified field 8
414  case 14: # CUSA ACH DFI member only; w/ modified field 8
415  case 18: # CUSA ACH w/TXT transactions identified
416  # Batch header (5) record has product name
417  $batch = sprintf("%05d",$batch);
418  $tstub = "${batch}${tdate}";
419  $DFI = substr($rt,0,8);
420 # ACH File Header Record
421  fwrite($TRANS,
422  "101 ${rt} ${rt}" . strftime("%y%m%d%H%M") . "0094101" .
423  str_pad("${Cu}",23) . str_pad("DMS HomeCU",31) . "${TEOL}");
424 # ACH Batch Header Record
425  fwrite($TRANS,
426  "5200" . str_pad("Website Transfer",36) .
427  "9 WEBONLINE TRF" .
428  strftime("%y%m%d") . strftime("%y%m%d") .
429  strftime("%j") . "1${DFI}0000001${TEOL}");
430  $btotal = 0;
431  $bhash = 0;
432  $bcount=0;
433  break;
434  case 6: # default format with destination member
435  $line = "AADMS HomeCU";
436  $batch = sprintf("%05d",$batch);
437  $line .= $batch . strftime("%a %b %d %T %Y") . $Cu;
438  $line = str_pad($line,158);
439  fwrite($TRANS, "$line${TEOL}");
440  break;
441  case 10: # CUSA format 2 with 25-char email
442  default:
443  $line = "AADMS HomeCU";
444  $batch = sprintf("%05d",$batch);
445  $line .= $batch . strftime("%a %b %d %T %Y") . $Cu;
446  $line = str_pad($line,80);
447  if ($tranfmt == 4 || $tranfmt == 21) {
448  $line = str_pad($line,170);
449  }
450  fwrite($TRANS, "$line${TEOL}");
451  }
452 
453  for ($row=0; $data = db_fetch_array($sth,$row); $row++) {
454  $count++;
455  if (in_array("ACH",$tfmt)) {
456  if (strpos($data['facct'],"@")) {
457  list($jfacct,$jfmem) = explode("@",$data['facct']);
458  $data['facct'] = $jfacct;
459  $data['fmember'] = trim($jfmem);
460  }
461  if (strpos($data['tacct'],"@")) {
462  list($jtacct,$jtmem) = explode("@",$data['tacct']);
463  $data['tacct'] = $jtacct;
464  $data['tmember'] = trim($jtmem);
465  }
466  } else {
467  if (strpos($data['reference1'],"@")) {
468  list($jfacct,$jfmem) = explode("@",$data['reference1']);
469  $data['reference1'] = $jfacct;
470  $data['accountnumber'] = trim($jfmem);
471  }
472  if (strpos($data['reference2'],"@")) {
473  list($jtacct,$jtmem) = explode("@",$data['reference2']);
474  $data['reference2'] = $jtacct;
475  $data['memberto'] = trim($jtmem);
476  }
477  }
478  switch ($tranfmt) {
479  case 7: # CUC ACH format
480  switch ($data['tcode']) {
481  case "AT":
482  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
483  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
484  break;
485  case "LP":
486  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
487  $ttran = '52';
488  break;
489  case "LA":
490  $ftran = '55';
491  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
492  break;
493  }
494  switch ("$ftran$ttran") {
495  case "2722":
496  $stf="30";
497  $stt="30";
498  break;
499  case "2732":
500  $stf="31";
501  $stt="35";
502  break;
503  case "3722":
504  $stf="35";
505  $stt="31";
506  break;
507  case "3732":
508  $stf="40";
509  $stt="40";
510  break;
511  case "2752":
512  $stf="01";
513  $stt="50";
514  break;
515  case "3752":
516  $stf="02";
517  $stt="51";
518  break;
519  case "5522":
520  $stf="50";
521  $stt="01";
522  break;
523  case "5532":
524  $stf="51";
525  $stt="02";
526  break;
527  }
528  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
529  $data['xamount'] = (substr($data['xamount'],0,8) .
530  substr($data['xamount'],9,2));
531  $btotal += $data['xamount'];
532  $bhash += $DFI;
533 
534  $addxdate = date("mdHis",strtotime(substr($data['xdate'],0,19)));
535  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
536 
537  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
538  $fDFI = substr(sprintf("%06d",$data['fmember']) . sprintf("%02d",$data['facct']), 0, 8);
539  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
540  $tDFI = substr(sprintf("%06d",$data['tmember']) . sprintf("%02d",$data['tacct']), 0, 8);
541  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
542  $trace=("${tstub}" . sprintf("%03d",$count));
543  fwrite($TRANS,"6${ftran}${rt}${fDFI} ${tDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
544  $bcount++;
545  fwrite($TRANS,"702${stf}1" . str_pad("",19) .
546  "${addxdate}" . str_pad("",44) . "${trace}0${TEOL}");
547  $bcount++;
548  fwrite($TRANS,"6${ttran}${rt}${tDFI} ${fDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
549  $bcount++;
550  fwrite($TRANS,"702${stt}2" . str_pad("",19) .
551  "${addxdate}" . str_pad("",44) . "${trace}1${TEOL}");
552  $bcount++;
553 
554  break;
555  case 2: # CUSA ACH format
556  switch ($data['tcode']) {
557  case "AT":
558  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
559  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
560  break;
561  case "LP":
562  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
563  $ttran = '52';
564  break;
565  }
566  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
567  $data['xamount'] = (substr($data['xamount'],0,8) .
568  substr($data['xamount'],9,2));
569  $btotal += $data['xamount'];
570  $bhash += $DFI;
571 
572  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
573 
574  $tacct = sprintf("%02d",$data['tacct']);
575  $facct = sprintf("%02d",$data['facct']);
576 
577  $fDFI = substr(str_pad(trim(sprintf("%10s",$data['fmember'])) . '-' . $facct, 17), 0, 17);
578  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
579  $tDFI = substr(str_pad(trim(sprintf("%10s",$data['tmember'])) . '-' . $tacct, 17), 0, 17);
580  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
581  $trace=("${tstub}" . sprintf("%03d",$count));
582  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
583  $bcount++;
584  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
585  $bcount++;
586 
587  break;
588  case 3: # Reliance ACH format
589  switch ($data['tcode']) {
590  case "AT":
591  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
592  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
593  break;
594  case "LP":
595  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
596  $ttran = '52';
597  break;
598  case "LA":
599  $ftran = '55';
600  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
601  break;
602  }
603  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
604  $data['xamount'] = (substr($data['xamount'],0,8) .
605  substr($data['xamount'],9,2));
606  $btotal += $data['xamount'];
607  $bhash += $DFI;
608 
609  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
610 
611  $tacct = sprintf("%02d",$data['tacct']);
612  $tacct = (intval($tacct) > 99 ? 'X' . substr($tacct,-1,1) : $tacct);
613  $facct = sprintf("%02d",$data['facct']);
614  $facct = (intval($facct) > 99 ? 'X' . substr($facct,-1,1) : $facct);
615 
616  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
617  $fDFI = substr(str_pad($facct . sprintf("%09d",$data['fmember']), 17), 0, 17);
618  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
619  $tDFI = substr(str_pad($tacct . sprintf("%09d",$data['tmember']), 17), 0, 17);
620  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
621  $trace=("${tstub}" . sprintf("%03d",$count));
622  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
623  $bcount++;
624  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
625  $bcount++;
626 
627  break;
628  case 8: # Sharetec ACH format
629  switch ($data['tcode']) {
630  case "AT":
631  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
632  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
633  break;
634  case "LP":
635  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
636  $ttran = '52';
637  break;
638  case "LA":
639  $ftran = '55';
640  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
641  break;
642  }
643  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
644  $data['xamount'] = (substr($data['xamount'],0,8) .
645  substr($data['xamount'],9,2));
646  $btotal += $data['xamount'];
647  $bhash += $DFI;
648 
649  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
650 
651  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
652  $fDFI = substr(str_pad((sprintf("%02d",$data['facct']) . sprintf("%09d",$data['fmember'])), 17), 0, 17);
653  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
654  $tDFI = substr(str_pad((sprintf("%02d",$data['tacct']) . sprintf("%09d",$data['tmember'])), 17), 0, 17);
655  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
656  $trace=("${tstub}" . sprintf("%03d",$count));
657  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
658  $bcount++;
659  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
660  $bcount++;
661 
662  break;
663  case 9: # CUSolutions
664  case 16: # Data Systems of Texas ACH format w/o LA
665  switch ($data['tcode']) {
666  case "AT":
667  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
668  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
669  break;
670  case "LP":
671  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
672  $ttran = '52';
673  break;
674  case "LA":
675  $ftran = '55';
676  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
677  break;
678  }
679  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
680  $data['xamount'] = (substr($data['xamount'],0,8) .
681  substr($data['xamount'],9,2));
682  $btotal += $data['xamount'];
683  $bhash += $DFI;
684 
685  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
686  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
687  $fDFI = substr(str_pad((sprintf("%02d",$data['facct']) . sprintf("%010d",$data['fmember'])),17), 0, 17);
688  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
689  $tDFI = substr(str_pad((sprintf("%02d",$data['tacct']) . sprintf("%010d",$data['tmember'])),17), 0, 17);
690  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
691  $trace=("${tstub}" . sprintf("%03d",$count));
692  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
693  $bcount++;
694  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
695  $bcount++;
696 
697  break;
698  case 19: # Cruise ACH format w/o LA
699  switch ($data['tcode']) {
700  case "AT":
701  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
702  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
703  break;
704  case "LP":
705  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
706  $ttran = '52';
707  break;
708  case "LA":
709  $ftran = '55';
710  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
711  break;
712  }
713  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
714  $data['xamount'] = (substr($data['xamount'],0,8) .
715  substr($data['xamount'],9,2));
716  $btotal += $data['xamount'];
717  $bhash += $DFI;
718 
719  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
720  $fDFI = substr(str_pad((str_pad($data['facct'],4,0) . sprintf("%08d",$data['fmember'])),17), 0, 17);
721  $fmem = substr(str_pad("$fDFI",22), 0, 22);
722  $tDFI = substr(str_pad((str_pad($data['tacct'],4,0) . sprintf("%08d",$data['tmember'])),17), 0, 17);
723  $tmem = substr(str_pad("$tDFI",22), 0, 22);
724  $trace=("${tstub}" . sprintf("%03d",$count));
725  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
726  $bcount++;
727  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
728  $bcount++;
729 
730  break;
731  case 11: # Sharetec 4/10 format (4 char acct/loan + 10 char member)
732  switch ($data['tcode']) {
733  case "AT":
734  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
735  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
736  break;
737  case "LP":
738  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
739  $ttran = '52';
740  break;
741  case "LA":
742  $ftran = '55';
743  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
744  break;
745  }
746  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
747  $data['xamount'] = (substr($data['xamount'],0,8) .
748  substr($data['xamount'],9,2));
749  $btotal += $data['xamount'];
750  $bhash += $DFI;
751 
752  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
753 
754  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
755  $fDFI = substr(str_pad((sprintf("%04d",$data['facct']) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
756  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
757  $tDFI = substr(str_pad((sprintf("%04d",$data['tacct']) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
758  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
759  $trace=("${tstub}" . sprintf("%03d",$count));
760  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
761  $bcount++;
762  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
763  $bcount++;
764 
765  break;
766  case 15: # DSOT 4/10 format (4 chr acct/4 digit loan + 10 digit member)
767  switch ($data['tcode']) {
768  case "AT":
769  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
770  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
771  $fDFI = substr(str_pad((str_pad($data['facct'],4) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
772  $tDFI = substr(str_pad((str_pad($data['tacct'],4) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
773  break;
774  case "LP":
775  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
776  $ttran = '52';
777  $fDFI = substr(str_pad((str_pad($data['facct'],4) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
778  $tDFI = substr(str_pad((sprintf("%04d",$data['tacct']) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
779  break;
780  case "LA":
781  $ftran = '55';
782  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
783  $fDFI = substr(str_pad((sprintf("%04d",$data['facct']) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
784  $tDFI = substr(str_pad((str_pad($data['tacct'],4) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
785  break;
786  }
787  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
788  $data['xamount'] = (substr($data['xamount'],0,8) .
789  substr($data['xamount'],9,2));
790  $btotal += $data['xamount'];
791  $bhash += $DFI;
792 
793  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
794 
795  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
796  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
797  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
798  $trace=("${tstub}" . sprintf("%03d",$count));
799  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
800  $bcount++;
801  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
802  $bcount++;
803 
804  break;
805  case 17: # FedComp 4/10 format (4 chr acct/loan + 10 digit member)
806  switch ($data['tcode']) {
807  case "AT":
808  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
809  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
810  $fDFI = substr(str_pad((str_pad($data['facct'],4) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
811  $tDFI = substr(str_pad((str_pad($data['tacct'],4) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
812  break;
813  case "LP":
814  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
815  $ttran = '52';
816  $fDFI = substr(str_pad((str_pad($data['facct'],4) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
817  $tDFI = substr(str_pad((str_pad($data['tacct'],4) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
818  break;
819  case "LA":
820  $ftran = '55';
821  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
822  $fDFI = substr(str_pad((str_pad($data['facct'],4) . sprintf("%010d",$data['fmember'])), 17), 0, 17);
823  $tDFI = substr(str_pad((str_pad($data['tacct'],4) . sprintf("%010d",$data['tmember'])), 17), 0, 17);
824  break;
825  }
826  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
827  $data['xamount'] = (substr($data['xamount'],0,8) .
828  substr($data['xamount'],9,2));
829  $btotal += $data['xamount'];
830  $bhash += $DFI;
831 
832  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
833 
834  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
835  $fmem = substr(str_pad("FROM $fDFI",22), 0, 22);
836  $tmem = substr(str_pad("TO $tDFI",22), 0, 22);
837  $trace=("${tstub}" . sprintf("%03d",$count));
838  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
839  $bcount++;
840  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
841  $bcount++;
842 
843  break;
844  case 12: # BSDC Sharetec 4/10 format (4 char acct/loan + 10 char member)
845  case 20: # GBS Sharetec 4/10 format w/ modified field 8 AT only
846  # Individual ID = 4 char DP acct . 4 digit Loan . 10 char member . FROM | TO
847  switch ($data['tcode']) {
848  case "AT":
849  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
850  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
851  $fmem = str_pad($data['facct'],4) . '0000' .
852  sprintf("%010d",$data['fmember']) . "FROM";
853  $tmem = str_pad($data['tacct'],4) . '0000' .
854  sprintf("%010d",$data['tmember']) . "TO ";
855  $fDFI = str_pad($data['facct'],4) .
856  sprintf("%010d",$data['fmember']);
857  $tDFI = str_pad($data['tacct'],4) .
858  sprintf("%010d",$data['tmember']);
859  break;
860  case "LP":
861  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
862  $ttran = '52';
863  $fmem = str_pad($data['facct'],4) . '0000' .
864  sprintf("%010d",$data['fmember']) . "FROM";
865  $tmem = " " . sprintf("%04d",$data['tacct']) .
866  sprintf("%010d",$data['tmember']) . "TO ";
867  $fDFI = str_pad($data['facct'],4) .
868  sprintf("%010d",$data['fmember']);
869  $tDFI = sprintf("%04d",$data['tacct']) .
870  sprintf("%010d",$data['tmember']);
871  break;
872  case "LA":
873  $ftran = '55';
874  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
875  $fmem = " " . sprintf("%04d",$data['facct']) .
876  sprintf("%010d",$data['fmember']) . "FROM";
877  $tmem = str_pad($data['tacct'],4) . '0000' .
878  sprintf("%010d",$data['tmember']) . "TO ";
879  $fDFI = sprintf("%04d",$data['facct']) .
880  sprintf("%010d",$data['fmember']);
881  $tDFI = str_pad($data['tacct'],4) .
882  sprintf("%010d",$data['tmember']);
883  break;
884  }
885  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
886  $data['xamount'] = (substr($data['xamount'],0,8) .
887  substr($data['xamount'],9,2));
888  $btotal += $data['xamount'];
889  $bhash += $DFI;
890 
891  $data['xdate'] = date("Ymd His",strtotime(substr($data['xdate'],0,19)));
892  $trace=("${tstub}" . sprintf("%03d",$count));
893 
894  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
895  // *** FORMAT fDFI, tDFI, tmem, fmem
896  $fDFI = substr(str_pad($fDFI, 17), 0, 17);
897  $tDFI = substr(str_pad($tDFI, 17), 0, 17);
898  $fmem = substr(str_pad($fmem, 22), 0, 22);
899  $tmem = substr(str_pad($tmem, 22), 0, 22);
900  // ** OKAY TO WRITE
901 
902  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${data['xdate']}${tmem} 0${trace}0${TEOL}");
903  $bcount++;
904  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${data['xdate']}${fmem} 0${trace}1${TEOL}");
905  $bcount++;
906 
907  break;
908  case 13: # CUSA ACH DFI member only; w/ modified field 8
909  case 14: # CUSA ACH DFI member only; w/ modified field 8
910  # Individual ID = 4 char acct#/Loan# . 10 char member . FROM | TO
911  case 18: # CUSA ACH DFI member only; w/ modified field 8
912  # Individual ID = 4 char acct#/Loan# . 10 char member . FROM | TO
913  switch ($data['tcode']) {
914  case "AT":
915  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
916  $ttran = ($data['ttype'] == 'Y' ? '22' : '32');
917  $tDFI = (strpos($achlist,$data['tacct']) === false ?
918  str_pad(($data['tmember'] . "-" . $data['tacct']),17)
919  : str_pad($data['tmember'],17));
920  break;
921  case "LP":
922  $ftran = ($data['ftype'] == 'Y' ? '27' : '37');
923  $ttran = '52';
924  if ($Cu == 'GCCU') {
925  # 52 record tDFI always includes suffix
926  $tDFI = str_pad(($data['tmember'] . "-" . $data['tacct']),17);
927  } else {
928  # 52 record tDFI does not include suffix if it's 'A'
929  $tDFI = ($data['tacct'] == 'A' ?
930  str_pad($data['tmember'],17) :
931  str_pad(($data['tmember'] . "-" . $data['tacct']),17));
932  }
933  break;
934  }
935  $fDFI = (strpos($achlist,$data['facct']) === false ?
936  str_pad(($data['fmember'] . "-" . $data['facct']),17)
937  : str_pad($data['fmember'],17));
938  if ($tranfmt == '18') {
939  $txt = (trim($data['rptid']) == 'TXT' ? 'TXT ' : '');
940  $fmem = str_pad("${txt}FR " . $data['fmember']
941  ."-". $data['facct'],15);
942  $tmem = str_pad("${txt}TO " . $data['tmember']
943  ."-". $data['tacct'],15);
944  } else {
945  $fmem = str_pad("FROM " . $data['fmember']
946  ."-". $data['facct'],15);
947  $tmem = str_pad("TO " . $data['tmember']
948  ."-". $data['tacct'],15);
949  }
950  $data['xamount'] = sprintf("%011.2f",$data['xamount']);
951  $data['xamount'] = (substr($data['xamount'],0,8) .
952  substr($data['xamount'],9,2));
953  $btotal += $data['xamount'];
954  $bhash += $DFI;
955 
956  $data['xdate'] = date("Ymd His ",strtotime(substr($data['xdate'],0,19)));
957  $trace=("${tstub}" . sprintf("%03d",$count));
958 
959 
960  // *** MWS 11/15/2004 -- Added substring function to be sure the pieces to not exceed ACH Formatted Piece
961  // *** FORMAT fDFI, tDFI, tmem, fmem -- They have already been padded, but should not hurt to keep the padding here again
962  $fDFI = substr(str_pad($fDFI, 17), 0, 17);
963  $tDFI = substr(str_pad($tDFI, 17), 0, 17);
964  $fmem = substr(str_pad($fmem, 15), 0, 15);
965  $tmem = substr(str_pad($tmem, 15), 0, 15);
966  // ** OKAY TO WRITE
967 
968  fwrite($TRANS,"6${ftran}${rt}${fDFI}${data['xamount']}${tmem}${data['xdate']} 0${trace}0${TEOL}");
969  $bcount++;
970  fwrite($TRANS,"6${ttran}${rt}${tDFI}${data['xamount']}${fmem}${data['xdate']} 0${trace}1${TEOL}");
971  $bcount++;
972 
973  break;
974  case 4:
975  case 21:
976  case 5:
977  switch ($data['transactioncode']) {
978  case "AT":
979  $FromCode = "TF";
980  $ToCode = "TT";
981  break;
982  case "LA":
983  $FromCode = "LA";
984  $ToCode = "TT";
985  break;
986  case "LC":
987  $FromCode = "LA";
988  $ToCode = "CW";
989  $data['reference2'] = (trim($data['reference2']) == "" || trim($data['reference2']) == "-" ? "Chk Withdraw" : "{$data['reference2']}");
990  break;
991  case "LP":
992  $FromCode = "LP";
993  $ToCode = "LP";
994  break;
995  case "CW":
996  $FromCode = "CW";
997  $ToCode = "CW";
998  $data['reference2'] = (trim($data['reference2']) == "" || trim($data['reference2']) == "-" ? "Chk Withdraw" : "{$data['reference2']}");
999  break;
1000  case "GM":
1001  $FromCode = "GM";
1002  $ToCode = "GM";
1003  $data['reference2'] = (trim($data['reference2']) == "" ? "Gen Merc" : "{$data['reference2']}");
1004  break;
1005  case "CP":
1006  $FromCode = "CC";
1007  $ToCode = "CC";
1008  $data['reference2'] = (trim($data['reference2']) == "" ? "Credit Card" : "{$data['reference2']}");
1009  break;
1010  case "VP":
1011  $FromCode = "CC";
1012  $ToCode = "VP";
1013  $data['reference2'] = (trim($data['reference2']) == "" ? "Visa Card" : "{$data['reference2']}");
1014  break;
1015  case "VH":
1016  $FromCode = "CC";
1017  $ToCode = "VH";
1018  $data['reference2'] = (trim($data['reference2']) == "" ? "Visa Home Eq" : "{$data['reference2']}");
1019  break;
1020  case "VG":
1021  $FromCode = "CC";
1022  $ToCode = "VG";
1023  $data['reference2'] = (trim($data['reference2']) == "" ? "Visa Gold" : "{$data['reference2']}");
1024  break;
1025  case "VC":
1026  $FromCode = "CC";
1027  $ToCode = "VC";
1028  $data['reference2'] = (trim($data['reference2']) == "" ? "Visa Classic" : "{$data['reference2']}");
1029  break;
1030  case "MP":
1031  $FromCode = "CC";
1032  $ToCode = "MP";
1033  $data['reference2'] = (trim($data['reference2']) == "" ? "Mastercard" : "{$data['reference2']}");
1034  break;
1035  }
1036  if ($tranfmt == 1) {
1037 # Sharetec format with source member; destination member implied as same
1038  $data['date'] = date("M d Y h:i:sA",strtotime(substr($data['date'],0,19)));
1039  $data['amount'] = sprintf("%12.2f", $data['amount'] * -1);
1040  $data['txid'] = sprintf("%08d",$data['txid']);
1041 
1042  fwrite($TRANS,"$FromCode${TFLS}${data['accountnumber']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TFLS}$ToCode${TFLS}${data['amount']}${TFLS}${data['date']}${TFLS}${data['txid']}${TFLS}${data['reference3']}${TEOL}");
1043  }
1044 
1045  if ($tranfmt == 4 || $tranfmt == 21) {
1046 # AMI
1047  $data['date'] = date("mdy h:i:sA",strtotime(substr($data['date'],0,19)));
1048  $data['date'] = str_pad( $data['date'],25);
1049  $data['amount'] = sprintf("%12.2f", $data['amount']);
1050  $data['memberto'] = ($data['memberto'] == "" ? $data['accountnumber'] : $data['memberto']);
1051  $data['txid'] = sprintf("%08d",$data['txid']);
1052  if (strlen($data['accountnumber']) > 12) {
1053  $data['accountnumber'] = substr( $data['accountnumber'],0,12);
1054  } else {
1055  $data['accountnumber'] = str_pad( $data['accountnumber'],12);
1056  }
1057  if (strlen($data['memberto']) > 12) {
1058  $data['memberto'] = substr( $data['memberto'],0,12);
1059  } else {
1060  $data['memberto'] = str_pad( $data['memberto'],12);
1061  }
1062  if (strlen($data['reference1']) > 12) {
1063  $data['reference1'] = substr( $data['reference1'],0,12);
1064  } else {
1065  $data['reference1'] = str_pad( $data['reference1'],12);
1066  }
1067  if (strlen($data['reference2']) > 12) {
1068  $data['reference2'] = substr( $data['reference2'],0,12);
1069  } else {
1070  $data['reference2'] = str_pad( $data['reference2'],12);
1071  }
1072  if (strlen($data['reference3']) > 64) {
1073  $data['reference3'] = substr( $data['reference3'],0,64);
1074  } else {
1075  $data['reference3'] = str_pad( $data['reference3'],64);
1076  }
1077 
1078  fwrite($TRANS,"$FromCode${TFLS}${data['accountnumber']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TFLS}$ToCode${TFLS}${data['memberto']}${TFLS}${data['amount']}${TFLS}${data['date']}${TFLS}${data['txid']}${TFLS}${data['reference3']}${TEOL}");
1079  }
1080 
1081  if ($tranfmt == 3) {
1082 # Compusource format with forced same source and destination member
1083  $data['date'] = date("M d Y h:i:sA",strtotime(substr($data['date'],0,19)));
1084  $amountF = sprintf("%12.2f", $data['amount'] * -1);
1085  $amountT = sprintf("%12.2f", $data['amount']);
1086 
1087  if ($data['transactioncode'] == "MA") {
1088  fwrite($TRANS,"${data['accountnumber']}${TFLS}NA${TFLS}${data['transactioncode']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TEOL}");
1089  } else {
1090  fwrite($TRANS,"${data['accountnumber']}${TFLS}${data['reference1']}${TFLS}$FromCode${TFLS}${amountF}${TFLS}${data['date']}${TEOL}");
1091  fwrite($TRANS,"${data['accountnumber']}${TFLS}${data['reference2']}${TFLS}$ToCode${TFLS}${amountT}${TFLS}${data['date']}${TEOL}");
1092  }
1093  }
1094 
1095  if ($tranfmt == 5) {
1096 # Compusource format allowing for cross-account transfers
1097 # (source and destination member numbers may or may not be the same)
1098  $data['date'] = date("M d Y h:i:sA",strtotime(substr($data['date'],0,19)));
1099  $amountF = sprintf("%12.2f", $data['amount'] * -1);
1100  $amountT = sprintf("%12.2f", $data['amount']);
1101  $data['memberto'] = ($data['memberto'] == "" ? $data['accountnumber'] : $data['memberto']);
1102 
1103  if ($data['transactioncode'] == "MA") {
1104  fwrite($TRANS,"${data['accountnumber']}${TFLS}NA${TFLS}${data['transactioncode']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TEOL}");
1105  } else {
1106  fwrite($TRANS,"${data['accountnumber']}${TFLS}${data['reference1']}${TFLS}$FromCode${TFLS}${amountF}${TFLS}${data['date']}${TEOL}");
1107  fwrite($TRANS,"${data['memberto']}${TFLS}${data['reference2']}${TFLS}$ToCode${TFLS}${amountT}${TFLS}${data['date']}${TEOL}");
1108  }
1109  }
1110  break;
1111 
1112  case 10: # CUSA format 2 with 25-char email
1113 # CUSA default download w/ 25 character email address (reference3);
1114 # default download format with source member number; destination implied as same
1115  # pad to desired size
1116  $data['accountnumber'] = str_pad( $data['accountnumber'],12);
1117  $data['date'] = date("Y-m-d h:i:s T",strtotime(substr($data['date'],0,19)));
1118  $data['date'] = str_pad( $data['date'],25);
1119  $data['transactioncode'] = str_pad( $data['transactioncode'],2);
1120  $data['reference1'] = str_pad( $data['reference1'],12);
1121  $data['reference2'] = str_pad( $data['reference2'],12);
1122  if (strlen($data['reference3']) > 25) {
1123  $data['reference3'] = substr( $data['reference3'],0,25);
1124  } else {
1125  $data['reference3'] = str_pad( $data['reference3'],25);
1126  }
1127  $data['amount'] = sprintf("%12.2f", $data['amount']);
1128  fwrite($TRANS,"${data['accountnumber']}${TFLS}${data['date']}${TFLS}${data['transactioncode']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TFLS}${data['reference3']}${TFLS}${data['amount']}${TEOL}");
1129  break;
1130 
1131  case 0:
1132  case 6:
1133  default:
1134 # same as default download format except add destination member number
1135  # pad to desired size
1136  $data['accountnumber'] = str_pad( $data['accountnumber'],12);
1137  $data['memberto'] = ($data['memberto'] == "" ? $data['accountnumber'] : $data['memberto']);
1138  $data['memberto'] = str_pad( $data['memberto'],12);
1139  $data['date'] = date("Y-m-d h:i:s T",strtotime(substr($data['date'],0,19)));
1140  $data['date'] = str_pad( $data['date'],25);
1141  $data['transactioncode'] = str_pad( $data['transactioncode'],2);
1142  $data['reference1'] = str_pad( $data['reference1'],12);
1143  $data['reference2'] = str_pad( $data['reference2'],12);
1144  $data['reference3'] = str_pad( $data['reference3'],64);
1145  $data['amount'] = sprintf("%12.2f", $data['amount']);
1146  fwrite($TRANS,"${data['accountnumber']}${TFLS}${data['date']}${TFLS}${data['transactioncode']}${TFLS}${data['reference1']}${TFLS}${data['reference2']}${TFLS}${data['reference3']}${TFLS}${data['amount']}${TFLS}${data['memberto']}${TEOL}");
1147  }
1148  }
1149  switch ($tranfmt) {
1150  case 7: # CUC ACH format without newlines
1151 # revised 11/2002 to use traneol defined in cuadmin,
1152 # which makes the trailer same as format 8.
1153  case 2: # CUSA ACH format
1154  case 3: # Reliance ACH format
1155  case 8: # Sharetec ACH format
1156  case 9: # Data Systems of Texas ACH format
1157  case 11: # Sharetec 4/10 format (4 char acct/loan + 10 char member)
1158  case 12: # BSDC Sharetec 4/10 format w/ modified field 8
1159  case 13: # CUSA ACH DFI member only; w/ modified field 8
1160  case 14: # CUSA ACH DFI member only; w/ modified field 8
1161  case 15: # DSOT 4/10 format (4 chr acct/4 digit loan + 10 digit member)
1162  case 16: # Data Systems of Texas ACH format w/o LA
1163  case 17: # FedComp 4/10 format (4 chr acct/loan + 10 digit member)
1164  case 18: # CUSA ACH w/TXT transfers identified
1165  case 19: # Cruise ACH format w/o LA
1166  case 20: # GBS Sharetec 4/10 format w/ modified field 8 AT only
1167 # ACH Batch Control Trailer Record
1168  fwrite($TRANS,
1169  "8200" . sprintf("%06d",$bcount) .
1170  sprintf("%010d",substr($bhash,-10)) .
1171  sprintf("%012d",$btotal) .
1172  sprintf("%012d",$btotal) .
1173  str_pad("9",35) . "${DFI}0000001${TEOL}");
1174 # ACH File Control Trailer Record
1175  fwrite($TRANS,
1176  "9000001" .
1177  sprintf("%06d",(ceil(($bcount+4)/10))) .
1178  sprintf("%08d",$bcount) .
1179  sprintf("%010d",substr($bhash,-10)) .
1180  sprintf("%012d",$btotal) .
1181  sprintf("%012d",$btotal) .
1182  str_pad(" ",39). "${TEOL}");
1183  break;
1184  case 10: # CUSA format 2 with 25-char email
1185  case 0:
1186  case 4:
1187  case 21:
1188  fwrite($TRANS,str_pad("ZZ",170) . "${TEOL}");
1189  break;
1190  case 5:
1191  fwrite($TRANS,str_pad("ZZ",80) . "${TEOL}");
1192  break;
1193  case 6:
1194  default:
1195  fwrite($TRANS,str_pad("ZZ",158) . "${TEOL}");
1196  }
1197  fclose($TRANS);
1198  db_free_result($sth);
1199 
1200  system("$zipcmd $zipfile $tabfile");
1201  header("Location: $main_url&action=SHOW&batch=$batch&count=$count");
1202  exit;
1203  }
1204  }
1205 }
1206 if ($action == "SHOW") {
1207  $b = ($batch * 1);
1208  $bnum = intval($batch);
1209  list($b, $identity) = getbatch($dbh,$Cu,$b);
1210  if (!$identity) {
1211  $msg ="Batch number $batch does not exist.";
1212  $action = "";
1213  } else {
1214  $sql = "select trim(tz), tranformat from cuadmin where cu='$Cu'";
1215  $sth = db_query($sql,$dbh);
1216  if($sth) { list($tz, $tranfmt) = db_fetch_array($sth,0); }
1217  $tz = ("$tz" == "" ? "Mountain" : $tz);
1218  if (strpos("$tz","/") === false) $tz = "US/$tz";
1219  $tranfmt = trim($tranfmt);
1220  $sql = "set time zone '$tz'; select accountnumber,
1221  reference3,
1222  transactioncode,
1223  amount,
1224  date,
1225  memberto,
1226  reference1,
1227  reference2,
1228  id as txid,
1229  reference5 as repeatid
1230  from ${Cu}transaction
1231  where id <$identity and id > ALL (select MAX(id)
1232  from ${Cu}transaction where id < $identity and
1233  accountnumber='CHECKPOINT') and accountnumber <> 'demo'
1234  order by date ";
1235  $sth = db_query($sql,$dbh);
1236  if(!$sth) {
1237  mailerror($sql, pg_last_error(), __LINE__, __FILE__);
1238  }
1239  $sth1 = db_query("set time zone '$localzone'",$dbh);
1240  db_free_result($sth1);
1241 
1242  if (in_array("ACH",$tfmt)) {
1243  $tabhdr="ACH-Formatted file";
1244  } else {
1245  $tabhdr="TAB-Delimited file";
1246  }
1247 
1248 #
1249 # Find out if there are any manual transactions in this batch
1250 #
1251  $sql2= "select count(*) from ${Cu}transaction
1252  where id <$identity and id > ALL (select MAX(id)
1253  from ${Cu}transaction where id < $identity and
1254  accountnumber='CHECKPOINT') and accountnumber <> 'demo'
1255  and (transactioncode not in $tcwhere ";
1256  if ($noxa > '') { $sql2 .= " or memberto <> accountnumber "; }
1257  if ($achwhere > '') { $sql2 .= " or trim(reference1) not in $achlist or trim(reference2) not in $achlist "; }
1258  if ($cwshareonly > '') { $sql2 .= " or ( transactioncode = 'CW' and substring(reference1,1,1) <> 'S') "; }
1259  $sql2 .= ")";
1260  $sth2 = db_query($sql2,$dbh);
1261  if($sth2) { list($tskcount) = db_fetch_array($sth2,0); }
1262 
1263  $tskcount = ("$tskcount" == "" ? 0 : $tskcount);
1264 #
1265 # if $tskcount is > 0, show message for manual transactions
1266 # if $count == 0, show message for empty batch and don't link files
1267 #
1268  if ($tskcount > 0 ) {
1269  if (in_array("ACH",$tfmt)) {
1270  $mantxn = '<td bgcolor="yellow" align="center" colspan="2">Caution! Batch contains non-ACH transactions. Manual entry required.';
1271  } else {
1272  $mantxn = '<td bgcolor="yellow" align="center" colspan="2">Caution! Batch contains transactions which will not post automatically. Manual entry required.';
1273  }
1274  } else {
1275  $mantxn = '<td colspan="2">&nbsp;';
1276  }
1277  $tottxn = $tskcount + $count;
1278  print <<<EOF
1279  <div align=center><br>
1280  <table width=90% cellspacing=0 cellpadding=2 border=0>
1281  <tr><td class="bar" align=center colspan=2>Download $Cu Transactions</td></tr>
1282  <tr><td class="dtl"><b>$tottxn Transactions in Batch $batch.</b><br>
1283  <b>$tskcount Manual Transactions</b></td>
1284 EOF;
1285  if ($ft != 36 ) {
1286  if ( $count > 0) {
1287  print <<< EOF
1288  <td class="dtl" valign="bottom">Download <a href="main.prg/sslforms/${zfile}?ft=82" target="get_file" class="link2"> ZIPPED file</a> ${zfile}</td></tr>
1289  <tr><td class="dtl">&nbsp;</td><td class="dtl">Download <a href="main.prg/sslforms/${tfile}?ft=82" target="get_file" class="link2"> ${tabhdr}</a> ${tfile}</td></tr>
1290 EOF;
1291 
1292  } else {
1293 
1294 print <<<EOF
1295  <td class="dtl" valign="bottom">ZIPPED file ${zfile} is empty</td></tr>
1296  <tr><td class="dtl">&nbsp;</td><td class="dtl">${tabhdr} ${tfile} is empty</td></tr>
1297 EOF;
1298  }
1299 print "<tr><td class='dtl'>";
1300 if ($tskcount > 0 ) {
1301 print <<<EOF
1302  <a href="javascript:print_man()"
1303  class="link2">View Manual Transactions Only</a></td>
1304  <script language="javascript">
1305  <!--
1306  function print_man() {
1307  //var win_det = "status=no, location=yes, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes";
1308  var win_det = "toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes";
1309  var url = "main.prg?ft=36&action=CREATE&batch=$bnum&tranfmt=$tranfmt&manualonly=1";
1310 
1311  window.open (url, "print_view", win_det, false);
1312  }
1313  // -->
1314  </script>
1315 EOF;
1316 } else {
1317 print "&nbsp;</td>";
1318 }
1319 print <<<EOF
1320  <td class="dtl" align="right"><a href="javascript:print_view()"
1321  class="link2">View Printable Version</a></td></tr>
1322  <script language="javascript">
1323  <!--
1324  function print_view() {
1325  //var win_det = "status=no, location=yes, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes";
1326  var win_det = "toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes";
1327  var url = "main.prg?ft=36&action=CREATE&batch=$bnum&tranfmt=$tranfmt";
1328 
1329  window.open (url, "print_view", win_det, false);
1330  }
1331  // -->
1332  </script>
1333 EOF;
1334  } else {
1335  print "
1336  <td class=dtl>
1337  <a href=\"javascript:window.print()\" class=\"link2\">Print Page</a>&nbsp;&nbsp;&nbsp;
1338  <a href=\"javascript:window.close()\" class=\"link2\">Close Window</a>
1339  </td></tr>";
1340  }
1341  print <<< EOF
1342  <tr>$mantxn</td></tr></table><br>
1343  </div>
1344  <div align=center>
1345  <table width=90% cellspacing=0 cellpadding=4 border=0>
1346  <tr><td class="bar" align=center colspan=9>Transaction Requests</td></tr>
1347  <tr>
1348  <td class="hdr">Confirm</td>
1349  <td class="hdr">Date</td>
1350  <td class="hdr">Type</td>
1351  <td class="hdr" colspan="2">From</td>
1352  <td class="hdr" colspan="2">To</td>
1353  <td class="hdr">Description</td>
1354  <td class="hdr" align=right>Amount</td>
1355  </tr>
1356 EOF;
1357  $rbg="odd";
1358  $atotal = 0;
1359  $ytotal = 0;
1360  for ($row=0;
1361  list($acct,$email,$txn,$amt,$date,$memberto,$from,$to,$txid,$rptid)= db_fetch_array($sth,$row);
1362  $row++) {
1363  $from = trim($from);
1364  $to = trim($to);
1365  $memberto = ($memberto == "" ? $acct : $memberto);
1366  $xdesc = ($acct == $memberto ? "" : "<font color='red'>CROSS ACCOUNT </font>");
1367  list ($xdesc,$tsk) = showline($txn, $xdesc);
1368  if (trim($email) > "") { $acct = ($txn == 'ED' ? "Dep# $email" : "<a href=mailto:$email class='link2'>$acct</a>"); }
1369  $atotal += $amt;
1370  $ytotal += ($tsk == "" ? 0 : $amt);
1371  $amt = sprintf("%12.2f",$amt);
1372  $atotal = sprintf("%12.2f",$atotal);
1373  $date = date("m/d/Y h:i:sA",strtotime(substr($date,0,19)));
1374  $goback = urlencode($_SERVER['QUERY_STRING']);
1375  if (trim($rptid) == "TXT") {
1376  // ** The record is from a TXT Banking Transaction
1377  $type = "TXT";
1378  } elseif (intval($rptid) > 0) {
1379  $type = "<a href=\"$menu_link?ft=95&mode=VIEW&goback=$goback&rptid=" . intval($rptid) . "\">Repeat</a>";
1380  } else {
1381  $type = "On-Line";
1382  }
1383 
1384  if ($txn != 'MA' && (!$manualonly) || (!$tsk == "")) {
1385  print "<tr CLASS=$rbg>
1386  <td><font size=-1>$txid</font></td>
1387  <td><font size=-1>$date</font></td>
1388  <td><font size=-1>$type</font></td>
1389  <td><font size=-1>$acct</font></td>
1390  <td><font size=-1>$from</font></td>
1391  <td><font size=-1>$memberto</font></td>
1392  <td><font size=-1>$to</font></td>
1393  <td$tsk><font size=-1>$xdesc</font></td>
1394  <td><font size=-1><div align=right>$amt</div></font></td>
1395  </tr>";
1396  $rbg = ($rbg == "odd" ? "even" : "odd");
1397  }
1398  }
1399  print "<tr CLASS=$rbg><td colspan=7 align=right>Total</td>";
1400 
1401  if (!$manualonly) {
1402  $yp = ($ytotal > 0 ? "<td bgcolor='yellow' align='right'>" . sprintf("%12.2f",$ytotal) . "</td>" : "<td>&nbsp;</td>");
1403  print "$yp<td align=right> <b>$atotal</b>";
1404  } else {
1405  $yp = "<td align='right'>" . sprintf("%12.2f",$ytotal) . "</td>";
1406  print "&nbsp;<td align=right> <b>$yp</b>";
1407  }
1408  print "</td></tr></table>
1409  </div>";
1410 # Need a query here: see if cu allows MA transactions, get 'em and show 'em
1411  $sql="select x.date,
1412  x.accountnumber,
1413  x.reference1,
1414  x.reference2,
1415  x.reference3,
1416  x.id as txid
1417  from ${Cu}transaction x, cuhavetrans ht
1418  where x.id <$identity and x.id > ALL (select MAX(id)
1419  from ${Cu}transaction where id < $identity and
1420  accountnumber='CHECKPOINT') and accountnumber <> 'demo'
1421  and ht.cu = '$Cu' and ht.trancode = 'MA'
1422  and ht.trancode = x.transactioncode
1423  order by 1";
1424  $sth = db_query($sql,$dbh);
1425  if(!$sth) {
1426  mailerror($sql, pg_last_error(), __LINE__, __FILE__);
1427  }
1428  if (db_num_rows($sth) > 0 ) {
1429  print <<<EOF
1430  <div align=center><br>
1431  <table width=90% cellspacing=0 cellpadding=4 border=0>
1432  <tr><td class="bar" align=center colspan=5>Member Activation Requests</td></tr>
1433  <tr><td class="hdr">Confirm</td>
1434  <td class="hdr">Date</td>
1435  <td class="hdr">Account</td>
1436  <td class="hdr">Reference 1</td>
1437  <td class="hdr">Reference 2</td></tr>
1438 EOF;
1439  $rbg="odd";
1440  for ($row=0;
1441  list($date,$acct,$ref1,$ref2,$email,$txid)= db_fetch_array($sth,$row);
1442  $row++) {
1443  if (trim($email) > "") { $acct = ($txn == 'ED' ? "Dep# $email" : "<a href=mailto:$email class='link2'>$acct</a>"); }
1444  $date = date("m/d/Y h:i:sA",strtotime(substr($date,0,19)));
1445  print "<tr CLASS=$rbg><td><font size=-1>$txid</font></td>
1446  <td><font size=-1>$date</font></td>
1447  <td><font size=-1>$acct</font></td>
1448  <td><font size=-1>$ref1</font></td>
1449  <td><font size=-1>$ref2</font></td></tr>";
1450  $rbg = ($rbg == "odd" ? "even" : "odd");
1451  }
1452  }
1453  }
1454  }
1455 if (trim($action) == "FIND") {
1456  $looktx = intval($looktx);
1457  $sql = "select trim(tz), tranformat from cuadmin where cu='$Cu'";
1458  $sth = db_query($sql,$dbh);
1459  if($sth) { list($tz, $tranfmt) = db_fetch_array($sth,0); }
1460  $tz = ("$tz" == "" ? "Mountain" : $tz);
1461  if (strpos("$tz","/") === false) $tz = "US/$tz";
1462  $sql = "set time zone '$tz'; select accountnumber,
1463  reference3,
1464  transactioncode,
1465  amount,
1466  date,
1467  memberto,
1468  reference1,
1469  reference2,
1470  id as txid
1471  from ${Cu}transaction
1472  where id = $looktx
1473  and accountnumber <> 'CHECKPOINT'
1474  and accountnumber <> 'demo'";
1475  $sth = db_query($sql,$dbh);
1476  if(!$sth) {
1477  mailerror($sql, pg_last_error(), __LINE__, __FILE__);
1478  }
1479  $sql2 = "select trim(reference3),
1480  to_char(date,'MM/DD/YY HH:MI:SSam TZ')
1481  from ${Cu}transaction where id > $looktx
1482  and id = (select coalesce(min(id),0)
1483  from ${Cu}transaction
1484  where accountnumber = 'CHECKPOINT'
1485  and id > $looktx);";
1486  $sth2 = db_query($sql2,$dbh);
1487  if(!$sth2) {
1488  mailerror($sql2, pg_last_error(), __LINE__, __FILE__);
1489  }
1490  $sth1 = db_query("set time zone '$localzone'",$dbh);
1491  db_free_result($sth1);
1492  if (db_num_rows($sth2) == 0 || db_num_rows($sth) == 0)
1493  {
1494  $d = "not found in any batch";
1495  } else {
1496  list($batch, $date) = db_fetch_array($sth2,0);
1497  $d = "included in Batch <a href='${self}&action=CREATE&batch=$batch&tranfmt=$tranfmt' class='link2'>$batch</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1498  created on $date";
1499  }
1500  print <<<EOF
1501  <div align=center><br>
1502  <table width=90% cellspacing=0 cellpadding=2 border=0>
1503  <tr><td class="bar" align=center colspan=8>Locate $Cu Transaction</td></tr>
1504  <tr><td class="dtl" colspan=8>Transaction <b>$looktx</b> was $d.</td></tr>
1505  <tr>
1506  <td class="hdr">Confirm</td>
1507  <td class="hdr">Date</td>
1508  <td class="hdr" colspan="2">From</td>
1509  <td class="hdr" colspan="2">To</td>
1510  <td class="hdr">Description</td>
1511  <td class="hdr" align=right>Amount</td>
1512  </tr>
1513 EOF;
1514  $rbg="odd";
1515  for ($row=0;
1516  list($acct,$email,$txn,$amt,$date,$memberto,$from,$to,$txid)= db_fetch_array($sth,$row);
1517  $row++) {
1518  $memberto = ($memberto == "" ? $acct : $memberto);
1519  $xdesc = ($acct == $memberto ? "" : "<font color='red'>CROSS ACCOUNT </font>");
1520  list ($xdesc,$tsk) = showline($txn, $xdesc);
1521  if (trim($email) > "") { $acct = ($txn == 'ED' ? "Dep# $email" : "<a href=mailto:$email class='link2'>$acct</a>"); }
1522  $atotal += $amt;
1523  $ytotal += ($tsk == "" ? 0 : $amt);
1524  $amt = sprintf("%12.2f",$amt);
1525  $atotal = sprintf("%12.2f",$atotal);
1526  $yp = ($ytotal > 0 ? "<td bgcolor='yellow' align='right'>" . sprintf("%12.2f",$ytotal) . "</td>" : "<td>&nbsp;</td>");
1527  $date = date("m/d/Y h:i:sA",strtotime(substr($date,0,19)));
1528  print "<tr CLASS=$rbg>
1529  <td><font size=-1>$txid</font></td>
1530  <td><font size=-1>$date</font></td>
1531  <td><font size=-1>$acct</font></td>
1532  <td><font size=-1>$from</font></td>
1533  <td><font size=-1>$memberto</font></td>
1534  <td><font size=-1>$to</font></td>
1535  <td$tsk><font size=-1>$xdesc</font></td>
1536  <td><font size=-1><div align=right>$amt</div></font></td>
1537  </tr>";
1538  $rbg = ($rbg == "odd" ? "even" : "odd");
1539  }
1540  print "<tr CLASS=$rbg><td colspan=6 align=right>Total</td>
1541  $yp<td align=right><b>$atotal</b></td></tr></table>
1542  </div>";
1543  }
1544 if ($action == "") {
1545  $sql = "select flagset from cuadmin where cu='$Cu'";
1546  $sth = db_query($sql,$dbh);
1547  if($sth) { list($Fset) = db_fetch_array($sth,0); }
1548 
1549  if (($Fset & $CU_SAVETXNS) != $CU_SAVETXNS) {
1550 
1551 print <<<EOF
1552  <div align=center><br><form action="main.prg?ft=21">
1553  <table width=80% cellspacing=0 cellpadding=4 border=0>
1554  <tr><td class="bar" align=center>Download $Cu Transactions</td></tr>
1555  <tr><td class="dtl" align=center>
1556  This option is not set up for your Credit Union. Contact
1557  HomeCU for details.</td></tr>
1558  <tr><td class="hdr" align=center><hr>
1559  <input type=submit name="action" value="OK">
1560  </td></tr></table></form></div>
1561 EOF;
1562  exit;
1563  }
1564 
1565  $sql= "select count(*) from ${Cu}transaction
1566  where ID > all (select max(ID) from ${Cu}transaction
1567  where AccountNumber='CHECKPOINT')
1568  and accountnumber <> 'demo'";
1569 
1570  $sth = db_query($sql,$dbh);
1571  list($rv) = db_fetch_array($sth,0);
1572 
1573  $sql= "select tranformat from cuadmin where cu='${Cu}'";
1574  $sth = db_query($sql,$dbh);
1575  list($tranfmt) = db_fetch_array($sth,0);
1576  db_free_result($sth);
1577  $tranfmt = trim($tranfmt);
1578 
1579  print "<div align=center><br>\n";
1580 
1581 print <<<EOF
1582  <table width=90% cellspacing=0 cellpadding=3 border=0>
1583  <tr><td class="bar" colspan=2 align=center>$Cu Download HomeCU Transactions
1584  </td></tr>
1585 EOF;
1586 if ($msg) {
1587 print <<<EOF
1588  <tr>
1589  <td class="msg" colspan=2>$msg &nbsp;</td></tr>
1590 EOF;
1591 }
1592 print <<<EOF
1593  <tr>
1594  <td class="dtl" align=right width=50%><b>
1595  Estimated Transactions to Download:</b></td>
1596  <td class="dtl" width=*>&nbsp;&nbsp;$rv</td></tr>
1597  <tr><td class="dtl" align=right><b>Batch Number to Create:</b></td>
1598  <td class="dtl">&nbsp;&nbsp;
1599  <form action="$self" method="post" style="display:inline;">
1600  <input type=text name=batch value='New' size=5 maxsize=5>&nbsp;&nbsp;
1601  <input type=submit name="action" value="CREATE">
1602  <input type=hidden name=tranfmt value="$tranfmt">
1603  </form>
1604  </td></tr>
1605  <tr><td class="dtl" colspan=2 align="center"><font size=-1>Leave batch number set to 'New' unless you want a copy of an old batch.</font></td>
1606  </tr>
1607 <tr><td class="hdr" colspan=2><hr></td></tr>
1608  <tr>
1609  <td class="dtl" align="right"><b>
1610  Find Confirmation ID:</b></td>
1611  <td class="dtl">&nbsp;&nbsp;
1612  <form action="$self" method="post" style="display:inline;">
1613  <input type=text name=looktx size=5 maxsize=5>&nbsp;&nbsp
1614  <input type=submit name="action" value=" FIND ">
1615  </form></td></tr></table>
1616 EOF;
1617 
1618  $os = intval($os); // Make sure offset is a value
1619  $em = trim($em); // Make sure em is trimmed for spaces
1620 
1621  // $os - is the Page offset, it will determine where in the query we are
1622  // When it is 0, it should start at the first position
1623  // $spos - starting position in the query, this is a 0 based value, so 0 is the 1 page, and 1 is the 2 page
1624  // $ret_rows - number of rows to return - the limit
1625  // $pg_cnt - Maximum number of pages to be seen on the result page
1626  $ret_rows = 20;
1627  $spos = (intval($os) * $ret_rows);
1628  $pg_cnt = 10;
1629 
1630  $sql = "select trim(tz) from cuadmin where cu='$Cu'";
1631  $sth = db_query($sql,$dbh);
1632  if($sth) { list($tz) = db_fetch_array($sth,0); }
1633  $tz = ("$tz" == "" ? "Mountain" : $tz);
1634  if (strpos("$tz","/") === false) $tz = "US/$tz";
1635  $sql = "set time zone '$tz'; select to_char(date,'MM/DD/YY HH:MI:SSam TZ'),
1636  trim(reference3), reference4
1637  from ${Cu}transaction
1638  where accountnumber='CHECKPOINT'
1639  order by date desc limit $ret_rows offset $spos ";
1640  // Need a query that returns the total number of records that exist for this credit union
1641  $rows_sql = "select count(accountnumber)
1642  from {$Cu}transaction
1643  where accountnumber = 'CHECKPOINT' ";
1644 
1645  $sth = db_query($sql,$dbh);
1646  $rows_rs = db_query($rows_sql, $dbh);
1647  list($rec_rows) = db_fetch_array($rows_rs, 0);
1648 
1649 
1650  $print_nav = "";
1651  if ($rec_rows > $ret_rows) {
1652  $mp = intval($rec_rows / $ret_rows) + ($rec_rows % $ret_rows > 0 ? 1 : 0);
1653  // Get the Integer portion of the query and add one if there was a remainder portion
1654 
1655  // Now at the top of the table will be the PREVIOUS PAGES NEXT options
1656  // Calculate the first and last page to show
1657  // $fp - first page: $lp - last page
1658 
1659 
1660  $pg_flds = intval($pg_cnt / 2); // An approximate position of where to put the current number
1661  if ((($os + 1) <= $pg_flds) || $mp <= $pg_cnt) {
1662  $fp = 1;
1663  } elseif ($os + 1 + $pg_flds > $mp) {
1664  $fp = ($mp - $pg_cnt + 1);
1665  } else {
1666  $fp = ($os - ($pg_cnt - $pg_flds) + 2);
1667  }
1668 
1669  if ($os > 0) {
1670  $prev = "<a href=\"$PHP_SELF?ft=$ft&os=0\">&lt;&lt;Begin</a>&nbsp;";
1671  $prev .= "<a href=\"$PHP_SELF?ft=$ft&os=" . ($os - 1) . "\">&lt;Previous</a>&nbsp;";
1672  } else {
1673  $prev = "<span style='font-size: 10px'>&lt;&lt;Begin</span>&nbsp;";
1674  $prev .= "<span style='font-size: 10px'>&lt;Previous</span>&nbsp;";
1675  }
1676 
1677  if ($os < ($mp - 1)) {
1678  $next = "<a href=\"$PHP_SELF?ft=$ft&os=" . ($os + 1) . "\">Next&gt;</a>&nbsp;";
1679  $next .= "<a href=\"$PHP_SELF?ft=$ft&os=" . ($mp - 1) . "\">End&gt;&gt;</a>&nbsp;";
1680  }
1681 
1682  $pg_list = (($fp + $pg_cnt) > ($mp + 1) ? ($mp + 1) : ($fp + $pg_cnt));
1683 
1684  for ($i = $fp; $i < $pg_list; $i++) {
1685  if ($i == ($os + 1))
1686  $pages .= "&nbsp;<span style='font-size: 10px'>$i</span>&nbsp;";
1687  else
1688  $pages .= "&nbsp;<a href=\"$PHP_SELF?ft=$ft&os=" . ($i - 1) . "\">$i</a>&nbsp;";
1689  }
1690 
1691  $print_nav = "<tr><td class='dtl' colspan='3'>$prev $pages $next</td></tr>";
1692  }
1693 
1694 
1695  $sth1 = db_query("set time zone '$localzone'",$dbh);
1696  db_free_result($sth1);
1697  if ($sth) {
1698  print <<<EOF
1699  <table width=90% border=0 cellpadding=2 cellspacing=0>
1700  <tr><td><caption align='center'><font size=-1><b>Click Batch Numbers Below to Retrieve Old Batch Files</b></font></caption></td></tr>
1701  $print_nav
1702  <tr><td class="hdr" width=50%>Date Created</td>
1703  <td class="hdr" width=40%>Created By</td>
1704  <td class="hdr" width=*>Batch Number</td></tr>
1705 EOF;
1706  for ($row=0;list($date,$bnum, $ref4) = db_fetch_array($sth,$row); $row++) {
1707  $ref4 = trim($ref4);
1708  $rbg = ($rbg == "odd" ? "even" : "odd");
1709  print "<tr><td class='$rbg'><span class='usu'>$date&nbsp;</span></td>
1710  <td class='$rbg'><span class='usu'>$ref4&nbsp;</span></td>
1711  <td class='$rbg' align='right'><span class='usu'>";
1712  if (is_numeric($bnum)) {
1713  print "<a href='${self}&action=CREATE&batch=$bnum&tranfmt=$tranfmt' class='link2'>$bnum</a>&nbsp;</span></td></tr>";
1714  } else {
1715  print "$bnum&nbsp;</span></td></tr>";
1716  }
1717  }
1718  print "</table>\n";
1719  db_free_result($sth);
1720  }else {
1721  mailerror($sql, pg_last_error(), __LINE__, __FILE__);
1722  }
1723 
1724  print "</div>\n";
1725 }
1726 function mailerror ($sql, $errstr, $line, $file) {
1727 global $Cu;
1728 global $Cn;
1729 global $chome;
1730  $notify = new ErrorMail;
1731  $notify->line=$line;
1732  $notify->file=$file;
1733  $notify->callingfunction = __FUNCTION__;
1734  $notify->error=$errstr;
1735  $notify->cu="$Cu";
1736  $notify->member="$Cn - user: $chome";
1737  $notify->sql="$sql";
1738  $notify->SendErr();
1739 }
1740 function getbatch($dbh, $cu, $batch) {
1741  global $Cn;
1742  if (preg_match("/^new$/i",$batch)) {
1743  $sqlcommit = "commit transaction";
1744  $sqlrollbk = "rollback transaction";
1745  $sqlbegin = "begin transaction";
1746 
1747  $sql1 = "update CUAdmin set nextbatch = nextbatch + 1
1748  where cu='" . ${cu} . "'";
1749 
1750  $sql2 = "select nextval('" . ${cu} . "transaction_id_seq')";
1751 
1752  $sth = db_query($sqlbegin, $dbh);
1753  if (!$sth) {
1754  mailerror ($sqlbegin,pg_last_error(), __LINE__, __FILE__);
1755  db_free_result($sth);
1756  return array("new",0);
1757  }
1758  $sth = db_query($sql1, $dbh);
1759  if (!$sth) {
1760  mailerror ($sql1,pg_last_error(), __LINE__, __FILE__);
1761  $sth = db_query($sqlrollbk, $dbh);
1762  db_free_result($sth);
1763  return array("new",0);
1764  }
1765  $sth = db_query($sql2, $dbh);
1766  if (!$sth) {
1767  mailerror ($sql2,pg_last_error(), __LINE__, __FILE__);
1768  $sth = db_query($sqlrollbk, $dbh);
1769  db_free_result($sth);
1770  return array("new",0);
1771  } else {
1772  list($id) = db_fetch_array($sth,0);
1773  }
1774  if ("$cu" == "DEMO") {
1775  $sql3 = "INSERT INTO ${cu}transaction
1776  (id, accountnumber, transactioncode, reference1,
1777  reference3, reference4, amount, date)
1778  select " . $id . ", 'CHECKPOINT', 'ZB', 'PHASE II',
1779  nextbatch, '$Cn', 0, now()
1780  from cuadmin where cu='" . ${cu} . "'";
1781  } else {
1782  $sql3 = "INSERT INTO ${cu}transaction
1783  (id, accountnumber, transactioncode, reference1,
1784  reference3, reference4, amount, date)
1785  select " . $id . ", 'CHECKPOINT', 'ZB', 'PHASE I',
1786  nextbatch, '$Cn', 0, now()
1787  from cuadmin where cu='" . ${cu} . "'";
1788  }
1789 
1790  $sql4 = "select reference3, id
1791  from ${cu}transaction
1792  where id = $id";
1793 
1794  $sth = db_query($sql3, $dbh);
1795  if (!$sth) {
1796  mailerror ($sql3,pg_last_error(), __LINE__, __FILE__);
1797  $sth = db_query($sqlrollbk, $dbh);
1798  db_free_result($sth);
1799  return array("new",0);
1800  }
1801  $sth = db_query($sql4, $dbh);
1802  if (!$sth) {
1803  mailerror ($sql4,pg_last_error(), __LINE__, __FILE__);
1804  $sth = db_query($sqlrollbk, $dbh);
1805  db_free_result($sth);
1806  return array("new",0);
1807  } else {
1808  $sth2 = db_query($sqlcommit, $dbh);
1809  }
1810  } else {
1811  $sql="select reference3, id from ${cu}transaction
1812  where reference3 = '" . $batch . "' and transactioncode = 'ZB'";
1813  $sth = db_query($sql, $dbh);
1814  if (!$sth) {
1815  mailerror ($sql,pg_last_error(), __LINE__, __FILE__);
1816  db_free_result($sth);
1817  return array("new",0);
1818  }
1819  }
1820  list($batch,$identity) = db_fetch_array($sth,0);
1821  db_free_result($sth);
1822  return array($batch,$identity);
1823 }
1824 function showline ($txn, $xdesc) {
1825 global $tfmt;
1826 global $codelist;
1827 global $achlist;
1828 global $achwhere;
1829 global $cwshareonly;
1830 global $noxa;
1831 global $acct;
1832 global $memberto;
1833 global $from;
1834 global $to;
1835 
1836  if (in_array("$txn",array_keys($codelist))) {
1837  $xdesc .= $codelist[$txn];
1838  $tsk=(!in_array("$txn",$tfmt) || ($noxa > '' && $acct != $memberto) ||
1839  ($achwhere > '' && (strpos($achlist,$from) === false || strpos($achlist,$to) === false )) ||
1840  ($cwshareonly > '' && "$txn" == 'CW' && substr($from,0,1) != 'S') ? " bgcolor='yellow'" : "");
1841  } else {
1842  $xdesc .= "($txn) ";
1843  $tsk="";
1844  }
1845  return array($xdesc,$tsk);
1846 }
1847 ?>