PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / modules / accounting / includes / class-admin-menu.php

class-admin-menu.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.3.13, at modules/accounting/includes/class-admin-menu.php

608 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WeDevs\ERP\Accounting;
3
4 /**
5 * Admin Menu
6 */
7 class Admin_Menu {
8
9 /**
10 * Kick-in the class
11 */
12 public function __construct() {
13 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
14 }
15
16 /**
17 * Register the admin menu
18 *
19 * @return void
20 */
21 public function admin_menu() {
22 $dashboard = 'erp_ac_view_dashboard';
23 $customer = 'erp_ac_view_customer';
24 $vendor = 'erp_ac_view_vendor';
25 $sale = 'erp_ac_view_sale';
26 $expense = 'erp_ac_view_expense';
27 $account_charts = 'erp_ac_view_account_lists';
28 $bank = 'erp_ac_view_bank_accounts';
29 $journal = 'erp_ac_view_journal';
30 $reports = 'erp_ac_view_reports';
31
32 add_menu_page( __( 'Accounting', 'erp' ), 'Accounting', $dashboard, 'erp-accounting', array( $this, 'dashboard_page' ), 'dashicons-chart-pie', null );
33
34 $dashboard = add_submenu_page( 'erp-accounting', __( 'Dashboard', 'erp' ), __( 'Dashboard', 'erp' ), $dashboard, 'erp-accounting', array( $this, 'dashboard_page' ) );
35 $customer = add_submenu_page( 'erp-accounting', __( 'Customers', 'erp' ), __( 'Customers', 'erp' ), $customer, 'erp-accounting-customers', array( $this, 'page_customers' ) );
36 $vendor = add_submenu_page( 'erp-accounting', __( 'Vendors', 'erp' ), __( 'Vendors', 'erp' ), $vendor, 'erp-accounting-vendors', array( $this, 'page_vendors' ) );
37 $sale = add_submenu_page( 'erp-accounting', __( 'Sales', 'erp' ), __( 'Sales', 'erp' ), $sale, 'erp-accounting-sales', array( $this, 'page_sales' ) );
38 $expense = add_submenu_page( 'erp-accounting', __( 'Expenses', 'erp' ), __( 'Expenses', 'erp' ), $expense, 'erp-accounting-expense', array( $this, 'page_expenses' ) );
39 $account_charts = add_submenu_page( 'erp-accounting', __( 'Chart of Accounts', 'erp' ), __( 'Chart of Accounts', 'erp' ), $account_charts, 'erp-accounting-charts', array( $this, 'page_chart_of_accounting' ) );
40 $bank = add_submenu_page( 'erp-accounting', __( 'Bank Accounts', 'erp' ), __( 'Bank Accounts', 'erp' ), $bank, 'erp-accounting-bank', array( $this, 'page_bank' ) );
41 $journal = add_submenu_page( 'erp-accounting', __( 'Journal Entry', 'erp' ), __( 'Journal Entry', 'erp' ), $journal, 'erp-accounting-journal', array( $this, 'page_journal_entry' ) );
42 $reports = add_submenu_page( 'erp-accounting', __( 'Reports', 'erp' ), __( 'Reports', 'erp' ), $reports, 'erp-accounting-reports', array( $this, 'page_reports' ) );
43
44 //Help page
45 add_submenu_page( 'erp-accounting', __( 'Help', 'erp' ), __( '<span style="color:#f18500">Help</span>', 'erp' ), 'erp_ac_view_dashboard', 'erp-ac-help', array( $this, 'help_page' ) );
46
47 add_action( 'admin_print_styles-' . $dashboard, array( $this, 'dashboard_script' ) );
48 add_action( 'admin_print_styles-' . $customer, array( $this, 'sales_chart_script' ) );
49 add_action( 'admin_print_styles-' . $vendor, array( $this, 'sales_chart_script' ) );
50 add_action( 'admin_print_styles-' . $bank, array( $this, 'bank_script' ) );
51 add_action( 'admin_print_styles-' . $sale, array( $this, 'sales_chart_script' ) );
52 add_action( 'admin_print_styles-' . $expense, array( $this, 'expense_chart_script' ) );
53 add_action( 'admin_print_styles-' . $journal, array( $this, 'journal_script' ) );
54 add_action( 'admin_print_styles-' . $account_charts, array( $this, 'chart_account_script' ) );
55 add_action( 'admin_print_styles-' . $reports, array( $this, 'reports_script' ) );
56 add_action( 'admin_print_styles-' . 'erp-settings_page_erp-settings', array( $this, 'accounting_settings_script' ) );
57 }
58
59 /**
60 * Load dashboard scripts
61 *
62 * @since 1.1.4
63 *
64 * @return void
65 */
66 public function dashboard_script() {
67 $this->chart_script();
68 $this->common_scripts();
69 }
70
71 /**
72 * Load Bank page scripts
73 *
74 * @since 1.1.4
75 *
76 * @return void
77 */
78 public function bank_script() {
79 $this->chart_script();
80 $this->common_scripts();
81 }
82
83 /**
84 * Load sales chart scripts
85 *
86 * @since 1.1.4
87 *
88 * @return void
89 */
90 public function sales_chart_script() {
91 $this->chart_script();
92 $this->common_scripts();
93 wp_localize_script( 'wp-erp-ac-js', 'erp_ac_tax', [ 'rate' => erp_ac_get_tax_info() ] );
94 }
95
96 /**
97 * Load expense chart scripts
98 *
99 * @since 1.1.4
100 *
101 * @return void
102 */
103 public function expense_chart_script() {
104 $this->chart_script();
105 $this->common_scripts();
106 wp_localize_script( 'wp-erp-ac-js', 'erp_ac_tax', [ 'rate' => erp_ac_get_tax_info() ] );
107 }
108
109 /**
110 * Load Journal scripts
111 *
112 * @since 1.1.4
113 *
114 * @return void
115 */
116 public function journal_script() {
117 $this->common_scripts();
118 }
119
120 /**
121 * Load chart of account scripts
122 *
123 * @since 1.1.4
124 *
125 * @return void
126 */
127 public function chart_account_script() {
128 $this->common_scripts();
129 }
130
131 /**
132 * Load account settings in ERP Settings menu scripts
133 *
134 * @since 1.1.4
135 *
136 * @return void
137 */
138 public function accounting_settings_script() {
139 if ( isset( $_GET['tab'] ) && 'accounting' == $_GET['tab'] ) {
140 $this->common_scripts();
141 }
142 }
143
144 /**
145 * Load Reports scripts
146 *
147 * @since 1.1.4
148 *
149 * @return void
150 */
151 public function reports_script() {
152 $this->common_scripts();
153 }
154
155 /**
156 * Load all chart scripts
157 *
158 * @since 1.1.4
159 *
160 * @return void
161 */
162 public function chart_script() {
163 wp_enqueue_script( 'plupload-handlers' );
164 wp_enqueue_script( 'erp-file-upload' );
165 wp_enqueue_script( 'erp-flotchart' );
166 wp_enqueue_script( 'erp-flotchart-resize' );
167 wp_enqueue_script( 'erp-flotchart-pie' );
168 wp_enqueue_script( 'erp-flotchart-time' );
169 wp_enqueue_script( 'erp-flotchart-tooltip' );
170 wp_enqueue_script( 'erp-flotchart-orerbars' );
171 wp_enqueue_script( 'erp-flotchart-axislables' );
172 wp_enqueue_script( 'erp-flotchart-navigate' );
173 wp_enqueue_script('erp-flotchart-selection');
174 }
175
176 /**
177 * Load common scripts
178 *
179 * @since 1.1.4
180 *
181 * @return void
182 */
183 public function common_scripts() {
184 $erp_ac_de_separator = erp_get_option('erp_ac_de_separator');
185 $erp_ac_th_separator = erp_get_option('erp_ac_th_separator');
186 $erp_ac_nm_decimal = erp_get_option('erp_ac_nm_decimal');
187
188 // styles
189 wp_enqueue_style('erp-tiptip');
190 wp_enqueue_style( 'erp-sweetalert' );
191 wp_enqueue_style( 'erp-tether-drop-theme' );
192 wp_enqueue_style( 'wp-erp-ac-styles', WPERP_ASSETS . '/css/accounting.css', array( 'wp-color-picker' ), WPERP_VERSION );
193
194 // scripts
195 wp_enqueue_script( 'erp-tiptip' );
196 wp_enqueue_script( 'erp-sweetalert' );
197 wp_enqueue_script( 'erp-tether-main' );
198 wp_enqueue_script( 'erp-tether-drop' );
199 wp_enqueue_script( 'erp-clipboard' );
200 wp_enqueue_script( 'accounting', WPERP_ACCOUNTING_ASSETS . '/js/accounting.min.js', array( 'jquery' ), date( 'Ymd' ), true );
201 wp_enqueue_script( 'wp-erp-ac-js', WPERP_ACCOUNTING_ASSETS . '/js/erp-accounting.js', array( 'jquery', 'wp-color-picker', 'erp-tiptip' ), date( 'Ymd' ), true );
202
203 wp_localize_script( 'wp-erp-ac-js', 'ERP_AC', array(
204 'nonce' => wp_create_nonce( 'erp-ac-nonce' ),
205 'emailConfirm' => __( 'Sent', 'erp' ),
206 'emailConfirmMsg' => __( 'The email has been sent', 'erp' ),
207 'confirmMsg' => __( 'You are about to permanently delete this item.', 'erp' ),
208 'copied' => __( 'Copied', 'erp' ),
209 'ajaxurl' => admin_url( 'admin-ajax.php' ),
210 'decimal_separator' => empty( $erp_ac_de_separator ) ? '.' : erp_get_option('erp_ac_de_separator'),
211 'thousand_separator' => empty( $erp_ac_th_separator ) ? ',' : erp_get_option('erp_ac_th_separator'),
212 'number_decimal' => empty( $erp_ac_nm_decimal ) ? '2' : erp_get_option('erp_ac_nm_decimal'),
213 'currency' => erp_get_option('erp_ac_currency'),
214 'symbol' => erp_ac_get_currency_symbol(),
215 'message' => erp_ac_message(),
216 'plupload' => array(
217 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'erp_ac_featured_img' ),
218 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
219 'filters' => array( array('title' => __( 'Allowed Files', 'erp' ), 'extensions' => '*')),
220 'multipart' => true,
221 'urlstream_upload' => true,
222 )
223 ));
224 }
225
226 /**
227 * Callback for dashboard view page
228 *
229 * @since 1.0
230 *
231 * @return void
232 */
233 public function dashboard_page() {
234 include dirname( __FILE__ ) . '/views/dashboard.php';
235 }
236
237 /**
238 * Render page sales view page
239 *
240 * @since 1.0
241 *
242 * @return void
243 */
244 public function page_sales() {
245 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
246 $type = isset( $_GET['type'] ) ? $_GET['type'] : 'pv';
247 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
248 $template = '';
249
250 switch ($action) {
251 case 'new':
252
253 if ( $type == 'invoice' && ( erp_ac_create_sales_invoice() || erp_ac_publish_sales_invoice() ) ) {
254 $template = dirname( __FILE__ ) . '/views/sales/invoice-new.php';
255 } else if ( $type == 'payment' && ( erp_ac_create_sales_payment() || erp_ac_publish_sales_payment() ) ) {
256 $template = dirname( __FILE__ ) . '/views/sales/payment-new.php';
257 }else {
258 $template = apply_filters( 'erp_ac_invoice_transaction_template', $template );
259 }
260
261 break;
262
263 case 'view':
264 $transaction = Model\Transaction::find( $id );
265
266 if ( $transaction->form_type == 'invoice' ) {
267 $template = dirname( __FILE__ ) . '/views/sales/invoice-single.php';
268 } else {
269 $template = dirname( __FILE__ ) . '/views/sales/payment-single.php';
270 }
271
272 break;
273
274 default:
275 $template = dirname( __FILE__ ) . '/views/sales/transaction-list.php';
276 break;
277 }
278
279 if ( file_exists( $template ) ) {
280 include $template;
281 } else {
282 echo sprintf( '<h1>%s</h1>', __( 'You do not have sufficient permissions to access this page.', 'erp' ) );
283 }
284 }
285
286 /**
287 * Render page expense page
288 *
289 * @since 1.0
290 *
291 * @return void
292 */
293 public function page_expenses() {
294 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
295 $type = isset( $_GET['type'] ) ? $_GET['type'] : 'pv';
296 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
297 $template = '';
298
299 switch ($action) {
300 case 'new':
301
302 if ( $type == 'payment_voucher' && ( erp_ac_create_expenses_voucher() || erp_ac_publish_expenses_voucher() ) ) {
303
304 $template = dirname( __FILE__ ) . '/views/expense/payment-voucher.php';
305
306 } else if ( $type == 'vendor_credit' && ( erp_ac_create_expenses_credit() || erp_ac_publish_expenses_credit() ) ) {
307
308 $template = dirname( __FILE__ ) . '/views/expense/vendor-credit.php';
309
310 } else {
311
312 $template = apply_filters( 'erp_ac_sales_transaction_template', $template );
313
314 }
315
316 break;
317
318 case 'view':
319 $transaction = Model\Transaction::find( $id );
320
321 if ( $transaction->form_type == 'payment_voucher' ) {
322 $template = dirname( __FILE__ ) . '/views/expense/payment-voucher-single.php';
323 } else {
324 $template = dirname( __FILE__ ) . '/views/expense/vendor-credit-single.php';
325 }
326
327 break;
328
329 default:
330 $template = dirname( __FILE__ ) . '/views/expense/transaction-list.php';
331 break;
332 }
333
334 if ( file_exists( $template ) ) {
335 include $template;
336 } else {
337 echo sprintf( '<h1>%s</h1>', __( 'You do not have sufficient permissions to access this page.', 'erp' ) );
338 }
339 }
340
341 /**
342 * Render page chart accounting page
343 *
344 * @since 1.0
345 *
346 * @return void
347 */
348 public function page_chart_of_accounting() {
349 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
350 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
351 $template = '';
352
353 switch ($action) {
354 case 'view':
355 if ( erp_ac_view_single_account() ) {
356 $ledger = Model\Ledger::find( $id );
357
358 $template = dirname( __FILE__ ) . '/views/accounts/single.php';
359 }
360 break;
361
362 case 'edit':
363 if ( erp_ac_edit_account() ) {
364 $template = dirname( __FILE__ ) . '/views/accounts/edit.php';
365 }
366 break;
367
368 case 'new':
369 if ( erp_ac_create_account() ) {
370 $template = dirname( __FILE__ ) . '/views/accounts/new.php';
371 }
372 break;
373
374 default:
375 $template = dirname( __FILE__ ) . '/views/chart-of-accounts.php';
376 break;
377 }
378
379 if ( file_exists( $template ) ) {
380 include $template;
381 } else {
382 echo sprintf( '<h1>%s</h1>', __( 'You do not have sufficient permissions to access this page.', 'erp' ) );
383 }
384 }
385
386 /**
387 * Render bank page
388 *
389 * @since 1.0
390 *
391 * @return void
392 */
393 public function page_bank() {
394 $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
395 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
396
397 switch ( $action ) {
398 case 'view':
399 $transaction = Model\Transaction::find( $id );
400 $template = dirname( __FILE__ ) . '/views/bank/invoice.php';
401 break;
402 default:
403 $template = dirname( __FILE__ ) . '/views/bank/bank.php';
404 break;
405 }
406
407 if ( file_exists( $template ) ) {
408 include $template;
409 }
410 }
411
412 /**
413 * Render page reports
414 *
415 * @since 1.0
416 *
417 * @return void
418 */
419 public function page_reports() {
420 $type = isset( $_GET['type'] ) ? $_GET['type'] : '';
421 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
422 $limit = 20;
423 $offset = ( $pagenum - 1 ) * $limit;
424
425
426 switch ( $type ) {
427 case 'trial-balance':
428 $template = dirname( __FILE__ ) . '/views/reports/trial-balance.php';
429 break;
430
431 case 'sales-tax':
432
433 $start = ! empty( $_GET['start'] ) ? $_GET['start'] : date( 'Y-m-d', strtotime( erp_financial_start_date() ) );
434 $end = ! empty( $_GET['end'] ) ? $_GET['end'] : date( 'Y-m-d', strtotime( erp_financial_end_date() ) );
435
436 if ( isset( $_GET['action'] ) && intval( $_GET['id'] ) ) {
437 $tax_id = $_GET['id'];
438 $taxs = erp_ac_normarlize_individual_tax( [ 'start' => $start, 'end' => $end, 'tax_id' => [$_GET['id']], 'offset' => $offset, 'number' => $limit] );
439 //$taxs = $taxs['individuals'][$_GET['id']];
440 $count = erp_ac_get_sales_tax_report_count( ['tax_id' => [$_GET['id']] ] );
441 $taxinfo = erp_ac_get_tax_info();
442
443 $template = dirname( __FILE__ ) . '/views/reports/tax/single-sales-tax.php';
444 } else {
445 $taxs = erp_ac_normarlize_tax_from_transaction( [ 'start' => $start, 'end' => $end ] );
446 $template = dirname( __FILE__ ) . '/views/reports/tax/sales-tax.php';
447 }
448 break;
449
450 case 'income-statement':
451 $template = dirname( __FILE__ ) . '/views/reports/income-statement/statement.php';
452 break;
453
454 case 'balance-sheet':
455 $template = dirname( __FILE__ ) . '/views/reports/balance-sheet/balance-sheet.php';
456 break;
457
458 default:
459 $template = dirname( __FILE__ ) . '/views/reports.php';
460 break;
461 }
462
463 $template = apply_filters( 'erp_ac_reporting_pages', $template, $type );
464
465 if ( file_exists( $template ) ) {
466 include $template;
467 }
468 }
469
470 /**
471 * Render journal entry page
472 *
473 * @since 1.0
474 *
475 * @return void
476 */
477 public function page_journal_entry() {
478 $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
479 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
480 $template = '';
481
482 switch ( $action ) {
483 case 'view':
484 $transaction = Model\Transaction::find( $id );
485 $template = dirname( __FILE__ ) . '/views/journal/single.php';
486 break;
487
488 case 'new':
489 if ( erp_ac_create_journal() ) {
490 $journal_id = isset( $_GET['journal_id'] ) ? intval( $_GET['journal_id'] ) : false;
491 $journal = [];
492
493 if ( $journal_id ) {
494 $journal = erp_ac_get_transaction( $journal_id, [
495 'join' => ['journals', 'items'],
496 'type' => 'journal'
497 ]);
498 }
499
500 $template = dirname( __FILE__ ) . '/views/journal/new.php';
501 }
502 break;
503
504 default:
505 $template = dirname( __FILE__ ) . '/views/journal/list.php';
506 break;
507 }
508
509 if ( file_exists( $template ) ) {
510 include $template;
511 } else {
512 echo sprintf( '<h1>%s</h1>', __( 'You do not have sufficient permissions to access this page.', 'erp' ) );
513 }
514 }
515
516 /**
517 * Handles the plugin page
518 *
519 * @return void
520 */
521 public function page_customers() {
522 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
523 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
524 $template = '';
525
526 switch ($action) {
527 case 'view':
528 if ( erp_ac_current_user_can_view_single_customer() ) {
529 $customer = new \WeDevs\ERP\People( $id );
530 $template = dirname( __FILE__ ) . '/views/customer/single.php';
531 }
532 break;
533
534 case 'edit':
535 $customer = new \WeDevs\ERP\People( $id );
536 if ( erp_ac_current_user_can_edit_customer( $customer->created_by ) ) {
537 $template = dirname( __FILE__ ) . '/views/customer/edit.php';
538 }
539 break;
540
541 case 'new':
542 if ( erp_ac_create_customer() ) {
543 $template = dirname( __FILE__ ) . '/views/customer/new.php';
544 }
545 break;
546
547 default:
548 $template = dirname( __FILE__ ) . '/views/customer/list.php';
549 break;
550 }
551
552 if ( file_exists( $template ) ) {
553 include $template;
554 } else {
555 echo sprintf( '<h1>%s</h1>', __( 'You do not have sufficient permissions to access this page.', 'erp' ) );
556 }
557 }
558
559 /**
560 * Handles the plugin page
561 *
562 * @return void
563 */
564 public function page_vendors() {
565 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
566 $id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
567 $template = '';
568
569 switch ($action) {
570 case 'view':
571 if ( erp_ac_current_user_can_view_single_vendor() ) {
572 $vendor = new \WeDevs\ERP\People( $id );
573 $template = dirname( __FILE__ ) . '/views/vendor/single.php';
574 }
575 break;
576
577 case 'edit':
578 $vendor = new \WeDevs\ERP\People( $id );
579 if ( erp_ac_current_user_can_edit_vendor( $vendor->created_by ) ) {
580 $template = dirname( __FILE__ ) . '/views/vendor/edit.php';
581 }
582 break;
583
584 case 'new':
585 if ( erp_ac_create_vendor() ) {
586 $template = dirname( __FILE__ ) . '/views/vendor/new.php';
587 }
588 break;
589
590 default:
591 $template = dirname( __FILE__ ) . '/views/vendor/list.php';
592 break;
593 }
594
595 if ( file_exists( $template ) ) {
596 include $template;
597 }
598 }
599
600 /**
601 * Show CRM Help Page
602 * @since 1.0.0
603 */
604 public function help_page(){
605 include WPERP_ACCOUNTING_PATH . '/includes/views/help.php';
606 }
607 }
608