Fixes from live website

This commit is contained in:
Deon George
2013-04-20 11:40:44 +10:00
parent 13982be9f6
commit 79c76995b9
22 changed files with 283 additions and 55 deletions

View File

@@ -496,7 +496,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
public function action_listadslbilling() {
$id = $this->request->param('id');
$aso = ORM::factory('Adsl_Supplier',$id);
$aso = ORM::factory('ADSL_Supplier',$id);
// Process upload
// @todo This should be separated out by supplier in case each supplier has a different format
@@ -616,37 +616,61 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
if (! $start && preg_match('/^Item ID,/',$line)) {
$start = true;
continue;
// Items end after "Subtotal"
} elseif ($start && ! $end && preg_match('/^Subtotal:,/',$line)) {
$end = true;
continue;
// If we havent started or not ended, continue
} elseif (! $start || $end) {
continue;
}
// @todo This is to workaround SEP2012 CSV invoice which had extra columns.
if (count(explode(',',$line)) == 9)
list($id,$ref,$unknown,$unknown,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
elseif (count(explode(',',$line)) == 10)
list($id,$ref,$unknown,$unknown,$unknown,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
else
list($id,$ref,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
$record = explode(',',$line);
// Extract the phone number from the $linedata
@list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$linedata)));
// 1 = Item ID (ignore)
// 2 = Reference ID (ignore - its not useful for us)
// 3 = Category (always appears blank)
// 4 = Item Description (has our service number, rental and excess charges description)
// 0nnnnnnnnn - Monthly Internet Charge On Plan XXXXX For billing period (dd/mm/yyyy - dd/mm/yyyy) (7 FIELDED LINES)
// 0nnnnnnnnn - Excess usage charges for March 2013 (8 FIELDED LINES)
// 5 = Quantity
// Always 1 for Plan Fees
// 0nnnnnnnnn@graytech.net.au Excess Usage y GB (for excess charges)
// 6 = Unit Price
// Always 1 for Excess Usage (probably quantity)
// 7 = Total Price
// Unit price for Excess Usage
// 8 = Total Price for Excess Usage
// If the description says Monthly Charge, we know its the monthly fee.
if (preg_match('/^Monthly Charge/',$description))
$result[$service]['cost'] = preg_replace('/\$/','',$total);
// If the description says VISP credit, we know this is commission.
elseif (preg_match('/^VISP Credit/',$description))
$result[$service]['credit'] = preg_replace('/\$/','',$total);
// If the description says Excess, we know this is excess charges.
elseif (preg_match('/^Excess usage/',$description))
$result[$service]['excess'] = preg_replace('/\$/','',$total);
else
$result[$service]['info'] = $line;
if (! count($record) >= 7)
throw Kohana_Exception('Format of CSV file changed? (:record)',array(':record'=>$record));
if (preg_match('/Monthly Internet Charge On Plan /',$record[3])) {
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
$result[$service]['cost'] = str_replace('$','',$record[6]);
} elseif (preg_match('/VISP Credit/',$record[3])) {
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
$result[$service]['credit'] = str_replace('$','',$record[6]);
} elseif (preg_match('/Excess usage charges for /',$record[3])) {
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
$result[$service]['excess'] = str_replace('$','',$record[7]);
// Ignore Payment For Invoice lines
} elseif (preg_match('/Payment For Invoice:/',$record[3])) {
} else {
try {
list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$record[3])));
$result[$service]['info'] = $line;
} catch (Exception $e) {
$result['000']['info'] = $line;
}
}
}
return $result;