require_once 'includes/dynamic_fields.inc.php';
-$contrib = new Contribution();
+$contrib = new Galette\Entity\Contribution();
$id_cotis = get_numeric_form_value('id_cotis', '');
$type_selected = false;
} else if ( $id_cotis != '' || $type_selected || $trans_id || $id_adh) {
if ( $id_cotis != '' ) {
- $contrib = new Contribution((int)$id_cotis);
+ $contrib = new Galette\Entity\Contribution((int)$id_cotis);
if ( $contrib->id == '' ) {
//not possible to load contribution, exit
header('location: index.php');
if ( $preferences->pref_membership_ext != '' ) {
$args['ext'] = $preferences->pref_membership_ext;
}
- $contrib = new Contribution($args);
+ $contrib = new Galette\Entity\Contribution($args);
if ( $contrib->isTransactionPart() ) {
$id_adh = $contrib->member;
//Should we disable contribution member selection if we're from
require_once 'classes/transaction.class.php';
require_once 'includes/dynamic_fields.inc.php';
-require_once 'classes/contributions.class.php';
$trans = new Transaction();
$disabled = array();
if ( isset($_GET['detach']) ) {
- if ( !Contribution::unsetTransactionPart($trans_id, $_GET['detach']) ) {
+ if ( !Galette\Entity\Contribution::unsetTransactionPart($trans_id, $_GET['detach']) ) {
$error_detected[] = _T("Unable to detach contribution from transaction");
} else {
$success_detected[] = _T("Contribution has been successfyully detached from current transaction");
}
if ( isset($_GET['cid']) && $_GET['cid'] != null ) {
- if ( !Contribution::setTransactionPart($trans_id, $_GET['cid']) ) {
+ if ( !Galette\Entity\Contribution::setTransactionPart($trans_id, $_GET['cid']) ) {
$error_detected[] = _T("Unable to attach contribution to transaction");
} else {
$success_detected[] = _T("Contribution has been successfyully attached to current transaction");
$tpl->assign('require_calendar', true);
if ( $trans->id != '' ) {
- $contribs = new Contributions();
+ $contribs = new Galette\Repository\Contributions();
$tpl->assign('contribs', $contribs->getListFromTransaction($trans->id));
}
+++ /dev/null
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Contribution class for galette
- *
- * PHP version 5
- *
- * Copyright © 2010-2012 The Galette Team
- *
- * This file is part of Galette (http://galette.tuxfamily.org).
- *
- * Galette is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Galette is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Galette. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Classes
- * @package Galette
- *
- * @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010-2012 The Galette Team
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @version SVN: $Id$
- * @link http://galette.tuxfamily.org
- * @since Available since 0.7dev - 2010-03-11
- */
-
-use Galette\Entity\ContributionsTypes as ContributionsTypes;
-
-/** @ignore */
-require_once 'transaction.class.php';
-
-/**
- * Contribution class for galette
- *
- * @category Classes
- * @name Contribution
- * @package Galette
- * @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010 The Galette Team
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @link http://galette.tuxfamily.org
- * @since Available since 0.7dev - 2010-03-11
- */
-class Contribution
-{
- const TABLE = 'cotisations';
- const PK = 'id_cotis';
-
- const PAYMENT_OTHER = 0;
- const PAYMENT_CASH = 1;
- const PAYMENT_CREDITCARD = 2;
- const PAYMENT_CHECK = 3;
- const PAYMENT_TRANSFER = 4;
- const PAYMENT_PAYPAL = 5;
-
- private $_id;
- private $_date;
- private $_member;
- private $_type;
- private $_amount;
- private $_payment_type;
- private $_orig_amount;
- private $_info;
- private $_begin_date;
- private $_end_date;
- private $_transaction = null;
- private $_is_cotis;
- private $_extension;
-
- //fields list and their translation
- private $_fields;
-
- /**
- * Default constructor
- *
- * @param null|int|ResultSet $args Either a ResultSet row to load
- * a specific contribution, or an type id
- * to just instanciate object
- */
- public function __construct($args = null)
- {
- /*
- * Fields configuration. Each field is an array and must reflect:
- * array(
- * (string)label,
- * (string) propname
- * )
- *
- * I'd prefer a static private variable for this...
- * But call to the _T function does not seems to be allowed there :/
- */
- $this->_fields = array(
- 'id_cotis' => array(
- 'label' => null, //not a field in the form
- 'propname' => 'id'
- ),
- Galette\Entity\Adherent::PK => array(
- 'label' => _T("Contributor:"),
- 'propname' => 'member'
- ),
- ContributionsTypes::PK => array(
- 'label' => _T("Contribution type:"),
- 'propname' => 'type'
- ),
- 'montant_cotis' => array(
- 'label' => _T("Amount:"),
- 'propname' => 'amount'
- ),
- 'type_paiement_cotis' => array(
- 'label' => _T("Payment type:"),
- 'propname' => 'payment_type'
- ),
- 'info_cotis' => array(
- 'label' => _T("Comments:"),
- 'propname' => 'info'
- ),
- 'date_enreg' => array(
- 'label' => null, //not a field in the form
- 'propname' => 'date'
- ),
- 'date_debut_cotis' => array(
- 'label' => _T("Date of contribution:"),
- 'cotlabel' => _T("Start date of membership:"), //if contribution is a cotisation, label differs
- 'propname' => 'begin_date'
- ),
- 'date_fin_cotis' => array(
- 'label' => _T("End date of membership:"),
- 'propname' => 'end_date'
- ),
- Transaction::PK => array(
- 'label' => null, //not a field in the form
- 'propname' => 'transaction'
- ),
- //this one is not really a field, but is required in some cases...
- //adding it here make simplier to check required fields
- 'duree_mois_cotis' => array(
- 'label' => _T("Membership extension:"),
- 'propname' => 'extension'
- )
- );
- if ( is_int($args) ) {
- $this->load($args);
- } else if ( is_array($args) ) {
- $this->_date = date("Y-m-d");
- if ( isset($args['adh']) && $args['adh'] != '' ) {
- $this->_member = (int)$args['adh'];
- }
- $this->_type = new ContributionsTypes((int)$args['type']);
- $this->_is_cotis = (bool)$this->_type->extension;
- //calculate begin date for cotisation
- $this->_begin_date = $this->_date;
- if ( $this->_is_cotis ) {
- $curend = self::getDueDate($args['adh']);
- if ($curend != '') {
- $dend = new DateTime($curend);
- $now = date('Y-m-d');
- $dnow = new DateTime($now);
- if ( $dend < $dnow ) {
- // Member didn't renew on time
- $this->_begin_date = $now;
- } else {
- $this->_begin_date = $curend;
- }
- }
- if ( isset($args['ext']) ) {
- $this->_extension = $args['ext'];
- }
- $this->_retrieveEndDate();
- }
- if ( isset($args['trans']) ) {
- $this->_transaction = new Transaction((int)$args['trans']);
- if ( !isset($this->_member) ) {
- $this->_member = (int)$this->_transaction->member;
- }
- $this->_amount = $this->_transaction->getMissingAmount();
- }
- } elseif ( is_object($args) ) {
- $this->_loadFromRS($args);
- }
- }
-
- /**
- * Sets end contribution date
- *
- * @return void
- */
- private function _retrieveEndDate()
- {
- global $preferences;
-
- $bdate = new DateTime($this->_begin_date);
- if ( $preferences->pref_beg_membership != '' ) {
- //case beginning of membership
- list($j, $m) = explode('/', $preferences->pref_beg_membership);
- $edate = new DateTime($bdate->format('Y') . '-' . $m . '-' . $j);
- while ( $edate <= $bdate ) {
- $edate->modify('+1 year');
- }
- $this->_end_date = $edate->format('Y-m-d');
- } else if ( $preferences->pref_membership_ext != '' ) {
- //case membership extension
- $dext = new DateInterval('P' . $this->_extension . 'M');
- $edate = $bdate->add($dext);
- $this->_end_date = $edate->format('Y-m-d');
- }
- }
-
- /**
- * Loads a contribution from its id
- *
- * @param int $id the identifiant for the contribution to load
- *
- * @return bool true if query succeed, false otherwise
- */
- public function load($id)
- {
- global $zdb, $log, $login;
-
- try {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' = ?', $id);
- //restrict query on current member id if he's not admin nor staff member
- if ( !$login->isAdmin() && !$login->isStaff() ) {
- $select->where(Galette\Entity\Adherent::PK . ' = ?', $login->id);
- }
- $row = $select->query()->fetch();
- if ( $row !== false ) {
- $this->_loadFromRS($row);
- return true;
- } else {
- throw new Exception(
- 'No contribution #' . $id . ' (user ' .$login->id . ')'
- );
- }
- } catch (Exception $e) {
- /** FIXME */
- $log->log(
- 'An error occured attempting to load contribution #' . $id .
- $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Populate object from a resultset row
- *
- * @param ResultSet $r the resultset row
- *
- * @return void
- */
- private function _loadFromRS($r)
- {
- $pk = self::PK;
- $this->_id = $r->$pk;
- $this->_date = $r->date_enreg;
- $this->_amount = $r->montant_cotis;
- //save original amount, we need it for transactions parts calulations
- $this->_orig_amount = $r->montant_cotis;
- $this->_payment_type = $r->type_paiement_cotis;
- $this->_info = $r->info_cotis;
- $this->_begin_date = $r->date_debut_cotis;
- $enddate = $r->date_fin_cotis;
- //do not work with knows bad dates...
- //the one with BC comes from 0.63/pgsl demo... Why the hell a so
- //strange date? dont know :(
- if ( $enddate !== '0000-00-00'
- && $enddate !== '1901-01-01'
- && $enddate !== '0001-01-01 BC'
- ) {
- $this->_end_date = $r->date_fin_cotis;
- }
- $adhpk = Galette\Entity\Adherent::PK;
- $this->_member = (int)$r->$adhpk;
-
- $transpk = Transaction::PK;
- if ( $r->$transpk != '' ) {
- $this->_transaction = new Transaction((int)$r->$transpk);
- }
-
- $this->_type = new ContributionsTypes((int)$r->id_type_cotis);
- if ( $this->_type->extension == 1 ) {
- $this->_is_cotis = true;
- } else {
- $this->_is_cotis = false;
- }
- }
-
- /**
- * Check posted values validity
- *
- * @param array $values All values to check, basically the $_POST array
- * after sending the form
- * @param array $required Array of required fields
- * @param array $disabled Array of disabled fields
- *
- * @return true|array
- */
- public function check($values, $required, $disabled)
- {
- global $zdb, $log;
- $errors = array();
-
- $fields = array_keys($this->_fields);
- foreach ( $fields as $key ) {
- //first of all, let's sanitize values
- $key = strtolower($key);
- $prop = '_' . $this->_fields[$key]['propname'];
-
- if ( isset($values[$key]) ) {
- $value = trim($values[$key]);
- } else {
- $value = '';
- }
-
- // if the field is enabled, check it
- if ( !isset($disabled[$key]) ) {
- // fill up the adherent structure
- //$this->$prop = stripslashes($value); //not relevant here!
-
- // now, check validity
- if ( $value != '' ) {
- switch ( $key ) {
- // dates
- case 'date_enreg':
- case 'date_debut_cotis':
- case 'date_fin_cotis':
- /** FIXME: only ok dates dd/mm/yyyy */
- if ( !preg_match(
- '@^([0-9]{2})/([0-9]{2})/([0-9]{4})$@',
- $value,
- $date
- ) ) {
- $errors[] = _T("- Wrong date format (dd/mm/yyyy)!");
- } else {
- if ( !checkdate($date[2], $date[1], $date[3]) ) {
- $errors[] = _T("- Non valid date!");
- } else {
- $this->$prop = $date[3] . '-' . $date[2] . '-' .
- $date[1];
- }
- }
- break;
- case Galette\Entity\Adherent::PK:
- $this->_member = $value;
- break;
- case ContributionsTypes::PK:
- $this->_type = new ContributionsTypes((int)$value);
- break;
- case 'montant_cotis':
- $this->_amount = $value;
- $us_value = strtr($value, ',', '.');
- if ( !is_numeric($value) ) {
- $errors[] = _T("- The amount must be an integer!");
- }
- break;
- case 'type_paiement_cotis':
- if ( $value == self::PAYMENT_OTHER
- || $value == self::PAYMENT_CASH
- || $value == self::PAYMENT_CREDITCARD
- || $value == self::PAYMENT_CHECK
- || $value == self::PAYMENT_TRANSFER
- || $value == self::PAYMENT_PAYPAL
- ) {
- $this->_payment_type = $value;
- } else {
- $errors[] = _T("- Unknown payment type");
- }
- break;
- case 'info_cotis':
- $this->_info = $value;
- break;
- case Transaction::PK:
- $this->_transaction = new Transaction((int)$value);
- break;
- case 'duree_mois_cotis':
- if ( !is_numeric($value) || $value<=0 ) {
- $errors[] = _T("- The duration must be a positive integer!");
- }
- $this->$prop = $value;
- $this->_retrieveEndDate();
- break;
- }
- }
- }
- }
-
- // missing required fields?
- while ( list($key, $val) = each($required) ) {
- if ( $val === 1) {
- $prop = '_' . $this->_fields[$key]['propname'];
- if ( !isset($disabled[$key])
- && (!isset($this->$prop)
- || (!is_object($this->$prop) && trim($this->$prop) == '')
- || (is_object($this->$prop) && trim($this->$prop->id) == ''))
- ) {
- $errors[] = _T("- Mandatory field empty: ") .
- ' <a href="#' . $key . '">' . $this->getFieldName($key) .'</a>';
- }
- }
- }
-
- if ( $this->_transaction != null && $this->_amount != null) {
- $missing = $this->_transaction->getMissingAmount();
- //calculate new missing amount
- $missing = $missing + $this->_orig_amount - $this->_amount;
- if ( $missing < 0 ) {
- $errors[] = _T("- Sum of all contributions exceed corresponding transaction amount.");
- }
- }
-
- if ( count($errors) > 0 ) {
- $log->log(
- 'Some errors has been throwed attempting to edit/store a contribution' .
- print_r($errors, true),
- PEAR_LOG_DEBUG
- );
- return $errors;
- } else {
- $log->log(
- 'Contribution checked successfully.',
- PEAR_LOG_DEBUG
- );
- return true;
- }
- }
-
- /**
- * Check that membership fees does not overlap
- *
- * @return boolean|string True if all is ok, false if error,
- * error message if overlap
- */
- public function checkOverlap()
- {
- global $zdb, $log;
-
- try {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- array('c' => PREFIX_DB . self::TABLE),
- array('date_debut_cotis', 'date_fin_cotis')
- )->join(
- array('ct' => PREFIX_DB . ContributionsTypes::TABLE),
- 'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
- array()
- )->where(Galette\Entity\Adherent::PK . ' = ?', $this->_member)
- ->where('cotis_extension = ?', (string)1)
- ->where(
- '((' . $zdb->db->quoteInto('date_debut_cotis >= ?', $this->_begin_date) .
- ' AND '. $zdb->db->quoteInto('date_debut_cotis < ?', $this->_end_date) .
- ') OR (' . $zdb->db->quoteInto('date_fin_cotis > ?', $this->_begin_date) .
- ' AND ' . $zdb->db->quoteInto('date_fin_cotis <= ?', $this->_end_date) . '))'
- );
-
- if ( $this->id != '' ) {
- $select->where(self::PK . ' != ?', $this->id);
- }
-
- $result = $select->query()->fetch();
- if ( $result !== false ) {
- $d = new DateTime($result->date_debut_cotis);
-
- return _T("- Membership period overlaps period starting at ") .
- $d->format(_T("Y-m-d"));
- }
- return true;
- } catch (Exception $e) {
- /** FIXME */
- $log->log(
- 'An error occured checking overlaping fee. ' . $e->getMessage(),
- PEAR_LOG_ERR
- );
- $log->log(
- 'Query was: ' . $select->__toString(),
- PEAR_LOG_DEBUG
- );
- return false;
- }
- }
-
- /**
- * Store the contribution
- *
- * @return boolean
- */
- public function store()
- {
- global $zdb, $log, $hist;
-
- try {
- $zdb->db->beginTransaction();
- $values = array();
- $fields = self::getDbFields();
- /** FIXME: quote? */
- foreach ( $fields as $field ) {
- $prop = '_' . $this->_fields[$field]['propname'];
- switch ( $field ) {
- case Galette\Entity\ContributionsTypes::PK:
- case Transaction::PK:
- $values[$field] = $this->$prop->id;
- break;
- default:
- $values[$field] = $this->$prop;
- break;
- }
- }
-
- //no end date,, let's take database defaults
- if ( !$this->isCotis() && !$this->_end_date ) {
- unset($values['date_fin_cotis']);
- }
-
- if ( !isset($this->_id) || $this->_id == '') {
- //we're inserting a new contribution
- unset($values[self::PK]);
- $add = $zdb->db->insert(PREFIX_DB . self::TABLE, $values);
- if ( $add > 0) {
- $this->_id = $zdb->db->lastInsertId(
- PREFIX_DB . self::TABLE,
- 'id'
- );
- // logging
- $hist->add(
- _T("Contribution added"),
- Galette\Entity\Adherent::getSName($this->_member)
- );
- } else {
- $hist->add(_T("Fail to add new contribution."));
- throw new Exception(
- 'An error occured inserting new contribution!'
- );
- }
- } else {
- //we're editing an existing contribution
- $edit = $zdb->db->update(
- PREFIX_DB . self::TABLE,
- $values,
- self::PK . '=' . $this->_id
- );
- //edit == 0 does not mean there were an error, but that there
- //were nothing to change
- if ( $edit > 0 ) {
- $hist->add(
- _T("Contribution updated"),
- Galette\Entity\Adherent::getSName($this->_member)
- );
- } else if ($edit === false) {
- throw new Exception(
- 'An error occured updating contribution # ' . $this->_id . '!'
- );
- }
- }
- //update deadline
- if ( $this->isCotis() ) {
- $deadline = $this->_updateDeadline();
- if ( $deadline !== true ) {
- //if something went wrong, we rollback transaction
- throw new Exception('An error occured updating member\'s deadline');
- }
- }
- $zdb->db->commit();
- $this->_orig_amount = $this->_amount;
- return true;
- } catch (Exception $e) {
- /** FIXME */
- $zdb->db->rollBack();
- $log->log(
- 'Something went wrong :\'( | ' . $e->getMessage() . "\n" .
- $e->getTraceAsString(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Update member dead line
- *
- * @return boolean
- */
- private function _updateDeadline()
- {
- global $zdb, $log;
-
- try {
- $due_date = self::getDueDate($this->_member);
-
- if ( $due_date != '' ) {
- $date_fin_update = $due_date;
- } else {
- $date_fin_update = 'NULL';
- }
-
- $edit = $zdb->db->update(
- PREFIX_DB . Galette\Entity\Adherent::TABLE,
- array('date_echeance' => $date_fin_update),
- Galette\Entity\Adherent::PK . '=' . $this->_member
- );
- return true;
- } catch (Exception $e) {
- $log->log(
- 'An error occured updating member ' . $this->_member .
- '\'s deadline |' .
- $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Remove contribution from database
- *
- * @param boolean $transaction Activate transaction mode (defaults to true)
- *
- * @return boolean
- */
- public function remove($transaction = true)
- {
- global $zdb, $log;
-
- try {
- if ( $transaction ) {
- $zdb->db->beginTransaction();
- }
- $del = $zdb->db->delete(
- PREFIX_DB . self::TABLE,
- self::PK . ' = ' . $this->_id
- );
- if ( $del > 0 ) {
- $this->_updateDeadline();
- }
- if ( $transaction ) {
- $zdb->db->commit();
- }
- return true;
- } catch (Exception $e) {
- /** FIXME */
- if ( $transaction ) {
- $zdb->db->rollBack();
- }
- $log->log(
- 'An error occured trying to remove contribution #' .
- $this->_id . ' | ' . $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Get field label
- *
- * @param string $field Field name
- *
- * @return string
- */
- public function getFieldName($field)
- {
- $label = $this->_fields[$field]['label'];
- if ( $this->isCotis() && $field == 'date_debut_cotis') {
- $label = $this->_fields[$field]['cotlabel'];
- }
- //remove trailing ':' and then nbsp (for french at least)
- $label = trim(trim($label, ':'), ' ');
- return $label;
- }
-
- /**
- * Retrieve fields from database
- *
- * @return array
- */
- public static function getDbFields()
- {
- global $zdb;
- return array_keys($zdb->db->describeTable(PREFIX_DB . self::TABLE));
- }
-
- /**
- * Get the relevant CSS class for current contribution
- *
- * @return string current contribution row class
- */
- public function getRowClass()
- {
- return ( $this->_end_date != $this->_begin_date && $this->_is_cotis) ?
- 'cotis-normal' :
- 'cotis-give';
- }
-
- /**
- * Retrieve member due date
- *
- * @param integer $member_id Member identifier
- *
- * @return date
- */
- public static function getDueDate($member_id)
- {
- global $zdb, $log;
-
- try {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . self::TABLE,
- 'MAX(date_fin_cotis)'
- )->where(Galette\Entity\Adherent::PK . ' = ?', $member_id);
- $due_date = $select->query()->fetchColumn();
- return $due_date;
- } catch (Exception $e) {
- /** FIXME */
- $log->log(
- 'An error occured trying to retrieve member\'s due date',
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Detach a contribution from a transaction
- *
- * @param int $trans_id Transaction identifier
- * @param int $contrib_id Contribution identifier
- *
- * @return boolean
- */
- public static function unsetTransactionPart($trans_id, $contrib_id)
- {
- global $zdb, $log;
-
- try {
- //first, we check if contribution is part of transaction
- $c = new Contribution((int)$contrib_id);
- if ( $c->isTransactionPartOf($trans_id)) {
- $zdb->db->update(
- PREFIX_DB . self::TABLE,
- array(Transaction::PK => null),
- self::PK . ' = ' . $contrib_id
- );
- return true;
- } else {
- $log->log(
- 'Contribution #' . $contrib_id .
- ' is not actually part of transaction #' . $trans_id,
- PEAR_LOG_WARNING
- );
- return false;
- }
- } catch (Exception $e) {
- $log->log(
- 'Unable to detach contribution #' . $contrib_id .
- ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Set a contribution as a transaction part
- *
- * @param int $trans_id Transaction identifier
- * @param int $contrib_id Contribution identifier
- *
- * @return boolean
- */
- public static function setTransactionPart($trans_id, $contrib_id)
- {
- global $zdb, $log;
-
- try {
- $zdb->db->update(
- PREFIX_DB . self::TABLE,
- array(Transaction::PK => $trans_id),
- self::PK . ' = ' . $contrib_id
- );
- return true;
- } catch (Exception $e) {
- $log->log(
- 'Unable to attach contribution #' . $contrib_id .
- ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Is current contribution a cotisation
- *
- * @return boolean
- */
- public function isCotis()
- {
- return $this->_is_cotis;
- }
-
- /**
- * Is current contribution part of specified transaction
- *
- * @param int $id Transaction identifier
- *
- * @return boolean
- */
- public function isTransactionPartOf($id)
- {
- if ( $this->isTransactionPart() ) {
- return $id == $this->_transaction->id;
- } else {
- return false;
- }
- }
-
- /**
- * Is current contribution part of transaction
- *
- * @return boolean
- */
- public function isTransactionPart()
- {
- return $this->_transaction != null;
- }
-
- /**
- * Global getter method
- *
- * @param string $name name of the property we want to retrive
- *
- * @return false|object the called property
- */
- public function __get($name)
- {
- global $log;
-
- $forbidden = array('is_cotis');
- $virtuals = array('duration', 'spayment_type');
-
- $rname = '_' . $name;
- if ( !in_array($name, $forbidden)
- && isset($this->$rname)
- || in_array($name, $virtuals)
- ) {
- switch($name) {
- case 'date':
- case 'begin_date':
- case 'end_date':
- if ( $this->$rname != '' ) {
- try {
- $d = new DateTime($this->$rname);
- return $d->format(_T("Y-m-d"));
- } catch (Exception $e) {
- //oops, we've got a bad date :/
- $log->log(
- 'Bad date (' . $his->$rname . ') | ' .
- $e->getMessage(),
- PER_LOG_INFO
- );
- return $this->$rname;
- }
- }
- break;
- case 'duration':
- if ( $this->_is_cotis ) {
- $date_end = new DateTime($this->_end_date);
- $date_start = new DateTime($this->_begin_date);
- $diff = $date_end->diff($date_start);
- return $diff->format('%y') * 12 + $diff->format('%m');
- } else {
- return '';
- }
- break;
- case 'spayment_type':
- switch ( $this->_payment_type ) {
- case self::PAYMENT_OTHER:
- return _T("Other");
- break;
- case self::PAYMENT_CASH:
- return _T("Cash");
- break;
- case self::PAYMENT_CREDITCARD:
- return _T("Credit card");
- break;
- case self::PAYMENT_CHECK:
- return _T("Check");
- break;
- case self::PAYMENT_TRANSFER:
- return _T("Transfer");
- break;
- case self::PAYMENT_PAYPAL:
- return _T("Paypal");
- break;
- default:
- $log->log(
- 'Unknown payment type ' . $this->_payment_type,
- PEAR_LOG_WARNING
- );
- return '-';
- break;
- }
- default:
- return $this->$rname;
- break;
- }
- } else {
- return false;
- }
- }
-
- /**
- * Global setter method
- *
- * @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
- *
- * @return void
- */
- public function __set($name, $value)
- {
- global $log;
- $forbidden = array('fields', 'is_cotis', 'end_date');
-
- if ( !in_array($name, $forbidden) ) {
- $rname = '_' . $name;
- switch($name) {
- case 'transaction':
- if ( is_int($value) ) {
- $this->$rname = new Transaction($value);
- } else {
- $log->log(
- 'Trying to set a transaction from an id that is not an integer.',
- PEAR_LOG_WARNING
- );
- }
- break;
- case 'type':
- if ( is_int($value) ) {
- //set type
- $this->$rname = new Galette\Entity\ContributionsTypes($value);
- //set is_cotis according to type
- if ( $this->$rname->extension == 1 ) {
- $this->_is_cotis = true;
- } else {
- $this->_is_cotis = false;
- }
- } else {
- $log->log(
- 'Trying to set a type from an id that is not an integer.',
- PEAR_LOG_WARNING
- );
- }
- break;
- case 'begin_date':
- /** FIXME: only ok dates dd/mm/yyyy */
- if ( !preg_match(
- '@^([0-9]{2})/([0-9]{2})/([0-9]{4})$@',
- $value,
- $date
- ) ) {
- $errors[] = _T("- Wrong date format (dd/mm/yyyy)!");
- } else {
- if ( !checkdate($date[2], $date[1], $date[3]) ) {
- $errors[] = _T("- Non valid date!");
- } else {
- $this->_begin_date = $date[3] . '-' . $date[2] . '-' .
- $date[1];
- }
- }
- break;
- case 'amount':
- if (is_numeric($value) && $value > 0 ) {
- $this->$rname = $value;
- } else {
- $log->log(
- 'Trying to set an amount with a non numeric value, ' .
- 'or with a zero value',
- PEAR_LOG_WARNING
- );
- }
- break;
- default:
- $log->log(
- '[' . __CLASS__ . ']: Trying to set an unknown property (' .
- $name . ')',
- PEAR_LOG_WARNING
- );
- break;
- }
- }
-
- }
-}
-?>
+++ /dev/null
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Contributions class
- *
- * PHP version 5
- *
- * Copyright © 2010-2012 The Galette Team
- *
- * This file is part of Galette (http://galette.tuxfamily.org).
- *
- * Galette is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Galette is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Galette. If not, see <http://www.gnu.org/licenses/>.
- *
- * @category Classes
- * @package Galette
- *
- * @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2010-2012 The Galette Team
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @version SVN: $Id$
- * @link http://galette.tuxfamily.org
- * @since Available since 0.7dev - 2010-03-11
- */
-
-/** @ignore */
-require_once 'contribution.class.php';
-
-/**
- * Contributions class for galette
- *
- * @name Contributions
- * @category Classes
- * @package Galette
- *
- * @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2009-2012 The Galette Team
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @link http://galette.tuxfamily.org
- */
-class Contributions extends Galette\Core\Pagination
-{
- const TABLE = Contribution::TABLE;
- const PK = Contribution::PK;
-
- const FILTER_DATE_BEGIN = 0;
- const FILTER_DATE_END = 1;
-
- const ORDERBY_DATE = 0;
- const ORDERBY_BEGIN_DATE = 1;
- const ORDERBY_END_DATE = 2;
- const ORDERBY_MEMBER = 3;
- const ORDERBY_TYPE = 4;
- const ORDERBY_AMOUNT = 5;
- const ORDERBY_DURATION = 6;
- const ORDERBY_PAYMENT_TYPE = 7;
-
- private $_count = null;
- private $_start_date_filter = null;
- private $_end_date_filter = null;
- private $_payment_type_filter = null;
- private $_filtre_cotis_adh = null;
- private $_filtre_transactions = null;
-
- private $_from_transaction = false;
- private $_max_amount = null;
- private $_sum;
-
- /**
- * Default constructor
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Returns the field we want to default set order to
- *
- * @return string field name
- */
- protected function getDefaultOrder()
- {
- return 'date_debut_cotis';
- }
-
- /**
- * Returns the field we want to default set order to (public method)
- *
- * @return string field name
- */
- public static function defaultOrder()
- {
- return self::getDefaultOrder();
- }
-
- /**
- * Get contributions list for a specific transaction
- *
- * @param int $trans_id Transaction identifier
- *
- * @return Contribution[]
- */
- public function getListFromTransaction($trans_id)
- {
- $this->_from_transaction = $trans_id;
- return $this->getContributionsList(true);
- }
-
- /**
- * Get contributions list
- *
- * @param bool $as_contrib return the results as an array of
- * Contribution object.
- * @param array $fields field(s) name(s) to get. Should be a string or
- * an array. If null, all fields will be
- * returned
- * @param boolean $count true if we want to count members
- *
- * @return Contribution[]|ResultSet
- */
- public function getContributionsList(
- $as_contrib=false, $fields=null, $count=true
- ) {
- global $zdb, $log;
-
- try {
- $select = $this->_buildSelect(
- $fields, $count
- );
-
- $this->setLimits($select);
-
- $contributions = array();
- if ( $as_contrib ) {
- foreach ( $select->query()->fetchAll() as $row ) {
- $contributions[] = new Contribution($row);
- }
- } else {
- $contributions = $select->query()->fetchAll();
- }
- return $contributions;
- } catch (Exception $e) {
- /** TODO */
- $log->log(
- 'Cannot list contributions | ' . $e->getMessage(),
- PEAR_LOG_WARNING
- );
- $log->log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Builds the SELECT statement
- *
- * @param array $fields fields list to retrieve
- * @param bool $count true if we want to count members
- (not applicable from static calls), defaults to false
- *
- * @return string SELECT statement
- */
- private function _buildSelect($fields, $count = false)
- {
- global $zdb;
-
- try {
- $fieldsList = ( $fields != null )
- ? (( !is_array($fields) || count($fields) < 1 ) ? (array)'*'
- : implode(', ', $fields)) : (array)'*';
-
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- array('a' => PREFIX_DB . self::TABLE),
- $fieldsList
- );
-
- $select->join(
- array('p' => PREFIX_DB . Galette\Entity\Adherent::TABLE, Galette\Entity\Adherent::PK),
- 'a.' . Galette\Entity\Adherent::PK . '=' . 'p.' . Galette\Entity\Adherent::PK
- );
-
- $this->_buildWhereClause($select);
- $select->order(self::_buildOrderClause());
-
- $this->_calculateSum($select);
-
- if ( $count ) {
- $this->_proceedCount($select);
- }
-
- return $select;
- } catch (Exception $e) {
- /** TODO */
- $log->log(
- 'Cannot build SELECT clause for contributions | ' . $e->getMessage(),
- PEAR_LOG_WARNING
- );
- $log->log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Count contributions from the query
- *
- * @param Zend_Db_Select $select Original select
- *
- * @return void
- */
- private function _proceedCount($select)
- {
- global $zdb, $log;
-
- try {
- $countSelect = clone $select;
- $countSelect->reset(Zend_Db_Select::COLUMNS);
- $countSelect->reset(Zend_Db_Select::ORDER);
- $countSelect->columns('count(' . self::PK . ') AS ' . self::PK);
-
- $result = $countSelect->query()->fetch();
-
- $k = self::PK;
- $this->_count = $result->$k;
- if ( $this->_count > 0 ) {
- $this->counter = (int)$this->_count;
- $this->countPages();
- }
- } catch (Exception $e) {
- /** TODO */
- $log->log(
- 'Cannot count contributions | ' . $e->getMessage(),
- PEAR_LOG_WARNING
- );
- $log->log(
- 'Query was: ' . $countSelect->__toString() . ' ' . $e->__toString(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Calculate sum of all selected contributions
- *
- * @param Zend_Db_Select $select Original select
- *
- * @return void
- */
- private function _calculateSum($select)
- {
- global $zdb, $log;
-
- try {
- $sumSelect = clone $select;
- $sumSelect->reset(Zend_Db_Select::COLUMNS);
- $sumSelect->reset(Zend_Db_Select::ORDER);
- $sumSelect->columns('SUM(montant_cotis) AS contribsum');
-
- $result = $sumSelect->query()->fetch();
-
- $this->_sum = round($result->contribsum, 2);
- } catch (Exception $e) {
- /** TODO */
- $log->log(
- 'Cannot calculate contributions sum | ' . $e->getMessage(),
- PEAR_LOG_WARNING
- );
- $log->log(
- 'Query was: ' . $sumSelect->__toString() . ' ' . $e->__toString(),
- PEAR_LOG_ERR
- );
- return false;
- }
- }
-
- /**
- * Builds the order clause
- *
- * @return string SQL ORDER clause
- */
- private function _buildOrderClause()
- {
- $order = array();
-
- switch ( $this->orderby ) {
- case self::ORDERBY_DATE:
- $order[] = 'date_enreg' . ' ' . $this->ordered;
- break;
- case self::ORDERBY_BEGIN_DATE:
- $order[] = 'date_debut_cotis' . ' ' . $this->ordered;
- break;
- case self::ORDERBY_END_DATE:
- $order[] = 'date_fin_cotis' . ' ' . $this->ordered;
- break;
- case self::ORDERBY_MEMBER:
- $order[] = 'nom_adh' . ' ' . $this->ordered;
- $order[] = 'prenom_adh' . ' ' . $this->ordered;
- break;
- case self::ORDERBY_TYPE:
- $order[] = ContributionsTypes::PK;
- break;
- case self::ORDERBY_AMOUNT:
- $order[] = 'montant_cotis' . ' ' . $this->ordered;
- break;
- /*
- Hum... I really do not know how to sort a query with a value that
- is calculated code side :/
- case self::ORDERBY_DURATION:
- break;*/
- default:
- $order[] = $this->orderby . ' ' . $this->ordered;
- break;
- }
-
- return $order;
- }
-
- /**
- * Builds where clause, for filtering on simple list mode
- *
- * @param Zend_Db_Select $select Original select
- *
- * @return string SQL WHERE clause
- */
- private function _buildWhereClause($select)
- {
- global $zdb, $log, $login;
-
- try {
- if ( $this->_start_date_filter != null ) {
- /** TODO: initial date format should be i18n
- $d = DateTime::createFromFormat(
- _T("d/m/Y"),
- $this->_start_date_filter
- );*/
- $d = DateTime::createFromFormat(
- 'd/m/Y',
- $this->_start_date_filter
- );
- $select->where('date_debut_cotis >= ?', $d->format('Y-m-d'));
- }
-
- if ( $this->_end_date_filter != null ) {
- /** TODO: initial date format should be i18n
- $d = DateTime::createFromFormat(
- _T("d/m/Y"),
- $this->_end_date_filter
- );*/
- $d = DateTime::createFromFormat(
- 'd/m/Y',
- $this->_end_date_filter
- );
- $select->where('date_debut_cotis <= ?', $d->format('Y-m-d'));
- }
-
- if ( $this->_payment_type_filter != null ) {
- $select->where('type_paiement_cotis = ?', $this->_payment_type_filter);
- }
-
- if ( $this->_from_transaction !== false ) {
- $select->where(
- Transaction::PK . ' = ?',
- $this->_from_transaction
- );
- }
-
- if ( $this->_max_amount !== null && is_int($this->_max_amount)) {
- $select->where(
- '(montant_cotis <= ' . $this->_max_amount .
- ' OR montant_cotis IS NULL)'
- );
- }
- $sql = $select->__toString();
-
- if ( !$login->isAdmin() && !$login->isStaff() ) {
- //non staff members can only view their own contributions
- $select->where('p.' . Galette\Entity\Adherent::PK . ' = ?', $login->id);
- } else if ( $this->_filtre_cotis_adh != null ) {
- $select->where('p.' . Galette\Entity\Adherent::PK . ' = ?', $this->_filtre_cotis_adh);
- }
- if ( $this->_filtre_transactions === true ) {
- $select->where('a.trans_id ?', new Zend_Db_Expr('IS NULL'));
- }
- $qry = $select->__toString();
- } catch (Exception $e) {
- /** TODO */
- $log->log(
- __METHOD__ . ' | ' . $e->getMessage(),
- PEAR_LOG_WARNING
- );
- }
- }
-
- /**
- * Get count for current query
- *
- * @return int
- */
- public function getCount()
- {
- return $this->_count;
- }
-
- /**
- * Reinit default parameters
- *
- * @return void
- */
- public function reinit()
- {
- parent::reinit();
- $this->_start_date_filter = null;
- $this->_end_date_filter = null;
- $this->_payment_type_filter = null;
- }
-
- /**
- * Remove specified contributions
- *
- * @param integer|array $ids Contributions identifiers to delete
- * @param boolean $transaction True to begin a database transaction
- *
- * @return boolean
- */
- public function removeContributions($ids, $transaction = true)
- {
- global $zdb, $log, $hist;
-
- $list = array();
- if ( is_numeric($ids) ) {
- //we've got only one identifier
- $list[] = $ids;
- } else {
- $list = $ids;
- }
-
- if ( is_array($list) ) {
- $res = true;
- try {
- if ( $transaction ) {
- $zdb->db->beginTransaction();
- }
- $select = new Zend_Db_Select($zdb->db);
- $select->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' IN (?)', $list);
- $contributions = $select->query()->fetchAll();
- foreach ( $contributions as $contribution ) {
- $c = new Contribution($contribution);
- $res = $c->remove(false);
- if ( $res === false ) {
- throw new Exception;
- }
- }
- if ( $transaction ) {
- $zdb->db->commit();
- }
- $hist->add(
- "Contributions deleted (" . print_r($list, true) . ')'
- );
- } catch (Exception $e) {
- /** FIXME */
- if ( $transaction ) {
- $zdb->db->rollBack();
- }
- $log->log(
- 'An error occured trying to remove contributions | ' .
- $e->getMessage(),
- PEAR_LOG_ERR
- );
- return false;
- }
- } else {
- //not numeric and not an array: incorrect.
- $log->log(
- 'Asking to remove contribution, but without providing an array or a single numeric value.',
- PEAR_LOG_WARNING
- );
- return false;
- }
-
- }
-
- /**
- * Global getter method
- *
- * @param string $name name of the property we want to retrive
- *
- * @return object the called property
- */
- public function __get($name)
- {
- global $log;
-
- $log->log(
- '[Contributions] Getting property `' . $name . '`',
- PEAR_LOG_DEBUG
- );
-
- if ( in_array($name, $this->pagination_fields) ) {
- return parent::__get($name);
- } else {
- $return_ok = array(
- 'filtre_cotis_adh',
- 'start_date_filter',
- 'end_date_filter',
- 'payment_type_filter',
- 'sum',
- 'max_amount'
- );
- if (in_array($name, $return_ok)) {
- $name = '_' . $name;
- return $this->$name;
- } else {
- $log->log(
- '[Contributions] Unable to get proprety `' .$name . '`',
- PEAR_LOG_WARNING
- );
- }
- }
- }
-
- /**
- * Global setter method
- *
- * @param string $name name of the property we want to assign a value to
- * @param object $value a relevant value for the property
- *
- * @return void
- */
- public function __set($name, $value)
- {
- global $log;
- if ( in_array($name, $this->pagination_fields) ) {
- parent::__set($name, $value);
- } else {
- $log->log(
- '[Contributions] Setting property `' . $name . '`',
- PEAR_LOG_DEBUG
- );
-
- $forbidden = array();
- if ( !in_array($name, $forbidden) ) {
- $rname = '_' . $name;
- switch($name) {
- case 'tri':
- $allowed_orders = array(
- self::ORDERBY_DATE,
- self::ORDERBY_BEGIN_DATE,
- self::ORDERBY_END_DATE,
- self::ORDERBY_MEMBER,
- self::ORDERBY_TYPE,
- self::ORDERBY_AMOUNT,
- self::ORDERBY_DURATION
- );
- if ( in_array($value, $allowed_orders) ) {
- $this->orderby = $value;
- }
- break;
- default:
- $this->$rname = $value;
- break;
- }
- } else {
- $log->log(
- '[Contributions] Unable to set proprety `' .$name . '`',
- PEAR_LOG_WARNING
- );
- }
- }
- }
-
-}
-?>
* @since Available since 0.7dev - 2011-07-31
*/
-/** @ignore */
-require_once 'contributions.class.php';
-require_once 'contribution.class.php';
+use Galette\Entity\Contribution as Contribution;
+use Galette\Repository\Contributions as Contributions;
/**
* Transaction class for galette
$ajax = true;
}
-require_once 'classes/contributions.class.php';
if ( isset($_SESSION['galette'][PREFIX_DB . '_' . NAME_DB]['contributions'])) {
$contribs = unserialize($_SESSION['galette'][PREFIX_DB . '_' . NAME_DB]['contributions']);
} else {
- $contribs = new Contributions();
+ $contribs = new Galette\Repository\Contributions();
}
if ( $ajax === true ) {
if ( isset($_GET['payment_type_filter']) ) {
$ptf = $_GET['payment_type_filter'];
- if ( $ptf == Contribution::PAYMENT_OTHER
- || $ptf == Contribution::PAYMENT_CASH
- || $ptf == Contribution::PAYMENT_CREDITCARD
- || $ptf == Contribution::PAYMENT_CHECK
- || $ptf == Contribution::PAYMENT_TRANSFER
- || $ptf == Contribution::PAYMENT_PAYPAL
+ if ( $ptf == Galette\Entity\Contribution::PAYMENT_OTHER
+ || $ptf == Galette\Entity\Contribution::PAYMENT_CASH
+ || $ptf == Galette\Entity\Contribution::PAYMENT_CREDITCARD
+ || $ptf == Galette\Entity\Contribution::PAYMENT_CHECK
+ || $ptf == Galette\Entity\Contribution::PAYMENT_TRANSFER
+ || $ptf == Galette\Entity\Contribution::PAYMENT_PAYPAL
) {
$contribs->payment_type_filter = $ptf;
} elseif ( $ptf == -1 ) {
/** @ignore */
require_once WEB_ROOT . 'classes/fields_config.class.php';
require_once WEB_ROOT . 'classes/fields_categories.class.php';
-require_once WEB_ROOT . 'classes/contribution.class.php';
/**
* Member class for galette
--- /dev/null
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contribution class for galette
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010-2012 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Classes
+ * @package Galette
+ *
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010-2012 The Galette Team
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version SVN: $Id$
+ * @link http://galette.tuxfamily.org
+ * @since Available since 0.7dev - 2010-03-11
+ */
+
+namespace Galette\Entity;
+
+/** @ignore */
+require_once WEB_ROOT . 'classes/transaction.class.php';
+
+/**
+ * Contribution class for galette
+ *
+ * @category Classes
+ * @name Contribution
+ * @package Galette
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 The Galette Team
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link http://galette.tuxfamily.org
+ * @since Available since 0.7dev - 2010-03-11
+ */
+class Contribution
+{
+ const TABLE = 'cotisations';
+ const PK = 'id_cotis';
+
+ const PAYMENT_OTHER = 0;
+ const PAYMENT_CASH = 1;
+ const PAYMENT_CREDITCARD = 2;
+ const PAYMENT_CHECK = 3;
+ const PAYMENT_TRANSFER = 4;
+ const PAYMENT_PAYPAL = 5;
+
+ private $_id;
+ private $_date;
+ private $_member;
+ private $_type;
+ private $_amount;
+ private $_payment_type;
+ private $_orig_amount;
+ private $_info;
+ private $_begin_date;
+ private $_end_date;
+ private $_transaction = null;
+ private $_is_cotis;
+ private $_extension;
+
+ //fields list and their translation
+ private $_fields;
+
+ /**
+ * Default constructor
+ *
+ * @param null|int|ResultSet $args Either a ResultSet row to load
+ * a specific contribution, or an type id
+ * to just instanciate object
+ */
+ public function __construct($args = null)
+ {
+ /*
+ * Fields configuration. Each field is an array and must reflect:
+ * array(
+ * (string)label,
+ * (string) propname
+ * )
+ *
+ * I'd prefer a static private variable for this...
+ * But call to the _T function does not seems to be allowed there :/
+ */
+ $this->_fields = array(
+ 'id_cotis' => array(
+ 'label' => null, //not a field in the form
+ 'propname' => 'id'
+ ),
+ Adherent::PK => array(
+ 'label' => _T("Contributor:"),
+ 'propname' => 'member'
+ ),
+ ContributionsTypes::PK => array(
+ 'label' => _T("Contribution type:"),
+ 'propname' => 'type'
+ ),
+ 'montant_cotis' => array(
+ 'label' => _T("Amount:"),
+ 'propname' => 'amount'
+ ),
+ 'type_paiement_cotis' => array(
+ 'label' => _T("Payment type:"),
+ 'propname' => 'payment_type'
+ ),
+ 'info_cotis' => array(
+ 'label' => _T("Comments:"),
+ 'propname' => 'info'
+ ),
+ 'date_enreg' => array(
+ 'label' => null, //not a field in the form
+ 'propname' => 'date'
+ ),
+ 'date_debut_cotis' => array(
+ 'label' => _T("Date of contribution:"),
+ 'cotlabel' => _T("Start date of membership:"), //if contribution is a cotisation, label differs
+ 'propname' => 'begin_date'
+ ),
+ 'date_fin_cotis' => array(
+ 'label' => _T("End date of membership:"),
+ 'propname' => 'end_date'
+ ),
+ \Transaction::PK => array(
+ 'label' => null, //not a field in the form
+ 'propname' => 'transaction'
+ ),
+ //this one is not really a field, but is required in some cases...
+ //adding it here make simplier to check required fields
+ 'duree_mois_cotis' => array(
+ 'label' => _T("Membership extension:"),
+ 'propname' => 'extension'
+ )
+ );
+ if ( is_int($args) ) {
+ $this->load($args);
+ } else if ( is_array($args) ) {
+ $this->_date = date("Y-m-d");
+ if ( isset($args['adh']) && $args['adh'] != '' ) {
+ $this->_member = (int)$args['adh'];
+ }
+ $this->_type = new ContributionsTypes((int)$args['type']);
+ $this->_is_cotis = (bool)$this->_type->extension;
+ //calculate begin date for cotisation
+ $this->_begin_date = $this->_date;
+ if ( $this->_is_cotis ) {
+ $curend = self::getDueDate($args['adh']);
+ if ($curend != '') {
+ $dend = new \DateTime($curend);
+ $now = date('Y-m-d');
+ $dnow = new \DateTime($now);
+ if ( $dend < $dnow ) {
+ // Member didn't renew on time
+ $this->_begin_date = $now;
+ } else {
+ $this->_begin_date = $curend;
+ }
+ }
+ if ( isset($args['ext']) ) {
+ $this->_extension = $args['ext'];
+ }
+ $this->_retrieveEndDate();
+ }
+ if ( isset($args['trans']) ) {
+ $this->_transaction = new \Transaction((int)$args['trans']);
+ if ( !isset($this->_member) ) {
+ $this->_member = (int)$this->_transaction->member;
+ }
+ $this->_amount = $this->_transaction->getMissingAmount();
+ }
+ } elseif ( is_object($args) ) {
+ $this->_loadFromRS($args);
+ }
+ }
+
+ /**
+ * Sets end contribution date
+ *
+ * @return void
+ */
+ private function _retrieveEndDate()
+ {
+ global $preferences;
+
+ $bdate = new \DateTime($this->_begin_date);
+ if ( $preferences->pref_beg_membership != '' ) {
+ //case beginning of membership
+ list($j, $m) = explode('/', $preferences->pref_beg_membership);
+ $edate = new \DateTime($bdate->format('Y') . '-' . $m . '-' . $j);
+ while ( $edate <= $bdate ) {
+ $edate->modify('+1 year');
+ }
+ $this->_end_date = $edate->format('Y-m-d');
+ } else if ( $preferences->pref_membership_ext != '' ) {
+ //case membership extension
+ $dext = new \DateInterval('P' . $this->_extension . 'M');
+ $edate = $bdate->add($dext);
+ $this->_end_date = $edate->format('Y-m-d');
+ }
+ }
+
+ /**
+ * Loads a contribution from its id
+ *
+ * @param int $id the identifiant for the contribution to load
+ *
+ * @return bool true if query succeed, false otherwise
+ */
+ public function load($id)
+ {
+ global $zdb, $log, $login;
+
+ try {
+ $select = new \Zend_Db_Select($zdb->db);
+ $select->from(PREFIX_DB . self::TABLE)
+ ->where(self::PK . ' = ?', $id);
+ //restrict query on current member id if he's not admin nor staff member
+ if ( !$login->isAdmin() && !$login->isStaff() ) {
+ $select->where(Adherent::PK . ' = ?', $login->id);
+ }
+ $row = $select->query()->fetch();
+ if ( $row !== false ) {
+ $this->_loadFromRS($row);
+ return true;
+ } else {
+ throw new Exception(
+ 'No contribution #' . $id . ' (user ' .$login->id . ')'
+ );
+ }
+ } catch (\Exception $e) {
+ /** FIXME */
+ $log->log(
+ 'An error occured attempting to load contribution #' . $id .
+ $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Populate object from a resultset row
+ *
+ * @param ResultSet $r the resultset row
+ *
+ * @return void
+ */
+ private function _loadFromRS($r)
+ {
+ $pk = self::PK;
+ $this->_id = $r->$pk;
+ $this->_date = $r->date_enreg;
+ $this->_amount = $r->montant_cotis;
+ //save original amount, we need it for transactions parts calulations
+ $this->_orig_amount = $r->montant_cotis;
+ $this->_payment_type = $r->type_paiement_cotis;
+ $this->_info = $r->info_cotis;
+ $this->_begin_date = $r->date_debut_cotis;
+ $enddate = $r->date_fin_cotis;
+ //do not work with knows bad dates...
+ //the one with BC comes from 0.63/pgsl demo... Why the hell a so
+ //strange date? dont know :(
+ if ( $enddate !== '0000-00-00'
+ && $enddate !== '1901-01-01'
+ && $enddate !== '0001-01-01 BC'
+ ) {
+ $this->_end_date = $r->date_fin_cotis;
+ }
+ $adhpk = Adherent::PK;
+ $this->_member = (int)$r->$adhpk;
+
+ $transpk = \Transaction::PK;
+ if ( $r->$transpk != '' ) {
+ $this->_transaction = new \Transaction((int)$r->$transpk);
+ }
+
+ $this->_type = new ContributionsTypes((int)$r->id_type_cotis);
+ if ( $this->_type->extension == 1 ) {
+ $this->_is_cotis = true;
+ } else {
+ $this->_is_cotis = false;
+ }
+ }
+
+ /**
+ * Check posted values validity
+ *
+ * @param array $values All values to check, basically the $_POST array
+ * after sending the form
+ * @param array $required Array of required fields
+ * @param array $disabled Array of disabled fields
+ *
+ * @return true|array
+ */
+ public function check($values, $required, $disabled)
+ {
+ global $zdb, $log;
+ $errors = array();
+
+ $fields = array_keys($this->_fields);
+ foreach ( $fields as $key ) {
+ //first of all, let's sanitize values
+ $key = strtolower($key);
+ $prop = '_' . $this->_fields[$key]['propname'];
+
+ if ( isset($values[$key]) ) {
+ $value = trim($values[$key]);
+ } else {
+ $value = '';
+ }
+
+ // if the field is enabled, check it
+ if ( !isset($disabled[$key]) ) {
+ // fill up the adherent structure
+ //$this->$prop = stripslashes($value); //not relevant here!
+
+ // now, check validity
+ if ( $value != '' ) {
+ switch ( $key ) {
+ // dates
+ case 'date_enreg':
+ case 'date_debut_cotis':
+ case 'date_fin_cotis':
+ /** FIXME: only ok dates dd/mm/yyyy */
+ if ( !preg_match(
+ '@^([0-9]{2})/([0-9]{2})/([0-9]{4})$@',
+ $value,
+ $date
+ ) ) {
+ $errors[] = _T("- Wrong date format (dd/mm/yyyy)!");
+ } else {
+ if ( !checkdate($date[2], $date[1], $date[3]) ) {
+ $errors[] = _T("- Non valid date!");
+ } else {
+ $this->$prop = $date[3] . '-' . $date[2] . '-' .
+ $date[1];
+ }
+ }
+ break;
+ case Galette\Entity\Adherent::PK:
+ $this->_member = $value;
+ break;
+ case ContributionsTypes::PK:
+ $this->_type = new ContributionsTypes((int)$value);
+ break;
+ case 'montant_cotis':
+ $this->_amount = $value;
+ $us_value = strtr($value, ',', '.');
+ if ( !is_numeric($value) ) {
+ $errors[] = _T("- The amount must be an integer!");
+ }
+ break;
+ case 'type_paiement_cotis':
+ if ( $value == self::PAYMENT_OTHER
+ || $value == self::PAYMENT_CASH
+ || $value == self::PAYMENT_CREDITCARD
+ || $value == self::PAYMENT_CHECK
+ || $value == self::PAYMENT_TRANSFER
+ || $value == self::PAYMENT_PAYPAL
+ ) {
+ $this->_payment_type = $value;
+ } else {
+ $errors[] = _T("- Unknown payment type");
+ }
+ break;
+ case 'info_cotis':
+ $this->_info = $value;
+ break;
+ case Transaction::PK:
+ $this->_transaction = new Transaction((int)$value);
+ break;
+ case 'duree_mois_cotis':
+ if ( !is_numeric($value) || $value<=0 ) {
+ $errors[] = _T("- The duration must be a positive integer!");
+ }
+ $this->$prop = $value;
+ $this->_retrieveEndDate();
+ break;
+ }
+ }
+ }
+ }
+
+ // missing required fields?
+ while ( list($key, $val) = each($required) ) {
+ if ( $val === 1) {
+ $prop = '_' . $this->_fields[$key]['propname'];
+ if ( !isset($disabled[$key])
+ && (!isset($this->$prop)
+ || (!is_object($this->$prop) && trim($this->$prop) == '')
+ || (is_object($this->$prop) && trim($this->$prop->id) == ''))
+ ) {
+ $errors[] = _T("- Mandatory field empty: ") .
+ ' <a href="#' . $key . '">' . $this->getFieldName($key) .'</a>';
+ }
+ }
+ }
+
+ if ( $this->_transaction != null && $this->_amount != null) {
+ $missing = $this->_transaction->getMissingAmount();
+ //calculate new missing amount
+ $missing = $missing + $this->_orig_amount - $this->_amount;
+ if ( $missing < 0 ) {
+ $errors[] = _T("- Sum of all contributions exceed corresponding transaction amount.");
+ }
+ }
+
+ if ( count($errors) > 0 ) {
+ $log->log(
+ 'Some errors has been throwed attempting to edit/store a contribution' .
+ print_r($errors, true),
+ PEAR_LOG_DEBUG
+ );
+ return $errors;
+ } else {
+ $log->log(
+ 'Contribution checked successfully.',
+ PEAR_LOG_DEBUG
+ );
+ return true;
+ }
+ }
+
+ /**
+ * Check that membership fees does not overlap
+ *
+ * @return boolean|string True if all is ok, false if error,
+ * error message if overlap
+ */
+ public function checkOverlap()
+ {
+ global $zdb, $log;
+
+ try {
+ $select = new \Zend_Db_Select($zdb->db);
+ $select->from(
+ array('c' => PREFIX_DB . self::TABLE),
+ array('date_debut_cotis', 'date_fin_cotis')
+ )->join(
+ array('ct' => PREFIX_DB . ContributionsTypes::TABLE),
+ 'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
+ array()
+ )->where(Adherent::PK . ' = ?', $this->_member)
+ ->where('cotis_extension = ?', (string)1)
+ ->where(
+ '((' . $zdb->db->quoteInto('date_debut_cotis >= ?', $this->_begin_date) .
+ ' AND '. $zdb->db->quoteInto('date_debut_cotis < ?', $this->_end_date) .
+ ') OR (' . $zdb->db->quoteInto('date_fin_cotis > ?', $this->_begin_date) .
+ ' AND ' . $zdb->db->quoteInto('date_fin_cotis <= ?', $this->_end_date) . '))'
+ );
+
+ if ( $this->id != '' ) {
+ $select->where(self::PK . ' != ?', $this->id);
+ }
+
+ $result = $select->query()->fetch();
+ if ( $result !== false ) {
+ $d = new \DateTime($result->date_debut_cotis);
+
+ return _T("- Membership period overlaps period starting at ") .
+ $d->format(_T("Y-m-d"));
+ }
+ return true;
+ } catch (\Exception $e) {
+ /** FIXME */
+ $log->log(
+ 'An error occured checking overlaping fee. ' . $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ $log->log(
+ 'Query was: ' . $select->__toString(),
+ PEAR_LOG_DEBUG
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Store the contribution
+ *
+ * @return boolean
+ */
+ public function store()
+ {
+ global $zdb, $log, $hist;
+
+ try {
+ $zdb->db->beginTransaction();
+ $values = array();
+ $fields = self::getDbFields();
+ /** FIXME: quote? */
+ foreach ( $fields as $field ) {
+ $prop = '_' . $this->_fields[$field]['propname'];
+ switch ( $field ) {
+ case ContributionsTypes::PK:
+ case \Transaction::PK:
+ $values[$field] = $this->$prop->id;
+ break;
+ default:
+ $values[$field] = $this->$prop;
+ break;
+ }
+ }
+
+ //no end date,, let's take database defaults
+ if ( !$this->isCotis() && !$this->_end_date ) {
+ unset($values['date_fin_cotis']);
+ }
+
+ if ( !isset($this->_id) || $this->_id == '') {
+ //we're inserting a new contribution
+ unset($values[self::PK]);
+ $add = $zdb->db->insert(PREFIX_DB . self::TABLE, $values);
+ if ( $add > 0) {
+ $this->_id = $zdb->db->lastInsertId(
+ PREFIX_DB . self::TABLE,
+ 'id'
+ );
+ // logging
+ $hist->add(
+ _T("Contribution added"),
+ Adherent::getSName($this->_member)
+ );
+ } else {
+ $hist->add(_T("Fail to add new contribution."));
+ throw new Exception(
+ 'An error occured inserting new contribution!'
+ );
+ }
+ } else {
+ //we're editing an existing contribution
+ $edit = $zdb->db->update(
+ PREFIX_DB . self::TABLE,
+ $values,
+ self::PK . '=' . $this->_id
+ );
+ //edit == 0 does not mean there were an error, but that there
+ //were nothing to change
+ if ( $edit > 0 ) {
+ $hist->add(
+ _T("Contribution updated"),
+ Galette\Entity\Adherent::getSName($this->_member)
+ );
+ } else if ($edit === false) {
+ throw new \Exception(
+ 'An error occured updating contribution # ' . $this->_id . '!'
+ );
+ }
+ }
+ //update deadline
+ if ( $this->isCotis() ) {
+ $deadline = $this->_updateDeadline();
+ if ( $deadline !== true ) {
+ //if something went wrong, we rollback transaction
+ throw new \Exception('An error occured updating member\'s deadline');
+ }
+ }
+ $zdb->db->commit();
+ $this->_orig_amount = $this->_amount;
+ return true;
+ } catch (\Exception $e) {
+ /** FIXME */
+ $zdb->db->rollBack();
+ $log->log(
+ 'Something went wrong :\'( | ' . $e->getMessage() . "\n" .
+ $e->getTraceAsString(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Update member dead line
+ *
+ * @return boolean
+ */
+ private function _updateDeadline()
+ {
+ global $zdb, $log;
+
+ try {
+ $due_date = self::getDueDate($this->_member);
+
+ if ( $due_date != '' ) {
+ $date_fin_update = $due_date;
+ } else {
+ $date_fin_update = 'NULL';
+ }
+
+ $edit = $zdb->db->update(
+ PREFIX_DB . Adherent::TABLE,
+ array('date_echeance' => $date_fin_update),
+ Adherent::PK . '=' . $this->_member
+ );
+ return true;
+ } catch (Exception $e) {
+ $log->log(
+ 'An error occured updating member ' . $this->_member .
+ '\'s deadline |' .
+ $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Remove contribution from database
+ *
+ * @param boolean $transaction Activate transaction mode (defaults to true)
+ *
+ * @return boolean
+ */
+ public function remove($transaction = true)
+ {
+ global $zdb, $log;
+
+ try {
+ if ( $transaction ) {
+ $zdb->db->beginTransaction();
+ }
+ $del = $zdb->db->delete(
+ PREFIX_DB . self::TABLE,
+ self::PK . ' = ' . $this->_id
+ );
+ if ( $del > 0 ) {
+ $this->_updateDeadline();
+ }
+ if ( $transaction ) {
+ $zdb->db->commit();
+ }
+ return true;
+ } catch (\Exception $e) {
+ /** FIXME */
+ if ( $transaction ) {
+ $zdb->db->rollBack();
+ }
+ $log->log(
+ 'An error occured trying to remove contribution #' .
+ $this->_id . ' | ' . $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Get field label
+ *
+ * @param string $field Field name
+ *
+ * @return string
+ */
+ public function getFieldName($field)
+ {
+ $label = $this->_fields[$field]['label'];
+ if ( $this->isCotis() && $field == 'date_debut_cotis') {
+ $label = $this->_fields[$field]['cotlabel'];
+ }
+ //remove trailing ':' and then nbsp (for french at least)
+ $label = trim(trim($label, ':'), ' ');
+ return $label;
+ }
+
+ /**
+ * Retrieve fields from database
+ *
+ * @return array
+ */
+ public static function getDbFields()
+ {
+ global $zdb;
+ return array_keys($zdb->db->describeTable(PREFIX_DB . self::TABLE));
+ }
+
+ /**
+ * Get the relevant CSS class for current contribution
+ *
+ * @return string current contribution row class
+ */
+ public function getRowClass()
+ {
+ return ( $this->_end_date != $this->_begin_date && $this->_is_cotis) ?
+ 'cotis-normal' :
+ 'cotis-give';
+ }
+
+ /**
+ * Retrieve member due date
+ *
+ * @param integer $member_id Member identifier
+ *
+ * @return date
+ */
+ public static function getDueDate($member_id)
+ {
+ global $zdb, $log;
+
+ try {
+ $select = new \Zend_Db_Select($zdb->db);
+ $select->from(
+ PREFIX_DB . self::TABLE,
+ 'MAX(date_fin_cotis)'
+ )->where(Adherent::PK . ' = ?', $member_id);
+ $due_date = $select->query()->fetchColumn();
+ return $due_date;
+ } catch (\Exception $e) {
+ /** FIXME */
+ $log->log(
+ 'An error occured trying to retrieve member\'s due date',
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Detach a contribution from a transaction
+ *
+ * @param int $trans_id Transaction identifier
+ * @param int $contrib_id Contribution identifier
+ *
+ * @return boolean
+ */
+ public static function unsetTransactionPart($trans_id, $contrib_id)
+ {
+ global $zdb, $log;
+
+ try {
+ //first, we check if contribution is part of transaction
+ $c = new Contribution((int)$contrib_id);
+ if ( $c->isTransactionPartOf($trans_id)) {
+ $zdb->db->update(
+ PREFIX_DB . self::TABLE,
+ array(Transaction::PK => null),
+ self::PK . ' = ' . $contrib_id
+ );
+ return true;
+ } else {
+ $log->log(
+ 'Contribution #' . $contrib_id .
+ ' is not actually part of transaction #' . $trans_id,
+ PEAR_LOG_WARNING
+ );
+ return false;
+ }
+ } catch (Exception $e) {
+ $log->log(
+ 'Unable to detach contribution #' . $contrib_id .
+ ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Set a contribution as a transaction part
+ *
+ * @param int $trans_id Transaction identifier
+ * @param int $contrib_id Contribution identifier
+ *
+ * @return boolean
+ */
+ public static function setTransactionPart($trans_id, $contrib_id)
+ {
+ global $zdb, $log;
+
+ try {
+ $zdb->db->update(
+ PREFIX_DB . self::TABLE,
+ array(Transaction::PK => $trans_id),
+ self::PK . ' = ' . $contrib_id
+ );
+ return true;
+ } catch (Exception $e) {
+ $log->log(
+ 'Unable to attach contribution #' . $contrib_id .
+ ' to transaction #' . $trans_id . ' | ' . $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Is current contribution a cotisation
+ *
+ * @return boolean
+ */
+ public function isCotis()
+ {
+ return $this->_is_cotis;
+ }
+
+ /**
+ * Is current contribution part of specified transaction
+ *
+ * @param int $id Transaction identifier
+ *
+ * @return boolean
+ */
+ public function isTransactionPartOf($id)
+ {
+ if ( $this->isTransactionPart() ) {
+ return $id == $this->_transaction->id;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Is current contribution part of transaction
+ *
+ * @return boolean
+ */
+ public function isTransactionPart()
+ {
+ return $this->_transaction != null;
+ }
+
+ /**
+ * Global getter method
+ *
+ * @param string $name name of the property we want to retrive
+ *
+ * @return false|object the called property
+ */
+ public function __get($name)
+ {
+ global $log;
+
+ $forbidden = array('is_cotis');
+ $virtuals = array('duration', 'spayment_type');
+
+ $rname = '_' . $name;
+ if ( !in_array($name, $forbidden)
+ && isset($this->$rname)
+ || in_array($name, $virtuals)
+ ) {
+ switch($name) {
+ case 'date':
+ case 'begin_date':
+ case 'end_date':
+ if ( $this->$rname != '' ) {
+ try {
+ $d = new \DateTime($this->$rname);
+ return $d->format(_T("Y-m-d"));
+ } catch (Exception $e) {
+ //oops, we've got a bad date :/
+ $log->log(
+ 'Bad date (' . $his->$rname . ') | ' .
+ $e->getMessage(),
+ PER_LOG_INFO
+ );
+ return $this->$rname;
+ }
+ }
+ break;
+ case 'duration':
+ if ( $this->_is_cotis ) {
+ $date_end = new \DateTime($this->_end_date);
+ $date_start = new \DateTime($this->_begin_date);
+ $diff = $date_end->diff($date_start);
+ return $diff->format('%y') * 12 + $diff->format('%m');
+ } else {
+ return '';
+ }
+ break;
+ case 'spayment_type':
+ switch ( $this->_payment_type ) {
+ case self::PAYMENT_OTHER:
+ return _T("Other");
+ break;
+ case self::PAYMENT_CASH:
+ return _T("Cash");
+ break;
+ case self::PAYMENT_CREDITCARD:
+ return _T("Credit card");
+ break;
+ case self::PAYMENT_CHECK:
+ return _T("Check");
+ break;
+ case self::PAYMENT_TRANSFER:
+ return _T("Transfer");
+ break;
+ case self::PAYMENT_PAYPAL:
+ return _T("Paypal");
+ break;
+ default:
+ $log->log(
+ 'Unknown payment type ' . $this->_payment_type,
+ PEAR_LOG_WARNING
+ );
+ return '-';
+ break;
+ }
+ default:
+ return $this->$rname;
+ break;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Global setter method
+ *
+ * @param string $name name of the property we want to assign a value to
+ * @param object $value a relevant value for the property
+ *
+ * @return void
+ */
+ public function __set($name, $value)
+ {
+ global $log;
+ $forbidden = array('fields', 'is_cotis', 'end_date');
+
+ if ( !in_array($name, $forbidden) ) {
+ $rname = '_' . $name;
+ switch($name) {
+ case 'transaction':
+ if ( is_int($value) ) {
+ $this->$rname = new Transaction($value);
+ } else {
+ $log->log(
+ 'Trying to set a transaction from an id that is not an integer.',
+ PEAR_LOG_WARNING
+ );
+ }
+ break;
+ case 'type':
+ if ( is_int($value) ) {
+ //set type
+ $this->$rname = new Galette\Entity\ContributionsTypes($value);
+ //set is_cotis according to type
+ if ( $this->$rname->extension == 1 ) {
+ $this->_is_cotis = true;
+ } else {
+ $this->_is_cotis = false;
+ }
+ } else {
+ $log->log(
+ 'Trying to set a type from an id that is not an integer.',
+ PEAR_LOG_WARNING
+ );
+ }
+ break;
+ case 'begin_date':
+ /** FIXME: only ok dates dd/mm/yyyy */
+ if ( !preg_match(
+ '@^([0-9]{2})/([0-9]{2})/([0-9]{4})$@',
+ $value,
+ $date
+ ) ) {
+ $errors[] = _T("- Wrong date format (dd/mm/yyyy)!");
+ } else {
+ if ( !checkdate($date[2], $date[1], $date[3]) ) {
+ $errors[] = _T("- Non valid date!");
+ } else {
+ $this->_begin_date = $date[3] . '-' . $date[2] . '-' .
+ $date[1];
+ }
+ }
+ break;
+ case 'amount':
+ if (is_numeric($value) && $value > 0 ) {
+ $this->$rname = $value;
+ } else {
+ $log->log(
+ 'Trying to set an amount with a non numeric value, ' .
+ 'or with a zero value',
+ PEAR_LOG_WARNING
+ );
+ }
+ break;
+ default:
+ $log->log(
+ '[' . __CLASS__ . ']: Trying to set an unknown property (' .
+ $name . ')',
+ PEAR_LOG_WARNING
+ );
+ break;
+ }
+ }
+
+ }
+}
+?>
namespace Galette\Entity;
-/* TODO: Most of the code is duplicated in contribution_types.class.php. Should
+/* TODO: Most of the code is duplicated in Galette\Entity\ContributionsTypes. Should
* probably use a superclass for genericity.
*/
namespace Galette\Filters;
+use Galette\Core\Pagination as Pagination;
+use Galette\Repository\Members as Members;
+
/**
* Members list filters and paginator
*
* @link http://galette.tuxfamily.org
*/
-class MembersList extends \Galette\Core\Pagination
+class MembersList extends Pagination
{
//filters
private $_filter_str;
$this->_field_filter = null;
$this->_membership_filter = null;
$this->_account_status_filter = null;
- $this->_email_filter = \Members::FILTER_DC_EMAIL;
+ $this->_email_filter = Members::FILTER_DC_EMAIL;
$this->_selected = array();
}
break;
case 'email_filter':
switch ($value) {
- case \Members::FILTER_DC_EMAIL:
- case \Members::FILTER_W_EMAIL:
- case \Members::FILTER_WO_EMAIL:
+ case Members::FILTER_DC_EMAIL:
+ case Members::FILTER_W_EMAIL:
+ case Members::FILTER_WO_EMAIL:
$this->_email_filter = $value;
break;
default:
$log->log(
'[MembersList] Value for email filter should be either ' .
- \Members::FILTER_DC_EMAIL . ', ' .
- \Members::FILTER_W_EMAIL . ' or ' .
- \Members::FILTER_WO_EMAIL . ' (' . $value . ' given)',
+ Members::FILTER_DC_EMAIL . ', ' .
+ Members::FILTER_W_EMAIL . ' or ' .
+ Members::FILTER_WO_EMAIL . ' (' . $value . ' given)',
PEAR_LOG_WARNING
);
break;
--- /dev/null
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Contributions class
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010-2012 The Galette Team
+ *
+ * This file is part of Galette (http://galette.tuxfamily.org).
+ *
+ * Galette is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Galette is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Galette. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Classes
+ * @package Galette
+ *
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010-2012 The Galette Team
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @version SVN: $Id$
+ * @link http://galette.tuxfamily.org
+ * @since Available since 0.7dev - 2010-03-11
+ */
+
+namespace Galette\Repository;
+
+use Galette\Core\Pagination as Pagination;
+use Galette\Entity\Contribution as Contribution;
+use Galette\Entity\Adherent as Adherent;
+
+/**
+ * Contributions class for galette
+ *
+ * @name Contributions
+ * @category Classes
+ * @package Galette
+ *
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2009-2012 The Galette Team
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
+ * @link http://galette.tuxfamily.org
+ */
+class Contributions extends Pagination
+{
+ const TABLE = Contribution::TABLE;
+ const PK = Contribution::PK;
+
+ const FILTER_DATE_BEGIN = 0;
+ const FILTER_DATE_END = 1;
+
+ const ORDERBY_DATE = 0;
+ const ORDERBY_BEGIN_DATE = 1;
+ const ORDERBY_END_DATE = 2;
+ const ORDERBY_MEMBER = 3;
+ const ORDERBY_TYPE = 4;
+ const ORDERBY_AMOUNT = 5;
+ const ORDERBY_DURATION = 6;
+ const ORDERBY_PAYMENT_TYPE = 7;
+
+ private $_count = null;
+ private $_start_date_filter = null;
+ private $_end_date_filter = null;
+ private $_payment_type_filter = null;
+ private $_filtre_cotis_adh = null;
+ private $_filtre_transactions = null;
+
+ private $_from_transaction = false;
+ private $_max_amount = null;
+ private $_sum;
+
+ /**
+ * Default constructor
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Returns the field we want to default set order to
+ *
+ * @return string field name
+ */
+ protected function getDefaultOrder()
+ {
+ return 'date_debut_cotis';
+ }
+
+ /**
+ * Returns the field we want to default set order to (public method)
+ *
+ * @return string field name
+ */
+ public static function defaultOrder()
+ {
+ return self::getDefaultOrder();
+ }
+
+ /**
+ * Get contributions list for a specific transaction
+ *
+ * @param int $trans_id Transaction identifier
+ *
+ * @return Contribution[]
+ */
+ public function getListFromTransaction($trans_id)
+ {
+ $this->_from_transaction = $trans_id;
+ return $this->getContributionsList(true);
+ }
+
+ /**
+ * Get contributions list
+ *
+ * @param bool $as_contrib return the results as an array of
+ * Contribution object.
+ * @param array $fields field(s) name(s) to get. Should be a string or
+ * an array. If null, all fields will be
+ * returned
+ * @param boolean $count true if we want to count members
+ *
+ * @return Contribution[]|ResultSet
+ */
+ public function getContributionsList(
+ $as_contrib=false, $fields=null, $count=true
+ ) {
+ global $zdb, $log;
+
+ try {
+ $select = $this->_buildSelect(
+ $fields, $count
+ );
+
+ $this->setLimits($select);
+
+ $contributions = array();
+ if ( $as_contrib ) {
+ foreach ( $select->query()->fetchAll() as $row ) {
+ $contributions[] = new Contribution($row);
+ }
+ } else {
+ $contributions = $select->query()->fetchAll();
+ }
+ return $contributions;
+ } catch (\Exception $e) {
+ /** TODO */
+ $log->log(
+ 'Cannot list contributions | ' . $e->getMessage(),
+ PEAR_LOG_WARNING
+ );
+ $log->log(
+ 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Builds the SELECT statement
+ *
+ * @param array $fields fields list to retrieve
+ * @param bool $count true if we want to count members
+ (not applicable from static calls), defaults to false
+ *
+ * @return string SELECT statement
+ */
+ private function _buildSelect($fields, $count = false)
+ {
+ global $zdb;
+
+ try {
+ $fieldsList = ( $fields != null )
+ ? (( !is_array($fields) || count($fields) < 1 ) ? (array)'*'
+ : implode(', ', $fields)) : (array)'*';
+
+ $select = new \Zend_Db_Select($zdb->db);
+ $select->from(
+ array('a' => PREFIX_DB . self::TABLE),
+ $fieldsList
+ );
+
+ $select->join(
+ array('p' => PREFIX_DB . Adherent::TABLE, Adherent::PK),
+ 'a.' . Adherent::PK . '=' . 'p.' . Adherent::PK
+ );
+
+ $this->_buildWhereClause($select);
+ $select->order(self::_buildOrderClause());
+
+ $this->_calculateSum($select);
+
+ if ( $count ) {
+ $this->_proceedCount($select);
+ }
+
+ return $select;
+ } catch (\Exception $e) {
+ /** TODO */
+ $log->log(
+ 'Cannot build SELECT clause for contributions | ' . $e->getMessage(),
+ PEAR_LOG_WARNING
+ );
+ $log->log(
+ 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Count contributions from the query
+ *
+ * @param Zend_Db_Select $select Original select
+ *
+ * @return void
+ */
+ private function _proceedCount($select)
+ {
+ global $zdb, $log;
+
+ try {
+ $countSelect = clone $select;
+ $countSelect->reset(\Zend_Db_Select::COLUMNS);
+ $countSelect->reset(\Zend_Db_Select::ORDER);
+ $countSelect->columns('count(' . self::PK . ') AS ' . self::PK);
+
+ $result = $countSelect->query()->fetch();
+
+ $k = self::PK;
+ $this->_count = $result->$k;
+ if ( $this->_count > 0 ) {
+ $this->counter = (int)$this->_count;
+ $this->countPages();
+ }
+ } catch (\Exception $e) {
+ /** TODO */
+ $log->log(
+ 'Cannot count contributions | ' . $e->getMessage(),
+ PEAR_LOG_WARNING
+ );
+ $log->log(
+ 'Query was: ' . $countSelect->__toString() . ' ' . $e->__toString(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Calculate sum of all selected contributions
+ *
+ * @param Zend_Db_Select $select Original select
+ *
+ * @return void
+ */
+ private function _calculateSum($select)
+ {
+ global $zdb, $log;
+
+ try {
+ $sumSelect = clone $select;
+ $sumSelect->reset(\Zend_Db_Select::COLUMNS);
+ $sumSelect->reset(\Zend_Db_Select::ORDER);
+ $sumSelect->columns('SUM(montant_cotis) AS contribsum');
+
+ $result = $sumSelect->query()->fetch();
+
+ $this->_sum = round($result->contribsum, 2);
+ } catch (\Exception $e) {
+ /** TODO */
+ $log->log(
+ 'Cannot calculate contributions sum | ' . $e->getMessage(),
+ PEAR_LOG_WARNING
+ );
+ $log->log(
+ 'Query was: ' . $sumSelect->__toString() . ' ' . $e->__toString(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ }
+
+ /**
+ * Builds the order clause
+ *
+ * @return string SQL ORDER clause
+ */
+ private function _buildOrderClause()
+ {
+ $order = array();
+
+ switch ( $this->orderby ) {
+ case self::ORDERBY_DATE:
+ $order[] = 'date_enreg' . ' ' . $this->ordered;
+ break;
+ case self::ORDERBY_BEGIN_DATE:
+ $order[] = 'date_debut_cotis' . ' ' . $this->ordered;
+ break;
+ case self::ORDERBY_END_DATE:
+ $order[] = 'date_fin_cotis' . ' ' . $this->ordered;
+ break;
+ case self::ORDERBY_MEMBER:
+ $order[] = 'nom_adh' . ' ' . $this->ordered;
+ $order[] = 'prenom_adh' . ' ' . $this->ordered;
+ break;
+ case self::ORDERBY_TYPE:
+ $order[] = ContributionsTypes::PK;
+ break;
+ case self::ORDERBY_AMOUNT:
+ $order[] = 'montant_cotis' . ' ' . $this->ordered;
+ break;
+ /*
+ Hum... I really do not know how to sort a query with a value that
+ is calculated code side :/
+ case self::ORDERBY_DURATION:
+ break;*/
+ default:
+ $order[] = $this->orderby . ' ' . $this->ordered;
+ break;
+ }
+
+ return $order;
+ }
+
+ /**
+ * Builds where clause, for filtering on simple list mode
+ *
+ * @param Zend_Db_Select $select Original select
+ *
+ * @return string SQL WHERE clause
+ */
+ private function _buildWhereClause($select)
+ {
+ global $zdb, $log, $login;
+
+ try {
+ if ( $this->_start_date_filter != null ) {
+ /** TODO: initial date format should be i18n
+ $d = DateTime::createFromFormat(
+ _T("d/m/Y"),
+ $this->_start_date_filter
+ );*/
+ $d = \DateTime::createFromFormat(
+ 'd/m/Y',
+ $this->_start_date_filter
+ );
+ $select->where('date_debut_cotis >= ?', $d->format('Y-m-d'));
+ }
+
+ if ( $this->_end_date_filter != null ) {
+ /** TODO: initial date format should be i18n
+ $d = DateTime::createFromFormat(
+ _T("d/m/Y"),
+ $this->_end_date_filter
+ );*/
+ $d = \DateTime::createFromFormat(
+ 'd/m/Y',
+ $this->_end_date_filter
+ );
+ $select->where('date_debut_cotis <= ?', $d->format('Y-m-d'));
+ }
+
+ if ( $this->_payment_type_filter != null ) {
+ $select->where('type_paiement_cotis = ?', $this->_payment_type_filter);
+ }
+
+ if ( $this->_from_transaction !== false ) {
+ $select->where(
+ \Transaction::PK . ' = ?',
+ $this->_from_transaction
+ );
+ }
+
+ if ( $this->_max_amount !== null && is_int($this->_max_amount)) {
+ $select->where(
+ '(montant_cotis <= ' . $this->_max_amount .
+ ' OR montant_cotis IS NULL)'
+ );
+ }
+ $sql = $select->__toString();
+
+ if ( !$login->isAdmin() && !$login->isStaff() ) {
+ //non staff members can only view their own contributions
+ $select->where('p.' . Adherent::PK . ' = ?', $login->id);
+ } else if ( $this->_filtre_cotis_adh != null ) {
+ $select->where('p.' . Adherent::PK . ' = ?', $this->_filtre_cotis_adh);
+ }
+ if ( $this->_filtre_transactions === true ) {
+ $select->where('a.trans_id ?', new Zend_Db_Expr('IS NULL'));
+ }
+ $qry = $select->__toString();
+ } catch (Exception $e) {
+ /** TODO */
+ $log->log(
+ __METHOD__ . ' | ' . $e->getMessage(),
+ PEAR_LOG_WARNING
+ );
+ }
+ }
+
+ /**
+ * Get count for current query
+ *
+ * @return int
+ */
+ public function getCount()
+ {
+ return $this->_count;
+ }
+
+ /**
+ * Reinit default parameters
+ *
+ * @return void
+ */
+ public function reinit()
+ {
+ parent::reinit();
+ $this->_start_date_filter = null;
+ $this->_end_date_filter = null;
+ $this->_payment_type_filter = null;
+ }
+
+ /**
+ * Remove specified contributions
+ *
+ * @param integer|array $ids Contributions identifiers to delete
+ * @param boolean $transaction True to begin a database transaction
+ *
+ * @return boolean
+ */
+ public function removeContributions($ids, $transaction = true)
+ {
+ global $zdb, $log, $hist;
+
+ $list = array();
+ if ( is_numeric($ids) ) {
+ //we've got only one identifier
+ $list[] = $ids;
+ } else {
+ $list = $ids;
+ }
+
+ if ( is_array($list) ) {
+ $res = true;
+ try {
+ if ( $transaction ) {
+ $zdb->db->beginTransaction();
+ }
+ $select = new \Zend_Db_Select($zdb->db);
+ $select->from(PREFIX_DB . self::TABLE)
+ ->where(self::PK . ' IN (?)', $list);
+ $contributions = $select->query()->fetchAll();
+ foreach ( $contributions as $contribution ) {
+ $c = new Contribution($contribution);
+ $res = $c->remove(false);
+ if ( $res === false ) {
+ throw new Exception;
+ }
+ }
+ if ( $transaction ) {
+ $zdb->db->commit();
+ }
+ $hist->add(
+ "Contributions deleted (" . print_r($list, true) . ')'
+ );
+ } catch (\Exception $e) {
+ /** FIXME */
+ if ( $transaction ) {
+ $zdb->db->rollBack();
+ }
+ $log->log(
+ 'An error occured trying to remove contributions | ' .
+ $e->getMessage(),
+ PEAR_LOG_ERR
+ );
+ return false;
+ }
+ } else {
+ //not numeric and not an array: incorrect.
+ $log->log(
+ 'Asking to remove contribution, but without providing an array or a single numeric value.',
+ PEAR_LOG_WARNING
+ );
+ return false;
+ }
+
+ }
+
+ /**
+ * Global getter method
+ *
+ * @param string $name name of the property we want to retrive
+ *
+ * @return object the called property
+ */
+ public function __get($name)
+ {
+ global $log;
+
+ $log->log(
+ '[Contributions] Getting property `' . $name . '`',
+ PEAR_LOG_DEBUG
+ );
+
+ if ( in_array($name, $this->pagination_fields) ) {
+ return parent::__get($name);
+ } else {
+ $return_ok = array(
+ 'filtre_cotis_adh',
+ 'start_date_filter',
+ 'end_date_filter',
+ 'payment_type_filter',
+ 'sum',
+ 'max_amount'
+ );
+ if (in_array($name, $return_ok)) {
+ $name = '_' . $name;
+ return $this->$name;
+ } else {
+ $log->log(
+ '[Contributions] Unable to get proprety `' .$name . '`',
+ PEAR_LOG_WARNING
+ );
+ }
+ }
+ }
+
+ /**
+ * Global setter method
+ *
+ * @param string $name name of the property we want to assign a value to
+ * @param object $value a relevant value for the property
+ *
+ * @return void
+ */
+ public function __set($name, $value)
+ {
+ global $log;
+ if ( in_array($name, $this->pagination_fields) ) {
+ parent::__set($name, $value);
+ } else {
+ $log->log(
+ '[Contributions] Setting property `' . $name . '`',
+ PEAR_LOG_DEBUG
+ );
+
+ $forbidden = array();
+ if ( !in_array($name, $forbidden) ) {
+ $rname = '_' . $name;
+ switch($name) {
+ case 'tri':
+ $allowed_orders = array(
+ self::ORDERBY_DATE,
+ self::ORDERBY_BEGIN_DATE,
+ self::ORDERBY_END_DATE,
+ self::ORDERBY_MEMBER,
+ self::ORDERBY_TYPE,
+ self::ORDERBY_AMOUNT,
+ self::ORDERBY_DURATION
+ );
+ if ( in_array($value, $allowed_orders) ) {
+ $this->orderby = $value;
+ }
+ break;
+ default:
+ $this->$rname = $value;
+ break;
+ }
+ } else {
+ $log->log(
+ '[Contributions] Unable to set proprety `' .$name . '`',
+ PEAR_LOG_WARNING
+ );
+ }
+ }
+ }
+
+}
+?>
<p>
<label class="bline" for="type_paiement_cotis">{_T string="Payment type:"}</label>
<select name="type_paiement_cotis" id="type_paiement_cotis">
- <option value="{php}echo Contribution::PAYMENT_CASH;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_CASH')} selected="selected"{/if}>{_T string="Cash"}</option>
- <option value="{php}echo Contribution::PAYMENT_CREDITCARD;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_CREDITCARD')} selected="selected"{/if}>{_T string="Credit card"}</option>
- <option value="{php}echo Contribution::PAYMENT_CHECK;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_CHECK')} selected="selected"{/if}>{_T string="Check"}</option>
- <option value="{php}echo Contribution::PAYMENT_TRANSFER;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_TRANSFER')} selected="selected"{/if}>{_T string="Transfer"}</option>
- <option value="{php}echo Contribution::PAYMENT_PAYPAL;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_PAYPAL')} selected="selected"{/if}>{_T string="Paypal"}</option>
- <option value="{php}echo Contribution::PAYMENT_OTHER;{/php}"{if $contribution->payment_type eq constant('Contribution::PAYMENT_OTHER')} selected="selected"{/if}>{_T string="Other"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CASH;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_CASH')} selected="selected"{/if}>{_T string="Cash"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CREDITCARD;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_CREDITCARD')} selected="selected"{/if}>{_T string="Credit card"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CHECK;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_CHECK')} selected="selected"{/if}>{_T string="Check"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_TRANSFER;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_TRANSFER')} selected="selected"{/if}>{_T string="Transfer"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_PAYPAL;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_PAYPAL')} selected="selected"{/if}>{_T string="Paypal"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_OTHER;{/php}"{if $contribution->payment_type eq constant('Galette\Entity\Contribution::PAYMENT_OTHER')} selected="selected"{/if}>{_T string="Other"}</option>
</select>
</p>
<p>
</div>
<p>{_T string="NB : The mandatory fields are in"} <span class="required">{_T string="red"}</span></p>
</form>
-{/if}
\ No newline at end of file
+{/if}
<label for="payment_type_filter">{_T string="Payment type"}</label>
<select name="payment_type_filter" id="payment_type_filter">
<option value="-1">{_T string="Select"}</option>
- <option value="{php}echo Contribution::PAYMENT_CASH;{/php}"{if $contributions->payment_type_filter eq constant('Contribution::PAYMENT_CASH')} selected="selected"{/if}>{_T string="Cash"}</option>
- <option value="{php}echo Contribution::PAYMENT_CREDITCARD;{/php}"{if $contributions->payment_type_filter eq constant('Contribution::PAYMENT_CREDITCARD')} selected="selected"{/if}>{_T string="Credit card"}</option>
- <option value="{php}echo Contribution::PAYMENT_CHECK;{/php}"{if $contributions->payment_type_filter eq constant('Contribution::PAYMENT_CHECK')} selected="selected"{/if}>{_T string="Check"}</option>
- <option value="{php}echo Contribution::PAYMENT_TRANSFER;{/php}"{if $contributions->payment_type_filter eq constant('Contribution::PAYMENT_TRANSFER')} selected="selected"{/if}>{_T string="Transfer"}</option>
- <option value="{php}echo Contribution::PAYMENT_PAYPAL;{/php}"{if $contributions->payment_type_filter eq constant('Contribution::PAYMENT_PAYPAL')} selected="selected"{/if}>{_T string="Paypal"}</option>
- <option value="{php}echo Contribution::PAYMENT_OTHER;{/php}"{if $contributions->payment_type_filter === constant('Contribution::PAYMENT_OTHER')} selected="selected"{/if}>{_T string="Other"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CASH;{/php}"{if $contributions->payment_type_filter eq constant('Galette\Entity\Contribution::PAYMENT_CASH')} selected="selected"{/if}>{_T string="Cash"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CREDITCARD;{/php}"{if $contributions->payment_type_filter eq constant('Galette\Entity\Contribution::PAYMENT_CREDITCARD')} selected="selected"{/if}>{_T string="Credit card"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_CHECK;{/php}"{if $contributions->payment_type_filter eq constant('Galette\Entity\Contribution::PAYMENT_CHECK')} selected="selected"{/if}>{_T string="Check"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_TRANSFER;{/php}"{if $contributions->payment_type_filter eq constant('Galette\Entity\Contribution::PAYMENT_TRANSFER')} selected="selected"{/if}>{_T string="Transfer"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_PAYPAL;{/php}"{if $contributions->payment_type_filter eq constant('Galette\Entity\Contribution::PAYMENT_PAYPAL')} selected="selected"{/if}>{_T string="Paypal"}</option>
+ <option value="{php}echo Galette\Entity\Contribution::PAYMENT_OTHER;{/php}"{if $contributions->payment_type_filter === constant('Galette\Entity\Contribution::PAYMENT_OTHER')} selected="selected"{/if}>{_T string="Other"}</option>
</select>
<input type="submit" class="inline" value="{_T string="Filter"}"/>
<input type="submit" name="clear_filter" class="inline" value="{_T string="Clear filter"}"/>
<tr>
<th class="listing id_row">#</th>
<th class="listing left date_row">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_DATE;{/php}" class="listing">{_T string="Date"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_DATE')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_DATE;{/php}" class="listing">{_T string="Date"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_DATE')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</a>
</th>
<th class="listing left date_row">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_BEGIN_DATE;{/php}" class="listing">{_T string="Begin"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_BEGIN_DATE')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_BEGIN_DATE;{/php}" class="listing">{_T string="Begin"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_BEGIN_DATE')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</a>
</th>
<th class="listing left date_row">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_END_DATE;{/php}" class="listing">{_T string="End"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_END_DATE')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_END_DATE;{/php}" class="listing">{_T string="End"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_END_DATE')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</th>
{if ($login->isAdmin() or $login->isStaff()) and !$member}
<th class="listing left">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_MEMBER;{/php}" class="listing">{_T string="Member"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_MEMBER')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_MEMBER;{/php}" class="listing">{_T string="Member"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_MEMBER')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</th>
{/if}
<th class="listing left">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_TYPE;{/php}" class="listing">{_T string="Type"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_TYPE')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_TYPE;{/php}" class="listing">{_T string="Type"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_TYPE')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</a>
</th>
<th class="listing left">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_AMOUNT;{/php}" class="listing">{_T string="Amount"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_AMOUNT')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_AMOUNT;{/php}" class="listing">{_T string="Amount"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_AMOUNT')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</a>
</th>
<th class="listing left">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_PAYMENT_TYPE;{/php}" class="listing">{_T string="Payment type"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_PAYMENT_TYPE')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_PAYMENT_TYPE;{/php}" class="listing">{_T string="Payment type"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_PAYMENT_TYPE')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
</a>
</th>
<th class="listing left">
- <a href="gestion_contributions.php?tri={php}echo Contributions::ORDERBY_DURATION;{/php}" class="listing">{_T string="Duration"}
- {if $contributions->orderby eq constant('Contributions::ORDERBY_DURATION')}
- {if $contributions->ordered eq constant('Contributions::ORDER_ASC')}
+ <a href="gestion_contributions.php?tri={php}echo Galette\Repository\Contributions::ORDERBY_DURATION;{/php}" class="listing">{_T string="Duration"}
+ {if $contributions->orderby eq constant('Galette\Repository\Contributions::ORDERBY_DURATION')}
+ {if $contributions->ordered eq constant('Galette\Repository\Contributions::ORDER_ASC')}
<img src="{$template_subdir}images/down.png" width="10" height="6" alt=""/>
{else}
<img src="{$template_subdir}images/up.png" width="10" height="6" alt=""/>
{rdelim}
_init_contribs_page();
{rdelim});
- </script>
\ No newline at end of file
+ </script>