<?php

class Payments extends Window
{
    protected $template = 'window/payment.tpl';

    public function get_vars()
    {
        $vars = parent::get_vars();

        $pageVars = getVal('body', $vars, []);

        $pageVars['acn'] = $acn = getVal('acn');
        $pageVars['id'] = $IDo = getVal('IDo');

        if ($acn == 'order' && isset($IDo) && is_numeric($IDo)) {
            $foundAll = 0;

            if (findModule('paymuzo')) {
                //	CLASS
                // ##########################################################
                // TODO include_once $cfg['Path']['shared_class'] . "class.paymuzo.php";
                // $classPayMuzo = new PayMuzo();
                // ##########################################################
                //	CLASS
                // TODO chybi tabulka
                $SQL = sqlQuery("SELECT id, order_state, amount_order, currency, pr_code, sr_code, DATE_FORMAT(date_order, '%e.%c.%Y %H:%i:%s') AS datef
				FROM ".getTableName('paymuzo_payments')."
				WHERE id_order='".$_GET['IDo']."'
				ORDER BY date_order DESC");
                $pageVars['paymuzo'] = $SQL;
            }

            if (findModule('multiservis')) {
                $SQL = sqlQuery("SELECT id, order_state, id_agreement, amount_order, currency,
						DATE_FORMAT(date_order, '%e.%c.%Y %H:%i:%s') AS datef, DATE_FORMAT(date_authorisation, '%e.%c.%Y %H:%i:%s') AS datea
					FROM ".getTableName('multiservis_payments')."
					WHERE id_order='".$_GET['IDo']."'
					ORDER BY date_order DESC");

                $pageVars['multiservis'] = $SQL;
            }
            if (findModule('homecredit')) {
                $SQL = sqlQuery("SELECT id, order_state, amount_order, currency,
						DATE_FORMAT(date_order, '%e.%c.%Y %H:%i:%s') AS datef, DATE_FORMAT(date_authorisation, '%e.%c.%Y %H:%i:%s') AS datea
					FROM ".getTableName('homecredit_payments')."
					WHERE id_order='".$_GET['IDo']."'
					ORDER BY date_order DESC");
                $pageVars['homecredit'] = $SQL;
            }
        }

        $vars['body'] = $pageVars;

        return $vars;
    }
}

$Payment = new Payments();
$Payment->run();
