Exemplo n.º 1
0
                echo module_job::link_open($job_id, true);
                echo "<br/>\n";
            }
        }
    }));
}
$fieldset_data['elements'][] = array('title' => 'Customer', 'fields' => array(function () use(&$invoice) {
    if (!$invoice['customer_id'] || isset($_REQUEST['change_customer'])) {
        // allow them to pick customer.
        $c = array();
        $customers = module_customer::get_customers();
        foreach ($customers as $customer) {
            $c[$customer['customer_id']] = $customer['customer_name'];
        }
        echo print_select_box($c, 'customer_id', $invoice['customer_id']);
        if ($invoice['customer_id'] && module_customer::can_i('view', 'Customers')) {
            ?>

                        <a href="<?php 
            echo module_customer::link_open($invoice['customer_id'], false);
            ?>
"><?php 
            _e('Open');
            ?>
</a>
                        <?php 
        }
    } else {
        echo module_customer::link_open($invoice['customer_id'], true);
        if (module_invoice::can_i('edit', 'Invoices')) {
            ?>
Exemplo n.º 2
0
$columns = array();
$columns['quote_title'] = array('title' => 'Quote Title', 'callback' => function ($quote) {
    echo module_quote::link_open($quote['quote_id'], true, $quote);
}, 'cell_class' => 'row_action');
$columns['quote_start_date'] = array('title' => 'Create Date', 'callback' => function ($quote) {
    echo print_date($quote['date_create']);
});
$columns['quote_completed_date'] = array('title' => 'Accepted Date', 'callback' => function ($quote) {
    echo print_date($quote['date_approved']);
});
if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
    $columns['quote_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($quote) {
        echo module_website::link_open($quote['website_id'], true);
    });
}
if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
    $columns['quote_customer'] = array('title' => 'Customer', 'callback' => function ($quote) {
        echo module_customer::link_open($quote['customer_id'], true);
    });
}
$columns['quote_type'] = array('title' => 'Type', 'callback' => function ($quote) {
    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);
    });
}
Exemplo n.º 3
0
    $responsive_summary = array();
    $responsive_summary[] = module_customer::link_open($ticket['customer_id'], true);
    $fieldset_data = array('heading' => array('title' => _l('Related to'), 'type' => 'h3', 'responsive' => array('summary' => implode(', ', $responsive_summary))), 'elements' => array());
    $fieldset_data['elements'][] = array('title' => _l('Customer'), 'fields' => array(function () use($ticket_id, $ticket, $done_in_ticket_billing) {
        // moved to ticket billing..?
        if (module_ticket::can_edit_tickets() && !isset($done_in_ticket_billing)) {
            $c = array();
            $res = module_customer::get_customers();
            while ($row = array_shift($res)) {
                $c[$row['customer_id']] = $row['customer_name'];
            }
            if ($ticket['customer_id'] < 0) {
                $ticket['customer_id'] = false;
            }
            echo print_select_box($c, 'change_customer_id', $ticket['customer_id'], '', _l(' - No Customer -'));
            if (module_customer::can_i('create', 'Customers') && $ticket['user_id'] && (int) $ticket_id > 0) {
                // is this a user, or a staff member. don't allow moving of staff members. (or maybe later we will)
                //$user_temp = module_user::get_user($ticket['user_id'],false);
                //if($user_temp['customer_id']<=0){
                ?>

                            <input type="button" name="new_customer" value="<?php 
                _e('New');
                ?>
" onclick="window.location.href='<?php 
                echo module_customer::link_open('new', false);
                ?>
&move_user_id=<?php 
                echo $ticket['user_id'];
                ?>
';" class="small_button"><?php 
Exemplo n.º 4
0
    echo _l('Assign Customer');
    ?>

                    </th>
                    <td>
                        <?php 
    $c = array();
    $customers = module_customer::get_customers();
    foreach ($customers as $customer) {
        $c[$customer['customer_id']] = $customer['customer_name'];
    }
    echo print_select_box($c, 'customer_id', $job['customer_id']);
    ?>

                        <?php 
    if ($job['customer_id'] && module_customer::can_i('view', 'Customers')) {
        ?>

                        <a href="<?php 
        echo module_customer::link_open($job['customer_id'], false);
        ?>
"><?php 
        _e('Open');
        ?>
</a>
                        <?php 
    }
    ?>

                    </td>
                </tr>
<?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 (!module_customer::can_i('edit', 'Customer Settings', 'Config')) {
    redirect_browser(_BASE_HREF);
}
if (isset($_REQUEST['customer_type_id']) && $_REQUEST['customer_type_id']) {
    $show_other_settings = false;
    $customer_type_id = (int) $_REQUEST['customer_type_id'];
    if ($customer_type_id > 0) {
        $customer_type = module_customer::get_customer_type($customer_type_id);
    } else {
        $customer_type = array();
    }
    if (!$customer_type) {
        $customer_type = array('type_name' => '', 'type_name_plural' => '', 'menu_position' => 0, 'menu_icon' => 'users');
    }
    ?>


	<form action="" method="post">
		<input type="hidden" name="_process" value="save_customer_type">
		<input type="hidden" name="customer_type_id" value="<?php 
Exemplo n.º 6
0
 public function handle_hook($hook)
 {
     switch ($hook) {
         case "invoice_paid":
             $foo = func_get_args();
             $invoice_id = (int) $foo[1];
             if ($invoice_id > 0) {
                 // see if any subscriptions match this invoice.
                 //module_cache::clear_cache();
                 $invoice = module_invoice::get_invoice($invoice_id);
                 $subscription = get_single('subscription_history', 'invoice_id', $invoice_id);
                 if ($subscription) {
                     // mark subscription as paid and move onto the next date.
                     update_insert('subscription_history_id', $subscription['subscription_history_id'], 'subscription_history', array('paid_date' => $invoice['date_paid']));
                     $subscription_owner = get_single('subscription_owner', 'subscription_owner_id', $subscription['subscription_owner_id']);
                     $this->update_next_due_date($subscription['subscription_id'], $subscription_owner['owner_table'], $subscription_owner['owner_id']);
                     /*if($subscription['customer_id']){
                           $this->update_next_due_date($subscription['subscription_id'],$subscription['customer_id'],true);
                       }else{
                           $this->update_next_due_date($subscription['subscription_id'],$subscription['member_id'],false);
                       }*/
                 }
             }
             break;
         case "home_alerts":
             $alerts = array();
             if (module_config::c('subscription_alerts', 1) && self::can_i('view', 'Subscriptions')) {
                 // find renewals due in a certain time.
                 $time = date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days'));
                 $key = _l('Subscription Due');
                 if (class_exists('module_dashboard', false)) {
                     module_dashboard::register_group($key, array('columns' => array('full_link' => _l('Name'), 'type' => _l('Type'), 'subscription_name' => _l('Subscription'), 'automatic_renew' => _l('Automatic Renew'), 'automatic_email' => _l('Automatic Email'), 'next_due_date' => _l('Next Due Date'), 'days' => _l('Day Count'))));
                 }
                 $db_fields = get_fields('subscription');
                 $sql = "SELECT s.*, so.* ";
                 if (isset($db_fields['invoice_prior_days'])) {
                     $sql .= ", DATE_SUB(so.next_due_date, INTERVAL `invoice_prior_days` DAY) AS next_generation_date ";
                 }
                 $sql .= " FROM `" . _DB_PREFIX . "subscription_owner` so ";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id)";
                 if (isset($db_fields['invoice_prior_days'])) {
                     $sql .= " WHERE DATE_SUB(so.next_due_date, INTERVAL `invoice_prior_days` DAY) <= '" . $time . "'";
                 } else {
                     $sql .= " WHERE so.next_due_date <= '" . $time . "'";
                 }
                 $sql .= " AND so.`deleted` = 0";
                 //                    echo $sql;
                 $items = qa($sql);
                 foreach ($items as $item) {
                     //                        echo '<hr>';print_r($item);echo '<hr>';
                     $alert_res = process_alert(isset($item['next_generation_date']) ? $item['next_generation_date'] : $item['next_due_date'], $key);
                     if ($alert_res) {
                         switch ($item['owner_table']) {
                             case 'member':
                                 $permission_check = module_member::get_member($item['owner_id']);
                                 if (!$permission_check || $permission_check['member_id'] != $item['owner_id'] || !module_member::can_i('view', 'Members')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_member::link_open($item['owner_id'], true);
                                 break;
                             case 'website':
                                 $permission_check = module_website::get_website($item['owner_id']);
                                 if (!$permission_check || $permission_check['website_id'] != $item['owner_id'] || !module_website::can_i('view', 'Websites')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_website::link_open($item['owner_id'], true);
                                 break;
                             case 'customer':
                                 $permission_check = module_customer::get_customer($item['owner_id']);
                                 if (!$permission_check || $permission_check['customer_id'] != $item['owner_id'] || !module_customer::can_i('view', 'Customers')) {
                                     continue 2;
                                 }
                                 $alert_res['full_link'] = module_customer::link_open($item['owner_id'], true);
                                 break;
                         }
                         $alert_res['name'] = $item['name'];
                         $alert_res['link'] = '#';
                         if (preg_match('@href="([^"]+)"@', $alert_res['full_link'], $link_match)) {
                             $alert_res['link'] = $link_match[1];
                         }
                         $alert_res['type'] = $item['owner_table'];
                         $alert_res['subscription_name'] = module_subscription::link_open($item['subscription_id'], true);
                         $alert_res['next_due_date'] = isset($item['next_generation_date']) ? print_date($item['next_generation_date']) : print_date($item['next_due_date']);
                         $alert_res['automatic_renew'] = $item['automatic_renew'] ? _l('Yes') : _l('No');
                         $alert_res['automatic_email'] = $item['automatic_email'] ? _l('Yes') : _l('No');
                         $alerts[] = $alert_res;
                     }
                 }
             }
             return $alerts;
             break;
     }
 }
Exemplo n.º 7
0
                $_REQUEST['customer_id'] = $old_customer_id;
            } else {
                unset($_REQUEST['customer_id']);
            }
        }
    });
}
if (class_exists('module_extra', false)) {
    // do extra before "table sorting" so that it can hook in with the table sort call
    $table_manager->display_extra('customer', function ($customer) {
        module_extra::print_table_data('customer', $customer['customer_id']);
    }, 'customer_id');
    $table_manager->display_extra('user', function ($customer) {
        module_extra::print_table_data('user', $customer['primary_user_id']);
    }, 'primary_user_id');
}
$table_manager->enable_table_sorting(array('table_id' => 'customer_list', 'sortable' => array('customer_name' => array('field' => 'customer_name'), 'primary_contact_name' => array('field' => 'primary_user_name'), 'primary_contact_email' => array('field' => 'primary_user_email'), 'customer_group' => array('group_sort' => true, 'owner_table' => 'customer', 'owner_id' => 'customer_id'))));
if (module_customer::can_i('view', 'Export ' . $page_type)) {
    $table_manager->enable_export(array('name' => $page_type_single . ' Export', 'fields' => array($page_type_single . ' ID' => 'customer_id', $page_type_single . ' Name' => 'customer_name', 'Credit' => 'credit', 'Address Line 1' => 'line_1', 'Address Line 2' => 'line_2', 'Address Suburb' => 'suburb', 'Address Country' => 'country', 'Address State' => 'state', 'Address Region' => 'region', 'Address Post Code' => 'post_code', 'Primary Contact First Name' => 'primary_user_name', 'Primary Contact Last Name' => 'primary_user_last_name', 'Primary Phone' => 'primary_user_phone', 'Primary Email' => 'primary_user_email', 'Primary Fax' => 'primary_user_fax', 'Primary Mobile' => 'primary_user_mobile', 'Primary Language' => 'primary_user_language', 'Invoice Prefix' => 'default_invoice_prefix', 'Tax Name' => 'default_tax_name', 'Tax Rate' => 'default_tax', 'Staff' => 'customer_staff'), 'extra' => array(array('owner_table' => 'customer', 'owner_id' => 'customer_id'), array('owner_table' => 'user', 'owner_id' => 'primary_user_id')), 'group' => array(array('title' => $page_type_single . ' Group', 'owner_table' => 'customer', 'owner_id' => 'customer_id'))));
}
$table_manager->set_columns($columns);
$table_manager->row_callback = function ($row_data) {
    // load the full customer data before displaying each row so we have access to more details
    return module_customer::get_customer($row_data['customer_id']);
};
$table_manager->set_rows($customers);
$table_manager->pagination = true;
$table_manager->print_table();
/** END TABLE LAYOUT **/
?>
</form>
Exemplo n.º 8
0
 public function handle_hook($hook, &$calling_module = false, $show_all = false)
 {
     switch ($hook) {
         case 'dashboard_widgets':
             // see finance for example of widget usage.
             break;
         case "home_alerts":
             $cache_timeout = module_config::c('cache_objects', 60);
             $cache_key = 'home_alerts_' . module_security::get_loggedin_id();
             $alerts = array();
             if ($show_all || module_config::c('quote_alerts', 1)) {
                 // find any quotes that are past the due date and dont have a finished date.
                 $key = _l('Unapproved Quote');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('quote' => _l('Quote Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'date' => _l('Sent Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns, 'sort' => array('time' => 'DESC')));
                 }
                 if ($cached_alerts = module_cache::get('quote', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Quote Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     if (module_config::c('quote_dashboard_show_all_unapproved', 1)) {
                         $quotes = self::get_quotes(array(), array('custom_where' => " AND u.date_approved = '0000-00-00'"));
                     } else {
                         $quotes = self::get_quotes(array(), array('custom_where' => " AND u.date_approved = '0000-00-00' AND u.date_create <= '" . date('Y-m-d', strtotime('-' . module_config::c('alert_days_in_future', 5) . ' days')) . "'"));
                     }
                     foreach ($quotes as $quote_data) {
                         // permission check:
                         //                            $quote_data = self::get_quote($task['quote_id']);
                         //                            if(!$quote_data || $quote_data['quote_id']!=$task['quote_id'])continue;
                         $alert_res = process_alert($quote_data['date_create'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($quote_data['quote_id'], false, $quote_data);
                             $alert_res['name'] = $quote_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['quote'] = $this->link_open($quote_data['quote_id'], true, $quote_data);
                             $alert_res['customer'] = $quote_data['customer_id'] ? module_customer::link_open($quote_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $quote_data['website_id'] ? module_website::link_open($quote_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $quote_data['user_id'] ? module_user::link_open($quote_data['user_id'], true) : _l('N/A');
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts['quoteincomplete' . $quote_data['quote_id']] = $alert_res;
                         }
                     }
                     module_cache::put('quote', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             return $alerts;
             break;
     }
     return false;
 }
Exemplo n.º 9
0
 public function handle_hook($hook, &$calling_module = false, $show_all = false)
 {
     switch ($hook) {
         case 'dashboard_widgets':
             // see finance for example of widget usage.
             break;
         case "home_alerts":
             $cache_timeout = module_config::c('cache_objects', 60);
             $cache_key = 'home_alerts_' . module_security::get_loggedin_id();
             $alerts = array();
             /*if(module_config::c('job_task_alerts',1)){
                   // find out any overdue tasks or jobs.
                   $sql = "SELECT t.*,p.name AS job_name FROM `"._DB_PREFIX."task` t ";
                   $sql .= " LEFT JOIN `"._DB_PREFIX."job` p USING (job_id) ";
                   $sql .= " WHERE t.date_due != '0000-00-00' AND t.date_due <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."' AND ((t.hours = 0 AND t.completed = 0) OR t.completed < t.hours)";
                   $tasks = qa($sql);
                   foreach($tasks as $task){
                       $alert_res = process_alert($task['date_due'], _l('Job: %s',$task['job_name']));
                       if($alert_res){
                           $alert_res['link'] = $this->link_open($task['job_id']);
                           $alert_res['name'] = $task['description'];
                           $alerts[] = $alert_res;
                       }
                   }
               }*/
             if ($show_all || module_config::c('job_alerts', 1)) {
                 // find any jobs that are past the due date and dont have a finished date.
                 $key = _l('Incomplete Job');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'progress' => _l('Job Progress'), 'assigned_staff' => _l('Staff'), 'date' => _l('Due Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns, 'sort' => array('time' => 'DESC')));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     //                        $sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //                        $sql .= " WHERE p.date_due != '0000-00-00' AND p.date_due <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."' AND p.date_completed = '0000-00-00'";
                     //                        $tasks = qa($sql);
                     $jobs = self::get_jobs(array(), array('custom_where' => " AND u.date_due != '0000-00-00' AND u.date_due <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "' AND u.date_completed = '0000-00-00'"));
                     foreach ($jobs as $job_data) {
                         // permission check:
                         //                            $job_data = self::get_job($task['job_id']);
                         //                            if(!$job_data || $job_data['job_id']!=$task['job_id'])continue;
                         $alert_res = process_alert($job_data['date_due'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                             $alert_res['name'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                             $alert_res['progress'] = $job_data['total_percent_complete'] * 100 . '%';
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts['jobincomplete' . $job_data['job_id']] = $alert_res;
                         }
                     }
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key . ' #2'));
                     // find any jobs that haven't started yet (ie: have a start date, but no completed tasks)
                     //                        $sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //                        $sql .= " WHERE p.date_completed = '0000-00-00' AND p.date_start != '0000-00-00' AND p.date_start <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."'";
                     //                        $jobs = qa($sql);
                     $jobs = self::get_jobs(array(), array('custom_where' => " AND u.date_completed = '0000-00-00' AND u.date_due = '0000-00-00' AND u.date_start != '0000-00-00' AND u.date_start <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "'"));
                     foreach ($jobs as $job_data) {
                         //$job_data = self::get_job($job['job_id']);
                         //if(!$job_data || $job_data['job_id']!=$job['job_id'])continue;
                         /*$job_started=true;
                                                     if(module_config::c('job_start_alerts_old',0)){
                                                         $tasks = self::get_tasks($job['job_id']);
                                                         $job_started = false;
                                                         foreach($tasks as $task){
                                                             if($task['fully_completed']){
                                                                 $job_started = true;
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                     if(!$job_started){
                         
                                                         $alert_res = process_alert($job['date_start'], _l('Job Not Started'));
                                                         if($alert_res){
                                                             $alert_res['link'] = $this->link_open($job['job_id'],false,$job);
                                                             $alert_res['name'] = $job['name'];
                                                             $alerts[] = $alert_res;
                                                         }
                                                     }else{*/
                         // do the same alert as above.
                         if (!isset($this_alerts['jobincomplete' . $job_data['job_id']])) {
                             $alert_res = process_alert($job_data['date_start'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                                 $alert_res['name'] = $job_data['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($alert_res['date']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                                 $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                                 $alert_res['progress'] = $job_data['total_percent_complete'] * 100 . '%';
                                 $alert_res['date'] = print_date($alert_res['date']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts['jobincomplete' . $job_data['job_id']] = $alert_res;
                             }
                         }
                         /* }*/
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if (module_config::c('job_allow_quotes', 0) && ($show_all || module_config::c('job_quote_alerts', 1))) {
                 // find any jobs that dont have a start date yet.
                 $key = _l('Pending Job Quote');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'date' => _l('Quoted Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     //$sql = "SELECT * FROM `"._DB_PREFIX."job` p ";
                     //$sql .= " WHERE p.date_quote != '0000-00-00' AND p.date_start = '0000-00-00'";
                     //$tasks = qa($sql);
                     $jobs = self::get_jobs(array('date_start' => '0000-00-00', 'date_quote' => '!0000-00-00'));
                     foreach ($jobs as $job_data) {
                         //$job_data = self::get_job($task['job_id']);
                         //if(!$job_data || $job_data['job_id']!=$task['job_id'])continue;
                         $alert_res = process_alert($job_data['date_quote'], $key);
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job_data['job_id'], false, $job_data);
                             $alert_res['name'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($job_data['date_quote']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job_data['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job_data['website_id'] ? module_website::link_open($job_data['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job_data['user_id'] ? module_user::link_open($job_data['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job_data['total_percent_complete'] * 100).'%';
                             $alert_res['date'] = print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_invoice_alerts', 1)) {
                 // find any completed jobs that don't have an invoice.
                 $key = _l('Please Generate Invoice');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'invoicable_amount' => _l('Invoiceable Amount'), 'date' => _l('Completed Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $sql = "SELECT j.* FROM `" . _DB_PREFIX . "job` j ";
                     $from = " LEFT JOIN `" . _DB_PREFIX . "task` t USING (job_id) ";
                     $from .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON t.task_id = ii.task_id ";
                     $from .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON ii.invoice_id = i.invoice_id  ";
                     $where = " WHERE i.invoice_id IS NULL AND (j.date_completed != '0000-00-00')";
                     switch (self::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 ";
                             $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.
                             $customers = module_customer::get_customers();
                             if (count($customers)) {
                                 $where .= " AND j.customer_id IN ( ";
                                 foreach ($customers as $customer) {
                                     $where .= $customer['customer_id'] . ', ';
                                 }
                                 $where = rtrim($where, ', ');
                                 $where .= " ) ";
                             }
                             break;
                     }
                     // 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 ( j.customer_id = 0 OR j.customer_id IN ( ";
                                 foreach ($valid_customer_ids as $valid_customer_id) {
                                     $where .= (int) $valid_customer_id . ", ";
                                 }
                                 $where = rtrim($where, ', ');
                                 $where .= " )";
                                 $where .= " )";
                             }
                     }
                     $res = qa($sql . $from . $where . " GROUP BY j.job_id");
                     foreach ($res as $job) {
                         if (!isset($job['c_total_amount_invoicable']) || $job['c_total_amount_invoicable'] < 0) {
                             $this->update_job_completion_status($job['job_id']);
                             // seed the cache
                             $job = $this->get_job($job['job_id']);
                         }
                         //$job = $this->get_job($r['job_id']);
                         //if($job && $job['job_id'] == $r['job_id'] && $job['total_amount_invoicable'] > 0 && module_invoice::can_i('create','Invoices')){
                         if (isset($job['c_total_amount_invoicable']) && $job['c_total_amount_invoicable'] > 0 && module_invoice::can_i('create', 'Invoices')) {
                             $alert_res = process_alert($job['date_completed'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($job['job_id'], false, $job);
                                 $alert_res['name'] = $job['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($job['date_completed']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                                 $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                                 $alert_res['invoicable_amount'] = currency($job['c_total_amount_invoicable'], true, $job['currency_id']);
                                 //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                                 $alert_res['date'] = print_date($alert_res['date']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts[] = $alert_res;
                             }
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_renew_alerts', 1)) {
                 // find any jobs that have a renew date soon and have not been renewed.
                 $key = _l('Job Renewal Pending');
                 $key_auto = _l('Automatic Job Renewal Pending');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'renewal_period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'renewal_period' => _l('Period'), 'date_create' => _l('Created Date'), 'date' => _l('Renewal Date'), 'renew_invoice' => _l('Automatic Invoice'), 'days' => _l('Day Count'));
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key_auto, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     /*$sql = "SELECT p.* FROM `"._DB_PREFIX."job` p ";
                       $sql .= " WHERE p.date_renew != '0000-00-00'";
                       $sql .= " AND p.date_renew <= '".date('Y-m-d',strtotime('+'.module_config::c('alert_days_in_future',5).' days'))."'";
                       $sql .= " AND (p.renew_job_id IS NULL OR p.renew_job_id = 0)";
                       $res = qa($sql);*/
                     $res = self::get_jobs(array(), array('custom_where' => " AND  u.date_renew != '0000-00-00' AND u.date_renew <= '" . date('Y-m-d', strtotime('+' . module_config::c('alert_days_in_future', 5) . ' days')) . "' AND (u.renew_job_id IS NULL OR u.renew_job_id = 0)"));
                     foreach ($res as $job) {
                         //$job = self::get_job($r['job_id']);
                         //if(!$job || $job['job_id']!=$r['job_id'])continue;
                         if ($job['renew_auto']) {
                             $alert_res = process_alert($job['date_renew'], $key_auto);
                         } else {
                             $alert_res = process_alert($job['date_renew'], $key);
                         }
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($job['job_id'], false, $job);
                             $alert_res['name'] = $job['name'];
                             $alert_res['renewal_period'] = _l('N/A');
                             // work out renewal period
                             if ($job['date_start'] && $job['date_start'] != '0000-00-00') {
                                 $time_diff = strtotime($job['date_renew']) - strtotime($job['date_start']);
                                 if ($time_diff > 0) {
                                     $diff_type = 'day';
                                     $days = round($time_diff / 86400);
                                     if ($days >= 365) {
                                         $time_diff = round($days / 365, 1);
                                         $diff_type = 'year';
                                     } else {
                                         $time_diff = $days;
                                     }
                                     $alert_res['renewal_period'] = $time_diff . ' ' . $diff_type;
                                 }
                             }
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($job['date_renew']);
                             if ($job['renew_auto']) {
                                 $alert_res['group'] = $key_auto;
                                 $alert_res['renew_invoice'] = $job['renew_invoice'] ? _l('Yes') : _l('No');
                             } else {
                                 $alert_res['group'] = $key;
                             }
                             $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                             $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                             $alert_res['date_create'] = print_date($job['date_start']);
                             $alert_res['date'] = print_date($job['date_renew']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if ($show_all || module_config::c('job_approval_alerts', 1)) {
                 $job_task_creation_permissions = self::get_job_task_creation_permissions();
                 if ($job_task_creation_permissions == _JOB_TASK_CREATION_WITHOUT_APPROVAL) {
                     // find any jobs that have tasks requiring approval
                     $key = _l('Tasks Require Approval');
                     if (class_exists('module_dashboard', false)) {
                         $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'task_count' => _l('Tasks to Approve'), 'date' => _l('Task Date'), 'days' => _l('Day Count'));
                         if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                             unset($columns['website']);
                         }
                         if (!module_customer::can_i('view', 'Customers')) {
                             unset($columns['customer']);
                         }
                         module_dashboard::register_group($key, array('columns' => $columns));
                     }
                     if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                         $alerts = array_merge($alerts, $cached_alerts);
                     } else {
                         module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                         $this_alerts = array();
                         $sql = "SELECT p.job_id,p.name, t.date_updated, t.date_created, COUNT(t.task_id) AS approval_count FROM `" . _DB_PREFIX . "job` p ";
                         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON p.job_id = t.job_id";
                         $sql .= " WHERE t.approval_required = 1";
                         $sql .= " GROUP BY p.job_id ";
                         $res = qa($sql);
                         foreach ($res as $r) {
                             $job = self::get_job($r['job_id']);
                             if (!$job || $job['job_id'] != $r['job_id']) {
                                 continue;
                             }
                             $alert_res = process_alert($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created'], $key);
                             if ($alert_res) {
                                 $alert_res['link'] = $this->link_open($r['job_id'], false, $r);
                                 $alert_res['name'] = $r['name'];
                                 // new dashboard alert layout here:
                                 $alert_res['time'] = strtotime($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created']);
                                 $alert_res['group'] = $key;
                                 $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                                 $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                                 $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                                 $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                                 //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                                 $alert_res['task_count'] = $r['approval_count'];
                                 $alert_res['date'] = print_date($alert_res['time']);
                                 $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                                 $this_alerts[] = $alert_res;
                             }
                         }
                         module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                         $alerts = array_merge($alerts, $this_alerts);
                     }
                 }
                 // find any rejected tasks
                 $key = _l('Tasks Have Been Rejected');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer'), 'website' => module_config::c('project_name_single', 'Website'), 'assigned_staff' => _l('Staff'), 'task_count' => _l('Tasks Rejected'), 'date' => _l('Task Date'), 'days' => _l('Day Count'));
                     if (!class_exists('module_website', false) || !module_website::is_plugin_enabled()) {
                         unset($columns['website']);
                     }
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $sql = "SELECT p.job_id,p.name, t.date_updated, t.date_created, COUNT(t.task_id) AS approval_count FROM `" . _DB_PREFIX . "job` p ";
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON p.job_id = t.job_id";
                     $sql .= " WHERE t.approval_required = 2";
                     $sql .= " GROUP BY p.job_id ";
                     $res = qa($sql);
                     foreach ($res as $r) {
                         $job = self::get_job($r['job_id']);
                         if (!$job || $job['job_id'] != $r['job_id']) {
                             continue;
                         }
                         $alert_res = process_alert($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created'], $key);
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($r['job_id'], false, $r);
                             $alert_res['name'] = $r['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($r['date_updated'] && $r['date_updated'] != '0000-00-00' ? $r['date_updated'] : $r['date_created']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($job['job_id'], true, $job);
                             $alert_res['customer'] = $job['customer_id'] ? module_customer::link_open($job['customer_id'], true) : _l('N/A');
                             $alert_res['website'] = $job['website_id'] ? module_website::link_open($job['website_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $job['user_id'] ? module_user::link_open($job['user_id'], true) : _l('N/A');
                             //$alert_res['progress'] = ($job['total_percent_complete'] * 100).'%';
                             $alert_res['task_count'] = $r['approval_count'];
                             $alert_res['date'] = print_date($alert_res['time']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             if (module_security::can_user(module_security::get_loggedin_id(), 'Show Dashboard Todo List')) {
                 $key = _l('Job Todo');
                 if (class_exists('module_dashboard', false)) {
                     $columns = array('job' => _l('Job Title'), 'customer' => _l('Customer Name'), 'progress' => _l('Task Progress'), 'task' => _l('Task Description'), 'assigned_staff' => _l('Staff'), 'date' => _l('Due Date'), 'days' => _l('Day Count'));
                     if (!module_customer::can_i('view', 'Customers')) {
                         unset($columns['customer']);
                     }
                     module_dashboard::register_group($key, array('columns' => $columns));
                 }
                 if ($cached_alerts = module_cache::get('job', $cache_key . $key)) {
                     $alerts = array_merge($alerts, $cached_alerts);
                 } else {
                     module_debug::log(array('title' => 'Job Home Alerts: ', 'data' => " starting: " . $key));
                     $this_alerts = array();
                     $todo_list = self::get_tasks_todo();
                     $x = 0;
                     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);
                         $alert_res = process_alert($todo_item['date_due'], 'temp');
                         if ($alert_res) {
                             $alert_res['link'] = $this->link_open($todo_item['job_id'], false, $job_data);
                             $alert_res['name'] = $percentage * 100 . '% ' . $todo_item['description'];
                             $alert_res['item'] = $job_data['name'];
                             // new dashboard alert layout here:
                             $alert_res['time'] = strtotime($alert_res['date']);
                             $alert_res['group'] = $key;
                             $alert_res['job'] = $this->link_open($todo_item['job_id'], true, $job_data);
                             $alert_res['customer'] = $job_data['customer_id'] ? module_customer::link_open($job_data['customer_id'], true) : _l('N/A');
                             $alert_res['assigned_staff'] = $todo_item['user_id'] ? module_user::link_open($todo_item['user_id'], true) : _l('N/A');
                             $alert_res['progress'] = $percentage * 100 . '%';
                             $alert_res['task'] = htmlspecialchars($todo_item['description']);
                             $alert_res['date'] = $alert_res['warning'] ? '<span class="important">' . print_date($alert_res['date']) . '</span>' : print_date($alert_res['date']);
                             $alert_res['days'] = $alert_res['warning'] ? '<span class="important">' . $alert_res['days'] . '</span>' : $alert_res['days'];
                             $this_alerts[] = $alert_res;
                         }
                     }
                     module_cache::put('job', $cache_key . $key, $this_alerts, $cache_timeout);
                     $alerts = array_merge($alerts, $this_alerts);
                 }
             }
             return $alerts;
             break;
     }
     return false;
 }
Exemplo n.º 10
0
            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();
            }
Exemplo n.º 11
0
        }
        if ($ticket['last_message_timestamp'] < $ticket['limit_time']) {
            echo '</span>';
        }
    }
});
$columns['ticket_type'] = array('title' => 'Type', 'callback' => function ($ticket) {
    echo htmlspecialchars($ticket['ticket_type']);
});
$columns['ticket_status'] = array('title' => 'Status', 'callback' => function ($ticket) {
    echo htmlspecialchars(module_ticket::$ticket_statuses[$ticket['status_id']]);
});
$columns['ticket_staff'] = array('title' => 'Staff', 'callback' => function ($ticket) {
    echo module_user::link_open($ticket['assigned_user_id'], true);
});
if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers') && module_config::c('ticket_list_show_customer', 1)) {
    $columns['ticket_customer'] = array('title' => 'Customer', 'callback' => function ($ticket) {
        echo module_customer::link_open($ticket['customer_id'], true);
    });
}
$columns['ticket_contact'] = array('title' => 'Contact', 'callback' => function ($ticket) {
    echo module_user::link_open($ticket['user_id'], true, array(), true);
});
if (class_exists('module_faq', false) && module_config::c('ticket_show_product_list', 1)) {
    $columns['ticket_product'] = array('title' => 'Product', 'callback' => function ($ticket) {
        if ($ticket['faq_product_id']) {
            $faq_product = module_faq::get_faq_product($ticket['faq_product_id']);
            echo $faq_product && isset($faq_product['name']) ? htmlspecialchars($faq_product['name']) : '';
        }
    });
}
Exemplo n.º 12
0
/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca, 0a3014a3-2b8f-460b-8850-d6025aa845f8
 * Package Date: 2015-11-25 03:08:08 
 * IP Address: 67.79.165.254
 */
if (class_exists('module_customer', false) && module_security::can_user(module_security::get_loggedin_id(), 'Show Dashboard Widgets')) {
    $customer_types = module_customer::get_customer_types();
    foreach ($customer_types as $customer_type) {
        // if(!empty($customer_type['type_name_plural']) && $customer_type['customer_type_id']) { // dtbaker
        if (!empty($customer_type['type_name_plural'])) {
            // dtbaker
            if (module_customer::can_i('view', $customer_type['type_name_plural'])) {
                // find out how many open customers are left..
                $customers = module_customer::get_customers(array('customer_type_id' => $customer_type['customer_type_id']), true);
                ob_start();
                // icons from http://ionicons.com/
                ?>

				<div class="small-box bg-yellow">
					<div class="inner">
						<h3>
							<?php 
                echo mysql_num_rows($customers);
                ?>
						</h3>
						<p>
							<?php 
Exemplo n.º 13
0
 public function save_customer($customer_id, $data)
 {
     $customer_id = (int) $customer_id;
     $temp_customer = false;
     if ($customer_id > 0) {
         // check permissions
         $temp_customer = $this->get_customer($customer_id);
         if (!$temp_customer || $temp_customer['customer_id'] != $customer_id) {
             $temp_customer = false;
             $customer_id = false;
         }
     }
     if (_DEMO_MODE && $customer_id == 1) {
         set_error('Sorry this is a Demo Customer. It cannot be changed.');
         redirect_browser(self::link_open($customer_id));
     }
     if (isset($data['default_tax_system']) && $data['default_tax_system']) {
         $data['default_tax'] = -1;
         $data['default_tax_name'] = '';
     }
     if (isset($data['primary_user_id'])) {
         unset($data['primary_user_id']);
     }
     // only allow this to be set through the method.
     $customer_id = update_insert("customer_id", $customer_id, "customer", $data);
     if (isset($data['single_staff_id']) && (int) $data['single_staff_id'] > 0 && module_customer::get_customer_data_access() == _CUSTOMER_ACCESS_STAFF && $data['single_staff_id'] == module_security::get_loggedin_id()) {
         $sql = "REPLACE INTO `" . _DB_PREFIX . "customer_user_rel` SET ";
         $sql .= " `user_id` = " . (int) $data['single_staff_id'];
         $sql .= ", `customer_id` = " . (int) $customer_id;
         query($sql);
     } else {
         if (isset($data['staff_ids']) && is_array($data['staff_ids']) && module_customer::can_i('edit', 'Customer Staff')) {
             $existing_staff = array();
             if ($temp_customer) {
                 $existing_staff = $temp_customer['staff_ids'];
             }
             foreach ($data['staff_ids'] as $staff_id) {
                 $sql = "REPLACE INTO `" . _DB_PREFIX . "customer_user_rel` SET ";
                 $sql .= " `user_id` = " . (int) $staff_id;
                 $sql .= ", `customer_id` = " . (int) $customer_id;
                 $key = array_search($staff_id, $existing_staff);
                 if ($key !== false) {
                     unset($existing_staff[$key]);
                 }
                 query($sql);
             }
             foreach ($existing_staff as $staff_id) {
                 delete_from_db('customer_user_rel', array('user_id', 'customer_id'), array($staff_id, $customer_id));
             }
         }
     }
     if (isset($_REQUEST['user_id'])) {
         $user_id = (int) $_REQUEST['user_id'];
         if ($user_id > 0) {
             // check permissions
             $temp_user = module_user::get_user($user_id);
             if (!$temp_user || $temp_user['user_id'] != $user_id) {
                 $user_id = false;
             }
         }
         // assign specified user_id to this customer.
         // could this be a problem?
         // maybe?
         // todo: think about security precautions here, maybe only allow admins to set primary contacts.
         $data['customer_id'] = $customer_id;
         if (!$user_id) {
             // hack to set the default role of a contact (if one is set in settings).
             if (!isset($data['last_name']) && isset($data['name']) && strpos($data['name'], ' ') > 0) {
                 // todo - save from customer import
                 $bits = explode(' ', $data['name']);
                 $data['last_name'] = array_pop($bits);
                 $data['name'] = implode(' ', $bits);
             }
             global $plugins;
             $user_id = $plugins['user']->create_user($data, 'contact');
             //$user_id = update_insert("user_id",false,"user",$data);
             //module_cache::clear('user');
             $role_id = module_config::c('contact_default_role', 0);
             if ($role_id > 0) {
                 module_user::add_user_to_role($user_id, $role_id);
             }
             $this->set_primary_user_id($customer_id, $user_id);
         } else {
             // make sure this user is part of this customer.
             // wait! addition, we want to be able to move an existing customer contact to this new customer.
             $saved_user_id = false;
             if (isset($_REQUEST['move_user_id']) && (int) $_REQUEST['move_user_id'] && module_customer::can_i('create', 'Active Leads')) {
                 $old_user = module_user::get_user((int) $_REQUEST['move_user_id']);
                 if ($old_user && $old_user['user_id'] == (int) $_REQUEST['move_user_id']) {
                     $saved_user_id = $user_id = update_insert("user_id", $user_id, "user", $data);
                     module_cache::clear('user');
                     hook_handle_callback('customer_contact_moved', $user_id, $old_user['customer_id'], $customer_id);
                     $this->set_primary_user_id($customer_id, $user_id);
                     module_cache::clear('user');
                 }
             } else {
                 // save normally, only those linked to this account:
                 $users = module_user::get_contacts(array('customer_id' => $customer_id));
                 foreach ($users as $user) {
                     if ($user['user_id'] == $user_id) {
                         $saved_user_id = $user_id = update_insert("user_id", $user_id, "user", $data);
                         $this->set_primary_user_id($customer_id, $user_id);
                         module_cache::clear('user');
                         break;
                     }
                 }
             }
             if (!$saved_user_id) {
                 $this->set_primary_user_id($customer_id, 0);
                 module_cache::clear('user');
             }
         }
         // todo: move this functionality back into the user class.
         // maybe with a static save_user method ?
         if ($user_id > 0 && class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
             module_extra::save_extras('user', 'user_id', $user_id);
         }
     }
     handle_hook("address_block_save", $this, "physical", "customer", "customer_id", $customer_id);
     //handle_hook("address_block_save",$this,"postal","customer","customer_id",$customer_id);
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::save_extras('customer', 'customer_id', $customer_id);
     }
     // save the company information if it's available
     if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
         if (isset($_REQUEST['available_customer_company']) && is_array($_REQUEST['available_customer_company'])) {
             $selected_companies = isset($_POST['customer_company']) && is_array($_POST['customer_company']) ? $_POST['customer_company'] : array();
             $company_access = module_company::get_company_data_access();
             if ($company_access == _COMPANY_ACCESS_ALL && !count($selected_companies)) {
                 // user is unassignging this customer from all companies we have access to, dont let them do this?
             }
             foreach ($_REQUEST['available_customer_company'] as $company_id => $tf) {
                 if (!isset($selected_companies[$company_id]) || !$selected_companies[$company_id]) {
                     // remove customer from this company
                     module_company::delete_customer($company_id, $customer_id);
                 } else {
                     // add customer to this company (if they are not already existing)
                     module_company::add_customer_to_company($company_id, $customer_id);
                 }
             }
         }
     }
     self::update_customer_status($customer_id);
     module_cache::clear('customer');
     return $customer_id;
 }
Exemplo n.º 14
0
">
		</td>
		<td width="60">
            <?php 
_e('Address:');
?>

		</td>
		<td>
			<input type="text" style="width: 180px;" name="search[address]" class="" value="<?php 
echo isset($search['address']) ? htmlspecialchars($search['address']) : '';
?>
">
		</td>
        <?php 
if (class_exists('module_group', false) && module_customer::can_i('view', 'Customer Groups')) {
    ?>

        <td width="60">
            <?php 
    _e('Group:');
    ?>

        </td>
        <td>
            <?php 
    echo print_select_box(module_group::get_groups('customer'), 'search[group_id]', isset($search['group_id']) ? $search['group_id'] : false, '', true, 'name');
    ?>

        </td>
        <?php 
Exemplo n.º 15
0
            $note_summary_owners['website'][] = $val['website_id'];
        }
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['job'][] = $val['job_id'];
            foreach (module_invoice::get_invoices(array('job_id' => $val['job_id'])) as $val) {
                $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
            }
        }
    }
    if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
        foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
        }
    }
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'All ' . $page_type_single . ' Notes', 'owner_table' => 'customer', 'owner_id' => $customer_id, 'view_link' => $module->link_open($customer_id), 'display_summary' => true, 'summary_owners' => $note_summary_owners));
    }
}
hook_handle_callback('customer_edit', $customer_id);
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'onclick' => "\$('#form_redirect').val('" . $module->link_open(false) . "');", 'value' => _l('Save and Return')), array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save')), array('ignore' => !(module_customer::can_i('delete', 'Customers') && $customer_id > 0), '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->link_open(false) . "';")));
echo module_form::generate_form_actions($form_actions);
?>



</form>

Exemplo n.º 16
0
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
$page_type = 'Active Leads';
$page_type_single = 'Active Lead';
$current_customer_type_id = module_customer::get_current_customer_type_id();
if ($current_customer_type_id > 0) {
    $customer_type = module_customer::get_customer_type($current_customer_type_id);
    if ($customer_type && !empty($customer_type['type_name'])) {
        $page_type = $customer_type['type_name_plural'];
        $page_type_single = $customer_type['type_name'];
    }
}
$module->page_title = $page_type_single;
if (!module_customer::can_i('view', $page_type)) {
    redirect_browser(_BASE_HREF);
}
if (isset($customer_id)) {
    // we're coming here a second time
}
$links = array();
$customer_id = $_REQUEST['customer_id'];
if ($customer_id && $customer_id != 'new') {
    $customer = module_customer::get_customer($customer_id);
    // we have to load the menu here for the sub plugins under customer
    // set default links to show in the bottom holder area.
    if (!$customer || $customer['customer_id'] != $customer_id) {
        redirect_browser('');
    }
    $class = '';