<?php
/**
 * @version     1.4.7
 * @package     sellacious
 *
 * @copyright   Copyright (C) 2012-2017 Bhartiy Web Technologies. All rights reserved.
 * @license     SPL Sellacious Private License; see http://www.sellacious.com/spl.html
 * @author      Izhar Aazmi <info@bhartiy.com> - http://www.bhartiy.com
 */
// no direct access
defined('_JEXEC') or die;

/** @var  SellaciousViewUsers $this */
JHtml::_('stylesheet', 'com_sellacious/view.users.css', null, true);

$profile_type = $this->state->get('filter.profile_type');
$listOrder    = $this->escape($this->state->get('list.ordering'));
$listDirn     = $this->escape($this->state->get('list.direction'));
$ordering     = ($listOrder == 'a.ordering');
$saveOrder    = ($listOrder == 'a.ordering' && strtolower($listDirn) == 'asc');

$gc = $this->helper->currency->getGlobal('code_3');
$uc = $this->helper->currency->forUser(null, 'code_3');

foreach ($this->items as $i => $item) :
	$canEdit   = $this->helper->access->check('user.edit', $item->id);
	$canChange = $this->helper->access->check('user.edit.state', $item->id);
	?>
	<tr role="row">
		<td class="nowrap center hidden-phone">
			<label>
				<input type="checkbox" name="cid[]" id="cb<?php echo $i ?>" class="checkbox style-0"
					   value="<?php echo $item->id ?>" onclick="Joomla.isChecked(this.checked);"
					<?php echo ($canEdit || $canChange) ? '' : ' disabled="disabled"' ?> />
				<span></span>
			</label>
		</td>
		<td class="nowrap center">
			<span class="btn-round"><?php echo JHtml::_('jgrid.published', !$item->state, $i, 'users.', $canChange);?></span>
		</td>
		<td class="nowrap">
			<?php if ($canEdit) : ?>
				<a href="<?php echo JRoute::_('index.php?option=com_sellacious&task=user.edit&id=' . (int)$item->id); ?>">
					<?php echo $this->escape($item->name); ?></a>
			<?php else : ?>
				<?php echo $this->escape($item->name); ?>
			<?php endif; ?>
		</td>

		<?php if ($profile_type == 'mfr') : ?>
		<td class="nowrap">
			<?php echo $this->escape($item->mfr_company); ?>
		</td>
		<?php endif; ?>

		<?php if ($profile_type == 'seller') : ?>
		<td class="nowrap">
			<?php echo $this->escape($item->seller_company); ?>
		</td>
		<?php endif; ?>

		<td class="nowrap">
			<?php echo $this->escape($item->username); ?>
		</td>

		<?php if ($profile_type != '') : ?>
			<td class="nowrap">
				<?php echo $this->escape($item->email); ?>
			</td>
			<td class="nowrap">
				<?php echo $this->escape($item->mobile); ?>
			</td>
		<?php endif; ?>


		<?php if ($profile_type == 'client' || $profile_type == '') : ?>
			<td class="nowrap">
				<?php echo $this->escape($item->client_category_name); ?>
			</td>
		<?php endif; ?>

		<?php if ($profile_type == 'mfr' || $profile_type == '') : ?>
			<td class="nowrap">
				<?php echo $this->escape($item->mfr_category_name); ?>
			</td>
		<?php endif; ?>

		<?php if ($profile_type == 'staff' || $profile_type == '') : ?>
			<td class="nowrap">
				<?php echo $this->escape($item->staff_category_name); ?>
			</td>
		<?php endif; ?>

		<?php if ($profile_type == 'seller' || $profile_type == '') : ?>
			<td class="nowrap">
				<?php echo $this->escape($item->seller_category_name); ?>
			</td>
			<td class="nowrap rating-stars" style="width: 80px">
				<?php
				$rating = $this->helper->rating->getProductRating($item->id);
				echo $rating ? $this->helper->core->getStars($rating->rating)	: 'NA';
				?>
			</td>
		<?php endif; ?>

		<?php if ($profile_type == 'client'): ?>
			<td class="center nowrap">
				<?php
				$filter = array('list.select' => 'count(1)', 'customer_uid' => $item->id);
				$oCount = $this->helper->order->loadResult($filter);
				echo $oCount;
				?>
			</td>
			<td class="text-right nowrap">
				<?php
				if ($oCount):
					$filter = array('list.select' => 'SUM(a.grand_total)', 'customer_uid' => $item->id);
					$amount = $this->helper->order->loadResult($filter);
					$amount = $this->helper->currency->display($amount, $gc, $uc);
					echo $amount;
				endif;
				?>
			</td>
		<?php endif; ?>

		<td class="center hidden-phone">
			<span><?php echo (int) $item->id; ?></span>
		</td>
	</tr>
<?php
endforeach;
