// 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">' . __('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;\\"> </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(); ?>
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_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); }
sa_formatted_money(si_get_invoice_taxes_total()); ?> </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_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>
/** * Check to see if the deposit is calculated or there's an actual deposit * @param integer $id * @return string */ function si_has_invoice_deposit($id = 0) { if (!$id) { $id = get_the_ID(); } $deposit = si_get_invoice_deposit($id); if ($deposit < 0.01) { return false; } $total = si_get_invoice_calculated_total($id); return $deposit < $total; }
/** * Check to see if the deposit is calculated or there's an actual deposit * @param integer $id * @return string */ function si_has_invoice_deposit($id = 0) { if (!$id) { global $post; $id = $post->ID; } $deposit = si_get_invoice_deposit($id); if ($deposit < 0.01) { return false; } $total = si_get_invoice_calculated_total($id); return $deposit < $total; }