Add functionality for handling draft invoices in statistics
Introduced new endpoints and methods to incorporate draft invoice data into economic statistics. This includes calculating totals across various timeframes and aggregations by departments. Updated routes and traits to support these additions, ensuring seamless integration with the existing economic module.
This commit is contained in:
@@ -4,8 +4,10 @@ namespace endpoints;
|
||||
require_once WD . '/modules/economic/endpoints/invoices/economic_invoices_totals_endpoint.php';
|
||||
require_once WD . '/modules/economic/endpoints/invoices/economic_invoices_sent_endpoint.php';
|
||||
require_once WD . '/modules/economic/endpoints/invoices/economic_invoices_booked_endpoint.php';
|
||||
require_once WD . '/modules/economic/endpoints/invoices/economic_invoices_drafts_endpoint.php';
|
||||
|
||||
use endpoints\orders\economic_invoices_booked_endpoint;
|
||||
use endpoints\orders\economic_invoices_drafts_endpoint;
|
||||
use endpoints\orders\economic_invoices_sent_endpoint;
|
||||
use endpoints\orders\economic_invoices_totals_endpoint;
|
||||
use traits\economic_endpoint_t;
|
||||
@@ -29,11 +31,17 @@ class economic_invoices_endpoint
|
||||
* @var economic_invoices_booked_endpoint
|
||||
*/
|
||||
public economic_invoices_booked_endpoint $booked;
|
||||
/**
|
||||
* Any endpoints reached by the /invoices/drafts endpoint
|
||||
* @var economic_invoices_drafts_endpoint
|
||||
*/
|
||||
public economic_invoices_drafts_endpoint $drafts;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->totals = new economic_invoices_totals_endpoint();
|
||||
$this->sent = new economic_invoices_sent_endpoint();
|
||||
$this->booked = new economic_invoices_booked_endpoint();
|
||||
$this->drafts = new economic_invoices_drafts_endpoint();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -13,10 +13,10 @@ class economic_invoices_booked_endpoint
|
||||
* @param string $filter Set the filter using the self::filter method
|
||||
* @return object {collection: [order], pagination: {maxPageSize: number, skipPages: number, results: number}}
|
||||
*/
|
||||
public function get(array $filters = []): object
|
||||
public function get(array $filters = [], array $pagination = []): object
|
||||
{
|
||||
$response = $this->send_request(
|
||||
'/invoices/booked/?filter=' . self::filters($filters),
|
||||
'/invoices/booked/?filter=' . self::filters($filters) . self::pagination($pagination),
|
||||
'GET'
|
||||
);
|
||||
// Return the response as an object
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace endpoints\orders;
|
||||
|
||||
use traits\economic_endpoint_t;
|
||||
|
||||
class economic_invoices_drafts_endpoint
|
||||
{
|
||||
use economic_endpoint_t;
|
||||
|
||||
/**
|
||||
* List draft invoices
|
||||
* @param array $filters
|
||||
* @param array $pagination
|
||||
* @return object {collection: [order], pagination: {maxPageSize: number, skipPages: number, results: number}}
|
||||
*/
|
||||
public function get(array $filters = [], array $pagination = []): object
|
||||
{
|
||||
$response = $this->send_request(
|
||||
'/invoices/drafts/?filter=' . self::filters($filters) . self::pagination($pagination),
|
||||
'GET'
|
||||
);
|
||||
// Return the response as an object
|
||||
return json_decode($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get invoice lines
|
||||
* @param array $invoice_ids List of invoice ids to get lines for (e.g. [1, 2, 3])
|
||||
* @param array $filters Set the filter using the self::filter method
|
||||
* @return array {invoice_id: {collection: [invoice_line], pagination: {maxPageSize: number, skipPages: number, results: number}}}
|
||||
*/
|
||||
public function get_invoice_lines(array $invoice_ids, array $filters = []): array
|
||||
{
|
||||
$tmp_invoices = [];
|
||||
foreach ( $invoice_ids as $invoice ) {
|
||||
$response = $this->send_request(
|
||||
'/invoices/drafts/' . $invoice . '/?filter=' . self::filters($filters),
|
||||
'GET'
|
||||
);
|
||||
$tmp_invoices[$invoice] = json_decode($response)->lines;
|
||||
}
|
||||
return $tmp_invoices;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -134,5 +134,221 @@ class statisticsRoute
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Department draft invoice totals */
|
||||
$this->get('/statistics/economic/totals/department_draft_invoice_totals', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_department_draft_invoice_totals');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'DEPARTMENT_DRAFT_INVOICE_TOTALS', 'User requested department draft invoice totals');
|
||||
$statics = new statistics();
|
||||
// Return the department draft invoice totals
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_department_draft_invoice_totals()
|
||||
->get_response()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'DEPARTMENT_DRAFT_INVOICE_TOTALS', 'User requested department draft invoice totals');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Total income today */
|
||||
$this->get('/statistics/income/today', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_today');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_TODAY', 'User requested total income today');
|
||||
$statics = new statistics();
|
||||
// Return the total income today
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_totals_today()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_TODAY', 'User requested total income today');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Total income yesterday */
|
||||
$this->get('/statistics/income/yesterday', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_yesterday');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_YESTERDAY', 'User requested total income yesterday');
|
||||
$statics = new statistics();
|
||||
// Return the total income yesterday
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_totals_yesterday()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_YESTERDAY', 'User requested total income yesterday');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Total income this month */
|
||||
$this->get('/statistics/income/this-month', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_this_month');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_THIS_MONTH', 'User requested total income this month');
|
||||
$statics = new statistics();
|
||||
// Return the total income this month
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_totals_this_month()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_THIS_MONTH', 'User requested total income this month');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Total income last month */
|
||||
$this->get('/statistics/income/last-month', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_last_month');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_LAST_MONTH', 'User requested total income last month');
|
||||
$statics = new statistics();
|
||||
// Return the total income last month
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_totals_last_month()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_LAST_MONTH', 'User requested total income last month');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
/** Statistics >> Economic >> Total income this year */
|
||||
$this->get('/statistics/income/this-year', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$EMAIL_WASH_CERTIFICATE_TOKEN,
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_this_year');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_THIS_YEAR', 'User requested total income this year');
|
||||
$statics = new statistics();
|
||||
// Return the total income this year
|
||||
$response->success(
|
||||
$statics
|
||||
->economic()
|
||||
->get_totals_this_year()
|
||||
);
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_THIS_YEAR', 'User requested total income this year');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
|
||||
$this->get('/statistics/income/departments', function () {
|
||||
// Require the user to be logged in
|
||||
global
|
||||
/** @var response $response */
|
||||
$response;
|
||||
$this->requirePermission('statistics_economic_income_today_departments');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 1, $user->id, 'TOTAL_INCOME_TODAY_DEPARTMENTS', 'User requested total income today by departments');
|
||||
$invoices = (new statistics())->economic()->get_department_sent_invoice_totals()->get_raw_data();
|
||||
$drafts = (new statistics())->economic()->get_department_draft_invoice_totals()->get_raw_data();
|
||||
$totals = [];
|
||||
// Loop through every department and add the drafts to the invoices
|
||||
foreach ( $invoices as $key => $invoice ) {
|
||||
if (isset($drafts[$key])) {
|
||||
// Add the totalNetAmount to the drafts in the totals array
|
||||
$totals[$key]['totalNetAmount'] = $invoice['totalNetAmount'] + $drafts[$key]['totalNetAmount'];
|
||||
} else {
|
||||
// Add the totalNetAmount to the invoices in the totals array
|
||||
$totals[$key]['totalNetAmount'] = $invoice['totalNetAmount'];
|
||||
}
|
||||
// Add the department name to the totals array
|
||||
$totals[$key]['id'] = $key;
|
||||
$totals[$key]['name'] = $invoice['name'];
|
||||
|
||||
}
|
||||
// Save the response
|
||||
$response->success(
|
||||
$totals
|
||||
);
|
||||
|
||||
} else {
|
||||
// Log the incident
|
||||
(new logs_o())->add('statistics', 'global', 0, 0, 'TOTAL_INCOME_TODAY_DEPARTMENTS', 'User requested total income today by departments');
|
||||
// Return an error
|
||||
$response->error('Invalid session', 400);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,16 @@ class economic_s
|
||||
}
|
||||
// Get the invoice lines
|
||||
$invoice_lines = $economic->invoices->booked->get_invoice_lines($booked_invoice_numbers);
|
||||
|
||||
// Clear the invoice lines that has quantity 0, since they don't have any value to the statistics
|
||||
foreach ( $invoice_lines as $invoice_id => $lines ) {
|
||||
foreach ( $lines as $key => $line ) {
|
||||
if ($line->quantity == 0) {
|
||||
unset($invoice_lines[$invoice_id][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the net amount, invoice count and products array to the departments
|
||||
foreach ( $invoice_lines as $invoice_id => $lines ) {
|
||||
foreach ( $lines as $line ) {
|
||||
@@ -125,24 +135,251 @@ class economic_s
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data sets
|
||||
foreach ( $departments as $department ) {
|
||||
$this->add_data_set($department['name'], [
|
||||
'Faktureret (DKK)' => $department['totalNetAmount'],
|
||||
]);
|
||||
$this->set_raw_data($department['departmentNumber'], [
|
||||
'invoiceCount' => $department['invoiceCount'],
|
||||
'products' => $department['products'],
|
||||
'totalNetAmount' => $department['totalNetAmount'],
|
||||
'name' => $department['name'],
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get department draft invoice total amount and count
|
||||
* @return $this
|
||||
*/
|
||||
public function get_department_draft_invoice_totals(): economic_s
|
||||
{
|
||||
// Get the economic class
|
||||
$economic = new economic();
|
||||
|
||||
// Get the totals
|
||||
$invoices = $economic->invoices->drafts->get([
|
||||
'(date$gte:' . $this->start . '$and:date$lte:' . $this->end . ')' => '', // To allow for time filtering, we need to add the time frame to the query
|
||||
])->collection;
|
||||
|
||||
// Get the departments
|
||||
$departments = $economic->departments->departments->get(
|
||||
[],
|
||||
[
|
||||
'skipPages' => 0,
|
||||
'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000.
|
||||
]
|
||||
)->collection;
|
||||
/**
|
||||
* To get the department name from the department number, we need to create an array with the department number as the key and the department name as the value.
|
||||
* This results in an array like this:
|
||||
* departmentNumber => name
|
||||
* [
|
||||
* 10 => ['name' => 'Department 1', 'departmentNumber' => 10, 'products' => ['product 1' => 10, 'product 2' => 20], 'totalNetAmount' => 0],
|
||||
* 20 => ['name' => 'Department 2', 'departmentNumber' => 20, 'products' => ['product 1' => 10, 'product 2' => 20], 'totalNetAmount' => 0],
|
||||
* ]
|
||||
*/
|
||||
$departments_temp = array_column($departments, 'name', 'departmentNumber');
|
||||
// Add an unknown (0) department, in case the departmentDistributionNumber is not set
|
||||
$departments_temp[0] = 'Unknown';
|
||||
$departments = [];
|
||||
foreach ( $departments_temp as $departmentNumber => $name ) {
|
||||
$departments[$departmentNumber] = [
|
||||
'name' => $name,
|
||||
'departmentNumber' => $departmentNumber,
|
||||
'products' => [],
|
||||
'totalNetAmount' => 0,
|
||||
'invoiceCount' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
// Get the draftInvoiceNumber for the draft invoices
|
||||
$draft_invoice_number = [];
|
||||
foreach ( $invoices as $invoice ) {
|
||||
$draft_invoice_number[] = $invoice->draftInvoiceNumber;
|
||||
}
|
||||
// Get the invoice lines
|
||||
$invoice_lines = $economic->invoices->drafts->get_invoice_lines($draft_invoice_number);
|
||||
|
||||
// Clear the invoice lines that has quantity 0, since they don't have any value to the statistics
|
||||
foreach ( $invoice_lines as $invoice_id => $lines ) {
|
||||
foreach ( $lines as $key => $line ) {
|
||||
// If the quantity key does not exist, we can just set the quantity to 0
|
||||
if (!isset($line->quantity)) {
|
||||
$line->quantity = 0;
|
||||
}
|
||||
// If the quantity is 0, we can unset the line, since it does not have any value to the statistics
|
||||
if ($line->quantity == 0) {
|
||||
unset($invoice_lines[$invoice_id][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the net amount, invoice count and products array to the departments
|
||||
foreach ( $invoice_lines as $invoice_id => $lines ) {
|
||||
foreach ( $lines as $line ) {
|
||||
// Check if the departmentDistributionNumber is set and the quantity is greater than 0
|
||||
$tmp_department = 0;
|
||||
if (isset($line->departmentalDistribution->departmentalDistributionNumber)) {
|
||||
// Set the department to unknown
|
||||
$tmp_department = $line->departmentalDistribution->departmentalDistributionNumber;
|
||||
}
|
||||
if ($line->quantity == 0) {
|
||||
// Skip the line if the quantity is 0
|
||||
continue;
|
||||
}
|
||||
// Add the net amount to the department
|
||||
$departments[$tmp_department]['totalNetAmount'] += $line->totalNetAmount;
|
||||
// Add the product to the department
|
||||
if (!isset($departments[$tmp_department]['products'][$line->product->productNumber])) {
|
||||
$departments[$tmp_department]['products'][$line->product->productNumber] = 0;
|
||||
}
|
||||
$departments[$tmp_department]['products'][$line->product->productNumber] += $line->quantity;
|
||||
// Add the invoice count to the department
|
||||
$departments[$tmp_department]['invoiceCount']++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data sets
|
||||
foreach ( $departments as $department ) {
|
||||
$this->add_data_set($department['name'], [
|
||||
'Faktureret (DKK)' => $department['totalNetAmount'],
|
||||
]);
|
||||
$this->set_raw_data($department['departmentNumber'], [
|
||||
'invoiceCount' => $department['invoiceCount'],
|
||||
'products' => $department['products'],
|
||||
'totalNetAmount' => $department['totalNetAmount'],
|
||||
'name' => $department['name'],
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount today
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_today(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-m-d'), date('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount today
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
protected function get_totals_in_time_frame(string $start = null, string $end = null): array
|
||||
{
|
||||
// Set the date range to the current day, if no start and end date is set
|
||||
$start = $start ?? date('Y-m-d');
|
||||
$end = $end ?? date('Y-m-d');
|
||||
|
||||
// Get the economic class
|
||||
$economic = new economic();
|
||||
$drafts = $economic->invoices->drafts->get([
|
||||
'(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query
|
||||
],
|
||||
[
|
||||
'skipPages' => 0,
|
||||
'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000.
|
||||
]
|
||||
)->collection;
|
||||
$booked = $economic->invoices->booked->get([
|
||||
'(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query
|
||||
],
|
||||
[
|
||||
'skipPages' => 0,
|
||||
'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000.
|
||||
]
|
||||
)->collection;
|
||||
$drafts_total = 0;
|
||||
$booked_total = 0;
|
||||
|
||||
foreach ( $drafts as $draft_obj ) {
|
||||
$drafts_total += $draft_obj->netAmountInBaseCurrency;
|
||||
}
|
||||
|
||||
foreach ( $booked as $booked_obj ) {
|
||||
$booked_total += $booked_obj->netAmountInBaseCurrency;
|
||||
}
|
||||
|
||||
return [
|
||||
'drafts' => [
|
||||
'netAmountInBaseCurrency' => $drafts_total,
|
||||
'invoiceCount' => count($drafts),
|
||||
],
|
||||
'booked' => [
|
||||
'netAmountInBaseCurrency' => $booked_total,
|
||||
'invoiceCount' => count($booked),
|
||||
],
|
||||
'total' => $drafts_total + $booked_total,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount this week
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_this_week(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-m-d', strtotime('monday this week')), date('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount this month 1st to last day of the month
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_this_month(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-m-01'), date('Y-m-t'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount last month 1st to last day of the month
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_last_month(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-m-01', strtotime('last month')), date('Y-m-t', strtotime('last month')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount last year
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_last_year(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-01-01', strtotime('last year')), date('Y-12-31', strtotime('last year')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount yesterday
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_yesterday(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime('yesterday')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total invoiced amount this year
|
||||
* @return array ['drafts' => object, 'booked' => object]
|
||||
*/
|
||||
public function get_totals_this_year(): array
|
||||
{
|
||||
return self::get_totals_in_time_frame(date('Y-01-01'), date('Y-12-31'));
|
||||
}
|
||||
|
||||
public function get_totals_departments()
|
||||
{
|
||||
// Get the
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace traits;
|
||||
|
||||
use statistics\bookings_s;
|
||||
use statistics\economic_s;
|
||||
use statistics\orders_s;
|
||||
|
||||
trait statistic_t
|
||||
{
|
||||
@@ -49,8 +51,7 @@ trait statistic_t
|
||||
* If the start date is not set, the default is fetched from self::get_default_start_date()
|
||||
* @var string
|
||||
*/
|
||||
public string $start;
|
||||
|
||||
public string $start; // The raw data for the statistics, this is used to merge the data sets.
|
||||
/**
|
||||
* The end date of the date range
|
||||
* This is set by the set_date_range method, and is used to filter the data.
|
||||
@@ -59,6 +60,7 @@ trait statistic_t
|
||||
* @var string
|
||||
*/
|
||||
public string $end;
|
||||
protected array $raw_data = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -205,5 +207,26 @@ trait statistic_t
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw data for the statistics
|
||||
* @return array
|
||||
*/
|
||||
public function get_raw_data(): array
|
||||
{
|
||||
return $this->raw_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw data for the statistics
|
||||
* @param string $key
|
||||
* @param array $raw_data The raw data for the statistics
|
||||
* @return bookings_s|economic_s|orders_s|statistic_t
|
||||
*/
|
||||
public function set_raw_data(string $key, array $raw_data): self
|
||||
{
|
||||
$this->raw_data[$key] = $raw_data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user