document.getElementById("table_progress").innerHTML="' . sprintf(__('%o records(s) of %o added.', 'sprout-invoices'), $i, $records->found_posts) . '";
						document.getElementById("progress_js").remove();
						</script>';
    $payment = SI_Payment::get_instance(get_the_ID());
    $invoice_id = $payment->get_invoice_id();
    if ($payment->get_status() == SI_Payment::STATUS_VOID) {
        $table_voided_payment_total += $payment->get_amount();
        $payment_total = 0;
        $payment_void_total = $payment->get_amount();
    } else {
        $table_payment_total += $payment->get_amount();
        $payment_total = $payment->get_amount();
        $payment_void_total = 0;
    }
    $payment_link = sprintf('<a class="payments_link" title="%s" href="%s&s=%s">#%s</a>', __('Payment', 'sprout-invoices'), get_admin_url('', '/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments'), get_the_ID(), get_the_ID());
    $payments_link = sprintf('<a class="payments_link" title="%s" href="%s&s=%s">%s</a>', __('Invoice Payments', 'sprout-invoices'), get_admin_url('', '/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments'), $invoice_id, sa_get_formatted_money(si_get_invoice_payments_total($invoice_id)));
    $invoice_name = $invoice_id ? sprintf('<a href="%s">%s</a>', get_edit_post_link($invoice_id), get_the_title($invoice_id)) : __('N/A', 'sprout-invoices');
    $client_name = si_get_invoice_client_id($invoice_id) ? sprintf('<a href="%s">%s</a>', get_edit_post_link(si_get_invoice_client_id($invoice_id)), get_the_title(si_get_invoice_client_id($invoice_id))) : __('N/A', 'sprout-invoices');
    ?>
						<tr> 
							<td><?php 
    echo $payment_link;
    ?>
</td>
							<td><span class="si_status payment_status <?php 
    echo esc_attr($payment->get_status());
    ?>
"><?php 
    echo str_replace('Publish', 'Complete', ucfirst($payment->get_status()));
    ?>
</span></td>
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">' . __('Preparing rows...', 'sprout-invoices') . '</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(__('%o records(s) of %o added.', 'sprout-invoices'), $i, $records->found_posts) . '";
						document.getElementById("progress_js").remove();
						</script>';
    $table_total_invoiced += si_get_invoice_calculated_total();
    $table_total_paid += si_get_invoice_payments_total();
    $table_total_balance += si_get_invoice_balance();
    $client_name = si_get_invoice_client_id() ? sprintf('<a href="%s">%s</a>', get_edit_post_link(si_get_invoice_client_id()), get_the_title(si_get_invoice_client_id())) : __('N/A', 'sprout-invoices');
    ?>
						<tr> 
							<td><?php 
    echo si_get_invoice_id(get_the_id());
    ?>
</td>
							<td><span class="si_status <?php 
    si_invoice_status();
    ?>
"><?php 
    si_invoice_status();
    ?>
