Exemplo n.º 1
0
            <?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>
        <td>
            <?php 
    echo module_customer::link_open($job_data['customer_id'], true);
    ?>

        </td>
        <td>
            <?php 
    echo htmlspecialchars($original_job_data['type']);
    ?>

        </td>
        <td>
            <?php 
    echo print_date($original_job_data['date_start']);
    //is there a renewal date?
    if (isset($original_job_data['date_renew']) && $original_job_data['date_renew'] && $original_job_data['date_renew'] != '0000-00-00') {
        _e(' to %s', print_date(strtotime("-1 day", strtotime($original_job_data['date_renew']))));
Exemplo n.º 2
0
include module_theme::include_ucm('includes/plugin_quote/template/quote_task_list.php');
$public_html = ob_get_clean();
$quote['task_list'] = $public_html;
/*ob_start();
$quote_data = $quote;
$ignore_task_hook=true;
$for_email=true;
include('quote_public.php');
$quote['quote_tasks'] = ob_get_clean();*/
// generate the PDF ready for sending.
$pdf = module_quote::generate_pdf($quote_id);
// find available "to" recipients.
// customer contacts.
$to_select = false;
if ($quote['customer_id']) {
    $customer = module_customer::get_customer($quote['customer_id']);
    $quote['customer_name'] = $customer['customer_name'];
    $to = module_user::get_contacts(array('customer_id' => $quote['customer_id']));
    if ($quote['contact_user_id']) {
        $primary = module_user::get_user($quote['contact_user_id']);
        if ($primary) {
            $to_select = $primary['email'];
        }
    } else {
        if ($customer['primary_user_id']) {
            $primary = module_user::get_user($customer['primary_user_id']);
            if ($primary) {
                $to_select = $primary['email'];
            }
        }
    }
Exemplo n.º 3
0
    echo module_user::link_open_contact($user['user_id'], true, $user);
    if ($user['is_primary'] == $user['user_id']) {
        echo ' *';
    }
}, 'cell_class' => 'row_action');
$columns['phone'] = array('title' => 'Phone Number', 'callback' => function ($user) {
    module_user::print_contact_summary($user['user_id'], 'html', array('phone|mobile'));
});
$columns['email'] = array('title' => 'Email Address', 'callback' => function ($user) {
    module_user::print_contact_summary($user['user_id'], 'html', array('email'));
});
if ($show_customer_details) {
    $columns['customer'] = array('title' => $contact_type_permission, 'callback' => function ($user) use($contact_module_name) {
        switch ($contact_module_name) {
            case 'customer':
                echo module_customer::link_open($user['customer_id'], true, $user);
                break;
            case 'vendor':
                echo module_vendor::link_open($user['vendor_id'], true, $user);
                break;
        }
    });
}
if (class_exists('module_group', false) && module_user::can_i('view', 'Contact Groups')) {
    $columns['group'] = array('title' => 'Group', 'callback' => function ($user) {
        $groups = module_group::get_groups_search(array('owner_table' => 'user', 'owner_id' => $user['user_id']));
        $g = array();
        foreach ($groups as $group) {
            $g[] = $group['name'];
        }
        echo implode(', ', $g);
Exemplo n.º 4
0
 public static function get_finances($search = array())
 {
     // we have to search for recent transactions. this involves combining the "finance" table with the "invoice_payment" table
     // then sort the results by date
     $hide_invoice_payments = false;
     $sql = "SELECT f.* ";
     $sql .= " , fa.name AS account_name ";
     $sql .= " , GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') AS categories ";
     $sql .= " FROM `" . _DB_PREFIX . "finance` f ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa USING (finance_account_id) ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category_rel` fcr ON f.finance_id = fcr.finance_id ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id ";
     $where = " WHERE 1 ";
     if (isset($search['finance_account_id']) && is_array($search['finance_account_id'])) {
         $fo = array();
         foreach ($search['finance_account_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " f.finance_account_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['finance_recurring_id']) && $search['finance_recurring_id']) {
         $where .= " AND f.finance_recurring_id = '" . (int) $search['finance_recurring_id'] . "'";
         $hide_invoice_payments = true;
     }
     if (isset($search['finance_category_id']) && is_array($search['finance_category_id'])) {
         $fo = array();
         foreach ($search['finance_category_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND EXISTS ( SELECT * FROM `" . _DB_PREFIX . "finance_category_rel` fcr2 WHERE fcr2.finance_id = f.finance_id AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " fcr2.finance_category_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['invoice_payment_id']) && $search['invoice_payment_id']) {
         $where .= " AND f.invoice_payment_id = '" . (int) $search['invoice_payment_id'] . "'";
         $hide_invoice_payments = true;
     }
     // below 6 searches are repeated again below in invoice payments
     if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
         $where .= " AND f.`job_id` = " . (int) $search['job_id'];
     }
     if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
         $where .= " AND f.`invoice_id` = " . (int) $search['invoice_id'];
     }
     if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
         $where .= " AND f.`customer_id` = " . (int) $search['customer_id'];
     }
     if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
         // check this user can view this company id or not
         if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
             $companys = module_company::get_companys();
             if (isset($companys[$search['company_id']])) {
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON f.customer_id = cc.customer_id ";
                 $where .= " AND ( cc.`company_id` = " . (int) $search['company_id'] . " OR  f.`company_id` = " . (int) $search['company_id'] . " )";
             }
         }
     }
     if (isset($search['generic']) && strlen(trim($search['generic']))) {
         $name = mysql_real_escape_string(trim($search['generic']));
         $where .= " AND (f.`name` LIKE '%{$name}%' OR f.description LIKE '%{$name}%' )";
     }
     if (isset($search['date_from']) && $search['date_from'] != '') {
         $where .= " AND f.transaction_date >= '" . input_date($search['date_from']) . "'";
     }
     if (isset($search['date_to']) && $search['date_to'] != '') {
         $where .= " AND f.transaction_date <= '" . input_date($search['date_to']) . "'";
     }
     if (isset($search['amount_from']) && $search['amount_from'] != '') {
         $where .= " AND f.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
     }
     if (isset($search['amount_to']) && $search['amount_to'] != '') {
         $where .= " AND f.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
     }
     if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
         $where .= " AND f.type = '" . mysql_real_escape_string($search['type']) . "'";
     }
     // permissions from job module.
     /*switch(module_job::get_job_access_permissions()){
                 case _JOB_ACCESS_ALL:
     
                     break;
                 case _JOB_ACCESS_ASSIGNED:
                     // only assigned jobs!
                     //$from .= " LEFT JOIN `"._DB_PREFIX."task` t ON u.job_id = t.job_id ";
                     //u.user_id = ".(int)module_security::get_loggedin_id()." OR
                     $where .= " AND (t.user_id = ".(int)module_security::get_loggedin_id().")";
                     break;
                 case _JOB_ACCESS_CUSTOMER:
                     break;
             }*/
     // permissions from customer module.
     // tie in with customer permissions to only get jobs from customers we can access.
     switch (module_customer::get_customer_data_access()) {
         case _CUSTOMER_ACCESS_ALL:
             // all customers! so this means all jobs!
             break;
         case _CUSTOMER_ACCESS_ALL_COMPANY:
         case _CUSTOMER_ACCESS_CONTACTS:
         case _CUSTOMER_ACCESS_TASKS:
         case _CUSTOMER_ACCESS_STAFF:
             $valid_customer_ids = module_security::get_customer_restrictions();
             if (count($valid_customer_ids)) {
                 $where .= " AND f.customer_id IN ( ";
                 foreach ($valid_customer_ids as $valid_customer_id) {
                     $where .= (int) $valid_customer_id . ", ";
                 }
                 $where = rtrim($where, ', ');
                 $where .= " )";
             }
     }
     $where .= " GROUP BY f.finance_id ";
     $where .= " ORDER BY f.transaction_date DESC ";
     $sql .= $where;
     $finances_from_finance_db_table = qa($sql);
     // invoice payments:
     $finance_from_invoice_payments = array();
     $finance_from_job_staff_expenses = array();
     if (!$hide_invoice_payments && (!isset($search['invoice_id']) || !(int) $search['invoice_id'] > 0)) {
         $sql = "SELECT j.*, f.finance_id AS existing_finance_id ";
         $sql .= " FROM `" . _DB_PREFIX . "job` j ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON j.job_id = f.job_id AND f.job_staff_expense > 0 ";
         $where = " WHERE 1 ";
         //j.date_completed != '0000-00-00' ";
         $where .= " AND j.`c_staff_total_amount` > 0 ";
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $where .= " AND (j.`job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND j.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON j.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             $where .= " AND j.date_completed >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             $where .= " AND j.date_completed <= '" . input_date($search['date_to']) . "'";
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND j.c_staff_total_amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND j.c_staff_total_amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         switch (module_job::get_job_access_permissions()) {
             case _JOB_ACCESS_ALL:
                 break;
             case _JOB_ACCESS_ASSIGNED:
                 // only assigned jobs!
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON j.job_id = t.job_id ";
                 $where .= " AND (j.user_id = " . (int) module_security::get_loggedin_id() . " OR t.user_id = " . (int) module_security::get_loggedin_id() . ")";
                 break;
             case _JOB_ACCESS_CUSTOMER:
                 // tie in with customer permissions to only get jobs from customers we can access.
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
                 break;
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " GROUP BY j.job_id ORDER BY j.date_completed DESC ";
         //echo $sql;
         $finance_from_job_staff_expenses = array();
         $res = qa($sql);
         foreach ($res as $finance) {
             // we have a job with staff expenses. split this up into gruops based on staff members.
             $staff_total_grouped = false;
             if (isset($finance['c_staff_total_grouped']) && strlen($finance['c_staff_total_grouped'])) {
                 $staff_total_grouped = @unserialize($finance['c_staff_total_grouped']);
             }
             if ($staff_total_grouped === false) {
                 //	                echo 'here: ';
                 //	                var_dump($finance);
                 //	                var_dump($staff_total_grouped);
                 $job_data = module_job::get_job($finance['job_id']);
                 $staff_total_grouped = $job_data['staff_total_grouped'];
             }
             if (is_array($staff_total_grouped)) {
                 foreach ($staff_total_grouped as $staff_id => $staff_total) {
                     $staff_member = module_user::get_user($staff_id);
                     if ($staff_member && $staff_member['user_id'] == $staff_id) {
                         // make sure this entry doesn't already exist in the database table for this job
                         // there MAY be an existing entry if 'existing_finance_id' is set
                         if ($finance['existing_finance_id'] > 0) {
                             // check if it exists for this staff member.
                             $existing = get_single('finance', array('job_id', 'job_staff_expense', 'amount'), array($finance['job_id'], $staff_id, $staff_total));
                             if ($existing) {
                                 // match exists already, skip adding this one to the list.
                                 continue;
                             }
                         }
                         //$finance = self::_format_invoice_payment($finance, $finance);
                         //$finance['url'] = module_job::link_open($finance['job_id'],false,$finance);
                         $finance['url'] = module_finance::link_open('new', false) . '&job_staff_expense=' . $staff_id . '&from_job_id=' . $finance['job_id'];
                         $finance['transaction_date'] = $finance['date_completed'];
                         $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']);
                         //"Exiting: ".$finance['existing_finance_id'].": ".
                         $finance['amount'] = $staff_total;
                         $finance['debit'] = $staff_total;
                         $finance['sub_amount'] = $staff_total;
                         $finance['taxable_amount'] = $staff_total;
                         $finance['credit'] = 0;
                         $finance['type'] = 'e';
                         $finance_from_job_staff_expenses[] = $finance;
                     }
                 }
             }
         }
     }
     if (!$hide_invoice_payments) {
         $sql = "SELECT p.*, i.customer_id ";
         if (module_config::c('finance_date_type', 'payment') == 'invoice') {
             // show entries by invoice create date, not payment date.
             $sql .= " , i.date_create AS transaction_date ";
         } else {
             // default, show by paid date.
             $sql .= " , p.date_paid AS transaction_date ";
         }
         $sql .= " FROM `" . _DB_PREFIX . "invoice_payment` p ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON p.invoice_id = i.invoice_id ";
         $where = " WHERE p.date_paid != '0000-00-00' ";
         $where .= " AND p.`amount` != 0 ";
         $where .= " AND ( p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_NORMAL . " OR p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_REFUND . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_CREDIT . ')';
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id";
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id";
             $where .= " AND (t.`job_id` = " . (int) $search['job_id'] . " OR i.`deposit_job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
             $where .= " AND p.`invoice_id` = " . (int) $search['invoice_id'];
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND i.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON i.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create >= '" . input_date($search['date_from']) . "'";
             } else {
                 $where .= " AND p.date_paid >= '" . input_date($search['date_from']) . "'";
             }
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create <= '" . input_date($search['date_to']) . "'";
             } else {
                 $where .= " AND p.date_paid <= '" . input_date($search['date_to']) . "'";
             }
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND p.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND p.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
             if ($search['type'] == 'i') {
                 $where .= " AND p.amount > 0";
             } else {
                 if ($search['type'] == 'e') {
                     $where .= " AND p.amount < 0";
                 }
             }
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND i.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " ORDER BY p.date_paid DESC ";
         //echo $sql;
         $finance_from_invoice_payments = qa($sql);
         foreach ($finance_from_invoice_payments as $finance_id => $finance) {
             // doesn't have an finance / account reference just yet.
             // but they can create one and this will become a child entry to it.
             $finance = self::_format_invoice_payment($finance, $finance);
             /*if(!isset($finance['customer_id']) || !$finance['customer_id']){
                   $invoice_data = module_invoice::get_invoice($finance['invoice_id'],2);
                   $finance['customer_id'] = $invoice_data['customer_id'];
               }*/
             // grab a new name/descriptino/etc.. from other plugins (at the moment only subscription)
             /*$new_finance = hook_handle_callback('finance_invoice_listing',$finance['invoice_id'],$finance);
               if(is_array($new_finance) && count($new_finance)){
                   foreach($new_finance as $n){
                       $finance = array_merge($finance,$n);
                   }
               }*/
             $finance_from_invoice_payments[$finance_id] = $finance;
         }
         if (isset($search['generic']) && strlen(trim($search['generic']))) {
             $name = mysql_real_escape_string(trim($search['generic']));
             //                $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
             // we have to do a PHP search here because
             foreach ($finance_from_invoice_payments as $finance_id => $finance) {
                 if (stripos($finance['name'], $name) === false && stripos($finance['description'], $name) === false) {
                     unset($finance_from_invoice_payments[$finance_id]);
                 }
             }
         }
     }
     $finances = array_merge($finances_from_finance_db_table, $finance_from_invoice_payments, $finance_from_job_staff_expenses);
     unset($finances_from_finance_db_table);
     unset($finance_from_invoice_payments);
     unset($finance_from_job_staff_expenses);
     // sort this
     if (!function_exists('sort_finance')) {
         function sort_finance($a, $b)
         {
             $t1 = strtotime($a['transaction_date']);
             $t2 = strtotime($b['transaction_date']);
             if ($t1 == $t2) {
                 // sort by finance id, putting ones with a finance id first before others. then amount.
                 if (isset($a['finance_id']) && !isset($b['finance_id'])) {
                     // put $a before $b
                     return -1;
                 } else {
                     if (!isset($a['finance_id']) && isset($b['finance_id'])) {
                         // put $b before $a
                         return 1;
                     } else {
                         return $a['amount'] > $b['amount'];
                     }
                 }
             } else {
                 return $t1 < $t2;
             }
         }
     }
     uasort($finances, 'sort_finance');
     foreach ($finances as $finance_id => $finance) {
         // we load each of these transactions
         // transaction can be a "transaction" or an "invoice_payment"
         // find out if this transaction is a child transaction to another transaction.
         // if it is a child transaction and we haven't already dispayed it in this listing
         // then we find the parent transaction and display it along with all it's children in this place.
         // this wont be perfect all the time but will be awesome in 99% of cases.
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             // displayed before already?
             if (isset($displayed_finance_ids[$finance['finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
             }
             $displayed_finance_ids[$finance['finance_id']] = $finance_id;
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id']) {
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             }
         } else {
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']) {
                 // this is an invoice payment (incoming payment)
                 // displayed before already?
                 if (isset($displayed_invoice_payment_ids[$finance['invoice_payment_id']])) {
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]] = array_merge($finance, $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]);
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]['link_count']++;
                     unset($finances[$finance_id]);
                     continue;
                 }
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             } else {
                 if (isset($finance['c_staff_total_amount'])) {
                     // staff expense.
                 } else {
                     // nfi?
                     unset($finances[$finance_id]);
                     continue;
                 }
             }
         }
         if (isset($finance['parent_finance_id']) && $finance['parent_finance_id']) {
             // check if it's parent finance id has been displayed already somewhere.
             if (isset($displayed_finance_ids[$finance['parent_finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['parent_finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
                 // already done it on this page.
             }
             $displayed_finance_ids[$finance['parent_finance_id']] = $finance_id;
             // we haven't displayed the parent one yet.
             // display the parent one in this listing.
             $finance = self::get_finance($finance['parent_finance_id']);
         }
         /*if(isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']){
               // moved to above.
           }else*/
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             $finance['url'] = self::link_open($finance['finance_id'], false);
             $finance['credit'] = $finance['type'] == 'i' ? $finance['amount'] : 0;
             $finance['debit'] = $finance['type'] == 'e' ? $finance['amount'] : 0;
             if (!isset($finance['categories'])) {
                 $finance['categories'] = '';
             }
             if (!isset($finance['account_name'])) {
                 $finance['account_name'] = '';
             }
         }
         if (isset($finance['taxes']) && !isset($finance['sub_amount'])) {
             $finance['sub_amount'] = $finance['amount'];
             foreach ($finance['taxes'] as $tax) {
                 if (isset($tax['amount'])) {
                     $finance['sub_amount'] -= $tax['amount'];
                 }
             }
         }
         $finance['link_count'] = 0;
         $finances[$finance_id] = $finance;
     }
     return $finances;
 }
