1. Go to this page and download the library: Download tontonpro/contracts 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/ */
tontonpro / contracts example snippets
use TontonPro\Contracts\Facts\SaleCompleted;
$fait = new SaleCompleted($entete, '2026-000123', null, $lignes);
event($fait); // dans la transaction ; sans comptabilité installée, rien ne change
use TontonPro\Contracts\Dashboard\{DashboardBoard, DashboardContributor, DashboardFigure, DashboardPanel};
use TontonPro\Contracts\Value\{BusinessDate, Money, UtcInstant};
final class HotelDashboard implements DashboardContributor
{
public function contributeTo(DashboardBoard $board, int $userId, UtcInstant $now): void
{
foreach ($this->sitesOf($userId) as $site) { // ses propres données ; aucun site : aucun panneau
$board->addPanel(new DashboardPanel(
key: 'hotelpro.desk.'.$site->id,
owner: 'hotelpro',
titleKey: 'hotelpro::dashboard.desk',
ability: 'hotelpro.ledger.view',
figures: [
DashboardFigure::percentBasisPoints('hotelpro::dashboard.occupancy', $site->occupancyBp($now)),
DashboardFigure::count('hotelpro::dashboard.arrivals_expected', $site->arrivalsExpected($now)),
DashboardFigure::money('hotelpro::dashboard.collected', new Money($site->collected($now), $site->currency())),
DashboardFigure::businessDate('hotelpro::dashboard.day_to_close', new BusinessDate($site->openDay())),
],
order: 10,
routeName: 'hotelpro.ledger',
linkTitleKey: 'hotelpro::nav.ledger',
subtitle: $site->name,
businessDate: new BusinessDate($site->businessDay($now)),
));
}
}
}
$board = new DashboardBoard();
$now = new UtcInstant(new \DateTimeImmutable('now', new \DateTimeZone('UTC')));
foreach ($contributors as $contributor) { // les contributeurs inscrits ; aucun : tableau vide
try {
$contributor->contributeTo($board, $user->id, $now);
} catch (ContractViolation $violation) {
report($violation); // un module fautif ne retire pas les panneaux des autres
}
}
$panels = $board->visibleFor(fn (string $ability): bool => $user->can($ability));
// [] : l'hôte montre son message utile. Sinon : traduire les clés, résoudre les routes, formater selon `kind`.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.