2 require_once 'Verify.php';
3 class Pman_Xtuple_VerifyAR extends Pman_Xtuple_Verify {
7 $sd = strtoupper(array_pop(explode('xtuple', HTML_FlexyFramework::get()->database)));
10 $lprefix = preg_match('/(lsg\.php|lhk.php)$/', $this->baseURL) ? 'l' : '';
12 // dump old db -> jsondecode -> get file contents ~/Dropbox/olddb...... [TBD]
13 // get Netsuite_Accounts from SG and HK and merge
15 // review the "View Financial Report" to see how it's pulling
16 // the Balances for the internal accounting accounts
19 // DB_DataObject::debugLevel(1);
22 //DB_DataObject::DebugLevel(1);
23 $db = DB_DataObject::factory('custinfo');
29 CASE WHEN (aropen_doctype IN ('C', 'R')) THEN
30 (aropen_amount - aropen_paid) * -1.0
32 (aropen_amount - aropen_paid)
38 aropen_cust_id = cust_id
43 $db->orderBy('cust_number ASC');
45 $xdb =$db->fetchAll('cust_number', 'balance');
50 // we only report on HK data..
51 // echo json_encode($xdb);
56 //$sgdata = (array) json_decode(file_get_contents("http://localhost/xtuple/{$lprefix}sg.php/Xtuple/VerifyAR"));
57 // echo '<PRE>';var_dump($sgdata);exit;
59 //echo '<PRE>';print_R($sgdatas['97']);exit;
61 // echo '<PRE>';var_dump( $sgdata );exit;
63 //$old = $this->oldParse('HK');
66 foreach($this->oldParse('SG') as $k =>$v) {
74 //(int) print_r(array_keys($sgdata));
75 // print_r(array_keys($old));
81 $out[] = array("Customer", "spacer","spacer", "NETSUITE", "HK", "SG", "difference");
82 foreach($old as $k=>$v) {
84 $hk = isset($hkdata[''.$k]) ? $hkdata[''.$k] : 0;
85 $sg = isset($sgdata[''.$k]) ? $sgdata[''.$k] : 0;
87 if ( ( ($hk + $sg) - $v) == 0.0) {
91 if (abs(( ($hk + $sg) - $v)) < 1.5) {
112 header('Content-type: text/csv');
113 header( 'Content-Disposition: attachment;filename=ARreport.csv');
114 $fh = fopen('php://output','w');
115 foreach($out as $o) {
121 // we now have all the data...
123 // for ar - look in aropen..
124 // eg. sgtru = SG based (224
126 // aropen - columns... docdate, doctype, docnumber,amount, paid,
129 foreach($historyfor as $cust=>$expect) {
134 $args = $this->toParams(array(
135 'query[cust_number]'=> trim($cust),
137 'sort'=>'aropen_docdate,aropen_id',
141 'csvCols[0]' => 'aropen_docdate',
142 'csvCols[1]' => 'aropen_doctype',
143 'csvCols[2]' => 'aropen_docnumber_r',
144 'csvCols[3]' => 'aropen_amount',
145 'csvCols[4]' => 'aropen_paid',
146 'csvCols[5]' => 'aropen_remaining',
147 'csvCols[6]' => 'aropen_running',
149 'csvTitles[0]' => 'Date',
150 'csvTitles[1]' => 'Type',
151 'csvTitles[2]' => 'Doc no.',
152 'csvTitles[3]' => 'Amount',
153 'csvTitles[4]' => 'Paid',
154 'csvTitles[5]' => 'Outstanding',
155 'csvTitles[6]' => 'Running',
161 //fwrite($fh, "\n\n\"http://www.bloomandgrowdirect.com/xtuple/{$lprefix}hk.php/Roo/aropen?$args\"\n");
162 //fwrite($fh, "\n\n\"http://www.bloomandgrowdirect.com/xtuple/{$lprefix}sg.php/Roo/aropen?$args\"\n");
164 fwrite($fh, "\n\n-- ". $cust ." ,,Expecting:, $expect\n");
167 fwrite($fh, file_get_contents("http://localhost/xtuple/{$lprefix}hk.php/Roo/aropen?$args"));
168 fwrite($fh, file_get_contents("http://localhost/xtuple/{$lprefix}sg.php/Roo/aropen?$args"));
185 function oldParse($cn)
187 $har = explode('/', realpath(__FILE__));
188 $home = '/home/'. $har[2];
189 $fn = "$home/Dropbox/xtuple_working/old_database_snapshot/$cn/Netsuite_Customer.sql.json.all";
192 foreach($ar as $i=>$l) {
194 $line = json_decode($l);
196 $ret[strtoupper($line->entityId)] = $line->balance;