3
* PurchaseDBO.class.php
5
* This file contains the definition for the PurchaseDBO class.
8
* @author John Diamond <jdiamond@solid-state.org>
9
* @copyright John Diamond <jdiamond@solid-state.org>
10
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
16
* Represent a Purchase. This class is abstract, it is implemented by the
17
* DomainServicePurchase, HostingServicePurchase, and ProductPurchase classes.
18
* A PurchaseDBO is still abstract, but it is more concrete than SaleDBO. A
19
* "Purchase" attaches a product or service to a specific account.
22
* @author John Diamond <jdiamond@solid-state.org>
24
abstract class PurchaseDBO extends SaleDBO
27
* @var integer Account ID
32
* @var AccountDBO Account
34
protected $accountdbo;
37
* @var string Purchase date (MySQL datetime)
39
protected $date = null;
42
* @var string The next day that this purchase will be billed on
44
protected $nextBillingDate = null;
47
* @var string Purchase note
52
* @var integer ID of the last invoice this purchase was billed on
54
protected $prevInvoiceID = null;
59
public function __construct()
61
parent::__construct();
63
// Initialize the next payment date to today
64
$this->setNextBillingDate( DBConnection::format_date( time() ) );
70
* @return integer Account ID
72
public function getAccountID() { return $this->accountid; }
77
* @return string Account Name
79
public function getAccountName() { return $this->accountdbo->getAccountName(); }
84
* @return string Purchase date (MySQL datetime)
86
public function getDate()
92
* Get Description for "One-time" Line Item
94
* @return string The text that should appear on the invoice for this purchase
96
public function getLineItemTextOneTime()
98
return $this->getTitle() . " ([ONETIME])";
102
* Get Description for "Recurring" Line Item
104
* @return string The text that should appear on the invoice for this purchase
106
public function getLineItemTextRecurring()
108
return $this->getTitle();
112
* Get Description for "Tax" Line Item
114
* @return string The text that should appear on the invoice for this purchase
116
public function getLineItemTextTax()
118
return $this->getTitle() . ": [TAX]";
122
* Get Next Billing Date
124
* @return string The next billing date for this purchase (MySQL DATETIME)
126
public function getNextBillingDate() { return $this->nextBillingDate; }
131
* @return string Purchase note
133
function getNote() { return $this->note; }
136
* Get Previous Invoice ID
138
* @return integer The ID of the invoice this purchase last appeared on or -1 if last charged to an order
140
public function getPrevInvoiceID() { return $this->prevInvoiceID; }
145
* @return array An array of tax rules that apply to this purchase
147
protected function getTaxRules()
149
$DB = DBConnection::getDBConnection();
152
"country=" . $DB->quote_smart( $this->accountdbo->getCountry() ) . " AND (" .
153
"allstates=" . $DB->quote_smart( "YES" ) . " OR " .
154
"state=" . $DB->quote_smart( $this->accountdbo->getState() ) . ")";
156
try { return load_array_TaxRuleDBO( $filter ); }
157
catch( DBNoRowsFoundException $e ) { return array(); }
161
* Get Product/Service Title
163
* @return string Product/Service title
165
abstract function getTitle();
168
* Increment Next Billing Date
170
public function incrementNextBillingDate()
172
$nextBillingDateTS = DBConnection::date_to_unix( $this->getNextBillingDate() );
173
$oldBillingDate = getdate( $nextBillingDateTS );
175
DBConnection::format_date( mktime( 0, 0, 1,
176
$oldBillingDate['mon'] + $this->getTerm(),
177
$oldBillingDate['mday'],
178
$oldBillingDate['year'] ) );
180
$this->setNextBillingDate( $nextBillingDate );
181
return $nextBillingDate;
187
* @param integer $id Account ID
189
public function setAccountID( $id )
191
$this->accountid = $id;
192
$this->accountdbo = load_AccountDBO( $id );
198
* @param string $date Purchase date (MySQL datetime)
200
public function setDate( $date ) { $this->date = $date; }
203
* Set Next Billing Date
205
* @param string The next billing date for this purchase (MySQL DATETIME)
207
public function setNextBillingDate( $date ) { $this->nextBillingDate = $date; }
212
* @param string $note Purchase note
214
function setNote( $note ) { $this->note = $note; }
217
* Set Previous Invoice ID
219
* @param integer The ID of the Invoice this purchase last appeared on
221
public function setPrevInvoiceID( $id ) { $this->prevInvoiceID = $id; }
b'\\ No newline at end of file'