OSB enhancements to date
This commit is contained in:
@@ -122,6 +122,12 @@ that will be used to process all recurring charges... this should be a gateway
|
||||
'desc' => '<b>Step 10:</b> Import the Invoices Items',
|
||||
'depn' => array('invoices')
|
||||
));
|
||||
|
||||
array_push($this->actions,array(
|
||||
'name' => 'payments',
|
||||
'desc' => '<b>Step 11:</b> Import the Payments',
|
||||
'depn' => array('invoices')
|
||||
));
|
||||
}
|
||||
|
||||
protected function pre_services() {
|
||||
@@ -443,6 +449,7 @@ that will be used to process all recurring charges... this should be a gateway
|
||||
foreach ($map as $a => $b)
|
||||
$update[$a] = $rs->fields[$b];
|
||||
|
||||
$update['date_orig'] = time();
|
||||
$update['date_last'] = time();
|
||||
$update['language_id'] = DEFAULT_LANGUAGE;
|
||||
# @todo Work out currency based on country address
|
||||
@@ -1099,5 +1106,124 @@ FROM tblhosting,tblproducts where tblhosting.packageid=tblproducts.id';
|
||||
printf("<script type='text/javascript' language=javascript>setTimeout('document.location=\'?_page=core:blank&offset=%s&action=%s&plugin=%s&do[]=import:do_action\'', 1200);</script>",
|
||||
$VAR['offset']+$this->select_limit,$VAR['action'],$VAR['plugin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payments
|
||||
*/
|
||||
protected function payments() {
|
||||
global $VAR,$C_debug;
|
||||
|
||||
# Connect to the remote DB
|
||||
$dbr = &NewADOConnection($this->type);
|
||||
$dbr->Connect($this->host,$this->user,$this->pass,$this->db);
|
||||
|
||||
# Determine the offset for the account
|
||||
if (empty($VAR['offset']))
|
||||
$VAR['offset'] = 0;
|
||||
|
||||
$offset = sprintf('%s,%s',$VAR['offset'],$this->select_limit);
|
||||
$remote_table = 'tblaccounts';
|
||||
$ab_table = 'payment';
|
||||
|
||||
# Select
|
||||
$sql = sprintf('SELECT * FROM %s',$remote_table);
|
||||
$rs = $dbr->SelectLimit($sql,$this->select_limit,$offset);
|
||||
|
||||
if ($rs === false) {
|
||||
$C_debug->alert(sprintf('Query to the table "%s" failed!',$remote_table));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($rs->RecordCount() == 0) {
|
||||
$C_debug->alert('No more records to process!');
|
||||
printf("<script type='text/javascript' language=javascript>setTimeout('document.location=\'?_page=import:import&plugin=%s\'',1500);</script>",$VAR['plugin']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Load Checkout Plugins
|
||||
$db = &DB();
|
||||
$imprs = $db->Execute(sqlSelect($db,'checkout','id,checkout_plugin',''));
|
||||
while (! $imprs->EOF) {
|
||||
$co[$imprs->fields['checkout_plugin']] = $imprs->fields['id'];
|
||||
$imprs->MoveNext();
|
||||
}
|
||||
|
||||
# Load Accounts Imported
|
||||
$imprs = $db->Execute(sqlSelect($db,'import','ab_id,remote_id',sprintf('plugin=::%s:: AND action=::%s:: AND remote_table=::%s::',$this->plugin,'accounts','tblclients')));
|
||||
while (! $imprs->EOF) {
|
||||
$account[$imprs->fields['remote_id']] = $imprs->fields['ab_id'];
|
||||
$imprs->MoveNext();
|
||||
}
|
||||
|
||||
$msg = sprintf('Processing %s Records...<br/>',$rs->RecordCount());
|
||||
|
||||
# If there is a map file, open it
|
||||
$pmap = $this->read_map();
|
||||
|
||||
# Table mapping
|
||||
$map = array();
|
||||
$map['notes'] = 'description';
|
||||
$map['total_amt'] = 'amountin';
|
||||
$map['fees_amt'] = 'fees';
|
||||
|
||||
# Loop through each remote item
|
||||
while (! $rs->EOF) {
|
||||
$msg .= sprintf('<br/>Processing : %s...',$rs->fields['invoiceid']);
|
||||
|
||||
# Start a new transaction for the insert:
|
||||
$db = &DB();
|
||||
$db->StartTrans();
|
||||
|
||||
$update = array();
|
||||
foreach ($map as $a => $b)
|
||||
$update[$a] = $rs->fields[$b];
|
||||
|
||||
$update['account_id'] = $account[$rs->fields['userid']*1];
|
||||
$update['checkout_plugin_id'] = $account[$rs->fields['userid']*1];
|
||||
$update['date_payment'] = strtotime($rs->fields['date']);
|
||||
$update['date_orig'] = strtotime($rs->fields['date']);
|
||||
if ($rs->fields['transid'])
|
||||
$update['checkout_plugin_data'] = serialize(array('transid'=>$rs->fields['transid']));
|
||||
# Get the fixed items in the map table.
|
||||
if (isset($pmap[$ab_table][$rs->fields['gateway']])) {
|
||||
foreach ($pmap[$ab_table][$rs->fields['gateway']] as $field => $value) {
|
||||
if (isset($co[$value]))
|
||||
$update[$field] = $co[$value];
|
||||
else {
|
||||
$update[$field] = sprintf('NOMAP-%s',$rs->fields['gateway']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Import the item
|
||||
$db->Execute($r=sqlInsert($db,$ab_table,$update));
|
||||
$id = $db->Execute($q=sqlSelect($db,$ab_table,'id',$update,'','0,1'));
|
||||
|
||||
# Insert the import record
|
||||
$this->import_transaction($this->plugin,$VAR['action'],$ab_table,$id->fields['id'],$remote_table,$rs->fields['id'],$db);
|
||||
|
||||
$update = array();
|
||||
$update['date_orig'] = strtotime($rs->fields['date']);
|
||||
$update['payment_id'] = $id->fields['id'];
|
||||
$update['invoice_id'] = $rs->fields['invoiceid'];
|
||||
$update['alloc_amt'] = $rs->fields['amountin'];
|
||||
|
||||
$db->Execute($r=sqlInsert($db,'payment_item',$update));
|
||||
$pi = $db->Execute($q=sqlSelect($db,'payment_item','id',$update,'','0,1'));
|
||||
|
||||
$this->import_transaction($this->plugin,$VAR['action'],'payment_item',$pi->fields['id'],'',null,$db);
|
||||
|
||||
# Complete the transaction
|
||||
$db->CompleteTrans();
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
$C_debug->alert($msg);
|
||||
|
||||
printf("<script type='text/javascript' language=javascript>setTimeout('document.location=\'?_page=core:blank&offset=%s&action=%s&plugin=%s&do[]=import:do_action\'', 1200);</script>",
|
||||
$VAR['offset']+$this->select_limit,$VAR['action'],$VAR['plugin']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user