diff --git a/CRM/Tbusainvoicegen/Timebank.php b/CRM/Tbusainvoicegen/Timebank.php index c050576..e6fc716 100644 --- a/CRM/Tbusainvoicegen/Timebank.php +++ b/CRM/Tbusainvoicegen/Timebank.php @@ -52,11 +52,17 @@ class CRM_Tbusainvoicegen_Timebank { private $contactId; /** - * The number of billable members. + * The number of members. * @var int */ 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. * @var float @@ -112,12 +118,15 @@ class CRM_Tbusainvoicegen_Timebank { public function __construct($cid, $memberCount) { $this->cid = $cid; $this->memberCount = $memberCount; + $this->memberCountBillable = $memberCount - 2; + if ($this->memberCountBillable < 0) { + $this->memberCountBillable = 0; + } } /** * Generate invoices (called from API). - * @param int $cid - * @param str $billingPeriod The billing period (e.g "2019-2" for the second 2019 payment) + * @param array $params An array containing all the values passed into the Invoicegen.generate API. * @return array APIv3 standard response. */ public static function generate($params) { @@ -184,7 +193,7 @@ class CRM_Tbusainvoicegen_Timebank { if ($this->price) { return $this->price; } - $adjustedMemberCount = $this->memberCount - 2; + $adjustedMemberCount = $this->memberCountBillable; foreach ($this->priceArray as $members => $cost) { if ($adjustedMemberCount <= $members) { break; @@ -244,7 +253,7 @@ class CRM_Tbusainvoicegen_Timebank { self::INVOICEDATE => $this->invoiceDate->format('Y-m-d'), self::PERIODBEGIN => $this->periodBegin->format('Y-m-d'), self::PERIODEND => $this->periodEnd->format('Y-m-d'), - self::BILLABLEMEMBERSCONTRIB => $this->memberCount, + self::BILLABLEMEMBERSCONTRIB => $this->memberCountBillable, 'total_amount' => $this->price, 'contact_id' => $this->cid, 'contribution_status_id' => 'Pending', @@ -347,4 +356,3 @@ class CRM_Tbusainvoicegen_Timebank { } } -