Exemplo n.º 5
0
                                         if(currentuser_key){
                                             $('#change_user_id').append($("<option></option>")
                                                 .attr("value", currentuser_key).text(currentuser_val));
                                             $('#change_user_id').val(currentuser_key);
                                         }
                                     },
                                     fail: function(){
                                         alert('Changing customer failed, please refresh and try again.');
                                     }
                                 });
                             });
                         });
                     </script> -->
                     <?php 
     } else {
         echo module_customer::link_open($ticket['customer_id'], true);
     }
     /*$c = array();
       $res = module_customer::get_customers();
       while($row = array_shift($res)){
           $c[$row['customer_id']] = $row['customer_name'];
       }
       if(false && module_ticket::can_i('edit','Related to','Tickets')){
           echo print_select_box($c,'customer_id',$ticket['customer_id']);
       }else if($ticket['customer_id']){
           echo isset($c[$ticket['customer_id']]) ? $c[$ticket['customer_id']] : 'N/A';
       }*/
 }));
 if ($ticket['customer_id'] && $ticket_id > 0) {
     $fieldset_data['elements'][] = array('title' => _l('Contact'), 'fields' => array(function () use($ticket_id, $ticket) {
         if (module_ticket::can_edit_tickets() && isset($_REQUEST['show_change_contact'])) {
Exemplo n.º 6
0
 public static function email_invoice_to_customer($invoice_id, $debug = false)
 {
     // this is a copy of some of the code in invoie_admin_email.php
     // used in the CRON job when sending out automated emails.
     $invoice = module_invoice::get_invoice($invoice_id);
     // template for sending emails.
     // are we sending the paid one? or the dueone.
     $template_name = '';
     $template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email';
     if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) {
         $template_name = 'credit_note_email';
     } else {
         if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
             $template_name = $template_prefix . '_paid';
         } else {
             if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                 $template_name = $template_prefix . '_overdue';
             } else {
                 $template_name = $template_prefix . '_due';
             }
         }
     }
     $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice);
     if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) {
         module_company::set_current_company_id($invoice_data['company_id']);
     }
     $template = module_template::get_template_by_key($template_name);
     if (!$template || $template->template_key != $template_name) {
         // backup default templates incase someone has chosen a template that doesn't exist (eg: created invoice_email_MINE_due but not invoice_email_MINE_paid )
         $template_prefix = 'invoice_email';
         if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
             $template_name = $template_prefix . '_paid';
         } else {
             if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                 $template_name = $template_prefix . '_overdue';
             } else {
                 $template_name = $template_prefix . '_due';
             }
         }
     }
     $replace = module_invoice::get_replace_fields($invoice_id, $invoice);
     if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) {
         $pdf = false;
     } else {
         $pdf = module_invoice::generate_pdf($invoice_id);
     }
     $send_email_to = array();
     $to = array();
     if ($invoice['customer_id']) {
         $customer = module_customer::get_customer($invoice['customer_id']);
         $replace['customer_name'] = $customer['customer_name'];
         if ($invoice['user_id']) {
             // this invoice has a manually assigned user, only send the invoice to this user.
             // todo: should we also send to accounts? not sure - see if peopel complain
             $primary = module_user::get_user($invoice['user_id']);
             if ($primary) {
                 $send_email_to[] = $primary;
             }
         } else {
             $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id']));
             // hunt for 'accounts' extra field
             $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts'));
             foreach ($to as $contact) {
                 $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id']));
                 foreach ($extras as $e) {
                     if (strtolower($e['extra_key']) == $field_to_find) {
                         // this is the accounts contact - woo!
                         $send_email_to[] = $contact;
                     }
                 }
             }
             if (!count($send_email_to) && $customer['primary_user_id']) {
                 $primary = module_user::get_user($customer['primary_user_id']);
                 if ($primary) {
                     $send_email_to[] = $primary;
                 }
             }
         }
     } else {
         if ($invoice['member_id']) {
             $member = module_member::get_member($invoice['member_id']);
             $to = array($member);
             $replace['customer_name'] = $member['first_name'];
         } else {
             $to = array();
         }
     }
     $template->assign_values($replace);
     $html = $template->render('html');
     // send an email to this user.
     $email = module_email::new_email();
     $email->replace_values = $replace;
     // todo: send to all customer contacts ?
     if ($send_email_to) {
         foreach ($send_email_to as $send_email_t) {
             if (!empty($send_email_t['user_id'])) {
                 $email->set_to('user', $send_email_t['user_id']);
             } else {
                 if (!empty($send_email_t['email'])) {
                     $email->set_to_manual($send_email_t['email']);
                 }
             }
         }
     } else {
         foreach ($to as $t) {
             if (!empty($t['user_id'])) {
                 $email->set_to('user', $t['user_id']);
             } else {
                 if (!empty($t['email'])) {
                     $email->set_to_manual($t['email']);
                 }
             }
             break;
             // only 1? todo: all?
         }
     }
     $email->set_bcc_manual(module_config::c('admin_email_address', ''), '');
     //$email->set_from('user',); // nfi
     $email->set_subject($template->description);
     // do we send images inline?
     $email->set_html($html);
     if ($pdf) {
         $email->add_attachment($pdf);
     }
     $email->invoice_id = $invoice_id;
     $email->customer_id = $invoice['customer_id'];
     $email->prevent_duplicates = true;
     if ($email->send($debug)) {
         // it worked successfully!!
         // record a log on the invoice when it's done.
         self::email_sent(array('invoice_id' => $invoice_id, 'template_name' => $template_name));
         return true;
     } else {
         /// log err?
         return false;
     }
 }
