예제 #1
0
 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);
 }
예제 #2
0
?>

							</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_invoice_subtotal());
?>
									</div>
									<?php 
if (si_get_invoice_taxes_total()) {
    ?>
										<div id="line_taxes">
											<b><?php 
    si_e('Taxes');
    ?>
</b>
											<?php 
    sa_formatted_money(si_get_invoice_taxes_total());
    ?>
										</div>
									<?php 
예제 #3
0
 /**
  * Echo the invoice subtotal
  * @param  integer $id 
  * @return string      
  */
 function si_invoice_subtotal($id = 0)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     echo apply_filters('si_invoice_subtotal', si_get_invoice_subtotal($id), $id);
 }
예제 #4
0
 /**
  * Echo the invoice subtotal
  * @param  integer $id
  * @return string
  */
 function si_invoice_subtotal($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     echo apply_filters('si_invoice_subtotal', si_get_invoice_subtotal($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);
 }