/** * Method provides itemwise tax details. * * @param object $vars Data needed for tax plugins. * * @since 1.0 * @return null */ function tj_calculateTax($vars) { $itemTaxDetails = array(); $cartitems = $vars->cartdetails; $dis_totalamt = $vars->totalAmount; $address = $vars->addressDetails; // Load helper files $this->_TjloadTaxHelperFiles(); $itemTaxDetails = array(); $taxHelper = new taxHelper(); foreach ($cartitems as $citem) { if ($citem['item_id']) { $item_id = $citem['item_id']; // Get Current item tax details $itemTaxDetails[$item_id] = $taxHelper->getItemTax($citem['product_final_price'], $citem['item_id'], $address); } } return $itemTaxDetails; /* ItemTaxDetails will be like below * [41] => Array // 41 is item_id ( [taxdetails] => Array ( * // add tax detail here ) [taxAmount] => 1.2 )*/ }
/** * Fetch custom Element view. * * @param string $name Field Name. * @param mixed $value Field value. * @param mixed $node Field node. * @param mixed $control_name Field control_name/Id. * * @since 2.2 * @return null */ public function fetchElement($name, $value, $node, $control_name) { $db = JFactory::getDBO(); $user = JFactory::getUser(); // While edit: get profile store id $app = JFactory::getApplication(); $jinput = $app->input; $id = $jinput->get('id'); $defaultStore_id = 0; // Load tax helper. $path = JPATH_SITE . DS . "components" . DS . "com_quick2cart" . DS . 'helpers' . DS . "taxHelper.php"; if (!class_exists('taxHelper')) { JLoader::register('taxHelper', $path); JLoader::load('taxHelper'); } $taxHelper = new taxHelper(); if ($id) { $defaultStore_id = $taxHelper->getTaxProfileStoreId($id); } $storeList = $taxHelper->getStoreListForTaxprofile(); $options = array(); foreach ($storeList as $store) { $storename = ucfirst($store['title']); $options[] = JHtml::_('select.option', $store['store_id'], $storename); } $fieldName = $name; return JHtml::_('select.genericlist', $options, $fieldName, 'class="inputbox required" size="1" ', 'value', 'text', $defaultStore_id, $control_name); }
/** * Display the view */ public function display($tpl = null) { $app = JFactory::getApplication(); $jinput = $app->input; $layout = $jinput->get('layout', 'edit'); $model = $this->getModel('taxprofile'); if ($layout == 'edit') { $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); // Get taxprofile_id $taxprofile_id = $app->input->get('id', 0); // Getting saved tax rules. if (!empty($taxprofile_id)) { $this->taxrules = $model->getTaxRules($taxprofile_id); } // Get store name while edit view if (!empty($this->item->id) && !empty($this->item->store_id)) { $comquick2cartHelper = new comquick2cartHelper(); $this->storeDetails = $comquick2cartHelper->getSoreInfo($this->item->store_id); // Getting tax rates and Adress types $this->taxrate = $model->getTaxRateListSelect($this->item->store_id, ''); $this->address = $model->getAddressList(); } // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors)); } $this->addToolbar(); } else { $this->taxRule_id = $jinput->get('id'); $defaultTaxRateId = ''; $defaultAddressId = ''; // Getting saved tax rules. if (!empty($this->taxRule_id)) { $this->taxrules = $model->getTaxRules('', $this->taxRule_id); if (!empty($this->taxrules)) { $defaultTaxRateId = $this->taxrules[0]->taxrate_id; $defaultAddressId = $this->taxrules[0]->address; } // Get store id of taxrule $taxHelper = new taxHelper(); $store_id = $taxHelper->getStoreIdFromTaxrule($this->taxRule_id); if (empty($store_id)) { $this->qtcStoreNotFoundMsg(); } // Getting tax rates and Adress types $this->taxrate = $model->getTaxRateListSelect($store_id, $defaultTaxRateId); $this->address = $model->getAddressList($defaultAddressId); } } parent::display($tpl); }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { $taxHelper = new taxHelper(); // Getting user accessible store ids $storeList = $taxHelper->getStoreListForTaxprofile(); $storeIds = array(); foreach ($storeList as $store) { $storeIds[] = $store['store_id']; } $accessibleStoreIds = ''; if (!empty($storeIds)) { $accessibleStoreIds = implode(',', $storeIds); } // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->select('s.title as storeName'); $query->from('`#__kart_taxprofiles` AS a'); $query->JOIN('INNER', ' `#__kart_store` AS s ON s.id=a.store_id'); if (!empty($accessibleStoreIds)) { $query->where('(a.store_id IN (' . $accessibleStoreIds . '))'); } else { // If tax rates are not set then Dont fetch data; $query->where('a.store_id = -1'); } // Filter by published state $published = $this->getState('filter.state'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } elseif ($published === '') { $query->where('(a.state IN (0, 1))'); } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('( a.name LIKE ' . $search . ')'); } } return $query; }
public function delete($pk = null) { if ($pk) { $taxHelper = new taxHelper(); // Check whether zone is allowed to delete or not. If not the enqueue error message accordingly. $count_id = $taxHelper->isAllowedToDelTaxrate($pk); if ($count_id === true) { $this->load($pk); $result = parent::delete($pk); if ($result) { } return $result; } } return false; }
/** * Method to add tax rule against tax profile. * * @since 2.2 * @return null object of address select box. */ public function saveTaxRule($update = 0) { $app = JFactory::getApplication(); $data = $app->input->post->get('jform', array(), 'array'); $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__kart_taxrules AS r'); if ($update == 1) { // Getting profile id of tax rule id. $taxHelper = new taxHelper(); $taxprofile_id = $taxHelper->getTaxProfileId($data['taxrule_id']); $data['taxprofile_id'] = $taxprofile_id; $query->where('r.taxrule_id !=' . $db->escape($data['taxrule_id'])); } $query->where('r.taxprofile_id=' . $db->escape($data['taxprofile_id'])); $query->where('r.taxrate_id=' . $db->escape($data['taxrate_id'])); $query->where('r.address=' . $db->Quote($db->escape($data['address']))); $db->setQuery($query); $result = $db->loadResult(); if (!empty($result)) { $this->setError(JText::_('COM_QUICK2CART_TAXRULE_ALREADY_EXISTS')); return false; } $taxRule = $this->getTable('Taxrules'); if (!$taxRule->bind($data)) { $this->setError($taxRule->getError()); return false; } if (!$taxRule->check()) { $this->setError($taxRule->getError()); return false; } if (!$taxRule->store()) { $this->setError($taxRule->getError()); return false; } $app->input->set('taxrule_id', $taxRule->taxrule_id); return true; }
/** * This method provide aplicable shipping charge detail using for provided shipping method. * * @param object $vars gives billing, shipping, item_id, methodId(unique plug shipping method id) etc. * * @since 2.2 * @return Shipping charges. */ function getShipMethodChargeDetail($vars) { $shipMethDetail = $this->getShipMethodDetail($vars->shipMethId); // 1.Check method is applicable or not (Min & max amount) etc. $shipMethRateDetail = $this->getApplicableShipMethRateDetail($vars, $shipMethDetail); $ShippingCharges = 0; if ($shipMethRateDetail !== false) { $ShippingCharges = $shipMethRateDetail['shipCost'] + $shipMethRateDetail['handleCost']; } $comp_params = JComponentHelper::getParams('com_quick2cart'); $isTaxationEnabled = $comp_params->get('enableTaxtion', 0); // 2. check shipping tax charges if (!empty($shipMethDetail['taxprofileId']) && $isTaxationEnabled) { $address = new stdClass(); $address->billing_address = $vars->billing_address; $address->shipping_address = $vars->shipping_address; $address->ship_chk = $vars->ship_chk; //$itemTaxDetails[$item_id] = $taxHelper->getItemTax($citem['product_final_price'], $citem['item_id'], $address); // LOAD tax helper $path = JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'helpers' . DS . 'taxHelper.php'; if (!class_exists('productHelper')) { //require_once $path; JLoader::register('taxHelper', $path); JLoader::load('taxHelper'); } $taxHelper = new taxHelper(); $taxDetail = $taxHelper->getItemTax($ShippingCharges, $vars->cartItemDetail['item_id'], $address, $shipMethDetail['taxprofileId']); } if ($shipMethRateDetail !== false) { $shipTaxDetail = isset($taxDetail) ? $taxDetail['taxdetails'] : array(); $taxOnShipCharge = isset($taxDetail) ? $taxDetail['taxAmount'] : 0; $retData['methodId'] = $shipMethDetail['methodId']; $retData['name'] = $shipMethDetail['name']; $retData['totalShipCost'] = $ShippingCharges + $taxOnShipCharge; // This is the unique id of method's price entry id. Which will be used further to revalidate price $retData['plugMethRateId'] = $shipMethRateDetail['id']; //$shipMethDetail['rateDetail'] = $shipMethRateDetail; return $retData; } }
/** * Display the view */ public function display($tpl = null) { $comquick2cartHelper = new comquick2cartHelper(); $zoneHelper = new zoneHelper(); // Check whether view is accessible to user if (!$zoneHelper->isUserAccessible()) { return; } $app = JFactory::getApplication(); $jinput = $app->input; $user = JFactory::getUser(); $this->params = $app->getParams('com_quick2cart'); $layout = $jinput->get('layout', 'default'); $model = $this->getModel('taxprofileform'); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors)); } if ($layout == 'default') { $this->state = $this->get('State'); $this->item = $this->get('Data'); $this->form = $this->get('Form'); // Get taxprofile_id $taxprofile_id = $app->input->get('id', 0); // Getting saved tax rules. if (!empty($taxprofile_id)) { $this->taxrules = $model->getTaxRules($taxprofile_id); } // Check whether user is authorized for this zone ? if (!empty($this->item->store_id)) { $status = $comquick2cartHelper->store_authorize('taxprofileform_default', $this->item->store_id); if (!$status) { $zoneHelper->showUnauthorizedMsg(); return false; } } // Get store name while edit view if (!empty($this->item->id) && !empty($this->item->store_id)) { $comquick2cartHelper = new comquick2cartHelper(); $this->storeDetails = $comquick2cartHelper->getSoreInfo($this->item->store_id); // Getting tax rates and Adress types $this->taxrate = $model->getTaxRateListSelect($this->item->store_id, ''); $this->address = $model->getAddressList(); } // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors)); } } else { $this->taxRule_id = $jinput->get('id'); $defaultTaxRateId = ''; $defaultAddressId = ''; // Getting saved tax rules. if (!empty($this->taxRule_id)) { $this->taxrules = $model->getTaxRules('', $this->taxRule_id); if (!empty($this->taxrules)) { $defaultTaxRateId = $this->taxrules[0]->taxrate_id; $defaultAddressId = $this->taxrules[0]->address; } // Get store id of taxrule $taxHelper = new taxHelper(); $store_id = $taxHelper->getStoreIdFromTaxrule($this->taxRule_id); if (empty($store_id)) { $this->qtcStoreNotFoundMsg(); } // Getting tax rates and Adress types $this->taxrate = $model->getTaxRateListSelect($store_id, $defaultTaxRateId); $this->address = $model->getAddressList($defaultAddressId); } } $this->_prepareDocument(); parent::display($tpl); }
/** * Method provides item tax details. pass the product price and the product price and get the tax, * nternally gets the taxprofile id and get the tax * * @param float $product_price product price. * @param integer $item_id item id. * @param array $address Adress detail object * @param integer $taxprofile_id Tax profile id. * * @since 2.2 * @return null */ public function getItemTax($product_price, $item_id, $address, $taxprofile_id = '') { $taxHelper = new taxHelper(); $amount = 0; $ret['taxdetails'] = array(); if (empty($taxprofile_id)) { // Get tax profile id $taxprofile_id = $taxHelper->getProductProfileId($item_id); } // Get Application tax rate details $ItemTaxes = $taxHelper->getApplicableTaxRates($taxprofile_id, $address); // Get tax rate wise commulative total $taxRateWiseTotal = $taxHelper->getTaxRateWiseTotal($product_price, $ItemTaxes); foreach ($taxRateWiseTotal as $tax_rate) { $amount += $tax_rate['amount']; } $ret['taxAmount'] = $amount; $ret['taxdetails'] = $taxRateWiseTotal; return $ret; }
/** * Method to delete a row from the database table by primary key value. * * @param array $items An array of primary key value to delete. * * @return int Returns count of success */ public function delete($items) { $user = JFactory::getUser(); $db = JFactory::getDBO(); $query = $db->getQuery(true); $successCount = 0; $app = JFactory::getApplication(); if (is_array($items)) { $taxHelper = new taxHelper(); foreach ($items as $id) { // Check whether zone is allowed to delete or not. If not the enqueue error message accordingly. $count_id = $taxHelper->isAllowedToDelTaxrate($id); if ($count_id === true) { try { $query = $db->getQuery(true)->delete('#__kart_taxrates')->where('id =' . $id); $db->setQuery($query); if (!$db->execute()) { $this->setError($this->_db->getErrorMsg()); return $successCount; } } catch (RuntimeException $e) { $this->setError($e->getMessage()); throw new Exception($this->_db->getErrorMsg()); return $successCount; } $successCount++; } } } return $successCount; }
<?php /** * @version SVN: <svn_id> * @package Quick2cart * @author Techjoomla <*****@*****.**> * @copyright Copyright (c) 2009-2015 TechJoomla. All rights reserved. * @license GNU General Public License version 2 or later. */ // no direct access defined('_JEXEC') or die; $qtczoneShipHelper = new qtczoneShipHelper(); $comquick2cartHelper = new comquick2cartHelper(); $taxHelper = new taxHelper(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $extension_id = $jinput->get('extension_id'); $itemid = $comquick2cartHelper->getitemid('index.php?option=com_quick2cart&view=vendor&layout=cp'); ?> <script type="text/javascript"> function qtcShipSubmitAction(action) { var form = document.qtcshipform; if (action=='publish' || action=='unpublish' || action=='delete') { if (document.qtcshipform.boxchecked.value==0){ alert("<?php echo JText::_('QTC_MAKE_SEL'); ?> ");