mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-14 02:32:04 -06:00
Update date related code to fix several issues with SQLite
This commit is contained in:
parent
36f67793cb
commit
089300d57e
@ -342,7 +342,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
*/
|
||||
public function setAfter(Carbon $after): JournalCollectorInterface
|
||||
{
|
||||
$afterStr = $after->format('Y-m-d');
|
||||
$afterStr = $after->format('Y-m-d 00:00:00');
|
||||
$this->query->where('transaction_journals.date', '>=', $afterStr);
|
||||
Log::debug(sprintf('JournalCollector range is now after %s (inclusive)', $afterStr));
|
||||
|
||||
@ -378,7 +378,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
*/
|
||||
public function setBefore(Carbon $before): JournalCollectorInterface
|
||||
{
|
||||
$beforeStr = $before->format('Y-m-d');
|
||||
$beforeStr = $before->format('Y-m-d 00:00:00');
|
||||
$this->query->where('transaction_journals.date', '<=', $beforeStr);
|
||||
Log::debug(sprintf('JournalCollector range is now before %s (inclusive)', $beforeStr));
|
||||
|
||||
@ -565,8 +565,8 @@ class JournalCollector implements JournalCollectorInterface
|
||||
public function setRange(Carbon $start, Carbon $end): JournalCollectorInterface
|
||||
{
|
||||
if ($start <= $end) {
|
||||
$startStr = $start->format('Y-m-d');
|
||||
$endStr = $end->format('Y-m-d');
|
||||
$startStr = $start->format('Y-m-d 00:00:00');
|
||||
$endStr = $end->format('Y-m-d 00:00:00');
|
||||
$this->query->where('transaction_journals.date', '>=', $startStr);
|
||||
$this->query->where('transaction_journals.date', '<=', $endStr);
|
||||
Log::debug(sprintf('JournalCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
||||
|
@ -43,8 +43,6 @@ class BudgetLimit extends Model
|
||||
'end_date' => 'date',
|
||||
'repeats' => 'boolean',
|
||||
];
|
||||
/** @var array */
|
||||
protected $dates = ['start_date', 'end_date'];
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
|
@ -62,8 +62,7 @@ class TransactionJournal extends Model
|
||||
'encrypted' => 'boolean',
|
||||
'completed' => 'boolean',
|
||||
];
|
||||
/** @var array */
|
||||
protected $dates = ['date', 'interest_date', 'book_date', 'process_date'];
|
||||
|
||||
/** @var array */
|
||||
protected $fillable
|
||||
= ['user_id', 'transaction_type_id', 'bill_id', 'interest_date', 'book_date', 'process_date',
|
||||
|
@ -367,8 +367,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
public function getYearAverage(Bill $bill, Carbon $date): string
|
||||
{
|
||||
$journals = $bill->transactionJournals()
|
||||
->where('date', '>=', $date->year . '-01-01')
|
||||
->where('date', '<=', $date->year . '-12-31')
|
||||
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
||||
->where('date', '<=', $date->year . '-12-31 00:00:00')
|
||||
->get();
|
||||
$sum = '0';
|
||||
$count = strval($journals->count());
|
||||
|
@ -489,8 +489,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
$availableBudget = new AvailableBudget;
|
||||
$availableBudget->user()->associate($this->user);
|
||||
$availableBudget->transactionCurrency()->associate($currency);
|
||||
$availableBudget->start_date = $start;
|
||||
$availableBudget->end_date = $end;
|
||||
$availableBudget->start_date = $start->format('Y-m-d 00:00:00');
|
||||
$availableBudget->end_date = $end->format('Y-m-d 00:00:00');
|
||||
}
|
||||
$availableBudget->amount = $amount;
|
||||
$availableBudget->save();
|
||||
@ -619,23 +619,23 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
// count the limits:
|
||||
$limits = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->get(['budget_limits.*'])->count();
|
||||
Log::debug(sprintf('Found %d budget limits.', $limits));
|
||||
// there might be a budget limit for these dates:
|
||||
/** @var BudgetLimit $limit */
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->first(['budget_limits.*']);
|
||||
|
||||
// if more than 1 limit found, delete the others:
|
||||
if ($limits > 1 && null !== $limit) {
|
||||
Log::debug(sprintf('Found more than 1, delete all except #%d', $limit->id));
|
||||
$budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.id', '!=', $limit->id)->delete();
|
||||
}
|
||||
|
||||
@ -660,8 +660,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// or create one and return it.
|
||||
$limit = new BudgetLimit;
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->start_date = $start;
|
||||
$limit->end_date = $end;
|
||||
$limit->start_date = $start->format('Y-m-d 00:00:00');
|
||||
$limit->end_date = $end->format('Y-m-d 00:00:00');
|
||||
$limit->amount = $amount;
|
||||
$limit->save();
|
||||
Log::debug(sprintf('Created new budget limit with ID #%d and amount %s', $limit->id, $amount));
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@ -301,14 +302,18 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$accounts = $this->storeAccounts($this->user, $transactionType, $data);
|
||||
$data = $this->verifyNativeAmount($data, $accounts);
|
||||
$amount = strval($data['amount']);
|
||||
$journal = new TransactionJournal(
|
||||
$dateString = $data['date'];
|
||||
if ($data['date'] instanceof Carbon) {
|
||||
$dateString = $data['date']->format('Y-m-d 00:00:00');
|
||||
}
|
||||
$journal = new TransactionJournal(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'transaction_type_id' => $transactionType->id,
|
||||
'transaction_currency_id' => $data['currency_id'], // no longer used.
|
||||
'description' => $data['description'],
|
||||
'completed' => 0,
|
||||
'date' => $data['date'],
|
||||
'date' => $dateString,
|
||||
]
|
||||
);
|
||||
$journal->save();
|
||||
|
Loading…
Reference in New Issue
Block a user