This commit is contained in:
Dennis Eichhorn 2024-01-02 23:34:17 +00:00
parent c750e20fa3
commit e79230dbf9
10 changed files with 228 additions and 98 deletions

View File

@ -43,7 +43,7 @@ use phpOMS\Views\View;
final class BackendController extends Controller
{
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -88,7 +88,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -146,7 +146,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -180,7 +180,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -201,7 +201,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -222,7 +222,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -269,7 +269,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -339,7 +339,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -368,7 +368,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -394,7 +394,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -415,7 +415,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -436,7 +436,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -481,7 +481,7 @@ final class BackendController extends Controller
}
/**
* Routing end-point for application behaviour.
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response

View File

@ -17,7 +17,7 @@ namespace Modules\Billing\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Permision state enum.
* Permission category enum.
*
* @package Modules\Billing\Models
* @license OMS License 2.0

View File

@ -118,22 +118,26 @@ final class SalesBillMapper extends BillMapper
/**
* Placeholder
*/
public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : FloatInt
public static function getItemAvgSalesPrice(int $item, \DateTime $start, \DateTime $end) : FloatInt
{
$sql = <<<SQL
SELECT
SUM(billing_bill_element_single_netsalesprice) as net_sales,
COUNT(billing_bill_element_total_netsalesprice) as net_count
FROM billing_bill_element
JOIN billing_bill ON billing_bill_element.billing_bill_element_bill = billing_bill.billing_bill_id
WHERE
billing_bill_element_item = {$item}
AND billing_bill_performance_date >= '{$start->format('Y-m-d H:i:s')}'
AND billing_bill_performance_date <= '{$end->format('Y-m-d H:i:s')}';
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
/** @var array $result */
$result = $query->select('SUM(billing_bill_element_single_netsalesprice)', 'COUNT(billing_bill_element_total_netsalesprice)')
->from(self::TABLE)
->leftJoin(BillElementMapper::TABLE)
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
->execute()
?->fetch() ?? [];
return new FloatInt(((int) ($result[1] ?? 0)) === 0 ? 0 : (int) (((int) ($result[0] ?? 0)) / ((int) $result[1])));
return isset($result[0]['net_count'])
? new FloatInt((int) ($result[0]['net_sales'] ?? 0) / ($result[0]['net_count']))
: new FloatInt(0);
}
/**
@ -295,6 +299,21 @@ final class SalesBillMapper extends BillMapper
return self::getAll()->execute($query);
}
/**
* Placeholder
*/
public static function getClientBills(int $id, \DateTime $start, \DateTime $end) : array
{
return self::getAll()
->with('type')
->with('type/l11n')
->where('client', $id)
->where('type/l11n/language', 'en') // @todo fix localization
->where('billDate', $start, '>=')
->where('billDate', $end, '<=')
->execute();
}
/**
* Placeholder
*/
@ -344,23 +363,26 @@ final class SalesBillMapper extends BillMapper
/**
* Placeholder
*/
public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
public static function getItemMonthlySalesCosts(int $item, \DateTime $start, \DateTime $end) : array
{
$sql = <<<SQL
SELECT
SUM(billing_bill_element_total_netsalesprice) as net_sales,
SUM(billing_bill_element_total_netpurchaseprice) as net_costs,
YEAR(billing_bill_performance_date) as year,
MONTH(billing_bill_performance_date) as month
FROM billing_bill_element
JOIN billing_bill ON billing_bill_element.billing_bill_element_bill = billing_bill.billing_bill_id
WHERE
billing_bill_element_item = {$item}
AND billing_bill_performance_date >= '{$start->format('Y-m-d H:i:s')}'
AND billing_bill_performance_date <= '{$end->format('Y-m-d H:i:s')}'
GROUP BY year, month
ORDER BY year ASC, month ASC;
SQL;
$query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::TABLE)
->leftJoin(BillElementMapper::TABLE)
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
->groupBy('year', 'month')
->orderBy(['year', 'month'], ['ASC', 'ASC'])
->execute()
?->fetchAll();
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return $result ?? [];
}
@ -368,22 +390,137 @@ final class SalesBillMapper extends BillMapper
/**
* Placeholder
*/
public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
public static function getClientMonthlySalesCosts(int $client, \DateTime $start, \DateTime $end) : array
{
$sql = <<<SQL
SELECT
SUM(billing_bill_netsales) as net_sales,
SUM(billing_bill_netcosts) as net_costs,
YEAR(billing_bill_performance_date) as year,
MONTH(billing_bill_performance_date) as month
FROM billing_bill
WHERE
billing_bill_client = {$client}
AND billing_bill_performance_date >= '{$start->format('Y-m-d H:i:s')}'
AND billing_bill_performance_date <= '{$end->format('Y-m-d H:i:s')}'
GROUP BY year, month
ORDER BY year ASC, month ASC;
SQL;
$query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_bill_netsales)', 'net_sales')
->selectAs('SUM(billing_bill_netcosts)', 'net_costs')
->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::TABLE)
->where(self::TABLE . '.billing_bill_client', '=', $id)
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
->groupBy('year', 'month')
->orderBy(['year', 'month'], ['ASC', 'ASC'])
->execute()
?->fetchAll();
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return $result ?? [];
}
public static function getItemNetSales(int $item, \DateTime $start, \DateTime $end) : FloatInt
{
$sql = <<<SQL
SELECT SUM(billing_bill_element_single_netsalesprice) as net_sales
FROM billing_bill_element
JOIN billing_bill ON billing_bill_element.billing_bill_element_bill = billing_bill.billing_bill_id
WHERE
billing_bill_element_item = {$item}
AND billing_bill_performance_date >= '{$start->format('Y-m-d H:i:s')}'
AND billing_bill_performance_date <= '{$end->format('Y-m-d H:i:s')}';
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return new FloatInt((int) ($result[0]['net_sales'] ?? 0));
}
public static function getILVHistoric(int $item) : FloatInt
{
$sql = <<<SQL
SELECT SUM(billing_bill_element_single_netsalesprice) as net_sales
FROM billing_bill_element
JOIN billing_bill ON billing_bill_element.billing_bill_element_bill = billing_bill.billing_bill_id
WHERE billing_bill_element_item = {$item}
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return new FloatInt((int) ($result[0]['net_sales'] ?? 0));
}
public static function getItemMRR() : FloatInt
{
return new FloatInt(0);
}
public static function getItemLastOrder(int $item) : ?\DateTime
{
$sql = <<<SQL
SELECT billing_bill_created_at
FROM billing_bill
JOIN billing_bill_element ON billing_bill.billing_bill_id = billing_bill_element.billing_bill_element_id
WHERE billing_bill_element_item = {$item}
ORDER BY billing_bill_created_at DESC
LIMIT 1;
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return isset($result[0]['billing_bill_created_at'])
? new \DateTime(($result[0]['billing_bill_created_at']))
: null;
}
public static function getClientNetSales(int $client, \DateTime $start, \DateTime $end) : FloatInt
{
$sql = <<<SQL
SELECT SUM(billing_bill_netsales) as net_sales
FROM billing_bill
WHERE
billing_bill_client = {$client}
AND billing_bill_performance_date >= '{$start->format('Y-m-d H:i:s')}'
AND billing_bill_performance_date <= '{$end->format('Y-m-d H:i:s')}';
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return new FloatInt((int) ($result[0]['net_sales'] ?? 0));
}
public static function getCLVHistoric(int $client) : FloatInt
{
$sql = <<<SQL
SELECT SUM(billing_bill_netsales) as net_sales
FROM billing_bill
WHERE billing_bill_client = {$client};
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return new FloatInt((int) ($result[0]['net_sales'] ?? 0));
}
public static function getClientMRR() : FloatInt
{
return new FloatInt(0);
}
public static function getClientLastOrder(int $client) : ?\DateTime
{
$sql = <<<SQL
SELECT billing_bill_created_at
FROM billing_bill
WHERE billing_bill_client = {$client}
ORDER BY billing_bill_created_at DESC
LIMIT 1;
SQL;
$query = new Builder(self::$db);
$result = $query->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC);
return isset($result[0]['billing_bill_created_at'])
? new \DateTime(($result[0]['billing_bill_created_at']))
: null;
}
}

