Skip to content

Commit

Permalink
Bad stat report
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 10, 2015
1 parent 688562a commit 8d77667
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 24 deletions.
7 changes: 5 additions & 2 deletions htdocs/core/lib/project.lib.php
Expand Up @@ -1004,8 +1004,11 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=
}

print '<tr><td>'.$langs->trans("Total")."</td>";
print '<td align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
print '<td align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmount"), 1).'</td>';
if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
{
print '<td align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
print '<td align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmount"), 1).'</td>';
}
if (empty($conf->global->PROJECT_HIDE_TASKS)) print '<td align="right">'.$total_task.'</td>';

$db->free($resql);
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/errors.lang
Expand Up @@ -171,6 +171,7 @@ ErrorGlobalVariableUpdater5=No global variable selected
ErrorFieldMustBeANumeric=Field <b>%s</b> must be a numeric value
ErrorFieldMustBeAnInteger=Field <b>%s</b> must be an integer
ErrorMandatoryParametersNotProvided=Mandatory parameter(s) not provided
ErrorOppStatusRequiredIfAmount=Vous avez renseigné un montant estimé de l'opportunité. Dans ce cas, il faut aussi renseigner le statut d'opportunité

# Warnings
WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/projects.lang
Expand Up @@ -127,7 +127,9 @@ TaskCreatedInDolibarr=Task %s created
TaskModifiedInDolibarr=Task %s modified
TaskDeletedInDolibarr=Task %s deleted
OpportunityStatus=Opportunity status
OpportunityStatusShort=Opp. status
OpportunityAmount=Opportunity amount
OpportunityAmountShort=Opp. amount
##### Types de contacts #####
TypeContact_project_internal_PROJECTLEADER=Project leader
TypeContact_project_external_PROJECTLEADER=Project leader
Expand Down
9 changes: 7 additions & 2 deletions htdocs/projet/card.php
Expand Up @@ -238,6 +238,12 @@
if ($ret < 0) $error++;
}

if ($object->opp_amount && ($object->opp_status <= 0))
{
$error++;
setEventMessage($langs->trans("ErrorOppStatusRequiredIfAmount"),'errors');
}

if (! $error)
{
$result=$object->update($user);
Expand Down Expand Up @@ -658,7 +664,7 @@

// Opportunity amount
print '<tr><td>'.$langs->trans("OpportunityAmount").'</td>';
print '<td><input size="4" type="text" name="opp_amount" value="'.(isset($_POST['opp_amount'])?GETPOST('opp_amount'):(strcmp($object->opp_amount,'')?price($object->opp_amount):'')).'"></td>';
print '<td><input size="6" type="text" name="opp_amount" value="'.(isset($_POST['opp_amount'])?GETPOST('opp_amount'):(strcmp($object->opp_amount,'')?price($object->opp_amount):'')).'"></td>';
print '</tr>';
}

Expand Down Expand Up @@ -899,7 +905,6 @@
// Hook to add more things on page
$parameters=array();
$reshook=$hookmanager->executeHooks('mainCardTabAddMore',$parameters,$object,$action); // Note that $action and $object may have been modified by hook

}

llxFooter();
Expand Down
34 changes: 23 additions & 11 deletions htdocs/projet/class/projectstats.class.php
Expand Up @@ -19,20 +19,24 @@
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';


