Example #1
0
/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!$job_safe) {
    die('denied');
}
$job_task_creation_permissions = module_job::get_job_task_creation_permissions();
$job_id = (int) $_REQUEST['job_id'];
$job = module_job::get_job($job_id);
$staff_members = module_user::get_staff_members();
$staff_member_rel = array();
foreach ($staff_members as $staff_member) {
    $staff_member_rel[$staff_member['user_id']] = $staff_member['name'];
}
$c = array();
$customers = module_customer::get_customers();
foreach ($customers as $customer) {
    $c[$customer['customer_id']] = $customer['customer_name'];
}
if (count($c) == 1) {
    $job['customer_id'] = key($c);
}
// check permissions.
if (class_exists('module_security', false)) {
    module_security::check_page(array('category' => 'Job', 'page_name' => 'Jobs', 'module' => 'job', 'feature' => 'create'));
Example #2
0
 public static function get_statistics_staff($search)
 {
     $staff_members = module_user::get_staff_members();
     $statistics = array();
     foreach ($staff_members as $staff_member) {
         $statistics[$staff_member['user_id']] = array('user_id' => $staff_member['user_id'], 'job_ids' => array(), 'job_count' => 0, 'task_count' => 0, 'task_ids' => array(), 'task_complete_ids' => array(), 'tasks_complete' => 0, 'hours_logged' => 0, 'hours_billed' => 0, 'amount_billed' => 0, 'amount_invoiced' => 0);
         $sql = "SELECT COUNT(j.job_id) AS job_count ";
         $sql .= " FROM `" . _DB_PREFIX . "job` j";
         $sql .= " WHERE j.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['job_count'] = $res['job_count'];
         $sql = "SELECT COUNT(t.task_id) AS task_count ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id";
         $sql .= " WHERE 1";
         $sql .= " AND t.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['task_count'] = $res['task_count'];
         // tasks completed on this date:
         $sql = "SELECT COUNT(t.task_id) AS task_count ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id";
         $sql .= " WHERE 1";
         $sql .= " AND t.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND t.date_done >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND t.date_done <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['tasks_complete'] = $res['task_count'];
         $sql = "SELECT t.task_id, tl.date_created, t.hours AS task_hours, t.amount, tl.hours AS hours_logged, p.job_id, p.hourly_rate ";
         $sql .= ", tl.create_user_id AS logged_user_id";
         $sql .= " FROM `" . _DB_PREFIX . "task_log` tl ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON tl.task_id = t.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON tl.job_id = p.job_id";
         $sql .= " WHERE 1 ";
         $sql .= " AND ( tl.create_user_id = " . (int) $staff_member['user_id'] . " )";
         //t.user_id = ".(int)$staff_member['user_id'] . " OR
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND tl.log_time >= '" . strtotime(input_date($search['date_from']) . " 00:00:00") . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND tl.log_time <= '" . strtotime(input_date($search['date_to']) . " 23:59:59") . "'";
         }
         //echo $sql;
         $tasks = query($sql);
         while ($r = mysql_fetch_assoc($tasks)) {
             //print_r($r);
             $jobtasks = module_job::get_tasks($r['job_id']);
             $statistics[$staff_member['user_id']]['job_ids'][$r['job_id']] = true;
             $task = $jobtasks[$r['task_id']];
             // this user has been assiged to this job individual task.
             if ($task['fully_completed']) {
                 $statistics[$staff_member['user_id']]['task_complete_ids'][$r['task_id']] = true;
                 $statistics[$staff_member['user_id']]['hours_billed'] += $r['task_hours'];
                 if ($task['amount'] > 0) {
                     $statistics[$staff_member['user_id']]['amount_billed'] += $task['amount'];
                 } else {
                     $statistics[$staff_member['user_id']]['amount_billed'] += $r['task_hours'] * $r['hourly_rate'];
                 }
                 $sql = "SELECT  * FROM `" . _DB_PREFIX . "invoice_item` ii WHERE ii.task_id = " . (int) $r['task_id'];
                 $task_invoice = qa1($sql);
                 if ($task_invoice && $task_invoice['task_id'] == $r['task_id']) {
                     if ($task_invoice['amount'] > 0) {
                         $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['amount'];
                     } else {
                         $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['hours'] * $task_invoice['hourly_rate'];
                     }
                 }
             }
             $statistics[$staff_member['user_id']]['task_ids'][$r['task_id']] = true;
             $statistics[$staff_member['user_id']]['hours_logged'] += $r['hours_logged'];
         }
         //$statistics[$staff_member['user_id']]['job_count'] = count($statistics[$staff_member['user_id']]['job_ids']);
     }
     return $statistics;
 }
