예제 #1
0
 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);
 }
 public static function prevent_auto_draft_title($title = '', $post_id = 0)
 {
     if (__('Auto Draft') !== $title) {
         return $title;
     }
     if (SI_Estimate::POST_TYPE !== get_post_type($post_id)) {
         return $title;
     }
     $estimate = SI_Estimate::get_instance($post_id);
     return apply_filters('si_default_estimate_title', sprintf('#%s', $estimate->get_estimate_id()), $estimate);
 }
예제 #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)));
 }
예제 #7
0
 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);
 }
예제 #8
0
 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;
 }
예제 #9
0
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']);
    }
}
예제 #11
0
 /**
  * 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);
 }
    _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':
예제 #13
0
 public static function maybe_filter_money_format_money_format($money_format = '', $doc_id = 0)
 {
     if (!$doc_id) {
         $doc_id = get_the_ID();
     }
     switch (get_post_type($doc_id)) {
         case SI_Client::POST_TYPE:
             $client = SI_Client::get_instance($doc_id);
             break;
         case SI_Invoice::POST_TYPE:
             $invoice = SI_Invoice::get_instance($doc_id);
             $client = $invoice->get_client();
             break;
         case SI_Estimate::POST_TYPE:
             $estimate = SI_Estimate::get_instance($doc_id);
             $client = $estimate->get_client();
             break;
         default:
             $client = null;
             break;
     }
     if (is_a($client, 'SI_Client')) {
         $client_money_format = $client->get_money_format();
         if ($client_money_format != '') {
             $money_format = $client_money_format;
         }
     }
     return $money_format;
 }
예제 #14
0
 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;
 }
예제 #15
0
 /**
  * Get the template for the current doc
  * @param  string $doc
  * @return
  */
 public static function get_doc_current_template($doc_id)
 {
     $template_id = get_post_meta($doc_id, self::TEMPLATE_OPTION, true);
     if ($template_id == '') {
         switch (get_post_type($doc_id)) {
             case SI_Invoice::POST_TYPE:
                 $invoice = SI_Invoice::get_instance($doc_id);
                 $client_id = $invoice->get_client_id();
                 $template_id = self::get_client_invoice_template($client_id);
                 break;
             case SI_Estimate::POST_TYPE:
                 $estimate = SI_Estimate::get_instance($doc_id);
                 $client_id = $estimate->get_client_id();
                 $template_id = self::get_client_estimate_template($client_id);
                 break;
             default:
                 break;
         }
     }
     if (!$template_id) {
         $template_id = '';
     }
     return $template_id;
 }
예제 #16
0
 /**
  * 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;
 }
예제 #18
0
 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 send_estimate($estimate_id = 0, $event = '')
 {
     if ($event == '') {
         return;
     }
     $estimate = SI_Estimate::get_instance($estimate_id);
     if (!is_a($estimate, 'SI_Estimate')) {
         return;
     }
     $zaps = self::get_zaps_by_event($event);
     if (empty($zaps)) {
         return;
     }
     $data = self::estimate_data($estimate);
     Zapier_API::send_zaps($zaps, $data);
 }
예제 #23
0
 /**
  * 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();
     }
 }
예제 #24
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;
 }
 /**
  * Create Estimate
  * @param  array  $args * subject
  *                      * requirements
  *                      * fields
  *                      
  */
 public static function maybe_create_estimate($args = array())
 {
     $defaults = array('subject' => sprintf(self::__('New Estimate: %s'), date(get_option('date_format') . ' @ ' . get_option('time_format'), current_time('timestamp'))), 'requirements' => self::__('No requirements submitted. Check to make sure the "requirements" field is required.'), 'fields' => $_REQUEST);
     $parsed_args = apply_filters('si_afi_maybe_create_estimate', wp_parse_args($args, $defaults));
     // Create estimate
     $estimate_id = SI_Estimate::create_estimate($parsed_args);
     $estimate = SI_Estimate::get_instance($estimate_id);
     // TODO Add images
     // TODO Set the solution type
     // End, don't use estimate_submitted since a notification will be fired.
     do_action('estimate_submitted_from_adv_form', $estimate, $parsed_args);
     // History
     do_action('si_new_record', sprintf(si__('Estimate Submitted: Form %s.'), $parsed_args['history_link']), self::SUBMISSION_UPDATE, $estimate_id, sprintf(si__('Estimate Submitted: Form %s.'), $parsed_args['history_link']), 0, false);
     return $estimate;
 }
예제 #26
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();
     }
 }
 /**
  * Saving line items first thing since totals are calculated later based on other options.
  * @param  int $post_id
  * @param  object $post
  * @param  array $callback_args
  * @param  int $estimate_id
  * @return
  */
 public static function save_notes($post_id, $post, $callback_args, $estimate_id = null)
 {
     $estimate = SI_Estimate::get_instance($post_id);
     $estimate_terms = isset($_POST['estimate_terms']) && $_POST['estimate_terms'] != '' ? $_POST['estimate_terms'] : '';
     $estimate_notes = isset($_POST['estimate_notes']) && $_POST['estimate_notes'] != '' ? $_POST['estimate_notes'] : '';
     $estimate->set_terms($estimate_terms);
     $estimate->set_notes($estimate_notes);
 }