Added Tasks to KH
This commit is contained in:
48
modules/invoice/classes/controller/task/invoice.php
Normal file
48
modules/invoice/classes/controller/task/invoice.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides OSB invoice task capabilities.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Invoice
|
||||
* @category Controllers/Task
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Task_Invoice extends Controller_Task {
|
||||
public function action_list($mode) {
|
||||
$io = ORM::factory('invoice');
|
||||
$tm = 'list_'.$mode;
|
||||
|
||||
if (! method_exists($io,$tm))
|
||||
throw new Kohana_Exception('Unknown Task List command :command',array(':command'=>$mode));
|
||||
|
||||
$total = $numinv = 0;
|
||||
$duelist = View::factory('invoice/task/'.$tm.'_header');
|
||||
foreach ($io->$tm() as $t) {
|
||||
$duelist .= View::factory('invoice/task/'.$tm.'_body')
|
||||
->set('io',$t);
|
||||
|
||||
$numinv++;
|
||||
$total += $t->due();
|
||||
}
|
||||
$duelist .= View::factory('invoice/task/'.$tm.'_footer');
|
||||
|
||||
// Send our email
|
||||
$et = EmailTemplate::instance('task_invoice_overdue');
|
||||
|
||||
// @todo Update this to be dynamic
|
||||
$et->to = array('account'=>array(1,68));
|
||||
$et->variables = array(
|
||||
'TABLE'=>$duelist,
|
||||
'NUM_INV'=>$numinv,
|
||||
'TOTAL'=>$total,
|
||||
);
|
||||
$et->send();
|
||||
|
||||
$output = sprintf('List (%s) sent to: %s',$mode,implode(',',array_keys($et->to)));
|
||||
$this->response->body($output);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -324,5 +324,37 @@ class Model_Invoice extends ORMOSB {
|
||||
|
||||
$this->_changed[$field] = $field;
|
||||
}
|
||||
|
||||
/** LIST FUNCTIONS **/
|
||||
|
||||
/**
|
||||
* Identify all the invoices that are due
|
||||
*/
|
||||
private function _list_due($time=NULL,$op='<=') {
|
||||
if (is_null($time))
|
||||
$time = time();
|
||||
|
||||
// @todo This rounding should be a system configuration
|
||||
return $this
|
||||
->where('round(total_amt-ifnull(credit_amt,0),2)','>','=billed_amt')
|
||||
->and_where('due_date',$op,$time)
|
||||
->and_where('status','=',1)
|
||||
->order_by('due_date,account_id,id')
|
||||
->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoices that are over their due date.
|
||||
*/
|
||||
public function list_overdue($time=NULL) {
|
||||
return $this->_list_due($time,'<=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoices that are due, excluding overdue.
|
||||
*/
|
||||
public function list_due($time=NULL) {
|
||||
return $this->_list_due($time,'>');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -2465,17 +2465,17 @@ AND (
|
||||
$this->setRecordAttr('account_id',$so->getRecordAttr('account_id'));
|
||||
$this->setRecordAttr('account_billing_id',$so->getRecordAttr('account_billing_id'));
|
||||
$this->setRecordAttr('billed_currency_id',$ao->getRecordAttr('currency_id'));
|
||||
$this->setRecordAttr('actual_billed_currency_id',DEFAULT_CURRENCY);
|
||||
// $this->setRecordAttr('actual_billed_currency_id',DEFAULT_CURRENCY);
|
||||
$this->setRecordAttr('reseller_id',$ao->getRecordAttr('reseller_id'));
|
||||
$this->setRecordAttr('checkout_plugin_id',$ao->getRecordAttr('checkout_plugin_id'));
|
||||
$this->setRecordAttr('checkout_plugin_data',$ao->getRecordAttr('checkout_plugin_data'));
|
||||
$this->setRecordAttr('grace_period',$ao->getRecordAttr('invoice_grace'));
|
||||
// $this->setRecordAttr('checkout_plugin_data',$ao->getRecordAttr('checkout_plugin_data'));
|
||||
// $this->setRecordAttr('grace_period',$ao->getRecordAttr('invoice_grace'));
|
||||
|
||||
# @todo this may unintentially allocate all service revenue to an affiliate, which should be configurable (not just the service that the account signed up for initially)
|
||||
$this->setRecordAttr('affiliate_id',$ao->getRecordAttr('affiliate_id'));
|
||||
// $this->setRecordAttr('affiliate_id',$ao->getRecordAttr('affiliate_id'));
|
||||
|
||||
# @todo the parent invoice should bring this campaign id.
|
||||
$this->setRecordAttr('campaign_id',null);
|
||||
// $this->setRecordAttr('campaign_id',null);
|
||||
}
|
||||
|
||||
$this->setRecordAttr('due_date',$so->getRecordAttr('date_next_invoice'));
|
||||
@@ -2519,7 +2519,7 @@ AND (
|
||||
$last_invoice = $x;
|
||||
}
|
||||
|
||||
array_push($invoice['recur_schedules'],$so->getRecordAttr('recur_schedule'));
|
||||
// array_push($invoice['recur_schedules'],$so->getRecordAttr('recur_schedule'));
|
||||
|
||||
# Update the last & next invoice date for this service
|
||||
$rs = $db->Execute(sqlUpdate($db,'service',
|
||||
@@ -2616,17 +2616,17 @@ AND (
|
||||
else
|
||||
$grace_period = GRACE_PERIOD;
|
||||
|
||||
$this->setRecordAttr('notice_next_date',time());
|
||||
// $this->setRecordAttr('notice_next_date',time());
|
||||
$this->setRecordAttr('billing_status',0);
|
||||
$this->setRecordAttr('print_status',0);
|
||||
$this->setRecordAttr('process_status',0);
|
||||
$this->setRecordAttr('status',1);
|
||||
// $this->setRecordAttr('suspend_billing',0);
|
||||
$this->setRecordAttr('billed_amt',0);
|
||||
$this->setRecordAttr('actual_billed_amt',0);
|
||||
$this->setRecordAttr('notice_count',0);
|
||||
$this->setRecordAttr('type',1);
|
||||
$this->setRecordAttr('notice_max',MAX_BILLING_NOTICE);
|
||||
// $this->setRecordAttr('actual_billed_amt',0);
|
||||
// $this->setRecordAttr('notice_count',0);
|
||||
// $this->setRecordAttr('type',1);
|
||||
// $this->setRecordAttr('notice_max',MAX_BILLING_NOTICE);
|
||||
$rs = $this->sql_SaveRecord(true);
|
||||
|
||||
if (! $rs) {
|
||||
@@ -2761,10 +2761,10 @@ AND (
|
||||
'total_amt' => $total,
|
||||
'billed_amt' => 0,
|
||||
'billed_currency_id'=> DEFAULT_CURRENCY,
|
||||
'actual_billed_amt' => 0,
|
||||
'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'],
|
||||
// 'actual_billed_amt' => 0,
|
||||
// 'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'],
|
||||
'notice_count' => 0,
|
||||
'notice_next_date' => time(),
|
||||
// 'notice_next_date' => time(),
|
||||
'notice_max' => MAX_BILLING_NOTICE,
|
||||
'grace_period' => 0,
|
||||
'due_date' => $due_date
|
||||
@@ -3402,7 +3402,7 @@ AND (
|
||||
$sInvoicesBal = array();
|
||||
$db = &DB();
|
||||
$rs = $db->Execute(sqlSelect('invoice','date_orig,account_id,id,total_amt,billed_amt,IFNULL(credit_amt,0) as credit_amt,ROUND(total_amt-billed_amt-IFNULL(credit_amt,0),2) as balance',
|
||||
array('where'=>'(refund_status=0 OR refund_status IS NULL) AND status=1 AND total_amt-billed_amt-IFNULL(credit_amt,0)!=0','orderby'=>'account_id,date_orig,id')));
|
||||
array('where'=>'status=1 AND total_amt-billed_amt-IFNULL(credit_amt,0)!=0','orderby'=>'account_id,date_orig,id')));
|
||||
if ($rs && $rs->RecordCount()) {
|
||||
while (! $rs->EOF) {
|
||||
$invoice = array();
|
||||
|
@@ -19,19 +19,13 @@
|
||||
<index>
|
||||
<orig>date_orig</orig>
|
||||
<last>date_last</last>
|
||||
<parent>parent_id</parent>
|
||||
<billing>billing_status</billing>
|
||||
<process>process_status</process>
|
||||
<suspend>suspend_billing</suspend>
|
||||
<refund>refund_status</refund>
|
||||
<account>account_id</account>
|
||||
<affiliate>affiliate_id</affiliate>
|
||||
<campaign>campaign_id</campaign>
|
||||
<reseller>reseller_id</reseller>
|
||||
<amount>total_amt</amount>
|
||||
<due_date>due_date</due_date>
|
||||
<checkout>checkout_plugin_id</checkout>
|
||||
<tax>tax_id</tax>
|
||||
<net_term>net_term_id</net_term>
|
||||
</index>
|
||||
|
||||
@@ -66,16 +60,6 @@
|
||||
<display>Active</display>
|
||||
<type>L</type>
|
||||
</status>
|
||||
<!-- @todo UNKNOWN - used when recurring payments come in, they must be linked to an invoice number -->
|
||||
<!-- DELETED
|
||||
<parent_id>
|
||||
<type>I4</type>
|
||||
</parent_id>
|
||||
-->
|
||||
<!-- NULL = IMPORTED INVOICE, 0=UNUSED, 2 = CHECKOUT INVOICE,1 = REOCURRING INVOICE -->
|
||||
<type>
|
||||
<type>L</type>
|
||||
</type>
|
||||
<!-- Invoice Approved: 1=YES, 0=UNUSED, NULL = NO (Approved invoices can have services provisioned) -->
|
||||
<process_status>
|
||||
<type>L</type>
|
||||
@@ -85,17 +69,6 @@
|
||||
<display>Invoice Status</display>
|
||||
<type>L</type>
|
||||
</billing_status>
|
||||
<!-- Invoice has been refunded when STATUS = 1 -->
|
||||
<refund_status>
|
||||
<display>Refund Status</display>
|
||||
<type>L</type>
|
||||
</refund_status>
|
||||
<!-- Suspend billing of reocurring invoices, where this invoice is the 1st/parent invoice -->
|
||||
<!-- DELETED
|
||||
<suspend_billing>
|
||||
<type>L</type>
|
||||
</suspend_billing>
|
||||
-->
|
||||
<!-- 1 = Has this invoice been printed -->
|
||||
<print_status>
|
||||
<type>L</type>
|
||||
@@ -115,16 +88,6 @@
|
||||
<affiliate_id>
|
||||
<type>C(32)</type>
|
||||
</affiliate_id>
|
||||
<!-- The compaign that resulted in this revenue -->
|
||||
<campaign_id>
|
||||
<type>I4</type>
|
||||
</campaign_id>
|
||||
<!-- @todo UNKNOWN -->
|
||||
<!-- DELETED
|
||||
<custom_affiliate_status>
|
||||
<type>L</type>
|
||||
</custom_affiliate_status>
|
||||
-->
|
||||
<!-- The reseller who should be credited for this invoice revenue -->
|
||||
<reseller_id>
|
||||
<type>C(32)</type>
|
||||
@@ -138,13 +101,6 @@
|
||||
<type>C(255)</type>
|
||||
<convert>array</convert>
|
||||
</checkout_plugin_data>
|
||||
<!-- The TAX id applicable for this invoice -->
|
||||
<!-- DELETED
|
||||
<tax_id>
|
||||
<display>Taxes</display>
|
||||
<type>I4</type>
|
||||
</tax_id>
|
||||
-->
|
||||
<!-- The amount of TAX this invoice includes -->
|
||||
<tax_amt>
|
||||
<display>Total Taxes</display>
|
||||
@@ -155,24 +111,11 @@
|
||||
<display>Total Credits</display>
|
||||
<type>F</type>
|
||||
</credit_amt>
|
||||
<!-- @todo - ? The discounts that were applied to this invoice -->
|
||||
<!-- DELETED
|
||||
<discount_arr>
|
||||
<type>C(255)</type>
|
||||
<convert>array</convert>
|
||||
</discount_arr>
|
||||
-->
|
||||
<!-- The amount of DISCOUNT this invoice includes -->
|
||||
<discount_amt>
|
||||
<display>Total Discounts</display>
|
||||
<type>F</type>
|
||||
</discount_amt>
|
||||
<!-- @todo?? The amount of re-ocurring items on this invoice -->
|
||||
<!-- DELETED
|
||||
<recur_amt>
|
||||
<type>F</type>
|
||||
</recur_amt>
|
||||
-->
|
||||
<!-- Invoice Total Charges (including taxes ??) -->
|
||||
<total_amt>
|
||||
<display>Amount</display>
|
||||
@@ -195,34 +138,12 @@
|
||||
<actual_billed_currency_id>
|
||||
<type>I4</type>
|
||||
</actual_billed_currency_id>
|
||||
<!-- @todo ?? -->
|
||||
<notice_count>
|
||||
<type>I4</type>
|
||||
</notice_count>
|
||||
<!-- @todo ?? -->
|
||||
<notice_max>
|
||||
<type>I4</type>
|
||||
</notice_max>
|
||||
<!-- @todo ?? -->
|
||||
<notice_next_date>
|
||||
<type>I8</type>
|
||||
<convert>date-time</convert>
|
||||
</notice_next_date>
|
||||
<!-- @todo ?? -->
|
||||
<grace_period>
|
||||
<type>I4</type>
|
||||
</grace_period>
|
||||
<!-- The date this invoice is due -->
|
||||
<due_date>
|
||||
<display>Date Due</display>
|
||||
<type>I8</type>
|
||||
<convert>date-time</convert>
|
||||
</due_date>
|
||||
<!-- @todo ?? -->
|
||||
<!-- DELETED
|
||||
<recur_arr>
|
||||
<type>X</type>
|
||||
</recur_arr> -->
|
||||
<!-- Admin notes attached to the invoice -->
|
||||
<notes>
|
||||
<type>X</type>
|
||||
@@ -231,33 +152,20 @@
|
||||
<net_term_id>
|
||||
<type>L</type>
|
||||
</net_term_id>
|
||||
<!-- @todo ?? -->
|
||||
<net_term_date_last>
|
||||
<type>I8</type>
|
||||
</net_term_date_last>
|
||||
<!-- @todo ?? -->
|
||||
<net_term_intervals>
|
||||
<type>I4</type>
|
||||
</net_term_intervals>
|
||||
<!-- @todo ?? -->
|
||||
<!-- DELETED
|
||||
<ip>
|
||||
<type>C(32)</type>
|
||||
</ip> -->
|
||||
</field>
|
||||
|
||||
<!-- Methods for this class, and the fields they have access to, if applicable -->
|
||||
<method>
|
||||
<add>id,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,status</add>
|
||||
<update>id,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</update>
|
||||
<add>id,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,status</add>
|
||||
<update>id,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</update>
|
||||
<delete>id</delete>
|
||||
<view>id,date_orig,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,credit_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</view>
|
||||
<search>id,date_orig,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</search>
|
||||
<export_excel>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_excel>
|
||||
<export_pdf>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_pdf>
|
||||
<export_xml>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_xml>
|
||||
<export_csv>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_csv>
|
||||
<export_tab>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_tab>
|
||||
<view>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,credit_amt,billed_currency_id,due_date,net_term_id</view>
|
||||
<search>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</search>
|
||||
<export_excel>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_excel>
|
||||
<export_pdf>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_pdf>
|
||||
<export_xml>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_xml>
|
||||
<export_csv>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_csv>
|
||||
<export_tab>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_tab>
|
||||
</method>
|
||||
|
||||
<!-- Method triggers -->
|
||||
|
6
modules/invoice/views/invoice/task/list_overdue_body.php
Normal file
6
modules/invoice/views/invoice/task/list_overdue_body.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<tr>
|
||||
<td><?php echo $io->account->name(); ?></td>
|
||||
<td><?php echo $io->display('due_date'); ?></td>
|
||||
<td><?php echo $io->id(); ?></td>
|
||||
<td><?php echo $io->due(TRUE); ?></td>
|
||||
</tr>
|
@@ -0,0 +1 @@
|
||||
</table>
|
@@ -0,0 +1,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td>Account</td>
|
||||
<td>Due Date</td>
|
||||
<td>Inv ID</td>
|
||||
<td>Amount Due</td>
|
||||
</tr>
|
Reference in New Issue
Block a user