コード例 #1
0
/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!$invoice_safe) {
    die('failed');
}
$invoice_id = (int) $_REQUEST['invoice_id'];
$invoice = module_invoice::get_invoice($invoice_id);
if (class_exists('module_company', false) && isset($invoice['company_id']) && (int) $invoice['company_id'] > 0) {
    module_company::set_current_company_id($invoice['company_id']);
}
// template for sending emails.
// are we sending the paid one? or the dueone.
$original_template_name = $template_name = '';
$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']) {
    $original_template_name = $template_name = 'credit_note_email';
} else {
    if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
        $original_template_name = $template_name = $template_prefix . '_paid';
    } else {
        if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
            $original_template_name = $template_name = $template_prefix . '_overdue';
        } else {
コード例 #2
0
ファイル: invoice.php プロジェクト: sgh1986915/php-crm
 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;
     }
 }
コード例 #3
0
ファイル: quote.php プロジェクト: sgh1986915/php-crm
 public static function quote_html($quote_id, $quote_data, $mode = 'html')
 {
     if ($quote_id && $quote_data) {
         // spit out the quote html into a file, then pass it to the pdf converter
         // to convert it into a PDF.
         $quote = $quote_data;
         if (class_exists('module_company', false) && isset($quote_data['company_id']) && (int) $quote_data['company_id'] > 0) {
             module_company::set_current_company_id($quote_data['company_id']);
         }
         $quote_template = isset($quote_data['quote_template_print']) && strlen($quote_data['quote_template_print']) ? $quote_data['quote_template_print'] : module_config::c('quote_template_print_default', 'quote_pdf');
         $quote_template_suffix = '';
         if ($quote_template != 'quote_pdf') {
             $quote_template_suffix = str_replace('quote_pdf', '', $quote_template);
         }
         ob_start();
         include module_theme::include_ucm('includes/plugin_quote/template/quote_task_list.php');
         $task_list_html = ob_get_clean();
         $replace = self::get_replace_fields($quote_id, $quote_data);
         $replace['task_list'] = $task_list_html;
         $replace['quote_link'] = module_quote::link_public($quote_id);
         $replace['external_quote_template_html'] = '';
         $external_quote_template = module_template::get_template_by_key('quote_pdf');
         $external_quote_template->assign_values($replace);
         $replace['external_quote_template_html'] = $external_quote_template->replace_content();
         ob_start();
         $template = module_template::get_template_by_key($quote_template);
         $template->assign_values($replace);
         echo $template->render('html');
         $quote_html = ob_get_clean();
         return $quote_html;
     }
     return false;
 }