/**
* Class to manage statistics on projects
*/
class ProjectStats extends Stats
{
protected $db;
private $project;
public $userid;
public $socid;
public $year;
function __construct($db) {

function __construct($db)
{
global $conf, $user;

$this->db = $db;

require_once 'project.class.php';

$this->project = new Project($this->db);
}

Expand Down Expand Up @@ -113,11 +117,15 @@ function getAllByYear()

return $this->_getAllByYear($sql);
}


/**
*
* Build the where part
*
* @return string
*/
public function buildWhere() {
public function buildWhere()
{
$sqlwhere_str = '';
$sqlwhere = array();

Expand Down Expand Up @@ -148,7 +156,8 @@ public function buildWhere() {
* @param int $year scan
* @return array of values
*/
function getNbByMonth($year) {
function getNbByMonth($year)
{
global $user;

$this->yearmonth = $year;
Expand All @@ -174,7 +183,8 @@ function getNbByMonth($year) {
* @param int $year scan
* @return array with amount by month
*/
function getAmountByMonth($year) {
function getAmountByMonth($year)
{
global $user;

$this->yearmonth = $year;
Expand Down Expand Up @@ -289,18 +299,19 @@ function getWeightedAmountByMonthWithPrevYear($endyear,$startyear,$cachedelay=0)


/**
* Return the Project amount by month for a year
* Return the Project weighted opp amount by month for a year
*
* @param int $year scan
* @return array with amount by month
*/
function getWeightedAmountByMonth($year) {
function getWeightedAmountByMonth($year)
{
global $user;

$this->yearmonth = $year;

$sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount)";
$sql .= " FROM " . MAIN_DB_PREFIX . "projet as t";
$sql = "SELECT date_format(t.datec,'%m') as dm, SUM(t.opp_amount * ".$this->db->ifsql('cls.percent IS NULL', '0', 'cls.percent')." / 100)";
$sql .= " FROM " . MAIN_DB_PREFIX . "projet as t LEFT JOIN ".MAIN_DB_PREFIX.'c_lead_status as cls ON t.fk_opp_status = cls.rowid';
if (! $user->rights->societe->client->voir && ! $user->societe_id)
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON sc.fk_soc=t.fk_soc AND sc.fk_user=" . $user->id;
$sql .= $this->buildWhere();
Expand Down Expand Up @@ -401,7 +412,8 @@ function getTransformRateByMonthWithPrevYear($endyear, $startyear, $cachedelay =
* @param int $year scan
* @return array with amount by month
*/
function getTransformRateByMonth($year) {
function getTransformRateByMonth($year)
{
global $user;

$this->yearmonth = $year;
Expand Down
27 changes: 20 additions & 7 deletions htdocs/projet/list.php
Expand Up @@ -274,13 +274,17 @@
print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"p.title","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("SalesRepresentative"),$_SERVER["PHP_SELF"],"","",$param,"",$sortfield,$sortorder);
if (! empty($conf->global->PROJECT_LIST_SHOW_STARTDATE)) print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"p.dateo","",$param,'align="center"',$sortfield,$sortorder);
if (empty($conf->global->PROJECT_LIST_HIDE_STARTDATE)) print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"p.dateo","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"p.datee","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Visibility"),$_SERVER["PHP_SELF"],"p.public","",$param,"",$sortfield,$sortorder);
if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
{
print_liste_field_titre($langs->trans("OpportunityAmountShort"),$_SERVER["PHP_SELF"],'p.opp_amount',"",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("OpportunityStatusShort"),$_SERVER["PHP_SELF"],'p.fk_opp_status',"",$param,'',$sortfield,$sortorder);
}
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES)) print_liste_field_titre($langs->trans("OpportunityStatus"),$_SERVER["PHP_SELF"],'p.fk_opp_status',"",$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],'p.fk_statut',"",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
print "</tr>\n";
Expand All @@ -298,7 +302,7 @@
// Sale representative
print '<td class="liste_titre">&nbsp;</td>';
// Start date
if (! empty($conf->global->PROJECT_LIST_SHOW_STARTDATE))
if (empty($conf->global->PROJECT_LIST_HIDE_STARTDATE))
{
print '<td class="liste_titre center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="sday" value="'.$sday.'">';
Expand All @@ -325,6 +329,8 @@
if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
{
print '<td class="liste_titre nowrap">';
print '</td>';
print '<td class="liste_titre nowrap">';
print $formproject->selectOpportunityStatus('search_opp_status',$search_opp_status,1,1);
print '</td>';
}
Expand Down Expand Up @@ -417,10 +423,13 @@
print '</td>';

// Date start
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_start),'day');
print '</td>';

if (empty($conf->global->PROJECT_LIST_HIDE_STARTDATE))
{
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_start),'day');
print '</td>';
}

// Date end
print '<td class="center">';
print dol_print_date($db->jdate($objp->date_end),'day');
Expand All @@ -438,6 +447,10 @@

if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
{
print '<td>';
if ($objp->opp_status_code) print $langs->trans("OppAmount".$objp->opp_amount);
print '</td>';

print '<td>';
if ($objp->opp_status_code) print $langs->trans("OppStatusShort".$objp->opp_status_code);
print '</td>';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/projet/stats/index.php
@@ -1,6 +1,6 @@
<?php
/* Lead
* Copyright (C) 2014-2015 Florian HENRY <florian.henry@open-concept.pro>
/* Copyright (C) 2014-2015 Florian HENRY <florian.henry@open-concept.pro>
* Copyright (C) 2015 Laurent Destailleur <ldestailleur@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 8d77667

Please sign in to comment.