/**
  * Remove all scripts and styles from the estimate view and then add those specific to si.
  * @return
  */
 public static function remove_scripts_and_styles()
 {
     if (SI_Estimate::is_estimate_query() && is_single()) {
         if (apply_filters('si_remove_scripts_styles_on_doc_pages', '__return_true')) {
             global $wp_scripts, $wp_styles;
             $allowed_scripts = apply_filters('si_allowed_doc_scripts', array('sprout_doc_scripts', 'qtip', 'dropdown'));
             $allowed_admin_scripts = apply_filters('si_allowed_admin_doc_scripts', array_merge(array('admin-bar'), $allowed_scripts));
             if (current_user_can('edit_sprout_invoices')) {
                 $wp_scripts->queue = $allowed_admin_scripts;
             } else {
                 $wp_scripts->queue = $allowed_scripts;
             }
             $allowed_styles = apply_filters('si_allowed_admin_doc_scripts', array('sprout_doc_style', 'qtip', 'dropdown'));
             $allowed_admin_styles = apply_filters('si_allowed_admin_doc_scripts', array_merge(array('admin-bar'), $allowed_styles));
             if (current_user_can('edit_sprout_invoices')) {
                 $wp_styles->queue = $allowed_admin_styles;
             } else {
                 $wp_styles->queue = $allowed_styles;
             }
             do_action('si_doc_enqueue_filtered');
         } else {
             // scripts
             wp_enqueue_script('sprout_doc_scripts');
             wp_enqueue_script('dropdown');
             wp_enqueue_script('qtip');
             // Styles
             wp_enqueue_style('sprout_doc_style');
             wp_enqueue_style('dropdown');
             wp_enqueue_style('qtip');
         }
     }
 }
 public static function estimate_embed($atts = array())
 {
     do_action('sprout_invoices_estimate_embed');
     $estimate_id = 0;
     // Make sure id given is for an invoice
     if (isset($atts['id'])) {
         $estimate_id = (int) $atts['id'];
     }
     if (isset($_GET['si_id'])) {
         $estimate_id = (int) $_GET['si_id'];
     }
     if (SI_Estimate::POST_TYPE !== get_post_type($estimate_id)) {
         return;
     }
     // enqueue style
     self::frontend_enqueue();
     // Show snippet view or not.
     $embed_view = '';
     if (isset($atts['snippet']) && 'true' === $atts['snippet']) {
         $embed_view = '-snippet';
     }
     self::remove_actions();
     // Setup global post for filters and functions to work
     global $post;
     $post = get_post($estimate_id);
     setup_postdata($post);
     $estimate = SI_Estimate::get_instance($estimate_id);
     $line_items = $estimate->get_line_items();
     $view = self::load_addon_view_to_string('estimates/embed' . $embed_view, array('id' => $estimate_id, 'line_items' => $line_items, 'prev_type' => '', 'totals' => SI_Line_Items::line_item_totals($estimate_id)), false);
     // reset to the original post
     wp_reset_postdata();
     return $view;
 }
 public static function invoice_notification(SI_Invoice $invoice, $recipients = array(), $from_email = null, $from_name = null)
 {
     $estimate = '';
     if ($estimate_id = $invoice->get_estimate_id()) {
         $estimate = SI_Estimate::get_instance($estimate_id);
     }
     foreach (array_unique($recipients) as $user_id) {
         /**
          * sometimes the recipients list will pass an email instead of an id
          * attempt to find a user first.
          */
         if (is_email($user_id)) {
             if ($user = get_user_by('email', $user_id)) {
                 $user_id = $user->ID;
                 $to = self::get_user_email($user_id);
             } else {
                 // no user found
                 $to = $user_id;
             }
         } else {
             $to = self::get_user_email($user_id);
         }
         $data = array('user_id' => is_numeric($user_id) ? $user_id : '', 'invoice' => $invoice, 'estimate' => $estimate, 'to' => $to);
         self::send_notification('send_invoice', $data, $to, $from_email, $from_name);
     }
 }
 /**
  * Show the estimate history, including the submission fields
  *
  * @param WP_Post $post
  * @param array   $metabox
  * @return
  */
 public static function show_submission_history_view($post, $metabox)
 {
     if ($post->post_status == 'auto-draft') {
         printf('<p>%s</p>', __('No history available.', 'sprout-invoices'));
         return;
     }
     $estimate = SI_Estimate::get_instance($post->ID);
     self::load_view('admin/meta-boxes/estimates/history-premium', array('id' => $post->ID, 'post' => $post, 'estimate' => $estimate, 'history' => si_doc_history_records($post->ID, false), 'submission_fields' => $estimate->get_submission_fields()), false);
 }
