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