<?php
global $transactions_type,$bank_trans_settings;
$bank_name ="Ned Bank";
$bank_branch ="";
$bank_account ="";
$transactions =array();
$min_date=false;
$max_date=false;
$curr_code =get_company_pref('curr_default');
while ($row=fgetcsv($file)) {
    if($row[0]=='Name:' && $bank_branch ==""){
        $bank_branch =$row[1];
    }
    if($row[0]=='ACC-NO' && $bank_account ==""){
        $bank_account =$row[1];
    }
    if($bank_account !="" ){
        $current_tansaction=array();
        if($date =date_create_from_format("j-M-y",$row[0])){
           $date =date_format($date,"Y-m-d");
            if(!$min_date && !$max_date){
                $min_date=$date;
                $max_date=$date;
            }
            if($date<$min_date){
                $min_date=$date;
            }
            if($date>$max_date){
                $max_date=$date;
            }
            $current_tansaction['date']=$date;
        }else{
            $current_tansaction['date']=null;
        }
        
        if($row[2] <0){
            $current_tansaction['debitcredit']='D';
        }else{
            $current_tansaction['debitcredit']='C';
        }

        $current_tansaction['account']="";
        $current_tansaction['price']=abs(str_replace(",","",$row[2]));
        $current_tansaction['description']=$row[1];  
        $current_tansaction['accountName']="";
        if($current_tansaction['date'] && $current_tansaction['price']){
            $transactions[] =$current_tansaction;
        }
    }
}
if(!empty($transactions)){
    $result =array('Bank'=>$bank_branch,'Account'=>$bank_account,'Currency'=>$curr_code,'Transactions'=>$transactions);

    //for getting bank trans settings for the corresponding bank
    $sql ="SELECT * FROM ".TB_PREF."kv_bank_trans_settings WHERE bank_name='' || bank_name='ned_bank'";
    $db_result = db_query($sql, "Could not get data from kv_bank_trans_settings");
    $bank_trans_settings =array();
    while($row = db_fetch_assoc($db_result)) {
        $bank_trans_settings[] = $row;
    }
    
    $bank_id =Import_Bank_Statement($result);
   meta_forward($path_to_root.'/modules/Kvcodes_importexport/inquiry/imported_bank_inquiry.php', 'b_id='.$bank_id.'&f_date='.$min_date.'&t_date='.$max_date);
    
}else{
    display_error("Unsupported bank statement !");
}





?>