<?php

	// Dismiss Session
	PHPVC_SESSION::VAR_STOP();
	
	// Perform Login
    $SHORTCODE_STATUS = PHPCUS_SHORTCODE::CUS_QUICK_LOGIN();
	
	// Check Array Input
	PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();
	
	// Check already authenticated
	PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();
	// Check access rights. This may slow down server, uncomment this if you requires an extra security
	// PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_ONLY, 'record_psactual');
	
	if
	(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
			[
					'PARAM_CAT_PRODUCT_ID',
					'PARAM_DATE'
			], True
		)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------	
		    $PARAM_CAT_PRODUCT_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_CAT_PRODUCT_ID');
		    $PARAM_DATE = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_DATE');
			// ------------------------------------------------------------------
			
			// Execute Stored Procedure
			// ...........................................
			$DATA_SET = PHPCUS_RECORD_PSAPLAN::CUS_OVERVIEW
			(
			    $PARAM_CAT_PRODUCT_ID,
			    $PARAM_DATE
			);

			// Return JSON response
			// ...........................................
			if(empty($DATA_SET) === False)
			{
				PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
			}
			else
			{
				PHPCUS_PARAM::CUS_JSON_SUCCESS('');
			}
			
		}
		Catch(Exception $ERR)
		{		
			PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
			if(isset($_SERVER['HTTP_ORIGIN']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_ORIGIN', $_SERVER['HTTP_ORIGIN']);
			}
			if(isset($_SERVER['HTTP_HOST']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_HOST', $_SERVER['HTTP_HOST']);
			}		
			if(isset($_SERVER['HTTP_REFERER']))
			{
			    PHPVC_LOG::VAR_ERROR('HTTP_REFERER', $_SERVER['HTTP_REFERER']);
			}
			if(isset($_SERVER['REMOTE_ADDR']))
			{
			    PHPVC_LOG::VAR_ERROR('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
			}
			
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}

?>