| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCart\Framework\Support\Arr; |
| 6 |
use FluentCart\App\Models\OrderTaxRate; |
| 7 |
use FluentCart\App\Services\Filter\TaxFilter; |
| 8 |
use FluentCart\App\Services\DateTime\DateTime; |
| 9 |
use FluentCart\Framework\Http\Request\Request; |
| 10 |
|
| 11 |
class TaxController extends Controller |
| 12 |
{ |
| 13 |
public function index(Request $request) |
| 14 |
{ |
| 15 |
return $this->sendSuccess([ |
| 16 |
'taxes' => TaxFilter::fromRequest($request)->paginate(), |
| 17 |
]); |
| 18 |
} |
| 19 |
|
| 20 |
public function markAsFiled(Request $request) |
| 21 |
{ |
| 22 |
$idsToMark = Arr::get($request->getSafe(['ids.*' => 'intval']), 'ids', []); |
| 23 |
|
| 24 |
if (empty($idsToMark)) { |
| 25 |
return $this->sendError([ |
| 26 |
'message' => __('No IDs provided to mark!', 'fluent-cart'), |
| 27 |
], 400); |
| 28 |
} |
| 29 |
|
| 30 |
$result = OrderTaxRate::whereIn('id', $idsToMark) |
| 31 |
->whereNull('filed_at') |
| 32 |
->update([ |
| 33 |
'filed_at' => DateTime::gmtNow(), |
| 34 |
]); |
| 35 |
|
| 36 |
if (is_wp_error($result)) { |
| 37 |
return $result; |
| 38 |
} |
| 39 |
|
| 40 |
return $this->sendSuccess(['message' => __('Taxes marked as filed successfully', 'fluent-cart')]); |
| 41 |
} |
| 42 |
} |
| 43 |
|