3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Contribution class for galette
10 * Copyright © 2010-2014 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2010-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7dev - 2010-03-11
38 namespace Galette\Entity
;
41 use Zend\Db\Sql\Expression
;
43 use Galette\Core\Login
;
44 use Galette\IO\ExternalScript
;
45 use Galette\IO\PdfContribution
;
48 * Contribution class for galette
53 * @author Johan Cwiklinski <johan@x-tnd.be>
54 * @copyright 2010-2014 The Galette Team
55 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
56 * @link http://galette.tuxfamily.org
57 * @since Available since 0.7dev - 2010-03-11
61 const TABLE
= 'cotisations';
62 const PK
= 'id_cotis';
64 const PAYMENT_OTHER
= 0;
65 const PAYMENT_CASH
= 1;
66 const PAYMENT_CREDITCARD
= 2;
67 const PAYMENT_CHECK
= 3;
68 const PAYMENT_TRANSFER
= 4;
69 const PAYMENT_PAYPAL
= 5;
76 private $_payment_type;
77 private $_orig_amount;
81 private $_transaction = null;
85 //fields list and their translation
94 * @param Db $zdb Database
95 * @param Login $login Login instance
96 * @param null|int|ResultSet $args Either a ResultSet row to load
97 * a specific contribution, or an type id
98 * to just instanciate object
100 public function __construct(Db
$zdb, Login
$login, $args = null)
103 $this->login
= $login;
106 * Fields configuration. Each field is an array and must reflect:
112 * I'd prefer a static private variable for this...
113 * But call to the _T function does not seem to be allowed there :/
115 $this->_fields
= array(
117 'label' => null, //not a field in the form
120 Adherent
::PK
=> array(
121 'label' => _T("Contributor:"),
122 'propname' => 'member'
124 ContributionsTypes
::PK
=> array(
125 'label' => _T("Contribution type:"),
128 'montant_cotis' => array(
129 'label' => _T("Amount:"),
130 'propname' => 'amount'
132 'type_paiement_cotis' => array(
133 'label' => _T("Payment type:"),
134 'propname' => 'payment_type'
136 'info_cotis' => array(
137 'label' => _T("Comments:"),
140 'date_enreg' => array(
141 'label' => null, //not a field in the form
144 'date_debut_cotis' => array(
145 'label' => _T("Date of contribution:"),
146 'cotlabel' => _T("Start date of membership:"), //if contribution is a cotisation, label differs
147 'propname' => 'begin_date'
149 'date_fin_cotis' => array(
150 'label' => _T("End date of membership:"),
151 'propname' => 'end_date'
153 Transaction
::PK
=> array(
154 'label' => null, //not a field in the form
155 'propname' => 'transaction'
157 //this one is not really a field, but is required in some cases...
158 //adding it here make simplier to check required fields
159 'duree_mois_cotis' => array(
160 'label' => _T("Membership extension:"),
161 'propname' => 'extension'
166 } elseif (is_array($args)) {
167 $this->_date
= date("Y-m-d");
168 if (isset($args['adh']) && $args['adh'] != '') {
169 $this->_member
= (int)$args['adh'];
171 if (isset($args['trans'])) {
172 $this->_transaction
= new Transaction($this->zdb
, $this->login
, (int)$args['trans']);
173 if (!isset($this->_member
)) {
174 $this->_member
= (int)$this->_transaction
->member
;
176 $this->_amount
= $this->_transaction
->getMissingAmount();
178 $this->type
= (int)$args['type'];
179 //calculate begin date for cotisation
180 $this->_begin_date
= $this->_date
;
181 if ($this->_is_cotis
) {
182 $curend = self
::getDueDate($this->zdb
, $this->_member
);
184 $dend = new \
DateTime($curend);
185 $now = date('Y-m-d');
186 $dnow = new \
DateTime($now);
188 // Member didn't renew on time
189 $this->_begin_date
= $now;
191 $this->_begin_date
= $curend;
194 $this->retrieveEndDate();
196 if (isset($args['payment_type'])) {
197 $this->_payment_type
= $args['payment_type'];
199 } elseif (is_object($args)) {
200 $this->loadFromRS($args);
205 * Sets end contribution date
209 private function retrieveEndDate()
213 $bdate = new \
DateTime($this->_begin_date
);
214 if ($preferences->pref_beg_membership
!= '') {
215 //case beginning of membership
216 list($j, $m) = explode('/', $preferences->pref_beg_membership
);
217 $edate = new \
DateTime($bdate->format('Y') . '-' . $m . '-' . $j);
218 while ($edate <= $bdate) {
219 $edate->modify('+1 year');
221 $this->_end_date
= $edate->format('Y-m-d');
222 } elseif ($preferences->pref_membership_ext
!= '') {
223 //case membership extension
224 $this->_extension
= $preferences->pref_membership_ext
;
225 $dext = new \
DateInterval('P' . $this->_extension
. 'M');
226 $edate = $bdate->add($dext);
227 $this->_end_date
= $edate->format('Y-m-d');
232 * Loads a contribution from its id
234 * @param int $id the identifiant for the contribution to load
236 * @return bool true if query succeed, false otherwise
238 public function load($id)
241 $select = $this->zdb
->select(self
::TABLE
);
242 $select->where(self
::PK
. ' = ' . $id);
243 //restrict query on current member id if he's not admin nor staff member
244 if (!$this->login
->isAdmin() && !$this->login
->isStaff()) {
245 $select->where(Adherent
::PK
. ' = ' . $this->login
->id
);
248 $results = $this->zdb
->execute($select);
249 $row = $results->current();
250 if ($row !== false) {
251 $this->loadFromRS($row);
254 throw new \
Exception(
255 'No contribution #' . $id . ' (user ' .$this->login
->id
. ')'
258 } catch (\Exception
$e) {
260 'An error occured attempting to load contribution #' . $id .
269 * Populate object from a resultset row
271 * @param ResultSet $r the resultset row
275 private function loadFromRS($r)
278 $this->_id
= (int)$r->$pk;
279 $this->_date
= $r->date_enreg
;
280 $this->_amount
= $r->montant_cotis
;
281 //save original amount, we need it for transactions parts calulations
282 $this->_orig_amount
= $r->montant_cotis
;
283 $this->_payment_type
= $r->type_paiement_cotis
;
284 $this->_info
= $r->info_cotis
;
285 $this->_begin_date
= $r->date_debut_cotis
;
286 $enddate = $r->date_fin_cotis
;
287 //do not work with knows bad dates...
288 //the one with BC comes from 0.63/pgsl demo... Why the hell a so
289 //strange date? dont know :(
290 if ($enddate !== '0000-00-00'
291 && $enddate !== '1901-01-01'
292 && $enddate !== '0001-01-01 BC'
294 $this->_end_date
= $r->date_fin_cotis
;
296 $adhpk = Adherent
::PK
;
297 $this->_member
= (int)$r->$adhpk;
299 $transpk = Transaction
::PK
;
300 if ($r->$transpk != '') {
301 $this->_transaction
= new Transaction($this->zdb
, $this->login
, (int)$r->$transpk);
304 $this->type
= (int)$r->id_type_cotis
;
308 * Check posted values validity
310 * @param array $values All values to check, basically the $_POST array
311 * after sending the form
312 * @param array $required Array of required fields
313 * @param array $disabled Array of disabled fields
317 public function check($values, $required, $disabled)
321 $fields = array_keys($this->_fields
);
322 foreach ($fields as $key) {
323 //first of all, let's sanitize values
324 $key = strtolower($key);
325 $prop = '_' . $this->_fields
[$key]['propname'];
327 if (isset($values[$key])) {
328 $value = trim($values[$key]);
333 // if the field is enabled, check it
334 if (!isset($disabled[$key])) {
335 // fill up the adherent structure
336 //$this->$prop = stripslashes($value); //not relevant here!
338 // now, check validity
342 case 'date_debut_cotis':
343 case 'date_fin_cotis':
346 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
348 throw new \
Exception('Incorrect format');
350 $this->$prop = $d->format('Y-m-d');
351 } catch (\Exception
$e) {
353 'Wrong date format. field: ' . $key .
354 ', value: ' . $value . ', expected fmt: ' .
355 __("Y-m-d") . ' | ' . $e->getMessage(),
358 $errors[] = str_replace(
365 $this->_fields
[$key]['label']
367 _T("- Wrong date format (%date_format) for %field!")
374 $this->_member
= $value;
377 case ContributionsTypes
::PK
:
379 $this->type
= (int)$value;
382 case 'montant_cotis':
383 $this->_amount
= $value;
384 $value = strtr($value, ',', '.');
385 if (!is_numeric($value)) {
386 $errors[] = _T("- The amount must be an integer!");
389 case 'type_paiement_cotis':
390 if ($value == self
::PAYMENT_OTHER
391 ||
$value == self
::PAYMENT_CASH
392 ||
$value == self
::PAYMENT_CREDITCARD
393 ||
$value == self
::PAYMENT_CHECK
394 ||
$value == self
::PAYMENT_TRANSFER
395 ||
$value == self
::PAYMENT_PAYPAL
397 $this->_payment_type
= $value;
399 $errors[] = _T("- Unknown payment type");
403 $this->_info
= $value;
405 case Transaction
::PK
:
407 $this->_transaction
= new Transaction($this->zdb
, $this->login
, (int)$value);
410 case 'duree_mois_cotis':
412 if (!is_numeric($value) ||
$value <= 0) {
413 $errors[] = _T("- The duration must be a positive integer!");
415 $this->$prop = $value;
416 $this->retrieveEndDate();
423 // missing required fields?
424 foreach ($required as $key => $val) {
426 $prop = '_' . $this->_fields
[$key]['propname'];
427 if (!isset($disabled[$key])
428 && (!isset($this->$prop)
429 ||
(!is_object($this->$prop) && trim($this->$prop) == '')
430 ||
(is_object($this->$prop) && trim($this->$prop->id
) == ''))
432 $errors[] = _T("- Mandatory field empty: ") .
433 ' <a href="#' . $key . '">' . $this->getFieldLabel($key) .'</a>';
438 if ($this->_transaction
!= null && $this->_amount
!= null) {
439 $missing = $this->_transaction
->getMissingAmount();
440 //calculate new missing amount
441 $missing = $missing +
$this->_orig_amount
- $this->_amount
;
443 $errors[] = _T("- Sum of all contributions exceed corresponding transaction amount.");
447 if (count($errors) > 0) {
449 'Some errors has been throwed attempting to edit/store a contribution' .
450 print_r($errors, true),
456 'Contribution checked successfully.',
464 * Check that membership fees does not overlap
466 * @return boolean|string True if all is ok, false if error,
467 * error message if overlap
469 public function checkOverlap()
472 $select = $this->zdb
->select(self
::TABLE
, 'c');
474 array('date_debut_cotis', 'date_fin_cotis')
476 array('ct' => PREFIX_DB
. ContributionsTypes
::TABLE
),
477 'c.' . ContributionsTypes
::PK
. '=ct.' . ContributionsTypes
::PK
,
479 )->where(Adherent
::PK
. ' = ' . $this->_member
)
480 ->where(array('cotis_extension' => new Expression('true')))
482 ->greaterThanOrEqualTo('date_debut_cotis', $this->_begin_date
)
483 ->lessThan('date_debut_cotis', $this->_end_date
)
486 ->greaterThan('date_fin_cotis', $this->_begin_date
)
487 ->lessThanOrEqualTo('date_fin_cotis', $this->_end_date
);
489 if ($this->id
!= '') {
490 $select->where(self
::PK
. ' != ' . $this->id
);
493 $results = $this->zdb
->execute($select);
494 if ($results->count() > 0) {
495 $result = $results->current();
496 $d = new \
DateTime($result->date_debut_cotis
);
498 return _T("- Membership period overlaps period starting at ") .
499 $d->format(__("Y-m-d"));
502 } catch (\Exception
$e) {
504 'An error occured checking overlaping fee. ' . $e->getMessage(),
512 * Store the contribution
516 public function store()
521 $this->zdb
->connection
->beginTransaction();
523 $fields = self
::getDbFields($this->zdb
);
524 foreach ($fields as $field) {
525 $prop = '_' . $this->_fields
[$field]['propname'];
527 case ContributionsTypes
::PK
:
528 case Transaction
::PK
:
529 if (isset($this->$prop)) {
530 $values[$field] = $this->$prop->id
;
534 $values[$field] = $this->$prop;
539 //no end date, let's take database defaults
540 if (!$this->isCotis() && !$this->_end_date
) {
541 unset($values['date_fin_cotis']);
544 if (!isset($this->_id
) ||
$this->_id
== '') {
545 //we're inserting a new contribution
546 unset($values[self
::PK
]);
548 $insert = $this->zdb
->insert(self
::TABLE
);
549 $insert->values($values);
550 $add = $this->zdb
->execute($insert);
552 if ($add->count() > 0) {
553 if ($this->zdb
->isPostgres()) {
554 $this->_id
= $this->zdb
->driver
->getLastGeneratedValue(
555 PREFIX_DB
. 'cotisations_id_seq'
558 $this->_id
= $this->zdb
->driver
->getLastGeneratedValue();
563 _T("Contribution added"),
564 Adherent
::getSName($this->zdb
, $this->_member
)
567 $hist->add(_T("Fail to add new contribution."));
568 throw new \
Exception(
569 'An error occured inserting new contribution!'
573 //we're editing an existing contribution
574 $update = $this->zdb
->update(self
::TABLE
);
575 $update->set($values)->where(
576 self
::PK
. '=' . $this->_id
578 $edit = $this->zdb
->execute($update);
580 //edit == 0 does not mean there were an error, but that there
581 //were nothing to change
582 if ($edit->count() > 0) {
584 _T("Contribution updated"),
585 Adherent
::getSName($this->zdb
, $this->_member
)
587 } elseif ($edit === false) {
588 throw new \
Exception(
589 'An error occured updating contribution # ' . $this->_id
. '!'
594 if ($this->isCotis()) {
595 $deadline = $this->updateDeadline();
596 if ($deadline !== true) {
597 //if something went wrong, we rollback transaction
598 throw new \
Exception('An error occured updating member\'s deadline');
601 $this->zdb
->connection
->commit();
602 $this->_orig_amount
= $this->_amount
;
604 } catch (\Exception
$e) {
605 $this->zdb
->connection
->rollBack();
607 'Something went wrong :\'( | ' . $e->getMessage() . "\n" .
608 $e->getTraceAsString(),
616 * Update member dead line
620 private function updateDeadline()
623 $due_date = self
::getDueDate($this->zdb
, $this->_member
);
625 if ($due_date != '') {
626 $date_fin_update = $due_date;
628 $date_fin_update = new Expression('NULL');
631 $update = $this->zdb
->update(Adherent
::TABLE
);
633 array('date_echeance' => $date_fin_update)
635 Adherent
::PK
. '=' . $this->_member
637 $this->zdb
->execute($update);
639 } catch (\Exception
$e) {
641 'An error occured updating member ' . $this->_member
.
651 * Remove contribution from database
653 * @param boolean $transaction Activate transaction mode (defaults to true)
657 public function remove($transaction = true)
661 $this->zdb
->connection
->beginTransaction();
664 $delete = $this->zdb
->delete(self
::TABLE
);
665 $delete->where(self
::PK
. ' = ' . $this->_id
);
666 $del = $this->zdb
->execute($delete);
667 if ($del->count() > 0) {
668 $this->updateDeadline();
671 $this->zdb
->connection
->commit();
674 } catch (\Exception
$e) {
676 $this->zdb
->connection
->rollBack();
679 'An error occured trying to remove contribution #' .
680 $this->_id
. ' | ' . $e->getMessage(),
690 * @param string $field Field name
694 public function getFieldLabel($field)
696 $label = $this->_fields
[$field]['label'];
697 if ($this->isCotis() && $field == 'date_debut_cotis') {
698 $label = $this->_fields
[$field]['cotlabel'];
700 //remove trailing ':' and then nbsp (for french at least)
701 $label = trim(trim($label, ':'), ' ');
706 * Retrieve fields from database
708 * @param Db $zdb Database instance
712 public static function getDbFields(Db
$zdb)
714 $columns = $zdb->getColumns(self
::TABLE
);
716 foreach ($columns as $col) {
717 $fields[] = $col->getName();
723 * Get the relevant CSS class for current contribution
725 * @return string current contribution row class
727 public function getRowClass()
729 return ( $this->_end_date
!= $this->_begin_date
&& $this->_is_cotis
) ?
735 * Retrieve member due date
737 * @param Db $zdb Database instance
738 * @param integer $member_id Member identifier
742 public static function getDueDate(Db
$zdb, $member_id)
745 $select = $zdb->select(self
::TABLE
, 'c');
748 'max_date' => new Expression('MAX(date_fin_cotis)')
751 array('ct' => PREFIX_DB
. ContributionsTypes
::TABLE
),
752 'c.' . ContributionsTypes
::PK
. '=ct.' . ContributionsTypes
::PK
,
755 Adherent
::PK
. ' = ' . $member_id
757 array('cotis_extension' => new Expression('true'))
760 $results = $zdb->execute($select);
761 $result = $results->current();
762 $due_date = $result->max_date
;
764 //avoid bad dates in postgres and bad mysql return from zenddb
765 if ($due_date == '0001-01-01 BC' ||
$due_date == '1901-01-01') {
769 } catch (\Exception
$e) {
771 'An error occured trying to retrieve member\'s due date',
779 * Detach a contribution from a transaction
781 * @param Db $zdb Database instance
782 * @param Login $login Login instance
783 * @param int $trans_id Transaction identifier
784 * @param int $contrib_id Contribution identifier
788 public static function unsetTransactionPart(Db
$zdb, Login
$login, $trans_id, $contrib_id)
791 //first, we check if contribution is part of transaction
792 $c = new Contribution($zdb, $login, (int)$contrib_id);
793 if ($c->isTransactionPartOf($trans_id)) {
794 $update = $zdb->update(self
::TABLE
);
796 array(Transaction
::PK
=> null)
798 self
::PK
. ' = ' . $contrib_id
800 $zdb->execute($update);
804 'Contribution #' . $contrib_id .
805 ' is not actually part of transaction #' . $trans_id,
810 } catch (\Exception
$e) {
812 'Unable to detach contribution #' . $contrib_id .
813 ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
821 * Set a contribution as a transaction part
823 * @param Db $zdb Database instance
824 * @param int $trans_id Transaction identifier
825 * @param int $contrib_id Contribution identifier
829 public static function setTransactionPart(Db
$zdb, $trans_id, $contrib_id)
832 $update = $zdb->update(self
::TABLE
);
834 array(Transaction
::PK
=> $trans_id)
835 )->where(self
::PK
. ' = ' . $contrib_id);
837 $zdb->execute($update);
839 } catch (\Exception
$e) {
841 'Unable to attach contribution #' . $contrib_id .
842 ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
850 * Is current contribution a cotisation
854 public function isCotis()
856 return $this->_is_cotis
;
860 * Is current contribution part of specified transaction
862 * @param int $id Transaction identifier
866 public function isTransactionPartOf($id)
868 if ($this->isTransactionPart()) {
869 return $id == $this->_transaction
->id
;
876 * Is current contribution part of transaction
880 public function isTransactionPart()
882 return $this->_transaction
!= null;
886 * Execute post contribution script
888 * @param ExternalScript $es External script to execute
889 * @param array $extra Extra informations on contribution
891 * @param array $pextra Extra information on payment
894 * @return mixed Script return value on success, values and script output on fail
896 public function executePostScript(
904 'type' => $this->getPaymentType()
907 if ($pextra !== null && is_array($pextra)) {
908 $payment = array_merge($payment, $pextra);
911 if (!file_exists(GALETTE_CACHE_DIR
. '/pdf_contribs')) {
912 @mkdir
(GALETTE_CACHE_DIR
. '/pdf_contribs');
915 $voucher_path = null;
916 if ($this->_id
!== null) {
917 $voucher = new PdfContribution($this, $this->zdb
, $preferences);
918 $voucher->store(GALETTE_CACHE_DIR
. '/pdf_contribs');
919 $voucher_path = $voucher->getPath();
923 'date' => $this->_date
,
924 'type' => $this->getRawType(),
925 'amount' => $this->amount
,
926 'voucher' => $voucher_path,
928 'id' => $this->type
->id
,
929 'label' => $this->type
->libelle
931 'payment' => $payment
934 if ($this->_member
!== null) {
935 $m = new Adherent($this->zdb
, (int)$this->_member
);
937 'name' => $m->sfullname
,
938 'email' => $m->email
,
939 'organization' => ($m->isCompany() ?
1 : 0),
942 'label' => $m->sstatus
944 'country' => $m->country
947 if ($m->isCompany()) {
948 $member['organization_name'] = $m->company_name
;
951 $contrib['member'] = $member;
954 if ($extra !== null && is_array($extra)) {
955 $contrib = array_merge($contrib, $extra);
958 $res = $es->send($contrib);
962 'An error occured calling post contribution ' .
963 "script:\n" . $es->getOutput(),
966 $res = _T("Contribution informations") . "\n";
967 $res .= print_r($contrib, true);
968 $res .= "\n\n" . _T("Script output") . "\n";
969 $res .= $es->getOutput();
975 * Get raw contribution type
979 public function getRawType()
981 if ($this->isCotis()) {
989 * Get contribution type label
993 public function getTypeLabel()
995 if ($this->isCotis()) {
996 return _T("Membership");
998 return _T("Donation");
1003 * Get payent type label
1007 public function getPaymentType()
1009 switch ($this->payment_type
) {
1010 case Contribution
::PAYMENT_CASH
:
1013 case Contribution
::PAYMENT_CREDITCARD
:
1014 return 'credit_card';
1016 case Contribution
::PAYMENT_CHECK
:
1019 case Contribution
::PAYMENT_TRANSFER
:
1022 case Contribution
::PAYMENT_PAYPAL
:
1025 case Contribution
::PAYMENT_OTHER
:
1030 __METHOD__
. ' Unknonw payment type ' . $this->payment_type
,
1033 throw new \
RuntimeException(
1034 'Unknonw payment type ' . $this->payment_type
1040 * Global getter method
1042 * @param string $name name of the property we want to retrive
1044 * @return false|object the called property
1046 public function __get($name)
1049 $forbidden = array('is_cotis');
1050 $virtuals = array('duration', 'spayment_type', 'model', 'raw_date',
1051 'raw_begin_date', 'raw_end_date'
1054 $rname = '_' . $name;
1055 if (!in_array($name, $forbidden)
1056 && isset($this->$rname)
1057 ||
in_array($name, $virtuals)
1061 case 'raw_begin_date':
1062 case 'raw_end_date':
1063 $rname = '_' . substr($name, 4);
1064 if ($this->$rname != '') {
1066 $d = new \
DateTime($this->$rname);
1068 } catch (\Exception
$e) {
1069 //oops, we've got a bad date :/
1071 'Bad date (' . $this->$rname . ') | ' .
1082 if ($this->$rname != '') {
1084 $d = new \
DateTime($this->$rname);
1085 return $d->format(__("Y-m-d"));
1086 } catch (\Exception
$e) {
1087 //oops, we've got a bad date :/
1089 'Bad date (' . $this->$rname . ') | ' .
1093 return $this->$rname;
1098 if ($this->_is_cotis
) {
1099 $date_end = new \
DateTime($this->_end_date
);
1100 $date_start = new \
DateTime($this->_begin_date
);
1101 $diff = $date_end->diff($date_start);
1102 return $diff->format('%y') * 12 +
$diff->format('%m');
1107 case 'spayment_type':
1108 switch ($this->_payment_type
) {
1109 case self
::PAYMENT_OTHER
:
1112 case self
::PAYMENT_CASH
:
1115 case self
::PAYMENT_CREDITCARD
:
1116 return _T("Credit card");
1118 case self
::PAYMENT_CHECK
:
1121 case self
::PAYMENT_TRANSFER
:
1122 return _T("Transfer");
1124 case self
::PAYMENT_PAYPAL
:
1125 return _T("Paypal");
1129 'Unknown payment type ' . $this->_payment_type
,
1137 return ($this->isCotis()) ?
1138 PdfModel
::INVOICE_MODEL
:
1139 PdfModel
::RECEIPT_MODEL
;
1142 return $this->$rname;
1151 * Global setter method
1153 * @param string $name name of the property we want to assign a value to
1154 * @param object $value a relevant value for the property
1158 public function __set($name, $value)
1160 $forbidden = array('fields', 'is_cotis', 'end_date');
1162 if (!in_array($name, $forbidden)) {
1163 $rname = '_' . $name;
1166 if (is_int($value)) {
1167 $this->$rname = new Transaction($this->zdb
, $this->login
, $value);
1170 'Trying to set a transaction from an id that is not an integer.',
1176 if (is_int($value)) {
1178 $this->$rname = new ContributionsTypes($this->zdb
, $value);
1179 //set is_cotis according to type
1180 if ($this->$rname->extension
== 1) {
1181 $this->_is_cotis
= true;
1183 $this->_is_cotis
= false;
1187 'Trying to set a type from an id that is not an integer.',
1194 $d = \DateTime
::createFromFormat(__("Y-m-d"), $value);
1196 throw new \
Exception('Incorrect format');
1198 $this->_begin_date
= $d->format('Y-m-d');
1199 } catch (\Exception
$e) {
1201 'Wrong date format. field: ' . $key .
1202 ', value: ' . $value . ', expected fmt: ' .
1203 __("Y-m-d") . ' | ' . $e->getMessage(),
1206 $errors[] = str_replace(
1213 $this->_fields
[$key]['label']
1215 _T("- Wrong date format (%date_format) for %field!")
1220 if (is_numeric($value) && $value > 0) {
1221 $this->$rname = $value;
1224 'Trying to set an amount with a non numeric value, ' .
1225 'or with a zero value',
1231 if (is_int($value)) {
1233 $this->$rname = $value;
1238 '[' . __CLASS__
. ']: Trying to set an unknown property (' .