1. Go to this page and download the library: Download condoedge/finance library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
condoedge / finance example snippets
class CustomableTeam extends Model implements CustomableContract
{
use CanBeFinancialCustomer;
}
// AbstractMainFinanceModel.php
public final static function checkIntegrity($ids = null): void
{
DB::table((new static)->getTable())
->when($ids, function ($query) use ($ids) {
return $query->whereIn('id', $ids);
})
->update(static::columnsIntegrityCalculations());
}
// InvoiceDetail.php
public static function columnsIntegrityCalculations()
{
return [
'unit_price' => DB::raw('get_detail_unit_price_with_sign(fin_invoice_details.id)'),
'tax_amount' => DB::raw('get_detail_tax_amount(fin_invoice_details.id)'),
];
}
// Example: Creating an invoice from both UI and API uses the same method
public static function createInvoiceFromDto(CreateInvoiceDto $dto): self
{
$invoice = new self();
// Set properties from DTO
// Apply business rules
// Save invoice and related records
return $invoice;
}
// Example: DTO for creating an invoice
class CreateInvoiceDto extends ValidatedDTO
{
public int $customer_id;
public int $invoice_type_id;
public Carbon $invoice_date;
// ...
public function rules(): array
{
return [
'customer_id' => '
// In InvoiceForm (UI)
public function handle()
{
InvoiceModel::createInvoiceFromDto(new CreateInvoiceDto(request()->all()));
}
// In InvoicesController (API)
public function createInvoice(CreateInvoiceDto $data)
{
InvoiceModel::createInvoiceFromDto($data);
return response()->json(['message' => 'Success']);
}
safeDecimal(10.5)->add(5.5); // 16.0
'decimal-scale' => 5,
$this->assertEqualsDecimals(5.6, new SafeDecimal(5.6)); // true
$this->assertEqualsDecimals(5.6, 5.6); // true
$this->assertEqualsDecimals(5.6, 5.6000); // true
$this->assertEqualsDecimals(5.6, 5.6001); // false
$this->assertEqualsDecimals(5.6, 5.6000001); // true (more than 5 decimals so it's rounded to 5.6)