api updated; can successfully calculate price now
This commit is contained in:
@ -47,6 +47,19 @@ class CRM_Tbusainvoicegen_Timebank {
|
||||
*/
|
||||
private $price;
|
||||
|
||||
/**
|
||||
* An array of all the contact IDs for whom a contribution already exists in this billing period.
|
||||
* @var array
|
||||
*/
|
||||
public static $contributionExists = [];
|
||||
|
||||
/**
|
||||
* A string that represents the current billing period - e.g. "2019-2".
|
||||
* First number is the year; second is 1 for Jan-Jun, 2 for Jul-Dec.
|
||||
* @var string
|
||||
*/
|
||||
public static $billingPeriod = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
@ -60,32 +73,52 @@ class CRM_Tbusainvoicegen_Timebank {
|
||||
* @param int $cid
|
||||
* @return array APIv3 standard response.
|
||||
*/
|
||||
public static function generate($cid = NULL) {
|
||||
public static function generate($cid = NULL, $billingPeriod = NULL) {
|
||||
self::setBillingPeriod($billingPeriod);
|
||||
// Get a list of contact IDs for everyone to generate an invoice for.
|
||||
$result = civicrm_api3('Contact', 'get', [
|
||||
$contacts = civicrm_api3('Contact', 'get', [
|
||||
'return' => ["id", self::BILLABLEMEMBERFIELD],
|
||||
'contact_id' => $cid,
|
||||
'contact_type' => 'Organization',
|
||||
self::TBBILLABLEFIELD => 1,
|
||||
'options' => ['limit' => 0],
|
||||
]);
|
||||
])['values'];
|
||||
self::setContributionExists();
|
||||
foreach ($result as $k => $contact) {
|
||||
$tb = new CRM_Tbusainvoicegen_Timebank($k, $contact[self::BILLABLEMEMBERFIELD]);
|
||||
$price = $tb->setPrice();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setBillingPeriod($billingPeriod) {
|
||||
if ($billingPeriod) {
|
||||
self::$billingPeriod = $billingPeriod;
|
||||
}
|
||||
else {
|
||||
// Should we try to auto-calculate it here? Or nah?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an array of contacts who already have a contribution created in this billing period.
|
||||
*/
|
||||
public static function setContributionExists() {
|
||||
// API call to contribution.get to find all records with this billing period
|
||||
// Return an array of contact IDs.
|
||||
}
|
||||
|
||||
private function setPrice() {
|
||||
if (self::$price) {
|
||||
return self::$price;
|
||||
if ($this->price) {
|
||||
return $this->price;
|
||||
}
|
||||
$adjustedMemberCount = $memberCount - 2;
|
||||
foreach ($priceArray as $members => $cost) {
|
||||
$adjustedMemberCount = $this->memberCount - 2;
|
||||
foreach ($this->priceArray as $members => $cost) {
|
||||
if ($adjustedMemberCount <= $members) {
|
||||
self::$price = $cost;
|
||||
$this->price = $cost;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return self::$price;
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user