<?php

	// 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
	PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_ONLY, 'record_po_receive_list');
	
	if
	(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
			[
					'PARAM_REC_PORECEIVE_LIST_ID',
					'PARAM_REC_PORECEIVE_LIST_REC_PORECEIVE_ID',
					'PARAM_REC_PORECEIVE_LIST_CAT_PRODUCT_ID',
					'PARAM_REC_PORECEIVE_LIST_QUANTITY_FROM',
					'PARAM_REC_PORECEIVE_LIST_QUANTITY_TO',
					'PARAM_REC_PORECEIVE_LIST_CAT_STORAGE_ID',
					'PARAM_REC_PORECEIVE_LIST_STATUS',
					
					'PARAM_ORDER_FIELD',
					'PARAM_ORDER_TYPE',
					'PARAM_SKIP',
					'PARAM_LIMIT'
			], True
		)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------	
			$PARAM_REC_PORECEIVE_LIST_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_PORECEIVE_LIST_ID');
			$PARAM_REC_PORECEIVE_LIST_REC_PORECEIVE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_PORECEIVE_LIST_REC_PORECEIVE_ID');
			$PARAM_REC_PORECEIVE_LIST_CAT_PRODUCT_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_PORECEIVE_LIST_CAT_PRODUCT_ID');
			$PARAM_REC_PORECEIVE_LIST_QUANTITY_FROM = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_PORECEIVE_LIST_QUANTITY_FROM');
			$PARAM_REC_PORECEIVE_LIST_QUANTITY_TO = PHPCUS_PARAM::CUS_READ_DECIMAL('PARAM_REC_PORECEIVE_LIST_QUANTITY_TO');
			$PARAM_REC_PORECEIVE_LIST_CAT_STORAGE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_PORECEIVE_LIST_CAT_STORAGE_ID');
			$PARAM_REC_PORECEIVE_LIST_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_PORECEIVE_LIST_STATUS');
			
			$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
			(
					'PARAM_ORDER_FIELD',
					[
						'REC_PORECEIVE_LIST_ID', 
						'REC_PORECEIVE_LIST_REC_PORECEIVE_ID', 
						'REC_PORECEIVE_LIST_CAT_PRODUCT_ID', 
						'REC_PORECEIVE_LIST_QUANTITY', 
						'REC_PORECEIVE_LIST_CAT_STORAGE_ID', 
						'REC_PORECEIVE_LIST_STATUS'
						, 
						'REC_PORECEIVE_ID',		
						'REC_PORECEIVE_REC_PORDER_ID',		
						'REC_PORECEIVE_ACC_GROUP_ID',		
						'REC_PORECEIVE_CODE',		
						'REC_PORECEIVE_DELIVERY_CODE',		
						'REC_PORECEIVE_REMARKS',		
						'REC_PORECEIVE_ACC_ACCOUNT_ID',		
						'REC_PORECEIVE_DATE',		
						'REC_PORECEIVE_STATUS',		
						'CAT_PRODUCT_ID',		
						'CAT_PRODUCT_BARCODE',		
						'CAT_PRODUCT_ITEMCODE',		
						'CAT_PRODUCT_DESCRIPTION',		
						'CAT_PRODUCT_ALIAS_MAIN',		
						'CAT_PRODUCT_ALIAS_SUB',		
						'CAT_PRODUCT_CAT_PRODTYPE_ID_LV1',		
						'CAT_PRODUCT_CAT_PRODTYPE_ID_LV2',		
						'CAT_PRODUCT_CAT_PRODTYPE_ID_LV3',		
						'CAT_PRODUCT_CAT_BRAND_ID',		
						'CAT_PRODUCT_CAT_UOM_ID',		
						'CAT_PRODUCT_CAT_DISCOUNT_ID',		
						'CAT_PRODUCT_CAT_TAXMODEL_ID',		
						'CAT_PRODUCT_AMOUNT_COST',		
						'CAT_PRODUCT_AMOUNT_PRICE',		
						'CAT_PRODUCT_AMOUNT_VAT',		
						'CAT_PRODUCT_AMOUNT_POINT',		
						'CAT_PRODUCT_ALLOW_DISCOUNT',		
						'CAT_PRODUCT_ALLOW_SENIOR',		
						'CAT_PRODUCT_IS_BASICCOM',		
						'CAT_PRODUCT_IS_SERVICE',		
						'CAT_PRODUCT_REORDER_POINT',		
						'CAT_PRODUCT_REORDER_QUANTITY',		
						'CAT_PRODUCT_CAT_PRODUCT_ID',		
						'CAT_PRODUCT_PER_PIECE_QTY',		
						'CAT_PRODUCT_CAT_SUPPLIER_ID',		
						'CAT_PRODUCT_IS_INVENTORY_ONLY',		
						'CAT_PRODUCT_IS_SERIALIZED',		
						'CAT_PRODUCT_STATUS',		
						'CAT_PRODUCT_SYSTEM_GENERATED',		
						'CAT_STORAGE_ID',		
						'CAT_STORAGE_ACC_GROUP_ID',		
						'CAT_STORAGE_DESCRIPTION',		
						'CAT_STORAGE_REMARKS',		
						'CAT_STORAGE_IS_INCORDER',		
						'CAT_STORAGE_IS_STORE',		
						'CAT_STORAGE_STATUS',		
						'CAT_STORAGE_SYSTEM_GENERATED'		
					]
			);		
			$PARAM_ORDER_TYPE = PHPCUS_PARAM::CUS_READ_SORT_TYPE('PARAM_ORDER_TYPE');
			$PARAM_SKIP	= PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SKIP');
			$PARAM_LIMIT = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_LIMIT');
			
			// ------------------------------------------------------------------
			
			
			// Populate Map Array
			// ...........................................
			$GET_MAP_ARRAY = PHPCUS_RECORD_PO_RECEIVE_LIST::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_ID'] = $PARAM_REC_PORECEIVE_LIST_ID;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_REC_PORECEIVE_ID'] = $PARAM_REC_PORECEIVE_LIST_REC_PORECEIVE_ID;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_CAT_PRODUCT_ID'] = $PARAM_REC_PORECEIVE_LIST_CAT_PRODUCT_ID;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_QUANTITY_FROM'] = $PARAM_REC_PORECEIVE_LIST_QUANTITY_FROM;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_QUANTITY_TO'] = $PARAM_REC_PORECEIVE_LIST_QUANTITY_TO;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_CAT_STORAGE_ID'] = $PARAM_REC_PORECEIVE_LIST_CAT_STORAGE_ID;
			$GET_MAP_ARRAY['PARAM_REC_PORECEIVE_LIST_STATUS'] = $PARAM_REC_PORECEIVE_LIST_STATUS;
			
			$GET_MAP_ARRAY["PARAM_ORDER_FIELD"] = $PARAM_ORDER_FIELD;
			$GET_MAP_ARRAY["PARAM_ORDER_TYPE"] = $PARAM_ORDER_TYPE;
			$GET_MAP_ARRAY["PARAM_SKIP"] = $PARAM_SKIP;
			$GET_MAP_ARRAY["PARAM_LIMIT"] = $PARAM_LIMIT;
			
			
			// Execute Stored Procedure
			// ...........................................
			$DATA_SET = PHPCUS_RECORD_PO_RECEIVE_LIST::CUS_GET_MA($GET_MAP_ARRAY);
			
						
			// 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');
	}

?>