| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2024-11-25 04:18:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * BillTransformer.php | 
					
						
							| 
									
										
										
										
											2020-02-16 13:57:18 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01: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. | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01: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. | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01: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/>. | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 19:49:29 +01:00
										 |  |  | namespace FireflyIII\Transformers; | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Models\Bill; | 
					
						
							| 
									
										
										
										
											2025-01-18 17:20:39 +01:00
										 |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							|  |  |  | use FireflyIII\Support\Facades\Amount; | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class BillTransformer | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-12-16 13:55:19 +01:00
										 |  |  | class BillTransformer extends AbstractTransformer | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-07-31 20:35:44 +02:00
										 |  |  |     private readonly TransactionCurrency $primary; | 
					
						
							| 
									
										
										
										
											2018-09-27 07:43:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * BillTransformer constructor. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-12-16 13:55:19 +01:00
										 |  |  |     public function __construct() | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-07-31 20:35:44 +02:00
										 |  |  |         $this->primary = Amount::getPrimaryCurrency(); | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-02-16 22:47:08 +01:00
										 |  |  |      * Transform the bill. | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function transform(Bill $bill): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-07-31 07:28:25 +02:00
										 |  |  |         $currency = $bill->transactionCurrency; | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 19:06:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 19:11:25 +02:00
										 |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'id'                              => $bill->id, | 
					
						
							|  |  |  |             'created_at'                      => $bill->created_at->toAtomString(), | 
					
						
							|  |  |  |             'updated_at'                      => $bill->updated_at->toAtomString(), | 
					
						
							|  |  |  |             'name'                            => $bill->name, | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // currencies according to 6.3.0
 | 
					
						
							| 
									
										
										
										
											2025-08-03 10:24:49 +02:00
										 |  |  |             'object_has_currency_setting'     => true, | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'currency_id'                     => (string) $bill->transaction_currency_id, | 
					
						
							| 
									
										
										
										
											2025-08-03 20:17:50 +02:00
										 |  |  |             'currency_name'                   => $currency->name, | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'currency_code'                   => $currency->code, | 
					
						
							|  |  |  |             'currency_symbol'                 => $currency->symbol, | 
					
						
							|  |  |  |             'currency_decimal_places'         => $currency->decimal_places, | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             'primary_currency_id'             => (string) $this->primary->id, | 
					
						
							| 
									
										
										
										
											2025-08-03 20:17:50 +02:00
										 |  |  |             'primary_currency_name'           => $this->primary->name, | 
					
						
							| 
									
										
										
										
											2025-07-31 20:35:44 +02:00
										 |  |  |             'primary_currency_code'           => $this->primary->code, | 
					
						
							|  |  |  |             'primary_currency_symbol'         => $this->primary->symbol, | 
					
						
							|  |  |  |             'primary_currency_decimal_places' => $this->primary->decimal_places, | 
					
						
							| 
									
										
										
										
											2025-07-30 20:35:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  |             // amounts according to 6.3.0
 | 
					
						
							| 
									
										
										
										
											2025-08-01 13:10:11 +02:00
										 |  |  |             'amount_min'                      => $bill->amounts['amount_min'], | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  |             'pc_amount_min'                   => $bill->amounts['pc_amount_min'], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'amount_max'                      => $bill->amounts['amount_max'], | 
					
						
							|  |  |  |             'pc_amount_max'                   => $bill->amounts['pc_amount_max'], | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'amount_avg'                      => $bill->amounts['average'], | 
					
						
							|  |  |  |             'pc_amount_avg'                   => $bill->amounts['pc_average'], | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'date'                            => $bill->date->toAtomString(), | 
					
						
							|  |  |  |             'end_date'                        => $bill->end_date?->toAtomString(), | 
					
						
							|  |  |  |             'extension_date'                  => $bill->extension_date?->toAtomString(), | 
					
						
							|  |  |  |             'repeat_freq'                     => $bill->repeat_freq, | 
					
						
							|  |  |  |             'skip'                            => $bill->skip, | 
					
						
							|  |  |  |             'active'                          => $bill->active, | 
					
						
							|  |  |  |             'order'                           => $bill->order, | 
					
						
							|  |  |  |             'notes'                           => $bill->meta['notes'], | 
					
						
							|  |  |  |             'object_group_id'                 => $bill->meta['object_group_id'], | 
					
						
							|  |  |  |             'object_group_order'              => $bill->meta['object_group_order'], | 
					
						
							|  |  |  |             'object_group_title'              => $bill->meta['object_group_title'], | 
					
						
							| 
									
										
										
										
											2025-08-03 08:12:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'paid_dates'                      => $bill->meta['paid_dates'], | 
					
						
							|  |  |  |             'pay_dates'                       => $bill->meta['pay_dates'], | 
					
						
							|  |  |  |             'next_expected_match'             => $bill->meta['nem']?->toAtomString(), | 
					
						
							|  |  |  |             'next_expected_match_diff'        => $bill->meta['nem_diff'], | 
					
						
							| 
									
										
										
										
											2025-07-31 07:28:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |             'links'                           => [ | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |                 [ | 
					
						
							|  |  |  |                     'rel' => 'self', | 
					
						
							| 
									
										
										
										
											2025-08-03 16:45:49 +02:00
										 |  |  |                     'uri' => '/bills/'.$bill->id, | 
					
						
							| 
									
										
										
										
											2018-02-06 07:49:56 +01:00
										 |  |  |                 ], | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-05 19:35:58 +01:00
										 |  |  | } |