Plugin Directory

Changeset 2428546


Ignore:
Timestamp:
11/30/2020 12:22:12 PM (5 years ago)
Author:
opurockey
Message:

Release version 1.7.0

Location:
erp
Files:
2348 added
21 edited

Legend:

Unmodified
Added
Removed
  • erp/trunk/includes/admin/class-audit-list-table.php

    r2417217 r2428546  
    166166
    167167            case 'created_at':
    168                 return erp_format_date( $audit_log->created_at );
     168                return ! empty( $audit_log->created_at ) ? gmdate( erp_get_date_format() . ', h:i:s', strtotime( $audit_log->created_at ) ) : $audit_log->created_at;
    169169
    170170            default:
  • erp/trunk/includes/admin/views/tools.php

    r2417217 r2428546  
    22
    33    <?php
    4         $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'general';
     4    $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'general';
    55
    6         $is_crm_activated = erp_is_module_active( 'crm' );
    7         $is_hrm_activated = erp_is_module_active( 'hrm' );
     6    $is_crm_activated = erp_is_module_active( 'crm' );
     7    $is_hrm_activated = erp_is_module_active( 'hrm' );
     8    $is_acc_activated = erp_is_module_active( 'accounting' );
    89
    9         $erp_import_export_fields = erp_get_import_export_fields();
    10         $keys                     = array_keys( $erp_import_export_fields );
     10    $erp_import_export_fields = erp_get_import_export_fields();
     11    $keys                     = array_keys( $erp_import_export_fields );
    1112
    12         $import_export_types = [];
     13    $import_export_types = [];
    1314
    14         foreach ( $keys as $type ) {
    15             $import_export_types[ $type ] = esc_html__( ucwords( $type ), 'erp' );
    16         }
     15    foreach ( $keys as $type ) {
     16        $import_export_types[ $type ] = sprintf( esc_html__( '%s', 'erp' ), ucwords( $type ) );
     17    }
    1718
    18         if ( ! $is_crm_activated ) {
    19             unset( $import_export_types['contact'] );
    20             unset( $import_export_types['company'] );
    21         }
     19    if ( ! $is_crm_activated ) {
     20        unset( $import_export_types['contact'] );
     21        unset( $import_export_types['company'] );
     22    }
    2223
    23         if ( ! $is_hrm_activated ) {
    24             unset( $import_export_types['employee'] );
    25         }
     24    if ( ! $is_hrm_activated ) {
     25        unset( $import_export_types['employee'] );
     26    }
    2627
    27         $tabs = [
    28             'general' => esc_html__( 'General', 'erp' ),
    29         ];
     28    if ( ! $is_acc_activated ) {
     29        unset( $import_export_types['vendor'] );
     30    }
    3031
    31         if ( $is_crm_activated || $is_hrm_activated ) {
    32             $tabs['import'] = esc_html__( 'Import', 'erp' );
    33             $tabs['export'] = esc_html__( 'Export', 'erp' );
    34         }
     32    $tabs = [
     33        'general' => esc_html__( 'General', 'erp' ),
     34    ];
    3535
    36         $tabs['misc']   = esc_html__( 'Misc.', 'erp' );
    37         $tabs['status'] =   esc_html__( 'Status', 'erp' );
    38         $tabs['log']    =   esc_html__( 'Audit Log', 'erp' );
     36    if ( $is_crm_activated || $is_hrm_activated || $is_acc_activated ) {
     37        $tabs['import'] = esc_html__( 'Import', 'erp' );
     38        $tabs['export'] = esc_html__( 'Export', 'erp' );
     39    }
    3940
    40         $tabs = apply_filters( 'erp_tools_tabs', $tabs );
     41    $tabs['misc']   = esc_html__( 'Misc.', 'erp' );
     42    $tabs['status'] = esc_html__( 'Status', 'erp' );
     43    $tabs['log']    = esc_html__( 'Audit Log', 'erp' );
     44
     45    $tabs = apply_filters( 'erp_tools_tabs', $tabs );
    4146    ?>
    4247
    4348    <h2 class="nav-tab-wrapper erp-nav-tab-wrapper">
    4449        <?php foreach ( $tabs as $tab_key => $tab_label ) { ?>
    45             <a class="nav-tab <?php echo esc_attr( ( $current_tab == $tab_key ) ? 'nav-tab-active' : '' ); ?>" href="<?php echo esc_url( admin_url( 'admin.php?page=erp-tools&tab=' ) ) . esc_html( $tab_key ); ?>"><?php echo esc_html( $tab_label ); ?></a>
     50            <a class="nav-tab <?php echo esc_attr( ( $current_tab === $tab_key ) ? 'nav-tab-active' : '' ); ?>" href="<?php echo esc_url( admin_url( 'admin.php?page=erp-tools&tab=' ) ) . esc_html( $tab_key ); ?>"><?php echo esc_html( $tab_label ); ?></a>
    4651        <?php } ?>
    4752    </h2>
  • erp/trunk/includes/admin/views/tools/import.php

    r2417217 r2428546  
    11<?php
    2 
    3     if ( ! $is_crm_activated && ! $is_hrm_activated ) {
    4         return;
     2if ( ! $is_crm_activated && ! $is_hrm_activated && ! $is_acc_activated ) {
     3    return;
     4}
     5
     6$page           = '?page=erp-tools&tab=import&action=download_sample';
     7$nonce          = 'erp-emport-export-sample-nonce';
     8$csv_sample_url = wp_nonce_url( $page, $nonce );
     9
     10$users       = [];
     11$life_stages = [];
     12$groups      = [];
     13
     14if ( $is_crm_activated ) {
     15    $life_stages    = erp_crm_get_life_stages_dropdown_raw();
     16    $crm_users      = erp_crm_get_crm_user();
     17
     18    foreach ( $crm_users as $user ) {
     19        $users[ $user->ID ] = $user->display_name . ' &lt;' . $user->user_email . '&gt;';
    520    }
    621
    7     $page           = '?page=erp-tools&tab=import&action=download_sample';
    8     $nonce          = 'erp-emport-export-sample-nonce';
    9     $csv_sample_url = wp_nonce_url( $page, $nonce );
    10 
    11     $users       = [];
    12     $life_stages = [];
    13     $groups      = [];
    14 
    15     if ( $is_crm_activated ) {
    16         $life_stages    = erp_crm_get_life_stages_dropdown_raw();
    17         $crm_users      = erp_crm_get_crm_user();
    18 
    19         foreach ( $crm_users as $user ) {
    20             $users[ $user->ID ] = $user->display_name . ' &lt;' . $user->user_email . '&gt;';
    21         }
    22 
    23         $contact_groups = erp_crm_get_contact_groups( [ 'number' => '-1' ] );
    24 
    25         $groups = ['' => __( '&mdash; Select Group &mdash;', 'erp' )];
    26 
    27         foreach ( $contact_groups as $group ) {
    28             $groups[ $group->id ] = $group->name;
    29         }
     22    $contact_groups = erp_crm_get_contact_groups( [ 'number' => '-1' ] );
     23
     24    $groups = [ '' => __( '&mdash; Select Group &mdash;', 'erp' ) ];
     25
     26    foreach ( $contact_groups as $group ) {
     27        $groups[ $group->id ] = $group->name;
    3028    }
     29}
    3130?>
    3231
    3332<?php
    34 if ( isset( $_GET['error'] ) && $_GET['error'] != '' ) {
     33if ( isset( $_GET['error'] ) && $_GET['error'] !== '' ) {
    3534    $errors = new \WeDevs\ERP\ERP_Errors( sanitize_text_field( wp_unslash( $_GET['error'] ) ) );
    3635    echo $errors->display();
     
    6564                        <td>
    6665                            <input type="file" name="csv_file" id="csv_file" />
    67                             <p class="description"><?php esc_html_e( 'Upload a csv file.', 'erp' ); ?><?php echo erp_help_tip( esc_html__( 'Make sure CSV meets the sample CSV format exactly.', 'erp' ) ) ?></p>
     66                            <p class="description">
     67                                <?php
     68                                esc_html_e( 'Upload a csv file.', 'erp' );
     69                                echo erp_help_tip( esc_html__( 'Make sure CSV meets the sample CSV format exactly.', 'erp' ) );
     70                                ?>
     71                            </p>
    6872                            <p id="download_sample_wrap">
    6973                                <input type="hidden" value="<?php echo esc_url( $csv_sample_url ); ?>" />
     
    8185                            <select name="contact_owner" id="contact_owner">
    8286                                <?php
    83                                     $current_user = get_current_user_id();
    84                                     echo wp_kses( erp_html_generate_dropdown( $users, $current_user ), [
    85                                         'option' => [
    86                                             'value'    => [],
    87                                             'selected' => [],
    88                                         ],
    89                                     ] );
    90                                 ?>
    91                             </select>
    92                             <p class="description"><?php esc_html_e( 'Contact owner for contact.', 'erp' ); ?></p>
    93                         </td>
    94                     </tr>
    95                     <tr>
    96                         <th>
    97                             <label for="life_stage"><?php esc_html_e( 'Life Stage', 'erp' ); ?></label>
    98                         </th>
    99                         <td>
    100                             <select name="life_stage" id="life_stage">
    101                                 <?php echo wp_kses( erp_html_generate_dropdown( $life_stages ), [
     87                                $current_user = get_current_user_id();
     88                                echo wp_kses( erp_html_generate_dropdown( $users, $current_user ), [
    10289                                    'option' => [
    10390                                        'value'    => [],
    10491                                        'selected' => [],
    10592                                    ],
    106                                 ] ); ?>
     93                                ] );
     94                                ?>
     95                            </select>
     96                            <p class="description"><?php esc_html_e( 'Contact owner for contact.', 'erp' ); ?></p>
     97                        </td>
     98                    </tr>
     99                    <tr>
     100                        <th>
     101                            <label for="life_stage"><?php esc_html_e( 'Life Stage', 'erp' ); ?></label>
     102                        </th>
     103                        <td>
     104                            <select name="life_stage" id="life_stage">
     105                                <?php
     106                                echo wp_kses(
     107                                    erp_html_generate_dropdown( $life_stages ), [
     108                                        'option' => [
     109                                            'value'    => [],
     110                                            'selected' => [],
     111                                        ],
     112                                    ]
     113                                );
     114                                ?>
    107115                            </select>
    108116                            <p class="description"><?php esc_html_e( 'Life stage for contact.', 'erp' ); ?></p>
     
    115123                        <td>
    116124                            <select name="contact_group">
    117                                 <?php echo wp_kses( erp_html_generate_dropdown( $groups ), [
     125                                <?php
     126                                echo wp_kses( erp_html_generate_dropdown( $groups ), [
    118127                                    'option' => [
    119128                                        'value'    => [],
    120129                                        'selected' => [],
    121130                                    ],
    122                                 ] ); ?>
     131                                ] );
     132                                ?>
    123133                            </select>
    124134                            <p class="description"><?php esc_html_e( 'Imported contacts will be subscribed in selected group.', 'erp' ); ?></p>
     
    161171                            <td>
    162172                                <select name="user_role" class="erp-select2" id="user_role" multiple="true">
    163                                     <?php echo wp_kses( erp_html_generate_dropdown( $roles, $default_role ), [
    164                                         'option' => [
    165                                             'value'    => [],
    166                                             'selected' => [],
    167                                         ],
    168                                     ] ); ?>
     173                                    <?php
     174                                    echo wp_kses( erp_html_generate_dropdown( $roles, $default_role ), [
     175                                        'option' => [
     176                                            'value'    => [],
     177                                            'selected' => [],
     178                                        ],
     179                                    ] );
     180                                    ?>
    169181                                </select>
    170182                                <p class="description"><?php esc_html_e( 'Selected user role are considered to import.', 'erp' ); ?></p>
     
    178190                                <select name="contact_owner" id="contact_owner">
    179191                                    <?php
    180                                         $current_user = get_current_user_id();
    181                                         echo wp_kses( erp_html_generate_dropdown( $users, $current_user ), [
    182                                             'option' => [
    183                                                 'value'    => [],
    184                                                 'selected' => [],
    185                                             ],
    186                                         ] );
     192                                    $current_user = get_current_user_id();
     193                                    echo wp_kses( erp_html_generate_dropdown( $users, $current_user ), [
     194                                        'option' => [
     195                                            'value'    => [],
     196                                            'selected' => [],
     197                                        ],
     198                                    ] );
    187199                                    ?>
    188200                                </select>
     
    196208                            <td>
    197209                                <select name="life_stage" id="life_stage">
    198                                     <?php echo wp_kses( erp_html_generate_dropdown( $life_stages ), [
    199                                         'option' => [
    200                                             'value'    => [],
    201                                             'selected' => [],
    202                                         ],
    203                                     ] ); ?>
     210                                    <?php
     211                                    echo wp_kses( erp_html_generate_dropdown( $life_stages ), [
     212                                        'option' => [
     213                                            'value'    => [],
     214                                            'selected' => [],
     215                                        ],
     216                                    ] );
     217                                    ?>
    204218                                </select>
    205219                                <p class="description"><?php esc_html_e( 'Life stage for contact.', 'erp' ); ?></p>
     
    212226                            <td>
    213227                                <select name="contact_group">
    214                                     <?php echo wp_kses( erp_html_generate_dropdown( $groups ), [
    215                                         'option' => [
    216                                             'value'    => [],
    217                                             'selected' => [],
    218                                         ],
    219                                     ] ); ?>
     228                                    <?php
     229                                    echo wp_kses( erp_html_generate_dropdown( $groups ), [
     230                                        'option' => [
     231                                            'value'    => [],
     232                                            'selected' => [],
     233                                        ],
     234                                    ] );
     235                                    ?>
    220236                                </select>
    221237                                <p class="description"><?php esc_html_e( 'Imported contacts will be subscribed in selected group.', 'erp' ); ?></p>
     
    243259        </div><!-- .inside -->
    244260    </div><!-- .postbox -->
    245 <?php
    246     }
    247 ?>
     261<?php } ?>
  • erp/trunk/includes/api/class-announcements-controller.php

    r2417217 r2428546  
    154154        $id   = wp_insert_post( $item );
    155155
    156         $type = ( $request['recipient_type'] == 'all_employees' ) ? 'all_employee' : 'selected_employee';
     156        $type = ( $request['recipient_type'] == 'all_employee' ) ? 'all_employee' : 'selected_employee';
    157157
    158158        $employees = [];
  • erp/trunk/includes/framework/views/status-report.php

    r2417217 r2428546  
    163163            <td data-export-label="Company Start Date"><?php esc_html_e( 'Company Start Date', 'erp' ); ?>:</td>
    164164            <td class="help"><?php echo wp_kses_post( erp_help_tip( esc_html__( 'The date the company officially started.', 'erp' ) ) ); ?></td>
    165             <td><?php echo esc_html( erp_get_option( 'gen_com_start', 'erp_settings_general' ) ); ?></td>
     165            <td><?php echo esc_html( erp_format_date( erp_get_option( 'gen_com_start', 'erp_settings_general' ) ) ); ?></td>
    166166        </tr>
    167167        <tr>
    168168            <td data-export-label="Financial Year Start Date"><?php esc_html_e( 'Financial Year Start Date', 'erp' ); ?>:</td>
    169169            <td class="help"><?php echo wp_kses_post( erp_help_tip( esc_html__( 'Financial and tax calculation starts from this month of every year.', 'erp' ) ) ); ?></td>
    170             <td><?php echo esc_html( erp_financial_start_date() ); ?></td>
     170            <td><?php echo esc_html( erp_format_date( erp_financial_start_date() ) ); ?></td>
    171171        </tr>
    172172        <tr>
    173173            <td data-export-label="Financial Year End Date"><?php esc_html_e( 'Financial Year End Date', 'erp' ); ?>:</td>
    174174            <td class="help"><?php echo wp_kses_post( erp_help_tip( esc_html__( 'The date the company\'s financial year ends.', 'erp' ) ) ); ?></td>
    175             <td><?php echo esc_html( erp_financial_end_date() ); ?></td>
     175            <td><?php echo esc_html( erp_format_date( erp_financial_end_date() ) ); ?></td>
    176176        </tr>
    177177        <tr>
  • erp/trunk/includes/functions.php

    r2417217 r2428546  
    636636
    637637/**
     638 * Get erp date format setting
     639 *
     640 * @since 1.6.9
     641 *
     642 * @param mixed $format
     643 *
     644 * @return string
     645 */
     646function erp_get_date_format( $format = false ) {
     647    $format = $format ? $format : 'd-m-Y';
     648
     649    return erp_get_option( 'date_format', 'erp_settings_general', $format );
     650}
     651
     652/**
    638653 * Get a formatted date from WordPress format
    639654 *
     
    643658 */
    644659function erp_format_date( $date, $format = false ) {
     660    if ( empty( $date ) ) {
     661        return false;
     662    }
     663
    645664    if ( ! $format ) {
    646         $format = erp_get_option( 'date_format', 'erp_settings_general', 'd-m-Y' );
     665        $format = erp_get_date_format();
    647666    }
    648667
     
    11151134                $messages[] = sprintf(
    11161135                    __( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'erp' ),
    1117                     date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
     1136                    date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'mysql' ) ) ),
    11181137                    'https://wperp.com/checkout/?edd_license_key=' . $addon['license'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
    11191138                );
     
    11501169                $messages[] = sprintf(
    11511170                    __( 'Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'erp' ),
    1152                     date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
     1171                    date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'mysql' ) ) ),
    11531172                    'https://wperp.com/checkout/?edd_license_key=' . $addon['license'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
    11541173                );
     
    11571176            case 'valid':
    11581177                $status_class = 'no-error';
    1159                 $now          = current_time( 'timestamp' );
    1160                 $expiration   = strtotime( $license->expires, current_time( 'timestamp' ) );
     1178                $now          = current_time( 'mysql' );
     1179                $expiration   = strtotime( $license->expires, current_time( 'mysql' ) );
    11611180
    11621181                if ( 'lifetime' === $license->expires ) {
     
    11651184                    $messages[] = sprintf(
    11661185                        __( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'erp' ),
    1167                         date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
     1186                        date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'mysql' ) ) ),
    11681187                        'https://wperp.com/checkout/?edd_license_key=' . $addon['license'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
    11691188                    );
     
    11711190                    $messages[] = sprintf(
    11721191                        __( 'Your license key expires on %s.', 'erp' ),
    1173                         date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
     1192                        date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'mysql' ) ) )
    11741193                    );
    11751194                }
     
    12851304            ],
    12861305        ],
     1306        'vendor' => [
     1307            'required_fields' => [
     1308                'first_name',
     1309                'last_name',
     1310                'email',
     1311            ],
     1312            'fields'          => [
     1313                'first_name',
     1314                'last_name',
     1315                'email',
     1316                'phone',
     1317                'company',
     1318                'mobile',
     1319                'fax',
     1320                'website',
     1321                'notes',
     1322                'street_1',
     1323                'street_2',
     1324                'city',
     1325                'country',
     1326                'state',
     1327                'postal_code',
     1328            ],
     1329        ],
    12871330    ];
    12881331
     
    14581501            });
    14591502
    1460             if ($('form#import_form').find('#type').val() == 'employee') {
     1503            var exportType = $('form#import_form').find('#type').val();
     1504
     1505            if (exportType == 'employee' || exportType == 'vendor') {
    14611506                $('form#import_form').find('#crm_contact_lifestage_owner_wrap').hide();
    14621507            } else {
     
    14681513                $('#fields_container').hide();
    14691514
    1470                 if ($(this).val() == 'employee') {
     1515                if ($(this).val() == 'employee' || $(this).val() == 'vendor') {
    14711516                    $('form#import_form').find('#crm_contact_lifestage_owner_wrap').hide();
    14721517                } else {
     
    15811626    $is_crm_activated = erp_is_module_active( 'crm' );
    15821627    $is_hrm_activated = erp_is_module_active( 'hrm' );
     1628    $is_acc_activated = erp_is_module_active( 'accounting' );
    15831629
    15841630    $departments  = $is_hrm_activated ? erp_hr_get_departments_dropdown_raw() : [];
     
    16121658    }
    16131659
     1660    $field_builder_vendor_options = get_option( 'erp-vendor-fields' );
     1661    $field_builder_vendors_fields = [];
     1662
     1663    if ( ! empty( $field_builder_vendor_options ) ) {
     1664        foreach ( $field_builder_vendor_options as $field ) {
     1665            $field_builder_vendors_fields[] = $field['name'];
     1666        }
     1667    }
     1668
    16141669    if ( isset( $_POST['erp_import_csv'] ) ) {
    16151670        define( 'ERP_IS_IMPORTING', true );
     
    16281683        do_action( 'erp_tool_import_csv_action', $data );
    16291684
    1630         if ( ! in_array( $type, [ 'contact', 'company', 'employee' ], true ) ) {
     1685        if ( ! in_array( $type, [ 'contact', 'company', 'employee', 'vendor' ], true ) ) {
    16311686            return;
    16321687        }
     
    17081763                        if ( ! empty( $line[ $value ] ) && is_numeric( $value ) ) {
    17091764                            if ( $type === 'employee' ) {
    1710                                 if ( in_array( $key, $employee_fields['work'] ) ) {
     1765                                if ( in_array( $key, $employee_fields['work'], true ) ) {
    17111766                                    if ( $key === 'designation' ) {
    1712                                         $line_data['work'][ $key ] = array_search( $line[ $value ], $designations );
     1767                                        $line_data['work'][ $key ] = array_search( $line[ $value ], $designations, true );
    17131768                                    } elseif ( $key === 'department' ) {
    1714                                         $line_data['work'][ $key ] = array_search( $line[ $value ], $departments );
     1769                                        $line_data['work'][ $key ] = array_search( $line[ $value ], $departments, true );
    17151770                                    } else {
    17161771                                        $line_data['work'][ $key ] = $line[ $value ];
    17171772                                    }
    1718                                 } elseif ( in_array( $key, $employee_fields['personal'] ) ) {
     1773                                } elseif ( in_array( $key, $employee_fields['personal'], true ) ) {
    17191774                                    $line_data['personal'][ $key ] = $line[ $value ];
    17201775                                } else {
     
    17411796                }
    17421797
     1798                if ( $type === 'vendor' && $is_acc_activated ) {
     1799                    $item_insert_id = erp_insert_people( $line_data );
     1800
     1801                    if ( is_wp_error( $item_insert_id ) ) {
     1802                        continue;
     1803                    }
     1804                }
     1805
    17431806                if ( ( $type === 'contact' || $type === 'company' ) && $is_crm_activated ) {
    17441807                    $contact_owner              = isset( $_POST['contact_owner'] ) ? absint( $_POST['contact_owner'] ) : erp_crm_get_default_contact_owner();
     
    18081871                $args = [
    18091872                    'number' => - 1,
    1810                     'status' => 'all',
    18111873                ];
    18121874
     
    18141876            }
    18151877
    1816             if ( ( $type === 'contact' || $type === 'company' ) && $is_crm_activated ) {
     1878            if (
     1879                ( ( $type === 'contact' || $type === 'company' ) && $is_crm_activated )
     1880                ||
     1881                ( $type === 'vendor' && $is_acc_activated )
     1882            ) {
    18171883                $args        = [
    18181884                    'type'  => $type,
     
    18741940                            }
    18751941                        }
     1942
     1943                        if ( $type === 'vendor' ) {
     1944                            if ( in_array( $field, $field_builder_vendors_fields, true ) ) {
     1945                                $csv_items[ $x ][ $field ] = erp_people_get_meta( $item->id, $field, true );
     1946                            } else {
     1947                                $csv_items[ $x ][ $field ] = $item->{$field};
     1948                            }
     1949                        }
    18761950                    }
    18771951                }
     
    18801954            }
    18811955
    1882             $file_name = 'export_' . date( 'd_m_Y' ) . '.csv';
     1956            $file_name = 'export_' . gmdate( 'd_m_Y' ) . '.csv';
    18831957
    18841958            erp_make_csv_file( $csv_items, $file_name );
     
    24522526 */
    24532527function erp_make_csv_file( $items, $file_name, $field_data = true ) {
    2454     $file_name = ( ! empty( $file_name ) ) ? $file_name : 'csv_' . date( 'd_m_Y' ) . '.csv';
     2528    $file_name = ( ! empty( $file_name ) ) ? $file_name : 'csv_' . gmdate( 'd_m_Y' ) . '.csv';
    24552529
    24562530    if ( empty( $items ) ) {
     
    26882762
    26892763    if ( $date == null ) {
    2690         $year  = date( 'Y' );
    2691         $month = date( 'n' );
     2764        $year  = gmdate( 'Y' );
     2765        $month = gmdate( 'n' );
    26922766    } else {
    26932767        if ( ! is_numeric( $date ) ) {
     
    26962770            $timestamp = $date;
    26972771        }
    2698         $year  = date( 'Y', $timestamp );
    2699         $month = date( 'n', $timestamp );
     2772        $year  = gmdate( 'Y', $timestamp );
     2773        $month = gmdate( 'n', $timestamp );
    27002774    }
    27012775
     
    33443418    }
    33453419
    3346     if ( isset( $_POST['save_email_enable_or_disable'] ) && $_POST['save_email_enable_or_disable'] == 'save_email_enable_or_disable' ) {
     3420    if ( isset( $_POST['save_email_enable_or_disable'] ) && $_POST['save_email_enable_or_disable'] === 'save_email_enable_or_disable' ) {
    33473421        $registered_email = array_keys( wperp()->emailer->get_emails() );
    33483422
     
    34313505    ] );
    34323506
    3433     if ( in_array( $get_option_id, $can_not_be_disabled ) ) {
     3507    if ( in_array( $get_option_id, $can_not_be_disabled, true ) ) {
    34343508        return $email;
    34353509    }
     
    37463820 */
    37473821function erp_is_valid_contact_no( $contact_no ) {
    3748     return preg_match( '/^\+?(?:[0-9]( |-)?){6,14}[0-9]$/', $contact_no );
     3822    return preg_match( '/^\+?[0-9]{1,3}([\s\.\-]?[0-9]{1,5}){3}$/', $contact_no );
    37493823}
    37503824
     
    37723846 */
    37733847function erp_is_valid_url( $url ) {
    3774     return filter_var( $url, FILTER_VALIDATE_URL );
     3848    return preg_match( '/^(?:(?:https?|ftp):\/\/)?(?:[a-z0-9-]+\.)*((?:[a-z0-9-]+\.)[a-z]+)/i', $url );
    37753849}
    37763850
     
    37983872 */
    37993873function erp_is_valid_currency_amount( $amount ) {
    3800     return preg_match( '/^[1-9](?:,?[0-9])*(?:.[0-9]{4})?$/', $amount );
    3801 }
     3874    return preg_match( '/^[0-9](?:,?[0-9])*(?:.[0-9]{4})?$/', $amount );
     3875}
  • erp/trunk/modules/crm/includes/contact-forms/class-contact-forms-integration.php

    r2417217 r2428546  
    7575     * Save form sumitted data as new CRM Contact
    7676     *
     77     * @since 1.6.5 added filter hook 'erp_pre_contact_form_people_data'
     78     * @since 1.6.8 added existing contact checking to prevent reseting contact owner
     79     *
    7780     * @param array  $data    submitted form data
    7881     * @param string $plugin  plugin slug defined in get_plugin_list function
     
    123126            }
    124127
    125             /**
    126              * @since 1.6.5
    127              */
     128            $existing_people_by_email = \WeDevs\ERP\Framework\Models\People::type( $contact['type'] )->where( 'email', $contact['email'] )->first();
     129
     130            if ( ! empty( $existing_people_by_email->email ) ) {
     131                $contact['contact_owner'] = $existing_people_by_email->contact_owner;
     132            }
     133
    128134            $contact = apply_filters( 'erp_pre_contact_form_people_data', $contact, $data, $plugin, $form_id );
    129135
  • erp/trunk/modules/crm/includes/contact-forms/class-erp-settings-contact-forms.php

    r2417217 r2428546  
    274274                                <label>
    275275                                    {{ i18n.labelContactOwner }} <span class="required">*</span>
    276                                     <select class="cfi-contact-group" v-model="formData.contactOwner">
    277                                         <option value="0">{{ i18n.labelSelectOwner }}</option>
     276                                    <select class="cfi-contact-group" v-model="formData.contactOwner" required>
     277                                        <option value="" disabled>{{ i18n.labelSelectOwner }}</option>
    278278                                        <option v-for="(userId, user) in contactOwners" value="{{ userId }}">{{ user }}</option>
    279279                                    </select>
     
    306306     * Ajax hook function to save the ERP Settings
    307307     *
     308     * @since 1.6.8 added contact owner validation
     309     *
    308310     * @return void prints json object
    309311     */
     
    318320        }
    319321
    320         if ( !erp_crm_is_current_user_manager() ) {
     322        if ( ! erp_crm_is_current_user_manager() ) {
    321323            $response['msg'] = __( 'Unauthorized operation', 'erp' );
    322324        }
    323325
    324         if ( !empty( $_POST['plugin'] ) && !empty( $_POST['formId'] ) && !empty( $_POST['map'] ) ) {
     326        if ( ! empty( $_POST['plugin'] ) && !empty( $_POST['formId'] ) && !empty( $_POST['map'] ) ) {
    325327            $required_options = $this->get_required_crm_contact_options();
    326328
     
    347349                    implode( ', ', $required_options )
    348350                );
    349             } elseif ( empty( $_POST['contactOwner'] ) && absint( $_POST['contactOwner'] ) ) {
     351            } elseif ( empty( $_POST['contactOwner'] ) ) {
    350352                $response['msg'] = __( 'Please set a contact owner.', 'erp' );
    351353            } else {
  • erp/trunk/modules/crm/views/company/single.php

    r2417217 r2428546  
    11<?php
     2if (
     3    ! current_user_can( erp_crm_get_manager_role() ) &&
     4    ! current_user_can( 'manage_options' ) &&
     5    intval( $customer->contact_owner ) !== get_current_user_id()
     6) {
     7    wp_die( __( 'Unauthorized request.', 'erp' ), 401 );
     8}
     9
    210$contact_tags = wp_get_object_terms( $customer->id, 'erp_crm_tag', ['orderby' => 'name', 'order' => 'ASC'] );
    311$contact_tags = wp_list_pluck( $contact_tags, 'name' );
     
    513<div class="wrap erp erp-crm-customer erp-single-customer" id="wp-erp">
    614
    7     <h2><?php esc_attr_e( 'Company #', 'erp' ); echo esc_attr( $customer->id ); ?>
    8         <a href="<?php echo esc_url_raw( add_query_arg( ['page' => 'erp-crm', 'section' => 'companies' ], admin_url( 'admin.php' ) ) ); ?>" id="erp-contact-list" class="add-new-h2"><?php esc_attr_e( 'Back to Company list', 'erp' ); ?></a>
     15    <h2>
     16        <?php
     17        esc_attr_e( 'Company #', 'erp' );
     18        echo esc_attr( $customer->id );
     19        ?>
     20        <a href="<?php echo esc_url_raw( add_query_arg( [ 'page' => 'erp-crm', 'section' => 'companies' ], admin_url( 'admin.php' ) ) ); ?>" id="erp-contact-list" class="add-new-h2"><?php esc_attr_e( 'Back to Company list', 'erp' ); ?></a>
    921
    1022        <?php if ( current_user_can( 'erp_crm_edit_contact', $customer->id ) || current_user_can( erp_crm_get_manager_role() ) ) { ?>
     
    4254                                <?php } ?>
    4355
    44                                 <?php if ( $customer->get_mobile() != '—' ) { ?>
     56                                <?php if ( $customer->get_mobile() !== '—' ) { ?>
    4557                                    <p>
    4658                                        <i class="fa fa-phone"></i>&nbsp;
     
    93105                                        <div class="user-wrap-content">
    94106                                            <?php
    95                                                 $crm_user_id = $customer->get_contact_owner();
    96 
    97                                                 if ( !empty( $crm_user_id ) ) {
    98                                                     $user        = get_user_by( 'id', $crm_user_id );
    99                                                     $user_string = esc_html( $user->display_name );
    100                                                     $user_email  = $user->get( 'user_email' );
    101                                                 } else {
    102                                                     $user_string = '';
    103                                                 }
     107                                            $crm_user_id = $customer->get_contact_owner();
     108
     109                                            if ( ! empty( $crm_user_id ) ) {
     110                                                $user        = get_user_by( 'id', $crm_user_id );
     111                                                $user_string = esc_html( $user->display_name );
     112                                                $user_email  = $user->get( 'user_email' );
     113                                            } else {
     114                                                $user_string = '';
     115                                            }
    104116                                            ?>
    105117                                            <?php if ( $crm_user_id && ! empty( $user ) ) { ?>
     
    164176                                        <p>
    165177                                            <input style="width: 82%;" data-wp-taxonomy="erp_crm_tag" type="text" id="new-tag-erp-crm-tag" name="newtag[erp_crm_tag]" class="newtag form-input-tip" size="16" autocomplete="on" aria-describedby="new-tag-erp-crm-tag-desc" value="" />
    166                                             <input type="button" id="add-crm-tag" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" /></p>
     178                                            <input type="button" id="add-crm-tag" class="button tagadd" value="<?php esc_attr_e( 'Add', 'erp' ); ?>" /></p>
    167179                                    </div>
    168180                                    <p class="howto" id="new-tag-erp-crm-tag-desc"><?php esc_attr_e( 'Separate tags with commas', 'erp' ); ?></p>
  • erp/trunk/modules/crm/views/contact/single.php

    r2417217 r2428546  
    11<?php
    2 $contact_tags     = wp_get_object_terms( $customer->id, 'erp_crm_tag', ['orderby' => 'name', 'order' => 'ASC'] );
     2if (
     3    ! current_user_can( erp_crm_get_manager_role() ) &&
     4    ! current_user_can( 'manage_options' ) &&
     5    intval( $customer->contact_owner ) !== get_current_user_id()
     6) {
     7    wp_die( __( 'Unauthorized request.', 'erp' ), 401 );
     8}
     9
     10$contact_tags     = wp_get_object_terms( $customer->id, 'erp_crm_tag', [ 'orderby' => 'name', 'order' => 'ASC' ] );
    311$contact_tags     = wp_list_pluck( $contact_tags, 'name' );
    4 $contact_list_url = add_query_arg( ['page' => 'erp-crm', 'section' => 'contacts'], admin_url( 'admin.php' ) );
     12$contact_list_url = add_query_arg( [ 'page' => 'erp-crm', 'section' => 'contacts' ], admin_url( 'admin.php' ) );
    513?>
    614<div class="wrap erp erp-crm-customer erp-single-customer" id="wp-erp" v-cloak>
    7     <h2><?php esc_attr_e( 'Contact #', 'erp' ); echo esc_attr( $customer->id ); ?>
     15    <h2>
     16        <?php
     17        esc_attr_e( 'Contact #', 'erp' );
     18        echo esc_attr( $customer->id );
     19        ?>
    820        <a href="<?php echo esc_url_raw( $contact_list_url ); ?>" id="erp-contact-list" class="add-new-h2"><?php esc_attr_e( 'Back to Contact list', 'erp' ); ?></a>
    921
     
    4153                                <?php } ?>
    4254
    43                                 <?php if ( $customer->get_mobile() != '—' ) { ?>
     55                                <?php if ( $customer->get_mobile() !== '—' ) { ?>
    4456                                    <p>
    4557                                        <i class="fa fa-phone"></i>&nbsp;
     
    96108                                        <div class="user-wrap-content">
    97109                                            <?php
    98                                                 $crm_user_id = $customer->get_contact_owner();
    99 
    100                                                 if ( !empty( $crm_user_id ) ) {
    101                                                     $user        = get_user_by( 'id', $crm_user_id );
    102                                                     $user_string = esc_html( $user->display_name );
    103                                                     $user_email  = $user->get( 'user_email' );
    104                                                 } else {
    105                                                     $user_string = '';
    106                                                 }
     110                                            $crm_user_id = $customer->get_contact_owner();
     111
     112                                            if ( ! empty( $crm_user_id ) ) {
     113                                                $user        = get_user_by( 'id', $crm_user_id );
     114                                                $user_string = esc_html( $user->display_name );
     115                                                $user_email  = $user->get( 'user_email' );
     116                                            } else {
     117                                                $user_string = '';
     118                                            }
    107119                                            ?>
    108120                                            <?php if ( $crm_user_id && ! empty( $user ) ) { ?>
     
    110122                                                <div class="user-details">
    111123                                                    <a href="#"><?php echo esc_attr( get_the_author_meta( 'display_name', $crm_user_id ) ); ?></a>
    112                                                     <span><?php echo esc_attr(  get_the_author_meta( 'user_email', $crm_user_id ) ); ?></span>
     124                                                    <span><?php echo esc_attr( get_the_author_meta( 'user_email', $crm_user_id ) ); ?></span>
    113125                                                </div>
    114126                                            <?php } else { ?>
  • erp/trunk/modules/hrm/includes/api/class-announcements-controller.php

    r2417217 r2428546  
    147147        $id   = wp_insert_post( $item );
    148148
    149         $type = ( $request['recipient_type'] == 'all_employees' ) ? 'all_employee' : 'selected_employee';
     149        $type = ( $request['recipient_type'] == 'all_employee' ) ? 'all_employee' : 'selected_employee';
    150150
    151151        $employees = [];
  • erp/trunk/modules/hrm/includes/class-ajax.php

    r2417217 r2428546  
    20112011        );
    20122012
    2013         $holidays = $holiday->get()->toArray();
     2013        $holidays        = $holiday->get()->toArray();
     2014        $match_holidays  = array();
     2015        $filter_holidays = apply_filters( 'filter_holidays', [], $start_date, $end_date );
     2016
     2017        if ( empty( $filter_holidays ) ) {
     2018            $weekends   = array();
     2019            $work_days  = erp_hr_get_work_days();
     2020
     2021            array_walk( $work_days, function( $value, $key ) use ( &$weekends ) {
     2022                if ( 0 === ( int ) $value ) {
     2023                    $weekends[] = $key ;
     2024                };
     2025            } );
     2026
     2027            $dates = new \DatePeriod(
     2028                new \DateTime( $start_date ),
     2029                new \DateInterval( 'P1D' ),
     2030                new \DateTime( $end_date )
     2031            );
     2032
     2033            foreach ( $dates as $index => $date ) {
     2034                $weekday = strtolower( $date->format( 'D' ) );
     2035                if ( in_array( $weekday, $weekends ) ) {
     2036                    $match_holidays[] = array(
     2037                        'title'      => __( 'Weekly Holiday', 'erp-pro' ),
     2038                        'start'      => erp_current_datetime()
     2039                            ->modify( $date->format( 'Y-m-d' ) )
     2040                            ->setTime( 0, 0, 0 )->format( 'Y-m-d' ),
     2041                        'end'        => erp_current_datetime()
     2042                            ->modify( $date->format( 'Y-m-d' ) )
     2043                            ->setTime( 23, 59, 59 )->format( 'Y-m-d' ),
     2044                        'id'         => $index,
     2045                        'background' => true
     2046                    );
     2047                }
     2048            }
     2049        }
     2050
     2051        $holidays = array_merge( $holidays, $filter_holidays, $match_holidays );
    20142052
    20152053        $events         = array();
     
    20472085        foreach ( erp_array_to_object( $holidays ) as $key => $holiday ) {
    20482086            $holiday_events[] = array(
    2049                 'id'      => $holiday->id,
    2050                 'title'   => $holiday->title,
    2051                 'start'   => $holiday->start,
    2052                 'end'     => $holiday->end,
    2053                 'color'   => '#FF5354',
    2054                 'img'     => '',
    2055                 'url'     => 'javascript:void(0)',
    2056                 'holiday' => true,
     2087                'id'        => $holiday->id,
     2088                'title'     => $holiday->title,
     2089                'start'     => $holiday->start,
     2090                'end'       => $holiday->end,
     2091                'img'       => '',
     2092                'url'       => 'javascript:void(0)',
     2093                'holiday'   => true,
     2094                'rendering' => isset( $holiday->background )
     2095                               && $holiday->background ? 'background' : '',
     2096                'color'     => isset( $holiday->background )
     2097                               && $holiday->background ? '#c5bfbf' : '#FF5354'
    20572098            );
    20582099        }
  • erp/trunk/modules/hrm/includes/class-employee-list-table.php

    r2417217 r2428546  
    108108
    109109            case 'date_of_hire':
    110                 return $employee->get_joined_date();
     110                return erp_format_date( $employee->get_joined_date() );
    111111
    112112            case 'status':
  • erp/trunk/modules/hrm/includes/functions-dashboard-widgets.php

    r2417217 r2428546  
    377377            editable: false,
    378378            eventLimit: true,
     379            firstDay: <?php echo esc_html( get_option( 'start_of_week', 1 ) );?>,
    379380            eventRender: function(event, element, calEvent) {
    380381                if ( event.holiday ) {
  • erp/trunk/modules/hrm/includes/functions-employee.php

    r2417217 r2428546  
    324324
    325325            // find leave entitlements and leave requests and delete them as well
    326             \WeDevs\ERP\HRM\Models\Leave_Request::where( 'user_id', '=', $employee_wp_user_id )->delete();
     326            $leave_requests = \WeDevs\ERP\HRM\Models\Leave_Request::where( 'user_id', '=', $employee_wp_user_id )->get()->toArray();
     327
     328            foreach ( $leave_requests as $lr ) {
     329                // deleting leave requests and entitlements with approval_status
     330                erp_hr_delete_leave_request( absint( $lr['id'] ) );
     331            }
     332
     333            // deleting rest of the leave entitlements
    327334            \WeDevs\ERP\HRM\Models\Leave_Entitlement::where( 'user_id', '=', $employee_wp_user_id )->delete();
     335
    328336            \WeDevs\ERP\HRM\Models\Education::where( 'employee_id', '=', $employee_wp_user_id )->delete();
    329337            \WeDevs\ERP\HRM\Models\Performance::where( 'employee_id', '=', $employee_wp_user_id )->delete();
  • erp/trunk/modules/hrm/includes/functions.php

    r2417217 r2428546  
    2424    $wizard_settings = get_option( $option_key, $default );
    2525
    26     return [
     26    $days = [
    2727        'mon' => get_option( 'mon', $wizard_settings['mon'] ),
    2828        'tue' => get_option( 'tue', $wizard_settings['tue'] ),
     
    3333        'sun' => get_option( 'sun', $wizard_settings['sun'] ),
    3434    ];
     35
     36    return apply_filters( 'work_days', $days );
    3537}
    3638
  • erp/trunk/modules/hrm/views/leave/calendar.php

    r2417217 r2428546  
    9696            },
    9797            editable: false,
     98            firstDay: <?php echo esc_html( get_option( 'start_of_week', 1 ) );?>,
    9899            eventLimit: 4, // allow "more" link when too many events
    99100            events: <?php echo json_encode( $events ); ?>,
  • erp/trunk/modules/hrm/views/reporting/headcount.php

    r2417217 r2428546  
    159159        <tbody>
    160160            <?php
    161                 foreach ( $user_filtered as $user_id ) {
    162                     $employee     = new \WeDevs\ERP\HRM\Employee( intval( $user_id ) );
    163                     $employee_url = '<a href="' . admin_url( 'admin.php?page=erp-hr&section=employee&action=view&id=' . $employee->get_user_id() ) . '">' . $employee->display_name . '</a>';
    164                     $date_format  = get_option( 'date_format' ); ?>
    165                     <tr>
    166                         <td><?php echo wp_kses_post( $employee_url ); ?></td>
    167                         <td><?php echo esc_html( date( $date_format, strtotime( esc_attr( $employee->hiring_date ) ) ) ); ?></td>
    168                         <td><?php echo esc_attr( $employee->designation_title ); ?></td>
    169                         <td><?php echo esc_attr( $employee->department_title ); ?></td>
    170                         <td><?php echo esc_attr( $employee->location_name ); ?></td>
    171                         <td><?php echo esc_attr( $employee->status ); ?></td>
    172                     </tr>
     161            foreach ( $user_filtered as $user_id ) {
     162                $employee     = new \WeDevs\ERP\HRM\Employee( intval( $user_id ) );
     163                $employee_url = '<a href="' . admin_url( 'admin.php?page=erp-hr&section=employee&action=view&id=' . $employee->get_user_id() ) . '">' . $employee->display_name . '</a>';
     164            ?>
     165                <tr>
     166                    <td><?php echo wp_kses_post( $employee_url ); ?></td>
     167                    <td><?php echo erp_format_date( esc_attr( $employee->hiring_date ) ); ?></td>
     168                    <td><?php echo esc_attr( $employee->designation_title ); ?></td>
     169                    <td><?php echo esc_attr( $employee->department_title ); ?></td>
     170                    <td><?php echo esc_attr( $employee->location_name ); ?></td>
     171                    <td><?php echo esc_attr( $employee->status ); ?></td>
     172                </tr>
    173173            <?php
    174174                }
  • erp/trunk/modules/hrm/views/reporting/salary-history.php

    r2417217 r2428546  
    33
    44$all_user_id = $wpdb->get_col( "SELECT user_id FROM {$wpdb->prefix}erp_hr_employees WHERE status = 'active' ORDER BY hiring_date DESC" );
    5 $date_format = get_option( 'date_format' );
    65?>
    76<div class="wrap">
     
    3332                            echo '<tr>';
    3433                            echo '<td>' . wp_kses_post( $emp_url ) . '</td>';
    35                             echo '<td>' . esc_html( date( $date_format, strtotime( esc_attr( $compensation['date'] ) ) ) ) . '</td>';
     34                            echo '<td>' . erp_format_date( esc_attr( $compensation['date'] ) ) . '</td>';
    3635                            echo '<td>' . esc_attr( $compensation['pay_rate'] ) . '</td>';
    3736                            echo '<td>' . esc_attr( $compensation['pay_type'] ) . '</td>';
  • erp/trunk/readme.txt

    r2422366 r2428546  
    66Tested up to: 5.5.3
    77Requires PHP: 5.6
    8 Stable tag: 1.6.9
     8Stable tag: 1.7.0
    99License: GPLv2
    1010License: GPLv2 or later
     
    280280
    281281== Changelog ==
     282
     283= v1.7.0 -> November 30, 2020 =
     284--------------------------
     285- [new] Added Accounting vendor import option in the CSV import feature
     286- [new] Added Accounting vendor export option in the CSV export feature
     287- [new] Added filter at holiday calender
     288- [new] Added hr calendar weekend marker
     289- [new] Added filter at workdays
     290- [fix] Fixed issue of deleting all leave related references when an employee is permanently deleted
     291- [fix] Fixed permission issue of contact and company single pages to ensure no unauthorized user can access those pages
     292- [fix] Fixed CRM contact form integration issue to prevent contact owner from being reset every time a contact form is submitted by an existing contact
     293- [fix] Fixed issue of contact form settings so that the settings can not be saved without selecting contact owner as a required field
     294- [fix] Set hr calendar starting day as per settings
     295- [fix] Fixed announcement employee selection tag
     296- [fix] Fixed issue of deleting all leave related references when an employee is permanently deleted
     297- [update] Updated weekend from setting at hr leave calendar
     298- [update] Updated validation for CSV import to show row-wise detailed error notice when import operation fails
    282299
    283300= v1.6.9 -> November 20, 2020 =
  • erp/trunk/wp-erp.php

    r2422366 r2428546  
    66 * Author: weDevs
    77 * Author URI: https://wedevs.com
    8  * Version: 1.6.9
     8 * Version: 1.7.0
    99 * License: GPL2
    1010 * Text Domain: erp
     
    5353     * @var string
    5454     */
    55     public $version = '1.6.9';
     55    public $version = '1.7.0';
    5656
    5757    /**
Note: See TracChangeset for help on using the changeset viewer.