Beispiel #1
0
 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');
 }
Beispiel #2
0
$link_search_proj = JRoute::_('index.php?option=com_jblance&view=project&layout=searchproject');
$link_my_project = JRoute::_('index.php?option=com_jblance&view=project&layout=showmyproject');
$link_my_bid = JRoute::_('index.php?option=com_jblance&view=project&layout=showmybid');
$link_my_services = JRoute::_('index.php?option=com_jblance&view=service&layout=myservice');
$link_service_bght = JRoute::_('index.php?option=com_jblance&view=service&layout=servicebought');
$link_deposit = JRoute::_('index.php?option=com_jblance&view=membership&layout=depositfund');
$link_withdraw = JRoute::_('index.php?option=com_jblance&view=membership&layout=withdrawfund');
$link_escrow = JRoute::_('index.php?option=com_jblance&view=membership&layout=escrow');
$link_transaction = JRoute::_('index.php?option=com_jblance&view=membership&layout=transaction');
$link_managepay = JRoute::_('index.php?option=com_jblance&view=membership&layout=managepay');
$link_subscr_hist = JRoute::_('index.php?option=com_jblance&view=membership&layout=planhistory');
$link_buy_subscr = JRoute::_('index.php?option=com_jblance&view=membership&layout=planadd');
JblanceHelper::setJoomBriToken();
if (!JBLANCE_FREE_MODE) {
    if (!$user->guest) {
        $planStatus = JblanceHelper::planStatus($user->id);
        if ($planStatus == '1') {
            ?>
            <div class="jbbox-warning">
                <?php 
            echo JText::sprintf('COM_JBLANCE_USER_SUBSCRIPTION_EXPIRED', $link_buy_subscr);
            ?>
            </div>
        <?php 
        } elseif ($planStatus == '2') {
            ?>
            <div class="jbbox-info">
                <?php 
            echo JText::sprintf('COM_JBLANCE_USER_DONT_HAVE_ACTIVE_PLAN', $link_subscr_hist);
            ?>
            </div>
Beispiel #3
0
 function getEditService()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $id = $app->input->get('id', 0, 'int');
     $user = JFactory::getUser();
     $isNew = $id > 0 ? false : true;
     //check if the owner is editing the service
     $isOwnedOperation = JblanceHelper::checkOwnershipOfOperation($id, 'service');
     if ($id > 0 && !$isOwnedOperation) {
         $msg = JText::sprintf('COM_JBLANCE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE');
         $app->enqueueMessage($msg, 'error');
         $link = JRoute::_('index.php?option=com_jblance&view=user&layout=dashboard', false);
         $app->redirect($link);
         return false;
     }
     //check if the user's plan is expired or not approved. If so, do not allow him to create service
     $planStatus = JblanceHelper::planStatus($user->id);
     if ($isNew && ($planStatus == 1 || $planStatus == 2)) {
         $msg = JText::sprintf('COM_JBLANCE_NOT_ALLOWED_TO_DO_OPERATION_NO_ACTIVE_SUBSCRIPTION');
         $app->enqueueMessage($msg, 'error');
         $link = JRoute::_('index.php?option=com_jblance&view=user&layout=dashboard', false);
         $app->redirect($link);
         return false;
     }
     //check if the user has enough fund to create new services. This should be checked for new services only
     $plan = JblanceHelper::whichPlan($user->id);
     $chargePerService = $plan->flChargePerService;
     if ($isNew && $chargePerService > 0) {
         $totalFund = JblanceHelper::getTotalFund($user->id);
         if ($totalFund < $chargePerService) {
             $msg = JText::sprintf('COM_JBLANCE_BALANCE_INSUFFICIENT_TO_POST_SERVICE', JblanceHelper::formatCurrency($chargePerService));
             $app->enqueueMessage($msg, 'error');
             $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=depositfund', false);
             $app->redirect($link);
             return false;
         }
     }
     $row = JTable::getInstance('service', 'Table');
     $row->load($id);
     //show reason if service is not approved.
     if (!$isNew && !$row->approved) {
         $msg = empty($row->disapprove_reason) ? JText::_('COM_JBLANCE_SERVICE_PENDING_APPROVAL_FROM_ADMIN') : $row->disapprove_reason;
         $app->enqueueMessage(nl2br($msg), 'Error');
     }
     $return[0] = $row;
     return $return;
 }
Beispiel #4
0
 function getPlaceBid()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $id = $app->input->get('id', 0, 'int');
     //id is the "project id"
     $finance = JblanceHelper::get('helper.finance');
     // create an instance of the class FinanceHelper
     $project = JTable::getInstance('project', 'Table');
     $project->load($id);
     // Project author is allowed to bid on his own project
     if ($project->publisher_userid == $user->id) {
         $msg = JText::sprintf('COM_JBLANCE_NOT_ALLOWED_TO_BID_ON_YOUR_OWN_PROJECT');
         $link = JRoute::_('index.php?option=com_jblance&view=user&layout=dashboard', false);
         $app->enqueueMessage($msg, 'error');
         $app->redirect($link);
         return false;
     }
     //project in Frozen/Closed should not be allowed to bid
     if ($project->status != 'COM_JBLANCE_OPEN') {
         $link = JRoute::_('index.php?option=com_jblance&view=project&layout=listproject', false);
         $app->redirect($link);
         return;
     }
     //redirect to dashboard if this is private invite project
     if ($project->is_private_invite) {
         $invite_ids = explode(',', $project->invite_user_id);
         if (!in_array($user->id, $invite_ids)) {
             $msg = JText::_('COM_JBLANCE_THIS_IS_A_PRIVATE_INVITE_PROJECT_VISIBLE_TO_OWNER_INVITEES');
             $link_dash = JRoute::_('index.php?option=com_jblance&view=user&layout=dashboard', false);
             $app->enqueueMessage($msg, 'error');
             $app->redirect($link_dash);
         }
     }
     //get the bid id
     $query = "SELECT id FROM #__jblance_bid WHERE project_id=" . $db->quote($id) . " AND user_id=" . $db->quote($user->id);
     $db->setQuery($query);
     $bid_id = $db->loadResult();
     $bid = JTable::getInstance('bid', 'Table');
     $bid->load($bid_id);
     //check if the user's plan is expired or not approved. If so, do not allow him to bid new on project
     $planStatus = JblanceHelper::planStatus($user->id);
     if (empty($bid_id) && ($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);
         $app->enqueueMessage($msg, 'error');
         $app->redirect($link);
         return false;
     }
     //check if the user has enough fund to bid new on projects. This should be checked for new bids only
     $plan = JblanceHelper::whichPlan($user->id);
     $chargePerBid = $plan->flChargePerBid;
     if ($chargePerBid > 0 && empty($bid_id)) {
         // bid_id will be empty for new bids
         $totalFund = JblanceHelper::getTotalFund($user->id);
         if ($totalFund < $chargePerBid) {
             $msg = JText::sprintf('COM_JBLANCE_BALANCE_INSUFFICIENT_TO_BID_PROJECT', JblanceHelper::formatCurrency($chargePerBid));
             $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=depositfund', false);
             $app->enqueueMessage($msg, 'error');
             $app->redirect($link);
             return false;
         }
     }
     //check if the user has any bid limit. If any and exceeds, then disallow him
     $lastSubscr = $finance->getLastSubscription($user->id);
     if (empty($bid_id) && ($lastSubscr->bids_allowed > 0 && $lastSubscr->bids_left <= 0)) {
         $msg = JText::sprintf('COM_JBLANCE_NOT_ALLOWED_TO_BID_PROJECT_LIMIT_EXCEEDED');
         $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=planadd', false);
         $app->enqueueMessage($msg, 'error');
         $app->redirect($link);
         return false;
     }
     $return[0] = $project;
     $return[1] = $bid;
     return $return;
 }