Exemplo n.º 7
0
if (isset($user['customer_id']) && $user['customer_id'] || isset($user['vendor_id']) && $user['vendor_id']) {
    // we have a contact!
    die('Wrong file');
} else {
    $use_master_key = false;
    // we have a normal site user..
}
// find a contact with matching email address.
if (isset($user['email']) && strlen($user['email']) > 3) {
    $contacts = module_user::get_contacts(array('email' => $user['email']));
    if (count($contacts) > 0) {
        foreach ($contacts as $c) {
            ?>

        <div class="warning"><?php 
            _e('Warning: a contact from the Customer %s exists with this same email address: %s <br/>This may create problems when trying to login. <br/>We suggest you remove/change THIS user account and use the existing CONTACT account instead.', module_customer::link_open($c['customer_id'], true), module_user::link_open_contact($c['user_id'], true));
            ?>
</div>
        <?php 
        }
    }
}
?>




<form action="" method="post" autocomplete="off">
	<input type="hidden" name="_process" value="save_user" />
	<!-- <input type="hidden" name="_redirect" value="<?php 
echo $module->link("", array("saved" => true, "user_id" => (int) $user_id ? $user_id : ''));
Exemplo n.º 8
0
 public static function get_customer_restrictions()
 {
     if (!self::is_logged_in()) {
         return array(-1 => -1);
     }
     /*
     new feature: we use this function instead of our hardcoded:
     switch($customer_access){
         case _CUSTOMER_ACCESS_ALL:
         case _CUSTOMER_ACCESS_CONTACTS:
         case _CUSTOMER_ACCESS_TASKS:
         case _CUSTOMER_ACCESS_STAFF:
     }
     through out the system.
     */
     /*$res = (isset($_SESSION['_restrict_customer_id'])) ? $_SESSION['_restrict_customer_id'] : false;
       if(!is_array($res) && $res > 0){
           $res = array($res);
       }*/
     if (isset(self::$customer_restrictions[module_security::get_loggedin_id()])) {
         return self::$customer_restrictions[module_security::get_loggedin_id()];
     }
     self::$customer_restrictions[module_security::get_loggedin_id()] = array();
     $customers = module_customer::get_customers(array(), array('columns' => 'c.customer_id', 'as_resource' => false));
     if (count($customers) > 0) {
         foreach ($customers as $customer) {
             self::$customer_restrictions[module_security::get_loggedin_id()][$customer['customer_id']] = $customer['customer_id'];
         }
     } else {
         self::$customer_restrictions[module_security::get_loggedin_id()] = array(-1 => -1);
     }
     return self::$customer_restrictions[module_security::get_loggedin_id()];
 }
