Bug fix to add appt with multi provider feature (note Find Available appt is not...
[openemr.git] / library / classes / OFX.class.php
blobe0be9c655863b13362ef22851e1df783083dd07d
1 <?php
3 include_once(dirname(__FILE__) . "/../../includes/config.php");
5 /**
6 * class OFX
8 */
9 class OFX {
11 var $billing_array;
12 var $config;
13 /**
14 * Constructor sets all OFX attributes to their default value
16 function OFX($ba = array()) {
17 $this->billing_array = $ba;
18 $this->config = $GLOBALS['oer_config']['ofx'];
21 function get_OFX() {
22 $string = $this->_ofx_header() . "\n";
23 $trns = array();
24 $sum = 0.00;
25 $date_start = date("YmdHis",strtotime($this->billing_array[0]['bill_date']));
26 $date_end = date("YmdHis",strtotime($this->billing_array[0]['bill_date']));
27 foreach ($this->billing_array as $bill) {
28 $key = $bill['pid'] . "-" . $bill['encounter'];
29 if ($bill['code_type'] != "ICD9" && $bill['code_type'] != "COPAY") {
30 $trns[$key]['amount'] += $bill['fee'];
31 $trns[$key]['date'] = $bill['bill_date'];
32 $trns[$key]['memo'] .= $bill['code'] . " ";
33 $trns[$key]['payeeid'] = $bill['pid'];
34 $trns[$key]['name'] = $bill['name'];
35 if ($date_start > date("YmdHis",strtotime($trns[$key]['date']))) {
36 //echo "\nsd: $date_start < " . date("YmdHis",strtotime($trn[$key]['date'])) . "\n";
37 $date_start = date("YmdHis",strtotime($trns[$key]['date']));
39 if ($date_end < date("YmdHis",strtotime($trns[$key]['date']))) {
40 //echo "\ned: $date_end < " . date("YmdHis",strtotime($trn[$key]['date'])) . "\n";
41 $date_end = date("YmdHis",strtotime($trns[$key]['date']));
45 if (!empty($date_start) && !empty($date_end)) {
46 $string .= "<DTSTART>" . $date_start . "\n";
47 $string .= "<DTEND>" . $date_end . "\n";
49 foreach ($trns as $key => $trn) {
50 $string .= "<STMTTRN>\n";
51 $string .= "<TRNTYPE>CREDIT\n";
52 $string .= "<DTPOSTED>" . date("YmdHis",strtotime($trn['date'])) . "\n";
53 $string .= "<TRNAMT>" . sprintf("%0.2f",$trn['amount']) . "\n";
54 $string .= "<FITID>" . $key . "\n";
55 $string .= "<NAME>" . $trn['name'] . "\n";
56 $string .= "<CHECKNUM>" . $key . "\n";
57 $string .= "<PAYEEID>" . $trn['payeeid'] . "\n";
58 $string .= "<MEMO>" . trim($trn['memo']) . "\n";
59 $string .= "</STMTTRN>\n";
60 $sum += $trn['amount'];
62 $string .= $this->_ofx_footer($sum);
63 return $string;
66 function _ofx_header() {
67 $string .= "OFXHEADER:100\n";
68 $string .= "DATA:OFXSGML\n";
69 $string .= "VERSION:102\n";
70 $string .= "SECURITY:NONE\n";
71 $string .= "ENCODING:USASCII\n";
72 $string .= "CHARSET:1252\n";
73 $string .= "COMPRESSION:NONE\n";
74 $string .= "OLDFILEUID:NONE\n";
75 $string .= "NEWFILEUID:NONE\n\n";
76 $string .= "<OFX>\n";
77 $string .= "<SIGNONMSGSRSV1>\n";
78 $string .= "<SONRS>\n";
79 $string .= "<STATUS>\n";
80 $string .= "<CODE>0\n";
81 $string .= "<SEVERITY>INFO\n";
82 $string .= "</STATUS>\n";
83 $string .= "<DTSERVER>" . date("YmdHis") . "\n";
84 $string .= "<LANGUAGE>ENG\n";
86 //OpenEMR doesn't have a good grasp of timezone so we will need to revisit this later if it causes problems for transaction timestamping
87 $string .= "<DTACCTUP>" . date("YmdHis") . ".000[-8:PST]\n";
89 //intuit programs requires the fields below or it won't accept our ofx transactions
90 $string .= "<FI>\n";
91 $string .= "<ORG>Bank of America\n";
92 $string .= "<FID>5959\n";
93 $string .= "</FI>\n";
94 $string .= "<INTU.BID>6526\n";
95 $string .= "<INTU.USERID>111111111\n";
96 //end intuit specific fields
98 $string .= "</SONRS>\n";
99 $string .= "</SIGNONMSGSRSV1>\n";
101 $string .= "<BANKMSGSRSV1>\n";
102 $string .= "<STMTTRNRS>\n";
103 $string .= "<TRNUID>0\n";
104 $string .= "<STATUS>\n";
105 $string .= "<CODE>0\n";
106 $string .= "<SEVERITY>INFO\n";
107 $string .= "</STATUS>\n";
108 $string .= "<STMTRS>\n";
109 $string .= "<CURDEF>USD\n";
110 $string .= "<BANKACCTFROM>\n";
111 $string .= "<BANKID>" . $this->config['bankid'] . "\n";
112 $string .= "<ACCTID>" . $this->config['acctid'] . "\n";
113 $string .= "<ACCTTYPE>CHECKING";
114 $string .= "</BANKACCTFROM>\n";
115 $string .= "<BANKTRANLIST>\n";
116 return $string;
119 function _ofx_footer($sum) {
120 $string = "</BANKTRANLIST>\n";
121 $string .= "<LEDGERBAL>\n";
122 $string .= "<BALAMT>" . sprintf("%0.2f",$sum) . "\n";
123 $string .= "<DTASOF>" . date("YmdHis"). "\n";
124 $string .= "</LEDGERBAL>\n";
125 $string .= "</STMTRS>\n";
126 $string .= "</STMTTRNRS>\n";
127 $string .= "</BANKMSGSRSV1>\n";
128 $string .= "</OFX>\n";
129 return $string;