function placeOrder() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $post = $app->input->post->getArray(); $row = JTable::getInstance('serviceorder', 'Table'); $now = JFactory::getDate(); $user = JFactory::getUser(); $service_id = $app->input->get('service_id', 0, 'int'); // id of service $svcHelper = JblanceHelper::get('helper.service'); // create an instance of the class ServiceHelper $service = JTable::getInstance('service', 'Table'); $userType = JblanceHelper::getUserType($user->id); //get the current user type $escrow = JTable::getInstance('escrow', 'Table'); $service->load($service_id); $isMine = $service->user_id == $user->id; // check if the user is guest if ($user->guest) { //return to same page after login $returnUrl = JRoute::_('index.php?option=com_jblance&view=service&layout=viewservice&id=' . $service_id, false); $msg = JText::_('COM_JBLANCE_MUST_BE_LOGGED_IN_TO_ACCESS_THIS_PAGE'); $link_login = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl), false); $this->setRedirect($link_login, $msg, 'warning'); } // check if the user doesn't have JoomBri Profile - or he is just a Joomla user if ($userType->joomlauser) { $msg = JText::_('COM_JBLANCE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE_CHOOSE_YOUR_ROLE'); $link = JRoute::_('index.php?option=com_jblance&view=guest&layout=showfront', false); $this->setRedirect($link, $msg, 'error'); return false; } // check if the user is a freelancer or service owner if ($isMine || !$userType->buyer) { $msg = JText::_('COM_JBLANCE_NOT_ALLOWED_TO_ORDER_SERVICE'); $link = JRoute::_('index.php?option=com_jblance&view=service&layout=viewservice&id=' . $service_id, false); $this->setRedirect($link, $msg, 'error'); return false; } //check if the user's plan is expired or not approved. If so, do not allow him to order service $planStatus = JblanceHelper::planStatus($user->id); if ($planStatus == 1 || $planStatus == 2) { $msg = JText::sprintf('COM_JBLANCE_NOT_ALLOWED_TO_DO_OPERATION_NO_ACTIVE_SUBSCRIPTION'); $link = JRoute::_('index.php?option=com_jblance&view=user&layout=dashboard', false); $this->setRedirect($link, $msg, 'error'); return false; } $post['user_id'] = $user->id; $post['status'] = 'COM_JBLANCE_ACCEPTED'; $post['order_date'] = $now->toSql(); //process extra add-ons $extras = $app->input->get('extras', null, 'array'); $registry = new JRegistry(); $registry->loadArray($extras); $post['extras'] = $registry->toString(); //calculate the total amount and duration as they could have been tampered $return = $svcHelper->calculateServiceTotalPrice($service_id, $extras); $post['price'] = $return['totalPrice']; $post['duration'] = $return['totalDuration']; //check if the buyer has enough money to buy the service $totalFund = JblanceHelper::getTotalFund($user->id); if ($totalFund < $return['totalPrice']) { $msg = JText::sprintf('COM_JBLANCE_BALANCE_INSUFFICIENT_TO_BUY_SERVICE', JblanceHelper::formatCurrency($return['totalPrice'])); $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=depositfund', false); $this->setRedirect($link, $msg, 'error'); return false; } if (!$row->save($post)) { throw new Exception($row->getError(), 500); } //deduct the amount from buyer and credit the seller after less service fee $plan = JblanceHelper::whichPlan($service->user_id); //get the plan details of the seller to get the service fee $serviceFee = $plan->flFeePercentPerService; //service fee in percent //deduct buyer $transDtl = JText::_('COM_JBLANCE_SERVICE_ORDER') . ' - ' . $service->service_title; $trans_buyer = JblanceHelper::updateTransaction($user->id, $transDtl, $return['totalPrice'], -1); $msg_debit = JText::sprintf('COM_JBLANCE_YOUR_ACCOUNT_DEBITED_WITH_CURRENCY_FOR_BUYING_SERVICE', JblanceHelper::formatCurrency($return['totalPrice'])); $app->enqueueMessage($msg_debit); $app->enqueueMessage(JText::_('COM_JBLANCE_RELEASE_PAYMENT_WHEN_SATISFIED')); //calculate the escrow amount (less service fee) $amountToCredit = $return['totalPrice'] - round($serviceFee / 100 * $return['totalPrice'], 2); //save to escrow table $escrow->from_id = $user->id; $escrow->to_id = $service->user_id; $escrow->date_transfer = $now->toSql(); $escrow->note = ''; $escrow->amount = $amountToCredit; $escrow->project_id = $row->id; //this has to be service order id instead of service id. Changed since v1.7 $escrow->type = 'COM_JBLANCE_SERVICE'; $escrow->from_trans_id = $trans_buyer->id; if (!$escrow->store()) { JError::raiseError(500, $escrow->getError()); } $escrow->checkin(); //send service order notification to seller $jbmail = JblanceHelper::get('helper.email'); // create an instance of the class EmailHelper $jbmail->sendServiceOrderNotification($row->id, $service_id); $msg = JText::_('COM_JBLANCE_SERVICE_ORDER_PLACED_SUCCESSFULLY') . ' : ' . $service->service_title; $return = JRoute::_('index.php?option=com_jblance&view=service&layout=servicebought', false); $this->setRedirect($return, $msg, 'message'); }
defined('_JEXEC') or die('Restricted access'); JHtml::_('jquery.framework'); JHtml::_('bootstrap.framework'); JHtml::_('bootstrap.carousel'); $user = JFactory::getUser(); $model = $this->getModel(); $config = JblanceHelper::getConfig(); $currencysym = $config->currencySymbol; $showUsername = $config->showUsername; $enableAddThis = $config->enableAddThis; $addThisPubid = $config->addThisPubid; $row = $this->row; $nameOrUsername = $showUsername ? 'username' : 'name'; $isMine = $row->user_id == $user->id; $sellerInfo = JFactory::getUser($row->user_id); $userType = JblanceHelper::getUserType($user->id); $link_edit = JRoute::_('index.php?option=com_jblance&view=service&layout=editservice&id=' . $row->id); ?> <script type="text/javascript"> <!-- jQuery(document).ready(function ($) { $("input.service-extra-checkbox").on("click", updateOrderAmount); }); var updateOrderAmount = function (e) { var finalTotal = parseFloat(jQuery("#finaltotal").val()); var finalDuration = parseFloat(jQuery("#finalduration").val()); var baseDuration = parseFloat(jQuery("#finalduration").data("base-duration")); if (this.checked) {
function pendingActions($userid) { $db = JFactory::getDbo(); $config = JblanceHelper::getConfig(); $enableEscrowPayment = $config->enableEscrowPayment; $result = array(); $userType = JblanceHelper::getUserType($userid); $link_my_bid = JRoute::_('index.php?option=com_jblance&view=project&layout=showmybid'); $link_my_project = JRoute::_('index.php?option=com_jblance&view=project&layout=showmyproject'); $link_project_list = JRoute::_('index.php?option=com_jblance&view=project&layout=listproject'); $link_my_service = JRoute::_('index.php?option=com_jblance&view=service&layout=myservice'); $link_svc_bought = JRoute::_('index.php?option=com_jblance&view=service&layout=servicebought'); $link_svc_sold = JRoute::_('index.php?option=com_jblance&view=service&layout=servicesold'); $link_managepay = JRoute::_('index.php?option=com_jblance&view=membership&layout=managepay'); //get no of bid offers $query = "SELECT COUNT(*) FROM #__jblance_project p " . "LEFT JOIN #__jblance_bid b ON p.id=b.project_id " . "WHERE b.user_id=" . $db->quote($userid) . " AND p.assigned_userid=" . $db->quote($userid) . " AND b.status=" . $db->quote(''); $db->setQuery($query); $bid_offers = $db->loadResult(); if ($bid_offers > 0) { $link = JHtml::_('link', $link_my_bid, '<i class="material-icons">pageview</i>', array()); $result['bid_offers'] = JText::sprintf('COM_JBLANCE_PENDING_X_BID_OFFERS_REQUIRING_ACTION', '<b>' . $bid_offers . '</b>') . ' ' . $link; } //get no of bids and projects $query = "SELECT p.id, COUNT(b.id) bidcount FROM #__jblance_project p " . "INNER JOIN #__jblance_bid b ON p.id=b.project_id " . "WHERE p.publisher_userid=" . $db->quote($userid) . " AND p.status=" . $db->quote('COM_JBLANCE_OPEN') . " " . "GROUP BY p.id"; //echo $query; $db->setQuery($query); $projects = $db->loadObjectList(); $tot_proj = count($projects); $tot_bids = 0; foreach ($projects as $project) { $tot_bids += $project->bidcount; } if ($tot_proj > 0) { $link = JHtml::_('link', $link_my_project, '<i class="material-icons">pageview</i>', array()); $result['project_bids'] = JText::sprintf('COM_JBLANCE_PENDING_X_BIDS_FROM_Y_PROJECTS_REQUIRING_ACTION', '<b>' . $tot_bids . '</b>', '<b>' . $tot_proj . '</b>') . ' ' . $link; } // get no of invited projects $query = "SELECT COUNT(*) FROM #__jblance_project p " . "LEFT JOIN #__jblance_bid b ON p.id=b.project_id " . "WHERE p.status='COM_JBLANCE_OPEN' AND FIND_IN_SET(" . $db->quote($userid) . ", p.invite_user_id) AND b.id IS NULL"; $db->setQuery($query); $invites = $db->loadResult(); if ($invites > 0) { $link = JHtml::_('link', $link_project_list, '<i class="material-icons">pageview</i>', array()); $result['invites'] = JText::sprintf('COM_JBLANCE_PENDING_X_PROJECT_INVITATION_REQUIRING_ACTION', '<b>' . $invites . '</b>') . ' ' . $link; } //get services yet to be started $query = "SELECT COUNT(*) FROM #__jblance_service_order so " . "LEFT JOIN #__jblance_service s ON so.service_id=s.id " . "WHERE s.user_id=" . $db->quote($userid) . " AND so.p_status = ''"; $db->setQuery($query); $service_not_started = $db->loadResult(); if ($service_not_started > 0) { $link = JHtml::_('link', $link_my_service, '<i class="material-icons">pageview</i>', array()); $result['service_not_started'] = JText::sprintf('COM_JBLANCE_PENDING_X_SERVICES_YET_TO_START', '<b>' . $service_not_started . '</b>') . ' ' . $link; } //get services in progress $query = "SELECT COUNT(*) FROM #__jblance_service_order so " . "LEFT JOIN #__jblance_service s ON so.service_id=s.id " . "WHERE s.user_id=" . $db->quote($userid) . " AND (so.p_status = 'COM_JBLANCE_INITIATED' OR so.p_status = 'COM_JBLANCE_IN_PROGRESS')"; $db->setQuery($query); $service_in_progress = $db->loadResult(); if ($service_in_progress > 0) { $link = JHtml::_('link', $link_my_service, '<i class="material-icons">pageview</i>', array()); $result['service_in_progress'] = JText::sprintf('COM_JBLANCE_PENDING_X_SERVICES_IN_PROGRESS', '<b>' . $service_in_progress . '</b>') . ' ' . $link; } //get pending rating for project and service if ($userType->freelancer) { // for project $query = "SELECT COUNT(*) FROM #__jblance_project p " . "LEFT JOIN #__jblance_bid b ON b.project_id=p.id " . "WHERE p.assigned_userid=" . $db->quote($userid) . " AND b.p_status='COM_JBLANCE_COMPLETED' AND " . "p.id NOT IN (SELECT project_id FROM #__jblance_rating r where r.actor=" . $db->quote($userid) . " and r.type='COM_JBLANCE_PROJECT')"; $db->setQuery($query); $seller_rating = $db->loadResult(); if ($seller_rating > 0) { $link = JHtml::_('link', $link_my_bid, '<i class="material-icons">pageview</i>', array()); $result['rating-project'] = JText::sprintf('COM_JBLANCE_PENDING_X_USERS_RATE_BID_REQUIRING_ACTION', '<b>' . $seller_rating . '</b>') . ' ' . $link; } // for service $query = "SELECT COUNT(*) FROM #__jblance_service s " . "LEFT JOIN #__jblance_service_order so ON s.id=so.service_id " . "WHERE s.user_id=" . $db->quote($userid) . " AND p_status='COM_JBLANCE_COMPLETED' AND " . "so.id NOT IN (SELECT project_id FROM #__jblance_rating r WHERE r.actor=" . $db->quote($userid) . " AND r.type='COM_JBLANCE_SERVICE')"; $db->setQuery($query); $seller_rating = $db->loadResult(); if ($seller_rating > 0) { $link = JHtml::_('link', $link_svc_sold, '<i class="material-icons">pageview</i>', array()); $result['rating-service'] = JText::sprintf('COM_JBLANCE_PENDING_X_USERS_RATE_SERVICE_SOLD_REQUIRING_ACTION', '<b>' . $seller_rating . '</b>') . ' ' . $link; } } elseif ($userType->buyer) { // for project $query = "SELECT COUNT(*) FROM #__jblance_project p " . "LEFT JOIN #__jblance_bid b ON b.project_id=p.id " . "WHERE p.publisher_userid=" . $db->quote($userid) . " AND b.p_status='COM_JBLANCE_COMPLETED' AND " . "p.id NOT IN (SELECT project_id FROM #__jblance_rating r where r.actor=" . $db->quote($userid) . " and r.type='COM_JBLANCE_PROJECT')"; $db->setQuery($query); $buyer_rating = $db->loadResult(); if ($buyer_rating > 0) { $link = JHtml::_('link', $link_my_project, '<i class="material-icons">pageview</i>', array()); $result['rating-project'] = JText::sprintf('COM_JBLANCE_PENDING_X_USERS_RATE_PROJECT_REQUIRING_ACTION', '<b>' . $buyer_rating . '</b>') . ' ' . $link; } // for service $query = "SELECT COUNT(*) FROM #__jblance_service_order so " . "WHERE so.user_id=" . $db->quote($userid) . " AND p_status='COM_JBLANCE_COMPLETED' AND " . "so.id NOT IN (SELECT project_id FROM #__jblance_rating r WHERE r.actor=" . $db->quote($userid) . " and r.type='COM_JBLANCE_SERVICE')"; $db->setQuery($query); $buyer_rating = $db->loadResult(); if ($buyer_rating > 0) { $link = JHtml::_('link', $link_svc_bought, '<i class="material-icons">pageview</i>', array()); $result['rating-service'] = JText::sprintf('COM_JBLANCE_PENDING_X_USERS_RATE_SERVICE_BOUGHT_REQUIRING_ACTION', '<b>' . $buyer_rating . '</b>') . ' ' . $link; } } //check if escrow payment is enabled? if ($enableEscrowPayment) { //get pending payments $query = "SELECT COUNT(*) FROM #__jblance_project p " . "WHERE p.publisher_userid=" . $db->quote($userid) . " AND p.status=" . $db->quote('COM_JBLANCE_CLOSED') . " AND p.paid_status <> " . $db->quote('COM_JBLANCE_PYMT_COMPLETE'); $db->setQuery($query); $payment = $db->loadResult(); if ($payment > 0) { $link = JHtml::_('link', $link_my_project, '<i class="material-icons">pageview</i>', array()); $result['payment'] = JText::sprintf('COM_JBLANCE_PENDING_X_PAYMENTS_REQUIRING_ACTION', '<b>' . $payment . '</b>') . ' ' . $link; } //pending incoming escrows $query = "SELECT COUNT(*) FROM #__jblance_escrow e " . "WHERE e.to_id= " . $db->quote($userid) . " AND e.status=" . $db->quote('COM_JBLANCE_RELEASED'); $db->setQuery($query); $in_escrow = $db->loadResult(); if ($in_escrow > 0) { $link = JHtml::_('link', $link_managepay, '<i class="material-icons">pageview</i>', array()); $result['in_escrow'] = JText::sprintf('COM_JBLANCE_PENDING_X_INCOMING_ESCROW_PAYMENTS_REQUIRING_ACTION', '<b>' . $in_escrow . '</b>') . ' ' . $link; } //pending outgoing escrows $query = "SELECT COUNT(*) FROM #__jblance_escrow e " . "WHERE e.from_id= " . $db->quote($userid) . " AND e.status=" . $db->quote(''); $db->setQuery($query); $out_escrow = $db->loadResult(); if ($out_escrow > 0) { $link = JHtml::_('link', $link_managepay, '<i class="material-icons">pageview</i>', array()); $result['out_escrow'] = JText::sprintf('COM_JBLANCE_PENDING_X_OUTGOING_ESCROW_PAYMENTS_REQUIRING_ACTION', '<b>' . $out_escrow . '</b>') . ' ' . $link; } } return $result; }