Exemplo n.º 9
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.º 10
0
 public static function handle_import_row($row, $debug, $add_to_group, $extra_options)
 {
     $debug_string = '';
     if (isset($row['job_id']) && (int) $row['job_id'] > 0) {
         // check if this ID exists.
         $job = self::get_job($row['job_id']);
         if (!$job || $job['job_id'] != $row['job_id']) {
             $row['job_id'] = 0;
         }
     }
     if (!isset($row['job_id']) || !$row['job_id']) {
         $row['job_id'] = 0;
     }
     if (!isset($row['name']) || !strlen($row['name'])) {
         $debug_string .= _l('No job data to import');
         if ($debug) {
             echo $debug_string;
         }
         return false;
     }
     // duplicates.
     //print_r($extra_options);exit;
     if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && (int) $row['job_id'] > 0) {
         if ($debug) {
             $debug_string .= _l('Skipping import, duplicate of job %s', self::link_open($row['job_id'], true));
             echo $debug_string;
         }
         // don't import duplicates
         return false;
     }
     $row['customer_id'] = 0;
     // todo - support importing of this id? nah
     if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0) {
         // check if this customer exists.
         $customer = get_single('customer', 'customer_name', $row['customer_name']);
         if ($customer && $customer['customer_id'] > 0) {
             $row['customer_id'] = $customer['customer_id'];
             $debug_string .= _l('Linked to customer %s', module_customer::link_open($row['customer_id'], true)) . ' ';
         } else {
             $debug_string .= _l('Create new customer: %s', htmlspecialchars($row['customer_name'])) . ' ';
         }
     } else {
         $debug_string .= _l('No customer') . ' ';
     }
     if ($row['job_id']) {
         $debug_string .= _l('Replace existing job: %s', self::link_open($row['job_id'], true)) . ' ';
     } else {
         $debug_string .= _l('Insert new job: %s', htmlspecialchars($row['name'])) . ' ';
     }
     if ($debug) {
         echo $debug_string;
         return true;
     }
     if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && $row['customer_id'] > 0) {
         // don't update customer record with new one.
     } else {
         if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0 || $row['customer_id'] > 0) {
             // update customer record with new one.
             $row['customer_id'] = update_insert('customer_id', $row['customer_id'], 'customer', $row);
         }
     }
     $job_id = (int) $row['job_id'];
     // check if this ID exists.
     $job = self::get_job($job_id);
     if (!$job || $job['job_id'] != $job_id) {
         $job_id = 0;
     }
     $job_id = update_insert("job_id", $job_id, "job", $row);
     // handle any extra fields.
     $extra = array();
     foreach ($row as $key => $val) {
         if (!strlen(trim($val))) {
             continue;
         }
         if (strpos($key, 'extra:') !== false) {
             $extra_key = str_replace('extra:', '', $key);
             if (strlen($extra_key)) {
                 $extra[$extra_key] = $val;
             }
         }
     }
     if ($extra) {
         foreach ($extra as $extra_key => $extra_val) {
             // does this one exist?
             $existing_extra = module_extra::get_extras(array('owner_table' => 'job', 'owner_id' => $job_id, 'extra_key' => $extra_key));
             $extra_id = false;
             foreach ($existing_extra as $key => $val) {
                 if ($val['extra_key'] == $extra_key) {
                     $extra_id = $val['extra_id'];
                 }
             }
             $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'job', 'owner_id' => $job_id);
             $extra_id = (int) $extra_id;
             update_insert('extra_id', $extra_id, 'extra', $extra_db);
         }
     }
     foreach ($add_to_group as $group_id => $tf) {
         module_group::add_to_group($group_id, $job_id, 'job');
     }
     return $job_id;
 }
Exemplo n.º 11
0
 public static 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 subscription operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n";
         }
         return;
     }
     // find all automatic subscriptions and renew them (if applicable)
     $sql = "SELECT * FROM `" . _DB_PREFIX . "subscription` s ";
     $sql .= " WHERE s.automatic_renew = 1";
     $subscriptions = qa($sql);
     foreach ($subscriptions as $subscription) {
         if ($subscription['automatic_renew']) {
             if ($debug) {
                 echo "<br>\nProcessing subscription renewals for subscription " . module_subscription::link_open($subscription['subscription_id'], true) . "<br>\n<br>\n";
             }
             // find all the members/customers from this subscription
             //$members = module_subscription::get_subscribed_members($subscription['subscription_id']);
             //$customers = module_subscription::get_subscribed_customers($subscription['subscription_id']);
             $owners = module_subscription::get_subscribed_owners($subscription['subscription_id']);
             foreach ($owners as $member) {
                 if (!$member['next_generation_date'] || $member['next_generation_date'] == '0000-00-00') {
                     continue;
                 }
                 if (!$member['next_due_date'] || $member['next_due_date'] == '0000-00-00') {
                     continue;
                 }
                 if ($debug) {
                     echo "Doing: " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n";
                 }
                 // check permissions for logged in users, dont want the cron to run when someone is logged in and no access to this account.
                 if (module_security::is_logged_in()) {
                     switch ($member['owner_table']) {
                         case 'website':
                             $website_perm_check = module_website::get_website($member['owner_id']);
                             if (!$website_perm_check || $website_perm_check['website_id'] != $member['owner_id']) {
                                 continue 2;
                             }
                             if ($debug) {
                                 echo "permission pass for website: " . $website_perm_check['website_id'];
                             }
                             break;
                         case 'customer':
                             $customer_perm_check = module_customer::get_customer($member['owner_id']);
                             if (!$customer_perm_check || $customer_perm_check['customer_id'] != $member['owner_id']) {
                                 continue 2;
                             }
                             if ($debug) {
                                 echo "permission pass for customer: " . $customer_perm_check['customer_id'];
                             }
                             break;
                     }
                 }
                 // is the last invoice unpaid?
                 $history = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']);
                 $next_due_time_invoice_created = false;
                 $invoice_unpaid = false;
                 if (isset($member['recur_limit']) && (int) $member['recur_limit'] > 0 && count($history) >= (int) $member['recur_limit']) {
                     if ($debug) {
                         echo " - not renewing this one because it has hit our recur limit of " . $member['recur_limit'] . "<br>\n";
                     }
                     continue;
                 }
                 foreach ($history as $h) {
                     $last_invoice = module_invoice::get_invoice($h['invoice_id']);
                     if (!$last_invoice || $last_invoice['date_cancel'] != '0000-00-00') {
                         continue;
                     }
                     // check the new 'next_due_date' entry in the db table
                     if (isset($h['from_next_due_date']) && $h['from_next_due_date'] && $h['from_next_due_date'] != '0000-00-00') {
                         // we're using the new method of checking when an invoice was generated, rather than the confusing invoice 'date_create' check below
                         if ($debug) {
                             echo " - checking if next_due_date " . print_date($member['next_due_date']) . " matches subscription history from_next_due_date for invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " from_next_due_date: " . print_date($h['from_next_due_date']) . " (invoice create_date: " . print_date($last_invoice['date_create']) . ")<br>\n";
                         }
                         if (print_date($member['next_due_date']) == print_date($h['from_next_due_date'])) {
                             //print_date($last_invoice['date_create'])){
                             // this invoice is for the next due date.
                             $next_due_time_invoice_created = $last_invoice;
                         }
                     } else {
                         if ($debug) {
                             echo " - checking if next_generation_date (" . print_date($member['next_generation_date']) . ") or next_due_date (" . print_date($member['next_due_date']) . ") matches invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " created date (" . print_date($last_invoice['date_create']) . ") <br>\n";
                         }
                         if (print_date($member['next_generation_date']) == print_date($last_invoice['date_create']) || print_date($member['next_due_date']) == print_date($last_invoice['date_create'])) {
                             //print_date($last_invoice['date_create'])){
                             // this invoice is for the next due date.
                             $next_due_time_invoice_created = $last_invoice;
                         }
                     }
                     if ($last_invoice['total_amount_due'] > 0) {
                         $invoice_unpaid = true;
                     }
                 }
                 //self::generate_subscription_invoice($subscription_id, $customer_hack, $member_id, $date, $amount)
                 $next_due_time = strtotime($member['next_generation_date']);
                 if ($debug) {
                     echo " - next subscription time is " . $member['next_generation_date'] . " <br>\n";
                 }
                 if ($next_due_time <= strtotime(date('Y-m-d')) && !$next_due_time_invoice_created) {
                     if ($debug) {
                         echo " - Yes its time to generate an invoice!<br>\n";
                     }
                     if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $invoice_unpaid) {
                         if ($debug) {
                             echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because a previous subscription is unpaid <br>\n";
                         }
                         continue;
                     }
                     // time to generate! woo!
                     if ($debug) {
                         echo " - generating subscription renewal for " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n";
                     }
                     $invoice_id = self::generate_subscription_invoice($subscription['subscription_id'], $member['owner_table'], $member['owner_id'], $member['next_generation_date'], $subscription['amount']);
                     if ($debug) {
                         echo " - generated invoice " . module_invoice::link_open($invoice_id, true) . " for subscription <br>\n";
                     }
                     if ($subscription['automatic_email']) {
                         if ($debug) {
                             echo " - emailing invoice to " . $member['owner_table'] . "... <br>\n";
                         }
                         if (module_invoice::email_invoice_to_customer($invoice_id, $debug)) {
                             if ($debug) {
                                 echo "send successfully <br>\n";
                             }
                         } else {
                             echo " - failed to send invoice " . module_invoice::link_open($invoice_id, true) . " to " . $member['owner_table'] . " <br>\n";
                         }
                     }
                 } else {
                     if ($debug) {
                         echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because the due date has already been generated <br>\n";
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
        }
        if (isset($finance['finance_record']['linked_invoice_payments'])) {
            foreach ($finance['finance_record']['linked_invoice_payments'] as $f) {
                if (strlen($f['description'])) {
                    $descriptions[preg_replace('#\\s+#', '', strip_tags($f['description']))] = $f['description'];
                }
            }
        }
    }
    echo implode('<br>', $descriptions);
});
$columns['finance_customer'] = array('title' => 'Customer', 'callback' => function ($finance) {
    if (!isset($finance['transaction_date'])) {
        return false;
    }
    echo isset($finance['customer_id']) && $finance['customer_id'] ? module_customer::link_open($finance['customer_id'], true) : '';
});
$columns['sort_credit'] = array('title' => 'Credit', 'callback' => function ($finance) {
    $info = '';
    if ($finance['credit'] > 0 && isset($finance['payment_type'])) {
        if ($finance['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $finance['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT) {
            // dont add these ones to the totals at thebottom, mark then with asterix so people know.
            $info = ' *';
        }
    }
    if (!isset($finance['transaction_date'])) {
        return false;
    }
    ?>
 <span class="success_text"><?php 
    echo $finance['credit'] > 0 ? '+' . dollar($finance['credit'], true, $finance['currency_id']) : '';
Exemplo n.º 13
0
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'popup':
                // popup not used any more. cross domain issues.
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false;
                if ($type == 'popupjs') {
                    @ob_end_clean();
                    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                    header("Cache-Control: no-cache");
                    header("Pragma: no-cache");
                    header("Content-type: text/javascript");
                }
                if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) {
                    $change_history = module_change_request::get_remaining_changes($website_id);
                    $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
                    // get the change details out
                    if ($change_request_id) {
                        $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id);
                    } else {
                        $change_request = array();
                    }
                    if (!$change_request) {
                        $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array());
                    }
                    switch ($type) {
                        case 'save':
                            // saving a change.
                            $data = $_POST;
                            $data['url'] = urldecode($data['url']);
                            $data['website_id'] = $website_id;
                            $data['change_request_id'] = $change_request['change_request_id'];
                            if (isset($_REQUEST['completed_test'])) {
                                if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_NEW;
                                    // not completed.
                                } else {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE;
                                    // completed!
                                }
                            }
                            if (isset($_REQUEST['delete_request'])) {
                                $data['status'] = _CHANGE_REQUEST_STATUS_DELETE;
                                // deleted
                            }
                            $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data);
                            // redirect to send email page if we're logged in
                            if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) {
                                // don't do the template, do the redirect to the email page (todo!)
                                redirect_browser(self::link_open($change_request_id));
                            } else {
                                // send email to administrator (everyone with change request edit permissions?) about this change request.
                                $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1));
                                $email_data = get_single('change_request', 'change_request_id', $change_request_id);
                                $customer_data = $website_data = array();
                                if ($website_id) {
                                    $website_data = module_website::get_website($website_id);
                                    $email_data['website_name'] = $website_data['name'];
                                    $email_data['website_link'] = module_website::link_open($website_id, true);
                                    if ($website_data && $website_data['customer_id']) {
                                        $customer_data = module_customer::get_customer($website_data['customer_id'], true);
                                    }
                                }
                                if (isset($email_data['request'])) {
                                    $email_data['request'] = nl2br($email_data['request']);
                                    // for the plain text emails.
                                }
                                foreach ($alert_users as $alert_user) {
                                    // todo: make sure this staff member has access to this website?
                                    // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website?
                                    $template = module_template::get_template_by_key('change_request_alert_email');
                                    $template->assign_values(array_merge($customer_data, $website_data, $email_data));
                                    $html = $template->render('html');
                                    // send an email to this user.
                                    $email = module_email::new_email();
                                    $email->replace_values = array_merge($customer_data, $website_data, $email_data);
                                    $email->set_to('user', $alert_user['user_id']);
                                    $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0);
                                    $email->set_subject($template->description);
                                    // do we send images inline?
                                    $email->set_html($html);
                                    if ($email->send()) {
                                        // it worked successfully!!
                                        // sweet.
                                    } else {
                                        /// log err?
                                        set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text));
                                    }
                                }
                            }
                            // display thankyou template.
                            module_template::init_template('change_request_submitted', '<h2>Change Request</h2>
    <p>Thank you. Your change request has been submitted successfully.</p>
    <p>Please <a href="{URL}">click here</a> to continue.</p>
    ', 'Displayed after a change request is created/updated.', 'code');
                            // correct!
                            // load up the receipt template.
                            $template = module_template::get_template_by_key('change_request_submitted');
                            $template->page_title = _l("Change Request");
                            foreach ($data as $key => $val) {
                                if (!is_array($val)) {
                                    $data[$key] = htmlspecialchars($val);
                                }
                            }
                            $template->assign_values($data);
                            echo $template->render('pretty_html');
                            exit;
                            break;
                        case 'display_change':
                            ob_start();
                            ?>

                            <div class="title">
                                <?php 
                            _e('Change request');
                            ?>

                            </div>
                            <div class="content">
                                <p><?php 
                            echo nl2br(htmlspecialchars($change_request['request']));
                            ?>
</p>
                                <div class="wp3changerequest_actions">
                                    <p>
                                       <!-- <strong><?php 
                            _e('Attachments:');
                            ?>
</strong>
                                        <?php 
                            if (!$change_request['attachments']) {
                                ?>
 - none - <?php 
                            } else {
                                foreach ($change_request['attachments'] as $attachment) {
                                    ?>

                                            <a href="#"><?php 
                                    echo htmlspecialchars($attachment->name);
                                    ?>
</a>
                                            <?php 
                                }
                                ?>

                                        <?php 
                            }
                            ?>

                                        <br/>-->
                                        <strong><?php 
                            _e('Created by:');
                            ?>
</strong> <?php 
                            echo htmlspecialchars($change_request['name']);
                            ?>
 <br/>
                                        <strong><?php 
                            _e('Created on:');
                            ?>
</strong> <?php 
                            echo print_date($change_request['date_created'], true);
                            ?>

	                                    <?php 
                            if (isset($change_request['job_id']) && $change_request['job_id']) {
                                ?>
 <br/>
		                                    <strong><?php 
                                _e('Converted to job:');
                                ?>
</strong> <?php 
                                _e('This task has been converted to a Job');
                                ?>

	                                    <?php 
                            }
                            ?>

                                    </p>
                                    <?php 
                            if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) {
                                ?>

                                    <p align="center">
                                        <input type="button" name="edit" value="<?php 
                                _e('Edit');
                                ?>
" class="wp3changerequest_button wp3changerequest_button_small"  onclick="dtbaker_changerequest.edit(<?php 
                                echo $change_request_id;
                                ?>
); return false;">
                                    </p>
	                                <?php 
                            }
                            ?>

                                </div>
                            </div>
                            <?php 
                            $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean());
                            //                                echo json_encode($change_request);
                            //                                exit;
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ?>


                            var t = dtbaker_changerequest;
                            var change_id = <?php 
                            echo $change_request_id;
                            ?>
