public static function add_time_line_item_type_columns($columns = array(), $type = '') { if (self::LINE_ITEM_TYPE !== $type) { return $columns; } $columns = array('desc' => array('label' => __('Time', 'sprout-invoices'), 'type' => 'textarea', 'calc' => false, 'hide_if_parent' => false, 'weight' => 1), 'rate' => array('label' => __('Rate', 'sprout-invoices'), 'type' => 'small-input', 'placehselect2-dropdownolder' => '120', 'calc' => false, 'hide_if_parent' => true, 'weight' => 5), 'qty' => array('label' => __('Hours', 'sprout-invoices'), 'type' => 'small-input', 'placeholder' => 1, 'calc' => true, 'hide_if_parent' => true, 'weight' => 10), 'tax' => array('label' => sprintf('% <span class="helptip" title="%s"></span>', __('A percentage adjustment per line item, i.e. tax or discount', 'sprout-invoices')), 'type' => 'small-input', 'placeholder' => 0, 'calc' => false, 'hide_if_parent' => true, 'weight' => 15), 'total' => array('label' => __('Amount', 'sprout-invoices'), 'type' => 'total', 'placeholder' => sa_get_formatted_money(0), 'calc' => true, 'hide_if_parent' => false, 'weight' => 50), 'sku' => array('type' => 'hidden', 'placeholder' => '', 'calc' => false, 'weight' => 50), 'time_id' => array('type' => 'hidden', 'placeholder' => '', 'calc' => false, 'weight' => 50)); return $columns; }
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>
public static function store_format_option() { if (isset($_GET['page']) && $_GET['page'] == 'sprout-apps/settings') { update_option(self::MONEY_FORMAT_OPTION, sa_get_formatted_money(rand(11000, 9999999))); } }
public static function ajax_number_formatter() { if (!isset($_REQUEST['number'])) { self::ajax_fail('Forget something?'); } $nonce = $_REQUEST['security']; if (!wp_verify_nonce($nonce, self::NONCE)) { self::ajax_fail('Not going to fall for it!'); } $number = $_REQUEST['number']; $currency = array('money' => sa_get_formatted_money($number), 'unformatted_money' => sa_get_unformatted_money($number), 'float' => si_get_number_format($number), 'int' => (int) si_get_number_format($number)); header('Content-type: application/json'); if (self::DEBUG) { header('Access-Control-Allow-Origin: *'); } echo wp_json_encode($currency); exit; }
function si_line_item_build($position = 1.0, $items = array(), $children = array()) { $data = $items[$position]; $has_percentage_adj = false; foreach ($items as $b_position => $b_data) { if (isset($b_data['tax']) && $b_data['tax']) { $has_percentage_adj = true; } } $desc = isset($data['desc']) ? $data['desc'] : ''; $rate = isset($data['rate']) ? $data['rate'] : 0; $qty = isset($data['qty']) ? $data['qty'] : 0; $total = isset($data['total']) ? $data['total'] : 0; if (!empty($children)) { $total = 0; foreach ($children as $child_position) { $child_data = $items[$child_position]; $total += $child_data['total']; } $data['rate'] = ''; $data['qty'] = ''; $data['tax'] = ''; } ob_start(); ?> <?php do_action('si_line_item_build_pre_row', $data, $items, $position, $children); ?> <div class="line_item<?php if (!empty($children)) { echo ' has_children'; } ?> "> <div class="column column_desc"> <?php echo apply_filters('si_line_item_content', $desc); ?> <?php do_action('si_line_item_build_desc', $data, $items, $position, $children); ?> </div><!-- / item_action_column --> <div class="column column_rate"> <?php if (empty($children)) { ?> <?php esc_attr_e(sa_get_formatted_money($rate)); ?> <?php } ?> <?php do_action('si_line_item_build_rate', $data, $items, $position, $children); ?> </div><!-- / column_rate --> <div class="column column_qty"> <?php if (empty($children)) { ?> <?php esc_attr_e($qty); ?> <?php } ?> <?php do_action('si_line_item_build_qty', $data, $items, $position, $children); ?> </div><!-- / column_qty --> <?php if ($has_percentage_adj) { ?> <div class="column column_tax"> <?php if (isset($data['tax']) && $data['tax']) { ?> <?php esc_attr_e($data['tax']); ?> % <?php } ?> <?php do_action('si_line_item_build_tax', $data, $items, $position, $children); ?> </div><!-- / column_tax --> <?php } ?> <div class="column column_total"> <?php sa_formatted_money($total); ?> <?php do_action('si_line_item_build_total', $data, $items, $position, $children); ?> </div><!-- / column_total --> </div> <?php do_action('si_line_item_build_row', $data, $items, $position, $children); ?> <?php $data = ob_get_contents(); ob_end_clean(); return apply_filters('si_line_item_build', $data, $position, $items, $children); }
public function get_title() { $title = get_the_title($this->get_id()); if ($this->is_billable() && $this->get_default_rate()) { $title .= ': ' . sa_get_formatted_money($this->get_default_rate()); } if ($this->is_billable() && $this->get_default_percentage()) { $title .= ' (' . $this->get_default_percentage() . '%)'; } return apply_filters('si_get_time_title', $title, $this); }
function si_doc_history_records($doc_id = 0, $filtered = true) { if (!$doc_id) { $doc_id = get_the_ID(); } $returned_history = array(); switch (get_post_type($doc_id)) { case SI_Estimate::POST_TYPE: $estimate = SI_Estimate::get_instance($doc_id); $history = $estimate->get_history(); break; case SI_Invoice::POST_TYPE: $invoice = SI_Invoice::get_instance($doc_id); $history = array_merge($invoice->get_history(), $invoice->get_payments()); break; default: # code... break; } $history = apply_filters('si_doc_history_records_pre_sort', $history, $doc_id, $filtered); // Sort in ascending order asort($history, SORT_NUMERIC); foreach ($history as $item_id) { if (get_post_type($item_id) == SI_Record::POST_TYPE) { $record = SI_Record::get_instance($item_id); // If no type is set than just keep on moving. if ($record->get_type() == SI_Record::DEFAULT_TYPE) { continue; } // filter these types of records out. if ($filtered) { if (in_array($record->get_type(), array(SI_Controller::PRIVATE_NOTES_TYPE, SI_Estimates::VIEWED_STATUS_UPDATE, SI_Notifications::RECORD))) { continue; } } $r_post = $record->get_post(); switch ($record->get_type()) { case SI_Controller::PRIVATE_NOTES_TYPE: $returned_history[$item_id]['type'] = __('Private Note', 'sprout-invoices'); break; case SI_Estimates::HISTORY_UPDATE: $returned_history[$item_id]['type'] = __('Updated', 'sprout-invoices'); break; case SI_Estimates::VIEWED_STATUS_UPDATE: $returned_history[$item_id]['type'] = __('Viewed', 'sprout-invoices'); break; case SI_Notifications::RECORD: $returned_history[$item_id]['type'] = __('Notification', 'sprout-invoices'); break; case SI_Estimates::HISTORY_INVOICE_CREATED: $returned_history[$item_id]['type'] = __('Invoice Created', 'sprout-invoices'); break; case SI_Estimate_Submissions::SUBMISSION_UPDATE: $returned_history[$item_id]['type'] = __('Submitted', 'sprout-invoices'); break; case SI_Importer::RECORD: $returned_history[$item_id]['type'] = __('Imported', 'sprout-invoices'); break; case SI_Estimates::HISTORY_STATUS_UPDATE: default: $returned_history[$item_id]['type'] = __('Status Update', 'sprout-invoices'); break; } $returned_history[$item_id]['status_type'] = $record->get_type(); $returned_history[$item_id]['post_date'] = $r_post->post_date; $returned_history[$item_id]['update_title'] = $r_post->post_title; $returned_history[$item_id]['content'] = $r_post->post_content; } elseif (get_post_type($item_id) == SI_Payment::POST_TYPE) { $payment = SI_Payment::get_instance($item_id); $p_post = $payment->get_post(); $returned_history[$item_id]['type'] = __('Payment', 'sprout-invoices'); $returned_history[$item_id]['status_type'] = 'payment'; $returned_history[$item_id]['post_date'] = $p_post->post_date; $returned_history[$item_id]['update_title'] = $p_post->post_title; $returned_history[$item_id]['content'] = ''; $returned_history[$item_id]['content'] .= '<span>' . $payment->get_payment_method() . '</span><br/>'; $returned_history[$item_id]['content'] .= '<b>' . __('Payment Total', 'sprout-invoices') . ':</b> ' . sa_get_formatted_money($payment->get_amount(), $item_id); } else { if ($filtered) { $comment = get_comment($item_id); if (!is_wp_error($comment)) { $returned_history[$item_id]['type'] = $comment->comment_author; $returned_history[$item_id]['status_type'] = 'comment'; $returned_history[$item_id]['post_date'] = $comment->comment_date; $returned_history[$item_id]['content'] = get_comment_text($comment->comment_ID); $returned_history[$item_id]['comment_id'] = intval($comment->comment_ID); } } } } return $returned_history; }
/** * Display the content for the column * * @param string $column_name * @param int $id post_id * @return string */ public static function column_display($column_name, $id) { $estimate = SI_Estimate::get_instance($id); if (!is_a($estimate, 'SI_Estimate')) { return; // return for that temp post } switch ($column_name) { case 'doc_link': $invoice_id = $estimate->get_invoice_id(); if ($invoice_id) { printf('<a class="doc_link si_status %1$s" title="%2$s" href="%3$s">%4$s</a>', si_get_invoice_status($invoice_id), __('Invoice for this estimate.', 'sprout-invoices'), get_edit_post_link($invoice_id), '<div class="dashicons icon-sproutapps-invoices"></div>'); } break; case 'status': self::status_change_dropdown($id); break; case 'total': printf('<span class="estimate_total">%s</span>', sa_get_formatted_money($estimate->get_total(), $estimate->get_id())); break; case 'client': if ($estimate->get_client_id()) { $client = $estimate->get_client(); printf('<b><a href="%s">%s</a></b><br/><em>%s</em>', get_edit_post_link($client->get_ID()), get_the_title($client->get_ID()), $client->get_website()); } else { printf('<b>%s</b> ', __('No client', 'sprout-invoices')); } break; default: // code... break; } }
<?php } else { ?> <tr><td colspan="5" rowspan="3"><?php _e('No invoices available.', 'sprout-invoices'); ?> </td></tr> <?php } ?> </tbody> <?php if ($total_balance_due) { ?> <tfoot> <tr> <td colspan="3"> </td> <td colspan="2"><?php printf(__('Balance Due: <b>%s</b>', 'sprout-invoices'), sa_get_formatted_money($total_balance_due)); ?> </td> </tr> </tfoot> <?php } ?> </table> </div> <?php }
$option .= sprintf('<input class="totalled_input sa_option_text%4$s" type="text" name="line_item_%2$s[]" value="%1$s" placeholder="%3$s" size="6">', esc_attr($value), $column_slug, $placeholder, $force_numeric); break; case 'hidden': $wrap = false; if ('' === $value) { $value = $placeholder; } $option .= sprintf('<input class="sa_option_hidden" type="hidden" name="line_item_%2$s[]" value="%1$s">', esc_attr($value), $column_slug); break; case 'checkbox': $option .= sprintf('<input class="sa_option_checkbox" type="hidden" name="line_item_%2$s[]" value="%1$s">', $value, $column_slug); $option .= sprintf('<input class="%2$s_decoy_checkbox sa_option_checkbox" type="checkbox" name="line_item_%2$s_decoy_checkbox" value="%1$s" %3$s>', $val, $column_slug, checked($value, $val, false)); break; case 'money': case 'total': $option .= sa_get_formatted_money($value, 0, '<span class="money_amount">%s</span>'); $option .= sprintf('<input class="totalled_input sa_option_hidden" type="hidden" name="line_item_%2$s[]" value="%1$s">', esc_attr($value), $column_slug); break; default: $option .= sprintf('<!-- no option built for column_%s -->', $column_slug); break; } $option = apply_filters('si_line_item_option', $option, $column_slug, $item_data); if ($wrap) { printf('<div class="column %3$s column_%2$s">%1$s</div><!-- / column_%2$s -->', $option, $column_slug, $hide_if_parent, $column['label']); } else { print $option; } } ?>
/** * Prints the amount as formatted money. Place symbol based on location. * @param integer $amount amount to convert * @param string $amount_wrap strintf * @param integer $doc_id used for filtering * @return string */ function sa_formatted_money($amount, $doc_id = 0, $amount_wrap = '<span class="money_amount">%s</span>') { echo apply_filters('sa_formatted_money', sa_get_formatted_money($amount, $doc_id, $amount_wrap), $amount, $doc_id); }
/** * 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); }
/** * Return the estimate get_subtotal * * @param array $atts * @param string $content * @param string $code * @param array $data * @return string filtered */ public static function shortcode_estimate_subtotal($atts, $content, $code, $data) { $amount = sa_get_formatted_money(0); if (isset($data['estimate']) && is_a($data['estimate'], 'SI_Estimate')) { $amount = sa_get_formatted_money($data['estimate']->get_subtotal(), $data['estimate']->get_id()); } return apply_filters('shortcode_estimate_subtotal', $amount, $data); }
public static function adv_form_fields($required = true, $client = 0) { $fields = array(); $fields['currency'] = array('weight' => 220, 'label' => __('Currency Code', 'sprout-invoices'), 'type' => 'text', 'default' => $client ? $client->get_currency() : '', 'required' => $required, 'placeholder' => 'USD', 'attributes' => array('size' => '8'), 'description' => __('This setting will override the setting for each payment processor that supports differing currency codes.', 'sprout-invoices')); /*/ $fields['currency_symbol'] = array( 'weight' => 225, 'label' => __( 'Currency Symbol', 'sprout-invoices' ), 'type' => 'text', 'default' => ( $client ) ? $client->get_currency_symbol() : '$', 'required' => $required, 'placeholder' => '$', 'attributes' => array( 'class' => 'small-text' ), 'description' => __( 'This setting will override the default payments setting. If your currency has the symbol after the amount place a % before your currency symbol. Example, % £', 'sprout-invoices' ) ); /**/ $money_format = $client ? $client->get_money_format() : get_locale(); $si_localeconv = si_localeconv(); $fields['money_format'] = array('weight' => 230, 'label' => __('Money Format', 'sprout-invoices'), 'type' => 'select', 'default' => $money_format, 'options' => $required, 'options' => array_flip(SI_Locales::$locales), 'attributes' => array('class' => 'select2'), 'description' => sprintf(__('Current format: %1$s. The default money formatting (%2$s) can be overridden for all client estimates and invoices here.', 'sprout-invoices'), sa_get_formatted_money(rand(11000, 9999999), get_the_id()), '<code>' . $si_localeconv['int_curr_symbol'] . '</code>')); $fields['nonce'] = array('type' => 'hidden', 'value' => wp_create_nonce(self::SUBMISSION_NONCE), 'weight' => 10000); $fields = apply_filters('si_client_adv_form_fields', $fields, $client); uasort($fields, array(__CLASS__, 'sort_by_weight')); return $fields; }
function column_total($item) { $payment = SI_Payment::get_instance($item->ID); $invoice_id = $payment->get_invoice_id(); if ($invoice_id) { $invoice = SI_Invoice::get_instance($invoice_id); if (is_a($invoice, 'SI_Invoice')) { echo '<strong>' . __('Payment Total', 'sprout-invoices') . ':</strong> ' . sa_get_formatted_money($payment->get_amount()) . '<br/>'; echo '<em>' . __('Invoice Balance', 'sprout-invoices') . ': ' . sa_get_formatted_money($invoice->get_balance(), $invoice->get_id()) . '</em><br/>'; echo '<em>' . __('Invoice Total', 'sprout-invoices') . ': ' . sa_get_formatted_money($invoice->get_total(), $invoice->get_id()) . '</em>'; } else { _e('No invoice found', 'sprout-invoices'); } } else { printf(__('No invoice associated with this payment.', 'sprout-invoices')); } }
/** * Display the content for the column * * @param string $column_name * @param int $id post_id * @return string */ public static function column_display($column_name, $id) { $invoice = SI_Invoice::get_instance($id); if (!is_a($invoice, 'SI_Invoice')) { return; // return for that temp post } switch ($column_name) { case 'doc_link': $estimate_id = $invoice->get_estimate_id(); if ($estimate_id) { printf('<a class="doc_link" title="%s" href="%s">%s</a>', self::__('Invoice\'s Estimate'), get_edit_post_link($estimate_id), '<div class="dashicons icon-sproutapps-estimates"></div>'); } break; case 'status': self::status_change_dropdown($id); break; case 'total': printf('%s <span class="description">(%s %s)</span>', sa_get_formatted_money($invoice->get_payments_total()), self::__('of'), sa_get_formatted_money($invoice->get_total(), $invoice->get_id())); echo '<div class="row-actions">'; printf('<a class="payments_link" title="%s" href="%s&s=%s">%s</a>', self::__('Review payments.'), get_admin_url('', '/edit.php?post_type=sa_invoice&page=sprout-apps/invoice_payments'), $id, self::__('Payments')); break; case 'client': if ($invoice->get_client_id()) { $client = $invoice->get_client(); printf('<b><a href="%s">%s</a></b><br/><em>%s</em>', get_edit_post_link($client->get_ID()), get_the_title($client->get_ID()), $client->get_website()); } else { printf('<b>%s</b> ', si__('No client')); } break; default: // code... break; } }
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); }