示例#1
0
 function acceptEscrow()
 {
     // Check for request forgeries
     JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $id = $app->input->get('id', 0, 'int');
     $escrow = JTable::getInstance('escrow', 'Table');
     $escrow->load($id);
     $type = $escrow->type;
     //if the status is accepted, then return false. This is done to avoid multiple account credits
     if ($escrow->status == 'COM_JBLANCE_ACCEPTED') {
         $msg = JText::_('COM_JBLANCE_ESCROW_PAYMENT_ACCEPTED_SUCCESSFULLY');
         $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=managepay', false);
         $this->setRedirect($link, $msg);
         return false;
     }
     $now = JFactory::getDate();
     $escrow->date_accept = $now->toSql();
     $escrow->status = 'COM_JBLANCE_ACCEPTED';
     if (!$escrow->check()) {
         JError::raiseError(500, $escrow->getError());
     }
     if (!$escrow->store()) {
         JError::raiseError(500, $escrow->getError());
     }
     $escrow->checkin();
     $senderInfo = JFactory::getUser($escrow->from_id);
     //get the sender info from the sender userid
     $project_id = $escrow->project_id;
     //update the paid_status in project table, if the type=project
     if ($type == 'COM_JBLANCE_PROJECT') {
         //get the sum of amount already paid for the project
         $query = "SELECT ROUND(SUM(amount),2) AS amt FROM #__jblance_escrow " . "WHERE project_id=" . $db->quote($project_id) . " AND status=" . $db->quote('COM_JBLANCE_ACCEPTED') . " AND type=" . $db->quote('COM_JBLANCE_PROJECT');
         $db->setQuery($query);
         $sum = $db->loadResult();
         //echo $query;
         $project = JTable::getInstance('project', 'Table');
         $project->load($project_id);
         $project->paid_amt = $sum;
         //get the bid amount of the project
         $projHelp = JblanceHelper::get('helper.project');
         // create an instance of the class ProjectHelper
         $bidamount = $projHelp->getBidAmt($project_id);
         if ($project->project_type == 'COM_JBLANCE_FIXED') {
             //calculate the project fee for buyer & freelancer and debit him when the payment is complete
             if ($sum == $bidamount) {
                 $project->paid_status = 'COM_JBLANCE_PYMT_COMPLETE';
                 $fee_from_buyer = $projHelp->calculateProjectFee($project->publisher_userid, $bidamount, 'buyer', 'COM_JBLANCE_FIXED');
                 $transDtl = JText::sprintf('COM_JBLANCE_PROJECT_COMMISSION_FOR_PROJECT_NAME', $project->project_title);
                 JblanceHelper::updateTransaction($project->publisher_userid, $transDtl, $fee_from_buyer, -1);
                 //update transaction table for freelancer
                 $fee_from_lancer = $projHelp->calculateProjectFee($project->assigned_userid, $bidamount, 'freelancer', 'COM_JBLANCE_FIXED');
                 $transDtl = JText::sprintf('COM_JBLANCE_PROJECT_COMMISSION_FOR_PROJECT_NAME', $project->project_title);
                 JblanceHelper::updateTransaction($project->assigned_userid, $transDtl, $fee_from_lancer, -1);
                 //update the profit of the project
                 $project->profit = $fee_from_buyer + $fee_from_lancer;
                 //update the buyer & freelancer commission
                 $project->buyer_commission = $fee_from_buyer;
                 $project->lancer_commission = $fee_from_lancer;
             } elseif ($sum < $bidamount) {
                 $project->paid_status = 'COM_JBLANCE_PYMT_PARTIAL';
             }
         } elseif ($project->project_type == 'COM_JBLANCE_HOURLY') {
             //calculate the project fee for buyer and debit him [ONLY FOR HOURLY PROJECT TYPE - FOR FIXED PROJECTS DEBIT COMMISSION WHEN PROJECT IS ACCEPTED BY FREELANCER]
             $fee_from_buyer = $projHelp->calculateProjectFee($project->publisher_userid, $escrow->amount, 'buyer', 'COM_JBLANCE_HOURLY');
             $transDtl = JText::sprintf('COM_JBLANCE_PROJECT_COMMISSION_FOR_PROJECT_NAME', $project->project_title);
             JblanceHelper::updateTransaction($project->publisher_userid, $transDtl, $fee_from_buyer, -1);
             //update transaction table for freelancer
             $fee_from_lancer = $projHelp->calculateProjectFee($project->assigned_userid, $escrow->amount, 'freelancer', 'COM_JBLANCE_HOURLY');
             $transDtl = JText::sprintf('COM_JBLANCE_PROJECT_COMMISSION_FOR_PROJECT_NAME', $project->project_title);
             JblanceHelper::updateTransaction($project->assigned_userid, $transDtl, $fee_from_lancer, -1);
             //update the profit of the project
             $project->profit = $project->profit + ($fee_from_buyer + $fee_from_lancer);
             //update the buyer & freelancer commission
             $project->buyer_commission += $fee_from_buyer;
             $project->lancer_commission += $fee_from_lancer;
             //assume that some amount is paid setting the payment status to 'partial'
             $project->paid_status = 'COM_JBLANCE_PYMT_PARTIAL';
         }
         if (!$project->check()) {
             JError::raiseError(500, $project->getError());
         }
         if (!$project->store()) {
             JError::raiseError(500, $project->getError());
         }
         $project->checkin();
         $transDtl_receiver = JText::sprintf('COM_JBLANCE_ESCROW_PAYMENT_FROM_FOR_PROJECT', $senderInfo->username, $project->project_title);
     } elseif ($type == 'COM_JBLANCE_SERVICE') {
         $service = JTable::getInstance('service', 'Table');
         $service->load($project_id);
         $transDtl_receiver = JText::_('COM_JBLANCE_SERVICE_ORDER') . ' - ' . $service->service_title;
     } elseif ($type == 'COM_JBLANCE_OTHER') {
         $transDtl_receiver = JText::sprintf('COM_JBLANCE_ESCROW_PAYMENT_FROM', $senderInfo->username);
     }
     //credit the recipient
     $row_trans = JblanceHelper::updateTransaction($escrow->to_id, $transDtl_receiver, $escrow->amount, 1);
     //update escrow table with the trans id
     $escrow->to_trans_id = $row_trans->id;
     if (!$escrow->store()) {
         JError::raiseError(500, $escrow->getError());
     }
     $escrow->checkin();
     //send escrow pymt accepted to sender
     $jbmail = JblanceHelper::get('helper.email');
     // create an instance of the class EmailHelper
     $jbmail->sendEscrowPaymentAccepted($escrow->id);
     //Trigger the plugin event to feed the activity - buyer pick freelancer
     JPluginHelper::importPlugin('joombri');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onFreelancerAcceptEscrow', array($escrow->to_id, $escrow->from_id, $escrow->project_id, $escrow->type));
     $msg = JText::_('COM_JBLANCE_ESCROW_PAYMENT_ACCEPTED_SUCCESSFULLY');
     $link = JRoute::_('index.php?option=com_jblance&view=membership&layout=managepay', false);
     $this->setRedirect($link, $msg);
     return false;
 }
