mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #355 from Lykegenes/master
Charts & reports SQLite compatibility
This commit is contained in:
commit
da6e59a925
@ -1,6 +1,7 @@
|
|||||||
<?php namespace App\Http\Controllers;
|
<?php namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Config;
|
||||||
use Input;
|
use Input;
|
||||||
use Utils;
|
use Utils;
|
||||||
use DB;
|
use DB;
|
||||||
@ -149,22 +150,56 @@ class ReportController extends BaseController
|
|||||||
$reportTotals['balance'][$currencyId] += $record->balance;
|
$reportTotals['balance'][$currencyId] += $record->balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'export') {
|
if ($action == 'export')
|
||||||
|
{
|
||||||
self::export($exportData, $reportTotals);
|
self::export($exportData, $reportTotals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($enableChart) {
|
if ($enableChart)
|
||||||
foreach ([ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_CREDIT] as $entityType) {
|
{
|
||||||
|
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')
|
$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('account_id', '=', Auth::user()->account_id)
|
||||||
->where($entityType.'s.is_deleted', '=', false)
|
->where($entityType.'s.is_deleted', '=', false)
|
||||||
->where($entityType.'s.'.$entityType.'_date', '>=', $startDate->format('Y-m-d'))
|
->where($entityType.'s.'.$entityType.'_date', '>=', $startDate->format('Y-m-d'))
|
||||||
->where($entityType.'s.'.$entityType.'_date', '<=', $endDate->format('Y-m-d'))
|
->where($entityType.'s.'.$entityType.'_date', '<=', $endDate->format('Y-m-d'))
|
||||||
->groupBy($groupBy);
|
->groupBy($groupBy);
|
||||||
|
|
||||||
if ($entityType == ENTITY_INVOICE) {
|
if ($entityType == ENTITY_INVOICE)
|
||||||
|
{
|
||||||
$records->where('is_quote', '=', false)
|
$records->where('is_quote', '=', false)
|
||||||
->where('is_recurring', '=', false);
|
->where('is_recurring', '=', false);
|
||||||
}
|
}
|
||||||
@ -181,12 +216,14 @@ class ReportController extends BaseController
|
|||||||
|
|
||||||
$totals = [];
|
$totals = [];
|
||||||
|
|
||||||
foreach ($period as $d) {
|
foreach ($period as $d)
|
||||||
|
{
|
||||||
$dateFormat = $groupBy == 'DAYOFYEAR' ? 'z' : ($groupBy == 'WEEK' ? 'W' : 'n');
|
$dateFormat = $groupBy == 'DAYOFYEAR' ? 'z' : ($groupBy == 'WEEK' ? 'W' : 'n');
|
||||||
$date = $d->format('Y'.$dateFormat);
|
$date = $d->format('Y'.$dateFormat);
|
||||||
$totals[] = isset($data[$date]) ? $data[$date] : 0;
|
$totals[] = isset($data[$date]) ? $data[$date] : 0;
|
||||||
|
|
||||||
if ($entityType == ENTITY_INVOICE) {
|
if ($entityType == ENTITY_INVOICE)
|
||||||
|
{
|
||||||
$labelFormat = $groupBy == 'DAYOFYEAR' ? 'j' : ($groupBy == 'WEEK' ? 'W' : 'F');
|
$labelFormat = $groupBy == 'DAYOFYEAR' ? 'j' : ($groupBy == 'WEEK' ? 'W' : 'F');
|
||||||
$label = $d->format($labelFormat);
|
$label = $d->format($labelFormat);
|
||||||
$labels[] = $label;
|
$labels[] = $label;
|
||||||
@ -195,7 +232,8 @@ class ReportController extends BaseController
|
|||||||
|
|
||||||
$max = max($totals);
|
$max = max($totals);
|
||||||
|
|
||||||
if ($max > 0) {
|
if ($max > 0)
|
||||||
|
{
|
||||||
$datasets[] = [
|
$datasets[] = [
|
||||||
'totals' => $totals,
|
'totals' => $totals,
|
||||||
'colors' => $entityType == ENTITY_INVOICE ? '78,205,196' : ($entityType == ENTITY_CREDIT ? '199,244,100' : '255,107,107'),
|
'colors' => $entityType == ENTITY_INVOICE ? '78,205,196' : ($entityType == ENTITY_CREDIT ? '199,244,100' : '255,107,107'),
|
||||||
|
@ -251,6 +251,10 @@ class Utils
|
|||||||
$currency = Currency::find(1);
|
$currency = Currency::find(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$value) {
|
||||||
|
$value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Cache::add('currency', $currency, DEFAULT_QUERY_CACHE);
|
Cache::add('currency', $currency, DEFAULT_QUERY_CACHE);
|
||||||
|
|
||||||
return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
|
return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
|
||||||
|
@ -628,7 +628,7 @@ return array(
|
|||||||
'archive_task' => 'Archiver tâche',
|
'archive_task' => 'Archiver tâche',
|
||||||
'restore_task' => 'Restaurer tâche',
|
'restore_task' => 'Restaurer tâche',
|
||||||
'delete_task' => 'Supprimer tâche',
|
'delete_task' => 'Supprimer tâche',
|
||||||
'stop_task' => 'Arrêter tâcher',
|
'stop_task' => 'Arrêter tâche',
|
||||||
'time' => 'Temps',
|
'time' => 'Temps',
|
||||||
'start' => 'Début',
|
'start' => 'Début',
|
||||||
'stop' => 'Fin',
|
'stop' => 'Fin',
|
||||||
@ -682,7 +682,7 @@ return array(
|
|||||||
|
|
||||||
'resume' => 'Resume',
|
'resume' => 'Resume',
|
||||||
'break_duration' => 'Break',
|
'break_duration' => 'Break',
|
||||||
'edit_details' => 'Editer détails',
|
'edit_details' => 'Modifier',
|
||||||
'work' => 'Travail',
|
'work' => 'Travail',
|
||||||
'timezone_unset' => 'Please :link to set your timezone',
|
'timezone_unset' => 'Please :link to set your timezone',
|
||||||
'click_here' => 'cliquer ici',
|
'click_here' => 'cliquer ici',
|
||||||
|
@ -619,50 +619,50 @@ return array(
|
|||||||
'last_invoice_sent' => 'Last invoice sent :date',
|
'last_invoice_sent' => 'Last invoice sent :date',
|
||||||
|
|
||||||
'processed_updates' => 'Successfully completed update',
|
'processed_updates' => 'Successfully completed update',
|
||||||
'tasks' => 'Tasks',
|
'tasks' => 'Tâches',
|
||||||
'new_task' => 'New Task',
|
'new_task' => 'Nouvelle Tâche',
|
||||||
'start_time' => 'Start Time',
|
'start_time' => 'Démarrée à',
|
||||||
'created_task' => 'Successfully created task',
|
'created_task' => 'Tâche créée avec succès',
|
||||||
'updated_task' => 'Successfully updated task',
|
'updated_task' => 'Tâche modifiée avec succès',
|
||||||
'edit_task' => 'Edit Task',
|
'edit_task' => 'Edit Task',
|
||||||
'archive_task' => 'Archive Task',
|
'archive_task' => 'Archiver la Tâche',
|
||||||
'restore_task' => 'Restore Task',
|
'restore_task' => 'Restaurer la Tâche',
|
||||||
'delete_task' => 'Delete Task',
|
'delete_task' => 'Supprimer la Tâche',
|
||||||
'stop_task' => 'Stop Task',
|
'stop_task' => 'Arrêter la Tâche',
|
||||||
'time' => 'Time',
|
'time' => 'Time',
|
||||||
'start' => 'Start',
|
'start' => 'Démarrer',
|
||||||
'stop' => 'Stop',
|
'stop' => 'Arrêter',
|
||||||
'now' => 'Now',
|
'now' => 'Now',
|
||||||
'timer' => 'Timer',
|
'timer' => 'Timer',
|
||||||
'manual' => 'Manual',
|
'manual' => 'Manual',
|
||||||
'date_and_time' => 'Date & Time',
|
'date_and_time' => 'Date & Time',
|
||||||
'second' => 'second',
|
'second' => 'seconde',
|
||||||
'seconds' => 'seconds',
|
'seconds' => 'secondes',
|
||||||
'minute' => 'minute',
|
'minute' => 'minute',
|
||||||
'minutes' => 'minutes',
|
'minutes' => 'minutes',
|
||||||
'hour' => 'hour',
|
'hour' => 'heure',
|
||||||
'hours' => 'hours',
|
'hours' => 'heures',
|
||||||
'task_details' => 'Task Details',
|
'task_details' => 'Détails de la Tâche',
|
||||||
'duration' => 'Duration',
|
'duration' => 'Durée',
|
||||||
'end_time' => 'End Time',
|
'end_time' => 'Arrêtée à',
|
||||||
'end' => 'End',
|
'end' => 'End',
|
||||||
'invoiced' => 'Invoiced',
|
'invoiced' => 'Invoiced',
|
||||||
'logged' => 'Logged',
|
'logged' => 'Logged',
|
||||||
'running' => 'Running',
|
'running' => 'Running',
|
||||||
'task_error_multiple_clients' => 'The tasks can\'t belong to different clients',
|
'task_error_multiple_clients' => 'Une tâche ne peut appartenir à plusieurs clients',
|
||||||
'task_error_running' => 'Please stop running tasks first',
|
'task_error_running' => 'Merci d\'arrêter les tâches en cours',
|
||||||
'task_error_invoiced' => 'Tasks have already been invoiced',
|
'task_error_invoiced' => 'Ces tâches ont déjà été facturées',
|
||||||
'restored_task' => 'Successfully restored task',
|
'restored_task' => 'Tâche restaurée avec succès',
|
||||||
'archived_task' => 'Successfully archived task',
|
'archived_task' => 'Tâche archivée avec succès',
|
||||||
'archived_tasks' => 'Successfully archived :count tasks',
|
'archived_tasks' => ':count tâches archivées avec succès',
|
||||||
'deleted_task' => 'Successfully deleted task',
|
'deleted_task' => 'Tâche supprimée avec succès',
|
||||||
'deleted_tasks' => 'Successfully deleted :count tasks',
|
'deleted_tasks' => ':count tâches supprimées avec succès',
|
||||||
'create_task' => 'Create Task',
|
'create_task' => 'Créer une Tâche',
|
||||||
'stopped_task' => 'Successfully stopped task',
|
'stopped_task' => 'Tâche arrêtée avec succès',
|
||||||
'invoice_task' => 'Invoice Task',
|
'invoice_task' => 'Facturer Tâche',
|
||||||
'invoice_labels' => 'Invoice Labels',
|
'invoice_labels' => 'Invoice Labels',
|
||||||
'prefix' => 'Prefix',
|
'prefix' => 'Préfixe',
|
||||||
'counter' => 'Counter',
|
'counter' => 'Compteur',
|
||||||
|
|
||||||
'payment_type_dwolla' => 'Dwolla',
|
'payment_type_dwolla' => 'Dwolla',
|
||||||
'gateway_help_43' => ':link to sign up for 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_feature7' => 'Customize Invoice Field Titles & Numbering',
|
||||||
'pro_plan_feature8' => 'Option to Attach PDFs to Client Emails',
|
'pro_plan_feature8' => 'Option to Attach PDFs to Client Emails',
|
||||||
|
|
||||||
'resume' => 'Resume',
|
'resume' => 'Continuer',
|
||||||
'break_duration' => 'Break',
|
'break_duration' => 'Pause',
|
||||||
'edit_details' => 'Edit Details',
|
'edit_details' => 'Modifier',
|
||||||
'work' => 'Work',
|
'work' => 'Travail',
|
||||||
'timezone_unset' => 'Please :link to set your timezone',
|
'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',
|
'email_receipt' => 'Email payment receipt to the client',
|
||||||
'created_payment_emailed_client' => 'Successfully created payment and emailed client',
|
'created_payment_emailed_client' => 'Successfully created payment and emailed client',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user