// Add a progress bar to show table record collection.
echo '<tr class="odd" id="progress_row"><td valign="top" colspan="8" class="dataTables_empty"><div id="rows_progress" style="width:100%;border:1px solid #ccc;"></div> <div id="table_progress">' . self::__('Preparing rows...') . '</div></td></tr>';
$records = new WP_Query($args);
$i = 0;
while ($records->have_posts()) {
    $records->the_post();
    // Calculate the percentage
    $i++;
    $percent = intval($i / $records->found_posts * 100) . "%";
    // Javascript for updating the progress bar and information
    echo '<script language="javascript" id="progress_js">
						document.getElementById("rows_progress").innerHTML="<div style=\\"width:' . $percent . ';background-color:#ddd;\\">&nbsp;</div>";
						document.getElementById("table_progress").innerHTML="' . sprintf(self::__('%o records(s) of %o added.'), $i, $records->found_posts) . '";
						document.getElementById("progress_js").remove();
						</script>';
    $table_total_estimated += si_get_estimate_total();
    $table_subtotal += si_get_estimate_subtotal();
    $invoice_name = si_get_estimate_invoice_id() ? sprintf('<a href="%s">%s</a>', get_edit_post_link(si_get_estimate_invoice_id()), get_the_title(si_get_estimate_invoice_id())) : self::__('N/A');
    $client_name = si_get_estimate_client_id() ? sprintf('<a href="%s">%s</a>', get_edit_post_link(si_get_estimate_client_id()), get_the_title(si_get_estimate_client_id())) : self::__('N/A');
    ?>
						<tr> 
							<td><?php 
    the_ID();
    ?>
</td>
							<td><span class="si_status estimate_status <?php 
    si_estimate_status();
    ?>
"><?php 
    si_estimate_status();
    ?>
    ?>
										</div>
									<?php 
}
?>

									<div id="line_total">
										<b title="<?php 
si_e('Total includes discounts and other fees.');
?>
" class="helptip"><?php 
si_e('Total');
?>
</b>
										<?php 
sa_formatted_money(si_get_estimate_total());
?>
									</div>
								</div>
							</footer>
						</div><!-- #doc_line_items -->

					</section>

					<section id="doc_notes">
						<?php 
do_action('si_document_notes_pre');
?>
						<?php 
if (strlen(si_get_estimate_notes()) > 1) {
    ?>
 public static function get_localized_js()
 {
     // Localization
     $si_js_object = array('ajax_url' => get_admin_url() . '/admin-ajax.php', 'plugin_url' => SI_URL, 'thank_you_string' => self::__('Thank you'), 'updating_string' => self::__('Updating...'), 'sorry_string' => self::__('Bummer. Maybe next time?'), 'security' => wp_create_nonce(self::NONCE), 'locale' => get_locale(), 'locale_standard' => str_replace('_', '-', get_locale()), 'inline_spinner' => '<span class="spinner si_inline_spinner" style="visibility:visible;display:inline-block;"></span>');
     if (is_single() && get_post_type(get_the_ID()) === SI_Invoice::POST_TYPE) {
         $si_js_object += array('invoice_id' => get_the_ID(), 'invoice_amount' => si_get_invoice_calculated_total(), 'invoice_balance' => si_get_invoice_balance());
     }
     if (is_single() && get_post_type(get_the_ID()) === SI_Estimate::POST_TYPE) {
         $si_js_object += array('estimate_id' => get_the_ID(), 'estimate_total' => si_get_estimate_total());
     }
     return apply_filters('si_sprout_doc_scripts_localization', $si_js_object);
 }
 public static function total_estimate_data_by_date_segment($segment = 'weeks', $span = 6)
 {
     // Return cache if present.
     $cache = self::get_cache(__FUNCTION__ . $segment . $span);
     if ($cache) {
         return $cache;
     }
     $frames = self::walk_back_x_span($span, $segment);
     $date_format = self::get_segment_date_format($segment);
     $year = date('Y', strtotime($span . ' ' . $segment . ' ago'));
     $start_date = date('Y-m-d', strtotime($span . ' ' . $segment . ' ago'));
     // Build data array, without a explicit build segments without posts will not show.
     $data = array();
     foreach ($frames as $frame_date) {
         $data[$frame_date] = array('estimates' => 0, 'requests' => 0, 'totals' => 0, 'subtotals' => 0, 'invoices_generated' => 0, 'status_request' => 0, 'status_pending' => 0, 'status_approved' => 0, 'status_declined' => 0);
     }
     $args = array('post_type' => SI_Estimate::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'date', 'fields' => 'ids', 'date_query' => array(array('after' => $start_date, 'inclusive' => true)));
     $estimates = new WP_Query($args);
     foreach ($estimates->posts as $estimate_id) {
         $frame = get_the_time($date_format, $estimate_id);
         $data[$frame]['estimates'] += 1;
         $data[$frame]['totals'] += si_get_estimate_total($estimate_id);
         $data[$frame]['subtotals'] += si_get_estimate_subtotal($estimate_id);
         if (si_get_estimate_invoice_id($estimate_id)) {
             $data[$frame]['invoices_generated'] += 1;
         }
         // If there are submission fields than it's a request
         if (si_is_estimate_submission($estimate_id)) {
             $data[$frame]['requests'] += 1;
         }
         switch (get_post_status($estimate_id)) {
             case SI_Estimate::STATUS_REQUEST:
                 $data[$frame]['status_request'] += 1;
                 break;
             case SI_Estimate::STATUS_PENDING:
                 $data[$frame]['status_pending'] += 1;
                 break;
             case SI_Estimate::STATUS_APPROVED:
                 $data[$frame]['status_approved'] += 1;
                 break;
             case SI_Estimate::STATUS_DECLINED:
                 $data[$frame]['status_declined'] += 1;
                 break;
             default:
                 break;
         }
     }
     return self::set_cache(__FUNCTION__ . $segment . $span, $data, self::CACHE_TIMEOUT);
 }
 /**
  * Echo the estimate total
  * @param  integer $id
  * @return string
  */
 function si_estimate_total($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     echo apply_filters('si_estimate_total', sa_get_formatted_money(si_get_estimate_total($id), $id), $id);
 }
 /**
  * Echo the estimate total
  * @param  integer $id 
  * @return string      
  */
 function si_estimate_total($id = 0)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     echo apply_filters('si_estimate_total', sa_get_formatted_money(si_get_estimate_total($id), $id), $id);
 }