예제 #1
0
 function wpestate_ajax_filter_invoices()
 {
     global $current_user;
     get_currentuserinfo();
     $userID = $current_user->ID;
     $start_date = esc_html($_POST['start_date']);
     $end_date = esc_html($_POST['end_date']);
     $type = esc_html($_POST['type']);
     $status = esc_html($_POST['status']);
     $meta_query = array();
     if (isset($_POST['type']) && $_POST['type'] != '') {
         $temp_arr = array();
         $type = esc_html($_POST['type']);
         $temp_arr['key'] = 'invoice_type';
         $temp_arr['value'] = $type;
         $temp_arr['type'] = 'char';
         $temp_arr['compare'] = 'LIKE';
         $meta_query[] = $temp_arr;
     }
     if (isset($_POST['status']) && $_POST['status'] != '') {
         $temp_arr = array();
         $type = esc_html($_POST['status']);
         $temp_arr['key'] = 'invoice_status';
         $temp_arr['value'] = $type;
         $temp_arr['type'] = 'char';
         $temp_arr['compare'] = 'LIKE';
         $meta_query[] = $temp_arr;
     }
     $date_query = array();
     if (isset($_POST['start_date']) && $_POST['start_date'] != '') {
         $start_date = esc_html($_POST['start_date']);
         $date_query['after'] = $start_date;
     }
     if (isset($_POST['end_date']) && $_POST['end_date'] != '') {
         $end_date = esc_html($_POST['end_date']);
         $date_query['before'] = $end_date;
     }
     $date_query['inclusive'] = true;
     $args = array('post_type' => 'wpestate_invoice', 'post_status' => 'publish', 'posts_per_page' => -1, 'author' => $userID, 'meta_query' => $meta_query, 'date_query' => $date_query);
     // print_r($args);
     $prop_selection = new WP_Query($args);
     $total_confirmed = 0;
     $total_issued = 0;
     ob_start();
     while ($prop_selection->have_posts()) {
         $prop_selection->the_post();
         get_template_part('templates/invoice_listing_unit');
         $inv_id = get_the_ID();
         $status = esc_html(get_post_meta($inv_id, 'invoice_status', true));
         $type = esc_html(get_post_meta($inv_id, 'invoice_type', true));
         $price = esc_html(get_post_meta($inv_id, 'item_price', true));
         if (trim($type) == 'Reservation fee') {
             if ($status == 'confirmed') {
                 $total_confirmed = $total_confirmed + $price;
             }
             if ($status == 'issued') {
                 $total_issued = $total_issued + $price;
             }
         } else {
             $total_issued = '-';
             $total_confirmed = $total_confirmed + $price;
         }
     }
     $templates = ob_get_contents();
     ob_end_clean();
     echo json_encode(array('results' => $templates, 'invoice_issued' => wpestate_show_price_custom_invoice($total_issued), 'invoice_confirmed' => wpestate_show_price_custom_invoice($total_confirmed)));
     die;
 }
                    <div class="col-md-3">
                        <select id="invoice_status" name="invoice_status" class="form-control">
                            <option value="">' . esc_html__('Any', 'wpestate') . '</option>
                            <option value="confirmed">' . esc_html__('confirmed', 'wpestate') . '</option>
                            <option value="issued">' . esc_html__('issued', 'wpestate') . '</option>   
                        </select>
                    
                    </div>

                </div>
                    
                <div class="invoices_explanation">' . esc_html__('Reservation fees filter applies only to the invoices issued by you!', 'wpestate') . '</div>

                <div class="col-md-12 invoice_totals">
                <strong>' . esc_html__('Total Invoices Confirmed: ', 'wpestate') . '</strong><span id="invoice_confirmed">' . wpestate_show_price_custom_invoice($total_confirmed) . '</span>
                <strong>' . esc_html__('Total Invoices Issued: ', 'wpestate') . '</strong><span id="invoice_issued">' . wpestate_show_price_custom_invoice($total_issued) . '</span>
                </div>
                ';
print '<div class="col-md-12 invoice_unit_title">
                    <div class="col-md-2">
                        <strong> ' . esc_html__('Title', 'wpestate') . '</strong> 
                    </div>

                    <div class="col-md-2">
                         <strong> ' . esc_html__('Date', 'wpestate') . '</strong> 
                    </div>

                    <div class="col-md-2">
                         <strong> ' . esc_html__('Invoice Type', 'wpestate') . '</strong> 
                    </div>