Example #5
0
 /**
  * Get the doc object
  * @param  integer $id
  * @return SI_Estimate/SI_Invoice
  */
 function si_get_doc_object($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     switch (get_post_type($id)) {
         case SI_Estimate::POST_TYPE:
             $doc = SI_Estimate::get_instance($id);
             break;
         case SI_Invoice::POST_TYPE:
             $doc = SI_Invoice::get_instance($id);
             break;
         default:
             $doc = '';
             break;
     }
     return apply_filters('si_get_doc_object', $doc);
 }
 public static function maybe_log_estimate_view()
 {
     global $post;
     if (!is_single()) {
         return;
     }
     // Make sure this is an estimate we're viewing
     if ($post->post_type !== SI_Estimate::POST_TYPE) {
         return;
     }
     // Don't log the authors views
     if ($post->post_author === get_current_user_id()) {
         return;
     }
     if (is_user_logged_in()) {
         $user = get_userdata(get_current_user_id());
         $name = $user->first_name . ' ' . $user->last_name;
         $whom = $name . ' (' . $user->user_login . ')';
     } else {
         $whom = self::get_user_ip();
     }
     $estimate = SI_Estimate::get_instance($post->ID);
     do_action('si_new_record', $_SERVER, self::VIEWED_STATUS_UPDATE, $estimate->get_id(), sprintf(__('Estimate viewed by %s.', 'sprout-invoices'), esc_html($whom)));
 }
 public static function maybe_change_status()
 {
     if (!isset($_REQUEST['change_status_nonce'])) {
         self::ajax_fail('Forget something?');
     }
     $nonce = esc_attr($_REQUEST['change_status_nonce']);
     if (!wp_verify_nonce($nonce, self::NONCE)) {
         self::ajax_fail('Not going to fall for it!');
     }
     if (!isset($_REQUEST['id'])) {
         self::ajax_fail('Forget something?');
     }
     if (!isset($_REQUEST['status'])) {
         self::ajax_fail('Forget something?');
     }
     $view = '';
     $doc_id = esc_attr($_REQUEST['id']);
     $new_status = esc_attr($_REQUEST['status']);
     switch (get_post_type($doc_id)) {
         case SI_Invoice::POST_TYPE:
             $doc = SI_Invoice::get_instance($doc_id);
             $doc->set_status($new_status);
             $view = self::load_view_to_string('admin/sections/invoice-status-change-drop', array('id' => $doc_id, 'status' => $doc->get_status()), false);
             break;
         case SI_Estimate::POST_TYPE:
             switch ($new_status) {
                 case 'accept':
                     $new_status = SI_Estimate::STATUS_APPROVED;
                     break;
                 case 'decline':
                     $new_status = SI_Estimate::STATUS_DECLINED;
                     break;
                 default:
                     break;
             }
             $doc = SI_Estimate::get_instance($doc_id);
             $doc->set_status($new_status);
             $view = self::load_view_to_string('admin/sections/estimate-status-change-drop', array('id' => $doc_id, 'status' => $doc->get_status()), false);
             break;
         default:
             self::ajax_fail('Not an estimate or invoice.');
             return;
             break;
     }
     // action
     do_action('doc_status_changed', $doc, $_REQUEST);
     header('Content-type: application/json');
     if (self::DEBUG) {
         header('Access-Control-Allow-Origin: *');
     }
     echo wp_json_encode(array('new_button' => $view));
     exit;
 }
Example #8
0
/**
 * Load the SI application
 * (function called at the bottom of this page)
 *
 * @package Sprout_Invoices
 * @return void
 */
