Skip to content

Commit

Permalink
Merge pull request #18 from techjoomla/feat-privacy-tools
Browse files Browse the repository at this point in the history
Merge `Feat privacy tools` into Master
  • Loading branch information
manojLondhe authored Nov 15, 2018
2 parents 908310c + ce1f3a1 commit dd87083
Show file tree
Hide file tree
Showing 27 changed files with 1,590 additions and 131 deletions.
403 changes: 403 additions & 0 deletions build/bump.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/com_tjvendors/admin/controllers/vendors.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function publish()
// Publish the items.
try
{
$model->setItemState($cid, $value);
$model->setItemState($cid, $value, $client);

if ($value == 1)
{
Expand All @@ -110,6 +110,6 @@ public function publish()
}
}

$this->setRedirect('index.php?option=com_tjvendors&view=vendors&client=' . $client, $msg);
$this->setRedirect('index.php?option=com_tjvendors&view=vendors&client=' . $client);
}
}
57 changes: 9 additions & 48 deletions src/com_tjvendors/admin/helpers/tjvendors.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,20 @@ public static function getTotalAmount($vendor_id, $currency, $client)
*/
public static function bulkPendingAmount($vendor_id, $currency)
{
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjvendors/models');
$tjvendorsModelVendor = JModelLegacy::getInstance('Vendor', 'TjvendorsModel');

$vendorClients = self::getClients($vendor_id);
$bulkPendingAmount = 0;

foreach ($vendorClients as $client)
{
$pendingAmount = self::getPayableAmount($vendor_id, $client['client'], $currency);
$bulkPendingAmount = $bulkPendingAmount + $pendingAmount;
$pendingAmount = $tjvendorsModelVendor->getPayableAmount($vendor_id, $client['client'], $currency);

if (!empty($pendingAmount))
{
$bulkPendingAmount = $bulkPendingAmount + $pendingAmount[$client['client']][$currency];
}
}

return $bulkPendingAmount;
Expand Down Expand Up @@ -360,52 +367,6 @@ public static function getCurrencies($vendor_id)
return $currencies;
}

/**
* Get get vendor_id
*
* @param integer $vendor_id integer
*
* @param string $client string
*
* @param string $currency string
*
* @return integer
*/
public static function getPayableAmount($vendor_id, $client, $currency)
{
$com_params = JComponentHelper::getParams('com_tjvendors');
$payout_day_limit = $com_params->get('payout_limit_days', '0', 'INT');
$date = JFactory::getDate();
$payout_date_limit = $date->modify("-" . $payout_day_limit . " day");
$bulkPayoutStatus = $com_params->get('bulk_payout');

// Query to get the credit amount
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('SUM(' . $db->quoteName('CREDIT') . ')');
$query->where($db->quoteName('vendor_id') . ' = ' . $db->quote($vendor_id));
$query->where($db->quoteName('currency') . ' = ' . $db->quote($currency));
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
$query->where($db->quoteName('transaction_time') . ' < ' . $db->quote($payout_date_limit));
$query->from($db->quoteName('#__tjvendors_passbook'));
$db->setQuery($query);
$credit = $db->loadResult();

// Query to get debit data
$query = $db->getQuery(true);
$query->select('SUM(' . $db->quoteName('debit') . ')');
$query->from($db->quoteName('#__tjvendors_passbook'));
$query->where($db->quoteName('vendor_id') . ' = ' . $db->quote($vendor_id));
$query->where($db->quoteName('currency') . ' = ' . $db->quote($currency));
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
$query->where($db->quoteName('status') . ' = ' . $db->quote(1));
$db->setQuery($query);
$debit = $db->loadResult();
$payableAmount = $credit - $debit;

return $payableAmount;
}

/**
* Get get currencies
*
Expand Down
9 changes: 6 additions & 3 deletions src/com_tjvendors/admin/models/fields/paymentgateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ protected function getOptions()
if (!empty($client))
{
$com_params = JComponentHelper::getParams($client);
$gateways = $com_params['gateways'];
$gateways = (array) $com_params->get('gateways');

foreach ($gateways as $detail)
if (!empty($gateways))
{
$options[] = JHtml::_('select.option', $detail, $detail);
foreach ($gateways as $detail)
{
$options[] = JHtml::_('select.option', $detail, $detail);
}
}
}
else
Expand Down
11 changes: 9 additions & 2 deletions src/com_tjvendors/admin/models/payout.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public function getForm($data = array(), $loadData = true)
*/
protected function loadFormData()
{
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjvendors/models');
$tjvendorsModelVendor = JModelLegacy::getInstance('Vendor', 'TjvendorsModel');

// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_tjvendors.edit.payout.data', array());
$com_params = JComponentHelper::getParams('com_tjvendors');
Expand All @@ -113,8 +116,12 @@ protected function loadFormData()
}
else
{
$payableAmount = TjvendorsHelper::getPayableAmount($this->item->vendor_id, $this->item->client, $this->item->currency);
$this->item->total = $payableAmount;
$payableAmount = $tjvendorsModelVendor->getPayableAmount($this->item->vendor_id, $this->item->client, $this->item->currency);

if (!empty($payableAmount))
{
$this->item->total = $payableAmount[$this->item->client][$this->item->currency];
}
}