</span></td>
 public static function total_invoice_data($this = 'century')
 {
     // Return cache if present.
     $cache = self::get_cache(__FUNCTION__ . $this);
     if ($cache) {
         return $cache;
     }
     $expire = self::CACHE_TIMEOUT;
     // Build data array, without a explicit build segments without posts will not show.
     $data = array('invoices' => 0, 'payments' => 0, 'totals' => 0, 'subtotals' => 0, 'paid' => 0, 'balance' => 0, 'status_temp' => 0, 'status_pending' => 0, 'status_partial' => 0, 'status_complete' => 0, 'status_writeoff' => 0);
     $args = array('post_type' => SI_Invoice::POST_TYPE, 'post_status' => array(SI_Invoice::STATUS_PENDING, SI_Invoice::STATUS_PARTIAL, SI_Invoice::STATUS_PAID), 'posts_per_page' => -1, 'fields' => 'ids');
     // If date filtered
     if ('century' !== $this) {
         switch ($this) {
             case 'week':
                 $args['date_query'] = array(array('week' => date('W', strtotime('this week')), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t'), strtotime('this Sunday')) - current_time('timestamp');
                 break;
             case 'lastweek':
                 $args['date_query'] = array(array('week' => date('W', strtotime('-1 week')), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t'), strtotime('this Sunday')) - current_time('timestamp');
                 break;
             case 'month':
                 $args['date_query'] = array(array('month' => date('m'), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t')) - current_time('timestamp');
                 break;
             case 'lastmonth':
                 $args['date_query'] = array(array('month' => date('m', strtotime('-1 month')), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t')) - current_time('timestamp');
                 break;
             case 'year':
                 $args['date_query'] = array(array('year' => date('Y'), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t'), strtotime('12/31')) - current_time('timestamp');
                 break;
             case 'lastyear':
                 $args['date_query'] = array(array('year' => date('Y', strtotime('-1  year')), 'inclusive' => true));
                 $expire = strtotime(date('Y-m-t'), strtotime('12/31')) - current_time('timestamp');
                 break;
             default:
                 break;
         }
     }
     $invoices = new WP_Query($args);
     foreach ($invoices->posts as $invoice_id) {
         $invoice = SI_Invoice::get_instance($invoice_id);
         $data['invoices'] += 1;
         $data['payments'] += count($invoice->get_payments());
         $data['totals'] += si_get_invoice_calculated_total($invoice_id);
         $data['subtotals'] += si_get_invoice_subtotal($invoice_id);
         $data['paid'] += si_get_invoice_payments_total($invoice_id);
         $data['balance'] += si_get_invoice_balance($invoice_id);
         switch (get_post_status($invoice_id)) {
             case 'draft':
             case SI_Invoice::STATUS_TEMP:
                 $data['status_temp'] += 1;
                 break;
             case SI_Invoice::STATUS_PENDING:
                 $data['status_pending'] += 1;
                 break;
             case SI_Invoice::STATUS_PARTIAL:
                 $data['status_partial'] += 1;
                 break;
             case SI_Invoice::STATUS_PAID:
                 $data['status_complete'] += 1;
                 break;
             case SI_Invoice::STATUS_WO:
                 $data['status_writeoff'] += 1;
                 break;
             default:
                 break;
         }
         unset($invoice);
     }
     return self::set_cache(__FUNCTION__ . $this, $data, $expire);
 }
Example #4
0
    ?>
" alt="document logo" >
									<?php 
}
?>
								</h1>	
							</header><!-- /header -->
							<?php 
if (si_get_invoice_status() == 'write-off') {
    ?>
								<span id="status" class="void"><span class="inner_status"><?php 
    _e('Void', 'sprout-invoices');
    ?>
</span></span>
							<?php 
} elseif (si_get_invoice_balance() > 0.0 && si_get_invoice_balance() <= si_get_invoice_payments_total()) {
    ?>
								<span id="status" class="void"><span class="inner_status"><?php 
    _e('Payment Pending', 'sprout-invoices');
    ?>
</span></span>
							<?php 
} elseif (!si_get_invoice_balance()) {
    ?>
								<span id="status" class="paid"><span class="inner_status"><?php 
    _e('Paid', 'sprout-invoices');
    ?>
</span></span>
							<?php 
}
?>
</b>
										<?php 
sa_formatted_money(si_get_invoice_calculated_total());
?>
									</div>
									<?php 
if (si_get_invoice_payments_total()) {
    ?>
										<hr/>
										<div id="line_payments">
											<b><?php 
    si_e('Payments');
    ?>
</b>
											<?php 
    sa_formatted_money(si_get_invoice_payments_total());
    ?>
										</div>
										<div id="line_balance">
											<b><?php 
    si_e('Balance');
    ?>
</b>
											<?php 
    sa_formatted_money(si_get_invoice_balance());
    ?>
										</div>
									<?php 
}
?>
								</div>
 /**
  * Echo the invoice total
  * @param  integer $id
  * @return string
  */
 function si_invoice_payments_total($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     echo apply_filters('si_invoice_payments_total', sa_get_formatted_money(si_get_invoice_payments_total($id), $id), $id);
 }
 /**
  * Echo the invoice total
  * @param  integer $id 
  * @return string      
  */
 function si_invoice_payments_total($id = 0)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     echo apply_filters('si_invoice_payments_total', sa_get_formatted_money(si_get_invoice_payments_total($id), $id), $id);
 }