;
                                var msg = <?php 
                            echo json_encode($change_request);
                            ?>
;

                            jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>');
                            var box = jQuery('#dtbaker_change_'+change_id);
                            box.html(msg.html);
                            if(msg.status == 0){
                                box.addClass('wp3changerequest_change_pending');
                            }else if(msg.status == 2){
                                box.addClass('wp3changerequest_change_complete');
                            }else if(msg.status == 3){
                                box.addClass('wp3changerequest_change_deleted');
                            }
                            box.css('top',msg.y+'px');
                            box.data('window_width',msg.window_width);
                            box.data('left',msg.x);
                            t.set_left(change_id);
                            with({i:change_id}){
                                jQuery(window).resize(function () {
                                    t.set_left(i);
                                });
                            }
                            box.data('original_height',box.height());
                            box.css('overflow','hidden');
                            jQuery('.title',box).slideUp();
                            box.stop(true, true).animate({
                                height: t.min_height,
                                width: t.min_width
                            },500);
                            box.hover(function(){
                                jQuery(this).addClass('wp3changerequest_change_active');
                                jQuery('.title',this).stop(true, true).slideDown();
                                jQuery(this).stop().animate({
                                    width: t.max_width,
                                    height: jQuery(this).data('original_height'),
                                    opacity: 1
                                },500);
                            },function(){
                                jQuery('.title',this).stop(true, true).slideUp();
                                jQuery(this).stop().animate({
                                    width: t.min_width,
                                    height: t.min_height,
                                    opacity: 0.7
                                },500,function(){
                                    jQuery(this).removeClass('wp3changerequest_change_active');
                                });
                            })


                                <?php 
                            break;
                        default:
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ob_start();
                            include 'pages/popup.php';
                            $html = ob_get_clean();
                            $html = addcslashes($html, "'");
                            $html = preg_replace('#\\r|\\n#', "' +\n'", $html);
                            // inject using javascript. fixes cross domain issues
                            ?>

                            if(!jQuery('#dtbaker_changerequest_inlinewizard').length){
                                // fix for jQuery 1.9+
                                jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>');
                            }
                            jQuery('#dtbaker_changerequest_inlinewizard').html('<?php 
                            echo $html;
                            ?>
');
                            <?php 
                    }
                }
                exit;
                break;
            case 'script':
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                @ob_end_clean();
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Cache-Control: no-cache");
                header("Pragma: no-cache");
                header("Content-type: text/javascript");
                if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) {
                    include "js/client.js";
                    $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false;
                    if ($client_url) {
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url));
                        // todo - option this out incase url causes issues. ie: old js check method
                        ?>

                        jQuery(function(){
                            <?php 
                        foreach ($change_requests as $change_request) {
                            $displayed = false;
                            if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) {
                                $displayed = true;
                                ?>

                                    dtbaker_changerequest.display_change(<?php 
                                echo $change_request['change_request_id'];
                                ?>
);
                            <?php 
                            }
                            if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) {
                                ?>

                                    <?php 
                                if (!$displayed) {
                                    ?>

                                    dtbaker_changerequest.display_change(<?php 
                                    echo $change_request['change_request_id'];
                                    ?>
);
                                    <?php 
                                }
                                ?>

                                    dtbaker_changerequest.highlight(<?php 
                                echo (int) $_SESSION['_change_request_highlight'];
                                ?>
);
                                    <?php 
                                unset($_SESSION['_change_request_highlight']);
                            }
                        }
                        ?>

                        });
                        <?php 
                    } else {
                        // not posting the URL, some setups do not like this
                        // get list of active change requests
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW));
                        // we also do completed ones because the change request highlight countbe in there
                        $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE));
                        ?>


                        jQuery(function(){
                            var current_url = window.location.href;
                            <?php 
                        foreach ($change_requests as $change_request) {
                            ?>

                            if(current_url == '<?php 
                            echo addcslashes(htmlspecialchars($change_request['url']), "'");
                            ?>
'){
                                // todo: do this better!
                                dtbaker_changerequest.display_change(<?php 
                            echo $change_request['change_request_id'];
                            ?>
);
                            }
                            <?php 
                        }
                        ?>

                            <?php 
                        // todo: do we display all previous change requests on the page or not?
                        if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) {
                            echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight'];
                            foreach ($completed_change_requests as $complete_change_request) {
                                if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) {
                                    // show this completed one as well.
                                    ?>

                                        dtbaker_changerequest.display_change(<?php 
                                    echo $complete_change_request['change_request_id'];
                                    ?>
);
                                        <?php 
                                }
                            }
                            ?>

                            dtbaker_changerequest.highlight(<?php 
                            echo (int) $_SESSION['_change_request_highlight'];
                            ?>
);
                            <?php 
                            // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed.
                            unset($_SESSION['_change_request_highlight']);
                        }
                        ?>

                        });
                        <?php 
                    }
                }
                exit;
                break;
            case 'public':
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) {
                    // correct!
                    // redirect to website with our "change_request" url parameter, that is picked up by the included text.
                    $website = module_website::get_website($website_id);
                    $change_request_website = get_single('change_request_website', 'website_id', $website_id);
                    if ($change_request_website && $change_request_website['enabled']) {
                        $url = module_website::urlify($website['url']);
                        // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http!
                        if (isset($_REQUEST['change_request_id'])) {
                            $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']);
                            if ($selected_change_request && $selected_change_request['url']) {
                                $url = $selected_change_request['url'];
                            }
                            //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id'];
                            $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id'];
                        }
                        $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true);
                        redirect_browser($url);
                    }
                }
                echo "Change request disabled.";
                break;
        }
    }
