function parseXmlAndUpdateDB($xmlData, $user_id, $score_id)
{
    $clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $xmlData);
    $xml = simplexml_load_string($clean_xml);
    //print_r($xml);
    $created_date = date('Y-m-d H:i:s');
    //echo "<h1>Score Related  Details</h1>";
    $CreditProfileHeader = $xml->CreditProfileHeader;
    // Fetch Main Object from XML
    $Enquiry_Username = $CreditProfileHeader->Enquiry_Username;
    $enq_username = $Enquiry_Username['0'];
    $ReportDate = $CreditProfileHeader->ReportDate;
    $report_date = $ReportDate['0'];
    $ReportNumber = $CreditProfileHeader->ReportNumber;
    $report_number = $ReportNumber['0'];
    $Subscriber = $CreditProfileHeader->Subscriber;
    $subscriber = $Subscriber['0'];
    $Subscriber_Name = $CreditProfileHeader->Subscriber_Name;
    $subscriber_name = $Subscriber_Name['0'];
    $Current_Application_Details = $xml->Current_Application->Current_Application_Details;
    // Fetch Main Object from XML
    $Enquiry_Reason = $Current_Application_Details->Enquiry_Reason;
    $enquiry_reason = $Enquiry_Reason['0'];
    $Finance_Purpose = $Current_Application_Details->Finance_Purpose;
    $finance_purpose = $Finance_Purpose['0'];
    $Amount_Financed = $Current_Application_Details->Amount_Financed;
    $amount_financed = $Amount_Financed['0'];
    $Duration_Of_Agreement = $Current_Application_Details->Duration_Of_Agreement;
    $duration_agreement = $Duration_Of_Agreement['0'];
    //echo "<h1>SCORE</h1>";
    $SCORE = $xml->SCORE;
    // Fetch Main Object from XML
    $score = $SCORE->BureauScore;
    $score_level = $SCORE->BureauScoreConfidLevel;
    //echo "<h1>Current Applicant Details</h1>";
    //$Applicant_Details = $xml->Current_Application->Current_Application_Details->Current_Applicant_Details;		 // Fetch Main Object from XML
    //echo "<h1>Account Details</h1>";
    $Credit_Account = $xml->CAIS_Account->CAIS_Summary->Credit_Account;
    // Fetch Main Object from XML
    $CreditAccountTotal = $Credit_Account->CreditAccountTotal;
    $accounts_total = $CreditAccountTotal['0'];
    $CreditAccountActive = $Credit_Account->CreditAccountActive;
    $accounts_active = $CreditAccountActive['0'];
    $CreditAccountClosed = $Credit_Account->CreditAccountClosed;
    $accounts_closed = $CreditAccountClosed['0'];
    $CreditAccountDefault = $Credit_Account->CreditAccountDefault;
    $accounts_default = $CreditAccountDefault['0'];
    $Total_Outstanding_Balance = $xml->CAIS_Account->CAIS_Summary->Total_Outstanding_Balance;
    // Fetch Main Object from XML
    $Outstanding_Balance_Secured = $Total_Outstanding_Balance->Outstanding_Balance_Secured;
    $os_balance_secured = $Outstanding_Balance_Secured['0'];
    $Outstanding_Balance_UnSecured = $Total_Outstanding_Balance->Outstanding_Balance_UnSecured;
    $os_balance_unsecured = $Outstanding_Balance_UnSecured['0'];
    // Insert all data  into table tbl_getscore_details
    $sql_score_details = "INSERT INTO  `tbl_getscore_details` (  `user_id` ,  `score_id` ,  `score` ,\n`score_level` ,  `enq_username` ,  `report_date` ,  `report_number` , `subscriber` ,\n`subscriber_name` ,  `enquiry_reason` ,  `finance_purpose` ,  `amount_financed` ,  `duration_agreement` ,\n`accounts_total` , `accounts_active` ,  `accounts_closed` ,  `accounts_default` ,  `os_balance_secured` ,\n`os_balance_unsecured` ,  `created` )\nVALUES ('{$user_id}', '{$score_id}', '{$score}', '{$score_level}', '{$enq_username}', '{$report_date}',\n'{$report_number}', '{$subscriber}', '{$subscriber_name}', '{$enquiry_reason}', '{$finance_purpose}',\n'{$amount_financed}', '{$duration_agreement}', '{$accounts_total}', '{$accounts_active}',\n'{$accounts_closed}', '{$accounts_default}', '{$os_balance_secured}', '{$os_balance_unsecured}', '{$created_date}');";
    $exe = mysql_query_with_throw($sql_score_details);
    //echo "<h1>List  Of Account</h1>";
    $CAIS_Account = $xml->CAIS_Account;
    // Fetch Main Object from XML
    foreach ($CAIS_Account->CAIS_Account_DETAILS as $Account_Details) {
        $Identification_Number = $Account_Details->Identification_Number;
        $identification_number = $Identification_Number['0'];
        $Subscriber_Name = $Account_Details->Subscriber_Name;
        $subscriber_name = $Subscriber_Name['0'];
        $Account_Number = $Account_Details->Account_Number;
        $account_number = $Account_Number['0'];
        $Portfolio_Type = $Account_Details->Portfolio_Type;
        $portfolio_type = $Portfolio_Type['0'];
        $Account_Type = $Account_Details->Account_Type;
        $account_type = $Account_Type['0'];
        $Open_Date = $Account_Details->Open_Date;
        $date_open = $Open_Date['0'];
        $Highest_Credit_Loan_Amount = $Account_Details->Highest_Credit_or_Original_Loan_Amount;
        $highcredit_loanamount = $Highest_Credit_Loan_Amount = $Highest_Credit_Loan_Amount['0'];
        $Terms_Duration = $Account_Details->Terms_Duration;
        $terms_duration = $Terms_Duration['0'];
        $Account_Status = $Account_Details->Account_Status;
        $account_status = $Account_Status['0'];
        $Date_Closed = $Account_Details->Date_Closed;
        $date_closed = $Date_Closed['0'];
        // add additional details
        $Value_of_Collateral = $Account_Details->Value_of_Collateral;
        $value_of_collateral = $Value_of_Collateral['0'];
        $Type_of_Collateral = $Account_Details->Type_of_Collateral;
        $type_of_collateral = $Type_of_Collateral['0'];
        $Date_Reported = $Account_Details->Date_Reported;
        $date_reported = $Date_Reported['0'];
        $Current_Balance = $Account_Details->Current_Balance;
        $current_balance = $Current_Balance['0'];
        $Amount_Past_Due = $Account_Details->Amount_Past_Due;
        $amount_past_due = $Amount_Past_Due['0'];
        // end additionals details
        $Date_of_Last_Payment = $Account_Details->Date_of_Last_Payment;
        $date_last_payment = $Date_of_Last_Payment['0'];
        $AccountHoldertypeCode = $Account_Details->AccountHoldertypeCode;
        $acc_holder_type = $AccountHoldertypeCode['0'];
        $CurrencyCode = $Account_Details->CurrencyCode;
        $currency = $CurrencyCode['0'];
        $CAIS_Account_History_Due_date = $Account_Details->CAIS_Account_History->Days_Past_Due;
        $last_history_duedays = $CAIS_Account_History_Due_date['0'];
        $account_status1 = account_status_good_bad("{$account_status}", "{$last_history_duedays}");
        // Categorize account as Good/Bad or Closed
        $CAIS_Account_History_Year = $Account_Details->CAIS_Account_History->Year;
        $last_history_year = $CAIS_Account_History_Year['0'];
        $CAIS_Account_History_Month = $Account_Details->CAIS_Account_History->Month;
        $last_history_month = $CAIS_Account_History_Month['0'];
        $account_holder_lname = $Account_Details->CAIS_Holder_Details->Surname_Non_Normalized;
        $account_holder_fname = $Account_Details->CAIS_Holder_Details->First_Name_Non_Normalized;
        $full_name = $account_holder_fname['0'] . ' ' . $account_holder_lname['0'];
        $Gender_Code = $Account_Details->CAIS_Holder_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $Income_TAX_PAN = $Account_Details->CAIS_Holder_Details->Income_TAX_PAN;
        $pan = @$Income_TAX_PAN['0'];
        $Passport_Number = $Account_Details->CAIS_Holder_Details->Passport_Number;
        $passport = @$Passport_Number['0'];
        $Date_of_birth = $Account_Details->CAIS_Holder_Details->Date_of_birth;
        $dob = $Date_of_birth['0'];
        $First_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->First_Line_Of_Address_non_normalized;
        $Second_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->Second_Line_Of_Address_non_normalized;
        $Third_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->Third_Line_Of_Address_non_normalized;
        $address = $First_Line_Of_Address_non_normalized['0'] . ' ' . $Second_Line_Of_Address_non_normalized['0'] . ' ' . $Third_Line_Of_Address_non_normalized['0'];
        $City_non_normalized = $Account_Details->CAIS_Holder_Address_Details->City_non_normalized;
        $city = $City_non_normalized['0'];
        $State_non_normalized = $Account_Details->CAIS_Holder_Address_Details->State_non_normalized;
        $state = $State_non_normalized['0'];
        $ZIP_Postal_Code_non_normalized = $Account_Details->CAIS_Holder_Address_Details->ZIP_Postal_Code_non_normalized;
        $zipcode = $ZIP_Postal_Code_non_normalized['0'];
        $Telephone_Number = $Account_Details->CAIS_Holder_Phone_Details->Telephone_Number;
        $telephone = $Telephone_Number['0'];
        $EMailId = $Account_Details->CAIS_Holder_Phone_Details->EMailId;
        $email_id = $EMailId['0'];
        $account_id = 0;
        if ($account_status1 == "Bad") {
            $query = "SELECT * FROM `tbl_banks` WHERE `bank` = '{$subscriber_name}' order by id DESC limit 1";
            $exe = mysql_query_with_throw($query);
            if (mysql_num_rows($exe) == 0) {
                $select_bank = mysql_query_with_throw("INSERT INTO `tbl_banks` ( `bank` , `logo` , `status` ,\n`add_date`) VALUES ('{$subscriber_name}', '', '0', NOW())");
                $bankidn = mysql_insert_id();
            } else {
                $user_code = mysql_fetch_assoc($exe);
                $bankidn = $user_code['id'];
            }
            $year = date("y");
            $month = date("m");
            $date = date("d");
            $rand2 = mt_rand(1000000, 9999999);
            $unikdueid = "DI-" . $date . $month . $year . '-' . $rand2;
            $product_type = get_account_type($account_type);
            // $dateofbirth = $_SESSION['myForm']['dob_yy'].'-'.$_SESSION['myForm']['dob_mm'].'-'.$_SESSION['myForm']['dob_dd'];
            $query = "INSERT INTO `tbl_accounts` ( `id` , `account` , `balance`, `bank` ,\n`product_type` , `account_no` , `date_opened` , `date_closed` , `dateofbirth` ,\n`pancard` , `otherbank` , `unikdueid` , `caption` , `notes` , `alert`, `status` ,\n`userid` , `payin` ,  `add_date`) VALUES (0, '{$full_name}', '{$balance}', '{$bankidn}',\n'{$product_type}', '{$account_number}', '{$date_opened}', '{$date_closed}', '{$dob}', '{$pan}',\n'{$otherbank}', '{$unikdueid}', '{$caption}', '{$notes}', '0', '', '" . $_SESSION['GTUserID'] . "',\n'{$rwspayfull}', NOW());";
            $result = mysql_query_with_throw($query);
            $account_id = mysql_insert_id();
        }
        $sql_accounts = "INSERT INTO `tbl_getaccounts` (`user_id`, `score_id`, `identification_number`,\n`subscriber_name`, `account_number`, `portfolio_type`, `account_type`, `account_status`,\n`account_status1`, `highcredit_loanamount`, `terms_duration`, `date_open`, `date_closed`,\n`date_last_payment`, `acc_holder_type`, `currency`, `last_history_year`, `last_history_month`,\n`last_history_duedays`, `full_name`, `gender`, `pan`, `passport`, `dob`, `address`, `city`, `state`,\n`zipcode`, `telephone`, `email_id`, `created`, `account_id`, `bank`, `date_reported`, `current_balance`, \n`amount_due`, `value_collateral`, `type_collateral` )\nVALUES ('{$user_id}', '{$score_id}', '{$identification_number}', '{$subscriber_name}',\n'{$account_number}', '{$portfolio_type}', '{$account_type}', '{$account_status}', '{$account_status1}',\n'{$highcredit_loanamount}', '{$terms_duration}', '{$date_open}', '{$date_closed}', '{$date_last_payment}',\n'{$acc_holder_type}', '{$currency}', '{$last_history_year}', '{$last_history_month}', '{$last_history_duedays}',\n'{$full_name}', '{$gender}', '{$pan}', '{$passport}', '{$dob}', '{$address}', '{$city}', '{$state}', '{$zipcode}', '{$telephone}',\n'{$email_id}', '{$created_date}', '{$account_id}', '{$bankidn}', '{$date_reported}', '{$current_balance}', '{$amount_past_due}',\n'{$value_of_collateral}', '{$type_of_collateral}' );";
        $exe = mysql_query_with_throw($sql_accounts);
    }
    //echo "<h1>List  Of Applications( CAPS)</h1>";
    $CAPS = $xml->CAPS;
    // Fetch Main Object from XML
    foreach ($CAPS->CAPS_Application_Details as $Apps_Details) {
        $Subscriber_code = $Apps_Details->Subscriber_code;
        $subscriber_code = $Subscriber_code['0'];
        $Subscriber_Name = $Apps_Details->Subscriber_Name;
        $subscriber = $Subscriber_Name['0'];
        $Date_of_Request = $Apps_Details->Date_of_Request;
        $request_date = $Date_of_Request['0'];
        $Product = $Apps_Details->Product;
        $product = $Product['0'];
        $ReportNumber = $Apps_Details->ReportNumber;
        $report_number = $ReportNumber['0'];
        $Enquiry_Reason = $Apps_Details->Enquiry_Reason;
        $enquiry_reason = $Enquiry_Reason['0'];
        $Finance_Purpose = $Apps_Details->Finance_Purpose;
        $finance_purpose = $Finance_Purpose['0'];
        $Amount_Financed = $Apps_Details->Amount_Financed;
        $amount_financed = $Amount_Financed['0'];
        $Duration_Of_Agreement = $Apps_Details->Duration_Of_Agreement;
        $duration_agreement = $Duration_Of_Agreement['0'];
        $First_Name = $Apps_Details->CAPS_Applicant_Details->First_Name;
        $Last_Name = $Apps_Details->CAPS_Applicant_Details->Last_Name;
        $full_name = $First_Name['0'] . ' ' . $Last_Name['0'];
        $Gender_Code = $Apps_Details->CAPS_Applicant_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $IncomeTaxPan = $Apps_Details->CAPS_Applicant_Details->IncomeTaxPan;
        $pan = $IncomeTaxPan['0'];
        $Date_Of_Birth_Applicant = $Apps_Details->CAPS_Applicant_Details->Date_Of_Birth_Applicant;
        $dob = $Date_Of_Birth_Applicant['0'];
        $Telephone_Number_Applicant_1st = $Apps_Details->CAPS_Applicant_Details->Telephone_Number_Applicant_1st;
        $telephone = $Telephone_Number_Applicant_1st['0'];
        $MobilePhoneNumber = $Apps_Details->CAPS_Applicant_Details->MobilePhoneNumber;
        $mobile = $MobilePhoneNumber['0'];
        $FlatNoPlotNoHouseNo = $Apps_Details->CAPS_Applicant_Address_Details->FlatNoPlotNoHouseNo;
        $BldgNoSocietyName = $Apps_Details->CAPS_Applicant_Address_Details->BldgNoSocietyName;
        $RoadNoNameAreaLocality = $Apps_Details->CAPS_Applicant_Address_Details->RoadNoNameAreaLocality;
        $address = $FlatNoPlotNoHouseNo['0'] . ' ' . $BldgNoSocietyName['0'] . ' ' . $RoadNoNameAreaLocality['0'];
        $City = $Apps_Details->CAPS_Applicant_Address_Details->City;
        $city = $City['0'];
        $State = $Apps_Details->CAPS_Applicant_Address_Details->State;
        $state = $State['0'];
        $PINCode = $Apps_Details->CAPS_Applicant_Address_Details->PINCode;
        $zipcode = $PINCode['0'];
        $non_credit_caps = '';
        $sql_applications = "INSERT INTO `tbl_getapplications` (`user_id`, `score_id`,\n`subscriber_code`, `subscriber`, `request_date`, `product`, `report_number`, `enquiry_reason`,\n`finance_purpose`, `amount_financed`, `duration_agreement`, `full_name`, `gender`, `pan`,\n`dob`, `telephone`, `mobile`, `address`, `city`, `state`, `zipcode`, `non_credit_caps`, `created`)\nVALUES ('{$user_id}', '{$score_id}', '{$subscriber_code}',\n'{$subscriber}', '{$request_date}', '{$product}', '{$report_number}',\n'{$enquiry_reason}', '{$finance_purpose}', '{$amount_financed}', '{$duration_agreement}',\n'{$full_name}', '{$gender}', '{$pan}', '{$dob}', '{$telephone}', '{$mobile}', '{$address}', '{$city}',\n'{$state}', '{$zipcode}', '{$non_credit_caps}', '{$created_date}') ;";
        $exe = mysql_query_with_throw($sql_applications);
    }
    //echo "<h1>List  Of Applications(Non Credit (NC) CAPS)</h1>";
    $NonCreditCAPS = $xml->NonCreditCAPS;
    // Fetch Main Object from XML
    foreach ($NonCreditCAPS->CAPS_Application_Details as $NC_Apps_Details) {
        $Subscriber_code = $Apps_Details->Subscriber_code;
        $subscriber_code = $Subscriber_code['0'];
        $Subscriber_Name = $Apps_Details->Subscriber_Name;
        $subscriber = $Subscriber_Name['0'];
        $Date_of_Request = $Apps_Details->Date_of_Request;
        $request_date = $Date_of_Request['0'];
        $Product = $Apps_Details->Product;
        $product = $Product['0'];
        $ReportNumber = $Apps_Details->ReportNumber;
        $report_number = $ReportNumber['0'];
        $Enquiry_Reason = $Apps_Details->Enquiry_Reason;
        $enquiry_reason = $Enquiry_Reason['0'];
        $Finance_Purpose = $Apps_Details->Finance_Purpose;
        $finance_purpose = $Finance_Purpose['0'];
        $Amount_Financed = $Apps_Details->Amount_Financed;
        $amount_financed = $Amount_Financed['0'];
        $Duration_Of_Agreement = $Apps_Details->Duration_Of_Agreement;
        $duration_agreement = $Duration_Of_Agreement['0'];
        $First_Name = $Apps_Details->CAPS_Applicant_Details->First_Name;
        $Last_Name = $Apps_Details->CAPS_Applicant_Details->Last_Name;
        $full_name = $First_Name['0'] . ' ' . $Last_Name['0'];
        $Gender_Code = $Apps_Details->CAPS_Applicant_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $IncomeTaxPan = $Apps_Details->CAPS_Applicant_Details->IncomeTaxPan;
        $pan = $IncomeTaxPan['0'];
        $Date_Of_Birth_Applicant = $Apps_Details->CAPS_Applicant_Details->Date_Of_Birth_Applicant;
        $dob = $Date_Of_Birth_Applicant['0'];
        $Telephone_Number_Applicant_1st = $Apps_Details->CAPS_Applicant_Details->Telephone_Number_Applicant_1st;
        $telephone = $Telephone_Number_Applicant_1st['0'];
        $MobilePhoneNumber = $Apps_Details->CAPS_Applicant_Details->MobilePhoneNumber;
        $mobile = $MobilePhoneNumber['0'];
        $FlatNoPlotNoHouseNo = $Apps_Details->CAPS_Applicant_Address_Details->FlatNoPlotNoHouseNo;
        $BldgNoSocietyName = $Apps_Details->CAPS_Applicant_Address_Details->BldgNoSocietyName;
        $RoadNoNameAreaLocality = $Apps_Details->CAPS_Applicant_Address_Details->RoadNoNameAreaLocality;
        $address = $FlatNoPlotNoHouseNo['0'] . ' ' . $BldgNoSocietyName['0'] . ' ' . $RoadNoNameAreaLocality['0'];
        $City = $Apps_Details->CAPS_Applicant_Address_Details->City;
        $city = $City['0'];
        $State = $Apps_Details->CAPS_Applicant_Address_Details->State;
        $state = $State['0'];
        $PINCode = $Apps_Details->CAPS_Applicant_Address_Details->PINCode;
        $zipcode = $PINCode['0'];
        $non_credit_caps = 'yes';
        $sql_applications_non_credit = "INSERT INTO `tbl_getapplications` (`user_id`, `score_id`, `subscriber_code`, `subscriber`, `request_date`, `product`, `report_number`, `enquiry_reason`, `finance_purpose`, `amount_financed`, `duration_agreement`, `full_name`, `gender`, `pan`, `dob`, `telephone`, `mobile`, `address`, `city`, `state`, `zipcode`, `non_credit_caps`, `created`)\nVALUES ('{$user_id}', '{$score_id}', '{$subscriber_code}', '{$subscriber}', '{$request_date}', '{$product}', '{$report_number}', '{$enquiry_reason}', '{$finance_purpose}', '{$amount_financed}', '{$duration_agreement}', '{$full_name}', '{$gender}', '{$pan}', '{$dob}', '{$telephone}', '{$mobile}', '{$address}', '{$city}', '{$state}', '{$zipcode}', '{$non_credit_caps}', '{$created_date}') ;";
        $exe = mysql_query_with_throw($sql_applications_non_credit);
    }
}
function parseXmlAndUpdateDB($xmlData, $user_id)
{
    $clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $xmlData);
    $xml = simplexml_load_string($clean_xml);
    //print_r($xml);
    $created_date = date('Y-m-d H:i:s');
    //echo "<h1>Score Related  Details</h1>";
    $CreditProfileHeader = $xml->CreditProfileHeader;
    // Fetch Main Object from XML
    $Enquiry_Username = $CreditProfileHeader->Enquiry_Username;
    $enq_username = $Enquiry_Username['0'];
    $ReportDate = $CreditProfileHeader->ReportDate;
    $report_date = $ReportDate['0'];
    $ReportNumber = $CreditProfileHeader->ReportNumber;
    $report_number = $ReportNumber['0'];
    $Subscriber = $CreditProfileHeader->Subscriber;
    $subscriber = $Subscriber['0'];
    $Subscriber_Name = $CreditProfileHeader->Subscriber_Name;
    $subscriber_name = $Subscriber_Name['0'];
    $Current_Application_Details = $xml->Current_Application->Current_Application_Details;
    // Fetch Main Object from XML
    $Enquiry_Reason = $Current_Application_Details->Enquiry_Reason;
    $enquiry_reason = $Enquiry_Reason['0'];
    $Finance_Purpose = $Current_Application_Details->Finance_Purpose;
    $finance_purpose = $Finance_Purpose['0'];
    $Amount_Financed = $Current_Application_Details->Amount_Financed;
    $amount_financed = $Amount_Financed['0'];
    $Duration_Of_Agreement = $Current_Application_Details->Duration_Of_Agreement;
    $duration_agreement = $Duration_Of_Agreement['0'];
    //echo "<h1>SCORE</h1>";
    $SCORE = $xml->SCORE;
    // Fetch Main Object from XML
    $score = $SCORE->BureauScore;
    $score_level = $SCORE->BureauScoreConfidLevel;
    //echo "<h1>Current Applicant Details</h1>";
    //$Applicant_Details = $xml->Current_Application->Current_Application_Details->Current_Applicant_Details;		 // Fetch Main Object from XML
    //echo "<h1>Account Details</h1>";
    $Credit_Account = $xml->CAIS_Account->CAIS_Summary->Credit_Account;
    // Fetch Main Object from XML
    $CreditAccountTotal = $Credit_Account->CreditAccountTotal;
    $accounts_total = $CreditAccountTotal['0'];
    $CreditAccountActive = $Credit_Account->CreditAccountActive;
    $accounts_active = $CreditAccountActive['0'];
    $CreditAccountClosed = $Credit_Account->CreditAccountClosed;
    $accounts_closed = $CreditAccountClosed['0'];
    $CreditAccountDefault = $Credit_Account->CreditAccountDefault;
    $accounts_default = $CreditAccountDefault['0'];
    $Total_Outstanding_Balance = $xml->CAIS_Account->CAIS_Summary->Total_Outstanding_Balance;
    // Fetch Main Object from XML
    $Outstanding_Balance_Secured = $Total_Outstanding_Balance->Outstanding_Balance_Secured;
    $os_balance_secured = $Outstanding_Balance_Secured['0'];
    $Outstanding_Balance_UnSecured = $Total_Outstanding_Balance->Outstanding_Balance_UnSecured;
    $os_balance_unsecured = $Outstanding_Balance_UnSecured['0'];
    // Insert all data  into table tbl_getscore_details
    $sql_score_details = "INSERT INTO  `tbl_getscore_details` (  `user_id` ,  `score_id` ,  `score` ,  `score_level` ,  `enq_username` ,  `report_date` ,  `report_number` , `subscriber` ,  `subscriber_name` ,  `enquiry_reason` ,  `finance_purpose` ,  `amount_financed` ,  `duration_agreement` ,  `accounts_total` , `accounts_active` ,  `accounts_closed` ,  `accounts_default` ,  `os_balance_secured` ,  `os_balance_unsecured` ,  `created` ) \n\t\t\t\t\t\t\t\t\tVALUES ('{$user_id}', '9', '{$score}', '{$score_level}', '{$enq_username}', '{$report_date}', '{$report_number}', '{$subscriber}', '{$subscriber_name}', '{$enquiry_reason}', '{$finance_purpose}', '{$amount_financed}', '{$duration_agreement}', '{$accounts_total}', '{$accounts_active}', '{$accounts_closed}', '{$accounts_default}', '{$os_balance_secured}', '{$os_balance_unsecured}', '{$created_date}');";
    $exe = mysql_query_with_throw($sql_score_details);
    //echo "<h1>List  Of Account</h1>";
    $CAIS_Account = $xml->CAIS_Account;
    // Fetch Main Object from XML
    foreach ($CAIS_Account->CAIS_Account_DETAILS as $Account_Details) {
        $Identification_Number = $Account_Details->Identification_Number;
        $identification_number = $Identification_Number['0'];
        $Subscriber_Name = $Account_Details->Subscriber_Name;
        $subscriber_name = $Subscriber_Name['0'];
        $Account_Number = $Account_Details->Account_Number;
        $account_number = $Account_Number['0'];
        $Portfolio_Type = $Account_Details->Portfolio_Type;
        $portfolio_type = $Portfolio_Type['0'];
        $Account_Type = $Account_Details->Account_Type;
        $account_type = $Account_Type['0'];
        $Open_Date = $Account_Details->Open_Date;
        $date_open = $Open_Date['0'];
        $Highest_Credit_Loan_Amount = $Account_Details->Highest_Credit_or_Original_Loan_Amount;
        $highcredit_loanamount = $Highest_Credit_Loan_Amount = $Highest_Credit_Loan_Amount['0'];
        $Terms_Duration = $Account_Details->Terms_Duration;
        $terms_duration = $Terms_Duration['0'];
        $Account_Status = $Account_Details->Account_Status;
        $account_status = $Account_Status['0'];
        $Date_Closed = $Account_Details->Date_Closed;
        $date_closed = $Date_Closed['0'];
        $Date_of_Last_Payment = $Account_Details->Date_of_Last_Payment;
        $date_last_payment = $Date_of_Last_Payment['0'];
        $AccountHoldertypeCode = $Account_Details->AccountHoldertypeCode;
        $acc_holder_type = $AccountHoldertypeCode['0'];
        $CurrencyCode = $Account_Details->CurrencyCode;
        $currency = $CurrencyCode['0'];
        $CAIS_Account_History_Due_date = $Account_Details->CAIS_Account_History->Days_Past_Due;
        $last_history_duedays = $CAIS_Account_History_Due_date['0'];
        $account_status1 = account_status_good_bad("{$account_status}", "{$last_histor_duedays}");
        // Categorize account as Good/Bad or Closed
        $CAIS_Account_History_Year = $Account_Details->CAIS_Account_History->Year;
        $last_history_year = $CAIS_Account_History_Year['0'];
        $CAIS_Account_History_Month = $Account_Details->CAIS_Account_History->Month;
        $last_history_month = $CAIS_Account_History_Month['0'];
        $account_holder_lname = $Account_Details->CAIS_Holder_Details->Surname_Non_Normalized;
        $account_holder_fname = $Account_Details->CAIS_Holder_Details->First_Name_Non_Normalized;
        $full_name = $account_holder_fname['0'] . ' ' . $account_holder_lname['0'];
        $Gender_Code = $Account_Details->CAIS_Holder_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $Income_TAX_PAN = $Account_Details->CAIS_Holder_Details->Income_TAX_PAN;
        $pan = @$Income_TAX_PAN['0'];
        $Passport_Number = $Account_Details->CAIS_Holder_Details->Passport_Number;
        $passport = @$Passport_Number['0'];
        $Date_of_birth = $Account_Details->CAIS_Holder_Details->Date_of_birth;
        $dob = $Date_of_birth['0'];
        $First_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->First_Line_Of_Address_non_normalized;
        $Second_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->Second_Line_Of_Address_non_normalized;
        $Third_Line_Of_Address_non_normalized = $Account_Details->CAIS_Holder_Address_Details->Third_Line_Of_Address_non_normalized;
        $address = $First_Line_Of_Address_non_normalized['0'] . ' ' . $Second_Line_Of_Address_non_normalized['0'] . ' ' . $Third_Line_Of_Address_non_normalized['0'];
        $City_non_normalized = $Account_Details->CAIS_Holder_Address_Details->City_non_normalized;
        $city = $City_non_normalized['0'];
        $State_non_normalized = $Account_Details->CAIS_Holder_Address_Details->State_non_normalized;
        $state = $State_non_normalized['0'];
        $ZIP_Postal_Code_non_normalized = $Account_Details->CAIS_Holder_Address_Details->ZIP_Postal_Code_non_normalized;
        $zipcode = $ZIP_Postal_Code_non_normalized['0'];
        $Telephone_Number = $Account_Details->CAIS_Holder_Phone_Details->Telephone_Number;
        $telephone = $Telephone_Number['0'];
        $EMailId = $Account_Details->CAIS_Holder_Phone_Details->EMailId;
        $email_id = $EMailId['0'];
        $sql_accounts = "INSERT INTO `tbl_getaccounts` (`user_id`, `score_id`, `identification_number`, `subscriber_name`, `account_number`, `portfolio_type`, `account_type`, `account_status`, `account_status1`, `highcredit_loanamount`, `terms_duration`, `date_open`, `date_closed`, `date_last_payment`, `acc_holder_type`, `currency`, `last_history_year`, `last_history_month`, `last_history_duedays`, `full_name`, `gender`, `pan`, `passport`, `dob`, `address`, `city`, `state`, `zipcode`, `telephone`, `email_id`, `created`) \n\tVALUES ('{$user_id}', '9', '{$identification_number}', '{$subscriber_name}', '{$account_number}', '{$portfolio_type}', '{$account_type}', '{$account_status}', '{$account_status1}', '{$highcredit_loanamount}', '{$terms_duration}', '{$date_open}', '{$date_closed}', '{$date_last_payment}', '{$acc_holder_type}', '{$currency}', '{$last_history_year}', '{$last_history_month}', '{$last_history_duedays}', '{$full_name}', '{$gender}', '{$pan}', '{$passport}', '{$dob}', '{$address}', '{$city}', '{$state}', '{$zipcode}', '{$telephone}', '{$email_id}', '{$created_date}');";
        $exe = mysql_query_with_throw($sql_accounts);
    }
    //echo "<h1>List  Of Applications( CAPS)</h1>";
    $CAPS = $xml->CAPS;
    // Fetch Main Object from XML
    foreach ($CAPS->CAPS_Application_Details as $Apps_Details) {
        $Subscriber_code = $Apps_Details->Subscriber_code;
        $subscriber_code = $Subscriber_code['0'];
        $Subscriber_Name = $Apps_Details->Subscriber_Name;
        $subscriber = $Subscriber_Name['0'];
        $Date_of_Request = $Apps_Details->Date_of_Request;
        $request_date = $Date_of_Request['0'];
        $Product = $Apps_Details->Product;
        $product = $Product['0'];
        $ReportNumber = $Apps_Details->ReportNumber;
        $report_number = $ReportNumber['0'];
        $Enquiry_Reason = $Apps_Details->Enquiry_Reason;
        $enquiry_reason = $Enquiry_Reason['0'];
        $Finance_Purpose = $Apps_Details->Finance_Purpose;
        $finance_purpose = $Finance_Purpose['0'];
        $Amount_Financed = $Apps_Details->Amount_Financed;
        $amount_financed = $Amount_Financed['0'];
        $Duration_Of_Agreement = $Apps_Details->Duration_Of_Agreement;
        $duration_agreement = $Duration_Of_Agreement['0'];
        $First_Name = $Apps_Details->CAPS_Applicant_Details->First_Name;
        $Last_Name = $Apps_Details->CAPS_Applicant_Details->Last_Name;
        $full_name = $First_Name['0'] . ' ' . $Last_Name['0'];
        $Gender_Code = $Apps_Details->CAPS_Applicant_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $IncomeTaxPan = $Apps_Details->CAPS_Applicant_Details->IncomeTaxPan;
        $pan = $IncomeTaxPan['0'];
        $Date_Of_Birth_Applicant = $Apps_Details->CAPS_Applicant_Details->Date_Of_Birth_Applicant;
        $dob = $Date_Of_Birth_Applicant['0'];
        $Telephone_Number_Applicant_1st = $Apps_Details->CAPS_Applicant_Details->Telephone_Number_Applicant_1st;
        $telephone = $Telephone_Number_Applicant_1st['0'];
        $MobilePhoneNumber = $Apps_Details->CAPS_Applicant_Details->MobilePhoneNumber;
        $mobile = $MobilePhoneNumber['0'];
        $FlatNoPlotNoHouseNo = $Apps_Details->CAPS_Applicant_Address_Details->FlatNoPlotNoHouseNo;
        $BldgNoSocietyName = $Apps_Details->CAPS_Applicant_Address_Details->BldgNoSocietyName;
        $RoadNoNameAreaLocality = $Apps_Details->CAPS_Applicant_Address_Details->RoadNoNameAreaLocality;
        $address = $FlatNoPlotNoHouseNo['0'] . ' ' . $BldgNoSocietyName['0'] . ' ' . $RoadNoNameAreaLocality['0'];
        $City = $Apps_Details->CAPS_Applicant_Address_Details->City;
        $city = $City['0'];
        $State = $Apps_Details->CAPS_Applicant_Address_Details->State;
        $state = $State['0'];
        $PINCode = $Apps_Details->CAPS_Applicant_Address_Details->PINCode;
        $zipcode = $PINCode['0'];
        $non_credit_caps = '';
        $sql_applications = "INSERT INTO `tbl_getapplications` (`user_id`, `score_id`, `subscriber_code`, `subscriber`, `request_date`, `product`, `report_number`, `enquiry_reason`, `finance_purpose`, `amount_financed`, `duration_agreement`, `full_name`, `gender`, `pan`, `dob`, `telephone`, `mobile`, `address`, `city`, `state`, `zipcode`, `non_credit_caps`, `created`) \n\tVALUES ('{$user_id}', '9', '{$subscriber_code}', '{$subscriber}', '{$request_date}', '{$product}', '{$report_number}', '{$enquiry_reason}', '{$finance_purpose}', '{$amount_financed}', '{$duration_agreement}', '{$full_name}', '{$gender}', '{$pan}', '{$dob}', '{$telephone}', '{$mobile}', '{$address}', '{$city}', '{$state}', '{$zipcode}', '{$non_credit_caps}', '{$created_date}') ;";
        $exe = mysql_query_with_throw($sql_applications);
    }
    //echo "<h1>List  Of Applications(Non Credit (NC) CAPS)</h1>";
    $NonCreditCAPS = $xml->NonCreditCAPS;
    // Fetch Main Object from XML
    foreach ($NonCreditCAPS->CAPS_Application_Details as $NC_Apps_Details) {
        $Subscriber_code = $Apps_Details->Subscriber_code;
        $subscriber_code = $Subscriber_code['0'];
        $Subscriber_Name = $Apps_Details->Subscriber_Name;
        $subscriber = $Subscriber_Name['0'];
        $Date_of_Request = $Apps_Details->Date_of_Request;
        $request_date = $Date_of_Request['0'];
        $Product = $Apps_Details->Product;
        $product = $Product['0'];
        $ReportNumber = $Apps_Details->ReportNumber;
        $report_number = $ReportNumber['0'];
        $Enquiry_Reason = $Apps_Details->Enquiry_Reason;
        $enquiry_reason = $Enquiry_Reason['0'];
        $Finance_Purpose = $Apps_Details->Finance_Purpose;
        $finance_purpose = $Finance_Purpose['0'];
        $Amount_Financed = $Apps_Details->Amount_Financed;
        $amount_financed = $Amount_Financed['0'];
        $Duration_Of_Agreement = $Apps_Details->Duration_Of_Agreement;
        $duration_agreement = $Duration_Of_Agreement['0'];
        $First_Name = $Apps_Details->CAPS_Applicant_Details->First_Name;
        $Last_Name = $Apps_Details->CAPS_Applicant_Details->Last_Name;
        $full_name = $First_Name['0'] . ' ' . $Last_Name['0'];
        $Gender_Code = $Apps_Details->CAPS_Applicant_Details->Gender_Code;
        $gender = $Gender_Code['0'];
        $IncomeTaxPan = $Apps_Details->CAPS_Applicant_Details->IncomeTaxPan;
        $pan = $IncomeTaxPan['0'];
        $Date_Of_Birth_Applicant = $Apps_Details->CAPS_Applicant_Details->Date_Of_Birth_Applicant;
        $dob = $Date_Of_Birth_Applicant['0'];
        $Telephone_Number_Applicant_1st = $Apps_Details->CAPS_Applicant_Details->Telephone_Number_Applicant_1st;
        $telephone = $Telephone_Number_Applicant_1st['0'];
        $MobilePhoneNumber = $Apps_Details->CAPS_Applicant_Details->MobilePhoneNumber;
        $mobile = $MobilePhoneNumber['0'];
        $FlatNoPlotNoHouseNo = $Apps_Details->CAPS_Applicant_Address_Details->FlatNoPlotNoHouseNo;
        $BldgNoSocietyName = $Apps_Details->CAPS_Applicant_Address_Details->BldgNoSocietyName;
        $RoadNoNameAreaLocality = $Apps_Details->CAPS_Applicant_Address_Details->RoadNoNameAreaLocality;
        $address = $FlatNoPlotNoHouseNo['0'] . ' ' . $BldgNoSocietyName['0'] . ' ' . $RoadNoNameAreaLocality['0'];
        $City = $Apps_Details->CAPS_Applicant_Address_Details->City;
        $city = $City['0'];
        $State = $Apps_Details->CAPS_Applicant_Address_Details->State;
        $state = $State['0'];
        $PINCode = $Apps_Details->CAPS_Applicant_Address_Details->PINCode;
        $zipcode = $PINCode['0'];
        $non_credit_caps = 'yes';
        $sql_applications_non_credit = "INSERT INTO `tbl_getapplications` (`user_id`, `score_id`, `subscriber_code`, `subscriber`, `request_date`, `product`, `report_number`, `enquiry_reason`, `finance_purpose`, `amount_financed`, `duration_agreement`, `full_name`, `gender`, `pan`, `dob`, `telephone`, `mobile`, `address`, `city`, `state`, `zipcode`, `non_credit_caps`, `created`) \n\tVALUES ('{$user_id}', '9', '{$subscriber_code}', '{$subscriber}', '{$request_date}', '{$product}', '{$report_number}', '{$enquiry_reason}', '{$finance_purpose}', '{$amount_financed}', '{$duration_agreement}', '{$full_name}', '{$gender}', '{$pan}', '{$dob}', '{$telephone}', '{$mobile}', '{$address}', '{$city}', '{$state}', '{$zipcode}', '{$non_credit_caps}', '{$created_date}') ;";
        $exe = mysql_query_with_throw($sql_applications_non_credit);
    }
}