2 require_once 'Verify.php';
3 class Pman_Xtuple_VerifyAP 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('vendinfo');
29 CASE WHEN (apopen_doctype IN ('C', 'R')) THEN
30 (apopen_amount - apopen_paid) * -1.0
32 (apopen_amount - apopen_paid)
37 ) as apopen_remaining_hkd
42 //DB_DataObject::DebugLevel(1);
55 CASE WHEN (apopen_doctype IN ('C', 'R')) THEN
56 (apopen_amount - apopen_paid) * -1.0
58 (apopen_amount - apopen_paid)
67 apopen_vend_id = vend_id
83 COALESCE(SUM(currtocurr(
95 CASE WHEN (apopen_doctype IN ('C', 'R')) THEN
96 (apopen_amount - apopen_paid) * -1.0
98 (apopen_amount - apopen_paid)
106 apopen_vend_id = vend_id
114 $db->orderBy('vend_number ASC');
116 $xdb =$db->fetchAll('vend_number', 'balance');
120 // we only report on HK data..
121 echo json_encode($xdb);
126 $sgdata = (array) json_decode(file_get_contents("http://localhost/xtuple/{$lprefix}sg.php/Xtuple/VerifyAP"));
128 //print_R($sgdata);exit;
129 //echo '<PRE>' ;print_R( $hkdata);
131 // echo '<PRE>';var_dump( $sgdata );exit;
133 $old = $this->oldParse('HK');
134 //echo"<PRE>"; print_r($old);
136 foreach($this->oldParse('SG') as $k =>$v) {
144 //(int) print_r(array_keys($sgdata));
145 // print_r(array_keys($old));
147 $historyfor = array();
148 header('Content-type: text/csv');
149 header( 'Content-Disposition: attachment;filename=APsummary.csv');
150 $fh = fopen('php://output','w');
152 fputcsv($fh, array("Customer", '','',"NETSUITE", "HK", "SG", "difference"));
153 foreach($old as $k=>$v) {
154 $hk = isset($hkdata[$k]) ? $hkdata[$k] : 0;
155 $sg = isset($sgdata[$k]) ? $sgdata[$k] : 0;
157 if ( ( ($hk + $sg) - $v) == 0.0) {
161 if (abs(( ($hk + $sg) - $v)) > 1.5) {
162 $historyfor[$k] = $v;
181 // aropen - columns... docdate, doctype, docnumber,amount, paid,
184 foreach($historyfor as $vend=>$expect) {
189 $args = $this->toParams(array(
190 'query[vend_number]'=> trim($vend),
191 'query[in_currency]'=> 'HKD',
192 'sort'=>'apopen_docdate,apopen_id',
196 'csvCols[0]' => 'apopen_docdate',
197 'csvCols[1]' => 'apopen_doctype',
198 'csvCols[2]' => 'apopen_docnumber_r',
199 'csvCols[3]' => 'apopen_amount_hkd',
200 'csvCols[4]' => 'apopen_paid_hkd',
201 'csvCols[5]' => 'apopen_remaining_hkd',
202 'csvCols[6]' => 'apopen_running_hkd',
204 'csvTitles[0]' => 'Date',
205 'csvTitles[1]' => 'Type',
206 'csvTitles[2]' => 'Doc no.',
207 'csvTitles[3]' => 'Amount',
208 'csvTitles[4]' => 'Paid',
209 'csvTitles[5]' => 'Outstanding',
210 'csvTitles[6]' => 'Running',
216 //fwrite($fh, "\n\n\"http://www.bloomandgrowdirect.com/xtuple/{$lprefix}hk.php/Roo/apopen?$args\"\n");
218 // fwrite($fh, "\n\n\"http://www.bloomandgrowdirect.com/xtuple/{$lprefix}sg.php/Roo/apopen?$args\"\n");
219 $hk = isset($hkdata[$vend]) ? $hkdata[$vend] : 0;
220 $sg = isset($sgdata[$vend]) ? $sgdata[$vend] : 0;
222 fwrite($fh, "\n\n-- ". $vend ." ,,Expecting:, $expect, HK:, $hk, SG: $sg\n");
225 fwrite($fh, file_get_contents("http://localhost/xtuple/{$lprefix}hk.php/Roo/apopen?$args"));
226 fwrite($fh, file_get_contents("http://localhost/xtuple/{$lprefix}sg.php/Roo/apopen?$args"));
246 function oldParse($cn)
248 $har = explode('/', realpath(__FILE__));
249 $home = '/home/'. $har[2];
250 $fn = "$home/Dropbox/xtuple_working/old_database_snapshot/$cn/Netsuite_Vendor.sql.json.all";
253 foreach($ar as $i=>$l) {
255 $line = json_decode($l);
257 $ret[strtoupper($line->entityId)] = $line->balance;