public static function print_discussion($job_id, $task_id, $job_data = array(), $task_data = array(), $allow_new = true) { $job_data = $job_data ? $job_data : module_job::get_job($job_id, true, true); if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 1) { // disabled & hidden. return; } $task_data = $task_data ? $task_data : module_job::get_task($job_id, $task_id); $comments = get_multiple('job_discussion', array('job_id' => $job_id, 'task_id' => $task_id), 'job_discussion_id', 'exact', 'job_discussion_id'); $current_user_id = module_security::get_loggedin_id(); $customer = module_customer::get_customer($job_data['customer_id']); if (!$current_user_id) { if ($job_data['customer_id'] && $customer['primary_user_id']) { $current_user_id = $customer['primary_user_id']; } } include module_theme::include_ucm('includes/plugin_job_discussion/inc/comment_list.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 */ 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)) {
<th id="sort_amount"><?php _e('Job Amount'); ?> </th> <th id="sort_invoice"><?php _e('Invoice'); ?> </th> </tr> </thead> <tbody> <?php $c = 0; $total = array('total_hours' => 0, 'total_amount_invoicable' => array(), 'invoice_paid' => array(), 'invoice_unpaid' => array(), 'invoice_pending' => array()); foreach ($job_reports as $original_job_data) { $job_data = module_job::get_job($original_job_data['job_id'], true); $total['total_hours'] += $job_data['total_hours']; if (!isset($total['total_amount_invoicable'][$job_data['currency_id']])) { $total['total_amount_invoicable'][$job_data['currency_id']] = 0; } $total['total_amount_invoicable'][$job_data['currency_id']] += $job_data['total_amount']; ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td> <?php echo module_job::link_open($job_data['job_id'], true, $job_data); ?>
public function process() { $errors = array(); if (isset($_REQUEST['butt_del']) && $_REQUEST['butt_del'] && $_REQUEST['job_id']) { $data = self::get_job($_REQUEST['job_id']); if (module_form::confirm_delete('job_id', _l("Really delete job: %s", $data['name']), self::link_open($_REQUEST['job_id']))) { $this->delete_job($_REQUEST['job_id']); set_message("job deleted successfully"); redirect_browser($this->link_open(false)); } } else { if ("ajax_job_list" == $_REQUEST['_process']) { $customer_id = isset($_REQUEST['customer_id']) ? (int) $_REQUEST['customer_id'] : 0; $res = module_job::get_jobs(array('customer_id' => $customer_id)); $options = array(); foreach ($res as $row) { $options[$row['job_id']] = $row['name']; } echo json_encode($options); exit; } else { if ("ajax_create_invoice" == $_REQUEST['_process']) { $job_id = (int) $_REQUEST['job_id']; $job = self::get_job($job_id, true); $job_tasks = self::get_tasks($job_id); if (!$job || $job['job_id'] != $job_id) { exit; } // no permissions. if (!module_invoice::can_i('create', 'Invoices')) { exit; } // no permissions ob_start(); ?> <p><?php _e('Please select which tasks to generate an invoice for:'); ?> </p> <ul> <?php foreach ($job['uninvoiced_task_ids'] as $task_id) { if (isset($job_tasks[$task_id])) { ?> <li> <input type="checkbox" id="invoice_create_task_<?php echo $task_id; ?> " data-taskid="<?php echo $task_id; ?> " class="invoice_create_task" name="invoice_task_id[<?php echo $task_id; ?> ]" value="1" <?php echo $job_tasks[$task_id]['fully_completed'] ? 'checked' : ''; ?> > <label for="invoice_create_task_<?php echo $task_id; ?> "> (#<?php echo $job_tasks[$task_id]['task_order']; ?> ) <?php echo htmlspecialchars($job_tasks[$task_id]['description']); ?> </label> </li> <?php } } ?> </ul> <?php $html = ob_get_clean(); echo $html; exit; } else { if ("ajax_task" == $_REQUEST['_process']) { // we are requesting editing a task. $job_id = (int) $_REQUEST['job_id']; $job = self::get_job($job_id, true); $job_tasks = self::get_tasks($job_id); if (!$job || $job['job_id'] != $job_id) { exit; } // no permissions. if (!self::can_i('edit', 'Job Tasks')) { exit; } // no permissions if (isset($_REQUEST['toggle_completed'])) { $task_id = (int) $_REQUEST['task_id']; $task_data = $job_tasks[$task_id]; $result = array(); if ($task_data && $task_data['job_id'] == $job_id) { if ($task_data['invoiced'] && $task_data['fully_completed']) { // dont allow to 'uncompleted' fully completed invoice tasks } else { // it is editable. $task_data['fully_completed_t'] = 1; $task_data['fully_completed'] = $task_data['fully_completed'] ? 0 : 1; // save a single job task $this->save_job_tasks($job_id, array('job_task' => array($task_id => $task_data))); $result['success'] = 1; $result['job_id'] = $job_id; $result['task_id'] = $task_id; $result['message'] = $task_data['fully_completed'] ? _l('Task marked as complete') : _l('Task marked as incomplete'); $email_status = self::send_job_task_email($job_id, $result['task_id'], 'toggle'); if ($email_status !== false) { $result['message'] .= is_array($email_status) && isset($email_status['message']) ? $email_status['message'] : _l(' and email sent to customer'); } } } echo json_encode($result); exit; } else { if (isset($_REQUEST['delete_task_log_id']) && (int) $_REQUEST['delete_task_log_id'] > 0) { $task_id = (int) $_REQUEST['task_id']; $task_log_id = (int) $_REQUEST['delete_task_log_id']; $sql = "DELETE FROM `" . _DB_PREFIX . "task_log` WHERE task_id = '{$task_id}' AND task_log_id = '{$task_log_id}' LIMIT 1"; query($sql); echo 'done'; } else { if (isset($_REQUEST['update_task_order'])) { // updating the task orders for this task.. $task_order = (array) $_REQUEST['task_order']; foreach ($task_order as $task_id => $new_order) { if ((int) $new_order > 0 && isset($job_tasks[$task_id])) { update_insert('task_id', $task_id, 'task', array('task_order' => (int) $new_order)); } } echo 'done'; } else { $task_id = (int) $_REQUEST['task_id']; $task_data = $job_tasks[$task_id]; $task_editable = !$task_data['invoiced']; $job_task_creation_permissions = module_job::get_job_task_creation_permissions(); // todo - load this select box in via javascript from existing one on page. $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 job data. $task_data['manual_task_type_real'] = $task_data['manual_task_type']; 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']; } $percentage = self::get_percentage($task_data); if (isset($_REQUEST['get_preview'])) { $after_task_id = $task_id; // this will put it right back where it started. $previous_task_id = 0; $job_tasks = self::get_tasks($job_id); $show_hours_summary = false; foreach ($job_tasks as $k => $v) { if ($v['manual_task_type'] < 0) { $job_tasks[$k]['manual_task_type'] = $job['default_task_type']; } if ($job_tasks[$k]['manual_task_type'] == _TASK_TYPE_HOURS_AMOUNT) { $show_hours_summary = true; } } foreach ($job_tasks as $k => $v) { // find out where this new task position is! if ($k == $task_id) { $after_task_id = $previous_task_id; break; } $previous_task_id = $k; } $create_invoice_button = ''; //if($job['total_amount_invoicable'] > 0 && module_invoice::can_i('create','Invoices')){ if (count($job['uninvoiced_task_ids']) && module_invoice::can_i('create', 'Invoices')) { //href="'.module_invoice::link_generate('new',array('arguments'=>array( 'job_id' => $job_id, ))).'" $create_invoice_button = '<a class="submit_button save_button uibutton job_generate_invoice_button" onclick="return ucm.job.generate_invoice();">' . _l('Create Invoice') . '</a>'; } $result = array('task_id' => $task_id, 'after_task_id' => $after_task_id, 'html' => self::generate_task_preview($job_id, $job, $task_id, $task_data), 'summary_html' => self::generate_job_summary($job_id, $job, $show_hours_summary), 'create_invoice_button' => $create_invoice_button); echo json_encode($result); } else { $show_task_numbers = module_config::c('job_show_task_numbers', 1) && $job['auto_task_numbers'] != 2; ob_start(); include 'pages/ajax_task_edit.php'; $result = array('task_id' => $task_id, 'hours' => isset($_REQUEST['hours']) ? (double) $_REQUEST['hours'] : 0, 'html' => ob_get_clean()); echo json_encode($result); } } } } exit; } else { if ("save_job_tasks_ajax" == $_REQUEST['_process']) { // do everything via ajax. trickery! // dont bother saving the job. it's already created. $job_id = (int) $_REQUEST['job_id']; $job_data = self::get_job($job_id); if (!$job_id || !$job_data || $job_data['job_id'] != $job_id) { set_error('Permission denied'); exit; } $result = $this->save_job_tasks($job_id, $_POST); $job_data = self::get_job($job_id, false); //if(!$job_data || $job_data['job_id'] != $job_id) $new_status = self::update_job_completion_status($job_id); $new_status = addcslashes(htmlspecialchars($new_status), "'"); //module_cache::clear_cache(); $new_job_data = self::get_job($job_id, false); // we now have to edit the parent DOM to reflect these changes. // what were we doing? adding a new task? editing an existing task? switch ($result['status']) { case 'created': // we added a new task. // add a new task to the bottom (OR MID WAY!) through the task list. if ((int) $result['task_id'] > 0) { // support for job task completion email. $email_status = self::send_job_task_email($job_id, $result['task_id'], 'created'); ?> <script type="text/javascript"> parent.refresh_task_preview(<?php echo (int) $result['task_id']; ?> ); parent.clear_create_form(); parent.ucm.add_message('<?php _e('New task created successfully'); echo is_array($email_status) && isset($email_status['message']) ? $email_status['message'] : ($email_status ? _l(' and email sent to customer') : ''); ?> '); parent.ucm.display_messages(true); <?php if ($job_data['status'] != $new_status) { ?> parent.jQuery('#status').val('<?php echo $new_status; ?> ').change();<?php } ?> <?php if ($new_job_data['date_completed'] != $job_data['date_completed']) { ?> parent.jQuery('#date_completed').val('<?php echo print_date($new_job_data['date_completed']); ?> ').change();<?php } ?> </script> <?php } else { set_error('New task creation failed.'); ?> <script type="text/javascript"> top.location.href = '<?php echo $this->link_open($_REQUEST['job_id']); ?> &added=true'; </script> <?php } break; case 'deleted': // we deleted a task. set_message('Task removed successfully'); ?> <script type="text/javascript"> top.location.href = '<?php echo $this->link_open($_REQUEST['job_id']); ?> '; <?php if ($job_data['status'] != $new_status) { ?> parent.jQuery('#status').val('<?php echo $new_status; ?> ').change();<?php } ?> </script> <?php break; case 'error': set_error('Something happened while trying to save a task. Unknown error.'); // something happened, refresh the parent browser frame ?> <script type="text/javascript"> top.location.href = '<?php echo $this->link_open($_REQUEST['job_id']); ?> '; </script> <?php break; case 'edited': // we changed a task (ie: completed?); // update this task above. if ((int) $result['task_id'] > 0) { $email_status = self::send_job_task_email($job_id, $result['task_id'], 'edited'); ?> <script type="text/javascript"> parent.canceledittask(); //parent.refresh_task_preview(<?php echo (int) $result['task_id']; ?> ); parent.ucm.add_message('<?php _e('Task saved successfully'); echo is_array($email_status) && isset($email_status['message']) ? $email_status['message'] : ($email_status ? _l(' and email sent to customer') : ''); ?> '); parent.ucm.display_messages(true); <?php if ($job_data['status'] != $new_status) { ?> parent.jQuery('#status').val('<?php echo $new_status; ?> ').change();<?php } ?> <?php if ($new_job_data['date_completed'] != $job_data['date_completed']) { ?> parent.jQuery('#date_completed').val('<?php echo print_date($new_job_data['date_completed']); ?> ').change();<?php } ?> </script> <?php } else { ?> <script type="text/javascript"> parent.canceledittask(); parent.ucm.add_error('<?php _e('Unable to save task'); ?> '); parent.ucm.display_messages(true); <?php if ($job_data['status'] != $new_status) { ?> parent.jQuery('#status').val('<?php echo $new_status; ?> ').change();<?php } ?> </script> <?php } break; default: ?> <script type="text/javascript"> parent.ucm.add_error('<?php _e('Unable to save task. Please check required fields.'); ?> '); parent.ucm.display_messages(true); </script> <?php break; } exit; } else { if ("save_job" == $_REQUEST['_process']) { $job_id = (int) $_REQUEST['job_id']; if ((int) $job_id > 0) { $original_job_data = self::get_job($job_id, false); if (!$original_job_data || $original_job_data['job_id'] != $job_id) { $original_job_data = array(); $job_id = false; } } else { $original_job_data = array(); $job_id = false; } // check create permissions. if (!$job_id && !self::can_i('create', 'Jobs')) { // user not allowed to create jobs. set_error('Unable to create new Jobs'); redirect_browser(self::link_open(false)); } else { if ($job_id && !self::can_i('edit', 'Jobs')) { // user not allowed to create jobs. set_error('Unable to edit Jobs'); redirect_browser(self::link_open(false)); } } $job_id = $this->save_job($job_id, $_POST); // look for the new tasks flag. if (isset($_REQUEST['default_task_list_id']) && isset($_REQUEST['default_tasks_action'])) { switch ($_REQUEST['default_tasks_action']) { case 'insert_default': if ((int) $_REQUEST['default_task_list_id'] > 0) { $default = self::get_default_task($_REQUEST['default_task_list_id']); $task_data = $default['task_data']; $new_task_data = array('job_task' => array()); foreach ($task_data as $task) { $task['job_id'] = $job_id; if ($task['date_due'] && $task['date_due'] != '0000-00-00') { $diff_time = strtotime($task['date_due']) - $task['saved_time']; $task['date_due'] = date('Y-m-d', time() + $diff_time); } $new_task_data['job_task'][] = $task; } $this->save_job_tasks($job_id, $new_task_data); } break; case 'save_default': $new_default_name = trim($_REQUEST['default_task_list_id']); if ($new_default_name != '') { // time to save it! $task_data = self::get_tasks($job_id); $cached_task_data = array(); foreach ($task_data as $task) { unset($task['task_id']); unset($task['date_done']); unset($task['invoice_id']); unset($task['task_order']); unset($task['create_user_id']); unset($task['update_user_id']); unset($task['date_created']); unset($task['date_updated']); $task['saved_time'] = time(); $cached_task_data[] = $task; /*$cached_task_data[] = array( 'hours' => $task['hours'], 'amount' => $task['amount'], 'billable' => $task['billable'], 'fully_completed' => $task['fully_completed'], 'description' => $task['description'], 'long_description' => $task['long_description'], 'date_due' => $task['date_due'], 'user_id' => $task['user_id'], 'approval_required' => $task['approval_required'], 'task_order' => $task['task_order'], 'saved_time' => time(), );*/ } self::save_default_tasks((int) $_REQUEST['default_task_list_id'], $new_default_name, $cached_task_data); unset($task_data); } break; } } // check if we are generating any renewals if (isset($_REQUEST['generate_renewal']) && $_REQUEST['generate_renewal'] > 0) { $new_job_id = $this->renew_job($job_id); set_message("Job renewed successfully"); redirect_browser($this->link_open($new_job_id)); } if (isset($_REQUEST['butt_create_deposit']) && isset($_REQUEST['job_deposit']) && $_REQUEST['job_deposit'] > 0) { if (strpos($_REQUEST['job_deposit'], '%') !== false) { $job_data = module_job::get_job($job_id); $percent = (int) str_replace('%', '', $_REQUEST['job_deposit']); $_REQUEST['job_deposit'] = number_out($job_data['total_amount'] * ($percent / 100)); } // create an invoice for this job. $url = module_invoice::link_generate('new', array('arguments' => array('job_id' => $job_id, 'as_deposit' => 1, 'amount_due' => number_in($_REQUEST['job_deposit']), 'description' => str_replace('{JOB_NAME}', $_POST['name'], module_config::c('job_deposit_text', 'Deposit for job: {JOB_NAME}'))))); redirect_browser($url); } set_message("Job saved successfully"); redirect_browser(isset($_REQUEST['_redirect']) && !empty($_REQUEST['_redirect']) ? $_REQUEST['_redirect'] : $this->link_open($job_id)); } } } } } } if (!count($errors)) { redirect_browser($_REQUEST['_redirect']); exit; } print_error($errors, true); }
} // check if there is any subscription credit available for this customer $subscription_credits = array(); if ((int) $invoice_id > 0 && !$invoice_locked && class_exists('module_subscription') && module_subscription::is_plugin_enabled()) { if ($customer_data && $customer_data['customer_id']) { $customer_credit = module_subscription::get_available_credit('customer', $customer_data['customer_id']); foreach ($customer_credit as $subscription_id => $c) { if ($c['remain'] > 0) { $subscription_credits[$subscription_id] = $c; } } } if (count($invoice['job_ids'])) { foreach ($invoice['job_ids'] as $job_id) { // linked website? $job_data = module_job::get_job($job_id, false); if ($job_data && $job_data['website_id']) { $website_credit = module_subscription::get_available_credit('website', $job_data['website_id']); foreach ($website_credit as $subscription_id => $c) { if ($c['remain'] > 0) { $subscription_credits[$subscription_id] = $c; } } } } } } if ((int) $invoice_id > 0 && module_invoice::can_i('edit', 'Invoices') && $invoice['total_amount_due'] > 0 && $customer_data && (count($subscription_credits) || $customer_data['credit'] > 0) && (!$invoice['date_cancel'] || $invoice['date_cancel'] == '0000-00-00')) { /** CREDIT */ ob_start(); ?>
$column = isset($_REQUEST['table_sort_column']) ? $_REQUEST['table_sort_column'] : $_SESSION['_table_sort']['job_list'][0]; if (isset(module_table_sort::$table_sort_options['sortable'][$column])) { $dbcolumn = module_table_sort::$table_sort_options['sortable'][$column]['field']; if (!isset($test[$dbcolumn])) { $test = module_job::get_job($test['job_id']); if (isset($test[$dbcolumn])) { // load all job data (EEP!) so we can sort better foreach ($jobs as $job_id => $job) { $full_job = module_job::get_job($job['job_id']); if (isset($full_job[$dbcolumn])) { $jobs[$job_id][$dbcolumn] = $full_job[$dbcolumn]; } } } } } } } } $table_manager->set_id('job_list'); $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return module_job::get_job($row_data['job_id']); }; $table_manager->set_rows($jobs); $table_manager->pagination = true; $table_manager->print_table(); ?> </form>
function customer_admin_email_generate_invoice_list($invoices, $customer_id) { ob_start(); $colspan = 9; $colspan2 = 0; $invoice_total = array(); $invoice_total_due = array(); foreach ($invoices as $invoice) { if (!isset($invoice_total[$invoice['currency_id']])) { $invoice_total[$invoice['currency_id']] = 0; } if ($invoice['c_total_amount'] == 0) { $invoice = module_invoice::get_invoice($invoice['invoice_id']); } $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount']; if (!isset($invoice_total_due[$invoice['currency_id']])) { $invoice_total_due[$invoice['currency_id']] = 0; } $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due']; } $table_manager = module_theme::new_table_manager(); $columns = array(); $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) { //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice); echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>'; }, 'cell_class' => 'row_action'); $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) { echo htmlspecialchars($invoice['status']); }); $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) { if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') { //echo print_date($invoice['date_created']); } else { echo print_date($invoice['date_create']); } }); $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) { if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) { echo '<span class="error_text">'; echo print_date($invoice['date_due']); echo '</span>'; } else { echo print_date($invoice['date_due']); } }); $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) { if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_sent']); ?> <?php } else { ?> <span class="error_text"><?php _e('Not sent'); ?> </span> <?php } }); $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { ?> <?php echo print_date($invoice['date_paid']); ?> <?php } else { if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') { ?> <span class="error_text"><?php _e('Cancelled'); ?> </span> <?php } else { if ($invoice['overdue']) { ?> <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php _e('Overdue'); ?> </span> <?php } else { ?> <span class="error_text"><?php _e('Not paid'); ?> </span> <?php } } } }); if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) { $colspan++; $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) { if (isset($invoice['website_ids'])) { foreach ($invoice['website_ids'] as $website_id) { if ((int) $website_id > 0) { echo module_website::link_open($website_id, true); echo '<br/>'; } } } }); } $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) { foreach ($invoice['job_ids'] as $job_id) { if ((int) $job_id > 0) { //echo module_job::link_open($job_id,true); $job_data = module_job::get_job($job_id); echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>'; if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') { _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } echo "<br/>\n"; } } hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']); }); if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $colspan++; $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) { echo module_customer::link_open($invoice['customer_id'], true); }); } $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) { echo dollar($invoice['total_amount'], true, $invoice['currency_id']); }); $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) { echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']); ?> <?php if ($invoice['total_amount_credit'] > 0) { ?> <span class="success_text"><?php echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id'])); ?> </span> <?php } }); if (class_exists('module_extra', false)) { ob_start(); $colspan2 += module_extra::print_table_header('invoice'); // used in the footer calc. ob_end_clean(); $table_manager->display_extra('invoice', function ($invoice) { module_extra::print_table_data('invoice', $invoice['invoice_id']); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) { return module_invoice::get_invoice($row_data['invoice_id']); } return array(); }; $table_manager->set_rows($invoices); if (module_config::c('invoice_list_show_totals', 1)) { $footer_rows = array(); foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) { $currency = get_single('currency', 'currency_id', $currency_id); $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2)); } $table_manager->set_footer_rows($footer_rows); } $table_manager->pagination = false; $table_manager->print_table(); return ob_get_clean(); }
public static function get_files($search = false, $skip_permissions = false) { // build up a custom search sql query based on the provided search fields $sql = "SELECT f.* "; $from = " FROM `" . _DB_PREFIX . "file` f "; if (class_exists('module_customer', false)) { $from .= " LEFT JOIN `" . _DB_PREFIX . "customer` c USING (customer_id)"; } $where = " WHERE 1 "; if (isset($search['generic']) && $search['generic']) { $str = mysql_real_escape_string($search['generic']); $where .= " AND ( "; $where .= " f.file_name LIKE '%{$str}%' "; //$where .= "OR u.url LIKE '%$str%' "; $where .= ' ) '; } /*if(isset($search['job']) && $search['job']){ $str = mysql_real_escape_string($search['job']); $from .= " LEFT JOIN `"._DB_PREFIX."job` j USING (job_id)"; $where .= " AND ( "; $where .= " j.name LIKE '%$str%' "; $where .= ' ) '; }*/ // tricky job searching, by name or by job id. // but we don't want to restrict it to customer if they are searching for a job. /* * this is the logic we have to follow: * $customer_access = module_customer::get_customer($file['customer_id']); $job_access = module_job::get_job($file['job_id']); if( ($customer_access && $customer_access['customer_id'] == $file['customer_id']) || ($job_access && $job_access['job_id'] == $file['job_id']) ){ */ foreach (array('file_id', 'owner_id', 'owner_table', 'status', 'bucket_parent_file_id') as $key) { if (isset($search[$key]) && $search[$key] !== '' && $search[$key] !== false) { $str = mysql_real_escape_string($search[$key]); $where .= " AND f.`{$key}` = '{$str}'"; } } // permissions from customer module. // tie in with customer permissions to only get jobs from customers we can access. if (!$skip_permissions) { switch (self::get_file_data_access()) { case _FILE_ACCESS_ALL: // all files, no limits on SQL here break; case _FILE_ACCESS_JOBS: $jobs = module_job::get_jobs(array(), array('columns' => 'u.job_id AS job_id')); $where .= " AND f.job_id IN ( "; if (count($jobs)) { foreach ($jobs as $valid_job_id) { $where .= (int) $valid_job_id['job_id'] . ','; } $where = rtrim($where, ','); } else { $where .= ' -1 '; } $where .= ' ) '; break; case _FILE_ACCESS_ME: $where .= " AND f.create_user_id = " . (int) module_security::get_loggedin_id(); break; case _FILE_ACCESS_ASSIGNED: $from .= " LEFT JOIN `" . _DB_PREFIX . "file_user_rel` cur ON f.file_id = cur.file_id"; $where .= " AND (cur.user_id = " . (int) module_security::get_loggedin_id() . ")"; break; case _FILE_ACCESS_CUSTOMERS: default: if (class_exists('module_customer', false)) { //added for compat in newsletter system that doesn't have customer module switch (module_customer::get_customer_data_access()) { case _CUSTOMER_ACCESS_ALL: // all customers! so this means all files! break; case _CUSTOMER_ACCESS_ALL_COMPANY: case _CUSTOMER_ACCESS_CONTACTS: case _CUSTOMER_ACCESS_TASKS: case _CUSTOMER_ACCESS_STAFF: $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND ( "; foreach ($valid_customer_ids as $valid_customer_id) { if (isset($search['owner_table'])) { $where .= " (f.owner_table = 'customer' AND f.owner_id = '" . (int) $valid_customer_id . "') OR "; } else { $where .= " (f.customer_id = '" . (int) $valid_customer_id . "') OR "; if (isset($search['customer_id']) && $search['customer_id'] && $search['customer_id'] == $valid_customer_id) { unset($search['customer_id']); } } } $where = rtrim($where, 'OR '); $where .= ' ) '; } break; } } } // file data access switch } if (class_exists('module_job', false)) { if (isset($search['job_id']) && (int) $search['job_id'] > 0) { // check if we have permissions to view this job. $job = module_job::get_job($search['job_id']); if (!$job || $job['job_id'] != $search['job_id']) { $search['job_id'] = false; } } } if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $where .= " AND f.job_id = " . (int) $search['job_id']; } else { if (isset($search['quote_id']) && (int) $search['quote_id'] > 0) { $where .= " AND f.quote_id = " . (int) $search['quote_id']; } else { if (isset($search['customer_id']) && (int) $search['customer_id']) { $where .= " AND f.customer_id = " . (int) $search['customer_id']; } } } $group_order = ' GROUP BY f.file_id ORDER BY f.file_name'; // stop when multiple company sites have same region $sql = $sql . $from . $where . $group_order; //echo $sql; $result = qa($sql); //module_security::filter_data_set("invoice",$result); return $result; //return get_multiple("file",$search,"file_id","exact","file_id"); }
if (isset($invoice['website_ids'])) { foreach ($invoice['website_ids'] as $website_id) { if ((int) $website_id > 0) { echo module_website::link_open($website_id, true); echo '<br/>'; } } } }); } if (module_job::is_plugin_enabled() && module_job::can_i('view', 'Jobs')) { $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) { foreach ($invoice['job_ids'] as $job_id) { if ((int) $job_id > 0) { echo module_job::link_open($job_id, true); $job_data = module_job::get_job($job_id); if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') { _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew'])))); } echo "<br/>\n"; } } hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']); }); } if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) { $colspan++; $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) { echo module_customer::link_open($invoice['customer_id'], true); }); }
public function external_hook($hook) { switch ($hook) { case 'public_signup_form': $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper'); $signup_form->page_title = $signup_form->description; $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html())); echo $signup_form->render('pretty_html'); exit; case 'public_signup': // sign out if testing. if (module_security::is_logged_in()) { set_message('Logged out due to signup'); module_security::logout(); } $result = array('messages' => array()); function customer_signup_complete($result) { if (isset($_REQUEST['via_ajax'])) { echo json_encode($result); } else { echo implode('<br/>', $result['messages']); } exit; } if (!module_config::c('customer_signup_allowed', 0)) { $result['error'] = 1; $result['messages'][] = 'Customer signup disabled'; customer_signup_complete($result); } //recaptcha on signup form. if (module_config::c('captcha_on_signup_form', 0)) { if (!module_captcha::check_captcha_form()) { $result['error'] = 1; $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.'; customer_signup_complete($result); } } $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array(); $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array(); $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array(); $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array(); $customer_extra = isset($customer['extra']) ? $customer['extra'] : array(); $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array(); $address = isset($_POST['address']) ? $_POST['address'] : array(); $website = isset($_POST['website']) ? $_POST['website'] : array(); $website_extra = isset($website['extra']) ? $website['extra'] : array(); $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array(); $job = isset($_POST['job']) ? $_POST['job'] : array(); $job_extra = isset($job['extra']) ? $job['extra'] : array(); $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array(); // sanatise possibly problematic fields: // customer: $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type'); foreach ($customer as $key => $val) { if (!in_array($key, $allowed)) { unset($customer[$key]); } } if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) { unset($customer['type']); } // added multiple contact support in the form of arrays. $contact_fields = array('name', 'last_name', 'email', 'phone'); if (module_config::c('customer_signup_password', 0)) { $contact_fields[] = 'password'; } foreach ($contact_fields as $multi_value) { if (isset($contact[$multi_value])) { if (!is_array($contact[$multi_value])) { $contact[$multi_value] = array($contact[$multi_value]); } } else { if (isset($customer[$multi_value])) { $contact[$multi_value] = array($customer[$multi_value]); } else { $contact[$multi_value] = array(); } } } $valid_contact_email = false; $name_fallback = false; $primary_email = false; foreach ($contact['email'] as $contact_key => $email) { if (!$name_fallback && isset($contact['name'][$contact_key])) { $name_fallback = $contact['name'][$contact_key]; } $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL); if ($contact['email'][$contact_key]) { $valid_contact_email = true; if (!$primary_email) { $primary_email = $contact['email'][$contact_key]; // set the primary contact details here by adding them to the master customer array foreach ($contact_fields as $primary_contact_field) { $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; unset($contact[$primary_contact_field][$contact_key]); } } } } // start error checking / required fields if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) { $customer['customer_name'] = $name_fallback; } if (!strlen($customer['customer_name'])) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide a customer name."; } if (!$valid_contact_email || !$primary_email) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide an email address."; } // check all posted required fields. function check_required($postdata, $messages = array()) { if (is_array($postdata)) { foreach ($postdata as $key => $val) { if (strpos($key, '_required') && strlen($val)) { $required_key = str_replace('_required', '', $key); if (!isset($postdata[$required_key]) || !$postdata[$required_key]) { $messages[] = 'Required field missing: ' . htmlspecialchars($val); } } if (is_array($val)) { $messages = check_required($val, $messages); } } } return $messages; } $messages = check_required($_POST); if (count($messages)) { $result['error'] = 1; $result['messages'] = array_merge($result['messages'], $messages); } if (isset($result['error'])) { customer_signup_complete($result); } // end error checking / required fields. // check if this customer already exists in the system, based on email address $customer_id = false; $creating_new = true; $_REQUEST['user_id'] = 0; if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) { $users = module_user::get_contacts(array('email' => $customer['email'])); foreach ($users as $user) { if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) { // this user exists as a customer! yey! // add them to this listing. $customer_id = $user['customer_id']; $creating_new = false; $_REQUEST['user_id'] = $user['user_id']; // dont let signups update existing passwords. if (isset($customer['password'])) { unset($customer['password']); } if (isset($customer['new_password'])) { unset($customer['new_password']); } } } } $_REQUEST['extra_customer_field'] = array(); $_REQUEST['extra_user_field'] = array(); module_extra::$config['allow_new_keys'] = false; module_extra::$config['delete_existing_empties'] = false; // save customer extra fields. if (count($customer_extra)) { // format the address so "save_customer" handles the save for us foreach ($customer_extra as $key => $val) { $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val); } } // save customer and customer contact details: $customer_id = $this->save_customer($customer_id, $customer); if (!$customer_id) { $result['error'] = 1; $result['messages'][] = 'System error: failed to create customer.'; customer_signup_complete($result); } $customer_data = module_customer::get_customer($customer_id); // todo - merge primary and secondary contact/extra/group saving into a single loop if (!$customer_data['primary_user_id']) { $result['error'] = 1; $result['messages'][] = 'System error: Failed to create customer contact.'; customer_signup_complete($result); } else { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($customer_data['primary_user_id'], $role_id); } // save contact extra data (repeated below for additional contacts) if (isset($contact_extra[0]) && count($contact_extra[0])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[0] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']); } // save contact groups if (isset($contact_group[0]) && count($contact_group[0])) { foreach ($contact_group[0] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user'); } } } } foreach ($contact['email'] as $contact_key => $email) { // add any additional contacts to the customer. $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id)); if (count($users)) { // this contact already exists for this customer, dont update/change it. continue; } $new_contact = array('customer_id' => $customer_id); foreach ($contact_fields as $primary_contact_field) { $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; } // dont let additional contacts have passwords. if (isset($new_contact['password'])) { unset($new_contact['password']); } if (isset($new_contact['new_password'])) { unset($new_contact['new_password']); } global $plugins; $contact_user_id = $plugins['user']->create_user($new_contact, 'signup'); if ($contact_user_id) { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($contact_user_id, $role_id); } // save contact extra data (repeated below for primary contacts) if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[$contact_key] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $contact_user_id); } // save contact groups if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) { foreach ($contact_group[$contact_key] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $contact_user_id, 'user'); } } } } } if (count($customer_group)) { // format the address so "save_customer" handles the save for us foreach ($customer_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_id, 'customer'); } } } $note_keys = array('customer', 'website', 'job', 'address', 'subscription'); $note_text = _l('Customer signed up from Signup Form:'); $note_text .= "\n\n"; foreach ($note_keys as $note_key) { $note_text .= "\n" . ucwords(_l($note_key)) . "\n"; if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) { foreach ($_POST[$note_key] as $post_key => $post_val) { $note_text .= "\n - " . _l($post_key) . ": "; if (is_array($post_val)) { foreach ($post_val as $p => $v) { $note_text .= "\n - - " . _l($p) . ': ' . $v; } } else { $note_text .= $post_val; } } } } $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0); update_insert('note_id', false, 'note', $note_data); // save customer address fields. if (count($address)) { $address_db = module_address::get_address($customer_id, 'customer', 'physical'); $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false; $address['owner_id'] = $customer_id; $address['owner_table'] = 'customer'; $address['address_type'] = 'physical'; // we have post data to save, write it to the table!! module_address::save_address($address_id, $address); } // website: $allowed = array('url', 'name', 'extra', 'notes'); foreach ($website as $key => $val) { if (!in_array($key, $allowed)) { unset($website[$key]); } } $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : ''; $website_id = 0; if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) { if (strlen($website['url'])) { // see if website already exists, don't create or update existing one for now. $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url'])); foreach ($existing_websites as $existing_website) { $website_id = $existing_website['website_id']; } } // echo $website_id;echo $website['url']; print_r($website_extra);exit; if (!$website_id) { $website_data = module_website::get_website($website_id); $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['customer_id'] = $customer_id; $website_id = update_insert('website_id', false, 'website', $website_data); // save website extra data. if ($website_id && count($website_extra)) { $_REQUEST['extra_website_field'] = array(); foreach ($website_extra as $key => $val) { $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('website', 'website_id', $website_id); } if ($website_id && isset($website['notes']) && strlen($website['notes'])) { // add notes to this website. $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']); $note_id = update_insert('note_id', false, 'note', $note_data); } } if ($website_id) { if (count($website_group)) { // format the address so "save_customer" handles the save for us foreach ($website_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $website_id, 'website'); } } } } } // generate jobs for this customer. $job_created = array(); if ($job && isset($job['type']) && is_array($job['type'])) { if (module_config::c('customer_signup_any_job_type', 0)) { foreach ($job['type'] as $type_name) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type_name; if (!$job_data['name']) { $job_data['name'] = $type_name; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } else { foreach (module_job::get_types() as $type_id => $type) { foreach ($job['type'] as $type_name) { if ($type_name == $type) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type; if (!$job_data['name']) { $job_data['name'] = $type; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } } } if (count($job_created) && count($job_extra)) { // save job extra data. foreach ($job_created as $job_created_id) { if ($job_created_id && count($job_extra)) { $_REQUEST['extra_job_field'] = array(); foreach ($job_extra as $key => $val) { $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('job', 'job_id', $job_created_id); } } } } // save files against customer $uploaded_files = array(); if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) { foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) { if (is_uploaded_file($tmp_file)) { // save to file module for this customer $file_name = basename($_FILES['customerfiles']['name'][$file_id]); if (strlen($file_name)) { $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name); if (move_uploaded_file($tmp_file, $file_path)) { // success! write to db. $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false); $file_id = update_insert('file_id', false, 'file', $file_data); $uploaded_files[] = $file_id; } } } } } // we create subscriptions for this customer/website (if none already exist) $subscription['subscription_name'] = array(); $subscription['subscription_invoice'] = array(); if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) { if ($subscription['for'] == 'website' && $website_id > 0) { $owner_table = 'website'; $owner_id = $website_id; } else { $owner_table = 'customer'; $owner_id = $customer_id; } $available_subscriptions = module_subscription::get_subscriptions(); $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id); foreach ($subscription['subscriptions'] as $subscription_id => $tf) { if (isset($available_subscriptions[$subscription_id])) { if (isset($members_subscriptions[$subscription_id])) { // we don't allow a member to sign up to the same subscription twice (just yet) } else { $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name']; $start_date = date('Y-m-d'); $start_modifications = module_config::c('customer_signup_subscription_start', ''); if ($start_modifications == 'hidden') { $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : ''; } if (!empty($start_modifications)) { $start_date = date('Y-m-d', strtotime($start_modifications)); } $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET "; $sql .= " owner_id = '" . (int) $owner_id . "'"; $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'"; $sql .= ", subscription_id = '" . (int) $subscription_id . "'"; $sql .= ", start_date = '{$start_date}'"; query($sql); module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true); // and the same option here to send a subscription straight away upon signup if (module_config::c('subscription_send_invoice_straight_away', 0)) { global $plugins; $plugins['subscription']->run_cron(); // check if there are any invoices for this subscription $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id); if (count($history) > 0) { foreach ($history as $h) { if ($h['invoice_id']) { $invoice_data = module_invoice::get_invoice($h['invoice_id']); if ($invoice_data['date_cancel'] != '0000-00-00') { continue; } $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>'; } } } } } } } } if (!count($subscription['subscription_name'])) { $subscription['subscription_name'][] = _l('N/A'); } if (!count($subscription['subscription_invoice'])) { $subscription['subscription_invoice'][] = _l('N/A'); } $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']); $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']); // email the admin when a customer signs up. $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription); $values['customer_name'] = $customer['customer_name']; $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id); $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true); if ($website_id) { $values['WEBSITE_LINK'] = module_website::link_open($website_id); $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true); } else { $values['WEBSITE_LINK'] = _l('N/A'); $values['WEBSITE_NAME_LINK'] = _l('N/A'); } $values['JOB_LINKS'] = ''; if (count($job_created)) { $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>'; foreach ($job_created as $job_created_id) { $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n"; } } else { $values['JOB_LINKS'] = _l('N/A'); } if (count($uploaded_files)) { $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n"; foreach ($uploaded_files as $uploaded_file) { $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n"; } } else { $values['uploaded_files'] = 'No files were uploaded'; } $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A'; if (!$creating_new) { $values['system_note'] = "Note: this signup updated the existing customer record in the system."; } else { $values['system_note'] = "Note: this signup created a new customer record in the system."; } $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin'); if (isset($_REQUEST['customer_signup_email_admin_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_admin_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_subject($template->description); $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address'))); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome'); if (isset($_REQUEST['customer_signup_email_welcome_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->customer_id = $customer_id; $email->replace_values = $values; $email->set_subject($template->description); $email->set_to('user', $customer_data['primary_user_id']); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } //todo: optional redirect to url if (isset($_REQUEST['via_ajax'])) { echo json_encode(array('success' => 1, 'customer_id' => $customer_id)); exit; } if (module_config::c('customer_signup_redirect', '')) { redirect_browser(module_config::c('customer_signup_redirect', '')); } // load up the thank you template. $template = module_template::get_template_by_key('customer_signup_thank_you_page'); $template->page_title = _l("Customer Signup"); foreach ($values as $key => $val) { if (!is_array($val)) { $values[$key] = htmlspecialchars($val); } } $template->assign_values($values); echo $template->render('pretty_html'); exit; break; } }
</th> <td> <?php echo htmlspecialchars($file['status']); ?> </td> </tr> <tr> <th> <?php echo _l('Job'); ?> </th> <td> <?php $job = module_job::get_job($file['job_id']); echo htmlspecialchars($job['name']); ?> </td> </tr> </tbody> </table> </td> <td valign="top" width="50%"> <h3><?php echo _l('File Description'); ?> </h3> <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form tableclass_full">
$current_template = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'email_template_blank'; $find_other_templates = 'email_template_'; $to = module_user::get_contacts(array('customer_id' => $customer_id)); $bcc = module_config::c('admin_email_address', ''); $headers = @unserialize($email['headers']); if ($current_template && !$email_id) { $template = module_template::get_template_by_key($current_template); //todo: replace fields. //$replace = module_invoice::get_replace_fields($invoice_id,$invoice); if ($email['customer_id']) { $customer_data = module_customer::get_customer($email['customer_id']); $replace = module_customer::get_replace_fields($email['customer_id'], false, $customer_data); $template->assign_values($replace); } if ($email['job_id']) { $job_data = module_job::get_job($email['job_id']); $replace = module_job::get_replace_fields($email['job_id'], $job_data); $template->assign_values($replace); } if ($email['website_id']) { $website_data = module_website::get_website($email['website_id']); $replace = module_website::get_replace_fields($email['website_id'], $website_data); $template->assign_values($replace); } $email['text_content'] = $template->render('html'); $email['subject'] = $template->replace_description(); } $options = array('cancel_url' => module_email::link_open(false), 'complete_url' => module_email::link_open(false), 'customer_id' => $customer_id); $options = module_email::get_email_compose_options($options); ?>
?> </td> <td> <?php if ($change_request['job_id']) { // check if this task still existing in this job. // if not we do a quick hack to remove it. $tasks = module_job::get_tasks($job_id); if (!$change_request['task_id'] || !isset($tasks[$change_request['task_id']])) { $change_request['job_id'] = 0; $change_request['task_id'] = 0; update_insert('change_request_id', $change_request['change_request_id'], 'change_request', array('job_id' => 0, 'task_id' => 0)); } } if ($change_request['job_id']) { $job_data = module_job::get_job($change_request['job_id']); echo module_job::link_open($change_request['job_id'], true, $job_data); echo ' '; $task = $tasks[$change_request['task_id']]; _e('%s hrs = %s', $task['hours'], currency($task['amount'] > 0 ? $task['amount'] : $task['hours'] * $job_data['hourly_rate']), true, $job_data['currency_id']); } else { if (module_job::can_i('edit', 'Job Tasks')) { if (count($jobs)) { echo print_select_box($jobs, 'change_request_job_id', '', '', _l('select a job'), 'name'); ?> @ <input type="text" name="add_job_hours" value="<?php echo module_config::c('change_request_job_hours', 1); ?> " class="add_job_hours" style="width:15px;"><?php _e('hrs');
public static function invoice_html($invoice_id, $invoice_data, $mode = 'html') { if ($invoice_id && $invoice_data) { // spit out the invoice html into a file, then pass it to the pdf converter // to convert it into a PDF. ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/invoice_print.php'); module_template::init_template('invoice_print', ob_get_clean(), 'Used for printing out an invoice for the customer.', 'html'); ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/invoice_print_basic.php'); module_template::init_template('invoice_print_basic', ob_get_clean(), 'Alternative template for printing out an invoice for the customer.', 'html'); ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/credit_note_pdf.php'); module_template::init_template('credit_note_pdf', ob_get_clean(), 'Used for printing out a a credit note for the customer.', 'html'); $invoice = $invoice_data; if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) { module_company::set_current_company_id($invoice_data['company_id']); } $job_data = module_job::get_job(current($invoice_data['job_ids'])); $website_data = $job_data['website_id'] ? module_website::get_website($job_data['website_id']) : array(); $website_data = array_merge($website_data, isset($invoice_data['website_id']) && $invoice_data['website_id'] ? module_website::get_website($invoice_data['website_id']) : array()); $invoice_template = isset($invoice_data['invoice_template_print']) && strlen($invoice_data['invoice_template_print']) ? $invoice_data['invoice_template_print'] : module_config::c('invoice_template_print_default', 'invoice_print'); $invoice_template_suffix = ''; if ($invoice_template != 'invoice_print') { $invoice_template_suffix = str_replace('invoice_print', '', $invoice_template); } ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/invoice_task_list.php'); $task_list_html = ob_get_clean(); ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/invoice_payment_history.php'); $payment_history = ob_get_clean(); ob_start(); include module_theme::include_ucm('includes/plugin_invoice/template/invoice_payment_methods.php'); $payment_methods = ob_get_clean(); $replace = self::get_replace_fields($invoice_id, $invoice_data); $replace['payment_history'] = $payment_history; $replace['payment_methods'] = $payment_methods; $replace['task_list'] = $task_list_html; $replace['external_invoice_template_html'] = ''; //$external_invoice_template = module_template::get_template_by_key('external_invoice'); $external_invoice_template = false; if (isset($invoice_template_suffix) && strlen($invoice_template_suffix) > 0) { $external_invoice_template = module_template::get_template_by_key('external_invoice' . $invoice_template_suffix); if (!$external_invoice_template->template_id) { $external_invoice_template = false; } } if (!$external_invoice_template) { $external_invoice_template = module_template::get_template_by_key('external_invoice'); } $external_invoice_template->assign_values($replace); $replace['external_invoice_template_html'] = $external_invoice_template->replace_content(); if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) { if ($invoice_data['invoice_template_print']) { $invoice_data['invoice_template_print'] = 'credit_note_pdf'; } $invoice_template = 'credit_note_pdf'; } ob_start(); $template = module_template::get_template_by_key($invoice_template); if (!$template || $template->template_key != $invoice_template) { echo "Invoice template {$invoice_template} not found"; } else { $template->assign_values($replace); echo $template->render('html'); } $invoice_html = ob_get_clean(); return $invoice_html; } return false; }
</li> <li> <ul class="menu"> <?php foreach ($todo_list as $todo_item) { if ($todo_item['hours_completed'] > 0) { if ($todo_item['hours'] > 0) { $percentage = round($todo_item['hours_completed'] / $todo_item['hours'], 2); $percentage = min(1, $percentage); } else { $percentage = 1; } } else { $percentage = 0; } $job_data = module_job::get_job($todo_item['job_id'], false); if ($job_data && $job_data['job_id'] == $todo_item['job_id']) { if ($job_data['customer_id']) { $customer_data = module_customer::get_customer($job_data['customer_id']); if (!$customer_data || $customer_data['customer_id'] != $job_data['customer_id']) { continue; } } else { $customer_data = array(); } ?> <li><!-- Task item --> <a href="<?php echo module_job::link_open($todo_item['job_id'], false, $job_data); ?>
echo htmlspecialchars($quote['type']); }); $columns['quote_status'] = array('title' => 'Status', 'callback' => function ($quote) { echo htmlspecialchars($quote['status']); }); if (module_config::c('quote_allow_staff_assignment', 1)) { $columns['quote_staff'] = array('title' => 'Staff Member', 'callback' => function ($quote) { echo module_user::link_open($quote['user_id'], true); }); } if (module_job::can_i('view', 'Jobs')) { $job_ids = array(); $columns['job'] = array('title' => 'Job', 'callback' => function ($quote) use(&$job_ids) { $job_ids = array(); foreach (module_job::get_jobs(array('quote_id' => $quote['quote_id'])) as $job) { $job = module_job::get_job($job['job_id']); if (!$job) { continue; } echo module_job::link_open($job['job_id'], true); $job_ids[] = $job['job_id']; echo " "; echo '<span class="'; if ($job['total_amount_due'] > 0) { echo 'error_text'; } else { echo 'success_text'; } echo '">'; if ($job['total_amount'] > 0) { echo dollar($job['total_amount'], true, $job['currency_id']);
module_template::init_template('file_approval_email', 'Dear {CUSTOMER_NAME},<br> <br> This email is regarding your file <strong>{FILE_NAME}</strong>{if:JOB_LINK} related to the job <a href="{JOB_LINK}">{JOB_NAME}</a>{endif:JOB_LINK}.<br><br> Please view this file and comments online by <a href="{FILE_URL}">clicking here</a>.<br><br> Thank you,<br><br> {FROM_NAME} ', 'File for Approval: {FILE_NAME}', array('CUSTOMER_NAME' => 'Customers Name', 'FILE_NAME' => 'File Name', 'JOB_NAME' => 'Job Name', 'FROM_NAME' => 'Your name', 'FILE_URL' => 'Link to file for customer')); // template for sending emails. // are we sending the paid one? or the dueone. //$template_name = 'file_email'; $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : 'file_approval_email'; $template = module_template::get_template_by_key($template_name); $file['from_name'] = module_security::get_loggedin_name(); $file['file_url'] = module_file::link_public($file_id); if (class_exists('module_job', false) && $file['job_id']) { $job_data = module_job::get_job($file['job_id'], false); $file['job_name'] = htmlspecialchars($job_data['name']); $file['job_link'] = module_job::link_public($file['job_id']); } else { $file['job_name'] = _l('N/A'); $file['job_link'] = ''; } // find available "to" recipients. // customer contacts. $to_select = false; if ($file['customer_id']) { $customer = module_customer::get_customer($file['customer_id']); $file['customer_name'] = $customer['customer_name']; $to = module_user::get_contacts(array('customer_id' => $file['customer_id'])); if ($customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']);
public static function get_finances($search = array()) { // we have to search for recent transactions. this involves combining the "finance" table with the "invoice_payment" table // then sort the results by date $hide_invoice_payments = false; $sql = "SELECT f.* "; $sql .= " , fa.name AS account_name "; $sql .= " , GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') AS categories "; $sql .= " FROM `" . _DB_PREFIX . "finance` f "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa USING (finance_account_id) "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category_rel` fcr ON f.finance_id = fcr.finance_id "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id "; $where = " WHERE 1 "; if (isset($search['finance_account_id']) && is_array($search['finance_account_id'])) { $fo = array(); foreach ($search['finance_account_id'] as $val) { if ((int) $val > 0) { $fo[(int) $val] = true; } } if (count($fo) > 0) { $where .= " AND ( "; foreach ($fo as $f => $ff) { $where .= " f.finance_account_id = " . $f . ' OR'; } $where = rtrim($where, 'OR'); $where .= ' )'; $hide_invoice_payments = true; } } if (isset($search['finance_recurring_id']) && $search['finance_recurring_id']) { $where .= " AND f.finance_recurring_id = '" . (int) $search['finance_recurring_id'] . "'"; $hide_invoice_payments = true; } if (isset($search['finance_category_id']) && is_array($search['finance_category_id'])) { $fo = array(); foreach ($search['finance_category_id'] as $val) { if ((int) $val > 0) { $fo[(int) $val] = true; } } if (count($fo) > 0) { $where .= " AND EXISTS ( SELECT * FROM `" . _DB_PREFIX . "finance_category_rel` fcr2 WHERE fcr2.finance_id = f.finance_id AND ( "; foreach ($fo as $f => $ff) { $where .= " fcr2.finance_category_id = " . $f . ' OR'; } $where = rtrim($where, 'OR'); $where .= ' )'; $where .= ' )'; $hide_invoice_payments = true; } } if (isset($search['invoice_payment_id']) && $search['invoice_payment_id']) { $where .= " AND f.invoice_payment_id = '" . (int) $search['invoice_payment_id'] . "'"; $hide_invoice_payments = true; } // below 6 searches are repeated again below in invoice payments if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $where .= " AND f.`job_id` = " . (int) $search['job_id']; } if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) { $where .= " AND f.`invoice_id` = " . (int) $search['invoice_id']; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND f.`customer_id` = " . (int) $search['customer_id']; } if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON f.customer_id = cc.customer_id "; $where .= " AND ( cc.`company_id` = " . (int) $search['company_id'] . " OR f.`company_id` = " . (int) $search['company_id'] . " )"; } } } if (isset($search['generic']) && strlen(trim($search['generic']))) { $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (f.`name` LIKE '%{$name}%' OR f.description LIKE '%{$name}%' )"; } if (isset($search['date_from']) && $search['date_from'] != '') { $where .= " AND f.transaction_date >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to'] != '') { $where .= " AND f.transaction_date <= '" . input_date($search['date_to']) . "'"; } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND f.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND f.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') { $where .= " AND f.type = '" . mysql_real_escape_string($search['type']) . "'"; } // permissions from job module. /*switch(module_job::get_job_access_permissions()){ case _JOB_ACCESS_ALL: break; case _JOB_ACCESS_ASSIGNED: // only assigned jobs! //$from .= " LEFT JOIN `"._DB_PREFIX."task` t ON u.job_id = t.job_id "; //u.user_id = ".(int)module_security::get_loggedin_id()." OR $where .= " AND (t.user_id = ".(int)module_security::get_loggedin_id().")"; break; case _JOB_ACCESS_CUSTOMER: break; }*/ // permissions from customer module. // tie in with customer permissions to only get jobs from customers we can access. switch (module_customer::get_customer_data_access()) { case _CUSTOMER_ACCESS_ALL: // all customers! so this means all jobs! break; case _CUSTOMER_ACCESS_ALL_COMPANY: case _CUSTOMER_ACCESS_CONTACTS: case _CUSTOMER_ACCESS_TASKS: case _CUSTOMER_ACCESS_STAFF: $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND f.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $where .= " GROUP BY f.finance_id "; $where .= " ORDER BY f.transaction_date DESC "; $sql .= $where; $finances_from_finance_db_table = qa($sql); // invoice payments: $finance_from_invoice_payments = array(); $finance_from_job_staff_expenses = array(); if (!$hide_invoice_payments && (!isset($search['invoice_id']) || !(int) $search['invoice_id'] > 0)) { $sql = "SELECT j.*, f.finance_id AS existing_finance_id "; $sql .= " FROM `" . _DB_PREFIX . "job` j "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON j.job_id = f.job_id AND f.job_staff_expense > 0 "; $where = " WHERE 1 "; //j.date_completed != '0000-00-00' "; $where .= " AND j.`c_staff_total_amount` > 0 "; if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $where .= " AND (j.`job_id` = " . (int) $search['job_id'] . " ) "; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND j.`customer_id` = " . (int) $search['customer_id']; } /*if(isset($search['generic']) && strlen(trim($search['generic']))){ $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; }*/ if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON j.customer_id = cc.customer_id "; $where .= " AND cc.`company_id` = " . (int) $search['company_id']; } } } if (isset($search['date_from']) && $search['date_from'] != '') { $where .= " AND j.date_completed >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to'] != '') { $where .= " AND j.date_completed <= '" . input_date($search['date_to']) . "'"; } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND j.c_staff_total_amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND j.c_staff_total_amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } switch (module_job::get_job_access_permissions()) { case _JOB_ACCESS_ALL: break; case _JOB_ACCESS_ASSIGNED: // only assigned jobs! $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON j.job_id = t.job_id "; $where .= " AND (j.user_id = " . (int) module_security::get_loggedin_id() . " OR t.user_id = " . (int) module_security::get_loggedin_id() . ")"; break; case _JOB_ACCESS_CUSTOMER: // tie in with customer permissions to only get jobs from customers we can access. $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND j.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } break; } switch (module_customer::get_customer_data_access()) { case _CUSTOMER_ACCESS_ALL: // all customers! so this means all jobs! break; case _CUSTOMER_ACCESS_ALL_COMPANY: case _CUSTOMER_ACCESS_CONTACTS: case _CUSTOMER_ACCESS_TASKS: case _CUSTOMER_ACCESS_STAFF: $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND j.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $sql .= $where . " GROUP BY j.job_id ORDER BY j.date_completed DESC "; //echo $sql; $finance_from_job_staff_expenses = array(); $res = qa($sql); foreach ($res as $finance) { // we have a job with staff expenses. split this up into gruops based on staff members. $staff_total_grouped = false; if (isset($finance['c_staff_total_grouped']) && strlen($finance['c_staff_total_grouped'])) { $staff_total_grouped = @unserialize($finance['c_staff_total_grouped']); } if ($staff_total_grouped === false) { // echo 'here: '; // var_dump($finance); // var_dump($staff_total_grouped); $job_data = module_job::get_job($finance['job_id']); $staff_total_grouped = $job_data['staff_total_grouped']; } if (is_array($staff_total_grouped)) { foreach ($staff_total_grouped as $staff_id => $staff_total) { $staff_member = module_user::get_user($staff_id); if ($staff_member && $staff_member['user_id'] == $staff_id) { // make sure this entry doesn't already exist in the database table for this job // there MAY be an existing entry if 'existing_finance_id' is set if ($finance['existing_finance_id'] > 0) { // check if it exists for this staff member. $existing = get_single('finance', array('job_id', 'job_staff_expense', 'amount'), array($finance['job_id'], $staff_id, $staff_total)); if ($existing) { // match exists already, skip adding this one to the list. continue; } } //$finance = self::_format_invoice_payment($finance, $finance); //$finance['url'] = module_job::link_open($finance['job_id'],false,$finance); $finance['url'] = module_finance::link_open('new', false) . '&job_staff_expense=' . $staff_id . '&from_job_id=' . $finance['job_id']; $finance['transaction_date'] = $finance['date_completed']; $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']); //"Exiting: ".$finance['existing_finance_id'].": ". $finance['amount'] = $staff_total; $finance['debit'] = $staff_total; $finance['sub_amount'] = $staff_total; $finance['taxable_amount'] = $staff_total; $finance['credit'] = 0; $finance['type'] = 'e'; $finance_from_job_staff_expenses[] = $finance; } } } } } if (!$hide_invoice_payments) { $sql = "SELECT p.*, i.customer_id "; if (module_config::c('finance_date_type', 'payment') == 'invoice') { // show entries by invoice create date, not payment date. $sql .= " , i.date_create AS transaction_date "; } else { // default, show by paid date. $sql .= " , p.date_paid AS transaction_date "; } $sql .= " FROM `" . _DB_PREFIX . "invoice_payment` p "; $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON p.invoice_id = i.invoice_id "; $where = " WHERE p.date_paid != '0000-00-00' "; $where .= " AND p.`amount` != 0 "; $where .= " AND ( p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_NORMAL . " OR p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_REFUND . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_CREDIT . ')'; if (isset($search['job_id']) && (int) $search['job_id'] > 0) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id"; $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id"; $where .= " AND (t.`job_id` = " . (int) $search['job_id'] . " OR i.`deposit_job_id` = " . (int) $search['job_id'] . " ) "; } if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) { $where .= " AND p.`invoice_id` = " . (int) $search['invoice_id']; } if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) { $where .= " AND i.`customer_id` = " . (int) $search['customer_id']; } /*if(isset($search['generic']) && strlen(trim($search['generic']))){ $name = mysql_real_escape_string(trim($search['generic'])); $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; }*/ if (isset($search['company_id']) && (int) $search['company_id'] > 0) { // check this user can view this company id or not if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) { $companys = module_company::get_companys(); if (isset($companys[$search['company_id']])) { $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON i.customer_id = cc.customer_id "; $where .= " AND cc.`company_id` = " . (int) $search['company_id']; } } } if (isset($search['date_from']) && $search['date_from'] != '') { if (module_config::c('finance_date_type', 'payment') == 'invoice') { $where .= " AND i.date_create >= '" . input_date($search['date_from']) . "'"; } else { $where .= " AND p.date_paid >= '" . input_date($search['date_from']) . "'"; } } if (isset($search['date_to']) && $search['date_to'] != '') { if (module_config::c('finance_date_type', 'payment') == 'invoice') { $where .= " AND i.date_create <= '" . input_date($search['date_to']) . "'"; } else { $where .= " AND p.date_paid <= '" . input_date($search['date_to']) . "'"; } } if (isset($search['amount_from']) && $search['amount_from'] != '') { $where .= " AND p.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'"; } if (isset($search['amount_to']) && $search['amount_to'] != '') { $where .= " AND p.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'"; } if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') { if ($search['type'] == 'i') { $where .= " AND p.amount > 0"; } else { if ($search['type'] == 'e') { $where .= " AND p.amount < 0"; } } } switch (module_customer::get_customer_data_access()) { case _CUSTOMER_ACCESS_ALL: // all customers! so this means all jobs! break; case _CUSTOMER_ACCESS_ALL_COMPANY: case _CUSTOMER_ACCESS_CONTACTS: case _CUSTOMER_ACCESS_TASKS: case _CUSTOMER_ACCESS_STAFF: $valid_customer_ids = module_security::get_customer_restrictions(); if (count($valid_customer_ids)) { $where .= " AND i.customer_id IN ( "; foreach ($valid_customer_ids as $valid_customer_id) { $where .= (int) $valid_customer_id . ", "; } $where = rtrim($where, ', '); $where .= " )"; } } $sql .= $where . " ORDER BY p.date_paid DESC "; //echo $sql; $finance_from_invoice_payments = qa($sql); foreach ($finance_from_invoice_payments as $finance_id => $finance) { // doesn't have an finance / account reference just yet. // but they can create one and this will become a child entry to it. $finance = self::_format_invoice_payment($finance, $finance); /*if(!isset($finance['customer_id']) || !$finance['customer_id']){ $invoice_data = module_invoice::get_invoice($finance['invoice_id'],2); $finance['customer_id'] = $invoice_data['customer_id']; }*/ // grab a new name/descriptino/etc.. from other plugins (at the moment only subscription) /*$new_finance = hook_handle_callback('finance_invoice_listing',$finance['invoice_id'],$finance); if(is_array($new_finance) && count($new_finance)){ foreach($new_finance as $n){ $finance = array_merge($finance,$n); } }*/ $finance_from_invoice_payments[$finance_id] = $finance; } if (isset($search['generic']) && strlen(trim($search['generic']))) { $name = mysql_real_escape_string(trim($search['generic'])); // $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )"; // we have to do a PHP search here because foreach ($finance_from_invoice_payments as $finance_id => $finance) { if (stripos($finance['name'], $name) === false && stripos($finance['description'], $name) === false) { unset($finance_from_invoice_payments[$finance_id]); } } } } $finances = array_merge($finances_from_finance_db_table, $finance_from_invoice_payments, $finance_from_job_staff_expenses); unset($finances_from_finance_db_table); unset($finance_from_invoice_payments); unset($finance_from_job_staff_expenses); // sort this if (!function_exists('sort_finance')) { function sort_finance($a, $b) { $t1 = strtotime($a['transaction_date']); $t2 = strtotime($b['transaction_date']); if ($t1 == $t2) { // sort by finance id, putting ones with a finance id first before others. then amount. if (isset($a['finance_id']) && !isset($b['finance_id'])) { // put $a before $b return -1; } else { if (!isset($a['finance_id']) && isset($b['finance_id'])) { // put $b before $a return 1; } else { return $a['amount'] > $b['amount']; } } } else { return $t1 < $t2; } } } uasort($finances, 'sort_finance'); foreach ($finances as $finance_id => $finance) { // we load each of these transactions // transaction can be a "transaction" or an "invoice_payment" // find out if this transaction is a child transaction to another transaction. // if it is a child transaction and we haven't already dispayed it in this listing // then we find the parent transaction and display it along with all it's children in this place. // this wont be perfect all the time but will be awesome in 99% of cases. if (isset($finance['finance_id']) && $finance['finance_id']) { // displayed before already? if (isset($displayed_finance_ids[$finance['finance_id']])) { $finances[$displayed_finance_ids[$finance['finance_id']]]['link_count']++; unset($finances[$finance_id]); continue; } $displayed_finance_ids[$finance['finance_id']] = $finance_id; if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id']) { $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id; // so we dont display again. } } else { if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']) { // this is an invoice payment (incoming payment) // displayed before already? if (isset($displayed_invoice_payment_ids[$finance['invoice_payment_id']])) { $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]] = array_merge($finance, $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]); $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]['link_count']++; unset($finances[$finance_id]); continue; } $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id; // so we dont display again. } else { if (isset($finance['c_staff_total_amount'])) { // staff expense. } else { // nfi? unset($finances[$finance_id]); continue; } } } if (isset($finance['parent_finance_id']) && $finance['parent_finance_id']) { // check if it's parent finance id has been displayed already somewhere. if (isset($displayed_finance_ids[$finance['parent_finance_id']])) { $finances[$displayed_finance_ids[$finance['parent_finance_id']]]['link_count']++; unset($finances[$finance_id]); continue; // already done it on this page. } $displayed_finance_ids[$finance['parent_finance_id']] = $finance_id; // we haven't displayed the parent one yet. // display the parent one in this listing. $finance = self::get_finance($finance['parent_finance_id']); } /*if(isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']){ // moved to above. }else*/ if (isset($finance['finance_id']) && $finance['finance_id']) { $finance['url'] = self::link_open($finance['finance_id'], false); $finance['credit'] = $finance['type'] == 'i' ? $finance['amount'] : 0; $finance['debit'] = $finance['type'] == 'e' ? $finance['amount'] : 0; if (!isset($finance['categories'])) { $finance['categories'] = ''; } if (!isset($finance['account_name'])) { $finance['account_name'] = ''; } } if (isset($finance['taxes']) && !isset($finance['sub_amount'])) { $finance['sub_amount'] = $finance['amount']; foreach ($finance['taxes'] as $tax) { if (isset($tax['amount'])) { $finance['sub_amount'] -= $tax['amount']; } } } $finance['link_count'] = 0; $finances[$finance_id] = $finance; } return $finances; }
if ($file['customer_id'] && !isset($c[$file['customer_id']])) { // this file is related to another job. from another customer. $related_customer = module_customer::get_customer($file['customer_id'], true); $c[$file['customer_id']] = $related_customer['customer_name']; } $fieldset_data['elements'][] = array('title' => 'Customer', 'field' => array('type' => 'select', 'name' => 'customer_id', 'value' => $file['customer_id'], 'options' => $c)); } if (class_exists('module_job', false) && class_exists('module_customer', false)) { $c = array(); $res = module_job::get_jobs(array('customer_id' => $file['customer_id'])); foreach ($res as $row) { $c[$row['job_id']] = $row['name']; } if ($file['job_id'] && !isset($c[$file['job_id']])) { // this file is related to another job. from another customer. $related_job = module_job::get_job($file['job_id'], false, true); if ($related_job && $related_job['job_id'] == $file['job_id']) { $related_customer = module_customer::get_customer($related_job['customer_id'], true); if ($related_customer && $related_customer['customer_id'] == $related_job['customer_id']) { $c[$file['job_id']] = _l('%s (from %s)', $related_job['name'], $related_customer['customer_name']); } else { $file['job_id'] = false; } } else { $file['job_id'] = false; } } $fieldset_data['elements'][] = array('title' => 'Job', 'fields' => array(array('type' => 'select', 'name' => 'job_id', 'value' => $file['job_id'], 'options' => $c), function () use(&$file) { if ($file['job_id']) { echo ' '; echo '<a href="' . module_job::link_open($file['job_id'], false) . '">' . _l('Open Job »') . '</a>';
function handle_hook($hook, $calling_module = false, $owner_table = false, $key_name = false, $key_value = false, $rel_data = false) { switch ($hook) { case "home_alerts": $alerts = array(); if (module_config::c('allow_note_reminders', 1)) { // find any jobs that are past the due date and dont have a finished date. $key = _l('Note Reminder'); if (class_exists('module_dashboard', false)) { module_dashboard::register_group($key, array('columns' => array('name' => _l('Reminder'), 'type' => _l('Type'), 'full_link' => _l('Link'), 'date' => _l('Date'), 'days' => _l('Date')))); } $sql = "SELECT * FROM `" . _DB_PREFIX . "note` n "; $sql .= " WHERE n.`reminder` = 1 AND n.note_time < " . (int) strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days') . ""; $sql .= " AND ( n.`user_id` = 0 OR n.`user_id` = " . module_security::get_loggedin_id() . ")"; $sql .= " ORDER BY n.note_time ASC"; $tasks = qa($sql); foreach ($tasks as $task) { $alert_res = process_alert(date('Y-m-d', $task['note_time']), $key); if ($alert_res) { $alert_res['link'] = $task['rel_data']; // fix for linking when changing folder. $alert_res['type'] = _l(ucwords($task['owner_table'])); switch ($task['owner_table']) { case 'user': $user = module_user::get_user($task['owner_id']); if ($user['customer_id'] || $user['vendor_id']) { $alert_res['link'] = module_user::link_open_contact($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open_contact($task['owner_id'], true, $user); $alert_res['type'] = _l('Contact'); } else { $alert_res['link'] = module_user::link_open($task['owner_id'], false, $user); $alert_res['full_link'] = module_user::link_open($task['owner_id'], true, $user); } break; case 'invoice': $invoice_data = module_invoice::get_invoice($task['owner_id'], true); if (!$invoice_data || !isset($invoice_data['invoice_id']) || $invoice_data['invoice_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_invoice::link_open($task['owner_id'], false, $invoice_data); $alert_res['full_link'] = module_invoice::link_open($task['owner_id'], true, $invoice_data); break; case 'quote': $quote_data = module_quote::get_quote($task['owner_id'], true); if (!$quote_data || !isset($quote_data['quote_id']) || $quote_data['quote_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_quote::link_open($task['owner_id'], false, $quote_data); $alert_res['full_link'] = module_quote::link_open($task['owner_id'], true, $quote_data); break; case 'website': $website_data = module_website::get_website($task['owner_id']); if (!$website_data || !isset($website_data['website_id']) || $website_data['website_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_website::link_open($task['owner_id'], false); $alert_res['full_link'] = module_website::link_open($task['owner_id'], true); break; case 'customer': $customer_data = module_customer::get_customer($task['owner_id']); if (!$customer_data || !isset($customer_data['customer_id']) || $customer_data['customer_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_customer::link_open($task['owner_id'], false, $customer_data); $alert_res['full_link'] = module_customer::link_open($task['owner_id'], true, $customer_data); break; case 'vendor': $vendor_data = module_vendor::get_vendor($task['owner_id']); if (!$vendor_data || !isset($vendor_data['vendor_id']) || $vendor_data['vendor_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_vendor::link_open($task['owner_id'], false, $vendor_data); $alert_res['full_link'] = module_vendor::link_open($task['owner_id'], true, $vendor_data); break; case 'job': $job_data = module_job::get_job($task['owner_id']); if (!$job_data || !isset($job_data['job_id']) || $job_data['job_id'] != $task['owner_id']) { continue 2; } $alert_res['link'] = module_job::link_open($task['owner_id'], false, $job_data); $alert_res['full_link'] = module_job::link_open($task['owner_id'], true, $job_data); break; // todo - add others. } $alert_res['name'] = $task['note']; $alert_res['date'] = print_date($alert_res['date']); $alert_res['time'] = $task['note_time']; $alerts[] = $alert_res; } } } return $alerts; break; /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ /*case "note_list": if($owner_id && $owner_id != 'new'){ $note_items = $this->get_notes(array("owner_table"=>$owner_table,"owner_id"=>$owner_id)); foreach($note_items as &$note_item){ // do it in loop here because of $this issues in static method below. // instead of include file below. $note_item['html'] = $this->print_note($note_item['note_id']); } include("pages/note_list.php"); }else{ echo 'Please save first before creating notes.'; } break;*/ case "note_delete": // find the key we are saving this address against. $owner_id = (int) $key_value; if (!$owner_id || $owner_id == 'new') { // find one in the post data. if (isset($_REQUEST[$key_name])) { $owner_id = $_REQUEST[$key_name]; } } $note_hash = md5($owner_id . '|' . $owner_table); // just for posting unique arrays. if ($owner_table && $owner_id) { $this->note_delete($owner_table, $owner_id); } break; } }
echo _l('Job Total'); ?> </th> <th><?php echo _l('Invoice'); ?> </th> </tr> </thead> <tbody> <?php $c = 0; foreach ($pagination['rows'] as $job_original) { // print_r(array_keys($job_original)); //echo $job_original['website_name']; $job = module_job::get_job($job_original['job_id']); ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td class="row_action"> <?php echo module_job::link_open($job['job_id'], true); ?> </td> <td> <?php echo print_date($job['date_start']);