function sprout_invoices_load()
{
    if (class_exists('Sprout_Invoices')) {
        error_log('** Sprout_Invoices Already Loaded **');
        return;
        // already loaded, or a name collision
    }
    do_action('sprout_invoices_preload');
    //////////
    // Load //
    //////////
    // Master class
    require_once SI_PATH . '/Sprout_Invoices.class.php';
    // base classes
    require_once SI_PATH . '/models/_Model.php';
    require_once SI_PATH . '/controllers/_Controller.php';
    do_action('si_require_base_classes');
    // models
    require_once SI_PATH . '/models/Client.php';
    require_once SI_PATH . '/models/Estimate.php';
    require_once SI_PATH . '/models/Invoice.php';
    require_once SI_PATH . '/models/Notification.php';
    require_once SI_PATH . '/models/Payment.php';
    require_once SI_PATH . '/models/Record.php';
    // Premium models
    require_once SI_PATH . '/models/Project.php';
    // i18n
    require_once SI_PATH . '/controllers/i18n/Countries_States.php';
    require_once SI_PATH . '/controllers/i18n/Locales.php';
    do_action('si_require_model_classes');
    /////////////////
    // Controllers //
    /////////////////
    // settings
    require_once SI_PATH . '/controllers/admin/Settings.php';
    if (!class_exists('SA_Settings_API')) {
        require_once SI_PATH . '/controllers/admin/Settings_API.php';
    }
    require_once SI_PATH . '/controllers/admin/Capabilities.php';
    require_once SI_PATH . '/controllers/admin/Help.php';
    // json api
    require_once SI_PATH . '/controllers/api/JSON_API.php';
    // checkouts
    require_once SI_PATH . '/controllers/checkout/Checkouts.php';
    // clients
    require_once SI_PATH . '/controllers/clients/Clients.php';
    // developer logs
    require_once SI_PATH . '/controllers/developer/Logs.php';
    // Estimates
    require_once SI_PATH . '/controllers/estimates/Estimate_Submission.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/estimates/Estimate_Submission_Premium.php')) {
        require_once SI_PATH . '/controllers/estimates/Estimate_Submission_Premium.php';
    }
    require_once SI_PATH . '/controllers/estimates/Estimates.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Admin.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Edit.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Records.php';
    require_once SI_PATH . '/controllers/estimates/Estimates_Template.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/estimates/Estimates_Premium.php')) {
        require_once SI_PATH . '/controllers/estimates/Estimates_Premium.php';
    }
    // invoices
    require_once SI_PATH . '/controllers/invoices/Invoices.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Admin.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Edit.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Records.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Template.php';
    require_once SI_PATH . '/controllers/invoices/Invoices_Deposit.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/invoices/Invoices_Premium.php')) {
        require_once SI_PATH . '/controllers/invoices/Invoices_Premium.php';
    }
    // Line Items
    require_once SI_PATH . '/controllers/line-items/Line_Items.php';
    // notifications
    require_once SI_PATH . '/controllers/notifications/Notifications_Control.php';
    require_once SI_PATH . '/controllers/notifications/Notifications.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/notifications/Notifications_Premium.php')) {
        require_once SI_PATH . '/controllers/notifications/Notifications_Premium.php';
    }
    require_once SI_PATH . '/controllers/notifications/Notifications_Admin_Table.php';
    // payment processing
    require_once SI_PATH . '/controllers/payment-processing/Payment_Processors.php';
    require_once SI_PATH . '/controllers/payment-processing/Credit_Card_Processors.php';
    require_once SI_PATH . '/controllers/payment-processing/Offsite_Processors.php';
    // payment processors
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_EC.php')) {
        require_once SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_EC.php';
    }
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_Pro.php')) {
        require_once SI_PATH . '/controllers/payment-processing/processors/SI_Paypal_Pro.php';
    }
    require_once SI_PATH . '/controllers/payment-processing/processors/SI_Checks.php';
    require_once SI_PATH . '/controllers/payment-processing/processors/SI_Admin_Payment.php';
    do_action('si_payment_processors_loaded');
    // payments
    require_once SI_PATH . '/controllers/payments/Payments.php';
    require_once SI_PATH . '/controllers/payments/Payments_Admin_Table.php';
    // Projects
    require_once SI_PATH . '/controllers/projects/Projects.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/projects/Projects_Premium.php')) {
        require_once SI_PATH . '/controllers/projects/Projects_Premium.php';
    }
    // internal records
    require_once SI_PATH . '/controllers/records/Internal_Records.php';
    require_once SI_PATH . '/controllers/records/Records_Admin_Table.php';
    // reporting
    require_once SI_PATH . '/controllers/reporting/Dashboard.php';
    require_once SI_PATH . '/controllers/reporting/Reporting.php';
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/reporting/Reporting_Premium.php')) {
        require_once SI_PATH . '/controllers/reporting/Reporting_Premium.php';
    }
    require_once SI_PATH . '/controllers/templating/Templating.php';
    require_once SI_PATH . '/controllers/templating/Customizer.php';
    // updates
    if (!SI_FREE_TEST && file_exists(SI_PATH . '/controllers/updates/Updates.php')) {
        require_once SI_PATH . '/controllers/updates/Updates.php';
    }
    if (file_exists(SI_PATH . '/controllers/updates/Free_License.php')) {
        require_once SI_PATH . '/controllers/updates/Free_License.php';
    }
    // importers
    require_once SI_PATH . '/importers/Importer.php';
    require_once SI_PATH . '/importers/Freshbooks.php';
    require_once SI_PATH . '/importers/Harvest.php';
    require_once SI_PATH . '/importers/WP-Invoice.php';
    require_once SI_PATH . '/importers/CSV.php';
    do_action('si_importers_loaded');
    // Fix others problems
    require_once SI_PATH . '/controllers/compat/Compatibility.php';
    // all done
    do_action('si_require_controller_classes');
    // Template tags
    require_once SI_PATH . '/template-tags/estimates.php';
    require_once SI_PATH . '/template-tags/clients.php';
    require_once SI_PATH . '/template-tags/forms.php';
    require_once SI_PATH . '/template-tags/invoices.php';
    require_once SI_PATH . '/template-tags/line-items.php';
    require_once SI_PATH . '/template-tags/projects.php';
    require_once SI_PATH . '/template-tags/ui.php';
    require_once SI_PATH . '/template-tags/utility.php';
    require_once SI_PATH . '/template-tags/docs.php';
    // l18n
    require_once SI_PATH . '/languages/SI_l10n.php';
    require_once SI_PATH . '/languages/SI_Strings.php';
    // i18n & l10n
    SI_l10n::init();
    SI_Strings::load_additional_strings();
    SI_Locales::init();
    SI_Countries_States::init();
    ///////////////////
    // init() models //
    ///////////////////
    do_action('si_models_init');
    SI_Post_Type::init();
    // _Model
    SI_Record::init();
    SI_Notification::init();
    SI_Invoice::init();
    SI_Estimate::init();
    SI_Client::init();
    SI_Payment::init();
    SI_Project::init();
    /////////////////////////
    // init() controllers //
    /////////////////////////
    do_action('si_controllers_init');
    SI_Controller::init();
    SA_Settings_API::init();
    SI_Templating_API::init();
    SI_Customizer::init();
    SI_Admin_Capabilities::init();
    // updates
    if (!SI_FREE_TEST && class_exists('SI_Updates')) {
        SI_Updates::init();
    }
    if (class_exists('SI_Free_License')) {
        SI_Free_License::init();
    }
    // api
    SI_JSON_API::init();
    // reports
    SI_Dashboard::init();
    SI_Reporting::init();
    if (!SI_FREE_TEST && class_exists('SI_Reporting_Premium')) {
        SI_Reporting_Premium::init();
    }
    // records and logs
    SI_Internal_Records::init();
    SI_Dev_Logs::init();
    // settings
    SI_Admin_Settings::init();
    // payments and processing
    SI_Payment_Processors::init();
    SI_Payments::init();
    // notifications
    SI_Notifications::init();
    // Hooks come before parent class.
    if (!SI_FREE_TEST && class_exists('SI_Notifications_Premium')) {
        SI_Notifications_Premium::init();
    }
    SI_Notifications_Control::init();
    // clients
    SI_Clients::init();
    // estimates
    SI_Estimates::init();
    if (!SI_FREE_TEST && class_exists('SI_Estimates_Premium')) {
        SI_Estimates_Premium::init();
    }
    if (!SI_FREE_TEST && class_exists('SI_Estimates_Submission_Premium')) {
        SI_Estimates_Submission_Premium::init();
    }
    SI_Estimate_Submissions::init();
    SI_Estimates_Admin::init();
    SI_Estimates_Edit::init();
    SI_Estimates_Template::init();
    SI_Estimates_Records::init();
    // checkouts
    SI_Checkouts::init();
    // invoices
    SI_Invoices::init();
    SI_Invoices_Admin::init();
    SI_Invoices_Edit::init();
    SI_Invoices_Template::init();
    SI_Invoices_Records::init();
    SI_Invoices_Deposit::init();
    if (!SI_FREE_TEST && class_exists('SI_Invoices_Premium')) {
        SI_Invoices_Premium::init();
    }
    // Line items
    SI_Line_Items::init();
    // projects
    SI_Projects::init();
    if (!SI_FREE_TEST && class_exists('SI_Projects_Premium')) {
        SI_Projects_Premium::init();
    }
    // importer
    SI_Importer::init();
    // help
    SI_Help::init();
    // Compat
    SI_Compatibility::init();
    // addons
    require_once SI_PATH . '/add-ons/Addons.php';
    require_once SI_PATH . '/add-ons/updates/edd_plugin_updater.class.php';
    SA_Addons::init();
    do_action('sprout_invoices_loaded');
}
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;
}
function remove_estimate_line_items($estimates, $id)
{
    if (!isset($estimates) && check_for_value($estimates) === false) {
        return;
        //this is not the function you are looking for
    }
    if (!is_array($estimates)) {
        $estimates = explode(",", $estimates);
    }
    foreach ($estimates as $estimate) {
        $SI_Estimate = SI_Estimate::get_instance($estimate);
        $line_items = $SI_Estimate->get_line_items();
        $fired = null;
        $new_line_items_array = array();
        foreach ($line_items as $li) {
            if (strpos($li['desc'], "task-{$id}") === false && strpos($li['desc'], 'task: ' . $id) === false) {
                $new_line_items_array[] = $li;
            } elseif ($fired !== true) {
                $fired = true;
            }
        }
        $SI_Estimate->set_line_items($new_line_items_array);
    }
    if (isset($_SESSION['changed_docs']['estimates'])) {
        $_SESSION['changed_docs']['estimates'] = array_merge($estimates, $_SESSION['changed_docs']['estimates']);
    }
}
 /**
  * Maybe create a client from submission
  * @param  SI_Estimate $estimate 
  * @param  array       $args     * email - required
  *                               * client_id - if client_id is passed than just assign estimate
  *                               * client_name - required
  *                               * full_name - 
  *                               * website
  *                               * contact_street
  *                               * contact_city
  *                               * contact_zone
  *                               * contact_postal_code
  *                               * contact_country
  *                               
  */
 public static function maybe_create_client(SI_Estimate $estimate, $args = array())
 {
     $args = apply_filters('si_afi_maybe_create_client', $args);
     $client_id = isset($args['client_id']) && get_post_type($args['client_id']) == SI_Client::POST_TYPE ? $args['client_id'] : 0;
     $user_id = get_current_user_id();
     // check to see if the user exists by email
     if (isset($args['email']) && $args['email'] != '') {
         if ($user = get_user_by('email', $args['email'])) {
             $user_id = $user->ID;
         }
     }
     // Check to see if the user is assigned to a client already
     if (!$client_id) {
         $client_ids = SI_Client::get_clients_by_user($user_id);
         if (!empty($client_ids)) {
             $client_id = array_pop($client_ids);
         }
     }
     // Create a user for the submission if an email is provided.
     if (!$user_id) {
         // email is critical
         if (isset($args['email']) && $args['email'] != '') {
             $user_args = array('user_login' => self::esc__($args['email']), 'display_name' => isset($args['client_name']) ? self::esc__($args['client_name']) : self::esc__($args['email']), 'user_pass' => wp_generate_password(), 'user_email' => isset($args['email']) ? self::esc__($args['email']) : '', 'first_name' => si_split_full_name(self::esc__($args['full_name']), 'first'), 'last_name' => si_split_full_name(self::esc__($args['full_name']), 'last'), 'user_url' => isset($args['website']) ? self::esc__($args['website']) : '');
             $user_id = SI_Clients::create_user($user_args);
         }
     }
     // create the client based on what's submitted.
     if (!$client_id) {
         $address = array('street' => isset($args['contact_street']) ? self::esc__($args['contact_street']) : '', 'city' => isset($args['contact_city']) ? self::esc__($args['contact_city']) : '', 'zone' => isset($args['contact_zone']) ? self::esc__($args['contact_zone']) : '', 'postal_code' => isset($args['contact_postal_code']) ? self::esc__($args['contact_postal_code']) : '', 'country' => isset($args['contact_country']) ? self::esc__($args['contact_country']) : '');
         $args = array('company_name' => isset($args['client_name']) ? self::esc__($args['client_name']) : '', 'website' => isset($args['website']) ? self::esc__($args['website']) : '', 'address' => $address, 'user_id' => $user_id);
         $client_id = SI_Client::new_client($args);
         // History
         do_action('si_new_record', sprintf('Client Created & Assigned: %s', get_the_title($client_id)), self::SUBMISSION_UPDATE, $estimate->get_id(), sprintf('Client Created & Assigned: %s', get_the_title($client_id)), 0, false);
     }
     // Set the estimates client
     $estimate->set_client_id($client_id);
 }
    _e('Estimate', 'sprout-invoices');
    ?>
