| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * BillRepositoryInterface.php | 
					
						
							| 
									
										
										
										
											2020-02-16 14:00:57 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Repositories\Bill; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-03 17:40:17 +01:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2025-03-08 15:52:50 +01:00
										 |  |  | use FireflyIII\Enums\UserRoleEnum; | 
					
						
							| 
									
										
										
										
											2019-10-30 20:02:21 +01:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  | use FireflyIII\Models\Bill; | 
					
						
							| 
									
										
										
										
											2025-03-08 15:52:50 +01:00
										 |  |  | use FireflyIII\Models\UserGroup; | 
					
						
							|  |  |  | use FireflyIII\User; | 
					
						
							|  |  |  | use Illuminate\Contracts\Auth\Authenticatable; | 
					
						
							| 
									
										
										
										
											2018-02-06 18:11:33 +01:00
										 |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
					
						
							| 
									
										
										
										
											2015-04-05 18:20:06 +02:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Interface BillRepositoryInterface. | 
					
						
							| 
									
										
										
										
											2025-03-08 15:52:50 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @method setUserGroup(UserGroup $group) | 
					
						
							|  |  |  |  * @method getUserGroup() | 
					
						
							|  |  |  |  * @method getUser() | 
					
						
							|  |  |  |  * @method checkUserGroupAccess(UserRoleEnum $role) | 
					
						
							|  |  |  |  * @method setUser(null|Authenticatable|User $user) | 
					
						
							|  |  |  |  * @method setUserGroupById(int $userGroupId) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-03-29 21:27:51 +02:00
										 |  |  | interface BillRepositoryInterface | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-20 17:11:33 +01:00
										 |  |  |     public function billEndsWith(string $query, int $limit): Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function billStartsWith(string $query, int $limit): Collection; | 
					
						
							| 
									
										
										
										
											2025-02-10 04:10:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 14:59:58 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Add correct order to bills. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function correctOrder(): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     public function destroy(Bill $bill): bool; | 
					
						
							| 
									
										
										
										
											2020-07-01 06:33:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     public function destroyAll(): void; | 
					
						
							| 
									
										
										
										
											2015-12-26 09:39:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 08:57:45 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-07-23 21:37:06 +02:00
										 |  |  |      * Find a bill by ID. | 
					
						
							| 
									
										
										
										
											2016-07-05 08:57:45 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-02-16 15:19:19 +01:00
										 |  |  |     public function find(int $billId): ?Bill; | 
					
						
							| 
									
										
										
										
											2016-07-05 08:57:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-17 17:05:16 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Find bill by parameters. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-03-31 13:36:49 +02:00
										 |  |  |     public function findBill(?int $billId, ?string $billName): ?Bill; | 
					
						
							| 
									
										
										
										
											2019-03-17 17:05:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 13:07:19 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-07-23 21:37:06 +02:00
										 |  |  |      * Find a bill by name. | 
					
						
							| 
									
										
										
										
											2016-04-01 13:07:19 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-02-16 15:19:19 +01:00
										 |  |  |     public function findByName(string $name): ?Bill; | 
					
						
							| 
									
										
										
										
											2016-04-01 13:07:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-06 18:59:48 +01:00
										 |  |  |     public function getActiveBills(): Collection; | 
					
						
							| 
									
										
										
										
											2015-12-27 17:29:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 13:09:43 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get all attachments. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getAttachments(Bill $bill): Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-06 18:59:48 +01:00
										 |  |  |     public function getBills(): Collection; | 
					
						
							| 
									
										
										
										
											2015-04-05 18:20:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-12 10:33:19 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Gets the bills which have some kind of relevance to the accounts mentioned. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-06 18:59:48 +01:00
										 |  |  |     public function getBillsForAccounts(Collection $accounts): Collection; | 
					
						
							| 
									
										
										
										
											2015-12-12 10:33:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 20:35:14 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get all bills with these ID's. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getByIds(array $billIds): Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-29 07:46:03 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get text or return empty string. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getNoteText(Bill $bill): string; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 20:08:04 +02:00
										 |  |  |     public function getOverallAverage(Bill $bill): array; | 
					
						
							| 
									
										
										
										
											2016-10-23 14:56:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 19:49:16 +01:00
										 |  |  |     public function getPaginator(int $size): LengthAwarePaginator; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-23 14:56:05 +02:00
										 |  |  |     public function getPaidDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection; | 
					
						
							| 
									
										
										
										
											2016-07-23 21:37:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 13:20:51 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Between start and end, tells you on which date(s) the bill is expected to hit. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 09:59:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Return all rules for one bill | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getRulesForBill(Bill $bill): Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-08 17:36:37 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Return all rules related to the bills in the collection, in an associative array: | 
					
						
							|  |  |  |      * 5= billid | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']] | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getRulesForBills(Collection $collection): array; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-06 20:08:04 +02:00
										 |  |  |     public function getYearAverage(Bill $bill, Carbon $date): array; | 
					
						
							| 
									
										
										
										
											2016-07-23 21:37:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 09:59:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Link a set of journals to a bill. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-07-21 17:15:06 +02:00
										 |  |  |     public function linkCollectionToBill(Bill $bill, array $transactions): void; | 
					
						
							| 
									
										
										
										
											2018-04-14 09:59:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 06:26:12 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Given a bill and a date, this method will tell you at which moment this bill expects its next | 
					
						
							|  |  |  |      * transaction. Whether or not it is there already, is not relevant. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function nextDateMatch(Bill $bill, Carbon $date): Carbon; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-20 21:40:45 +02:00
										 |  |  |     public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:19:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     public function removeObjectGroup(Bill $bill): Bill; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 06:22:29 +02:00
										 |  |  |     public function searchBill(string $query, int $limit): Collection; | 
					
						
							| 
									
										
										
										
											2019-03-02 14:12:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     public function setObjectGroup(Bill $bill, string $objectGroupTitle): Bill; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set specific piggy bank to specific order. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function setOrder(Bill $bill, int $order): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-05 18:20:06 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-10-30 20:02:21 +01:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2015-04-05 18:20:06 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-10-30 20:02:21 +01:00
										 |  |  |     public function store(array $data): Bill; | 
					
						
							| 
									
										
										
										
											2015-04-05 18:20:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  |      * Collect multi-currency of sum of bills already paid. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function sumPaidInRange(Carbon $start, Carbon $end): array; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Collect multi-currency of sum of bills yet to pay. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function sumUnpaidInRange(Carbon $start, Carbon $end): array; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 06:20:01 +01:00
										 |  |  |     public function unlinkAll(Bill $bill): void; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-06 18:59:48 +01:00
										 |  |  |     public function update(Bill $bill, array $data): Bill; | 
					
						
							| 
									
										
										
										
											2015-03-29 08:14:32 +02:00
										 |  |  | } |