$search['bucket_parent_file_id'] = $file['file_id']; echo _l('%s files', count(module_file::get_files($search))); } else { if (file_exists($file['file_path'])) { echo module_file::format_bytes(filesize($file['file_path'])); } } }); if (!isset($_REQUEST['customer_id'])) { $columns['file_customer'] = array('title' => 'Customer', 'callback' => function ($file) { echo module_customer::link_open($file['customer_id'], true); }); } if (class_exists('module_job', false)) { $columns['file_job'] = array('title' => 'Job', 'callback' => function ($file) { echo module_job::link_open($file['job_id'], true); }); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) { $columns['file_quote'] = array('title' => 'Quote', 'callback' => function ($file) { echo module_quote::link_open($file['quote_id'], true); }); } $columns['file_date_added'] = array('title' => 'Date Added', 'callback' => function ($file) { echo _l('%s by %s', print_date($file['date_created']), module_user::link_open($file['create_user_id'], true)); }); if (module_file::can_i('edit', 'Files')) { $columns['file_action'] = array('title' => ' ', 'callback' => function ($file) { echo '<input type="checkbox" name="bulk_operation[' . $file['file_id'] . ']" value="yes">'; }); }
public function run_cron($debug = false) { // we only want to perform these cron actions if we're after a certain time of day // because we dont want to be generating these renewals and sending them at midnight, can get confusing $after_time = module_config::c('invoice_automatic_after_time', 7); $time_of_day = date('G'); if ($time_of_day < $after_time) { if ($debug) { echo "Not performing automatic invoice operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n"; } return; } // find automatic job renewals $sql = "SELECT p.* FROM `" . _DB_PREFIX . "job` p "; $sql .= " WHERE p.date_renew != '0000-00-00'"; $sql .= " AND p.date_start != '0000-00-00'"; $sql .= " AND p.date_renew <= '" . date('Y-m-d') . "'"; $sql .= " AND (p.renew_job_id IS NULL OR p.renew_job_id = 0)"; $sql .= " AND (p.renew_auto = 1)"; $renew_jobs = qa($sql); foreach ($renew_jobs as $renew_job) { // time to automatically renew this job! woo! if ($debug) { echo "Automatically Renewing Job " . module_job::link_open($renew_job['job_id'], true) . "<br>\n"; } //$job_details = $this->get_job($renew_job['job_id']); $job_invoices = module_invoice::get_invoices(array('job_id' => $renew_job['job_id'])); $unpaid_invoice = false; foreach ($job_invoices as $job_invoice) { $job_invoice = module_invoice::get_invoice($job_invoice['invoice_id']); if ($job_invoice['total_amount_due'] > 0) { $unpaid_invoice = true; } } if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $unpaid_invoice) { if ($debug) { echo "Not automatically renewing this job because it has unpaid invoices. <br>\n"; } } else { $new_job_id = $this->renew_job($renew_job['job_id'], true); if ($new_job_id) { //module_cache::clear_cache(); if ($debug) { echo "Job Automatically Renewed: " . module_job::link_open($new_job_id, true) . "<br>\n"; } if ($renew_job['renew_invoice']) { // we want to tick all these tasks off and invoice this job, then send this invoice to the customer. $job_tasks = module_job::get_tasks($new_job_id); foreach ($job_tasks as $job_task_id => $job_task) { $job_tasks[$job_task_id]['fully_completed_t'] = 1; $job_tasks[$job_task_id]['fully_completed'] = 1; } $this->save_job_tasks($new_job_id, array('job_task' => $job_tasks)); //module_cache::clear_cache(); // generate an invoice for this job. $_REQUEST['job_id'] = $new_job_id; $new_invoice = module_invoice::get_invoice('new'); $new_invoice['date_create'] = $renew_job['date_renew']; $new_invoice['invoice_invoice_item'] = module_invoice::get_invoice_items('new', $new_invoice); $new_invoice_id = module_invoice::save_invoice('new', $new_invoice); //module_cache::clear_cache(); if ($debug) { echo "Generated new invoice for renewed job: " . module_invoice::link_open($new_invoice_id, true) . "<br/>"; } if ($debug) { echo "Emailing invoice to customer..."; } if (module_invoice::email_invoice_to_customer($new_invoice_id)) { if ($debug) { echo "send successfully"; } } else { if ($debug) { echo "send failed"; } } if ($debug) { echo "<br>\n"; } } } } } }
}, array('type' => 'html', 'value' => '', 'help' => 'Here you can apply a before tax discount to this job. You can name this anything, eg: DISCOUNT, CREDIT, REFUND, etc..'))); $fieldset_data['elements'][] = array('title' => 'Discount Name', 'fields' => array(function () use($job_id, &$job) { echo !module_security::is_page_editable() ? htmlspecialchars(_l($job['discount_description'])) : '<input type="text" name="discount_description" value="' . htmlspecialchars(_l($job['discount_description'])) . '" style="width:80px;">'; })); $fieldset_data['elements'][] = array('title' => 'Discount Type', 'field' => array('type' => 'select', 'options' => array('0' => _l('Before Tax'), 1 => _l('After Tax')), 'name' => 'discount_type', 'value' => $job['discount_type'])); if (class_exists('module_job_discussion', false) && isset($job['job_discussion']) && module_job_discussion::is_plugin_enabled()) { $fieldset_data['elements'][] = array('title' => 'Job Discussion', 'field' => array('type' => 'select', 'options' => array(0 => _l('Allowed'), 1 => _l('Disabled & Hidden'), 2 => _l('Disabled & Shown')), 'name' => 'job_discussion', 'value' => isset($job['job_discussion']) ? $job['job_discussion'] : 0)); } if ((int) $job_id > 0 && module_invoice::can_i('create', 'Invoices')) { $fieldset_data['elements'][] = array('title' => 'Job Deposit', 'fields' => array(array('type' => 'currency', 'name' => 'job_deposit', 'value' => ''), array('type' => 'submit', 'name' => 'butt_create_deposit', 'value' => 'Create Deposit Invoice', 'class' => 'exit_button small_button', 'help' => 'Enter a dollar value here to create a deposit invoice for this job. Also supports entering a percentage (eg: 20%%)'))); } $fieldset_data['elements'][] = array('title' => 'Job Completed', 'fields' => array(array('type' => 'text', 'name' => 'total_percent_complete_override', 'value' => $job['total_percent_complete_manual'] ? $job['total_percent_complete'] * 100 : '', 'style' => 'width:30px;'), '%', $job['total_percent_complete_manual'] ? _l('(calculated: %s%%)', $job['total_percent_complete_calculated'] * 100) : '', array('type' => 'html', 'value' => '', 'help' => 'Enter a manual job "percent completed" here and this will be used instead of the automatically calculated value.'))); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); } $form_actions = array('class' => 'action_bar action_bar_left', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'onclick' => "\$('#form_redirect').val('" . module_job::link_open(false) . "');", 'value' => _l('Save and Return')), array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save Job')), array('ignore' => !((int) $job_id && module_job::can_i('delete', 'Jobs')), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . module_job::link_open(false) . "';"))); echo module_form::generate_form_actions($form_actions); ?> </form> <?php if ($do_perm_finish_check) { // we call our permission check // render finish method here instead of in index.php // this allows job task edit permissions without job edit permissions. // HOPE THIS WORKS! :) module_security::render_page_finished(); } hook_handle_callback('layout_column_half', 2, '65');
?> </div> <?php $fieldset_data = array('heading' => array('title' => _l('Quote Jobs'), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); } if ($quote['date_approved'] != '0000-00-00' && module_job::can_i('create', 'Jobs') && (!count($jobs) || module_config::c('quote_allow_multi_jobs', 0))) { ob_start(); ?> <div class="tableclass_form content"> <div style="text-align: center"> <?php $form_actions = array('class' => 'custom_actions action_bar_single', 'elements' => array(array('type' => 'button', 'name' => 'butt_convert_to_job', 'value' => _l('Convert this Quote into a Job'), 'onclick' => "window.location.href='" . module_job::link_open('new', false) . "&from_quote_id={$quote_id}'; return false;"))); echo module_form::generate_form_actions($form_actions); ?> </div> </div> <?php $fieldset_data = array('heading' => array('title' => _l('Quote Has Been Approved'), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); } if ($quote['date_approved'] == '0000-00-00') { ob_start(); ?> <div class="tableclass_form content">
<td><?php if ($finance['invoice_id']) { $invoice_data = module_invoice::get_invoice($finance['invoice_id']); echo module_invoice::link_open($finance['invoice_id'], true, $invoice_data); } else { _e('N/A'); } ?> </td> <td><?php if (isset($finance['job_id']) && $finance['job_id']) { echo module_job::link_open($finance['job_id'], true); } else { if ($finance['invoice_id'] && count($invoice_data['job_ids'])) { foreach ($invoice_data['job_ids'] as $job_id) { echo module_job::link_open($job_id, true) . ' '; } } else { _e('N/A'); } } ?> </td> <?php foreach ($currencies as $currency_id) { $currency = get_single('currency', 'currency_id', $currency_id); if (!isset($search['type']) || $search['type'] == 'ie' || $search['type'] == 'i') { ?> <td> <?php
}); 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']); } echo '</span>'; echo "<br>"; }
</tbody> </table> </div> <?php $fieldset_data = array('heading' => array('title' => _l('Invoice Payment History'), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); if (class_exists('module_finance', false) && module_finance::is_plugin_enabled() && module_finance::can_i('view', 'Finance') && module_finance::is_enabled() && is_file('includes/plugin_finance/pages/finance_invoice_edit.php') && module_config::c('invoice_show_finances', 1)) { include 'includes/plugin_finance/pages/finance_invoice_edit.php'; } } // invoice_id check hook_handle_callback('layout_column_half', 'end'); $form_actions = array('class' => 'action_bar action_bar_left', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'onclick' => "\$('#form_redirect').val('" . (!$invoice_id && isset($_REQUEST['job_id']) && (int) $_REQUEST['job_id'] > 0 ? module_job::link_open($_REQUEST['job_id']) : module_invoice::link_open(false)) . "');", 'value' => _l('Save and Return')), array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save')))); if ((int) $invoice_id) { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $form_actions['elements'][] = array('type' => 'save_button', 'class' => 'submit_button', 'name' => 'butt_email', 'value' => _l('Email Receipt')); } else { $form_actions['elements'][] = array('type' => 'submit', 'class' => 'submit_button', 'name' => 'butt_email', 'value' => _l('Email Invoice')); } if (function_exists('convert_html2pdf')) { if (!module_invoice::can_i('edit', 'Invoices')) { $form_actions['elements'][] = array('type' => 'button', 'class' => 'submit_button no_permissions', 'name' => 'butt_print', 'value' => _l('Print PDF'), 'onclick' => "window.location.href='" . module_invoice::link_public_print($invoice_id) . "';"); } else { $form_actions['elements'][] = array('type' => 'submit', 'class' => 'submit_button', 'name' => 'butt_print', 'value' => _l('Print PDF')); } } } if ((int) $invoice_id && module_invoice::can_i('delete', 'Invoices')) {
?> </a> </td> <?php if ($display_mode != 'mobile') { ?> <td width="5%"> <?php echo $percentage * 100; ?> % </td> <td> <?php echo module_job::link_open($todo_item['job_id'], true, $job_data); ?> </td> <td width="16%"> <?php $alert = process_alert($todo_item['date_due'], 'temp'); ?> <?php echo $alert['warning'] ? '<span class="important">' : ''; ?> <?php echo $alert['days']; ?>
?> </span> </div> </div> </a> </li><!-- end task item --> <?php } } ?> </ul> </li> <li class="footer"> <a href="<?php echo module_job::link_open(false); ?> "><?php _e('View All Jobs'); ?> </a> </li> </ul> </li> <?php } $job_todo_cache = ob_get_clean(); echo $job_todo_cache; module_cache::put('job', 'job_todo_header_cache', $job_todo_cache); } }
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; } }
<?php if (isset($r['job_id']) && $r['job_id']) { ?> <a href="<?php echo module_job::link_open($r['job_id']); ?> "><?php echo $foo; ?> </a> <?php } else { if (isset($r['job_ids']) && is_array($r['job_ids'])) { foreach ($r['job_ids'] as $job_id) { ?> <a href="<?php echo module_job::link_open($job_id); ?> "><?php echo $foo; ?> </a> <?php } } } ?> </td> <td> <?php echo $hours_logged; if ($hours_logged != $r['hours']) {
<tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <?php if (isset($_REQUEST['view_all'])) { ?> <td><?php foreach ($module->get_data_link_keys() as $key) { if (isset($data[$key]) && (int) $data[$key] > 0) { switch ($key) { case 'customer_id': echo module_customer::link_open($data[$key], true); break; case 'job_id': echo module_job::link_open($data[$key], true); break; case 'invoice_id': echo module_invoice::link_open($data[$key], true); break; case 'quote_id': echo module_quote::link_open($data[$key], true); break; case 'file_id': echo module_file::link_open($data[$key], true); break; } } } ?> </td>
if (module_config::c('job_staff_email_skip_complete', 0) && $job_task['fully_completed']) { continue; } $job['job_tasks'] .= '<li><strong>' . $job_task['description'] . '</strong>'; if ($job_task['fully_completed']) { $job['job_tasks'] .= ' <span style="color: #99cc00; font-weight:bold;">(' . _l('complete') . ')</span>'; } $job['job_tasks'] .= ' <br/>'; if ($job_task['long_description']) { $job['job_tasks'] .= _l('Notes:') . ' <em>' . $job_task['long_description'] . '</em><br/>'; } if ($job_task['date_due'] && $job_task['date_due'] != '0000-00-00') { $job['job_tasks'] .= _l('Date Due:') . ' ' . print_date($job_task['date_due']) . '<br/>'; } if ($job_task['hours']) { $job['job_tasks'] .= _l('Assigned Hours:') . ' ' . $job_task['hours'] . '<br/>'; } if ($job_task['completed']) { $job['job_tasks'] .= _l('Completed Hours:') . ' ' . $job_task['completed'] . '<br/>'; } $job['job_tasks'] .= '</li>'; $job['task_count']++; } $job['job_tasks'] .= '</ul>'; // find available "to" recipients. // customer contacts. $to = array(); $to[] = array('name' => $staff['name'], 'email' => $staff['email']); $template->assign_values($job); module_email::print_compose(array('title' => _l('Email Job: %s', $job['name']), 'find_other_templates' => 'job_staff_email', 'current_template' => $template_name, 'job_id' => $job['job_id'], 'debug_message' => 'Sending job to staff', 'to' => $to, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_job::link_open($job_id), 'cancel_url' => module_job::link_open($job_id)));
</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'); ?>
</tr> <?php } } ?> </tr> </tbody> </table> <?php $fieldset_data = array('heading' => array('title' => _l('Advanced'), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data); unset($fieldset_data); } $form_actions = array('class' => 'action_bar action_bar_left', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save Job')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . module_job::link_open(false) . "';"))); echo module_form::generate_form_actions($form_actions); hook_handle_callback('layout_column_half', 2, '65'); if (module_job::can_i('edit', 'Job Tasks') || module_job::can_i('view', 'Job Tasks')) { $header = array('title_final' => _l('Job Tasks %s', ''), 'button' => array(), 'type' => 'h3'); ob_start(); ?> <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_rows tableclass_full"> <thead> <tr> <?php if (module_config::c('job_show_task_numbers', 1)) { ?>
echo $invoice_item_id; ?> "> <br/> <textarea name="invoice_invoice_item[<?php echo $invoice_item_id; ?> ][long_description]" style="width:90%;"><?php echo htmlspecialchars($invoice_item_data['custom_long_description'] ? $invoice_item_data['custom_long_description'] : $invoice_item_data['long_description']); ?> </textarea> <?php if ($invoice_item_data['task_id']) { // echo htmlspecialchars($invoice_item_data['custom_description'] ? $invoice_item_data['custom_description'] : $invoice_item_data['description']); echo '<br/>'; echo _l('(linked to job: %s)', module_job::link_open($invoice_item_data['job_id'], true)); } else { } ?> <a href="#" onclick="if(confirm('<?php _e('Delete invoice item?'); ?> ')){$(this).parent().find('input').val(''); $('#invoice_form')[0].submit();} return false;" class="delete ui-state-default ui-corner-all ui-icon ui-icon-trash" style="display:inline-block; float:right;">[x]</a> </td> <?php if ($show_task_dates) { ?> <td> <input type="text" name="invoice_invoice_item[<?php
public function process() { $errors = array(); if ($_REQUEST['_process'] == 'make_payment') { $this->handle_payment(); } else { if (isset($_REQUEST['butt_del']) && $_REQUEST['butt_del'] && $_REQUEST['invoice_id'] && module_invoice::can_i('delete', 'Invoices')) { $data = self::get_invoice($_REQUEST['invoice_id']); if (module_form::confirm_delete('invoice_id', _l("Really delete invoice: %s", htmlspecialchars($data['name'])), self::link_open($_REQUEST['invoice_id']))) { $invoice_data = self::get_invoice($_REQUEST['invoice_id'], true); $this->delete_invoice($_REQUEST['invoice_id']); set_message("Invoice deleted successfully"); if (isset($invoice_data['job_ids']) && $invoice_data['job_ids']) { redirect_browser(module_job::link_open(current($invoice_data['job_ids']))); } else { redirect_browser(self::link_open(false)); } } } else { if ("assign_credit_to_customer" == $_REQUEST['_process']) { $invoice_id = (int) $_REQUEST['invoice_id']; if ($invoice_id > 0) { $invoice_data = $this->get_invoice($invoice_id); $credit = $invoice_data['total_amount_credit']; if ($credit > 0) { if ($invoice_data['customer_id']) { // assign to customer. module_customer::add_credit($invoice_data['customer_id'], $credit); // assign this as a negative payment, and also give it to the customer account. $this->add_history($invoice_id, 'Added ' . dollar($credit) . ' credit to customers account from this invoice overpayment'); update_insert('invoice_payment_id', 'new', 'invoice_payment', array('invoice_id' => $invoice_id, 'amount' => -$credit, 'payment_type' => _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT, 'currency_id' => $invoice_data['currency_id'], 'method' => _l('Assigning Credit'), 'date_paid' => date('Y-m-d'))); module_cache::clear('invoice'); } } redirect_browser($this->link_open($invoice_id)); } } else { if ("save_invoice" == $_REQUEST['_process']) { $invoice_id = isset($_REQUEST['invoice_id']) ? (int) $_REQUEST['invoice_id'] : false; // check the user has permissions to edit this page. if ($invoice_id > 0) { $invoice = $this->get_invoice($invoice_id); if (!module_security::can_access_data('invoice', $invoice, $invoice_id)) { echo 'Data access denied. Sorry.'; exit; } } if (!$this->can_i('edit', 'Invoices')) { // bug fix, customer making a payment displays this edit access denied. if (isset($_REQUEST['butt_makepayment']) && $_REQUEST['butt_makepayment'] == 'yes') { //redirect_browser(self::link_public_pay($invoice_id)); self::handle_payment(); return; } else { echo 'Edit access denied. Sorry.'; exit; } } $data = $_POST; if (isset($data['default_renew_auto']) && !isset($data['renew_auto'])) { $data['renew_auto'] = 0; } if (isset($data['default_renew_email']) && !isset($data['renew_email'])) { $data['renew_email'] = 0; } if (isset($data['default_overdue_email_auto']) && !isset($data['overdue_email_auto'])) { $data['overdue_email_auto'] = 0; } if (isset($data['set_manual_company_id'])) { $data['company_id'] = $data['set_manual_company_id']; } if (isset($data['customer_id']) && $data['customer_id'] && (!isset($data['user_id']) || !$data['user_id'])) { // find the primary contact for this invoice and set that there? // no - we don't! we leave it as blank so we can update the customer primary contact when needed. /* $customer_data = module_customer::get_customer($data['customer_id']); if($customer_data && $customer_data['customer_id'] == $data['customer_id']){ if($customer_data['primary_user_id']){ $data['user_id'] = $customer_data['primary_user_id']; }else{ $customer_contacts = module_user::get_contacts(array('customer_id'=>$data['customer_id'])); foreach($customer_contacts as $contact){ // todo - search roles or something to find the accountant. $data['user_id'] = $contact['user_id']; break; } } }*/ } // check for credit assessment. if (isset($_POST['apply_credit_from_customer']) && $_POST['apply_credit_from_customer'] == 'do') { $invoice_data = $this->get_invoice($invoice_id); $customer_data = module_customer::get_customer($invoice_data['customer_id']); if ($customer_data['credit'] > 0) { $apply_credit = min($invoice_data['total_amount_due'], $customer_data['credit']); //$invoice_data['discount_amount'] += $customer_data['credit']; //$this->save_invoice($invoice_id,array('discount_amount'=>$invoice_data['discount_amount'],'discount_description'=>_l('Credit:'))); update_insert('invoice_payment_id', false, 'invoice_payment', array('invoice_id' => $invoice_id, 'payment_type' => _INVOICE_PAYMENT_TYPE_CREDIT, 'method' => _l('Credit'), 'amount' => $apply_credit, 'currency_id' => $invoice_data['currency_id'], 'other_id' => $invoice_data['customer_id'], 'date_paid' => date('Y-m-d'))); $this->add_history($invoice_id, _l('Applying %s customer credit to this invoice.', dollar($apply_credit))); module_cache::clear('invoice'); module_customer::remove_credit($customer_data['customer_id'], $apply_credit); } } // check for subsscription credit assessment. if (isset($_POST['apply_credit_from_subscription_bucket']) && $_POST['apply_credit_from_subscription_bucket'] == 'do' && (int) $_POST['apply_credit_from_subscription_id'] > 0) { $invoice_data = $this->get_invoice($invoice_id); $subscription_owner = module_subscription::get_subscription_owner($_POST['apply_credit_from_subscription_id']); $available_subscription_credit = module_subscription::get_available_credit($subscription_owner['owner_table'], $subscription_owner['owner_id']); //print_r($subscription_owner); print_r($available_subscription_credit);exit; if ($subscription_owner['subscription_owner_id'] && $available_subscription_credit[$subscription_owner['subscription_id']]['remain'] > 0) { $apply_credit = min($invoice_data['total_amount_due'], $available_subscription_credit[$subscription_owner['subscription_id']]['remain']); //$invoice_data['discount_amount'] += $customer_data['credit']; //$this->save_invoice($invoice_id,array('discount_amount'=>$invoice_data['discount_amount'],'discount_description'=>_l('Credit:'))); update_insert('invoice_payment_id', false, 'invoice_payment', array('invoice_id' => $invoice_id, 'payment_type' => _INVOICE_PAYMENT_TYPE_SUBSCRIPTION_CREDIT, 'method' => _l('Credit'), 'amount' => $apply_credit, 'currency_id' => $invoice_data['currency_id'], 'other_id' => $subscription_owner['subscription_owner_id'], 'date_paid' => date('Y-m-d'))); $this->add_history($invoice_id, _l('Applying %s subscription credit to this invoice.', dollar($apply_credit))); module_cache::clear('invoice'); } } $invoice_id = $this->save_invoice($invoice_id, $data); if (isset($_REQUEST['allowed_payment_method_check'])) { // todo - ability to disable ALL payment methods. - array wont be set if none are ticked $payment_methods = handle_hook('get_payment_methods'); foreach ($payment_methods as &$payment_method) { if ($payment_method->is_enabled()) { // is this one already enabled for this invoice? //$is_already_allowed = $payment_method->is_allowed_for_invoice($invoice_id); if (isset($_REQUEST['allowed_payment_method']) && isset($_REQUEST['allowed_payment_method'][$payment_method->module_name])) { $payment_method->set_allowed_for_invoice($invoice_id, 1); } else { $payment_method->set_allowed_for_invoice($invoice_id, 0); } } } } // check if we are generating any renewals if (isset($_REQUEST['generate_renewal']) && $_REQUEST['generate_renewal'] > 0) { $new_invoice_id = $this->renew_invoice($invoice_id); if ($new_invoice_id) { set_message("Invoice renewed successfully"); redirect_browser(module_invoice::link_open($new_invoice_id, false)); } else { } } if (isset($_REQUEST['butt_makepayment']) && $_REQUEST['butt_makepayment'] == 'yes') { //redirect_browser(self::link_public_pay($invoice_id)); self::handle_payment(); } else { if (isset($_REQUEST['butt_print']) && $_REQUEST['butt_print']) { $_REQUEST['_redirect'] = self::link_generate($invoice_id, array('arguments' => array('print' => 1))); } else { if (isset($_REQUEST['butt_merge']) && $_REQUEST['butt_merge'] && isset($_REQUEST['merge_invoice']) && is_array($_REQUEST['merge_invoice'])) { $merge_invoice_ids = self::check_invoice_merge($invoice_id); foreach ($merge_invoice_ids as $merge_invoice) { if (isset($_REQUEST['merge_invoice'][$merge_invoice['invoice_id']])) { // copy all the tasks from that invoice over to this invoice. $sql = "UPDATE `" . _DB_PREFIX . "invoice_item` SET invoice_id = " . (int) $invoice_id . " WHERE invoice_id = " . (int) $merge_invoice['invoice_id'] . " "; query($sql); $this->delete_invoice($merge_invoice['invoice_id']); } } $_REQUEST['_redirect'] = $this->link_open($invoice_id); set_message('Invoices merged successfully'); } else { if (isset($_REQUEST['butt_email']) && $_REQUEST['butt_email']) { $_REQUEST['_redirect'] = self::link_generate($invoice_id, array('arguments' => array('email' => 1))); } else { if (isset($_REQUEST['butt_generate_credit']) && $_REQUEST['butt_generate_credit']) { // generate a credit note against this invioce. // to do this we duplicate the invoice, remove the cancel date, remove the sent date, // set a new create date, set the credit_note_id variable, remove the paid date, // (copied from the generate renewal code above) $invoice = $this->get_invoice($invoice_id); unset($invoice['invoice_id']); unset($invoice['date_renew']); unset($invoice['date_sent']); unset($invoice['date_paid']); unset($invoice['date_cancel']); unset($invoice['renew_invoice_id']); unset($invoice['deposit_job_id']); $invoice['name'] = self::new_invoice_number($invoice['customer_id']); $invoice['credit_note_id'] = $invoice_id; $invoice['date_create'] = date('Y-m-d'); $invoice['discount_amount'] = 0; $invoice['discount_description'] = _l('Discount:'); $invoice['discount_type'] = module_config::c('invoice_discount_type', _DISCOUNT_TYPE_BEFORE_TAX); // 1 = After Tax $invoice['tax_type'] = module_config::c('invoice_tax_type', 0); $invoice['date_due'] = false; $invoice['status'] = module_config::s('invoice_status_default', 'New'); $new_invoice_id = $this->save_invoice('new', $invoice); if ($new_invoice_id) { // now we create the tasks $tasks = $this->get_invoice_items($invoice_id, $invoice); foreach ($tasks as $task) { unset($task['invoice_item_id']); if ($task['custom_description']) { $task['description'] = $task['custom_description']; } if ($task['custom_long_description']) { $task['long_description'] = $task['custom_long_description']; } $task['invoice_id'] = $new_invoice_id; $task['date_done'] = $invoice['date_create']; update_insert('invoice_item_id', 'new', 'invoice_item', $task); } set_message("Credit note generated successfully"); module_cache::clear('invoice'); redirect_browser($this->link_open($new_invoice_id)); } else { set_error('Generating credit note failed'); redirect_browser($this->link_open($invoice_id)); } } else { $_REQUEST['_redirect'] = isset($_REQUEST['_redirect']) && !empty($_REQUEST['_redirect']) ? $_REQUEST['_redirect'] : $this->link_open($invoice_id); set_message("Invoice saved successfully"); } } } } } } } } } if (!count($errors)) { redirect_browser($_REQUEST['_redirect']); exit; } print_error($errors, true); }
$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>'; } })); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) { $c = array(); $res = module_quote::get_quotes(array('customer_id' => $file['customer_id'])); foreach ($res as $row) { $c[$row['quote_id']] = $row['name']; } if ($file['quote_id'] && !isset($c[$file['quote_id']])) { // this file is related to another quote. from another customer. $related_quote = module_quote::get_quote($file['quote_id'], false, true); if ($related_quote && $related_quote['quote_id'] == $file['quote_id']) { $related_customer = module_customer::get_customer($related_quote['customer_id'], true); if ($related_customer && $related_customer['customer_id'] == $related_quote['customer_id']) {
public function process() { switch ($_REQUEST['_process']) { case 'quick_save_finance': if (isset($_REQUEST['link_go']) && $_REQUEST['link_go'] == 'go') { module_finance::handle_link_transactions(); } else { // check for date / name at least. $date = trim($_REQUEST['transaction_date']); $name = trim($_REQUEST['name']); if (!$date || !$name) { redirect_browser(module_finance::link_open(false)); } $credit = trim($_REQUEST['credit']); $debit = trim($_REQUEST['debit']); if ($credit > 0) { $_POST['type'] = 'i'; $_POST['amount'] = $credit; } else { $_POST['type'] = 'e'; $_POST['amount'] = $debit; } } case 'save_finance': if (isset($_REQUEST['butt_del'])) { $this->delete($_REQUEST['finance_id']); redirect_browser(self::link_open(false)); } if (isset($_REQUEST['butt_unlink'])) { // unlink this finance_id from other finance_ids. $sql = "UPDATE `" . _DB_PREFIX . "finance` SET parent_finance_id = 0 WHERE parent_finance_id = '" . (int) $_REQUEST['finance_id'] . "'"; query($sql); $sql = "UPDATE `" . _DB_PREFIX . "invoice_payment` SET parent_finance_id = 0 WHERE parent_finance_id = '" . (int) $_REQUEST['finance_id'] . "'"; query($sql); redirect_browser(self::link_open(false)); } $temp_data = $this->get_finance($_REQUEST['finance_id']); $data = $_POST + $temp_data; // save the finance categories and account. $account_id = $_REQUEST['finance_account_id']; if ((string) (int) $account_id != (string) $account_id && strlen($account_id) > 2) { // we have a new account to create. $account_id = update_insert('finance_account_id', 'new', 'finance_account', array('name' => $account_id)); } $data['finance_account_id'] = $account_id; $finance_id = update_insert('finance_id', isset($_REQUEST['finance_id']) ? $_REQUEST['finance_id'] : 'new', 'finance', $data); module_extra::save_extras('finance', 'finance_id', $finance_id); if (!isset($data['tax_ids']) && isset($data['taxes']) && is_array($data['taxes'])) { // default data when saving a new invoice payment to finance area $data['tax_ids'] = array(); $data['tax_names'] = array(); $data['tax_percents'] = array(); $data['tax_increment_checkbox'] = 0; foreach ($data['taxes'] as $tax) { $data['tax_ids'][] = false; $data['tax_names'][] = $tax['name']; $data['tax_percents'][] = $tax['percent']; $data['tax_amount'][] = $tax['amount']; if ($tax['increment']) { $data['tax_increment_checkbox'] = 1; } } } // save the finance tax rates (copied from invoice.php) if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) { $existing_taxes = get_multiple('finance_tax', array('finance_id' => $finance_id), 'finance_tax_id', 'exact', 'order'); $order = 1; foreach ($data['tax_ids'] as $key => $val) { if ((int) $val > 0 && isset($existing_taxes[$val])) { // this means we are trying to update an existing record on the finance_tax table, we confirm this id matches this finance. $finance_tax_id = $val; unset($existing_taxes[$finance_tax_id]); // so we know which ones to remove from the end. } else { $finance_tax_id = false; // create new record } $finance_tax_data = array('finance_id' => $finance_id, 'percent' => isset($data['tax_percents'][$key]) ? $data['tax_percents'][$key] : 0, 'amount' => isset($data['tax_amount'][$key]) ? $data['tax_amount'][$key] : 0, 'name' => isset($data['tax_names'][$key]) ? $data['tax_names'][$key] : 'TAX', 'order' => $order++, 'increment' => isset($data['tax_increment_checkbox']) && $data['tax_increment_checkbox'] ? 1 : 0); $finance_tax_id = update_insert('finance_tax_id', $finance_tax_id, 'finance_tax', $finance_tax_data); } foreach ($existing_taxes as $existing_tax) { delete_from_db('finance_tax', array('finance_id', 'finance_tax_id'), array($finance_id, $existing_tax['finance_tax_id'])); } } $category_ids = isset($_REQUEST['finance_category_id']) && is_array($_REQUEST['finance_category_id']) ? $_REQUEST['finance_category_id'] : array(); $sql = "DELETE FROM `" . _DB_PREFIX . "finance_category_rel` WHERE finance_id = {$finance_id}"; query($sql); foreach ($category_ids as $category_id) { $category_id = (int) $category_id; if ($category_id <= 0) { continue; } $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_category_rel` SET finance_id = {$finance_id}, finance_category_id = {$category_id}"; query($sql); } if (isset($_REQUEST['finance_category_new']) && strlen(trim($_REQUEST['finance_category_new'])) > 0) { $category_name = trim($_REQUEST['finance_category_new']); $category_id = update_insert('finance_category_id', 'new', 'finance_category', array('name' => $category_name)); if (isset($_REQUEST['finance_category_new_checked'])) { $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_category_rel` SET finance_id = {$finance_id}, finance_category_id = {$category_id}"; query($sql); } } if (isset($_REQUEST['invoice_payment_id']) && (int) $_REQUEST['invoice_payment_id'] > 0) { // link this as a child invoice payment to this one. update_insert('invoice_payment_id', $_REQUEST['invoice_payment_id'], 'invoice_payment', array('parent_finance_id' => $finance_id)); } if (isset($_REQUEST['finance_recurring_id']) && (int) $_REQUEST['finance_recurring_id'] > 0) { // if we have set a custom "next recurring date" then we don't recalculate this date unless we are saving a new finance id. $recurring = self::get_recurring($_REQUEST['finance_recurring_id']); if (!(int) $_REQUEST['finance_id'] || !$recurring['next_due_date_custom']) { self::calculate_recurring_date((int) $_REQUEST['finance_recurring_id'], true); } // we also have to adjust the starting balance of our recurring amount by this amount. // just a little helpful feature. if (!(int) $_REQUEST['finance_id']) { $balance = module_config::c('finance_recurring_start_balance', 0); if ($balance != 0) { if ($data['type'] == 'e') { $balance -= $data['amount']; } else { if ($data['type'] == 'i') { $balance += $data['amount']; } } module_config::save_config('finance_recurring_start_balance', $balance); } } // redirect back to recurring listing. set_message('Recurring transaction saved successfully'); if (isset($_REQUEST['recurring_next']) && $_REQUEST['recurring_next']) { redirect_browser($_REQUEST['recurring_next']); } redirect_browser(self::link_open_recurring(false)); } set_message(_l('Transaction saved successfully: %s', module_finance::link_open($finance_id, true))); if (isset($_REQUEST['job_id']) && (int) $_REQUEST['job_id'] > 0) { redirect_browser(module_job::link_open((int) $_REQUEST['job_id'])); } if (isset($_REQUEST['butt_save_return'])) { if (isset($_REQUEST['_redirect']) && strlen($_REQUEST['_redirect'])) { redirect_browser($_REQUEST['_redirect']); } redirect_browser(self::link_open(false, false)); } if ($_REQUEST['_process'] == 'quick_save_finance') { redirect_browser(self::link_open(false, false)); } redirect_browser(self::link_open($finance_id, false)); break; case 'save_recurring': if (isset($_REQUEST['butt_del'])) { $this->delete_recurring($_REQUEST['finance_recurring_id']); redirect_browser(self::link_open_recurring(false)); } $data = $_POST; // save the finance categories and account. $account_id = $_REQUEST['finance_account_id']; if ((string) (int) $account_id != (string) $account_id && strlen($account_id) > 2) { // we have a new account to create. $account_id = update_insert('finance_account_id', 'new', 'finance_account', array('name' => $account_id)); } if (isset($_REQUEST['finance_recurring_id']) && (int) $_REQUEST['finance_recurring_id']) { $original_finance_recurring = self::get_recurring($_REQUEST['finance_recurring_id']); } else { $original_finance_recurring = array(); } $data['finance_account_id'] = $account_id; $finance_recurring_id = update_insert('finance_recurring_id', isset($_REQUEST['finance_recurring_id']) ? $_REQUEST['finance_recurring_id'] : 'new', 'finance_recurring', $data); if ((int) $finance_recurring_id > 0) { $category_ids = isset($_REQUEST['finance_category_id']) && is_array($_REQUEST['finance_category_id']) ? $_REQUEST['finance_category_id'] : array(); $sql = "DELETE FROM `" . _DB_PREFIX . "finance_recurring_catrel` WHERE finance_recurring_id = {$finance_recurring_id}"; query($sql); foreach ($category_ids as $category_id) { $category_id = (int) $category_id; if ($category_id <= 0) { continue; } $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_recurring_catrel` SET finance_recurring_id = {$finance_recurring_id}, finance_category_id = {$category_id}"; query($sql); } if (isset($_REQUEST['finance_category_new']) && strlen(trim($_REQUEST['finance_category_new'])) > 0) { $category_name = trim($_REQUEST['finance_category_new']); $category_id = update_insert('finance_category_id', 'new', 'finance_category', array('name' => $category_name)); if (isset($_REQUEST['finance_category_new_checked'])) { $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_recurring_catrel` SET finance_recurring_id = {$finance_recurring_id}, finance_category_id = {$category_id}"; query($sql); } } $calculated_next_date = self::calculate_recurring_date($finance_recurring_id); if (isset($data['set_next_due_date']) && $data['set_next_due_date']) { $next_date = input_date($data['set_next_due_date']); $next_due_date_real = module_finance::calculate_recurring_date($finance_recurring_id, true, false); if ($next_date != $next_due_date_real) { // we have accustom date. update_insert('finance_recurring_id', $finance_recurring_id, 'finance_recurring', array('next_due_date' => $next_date, 'next_due_date_custom' => 1)); } else { // date is the same. not doing a custom date any more update_insert('finance_recurring_id', $finance_recurring_id, 'finance_recurring', array('next_due_date' => $next_due_date_real, 'next_due_date_custom' => 0)); } } /* $finance_recurring = self::get_recurring($finance_recurring_id); if($finance_recurring['next_due_date_custom']){ $next_due_date_real = module_finance::calculate_recurring_date($finance_recurring_id,true,false); // unset the "custom" flag if we've picked the same date as what it should be. if($next_due_date_real == $finance_recurring['next_due_date']){ module_finance::calculate_recurring_date($finance_recurring_id,true,true); } }*/ } set_message('Recurring transaction saved successfully'); //redirect_browser(self::link_open($finance_id,false)); redirect_browser(self::link_open_recurring(false, false)); break; } }
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); ?> <?php if (isset($original_job_data['renew_from_job_id'])) { _e('(will renew on %s)', print_date($original_job_data['date_start'])); } ?> </td> <td> <?php echo module_website::link_open($original_job_data['website_id'], true); ?> </td>
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; } }
}); }); </script> <?php })); $fieldset_data['elements'][] = array('title' => 'Linked Job', 'fields' => array(function () use(&$finance, $locked) { $d = array(); if ($finance['customer_id']) { $jobs = module_job::get_jobs(array('customer_id' => $finance['customer_id'])); foreach ($jobs as $job) { $d[$job['job_id']] = $job['name']; } } echo print_select_box($d, 'job_id', isset($finance['job_id']) ? $finance['job_id'] : 0, '', _l(' - None - ')); if (isset($finance['job_id']) && $finance['job_id']) { echo ' <a href="' . module_job::link_open($finance['job_id'], false) . '">' . _l('Open Job') . '</a>'; } })); } $fieldset_data['elements'][] = array('title' => 'Linked Invoice', 'fields' => array(function () use(&$finance, $locked) { $d = array(); if ($finance['customer_id']) { $invoices = module_invoice::get_invoices(array('customer_id' => $finance['customer_id'])); foreach ($invoices as $invoice) { $d[$invoice['invoice_id']] = $invoice['name']; } } echo print_select_box($d, 'invoice_id', $finance['invoice_id'], '', _l(' - None - ')); if ($finance['invoice_id']) { echo ' <a href="' . module_invoice::link_open($finance['invoice_id'], false) . '">' . _l('Open Invoice') . '</a>'; }