Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Data/Export/VATCommand.php
- This file was added.
<?php | |||||
namespace App\Console\Commands\Data\Export; | |||||
use Illuminate\Console\Command; | |||||
use Illuminate\Support\Facades\DB; | |||||
class VATCommand extends Command | |||||
{ | |||||
/** | |||||
* The name and signature of the console command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'data:export:vat'; | |||||
/** | |||||
* The console command description. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'Export VAT data'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return int | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
$transactions = DB::select(" | |||||
SELECT | |||||
YEAR(t.created_at) AS year, | |||||
MONTH(t.created_at) AS month, | |||||
SUM(t.amount) AS amount, | |||||
(0.077 * SUM(t.amount)) AS vat | |||||
FROM transactions t | |||||
INNER JOIN wallets w ON t.object_id = w.id | |||||
INNER JOIN user_settings u ON w.user_id = u.user_id | |||||
WHERE u.`key` = 'country' | |||||
AND u.value in ('CH', 'LI') | |||||
AND t.object_type = 'App\Wallet' | |||||
AND t.type = 'credit' | |||||
GROUP BY YEAR(t.created_at), MONTH(t.created_at) | |||||
"); | |||||
foreach ($transactions as $transaction) { | |||||
$this->info( | |||||
sprintf( | |||||
"%s %02d %d %d", | |||||
$transaction->{'year'}, | |||||
$transaction->{'month'}, | |||||
$transaction->{'amount'}, | |||||
$transaction->{'vat'} | |||||
) | |||||
); | |||||
} | |||||
} | |||||
} |