<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Scopes\MessageScope;

class AvanseCreateFinance extends Model
{
    protected $table = 'avanse_finance';

    public static function getAvanseLoanId($id) {

    	$obj = self::where('application_id', $id)->first(['finReference']);
    	if(!empty($obj->finReference)) {
    		return $obj->finReference;
    	}
    	return false;
    }
    public static function getAvanseCustomerId($keyword) {
    	$obj = self::where('finReference', $keyword)->first(['application_id']);
        if(!empty($obj->application_id)) {
    		return $obj->application_id;
        }
        return false;
    }

    protected $fillable = [
        "application_id",
        "finReference",
        "collateralOverride",
        "outstandingPri",
        "isUpfrontAuto",
        "receiptId",
        "stp",
        "created_at"
    ];

    public function save(array $options = array())
    {
        $missingKeys = array_diff(array_values($this->fillable), array_keys($this->getAttributes()));
        foreach ($missingKeys as $missingKey){
            $this->$missingKey = '';
        }
        parent::save($options);
    }
}
