<?php

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper;

use \Illuminate\Database\Capsule\Manager as DB;
use ModulesGarden\HostingQuotaNotifications\Core\Helper;

/**
 * Description of TaxesHelper
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class TaxesHelper
{

    public static function getTax($level, $state = "", $country = "")
    {
        //$db = new MG_SMS_DBWorld();

        $tax = DB::table('tbltax')
                ->select("tbltax.*")
                ->where('level', $level)
                ->where('state', $state)
                ->where('country', $country)
                ->first();

        $tax = (array) $tax;


        if (empty($tax))
        {
            $tax = DB::table('tbltax')
                    ->select("tbltax.*")
                    ->where('level', $level)
                    ->where('state', "")
                    ->where('country', $country)
                    ->first();

            $tax = (array) $tax;
        }
        if (empty($tax))
        {
            $tax = DB::table('tbltax')
                    ->select("tbltax.*")
                    ->where('level', $level)
                    ->where('state', "")
                    ->where('country', "")
                    ->first();
            $tax = (array) $tax;
        }

        if (empty($tax))
        {
            $tax['taxrate'] = 0;
        }
        if (!$tax['name'])
        {
            $tax['name'] = Helper\sl('lang')->T('invoicestax');
        }

        return $tax;
    }
}
