Exclude self-produced product prices from spending reports (#2596)

* Exclude self-produced product prices from spending reports

* Fix SQL query

* Code style

---------

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
Daniel Reinoso
2024-10-25 18:19:00 -03:00
committed by GitHub
parent 9e1020b7f8
commit 5b48004449
2 changed files with 28 additions and 2 deletions

View File

@@ -9,16 +9,18 @@ class StockReportsController extends BaseController
{
public function Spendings(Request $request, Response $response, array $args)
{
$where = "pph.transaction_type != 'self-production'";
if (isset($request->getQueryParams()['start_date']) && isset($request->getQueryParams()['end_date']) && IsIsoDate($request->getQueryParams()['start_date']) && IsIsoDate($request->getQueryParams()['end_date']))
{
$startDate = $request->getQueryParams()['start_date'];
$endDate = $request->getQueryParams()['end_date'];
$where = "pph.purchased_date BETWEEN '$startDate' AND '$endDate'";
$where .= " AND pph.purchased_date BETWEEN '$startDate' AND '$endDate'";
}
else
{
// Default to this month
$where = "pph.purchased_date >= DATE(DATE('now', 'localtime'), 'start of month')";
$where .= " AND pph.purchased_date >= DATE(DATE('now', 'localtime'), 'start of month')";
}
$groupBy = 'product';