public static function widget_dashboard_invoices() { $si_project_id = self::get_si_project_id_from_psp_project_id(); if (is_a($si_project_id, 'WP_Post')) { $si_project_id = $si_project_id->ID; } $si_project = SI_Project::get_instance($si_project_id); if (!is_a($si_project, 'SI_Project')) { return; } $invoices = $si_project->get_invoices(); $estimates = $si_project->get_estimates(); $payments = $si_project->get_payments(); if ($invoices) { self::load_addon_view('panorama/invoices-widget', array('invoices' => $invoices, 'estimates' => $estimates, 'payments' => $payments), true); } /** * By default we are only going to show estimates * that do not have invoices associated. That estimate can * be linked from the invoices table instead. */ $estimates_to_show = array(); foreach ($estimates as $estimate_id) { $ass_invoice_id = si_get_estimate_invoice_id($estimate_id); if (!$ass_invoice_id || get_post_type($ass_invoice_id) != SI_Invoice::POST_TYPE) { $estimates_to_show[] = $estimate_id; } } if ($estimates) { self::load_addon_view('panorama/estimates-widget', array('invoices' => $invoices, 'estimates' => $estimates_to_show, 'payments' => $payments), true); } }
/** * Show the history * * @param WP_Post $post * @param array $metabox * @return */ public static function show_project_history_view($post, $metabox) { if ($post->post_status == 'auto-draft') { printf('<p>%s</p>', __('No history available.', 'sprout-invoices')); return; } $project = SI_Project::get_instance($post->ID); self::load_view('admin/meta-boxes/projects/history-premium', array('id' => $post->ID, 'post' => $post, 'project' => $project, 'historical_records' => array_reverse($project->get_history())), false); }
public static function show_pspsi_meta_box($post, $metabox) { $si_project_id = get_post_meta($post->ID, self::META_KEY, true); $invoices = array(); $estimates = array(); $payments = array(); if ($si_project_id) { $si_project = SI_Project::get_instance($si_project_id); $invoices = $si_project->get_invoices(); $estimates = $si_project->get_estimates(); $payments = $si_project->get_payments(); } wp_enqueue_script('select2_4.0'); wp_enqueue_style('select2_4.0_css'); self::load_addon_view('admin/meta-boxes/panorama-si', array('si_project_id' => $si_project_id, 'invoices' => $invoices, 'estimates' => $estimates, 'payments' => $payments), false); }
public static function maybe_disassociate_records($post_id = 0) { if (SI_Client::POST_TYPE === get_post_type($post_id)) { $client = SI_Client::get_instance($post_id); $invoices = $client->get_invoices(); foreach ($invoices as $invoice_id) { $invoice = SI_Invoice::get_instance($invoice_id); $invoice->set_client_id(0); } $estimates = $client->get_estimates(); foreach ($estimates as $estimate_id) { $estimate = SI_Estimate::get_instance($estimate_id); $estimate->set_client_id(0); } $projects = SI_Project::get_projects_by_client($post_id); foreach ($projects as $project_id) { $project = SI_Project::get_instance($project_id); $project->set_associated_clients(array()); } } }
/** * Display the content for the column * * @param string $column_name * @param int $id post_id * @return string */ public static function column_display($column_name, $id) { $project = SI_Project::get_instance($id); if (!is_a($project, 'SI_Project')) { return; // return for that temp post } switch ($column_name) { case 'psp': $psp_project_id = self::get_psp_project_id_from_si_project_id($id); printf('<a href="%s">%s</a>', get_edit_post_link($psp_project_id), get_the_title($psp_project_id)); $completed = psp_compute_progress($psp_project_id); if ($completed > 10) { echo '<p class="psp-progress"><span class="psp-' . $completed . '"><strong>%' . $completed . '</strong></span></p>'; } else { echo '<p class="psp-progress"><span class="psp-' . $completed . '"></span></p>'; } break; default: // code... break; } }
/** * Checks to see if the user is accessing a post they have access to as part of an sa_client * @param boolean $result Current pass/fail of access * @param integer $psp_id The project id of the current viewed psp project * @return boolean Access or not. */ public static function check_access_on_post($result = false, $psp_id = 0) { $current_user_id = get_current_user_id(); $user_associated_clients = SI_Client::get_clients_by_user($current_user_id); // If the result is true, then nothing will override it below // Plus if there are not associated clients than tough luck. if ($result || empty($user_associated_clients)) { return $result; } $si_project_id = get_field(self::META_KEY, $psp_id); // what si_project is assigned to this project access if (!$si_project_id || '' === $si_project_id) { return false; } $si_project = SI_Project::get_instance($si_project_id); $project_associated_clients = $si_project->get_associated_clients(); $matches = array_intersect($project_associated_clients, $user_associated_clients); // If there are no matches if (empty($matches)) { return false; } // there were matches return true; }
/** * Display the content for the column * * @param string $column_name * @param int $id post_id * @return string */ public static function column_display($column_name, $id) { $project = SI_Project::get_instance($id); if (!is_a($project, 'SI_Project')) { return; } // return for that temp post switch ($column_name) { case 'info': $associated_clients = $project->get_associated_clients(); echo '<p>'; printf('<b>%s</b>: ', si__('Client')); if (!empty($associated_clients)) { $clients_print = array(); foreach ($associated_clients as $client_id) { $clients_print[] = sprintf('<span class="associated_client"><a href="%s">%s</a></span>', get_edit_post_link($client_id), get_the_title($client_id)); } } if (!empty($clients_print)) { echo implode(', ', $clients_print); } else { echo si__('No associated clients'); } echo '</p>'; echo '<p>'; printf('<b>%s</b>: ', si__('Site')); echo make_clickable(esc_url($project->get_website())); echo '</p>'; break; case 'invoices': $invoices = $project->get_invoices(); $split = 2; $split_invoices = array_slice($invoices, 0, $split); if (!empty($split_invoices)) { echo "<dl>"; foreach ($split_invoices as $invoice_id) { printf('<dt>%s</dt><dd><a href="%s">%s</a></dd>', get_post_time(get_option('date_format'), false, $invoice_id), get_edit_post_link($invoice_id), get_the_title($invoice_id)); } echo "</dl>"; if (count($invoices) > $split) { printf('<span class="description">' . si__('...%s of <a href="%s">%s</a> most recent shown') . '</span>', $split, get_edit_post_link($id), count($invoices)); } } else { printf('<em>%s</em>', si__('No invoices')); } break; case 'estimates': $estimates = $project->get_estimates(); $split = 2; $split_estimates = array_slice($estimates, 0, $split); if (!empty($split_estimates)) { echo "<dl>"; foreach ($split_estimates as $estimate_id) { printf('<dt>%s</dt><dd><a href="%s">%s</a></dd>', get_post_time(get_option('date_format'), false, $estimate_id), get_edit_post_link($estimate_id), get_the_title($estimate_id)); } echo "</dl>"; if (count($estimates) > $split) { printf('<span class="description">' . si__('...%s of <a href="%s">%s</a> most recent shown') . '</span>', $split, get_edit_post_link($id), count($estimates)); } } else { printf('<em>%s</em>', si__('No estimates')); } break; default: // code... break; } }
function si_get_project_website($id = 0) { if (!$id) { global $post; $id = $post->ID; } $project = SI_Project::get_instance($id); return apply_filters('si_get_project_website', $project->get_website(), $project); }
public function get_project() { if (class_exists('SI_Project')) { $project_id = $this->get_project_id(); $project = SI_Project::get_instance($project_id); return $project; } }
public static function unbilled_time_tracking_dashboard() { $args = array('post_type' => SI_Project::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => 3, 'fields' => 'ids', 'orderby' => 'modified'); $projects = get_posts($args); if (empty($projects)) { _e('No new projects.', 'sprout-invoices'); return; } $something_shown = false; foreach ($projects as $project_id) { $project = SI_Project::get_instance($project_id); $times = $project->get_associated_times(); if (empty($times)) { continue; } self::load_addon_view('admin/dashboards/project-time-tracking-unbilled', array('project' => $project, 'times' => $times), true); $something_shown = true; } if (!$something_shown) { _e('No unbilled time from your most recent projects.', 'sprout-invoices'); } }
<p> <b><?php _e('Projects', 'sprout-invoices'); ?> </b> <?php if (!empty($projects)) { ?> <dl> <?php foreach ($projects as $project_id) { ?> <?php $project = SI_Project::get_instance($project_id); ?> <dt><?php printf('<a href="%s">%s</a>', get_edit_post_link($project_id), get_the_title($project_id)); ?> </dt> <dd> <?php if ($project->get_start_date() && $project->get_end_date()) { ?> <?php printf('%s—%s', date_i18n(get_option('date_format'), $project->get_start_date()), date_i18n(get_option('date_format'), $project->get_end_date())); ?> <?php } elseif ($project->get_start_date()) { ?> <?php printf('<b>Start</b>—%s', date_i18n(get_option('date_format'), $project->get_start_date()));
public static function save_meta_box_time_tracking_toggl($post_id, $post, $callback_args, $invoice_id = null) { $toggl_id = isset($_POST['sa_toggl_toggl_id']) ? $_POST['sa_toggl_toggl_id'] : 0; // Create new toggl project if selection permits if ($toggl_id == 'create_new') { // args $project = SI_Project::get_instance($post_id); $args = array('project_name' => $post->post_title); // create $toggl_id = self::maybe_create_toggl_project($project, $args); return; } // set the meta self::set_projects_toggl_id($post_id, (int) $toggl_id); self::set_to_sync_time($post_id); // Reset if (isset($_POST['sa_toggl_sync_time']) && $_POST['sa_toggl_sync_time']) { self::set_to_sync_time($post_id, true); } $default_activity = isset($_POST['sa_toggl_default_activity']) ? $_POST['sa_toggl_default_activity'] : 0; self::set_projects_default_time_import_activity($post_id, (int) $default_activity); if (isset($_POST['sa_toggl_pulldown_time']) && $_POST['sa_toggl_pulldown_time']) { self::download_toggl_time($post_id); } }
function si_get_project_website($id = 0) { if (!$id) { $id = get_the_ID(); } $project = SI_Project::get_instance($id); return apply_filters('si_get_project_website', $project->get_website(), $project); }
public static function download_toggl_time($project_id = 0) { $toggl_id = self::get_projects_toggl_id($project_id); if (!$toggl_id) { return; } $entries = Toggl_API::get_workspace_time($toggl_id); if (!isset($entries->data)) { return; } $project = SI_Project::get_instance($project_id); if (!is_a($project, 'SI_Project')) { return; } // Don't import times already imported, duh. $time_records = $project->get_associated_times(); $already_imported = array(); foreach ($time_records as $time_id) { $time = SI_Record::get_instance($time_id); if (!is_a($time, 'SI_Record')) { continue; } $data = $time->get_data(); if (isset($data['toggl_id'])) { $already_imported[] = $data['toggl_id']; } } $entries = apply_filters('si_toggl_import_entries', $entries->data); foreach ($entries as $key => $time_entry) { if (in_array($time_entry->id, $already_imported)) { continue; // already imported } $data = array('project_id' => (int) $project_id, 'activity_id' => (int) self::get_projects_default_time_import_activity($project_id), 'time_val' => $time_entry->dur / 3600000, 'note' => $time_entry->description, 'date' => strtotime($time_entry->start), 'toggl_id' => $time_entry->id); $project->create_associated_time($data); } }
function process_ajax_on_project_change() { $has_admin = array(); //@TODO ADD NONCE CHECK $post_id = $_POST['post_id']; if ($post_id <= 0) { return; } $SI_Project = SI_Project::get_instance($post_id); $invoice_ids = $SI_Project->get_invoices(); $estimate_ids = $SI_Project->get_estimates(); $client_ids = $SI_Project->get_associated_clients(); $clients = array(); $estimates = array(); $invoices = array(); $asscoiativeTasks = array(); foreach ($client_ids as $clients_id) { $SI_Client = SI_Client::get_instance($clients_id); $user_ids = $SI_Client->get_associated_users(); foreach ($user_ids as $user_id) { if (user_can($user_id, 'update_core')) { $has_admin[] = $user_id; } $user = get_user_by('ID', $user_id); $display_name = $user->data->display_name; $clients[] = array('user_id' => (int) $user_id, 'display_name' => $display_name); } } if (empty($has_admin) && current_user_can('update_core')) { $args = array('role' => 'administrator'); $users = get_users($args); foreach ($users as $user) { $clients[] = array('user_id' => (int) $user->ID, 'display_name' => $user->data->display_name); } } $blank_option = array('user_id' => '', 'display_name' => ''); array_unshift($clients, $blank_option); foreach ($estimate_ids as $estimate_id) { $title = get_the_title($estimate_id); $estimates[] = array('est_id' => (int) $estimate_id, 'est_title' => $title); } foreach ($invoice_ids as $invoice_id) { $title = get_the_title($invoice_id); $invoices[] = array('inv_id' => (int) $invoice_id, 'inv_title' => $title); } $args = array('post_type' => 'mg_task', 'meta_key' => 'project', 'meta_value' => $post_id, 'post_status' => array('complete', 'in-progress', 'not-started', 'publish', 'published')); $the_query = new WP_Query($args); while ($the_query->have_posts()) { $the_query->the_post(); $asscoiativeTasks[] = array('task_title' => get_the_title(), 'task_id' => get_the_ID()); } $data = array('clients' => $clients, 'estimates' => $estimates, 'invoices' => $invoices, 'tasks' => $asscoiativeTasks); $output = json_encode($data); exit($output); }