Merge pull request #4979 from xurizaemon/codingstandards-12
[civicrm-core.git] / CRM / Admin / Form / Preferences / Contribute.php
CommitLineData
d75f2f47 1<?php
9d4da082
RK
2
3/**
4 * This class generates form components for the display preferences
5 *
6 */
7class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences {
1be9403d 8 /**
c490a46a 9 * Process the form submission
1be9403d 10 *
1be9403d 11 *
12 * @return void
13 */
00be9182 14 public function preProcess() {
fff0f449 15 $config = CRM_Core_Config::singleton();
9d4da082
RK
16 CRM_Utils_System::setTitle(ts('CiviContribute Component Settings'));
17 $this->_varNames = array(
9d72cede 18 CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME => array(
353ffa53
TO
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'),
9d72cede 46 ),
353ffa53
TO
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]'),
fff0f449 79 ),
80 ),
353ffa53 81 ),
fff0f449 82 );
9d4da082
RK
83 parent::preProcess();
84 }
d75f2f47 85
9d4da082 86 /**
c490a46a 87 * Build the form object
9d4da082
RK
88 *
89 * @return void
9d4da082 90 */
00be9182 91 public function buildQuickForm() {
e0d683cf 92 $this->add('checkbox', 'invoicing', ts('Enable Tax and Invoicing'));
9d4da082
RK
93 parent::buildQuickForm();
94 }
1be9403d 95
96 /**
c490a46a 97 * Set default values for the form.
1be9403d 98 * default values are retrieved from the database
99 *
1be9403d 100 *
101 * @return void
102 */
00be9182 103 public function setDefaultValues() {
9d72cede 104 $defaults = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
1be9403d 105 return $defaults;
106 }
107
108 /**
100fef9d 109 * Process the form after the input has been submitted and validated
1be9403d 110 *
1be9403d 111 *
112 * @return void
113 */
114 public function postProcess() {
115 // store the submitted values in an array
116 $params = $this->controller->exportValues($this->_name);
fff0f449 117 unset($params['qfKey']);
118 unset($params['entryURL']);
1be9403d 119 $setInvoiceSettings = CRM_Core_BAO_Setting::setItem($params, CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
e0d683cf
PB
120
121 // to set default value for 'Invoices / Credit Notes' checkbox on display preferences
122 $values = CRM_Core_BAO_Setting::getItem("CiviCRM Preferences");
9148c277 123 $optionValues = CRM_Core_OptionGroup::values('user_dashboard_options', FALSE, FALSE, FALSE, NULL, 'name');
e0d683cf
PB
124 $setKey = array_search('Invoices / Credit Notes', $optionValues);
125
126 if (isset($params['invoicing'])) {
127 $value = array($setKey => $optionValues[$setKey]);
9d72cede
EM
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');
e0d683cf
PB
133 }
134 else {
135 $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1));
9d72cede 136 $invoiceKey = array_search($setKey, $setting);
e0d683cf 137 unset($setting[$invoiceKey]);
9d72cede
EM
138 $settingName = CRM_Core_DAO::VALUE_SEPARATOR .
139 implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) .
140 CRM_Core_DAO::VALUE_SEPARATOR;
e0d683cf
PB
141 CRM_Core_BAO_Setting::setItem($settingName, 'CiviCRM Preferences', 'user_dashboard_options');
142 }
1be9403d 143 }
9d4da082 144}