Ejemplo n.º 1
0
/**
 * Get users as array
 *
 * @since 1.0
 *
 * @param  array   $args
 *
 * @return array
 */
function erp_get_peoples_array($args = [])
{
    $users = [];
    $peoples = erp_get_peoples($args);
    foreach ($peoples as $user) {
        $users[$user->id] = 'company' == $user->type ? $user->company : $user->first_name . ' ' . $user->last_name;
    }
    return $users;
}
Ejemplo n.º 2
0
/**
 * Get contact dropdown list as array
 *
 * @since 1.0
 *
 * @param  array  $label
 *
 * @return array | list of all contact with copmany
 */
function erp_crm_get_contact_dropdown($label = [])
{
    $contacts = erp_get_peoples(['number' => '-1', 'type' => ['contact', 'company']]);
    $list = [];
    foreach ($contacts as $key => $contact) {
        $name = $contact->type == 'company' ? $contact->company : $contact->first_name . ' ' . $contact->last_name;
        $list[$contact->id] = $name . ' ( ' . ucfirst($contact->type) . ' ) ';
    }
    if ($label) {
        $list = $label + $list;
    }
    return $list;
}
 /**
  * Prepare the class items
  *
  * @return void
  */
 function prepare_items()
 {
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $per_page = 20;
     $current_page = $this->get_pagenum();
     $offset = ($current_page - 1) * $per_page;
     $this->page_status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : '2';
     // only ncessary because we have sample data
     $args = array('offset' => $offset, 'number' => $per_page, 'type' => $this->type);
     if (isset($_REQUEST['orderby']) && isset($_REQUEST['order'])) {
         $args['orderby'] = $_REQUEST['orderby'];
         $args['order'] = $_REQUEST['order'];
     }
     $this->items = erp_get_peoples($args);
     $this->set_pagination_args(array('total_items' => erp_get_peoples_count($this->type), 'per_page' => $per_page));
 }
Ejemplo n.º 4
0
 /**
  * Prepare the class items
  *
  * @since 1.0
  *
  * @return void
  */
 function prepare_items()
 {
     $columns = $this->get_columns();
     $hidden = [];
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = [$columns, $hidden, $sortable];
     $per_page = 20;
     $current_page = $this->get_pagenum();
     $offset = ($current_page - 1) * $per_page;
     $this->page_status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : 'all';
     // only ncessary because we have sample data
     $args = ['type' => $this->contact_type, 'offset' => $offset, 'number' => $per_page];
     // Filter for serach
     if (isset($_REQUEST['s']) && !empty($_REQUEST['s'])) {
         $args['s'] = $_REQUEST['s'];
     }
     // Filter for order by
     if (isset($_REQUEST['orderby']) && !empty($_REQUEST['orderby'])) {
         $args['orderby'] = $_REQUEST['orderby'];
     }
     // Filter for order
     if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
         $args['order'] = $_REQUEST['order'];
     }
     // Filter for cusotmer life stage
     if (isset($_REQUEST['status']) && !empty($_REQUEST['status'])) {
         if ($_REQUEST['status'] != 'all') {
             if ($_REQUEST['status'] == 'trash') {
                 $args['trashed'] = true;
             } else {
                 $args['meta_query'] = ['meta_key' => 'life_stage', 'meta_value' => $_REQUEST['status']];
             }
         }
     }
     // Total counting for customer type filter
     $this->counts = erp_crm_customer_get_status_count($this->contact_type);
     // Prepare all item after all filtering
     $this->items = erp_get_peoples($args);
     // Render total customer according to above filter
     $args['count'] = true;
     $total_items = erp_get_peoples($args);
     // Set pagination according to filter
     $this->set_pagination_args(['total_items' => $total_items, 'per_page' => $per_page]);
 }