<?php

namespace App;

use App\Http\Controllers\ApiController;
use App\Http\Controllers\Admin\ConsumerApplicationController;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Http\Request;
use App\Scopes\MessageScope;
use App\Avanse\Services\SubService\CreateCustomer;
use App\Avanse\Services\SubService\CreateFinance;
use App\Avanse\DataModels\AvanseDisbursementInstruction;
use App\Model\Prediction;

class ConsumerApplication  extends Model
{
    use SoftDeletes;
    use Encryptable;

    const AVANSE_LENDER_ID = 3;

    private static $isAccountOpened = false;
    private static $isApplicantType = false;
    public static $isCFFoirNotInclude = false;
    public static $isSubventionInvoice = false;
    public static $isMandateManyFilter = false;
    public static $center_id = 0;
    public static $uniqueRefId = 'avanse_da';
    public static $emi_date = "";

    public static $encryptable = [
        'pan_card',
        'mobile_number',
        'aadhaar_card',
        'co_applicant_aadhaar_card',
        'co_applicant_mobile_number',
        'co_applicant_pan_card',
        'alt_contact_number',
        'company_number',
        'email',
        'co_applicant_email'


    ];

    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new MessageScope(static::$encryptable));
    }
    protected $table = 'consumer_application';
    public static $model = 'consumer_application';

    public $fillable = ['user_id', 'merchant_id', 'merchant_location_id', 'name', 'email', 'mobile_number', 'gender', 'tenure', 'purpose', 'src_merchant_name', 'src_representative_name', 'lead_src_email', 'lead_src_phone', 'long_link', 'pan_card', 'aadhaar_card', 'dob', 'marital_status', 'approved_amount', 'loan_amount',
        'current_address_line_1', 'current_address_state', 'current_address_city', 'current_address_pincode', 'current_address_landmark', 'current_address_status',
        'permanent_address_line_1', 'permanent_address_state', 'permanent_address_city', 'permanent_address_pincode', 'permanent_address_landmark', 'permanent_address_status',
        'work_address_line_1', 'work_address_state', 'work_address_city', 'work_address_pincode', 'work_address_landmark',
        'employee_status', 'monthly_income', 'company_name', 'company_number', 'experience', 'contact_address', 'alt_contact_number',
        'co_applicant_name', 'co_applicant_relationship', 'co_applicant_dob', 'co_applicant_gender', 'co_applicant_pan_card', 'co_applicant_aadhaar_card', 'co_applicant_email', 'co_applicant_mobile_number', 'co_applicant_address_line_1', 'co_applicant_address_state', 'co_applicant_address_pincode', 'co_applicant_address_city', 'co_applicant_address_landmark', 'co_applicant_address_status', 'co_applicant_required',
        'co_applicant_employee_status', 'co_applicant_monthly_income', 'co_applicant_company_name', 'co_applicant_company_number', 'co_applicant_experience',
        'state', 'completed_stage', 'credit_score', 'rejection_reason', 'assigned_to', 'misc_info', 'updated_by','created_by','lender_id','offer_id','pre_created_by', 'linked_status'];

    public static function isAccountOpened($boolean){
        static::$isAccountOpened = $boolean;
    }

    public static function isSubventionInvoice($boolean){
        static::$isSubventionInvoice = $boolean;
    }

    public static function isApplicantType($boolean){
        static::$isApplicantType = $boolean;
    }
    public static function setEmiDate($emidate){
        static::$emi_date = $emidate;
    }

    public function merchant()
    {
        return $this->hasOne('App\Merchant','id','merchant_id');
    }

    public function merchant_bank_details(){
        return $this->hasOne('App\MerchantBank','merchant_id','merchant_id');
    }

    public function category()
    {
        return $this->hasOne('App\MerchantCategory','id','purpose');
    }

    public function merchant_location()
    {
        return $this->hasOne('App\MerchantLocation','id','merchant_location_id');
    }

    public function centers()
    {
        return $this->hasMany('App\MerchantLocation','id','merchant_id');
    }

    public function mandate()
    {
        return $this->hasOne('App\Mandate','consumer_application_id','id');
    }

    public function equifax_report()
    {
        return $this->hasOne('App\EquifaxReport','_id','id')->where('id_type','application_id')->where('applicant_type',1);
    }

    public function checkmandate()
    {
        return $this->hasOne('App\Mandate','consumer_application_id','id')->whereNotNull('umrn')->where('umrn','!=','0')->orderBy('mandate_amount','desc')->where('status','active');
    }

    public function monthlymandate()
    {
        return $this->hasOne('App\Mandate','consumer_application_id','id')->whereNotNull('umrn')->where('umrn','!=','0')->where('frequency',"M");
    }

    public function fullmandate()
    {
        return $this->hasOne('App\Mandate','consumer_application_id','id')->whereNotNull('umrn')->where('umrn','!=','0')->where('frequency',"O");
    }

    public function mandateMany(){
        $mandateMany = $this->hasMany('App\Mandate','consumer_application_id','id');
        if (static::$isMandateManyFilter){
            $mandateMany->where('created_at','>=',static::$isMandateManyFilter['from_date'])->where('created_at','<=',static::$isMandateManyFilter['to_date']);
        }
        return $mandateMany;
    }

    public function bank_details()
    {
        return $this->hasOne('App\Bank','application_id','id')->where('applicant_type',1);
    }

    public function document_details(){
        return $this->hasMany('App\DocumentDetails','application_id','id');
    }

    public function bank_details_multiple()
    {
        return $this->hasMany('App\Bank','application_id','id')->orderBy('applicant_type','asc');
    }

    public function emi()
    {
        return $this->hasOne('App\ApplicationEMICalculation','application_id','id');
    }

    public function proFormaInvoice(){
        return $this->hasOne('App\ProFormaInvoice','application_id','id');
    }

    public function creditReport(){
        $creditReport = $this->hasMany('App\CreditReport','application_id','id');
        if(static::$isAccountOpened){
            $creditReport->where('applicant_type',1);
        }
        return $creditReport;
    }

    public function scopeWhere($query, $column, $value){
        return in_array($column, $this->encryptable) ? $query->where($column, wall_encrypt($value)) : $query->where($column, $value);
    }

    public function logs(){
        return $this->hasMany('App\StatusLogs','application_id','id');
    }

    public function disbursed(){
        return $this->hasOne('App\StatusLogs','application_id','id')->where('status','disbursed')->orderBy('created_at','desc');
    }

    public function cancelled(){
        return $this->hasOne('App\StatusLogs','application_id','id')->whereIn('status', ['cancelled','cancellation in-process'])->orderBy('created_at','desc');
    }

    public function closed(){
        return $this->hasOne('App\StatusLogs','application_id','id')->where('status','closed')->orderBy('created_at','desc');
    }

    public function rejected(){
        return $this->hasOne('App\StatusLogs','application_id','id')->where('status','rejected')->orderBy('created_at','desc');
    }

    public function aborted(){
        return $this->hasOne('App\StatusLogs','application_id','id')->where('status','aborted')->orderBy('created_at','desc');
    }

    public function approved(){
        return $this->hasOne('App\StatusLogs','application_id','id')->where('status','approved')->orderBy('created_at','desc');
    }

    public function verificationChecklist(){
        return $this->hasone('App\checklist','consumer_application_id','id');
    }

    public function foir(){
        $foir = $this->hasMany('App\FOIR','application_id','id');
        if(static::$isAccountOpened){
            $foir->where('isOpened',1);
        }
        if(static::$isCFFoirNotInclude){
            $foir->where('AccountType','!=','Credit Fair EMI');
        }
        $foir = $foir->select(['id','application_id','credit_id','AccountType','ApprovedAmount','Balance','InterestRate','RepaymentTenure','InstallmentAmount','cc_loan','DateOpened','applicant_type', 'isOpened', 'LastPaymentDate', 'dpd', 'DateClosed','OwnershipType','created_by','PastDueAmount','LastPayment','ReportedDate', 'is_close_date_updated','reason_info', 'created_at'])->orderBy('applicant_type','asc');
        return $foir;
    }

    public function documents(){
        return  $this->hasMany('App\ConsumerApplicationFiles','consumer_application_id','id');
    }

    public function disbursement_requests(){
        return $this->hasMany('App\DisbursementRequests', 'application_id', 'id')->where('is_disbursed', false);
    }

    public function equifax_documents(){
        return  $this->hasOne('App\ConsumerApplicationFiles','consumer_application_id','id')->where('file_type','equifax_report')->where('applicant_type', 1)->orderBy('created_at', 'DESC');
    }

    public function coapp_equifax_documents(){
        return  $this->hasOne('App\ConsumerApplicationFiles','consumer_application_id','id')->where('file_type','co_applicant_equifax_report')->where('applicant_type', 2)->orderBy('created_at', 'DESC');
    }

    public function electricity_bill(){
        return  $this->hasOne('App\ConsumerApplicationFiles','consumer_application_id','id')->where('file_type','electricity_bill')->where('applicant_type', 1)->orderBy('created_at', 'DESC');
    }

    /*public function disbursementAdvice(){
        return  $this->hasOne('App\ConsumerApplicationFiles','consumer_application_id','id')->where('file_type','pro_forma_invoice')->orderBy('created_at','desc');
    }*/

    public function company(){
        return $this->hasOne('App\Company','id','company_name');
    }

    public function co_applicant_company(){
        return $this->hasOne('App\Company','id','co_applicant_company_name');
    }

    public function application_element(){
        $application_element = $this->hasOne('App\ConsumerApplicationElement','application_id','id');
        if(static::$center_id > 0){
            $application_element = $application_element->where('center_id','=',static::$center_id);
        }
        return $application_element;
    }

    public function user(){
        return $this->hasOne('App\User','id','user_id');
    }

    public function application_additional(){
        return $this->hasOne('App\ConsumerApplicationAdditional','application_id','id');
    }

    public function latestFollowUp(){
        return $this->hasOne('App\ConsumerApplicationFollowUp','application_id','id')->latest('id');
    }

    public function followUpHistory(){
        return $this->hasMany('App\ConsumerApplicationFollowUp','application_id','id')->orderBy('id','desc');
    }

    public function advisor(){
        return $this->hasOne('App\User','id','created_by');
    }
    public function activeOffer(){
        return $this->hasOne('App\MerchantOffers','id','offer_id');
    }
    public function Checklist(){
        return $this->hasOne('App\Checklist','application_id','id');
    }
    public function lender(){
        return $this->hasOne('App\Lenders','id','lender_id');
    }
    public function digital_sign(){
        $application_element = $this->hasMany('App\DigitalSignDetails','application_id','id');
        if(static::$isApplicantType){
            $application_element = $application_element->where('type','=','consumer');
        }
        return $application_element;
    }

    public function invoice(){
        $invoice =  $this->hasOne('App\Invoices','application_id','id');
        if(static::$isSubventionInvoice){
            $invoice = $invoice->where('type', 'subvention_invoice');
        }else{
            $invoice = $invoice->where('type', 'processing_invoice');
        }
        return $invoice;
    }

    public function invoices(){
        return $this->hasMany('App\Invoices','application_id','id');
    }

    public function co_applicant_logs(){
        return $this->hasMany('App\CoApplicateValidationLog','application_id','id');
    }

    public function comments(){
        return $this->hasMany('App\Comments','application_id','id')->where('type','consumer')->orderBy('created_at','DESC');
    }

    public function merchant_comment(){
        return $this->hasOne('App\Comments','application_id','id')->where('show_merchant','=',1)->where('type','consumer')
            ->orderBy('created_at','DESC')->limit(1);
    }

    public function comment(){
        return $this->hasMany('App\Comments','application_id','id')
            ->orderBy('created_at','DESC')->limit(1);
    }

    public function application_rating(){
        return $this->hasOne('App\Rating','application_id','id');
    }

    public function hypothecation_logs(){
        return $this->hasMany('App\Hypothecation','application_id','id');
    }

    public function calls(){
        return $this->hasMany('App\CallLogs','_id','id')->where('id_type','application_id')->where(function ($query) {
            $query->whereNull('status')
                ->orWhereIn('status', ['in-progress','ringing']);
        });
    }

    public function totalCalls(){
        return $this->hasMany('App\CallLogs','_id','id')->where('id_type','application_id');
    }

    public function approval(){
        return $this->hasOne('App\Approval','application_id','id');
    }

    public function highest_dpd(){
        return $this->hasOne('App\EmiPayment','application_id','id')->where('payment_status','!=','success')->orderBy('delay_days','desc');
    }

    public function emi_payment()
    {
        $emi_payment  = $this->hasMany('App\EmiPayment','application_id','id')->orderBy('emi_date','asc');
        if(static::$emi_date){
            $emi_payment = $emi_payment->where('emi_date', static::$emi_date);
        }
        return $emi_payment;
    }

    public function payment_transaction()
    {
        $payment_transaction  = $this->hasMany('App\PaymentTransaction','application_id','id')->orderBy('payment_reconciliation_date','asc');
        return $payment_transaction;
    }

    public function foreclosed_transaction()
    {
        return $this->hasOne('App\PaymentTransaction','application_id','id')->where('payment_for', 'Foreclosure')->orderBy('payment_reconciliation_date','desc');
    }

    public function foreclosure_breakup()
    {
        return $this->hasOne('App\ForeclosureBreakup','application_id','id')->whereNull('deleted_at')->orderBy('created_at', 'desc');
    }

    public function writeoff_transaction()
    {
        return $this->hasOne('App\PaymentTransaction','application_id','id')->where('payment_for', 'Write-off')->orderBy('payment_reconciliation_date','desc');
    }

    public function settlement_payment()
    {
        return $this->hasMany('App\PaymentTransaction', 'application_id', 'id')
            ->whereIn('payment_for', [
                'settled_principal',
                'settled_interest',
                'settled_bounce',
                'settled_penal'
            ])
            ->orderBy('created_at', 'desc');
    }
    
    public function last_payment_date()
    {
        $last_payment_date  = $this->hasOne('App\PaymentTransaction','application_id','id')->where('status','success')->orderBy('created_at','desc');
        return $last_payment_date;
    }

    public function telecom_data()
    {
        return $this->hasOne('App\TelecomData','mobile_number','mobile_number')->orderBy('id');
    }
    public function offer(){
        return $this->hasOne('App\MerchantOffers','id','offer_id');
    }

    public function saveCustomer($d = array()){
        if($d){
            $this->attributes = $d;
        }
        $apiController = new ApiController();
        $customer = new \stdClass();
        $c_applicant_id = 0;
        $c_co_applicant_id = 0;
        if($applicant_id = $this->getIdFromExisting($apiController->isExistingCustomer(new Request($this->attributes)))){
            if (is_bool($applicant_id)) {
                $applicant = new Customers();
                $attributes = $this->attributes;
                $attributes['gender'] = isset($this->attributes['gender']) ? (($this->attributes['gender'] == 'FEMALE') ? 1 : 2) : null;
                $applicant->fill($attributes)->save();
            }
            $c_applicant_id = isset($applicant->id) ? $applicant->id : $applicant_id;
        }

        if(isset($this->attributes['co_applicant_name']) && !empty($this->attributes['co_applicant_name']) && $applicant_id = $this->getIdFromExisting($apiController->isExistingCustomer(new Request([
            'pan_card' => $this->attributes['co_applicant_pan_card'],
            'mobile_number' => $this->attributes['co_applicant_mobile_number'],
            'email' => $this->attributes['co_applicant_email'],
        ])))){
            if (is_bool($applicant_id)){
                $co_applicant = new Customers();
                $co_app_gender = isset($this->attributes['co_applicant_gender']) ? (($this->attributes['co_applicant_gender'] == 'FEMALE') ? 1 : 2) : null;
                $co_applicant->fill([
                    'name' => $this->attributes['co_applicant_name'],
                    'email' => $this->attributes['co_applicant_email'],
                    'mobile_number' => $this->attributes['co_applicant_mobile_number'],
                    'gender' => $co_app_gender,
                    'pan_card' => $this->attributes['co_applicant_pan_card'],
                    'aadhaar_card' => $this->attributes['co_applicant_aadhaar_card'],
                    'dob' => $this->attributes['co_applicant_dob'],
                ])->save();
            }
            $c_co_applicant_id = isset($co_applicant->id) ? $co_applicant->id : $applicant_id;
        }
        $customer->applicant_id = $c_applicant_id;
        $customer->co_applicant_id = $c_co_applicant_id;
        return $customer;
    }

    public function getIdFromExisting($existingCustomers){
        $applicant_id = true;
        $existingCustomers = $existingCustomers->getData();
        if ($existingCustomers){
            foreach ($existingCustomers->data as $existingCustomer){
                if ($existingCustomer->applicant_id && $applicant_id == true){
                    $applicant_id = $existingCustomer->applicant_id;
                    break;
                }
            }
        }
        return $applicant_id;
    }

    public function activeMerchant(){
        return $this->hasOne('App\Merchant','id','merchant_id')->where('status','active')->where('is_guest_active',1);
    }

    public function abflUTR(){
        return $this->hasMany('App\ABFLUTRUpdate','account_id','id');
    }

    public function getAgeAttribute()
    {
        return Carbon::parse($this->attributes['dob'])->age;
    }

    public function getNameSplitAttribute($type = 1, $name = '')
    {
        $custName = $type == 1 ?( $this->attributes['name'] ?? '') : ($this->attributes['co_applicant_name'] ?? '');
        $custName = empty($custName) ? $name : $custName;
        $firstName = ''; $middleName = ''; $lastName = '';
        $nameSplit = explode(' ', $custName);
        if ($nameSplit > 1){
            $firstName = $nameSplit[0];
            if (!isset($nameSplit[2]) && isset($nameSplit[1])){
                $lastName = $nameSplit[1];
            }
            if (isset($nameSplit[2])){
                $middleName = $nameSplit[1];
                unset($nameSplit[0], $nameSplit[1]);
                $lastName = implode(' ', $nameSplit);
            }
        }

        return ['firstName' => $firstName, 'middleName' => $middleName, 'lastName' => $lastName];
    }

    public function getAddressSplitAttribute($type = 1, $address = '')
    {
        $addrLine = [];
        $addressL1 = '';

        if (!empty($address)) {
            $ds = explode(' ', trim($address));
            $lineLength = 0;

            foreach ($ds as $ads) {
                if ($lineLength + strlen($ads) + 1 <= 60) {
                    $addressL1 .= $ads . ' ';
                    $lineLength += strlen($ads) + 1;
                } else {
                    $addrLine[] = trim($addressL1);
                    $addressL1 = $ads . ' ';
                    $lineLength = strlen($ads) + 1;
                }
            }

            // Add the last line
            if (!empty($addressL1)) {
                $addrLine[] = trim($addressL1);
            }

            $addrLine1 = $addrLine[0] ?? '';
            $addrLine2 = $addrLine[1] ?? '';
            $addrLine3 = ($addrLine[2] ?? '').' '.($addrLine[3] ?? '');
        }

        return ['address_1' => trim($addrLine1 ?? ''), 'address_2' => trim($addrLine2 ?? ''), 'address_3' => trim($addrLine3 ?? '')];
    }

    public function cancellation(){
        return $this->hasMany('App\CancellationDisbursement','merchant_id','merchant_id')->whereNull('adjusted_to')->select('id','application_id','merchant_id','cancellation_interest_charges','cancellation_fixed_charges','total_amount_adjusted','adjusted_by');
    }

    public function disbursement(){
        return $this->hasMany('App\Disbursement','application_id','id')->where('adjusted_amount','>', 0);
    }

    public function disbursementV1(){
        return $this->hasOne('App\Disbursement','application_id','id')->orderBy('created_at', 'desc');
    }

    public function pendingAdjustableAmount(){
        return $this->hasMany('App\PendingBalance','merchant_id','merchant_id')->where('status','pending')->where('pending','>',0)->where('adjusted_to',0);
    }

    public function userGeolocation(){
        return $this->hasOne('App\UserGeolocation','_id','id')->where('service','cpv')->whereNull('deleted_at')->where('id_type','application_id');
    }
    public function finBitData(){
        return $this->hasOne('App\FinBitData','application_id','id');
    }

    public function payoutStatus(){
        return $this->hasOne('App\PayoutStatus','application_id','id');
    }

    public function CFPayoutDirectTransfer(){
        return $this->hasOne('App\CFPayoutDirectTransfer','application_id','id')->orderBy('created_at','desc');
    }

    public function CFPayoutRequestTransferStatus(){
        return $this->hasMany('App\CFPayoutRequestTransferStatus','application_id','id')->orderBy('created_at','desc');
    }

    public function avanseUTRStatus(){
        return $this->hasOne('App\AvanseDisbursementStatus','application_id','id')->orderBy('created_at','desc');
    }

    public function avanseMandateStatus(){
        return $this->hasOne('App\AvanseMandate','application_id','id')->orderBy('created_at','desc');
    }

    public function moratorium(){
        return $this->hasOne('App\Moratorium','application_id','id')->where('status',1)->orderBy('emi_date','asc');
    }

    public function moratoriums(){
        return $this->hasMany('App\Moratorium','application_id','id')->where('status',1)->orderBy('emi_date','asc');
    }

    public function moratoriumEMIPayment(){
        return $this->hasOne('App\Moratorium','application_id','id')->where('status',1)->orderBy('emi_date','asc');
    }

    public function principal_outstanding(){
        return $this->hasOne('App\PrincipalOutstanding','application_id','id')->orderBy('date','desc');
    }

    public function ApproverData(){
        return $this->hasOne('App\ApproverData','application_id','id');
    }

    public function trade_advance(){
        return $this->hasOne('App\TradeAdvanceDisbursement','application_id','id');
    }

    public function products(){
        return $this->hasMany('App\Products','merchant_id','merchant_id')->withTrashed();
    }

    public function logger(){
        return $this->hasMany('App\ContentLogger','application_id','id')->whereNotIn('status', array('form completed', 'incomplete form', 'rejected', 'aborted', 'in-process', 'waiting for documents', 'waiting for decision', 'pre approved'));
    }

    public function all_logger(){
        return $this->hasMany('App\ContentLogger','application_id','id');
    }

    public function DisbursementOffersData(){
        return $this->hasMany('App\DisbursementOffersData','offer_id','offer_id');
    }

    public function disbursementOfferDisbursed(){
        return $this->hasMany('App\DisbursementOffers','application_id','id')->whereNull('deleted_at');
    }

    public function gst_pan_data(){
        return $this->hasOne('App\GSTPANData','application_id','id');
    }

    public function epf_uan_lookup(){
        return $this->hasOne('App\EPFUANLookup','application_id','id');
    }

    public function devices(){
        return $this->hasMany('App\Devices','user_id','user_id');
    }

    public function isAvanse() {
        return ($this->lender_id === self::AVANSE_LENDER_ID) ? true : false;
    }

    public function isLendBox() {
        return ($this->lender_id === LendBox::$lender_id) ? true : false;
    }

    public function isLendBoxLSP() {
        return ($this->lender_id === LendBoxLSP::$lender_id) ? true : false;
    }

    public function isKMGP2P() {
        return ($this->lender_id === KMGP2P::$lender_id) ? true : false;
    }

    public function finBitDataBorrower(){
        return $this->hasOne('App\FinBitData','application_id','id')->where('applicant_type',1);
    }

    public function finBitDataCoBorrower(){
        return $this->hasOne('App\FinBitData','application_id','id')->where('applicant_type',2);
    }

    public function avanse(){
        return $this->hasOne('App\AvanseCreateCustomer','application_id','id');
    }

    public function coAvanse(){
        return $this->hasOne('App\AvanseCreateCustomer','application_id','id');
    }

    public function avanseDisbursed(){
        return $this->hasOne('App\AvanseDisbursement','application_id','id');
    }

    public function avanseByApplicant(){
        return $this->hasOne('App\AvanseCreateCustomer','applicant_id','applicant_id');
    }

    public function avanseByCoApplicant(){
        return $this->hasOne('App\AvanseCreateCustomer','applicant_id','applicant_id');
    }

    public function disbursement_log(){
        return  $this->hasMany('App\DisbursementLogs','application_id','id');
    }

    public function liability_log(){
        return $this->hasOne('App\LiabilityLog','application_id','id');
    }

    public function ConsumerApplicationElement(){
        return $this->hasOne('App\ConsumerApplicationElement','application_id','id');
    }

    public function cibilReportBorrower(){
        return $this->hasMany('App\CibilBureau','application_id','id')->where('applicant_type', 1);
    }

    public function cibilReportCoBorrower(){
        return $this->hasMany('App\CibilBureau','application_id','id')->where('applicant_type', 2);
    }

    public function agency(){
        return $this->hasOne('App\AgencyApplication','application_id','id')->whereNull('deleted_at');
    }

    public function digioLoanAgreement(){
        return $this->hasOne('App\Model\LoanAgreementVendor','application_id','id')->whereNull('deleted_at')->where('status','com');
    }
    public function kycdetails(){
        return $this->hasOne('App\KYCDetails','application_id','id')->whereNull('deleted_at');
    }
    public function co_kycdetails(){
        return $this->hasOne('App\KYCDetails','application_id','co_applicant_id')->whereNull('deleted_at');
    }

    public static function postVkycAction($id) {
        $appObj = self::where('id', $id)->first();
        switch ($appObj->lender_id) {
            // for avanse lender run the login here
            case 3:
                $aa = $coaa = false;
                // check if applicant has been approved
                if (!empty($appObj->pan_card)) {
                    if(ConsumerApplicationController::VKYC_VENDOR == "karza") {
                        $aa = self::checkKarzaApproved($appObj->id, 1);
                    }else {
                        $aa = self::checkHypervergeApproved($appObj->id, 1);
                    }
                }

                // check if co-applicant has been approved
                if (!empty($appObj->co_applicant_pan_card)) {
                    if(ConsumerApplicationController::VKYC_VENDOR == "karza") {
                        $coaa = self::checkKarzaApproved($appObj->id, 2);
                    }else {
                        $coaa = self::checkHypervergeApproved($appObj->id, 2);
                    }
                } else { // no co-applicant on the application
                    $coaa = true;
                }
                //return "Applicant VKYC ".(($aa === true) ? "approved" : "unapproved")." Co-spplicant VKYC ".(($coaa === true) ? "approved" : "unapproved");
                // applicant and/or co-applicant has been approved
                if ($aa === true && $coaa === true) {
                    //@info: we make up this request to work on updateStatusFromJob function
                    //request()->merge(['status' => $appObj->state,'previous_state' => 'cf approved', 'state' => 'cf approved']);
                    $cacObj = new ConsumerApplicationController();
                    $cacObj->initiateForLatestBankStatement($appObj->id);
                    $cacObj->saveLiabilityPercent($appObj, $appObj->id, 'job');
                    $cacObj->checkApprovedPinCode($appObj->id);
                    $cacObj->ApprovalInit($appObj, $appObj->id);
                    $cacObj->disbursementOffers($appObj->id);
                    $cacObj->sendemandate($appObj->id);
                    $cacObj->sendSanctionLetter($appObj->id);
                    $cacObj->proformaSigningNotification($appObj->id);
                    $cacObj->creditLimitNotification($appObj->id);
                    $cacObj->insertIntoJob($appObj->id, 'referral_communication', 'approved');
                    $cacObj->whatsAppCommunication($appObj, 'approved');
                    unset($cacObj);
                }
                return "Applicant VKYC ".(($aa === true) ? "approved" : "unapproved")." Co-applicant VKYC ".(($coaa === true) ? "approved" : "unapproved");
                break;
            default:
                break;
        }
    }

    public static function checkKarzaApproved($applicant_id, $applicant_type) {
        $status = false;
        $hwObj = KarzaVideoWebhook::where('application_id', $applicant_id)
                ->where('applicant_type', $applicant_type)->first();
        if (!empty($hwObj) && !empty($hwObj->data)) {
            $vkycStatus = json_decode($hwObj->data, 1);
            if(!empty($vkycStatus['approvedByAgent']) && strtolower($vkycStatus['approvedByAgent']) === 'accepted') {
                $status = true;
            }
        }
        unset($hwObj);
        return $status;
    }

    public static function checkHypervergeApproved($applicant_id, $applicant_type) {
        $status = false;
        $hwObj = HypervergeWebhook::where('event_type', 'vcip_kyc_status')
                ->where('application_id', $applicant_id)
                ->where('applicant_type', $applicant_type)->first();
        if (!empty($hwObj) && !empty($hwObj->data)) {
            $vkycStatus = json_decode($hwObj->data, 1);
            if(!empty($vkycStatus['status']) && strtolower($vkycStatus['status']) === 'approved') {
                $status = true;
            }
        }
        unset($hwObj);
        return $status;
    }

    public static function postCreateCustomerAction($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            switch ($appObj->lender_id) {
                case 3: // avanse lender
                    return CreateCustomer::postCreateActions($appObj);
                    break;
                default:
                    return true;
                    break;
            }
        }
        return "Invalid loan id";

    }

    public static function postCreateFinanceAction($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            switch ($appObj->lender_id) {
                case 3: // avanse lender
                    return CreateFinance::postCreateActions($appObj);
                    break;
                default:
                    return true;
                    break;
            }
        }
        return "Invalid loan id";

    }

    public static function postDisbursementInstructionAction($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            switch ($appObj->lender_id) {
                case 3: // avanse lender
                    return AvanseDisbursementInstruction::postDisbursementInstructionActions($appObj);
                    break;
                default:
                    return true;
                    break;
            }
        }
        return "Invalid loan id";

    }

    public static function postFormCompleted($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            // call markytics api here
            $obj = Prediction::apiCustomerResponse($appObj);
            if ($obj instanceof Prediction) {
                return $obj->pid;
            }
            return $obj;
        }
        return "Invalid loan id";
    }

    public static function postBureauPull($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            $creditReport = CreditReport::where('application_id', $id)->first(['id']);
            if(isset($creditReport->id)) {
                // call markytics api here
                $obj = Prediction::apiBureauResponse($appObj);
                if ($obj instanceof Prediction) {
                    $returnId = 0;
                    if(isset($obj->id)){
                        $returnId = $obj->id;
                    } elseif(isset($obj->pif)){
                        $returnId = $obj->pif;
                    }
                    return $returnId;
                }
                return $obj;
            }
        }
        return "Invalid loan id";
    }

    public static function postCSBureauBankPull($id) {
        $appObj = self::where('id', $id)->first();
        if (!empty($appObj)) {
            // call markytics api here
            $obj = Prediction::apiCSBureauBankResponse($appObj);
            if ($obj instanceof Prediction) {
                return $obj->pid;
            }
            return $obj;
        }
        return "Invalid loan id";
    }

    public function AvanseNoc(){
        return $this->hasOne('App\AvanseNoc','application_id','id')->whereIn('execution_status',['pending','failed'])->where('is_available',1);
    }

    public function approved_pincode()
    {
        return $this->hasOne('App\ApprovedPincodeLists','pin_codes','current_address_pincode');
    }

    public function lender_bank(){
        return $this->hasOne('App\LenderBank','id','lender_id');
    }

    public function application_emi_details(){
        return $this->hasOne('App\ApplicationEMIDetails', 'application_id', 'id');
    }

    public function avanse_access(){

        return $this->hasOne('App\ConsumerApplicationElement','application_id','id')
            ->where(function ($q) {
                $q->where('unique_id_number', static::$uniqueRefId)
                    ->orWhereIn('application_id', [173589,
                        179991,
                        182604,
                        183167,
                        187304,
                        188806,
                        192154,
                        196290,
                        196658,
                        197474,
                        197860,
                        199564,
                        199647,
                        200285,
                        200519,
                        201022,
                        201479,
                        202157,
                        203000,
                        203158,
                        203194,
                        203339,
                        204020,
                        204317,
                        206302,
                        206358,
                        206663,
                        206829,
                        207288,
                        207357,
                        207582,
                        207859,
                        208687,
                        209695,
                        210427,
                        210935,
                        211130,
                        211246,
                        211271,
                        211774,
                        211925,
                        212131,
                        212498,
                        212528,
                        212631,
                        212675,
                        213195,
                        213689,
                        214587,
                        215088,
                        215404,
                        215689,
                        215743,
                        216027,
                        216408,
                        217019,
                        217189,
                        217708,
                        217959,
                        218467,
                        218487,
                        218977,
                        220578,
                        220712,
                        221223,
                        221259,
                        221321,
                        221358,
                        222372,
                        222516,
                        222734,
                        222771,
                        223122,
                        223332,
                        223461,
                        224274,
                        224519,
                        224653,
                        224684,
                        224786,
                        225011,
                        225132,
                        225197,
                        225240,
                        225483,
                        225530,
                        225689,
                        225766,
                        225880,
                        226313,
                        226431,
                        226690,
                        226794,
                        226862,
                        227013,
                        227030,
                        227043,
                        227111,
                        227417,
                        227704,
                        227895,
                        228001,
                        228092,
                        228193,
                        228203,
                        228234,
                        228517,
                        228586,
                        228769,
                        228780,
                        228845,
                        229016,
                        229068,
                        229073,
                        229130,
                        229343,
                        229501,
                        229542,
                        229578,
                        229750,
                        229761,
                        229786,
                        229791,
                        229840,
                        229933,
                        230003,
                        230118,
                        230277,
                        230284,
                        230351,
                        230362,
                        230364,
                        230401,
                        230754,
                        230840,
                        230892,
                        230921,
                        231107,
                        231194,
                        231247,
                        231287,
                        231297,
                        231378,
                        231484,
                        231550,
                        231618,
                        231735,
                        231860,
                        231977,
                        231990,
                        232075,
                        232091,
                        232100,
                        232133,
                        232312,
                        232388,
                        232538,
                        232610,
                        232769,
                        232867,
                        232973,
                        232989,
                        233078,
                        233091,
                        233186,
                        233249,
                        233302,
                        233308,
                        233310,
                        233421,
                        233471,
                        233580,
                        233737,
                        233746,
                        234054,
                        234063,
                        234248,
                        234270,
                        234293,
                        234339,
                        234357,
                        234399,
                        234404,
                        234405,
                        234415,
                        234472,
                        234532,
                        234569,
                        234572,
                        234735,
                        234739,
                        234867,
                        234910,
                        235038,
                        235079,
                        235172,
                        235253,
                        235301,
                        235436,
                        235450,
                        235494,
                        235603,
                        235604,
                        235702,
                        235806,
                        235909,
                        236040,
                        236099,
                        236124,
                        236141,
                        236207,
                        236284,
                        236295,
                        236363,
                        236592,
                        236614,
                        236617,
                        236659,
                        236832,
                        236846,
                        236928,
                        236969,
                        236971,
                        236981,
                        237143,
                        237146,
                        237200,
                        237284,
                        237291,
                        237293,
                        237344,
                        237350,
                        237353,
                        237468,
                        237480,
                        237606,
                        237753,
                        237886,
                        237919,
                        237997,
                        238057,
                        238063,
                        238090,
                        238092,
                        238181,
                        238200,
                        238229,
                        238238,
                        238251,
                        238283,
                        238323,
                        238371,
                        238386,
                        238389,
                        238457,
                        238617,
                        238696,
                        238699,
                        238845,
                        238953,
                        238996,
                        239038,
                        239117,
                        239176,
                        239196,
                        239214,
                        239244,
                        239281,
                        239423,
                        239462,
                        239568,
                        239622,
                        239690,
                        239834,
                        239851,
                        239899,
                        239931,
                        239948,
                        240007,
                        240015,
                        240087,
                        240134,
                        240160,
                        240199,
                        240203,
                        240232,
                        240312,
                        240343,
                        240385,
                        240490,
                        240506,
                        240529,
                        240555,
                        240699,
                        240799,
                        240800,
                        240913,
                        241000,
                        241018,
                        241022,
                        241047,
                        241074,
                        241110,
                        241132,
                        241134,
                        241144,
                        241149,
                        241157,
                        241190,
                        241214,
                        241298,
                        241310,
                        241412,
                        241523,
                        241551,
                        241578,
                        241579,
                        241682,
                        241762,
                        241793,
                        241967,
                        241984,
                        242042,
                        242103,
                        242138,
                        242162,
                        242185,
                        242189,
                        242211,
                        242223,
                        242302,
                        242372,
                        242427,
                        242515,
                        242556,
                        242575,
                        242758,
                        242781,
                        242795,
                        242848,
                        242859,
                        242896,
                        242915,
                        242928,
                        242944,
                        243044,
                        243078,
                        243161,
                        243180,
                        243190,
                        243222,
                        243223,
                        243238,
                        243310,
                        243337,
                        243377,
                        243416,
                        243437,
                        243519,
                        243545,
                        243605,
                        243659,
                        243782,
                        243800,
                        243812,
                        243826,
                        243828,
                        243832,
                        243864,
                        243926,
                        243953,
                        243971,
                        244047,
                        244091,
                        244138,
                        244284,
                        244491,
                        244504,
                        244509,
                        244545,
                        244552,
                        244684,
                        244687,
                        244704,
                        244753,
                        244809,
                        244827,
                        244898,
                        244906,
                        244940,
                        244967,
                        244980,
                        244983,
                        245032,
                        245090,
                        245104,
                        245136,
                        245193,
                        245196,
                        245208,
                        245272,
                        245284,
                        245302,
                        245357,
                        245358,
                        245360,
                        245564,
                        245593,
                        245666,
                        245673,
                        245680,
                        245777,
                        245798,
                        245859,
                        245927,
                        245958,
                        245975,
                        245983,
                        245989,
                        246003,
                        246008,
                        246021,
                        246031,
                        246032,
                        246053,
                        246066,
                        246088,
                        246117,
                        246129,
                        246148,
                        246187,
                        246263,
                        246301,
                        246340,
                        246360,
                        246380,
                        246395,
                        246432,
                        246502,
                        246610,
                        246624,
                        246708,
                        246732,
                        246833,
                        246870,
                        246912,
                        246939,
                        247025,
                        247055,
                        247166,
                        247189,
                        247202,
                        247214,
                        247215,
                        247255,
                        247274,
                        247345,
                        247459,
                        247501,
                        247523,
                        247547,
                        247580,
                        247599,
                        247604,
                        247635,
                        247651,
                        247685,
                        247699,
                        247711,
                        247741,
                        247752,
                        247759,
                        247776,
                        247780,
                        247784,
                        247806,
                        247832,
                        247881,
                        247911,
                        247930,
                        247957,
                        247965,
                        248001,
                        248059,
                        248101,
                        248115,
                        248173,
                        248183,
                        248202,
                        248288,
                        248427,
                        248439,
                        248538,
                        248576,
                        248584,
                        248599,
                        248603,
                        248621,
                        248717,
                        248811,
                        248843,
                        248872,
                        248874,
                        248915,
                        248960,
                        249003,
                        249015,
                        249039,
                        249080,
                        249090,
                        249095,
                        249115,
                        249147,
                        249150,
                        249211,
                        249261,
                        249268,
                        249303,
                        249319,
                        249406,
                        249446,
                        249520,
                        249534,
                        249601,
                        249609,
                        249614,
                        249623,
                        249633,
                        249648,
                        249654,
                        249659,
                        249675,
                        249731,
                        249740,
                        249766,
                        249783,
                        249786,
                        249789,
                        249911,
                        249912,
                        249928,
                        249965,
                        250007,
                        250087,
                        250089,
                        250093,
                        250119,
                        250144,
                        250181,
                        250312,
                        250353,
                        250372,
                        250440,
                        250477,
                        250503,
                        250511,
                        250516,
                        250565,
                        250606,
                        250633,
                        250638,
                        250661,
                        250683,
                        250718,
                        250725,
                        250750,
                        250767,
                        250777,
                        250861,
                        250864,
                        250873,
                        250881,
                        250896,
                        250909,
                        250916,
                        250921,
                        250928,
                        250940,
                        250954,
                        250987,
                        250989,
                        251028,
                        251125,
                        251128,
                        251140,
                        251159,
                        251171,
                        251172,
                        251193,
                        251202,
                        251289,
                        251300,
                        251310,
                        251349,
                        251371,
                        251406,
                        251449,
                        251472,
                        251474,
                        251495,
                        251500,
                        251555,
                        251559,
                        251578,
                        251579,
                        251630,
                        251631,
                        251675,
                        251685,
                        251693,
                        251759,
                        251800,
                        251887,
                        251893,
                        251909,
                        251924,
                        251947,
                        251955,
                        251996,
                        252007,
                        252012,
                        252014,
                        252032,
                        252106,
                        252138,
                        252145,
                        252170,
                        252268,
                        252293,
                        252294,
                        252331,
                        252348,
                        252455,
                        252477,
                        252498,
                        252508,
                        252514,
                        252560,
                        252564,
                        252589,
                        252599,
                        252610,
                        252644,
                        252652,
                        252656,
                        252670,
                        252699,
                        252783,
                        252804,
                        252816,
                        252835,
                        252897,
                        252901,
                        252925,
                        252950,
                        252982,
                        253029,
                        253035,
                        253040,
                        253078,
                        253086,
                        253111,
                        253134,
                        253159,
                        253165,
                        253169,
                        253180,
                        253207,
                        253277,
                        253285,
                        253309,
                        253348,
                        253403,
                        253430,
                        253469,
                        253476,
                        253532,
                        253547,
                        253552,
                        253567,
                        253598,
                        253634,
                        253657,
                        253809,
                        253838,
                        253870,
                        253871,
                        253883,
                        253885,
                        253907,
                        253927,
                        253934,
                        253936,
                        253941,
                        253944,
                        254006,
                        254015,
                        254031,
                        254032,
                        254055,
                        254075,
                        254143,
                        254159,
                        254167,
                        254186,
                        254218,
                        254240,
                        254255,
                        254293,
                        254298,
                        254302,
                        254351,
                        254360,
                        254410,
                        254413,
                        254417,
                        254443,
                        254498,
                        254528,
                        254554,
                        254564,
                        254566,
                        254583,
                        254599,
                        254652,
                        254707,
                        254746,
                        254759,
                        254761,
                        254813,
                        254832,
                        254840,
                        254843,
                        254849,
                        254876,
                        254883,
                        254892,
                        255036,
                        255102,
                        255117,
                        255129,
                        255154,
                        255173,
                        255188,
                        255301,
                        255306,
                        255392,
                        255419,
                        255437,
                        255478,
                        255515,
                        255534,
                        255587,
                        255590,
                        255609,
                        255691,
                        255736,
                        255760,
                        255770,
                        255806,
                        255819,
                        255834,
                        255844,
                        255864,
                        255930,
                        255950,
                        255998,
                        256020,
                        256054,
                        256065,
                        256067,
                        256085,
                        256100,
                        256105,
                        256116,
                        256117,
                        256122,
                        256126,
                        256136,
                        256151,
                        256266,
                        256278,
                        256319,
                        256342,
                        256351,
                        256372,
                        256393,
                        256405,
                        256445,
                        256452,
                        256456,
                        256562,
                        256660,
                        256688,
                        256742,
                        256804,
                        256821,
                        256890,
                        256939,
                        256954,
                        256956,
                        256979,
                        257001,
                        257031,
                        257047,
                        257059,
                        257079,
                        257087,
                        257156,
                        257163,
                        257186,
                        257188,
                        257278,
                        257342,
                        257358,
                        257400,
                        257431,
                        257437,
                        257458,
                        257468,
                        257485,
                        257499,
                        257519,
                        257531,
                        257557,
                        257567,
                        257623,
                        257633,
                        257677,
                        257788,
                        257804,
                        257838,
                        257915,
                        257921,
                        257942,
                        257947,
                        257973,
                        257985,
                        258091,
                        258200,
                        258209,
                        258252,
                        258254,
                        258297,
                        258317,
                        258326,
                        258333,
                        258339,
                        258348,
                        258390,
                        258488,
                        258513,
                        258517,
                        258587,
                        258595,
                        258622,
                        258737,
                        258751,
                        258757,
                        258782,
                        258814,
                        258876,
                        258931,
                        259024,
                        259033,
                        259043,
                        259049,
                        259073,
                        259105,
                        259136,
                        259141,
                        259199,
                        259218,
                        259294,
                        259306,
                        259316,
                        259319,
                        259325,
                        259329,
                        259363,
                        259366,
                        259378,
                        259484,
                        259532,
                        259586,
                        259610,
                        259628,
                        259632,
                        259704,
                        259718,
                        259719,
                        259778,
                        259779,
                        259782,
                        259810,
                        259812,
                        259850,
                        259868,
                        259894,
                        259904,
                        259912,
                        259918,
                        259919,
                        259944,
                        259955,
                        259956,
                        259977,
                        260049,
                        260058,
                        260068,
                        260090,
                        260118,
                        260130,
                        260156,
                        260193,
                        260230,
                        260243,
                        260247,
                        260250,
                        260281,
                        260319,
                        260329,
                        260347,
                        260351,
                        260362,
                        260367,
                        260396,
                        260433,
                        260451,
                        260457,
                        260475,
                        260512,
                        260530,
                        260536,
                        260552,
                        260572,
                        260651,
                        260687,
                        260689,
                        260704,
                        260715,
                        260719,
                        260726,
                        260729,
                        260739,
                        260752,
                        260780,
                        260811,
                        260818,
                        260842,
                        260849,
                        260850,
                        260871,
                        260874,
                        260875,
                        260886,
                        260888,
                        260905,
                        260916,
                        260985,
                        261009,
                        261021,
                        261158,
                        261175,
                        261193,
                        261200,
                        261207,
                        261229,
                        261232,
                        261242,
                        261244,
                        261250,
                        261261,
                        261262,
                        261280,
                        261281,
                        261285,
                        261301,
                        261348,
                        261351,
                        261364,
                        261365,
                        261382,
                        261384,
                        261396,
                        261419,
                        261463,
                        261479,
                        261484,
                        261511,
                        261538,
                        261568,
                        261585,
                        261619,
                        261629,
                        261671,
                        261715,
                        261724,
                        261753,
                        261780,
                        261846,
                        261861,
                        261874,
                        261900,
                        261913,
                        261924,
                        261925,
                        261928,
                        261940,
                        261959,
                        261982,
                        261997,
                        262030,
                        262036,
                        262044,
                        262071,
                        262084,
                        262090,
                        262094,
                        262109,
                        262126,
                        262130,
                        262137,
                        262171,
                        262184,
                        262186,
                        262197,
                        262213,
                        262241,
                        262252,
                        262269,
                        262297,
                        262308,
                        262324,
                        262466,
                        262495,
                        262507,
                        262626,
                        262647,
                        262693,
                        262715,
                        262749,
                        262828,
                        262841,
                        262850,
                        262865,
                        262954,
                        262958,
                        262979,
                        262999,
                        263106,
                        263158,
                        263196,
                        263304,
                        263324,
                        263346,
                        263393,
                        263444,
                        263459,
                        263511,
                        263534,
                        263537,
                        263570,
                        263583,
                        263609,
                        263666,
                        263672,
                        263720,
                        263751,
                        263764,
                        263770,
                        263797,
                        263829,
                        263850,
                        263899,
                        263935,
                        263938,
                        263959,
                        264194,
                        264260,
                        264295,
                        264313,
                        264318,
                        264341,
                        264368,
                        264421,
                        264438,
                        264462,
                        264538,
                        264562,
                        264569,
                        264577,
                        264594,
                        264599,
                        264621,
                        264631,
                        264645,
                        264654,
                        264717,
                        264754,
                        264808,
                        264829,
                        264830,
                        264870,
                        264928,
                        264945,
                        264955,
                        264967,
                        264995,
                        265003,
                        265004,
                        265006,
                        265012,
                        265013,
                        265030,
                        265037,
                        265106,
                        265115,
                        265139,
                        265151,
                        265152,
                        265161,
                        265163,
                        265302,
                        265306,
                        265312,
                        265316,
                        265339,
                        265396,
                        265419,
                        265460,
                        265505,
                        265521,
                        265541,
                        265555,
                        265557,
                        265561,
                        265575,
                        265607,
                        265612,
                        265656,
                        265679,
                        265695,
                        265723,
                        265778,
                        265799,
                        265802,
                        265879,
                        265883,
                        265885,
                        265889,
                        265900,
                        265945,
                        265955,
                        265989,
                        266012,
                        266049,
                        266062,
                        266070,
                        266089,
                        266096,
                        266116,
                        266121,
                        266140,
                        266144,
                        266146,
                        266154,
                        266166,
                        266169,
                        266187,
                        266267,
                        266274,
                        266296,
                        266297,
                        266303,
                        266319,
                        266331,
                        266380,
                        266389,
                        266419,
                        266426,
                        266434,
                        266447,
                        266480,
                        266559,
                        266611,
                        266633,
                        266646,
                        266661,
                        266732,
                        266733,
                        266734,
                        266773,
                        266776,
                        266785,
                        266807,
                        266813,
                        266837,
                        266885,
                        266919,
                        266998,
                        267004,
                        267021,
                        267036,
                        267093,
                        267094,
                        267105,
                        267153,
                        267160,
                        267174,
                        267195,
                        267203,
                        267219,
                        267222,
                        267227,
                        267261,
                        267273,
                        267278,
                        267326,
                        267376,
                        267382,
                        267395,
                        267417,
                        267424,
                        267430,
                        267457,
                        267467,
                        267516,
                        267520,
                        267549,
                        267578,
                        267581,
                        267582,
                        267593,
                        267601,
                        267609,
                        267634,
                        267645,
                        267710,
                        267714,
                        267791,
                        267813,
                        267816,
                        267833,
                        267881,
                        267892,
                        267925,
                        267934,
                        267938,
                        267953,
                        267978,
                        268020,
                        268048,
                        268088,
                        268090,
                        268094,
                        268105,
                        268109,
                        268118,
                        268129,
                        268146,
                        268160,
                        268162,
                        268166,
                        268202,
                        268209,
                        268232,
                        268272,
                        268282,
                        268375,
                        268380,
                        268401,
                        268411,
                        268436,
                        268445,
                        268447,
                        268473,
                        268511,
                        268534,
                        268554,
                        268614,
                        268624,
                        268631,
                        268648,
                        268653,
                        268697,
                        268706,
                        268712,
                        268727,
                        268762,
                        268763,
                        268764,
                        268773,
                        268776,
                        268780,
                        268782,
                        268808,
                        268812,
                        268832,
                        268853,
                        268865,
                        268933,
                        268985,
                        269030,
                        269060,
                        269073,
                        269078,
                        269083,
                        269097,
                        269111,
                        269135,
                        269144,
                        269166,
                        269185,
                        269187,
                        269250,
                        269255,
                        269272,
                        269278,
                        269313,
                        269325,
                        269347,
                        269368,
                        269370,
                        269389,
                        269474,
                        269498,
                        269517,
                        269552,
                        269603,
                        269654,
                        269656,
                        269664,
                        269681,
                        269686,
                        269688,
                        269708,
                        269718,
                        269754,
                        269759,
                        269760,
                        269778,
                        269787,
                        269796,
                        269829,
                        269833,
                        269834,
                        269847,
                        269850,
                        269854,
                        269883,
                        269891,
                        269898,
                        269899,
                        269901,
                        269946,
                        269947,
                        269957,
                        270008,
                        270027,
                        270092,
                        270102,
                        270122,
                        270127,
                        270136,
                        270139,
                        270144,
                        270213,
                        270227,
                        270251,
                        270253,
                        270325,
                        270333,
                        270363,
                        270373,
                        270388,
                        270423,
                        270446,
                        270464,
                        270489,
                        270513,
                        270540,
                        270544,
                        270547,
                        270578,
                        270588,
                        270620,
                        270655,
                        270667,
                        270682,
                        270721,
                        270755,
                        270759,
                        270760,
                        270772,
                        270778,
                        270796,
                        270805,
                        270807,
                        270824,
                        270826,
                        270861,
                        270883,
                        270893,
                        270909,
                        270911,
                        270915,
                        270943,
                        270957,
                        270966,
                        271094,
                        271133,
                        271147,
                        271162,
                        271180,
                        271204,
                        271226,
                        271228,
                        271239,
                        271258,
                        271277,
                        271279,
                        271283,
                        271291,
                        271303,
                        271310,
                        271327,
                        271331,
                        271352,
                        271362,
                        271371,
                        271382,
                        271394,
                        271400,
                        271403,
                        271421,
                        271447,
                        271449,
                        271481,
                        271484,
                        271498,
                        271508,
                        271538,
                        271550,
                        271559,
                        271560,
                        271570,
                        271572,
                        271579,
                        271595,
                        271596,
                        271599,
                        271638,
                        271662,
                        271668,
                        271671,
                        271676,
                        271681,
                        271691,
                        271749,
                        271759,
                        271766,
                        271772,
                        271787,
                        271809,
                        271812,
                        271864,
                        271869,
                        271916,
                        271936,
                        271974,
                        271980,
                        271988,
                        271991,
                        272000,
                        272001,
                        272014,
                        272057,
                        272072,
                        272083,
                        272086,
                        272115,
                        272116,
                        272128,
                        272136,
                        272179,
                        272237,
                        272257,
                        272265,
                        272276,
                        272278,
                        272357,
                        272391,
                        272393,
                        272403,
                        272417,
                        272421,
                        272432,
                        272437,
                        272459,
                        272468,
                        272503,
                        272537,
                        272556,
                        272561,
                        272584,
                        272609,
                        272648,
                        272684,
                        272705,
                        272724,
                        272746,
                        272755,
                        272769,
                        272781,
                        272795,
                        272858,
                        272888,
                        272916,
                        272965,
                        272974,
                        272986,
                        272987,
                        272989,
                        272990,
                        272994,
                        272995,
                        273009,
                        273013,
                        273017,
                        273038,
                        273046,
                        273054,
                        273084,
                        273128,
                        273129,
                        273139,
                        273152,
                        273153,
                        273164,
                        273167,
                        273193,
                        273203,
                        273209,
                        273216,
                        273224,
                        273230,
                        273231,
                        273248,
                        273275,
                        273284,
                        273286,
                        273304,
                        273321,
                        273326,
                        273334,
                        273345,
                        273358,
                        273365,
                        273392,
                        273397,
                        273405,
                        273425,
                        273447,
                        273463,
                        273475,
                        273492,
                        273515,
                        273517,
                        273521,
                        273534,
                        273541,
                        273599,
                        273637,
                        273641,
                        273648,
                        273675,
                        273689,
                        273721,
                        273772,
                        273797,
                        273819,
                        273838,
                        273954,
                        273962,
                        273964,
                        273972,
                        273995,
                        274000,
                        274024,
                        274025,
                        274057,
                        274110,
                        274189,
                        274304,
                        274308,
                        274320,
                        274387,
                        274390,
                        274410,
                        274471,
                        274483,
                        274532,
                        274533,
                        274628,
                        274633,
                        274774,
                        274863,
                        157541,
                        180249,
                        198280,
                        205291,
                        210172,
                        218667,
                        221052,
                        221867,
                        222360,
                        222864,
                        223022,
                        227240,
                        227961,
                        230604,
                        234690,
                        235812,
                        239085,
                        240310,
                        242375,
                        244385,
                        248353,
                        252189,
                        252242,
                        252920,
                        252981,
                        253118,
                        254194,
                        254833,
                        255265,
                        255447,
                        255954,
                        256221,
                        256575,
                        256697,
                        256735,
                        257123,
                        257277,
                        257280,
                        258125,
                        258487,
                        258576,
                        259280,
                        259612,
                        260313,
                        260547,
                        261532,
                        261893,
                        262053,
                        262396,
                        262414,
                        263153,
                        263656,
                        264550,
                        264643,
                        264938,
                        265095,
                        265245,
                        265777,
                        266066,
                        266123,
                        266253,
                        266512,
                        266562,
                        266944,
                        267011,
                        267075,
                        267136,
                        267940,
                        268222,
                        268291,
                        269121,
                        269146,
                        269813,
                        270189,
                        270417,
                        270894,
                        271037,
                        272059,
                        272407,
                        272920,
                        273051,
                        273360,
                        273569,
                        273871,
                        273968,
                        274014,
                        276521,
                        278999]);
            });

        //$application_element = $this->hasOne('App\ConsumerApplicationElement','application_id','id');
        //$application_element = $application_element->where('unique_id_number',static::$uniqueRefId)->orWhereIn('application_id', []);
        //return $application_element;
    }
}