Example #3
0
 public static function generate_task_preview($job_id, $job, $task_id, $task_data, $task_editable = true, $options = array())
 {
     ob_start();
     // can we edit this task?
     // if its been invoiced we cannot edit it.
     if ($task_editable && $task_data['invoiced'] && module_config::c('job_task_lock_invoiced_items', 1) && $task_data['fully_completed']) {
         $task_editable = false;
         // don't allow editable invoiced tasks
     }
     // todo-move this into a method so we can update it via ajax.
     $percentage = self::get_percentage($task_data);
     /*if($task_data['hours'] <= 0 && $task_data['fully_completed']){
           $percentage = 1;
       }else if ($task_data['completed'] > 0) {
           if($task_data['hours'] > 0){
               $percentage = round($task_data['completed'] / $task_data['hours'],2);
               $percentage = min(1,$percentage);
           }else{
               $percentage = 1;
           }
       }else{
           $percentage = 0;
       }*/
     $task_due_time = strtotime($task_data['date_due']);
     $show_task_numbers = module_config::c('job_show_task_numbers', 1) && $job['auto_task_numbers'] != 2;
     $staff_members = module_user::get_staff_members();
     $staff_member_rel = array();
     foreach ($staff_members as $staff_member) {
         $staff_member_rel[$staff_member['user_id']] = $staff_member['name'];
     }
     // hack to set the done_date if none exists.
     if ($percentage >= 1) {
         if ($task_data['task_id'] && isset($task_data['date_done']) && (!$task_data['date_done'] || $task_data['date_done'] == '0000-00-00')) {
             $task_logs = module_job::get_task_log($task_id);
             $done_date = $task_data['date_updated'];
             foreach ($task_logs as $task_log) {
                 if ($task_log['log_time']) {
                     $done_date = date('Y-m-d', $task_log['log_time']);
                 }
             }
             if ($done_date) {
                 update_insert('task_id', $task_data['task_id'], 'task', array('date_done' => $done_date));
                 $task_data['date_done'] = $done_date;
             }
         }
     } else {
         if ($task_data['task_id'] && isset($task_data['date_done']) && $task_data['date_done'] && $task_data['date_done'] != '0000-00-00') {
             $done_date = '0000-00-00';
             update_insert('task_id', $task_data['task_id'], 'task', array('date_done' => $done_date));
             $task_data['date_done'] = $done_date;
         }
     }
     // new different formats for job data.
     if ((!isset($task_data['manual_task_type']) || $task_data['manual_task_type'] < 0) && isset($job['default_task_type'])) {
         // use the job task type
         $task_data['manual_task_type'] = $job['default_task_type'];
         // if this task has been invoiced then we lock the manual_task_type to wahtever the job default currently is
         // this helps with the upgrade.
         if ($task_data['invoiced'] && $task_data['invoice_id']) {
             update_insert('task_id', $task_data['task_id'], 'task', array('manual_task_type' => $job['default_task_type']));
         }
     }
     include 'pages/ajax_task_preview.php';
     return ob_get_clean();
 }
Example #4
0
 public static function generate_task_preview($quote_id, $quote, $quote_task_id, $task_data, $task_editable = true)
 {
     ob_start();
     // can we edit this task?
     // if its been invoiced we cannot edit it.
     // todo-move this into a method so we can update it via ajax.
     /*if($task_data['hours'] <= 0 && $task_data['fully_completed']){
           $percentage = 1;
       }else if ($task_data['completed'] > 0) {
           if($task_data['hours'] > 0){
               $percentage = round($task_data['completed'] / $task_data['hours'],2);
               $percentage = min(1,$percentage);
           }else{
               $percentage = 1;
           }
       }else{
           $percentage = 0;
       }*/
     $show_task_numbers = module_config::c('quote_show_task_numbers', 1) && $quote['auto_task_numbers'] != 2;
     $staff_members = module_user::get_staff_members();
     $staff_member_rel = array();
     foreach ($staff_members as $staff_member) {
         $staff_member_rel[$staff_member['user_id']] = $staff_member['name'];
     }
     // new different formats for quote data.
     if ((!isset($task_data['manual_task_type']) || $task_data['manual_task_type'] < 0) && isset($quote['default_task_type'])) {
         // use the quote task type
         $task_data['manual_task_type'] = $quote['default_task_type'];
     }
     include 'pages/ajax_task_preview.php';
     return ob_get_clean();
 }