$this->item->reference_order_id = '';
Expand Down
29 changes: 19 additions & 10 deletions src/com_tjvendors/admin/models/vendorfee.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TjvendorsModelVendorFee extends JModelAdmin
*/
public function getTable($type = 'Vendorfee', $prefix = 'TjvendorsTable', $config = array())
{
$db = JFactory::getDbo();
$db = JFactory::getDbo();
$tables = $db->getTableList();

return JTable::getInstance($type, $prefix, $config);
Expand Down Expand Up @@ -96,8 +96,8 @@ public function getItem($pk = null)
$data = parent::getItem($pk);
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/models', 'vendor');
$TjvendorsModelVendor = JModelLegacy::getInstance('Vendor', 'TjvendorsModel');
$vendorDetail = $TjvendorsModelVendor->getItem();
$data->vendor_title = $vendorDetail->vendor_title;
$vendorDetail = $TjvendorsModelVendor->getItem();
$data->vendor_title = $vendorDetail->vendor_title;

return $data;
}
Expand Down Expand Up @@ -137,24 +137,33 @@ protected function loadFormData()
*/
public function save($data)
{
$table = $this->getTable();
$db = JFactory::getDbo();
$input = JFactory::getApplication()->input;
$isNew = (empty($data['id']))? true : false;
$app = JFactory::getApplication();
$table = $this->getTable();
$db = JFactory::getDbo();
$input = $app->input;
$data['vendor_id'] = $input->get('vendor_id', '', 'INTEGER');
$app = JFactory::getApplication();

$uniqueCurrency = TjvendorsHelper::checkUniqueCurrency($data['currency'], $data['vendor_id'], $data['client']);
$uniqueCurrency = TjvendorsHelper::checkUniqueCurrency($data['currency'], $data['vendor_id'], $data['client']);

if (!empty($uniqueCurrency))
{
if (parent::save($data))
{
if (empty($data['id']))
{
$data['id'] = (int) $this->getState($this->getName() . '.id');
}

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjvendors');
$dispatcher->trigger('tjVendorsOnAfterVendorFeeSave', array($data, $isNew));

return true;
}
}
else
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_TJVENDORS_VENDORFEE_DUPLICATE_CURRENCY'), 'error');
$app->enqueueMessage(JText::_('COM_TJVENDORS_VENDORFEE_DUPLICATE_CURRENCY'), 'error');
}

