| 1 |
<?php |
| 2 |
namespace WeDevs\ERP\Accounting; |
| 3 |
|
| 4 |
use WeDevs\ERP\Framework\ERP_Settings_Page; |
| 5 |
|
| 6 |
/** |
| 7 |
* General class |
| 8 |
*/ |
| 9 |
class Settings extends ERP_Settings_Page { |
| 10 |
|
| 11 |
|
| 12 |
function __construct() { |
| 13 |
$this->id = 'accounting'; |
| 14 |
$this->label = __( 'Accounting', 'erp' ); |
| 15 |
$this->single_option = true; |
| 16 |
$this->sections = $this->get_sections(); |
| 17 |
|
| 18 |
add_action( 'erp_admin_field_ac_tax_list', [ $this, 'ac_tax_list' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get sections |
| 23 |
* |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
public function get_sections() { |
| 27 |
$sections = array( |
| 28 |
'customers' => __( 'Customers', 'erp' ), |
| 29 |
'currency_option' => __( 'Currency Settings', 'erp' ), |
| 30 |
'general' => __( 'Invoice Formatting', 'erp' ), |
| 31 |
'erp_ac_tax' => __( 'Sales Tax', 'erp' ) |
| 32 |
); |
| 33 |
|
| 34 |
return apply_filters( 'erp_get_sections_' . $this->id, $sections ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get sections fields |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function get_section_fields( $section = '' ) { |
| 43 |
|
| 44 |
$fields['general'] = array( |
| 45 |
array( 'title' => __( '', 'erp' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), |
| 46 |
|
| 47 |
array( |
| 48 |
'title' => __( 'Sales Payment', 'erp' ), |
| 49 |
'id' => 'erp_ac_payment', |
| 50 |
'type' => 'text', |
| 51 |
'default' => erp_ac_get_default_invoice_prefix( 'erp_ac_payment' ), |
| 52 |
'desc' => __( 'Sales payment invoice format. Rearrange if you like. <strong>prefix-{id}, {id}-postfix, prefix-{id}-postfix</strong>', 'erp' ) |
| 53 |
), |
| 54 |
|
| 55 |
array( |
| 56 |
'title' => __( 'Sales Invoice', 'erp' ), |
| 57 |
'id' => 'erp_ac_invoice', |
| 58 |
'type' => 'text', |
| 59 |
'default' => erp_ac_get_default_invoice_prefix( 'erp_ac_invoice' ), |
| 60 |
'desc' => __( 'Sales invoice format. Rearrange if you like. <strong>prefix-{id}, {id}-postfix, prefix-{id}-postfix</strong>', 'erp' ) |
| 61 |
), |
| 62 |
|
| 63 |
array( |
| 64 |
'title' => __( 'Expense Voucher', 'erp' ), |
| 65 |
'id' => 'erp_ac_payment_voucher', |
| 66 |
'type' => 'text', |
| 67 |
'default' => erp_ac_get_default_invoice_prefix( 'erp_ac_payment_voucher' ), |
| 68 |
'desc' => __( 'Expense voucher invoice format. Rearrange if you like. <strong>prefix-{id}, {id}-postfix, prefix-{id}-postfix</strong>', 'erp' ) |
| 69 |
), |
| 70 |
|
| 71 |
array( |
| 72 |
'title' => __( 'Expense Credit', 'erp' ), |
| 73 |
'id' => 'erp_ac_vendor_credit', |
| 74 |
'type' => 'text', |
| 75 |
'default' => erp_ac_get_default_invoice_prefix( 'erp_ac_vendor_credit' ), |
| 76 |
'desc' => __( 'Expense credit invoice format. Rearrange if you like. <strong>prefix-{id}, {id}-postfix, prefix-{id}-postfix</strong>', 'erp' ) |
| 77 |
), |
| 78 |
|
| 79 |
array( |
| 80 |
'title' => __( 'Journal', 'erp' ), |
| 81 |
'id' => 'erp_ac_journal', |
| 82 |
'type' => 'text', |
| 83 |
'default' => erp_ac_get_default_invoice_prefix( 'erp_ac_journal' ), |
| 84 |
'desc' => __( 'Journal invoice format. Rearrange if you like. <strong>prefix-{id}, {id}-postfix, prefix-{id}-postfix</strong>', 'erp' ) |
| 85 |
), |
| 86 |
|
| 87 |
array( 'type' => 'sectionend', 'id' => 'script_styling_options' ), |
| 88 |
); |
| 89 |
|
| 90 |
$fields['customers'] = array( |
| 91 |
array( 'title' => __( '', 'erp' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), |
| 92 |
|
| 93 |
array( |
| 94 |
'title' => __( 'Customer Settings', 'erp' ), |
| 95 |
'type' => 'title', |
| 96 |
'desc' => __( 'Settings for Accounting customers.', 'erp' ), |
| 97 |
'id' => 'customer_settings' |
| 98 |
), |
| 99 |
|
| 100 |
array( |
| 101 |
'title' => __( 'Auto Import', 'erp' ), |
| 102 |
'id' => 'customer_auto_import', |
| 103 |
'type' => 'select', |
| 104 |
'desc' => __( 'Allow to auto import new crm user as accounting customer.', 'erp' ), |
| 105 |
'options' => [ 1 => __('On', 'erp'), 0 => __( 'Off', 'erp') ], |
| 106 |
'default' => 0, |
| 107 |
), |
| 108 |
|
| 109 |
array( |
| 110 |
'title' => __( 'Import User\'s From', 'erp' ), |
| 111 |
'id' => 'crm_user_type', |
| 112 |
'type' => 'multicheck', |
| 113 |
'desc' => __( 'Selected user type are considered to auto import.', 'erp' ), |
| 114 |
'options' => [ 'contact' => __('Contact', 'erp'), 'company' => __( 'Company', 'erp') ], |
| 115 |
'default' => [] |
| 116 |
), |
| 117 |
|
| 118 |
array( |
| 119 |
'type' => 'sectionend', |
| 120 |
'id' => 'script_styling_options' |
| 121 |
) |
| 122 |
); |
| 123 |
|
| 124 |
$fields['currency_option'] = array( |
| 125 |
|
| 126 |
array( 'title' => __( '', 'erp' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), |
| 127 |
|
| 128 |
array( |
| 129 |
'title' => __( 'Currency Position', 'erp' ), |
| 130 |
'id' => 'erp_ac_currency_position', |
| 131 |
'type' => 'select', |
| 132 |
'class' => 'erp-select2', |
| 133 |
'options' => array( |
| 134 |
'left' => sprintf( '%1$s (%2$s99.99)', __( 'Left', 'erp' ), erp_ac_get_currency_symbol() ), |
| 135 |
'right' => sprintf( '%1$s (99.99%2$s)', __( 'Right', 'erp' ), erp_ac_get_currency_symbol() ), |
| 136 |
'left_space' => sprintf( '%1$s (%2$s 99.99)', __( 'Left with space', 'erp' ), erp_ac_get_currency_symbol() ), |
| 137 |
'right_space' => sprintf( '%1$s (99.99 %2$s)', __( 'Right with space', 'erp' ), erp_ac_get_currency_symbol() ), |
| 138 |
), |
| 139 |
), |
| 140 |
|
| 141 |
array( |
| 142 |
'title' => __( 'Thousand Separator', 'erp' ), |
| 143 |
'type' => 'text', |
| 144 |
'id' => 'erp_ac_th_separator', |
| 145 |
'default' => ',' |
| 146 |
), |
| 147 |
|
| 148 |
array( |
| 149 |
'title' => __( 'Decimal Separator', 'erp' ), |
| 150 |
'id' => 'erp_ac_de_separator', |
| 151 |
'type' => 'text', |
| 152 |
'default' => '.' |
| 153 |
), |
| 154 |
|
| 155 |
array( |
| 156 |
'title' => __( 'Number of Decimals', 'erp' ), |
| 157 |
'type' => 'text', |
| 158 |
'id' => 'erp_ac_nm_decimal', |
| 159 |
'default' => 2 |
| 160 |
), |
| 161 |
|
| 162 |
array( |
| 163 |
'title' => __( 'PDF Theme Color', 'erp' ), |
| 164 |
'type' => 'text', |
| 165 |
'id' => 'erp_ac_pdf_theme_color', |
| 166 |
'class' => 'erp-color-picker' |
| 167 |
), |
| 168 |
|
| 169 |
array( 'type' => 'sectionend', 'id' => 'script_styling_options' ), |
| 170 |
|
| 171 |
); // End general settings |
| 172 |
|
| 173 |
$fields['erp_ac_tax'] = array( |
| 174 |
array( |
| 175 |
'title' => __( 'Sales Taxes', 'erp' ), |
| 176 |
'type' => 'title', |
| 177 |
'desc' => __( '', 'erp' ), |
| 178 |
'id' => 'erp-ac-tax-options' |
| 179 |
), |
| 180 |
array( |
| 181 |
'type' => 'ac_tax_list' |
| 182 |
), |
| 183 |
array( 'type' => 'sectionend', 'id' => 'script_styling_optionsjj' ), |
| 184 |
); |
| 185 |
|
| 186 |
$fields['erp_ac_tax']['submit_button'] = false; |
| 187 |
|
| 188 |
$section = $section === false ? $fields['checkout'] : isset( $fields[$section] ) ? $fields[$section] : array(); |
| 189 |
|
| 190 |
return apply_filters( 'erp_ac_settings_section_fields_' . $this->id , $section ); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Get sections fields |
| 195 |
* |
| 196 |
* @return array |
| 197 |
*/ |
| 198 |
public function get_settings() { |
| 199 |
|
| 200 |
$fields = array( |
| 201 |
|
| 202 |
array( 'title' => __( 'Accounting Settings', 'erp' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), |
| 203 |
|
| 204 |
array( |
| 205 |
'title' => __( 'Home Currency', 'erp' ), |
| 206 |
'id' => 'base_currency', |
| 207 |
'desc' => __( 'The base currency of the system.', 'erp' ), |
| 208 |
'type' => 'select', |
| 209 |
'options' => erp_get_currencies() |
| 210 |
), |
| 211 |
|
| 212 |
array( 'type' => 'sectionend', 'id' => 'script_styling_options' ), |
| 213 |
|
| 214 |
); // End general settings |
| 215 |
|
| 216 |
|
| 217 |
return apply_filters( 'erp_ac_settings_general', $fields ); |
| 218 |
} |
| 219 |
|
| 220 |
function ac_tax_list() { |
| 221 |
require_once WPERP_ACCOUNTING_VIEWS . '/settings/tax.php'; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
return new Settings(); |
| 226 |
|