Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * This class generates form components for Financial Type | |
39 | * | |
40 | */ | |
41 | class CRM_Financial_Form_FinancialType extends CRM_Contribute_Form { | |
42 | ||
43 | /** | |
44 | * Function to build the form | |
45 | * | |
46 | * @return None | |
47 | * @access public | |
48 | */ | |
49 | public function buildQuickForm( ) { | |
50 | parent::buildQuickForm( ); | |
51 | ||
52 | $this->_id = CRM_Utils_Request::retrieve( 'id' , 'Positive', $this ); | |
53 | if ( $this->_id ) { | |
54 | $this->_title = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $this->_id, 'name' ); | |
55 | CRM_Utils_System::setTitle( $this->_title .' - '.ts( 'Financial Type' ) ); | |
56 | } | |
57 | if ($this->_action & CRM_Core_Action::DELETE ) { | |
58 | return; | |
59 | } | |
60 | $this->applyFilter('__ALL__', 'trim'); | |
61 | $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_FinancialType', 'name' ),true); | |
62 | ||
63 | $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_FinancialType', 'description' ) ); | |
64 | ||
65 | $this->add('checkbox', 'is_deductible', ts('Tax-Deductible?'), CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_FinancialType', 'is_deductible' ) ); | |
66 | $this->add('checkbox', 'is_active', ts('Enabled?'), CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_FinancialType', 'is_active' ) ); | |
67 | $this->add('checkbox', 'is_reserved', ts('Reserved?'), CRM_Core_DAO::getAttribute( 'CRM_Financial_DAO_FinancialType', 'is_reserved' ) ); | |
68 | if ( $this->_action == CRM_Core_Action::UPDATE ) | |
69 | $this->assign( 'aid', $this->_id ); | |
70 | if ( $this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $this->_id, 'is_reserved','vid' )) { | |
71 | $this->freeze(array( 'is_active' )); | |
72 | } | |
73 | ||
74 | //$this->addFormRule( array( 'CRM_Financial_Form_FinancialType', 'formRule'), $this ); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Function to process the form | |
79 | * | |
80 | * @access public | |
81 | * @return None | |
82 | */ | |
83 | public function postProcess() { | |
84 | if ($this->_action & CRM_Core_Action::DELETE) { | |
85 | $errors = CRM_Financial_BAO_FinancialType::del($this->_id); | |
86 | if (!empty($errors)) { | |
87 | $message = ts('This item cannot be deleted.') . $errors['error_message']; | |
88 | CRM_Core_Session::setStatus($message); | |
89 | return CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/admin/financial/financialType', "reset=1&action=browse" )); | |
90 | } | |
91 | CRM_Core_Session::setStatus( ts('Selected financial type has been deleted.') ); | |
92 | } else { | |
93 | $params = $ids = array( ); | |
94 | // store the submitted values in an array | |
95 | $params = $this->exportValues(); | |
96 | ||
97 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
98 | $ids['financialType'] = $this->_id; | |
99 | } | |
100 | ||
101 | $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); | |
102 | if ( $this->_action & CRM_Core_Action::UPDATE ) { | |
103 | $url = CRM_Utils_System::url( 'civicrm/admin/financial/financialType', 'reset=1&action=browse'); | |
104 | CRM_Core_Session::setStatus( ts('The financial type \'%1\' has been saved.', array( 1 => $financialType->name )) ); | |
105 | } else { | |
106 | $url = CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts', 'reset=1&action=add&aid=' . $financialType->id); | |
107 | CRM_Core_Session::setStatus( ts('The financial type \'%1\' has been added. You can add Financial Accounts to this Financial Type now.', array( 1 => $financialType->name )) ); | |
108 | } | |
109 | ||
110 | $session = CRM_Core_Session::singleton( ); | |
111 | $session->replaceUserContext($url); | |
112 | } | |
113 | } | |
114 | } |