return false;
Expand Down
6 changes: 3 additions & 3 deletions src/com_tjvendors/admin/models/vendorfees.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ protected function populateState($ordering = null, $direction = null)
*/
protected function getListQuery()
{
$input = JFactory::getApplication()->input;
$input = JFactory::getApplication()->input;
$this->vendor_id = $input->get('vendor_id', '', 'INT');
$vendor_id = $this->vendor_id;
$client = $input->get('client', '', 'STRING');
$vendor_id = $this->vendor_id ? $this->vendor_id : $this->getState('vendor_id');
$client = $input->get('client', '', 'STRING');

// Create a new query object.
$db = $this->getDbo();
Expand Down
71 changes: 51 additions & 20 deletions src/com_tjvendors/admin/models/vendors.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function getListQuery()
$query = $db->getQuery(true);

// Create the base select statement.
$query->select('v.*, vx.approved');
$query->select('v.*, vx.approved, vx.state');
$query->from($db->quoteName('#__tjvendors_vendors', 'v'));
$query->join('LEFT', $db->quoteName('#__vendor_client_xref', 'vx') .
'ON (' . $db->quoteName('v.vendor_id') . ' = ' . $db->quoteName('vx.vendor_id') . ')');
Expand Down Expand Up @@ -204,17 +204,43 @@ public function deleteVendor($vendor_id)
*/
public function deleteClientFromVendor($vendor_id,$client)
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__vendor_client_xref'));
$query->where($db->quoteName('vendor_id') . ' = ' . $db->quote($vendor_id));
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_tjvendors/models');
$tjvendorsModelVendor = JModelLegacy::getInstance('Vendor', 'TjvendorsModel');
$tjvendorsModelVendorFees = JModelLegacy::getInstance('VendorFees', 'TjvendorsModel');
$vendorData = $tjvendorsModelVendor->getItem($vendor_id);
$db = $this->getDbo();

if (!empty($client))
// Get vendor specific Fees Data
$tjvendorsModelVendorFees->setState('vendor_id', $vendor_id);
$vendorFeeData = $tjvendorsModelVendorFees->getItems();

if (!empty($vendorFeeData))
{
foreach ($vendorFeeData as $feeData)
{
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
// Getting Vendor Payable Amount here
$result = $tjvendorsModelVendor->getPayableAmount($feeData->vendor_id, $feeData->client, $feeData->currency);

// If Vendor Payable amount is remaining then don't allow to delete vendor
if (!empty($result))
{
JFactory::getApplication()->enqueueMessage(sprintf(JText::_("COM_TJVENDORS_VENDOR_DELETE_ERROR_MESSAGE"), $vendorData->vendor_title), 'error');

return false;
}
}
}

$db->setQuery($query);
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__vendor_client_xref'));
$query->where($db->quoteName('vendor_id') . ' = ' . $db->quote($vendor_id));

if (!empty($client))
{
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
}

$db->setQuery($query);

try
{
Expand All @@ -236,39 +262,40 @@ public function deleteClientFromVendor($vendor_id,$client)
{
$this->deleteVendor($vendor_id);
}

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjvendors');
$dispatcher->trigger('tjvendorOnAfterVendorDelete', array($vendorData, $client));
}

/**
* Method To plublish and unpublish vendors
*
* @param Array $items Vendor Ids
*
* @param Integer $state State
* @param Array $items Vendor Ids
* @param Integer $state State
* @param String $client Client like com_jgive or com_jticketing
*
* @return Boolean
*
* @since 1.0
*/
public function setItemState($items, $state)
public function setItemState($items, $state, $client)
{
$db = JFactory::getDbo();
/*
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables');
$vendorObject = JTable::getInstance('vendor', 'TjvendorsTable');

JLoader::import('components.com_tjvendors.events.vendor', JPATH_SITE);
$tjvendorsTriggerVendor = new TjvendorsTriggerVendor;
*/
foreach ($items as $id)
{
JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjvendors/tables');
$tjvendorsTablevendorclientxref = JTable::getInstance('vendorclientxref', 'TjvendorsTable', array());
$tjvendorsTablevendorclientxref->load(array('vendor_id' => $id, 'client' => $client));
$updateState = new stdClass;

// Must be a valid primary key value.
$updateState->vendor_id = $id;
$updateState->id = $tjvendorsTablevendorclientxref->id;
$updateState->state = $state;

// Update their details in the users table using id as the primary key.
JFactory::getDbo()->updateObject('#__tjvendors_vendors', $updateState, 'vendor_id');
JFactory::getDbo()->updateObject('#__vendor_client_xref', $updateState, 'id');

/* Send Mail when Admin users change vendor state of vendor, these mails are not needed.. */
/*
Expand All @@ -285,6 +312,10 @@ public function setItemState($items, $state)
}
}

$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('tjvendors');
$dispatcher->trigger('tjVendorsOnAfterVendorStateChange', array($items, $state, $client));

return true;
}
}
31 changes: 24 additions & 7 deletions src/com_tjvendors/admin/views/payouts/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');

JLoader::import('vendor', JPATH_SITE . '/components/com_tjvendors/models');
$tjvendorsModelVendor = new TjvendorsModelVendor;

// Import CSS
$document = JFactory::getDocument();
$document->addStyleSheet(JUri::root() . 'administrator/components/com_tjvendors/assets/css/tjvendors.css');
Expand Down Expand Up @@ -227,16 +230,30 @@

<td>
<?php
if($this->bulkPayoutStatus==0)
if ($this->bulkPayoutStatus==0)
{

$result = TjvendorsHelper::getPayableAmount($item->vendor_id, $item->client, $item->currency);
echo $result;
$result = $tjvendorsModelVendor->getPayableAmount($item->vendor_id, $item->client, $item->currency);

if (!empty($result))
{
echo $result[$item->client][$item->currency];
}
}
else
{
$result = TjvendorsHelper::bulkPendingAmount($item->vendor_id, $item->currency);
echo $result;
$result = $tjvendorsModelVendor->getPayableAmount($item->vendor_id, '' , $item->currency);

if (!empty($result))
{
$totalPayableAmount = 0;

foreach( $result as $payment)
{
$totalPayableAmount = $totalPayableAmount + $payment[$item->currency];
}

echo $totalPayableAmount;
}
}

?>
Expand All @@ -259,7 +276,7 @@
<div class="alert alert-no-items">
<?php echo JText::_('COM_TJVENDOR_NO_MATCHING_RESULTS'); ?>
</div>
<?php
<?php
}
?>

Expand Down
Loading

0 comments on commit dd87083

Please sign in to comment.