Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  *
  * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory()
  */
 public function getPaymentHistory()
 {
     $paymentHistory = array();
     $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2));
     $past = new Zend_Date("01-01-2010", "dd-MM-yyyy");
     $now = new Zend_Date();
     $dateList = Oara_Utilities::yearsOfDifference($past, $now);
     $dateList[] = $now;
     foreach ($this->_siteList as $site) {
         for ($i = 0; $i < count($dateList) - 1; $i++) {
             $bdate = clone $dateList[$i];
             $edate = clone $dateList[$i + 1];
             if ($i != count($dateList) - 1) {
                 $edate->subDay(1);
             }
             echo "getting Payment for Site " . $site->id . " and year " . $bdate->toString("yyyy") . " \n\n";
             // https://65.245.193.87
             $url = "https://reportws.linksynergy.com/downloadreport.php?bdate=" . $bdate->toString("yyyyMMdd") . "&edate=" . $edate->toString("yyyyMMdd") . "&token=" . $site->secureToken . "&nid=" . $this->_nid . "&reportid=1";
             $result = file_get_contents($url);
             if (preg_match("/You cannot request/", $result)) {
                 throw new Exception("Reached the limit");
             }
             $paymentLines = str_getcsv($result, "\n");
             $number = count($paymentLines);
             for ($j = 1; $j < $number; $j++) {
                 $paymentData = str_getcsv($paymentLines[$j], ",");
                 $obj = array();
                 $date = new Zend_Date($paymentData[1], "yyyy-MM-dd");
                 $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss");
                 $obj['value'] = $filter->filter($paymentData[5]);
                 $obj['method'] = "BACS";
                 $obj['pid'] = $paymentData[0];
                 $paymentHistory[] = $obj;
             }
         }
     }
     return $paymentHistory;
 }