Address wallet feedback: use the clinic's real payment infrastructure,
redesign the tab to match the admin panel, and make every wallet movement
fully auditable.
Backend:
- WalletTransaction: add createdBy (acting user) + createdByName, payment_method,
reference, status; toArray exposes them (migration Version20260716083939).
- WalletService (Settlement): balance/charge/withdraw + settleSessionFromWallet,
records actor/method/reason; insufficient balance throws ERR_WALLET_INSUFFICIENT.
- PatientController: charge/withdraw delegate to WalletService and accept
payment_method/reference; PATCH /session/{uuid} with payment_method=wallet
debits the patient's final share from the wallet (reference=session:{uuid}).
- docs/api/patient.md updated.
Frontend:
- Wallet modal redesigned to panel style (no gradient); payment method now uses
the clinic's real bank accounts + POS devices (usePaymentMethods) plus cash.
- Wallet tab: panel balance card + DataTable ledger with columns مبلغ/نوع/روش/
دلیل/ثبتکننده/تاریخ/ساعت/وضعیت + همه/واریزی/برداشت filters.
- Session card «تکمیل پرداخت» opens a payment-method chooser incl. کیف پول.
Tests: backend transparency + session-from-wallet (success/insufficient/cash);
frontend modal (real methods, toman→rials) + wallet tab + settle chooser.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
121 lines
5.2 KiB
PHP
121 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Settlement\Entity;
|
|
|
|
use App\Auth\Entity\User;
|
|
use App\Payment\Entity\Payment;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use App\Settlement\Repository\WalletTransactionRepository;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity(repositoryClass: WalletTransactionRepository::class)]
|
|
#[ORM\Table(name: 'wallet_transactions')]
|
|
#[ORM\Index(columns: ['user_id', 'created_at'], name: 'idx_wallet_user_date')]
|
|
#[ORM\Index(columns: ['user_id', 'type'], name: 'idx_wallet_user_type')]
|
|
class WalletTransaction
|
|
{
|
|
public const TYPE_CREDIT = 'credit';
|
|
public const TYPE_DEBIT = 'debit';
|
|
|
|
public const STATUS_CONFIRMED = 'confirmed';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
|
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
|
private User $user;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Payment::class)]
|
|
#[ORM\JoinColumn(name: 'payment_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
|
private ?Payment $payment = null;
|
|
|
|
#[ORM\Column(name: 'amount_rials', type: 'integer')]
|
|
private int $amountRials;
|
|
|
|
#[ORM\Column(type: 'string', length: 10)]
|
|
private string $type;
|
|
|
|
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
|
private ?string $description = null;
|
|
|
|
#[ORM\Column(name: 'balance_after', type: 'integer')]
|
|
private int $balanceAfter;
|
|
|
|
/** کاربرِ عاملِ تراکنش (منشی/دکتر که شارژ/برداشت را ثبت کرده) — برای شفافیت. */
|
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
|
#[ORM\JoinColumn(name: 'created_by_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
|
private ?User $createdBy = null;
|
|
|
|
/** نامِ denormalizedِ کاربرِ عامل، تا خواندنِ دفتر تراکنش join نخواهد. */
|
|
#[ORM\Column(name: 'created_by_name', type: 'string', length: 120, nullable: true)]
|
|
private ?string $createdByName = null;
|
|
|
|
/** روش پرداخت: card | pos | cash | gateway | wallet. */
|
|
#[ORM\Column(name: 'payment_method', type: 'string', length: 20, nullable: true)]
|
|
private ?string $paymentMethod = null;
|
|
|
|
/** مرجع/دلیلِ ماشینی تراکنش (مثلاً session:{uuid} برای کسر بابت سرویس). */
|
|
#[ORM\Column(type: 'string', length: 120, nullable: true)]
|
|
private ?string $reference = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 15)]
|
|
private string $status = self::STATUS_CONFIRMED;
|
|
|
|
#[ORM\Column(name: 'created_at', type: 'integer')]
|
|
private int $createdAt;
|
|
|
|
public function __construct(User $user, int $amountRials, string $type, int $balanceAfter)
|
|
{
|
|
$this->uuid = Uuid::v4()->toRfc4122();
|
|
$this->user = $user;
|
|
$this->amountRials = $amountRials;
|
|
$this->type = $type;
|
|
$this->balanceAfter = $balanceAfter;
|
|
$this->createdAt = time();
|
|
}
|
|
|
|
public function getId(): ?int { return $this->id; }
|
|
public function getUuid(): string { return $this->uuid; }
|
|
public function getUser(): User { return $this->user; }
|
|
public function getPayment(): ?Payment { return $this->payment; }
|
|
public function getAmountRials(): int { return $this->amountRials; }
|
|
public function getType(): string { return $this->type; }
|
|
public function getDescription(): ?string { return $this->description; }
|
|
public function getBalanceAfter(): int { return $this->balanceAfter; }
|
|
public function getCreatedBy(): ?User { return $this->createdBy; }
|
|
public function getCreatedByName(): ?string { return $this->createdByName; }
|
|
public function getPaymentMethod(): ?string { return $this->paymentMethod; }
|
|
public function getReference(): ?string { return $this->reference; }
|
|
public function getStatus(): string { return $this->status; }
|
|
|
|
public function setPayment(?Payment $p): self { $this->payment = $p; return $this; }
|
|
public function setDescription(?string $d): self { $this->description = $d; return $this; }
|
|
public function setCreatedBy(?User $u): self { $this->createdBy = $u; return $this; }
|
|
public function setCreatedByName(?string $n): self { $this->createdByName = $n; return $this; }
|
|
public function setPaymentMethod(?string $m): self { $this->paymentMethod = $m; return $this; }
|
|
public function setReference(?string $r): self { $this->reference = $r; return $this; }
|
|
public function setStatus(string $s): self { $this->status = $s; return $this; }
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'uuid' => $this->uuid,
|
|
'amount_rials' => $this->amountRials,
|
|
'type' => $this->type,
|
|
'description' => $this->description,
|
|
'balance_after' => $this->balanceAfter,
|
|
'created_by_name' => $this->createdByName,
|
|
'payment_method' => $this->paymentMethod,
|
|
'reference' => $this->reference,
|
|
'status' => $this->status,
|
|
'created_at' => $this->createdAt,
|
|
];
|
|
}
|
|
}
|