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; }
/** * Maybe create a status update record * @param SI_Estimate $estimate * @param string $status * @param string $original_status * @return null */ public static function maybe_create_status_update_record(SI_Estimate $estimate, $status = '', $original_status = '') { do_action('si_new_record', sprintf(__('Status changed: %s to <b>%s</b>.', 'sprout-invoices'), $estimate->get_status_label($original_status), $estimate->get_status_label($status)), self::HISTORY_STATUS_UPDATE, $estimate->get_id(), sprintf(__('Status update for %s.', 'sprout-invoices'), $estimate->get_id()), 0, false); }
/** * 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); }
public static function sender_submission_fields(SI_Estimate $estimate) { $fields = array(); $from_name = SI_Notifications_Control::from_name(array('estimate_id' => $estimate->get_id())); $from_email = SI_Notifications_Control::from_email(array('estimate_id' => $estimate->get_id())); $fields['send_as'] = array('weight' => 1, 'label' => __('Sender', 'sprout-invoices'), 'type' => 'text', 'placeholder' => '', 'attributes' => array('readonly' => 'readonly'), 'default' => $from_name . ' <' . $from_email . '>'); // options for recipients $client = $estimate->get_client(); $recipient_options = '<div class="form-group"><div class="input_wrap">'; // client users if (is_a($client, 'SI_Client')) { $client_users = $client->get_associated_users(); foreach ($client_users as $user_id) { $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_recipients[]" value="%1$s"> %2$s</label>', $user_id, esc_attr(SI_Notifications::get_user_email($user_id))); } } $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_custom_recipient_check" disabled="disabled"><input type="text" name="sa_metabox_custom_recipient" placeholder="%1$s"><span class="helptip" title="%2$s"></span></label>', __('*****@*****.**', 'sprout-invoices'), __('Entering an email will prevent some notification shortcodes from working since there is no client.', 'sprout-invoices')); // Send to me. $recipient_options .= sprintf('<label class="clearfix"><input type="checkbox" name="sa_metabox_recipients[]" value="%1$s"> %2$s</label>', get_current_user_id(), __('Send me a copy', 'sprout-invoices')); $recipient_options .= '</div></div>'; $fields['recipients'] = array('weight' => 5, 'label' => sprintf('%s <span class="helptip" title="%s"></span>', __('Recipients', 'sprout-invoices'), __('A notification will be sent if recipients are selected and this estimate is saved.', 'sprout-invoices')), 'type' => 'bypass', 'output' => $recipient_options); $fields['sender_note'] = array('weight' => 10, 'label' => __('Note', 'sprout-invoices'), 'type' => 'textarea', 'default' => $estimate->get_sender_note(), 'description' => __('This note will be added to the Estimate Notification via the [admin_note] shortcode.', 'sprout-invoices')); $fields['doc_id'] = array('type' => 'hidden', 'value' => $estimate->get_id(), 'weight' => 10000); $fields['notification_nonce'] = array('type' => 'hidden', 'value' => wp_create_nonce(SI_Controller::NONCE), 'weight' => 10001); $fields = apply_filters('si_sender_submission_fields', $fields); uasort($fields, array(__CLASS__, 'sort_by_weight')); return $fields; }