~katiekitty/+junk/solidstate

« back to all changes in this revision

Viewing changes to solidstate/trunk/DBO/PurchaseDBO.class.php

  • Committer: root
  • Date: 2010-01-13 07:44:31 UTC
  • Revision ID: root@ds3-vamp.cs-monitor.cz.cc-20100113074431-kt8ceoeznpjg22x7
Reviving the project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PurchaseDBO.class.php
 
4
 *
 
5
 * This file contains the definition for the PurchaseDBO class.
 
6
 *
 
7
 * @package DBO
 
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
 
11
 */
 
12
 
 
13
/**
 
14
 * PurchaseDBO
 
15
 *
 
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.
 
20
 *
 
21
 * @package DBO
 
22
 * @author John Diamond <jdiamond@solid-state.org>
 
23
 */
 
24
abstract class PurchaseDBO extends SaleDBO
 
25
{
 
26
  /**
 
27
   * @var integer Account ID
 
28
   */
 
29
  protected $accountid;
 
30
 
 
31
  /**
 
32
   * @var AccountDBO Account
 
33
   */
 
34
  protected $accountdbo;
 
35
 
 
36
  /**
 
37
   * @var string Purchase date (MySQL datetime)
 
38
   */
 
39
  protected $date = null;
 
40
 
 
41
  /**
 
42
   * @var string The next day that this purchase will be billed on
 
43
   */
 
44
  protected $nextBillingDate = null;
 
45
 
 
46
  /**
 
47
   * @var string Purchase note
 
48
   */
 
49
  protected $note;
 
50
 
 
51
  /**
 
52
   * @var integer ID of the last invoice this purchase was billed on
 
53
   */
 
54
  protected $prevInvoiceID = null;
 
55
 
 
56
  /**
 
57
   * Constructor
 
58
   */
 
59
  public function __construct()
 
60
  {
 
61
    parent::__construct();
 
62
 
 
63
    // Initialize the next payment date to today
 
64
    $this->setNextBillingDate( DBConnection::format_date( time() ) );
 
65
  }
 
66
 
 
67
  /**
 
68
   * Get Account ID
 
69
   *
 
70
   * @return integer Account ID
 
71
   */
 
72
  public function getAccountID() { return $this->accountid; }
 
73
 
 
74
  /**
 
75
   * Get Account Name
 
76
   *
 
77
   * @return string Account Name
 
78
   */
 
79
  public function getAccountName() { return $this->accountdbo->getAccountName(); }
 
80
 
 
81
  /**
 
82
   * Get Purchase Date
 
83
   *
 
84
   * @return string Purchase date (MySQL datetime)
 
85
   */
 
86
  public function getDate()
 
87
  {
 
88
    return $this->date;
 
89
  }
 
90
 
 
91
  /**
 
92
   * Get Description for "One-time" Line Item
 
93
   *
 
94
   * @return string The text that should appear on the invoice for this purchase
 
95
   */
 
96
  public function getLineItemTextOneTime()
 
97
  {
 
98
    return $this->getTitle() . " ([ONETIME])";
 
99
  }
 
100
 
 
101
  /**
 
102
   * Get Description for "Recurring" Line Item
 
103
   *
 
104
   * @return string The text that should appear on the invoice for this purchase
 
105
   */
 
106
  public function getLineItemTextRecurring()
 
107
  {
 
108
    return $this->getTitle();
 
109
  }
 
110
 
 
111
  /**
 
112
   * Get Description for "Tax" Line Item
 
113
   *
 
114
   * @return string The text that should appear on the invoice for this purchase
 
115
   */
 
116
  public function getLineItemTextTax()
 
117
  {
 
118
    return $this->getTitle() . ": [TAX]";
 
119
  }
 
120
 
 
121
  /**
 
122
   * Get Next Billing Date
 
123
   *
 
124
   * @return string The next billing date for this purchase (MySQL DATETIME)
 
125
   */
 
126
  public function getNextBillingDate() { return $this->nextBillingDate; }
 
127
 
 
128
  /**
 
129
   * Get Purchase Note
 
130
   *
 
131
   * @return string Purchase note
 
132
   */
 
133
  function getNote() { return $this->note; }
 
134
 
 
135
  /**
 
136
   * Get Previous Invoice ID
 
137
   *
 
138
   * @return integer The ID of the invoice this purchase last appeared on or -1 if last charged to an order
 
139
   */
 
140
  public function getPrevInvoiceID() { return $this->prevInvoiceID; }
 
141
 
 
142
  /**
 
143
   * Get Tax Rules
 
144
   *
 
145
   * @return array An array of tax rules that apply to this purchase
 
146
   */
 
147
  protected function getTaxRules() 
 
148
  { 
 
149
    $DB = DBConnection::getDBConnection();
 
150
 
 
151
    $filter = 
 
152
      "country=" . $DB->quote_smart( $this->accountdbo->getCountry() ) . " AND (" .
 
153
      "allstates=" . $DB->quote_smart( "YES" ) . " OR " .
 
154
      "state=" . $DB->quote_smart( $this->accountdbo->getState() ) . ")";
 
155
 
 
156
    try { return load_array_TaxRuleDBO( $filter ); }
 
157
    catch( DBNoRowsFoundException $e ) { return array(); }
 
158
  }
 
159
 
 
160
  /**
 
161
   * Get Product/Service Title
 
162
   *
 
163
   * @return string Product/Service title
 
164
   */
 
165
  abstract function getTitle();
 
166
 
 
167
  /**
 
168
   * Increment Next Billing Date
 
169
   */
 
170
  public function incrementNextBillingDate()
 
171
  {
 
172
    $nextBillingDateTS = DBConnection::date_to_unix( $this->getNextBillingDate() );
 
173
    $oldBillingDate = getdate( $nextBillingDateTS );
 
174
    $nextBillingDate = 
 
175
      DBConnection::format_date( mktime( 0, 0, 1,
 
176
                                         $oldBillingDate['mon'] + $this->getTerm(),
 
177
                                         $oldBillingDate['mday'],
 
178
                                         $oldBillingDate['year'] ) );
 
179
 
 
180
    $this->setNextBillingDate( $nextBillingDate );
 
181
    return $nextBillingDate;
 
182
  }
 
183
 
 
184
  /**
 
185
   * Set Account ID
 
186
   *
 
187
   * @param integer $id Account ID
 
188
   */
 
189
  public function setAccountID( $id )
 
190
  {
 
191
    $this->accountid = $id;
 
192
    $this->accountdbo = load_AccountDBO( $id );
 
193
  }
 
194
 
 
195
  /**
 
196
   * Set Purchase Date
 
197
   *
 
198
   * @param string $date Purchase date (MySQL datetime)
 
199
   */
 
200
  public function setDate( $date ) { $this->date = $date; }
 
201
 
 
202
  /**
 
203
   * Set Next Billing Date
 
204
   *
 
205
   * @param string The next billing date for this purchase (MySQL DATETIME)
 
206
   */
 
207
  public function setNextBillingDate( $date ) { $this->nextBillingDate = $date; }
 
208
 
 
209
  /**
 
210
   * Set Purchase Note
 
211
   *
 
212
   * @param string $note Purchase note
 
213
   */
 
214
  function setNote( $note ) { $this->note = $note; }
 
215
 
 
216
  /**
 
217
   * Set Previous Invoice ID
 
218
   *
 
219
   * @param integer The ID of the Invoice this purchase last appeared on
 
220
   */
 
221
  public function setPrevInvoiceID( $id ) { $this->prevInvoiceID = $id; }
 
222
}
 
223
 
 
224
?>
 
 
b'\\ No newline at end of file'