Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Core/Model/Base/JoinModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use FacturaScripts\Core\Base\DataBase;
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
use FacturaScripts\Core\Cache;
use FacturaScripts\Core\Where;

/**
* @deprecated Usar FacturaScripts\Core\Template\JoinModel en su lugar.
Expand Down Expand Up @@ -130,7 +131,7 @@ public function __set($name, $value)
/**
* Load data for the indicated where.
*
* @param DataBaseWhere[] $where filters to apply to model records.
* @param DataBaseWhere[]|Where[] $where filters to apply to model records.
* @param array $order fields to use in the sorting. For example ['code' => 'ASC']
* @param int $offset
* @param int $limit
Expand All @@ -142,7 +143,7 @@ public function all(array $where, array $order = [], int $offset = 0, int $limit
$result = [];
if ($this->checkTables()) {
$sql = 'SELECT ' . $this->fieldsList() . ' FROM ' . $this->getSQLFrom()
. DataBaseWhere::getSQLWhere($where) . $this->getGroupBy() . $this->getOrderBy($order);
. Where::multiSqlLegacy($where) . $this->getGroupBy() . $this->getOrderBy($order);
foreach (self::$dataBase->selectLimit($sql, $limit, $offset) as $row) {
$result[] = new static($row);
}
Expand All @@ -164,7 +165,7 @@ public function clear()
/**
* Returns the number of records that meet the condition.
*
* @param DataBaseWhere[] $where filters to apply to records.
* @param DataBaseWhere[]|Where[] $where filters to apply to records.
*
* @return int
*/
Expand All @@ -186,7 +187,7 @@ public function count(array $where = []): int

$sql = 'SELECT ' . $groupFields . 'COUNT(*) count_total'
. ' FROM ' . $this->getSQLFrom()
. DataBaseWhere::getSQLWhere($where)
. Where::multiSqlLegacy($where)
. $this->getGroupBy();

$data = self::$dataBase->select($sql);
Expand Down Expand Up @@ -285,7 +286,7 @@ public function loadFromCode($cod, array $where = [], array $orderby = []): bool

$sql = 'SELECT ' . $this->fieldsList()
. ' FROM ' . $this->getSQLFrom()
. DataBaseWhere::getSQLWhere($where)
. Where::multiSqlLegacy($where)
. $this->getGroupBy()
. $this->getOrderBy($orderby);

Expand Down Expand Up @@ -330,8 +331,8 @@ public function totalSum(string $field, array $where = []): float
$field = $fields[$field] ?? $field;

$sql = false !== strpos($field, '(') ?
'SELECT ' . $field . ' AS total_sum' . ' FROM ' . $this->getSQLFrom() . DataBaseWhere::getSQLWhere($where) :
'SELECT SUM(' . $field . ') AS total_sum' . ' FROM ' . $this->getSQLFrom() . DataBaseWhere::getSQLWhere($where);
'SELECT ' . $field . ' AS total_sum' . ' FROM ' . $this->getSQLFrom() . Where::multiSqlLegacy($where) :
'SELECT SUM(' . $field . ') AS total_sum' . ' FROM ' . $this->getSQLFrom() . Where::multiSqlLegacy($where);

$data = self::$dataBase->select($sql);
$sum = count($data) == 1 ? (float)$data[0]['total_sum'] : 0.0;
Expand Down
Loading