Sometimes some countries don't follow standard Carbon::now()->isLeapYear() logic. Hence we can change that by using a class-implementing IsLeapYearInterface interface.
For example, In the Nepali calendar, which is also known as the Bikram Sambat (B.S.) calendar, leap years are calculated based on a specific rule. The Nepali calendar follows a 57-year cycle, where every 57th year is a leap year. This means that in the Nepali calendar, leap years occur at regular intervals and are predictable.
Let's create a class IsNepaliNewYear
<?php
namespace App\Services;
use Carbon\Carbon;
use Pratiksh\Payable\Contracts\IsLeapYearInterface;
class IsNepaliNewYear implements IsLeapYearInterface
{
/**
* Leap year logic
* Determine how leap year is identified.
*/
public function __invoke($year = null): bool
{
// Check if the year is divisible by 4 and not divisible by 100
// Or if it's divisible by 400, then it's a leap year
return (($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400 == 0);
}
}
Then change leap_year the configuration in payable.php config file.
'leap_year' => \App\Services\IsNepali::class,
Current Year
Sometimes some countries don't follow standard Carbon::now()->year logic. Hence we can change that by using a class-implementing CurrentYearInterfaceinterface.
For example, In the Nepali calendar, which is also known as the Bikram Sambat (B.S.) calendar, 2024 AD is 2080-81 B.S
Let's create a class NepaliCurrentYear implementing CurrentYearInterface and use composer package pratiksh/nepalidate
<?php
namespace App\Services;
use Carbon\Carbon;
use Pratiksh\Payable\Contracts\CurrentYearInterface;
class NepaliCurrentYear implements CurrentYearInterface
{
/**
* Leap year logic
* Determine how leap year is identified.
*/
public function __invoke(): int
{
return toDetailBS(\Carbon\Carbon::now())->year;
}
}
Then change current_yearthe configuration in payable.php config file.
Payable package uses default Pratiksh\Payable\Services\ReceiptNo class to return receipt no structure of payment which is as below :-
<?php
namespace Pratiksh\Payable\Services;
use Pratiksh\Payable\Contracts\ReceiptNoInterface;
use Pratiksh\Payable\Facades\Payable;
use Pratiksh\Payable\Models\Payment;
class ReceiptNo implements ReceiptNoInterface
{
/**
* Returns receipt no structure.
*/
public function __invoke($year = null): string
{
$year = $year ?? Payable::fiscal()->year;
return $year.'-'.str_pad(Payment::count() + 1, 5, '0', STR_PAD_LEFT);
}
}
Here receipt number structure is current fiscal year and payment count added one.
We can change this strcuture by our own structure.
Let's create a class MyReceiptNo implementing ReceiptNoInterface
<?php
namespace App\Services;
use Carbon\Carbon;
use Pratiksh\Payable\Contracts\ReceiptNoInterface;
class MyReceiptNo implements ReceiptNoInterface
{
/**
* Returns receipt no structure.
*/
public function __invoke($year = null): string
{
return rand(100000,999999);
}
}
Then change current_yearthe configuration in payable.php config file.