Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #143

Open
wants to merge 8 commits into
base: staging
Choose a base branch
from
Open

Fixes #143

Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/joomla/language/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public static function alt($string, $alt, $jsSafe = false, $interpretBackSlashes
* script is a boolean to indicate that the string will be push in the javascript language store.
*
* Examples:
* <script>alert(Joomla.JText._('<?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1, array("script"=>true));?>'));</script>
* <script>alert(Joomla.JText._('<?php echo TextHelper::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1, array("script"=>true));?>'));</script>
* will generate an alert message containing '1 plugin successfully disabled'
* <?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1);?> it will generate a '1 plugin successfully disabled' string
* <?php echo TextHelper::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1);?> it will generate a '1 plugin successfully disabled' string
*
* @param string $string The format string.
* @param integer $n The number of items
Expand Down
4 changes: 2 additions & 2 deletions src/Cobalt/Controller/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function execute()
//get graph data from model
$model = new GraphsModel;

$type = $this->getInput()->get('filter');
$type = $this->getInput()->getCmd('filter');
if ($type == 'company') {
$graph_data = $model->getGraphData('company');
} else {
$graph_data = $model->getGraphData($type,$this->getInput()->get('id'));
$graph_data = $model->getGraphData($type,$this->getInput()->getInt('id'));
}

//return data
Expand Down
5 changes: 3 additions & 2 deletions src/Cobalt/Controller/SaveCf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Cobalt\Helper\DateHelper;
use Cobalt\Model\Deal as DealModel;
use Cobalt\Model\People as PeopleModel;
use Cobalt\Helper\TextHelper;

// no direct access
defined( '_CEXEC' ) or die( 'Restricted access' );
Expand Down Expand Up @@ -79,7 +80,7 @@ public function execute()
$model = new PeopleModel;
$return = $model->getPerson($data['person_id']);
$response->alert = new \stdClass;
$response->alert->message = \JText::_('DEAL_CONTACT_ADDED_SUCCESS');
$response->alert->message = TextHelper::_('DEAL_CONTACT_ADDED_SUCCESS');
$response->alert->type = 'success';
$response->item = $return;
$response->reload = 2000;
Expand All @@ -96,7 +97,7 @@ public function execute()
}
} else {
$response->alert = new \stdClass;
$response->alert->message = \JText::_('DEAL_CONTACT_ERROR_FAILURE_ADD_PERSON');
$response->alert->message = TextHelper::_('DEAL_CONTACT_ERROR_FAILURE_ADD_PERSON');
$response->alert->type = 'error';
}

Expand Down
199 changes: 199 additions & 0 deletions src/Cobalt/Helper/LinkHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php

/*------------------------------------------------------------------------
# Cobalt
# ------------------------------------------------------------------------
# @author Cobalt
# @copyright Copyright (C) 2012 cobaltcrm.org All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Website: http://www.cobaltcrm.org
-------------------------------------------------------------------------*/

namespace Cobalt\Helper;

// no direct access
defined( '_CEXEC' ) or die( 'Restricted access' );

use Cobalt\Helper\RouteHelper;

