예제 #1
0
$template_html = ob_get_clean();
$payment_methods_options = array();
$payment_methods = handle_hook('get_payment_methods', $module);
foreach ($payment_methods as $payment_method) {
    if ($payment_method->is_method('online') && $payment_method->is_enabled()) {
        $payment_methods_options[$payment_method->module_name] = $payment_method->get_payment_method_name();
    }
}
$settings = array(array('key' => 'overdue_email_auto', 'default' => '0', 'type' => 'checkbox', 'description' => 'Automatic Overdue Emails', 'help' => 'If this is ticked then by default newly created invoices will be sent automatic overdue notices. This can be disabled/enabled per invoice. See the "Auto Overdue Email" option near "Due Date".'), array('key' => 'invoice_automatic_receipt', 'default' => '1', 'type' => 'checkbox', 'description' => 'Automatic Send Invoice Receipt', 'help' => 'Automatically send the invoice receipt to the customer once the invoice is marked as paid. If this is disabled you will have to go into the invoice and manually send it after payment is received.'), array('key' => 'invoice_template_print_default', 'default' => 'invoice_print', 'type' => 'text', 'description' => 'Default PDF invoice template', 'help' => 'Used for invoice PDF. You can overwrite in the Advanced settings of each invoice.'), array('key' => 'overdue_email_auto_days', 'default' => '3', 'type' => 'text', 'description' => 'Automically send after', 'help' => 'How many days after the invoice is overdue is the automated email sent (set to 0 will send on the date the invoice is due)'), array('key' => 'overdue_email_auto_days_repeat', 'default' => '7', 'type' => 'text', 'description' => 'Automically re-send every', 'help' => 'How many days after the last automatic overdue reminder is the overdue reminder re-sent automatically (set to 0 to disable this option)'), array('key' => 'invoice_automatic_after_time', 'default' => '7', 'type' => 'text', 'description' => 'Hour of day to perform automatic operations', 'help' => 'Enter the hour of day (eg: 7 for 7am, 14 for 2pm) to perform automatic actions - such as renewing invoices, subscriptions, overdue notices, etc...'), array('key' => 'invoice_auto_renew_only_paid_invoices', 'default' => '1', 'type' => 'checkbox', 'description' => 'Only renew paid invoices', 'help' => 'If an invoice (or past subscription invoice) has not been paid then do not renew the next one until original payment has been received.'), array('key' => 'invoice_default_payment_method', 'default' => 'paymethod_paypal', 'type' => 'select', 'options' => $payment_methods_options, 'description' => 'Default Payment Method'), array('key' => 'invoice_due_days', 'default' => '30', 'type' => 'text', 'description' => 'Invoice Due Days', 'help' => 'The number of days used to calculate the "Due Date" on new invoices. Due Date can be overridden per invoice.'), array('key' => 'invoice_name_match_job', 'default' => '0', 'type' => 'checkbox', 'description' => 'Match Invoice with Job Name', 'help' => 'If an invoice is created from a Job, set the Invoice name the same as the job name'), array('key' => 'invoice_incrementing', 'default' => '0', 'type' => 'checkbox', 'description' => 'Incrementing Invoice Numbers', 'help' => 'If this is enabled the system will pick a new invoice number each time. Choose what number to start from below.'), array('key' => 'invoice_incrementing_next', 'default' => '1', 'type' => 'text', 'description' => 'Incrementing Invoice Number', 'help' => 'What will be the next invoice number'), array('key' => 'invoice_task_list_show_date', 'default' => '1', 'type' => 'checkbox', 'description' => 'Show Dates on Invoice Items'), array('key' => 'invoice_task_numbers', 'default' => '1', 'type' => 'checkbox', 'description' => 'Show Task Numbers on Invoice Items'), array('key' => 'invoice_allow_payment_amount_adjustment', 'default' => '1', 'type' => 'checkbox', 'description' => 'Allow User To Enter Payment Amount', 'help' => 'If this is enabled the user can change the payment amount on invoices. For example, they might want to pay $50 of a $100 invoice with PayPal, and $50 with cash.'), array('type' => 'html', 'description' => 'Templates', 'html' => $template_html));
module_config::print_settings_form(array('heading' => array('title' => 'Invoice Settings', 'type' => 'h2', 'main' => true), 'settings' => $settings));
// find any blank invoices.
$sql = "SELECT * FROM `" . _DB_PREFIX . "invoice` WHERE customer_id IS NULL AND `name` = '' AND `status` = '' AND `date_create` = '0000-00-00' AND `date_sent` = '0000-00-00' AND `date_paid` = '0000-00-00' AND `date_due` = '0000-00-00' AND c_total_amount = 0 ";
$invoices = qa($sql);
$blank_invoices = array();
foreach ($invoices as $invoice) {
    $items = module_invoice::get_invoice_items($invoice['invoice_id']);
    if (empty($items)) {
        $blank_invoices[] = $invoice;
    }
}
if (count($blank_invoices) && isset($_POST['remove_duplicates']) && $_POST['remove_duplicates'] == 'yes') {
    foreach ($blank_invoices as $id => $blank_invoice) {
        module_invoice::delete_invoice($blank_invoice['invoice_id']);
        unset($blank_invoices[$id]);
    }
}
if (count($blank_invoices)) {
    ?>
	<h2>Blank invoices found</h2>
	We found the following <?php 
    echo count($blank_invoices);
예제 #2
0
        // make sure current customer can access this invoice
        if (!module_security::can_access_data('invoice', $invoice, $invoice_id)) {
            echo 'Data access denied. Sorry.';
            exit;
        }
        module_security::check_page(array('category' => 'Invoice', 'page_name' => 'Invoices', 'module' => 'invoice', 'feature' => 'edit'));
    }
} else {
    $invoice_id = 0;
    $invoice = module_invoice::get_invoice($invoice_id);
    if (class_exists('module_security', false)) {
        module_security::check_page(array('category' => 'Invoice', 'page_name' => 'Invoices', 'module' => 'invoice', 'feature' => 'create'));
    }
    module_security::sanatise_data('invoice', $invoice);
}
$invoice_items = module_invoice::get_invoice_items($invoice_id, $invoice);
$invoice_locked = $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00' || $invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00';
if (isset($_REQUEST['as_deposit']) && isset($_REQUEST['job_id'])) {
    $invoice['deposit_job_id'] = (int) $_REQUEST['job_id'];
}
$discounts_allowed = !(isset($invoice['deposit_job_id']) && $invoice['deposit_job_id'] > 0);
$customer_data = array();
if ($invoice['customer_id']) {
    $customer_data = module_customer::get_customer($invoice['customer_id']);
}
$show_task_dates = module_config::c('invoice_task_list_show_date', 1);
$colspan = 2;
if ($show_task_dates) {
    $colspan++;
}
if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) {
예제 #3
0
        </td>
    </tr>
<?php 
}
$replace['invoice_summary'] = ob_get_clean();
/* START INVOICE LINE ITEMS */
$task_decimal_places = module_config::c('task_amount_decimal_places', -1);
if ($task_decimal_places < 0) {
    $task_decimal_places = false;
    // use default currency dec places.
}
$task_decimal_places_trim = module_config::c('task_amount_decimal_places_trim', 0);
$all_item_row_html = '';
$item_count = 0;
// changed from 1
foreach (module_invoice::get_invoice_items($invoice_id, $invoice) as $invoice_item_id => $invoice_item_data) {
    $row_replace = $invoice_item_data;
    $row_replace['item_odd_or_even'] = $item_count++ % 2 ? 'odd' : 'even';
    $row_replace['item_number'] = '';
    $row_replace['item_description'] = '';
    $row_replace['item_date'] = '';
    $row_replace['item_tax'] = 0;
    $row_replace['item_tax_rate'] = '';
    if (isset($invoice_item_data['custom_task_order']) && (int) $invoice_item_data['custom_task_order'] > 0) {
        $row_replace['item_number'] = $invoice_item_data['custom_task_order'];
    } else {
        if (isset($invoice_item_data['task_order']) && $invoice_item_data['task_order'] > 0) {
            $row_replace['item_number'] = $invoice_item_data['task_order'];
        } else {
            $row_replace['item_number'] = $item_count;
        }
예제 #4
0
파일: job.php 프로젝트: sgh1986915/php-crm
 public function run_cron($debug = false)
 {
     // we only want to perform these cron actions if we're after a certain time of day
     // because we dont want to be generating these renewals and sending them at midnight, can get confusing
     $after_time = module_config::c('invoice_automatic_after_time', 7);
     $time_of_day = date('G');
     if ($time_of_day < $after_time) {
         if ($debug) {
             echo "Not performing automatic invoice operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n";
         }
         return;
     }
     // find automatic job renewals
     $sql = "SELECT p.* FROM `" . _DB_PREFIX . "job` p ";
     $sql .= " WHERE p.date_renew != '0000-00-00'";
     $sql .= " AND p.date_start != '0000-00-00'";
     $sql .= " AND p.date_renew <= '" . date('Y-m-d') . "'";
     $sql .= " AND (p.renew_job_id IS NULL OR p.renew_job_id = 0)";
     $sql .= " AND (p.renew_auto = 1)";
     $renew_jobs = qa($sql);
     foreach ($renew_jobs as $renew_job) {
         // time to automatically renew this job! woo!
         if ($debug) {
             echo "Automatically Renewing Job " . module_job::link_open($renew_job['job_id'], true) . "<br>\n";
         }
         //$job_details = $this->get_job($renew_job['job_id']);
         $job_invoices = module_invoice::get_invoices(array('job_id' => $renew_job['job_id']));
         $unpaid_invoice = false;
         foreach ($job_invoices as $job_invoice) {
             $job_invoice = module_invoice::get_invoice($job_invoice['invoice_id']);
             if ($job_invoice['total_amount_due'] > 0) {
                 $unpaid_invoice = true;
             }
         }
         if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $unpaid_invoice) {
             if ($debug) {
                 echo "Not automatically renewing this job because it has unpaid invoices. <br>\n";
             }
         } else {
             $new_job_id = $this->renew_job($renew_job['job_id'], true);
             if ($new_job_id) {
                 //module_cache::clear_cache();
                 if ($debug) {
                     echo "Job Automatically Renewed: " . module_job::link_open($new_job_id, true) . "<br>\n";
                 }
                 if ($renew_job['renew_invoice']) {
                     // we want to tick all these tasks off and invoice this job, then send this invoice to the customer.
                     $job_tasks = module_job::get_tasks($new_job_id);
                     foreach ($job_tasks as $job_task_id => $job_task) {
                         $job_tasks[$job_task_id]['fully_completed_t'] = 1;
                         $job_tasks[$job_task_id]['fully_completed'] = 1;
                     }
                     $this->save_job_tasks($new_job_id, array('job_task' => $job_tasks));
                     //module_cache::clear_cache();
                     // generate an invoice for this job.
                     $_REQUEST['job_id'] = $new_job_id;
                     $new_invoice = module_invoice::get_invoice('new');
                     $new_invoice['date_create'] = $renew_job['date_renew'];
                     $new_invoice['invoice_invoice_item'] = module_invoice::get_invoice_items('new', $new_invoice);
                     $new_invoice_id = module_invoice::save_invoice('new', $new_invoice);
                     //module_cache::clear_cache();
                     if ($debug) {
                         echo "Generated new invoice for renewed job: " . module_invoice::link_open($new_invoice_id, true) . "<br/>";
                     }
                     if ($debug) {
                         echo "Emailing invoice to customer...";
                     }
                     if (module_invoice::email_invoice_to_customer($new_invoice_id)) {
                         if ($debug) {
                             echo "send successfully";
                         }
                     } else {
                         if ($debug) {
                             echo "send failed";
                         }
                     }
                     if ($debug) {
                         echo "<br>\n";
                     }
                 }
             }
         }
     }
 }
예제 #5
0
 public static function multisafepay_redirect($description, $amount, $user_id, $payment_id, $invoice_id, $currency_id)
 {
     $currency = module_config::get_currency($currency_id);
     if ($currency['code'] != 'EUR') {
         echo "Multisafepay only accepts currency in EUR";
     }
     include 'MultiSafepay.combined.php';
     $msp = new MultiSafepay();
     /*
      * Merchant Settings
      */
     $msp->test = self::is_sandbox();
     $msp->merchant['account_id'] = module_config::c('payment_method_multisafepay_account', '');
     $msp->merchant['site_id'] = module_config::c('payment_method_multisafepay_site_id', '');
     $msp->merchant['site_code'] = module_config::c('payment_method_multisafepay_side_code', '');
     $msp->merchant['notification_url'] = full_link(_EXTERNAL_TUNNEL . '?m=paymethod_multisafepay&h=ipn&method=multisafepay&type=initial');
     $msp->merchant['cancel_url'] = module_invoice::link_public($invoice_id);
     // optional automatic redirect back to the shop:
     $msp->merchant['redirect_url'] = module_invoice::link_public($invoice_id);
     /*
      * Customer Details
      */
     $invoice = $invoice_data = module_invoice::get_invoice($invoice_id);
     $customer = module_customer::get_customer($invoice_data['customer_id'], true);
     if (!$user_id) {
         $user_id = $customer['primary_user_id'];
     }
     $user = module_user::get_user($user_id, false);
     //$msp->customer['locale']           = 'nl';
     $msp->customer['firstname'] = $user['name'];
     $msp->customer['lastname'] = $user['last_name'];
     $address = module_address::get_address($invoice_data['customer_id'], 'customer', 'physical');
     $msp->customer['zipcode'] = isset($address['post_code']) ? $address['post_code'] : '';
     $msp->customer['city'] = isset($address['region']) ? $address['region'] : '';
     $msp->customer['country'] = isset($address['country']) ? $address['country'] : module_config::c('payment_method_multisafepay_country', '');
     $msp->customer['phone'] = $user['phone'];
     $msp->customer['email'] = $user['email'];
     $msp->parseCustomerAddress(isset($address['line_1']) ? $address['line_1'] : '');
     // or
     // $msp->customer['address1']         = 'Teststraat';
     // $msp->customer['housenumber']      = '21';
     /*
      * Transaction Details
      */
     $msp->transaction['id'] = self::multisafepay_custom($user_id, $payment_id, $invoice_id);
     $msp->transaction['currency'] = $currency['code'];
     $msp->transaction['amount'] = $amount * 100;
     // cents
     $msp->transaction['description'] = $description;
     $msp->transaction['items'] = '<br/><ul>';
     // copied from invoice_task_list.php
     foreach (module_invoice::get_invoice_items($invoice_id) as $invoice_item_id => $invoice_item_data) {
         // copy any changes here to template/invoice_task_list.php
         $task_hourly_rate = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate'] != 0 ? $invoice_item_data['hourly_rate'] : $invoice_data['hourly_rate'];
         // if there are no hours logged against this task
         if (!$invoice_item_data['hours']) {
             //$task_hourly_rate=0;
         }
         // if we have a custom price for this task
         if ($invoice_item_data['amount'] != 0 && $invoice_item_data['amount'] != $invoice_item_data['hours'] * $task_hourly_rate) {
             $invoice_item_amount = $invoice_item_data['amount'];
             $task_hourly_rate = false;
         } else {
             if ($invoice_item_data['hours'] > 0) {
                 $invoice_item_amount = $invoice_item_data['hours'] * $task_hourly_rate;
             } else {
                 $invoice_item_amount = 0;
                 $task_hourly_rate = false;
             }
         }
         $msp->transaction['items'] .= '<li>';
         $msp->transaction['items'] .= $invoice_item_data['hours'] > 0 ? $invoice_item_data['hours'] . ' x ' : '';
         $msp->transaction['items'] .= $invoice_item_data['custom_description'] ? htmlspecialchars($invoice_item_data['custom_description']) : htmlspecialchars($invoice_item_data['description']);
         $msp->transaction['items'] .= ' = ' . dollar($invoice_item_amount, true, $invoice['currency_id']);
         $msp->transaction['items'] .= '</li>';
     }
     $msp->transaction['items'] .= '<li>Sub Total: ' . dollar($invoice_data['total_sub_amount'], true, $invoice_data['currency_id']) . '</li>';
     if ($invoice_data['total_tax_rate'] > 0) {
         $msp->transaction['items'] .= '<li>' . $invoice['total_tax_name'] . ' ' . $invoice['total_tax_rate'] . '% = ' . dollar($invoice['total_tax'], true, $invoice['currency_id']) . '</li>';
     }
     $msp->transaction['items'] .= '<li>Total: ' . dollar($invoice['total_amount'], true, $invoice['currency_id']) . '</li>';
     $msp->transaction['items'] .= '</ul>';
     // returns a payment url
     $url = $msp->startTransaction();
     if ($msp->error) {
         echo "Error " . $msp->error_code . ": " . $msp->error;
         exit;
     }
     // redirect
     redirect_browser($url);
     /*
             $url = 'https://www.'. (self::is_sandbox()? 'sandbox.' : '') . 'multisafepay.com/cgi-bin/webscr?';
     
             $fields = array(
                 'cmd' => '_xclick',
                 'business' => module_config::c('payment_method_multisafepay_email',_ERROR_EMAIL),
                 'currency_code' => $currency['code'],
                 'item_name' => $description,
                 'amount' => $amount,
                 'return' => module_invoice::link_open($invoice_id),
                 'notify_url' => full_link(_EXTERNAL_TUNNEL.'?m=paymethod_multisafepay&h=ipn&method=multisafepay'),
                 'custom' => self::multisafepay_custom($user_id,$payment_id,$invoice_id),
             );
     
             foreach($fields as $key=>$val){
                 $url .= $key.'='.urlencode($val).'&';
             }
     
             //echo '<a href="'.$url.'">'.$url.'</a>';exit;
     
             redirect_browser($url);
     */
 }