<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Product
{
    public static $generatePrevProgram = true;
    public static $instalments = 2;

    public static function getLivePrice($ctrID)
    {
        return 200;
    }

    public static function getMaintenancePrice()
    {
        $db = &get_instance();

        $query = "SELECT * FROM cl_hlusers.o_products
            WHERE id = 1297 AND lang = 36 AND seq > 0";
        $product = $db->db->query($query)->row();

        if ($product->akcio != '' && $product->akcio != null && date('Y-m-d') <= $product->ackio_date)
            $product->price = $product->akcio;
        else
            $product->price = $product->huf;

        return $product->price;
    }

    public static function getInstalment($prodID, $seq, $o_type, $akcio)
    {
        if ($akcio == '' || $akcio == null || date('Y-m-d') > $akcio)
            return self::$instalments;

        /*if ($prodID == 1298) {
            return 3;
        }

        if ($prodID == 1300) {
            return 4;
        }

        if ($prodID == 1551) {
            return 4;
        }*/

        return self::$instalments;
    }

    public static function getFloatingPrice($ctrID)
    {
        $db = &get_instance();

        $product = $db->db->query("SELECT * FROM cl_hlusers.o_products WHERE kategoria = 'floating' AND lang = '{$ctrID}'")->row();

        return substr($ctrID, 0, 2) == '11' ? $product->usd : $product->euro;
    }

    public static function getLanPrice($ctrID, $type)
    {
        $db = &get_instance();

        $product = $db->db->query("SELECT * FROM cl_hlusers.o_products WHERE kategoria = 'lan' AND lang = '{$ctrID}' AND type = '{$type}' AND seq = 2")->row();

        return substr($ctrID, 0, 2) == '11' ? $product->usd : $product->euro;
    }

    public static function needPeriod($category, $type, $period)
    {
        return $category == 'perp' && $type == 8 && $period > 1;
    }

    public static function getHardlockPrice($ctrID)
    {
        if ($ctrID == "43" || $ctrID == "39" || $ctrID == '11')
            return 0;
        else
            return 84;
    }

    public static function getProductID($category)
    {
        if ($category == 'live')
            return 2;
        else
            return 1;
    }

    public static function getPrevSoftwarePrice($ctrID)
    {
        if (Product::$generatePrevProgram == false && ($ctrID == '37' || $ctrID == '43'))
            return 150;
        else
            return 0;
    }

    public static function getTypeFromSerial($serial)
    {
        return substr($serial, 6, 1);
    }

    public static function getVer8And9FromSerial($serial)
    {
        return substr($serial, 7, 2);
    }

    public static function getNonprofitVersion($prodName, $id = 0)
    {
        $nonp = new stdClass();

        if (strstr($prodName, "LIVE") || $id == 2036 || $id == 2037) {
            $nonp->name = 'XP 2023';
            $nonp->ver  = '2023';
        } else {
            $nonp->name = 'XP 2024';
            $nonp->ver  = '2024';
        }

        return $nonp;
    }

    public static function GetLanSignFromLanUserNumber($users)
    {
        $lan = 0;

        if ($users == 0) $lan = 0;
        elseif ($users == 1) $lan = 1;
        elseif ($users == 2) $lan = 2;
        elseif ($users == 3) $lan = 3;
        elseif ($users == 4) $lan = 4;
        elseif ($users == 5) $lan = 5;
        elseif ($users == 10) $lan = 6;
        elseif ($users == 15) $lan = 7;
        elseif ($users == 20) $lan = 8;
        elseif ($users <= 49) $lan = 9;

        return $lan;
    }

    public static function getSubscriptionInfo($productName)
    {
        $message = '';

        if (strpos($productName, "yearly")) {
            $message = 'This is a "pay as you go" product. The first year is paid now. Once the paid subscription period is paid, the subscription shall automatically 
                renew for additional year(s) and you will be automatically issued an invoice for the next year(s) for as long as the subscription is active. <br/>
                The contemporary price list for subscription products is announced each January, expected price increase is maximum the Eurozone inflation rate +1.5%.';
        } else {
            $message = 'This is a "pay as you go" product. The first 3 months are paid now. Once the initial 3 months pass, the subscription shall automatically 
                renew for additional months, and you will be automatically issued an invoice for the next month(s) for as long as the subscription is active. <br/>
                The contemporary price list for subscription products is announced each January, expected price increase is maximum the Eurozone inflation rate +1.5%.';
        }

        return $message;
    }

    public static function getSubscriptionExpirationDate($productName)
    {
        $date = new DateTime();

        if (strpos($productName, "yearly"))
            $date->modify('+1 year');
        else
            $date->modify('+3 month');

        return $date->format('t/m/Y');
    }

    public static function getFileInfo($id, $category)
    {
        if ($category == 'nonp')
            return 'Enrollment Certification';

        if ($category == 'comp')
            return 'Receipt for Comp. Upgrade';

        if ($id == 767 || $id == 766)
            return 'Proof of studies';

        if ($id == 775 || $id == 777)
            return 'Membership proof';
    }

    public static function needCertification($id, $category)
    {
        if ($category == 'nonp')
            return true;

        if ($id == 767 || $id == 766 || $id == 775 || $id == 777)
            return true;

        return false;
    }

    public static function getMEPmoduleForSubscription($prodName, $ctrID)
    {
        $module = new stdClass();

        switch (substr($ctrID, 0, 2)) {
            case 37:
                $module->price  = strpos($prodName, "monthly") ? 15 : 144;
                break;

            case 61:
                $module->price  = strpos($prodName, "monthly") ? 15 : 144;
                break;

            case 55:
                $module->price  = strpos($prodName, "monthly") ? 14 : 130;
                break;

            case 42:
                $module->price  = strpos($prodName, "monthly") ? 17 : 158;
                break;

            case 33:
                $module->price  = strpos($prodName, "monthly") ? 15 : 144;
                break;

            case 39:
                $module->price  = strpos($prodName, "monthly") ? 15 : 144;
                break;

            case 82:
                $module->price  = strpos($prodName, "monthly") ? 15 : 144;
                break;

            case 34:
                $module->price  = strpos($prodName, "monthly") ? 17 : 158;
                break;

            case 88:
                $module->price  = strpos($prodName, "monthly") ? 17 : 158;
                break;

            default:
                $module->price  = strpos($prodName, "monthly") ? 18 : 173;
                break;
        }

        $module->name   = strpos($prodName, "monthly") ? 'MEP module for ARCHLine.XP LT or PRO 2022 monthly subscription' : 'MEP module for ARCHLine.XP LT or PRO 2022 yearly subscription';
        $module->mdCode = 16;

        return $module;
    }

    public static function isInvoice($ctrID)
    {
        $isInvoice = false;

        switch ($ctrID) {
            case '49': // Nemetorszag
                $isInvoice = true;
                break;

            case '38': // Horvatorszag
                $isInvoice = true;
                break;

            case '33': // Franciaorszag
                $isInvoice = true;
                break;

            case '42': // Csehorszag
                $isInvoice = true;
                break;

            case '48': // Lengyelorszag
                $isInvoice = false; // 2023.06.14 - Atallitva havi szamlazasra
                break;

            case '34': // Spanyolorszag
                $isInvoice = true;
                break;

            case '37': // TESZT
                $isInvoice = true;
                break;

            case '82':  //Korea
                $isInvoice = true;
                break;

            case '61':  //Ausztralia
                $isInvoice = true;
                break;

            case '88':  //Tajvan
                $isInvoice = true;
                break;

            case '44':  //UK
                $isInvoice = true;
                break;

            case '60':  //Malajzia
                $isInvoice = true;
                break;

            case '65':  //Szingapur
                $isInvoice = true;
                break;

            case '30': //Gorogorszag
                $isInvoice = true;
                break;

            case '51': //Portugalia
                $isInvoice = true;
                break;

            case '11': // USA
                $isInvoice = true;
                break;

            case '71': // Lettorszag
                $isInvoice = true;
                break;

            case '86': // Szlovenia (e-DISTI)
                $isInvoice = true;
                break;

            case '861': // Szlovenia (CAX)
                $isInvoice = true;
                break;

            case '55':  // Brazilia
                $isInvoice = true;
                break;

            case '90': // Torokorszag
                $isInvoice = true;
                break;

            case '491': // Nemetorszag (POLZIN Systemhaus)
                $isInvoice = true;

            case '492': // Nemetorszag (Alpha Software)
                $isInvoice = true;

            case '493': // Nemetorszag (Hannes Süer)
                $isInvoice = true;

            case '494': // Nemetorszag (Encee GmbH)
                $isInvoice = true;
                break;

            case '495': // Nemetorszag (Breeze Media)
                $isInvoice = true;
                break;

            case '401': // Romania (ZWCAD Distribution SRL)
                $isInvoice = true;
                break;

            case '402': // Romania (TMSYS Rom S.R.L.)
                $isInvoice = true;
                break;

            case '91': // India
                $isInvoice = true;
                break;

            case '13': // Peru
                $isInvoice = true;
                break;

            case '301': // Gorogorszag (EASYCAD)
                $isInvoice = true;
                break;

            case '380': // Horvatorszag (Cad Global doo)
                $isInvoice = true;
                break;

            case '12': // Bulgaria
                $isInvoice = true;
                break;

            case '31': // Hollandia
                $isInvoice = true;
                break;

            case '43': // Ausztria
                $isInvoice = true;
                break;

            default: // Minden mas
                $isInvoice = false;
                break;
        }

        return $isInvoice;
    }
}