/**
* Class to build link to specific items
*
* Class LinkHelper
* @package Cobalt\Helper
*/
class LinkHelper
{
/**
* @param array $params
* @return string
*/
public static function viewDashboard(array $params = array())
{
$link = array(
'view' => 'dashboard'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function viewDocuments(array $params = array())
{
$link = array(
'view' => 'documents'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function viewAdminDocuments(array $params = array())
{
$link = array(
'view' => 'admindocuments'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function viewImport(array $params = array())
{
$link = array(
'view' => 'import'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function upload(array $params = array())
{
$link = array(
'task' => 'upload'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* Link to view deal
*
* @param $deal_id
* @return string
*/
public static function viewDeal($deal_id, array $params = array())
{
$link = array(
'view' => 'deal',
'layout' => 'deal',
'id' => intval($deal_id)
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function viewDeals(array $params = array())
{
$link = array(
'view' => 'deals'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* @param array $params
* @return string
*/
public static function viewReports(array $params = array())
{
$link = array(
'view' => 'reports'
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* Link to view person
*
* @param $person_id
* @return string
*/
public static function viewPerson($person_id, array $params = array())
{
$link = array(
'view' => 'people',
'layout' => 'person',
'id' => intval($person_id)
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* Link to view Company
*
* @param $copmany_id
* @return string
*/
public static function viewCompany($copmany_id, array $params = array())
{
$link = array(
'view' => 'companies',
'layout' => 'company',
'id' => intval($copmany_id)
);

$query = array_merge($link, $params);

return self::create($query);
}

/**
* Build Custom URL by array of keys and values
*
* @param array $query
* @return string
*/
public static function create(array $query)
{
return RouteHelper::_('index.php?'.http_build_query($query));
}
}
67 changes: 53 additions & 14 deletions src/Cobalt/Model/Commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Cobalt\Helper\UsersHelper;
use Cobalt\Helper\DateHelper;
use Cobalt\Helper\DealHelper;
use Cobalt\Helper\TextHelper;

// no direct access
defined( '_CEXEC' ) or die( 'Restricted access' );
Expand Down Expand Up @@ -58,9 +59,9 @@ public function getMonthlyCommission($access_type=null,$access_id=null)
foreach ($members as $key=>$member) {
foreach ($member as $date_key => $data) {
if ( array_key_exists($date_key,$results) ) {
$results[$date_key]['y'] += $data['y'];
$results[$date_key] += $data;
} else {
$results[$date_key]['y'] = $data['y'];
$results[$date_key] = $data;
}
}
}
Expand All @@ -84,7 +85,9 @@ public function getYearlyCommission($access_type=null,$access_id=null)

//array to assign our data
$members = array();
$results = array();
$data = new \stdClass;
$data->labels = array();
$data->datasets = array();

//get team data
if ($access_type == 'team') {
Expand All @@ -105,17 +108,25 @@ public function getYearlyCommission($access_type=null,$access_id=null)
}

//combine data
foreach ($members as $key=>$member) {
foreach ($member as $date_key=>$data) {
if ( array_key_exists($date_key,$results) ) {
$results[$date_key]['y'] += $data['y'];
} else {
$results[$date_key]['y'] = $data['y'];
$results = array();
foreach ($members as $member) {
foreach ($member->datasets[0]->data as $key => $value) {
if (!isset($results[$key])) {
$results[$key] = 0;
}
$results[$key] += $value;
}
}

return $results;
$data->datasets[0] = new \stdClass;
$data->datasets[0]->data = $results;
$data->datasets[0]->label = '';
$data->datasets[0]->fillColor = "rgba(151,187,205,0.5)";
$data->datasets[0]->strokeColor = "rgba(151,187,205,0.8)";
$data->datasets[0]->pointColor = "rgba(151,187,205,0.75)";
$data->datasets[0]->pointStrokeColor = "rgba(151,187,205,1)";

return $data;
}

}
Expand All @@ -136,11 +147,17 @@ public function getMonthlyCommissionData($id)
//get stage id to filter deals by
$won_stage_ids = DealHelper::getWonStages();

$data = new \stdClass;
$data->labels = array();
$data->datasets = array();

//gen query
$results = array();
foreach ($weeks as $week) {
$start_date = $week['start_date'];
$end_date = $week['end_date'];
$weekDate = new \DateTime($start_date);
$data->labels[] = TextHelper::_('COBALT_WEEK') . ' ' . $weekDate->format('W');

//flush query
$query = $this->db->getQuery(true)
Expand All @@ -160,10 +177,18 @@ public function getMonthlyCommissionData($id)
//clean data for commission rate
foreach ($results as $key => $result) {
$commission_rate = UsersHelper::getCommissionRate($result['owner_id']);
$results[$key]['y'] = (int) $result['y']*($commission_rate/100);
$results[$key] = (int) $result['y']*($commission_rate/100);
}

return $results;
$data->datasets[0] = new \stdClass;
$data->datasets[0]->data = $results;
$data->datasets[0]->label = '';
$data->datasets[0]->fillColor = "rgba(151,187,205,0.5)";
$data->datasets[0]->strokeColor = "rgba(151,187,205,0.8)";
$data->datasets[0]->pointColor = "rgba(151,187,205,0.75)";
$data->datasets[0]->pointStrokeColor = "rgba(151,187,205,1)";

return $data;
}

/**
Expand All @@ -178,6 +203,10 @@ public function getYearlyCommissionData($id)
$month_names = DateHelper::getMonthNames();
$months = DateHelper::getMonthDates();

$data = new \stdClass;
$data->labels = array();
$data->datasets = array();

//get stage id to filter deals by
$won_stage_ids = DealHelper::getWonStages();

Expand All @@ -186,6 +215,8 @@ public function getYearlyCommissionData($id)
foreach ($months as $month) {
$start_date = $month['date'];
$end_date = DateHelper::formatDBDate(date('Y-m-d 00:00:00',strtotime("$start_date + 1 months")));
$weekDate = new \DateTime($start_date);
$data->labels[] = TextHelper::_('COBALT_MONTH') . ' ' . $weekDate->format('m');

//flush the query
$query = $this->db->getQuery(true)
Expand All @@ -205,10 +236,18 @@ public function getYearlyCommissionData($id)
//clean data for commission rate
foreach ($results as $key=>$result) {
$commission_rate = UsersHelper::getCommissionRate($result['owner_id']);
$results[$key]['y'] = (int) $result['y']*($commission_rate/100);
$results[$key] = (int) $result['y']*($commission_rate/100);
}

return $results;
$data->datasets[0] = new \stdClass;
$data->datasets[0]->data = $results;
$data->datasets[0]->label = '';
$data->datasets[0]->fillColor = "rgba(151,187,205,0.5)";
$data->datasets[0]->strokeColor = "rgba(151,187,205,0.8)";
$data->datasets[0]->pointColor = "rgba(151,187,205,0.75)";
$data->datasets[0]->pointStrokeColor = "rgba(151,187,205,1)";

return $data;
}

}
Loading