billable members on contribution should already subtract 2
This commit is contained in:
		@@ -52,11 +52,17 @@ class CRM_Tbusainvoicegen_Timebank {
 | 
				
			|||||||
  private $contactId;
 | 
					  private $contactId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The number of billable members.
 | 
					   * The number of members.
 | 
				
			||||||
   * @var int
 | 
					   * @var int
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private $memberCount;
 | 
					  private $memberCount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * The number of billable members. It's $memberCount -2 with a minimum of zero.
 | 
				
			||||||
 | 
					   * @var int
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  private $memberCountiBillable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The price for one period of this timebank.
 | 
					   * The price for one period of this timebank.
 | 
				
			||||||
   * @var float
 | 
					   * @var float
 | 
				
			||||||
@@ -112,12 +118,15 @@ class CRM_Tbusainvoicegen_Timebank {
 | 
				
			|||||||
  public function __construct($cid, $memberCount) {
 | 
					  public function __construct($cid, $memberCount) {
 | 
				
			||||||
    $this->cid = $cid;
 | 
					    $this->cid = $cid;
 | 
				
			||||||
    $this->memberCount = $memberCount;
 | 
					    $this->memberCount = $memberCount;
 | 
				
			||||||
 | 
					    $this->memberCountBillable = $memberCount - 2;
 | 
				
			||||||
 | 
					    if ($this->memberCountBillable < 0) {
 | 
				
			||||||
 | 
					      $this->memberCountBillable = 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Generate invoices (called from API).
 | 
					   * Generate invoices (called from API).
 | 
				
			||||||
   * @param int $cid
 | 
					   * @param array $params An array containing all the values passed into the Invoicegen.generate API.
 | 
				
			||||||
   * @param str $billingPeriod The billing period (e.g "2019-2" for the second 2019 payment)
 | 
					 | 
				
			||||||
   * @return array APIv3 standard response.
 | 
					   * @return array APIv3 standard response.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public static function generate($params) {
 | 
					  public static function generate($params) {
 | 
				
			||||||
@@ -184,7 +193,7 @@ class CRM_Tbusainvoicegen_Timebank {
 | 
				
			|||||||
    if ($this->price) {
 | 
					    if ($this->price) {
 | 
				
			||||||
      return $this->price;
 | 
					      return $this->price;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $adjustedMemberCount = $this->memberCount - 2;
 | 
					    $adjustedMemberCount = $this->memberCountBillable;
 | 
				
			||||||
    foreach ($this->priceArray as $members => $cost) {
 | 
					    foreach ($this->priceArray as $members => $cost) {
 | 
				
			||||||
      if ($adjustedMemberCount <= $members) {
 | 
					      if ($adjustedMemberCount <= $members) {
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
@@ -244,7 +253,7 @@ class CRM_Tbusainvoicegen_Timebank {
 | 
				
			|||||||
      self::INVOICEDATE => $this->invoiceDate->format('Y-m-d'),
 | 
					      self::INVOICEDATE => $this->invoiceDate->format('Y-m-d'),
 | 
				
			||||||
      self::PERIODBEGIN => $this->periodBegin->format('Y-m-d'),
 | 
					      self::PERIODBEGIN => $this->periodBegin->format('Y-m-d'),
 | 
				
			||||||
      self::PERIODEND => $this->periodEnd->format('Y-m-d'),
 | 
					      self::PERIODEND => $this->periodEnd->format('Y-m-d'),
 | 
				
			||||||
      self::BILLABLEMEMBERSCONTRIB => $this->memberCount,
 | 
					      self::BILLABLEMEMBERSCONTRIB => $this->memberCountBillable,
 | 
				
			||||||
      'total_amount' => $this->price,
 | 
					      'total_amount' => $this->price,
 | 
				
			||||||
      'contact_id' => $this->cid,
 | 
					      'contact_id' => $this->cid,
 | 
				
			||||||
      'contribution_status_id' => 'Pending',
 | 
					      'contribution_status_id' => 'Pending',
 | 
				
			||||||
@@ -347,4 +356,3 @@ class CRM_Tbusainvoicegen_Timebank {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user