Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Wallet/AddTransaction.php
- This file was moved from src/app/Console/Commands/WalletAddTransaction.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands\Wallet; | ||||
use Illuminate\Console\Command; | use App\Console\Command; | ||||
class WalletAddTransaction extends Command | class AddTransaction extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'wallet:add-transaction {wallet} {qty} {--message=}'; | protected $signature = 'wallet:add-transaction {wallet} {qty} {--message=}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Add a transaction to a wallet'; | protected $description = 'Add a transaction to a wallet'; | ||||
/** | /** | ||||
* Create a new command instance. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function __construct() | |||||
{ | |||||
parent::__construct(); | |||||
} | |||||
/** | |||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallet = \App\Wallet::find($this->argument('wallet')); | $wallet = \App\Wallet::find($this->argument('wallet')); | ||||
if (!$wallet) { | if (!$wallet) { | ||||
$this->error("Wallet not found"); | |||||
return 1; | return 1; | ||||
} | } | ||||
$qty = (int) $this->argument('qty'); | $qty = (int) $this->argument('qty'); | ||||
$message = $this->option('message'); | $message = $this->option('message'); | ||||
if ($qty < 0) { | if ($qty < 0) { | ||||
$wallet->debit($qty, $message); | $wallet->debit($qty, $message); | ||||
} else { | } else { | ||||
$wallet->credit($qty, $message); | $wallet->credit($qty, $message); | ||||
} | } | ||||
} | } | ||||
} | } |