Exemplo n.º 14
0
    }
    echo implode(', ', array_keys($dates));
    ?>

        </td>
        <td>
            <a href="<?php 
    echo $finance['url'];
    ?>
"><?php 
    echo !trim($finance['name']) ? 'N/A' : htmlspecialchars($finance['name']);
    ?>
</a>
        </td>
	    <td><?php 
    echo $finance['customer_id'] ? module_customer::link_open($finance['customer_id'], true) : _l('N/A');
    ?>
</td>
	    <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 {
Exemplo n.º 15
0
                    <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 
    if (class_exists('module_quote', false) && module_quote::is_plugin_enabled() && module_quote::can_i('view', 'Quotes')) {
        ?>
Exemplo n.º 16
0
ob_start();
if (isset($user_id) && (int) $user_id > 0) {
    module_user::print_contact_summary($user_id, 'text', array('name', 'last_name', 'email'));
}
$short_user_details = ob_get_clean();
$fieldset_data = array('heading' => array('type' => 'h3', 'title' => isset($title) ? $title : 'Primary Contact Details', 'responsive' => array('title' => isset($title) ? $title : 'Primary Contact', 'summary' => htmlspecialchars($short_user_details))), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
/*if($customer['primary_user_id']){
    $fieldset_data['heading']['button'] = array(
        'title' => 'More',
        'url' => module_user::link_open_contact($customer['primary_user_id'],false)
    );
}*/
if (isset($use_master_key) && ($use_master_key == 'customer_id' || $use_master_key == 'vendor_id') && isset($user[$use_master_key])) {
    $primary = false;
    if ($use_master_key == 'customer_id') {
        $customer_data = module_customer::get_customer($user[$use_master_key]);
        if ($customer_data['primary_user_id'] == $user_id) {
            $primary = true;
        }
    } else {
        if ($use_master_key == 'vendor_id') {
            $vendor_data = module_vendor::get_vendor($user[$use_master_key]);
            if ($vendor_data['primary_user_id'] == $user_id) {
                $primary = true;
            }
        }
    }
    if ($primary && !isset($hide_more_button)) {
        $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($user_id, false));
    }
    $fieldset_data['elements']['primary'] = array('title' => 'Primary', 'fields' => array(array('type' => 'check', 'name' => 'customer_primary', 'value' => '1', 'checked' => $primary), _hr('This users details will be used as a primary point of contact for this customer. These details will display in the main customer listing for this customer. Also if you send an invoice or a newsletter to this "customer" then this email address will be used.')));
Exemplo n.º 17
0
        $fieldset_data['extra_settings'] = array('owner_table' => 'customer_type', 'owner_key' => 'customer_type_id', 'owner_id' => $customer_type_id, 'layout' => 'table_row');
    }
    echo module_form::generate_fieldset($fieldset_data);
    unset($fieldset_data);
    $form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save')), array('ignore' => !(int) $customer_type_id, '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_customer_type(false) . "';")));
    echo module_form::generate_form_actions($form_actions);
    ?>


	</form>

	<?php 
} else {
    $customer_types = module_customer::get_customer_types();
    $header = array('title' => _l('Customer Types'), 'type' => 'h2', 'main' => true, 'button' => array());
    $header['button'] = array('url' => module_customer::link_open_customer_type('new'), 'title' => _l('Add New Type'), 'type' => 'add');
    print_heading($header);
    /** START TABLE LAYOUT **/
    $table_manager = module_theme::new_table_manager();
    $columns = array();
    $columns['customer_type'] = array('title' => _l('Customer Type'), 'callback' => function ($data) {
        echo module_customer::link_open_customer_type($data['customer_type_id'], true, $data);
    }, 'cell_class' => 'row_action');
    $columns['menu_position'] = array('title' => _l('Menu Position'));
    $table_manager->set_id('customer_type_list');
    $table_manager->set_columns($columns);
    $table_manager->set_rows($customer_types);
    $table_manager->pagination = true;
    $table_manager->print_table();
    /** END TABLE LAYOUT **/
}
Exemplo n.º 18
0
            <?php 
echo $form_html;
?>
        </td>
        <td valign="top">
            <p>
                On the left is an example signup form - your customers can complete this form to input their details directly into your system - handy! <br> You can copy &amp; paste the HTML code onto your website.
                You can adjust this HTML to suit your needs - you can even remove all the fields except the required ones.
                As long as the field names are kept the same as they are now you will be fine.
            </p>
	        <p>
		        Or if you are happy with the default signup form then you can use it at this address here: <a href="<?php 
echo module_customer::link_public_signup_form();
?>
" target="_blank"><?php 
echo module_customer::link_public_signup_form();
?>
</a>.
	        </p>
            <p>
                The best way to see how this works is to fill in the example form then have a look through your system to see how that information is inserted. Below is the information that is inserted into the system from this form:

            </p>
            <ul>
                <li>A Customer with the customer name from the form (new or existing customer, depending on the 'matching' setting above)</li>
                <li>A Customer Contact with the name, email and phone number from the form</li>
                <li>A new Website linked to the Customer, the "notes" will be added to this website entry.</li>
                <li>A new Job linked to the Customer for each "service" that is ticked in the form.</li>
                <li>Any files will be uploaded and linked to the Customer account.</li>
                <li>If there are any "custom" fields for the Customer or Website you will see them here in the form. These also get added to the system respectively. After adding new custom fields please come back here to regenerate the HTML code for your website.</li>
                <li>An email will be sent to the customer (see Settings > Template to configure this email)</li>
Exemplo n.º 19
0
    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);
    });
}
if (module_job::can_i('view', 'Jobs')) {
    $job_ids = array();
Exemplo n.º 20
0
                <?php 
        }
        ?>

            </td>
            <?php 
    }
    ?>

            <?php 
    if (!isset($_REQUEST['customer_id'])) {
        ?>

            <td>
                <?php 
        echo module_customer::link_open($website['customer_id'], true);
        ?>

            </td>
            <?php 
    }
    ?>

		</tr>
		<?php 
}
?>

	</tbody>
</table>
    <?php 
Exemplo n.º 21
0
 public function get_data()
 {
     if (count($this->_get_data_cache)) {
         return $this->_get_data_cache;
     }
     $file = false;
     if ($this->file_id > 0) {
         $file = get_single("file", "file_id", $this->file_id);
     }
     // check user has permissions to view this file.
     // for now we just base this on the customer id check
     if ($file) {
         // staff listing
         $staff = get_multiple('file_user_rel', array('file_id' => $file['file_id']), 'user_id');
         $file['staff_ids'] = array_keys($staff);
         $file['type'] = isset($file['file_url']) && $file['file_url'] ? 'remote' : (isset($file['bucket']) && $file['bucket'] ? 'bucket' : 'upload');
         if ($this->do_permissions) {
             switch (module_file::get_file_data_access()) {
                 case _FILE_ACCESS_ALL:
                     // all files, no limits on SQL here
                     break;
                 case _FILE_ACCESS_JOBS:
                     $jobs = module_job::get_jobs(array(), array('columns' => 'u.job_id AS id'));
                     if (!$file['job_id'] || !isset($jobs[$file['job_id']])) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_ME:
                     if ($file['create_user_id'] != module_security::get_loggedin_id()) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_ASSIGNED:
                     if (!in_array(module_security::get_loggedin_id(), $file['staff_ids'])) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_CUSTOMERS:
                 default:
                     if (class_exists('module_customer', false)) {
                         //added for compat in newsletter system that doesn't have customer module
                         $customer_permission_check = module_customer::get_customer($file['customer_id']);
                         if ($customer_permission_check['customer_id'] != $file['customer_id']) {
                             $file = false;
                         }
                     }
             }
             // file data access switch
         }
     }
     if (!$file) {
         $file = array('new' => true, 'type' => 'upload', 'file_id' => 0, 'customer_id' => isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : 0, 'job_id' => isset($_REQUEST['job_id']) ? $_REQUEST['job_id'] : 0, 'quote_id' => isset($_REQUEST['quote_id']) ? $_REQUEST['quote_id'] : 0, 'description' => '', 'status' => module_config::c('file_default_status', 'Uploaded'), 'file_name' => '', 'file_url' => '', 'staff_ids' => array(), 'bucket' => 0, 'bucket_parent_file_id' => 0, 'approved_time' => 0);
     }
     $this->_get_data_cache = $file;
     return $file;
 }
