Topic: Importing journal entries from remote table
Please help, have studied the module for importing journal entries from CSV, but I want to do the same but get them from a remote table, been trying but don't seem to get it right, here is my code
include_once($path_to_root . "/includes/ui/items_cart.inc");
function get_dimension_id_from_reference($ref)
{
if ($ref == null || $ref == '')
return 0;
$sql = "SELECT id FROM ".TB_PREF."dimensions WHERE reference LIKE '$ref'";
$result = db_query($sql, null);
$row = db_fetch_row($result);
return $row[0];
}
add_access_extensions();
global $Refs;
$cart = new items_cart(0);
$cart->order_id = 0;
$cart->reference = $Refs->get_next(0);
$cart->tran_date = new_doc_date();
if (!is_date_in_fiscalyear($cart->tran_date))
$cart->tran_date = end_fiscalyear();
$_POST['memo_'] = $cart->memo_;
$_POST['ref'] = $cart->reference;
$_POST['date_'] = $cart->tran_date;
$_SESSION['journal_items'] = &$cart;
//print_r($_SESSION['journal_items']);
$dim1 = get_dimension_id_from_reference('1');
$dim2 = get_dimension_id_from_reference('2');
$data = array(0=>array(0 => '1060',1=>$dim1,2=>'90000',3=>"Savings Account"),
1=>array(0 => '204',1=>$dim1,2=>'-90000',3=>"Construction Donations")
);
foreach($data as $r){
// Check that the account code exists
if (get_gl_account($r[0]) == null) die("Error: Could not find account code $r[0]");
//$test .= $r[0]." ".$r[1]." ".$r[2]." ".$r[3]."</br>";
$_SESSION['journal_items']->add_gl_item($r[0], $r[1], '', $r[2], $r[3]);
}