</th>
				<th><?php 
    _e('Status', 'sprout-invoices');
    ?>
</th>
			</tr>
		</thead>
		<tbody>
			<?php 
    if (!empty($estimates_to_show)) {
        ?>
				<?php 
        foreach ($estimates_to_show as $estimate_id) {
            $estimate = SI_Estimate::get_instance($estimate_id);
            if (!is_a($estimate, 'SI_Estimate')) {
                continue;
            }
            // Get a label class for the status.
            switch (si_get_estimate_status($estimate_id)) {
                case 'pending':
                    $label = 'warning';
                    break;
                case 'request':
                    $label = 'default';
                    break;
                case 'declined':
                    $label = 'danger';
                    break;
                case 'temp':
 public static function create_estimate($estimate = array())
 {
     $possible_dups = SI_Post_Type::find_by_meta(SI_Estimate::POST_TYPE, array(self::FRESHBOOKS_ID => $estimate['estimate_id']));
     // Don't create a duplicate if this was already imported.
     if (!empty($possible_dups)) {
         do_action('si_error', 'Estimate imported already', $estimate['estimate_id']);
         return;
     }
     $clients = SI_Post_Type::find_by_meta(SI_Client::POST_TYPE, array(self::FRESHBOOKS_ID => $estimate['client_id']));
     // Get client and confirm it's validity
     $client_id = 0;
     if (is_array($clients)) {
         $client = SI_Client::get_instance($clients[0]);
         $client_id = is_a($client, 'SI_Client') ? $client->get_id() : 0;
     }
     $args = array('subject' => $estimate['description'] ? $estimate['description'] : 'Freshbooks Import #' . $estimate['estimate_id']);
     $new_estimate_id = SI_Estimate::create_estimate($args, SI_Estimate::STATUS_PENDING);
     update_post_meta($new_estimate_id, self::FRESHBOOKS_ID, $estimate['estimate_id']);
     $est = SI_Estimate::get_instance($new_estimate_id);
     $est->set_client_id($client_id);
     if (!is_array($estimate['number'])) {
         $est->set_estimate_id($estimate['number']);
     }
     if (!is_array($estimate['amount'])) {
         $est->set_total($estimate['amount']);
     }
     if (!is_array($estimate['currency_code'])) {
         $est->set_currency($estimate['currency_code']);
     }
     if (!is_array($estimate['po_number'])) {
         $est->set_po_number($estimate['po_number']);
     }
     if (!is_array($estimate['discount'])) {
         $est->set_discount($estimate['discount']);
     }
     if (!is_array($estimate['notes'])) {
         $est->set_notes($estimate['notes']);
     }
     if (!is_array($estimate['terms'])) {
         $est->set_terms($estimate['terms']);
     }
     $est->set_issue_date(strtotime($estimate['date']));
     // post date
     $est->set_post_date(date('Y-m-d H:i:s', strtotime($estimate['date'])));
     // line items
     $line_items = array();
     if (isset($estimate['lines']['line']) && !empty($estimate['lines']['line'])) {
         // for some reason FB
         if (isset($estimate['lines']['line'][0])) {
             foreach ($estimate['lines']['line'] as $key => $item) {
                 $line_items[] = array('rate' => !is_array($item['unit_cost']) ? $item['unit_cost'] : '', 'qty' => !is_array($item['quantity']) ? $item['quantity'] : '', 'desc' => !is_array($item['description']) ? $item['description'] : '', 'type' => !is_array($item['type']) ? $item['type'] : '', 'total' => !is_array($item['amount']) ? $item['amount'] : '', 'tax' => !is_array($item['tax1_percent']) ? $item['tax1_percent'] : '');
             }
         } else {
             $line_items[] = array('rate' => !is_array($estimate['lines']['line']['unit_cost']) ? $estimate['lines']['line']['unit_cost'] : '', 'qty' => !is_array($estimate['lines']['line']['quantity']) ? $estimate['lines']['line']['quantity'] : '', 'desc' => !is_array($estimate['lines']['line']['description']) ? $estimate['lines']['line']['description'] : '', 'type' => !is_array($estimate['lines']['line']['type']) ? $estimate['lines']['line']['type'] : '', 'total' => !is_array($estimate['lines']['line']['amount']) ? $estimate['lines']['line']['amount'] : '', 'tax' => !is_array($estimate['lines']['line']['tax1_percent']) ? $estimate['lines']['line']['tax1_percent'] : '');
         }
     }
     $est->set_line_items($line_items);
     // Record
     do_action('si_new_record', $estimate, self::RECORD, $new_estimate_id, self::__('Estimate Imported'), 0);
     return $est;
 }
 /**
  * Get the estimate currency
  * @param  integer $id 
  * @return string      
  */
 function si_get_estimate_currency($id = 0)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     $estimate = SI_Estimate::get_instance($id);
     return apply_filters('si_get_estimate_currency', $estimate->get_currency(), $estimate);
 }
 /**
  * Override the template and use something custom.
  * @param  string $template
  * @return string           full path.
  */
 public static function override_template($template)
 {
     // Invoicing
     if (SI_Invoice::is_invoice_query()) {
         if (is_single()) {
             if (!current_user_can('edit_sprout_invoices') && apply_filters('si_redirect_temp_status', true)) {
                 $status = get_post_status();
                 if (SI_Invoice::STATUS_TEMP === $status) {
                     wp_safe_redirect(add_query_arg(array('si_id' => get_the_id()), get_home_url()));
                     exit;
                 }
             }
             $custom_template = self::get_doc_current_template(get_the_id());
             $custom_path = $custom_template != '' ? 'invoice/' . $custom_template : '';
             $template = self::locate_template(array($custom_path, 'invoice-' . get_locale() . '.php', 'invoice.php', 'invoice/invoice.php'), $template);
         } else {
             $status = get_query_var(self::FILTER_QUERY_VAR);
             $template = self::locate_template(array('invoice/' . $status . '-invoices.php', $status . '-invoices.php', 'invoices.php', 'invoice/invoices.php'), $template);
         }
         $template = apply_filters('si_doc_template', $template, 'invoice');
     }
     // Estimates
     if (SI_Estimate::is_estimate_query()) {
         if (is_single()) {
             if (!current_user_can('edit_sprout_invoices') && apply_filters('si_redirect_temp_status', true)) {
                 $status = get_post_status();
                 if (SI_Estimate::STATUS_TEMP === $status) {
                     wp_safe_redirect(add_query_arg(array('si_id' => get_the_id()), get_home_url()));
                     exit;
                 }
             }
             $custom_template = self::get_doc_current_template(get_the_id());
             $custom_path = $custom_template != '' ? 'estimate/' . $custom_template : '';
             $template = self::locate_template(array($custom_path, 'estimate-' . get_locale() . '.php', 'estimate.php', 'estimate/estimate.php'), $template);
         } else {
             $status = get_query_var(self::FILTER_QUERY_VAR);
             $template = self::locate_template(array('estimate/' . $status . '-estimates.php', $status . '-estimates.php', 'estimates.php', 'estimate/estimates.php'), $template);
         }
         $template = apply_filters('si_doc_template', $template, 'estimate');
     }
     return $template;
 }
 /**
  * Hooked into the estimate submission form. Create a client
  * if one already doesn't exist.
  * @param  SI_Estimate $estimate
  * @param  array       $parsed_args
  * @return
  */
 public static function create_client_from_submission(SI_Estimate $estimate, $parsed_args = array())
 {
     $client_id = isset($_REQUEST['client_id']) && get_post_type($_REQUEST['client_id']) == SI_Client::POST_TYPE ? $_REQUEST['client_id'] : 0;
     $user_id = get_current_user_id();
     // check to see if the user exists by email
     if (isset($_REQUEST['sa_estimate_email']) && $_REQUEST['sa_estimate_email'] != '') {
         if ($user = get_user_by('email', $_REQUEST['sa_estimate_email'])) {
             $user_id = $user->ID;
         }
     }
     // Check to see if the user is assigned to a client already
     if (!$client_id) {
         $client_ids = SI_Client::get_clients_by_user($user_id);
         if (!empty($client_ids)) {
             $client_id = array_pop($client_ids);
         }
     }
     // Create a user for the submission if an email is provided.
     if (!$user_id) {
         // email is critical
         if (isset($_REQUEST['sa_estimate_email']) && $_REQUEST['sa_estimate_email'] != '') {
             $user_args = array('user_login' => esc_html($_REQUEST['sa_estimate_email'], 'sprout-invoices'), 'display_name' => isset($_REQUEST['sa_estimate_client_name']) ? esc_html($_REQUEST['sa_estimate_client_name'], 'sprout-invoices') : esc_html($_REQUEST['sa_estimate_email'], 'sprout-invoices'), 'user_pass' => wp_generate_password(), 'user_email' => isset($_REQUEST['sa_estimate_email']) ? esc_html($_REQUEST['sa_estimate_email'], 'sprout-invoices') : '', 'first_name' => si_split_full_name(esc_html($_REQUEST['sa_estimate_name'], 'sprout-invoices'), 'first'), 'last_name' => si_split_full_name(esc_html($_REQUEST['sa_estimate_name'], 'sprout-invoices'), 'last'), 'user_url' => isset($_REQUEST['sa_estimate_website']) ? esc_html($_REQUEST['sa_estimate_website'], 'sprout-invoices') : '');
             $user_id = self::create_user($user_args);
         }
     }
     // create the client based on what's submitted.
     if (!$client_id) {
         $address = array('street' => isset($_REQUEST['sa_contact_street']) ? esc_html($_REQUEST['sa_contact_street'], 'sprout-invoices') : '', 'city' => isset($_REQUEST['sa_contact_city']) ? esc_html($_REQUEST['sa_contact_city'], 'sprout-invoices') : '', 'zone' => isset($_REQUEST['sa_contact_zone']) ? esc_html($_REQUEST['sa_contact_zone'], 'sprout-invoices') : '', 'postal_code' => isset($_REQUEST['sa_contact_postal_code']) ? esc_html($_REQUEST['sa_contact_postal_code'], 'sprout-invoices') : '', 'country' => isset($_REQUEST['sa_contact_country']) ? esc_html($_REQUEST['sa_contact_country'], 'sprout-invoices') : '');
         $args = array('company_name' => isset($_REQUEST['sa_estimate_client_name']) ? esc_html($_REQUEST['sa_estimate_client_name'], 'sprout-invoices') : '', 'website' => isset($_REQUEST['sa_estimate_website']) ? esc_html($_REQUEST['sa_estimate_website'], 'sprout-invoices') : '', 'address' => $address, 'user_id' => $user_id);
         $client_id = SI_Client::new_client($args);
     }
     // Set the estimates client
     $estimate->set_client_id($client_id);
 }
 /**
  * Get the estimate currency
  * @param  integer $id
  * @return string
  */
 function si_get_estimate_currency($id = 0)
 {
     if (!$id) {
         $id = get_the_ID();
     }
     $estimate = SI_Estimate::get_instance($id);
     return apply_filters('si_get_estimate_currency', $estimate->get_currency(), $estimate);
 }
 /**
  * Filter the default post display states used in the Posts list table.
  *
  * @param array $post_states An array of post display states. Values include 'Password protected',
  *                           'Private', 'Draft', 'Pending', and 'Sticky'.
  * @param int   $post        The post.
  */
 public static function filter_post_states($post_states = array(), WP_Post $post)
 {
     if (get_post_type($post) == SI_Estimate::POST_TYPE) {
         $post_states = array();
         $estimate = SI_Estimate::get_instance($post->ID);
         if ($estimate->get_status() == SI_Estimate::STATUS_REQUEST) {
             // FUTURE show "New" with some sort of logic
             // $post_states[$estimate->get_status()] = __( 'New', 'sprout-invoices' );
         }
     }
     return $post_states;
 }
 public static function estimate($data = array())
 {
     if (!isset($data['id'])) {
         $data['id'] = $_GET['id'];
     }
     $estimate = SI_Estimate::get_instance($data['id']);
     if (!is_a($estimate, 'SI_Estimate')) {
         return;
     }
     return self::estimate_data($estimate);
 }
 public static function status_change_dropdown($id)
 {
     if (!$id) {
         global $post;
         $id = $post->ID;
     }
     $estimate = SI_Estimate::get_instance($id);
     if (!is_a($estimate, 'SI_Estimate')) {
         return;
         // return for that temp post
     }
     self::load_view('admin/sections/estimate-status-change-drop', array('id' => $id, 'status' => $estimate->get_status()), false);
 }
function inline_edit_mg_task_meta()
{
    $response = false;
    $new_data = '';
    $r = array();
    // we need the post IDs
    $post_id = isset($_POST['post_ID']) && !empty($_POST['post_ID']) ? $_POST['post_ID'] : NULL;
    // if we have post IDs
    if (!empty($post_id) && is_numeric($post_id)) {
        if (!empty($_POST['referrer']) && $_POST['referrer'] !== 'quick_save') {
            $_SESSION['doing_inline_edit'] = true;
            $field = str_replace('-', '_', $_POST['referrer']);
            $_SESSION['changed_docs'] = array('invoices' => array(), 'estimates' => array());
            if ($field === 'status') {
                $field = 'task_status';
            }
            // if it has a value, doesn't update if empty on bulk
            if (isset($_POST[$field]) && !empty($_POST[$field])) {
                if ($field === 'task_status') {
                    $update_post = wp_update_post(array('ID' => $post_id, 'post_status' => $_POST[$field]));
                    if (is_numeric($update_post) && intval($update_post) > 0) {
                        $new_data = $_POST[$field];
                    } else {
                        $new_data = false;
                    }
                } else {
                    $old_value = get_post_meta($post_id, $field, true);
                    $response = update_post_meta($post_id, $field, $_POST[$field], $old_value);
                    $new_data = get_post_meta($post_id, $field, true);
                    if ($field === 'estimated_time' && $response === true) {
                        if (isset($_SESSION['changed_docs']['invoices']) && check_for_value($_SESSION['changed_docs']['invoices'])) {
                            foreach ($_SESSION['changed_docs']['invoices'] as $item) {
                                $item_id = maybe_get_pod_id($item);
                                $object = SI_Invoice::get_instance($item_id[0]);
                                if (isset($object) && is_object($object)) {
                                    $object->set_calculated_total();
                                }
                            }
                        }
                        if (isset($_SESSION['changed_docs']['estimates']) && check_for_value($_SESSION['changed_docs']['estimates'])) {
                            foreach ($_SESSION['changed_docs']['estimates'] as $item) {
                                $item_id = maybe_get_pod_id($item);
                                $object = SI_Estimate::get_instance($item_id[0]);
                                if (isset($object) && is_object($object)) {
                                    $object->set_calculated_total();
                                }
                            }
                        }
                        if (!is_numeric($new_data)) {
                            $new_data = convert_estimated_time_to_minutes($new_data);
                        }
                    }
                }
                $r = array('post_id' => (int) $post_id, $field => $new_data);
            }
        } elseif ($_POST['referrer'] == 'quick_save') {
            $new_data = get_post_meta($post_id, 'estimated_time', true);
            $r = array('post_id' => (int) $post_id, 'estimated_time' => (int) $new_data);
        }
        unset($_SESSION['changed_docs']);
    }
    unset($_SESSION['doing_inline_edit']);
    $response = json_encode($r, JSON_FORCE_OBJECT);
    exit($response);
}
 public static function maybe_create_estimate($args = array())
 {
     // create array of fields
     if (!isset($args['fields'])) {
         $fields = self::submission_form_fields();
         foreach ($fields as $key => $data) {
             if (isset($_REQUEST['sa_estimate_' . $key]) && $_REQUEST['sa_estimate_' . $key] != '') {
                 $args['fields'][$key] = array('data' => $data, 'value' => $_REQUEST['sa_estimate_' . $key]);
             }
         }
     }
     if (isset($_REQUEST['sa_estimate_requirements'])) {
         $args['line_items'] = array(array('rate' => 0, 'qty' => 1, 'tax' => 0, 'total' => 0, 'desc' => esc_textarea($_REQUEST['sa_estimate_requirements'])));
     }
     $defaults = array('subject' => isset($_REQUEST['sa_estimate_title']) ? $_REQUEST['sa_estimate_title'] : sprintf(__('New Estimate: %s', 'sprout-invoices'), date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), current_time('timestamp'))), 'requirements' => isset($_REQUEST['sa_estimate_requirements']) ? $_REQUEST['sa_estimate_requirements'] : __('No requirements submitted. Check to make sure the "requirements" field is required.', 'sprout-invoices'), 'fields' => !empty($args['fields']) ? $args['fields'] : $_REQUEST);
     $parsed_args = wp_parse_args($args, $defaults);
     // Create estimate
     $estimate_id = SI_Estimate::create_estimate($parsed_args);
     // handle image uploads
     $estimate = SI_Estimate::get_instance($estimate_id);
     if (!empty($_FILES['sa_estimate_file'])) {
         // Set the uploaded field as an attachment
         $estimate->set_attachement($_FILES);
     }
     // TODO Set the solution type
     // End
     do_action('estimate_submitted', $estimate, $parsed_args);
 }
 public static function add_estimate_acceptance_meta_fields($fields = array())
 {
     $estimate = SI_Estimate::get_instance(get_the_id());
     if (!is_a($estimate, 'SI_Estimate')) {
         return $fields;
     }
     $recurring_fields = self::recurring_options($estimate);
     $recurring_fields['recurring_heading'] = array('weight' => 99, 'label' => __('Recurring Invoice Settings', 'sprout-invoices'), 'type' => 'heading');
     $fields = array_merge($recurring_fields, $fields);
     uasort($fields, array(__CLASS__, 'sort_by_weight'));
     return $fields;
 }
 public static function estimate_data(SI_Estimate $estimate)
 {
     $estimate_data = array('title' => $estimate->get_title(), 'id' => $estimate->get_id(), 'estimate_id' => $estimate->get_estimate_id(), 'invoice_id' => $estimate->get_invoice_id(), 'client_id' => $estimate->get_client_id(), 'client_data' => array(), 'status' => $estimate->get_status(), 'issue_date' => $estimate->get_issue_date(), 'expiration_date' => $estimate->get_expiration_date(), 'po_number' => $estimate->get_po_number(), 'discount' => $estimate->get_discount(), 'tax' => $estimate->get_tax(), 'tax2' => $estimate->get_tax2(), 'currency' => $estimate->get_currency(), 'total' => $estimate->get_total(), 'subtotal' => $estimate->get_subtotal(), 'calculated_total' => $estimate->get_calculated_total(), 'project_id' => $estimate->get_project_id(), 'terms' => $estimate->get_terms(), 'notes' => $estimate->get_notes(), 'line_items' => $estimate->get_line_items(), 'user_id' => $estimate->get_user_id());
     if ($estimate->get_client_id()) {
         $client = SI_Client::get_instance($estimate->get_client_id());
         if (is_a($client, 'SI_Client')) {
             $estimate_data['client_data'] = self::client_data($client);
         }
     }
     return $estimate_data;
 }
 /**
  * Adjust the estimate id
  * @param  integer $new_post_id
  * @param  integer $cloned_post_id
  * @param  string  $new_post_type
  * @return
  */
 public static function adjust_cloned_estimate($new_post_id = 0, $cloned_post_id = 0, $new_post_type = '')
 {
     if (get_post_type($new_post_id) == SI_Estimate::POST_TYPE) {
         $og_estimate = SI_Estimate::get_instance($cloned_post_id);
         $og_id = $og_estimate->get_estimate_id();
         $estimate = SI_Estimate::get_instance($new_post_id);
         // Adjust estimate id
         $new_id = apply_filters('si_adjust_cloned_estimate_id', $og_id . '-' . $new_post_id, $new_post_id, $cloned_post_id);
         $estimate->set_estimate_id($new_id);
         // Adjust status
         $estimate->set_pending();
     }
 }