View File

@ -49,13 +49,13 @@ echo $this->data['nav']->render(); ?>
<div class="tabview tab-2 col-simple">
<div class="box">
<ul class="tab-links">
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label></li>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label></li>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label></li>
<li><label for="c-tab-4"><?= $this->getHtml('Archive'); ?></label></li>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label></li>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label></li>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label></li>
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label>
<li><label for="c-tab-4"><?= $this->getHtml('Archive'); ?></label>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label>
</ul>
</div>
<div class="tab-content col-simple">
@ -349,7 +349,7 @@ echo $this->data['nav']->render(); ?>
<?php if ($editable) : ?>
<div class="box">
<input type="submit" class="add-form" value="<?= $this->getHtml('Add', '0', '0') ?>" form="invoiceElements">
<input type="submit" class="add-form" value="<?= $this->getHtml('Add', '0', '0'); ?>" form="invoiceElements">
</div>
<?php endif; ?>
</div>
@ -481,7 +481,7 @@ echo $this->data['nav']->render(); ?>
<?php if ($editable) : ?>
<div class="box">
<input type="submit" class="add-payment-form" value="<?= $this->getHtml('Add', '0', '0') ?>" form="paymentPlan">
<input type="submit" class="add-payment-form" value="<?= $this->getHtml('Add', '0', '0'); ?>" form="paymentPlan">
</div>
<?php endif; ?>
</div>
@ -497,7 +497,7 @@ echo $this->data['nav']->render(); ?>
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Logs'); ?><i class="g-icon download btn end-xs">download</i></div>
<table class="default">
<table class="default sticky">
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>

