Improvements to payment and other misc items
This commit is contained in:
@@ -10,24 +10,11 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Payment_Bulk_Ezypay {
|
||||
public function form() {
|
||||
$result = '';
|
||||
private function file($name) {
|
||||
$result = array();
|
||||
|
||||
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
|
||||
$result .= Form::hidden('payer',$_POST['payer']);
|
||||
$result .= View::factory('payment/admin/addbulk/ezypay');
|
||||
$result .= Form::submit('submit','submit',array('class'=>'form_button'));
|
||||
$result .= Form::close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function process() {
|
||||
$payments = array();
|
||||
|
||||
// Process payment
|
||||
$file = file_get_contents($_FILES['payment']['tmp_name']);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
// Process file
|
||||
$file = preg_split("/[\r]?[\n]+/",file_get_contents($_FILES[$name]['tmp_name']));
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
@@ -37,8 +24,33 @@ class Payment_Bulk_Ezypay {
|
||||
|
||||
// Trim our whitespace on the end of the line.
|
||||
$line = preg_replace("/\s+$/",'',$line);
|
||||
$array = explode("\t",$line);
|
||||
array_push($result,explode("\t",$line));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The input form to capture the required files
|
||||
*/
|
||||
public function form() {
|
||||
$result = '';
|
||||
|
||||
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data','class'=>'form-horizontal'));
|
||||
$result .= View::factory('payment/admin/addbulk/ezypay');
|
||||
$result .= Form::close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the uploaded files
|
||||
*/
|
||||
public function process() {
|
||||
// Process payment
|
||||
$payments = array();
|
||||
|
||||
foreach ($this->file('payment') as $line => $array) {
|
||||
// Field 4 has our account reference
|
||||
if (preg_match('/^'.Company::instance()->site(TRUE).'-/',$array[4]) AND $array[10] == 'Cleared') {
|
||||
$aid = preg_replace('/^'.Company::instance()->site(TRUE).'-/','',$array[4]);
|
||||
@@ -46,62 +58,59 @@ class Payment_Bulk_Ezypay {
|
||||
$po = ORM::factory('Payment');
|
||||
$po->account_id = $aid;
|
||||
$po->total_amt = $array[7];
|
||||
$po->notes = $array[2].':'.$array[3];
|
||||
$po->checkout_data = array('transid'=>$array[2].':'.$array[3]);
|
||||
$po->date_payment = strtotime(str_replace('/','-',$array[8]));
|
||||
|
||||
$sbo = $po->account->service_billing->where('plugin_data','=',$array[3])->find();
|
||||
if (! $sbo->loaded())
|
||||
throw HTTP_Exception::factory(501,'No Service Billing Data for :aid (:pd)?',array(':aid'=>$aid,':pd'=>$array[3]));
|
||||
|
||||
$po->checkout_id = $sbo->checkout_id;
|
||||
|
||||
$payments[$array[3]] = $po;
|
||||
}
|
||||
}
|
||||
|
||||
$file = file_get_contents($_FILES['transaction']['tmp_name']);
|
||||
$file = preg_split("/[\r]?[\n]+/",$file);
|
||||
|
||||
$i = 0;
|
||||
foreach ($file as $line) {
|
||||
// Line 0 is our header
|
||||
if ($i++ == 0 OR ! trim($line))
|
||||
continue;
|
||||
|
||||
// Trim our whitespace on the end of the line.
|
||||
$line = preg_replace("/\s+$/",'',$line);
|
||||
$array = explode("\t",$line);
|
||||
|
||||
foreach ($this->file('transaction') as $line => $array) {
|
||||
// If we dont have a payment item for this fee, we'll continue.
|
||||
if (! isset($payments[$array[3]]))
|
||||
continue;
|
||||
|
||||
// Our commission fees
|
||||
// @todo This should be in a config file
|
||||
// Our commission fees, which appear has Type 1 or 15
|
||||
if (in_array($array[9],array(1,15)))
|
||||
$payments[$array[3]]->fees_amt = (float)$array[7];
|
||||
|
||||
// @todo Hack - since the reports dont show how the payment was made.
|
||||
// @todo Put this in a config file, in the mean time.
|
||||
if ($array[7] == 1.05)
|
||||
$payments[$array[3]]->checkout_id = 2;
|
||||
else
|
||||
$payments[$array[3]]->checkout_id = 4;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/head');
|
||||
|
||||
$total = $fees = 0;
|
||||
foreach ($payments as $po) {
|
||||
$po->save();
|
||||
|
||||
if (! $po->saved())
|
||||
throw HTTP_Exception::factory(501,'Failed to Save Payment for :aid (:pd)?',array(':aid'=>$po->account_id,':pd'=>$po->checkout_data['transid']));
|
||||
|
||||
$total += $po->total_amt;
|
||||
$fees += $po->fees_amt;
|
||||
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/body')
|
||||
->set('o',$po);
|
||||
}
|
||||
|
||||
$result .= View::Factory('payment/admin/addbulk/ezypay/foot')
|
||||
->set('total',$total)
|
||||
->set('fees',$fees);;
|
||||
$output = Table::factory()
|
||||
->data($payments)
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'date_payment'=>'Date',
|
||||
'checkout->display("name")'=>'Method',
|
||||
'total_amt'=>'Amount',
|
||||
'fees_amt'=>'Fees',
|
||||
'account->accnum()'=>'Cust ID',
|
||||
'account->name()'=>'Customer',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','payment/view/')),
|
||||
));
|
||||
|
||||
return $result;
|
||||
return View::factory('payment/admin/addbulk/ezypay_processed')
|
||||
->set('table',$output)
|
||||
->set('fee',$fees)
|
||||
->set('total',$total);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user