Minor fixes to statement, services and internal things
Many misc updates
This commit is contained in:
@@ -13,77 +13,48 @@
|
||||
class Controller_Admin_Export extends Controller_TemplateDefault_Admin {
|
||||
protected $control_title = 'Export';
|
||||
protected $secure_actions = array(
|
||||
'index'=>TRUE,
|
||||
'export'=>TRUE,
|
||||
'add'=>TRUE,
|
||||
'edit'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Export plugins must define an export action.
|
||||
* Add Export Maping items
|
||||
*/
|
||||
public function action_export() {
|
||||
if (empty($_POST['plugin']))
|
||||
$this->request->redirect('admin/export');
|
||||
public function action_add() {
|
||||
$eo = ORM::factory('export');
|
||||
$output = '';
|
||||
|
||||
$sc = sprintf('Export_%s',$_POST['plugin']);
|
||||
if (! class_exists($sc))
|
||||
throw new Kohana_Exception('Export Class doesnt exist for :plugin',array(':plugin'=>$_POST['plugin']));
|
||||
else
|
||||
$export = new $sc;
|
||||
if ($_POST AND $eo->values($_POST)->check()) {
|
||||
$eo->module_id = ORM::factory('module',array('name'=>'product'))->id; // @todo This probably should be in the form.
|
||||
$eo->plugin_name = 'quicken'; // @todo This should be in the form.
|
||||
// Entry updated
|
||||
if (! $eo->save())
|
||||
throw new Kohana_Exception('Unable to save data :post',array(':post'=>serialize($_POST)));
|
||||
|
||||
$export->export();
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Record add'),
|
||||
'type'=>'info',
|
||||
'body'=>_('Export Map entry added.')
|
||||
));
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
$output .= View::factory('export/admin/map/add')
|
||||
->set('eo',$eo);
|
||||
|
||||
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Add Export Map'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main call to export, providing a list of items to export and
|
||||
* setting up the page to call the export plugin when submitted.
|
||||
* Edit Export Maping items
|
||||
*/
|
||||
public function action_index($daysago) {
|
||||
// @todo this should come from a file list
|
||||
$TBRexportplugins = array('quicken'=>'Export to Quicken');
|
||||
|
||||
if (! $daysago)
|
||||
$daysago = 30;
|
||||
|
||||
$payments = ORM::factory('payment')
|
||||
->export($daysago);
|
||||
|
||||
if (count($payments)) {
|
||||
$output = Form::open(Request::current()->uri(array('action'=>'export')));
|
||||
$output .= '<table class="box-left">';
|
||||
|
||||
$output .= View::factory('export/payment/header')
|
||||
->set('plugins',$TBRexportplugins);
|
||||
|
||||
$i = 0;
|
||||
foreach ($payments as $payment) {
|
||||
$output .= View::factory('export/payment/body')
|
||||
->set('payment',$payment)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
|
||||
$output .= '</table>';
|
||||
$output .= Form::submit('submit','export',array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Payments to Export'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
# Nothing to export
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('No payments to export'),
|
||||
'type'=>'info',
|
||||
'body'=>sprintf(_('There are no payments within the last %s days (since %s) to show.'),
|
||||
$daysago,date(Kohana::config('osb')->get('date_format'),$daysago*86400+time())),
|
||||
));
|
||||
}
|
||||
public function action_edit() {
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -22,7 +22,7 @@ class Controller_Affiliate_Export extends Controller_TemplateDefault_Affiliate {
|
||||
*/
|
||||
public function action_export() {
|
||||
if (empty($_POST['plugin']))
|
||||
$this->request->redirect('affiliate/export');
|
||||
$this->request->redirect('affiliate/export/index');
|
||||
|
||||
$sc = sprintf('Export_%s',$_POST['plugin']);
|
||||
if (! class_exists($sc))
|
||||
@@ -38,43 +38,40 @@ class Controller_Affiliate_Export extends Controller_TemplateDefault_Affiliate {
|
||||
* This is the main call to export, providing a list of items to export and
|
||||
* setting up the page to call the export plugin when submitted.
|
||||
*/
|
||||
public function action_index($daysago) {
|
||||
public function action_index() {
|
||||
// @todo this should come from a file list
|
||||
$TBRexportplugins = array('quicken'=>'Export to Quicken');
|
||||
|
||||
if (! $daysago)
|
||||
$daysago = 30;
|
||||
|
||||
// @todo: Need to limit this to affiliate acounts
|
||||
$payments = ORM::factory('payment')
|
||||
->export($daysago);
|
||||
|
||||
if (count($payments)) {
|
||||
$output = Form::open(Request::current()->uri(array('action'=>'export')));
|
||||
$output .= '<table class="box-left">';
|
||||
|
||||
$output .= View::factory('export/payment/header')
|
||||
->set('plugins',$TBRexportplugins);
|
||||
|
||||
$i = 0;
|
||||
foreach ($payments as $payment) {
|
||||
$output .= View::factory('export/payment/body')
|
||||
->set('payment',$payment)
|
||||
->set('i',$i++%2);
|
||||
}
|
||||
|
||||
$output .= '</table>';
|
||||
$output .= Form::submit('submit','export',array('class'=>'form_button'));
|
||||
$output .= Form::close();
|
||||
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/list.css',
|
||||
));
|
||||
$p = ORM::factory('payment');
|
||||
|
||||
if ($p->find_all()->count()) {
|
||||
Block::add(array(
|
||||
'title'=>_('Payments to Export'),
|
||||
'body'=>$output,
|
||||
'body'=>Table::display(
|
||||
$p->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID'),
|
||||
'date_payment'=>array('label'=>'Date'),
|
||||
'checkout->display("name")'=>array('label'=>'Method'),
|
||||
'account->accnum()'=>array('label'=>'Acc Num'),
|
||||
'account->name()'=>array('label'=>'Account'),
|
||||
'total_amt'=>array('label'=>'Total','class'=>'right'),
|
||||
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
|
||||
'invoicelist()'=>array('label'=>'Invoices'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'affiliate/export/export',
|
||||
'hidden'=>array(
|
||||
Form::hidden('plugin','quicken'),
|
||||
),
|
||||
'button'=>array(
|
||||
Form::submit('submit',_('Export'),array('class'=>'form_button')),
|
||||
),
|
||||
)),
|
||||
));
|
||||
|
||||
# Nothing to export
|
||||
|
@@ -12,16 +12,16 @@
|
||||
*/
|
||||
class Export_Quicken extends Export {
|
||||
public function export() {
|
||||
if (! empty($_POST['payment_id']) AND count($_POST['payment_id'])) {
|
||||
if (! empty($_POST['id']) AND count($_POST['id'])) {
|
||||
$qo = new Quicken;
|
||||
|
||||
foreach ($_POST['payment_id'] as $pid) {
|
||||
$mpo = ORM::factory('payment',$pid);
|
||||
foreach ($_POST['id'] as $pid) {
|
||||
$po = ORM::factory('payment',$pid);
|
||||
|
||||
if ($mpo->loaded()) {
|
||||
if ($po->loaded()) {
|
||||
$invoice_ids = array();
|
||||
|
||||
foreach ($mpo->payment_item->find_all() as $pio) {
|
||||
foreach ($po->payment_item->find_all() as $pio) {
|
||||
// If our invoice ID is not blank, then the payment was applied to an invoice
|
||||
if ($pio->invoice->id) {
|
||||
// Record our invoice IDs for the summary
|
||||
@@ -34,23 +34,23 @@ class Export_Quicken extends Export {
|
||||
$qio->CLEAR = 'N';
|
||||
$qio->TOPRINT = 'N';
|
||||
$qio->PAID = 'N';
|
||||
$qio->ADDR1 = $mpo->account->address1;
|
||||
$qio->ADDR2 = $mpo->account->address2;
|
||||
$qio->ADDR3 = sprintf('%s, %s %s',$mpo->account->city,$mpo->account->state,$mpo->account->zip);
|
||||
$qio->ADDR1 = $po->account->address1;
|
||||
$qio->ADDR2 = $po->account->address2;
|
||||
$qio->ADDR3 = sprintf('%s, %s %s',$po->account->city,$po->account->state,$po->account->zip);
|
||||
// @todo - should be configurable
|
||||
$qio->TERMS = '7 Days';
|
||||
// @todo - should be configurable
|
||||
$qio->INVTITLE = 'Graytech Hosting Invoice';
|
||||
$qio->INVTITLE = Company::name().' Invoice';
|
||||
// @todo - should be configurable
|
||||
$qio->INVMEMO = 'Thank you for using Graytech Hosting';
|
||||
$qio->INVMEMO = 'Thank you for using '.Company::name();
|
||||
$qio->DOCNUM = sprintf('%06s',$pio->invoice->id);
|
||||
$qio->DUEDATE = date('m/d/Y',$pio->invoice->due_date);
|
||||
$qio->AMOUNT = sprintf('%3.2f',$pio->invoice->total_amt);
|
||||
$qio->AMOUNT = sprintf('%3.2f',$pio->invoice->total());
|
||||
|
||||
if ($mpo->account->company)
|
||||
$qio->NAME = $mpo->account->company;
|
||||
if ($po->account->company)
|
||||
$qio->NAME = $po->account->company;
|
||||
else
|
||||
$qio->NAME = sprintf('%s %s',$mpo->account->last_name,$mpo->account->first_name);
|
||||
$qio->NAME = sprintf('%s %s',$po->account->last_name,$po->account->first_name);
|
||||
|
||||
// Other Quicken fields not used.
|
||||
#$qio->CLASS = '';
|
||||
@@ -70,41 +70,37 @@ class Export_Quicken extends Export {
|
||||
foreach ($pio->invoice->invoice_item->find_all() as $iio) {
|
||||
$qto = new Quicken_InvoiceItem;
|
||||
|
||||
if ($iio->date_start OR $iio->date_stop)
|
||||
$daterange = sprintf('%s-%s',date('d-m-Y',$iio->date_start),date('d-m-Y',$iio->date_stop));
|
||||
if ($iio->period())
|
||||
$daterange = $iio->period();
|
||||
|
||||
// @todo This should go.
|
||||
elseif ($iio->product_attr && preg_match('/^a/',$iio->product_attr)) {
|
||||
echo 'Uncaptured';die();
|
||||
|
||||
// @todo This should go.
|
||||
} elseif ($iio->product_attr && preg_match('/^s/',$iio->product_attr))
|
||||
$daterange = preg_replace("/\r?\n/",' ',unserialize($iio->product_attr));
|
||||
|
||||
else
|
||||
$daterange = '';
|
||||
|
||||
if (! $iio->product_id && preg_match('/^DOMAIN/',$iio->sku)) {
|
||||
$qto->ACCNT = 'Internet:Domain Name';
|
||||
|
||||
$qto->INVITEM = sprintf('Domain:%s',
|
||||
($iio->domain_tld) ? strtoupper($iio->domain_tld) : 'Unknown');
|
||||
|
||||
$qto->MEMO = sprintf('Domain: %s.%s (%s)',
|
||||
strtoupper($iio->domain_name),strtoupper($iio->domain_tld),$daterange);
|
||||
|
||||
} elseif ($iio->product_id) {
|
||||
$module = ORM::factory('module',array('name'=>'product'));
|
||||
$export = ORM::factory('export','module')
|
||||
if ($iio->product_id) {
|
||||
$mo = ORM::factory('module',array('name'=>'product'));
|
||||
$eo = ORM::factory('export')
|
||||
->where('plugin_name','=',$this->plugin)
|
||||
->and_where('module_id','=',$module->id)
|
||||
->and_where('module_id','=',$mo->id)
|
||||
->and_where('item_id','=',$iio->product_id)
|
||||
->find();
|
||||
|
||||
if ($export->loaded()) {
|
||||
$map_data = unserialize($export->map_data);
|
||||
if ($eo->loaded()) {
|
||||
$map_data = unserialize($eo->map_data);
|
||||
$qto->ACCNT = $map_data['account'];
|
||||
$qto->INVITEM = $map_data['item'];
|
||||
|
||||
} else {
|
||||
throw new Kohana_Exception('Missing product map data for :product (:id)',
|
||||
array(':product'=>$iio->product->name(),':id'=>$iio->product_id));
|
||||
|
||||
$qto->ACCNT = 'Other Income';
|
||||
$qto->INVITEM = 'Product:Unknown';
|
||||
}
|
||||
@@ -122,18 +118,19 @@ class Export_Quicken extends Export {
|
||||
$qto->CLEAR = 'N';
|
||||
$qto->QNTY = -1;
|
||||
|
||||
if ($pio->invoice->tax_amt) {
|
||||
if ($pio->invoice->tax()) {
|
||||
$qto->TAXABLE = 'Y';
|
||||
# @todo, get this from OSB
|
||||
$qto->TAXCODE = 'GST';
|
||||
$qto->TAXRATE = sprintf('%3.2f%%','0.10');
|
||||
$qto->TAXAMOUNT = sprintf('%3.2f',$iio->tax_amt*-1);
|
||||
$qto->TAXAMOUNT = sprintf('%3.2f',$iio->tax()*-1);
|
||||
} else {
|
||||
$qto->TAXAMOUNT = 0;
|
||||
}
|
||||
|
||||
$qto->PRICE = sprintf('%3.2f',$iio->total_amt-$iio->tax_amt);
|
||||
$qto->AMOUNT = sprintf('%3.2f',($iio->total_amt-$iio->tax_amt)*-1);
|
||||
// @todo This rounding should be a system config.
|
||||
$qto->PRICE = sprintf('%3.2f',round($iio->subtotal()-$iio->discount(),2));
|
||||
$qto->AMOUNT = sprintf('%3.2f',round($iio->subtotal()-$iio->discount(),2)*-1);
|
||||
|
||||
$qio->addInvoiceItem($qto);
|
||||
}
|
||||
@@ -143,21 +140,21 @@ class Export_Quicken extends Export {
|
||||
}
|
||||
|
||||
$qpo = new Quicken_Payment;
|
||||
$qpo->AMOUNT = sprintf('%3.2f',$mpo->total_amt);
|
||||
$qpo->TRNSID = sprintf('P%06s',$mpo->id);
|
||||
$qpo->DATE = date('m/d/Y',$mpo->date_payment);
|
||||
$qpo->AMOUNT = sprintf('%3.2f',$po->total_amt);
|
||||
$qpo->TRNSID = sprintf('P%06s',$po->id);
|
||||
$qpo->DATE = date('m/d/Y',$po->date_payment);
|
||||
|
||||
// @todo this should be from a function - when no invoice is paid we cant use $qio
|
||||
if ($mpo->account->company)
|
||||
$qpo->NAME = $mpo->account->company;
|
||||
if ($po->account->company)
|
||||
$qpo->NAME = $po->account->company;
|
||||
else
|
||||
$qpo->NAME = sprintf('%s %s',$mpo->account->last_name,$mpo->account->first_name);
|
||||
$qpo->NAME = sprintf('%s %s',$po->account->last_name,$po->account->first_name);
|
||||
|
||||
$qpo->CLEAR = 'N';
|
||||
$qpo->MEMO = sprintf('Payment for invoice(s) %s (%s)',implode(':',$invoice_ids),$mpo->checkout->name);
|
||||
$qpo->MEMO = sprintf('Payment for invoice(s) %s (%s)',implode(':',$invoice_ids),$po->checkout->name);
|
||||
|
||||
// @todo Accounts/Payment should be configurable
|
||||
switch ($mpo->checkout->checkout_plugin) {
|
||||
switch ($po->checkout->checkout_plugin) {
|
||||
// @todo this is direct debit
|
||||
case 'MANUAL':
|
||||
$qpo->PAYMETH = 'DirectDebit';
|
||||
@@ -184,7 +181,8 @@ class Export_Quicken extends Export {
|
||||
$qpo->ACCNT = 'Undeposited Funds';
|
||||
}
|
||||
|
||||
$qio->addPayment($qpo);
|
||||
if (isset($qio))
|
||||
$qio->addPayment($qpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,5 +11,26 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Export extends ORMOSB {
|
||||
public function rules() {
|
||||
return array_merge(parent::rules(),array(
|
||||
'map_data'=>array(
|
||||
array('ORMOSB::serialize_array',array(':model',':field',':value')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function list_itemsnoexport() {
|
||||
$result = array();
|
||||
|
||||
$mo = ORM::factory('module',array('name'=>'product'));
|
||||
$p = ORM::factory('product')
|
||||
->order_by('id');
|
||||
|
||||
foreach ($p->find_all() as $po)
|
||||
if (! ORM::factory('export')->where('module_id','=',$mo->id)->where('item_id','=',$po->id)->find()->loaded())
|
||||
$result[$po->id] = $po;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
18
modules/export/views/export/admin/map/add.php
Normal file
18
modules/export/views/export/admin/map/add.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td>Product</td>
|
||||
<td><?php echo Form::select('item_id',$eo->list_itemsnoexport()); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Export</td>
|
||||
<td><?php echo Form::input('plugin_name','quicken',array('disabled'=>'disabled')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Account ID</td>
|
||||
<td><?php echo Form::input('map_data[account]','Internet:ADSL Supply'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Item ID</td>
|
||||
<td><?php echo Form::input('map_data[item]','ADSL:0256/064'); ?></td>
|
||||
</tr>
|
||||
</table>
|
@@ -1,7 +0,0 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $payment->display('date_payment'); ?></td>
|
||||
<td><?php printf('%s (%s)',$payment->checkout->name,$payment->checkout->id); ?></td>
|
||||
<td><?php echo $payment->display('total_amt'); ?></td>
|
||||
<td><?php echo $payment->account->name(); ?></td>
|
||||
<td><?php echo Form::checkbox('payment_id[]',$payment->id); ?></td>
|
||||
</tr>
|
@@ -1,12 +0,0 @@
|
||||
<tr>
|
||||
<td colspan="3"><?php echo Form::select('plugin',$plugins); ?></td>
|
||||
<td colspan="2" style="text-align: right;"><?php echo Form::submit('submit','export',array('class'=>'form_button')); ?></td>
|
||||
</tr>
|
||||
<!-- // @todo To translate -->
|
||||
<tr>
|
||||
<td class="heading">Date</td>
|
||||
<td class="heading">Method</td>
|
||||
<td class="heading">Pay/Amount</td>
|
||||
<td class="heading">Customer</td>
|
||||
<td class="heading">Export</td>
|
||||
</tr>
|
Reference in New Issue
Block a user