-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add credit card widgets top categories and usage
- Loading branch information
1 parent
6f4f3b5
commit 53e5353
Showing
18 changed files
with
785 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use App\Domains\Loans\Actions\UpdateLatePayments; | ||
use Tests\Feature\CreditCard\Helpers\CreditCardBase; | ||
use App\Domains\Transaction\Services\CreditCardReportService; | ||
|
||
class GenerateBillingCycles extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'bg:generate-billing-cycles {teamId} {date?}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(CreditCardReportService $service) | ||
{ | ||
$teamId = $this->argument('teamId'); | ||
$date = $this->argument('date'); | ||
|
||
$monthsWithTransactions = $this->getFirstTransaction($teamId); | ||
return $service->generateBillingCycles($teamId, $date ?? $monthsWithTransactions->date); | ||
} | ||
|
||
private function getFirstTransaction(int $teamId) { | ||
return DB::table('transaction_lines') | ||
->where([ | ||
"team_id" => $teamId | ||
]) | ||
->selectRaw("date_format(transaction_lines.date, '%Y-%m') AS date") | ||
->groupBy(DB::raw("date_format(transaction_lines.date, '%Y-%m')")) | ||
->orderBy('date') | ||
->first(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace App\Domains\Transaction\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Insane\Journal\Models\Core\Transaction; | ||
use Insane\Journal\Traits\HasPaymentDocuments; | ||
|
||
class BillingCycle extends Model | ||
{ | ||
// use HasPaymentDocuments; | ||
|
||
const STATUS_PENDING = 'PENDING'; | ||
const STATUS_PARTIALLY_PAID = 'PARTIALLY_PAID'; | ||
const STATUS_LATE = 'LATE'; | ||
const STATUS_PAID = 'PAID'; | ||
const STATUS_CANCELLED = 'CANCELLED'; | ||
|
||
protected $fillable = [ | ||
'team_id', | ||
'user_id', | ||
'account_id', | ||
'end_at', | ||
'due_at', | ||
'start_at', | ||
'due', | ||
'subtotal', | ||
'discounts', | ||
'total' | ||
]; | ||
|
||
protected $creditCategory = 'credit_cards'; | ||
protected $creditAccount = 'Credit Card Billings'; | ||
|
||
public function transactions() { | ||
return $this->hasMany(TransactionLine::class, 'account_id') | ||
->whereBetween("date", [$this->from, $this->until]); | ||
} | ||
|
||
// Transactionable config | ||
public function getTransactionItems() { | ||
return []; | ||
} | ||
|
||
public static function getCategoryName($payable): string { | ||
return "credit_cards"; | ||
} | ||
|
||
public function getTransactionDescription() { | ||
return "Balance de credito"; | ||
} | ||
|
||
public function getTransactionDirection(): string { | ||
return Transaction::DIRECTION_CREDIT; | ||
} | ||
|
||
public function getAccountId() { | ||
return $this->account_id; | ||
} | ||
|
||
public function getCounterAccountId(): int { | ||
return $this->client_account_id; | ||
} | ||
|
||
// payable config | ||
public function getStatusField(): string { | ||
return 'payment_status'; | ||
} | ||
|
||
public static function calculateTotal($payable) { | ||
$payable->total = $payable->transactions()->sum('amount'); | ||
$payable->due = $payable->total - $payable->paid; | ||
} | ||
|
||
public static function checkStatus($payable) { | ||
$debt = $payable->total - $payable->paid; | ||
if ($debt <= 0) { | ||
$status = self::STATUS_PAID; | ||
} elseif ($debt > 0 && $debt < $payable->amount) { | ||
$status = self::STATUS_PARTIALLY_PAID; | ||
} elseif ($debt && $payable->hasLateInstallments()) { | ||
$status = self::STATUS_LATE; | ||
} elseif ($debt && !$payable->cancelled_at) { | ||
$status = self::STATUS_PENDING; | ||
} elseif ($payable->cancelled_at) { | ||
$status = self::STATUS_CANCELLED; | ||
} else { | ||
$status = $payable->status; | ||
} | ||
$payable->status = $status; | ||
} | ||
|
||
public function updateStatus() { | ||
self::checkPayments($this); | ||
$this->save(); | ||
self::calculateTotal($this); | ||
self::checkStatus($this); | ||
} | ||
|
||
public function getConceptLine(): string { | ||
return ""; | ||
} | ||
} |
Oops, something went wrong.