<?php
namespace App\Entity;
use App\Repository\MouvementCaisseRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: MouvementCaisseRepository::class)]
#[ORM\Index(columns: ['date_mouvement'], name: 'idx_mouvement_date')]
#[ORM\Index(columns: ['type_mouvement'], name: 'idx_mouvement_type')]
class MouvementCaisse
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'mouvements')]
#[ORM\JoinColumn(nullable: false)]
private ?Caisse $caisse = null;
#[ORM\ManyToOne(inversedBy: 'mouvements')]
#[ORM\JoinColumn(nullable: true)]
private ?SessionCaisse $session = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $dateMouvement = null;
#[ORM\Column(length: 50)]
private ?string $typeMouvement = null; // entree, sortie
#[ORM\Column(length: 100)]
private ?string $natureMouvement = null;
// vente, paiement_dette_client, remboursement_client, versement_initial,
// achat_fournisseur, paiement_dette_fournisseur, depense,
// versement_banque, prelevement, regularisation
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2)]
private ?string $montant = null;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2)]
private ?string $soldeAvant = null;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2)]
private ?string $soldeApres = null;
#[ORM\Column(length: 255)]
private ?string $libelle = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
// Références vers les entités sources
#[ORM\Column(length: 50, nullable: true)]
private ?string $typeReference = null; // vente, echeance, paiement_dette, paiement_fournisseur, depense, manuel
#[ORM\Column(nullable: true)]
private ?int $idReference = null;
#[ORM\ManyToOne(targetEntity: Vente::class)]
private ?Vente $vente = null;
#[ORM\ManyToOne(targetEntity: Echeance::class)]
private ?Echeance $echeance = null;
#[ORM\ManyToOne(targetEntity: PaiementDette::class)]
private ?PaiementDette $paiementDette = null;
#[ORM\ManyToOne(targetEntity: PaiementFournisseur::class)]
private ?PaiementFournisseur $paiementFournisseur = null;
#[ORM\ManyToOne(targetEntity: Depense::class)]
private ?Depense $depense = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: false)]
private ?User $createdBy = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(targetEntity: Boutique::class)]
private ?Boutique $boutique = null;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->dateMouvement = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getCaisse(): ?Caisse
{
return $this->caisse;
}
public function setCaisse(?Caisse $caisse): static
{
$this->caisse = $caisse;
return $this;
}
public function getSession(): ?SessionCaisse
{
return $this->session;
}
public function setSession(?SessionCaisse $session): static
{
$this->session = $session;
return $this;
}
public function getDateMouvement(): ?\DateTimeInterface
{
return $this->dateMouvement;
}
public function setDateMouvement(\DateTimeInterface $dateMouvement): static
{
$this->dateMouvement = $dateMouvement;
return $this;
}
public function getTypeMouvement(): ?string
{
return $this->typeMouvement;
}
public function setTypeMouvement(string $typeMouvement): static
{
$this->typeMouvement = $typeMouvement;
return $this;
}
public function getNatureMouvement(): ?string
{
return $this->natureMouvement;
}
public function setNatureMouvement(string $natureMouvement): static
{
$this->natureMouvement = $natureMouvement;
return $this;
}
public function getMontant(): ?string
{
return $this->montant;
}
public function setMontant(string $montant): static
{
$this->montant = $montant;
return $this;
}
public function getSoldeAvant(): ?string
{
return $this->soldeAvant;
}
public function setSoldeAvant(string $soldeAvant): static
{
$this->soldeAvant = $soldeAvant;
return $this;
}
public function getSoldeApres(): ?string
{
return $this->soldeApres;
}
public function setSoldeApres(string $soldeApres): static
{
$this->soldeApres = $soldeApres;
return $this;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(string $libelle): static
{
$this->libelle = $libelle;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getTypeReference(): ?string
{
return $this->typeReference;
}
public function setTypeReference(?string $typeReference): static
{
$this->typeReference = $typeReference;
return $this;
}
public function getIdReference(): ?int
{
return $this->idReference;
}
public function setIdReference(?int $idReference): static
{
$this->idReference = $idReference;
return $this;
}
public function getVente(): ?Vente
{
return $this->vente;
}
public function setVente(?Vente $vente): static
{
$this->vente = $vente;
return $this;
}
public function getEcheance(): ?Echeance
{
return $this->echeance;
}
public function setEcheance(?Echeance $echeance): static
{
$this->echeance = $echeance;
return $this;
}
public function getPaiementDette(): ?PaiementDette
{
return $this->paiementDette;
}
public function setPaiementDette(?PaiementDette $paiementDette): static
{
$this->paiementDette = $paiementDette;
return $this;
}
public function getPaiementFournisseur(): ?PaiementFournisseur
{
return $this->paiementFournisseur;
}
public function setPaiementFournisseur(?PaiementFournisseur $paiementFournisseur): static
{
$this->paiementFournisseur = $paiementFournisseur;
return $this;
}
public function getDepense(): ?Depense
{
return $this->depense;
}
public function setDepense(?Depense $depense): static
{
$this->depense = $depense;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): static
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getBoutique(): ?Boutique
{
return $this->boutique;
}
public function setBoutique(?Boutique $boutique): static
{
$this->boutique = $boutique;
return $this;
}
public function __toString(): string
{
$type = $this->typeMouvement === 'entree' ? '+' : '-';
return sprintf(
'%s %s FCFA - %s',
$type,
number_format(floatval($this->montant), 0, ',', ' '),
$this->libelle
);
}
}