Merge pull request #355 from Lykegenes/master

Charts & reports SQLite compatibility
This commit is contained in:
Hillel Coren 2015-07-28 10:00:32 +03:00
commit da6e59a925
4 changed files with 141 additions and 99 deletions

View File

@ -1,6 +1,7 @@
<?php namespace App\Http\Controllers;
use Auth;
use Config;
use Input;
use Utils;
use DB;
@ -149,22 +150,56 @@ class ReportController extends BaseController
$reportTotals['balance'][$currencyId] += $record->balance;
}
if ($action == 'export') {
if ($action == 'export')
{
self::export($exportData, $reportTotals);
}
}
if ($enableChart) {
foreach ([ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_CREDIT] as $entityType) {
if ($enableChart)
{
foreach ([ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_CREDIT] as $entityType)
{
// SQLite does not support the YEAR(), MONTH(), WEEK() and similar functions.
// Let's see if SQLite is being used.
if (Config::get('database.connections.'.Config::get('database.default').'.driver') == 'sqlite')
{
// Replace the unsupported function with it's date format counterpart
switch ($groupBy)
{
case 'MONTH':
$dateFormat = '%m'; // returns 01-12
break;
case 'WEEK':
$dateFormat = '%W'; // returns 00-53
break;
case 'DAYOFYEAR':
$dateFormat = '%j'; // returns 001-366
break;
default:
$dateFormat = '%m'; // MONTH by default
break;
}
// Concatenate the year and the chosen timeframe (Month, Week or Day)
$timeframe = 'strftime("%Y", '.$entityType.'_date) || strftime("'.$dateFormat.'", '.$entityType.'_date)';
}
else
{
// Supported by Laravel's other DBMS drivers (MySQL, MSSQL and PostgreSQL)
$timeframe = 'concat(YEAR('.$entityType.'_date), '.$groupBy.'('.$entityType.'_date))';
}
$records = DB::table($entityType.'s')
->select(DB::raw('sum(amount) as total, concat(YEAR('.$entityType.'_date), '.$groupBy.'('.$entityType.'_date)) as '.$groupBy))
->select(DB::raw('sum(amount) as total, '.$timeframe.' as '.$groupBy))
->where('account_id', '=', Auth::user()->account_id)
->where($entityType.'s.is_deleted', '=', false)
->where($entityType.'s.'.$entityType.'_date', '>=', $startDate->format('Y-m-d'))
->where($entityType.'s.'.$entityType.'_date', '<=', $endDate->format('Y-m-d'))
->groupBy($groupBy);
if ($entityType == ENTITY_INVOICE) {
if ($entityType == ENTITY_INVOICE)
{
$records->where('is_quote', '=', false)
->where('is_recurring', '=', false);
}
@ -181,12 +216,14 @@ class ReportController extends BaseController
$totals = [];
foreach ($period as $d) {
foreach ($period as $d)
{
$dateFormat = $groupBy == 'DAYOFYEAR' ? 'z' : ($groupBy == 'WEEK' ? 'W' : 'n');
$date = $d->format('Y'.$dateFormat);
$totals[] = isset($data[$date]) ? $data[$date] : 0;
if ($entityType == ENTITY_INVOICE) {
if ($entityType == ENTITY_INVOICE)
{
$labelFormat = $groupBy == 'DAYOFYEAR' ? 'j' : ($groupBy == 'WEEK' ? 'W' : 'F');
$label = $d->format($labelFormat);
$labels[] = $label;
@ -195,7 +232,8 @@ class ReportController extends BaseController
$max = max($totals);
if ($max > 0) {
if ($max > 0)
{
$datasets[] = [
'totals' => $totals,
'colors' => $entityType == ENTITY_INVOICE ? '78,205,196' : ($entityType == ENTITY_CREDIT ? '199,244,100' : '255,107,107'),

View File

@ -251,6 +251,10 @@ class Utils
$currency = Currency::find(1);
}
if (!$value) {
$value = 0;
}
Cache::add('currency', $currency, DEFAULT_QUERY_CACHE);
return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);

View File

@ -628,7 +628,7 @@ return array(
'archive_task' => 'Archiver tâche',
'restore_task' => 'Restaurer tâche',
'delete_task' => 'Supprimer tâche',
'stop_task' => 'Arrêter tâcher',
'stop_task' => 'Arrêter tâche',
'time' => 'Temps',
'start' => 'Début',
'stop' => 'Fin',
@ -682,7 +682,7 @@ return array(
'resume' => 'Resume',
'break_duration' => 'Break',
'edit_details' => 'Editer détails',
'edit_details' => 'Modifier',
'work' => 'Travail',
'timezone_unset' => 'Please :link to set your timezone',
'click_here' => 'cliquer ici',

View File

@ -619,50 +619,50 @@ return array(
'last_invoice_sent' => 'Last invoice sent :date',
'processed_updates' => 'Successfully completed update',
'tasks' => 'Tasks',
'new_task' => 'New Task',
'start_time' => 'Start Time',
'created_task' => 'Successfully created task',
'updated_task' => 'Successfully updated task',
'tasks' => 'Tâches',
'new_task' => 'Nouvelle Tâche',
'start_time' => 'Démarrée à',
'created_task' => 'Tâche créée avec succès',
'updated_task' => 'Tâche modifiée avec succès',
'edit_task' => 'Edit Task',
'archive_task' => 'Archive Task',
'restore_task' => 'Restore Task',
'delete_task' => 'Delete Task',
'stop_task' => 'Stop Task',
'archive_task' => 'Archiver la Tâche',
'restore_task' => 'Restaurer la Tâche',
'delete_task' => 'Supprimer la Tâche',
'stop_task' => 'Arrêter la Tâche',
'time' => 'Time',
'start' => 'Start',
'stop' => 'Stop',
'start' => 'Démarrer',
'stop' => 'Arrêter',
'now' => 'Now',
'timer' => 'Timer',
'manual' => 'Manual',
'date_and_time' => 'Date & Time',
'second' => 'second',
'seconds' => 'seconds',
'second' => 'seconde',
'seconds' => 'secondes',
'minute' => 'minute',
'minutes' => 'minutes',
'hour' => 'hour',
'hours' => 'hours',
'task_details' => 'Task Details',
'duration' => 'Duration',
'end_time' => 'End Time',
'hour' => 'heure',
'hours' => 'heures',
'task_details' => 'Détails de la Tâche',
'duration' => 'Durée',
'end_time' => 'Arrêtée à',
'end' => 'End',
'invoiced' => 'Invoiced',
'logged' => 'Logged',
'running' => 'Running',
'task_error_multiple_clients' => 'The tasks can\'t belong to different clients',
'task_error_running' => 'Please stop running tasks first',
'task_error_invoiced' => 'Tasks have already been invoiced',
'restored_task' => 'Successfully restored task',
'archived_task' => 'Successfully archived task',
'archived_tasks' => 'Successfully archived :count tasks',
'deleted_task' => 'Successfully deleted task',
'deleted_tasks' => 'Successfully deleted :count tasks',
'create_task' => 'Create Task',
'stopped_task' => 'Successfully stopped task',
'invoice_task' => 'Invoice Task',
'task_error_multiple_clients' => 'Une tâche ne peut appartenir à plusieurs clients',
'task_error_running' => 'Merci d\'arrêter les tâches en cours',
'task_error_invoiced' => 'Ces tâches ont déjà été facturées',
'restored_task' => 'Tâche restaurée avec succès',
'archived_task' => 'Tâche archivée avec succès',
'archived_tasks' => ':count tâches archivées avec succès',
'deleted_task' => 'Tâche supprimée avec succès',
'deleted_tasks' => ':count tâches supprimées avec succès',
'create_task' => 'Créer une Tâche',
'stopped_task' => 'Tâche arrêtée avec succès',
'invoice_task' => 'Facturer Tâche',
'invoice_labels' => 'Invoice Labels',
'prefix' => 'Prefix',
'counter' => 'Counter',
'prefix' => 'Préfixe',
'counter' => 'Compteur',
'payment_type_dwolla' => 'Dwolla',
'gateway_help_43' => ':link to sign up for Dwolla.',
@ -681,12 +681,12 @@ return array(
'pro_plan_feature7' => 'Customize Invoice Field Titles & Numbering',
'pro_plan_feature8' => 'Option to Attach PDFs to Client Emails',
'resume' => 'Resume',
'break_duration' => 'Break',
'edit_details' => 'Edit Details',
'work' => 'Work',
'resume' => 'Continuer',
'break_duration' => 'Pause',
'edit_details' => 'Modifier',
'work' => 'Travail',
'timezone_unset' => 'Please :link to set your timezone',
'click_here' => 'click here',
'click_here' => 'cliquer içi',
'email_receipt' => 'Email payment receipt to the client',
'created_payment_emailed_client' => 'Successfully created payment and emailed client',