1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on projects

This commit is contained in:
Hillel Coren 2017-12-25 12:13:01 +02:00
parent d7fbccba3e
commit f1052ef377
2 changed files with 51 additions and 126 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Jobs\GenerateProjectChartData;
use App\Http\Requests\CreateProjectRequest;
use App\Http\Requests\ProjectRequest;
use App\Http\Requests\UpdateProjectRequest;
@ -10,9 +11,6 @@ use App\Models\Project;
use App\Ninja\Datatables\ProjectDatatable;
use App\Ninja\Repositories\ProjectRepository;
use App\Services\ProjectService;
use DateInterval;
use DatePeriod;
use stdClass;
use Auth;
use Input;
use Session;
@ -56,65 +54,14 @@ class ProjectController extends BaseController
{
$account = auth()->user()->account;
$project = $request->entity();
$taskMap = [];
foreach ($project->tasks as $task) {
$parts = json_decode($task->time_log) ?: [];
if (! count($parts)) {
continue;
}
foreach ($parts as $part) {
$start = $part[0];
$end = count($part) > 1 ? $part[1] : time();
$date = $account->getDateTime();
$date->setTimestamp($part[0]);
$sqlDate = $date->format('Y-m-d');
if (! isset($taskMap[$sqlDate])) {
$taskMap[$sqlDate] = 0;
}
$taskMap[$sqlDate] += $end - $start;
}
}
$labels = [];
$records = [];
$startDate = date_create('2017-11-01');
$endDate = date_create('2017-12-01');
$interval = new DateInterval('P1D');
$period = new DatePeriod($startDate, $interval, $endDate);
$data = [];
$amount = 0;
$color = '51,122,183';
foreach ($period as $date) {
$labels[] = $date->format('m/d/Y');
$records[] = $amount+=10;
}
$dataset = new stdClass();
$dataset->data = $records;
$dataset->label = trans("texts.tasks");
$dataset->lineTension = 0;
$dataset->borderWidth = 4;
$dataset->borderColor = "rgba({$color}, 1)";
$dataset->backgroundColor = "rgba({$color}, 0.1)";
$data = new stdClass();
$data->labels = $labels;
$data->datasets = [$dataset];
$chartData = dispatch(new GenerateProjectChartData($project));
$data = [
'account' => auth()->user()->account,
'project' => $project,
'title' => trans('texts.view_project'),
'showBreadcrumbs' => false,
'data' => $data,
'chartData' => $chartData,
];
return View::make('projects.show', $data);

View File

@ -77,18 +77,28 @@
</div>
<div class="col-md-3">
<h3>{{ trans('texts.summary') }}</h3>
<h3>{{ trans('texts.summary') }}
<table class="table" style="width:100%">
<tr>
<td><small>{{ trans('texts.tasks') }}</small></td>
<td style="text-align: right">3</td>
</tr>
<tr>
<td><small>{{ trans('texts.duration') }}</small></td>
<td style="text-align: right">04:15:00</td>
</tr>
</table>
</h3>
</div>
</div>
</div>
</div>
<canvas id="chart-canvas" height="50px" style="background-color:white;padding:20px;display:none"></canvas><br/>
@if ($chartData)
<canvas id="chart-canvas" height="50px" style="background-color:white;padding:20px;display:none"></canvas><br/>
@endif
<ul class="nav nav-tabs nav-justified">
{!! Form::tab_link('#tasks', trans('texts.tasks')) !!}
@ -119,8 +129,7 @@
$('.nav-tabs a[href="#tasks"]').tab('show');
var chartData = {!! json_encode($data) !!};
console.log(chartData);
var chartData = {!! json_encode($chartData) !!};
loadChart(chartData);
});
@ -143,70 +152,39 @@
function loadChart(data) {
var ctx = document.getElementById('chart-canvas').getContext('2d');
if (window.myChart) {
window.myChart.config.data = data;
//window.myChart.config.options.scales.xAxes[0].time.unit = chartGroupBy.toLowerCase();
//window.myChart.config.options.scales.xAxes[0].time.round = chartGroupBy.toLowerCase();
window.myChart.update();
} else {
$('#chart-canvas').fadeIn();
window.myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
mode: 'x-axis',
titleFontSize: 15,
titleMarginBottom: 12,
bodyFontSize: 15,
bodySpacing: 10,
callbacks: {
title: function(item) {
//return moment(item[0].xLabel).format("{{ $account->getMomentDateFormat() }}");
},
label: function(item, data) {
/*
if (item.datasetIndex == 0) {
var label = " {!! trans('texts.invoices') !!}: ";
} else if (item.datasetIndex == 1) {
var label = " {!! trans('texts.payments') !!}: ";
} else if (item.datasetIndex == 2) {
var label = " {!! trans('texts.expenses') !!}: ";
}
return label + formatMoney(item.yLabel, chartCurrencyId, account.country_id);
*/
$('#chart-canvas').fadeIn();
window.myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
legend: {
display: false,
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'day',
round: 'day',
},
gridLines: {
display: false,
},
}],
yAxes: [{
ticks: {
@if ($project->budgeted_hours)
max: {{ $project->budgeted_hours }},
@endif
beginAtZero: true,
callback: function(label, index, labels) {
return roundToTwo(label) + " {{ trans('texts.hours') }}";
}
}
},
title: {
display: false,
fontSize: 18,
text: '{{ trans('texts.total_revenue') }}'
},
scales: {
xAxes: [{
type: 'time',
time: {
//unit: chartGroupBy,
//round: chartGroupBy,
},
gridLines: {
display: false,
},
}],
yAxes: [{
ticks: {
beginAtZero: true,
callback: function(label, index, labels) {
//return formatMoney(label, chartCurrencyId, account.country_id);
}
},
}]
}
},
}]
}
});
}
}
});
}