<?php

    require_once("{$sitepath}autentificare.php");
    require_once("{$sitepath}pagecomponents.php");

    check_connected();
    
    if (!isset($run_from_service))
    {
        $id = getuserdata('id', 0);
        $cant = getuserdata('cant', 0);
    }
    
    $errorMessage = "";
echo 1;
    
    $q = $connMain->query("
                SELECT
                    *
                FROM cas_compensari
                WHERE IdCasCompensare = $id
            ");
    if ($r = $q->fetch_assoc())
    {
        $fPretAmanuntUT = $r['PretMaximUT'];
        $fPretCompensat = $r['ValoareCompensare'];
        $fValoareAmanunt = round($fPretAmanuntUT * $cant, 2);
        $fValoareCompensare = round($fPretCompensat * $cant, 2);
        $connMain->query("INSERT INTO retete (IdSesiune, IdCasCompensare, Cantitate, ValoareAmanunt, ValoareCompensata)
                          VALUES('{$_SESSION['saved_session_id']}', $id, $cant, $fValoareAmanunt, $fValoareCompensare)");
        echo $connMain->error;
    }
    
?>