' );
erp_add_menu(
'accounting',
[
'title' => __( 'Dashboard', 'erp' ),
'capability' => $dashboard,
'slug' => 'dashboard',
'position' => 1,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Users', 'erp' ),
'capability' => $customer,
'slug' => 'users',
'position' => 5,
]
);
erp_add_submenu(
'accounting',
'users',
[
'title' => __( 'Customers', 'erp' ),
'capability' => $customer,
'slug' => 'users/customers',
'position' => 5,
]
);
erp_add_submenu(
'accounting',
'users',
[
'title' => __( 'Vendors', 'erp' ),
'capability' => $vendor,
'slug' => 'users/vendors',
'position' => 10,
]
);
erp_add_submenu(
'accounting',
'users',
[
'title' => __( 'Employees', 'erp' ),
'capability' => 'erp_ac_manager',
'slug' => 'users/employees',
'position' => 15,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Transactions', 'erp' ),
'capability' => $expense,
'slug' => 'transactions',
'position' => 25,
]
);
erp_add_submenu(
'accounting',
'transactions',
[
'title' => __( 'Sales', 'erp' ),
'capability' => $sale,
'slug' => 'transactions/sales',
'position' => 5,
]
);
erp_add_submenu(
'accounting',
'transactions',
[
'title' => __( 'Expenses', 'erp' ),
'capability' => $expense,
'slug' => 'transactions/expenses',
'position' => 10,
]
);
erp_add_submenu(
'accounting',
'transactions',
[
'title' => __( 'Purchases', 'erp' ),
'capability' => $sale,
'slug' => 'transactions/purchases',
'position' => 15,
]
);
erp_add_submenu(
'accounting',
'transactions',
[
'title' => __( 'Journals', 'erp' ),
'capability' => $journal,
'slug' => 'transactions/journals',
'position' => 25,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Chart of Accounts', 'erp' ),
'capability' => $account_charts,
'slug' => 'charts',
'position' => 30,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Bank Accounts', 'erp' ),
'capability' => $bank,
'slug' => 'banks',
'position' => 35,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Products', 'erp' ),
'capability' => 'erp_ac_view_sale',
'slug' => 'products',
'position' => 45,
]
);
erp_add_submenu(
'accounting',
'products',
[
'title' => __( 'Products & Services', 'erp' ),
'capability' => 'erp_ac_view_sale',
'slug' => 'products/product-service',
'position' => 5,
]
);
erp_add_submenu(
'accounting',
'products',
[
'title' => __( 'Product Categories', 'erp' ),
'capability' => 'erp_ac_view_sale',
'slug' => 'products/product-categories',
'position' => 10,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Tax', 'erp' ),
'capability' => 'erp_ac_view_sale',
'slug' => 'taxes',
'position' => 45,
]
);
erp_add_submenu(
'accounting',
'taxes',
[
'title' => __( 'Tax Rates', 'erp' ),
'capability' => $sale,
'slug' => 'taxes/tax-rates',
'position' => 5,
]
);
erp_add_submenu(
'accounting',
'taxes',
[
'title' => __( 'Tax Payments', 'erp' ),
'capability' => $sale,
'slug' => 'taxes/tax-records',
'position' => 10,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Reports', 'erp' ),
'capability' => $reports,
'slug' => 'reports',
'position' => 100,
]
);
erp_add_menu(
'accounting',
[
'title' => __( 'Help', 'erp' ),
'capability' => $dashboard,
'slug' => 'erp-ac-help',
'position' => 200,
]
);
}
/**
* Render Admin bar menu
*/
public function add_admin_bar_menu() {
global $wp_admin_bar;
/* Check that the admin bar is showing and user has permission... */
if ( ! is_admin_bar_showing() ) {
return;
}
$hide = [];
$header = erp_get_menu_headers();
if ( ! current_user_can( 'administrator' ) ) {
if ( ! current_user_can( 'erp_hr_manager' ) && ! current_user_can( 'erp_recruiter' ) && ! current_user_can( 'erp_list_employee' ) ) {
unset( $header['hr'] );
$hide[] = true;
}
if ( ! current_user_can( 'erp_crm_manager' ) && ! current_user_can( 'erp_crm_agent' ) ) {
unset( $header['crm'] );
$hide[] = true;
}
if ( ! current_user_can( 'erp_ac_manager' ) ) {
unset( $header['accounting'] );
$hide[] = true;
}
}
if ( count( $hide ) === 3 ) {
return;
}
$menu = erp_acct_quick_access_menu();
if ( current_user_can( 'erp_ac_manager' ) ) {
$wp_admin_bar->add_menu(
[
'parent' => 'top-secondary',
'id' => 'wp-erp-acct',
'title' => 'New Transaction',
]
);
}
foreach ( $menu as $component => $items ) {
$wp_admin_bar->add_menu(
[
'parent' => 'wp-erp-acct',
'id' => 'wp-erp-acct-' . $items['slug'],
'href' => admin_url( 'admin.php?page=erp-accounting' ) . '#/' . $items['url'],
'title' => $items['title'],
]
);
}
}
/**
* Initialize our hooks for the admin page
*
* @return void
*/
public function init_hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* Load scripts and styles for the app
*
* @return void
*/
public function enqueue_scripts() {
// load styles
wp_enqueue_style( 'accounting-admin' );
// load hook
wp_enqueue_script( 'accounting-bootstrap' );
// JS do action
do_action( 'erp_acct_js_hook_loaded' );
// load scripts
wp_enqueue_script( 'accounting-admin' );
}
/**
* Render our admin page
*
* @return void
*/
public function erp_accounting_page() {
?>
';
$component = 'accounting';
$menu = erp_menu();
$menu = $menu[ $component ];
$section = ( isset( $_GET['section'] ) && isset( $menu[ $_GET['section'] ] ) ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : 'dashboard';
$sub = ( isset( $_GET['sub-section'] ) && ! empty( $menu[ $section ]['submenu'][ $_GET['sub-section'] ] ) ) ? sanitize_text_field( wp_unslash( $_GET['sub-section'] ) ) : false;
}
/**
* Make employee as people
*
* @param int $id
* @param array $data
*
* @return bool
*/
public function make_people_from_employee( $id, $data ) {
if ( ! current_user_can( 'erp_create_employee' ) ) {
return;
}
$first_name = isset( $data['personal']['first_name'] ) ? $data['personal']['first_name'] : '';
$last_name = isset( $data['personal']['last_name'] ) ? $data['personal']['last_name'] : '';
$mobile = isset( $data['personal']['mobile'] ) ? $data['personal']['mobile'] : '';
$phone = isset( $data['personal']['phone'] ) ? $data['personal']['phone'] : '';
$email = isset( $data['user_email'] ) ? $data['user_email'] : '';
$args = [
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'mobile' => $mobile,
'phone' => $phone,
'type' => 'employee',
];
$people_id = erp_insert_people( $args );
if ( is_wp_error( $people_id ) ) {
return new \WP_Error( 'crate_people', __( 'Could not create people', 'erp' ) );
}
return $people_id;
}
/**
* Save Financial Year settings
*
* @param int $id
* @param array $data
*
* @return bool
*/
public function save_accounting_settings() {
if ( $_SERVER['REQUEST_METHOD'] !== 'POST' || ! isset( $_POST['erp-ac-ob-fyears-add'] ) ) {
return;
}
global $wpdb;
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'erp-settings-nonce' ) ) {
die( 'Nonce failed.' );
}
$fin_years = [];
if (
empty( $_POST['ob_names'] )
|| empty( $_POST['ob_starts'] )
|| empty( $_POST['ob_ends'] )
) {
return;
}
$ob_names = array_map( 'sanitize_text_field', wp_unslash( $_POST['ob_names'] ) );
$ob_starts = array_map( 'sanitize_text_field', wp_unslash( $_POST['ob_starts'] ) );
$ob_ends = array_map( 'sanitize_text_field', wp_unslash( $_POST['ob_ends'] ) );
$created_by = get_current_user_id();
if ( ! empty( $ob_names ) ) {
for ( $i = 0; $i < count( $ob_names ); $i++ ) {
$fin_years['ob_names'][] = $ob_names[ $i ];
}
}
if ( ! empty( $ob_starts ) ) {
for ( $i = 0; $i < count( $ob_starts ); $i++ ) {
$fin_years['ob_starts'][] = $ob_starts[ $i ];
}
}
if ( ! empty( $ob_ends ) ) {
for ( $i = 0; $i < count( $ob_ends ); $i++ ) {
$fin_years['ob_ends'][] = $ob_ends[ $i ];
}
}
$wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . 'erp_acct_financial_years' );
for ( $i = 0; $i < count( $ob_names ); $i++ ) {
$wpdb->insert(
$wpdb->prefix . 'erp_acct_financial_years',
[
'name' => $fin_years['ob_names'][ $i ],
'start_date' => $fin_years['ob_starts'][ $i ],
'end_date' => $fin_years['ob_ends'][ $i ],
'created_at' => date( 'Y-m-d' ),
'created_by' => $created_by,
],
['%s', '%s', '%s', '%s', '%d']
);
}
}
/**
* Check accounting permission for users
*
* @since 1.5.12
*
* @param object $employee
*
* @return void
*/
public function permission_management_field( $employee ) {
if ( ! erp_acct_is_hr_current_user_manager() ) {
return;
}
$is_manager = user_can( $employee->id, erp_ac_get_manager_role() ) ? 'on' : 'off';
erp_html_form_input( [
'label' => esc_html__( 'Accounting Manager', 'erp' ),
'name' => 'acct_manager',
'type' => 'checkbox',
'tag' => 'div',
'value' => $is_manager,
'help' => esc_html__( 'This Employee is Accounting Manager', 'erp' ),
] );
}
/**
* Set employee permission as account manager
*
* @since 1.5.12
*
* @param array $post
* @param object $user
*
* @return void
*/
public function permission_set( $post, $user ) {
$enable_acct_manager = isset( $post['acct_manager'] ) ? filter_var( $post['acct_manager'], FILTER_VALIDATE_BOOLEAN ) : false;
$acct_manager_role = erp_ac_get_manager_role();
if ( current_user_can( $acct_manager_role ) ) {
if ( $enable_acct_manager ) {
$user->add_role( $acct_manager_role );
} else {
$user->remove_role( $acct_manager_role );
}
}
}
}