Exemplo n.º 22
0
    public static function hook_job_task_after($hook, $job_id, $task_id, $job_data, $task_data)
    {
        $comments = get_multiple('job_discussion', array('job_id' => $job_id, 'task_id' => $task_id), 'job_discussion_id', 'exact', 'job_discussion_id');
        if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 1) {
            // disabled & hidden.
            return;
        }
        if ($job_data && isset($job_data['job_discussion']) && $job_data['job_discussion'] == 2 && count($comments) == 0) {
            // disabled & shown.
            return;
        }
        if (isset($_POST['job_discussion_add_job_id']) && isset($_POST['job_discussion_add_task_id']) && $_POST['job_discussion_add_job_id'] == $job_id && $_POST['job_discussion_add_task_id'] == $task_id && isset($_POST['note']) && strlen($_POST['note'])) {
            $x = 0;
            while (ob_get_level() && $x++ < 10) {
                ob_end_clean();
            }
            $current_user_id = module_security::get_loggedin_id();
            $customer = module_customer::get_customer($job_data['customer_id']);
            if (!$current_user_id) {
                if ($job_data['customer_id'] && $customer['primary_user_id']) {
                    $current_user_id = $customer['primary_user_id'];
                }
            }
            $result = array();
            // adding a new note.
            $job_discussion_id = update_insert('job_discussion_id', 0, 'job_discussion', array('job_id' => $job_id, 'task_id' => $task_id, 'user_id' => $current_user_id, 'note' => $_POST['note']));
            $result['job_discussion_id'] = $job_discussion_id;
            $result['count'] = count($comments) + 1;
            $tasks = module_job::get_tasks($job_id);
            $result['email_customer'] = array();
            if (isset($_POST['sendemail_customer']) && is_array($_POST['sendemail_customer'])) {
                //$_POST['sendemail_customer'] == 'yes' && $customer['primary_user_id']){
                // send email to customer primary user id.
                $customer_contacts = module_user::get_contacts(array('customer_id' => $job_data['customer_id']));
                foreach ($_POST['sendemail_customer'] as $user_id) {
                    $user_id = (int) $user_id;
                    if ($user_id && isset($customer_contacts[$user_id])) {
                        // we can email this user.
                        $user = module_user::get_user($user_id, false);
                        if ($user && $user['user_id'] == $user_id) {
                            $values = array_merge($user, $job_data);
                            $values['job_url'] = module_job::link_public($job_id);
                            $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id;
                            $values['job_name'] = $job_data['name'];
                            $values['customer_name'] = $user['name'] . ' ' . $user['last_name'];
                            $values['note'] = $_POST['note'];
                            //todo: no order if no showning numbers
                            $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description'];
                            $template = module_template::get_template_by_key('job_discussion_email_customer');
                            $template->assign_values($values);
                            $html = $template->render('html');
                            $email = module_email::new_email();
                            $email->replace_values = $values;
                            $email->set_to('user', $user['user_id']);
                            $email->set_from('user', $current_user_id);
                            $email->set_subject($template->description);
                            // do we send images inline?
                            $email->set_html($html);
                            if ($email->send()) {
                                // it worked successfully!!
                                $result['email_customer'][] = $user['user_id'];
                            } else {
                                /// log err?
                            }
                        }
                    }
                }
                /*$user = module_user::get_user($customer['primary_user_id'],false);
                                if($user['user_id'] == $customer['primary_user_id']){
                                    $values = array_merge($user,$job_data);
                                    $values['job_url'] = module_job::link_public($job_id);
                                    $values['job_url'] .= (strpos($values['job_url'],'?')===false ? '?' : '&').'discuss='.$task_id.'#discuss'.$task_id;
                                    $values['job_name'] = $job_data['name'];
                                    $values['customer_name'] = $user['name'].' '.$user['last_name'];
                                    $values['note'] = $_POST['note'];
                                    //todo: no order if no showning numbers
                                    $values['task_name'] = '#'.$tasks[$task_id]['task_order'].': '.$tasks[$task_id]['description'];
                
                                    $template = module_template::get_template_by_key('job_discussion_email_customer');
                                    $template->assign_values($values);
                                    $html = $template->render('html');
                
                                    $email = module_email::new_email();
                                    $email->replace_values = $values;
                                    $email->set_to('user',$user['user_id']);
                                    $email->set_from('user',$current_user_id);
                                    $email->set_subject($template->description);
                                    // do we send images inline?
                                    $email->set_html($html);
                
                                    if($email->send()){
                                        // it worked successfully!!
                                        $result['email_customer'] = 1;
                                    }else{
                                        /// log err?
                                        $result['email_customer'] = 0;
                                    }
                                }else{
                                    // log error?
                                    $result['email_customer'] = 0;
                                }*/
            }
            if (isset($_POST['sendemail_staff']) && is_array($_POST['sendemail_staff'])) {
                // == 'yes' && $job_data['user_id']
                // todo: handle the restul better when sending to multiple people
                $result['email_staff_list'] = $_POST['sendemail_staff'];
                foreach ($_POST['sendemail_staff'] as $staff_id) {
                    // send email to staff
                    $staff_id = (int) $staff_id;
                    if (!$staff_id) {
                        $result['nostaff'] = 1;
                        continue;
                    }
                    if (isset($task_data['user_id']) && $task_data['user_id'] == $staff_id || isset($job_data['user_id']) && $job_data['user_id'] == $staff_id) {
                        //$user = module_user::get_user($job_data['user_id'],false);
                        $user = module_user::get_user($staff_id, false);
                        if ($user['user_id'] == $staff_id) {
                            $values = array_merge($user, $job_data);
                            $values['job_url'] = module_job::link_public($job_id);
                            $values['job_url'] .= (strpos($values['job_url'], '?') === false ? '?' : '&') . 'discuss=' . $task_id . '#discuss' . $task_id;
                            $values['job_name'] = $job_data['name'];
                            $values['staff_name'] = $user['name'] . ' ' . $user['last_name'];
                            $values['note'] = $_POST['note'];
                            //todo: no order if no showning numbers
                            $values['task_name'] = '#' . $tasks[$task_id]['task_order'] . ': ' . $tasks[$task_id]['description'];
                            $template = module_template::get_template_by_key('job_discussion_email_staff');
                            $template->assign_values($values);
                            $html = $template->render('html');
                            $email = module_email::new_email();
                            $email->replace_values = $values;
                            $email->set_to('user', $staff_id);
                            $email->set_from('user', $current_user_id);
                            $email->set_subject($template->description);
                            // do we send images inline?
                            $email->set_html($html);
                            if ($email->send()) {
                                // it worked successfully!!
                                $result['email_staff'] = 1;
                            } else {
                                /// log err?
                                $result['email_staff'] = 0;
                            }
                        } else {
                            // log error?
                            $result['email_staff'] = 0;
                        }
                    }
                }
            }
            $x = 0;
            while ($x++ < 5 && ob_get_level()) {
                ob_end_clean();
            }
            header("Content-type: text/javascript", true);
            echo json_encode($result);
            exit;
        }
        $label = htmlspecialchars(module_config::c('job_discussion_button_label', 'Task Comments'));
        ?>

        <a href="<?php 
        echo self::link_public($job_id, $task_id);
        ?>
" id="discuss<?php 
        echo $task_id;
        ?>
" class="task_job_discussion <?php 
        echo $label ? 'with_text' : '';
        ?>
" title="<?php 
        _e('View Discussion');
        ?>
"><span><?php 
        echo count($comments) > 0 ? count($comments) : '';
        ?>
</span><?php 
        echo $label;
        ?>
</a>
            <div class="task_job_discussion_holder"<?php 
        echo isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id ? ' style="display:block;"' : '';
        ?>
>
                <?php 
        if (isset($_REQUEST['discuss']) && $_REQUEST['discuss'] == $task_id) {
            $_REQUEST['t'] = $task_id;
            $_REQUEST['i'] = $job_id;
            $_REQUEST['hash'] = self::link_public($job_id, $task_id, true);
            self::external_hook('public');
        }
        ?>

            </div>
        <?php 
    }
?>
" />


    <?php 
