<?php

use App\BranchModel;
use App\FundsRegisterModel;
use App\User;

function defaultAvatar(){
    return asset('storage/images/default.png');
}
function defaultImg(){
    return asset('storage/images/image.png');
}
function company(){
    return BranchModel::whereNotNull('key_code')->first();
}
function branch(){
    return BranchModel::find(auth()->user()->branch_id);
}
function secret(){
    return !is_null(branch()->key_code);
}
function wallet(){
    return FundsRegisterModel::where('user_id',auth()->user()->id)->first();
}
function monthRanges($date1, $date2)
{
    $ts1    = strtotime($date1);
    $ts2    = strtotime($date2);
    $year1  = date('Y', $ts1);
    $year2  = date('Y', $ts2);

    $month1 = date('m', $ts1);
    $month2 = date('m', $ts2);

    $months = (($year2 - $year1) * 12) + ($month2 - $month1);

    $arrMonths  = [];
    $increment  = 0;
    while($months>=0){
        $month = date("Y-m-d", strtotime("+$increment month", $ts1));
        array_push($arrMonths,$month);
        $months--;
        $increment++;
    }
    return $arrMonths;
}