<?php
/**
 * @package     Reporter for VirtueMart
 * 
 * @copyright   Copyright (C) 2012-2019 VirtuePlanet Services LLP. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Abhishek Das <info@virtueplanet.com> - https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

jimport('joomla.form.formfield');

JFormHelper::loadFieldClass('list');

class JFormFieldVmorder extends JFormFieldList
{
	public $type = 'Vmorder';
	
	protected function getOptions()
	{
		$options = [];
		
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);
		
		$query->select($db->quoteName(['virtuemart_order_id', 'order_number']))
			->from($db->quoteName('#__virtuemart_orders'))
			->setLimit(100, 0)
			->order($db->quoteName('virtuemart_order_id') . ' DESC');

		$db->setQuery($query);
		$orders = $db->loadObjectList();
		
		if (!empty($orders))
		{
			foreach ($orders as $order)
			{
				$options[] = JHTML::_('select.option', $order->virtuemart_order_id, htmlspecialchars($order->order_number, ENT_COMPAT, 'UTF-8', false));
			}
		}
		
		return array_merge(parent::getOptions(), $options);
	}
}