Example #26
0
 public static function create_estimate($estimate = array())
 {
     if (isset($estimate['Description']) && $estimate['Description'] != '') {
         $subject = $estimate['Description'];
     } elseif (isset($estimate['Client']) && $estimate['Client'] != '') {
         $subject = $estimate['Client'] . ' #' . $estimate['Estimate ID'];
     } else {
         $subject = '#' . $estimate['Estimate ID'];
     }
     $args = array('subject' => $subject);
     // Attempt to find matching client
     if (isset($estimate['Company'])) {
         global $wpdb;
         $client_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = %s", esc_sql($estimate['Company']), SI_Client::POST_TYPE));
         // Get client and confirm it's validity
         if (is_array($client_ids) && !empty($client_ids)) {
             $client = SI_Client::get_instance($client_ids[0]);
             $args['client_id'] = $client->get_id();
         }
     }
     if (isset($estimate['Estimate ID'])) {
         $args['invoice_id'] = $estimate['Estimate ID'];
     }
     if (isset($estimate['Total'])) {
         $args['total'] = $estimate['Total'];
     }
     if (isset($estimate['Currency Code'])) {
         $args['currency'] = $estimate['Currency Code'];
     }
     if (isset($estimate['PO Number'])) {
         $args['po_number'] = $estimate['PO Number'];
     }
     if (isset($estimate['Discount %'])) {
         $args['discount'] = $estimate['Discount %'];
     }
     if (isset($estimate['Tax 1 %'])) {
         $args['tax'] = $estimate['Tax 1 %'];
     }
     if (isset($estimate['Tax 2 %'])) {
         $args['tax2'] = $estimate['Tax 2 %'];
     }
     if (isset($estimate['Notes'])) {
         $args['notes'] = $estimate['Notes'];
     }
     if (isset($estimate['Terms'])) {
         $args['terms'] = $estimate['Terms'];
     }
     if (isset($estimate['Estimate Date'])) {
         $args['issue_date'] = strtotime($estimate['Estimate Date']);
     }
     if (isset($estimate['Due Date'])) {
         $args['due_date'] = strtotime($estimate['Due Date']);
     }
     $line_items = self::build_line_items($invoice);
     $args['line_items'] = $line_items;
     $new_estimate_id = SI_Estimate::create_estimate($args, SI_Estimate::STATUS_TEMP);
     update_post_meta($new_estimate_id, self::CSV_ID, $estimate['Estimate ID']);
     $est = SI_Estimate::get_instance($new_estimate_id);
     // post date
     if (isset($estimate['Estimate Date'])) {
         $est->set_post_date(date('Y-m-d H:i:s', strtotime($estimate['Estimate Date'])));
     }
     return $est;
 }
 /**
  * Override the template and use something custom.
  * @param  string $template 
  * @return string           full path.
  */
 public static function override_template($template)
 {
     // Invoicing
     if (SI_Invoice::is_invoice_query()) {
         if (is_single()) {
             $custom_template = self::get_doc_current_template(get_the_id());
             $custom_path = $custom_template != '' ? 'invoice/' . $custom_template : '';
             $template = self::locate_template(array($custom_path, 'invoice-' . get_locale() . '.php', 'invoice.php', 'invoice/invoice.php'), $template);
         } else {
             $status = get_query_var(self::FILTER_QUERY_VAR);
             $template = self::locate_template(array('invoice/' . $status . '-invoices.php', $status . '-invoices.php', 'invoices.php', 'invoice/invoices.php'), $template);
         }
         $template = apply_filters('si_doc_template', $template, 'invoice');
     }
     // Estimates
     if (SI_Estimate::is_estimate_query()) {
         if (is_single()) {
             $custom_template = self::get_doc_current_template(get_the_id());
             $custom_path = $custom_template != '' ? 'estimate/' . $custom_template : '';
             $template = self::locate_template(array($custom_path, 'estimate-' . get_locale() . '.php', 'estimate.php', 'estimate/estimate.php'), $template);
         } else {
             $status = get_query_var(self::FILTER_QUERY_VAR);
             $template = self::locate_template(array('estimate/' . $status . '-estimates.php', $status . '-estimates.php', 'estimates.php', 'estimate/estimates.php'), $template);
         }
         $template = apply_filters('si_doc_template', $template, 'estimate');
     }
     return $template;
 }