$fields = array('fields' => array('name' => 'Name'));
module_form::set_required($fields);
module_form::prevent_exit(array('valid_exits' => array('.submit_button', '.form_save')));
hook_handle_callback('layout_column_half', 1, '35');
$fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Widget' . ' Details')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array('name' => array('title' => _l('Name'), 'field' => array('type' => 'text', 'name' => 'name', 'value' => $widget['name']))), 'extra_settings' => array('owner_table' => 'widget', 'owner_key' => 'widget_id', 'owner_id' => $widget['widget_id'], 'layout' => 'table_row', 'allow_new' => module_widget::can_i('create', 'Widgets'), 'allow_edit' => module_widget::can_i('create', 'Widgets')));
$fieldset_data['elements']['Status'] = array('title' => _l('Status'), 'fields' => array(array('type' => 'select', 'name' => 'status', 'value' => $widget['status'], 'options' => module_widget::get_statuses(), 'allow_new' => true)));
echo module_form::generate_fieldset($fieldset_data);
/*** ADVANCED ****/
if (module_widget::can_i('edit', 'Widgets')) {
    $c = array();
    $res = module_customer::get_customers();
    foreach ($res as $row) {
        $c[$row['customer_id']] = $row['customer_name'];
    }
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Advanced')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    if (count($res) <= 1 && $widget['customer_id'] && isset($c[$widget['customer_id']])) {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(htmlspecialchars($c[$widget['customer_id']]), array('type' => 'hidden', 'name' => 'customer_id', 'value' => $widget['customer_id'])));
    } else {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(array('type' => 'select', 'name' => 'customer_id', 'options' => $c, 'value' => $widget['customer_id'], 'help' => 'Changing a customer will also change all the current linked jobs and invoices across to this new customer.')));
    }
    echo module_form::generate_fieldset($fieldset_data);
}
if ((int) $widget_id > 0) {
    if (class_exists('module_group', false)) {
        module_group::display_groups(array('title' => 'Widget' . ' Groups', 'owner_table' => 'widget', 'owner_id' => $widget_id, 'view_link' => module_widget::link_open($widget_id)));
    }
Exemplo n.º 24
0
 if (!function_exists('convert_html2pdf')) {
     die('PDF generation not available');
 }
 end($data_record_revisions);
 $current_revision = current($data_record_revisions);
 $current_revision['number'] = count($data_record_revisions);
 $view_revision_id = $current_revision['data_record_revision_id'];
 $current_revision = array();
 // delete this if you want to display view revisions at the top.
 if ($current_revision && $view_revision_id) {
     // user wants a custom revision, we pull out the custom $data_field_groups
     // and we tell the form layout to use the serialized cached field layout information
     $data_field_groups = unserialize($current_revision['field_group_cache']);
     // we dont always read from cache, because then any ui changes wouldn't be reflected in older reports (if we want to change older reports)
 }
 $replace = !empty($_REQUEST['customer_id']) ? module_customer::get_replace_fields($_REQUEST['customer_id']) : array();
 $replace['from_name'] = module_security::get_loggedin_name();
 foreach ($data_field_groups as $data_field_group) {
     $data_field_group_id = $data_field_group['data_field_group_id'];
     $data_field_group = $module->get_data_field_group($data_field_group_id);
     $data_fields = $module->get_data_fields($data_field_group_id);
     foreach ($data_fields as $data_field) {
         $data_field_id = $data_field['data_field_id'];
         if (isset($data_items[$data_field_id])) {
             $data_field['value'] = $data_items[$data_field_id]['data_text'];
             // todo, could be data_number or data_varchar as well... hmmm
         }
         $replace[$data_field['title']] = $module->get_form_element($data_field, true, isset($data_record) ? $data_record : array());
     }
 }
 ob_end_clean();
Exemplo n.º 25
0
                                    </td>
                                    <td>
                                        <?php 
        switch ($invoice_payment_data['payment_type']) {
            case _INVOICE_PAYMENT_TYPE_NORMAL:
                echo htmlspecialchars($invoice_payment_data['method']);
                break;
            case _INVOICE_PAYMENT_TYPE_CREDIT:
                _e('Credit from customer %s', module_customer::link_open($invoice_payment_data['other_id'], true));
                break;
            case _INVOICE_PAYMENT_TYPE_DEPOSIT:
                _e('Deposit from invoice %s', module_invoice::link_open($invoice_payment_data['other_id'], true));
                break;
            case _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT:
                _e('Assigning Credit to: %s', module_customer::link_open($invoice['customer_id'], true));
                break;
            case _INVOICE_PAYMENT_TYPE_REFUND:
                _e('Refund: %s', htmlspecialchars($invoice_payment_data['method']));
                break;
            case _INVOICE_PAYMENT_TYPE_SUBSCRIPTION_CREDIT:
                $subscription_owner = module_subscription::get_subscription_owner($invoice_payment_data['other_id']);
                _e('Subscription credit from %s', module_subscription::link_open($subscription_owner['subscription_id'], true));
                break;
        }
        ?>

                                    </td>
                                    <td>
                                        <span class="currency">
                                        <?php 
Exemplo n.º 26
0
        }
    }
}
$template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : $template_name;
$template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice);
$template = module_template::get_template_by_key($template_name);
$replace = module_invoice::get_replace_fields($invoice_id, $invoice);
$replace['from_name'] = module_security::get_loggedin_name();
// generate the PDF ready for sending.
$pdf = module_invoice::generate_pdf($invoice_id);
// find available "to" recipients.
// customer contacts.
$to_select = false;
$to = array();
if ($invoice['customer_id']) {
    $customer = module_customer::get_customer($invoice['customer_id']);
    $replace['customer_name'] = $customer['customer_name'];
    if ($invoice['user_id']) {
        $primary = module_user::get_user($invoice['user_id']);
        if ($primary) {
            $to_select = $primary['email'];
        }
    } else {
        $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id']));
        // hunt for 'accounts' extra field
        $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts'));
        foreach ($to as $contact) {
            $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id']));
            foreach ($extras as $e) {
                if (strtolower($e['extra_key']) == $field_to_find) {
                    // this is the accounts contact - woo!
Exemplo n.º 27
0
                                data: {
                                    address_id: cust.address_id,
                                    address_hash: cust.address_hash,
                                    lat: results[0].geometry.location.lat(),
                                    lng: results[0].geometry.location.lng()
                                },
                                dataType: "json",
                                success: function(d){
                                }
                            });
                            customer_address[index].marker = new google.maps.Marker({
                                map: map,
                                position: results[0].geometry.location
                            });
                            createInfoWindow(customer_address[index].marker,'Customer: <a href="<?php 
$link = module_customer::link_open(1);
echo $link;
echo strpos($link, '?') ? '&' : '?';
?>
customer_id='+ cust.customer_id + '">' + cust.customer_name + '</a><br/>' + address);
                            bounds.extend(results[0].geometry.location);
                            <?php 
if (empty($search['location'])) {
    ?>
                            map.fitBounds(bounds);
                            <?php 
}
?>
                        } else {
                            console.log('Address ' + address + ' not found: ' + status);
                        }
Exemplo n.º 28
0
$customer_import = array('customer_name' => $callername, 'customer_extra' => array('Medium' => $referrermedium, 'Source' => $callsource, 'Campaign' => $utm_campaign, 'Content' => $utm_content, 'Term' => $utm_term, 'Query' => $keywords, 'Conversion URL' => $last_requested_url, 'IP Address' => $ip, 'Called In' => $datetime), 'address' => array('line_1' => '123 Test Street', 'line_2' => '', 'suburb' => $callercity, 'state' => $callerstate, 'post_code' => $callerzip), 'contact' => array('name' => $callername, 'last_name' => $callername, 'email' => $trackingnum, 'mobile' => $callernum));
include 'init.php';
// the UCM init code.
$customer_id = $plugins['customer']->save_customer('new', array('customer_name' => $customer_import['customer_name']));
if (!$customer_id) {
    echo 'Failed to create customer';
    exit;
}
if (!empty($customer_import['customer_extra'])) {
    foreach ($customer_import['customer_extra'] as $extra_key => $extra_val) {
        // Add the Medium extra field to that newly created customer
        $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'customer', 'owner_id' => $customer_id);
        $extra_id = update_insert('extra_id', false, 'extra', $extra_db);
    }
}
if (!empty($customer_import['address'])) {
    // Save the address for the customer
    $customer_import['address']['owner_id'] = $customer_id;
    $customer_import['address']['owner_table'] = 'customer';
    $customer_import['address']['address_type'] = 'physical';
    module_address::save_address(false, $customer_import['address']);
}
if (!empty($customer_import['contact'])) {
    // add the contact details to this customer record
    $customer_import['contact']['customer_id'] = $customer_id;
    $contact_user_id = $plugins['user']->create_user($customer_import['contact'], 'signup');
    if ($contact_user_id) {
        module_customer::set_primary_user_id($customer_id, $contact_user_id);
    }
}
echo "Created a customer with ID {$customer_id} and a contact with ID {$contact_user_id} ";
Exemplo n.º 29
0
 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;
     }
 }
Exemplo n.º 30
0
            echo ' ';
            echo '<a href="' . module_job::link_open($file['job_id'], false) . '">' . _l('Open Job &raquo;') . '</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']) {
                $c[$file['quote_id']] = _l('%s (from %s)', $related_quote['name'], $related_customer['customer_name']);
            } else {
                $file['quote_id'] = false;
            }
        } else {
            $file['quote_id'] = false;
        }
    }
    $fieldset_data['elements'][] = array('title' => 'Quote', 'fields' => array(array('type' => 'select', 'name' => 'quote_id', 'value' => $file['quote_id'], 'options' => $c), function () use(&$file) {
        if ($file['quote_id']) {
            echo ' ';
            echo '<a href="' . module_quote::link_open($file['quote_id'], false) . '">' . _l('Open Quote &raquo;') . '</a>';
        }
    }));