View File

@ -12,7 +12,6 @@
*/
declare(strict_types=1);
use phpOMS\System\File\FileUtils;
use phpOMS\Uri\UriFactory;
// Media helper functions (e.g. file icon generator)
@ -40,13 +39,13 @@ echo $this->data['nav']->render(); ?>
<div class="tabview tab-2 col-simple">
<div class="box">
<ul class="tab-links">
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label></li>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label></li>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label></li>
<li><label for="c-tab-4"><?= $this->getHtml('Original'); ?></label></li>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label></li>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label></li>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label></li>
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label>
<li><label for="c-tab-4"><?= $this->getHtml('Original'); ?></label>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label>
</ul>
</div>
<div class="tab-content col-simple">
@ -152,7 +151,7 @@ echo $this->data['nav']->render(); ?>
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Invoice'); ?><i class="g-icon download btn end-xs">download</i></div>
<div class="slider">
<table class="default" id="invoice-item-list">
<table class="default sticky" id="invoice-item-list">
<thead>
<tr>
<td>
@ -279,7 +278,7 @@ echo $this->data['nav']->render(); ?>
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Logs'); ?><i class="g-icon download btn end-xs">download</i></div>
<table class="default">
<table class="default sticky">
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?>

View File

@ -36,13 +36,13 @@ echo $this->data['nav']->render(); ?>
<div class="tabview tab-2">
<div class="box">
<ul class="tab-links">
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label></li>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label></li>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label></li>
<li><label for="c-tab-4"><?= $this->getHtml('Original'); ?></label></li>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label></li>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label></li>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label></li>
<li><label for="c-tab-1"><?= $this->getHtml('Invoice'); ?></label>
<li><label for="c-tab-2"><?= $this->getHtml('Items'); ?></label>
<li><label for="c-tab-3"><?= $this->getHtml('Preview'); ?></label>
<li><label for="c-tab-4"><?= $this->getHtml('Original'); ?></label>
<li><label for="c-tab-5"><?= $this->getHtml('Payment'); ?></label>
<li><label for="c-tab-6"><?= $this->getHtml('Media'); ?></label>
<li><label for="c-tab-7"><?= $this->getHtml('Logs'); ?></label>
</ul>
</div>
<div class="tab-content">
@ -147,7 +147,7 @@ echo $this->data['nav']->render(); ?>
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Invoice'); ?><i class="g-icon download btn end-xs">download</i></div>
<table class="default" id="invoice-item-list">
<table class="default sticky" id="invoice-item-list">
<thead>
<tr>
<td>
@ -275,7 +275,7 @@ echo $this->data['nav']->render(); ?>
<table class="layout wf-100">
<tbody>
<tr><td colspan="2"><label for="iMedia"><?= $this->getHtml('Media'); ?></label>
<tr><td><input type="text" id="iMedia" placeholder="&#xf15b; File"><td><button><?= $this->getHtml('Select'); ?></button>
<tr><td><input type="text" id="iMedia" placeholder="File"><td><button><?= $this->getHtml('Select'); ?></button>
<tr><td colspan="2"><label for="iUpload"><?= $this->getHtml('Upload'); ?></label>
<tr><td><input type="file" id="iUpload" form="fTask"><input form="fTask" type="hidden" name="type"><td>
</table>
@ -287,7 +287,7 @@ echo $this->data['nav']->render(); ?>
<div class="col-xs-12 col-md-6 col-lg-8">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Media'); ?><i class="g-icon download btn end-xs">download</i></div>
<table class="default" id="invoice-item-list">
<table class="default sticky" id="invoice-item-list">
<thead>
<tr>
<td>
@ -324,7 +324,7 @@ echo $this->data['nav']->render(); ?>
<div class="row">
<div class="col-xs-12">
<div class="box wf-100">
<table class="default">
<table class="default sticky">
<caption><?= $this->getHtml('Logs'); ?><i class="g-icon end-xs download btn">download</i></caption>
<thead>
<tr>

View File

@ -14,7 +14,6 @@
"name": "Jingga",
"website": "jingga.app"
},
"description": "Accounting module.",
"directory": "Billing",
"dependencies": {
"Admin": "1.0.0",

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace Modules\Billing\tests\Controller\Api;
use phpOMS\Account\AccountStatus;
use phpOMS\Account\AccountType;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;

View File

@ -14,14 +14,11 @@ declare(strict_types=1);
namespace Modules\Billing\tests\Controller\Api;
use phpOMS\Account\AccountStatus;
use phpOMS\Account\AccountType;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\System\File\Local\Directory;
use phpOMS\Uri\HttpUri;
use phpOMS\Utils\RnG\DateTime;
use phpOMS\Utils\TestUtils;
trait ApiPurchaseControllerTrait