public static function projects_time() { $nonce = $_REQUEST['nonce']; if (!wp_verify_nonce($nonce, self::SUBMISSION_NONCE)) { self::ajax_fail('Not going to fall for it!'); } if (isset($_REQUEST['project_id'])) { $project_id = $_REQUEST['project_id']; } if (!$project_id) { self::ajax_fail('No project id'); } $project = SI_Project::get_instance($project_id); if (!is_a($project, 'SI_Project')) { self::ajax_fail('Project not found'); } $times = $project->get_associated_times(); $time_data = array(); if (!empty($times)) { foreach ($times as $time_id) { $time = SI_Record::get_instance($time_id); if (!is_a($time, 'SI_Record')) { continue; } $activity = SI_Time::get_instance($time->get_associate_id()); $data = $time->get_data(); // If time is unbillable don't import // This includes not returning time that has already been invoiced. if (isset($_REQUEST['billable'])) { if (is_a($activity, 'SI_Time') && !$activity->is_billable()) { continue; } // Don't return the time that has already been invoiced if (isset($data['invoice_id'])) { continue; } } $description = is_a($activity, 'SI_Time') ? '<b>' . get_the_title($activity->get_id()) . "</b>\n" . $time->get_title() . "\n<small>" . date_i18n(get_option('date_format'), $data['date']) . '</small>' : $time->get_title() . "\n<small>" . date_i18n(get_option('date_format'), $data['date']) . '</small>'; $description = apply_filters('the_content', $description); $time_data[] = array('id' => $time_id, 'date' => date_i18n(get_option('date_format'), $data['date']), 'note' => apply_filters('the_content', $time->get_title()), 'qty' => si_get_number_format((double) $data['time_val']), 'description' => apply_filters('si_project_time_imported_description', $description), 'activity_id' => is_a($activity, 'SI_Time') ? $activity->get_id() : false, 'activity' => is_a($activity, 'SI_Time') ? $activity->get_title() : '', 'activity_rate' => is_a($activity, 'SI_Time') ? $activity->get_default_rate() : 0, 'activity_tax' => is_a($activity, 'SI_Time') ? $activity->get_default_percentage() : 0); } } if (empty($time_data)) { self::ajax_fail('Nothing to import'); } header('Content-type: application/json'); if (self::DEBUG) { header('Access-Control-Allow-Origin: *'); } echo wp_json_encode($time_data); exit; }
/** * Remove single time to associated array * @param int $time_id */ public function remove_time_associated($time_id = 0) { // Delete time record $time = SI_Record::get_instance($time_id); if (is_a($time, 'SI_Record')) { $activity_id = $time->get_associate_id(); $activity = SI_Time::get_instance($activity_id); $activity->delete_time($time_id); } // Remove from associated array $times = $this->get_associated_times(); if (($key = array_search($time_id, $times)) !== false) { unset($times[$key]); } $this->set_associated_times($times); }
</th> <th><?php _e('Billable', 'sprout-invoices'); ?> </th> </tr> </thead> <tbody> <?php if (!empty($time)) { ?> <?php foreach ($time as $time_id) { ?> <?php $time = SI_Time::get_instance($time_id); if (!is_a($time, 'SI_Time')) { continue; } ?> <tr id="<?php echo (int) $time_id; ?> "> <td><span class="time_activity_deletion item_action item_delete" data-id="<?php echo (int) $time_id; ?> " data-nonce="<?php echo wp_create_nonce(SI_Time_Tracking_Premium::SUBMISSION_NONCE); ?> "></span></td>
?> </th> </tr> </thead> <tbody> <?php $shown_item = 0; krsort($unbilled_time); foreach ($unbilled_time as $time_id => $data) { $shown_item++; // only show 5 if ($shown_item > 5) { break; } $time = SI_Time::get_time_entry($time_id); $activity = SI_Time::get_instance($time->get_associate_id()); $cost = is_a($activity, 'SI_Time') ? $data['time_val'] * $activity->get_default_rate() : 0; $unbilled_total_time += (double) $data['time_val']; $unbilled_total_cost += $cost; $user = get_userdata($data['user_id']); ?> <tr id="<?php echo (int) $time_id; ?> "> <td><span class="time_submitted_by"><a href="<?php echo get_edit_user_link($user->ID); ?> "><?php echo $user->data->display_name; ?>
public static function get_activities($time_types = array()) { if (empty($time_types)) { $args = array('post_type' => self::POST_TYPE, 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids'); $time_types = get_posts($args); } $time_types_options = array(); foreach ($time_types as $time_id) { $time = SI_Time::get_instance($time_id); if (is_a($time, 'SI_Time')) { $time_types_options[$time_id] = $time->get_title(); } } return $time_types_options; }