2017-01-22 11:09:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Reports;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
|
|
|
|
class AbstractReport
|
|
|
|
{
|
|
|
|
public $startDate;
|
|
|
|
public $endDate;
|
|
|
|
public $isExport;
|
|
|
|
public $options;
|
|
|
|
|
|
|
|
public $totals = [];
|
|
|
|
public $columns = [];
|
|
|
|
public $data = [];
|
|
|
|
|
|
|
|
public function __construct($startDate, $endDate, $isExport, $options = false)
|
|
|
|
{
|
|
|
|
$this->startDate = $startDate;
|
|
|
|
$this->endDate = $endDate;
|
|
|
|
$this->isExport = $isExport;
|
|
|
|
$this->options = $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
2017-03-08 10:41:24 +01:00
|
|
|
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function results()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'columns' => $this->columns,
|
|
|
|
'displayData' => $this->data,
|
|
|
|
'reportTotals' => $this->totals,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function addToTotals($currencyId, $field, $value, $dimension = false)
|
|
|
|
{
|
|
|
|
$currencyId = $currencyId ?: Auth::user()->account->getCurrencyId();
|
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
if (! isset($this->totals[$currencyId][$dimension])) {
|
2017-01-22 11:09:29 +01:00
|
|
|
$this->totals[$currencyId][$dimension] = [];
|
|
|
|
}
|
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
if (! isset($this->totals[$currencyId][$dimension][$field])) {
|
2017-01-22 11:09:29 +01:00
|
|
|
$this->totals[$currencyId][$dimension][$field] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->totals[$currencyId][$dimension][$field] += $value;
|
|
|
|
}
|
|
|
|
|
2017-07-31 00:49:24 +02:00
|
|
|
public function tableHeaderArray() {
|
2017-08-01 15:37:33 +02:00
|
|
|
$columns_labeled = [];
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
foreach ($this->columns as $key => $val) {
|
|
|
|
if (is_array($val)) {
|
|
|
|
$field = $key;
|
|
|
|
$class = $val;
|
|
|
|
} else {
|
|
|
|
$field = $val;
|
|
|
|
$class = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($field, 'date') !== false) {
|
|
|
|
$class[] = 'group-date-' . (isset($this->options['group_dates_by']) ? $this->options['group_dates_by'] : 'monthyear');
|
2017-03-23 16:39:28 +01:00
|
|
|
} elseif (in_array($field, ['client', 'vendor', 'product', 'user', 'method', 'category', 'project'])) {
|
2017-01-22 11:09:29 +01:00
|
|
|
$class[] = 'group-letter-100';
|
|
|
|
} elseif (in_array($field, ['amount', 'paid', 'balance'])) {
|
|
|
|
$class[] = 'group-number-50';
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = count($class) ? implode(' ', $class) : 'group-false';
|
|
|
|
$label = trans("texts.{$field}");
|
2017-07-31 00:49:24 +02:00
|
|
|
|
2018-01-21 11:16:02 +01:00
|
|
|
$columns_labeled[] = [
|
|
|
|
'label' => $label,
|
|
|
|
'class' => $class,
|
|
|
|
'key' => $field
|
|
|
|
];
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|
2017-08-01 15:37:33 +02:00
|
|
|
|
|
|
|
return $columns_labeled;
|
2017-07-31 00:49:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tableHeader()
|
|
|
|
{
|
2017-08-01 15:37:33 +02:00
|
|
|
$columns_labeled = $this->tableHeaderArray();
|
2017-07-31 00:49:24 +02:00
|
|
|
$str = '';
|
|
|
|
|
2017-08-01 15:37:33 +02:00
|
|
|
foreach ($columns_labeled as $field => $attr)
|
2018-01-21 11:16:02 +01:00
|
|
|
$str .= "<th class=\"{$attr['class']}\" data-priority=\"3\">{$attr['label']}</th>";
|
2017-01-22 11:09:29 +01:00
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
2017-04-26 18:50:43 +02:00
|
|
|
|
|
|
|
// convert the date format to one supported by tablesorter
|
|
|
|
public function convertDateFormat()
|
|
|
|
{
|
|
|
|
$account = Auth::user()->account;
|
|
|
|
$format = $account->getMomentDateFormat();
|
|
|
|
$format = strtolower($format);
|
|
|
|
$format = str_replace('do', '', $format);
|
|
|
|
|
|
|
|
$orignalFormat = $format;
|
|
|
|
$format = preg_replace("/[^mdy]/", '', $format);
|
|
|
|
|
|
|
|
$lastLetter = false;
|
|
|
|
$reportParts = [];
|
|
|
|
$phpParts = [];
|
|
|
|
|
|
|
|
foreach (str_split($format) as $letter) {
|
|
|
|
if ($lastLetter && $letter == $lastLetter) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$lastLetter = $letter;
|
|
|
|
if ($letter == 'm') {
|
|
|
|
$reportParts[] = 'mm';
|
|
|
|
$phpParts[] = 'm';
|
|
|
|
} elseif ($letter == 'd') {
|
|
|
|
$reportParts[] = 'dd';
|
|
|
|
$phpParts[] = 'd';
|
|
|
|
} elseif ($letter == 'y') {
|
|
|
|
$reportParts[] = 'yyyy';
|
|
|
|
$phpParts[] = 'Y';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return join('', $reportParts);
|
|
|
|
}
|
2017-01-22 11:09:29 +01:00
|
|
|
}
|