ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserDefinedInvoiceNumber.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 include_once './Services/Payment/classes/class.ilPaymentSettings.php';
14 
16 {
17  public $pSettings;
18 
19  public $ud_invoice_number = 0;
20  public $invoice_number_text = null;
21  public $inc_start_value = 0;
22  public $inc_current_value = 0;
23  public $inc_reset_period = 0;
24  public $last_reset = 0;
25 
26  // SETTER/GETTER
27 
28  /* enable user-defined invoice number -> 1
29  * disable for using standard ilias invoice number -> 0
30  *
31  */
32  public function setUDInvoiceNumberActive($a_ud_invoice_number)
33  {
34  $this->ud_invoice_number = $a_ud_invoice_number;
35  }
36  public function getUDInvoiceNumberActive()
37  {
39  }
40 
41  public function setInvoiceNumberText($a_invoice_number_text)
42  {
43  $this->invoice_number_text = $a_invoice_number_text;
44  }
45  public function getInvoiceNumberText()
46  {
48  }
49 
50  public function setIncStartValue($a_inc_start_value)
51  {
52  $this->inc_start_value = $a_inc_start_value;
53  }
54  public function getIncStartValue()
55  {
57  }
58 
59  public function setIncCurrentValue($a_inc_current_value)
60  {
61  $this->inc_current_value = $a_inc_current_value;
62  }
63  public function getIncCurrentValue()
64  {
66  }
67 
68  /*
69  * @param integer $a_inc_reset_period (1=yearly, 2=monthly)
70  */
71  public function setIncResetPeriod($a_inc_reset_period)
72  {
73  $this->inc_reset_period = $a_inc_reset_period;
74  }
75  public function getIncResetPeriod()
76  {
78  }
79 
80  /*
81  * @param integer timestamp
82  */
83  public function setIncLastReset($a_timestamp)
84  {
85  $this->inc_last_reset = $a_timestamp;
86  }
87 
88  public function getIncLastReset()
89  {
90  return $this->inc_last_reset;
91  }
92 
93  public function __construct()
94  {
95  $this->pSettings = ilPaymentSettings::_getInstance();
96  $this->read();
97  }
98 
99  public function read()
100  {
101  $settings = $this->pSettings->getValuesByScope('invoice_number');
102  $this->ud_invoice_number = $settings['ud_invoice_number'];
103  $this->invoice_number_text = $settings['invoice_number_text'];
104  $this->inc_start_value = $settings['inc_start_value'];
105  $this->inc_current_value = $settings['inc_current_value'];
106  $this->inc_reset_period = $settings['inc_reset_period'];
107  $this->inc_last_reset = $settings['inc_last_reset'];
108  }
109 
110  public function update()
111  {
112  $this->pSettings->set('ud_invoice_number', $this->getUDInvoiceNumberActive(),'invoice_number');
113  $this->pSettings->set('invoice_number_text', $this->getInvoiceNumberText(),'invoice_number');
114  $this->pSettings->set('inc_start_value', $this->getIncStartValue(),'invoice_number');
115  $this->pSettings->set('inc_reset_period', $this->getIncResetPeriod(),'invoice_number');
116  }
117 
118 
119  public static function _nextIncCurrentValue()
120  {
122  $cur_id = $pSettings->get('inc_current_value');
123  $next_id = ++$cur_id;
124 
125  $pSettings->set('inc_current_value', $next_id, 'invoice_number');
126 
127  return $next_id;
128 
129  }
133  public static function _setIncCurrentValue($a_value)
134  {
136  $pSettings->set('inc_current_value', $a_value, 'invoice_number');
137  }
138 
139  public static function _getIncCurrentValue()
140  {
142  return $pSettings->get('inc_current_value');
143 
144  }
145  public static function _getResetPeriod()
146  {
148  return $pSettings->get('inc_reset_period');
149  }
150 
151  /*
152  *
153  * @return boolean
154  */
155  public static function _isUDInvoiceNumberActive()
156  {
158 
159  if(!IS_PAYMENT_ENABLED) return false;
160 
161  if($pSettings->get('ud_invoice_number') == 1)
162  return true;
163  else
164  return false;
165  }
166 
167 // CRON CHECK
168  public function cronCheck()
169  {
170  $last_reset = $this->getIncLastReset();
171  $last_month = date('n', $last_reset);
172  $last_year = date('Y', $last_reset);
173 
174  $now = time();
175  $now_month = date('n', $now);
176  $now_year = date('Y', $now);
177 
178  $reset_type = $this->getIncResetPeriod();
179 
180  switch($reset_type)
181  {
182  case '1': #yearly
183  if($last_year < $now_year)
184  {
185  $reset = true;
186  }
187  break;
188  case '2': #monthly
189  if(($last_month < $now_month) || ($last_month > $now_month && $last_year < $now_year) )
190  {
191  $reset = true;
192  }
193  break;
194  default:
195  $reset = false;
196  break;
197  }
198 
199  if($reset == true)
200  {
201  $this->setIncCurrentValue($this->getIncStartValue());
202  $this->setIncLastReset(mktime(0, 0, 0, $now_month, 1, $now_year));
203  $this->__updateCron();
204  }
205  }
206 
207  private function __updateCron()
208  {
209  $this->pSettings->set('inc_current_value',$this->getIncCurrentValue(),'invoice_number');
210  $this->pSettings->set('inc_last_reset',$this->getIncLastReset(), 'invoice_number');
211  }
212 }
213 ?>