Skip to content
Snippets Groups Projects
Select Git revision
  • 40850a83f2479e286518b0a3b371efeb8354ce65
  • customer_portal default
  • BRCD-4840
  • BRCD-4719
  • BRCD-4945
  • BRCD-3086
  • BRCD-4944
  • BRCD-4940
  • BRCD-4946
  • BRCD-4939
  • BRCD-4940-FE
  • BRCD-4936
  • BRCD-4928
  • BRCD-4935
  • BRCD-4734
  • BRCD-4927
  • BRCD-4932
  • BRCD-4933
  • BRCD-4924
  • BRCD-1714
  • BRCD-3218
  • BRCD-3647
  • 5.16.0-rc25
  • 5.16.0-rc24
  • 5.16.0-rc23
  • 5.16.0-rc22
  • 5.16.0-rc21
  • 5.16.0-rc20
  • 5.16.0-rc19
  • v20250422_fraud_legacy
  • 5.16.0-rc18
  • 5.16.0-rc17
  • 5.16.0-rc16
  • 5.16.0-rc15
  • 5.16.0-rc14
  • 5.16.0-rc13
  • 5.16.0-rc12
  • 5.16.0-rc11
  • 5.13.46
  • 5.13.45
  • 5.16.0-rc10
  • v20250408_fraud_legacy
42 results

Query.php

Blame
  • Forked from sdoc / BillRun
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Query.php 5.86 KiB
    <?php
    
    /**
     * @package         Billing
     * @copyright       Copyright (C) 2012-2015 S.D.O.C. LTD. All rights reserved.
     * @license         GNU Affero General Public License Version 3; see LICENSE.txt
     */
    
    /**
     * This is a parser to be used by the auto renew action.
     *
     * @author Tom Feigin
     * @todo This class is very similar to balances query, 
     * a generic query class should be created for both to implement.
     */
    class Billrun_ActionManagers_Subscribersautorenew_Query extends Billrun_ActionManagers_APIAction{
    	
    	/**
    	 * Field to hold the data to be written in the DB.
    	 * @var type Array
    	 */
    	protected $query = array();
    	
    	const DEFAULT_ERROR = "Success querying auto renew";
    	
    	/**
    	 */
    	public function __construct() {
    		parent::__construct(array('error' => self::DEFAULT_ERROR));
    		$this->collection = Billrun_Factory::db()->subscribers_auto_renew_servicesCollection();
    	}
    	
    	/**
    	 * Get a plan record according to the subscribers auto renew record.
    	 * @param Mongodloid_Entity $record
    	 * @return plan record.
    	 */
    	protected function getPlanRecord($record) {
    		$planCollection = Billrun_Factory::db()->plansCollection();
    		$planQuery = Billrun_Util::getDateBoundQuery();
    		$planQuery["name"] = $record['charging_plan_name'];
    		$planQuery["type"] = 'charging';
    		return $planCollection->query($planQuery)->cursor()->current();
    	}
    	
    	/**
    	 * Populate the plan values.
    	 * @param Mongodloid_Entity $record - Record to populate with plan values.
    	 */
    	protected function populatePlanValues(&$record) {
    		if(!isset($record['charging_plan_name'])) {
    			$errorCode = Billrun_Factory::config()->getConfigValue("autorenew_error_base") + 4;
    			$this->reportError($errorCode, Zend_Log::NOTICE);
    			return false;
    		}
    		
    		$planRecord = $this->getPlanRecord($record);
    		if($planRecord->isEmpty()) {
    			$errorCode = Billrun_Factory::config()->getConfigValue("autorenew_error_base") + 5;
    			$this->reportError($errorCode, Zend_Log::NOTICE);
    			return false;
    		}
    		
    		$record['includes'] = $this->getIncludesArray($planRecord);
    		
    		return true;
    	}
    	
    	/**
    	 * Get the 'includes' array to return for the plan record.