function savePricingData($post) { $response = array(); $db = JFactory::getDBO(); $session = JFactory::getSession(); require JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_socialads" . DS . "config" . DS . "config.php"; $app = JFactory::getApplication(); //.. do Back End Stuff if ($app->isAdmin()) { $ad_creator_id = $post->get('ad_creator_id'); $user = JFactory::getUser($ad_creator_id); $userid = $user->id; } else { $user = JFactory::getUser(); $userid = $user->id; } if (!$userid) { $userid = 0; return false; } $ad_id = $session->get('ad_id'); $ad_data = new stdClass(); $ad_data->ad_id = $ad_id; $ad_data->ad_startdate = $post->get('datefrom', '', 'STRING'); $ad_data->ad_payment_type = $post->get('chargeoption'); $ad_data->ad_noexpiry = $post->get('unlimited_ad', '', 'INT'); if ($ad_data->ad_noexpiry == 1) { $ad_data->ad_approved = 1; } $camp_id = ''; if ($socialads_config['select_campaign'] == 1) { $db = JFactory::getDBO(); $camp_id = $post->get('camp', '0', 'STRING'); $camp_name = $post->get('camp_name', '', 'STRING'); $camp_amount = $post->get('camp_amount', '0', 'FLOAT'); if (!$camp_id && !empty($camp_name) && !empty($camp_amount)) { $db = JFactory::getDBO(); $obj = new stdclass(); $obj->camp_id = ''; $obj->user_id = $userid; $obj->campaign = $post->get('camp_name', '', 'STRING'); $obj->daily_budget = $post->get('camp_amount', '0', 'FLOAT'); $obj->camp_published = 1; if ($obj->camp_id) { if (!$db->updateObject('#__ad_campaign', $obj, 'camp_id')) { echo $db->stderr(); return false; } } else { if (!$db->insertObject('#__ad_campaign', $obj, 'camp_id')) { echo $db->stderr(); return false; } $response['camp_id'] = $camp_id = $db->insertid(); } } $ad_data->camp_id = $camp_id; $ad_data->ad_payment_type = $post->get('pricing_opt', '', 'STRING'); if ($socialads_config['bidding'] == 1) { $ad_data->bid_value = $post->get('bid_value', '', 'STRING'); } } if (!$db->updateObject('#__ad_data', $ad_data, 'ad_id')) { echo $db->stderr(); return false; } //If campaign is selected then there is no need to place order So need to skip oreder code //If unlimited ad then there is no need to save payment info so return from here itself if ($ad_data->ad_noexpiry == 1) { //Delete Price data if already exist $db = JFactory::getDBO(); $query = " DELETE FROM `#__ad_payment_info`\n\t\t\t\t\t WHERE ad_id = " . $ad_id . " AND status ='P' "; $db->setQuery($query); $db->execute(); return true; } //NO campaign option is not selected then only place order if ($socialads_config['select_campaign'] == 0) { $paymentdata = new stdClass(); $paymentdata->id = ''; //Get ad id if ($ad_id) { $paymentdata->ad_id = $ad_id; //Get order id // @params $value,$field_name,$tableName //$orderid = $this->getIdFromAnyFieldValue($paymentdata->ad_id, 'ad_id', '#__ad_payment_info'); $db = JFactory::getDBO(); $query = " SELECT id FROM `#__ad_payment_info`\n\t\t\t\t\t\t WHERE ad_id = " . $paymentdata->ad_id . " AND status ='P' "; $db->setQuery($query); $orderid = $db->loadResult(); if ($orderid) { $paymentdata->id = $orderid; } } else { $app = JFactory::getApplication(); $app->enqueueMessage('Session Expire', 'error'); return false; } $paymentdata->cdate = date('Y-m-d H:i:s'); $paymentdata->processor = ''; $ad_chargeoption = $post->get('chargeoption', '', 'INT'); if ($ad_chargeoption >= 2) { $credits = $post->get('totaldays', '', 'INT'); } else { $credits = $post->get('totaldisplay', '', 'INT'); } $paymentdata->ad_credits_qty = $credits; //Need $paymentdata->ad_amount = $post->get('totalamount', '', 'FLOAT'); $paymentdata->ad_original_amt = $post->get('totalamount', '', 'FLOAT'); $paymentdata->status = 'P'; //Need $paymentdata->ad_coupon = ''; $paymentdata->payee_id = $userid; $paymentdata->ip_address = $_SERVER["REMOTE_ADDR"]; jimport('joomla.application.component.model'); JLoader::import('showad', JPATH_ROOT . DS . 'components' . DS . 'com_socialads' . DS . 'models'); //@ VM CHECK FOR COUPON $coupon = $post->get('sa_cop', '', 'RAW'); //JLoader::import('controller', JPATH_SITE.DS.'components'.DS.'com_socialads'); $socialadsModelShowad = new socialadsModelShowad(); $adcop = $socialadsModelShowad->getcoupon($coupon); if (!empty($adcop)) { if ($adcop[0]->val_type == 1) { $val = $adcop[0]->value / 100 * $paymentdata->ad_original_amt; } else { $val = $adcop[0]->value; } if (!empty($val)) { $paymentdata->ad_coupon = $coupon; } } else { $val = 0; } $discountedPrice = $paymentdata->ad_original_amt - $val; if ($discountedPrice <= 0) { $discountedPrice = 0; } //<!-- TAX CALCULATION--> $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('adstax'); //@TODO:need to check plugim type.. $taxresults = $dispatcher->trigger('addTax', array($discountedPrice)); //Call the plugin and get the result $appliedTax = 0; if (!empty($taxresults)) { foreach ($taxresults as $tax) { if (!empty($tax)) { $appliedTax += $tax[1]; } } } $amountAfterTax = $discountedPrice + $appliedTax; $paymentdata->ad_amount = $amountAfterTax; // if order amount is 0 due to coupon if ($paymentdata->ad_amount == 0 && !empty($paymentdata->ad_coupon)) { //$paymentdata->status = 'C'; } //@ VM CHECK FOR COUPON if (!$paymentdata->id) { if (!$db->insertObject('#__ad_payment_info', $paymentdata, 'id')) { echo $db->stderr(); return false; } } else { if (!$db->updateObject('#__ad_payment_info', $paymentdata, 'id')) { echo $db->stderr(); return false; } } } return $response; }
echo $adDetail['ad_original_amt']; ?> </td> </tr> <?php $makecal = 'makepayment();'; } ?> <?php $cop_dis = 0; if (!empty($adDetail['ad_coupon'])) { // get payment HTML JLoader::import('showad', JPATH_SITE . DS . 'components' . DS . 'com_socialads' . DS . 'models'); $showadmodel = new socialadsModelShowad(); $adcop = $showadmodel->getcoupon($adDetail['ad_coupon']); if ($adcop) { if ($adcop[0]->val_type == 1) { $cop_dis = $adcop[0]->value / 100 * $adDetail['ad_original_amt']; } else { $cop_dis = $adcop[0]->value; } } else { $cop_dis = 0; } } $discountedPrice = $adDetail['ad_original_amt'] - $cop_dis; ?> <!-- coupon discount display:block-->
/** vm:This function deduct tax amount from discounted amount and store in orders final amount * */ function syncOrderDetail($order_id) { $db = JFactory::getDBO(); $query = "SELECT a.`ad_original_amt`,a.`ad_coupon`,a.`ad_tax`,a.ad_tax_details\n\t\tFROM #__ad_payment_info AS a\n\t\tWHERE a.id= {$order_id} AND a.status != 'C'"; $db->setQuery($query); $orderData = $db->loadAssoc(); $val = 0; // for coupon discount if (!empty($orderData) && !empty($orderData['ad_coupon'])) { // get payment HTML JLoader::import('showad', JPATH_SITE . DS . 'components' . DS . 'com_socialads' . DS . 'models'); $showadmodel = new socialadsModelShowad(); $adcop = $showadmodel->getcoupon($orderData['ad_coupon']); if ($adcop) { if ($adcop[0]->val_type == 1) { $val = $adcop[0]->value / 100 * $orderData['ad_original_amt']; } else { $val = $adcop[0]->value; } } else { $val = 0; } } $discountedPrice = $orderData['ad_original_amt'] - $val; //<!-- TAX CALCULATION--> $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('adstax'); //@TODO:need to check plugim type.. $taxresults = $dispatcher->trigger('addTax', array($discountedPrice)); //Call the plugin and get the result $appliedTax = 0; if (!empty($taxresults)) { foreach ($taxresults as $tax) { if (!empty($tax)) { $appliedTax += $tax[1]; } } } $amountAfterTax = $discountedPrice + $appliedTax; if ($amountAfterTax <= 0) { $amountAfterTax = 0; } $row = new stdClass(); $row->ad_coupon = ''; if (!empty($val)) { $row->ad_coupon = $orderData['ad_coupon']; } $row->id = $order_id; $row->ad_tax_details = json_encode($taxresults); $row->ad_amount = $amountAfterTax; $row->ad_tax = $appliedTax; if (!$db->updateObject('#__ad_payment_info', $row, 'id')) { echo $this->_db->stderr(); } return $row; }