<?php
    ini_set('display_errors', 0);
    ini_set('display_startup_errors', 0);
    // error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);

    chdir(dirname(__DIR__));
    require_once('./REST/config.php');

    $GLOBALS['mailLog'] = '';
    
    if ($_GET['key'] != $restConfig['twinpolKey']) {
        echo 'Unauthorized';
        exit;
    }

    require_once('./REST/functions.php');
    // Enable SugarCRM features
    if(!defined('sugarEntry'))define('sugarEntry', true);
    require_once('./include/entryPoint.php');
    require_once ('data/SugarBean.php');
    require_once ('include/utils.php');
    // fix db, but why? 
    $GLOBALS['db']->query("USE preDb_0dcc87940d3655fa574b253df04ca1c3;");

    switch ($_GET["action"]) {
        case 'createPzFromInvoice': 
            createPzFromInvoice($_GET['record'], $_GET['stock_id']);
            break;
        case 'getSale':
            sendSale($_GET['record']);
            break;
        case 'getStocks':
            sendStocks();
            break;
        case 'updateSaleE5Number':
            updateSaleE5Number($_GET['record'], $_GET['e5_record'], $_GET['e5_document_no']);
            break;
    }
?>