Example #28
0
 /**
  * Adjust the invoice id
  * @param  integer $new_post_id
  * @param  integer $cloned_post_id
  * @param  string  $new_post_type
  * @return
  */
 public static function adjust_cloned_invoice($new_post_id = 0, $cloned_post_id = 0, $new_post_type = '')
 {
     if (get_post_type($cloned_post_id) === SI_Estimate::POST_TYPE) {
         $estimate = SI_Estimate::get_instance($cloned_post_id);
         $est_id = $estimate->get_invoice_id();
         $invoice = SI_Invoice::get_instance($new_post_id);
         if (!is_a($invoice, 'SI_Invoice')) {
             return;
         }
         // Adjust invoice id
         $new_id = apply_filters('si_adjust_cloned_invoice_id', $est_id . '-' . $new_post_id, $new_post_id, $cloned_post_id);
         $invoice->set_invoice_id($new_id);
         // Adjust status
         $invoice->set_as_temp();
     }
 }
 /**
  * Set the default estimate notes based on current status. The idea is that anything edited will have a different status.
  *
  * @param string  $terms
  * @param SI_Estimate $estimate
  * @return string
  */
 public static function maybe_set_estimate_notes($notes = '', SI_Estimate $estimate)
 {
     if (!in_array($estimate->get_status(), array(SI_Estimate::STATUS_PENDING, SI_Estimate::STATUS_APPROVED, SI_Estimate::STATUS_DECLINED))) {
         if ($notes == '') {
             $notes = self::get_default_notes();
         }
     }
     return $notes;
 }