added item taxes and totals to document api
This commit is contained in:
		| @@ -5,7 +5,6 @@ namespace App\Models\Document; | ||||
| use App\Abstracts\Model; | ||||
| use App\Traits\Currencies; | ||||
| use Illuminate\Database\Eloquent\Builder; | ||||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||||
| use Znck\Eloquent\Traits\BelongsToThrough; | ||||
|  | ||||
| class DocumentItemTax extends Model | ||||
|   | ||||
| @@ -2,10 +2,10 @@ | ||||
|  | ||||
| namespace App\Transformers\Document; | ||||
|  | ||||
| use App\Models\Document\Document as Model; | ||||
| use App\Transformers\Banking\Transaction; | ||||
| use App\Transformers\Common\Contact; | ||||
| use App\Transformers\Setting\Currency; | ||||
| use App\Models\Document\Document as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
|  | ||||
| class Document extends TransformerAbstract | ||||
| @@ -13,7 +13,7 @@ class Document extends TransformerAbstract | ||||
|     /** | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'transactions']; | ||||
|     protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'item_taxes', 'totals', 'transactions']; | ||||
|  | ||||
|     /** | ||||
|      * @param Model $model | ||||
| @@ -70,7 +70,7 @@ class Document extends TransformerAbstract | ||||
|      */ | ||||
|     public function includeHistories(Model $model) | ||||
|     { | ||||
|         return $this->collection($model->histories, new DocumentHistories()); | ||||
|         return $this->collection($model->histories, new DocumentHistory()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -79,7 +79,25 @@ class Document extends TransformerAbstract | ||||
|      */ | ||||
|     public function includeItems(Model $model) | ||||
|     { | ||||
|         return $this->collection($model->items, new DocumentItems()); | ||||
|         return $this->collection($model->items, new DocumentItem()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Model $model | ||||
|      * @return \League\Fractal\Resource\Collection | ||||
|      */ | ||||
|     public function includeItemTaxes(Model $model) | ||||
|     { | ||||
|         return $this->collection($model->item_taxes, new DocumentItemTax()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Model $model | ||||
|      * @return \League\Fractal\Resource\Collection | ||||
|      */ | ||||
|     public function includeTotals(Model $model) | ||||
|     { | ||||
|         return $this->collection($model->totals, new DocumentTotal()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -5,7 +5,7 @@ namespace App\Transformers\Document; | ||||
| use App\Models\Document\DocumentHistory as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
| 
 | ||||
| class DocumentHistories extends TransformerAbstract | ||||
| class DocumentHistory extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * @param Model $model | ||||
| @@ -5,7 +5,7 @@ namespace App\Transformers\Document; | ||||
| use App\Models\Document\DocumentItem as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
| 
 | ||||
| class DocumentItems extends TransformerAbstract | ||||
| class DocumentItem extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * @param Model $model | ||||
							
								
								
									
										48
									
								
								app/Transformers/Document/DocumentItemTax.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/Transformers/Document/DocumentItemTax.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Transformers\Document; | ||||
|  | ||||
| use App\Models\Document\DocumentItemTax as Model; | ||||
| use App\Transformers\Setting\Tax; | ||||
| use League\Fractal\TransformerAbstract; | ||||
|  | ||||
| class DocumentItemTax extends TransformerAbstract | ||||
| { | ||||
|     /** | ||||
|      * @var array | ||||
|      */ | ||||
|     protected $defaultIncludes = ['tax']; | ||||
|  | ||||
|     /** | ||||
|      * @param  Model $model | ||||
|      * @return array | ||||
|      */ | ||||
|     public function transform(Model $model) | ||||
|     { | ||||
|         return [ | ||||
|             'id' => $model->id, | ||||
|             'company_id' => $model->company_id, | ||||
|             'type' => $model->type, | ||||
|             'document_id' => $model->document_id, | ||||
|             'document_item_id' => $model->document_item_id, | ||||
|             'tax_id' => $model->tax_id, | ||||
|             'name' => $model->name, | ||||
|             'amount' => $model->amount, | ||||
|             'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '', | ||||
|             'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param  Model $model | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function includeTax(Model $model) | ||||
|     { | ||||
|         if (!$model->tax) { | ||||
|             return $this->null(); | ||||
|         } | ||||
|  | ||||
|         return $this->item($model->tax, new Tax()); | ||||
|     } | ||||
| } | ||||
| @@ -5,7 +5,7 @@ namespace App\Transformers\Document; | ||||
| use App\Models\Document\DocumentTotal as Model; | ||||
| use League\Fractal\TransformerAbstract; | ||||
| 
 | ||||
| class DocumentTotals extends TransformerAbstract | ||||
| class DocumentTotal extends TransformerAbstract | ||||
| { | ||||
| 
 | ||||
|     /** | ||||
		Reference in New Issue
	
	Block a user