Example #5
0
 public static function handle_import($data, $add_to_group)
 {
     // woo! we're doing an import.
     // our first loop we go through and find matching customers by their "customer_name" (required field)
     // and then we assign that customer_id to the import data.
     // our second loop through if there is a customer_id we overwrite that existing customer with the import data (ignoring blanks).
     // if there is no customer id we create a new customer record :) awesome.
     foreach ($data as $rowid => $row) {
         if (!isset($row['customer_name']) || !trim($row['customer_name'])) {
             unset($data[$rowid]);
             continue;
         }
         if (!isset($row['customer_id']) || !$row['customer_id']) {
             $data[$rowid]['customer_id'] = 0;
         }
     }
     $staff_members = module_user::get_staff_members();
     $staff_member_rel = array();
     $staff_member_rel2 = array();
     foreach ($staff_members as $staff_member) {
         $staff_member_rel[$staff_member['name']] = $staff_member['user_id'];
         $staff_member_rel2[$staff_member['name'] . ' ' . $staff_member['last_name']] = $staff_member['user_id'];
     }
     // now save the data.
     foreach ($data as $rowid => $row) {
         //module_cache::clear_cache();
         $customer_id = isset($row['customer_id']) ? (int) $row['customer_id'] : 0;
         // check if this ID exists.
         if ($customer_id > 0) {
             $customer = self::get_customer($customer_id);
             if (!$customer || !isset($customer['customer_id']) || $customer['customer_id'] != $customer_id) {
                 $customer_id = 0;
             }
         }
         if (!$customer_id) {
             // search for a custoemr based on name.
             $customer = get_single('customer', 'customer_name', $row['customer_name']);
             //print_r($row); print_r($customer);echo '<hr>';
             if ($customer && $customer['customer_id'] > 0) {
                 $customer_id = $customer['customer_id'];
             }
         }
         $customer_id = update_insert("customer_id", $customer_id, "customer", $row);
         // add staff to customer.
         if (isset($row['customer_staff'])) {
             $staff_split = explode(',', $row['customer_staff']);
             foreach ($staff_split as $staff_name) {
                 $staff_name2 = trim($staff_name);
                 $staff_id = false;
                 if (isset($staff_member_rel[$staff_name])) {
                     $staff_id = $staff_member_rel[$staff_name];
                 } else {
                     if (isset($staff_member_rel[$staff_name2])) {
                         $staff_id = $staff_member_rel[$staff_name2];
                     } else {
                         if (isset($staff_member_rel2[$staff_name])) {
                             $staff_id = $staff_member_rel2[$staff_name];
                         } else {
                             if (isset($staff_member_rel2[$staff_name2])) {
                                 $staff_id = $staff_member_rel2[$staff_name2];
                             }
                         }
                     }
                 }
                 if ($staff_id) {
                     $sql = "REPLACE INTO `" . _DB_PREFIX . "customer_user_rel` SET ";
                     $sql .= " `user_id` = " . (int) $staff_id;
                     $sql .= ", `customer_id` = " . (int) $customer_id;
                     query($sql);
                 }
             }
         }
         // ad notes if possible
         if (isset($row['notes']) && strlen(trim($row['notes']))) {
             if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
                 module_note::save_note(array('owner_table' => 'customer', 'owner_id' => $customer_id, 'note' => trim($row['notes']), 'note_time' => time()));
             }
         }
         // see if we're updating an old contact, or adding a new primary contact.
         // match on name since that's a required field.
         $users = module_user::get_contacts(array('customer_id' => $customer_id));
         $user_match = 0;
         foreach ($users as $user) {
             if ($user['name'] == $row['primary_user_name']) {
                 $user_match = $user['user_id'];
                 break;
             }
         }
         $user_update = array('customer_id' => $customer_id);
         if (isset($row['primary_user_name'])) {
             $user_update['name'] = $row['primary_user_name'];
         }
         if (isset($row['primary_user_last_name'])) {
             $user_update['last_name'] = $row['primary_user_last_name'];
         }
         if (isset($row['primary_user_email'])) {
             $user_update['email'] = $row['primary_user_email'];
         }
         if (isset($row['primary_user_phone'])) {
             $user_update['phone'] = $row['primary_user_phone'];
         }
         if (isset($row['primary_user_fax'])) {
             $user_update['fax'] = $row['primary_user_fax'];
         }
         if (isset($row['primary_user_mobile'])) {
             $user_update['mobile'] = $row['primary_user_mobile'];
         }
         if (isset($row['primary_user_language'])) {
             $user_update['language'] = $row['primary_user_language'];
         }
         if (isset($row['password']) && strlen($row['password'])) {
             $user_update['password'] = md5(trim($row['password']));
         }
         $user_match = update_insert("user_id", $user_match, "user", $user_update);
         if ($user_match && isset($row['role']) && strlen(trim($row['role']))) {
             // find this role name and assign it to this user.
             $role = module_security::get_roles(array('name' => $row['role']));
             if ($role) {
                 $user_role = array_shift($role);
                 $role_id = $user_role['security_role_id'];
                 module_user::add_user_to_role($user_match, $role_id);
             }
         }
         self::set_primary_user_id($customer_id, $user_match);
         // do a hack to save address.
         $existing_address = module_address::get_address($customer_id, 'customer', 'physical');
         $address_id = $existing_address && isset($existing_address['address_id']) ? (int) $existing_address['address_id'] : 'new';
         $address = array_merge($row, array('owner_id' => $customer_id, 'owner_table' => 'customer', 'address_type' => 'physical'));
         module_address::save_address($address_id, $address);
         foreach ($add_to_group as $group_id => $tf) {
             module_group::add_to_group($group_id, $customer_id, 'customer');
         }
         // handle any extra fields.
         $extra = array();
         foreach ($row as $key => $val) {
             if (!strlen(trim($val))) {
                 continue;
             }
             if (strpos($key, 'extra:') !== false) {
                 $extra_key = str_replace('extra:', '', $key);
                 if (strlen($extra_key)) {
                     $extra[$extra_key] = $val;
                 }
             }
         }
         if ($extra) {
             // we handle extra importing for customer extra fields and contact extra fields.
             // sort out which are which.
             // but they have to be unique names. for now. oh well that'll do.
             $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'customer' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
             $customer_fields = qa($sql);
             $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'user' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
             $contact_fields = qa($sql);
             foreach ($extra as $extra_key => $extra_val) {
                 // does this one exist?
                 if (isset($customer_fields[$extra_key])) {
                     // this is a customer extra field.
                     $existing_extra = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $customer_id, 'extra_key' => $extra_key));
                     $extra_id = false;
                     foreach ($existing_extra as $key => $val) {
                         if ($val['extra_key'] == $extra_key) {
                             $extra_id = $val['extra_id'];
                         }
                     }
                     $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'customer', 'owner_id' => $customer_id);
                     $extra_id = (int) $extra_id;
                     update_insert('extra_id', $extra_id, 'extra', $extra_db);
                 } else {
                     if ($user_match && isset($contact_fields[$extra_key])) {
                         // this is a primary contact extra field
                         $existing_extra = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user_match, 'extra_key' => $extra_key));
                         $extra_id = false;
                         foreach ($existing_extra as $key => $val) {
                             if ($val['extra_key'] == $extra_key) {
                                 $extra_id = $val['extra_id'];
                             }
                         }
                         $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'user', 'owner_id' => $user_match);
                         $extra_id = (int) $extra_id;
                         update_insert('extra_id', $extra_id, 'extra', $extra_db);
                     }
                 }
             }
         }
     }
 }
Example #6
0
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
$locked = false;
$linked_staff_members = $linked_finances = $linked_invoice_payments = array();
foreach (module_user::get_staff_members() as $staff) {
    $linked_staff_members[$staff['user_id']] = $staff['name'] . ' ' . $staff['last_name'];
}
$finance_id = (int) $_REQUEST['finance_id'];
$finance = module_finance::get_finance($finance_id);
if (!isset($finance['finance_id']) || $finance['finance_id'] != $finance_id) {
    $finance_id = 0;
}
if ($finance_id <= 0) {
    if (isset($_REQUEST['from_invoice_id'])) {
        $invoice_data = module_invoice::get_invoice((int) $_REQUEST['from_invoice_id'], false);
        $finance['invoice_id'] = $invoice_data['invoice_id'];
        if ($invoice_data['customer_id']) {
            $finance['customer_id'] = $invoice_data['customer_id'];
        }
    }
    if (isset($_REQUEST['invoice_payment_id'])) {
        $invoice_payment_data = module_invoice::get_invoice_payment($_REQUEST['invoice_payment_id']);