Minor work on ADSL/Domain/Hosting and other minor fixes

This commit is contained in:
Deon George 2011-10-11 10:38:21 +11:00
parent 0f45467ec8
commit 50a096e22a
12 changed files with 110 additions and 28 deletions

View File

@ -146,6 +146,12 @@ $(document).ready(function() {
});
}
});
// Double click to select a row
$("#select-table tr:not(.head)")
.dblclick(function(e) {
window.location = $("a", this).attr("href");
});
});
'));

View File

@ -19,12 +19,10 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
* Show a list of invoices
*/
public function action_list() {
$io = ORM::factory('invoice');
Block::add(array(
'title'=>_('System Customer Invoices'),
'body'=>Table::display(
$io->find_all(),
ORM::factory('invoice')->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
@ -43,12 +41,5 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
)),
));
}
public function action_convert() {
if (Config::sitemode() != KOHANA::DEVELOPMENT)
throw new Kohana_Exception(__METHOD__.' can only be run in development');
else
throw new Kohana_Exception(__METHOD__.' can be run in development');
}
}
?>

View File

@ -18,7 +18,7 @@ class Model_Invoice extends ORMOSB {
);
protected $_has_many = array(
'invoice_item'=>array('far_key'=>'id'),
'invoice_item_tax'=>array(),
'invoice_item_tax'=>array('through'=>'invoice_item'),
'service'=>array('through'=>'invoice_item'),
'payment'=>array('through'=>'payment_item'),
'payment_item'=>array('far_key'=>'id'),
@ -112,7 +112,11 @@ class Model_Invoice extends ORMOSB {
$result = 0;
foreach ($this->items() as $ito)
$result += $ito->tax_amt;
$result += $ito->tax();
// @todo This should eventually be removed.
if (! $result AND $this->tax_amt)
$result = $this->tax_amt;
return $format ? Currency::display($result) : $result;
}
@ -188,7 +192,7 @@ class Model_Invoice extends ORMOSB {
*
* @param int Service ID
*/
private function items_service($sid) {
private function list_items_service($sid) {
return $this->invoice_item->where('service_id','=',$sid)->find_all();
}
@ -198,7 +202,7 @@ class Model_Invoice extends ORMOSB {
public function items_service_total($sid) {
$total = 0;
foreach ($this->items_service($sid) as $ito)
foreach ($this->list_items_service($sid) as $ito)
$total += $ito->total();
return $total;
@ -206,16 +210,19 @@ class Model_Invoice extends ORMOSB {
/**
* Calculate the tax of items for a service
* @todo This can be optimised
*/
public function items_service_tax($sid) {
$total = 0;
foreach ($this->items_service($sid) as $ito)
foreach ($this->list_items_service($sid) as $ito)
$total += $ito->tax_amt;
return $total;
}
// @todo Add discounts
/**
* Return a list of items based on a sort criteria
*/
@ -242,6 +249,7 @@ class Model_Invoice extends ORMOSB {
/**
* Return a list of taxes used on this invoice
* @todo Move some of this to invoice_item_tax.
*/
public function tax_summary() {
$summary = array();
@ -255,6 +263,10 @@ class Model_Invoice extends ORMOSB {
}
}
// @todo This should be removed eventually
if (! $summary AND $this->tax_amt)
$summary[1] = $this->tax_amt;
return $summary;
}

View File

@ -11,6 +11,9 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Invoice_Item extends ORMOSB {
protected $_updated_column = FALSE; // @todo No update columns
// Relationships
protected $_belongs_to = array(
'product'=>array(),
'invoice'=>array(),
@ -19,7 +22,16 @@ class Model_Invoice_Item extends ORMOSB {
protected $_has_many = array(
'invoice_item_tax'=>array('far_key'=>'id')
);
protected $_updated_column = FALSE; // @todo No update columns
protected $_display_filters = array(
'date_start'=>array(
array('Config::date',array(':value')),
),
'date_stop'=>array(
array('Config::date',array(':value')),
),
);
// Display a transaction number
public function trannum() {
@ -35,6 +47,31 @@ class Model_Invoice_Item extends ORMOSB {
return sprintf('%s -> %s',Config::date($this->date_start),Config::date($this->date_stop));
}
// Sum up the tax that applies to this invoice item
public function tax() {
$amount = 0;
foreach ($this->invoice_item_tax->find_all() as $iit)
$amount += $iit->amount;
return $amount;
}
// This total of this item before discounts and taxes
public function subtotal() {
return ($this->price_base)*$this->quantity;
}
// The total of all discounts
public function discount() {
return $this->discount_amt;
}
public function total() {
// @todo This rounding should be a system config
return round($this->subtotal()+$this->tax()-$this->discount(),2);
}
public function invoice_detail_items() {
if ($this->item_type != 0)
return;
@ -42,14 +79,6 @@ class Model_Invoice_Item extends ORMOSB {
return $this->service->details('invoice_detail_items');
}
public function subtotal() {
return ($this->price_base+$this->price_setup)*$this->quantity;
}
public function total() {
return ($this->price_base+$this->price_setup)*$this->quantity+$this->tax_amt-$this->discount_amt;
}
public function save(Validation $validation = NULL) {
// Save the invoice item
parent::save();
@ -80,8 +109,6 @@ class Model_Invoice_Item extends ORMOSB {
// Save DISCOUNT details
// @todo calculate discounts
$this->tax_amt = $tax_total;
$this->total_amt = $this->total();
parent::save();
} else

View File

@ -70,7 +70,7 @@
<!-- Product Information -->
<tr class="head">
<td><?php echo HTML::anchor('/user/service/view/'.$item->service->id,$item->service->id()); ?></td>
<td colspan="3"><?php echo $item->product->product_translate->find()->name; ?> (<?php echo $item->product_id; ?>)</td>
<td colspan="3"><?php echo $item->product_name ? $item->product_name : $item->product->product_translate->find()->name; ?> (<?php echo $item->product_id; ?>)</td>
<td class="right"><?php echo Currency::display($io->items_service_total($item->service_id));?></td>
</tr>
<!-- End Product Information -->
@ -109,7 +109,7 @@
<tr>
<td colspan="2">&nbsp;</td>
<td><?php echo _('Taxes'); ?></td>
<td class="right"><?php echo Currency::display($io->items_service_tax($item->service_id));?></td>
<td class="right"><?php echo $io->tax(TRUE);?></td>
</tr>
<!-- Product End Sub Items Tax -->
<?php } ?>

View File

@ -23,6 +23,9 @@ class Model_Product extends ORMOSB {
);
protected $_display_filters = array(
'active'=>array(
array('StaticList_YesNo::display',array(':value')),
),
'price_type'=>array(
array('StaticList_PriceType::display',array(':value')),
),
@ -43,6 +46,7 @@ class Model_Product extends ORMOSB {
/**
* Get the product name, after translating
* @todo This needs to be improved to find the right language item.
*/
public function name() {
return $this->product_translate->find()->display('name');

View File

@ -19,6 +19,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'listdomainservices'=>TRUE,
'listhostservices'=>TRUE,
'listhspaservices'=>TRUE,
'listinvoicesoon'=>TRUE,
'update'=>TRUE,
);
@ -434,6 +435,33 @@ ORDER BY c.id,s.recur_schedule,c.name,a.company,a.last_name,a.first_name
return $return;
}
/**
* List services that need to be invoiced.
*/
public function action_listinvoicesoon() {
Block::add(array(
'title'=>_('Services to Invoice'),
'body'=>Table::display(
ORM::factory('service')->list_invoicesoon(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
'price'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
public function action_update($id) {
$so = ORM::factory('service',$id);

View File

@ -163,5 +163,19 @@ class Model_Service extends ORMOSB {
return $result;
}
/**
* List services that need to be billed.
*/
public function list_invoicesoon() {
$result = array();
foreach ($this->list_active() as $so)
// @todo This should be configurable
if (! $so->suspend_billing AND $so->date_next_invoice < time()+35*86400)
array_push($result,$so);
return $result;
}
}
?>