<?php
namespace App\Entity\GestionComerciale;
use DateInterval;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Articles\Devise;
use App\Entity\Clients\Client;
use App\Entity\FO\CompteBancaire;
use App\Entity\Utilisateur\Utilisateur;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
use App\Annotations\SecuredEntity;
/**
* Acompte
*
* @ORM\Table("commerciale__acompte")
* @ORM\Entity(repositoryClass="App\Repository\GestionComerciale\AcompteRepository")
* @Gedmo\SoftDeleteable(fieldName="dateSuppression",timeAware=false)
* @ORM\HasLifecycleCallbacks()
* @SecuredEntity(name="Acompte", group="VENTES")
*/
class Acompte
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="commentaire", type="text", nullable=true)
*/
private $commentaire;
/**
* @ORM\Column(name="id_import", type="string", length=255, nullable=true)
*/
private $idImport;
/**
* @ORM\Column(name="id_transaction", type="string", length=255, nullable=true)
*/
private $idTransaction;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur\Utilisateur", inversedBy="acomptes")
* @ORM\JoinColumn(nullable=true)
*/
private $utilisateur;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\ModeReglement", cascade={"persist"})
* @Assert\NotBlank(message="Le mode de réglement est obligatoire")
*/
private $modeReglement;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\TypeReglement", cascade={"persist"})
* @Assert\NotBlank(message="Le type de réglement est obligatoire")
*/
private $typeReglement;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Acompte")
* @ORM\JoinColumn(nullable=true)
*/
private $acompteParent;
/**
* @ORM\Column(name="est_parent", type="boolean", nullable=true)
*/
private $estParent;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Acompte")
* @ORM\JoinColumn(nullable=true)
*/
private $remboursement;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Commande", inversedBy="acomptes")
* @ORM\JoinColumn(nullable=true)
*/
private $commande;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Commande")
* @ORM\JoinColumn(nullable=true)
*/
private $avoir;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Commande", inversedBy="reglements")
* @ORM\JoinColumn(nullable=true)
*/
private $parent;
/**
* @ORM\Column(name="montant", type="float", nullable=true)
* @Assert\NotBlank(message="Le montant est obligatoire")
*/
private $montant;
/**
* @ORM\Column(name="dateReglement", type="datetime", nullable=true)
*/
private $dateReglement;
/**
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
private $date;
/**
* @ORM\Column(name="dateSuppression", type="datetime", nullable=true)
*/
private $dateSuppression;
/**
* @ORM\Column(name="dateMaj", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $dateMaj;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\DelaiPaiement", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $delaiPaiement;
/**
* @ORM\Column(name="dateEcheance", type="datetime", nullable=true)
*/
private $dateEcheance;
/**
* @ORM\Column(name="nomClient", type="string", length=255, nullable=true)
*/
private $nomClient;
/**
* @ORM\Column(name="numPiece", type="string", length=255, nullable=true)
*/
private $numPiece;
/**
* @ORM\Column(name="numTraite", type="string", length=255, nullable=true)
*/
private $numTraite;
/**
* @ORM\Column(name="codeAgence", type="string", length=255, nullable=true)
*/
private $codeAgence;
/**
* @ORM\Column(name="nomAgence", type="string", length=255, nullable=true)
*/
private $nomAgence;
/**
* @ORM\Column(name="domiciliation", type="string", length=255, nullable=true)
*/
private $domiciliation;
/**
* @ORM\Column(name="domiciliation2", type="string", length=255, nullable=true)
*/
private $domiciliation2;
/**
* @ORM\Column(name="bor", type="boolean", nullable=true)
*/
private $bor;
/**
* @ORM\Column(name="codeEtablissement", type="string", length=255, nullable=true)
*/
private $codeEtablissement;
/**
* @ORM\Column(name="codeGuichet", type="string", length=255, nullable=true)
*/
private $codeGuichet;
/**
* @ORM\Column(name="numCompte", type="string", length=255, nullable=true)
*/
private $numCompte;
/**
* @ORM\Column(name="cleCompte", type="string", length=255, nullable=true)
*/
private $cleCompte;
/**
* @ORM\Column(name="IBAN", type="string", length=255, nullable=true)
*/
private $iBAN;
/**
* @ORM\Column(name="BIC", type="string", length=255, nullable=true)
*/
private $bIC;
/**
* @ORM\Column(name="numRUM", type="string", length=255, nullable=true)
*/
private $numRUM;
/**
* @ORM\Column(name="dateContrat", type="datetime", nullable=true)
*/
private $dateContrat;
/**
* @ORM\Column(name="lieuContrat", type="string", length=255, nullable=true)
*/
private $lieuContrat;
/**
* @ORM\Column(name="refTire", type="string", length=255, nullable=true)
*/
private $refTire;
/**
* @ORM\Column(name="refTireur", type="string", length=255, nullable=true)
*/
private $refTireur;
/**
* @ORM\Column(name="codeBanque", type="string", length=255, nullable=true)
*/
private $codeBanque;
/**
* @ORM\Column(name="codeTransfert", type="string", length=255, nullable=true)
*/
private $codeTransfert;
/**
* @ORM\Column(name="codeAcceptation", type="string", length=255, nullable=true)
*/
private $codeAcceptation;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Clients\Client", inversedBy="reglements")
* @ORM\JoinColumn(nullable=true)
*/
private $client;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Articles\Devise", inversedBy="reglements")
* @ORM\JoinColumn(nullable=true)
*/
private $devise;
/**
* @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Commande", cascade={"persist"}, mappedBy="lcr")
*/
private $factures;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Bordereau", inversedBy="reglements")
* @ORM\JoinColumn(nullable=true)
*/
private $bordereau;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\FO\CompteBancaire", inversedBy="reglements")
* @ORM\JoinColumn(nullable=true)
*/
private $compteBancaireSociete;
/**
* @ORM\Column(name="transfert_compta", type="boolean")
*/
private $transfertCompta;
/**
* @ORM\Column(name="operation_diverse", type="float", nullable=true)
*/
private $operationDiverse;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\GestionComerciale\Acompte", inversedBy="reglementsEnfant")
* @ORM\JoinColumn(nullable=true)
*/
private $reglementParent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\GestionComerciale\Acompte", mappedBy="reglementParent")
*/
private $reglementsEnfant;
/**
*
* @ORM\OneToOne(targetEntity="App\Entity\GestionComerciale\MouvementCaisse", mappedBy="reglement")
*
*/
private $mouvementCaisse;
/**
* @ORM\Column(name="mouvement_equilibrage", type="boolean", nullable=true)
*/
private $mouvementEquilibrage;
/**
* @ORM\Column(name="hors_erp", type="boolean", nullable=true)
*/
private $horsErp;
/**
* @ORM\Column(name="solde", type="float", nullable=true)
*
*/
private $solde;
/**
* @ORM\Column(name="numero_lettrage", type="float", nullable=true)
*
*/
private $numeroLettrage;
/**
* @ORM\Column(name="lettrage", type="string", length=255, nullable=true)
*/
private $lettrage;
public function __construct()
{
$date = new Datetime ;
$this->date = $date;
//$this->dateEcheance = $date;
$this->dateReglement = new Datetime();
$this->bor = false;
$this->transfertCompta = false;
$this->estParent = false;
$this->mouvementEquilibrage = false;
$this->horsErp = false;
$this->operationDiverse = 0;
$this->reglementsEnfant = new ArrayCollection();
$this->factures = new ArrayCollection();
}
/*
public function isMontantValid()
{
$montantCommande = $this->commande->getTotalTtc();
$montantAcompte = $this->getMontant();
if($montantAcompte > $montantCommande) return false;
return true;
}
*
*/
public function getId(): int
{
return $this->id;
}
public function setMontant(?float $montant): Acompte
{
$this->montant = $montant;
return $this;
}
public function getMontant(): ?float
{
return $this->montant;
}
public function setDate(?DateTime $date): Acompte
{
$this->date = $date;
return $this;
}
public function getDate(): ?DateTime
{
return $this->date;
}
public function setDateSuppression(?DateTime $dateSuppression): Acompte
{
$this->dateSuppression = $dateSuppression;
return $this;
}
public function getDateSuppression(): ?DateTime
{
return $this->dateSuppression;
}
public function setDateMaj(?DateTime $dateMaj): Acompte
{
$this->dateMaj = $dateMaj;
return $this;
}
public function getDateMaj(): ?DateTime
{
return $this->dateMaj;
}
public function setDelaiPaiement(?DelaiPaiement $delaiPaiement): Acompte
{
$this->delaiPaiement = $delaiPaiement;
return $this;
}
public function getDelaiPaiement(): ?DelaiPaiement
{
return $this->delaiPaiement;
}
public function setUtilisateur(?Utilisateur $utilisateur): Acompte
{
$this->utilisateur = $utilisateur;
return $this;
}
public function getUtilisateur(): ?Utilisateur
{
return $this->utilisateur;
}
public function setCommande(?Commande $commande): Acompte
{
$this->commande = $commande;
return $this;
}
public function getCommande(): ?Commande
{
return $this->commande;
}
public function setDateReglement(?DateTime $dateReglement): Acompte
{
$date = new Datetime();
$dateReglement->modify("+".$date->format("H")."hours");
$dateReglement->modify("+".$date->format("i")."minutes");
$this->dateReglement = $dateReglement ;
return $this;
}
public function getDateReglement(): ?DateTime
{
return $this->dateReglement;
}
public function setModeReglement(?ModeReglement $modeReglement): Acompte
{
$this->modeReglement = $modeReglement;
return $this;
}
public function getModeReglement(): ?ModeReglement
{
return $this->modeReglement;
}
public function setTypeReglement(?TypeReglement $typeReglement): Acompte
{
$this->typeReglement = $typeReglement;
return $this;
}
public function getTypeReglement(): ?TypeReglement
{
return $this->typeReglement;
}
public function setNomClient(?string $nomClient): Acompte
{
$this->nomClient = $nomClient;
return $this;
}
public function getNomClient(): ?string
{
return $this->nomClient;
}
public function setNumPiece(?string $numPiece): Acompte
{
$this->numPiece = $numPiece;
return $this;
}
public function getNumPiece(): ?string
{
return $this->numPiece;
}
public function setNumTraite(?string $numTraite): Acompte
{
$this->numTraite = $numTraite;
return $this;
}
public function getNumTraite(): ?string
{
return $this->numTraite;
}
public function setCodeAgence(?string $codeAgence): Acompte
{
$this->codeAgence = $codeAgence;
return $this;
}
public function getCodeAgence(): ?string
{
return $this->codeAgence;
}
public function setNomAgence(?string $nomAgence): Acompte
{
$this->nomAgence = $nomAgence;
return $this;
}
public function getNomAgence(): ?string
{
return $this->nomAgence;
}
public function setDomiciliation(?string $domiciliation): Acompte
{
$this->domiciliation = $domiciliation;
return $this;
}
public function getDomiciliation(): ?string
{
return $this->domiciliation;
}
public function setDomiciliation2(?string $domiciliation2): Acompte
{
$this->domiciliation2 = $domiciliation2;
return $this;
}
public function getDomiciliation2(): ?string
{
return $this->domiciliation2;
}
public function setBor(?bool $bor): Acompte
{
$this->bor = $bor;
return $this;
}
public function getBor(): ?bool
{
return $this->bor;
}
public function setCodeEtablissement(?string $codeEtablissement): Acompte
{
$this->codeEtablissement = $codeEtablissement;
return $this;
}
public function getCodeEtablissement(): ?string
{
return $this->codeEtablissement;
}
public function setCodeGuichet(?string $codeGuichet): Acompte
{
$this->codeGuichet = $codeGuichet;
return $this;
}
public function getCodeGuichet(): ?string
{
return $this->codeGuichet;
}
public function setNumCompte(?string $numCompte): Acompte
{
$this->numCompte = $numCompte;
return $this;
}
public function getNumCompte(): ?string
{
return $this->numCompte;
}
public function setCleCompte(?string $cleCompte): Acompte
{
$this->cleCompte = $cleCompte;
return $this;
}
public function getCleCompte(): ?string
{
return $this->cleCompte;
}
public function setIBAN(?string $iBAN): Acompte
{
$this->iBAN = $iBAN;
return $this;
}
public function getIBAN(): ?string
{
return $this->iBAN;
}
public function setBIC(?string $bIC): Acompte
{
$this->bIC = $bIC;
return $this;
}
public function getBIC(): ?string
{
return $this->bIC;
}
public function setNumRUM(?string $numRUM): Acompte
{
$this->numRUM = $numRUM;
return $this;
}
public function getNumRUM(): ?string
{
return $this->numRUM;
}
public function setDateContrat(?DateTime $dateContrat): Acompte
{
$this->dateContrat = $dateContrat;
return $this;
}
public function getDateContrat(): ?DateTime
{
return $this->dateContrat;
}
public function setLieuContrat(?string $lieuContrat): Acompte
{
$this->lieuContrat = $lieuContrat;
return $this;
}
public function getLieuContrat(): ?string
{
return $this->lieuContrat;
}
public function setRefTire(?string $refTire): Acompte
{
$this->refTire = $refTire;
return $this;
}
public function getRefTire(): ?string
{
return $this->refTire;
}
public function setRefTireur(?string $refTireur): Acompte
{
$this->refTireur = $refTireur;
return $this;
}
public function getRefTireur(): ?string
{
return $this->refTireur;
}
public function setCodeBanque(?string $codeBanque): Acompte
{
$this->codeBanque = $codeBanque;
return $this;
}
public function getCodeBanque(): ?string
{
return $this->codeBanque;
}
public function setCodeTransfert(?string $codeTransfert): Acompte
{
$this->codeTransfert = $codeTransfert;
return $this;
}
public function getCodeTransfert(): ?string
{
return $this->codeTransfert;
}
public function setCodeAcceptation(?string $codeAcceptation): Acompte
{
$this->codeAcceptation = $codeAcceptation;
return $this;
}
public function getCodeAcceptation(): ?string
{
return $this->codeAcceptation;
}
public function setTransfertCompta(bool $transfertCompta): Acompte
{
$this->transfertCompta = $transfertCompta;
return $this;
}
public function getTransfertCompta(): bool
{
return $this->transfertCompta;
}
public function setClient(?Client $client): Acompte
{
$this->client = $client;
if($client->getBanque() != "" and $client->getBanque() != null)$this->setCodeBanque($client->getBanque());
if($client->getGuichet() != "" and $client->getGuichet() != null)$this->setCodeGuichet($client->getGuichet());
if($client->getNCpteBanque() != "" and $client->getNCpteBanque() != null)$this->setNumCompte ($client->getNCpteBanque());
if($client->getCleBanque() != "" and $client->getCleBanque() != null)$this->setCleCompte($client->getCleBanque());
if($client->getDomiciliation1() != "" and $client->getDomiciliation1() != null)$this->setDomiciliation($client->getDomiciliation1());
if($client->getDomiciliation2() != "" and $client->getDomiciliation2() != null)$this->setDomiciliation2($client->getDomiciliation2());
if($client->getIban() != "" and $client->getIban() != null)$this->setIBAN($client->getIban());
if($client->getBic() != "" and $client->getBic() != null)$this->setBIC($client->getBic());
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setDevise(?Devise $devise): Acompte
{
$this->devise = $devise;
return $this;
}
public function getDevise(): ?Devise
{
return $this->devise;
}
public function addFacture(Commande $facture): Acompte
{
$this->factures[] = $facture;
return $this;
}
public function removeFacture(Commande $facture)
{
$this->factures->removeElement($facture);
}
public function getFactures(): Collection
{
return $this->factures;
}
public function setBordereauLCR(?BordereauLCR $bordereauLCR): Acompte
{
$this->bordereauLCR = $bordereauLCR;
return $this;
}
public function getBordereauLCR(): BordereauLCR
{
return $this->bordereauLCR;
}
public function setCompteBancaireSociete(?CompteBancaire $compteBancaireSociete): Acompte
{
$this->compteBancaireSociete = $compteBancaireSociete;
return $this;
}
public function getCompteBancaireSociete(): ?CompteBancaire
{
return $this->compteBancaireSociete;
}
public function setDateEcheance(?DateTime $dateEcheance): Acompte
{
$this->dateEcheance = $dateEcheance;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setDateEcheanceAuto(){
if(is_object($this->client) and !is_object($this->dateEcheance)) {
$client = $this->client;
//Calcul de l'échéance
if(is_object($client->getDelaiPaiement()))
$delai = $client->getDelaiPaiement()->getId();
else
$delai = 0;
if(is_object($this->commande)){
$date = $this->commande->getDate();
} else {
$date = new DateTime();
}
switch ($delai) {
case 1://30 jours fin de mois
$interval = new DateInterval( "P30D" );
$date->add($interval);
$echeance = new DateTime('last day of '.$date->format('F Y'));
break;
case 2://A reception facture
$echeance = $date;
break;
case 3://30 jours
$echeance = $date;
$interval = new DateInterval( "P30D" );
$echeance->add($interval);
break;
case 4://45 jours fin de mois
$interval = new DateInterval( "P45D" );
$date->add($interval);
$echeance = new DateTime('last day of '.$date->format('F Y'));
break;
case 5://60 jours
$echeance = $date;
$interval = new DateInterval( "P60D" );
$echeance->add($interval);
break;
default:
$echeance = $date;
}
$this->setDateEcheance($echeance);
} elseif(!is_object($this->dateEcheance)) {
$echeance = $this->date;
$this->setDateEcheance($echeance);
}
}
public function getDateEcheance(): ?DateTime
{
return $this->dateEcheance;
}
public function setBordereau(?Bordereau $bordereau): Acompte
{
$this->bordereau = $bordereau;
return $this;
}
public function getBordereau(): ?Bordereau
{
return $this->bordereau;
}
public function setOperationDiverse(?float $operationDiverse): Acompte
{
$this->operationDiverse = $operationDiverse;
return $this;
}
public function getOperationDiverse(): ?float
{
return $this->operationDiverse;
}
public function setParent(?Commande $parent): Acompte
{
$this->parent = $parent;
return $this;
}
public function getParent(): ?Commande
{
return $this->parent;
}
public function setRemboursement(?Acompte $remboursement): Acompte
{
$this->remboursement = $remboursement;
return $this;
}
public function getRemboursement(): ?Acompte
{
return $this->remboursement;
}
public function setCommentaire(?string $commentaire): Acompte
{
$this->commentaire = $commentaire;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setAcompteParent(?Acompte $acompteParent): Acompte
{
$this->acompteParent = $acompteParent;
return $this;
}
public function getAcompteParent(): ?Acompte
{
return $this->acompteParent;
}
public function setEstParent(?bool $estParent): Acompte
{
$this->estParent = $estParent;
return $this;
}
public function getEstParent(): ?bool
{
return $this->estParent;
}
public function setReglementParent(?Acompte $reglementParent): Acompte
{
$this->reglementParent = $reglementParent;
return $this;
}
public function getReglementParent(): ?Acompte
{
return $this->reglementParent;
}
public function addReglementsEnfant(Acompte $reglementsEnfant): Acompte
{
$this->reglementsEnfant[] = $reglementsEnfant;
return $this;
}
public function removeReglementsEnfant(Acompte $reglementsEnfant)
{
$this->reglementsEnfant->removeElement($reglementsEnfant);
}
public function getReglementsEnfant(): Collection
{
return $this->reglementsEnfant;
}
public function setAvoir(?Commande $avoir): Acompte
{
$this->avoir = $avoir;
return $this;
}
public function getAvoir(): ?Commande
{
return $this->avoir;
}
public function setMouvementCaisse(?MouvementCaisse $mouvementCaisse): Acompte
{
$this->mouvementCaisse = $mouvementCaisse;
return $this;
}
public function getMouvementCaisse(): ?MouvementCaisse
{
return $this->mouvementCaisse;
}
public function setMouvementEquilibrage(?bool $mouvementEquilibrage): Acompte
{
$this->mouvementEquilibrage = $mouvementEquilibrage;
return $this;
}
public function getMouvementEquilibrage(): ?bool
{
return $this->mouvementEquilibrage;
}
public function setHorsErp(?bool $horsErp): Acompte
{
$this->horsErp = $horsErp;
return $this;
}
public function getHorsErp(): ?bool
{
return $this->horsErp;
}
public function setSolde(?float $solde): Acompte
{
$this->solde = $solde;
return $this;
}
public function getSolde(): ?float
{
return $this->solde;
}
public function setLettrage(?string $lettrage): Acompte
{
$this->lettrage = $lettrage;
return $this;
}
public function getLettrage(): ?string
{
return $this->lettrage;
}
public function setNumeroLettrage(?float $numeroLettrage): Acompte
{
$this->numeroLettrage = $numeroLettrage;
if($numeroLettrage == null) {
$this->setLettrage(null);
} else {
$lettres = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
$lettrage = '';
$reste = floatval($numeroLettrage);
$lettrage .= $reste . ' ';
$premiereLettreKey = $reste % 26;
$lettrage .= $premiereLettreKey . ' ';
$reste -= $premiereLettreKey;
$lettrage .= $reste . ' ';
$deuxiemeLettreKey = $reste % (26*26);
$lettrage .= $deuxiemeLettreKey . ' ';
$reste -= $deuxiemeLettreKey;
$lettrage .= $reste . ' ';
$deuxiemeLettreKey = $deuxiemeLettreKey / 26;
$lettrage .= $deuxiemeLettreKey . ' ';
$troisiemeLettreKey = $reste % (26*26*26);
$troisiemeLettreKey = $troisiemeLettreKey / (26*26);
$premiereLettre = $lettres[$premiereLettreKey];
$deuxiemeLettre = $lettres[$deuxiemeLettreKey];
$troisiemeLettre = $lettres[$troisiemeLettreKey];
$lettrage = $troisiemeLettre.$deuxiemeLettre.$premiereLettre;
$this->setLettrage($lettrage);
}
return $this;
}
public function getNumeroLettrage(): ?float
{
return $this->numeroLettrage;
}
public function setIdImport(?string $idImport): Acompte
{
$this->idImport = $idImport;
return $this;
}
public function getIdImport(): ?string
{
return $this->idImport;
}
public function setIdTransaction(?string $idTransaction): Acompte
{
$this->idTransaction = $idTransaction;
return $this;
}
public function getIdTransaction(): ?string
{
return $this->idTransaction;
}
}