Merge pull request #4943 from rohankatkar/batch-9
[civicrm-core.git] / CRM / Admin / Form / Preferences / Contribute.php
1 <?php
2
3 /**
4 * This class generates form components for the display preferences
5 *
6 */
7 class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences {
8 /**
9 * Process the form submission
10 *
11 *
12 * @return void
13 */
14 public function preProcess() {
15 $config = CRM_Core_Config::singleton();
16 CRM_Utils_System::setTitle(ts('CiviContribute Component Settings'));
17 $this->_varNames = array(
18 CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array(
19 'invoice_prefix' => array(
20 'html_type' => 'text',
21 'title' => ts('Invoice Prefix'),
22 'weight' => 1,
23 'description' => ts('Enter prefix to be display on PDF for invoice'),
24 ),
25 'credit_notes_prefix' => array(
26 'html_type' => 'text',
27 'title' => ts('Credit Notes Prefix'),
28 'weight' => 2,
29 'description' => ts('Enter prefix to be display on PDF for credit notes.'),
30 ),
31 'due_date' => array(
32 'html_type' => 'text',
33 'title' => ts('Due Date'),
34 'weight' => 3,
35 ),
36 'due_date_period' => array(
37 'html_type' => 'select',
38 'title' => ts('For transmission'),
39 'weight' => 4,
40 'description' => ts('Select the interval for due date.'),
41 'option_values' => array(
42 'select' => ts('- select -'),
43 'days' => ts('Days'),
44 'months' => ts('Months'),
45 'years' => ts('Years'),
46 ),
47 ),
48 'notes' => array(
49 'html_type' => 'wysiwyg',
50 'title' => ts('Notes or Standard Terms'),
51 'weight' => 5,
52 'description' => ts('Enter note or message to be displayed on PDF invoice or credit notes '),
53 'attributes' => array('rows' => 2, 'cols' => 40),
54 ),
55 'is_email_pdf' => array(
56 'html_type' => 'checkbox',
57 'title' => ts('Automatically email invoice when user purchases online'),
58 'weight' => 6,
59 ),
60 'tax_term' => array(
61 'html_type' => 'text',
62 'title' => ts('Tax Term'),
63 'weight' => 7,
64 ),
65 'tax_display_settings' => array(
66 'html_type' => 'select',
67 'title' => ts('Tax Display Settings'),
68 'weight' => 8,
69 'option_values' => array(
70 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' .
71 $config->defaultCurrencySymbol . '120.00'),
72 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' .
73 $config->defaultCurrencySymbol .
74 '120.00 (includes [tax term] of ' .
75 $config->defaultCurrencySymbol . '20.00)'),
76 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' .
77 $config->defaultCurrencySymbol . '100.00 + ' .
78 $config->defaultCurrencySymbol . '20.00 [tax term]'),
79 ),
80 ),
81 ),
82 );
83 parent::preProcess();
84 }
85
86 /**
87 * Build the form object
88 *
89 * @return void
90 */
91 public function buildQuickForm() {
92 $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing'));
93 parent::buildQuickForm();
94 }
95
96 /**
97 * Set default values for the form.
98 * default values are retrieved from the database
99 *
100 *
101 * @return void
102 */
103 public function setDefaultValues() {
104 $defaults = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
105 return $defaults;
106 }
107
108 /**
109 * Process the form after the input has been submitted and validated
110 *
111 *
112 * @return void
113 */
114 public function postProcess() {
115 // store the submitted values in an array
116 $params = $this->controller->exportValues($this->_name);
117 unset($params['qfKey']);
118 unset($params['entryURL']);
119 $setInvoiceSettings = CRM_Core_BAO_Setting::setItem($params, CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
120
121 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
122 $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences");
123 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
124 $setKey = array_search('Invoices / Credit Notes', $optionValues);
125
126 if (isset($params['invoicing'])) {
127 $value = array($setKey => $optionValues[$setKey]);
128 $setInvoice = CRM_Core_DAO::VALUE_SEPARATOR .
129 implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value)) .
130 CRM_Core_DAO::VALUE_SEPARATOR;
131 CRM_Core_BAO_Setting::setItem($values['user_dashboard_options'] .
132 $setInvoice, 'CiviCRM Preferences', 'user_dashboard_options');
133 }
134 else {
135 $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1));
136 $invoiceKey = array_search($setKey, $setting);
137 unset($setting[$invoiceKey]);
138 $settingName = CRM_Core_DAO::VALUE_SEPARATOR .
139 implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) .
140 CRM_Core_DAO::VALUE_SEPARATOR;
141 CRM_Core_BAO_Setting::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options');
142 }
143 }
144 }