示例#2
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');
 }
示例#3
0
 function repostProject()
 {
     // Check for request forgeries
     JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $id = $app->input->get('id', 0, 'int');
     $user = JFactory::getUser();
     $now = JFactory::getDate();
     //update status project
     $project = JTable::getInstance('project', 'Table');
     $project->load($id);
     $project->status = 'COM_JBLANCE_OPEN';
     $project->start_date = $now->toSql();
     if (!$project->check()) {
         JError::raiseError(500, $project->getError());
     }
     if (!$project->store()) {
         JError::raiseError(500, $project->getError());
     }
     $project->checkin();
     // deduce `charge per project` if amount is > 0
     $plan = JblanceHelper::whichPlan($user->id);
     $chargePerProject = $plan->buyChargePerProject;
     if ($chargePerProject > 0) {
         $transDtl = JText::_('COM_JBLANCE_REPOST') . ' - ' . $project->project_title;
         JblanceHelper::updateTransaction($user->id, $transDtl, $chargePerProject, -1);
         $msg_debit = JText::sprintf('COM_JBLANCE_YOUR_ACCOUNT_DEBITED_WITH_CURRENCY_FOR_POSTING_PROJECT', JblanceHelper::formatCurrency($chargePerProject));
         $app->enqueueMessage($msg_debit);
     }
     /* //send send hourly project payment complete notification
     		$jbmail = JblanceHelper::get('helper.email');		// create an instance of the class EmailHelper
     		$jbmail->sendProjectPaymentCompleteNotification($id, $user->id); */
     $msg = JText::_('COM_JBLANCE_PROJECT_REPOSTED_SUCCESSFULLY');
     $return = JRoute::_('index.php?option=com_jblance&view=project&layout=showmyproject', false);
     $this->setRedirect($return, $msg);
     return false;
 }