tbusainvoicegen/CRM/Tbusainvoicegen/Generator.php

92 lines
2.0 KiB
PHP

<?php
class CRM_Tbusainvoicegen_Timebank {
/**
* Live settings
* const TBBILLABLEFIELD = 'custom_202';
* const BILLABLEMEMBERFIELD = 'custom_199';
*/
const TBBILLABLEFIELD = 'custom_9';
const BILLABLEMEMBERFIELD = 'custom_10';
/**
* Set the pricing here.
* Up to the number of members in single quotes means you pay the second number every 6 months.
*/
private $priceArray = [
'34' => 30,
'49' => 60,
'79' => 90,
'119' => 160,
'149' => 200,
'199' => 240,
'249' => 340,
'349' => 440,
'499' => 590,
'749' => 880,
'1000' => 1200,
'9999999' => 9999,
];
/**
* The contact ID of this timebank.
* @var int
*/
private $contactId;
/**
* The number of billable members.
* @var int
*/
private $memberCount;
/**
* The price for one period of this timebank.
* @var float
*/
private $price;
/**
* Class constructor.
*/
public function __construct($cid, $memberCount) {
$this->cid = $cid;
$this->memberCount = $memberCount;
}
/**
* Generate invoices (called from API).
* @param int $cid
* @return array APIv3 standard response.
*/
public static function generate($cid = NULL) {
// Get a list of contact IDs for everyone to generate an invoice for.
$result = civicrm_api3('Contact', 'get', [
'return' => ["id", self::BILLABLEMEMBERFIELD],
'contact_id' => $cid,
'contact_type' => 'Organization',
self::TBBILLABLEFIELD => 1,
'options' => ['limit' => 0],
]);
foreach ($result as $k => $contact) {
$tb = new CRM_Tbusainvoicegen_Timebank($k, $contact[self::BILLABLEMEMBERFIELD]);
}
}
private function setPrice() {
if (self::$price) {
return self::$price;
}
$adjustedMemberCount = $memberCount - 2;
foreach ($priceArray as $members => $cost) {
if ($adjustedMemberCount <= $members) {
self::$price = $cost;
break;
}
}
return self::$price;
}
}