Local fixes to invoice display and retrieve traffic data

This commit is contained in:
Deon George
2011-08-02 16:48:41 +10:00
parent 41eec89afa
commit 5953e28f22
9 changed files with 1039 additions and 15 deletions

View File

@@ -16,5 +16,18 @@ class Model_Charge extends ORMOSB {
'Currency::display',array(':value')
),
);
/**
* Render some details for specific calls, eg: invoice
*/
public function details($type) {
switch ($type) {
case 'invoice':
return sprintf('%s (%s@%s)',$this->description,$this->quantity,Currency::display($this->amount));
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
}
?>

View File

@@ -416,7 +416,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetX($x+8);
$this->Cell(0,0,'Payments Received');
$this->SetX($x+135);
$this->Cell(0,0,Currency::display($this->io->payments()),0,0,'R');
$this->Cell(0,0,$this->io->payments_total(TRUE),0,0,'R');
}
if ($this->io->credit_amt) {

View File

@@ -21,6 +21,7 @@ class Model_Invoice extends ORMOSB {
'invoice_item_tax'=>array(),
'service'=>array('through'=>'invoice_item'),
'payment'=>array('through'=>'payment_item'),
'payment_item'=>array('far_key'=>'id'),
);
protected $_sorting = array(
@@ -132,14 +133,14 @@ class Model_Invoice extends ORMOSB {
}
public function payments() {
return ($this->loaded() AND ! $this->_changed) ? $this->payments->find_all() : NULL;
return ($this->loaded() AND ! $this->_changed) ? $this->payment_item->find_all() : NULL;
}
public function payments_total($format=FALSE) {
$result = 0;
foreach ($this->payments() as $po)
$result += $po->total_amt;
$result += $po->alloc_amt;
return $format ? Currency::display($result) : $result;
}

View File

@@ -47,18 +47,26 @@
<td class="head" colspan="4">Charges Detail:</td>
</tr>
<?php foreach ($invoice->sorted_service_items('recur_schedule') as $cat => $catitems) { ?>
<?php if ($cat) { ?>
<tr>
<td><div id="toggle_<?php echo $cat; ?>"><?php echo HTML::image($mediapath->uri(array('file'=>'img/toggle-closed.png')),array('alt'=>'+')); ?></div><script type="text/javascript">$("#toggle_<?php echo $cat; ?>").click(function() {$('#detail_toggle_<?php echo $cat; ?>').toggle();});</script></td>
<td><?php echo StaticList_RecurSchedule::display($cat); ?></td>
<td><?php printf('%s Services',count($catitems['items'])); ?></td>
<td class="bold-right"><?php echo Currency::display($catitems['total']); ?></td>
</tr>
<?php } else { ?>
<tr>
<td colspan="3">Other Items</td>
<td class="bold-right"><?php echo Currency::display($catitems['total']); ?></td>
</tr>
<?php } ?>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<div id="detail_toggle_<?php echo $cat; ?>">
<table class="box-full" border="0">
<?php foreach ($catitems['items'] as $item) {?>
<?php if ($catitems['items']) { ?>
<?php foreach ($catitems['items'] as $item) { ?>
<!-- Product Information -->
<tr class="head">
<td><?php echo HTML::anchor('/user/service/view/'.$item->service->id,$item->service->id()); ?></td>
@@ -83,7 +91,7 @@
$m = StaticList_Module::record('module','name','id',$subitem->module_id);
// @todo Need to remove the explicit test for 'charge' and be more dynamic
$mi = ORM::factory($m,$m == 'charge' ? $subitem->charge_id : $subitem->id);
$display = $mi->invoice_display();
$display = $mi->details('invoice');
} else {
$display = 'Other';
}
@@ -104,6 +112,28 @@
<td class="right"><?php echo Currency::display($invoice->items_service_tax($item->service_id));?></td>
</tr>
<!-- Product End Sub Items Tax -->
<?php } ?>
<?php } else { ?>
<!-- Product Sub Items -->
<?php
foreach ($invoice->items_sub(NULL) as $subitem) {
if (! is_null($subitem->module_id)) {
$m = StaticList_Module::record('module','name','id',$subitem->module_id);
// @todo Need to remove the explicit test for 'charge' and be more dynamic
$mi = ORM::factory($m,$m == 'charge' ? $subitem->charge_id : $subitem->id);
$display = $mi->details('invoice');
} else {
$display = 'Other';
}
?>
<tr>
<td>&nbsp;</td>
<td><?php echo $subitem->trannum(); ?></td>
<td><?php echo $display; ?></td>
<td class="right"><?php echo Currency::display($subitem->subtotal());?></td>
</tr>
<?php } ?>
<!-- Product End Sub Items -->
<?php } ?>
</table>
</div>

View File

@@ -195,10 +195,13 @@ class Model_Service_ADSL extends Model_Service {
return $this->traffic_month(strtotime('yesterday'),$string);
}
public function traffic_lastmonth_exceed($all=FALSE) {
public function traffic_lastmonth_exceed($all=FALSE,$date=NULL) {
$return = array();
foreach ($this->traffic_month(strtotime('last month'),FALSE) as $k => $v) {
if (is_null($date))
$date = strtotime('last month');
foreach ($this->traffic_month($date,FALSE) as $k => $v) {
// We shouldnt need to eval for nulls, since the traffic calc does that
if ($all OR ($v > $this->adsl_plan->$k)) {
$return[$k]['allowance'] = $this->adsl_plan->$k;
@@ -351,7 +354,7 @@ class Model_Service_ADSL extends Model_Service {
case 'invoice':
return array(
_('Service Address')=>$this->display('service_address'),
_('Contact Until')=>$this->contract_date_end(),
_('Contract Until')=>$this->contract_date_end(),
);
break;
default:

View File

@@ -107,9 +107,11 @@ class Service_Traffic_ADSL {
}
public function charge_excess_traffic() {
$date = strtotime('last month');
// @todo need a way to find out services that have traffic charges dynamically.
foreach ($this->so->services() as $so) {
if ($charge = $so->service_adsl->traffic_lastmonth_exceed(FALSE)) {
if ($charge = $so->service_adsl->traffic_lastmonth_exceed(FALSE,$date)) {
foreach ($charge as $metric => $details) {
$co = ORM::factory('charge');
@@ -128,14 +130,12 @@ class Service_Traffic_ADSL {
sprintf('Allowance==%s',$details['allowance']),
sprintf('Metric==%s',$metric),
sprintf('Used==%s',$details['used']),
sprintf('Month==%s',date('Y-m',strtotime('last month'))),
sprintf('Month==%s',date('Y-m',$date)),
));
$co->check();
$co->save();
}
print_r(array('s'=>$so->id,'a'=>$so->service_adsl->service_number,'al'=>$so->service_adsl->adsl_plan->allowance(FALSE),'charge'=>$charge));
}
}
}

View File

@@ -1,7 +1,5 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
/**
* This class is able to collect traffic information for Exetel HSPA
*
@@ -64,6 +62,8 @@ class Service_Traffic_ADSL_ExetelHSPA extends Service_Traffic_ADSL {
continue;
}
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
$servicedate <= $this->today;
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {