Blame view

app/Transformers/Expense/Payment.php 2.2 KB
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  <?php
  
  namespace App\Transformers\Expense;
  
  use App\Transformers\Banking\Account;
  use App\Transformers\Expense\Vendor;
  use App\Transformers\Setting\Category;
  use App\Transformers\Setting\Currency;
  use App\Models\Expense\Payment as Model;
  use League\Fractal\TransformerAbstract;
  
  class Payment extends TransformerAbstract
  {
      /**
       * @var array
       */
      protected $defaultIncludes = ['account', 'category', 'currency', 'vendor'];
  
      /**
       * @param  Model $model
       * @return array
       */
      public function transform(Model $model)
      {
          return [
              'id' => $model->id,
              'company_id' => $model->company_id,
              'account_id' => $model->account_id,
              'paid_at' => $model->paid_at->toIso8601String(),
              'amount' => $model->amount,
              'currency_code' => $model->currency_code,
              'currency_rate' => $model->currency_rate,
              'vendor_id' => $model->vendor_id,
              'description' => $model->description,
              'category_id' => $model->category_id,
              'payment_method' => $model->payment_method,
              'reference' => $model->reference,
              'attachment' => $model->attachment,
              'created_at' => $model->created_at->toIso8601String(),
              'updated_at' => $model->updated_at->toIso8601String(),
          ];
      }
  
      /**
       * @param  Model $model
       * @return \League\Fractal\Resource\Item
       */
      public function includeAccount(Model $model)
      {
          return $this->item($model->account, new Account());
      }
  
      /**
       * @param  Model $model
       * @return \League\Fractal\Resource\Item
       */
      public function includeCategory(Model $model)
      {
          return $this->item($model->category, new Category());
      }
  
      /**
       * @param  Model $model
       * @return \League\Fractal\Resource\Item
       */
      public function includeCurrency(Model $model)
      {
          return $this->item($model->currency, new Currency());
      }
  
      /**
       * @param  Model $model
       * @return mixed
       */
      public function includeVendor(Model $model)
      {
          if (!$model->vendor) {
              return $this->null();
          }
  
          return $this->item($model->vendor, new Vendor());
      }
  }