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();
    ?>
</span></td>
?>

							</ol>

							<footer id="line_items_footer" class="clearfix">
								<?php 
do_action('si_document_line_items_footer');
?>
								<div id="line_items_totals">
									<div id="line_subtotal">
										<b><?php 
si_e('Subtotal');
?>
</b>
										<?php 
sa_formatted_money(si_get_estimate_subtotal());
?>
									</div>

									<?php 
if (si_get_estimate_taxes_total()) {
    ?>
										<div id="line_taxes">
											<b><?php 
    si_e('Taxes');
    ?>
</b>
											<?php 
    sa_formatted_money(si_get_estimate_taxes_total());
    ?>
										</div>
 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 subtotal
  * @param  integer $id
  * @return string
  */
 function si_estimate_subtotal($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     echo apply_filters('si_estimate_subtotal', sa_get_formatted_money(si_get_estimate_subtotal($id), $id), $id);
 }
 /**
  * Echo the estimate subtotal
  * @param  integer $id 
  * @return string      
  */
 function si_estimate_subtotal($id = 0)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     echo apply_filters('si_estimate_subtotal', sa_get_formatted_money(si_get_estimate_subtotal($id), $id), $id);
 }
 public static function discount($atts = array())
 {
     $discount = 0;
     if (si_get_doc_context() == 'estimate') {
         $discount = si_get_estimate_subtotal() * (si_get_estimate_discount() / 100);
     } else {
         $discount = si_get_invoice_subtotal() * (si_get_invoice_discount() / 100);
     }
     return sa_get_formatted_money($discount);
 }