예제 #1
0
<br/>
                    <?php 
    _e('The deposit will apply to this job once this invoice is paid.');
    ?>

                </p>
            </div>
        <?php 
    $fieldset_data = array('heading' => array('title' => _l('Deposit Invoice'), 'type' => 'h3'), 'elements_before' => ob_get_clean());
    echo module_form::generate_fieldset($fieldset_data);
    unset($fieldset_data);
} else {
    if ($invoice_id > 0 && $invoice['total_amount_due'] > 0 && module_security::is_page_editable() && module_invoice::can_i('create', 'Invoice Payments')) {
        foreach ($invoice['job_ids'] as $possible_job_id) {
            // find any deposit invoices matching this job.
            $possible_invoices = module_invoice::get_invoices(array('deposit_job_id' => $possible_job_id));
            if ($possible_invoices) {
                foreach ($possible_invoices as $possible_invoice) {
                    if ($possible_invoice['invoice_id'] == $invoice_id) {
                        continue;
                    }
                    // skip me
                    // see if this deposit invoice has been paid.
                    $possible_invoice = module_invoice::get_invoice($possible_invoice['invoice_id']);
                    if (isset($possible_invoice['deposit_remaining']) && $possible_invoice['deposit_remaining'] > 0) {
                        // we have some cash that can be applied to this invoice from the deposit! woo!
                        $this_take = min($invoice['total_amount_due'], $possible_invoice['deposit_remaining']);
                        if ($this_take > 0) {
                            /** PREVIOUS DEPOSIT  */
                            ob_start();
                            ?>
예제 #2
0
}
// end can i view job tasks
if (module_invoice::can_i('view', 'Invoices') && (int) $job_id > 0) {
    ?>


                    <div id="create_invoice_options">
                    <div id="create_invoice_options_inner"></div>
                    </div>
                    <?php 
    ob_start();
    ?>

                    <div class="content_box_wheader">
                    <?php 
    $job_invoices = module_invoice::get_invoices(array('job_id' => $job_id));
    if (!count($job_invoices)) {
        ?>

                            <p align="center">
                                <?php 
        _e('There are no invoices for this job yet.');
        ?>

                            </p>
                    <?php 
    } else {
        ?>


                <?php 
예제 #3
0
             echo 'error_text';
         } else {
             echo 'success_text';
         }
         echo '">';
         if ($job['total_amount'] > 0) {
             echo dollar($job['total_amount'], true, $job['currency_id']);
         }
         echo '</span>';
         echo "<br>";
     }
 });
 if (module_invoice::can_i('view', 'Invoices')) {
     $columns['invoice'] = array('title' => 'Invoice', 'callback' => function ($quote) use(&$job_ids) {
         foreach ($job_ids as $job_id) {
             foreach (module_invoice::get_invoices(array('job_id' => $job_id)) as $invoice) {
                 $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                 if (!$invoice) {
                     continue;
                 }
                 echo module_invoice::link_open($invoice['invoice_id'], true);
                 echo " ";
                 echo '<span class="';
                 if ($invoice['total_amount_due'] > 0) {
                     echo 'error_text';
                 } else {
                     echo 'success_text';
                 }
                 echo '">';
                 if ($invoice['total_amount_due'] > 0) {
                     echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']);
예제 #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
        if (isset($customer['group_sort_customer'])) {
            echo htmlspecialchars($customer['group_sort_customer']);
        } else {
            // find the groups for this customer.
            $groups = module_group::get_groups_search(array('owner_table' => 'customer', 'owner_id' => $customer['customer_id']));
            $g = array();
            foreach ($groups as $group) {
                $g[] = $group['name'];
            }
            echo htmlspecialchars(implode(', ', $g));
        }
    });
}
if (class_exists('module_invoice', false) && module_invoice::can_i('view', 'Invoices') && module_config::c('customer_list_show_invoices', 1)) {
    $columns['customer_invoices'] = array('title' => 'Invoices', 'callback' => function ($customer) {
        $invoices = module_invoice::get_invoices(array('customer_id' => $customer['customer_id']));
        if (count($invoices)) {
            $total_due = 0;
            $total_paid = 0;
            foreach ($invoices as $invoice) {
                $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                $total_due += $invoice['total_amount_due'];
                $total_paid += $invoice['total_amount_paid'];
            }
            $old_customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : false;
            $_REQUEST['customer_id'] = $customer['customer_id'];
            echo '<a href="' . module_invoice::link_open(false) . '">' . _l('%s invoice%s: %s', count($invoices), count($invoices) > 1 ? 's' : '', ($total_due > 0 ? '<span class="error_text">' . _l('%s due', dollar($total_due, true, $invoice['currency_id'])) . ' </span>' : '') . ($total_paid > 0 ? '<span class="success_text">' . _l('%s paid', dollar($total_paid, true, $invoice['currency_id'])) . ' </span>' : '')) . '</a>';
            if ($old_customer_id) {
                $_REQUEST['customer_id'] = $old_customer_id;
            } else {
                unset($_REQUEST['customer_id']);
예제 #6
0
         foreach ($invoices as $invoice_id => $invoice) {
             if ($invoice['date_cancel'] != '0000-00-00') {
                 unset($invoices[$invoice_id]);
             }
         }
         if (count($invoices)) {
             $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Invoices Paid Between %s and %s', print_date($date_from), print_date($date_to))));
             $fieldset_data['elements_before'] = customer_admin_email_generate_invoice_list($invoices, $customer_id);
             $email_details .= module_form::generate_fieldset($fieldset_data);
         }
     }
     if (isset($_REQUEST['email']['invoice_unpaid'])) {
         // find all unpaid invoices
         $date_from = input_date($_REQUEST['email']['invoice_paid_date_from']);
         $date_to = input_date($_REQUEST['email']['invoice_paid_date_to']);
         $invoices = module_invoice::get_invoices(array('customer_id' => $customer['customer_id'], 'date_paid' => '0000-00-00'));
         // remove cancelled invoices
         foreach ($invoices as $invoice_id => $invoice) {
             if ($invoice['date_cancel'] != '0000-00-00') {
                 unset($invoices[$invoice_id]);
             }
         }
         if (count($invoices)) {
             $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Unpaid Invoices')));
             $fieldset_data['elements_before'] = customer_admin_email_generate_invoice_list($invoices, $customer_id);
             $email_details .= module_form::generate_fieldset($fieldset_data);
         }
     }
 }
 $template->assign_values(array('email_details' => $email_details));
 module_email::print_compose(array('title' => _l('Email Customer: %s', $customer['customer_name']), 'find_other_templates' => 'customer_statement_email', 'current_template' => $template_name, 'customer_id' => $customer['customer_id'], 'debug_message' => 'Sending customer statement email', 'to' => $to, 'to_select' => $to_select, 'bcc' => module_config::c('admin_email_address', ''), 'content' => $template->render('html'), 'subject' => $template->replace_description(), 'success_url' => module_customer::link_open($customer['customer_id']), 'cancel_url' => module_customer::link_open($customer['customer_id'])));
예제 #7
0
                                <th>
                                    <?php 
        _e('Discount Type');
        ?>

                                </th>
                                <td>
                                    <?php 
        echo print_select_box(array('0' => _l('Before Tax'), 1 => _l('After Tax')), 'discount_type', $invoice['discount_type']);
        ?>

                                </td>
                            </tr>
                            <?php 
        // see if this invoice was renewed from anywhere
        $invoice_history = module_invoice::get_invoices(array('renew_invoice_id' => $invoice_id));
        if (count($invoice_history)) {
            foreach ($invoice_history as $invoice_h) {
                ?>

                                    <tr>
                                        <th class="width1">
                                            <?php 
                echo _l('Renewal History');
                ?>

                                        </th>
                                        <td>
                                            <?php 
                echo _l('This invoice was renewed from %s on %s', module_invoice::link_open($invoice_h['invoice_id'], true), print_date($invoice_h['date_renew']));
                ?>
예제 #8
0
 public function delete_customer($customer_id, $remove_linked_data = true)
 {
     $customer_id = (int) $customer_id;
     if ($customer_id > 0) {
         if (_DEMO_MODE && $customer_id == 1) {
             set_error('Sorry this is a Demo Customer. It cannot be changed.');
             redirect_browser(self::link_open($customer_id));
         }
         $customer = self::get_customer($customer_id);
         if ($customer && $customer['customer_id'] == $customer_id) {
             // todo: Delete emails (wack these in this customer_deleted hook)
             hook_handle_callback('customer_deleted', $customer_id, $remove_linked_data);
             if (class_exists('module_group', false)) {
                 // remove the customer from his groups
                 module_group::delete_member($customer_id, 'customer');
             }
             if (class_exists('module_extra', false)) {
                 module_extra::delete_extras('customer', 'customer_id', $customer_id);
             }
             // remove the contacts from this customer
             foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) {
                 if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                     module_user::delete_user($val['user_id']);
                 }
             }
             // remove staff
             delete_from_db('customer_user_rel', 'customer_id', $customer_id);
             if (class_exists('module_note', false)) {
                 module_note::note_delete("customer", 'customer_id', $customer_id);
             }
             handle_hook("address_delete", $this, 'all', "customer", 'customer_id', $customer_id);
             // todo, check the 'delete' permission on each one of these 'delete' method calls
             // do that better when we remove each of these and put them into the customer delete hook
             if ($remove_linked_data) {
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_website::delete_website($val['website_id']);
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_job::delete_job($val['job_id']);
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_invoice::delete_invoice($val['invoice_id']);
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_quote::delete_quote($val['quote_id']);
                         }
                     }
                 }
                 //handle_hook("file_delete",$this,"customer",'customer_id',$customer_id);
             } else {
                 // instead of deleting these records we just update them to customer_id = 0
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('website_id', $val['website_id'], 'website', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('job_id', $val['job_id'], 'job', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('invoice_id', $val['invoice_id'], 'invoice', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('quote_id', $val['quote_id'], 'quote', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_file', false) && module_file::is_plugin_enabled()) {
                     foreach (module_file::get_files(array('owner_id' => $customer_id, 'owner_table' => 'customer')) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('file_id', $val['file_id'], 'file', array('owner_id' => 0, 'owner_table' => ''));
                         }
                     }
                 }
             }
             // finally delete the main customer record
             // (this is so the above code works with its sql joins)
             $sql = "DELETE FROM " . _DB_PREFIX . "customer WHERE customer_id = '" . $customer_id . "' LIMIT 1";
             query($sql);
         }
     }
 }
예제 #9
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');
}
$search = isset($_REQUEST['search']) && is_array($_REQUEST['search']) ? $_REQUEST['search'] : array();
if (isset($_REQUEST['customer_id'])) {
    $search['customer_id'] = $_REQUEST['customer_id'];
}
$invoices = module_invoice::get_invoices($search);
$all_invoice_ids = array();
foreach ($invoices as $invoice) {
    $all_invoice_ids[] = $invoice['invoice_id'];
}
if (class_exists('module_table_sort', false) && module_table_sort::is_plugin_enabled()) {
    // get full invoice data.
    // todo: only grab data if we're sorting by something
    // that isn't in the default invoice listing.
    module_table_sort::enable_pagination_hook(array('table_id' => 'invoice_list', 'sortable' => array('invoice_number' => array('field' => 'name'), 'invoice_status' => array('field' => 'status'), 'invoice_create_date' => array('field' => 'date_create', 'current' => 2), 'invoice_due_date' => array('field' => 'date_due'), 'invoice_sent_date' => array('field' => 'date_sent'), 'invoice_paid_date' => array('field' => 'date_paid'), 'invoice_customer' => array('field' => 'customer_name'), 'c_invoice_total' => array('field' => 'cached_total'), 'c_invoice_total_due' => array('field' => 'total_amount_due'))));
    if (isset($_REQUEST['table_sort_column']) || isset($_SESSION['_table_sort']) && isset($_SESSION['_table_sort']['invoice_list']) && isset($_SESSION['_table_sort']['invoice_list'][0])) {
        // we're sorting by something!
        reset($invoices);
        $test = current($invoices);
        if ($test && $test['invoice_id']) {
            $column = isset($_REQUEST['table_sort_column']) ? $_REQUEST['table_sort_column'] : $_SESSION['_table_sort']['invoice_list'][0];
예제 #10
0
    }
    if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
        foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['website'][] = $val['website_id'];
        }
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['job'][] = $val['job_id'];
            foreach (module_invoice::get_invoices(array('job_id' => $val['job_id'])) as $val) {
                $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
            }
        }
    }
    if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
        foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['invoice'][$val['invoice_id']] = $val['invoice_id'];
        }
    }
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'All ' . $page_type_single . ' Notes', 'owner_table' => 'customer', 'owner_id' => $customer_id, 'view_link' => $module->link_open($customer_id), 'display_summary' => true, 'summary_owners' => $note_summary_owners));
    }
}
hook_handle_callback('customer_edit', $customer_id);
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'onclick' => "\$('#form_redirect').val('" . $module->link_open(false) . "');", 'value' => _l('Save and Return')), array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save')), array('ignore' => !(module_customer::can_i('delete', 'Customers') && $customer_id > 0), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . $module->link_open(false) . "';")));
echo module_form::generate_form_actions($form_actions);
?>