From e79230dbf93d916aa3881f26d66ca5ba2ab0cda5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 2 Jan 2024 23:34:17 +0000 Subject: [PATCH] update --- Controller/BackendController.php | 30 +-- Models/PermissionCategory.php | 2 +- Models/SalesBillMapper.php | 223 ++++++++++++++---- Theme/Backend/bill-create.tpl.php | 20 +- Theme/Backend/purchase-bill.tpl.php | 19 +- Theme/Backend/user-purchase-bill.tpl.php | 22 +- info.json | 1 - .../Controller/Api/ApiBillControllerTrait.php | 2 - .../Api/ApiPurchaseControllerTrait.php | 5 +- tests/Controller/ApiControllerTest.php | 2 +- 10 files changed, 228 insertions(+), 98 deletions(-) diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 606917f..e9d735e 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -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 @@ -139,14 +139,14 @@ final class BackendController extends Controller $logs = \array_merge($logs, $logsElements); - $view->data['logs'] = $logs; + $view->data['logs'] = $logs; $view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response); return $view; } /** - * 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 @@ -387,14 +387,14 @@ final class BackendController extends Controller $bill = StockBillMapper::get()->where('id', (int) $request->getData('id'))->execute(); - $view->data['bill'] = $bill; + $view->data['bill'] = $bill; $view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response); return $view; } /** - * 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 diff --git a/Models/PermissionCategory.php b/Models/PermissionCategory.php index a9968a0..1987ca4 100755 --- a/Models/PermissionCategory.php +++ b/Models/PermissionCategory.php @@ -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 diff --git a/Models/SalesBillMapper.php b/Models/SalesBillMapper.php index 7ebf142..a1d858e 100755 --- a/Models/SalesBillMapper.php +++ b/Models/SalesBillMapper.php @@ -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 = <<= '{$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 { - $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(); + $sql = <<= '{$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->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 { - $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(); + $sql = <<= '{$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->raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC); return $result ?? []; } + + public static function getItemNetSales(int $item, \DateTime $start, \DateTime $end) : FloatInt + { + $sql = <<= '{$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 = <<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 = <<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 = <<= '{$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 = <<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 = <<raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC); + + return isset($result[0]['billing_bill_created_at']) + ? new \DateTime(($result[0]['billing_bill_created_at'])) + : null; + } } diff --git a/Theme/Backend/bill-create.tpl.php b/Theme/Backend/bill-create.tpl.php index 2dc1319..30f10c0 100755 --- a/Theme/Backend/bill-create.tpl.php +++ b/Theme/Backend/bill-create.tpl.php @@ -49,13 +49,13 @@ echo $this->data['nav']->render(); ?>
@@ -349,7 +349,7 @@ echo $this->data['nav']->render(); ?>
- +
@@ -481,7 +481,7 @@ echo $this->data['nav']->render(); ?>
- +
@@ -497,7 +497,7 @@ echo $this->data['nav']->render(); ?>
getHtml('Logs'); ?>download
- +
getHtml('ID', '0', '0'); ?> diff --git a/Theme/Backend/purchase-bill.tpl.php b/Theme/Backend/purchase-bill.tpl.php index 625f479..46fb14f 100755 --- a/Theme/Backend/purchase-bill.tpl.php +++ b/Theme/Backend/purchase-bill.tpl.php @@ -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(); ?>
@@ -152,7 +151,7 @@ echo $this->data['nav']->render(); ?>
getHtml('Invoice'); ?>download
- +
@@ -279,7 +278,7 @@ echo $this->data['nav']->render(); ?>
getHtml('Logs'); ?>download
- +
getHtml('ID', '0', '0'); ?> diff --git a/Theme/Backend/user-purchase-bill.tpl.php b/Theme/Backend/user-purchase-bill.tpl.php index 6328a73..2c1a8bd 100755 --- a/Theme/Backend/user-purchase-bill.tpl.php +++ b/Theme/Backend/user-purchase-bill.tpl.php @@ -36,13 +36,13 @@ echo $this->data['nav']->render(); ?>
@@ -147,7 +147,7 @@ echo $this->data['nav']->render(); ?>
getHtml('Invoice'); ?>download
- +
@@ -275,7 +275,7 @@ echo $this->data['nav']->render(); ?>
-
+
@@ -287,7 +287,7 @@ echo $this->data['nav']->render(); ?>
getHtml('Media'); ?>download
- +
@@ -324,7 +324,7 @@ echo $this->data['nav']->render(); ?>
- +
diff --git a/info.json b/info.json index 3f570d3..ea95bcf 100755 --- a/info.json +++ b/info.json @@ -14,7 +14,6 @@ "name": "Jingga", "website": "jingga.app" }, - "description": "Accounting module.", "directory": "Billing", "dependencies": { "Admin": "1.0.0", diff --git a/tests/Controller/Api/ApiBillControllerTrait.php b/tests/Controller/Api/ApiBillControllerTrait.php index 3f1169e..9c7decd 100644 --- a/tests/Controller/Api/ApiBillControllerTrait.php +++ b/tests/Controller/Api/ApiBillControllerTrait.php @@ -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; diff --git a/tests/Controller/Api/ApiPurchaseControllerTrait.php b/tests/Controller/Api/ApiPurchaseControllerTrait.php index 13489b2..b995e60 100644 --- a/tests/Controller/Api/ApiPurchaseControllerTrait.php +++ b/tests/Controller/Api/ApiPurchaseControllerTrait.php @@ -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 @@ -44,7 +41,7 @@ trait ApiPurchaseControllerTrait for ($i = 0; $i < $count; ++$i) { $toUpload = []; - $file = $invoiceDocs[$i]; + $file = $invoiceDocs[$i]; $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index e93b1e2..76644de 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -88,7 +88,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $this->app->accountManager->add($account); $this->app->router = new WebRouter(); - $this->module = $this->app->moduleManager->get('Billing', 'ApiBill'); + $this->module = $this->app->moduleManager->get('Billing', 'ApiBill'); $this->modulePurchase = $this->app->moduleManager->get('Billing', 'ApiPurchase'); TestUtils::setMember($this->module, 'app', $this->app);
getHtml('Logs'); ?>download