1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Repositories/RecurringExpenseRepository.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2021-08-23 01:38:55 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2021-08-23 01:38:55 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Repositories;
use App\Factory\RecurringExpenseFactory;
use App\Models\RecurringExpense;
use App\Utils\Traits\GeneratesCounter;
/**
* RecurringExpenseRepository.
*/
class RecurringExpenseRepository extends BaseRepository
{
use GeneratesCounter;
/**
* Saves the recurring_expense and its contacts.
*
* @param array $data The data
* @param \App\Models\RecurringExpense $recurring_expense The recurring_expense
*
* @return \App\Models\RecurringExpense|null recurring_expense Object
2021-08-23 01:38:55 +02:00
*/
2024-01-14 05:05:00 +01:00
public function save(array $data, RecurringExpense $recurring_expense): ?RecurringExpense
2021-08-23 01:38:55 +02:00
{
$recurring_expense->fill($data);
$recurring_expense->number = empty($recurring_expense->number) ? $this->getNextRecurringExpenseNumber($recurring_expense) : $recurring_expense->number;
$recurring_expense->save();
if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $recurring_expense);
}
return $recurring_expense;
}
/**
* Store recurring_expenses in bulk.
*
* @param array $recurring_expense
* @return \App\Models\RecurringExpense|null
*/
public function create($recurring_expense): ?RecurringExpense
{
return $this->save(
$recurring_expense,
RecurringExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id)
);
}
}