Skip to content

Commit

Permalink
Merge pull request #3 from A5sys/init-reader
Browse files Browse the repository at this point in the history
Add reading FEC file functionnality
  • Loading branch information
thomasbeaujean authored Dec 16, 2016
2 parents 507c702 + 9a0e3cf commit 17476e7
Show file tree
Hide file tree
Showing 29 changed files with 740 additions and 99 deletions.
13 changes: 11 additions & 2 deletions Computer/ComputerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace A5sys\FecBundle\Computer;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;

/**
* Interface representing a computer, so that is capable to calculate some values from a EcritureComptableInterface or one of its child
Expand All @@ -16,5 +16,14 @@ interface ComputerInterface
*
* @return array
*/
public function compute(EcritureComptableInterface $ecritureComptableInterface);
public function toArray(EcritureComptableInterface $ecritureComptableInterface);

/**
* compute data to an ecritureComptableinterface
* @param EcritureComptableInterface $ecritureComptableInterface
* @param array $data the FEC entry
*
* @return EcritureComptableInterface
*/
public function toValueObject(EcritureComptableInterface $ecritureComptableInterface, array $data);
}
20 changes: 18 additions & 2 deletions Computer/DebitCredit/DebitCreditComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace A5sys\FecBundle\Computer\DebitCredit;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\Exception\FecException;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;

/**
* Compute Debit and Credit fields according to input into an assoc array
Expand All @@ -28,7 +29,7 @@ public function getFieldNames()
* @param EcritureComptableInterface $ecritureComptable
* @return type
*/
public function compute(EcritureComptableInterface $ecritureComptable)
public function toArray(EcritureComptableInterface $ecritureComptable)
{
$data = array();

Expand All @@ -37,4 +38,19 @@ public function compute(EcritureComptableInterface $ecritureComptable)

return $data;
}

/**
* Compute Debit and Credit Fields
* @param EcritureComptableInterface $ecritureComptable
* @param array $data the FEC entry
*
* @return EcritureComptableInterface
*/
public function toValueObject(EcritureComptableInterface $ecritureComptable, array $data)
{
$ecritureComptable->setDebit($data['Debit']);
$ecritureComptable->setCredit($data['Credit']);

return $data;
}
}
1 change: 0 additions & 1 deletion Computer/DebitCredit/DebitCreditComputerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace A5sys\FecBundle\Computer\DebitCredit;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\Computer\ComputerInterface;

/**
Expand Down
32 changes: 30 additions & 2 deletions Computer/DebitCredit/MontantSensAlphaComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace A5sys\FecBundle\Computer\DebitCredit;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\Exception\FecException;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;

/**
* Compute Montant and Sens fields in alphanumeric mode according to input into an assoc array
Expand Down Expand Up @@ -31,7 +32,7 @@ public function getFieldNames()
* @param EcritureComptableInterface $ecritureComptable
* @return type
*/
public function compute(EcritureComptableInterface $ecritureComptable)
public function toArray(EcritureComptableInterface $ecritureComptable)
{
$data = array();

Expand All @@ -47,4 +48,31 @@ public function compute(EcritureComptableInterface $ecritureComptable)

return $data;
}

/**
* Compute Debit and Credit Fields
* @param EcritureComptableInterface $ecritureComptable
* @param array $data the FEC entry
*
* @throw FecException
* @return EcritureComptableInterface
*/
public function toValueObject(EcritureComptableInterface $ecritureComptable, array $data)
{
if (!isset($data['Sens']) || !isset($data['Montant'])) {
throw new FecException('Fields "Sens" and "Montant" are mandatory when using the computer '.get_class($this));
}

if ($data['Sens'] !== static::DEBIT || $data['Sens'] !== static::CREDIT) {
throw new FecException('Field "Sens" must be one of "'.static::DEBIT.'" or "'.static::CREDIT.'" when using the computer '.get_class($this));
}

if ($data['Sens'] === static::DEBIT) {
$ecritureComptable->setDebit($data['Montant']);
} else {
$ecritureComptable->setCredit($data['Montant']);
}

return $data;
}
}
32 changes: 30 additions & 2 deletions Computer/DebitCredit/MontantSensNumComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace A5sys\FecBundle\Computer\DebitCredit;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\Exception\FecException;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;

/**
* Compute Montant and Sens in numeric fields according to input into an assoc array
Expand Down Expand Up @@ -31,7 +32,7 @@ public function getFieldNames()
* @param EcritureComptableInterface $ecritureComptable
* @return type
*/
public function compute(EcritureComptableInterface $ecritureComptable)
public function toArray(EcritureComptableInterface $ecritureComptable)
{
$data = array();

Expand All @@ -47,4 +48,31 @@ public function compute(EcritureComptableInterface $ecritureComptable)

return $data;
}

/**
* Compute Debit and Credit Fields
* @param EcritureComptableInterface $ecritureComptable
* @param array $data the FEC entry
*
* @throw FecException
* @return EcritureComptableInterface
*/
public function toValueObject(EcritureComptableInterface $ecritureComptable, array $data)
{
if (!isset($data['Sens']) || !isset($data['Montant'])) {
throw new FecException('Fields "Sens" and "Montant" are mandatory when using the computer '.get_class($this));
}

if ($data['Sens'] !== static::DEBIT || $data['Sens'] !== static::CREDIT) {
throw new FecException('Field "Sens" must be one of "'.static::DEBIT.'" or "'.static::CREDIT.'" when using the computer '.get_class($this));
}

if ($data['Sens'] === static::DEBIT) {
$ecritureComptable->setDebit($data['Montant']);
} else {
$ecritureComptable->setCredit($data['Montant']);
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace A5sys\FecBundle\Normalizer;

use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;
use A5sys\FecBundle\Validator\ValidatorInterface;

/**
* Normalize standard input to an assoc array
*/
class StandardNormalizer implements NormalizerInterface
abstract class AbstractStandardNormalizer implements NormalizerInterface
{
/**
* Validator of this normalizer
Expand Down Expand Up @@ -60,7 +60,7 @@ public function getFieldNames()
* @throw A5sys\FecBundle\Exception\FecValidationException
* @return array
*/
public function normalize(EcritureComptableInterface $ecritureComptable)
public function toArray(EcritureComptableInterface $ecritureComptable)
{
$this->validator->validate($ecritureComptable);

Expand All @@ -85,4 +85,41 @@ public function normalize(EcritureComptableInterface $ecritureComptable)

return $data;
}

/**
* Sets the standard properties on the EcritureComptableInterface instance
* Thos properties are set for all kind of EcritureComptableInterface implementing classes
* @param EcritureComptableInterface $ecritureComptable
* @param array $data
*/
protected function setStandardProperties(EcritureComptableInterface $ecritureComptable, $data)
{
$ecritureComptable->setJournalCode($data['JournalCode']);
$ecritureComptable->setJournalLib($data['JournalLib']);
$ecritureComptable->setEcritureNum($data['EcritureNum']);
$ecritureComptable->setEcritureDate($data['EcritureDate']);
$ecritureComptable->setCompteNum($data['CompteNum']);
$ecritureComptable->setCompteLib($data['CompteLib']);
$ecritureComptable->setCompAuxNum($data['CompAuxNum']);
$ecritureComptable->setCompAuxLib($data['CompAuxLib']);
$ecritureComptable->setPieceRef($data['PieceRef']);
$ecritureComptable->setPieceDate($data['PieceDate']);
$ecritureComptable->setEcritureLib($data['EcritureLib']);
$ecritureComptable->setEcritureLet($data['EcritureLet']);
$ecritureComptable->setDateLet($data['DateLet']);
$ecritureComptable->setValidDate($data['ValidDate']);
$ecritureComptable->setMontantdevise($data['Montantdevise']);
$ecritureComptable->setIdevise($data['Idevise']);
}

/**
* Validate the object
* @param EcritureComptableInterface $ecritureComptable
*
* @throw FecValidationException
*/
public function validateValueObject(EcritureComptableInterface $ecritureComptable)
{
$this->validator->validate($ecritureComptable);
}
}
38 changes: 33 additions & 5 deletions Normalizer/BATresorerieNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace A5sys\FecBundle\Normalizer;

use A5sys\FecBundle\Exception\FecException;
use A5sys\FecBundle\Input\EcritureBATresorerieInterface;
use A5sys\FecBundle\Input\EcritureComptableInterface;
use A5sys\FecBundle\ValueObject\EcritureBATresorerie;
use A5sys\FecBundle\ValueObject\EcritureBATresorerieInterface;
use A5sys\FecBundle\ValueObject\EcritureComptableInterface;

/**
* EN : Normalize input to an assoc array for BA Tresorerie
* FR : Normalise l'entrée en un tableau associatif pour les déclarations de trésorerie des bénéfices agricoles
*/
class BATresorerie extends StandardNormalizer
class BATresorerieNormalizer extends AbstractStandardNormalizer
{
/**
* Returns the names of the fields.
Expand All @@ -36,14 +37,14 @@ public function getFieldNames()
* @throw A5sys\FecBundle\Exception\FecValidationException
* @return array
*/
public function normalize(EcritureComptableInterface $ecritureComptable)
public function toArray(EcritureComptableInterface $ecritureComptable)
{
if (!$ecritureComptable instanceof EcritureBATresorerieInterface) {
throw new FecException(get_class($this).' accepts only EcritureBATresorerieInterface instances. Maybe check object list you gave to the manager.');
}

// validation in parent
$data = parent::normalize($ecritureComptable);
$data = parent::toArray($ecritureComptable);

// add new fields
$data['DateRglt'] = $ecritureComptable->getDateRglt();
Expand All @@ -52,4 +53,31 @@ public function normalize(EcritureComptableInterface $ecritureComptable)

return $data;
}

/**
* Normalize one array to an EcritureComptableInterface
* @param array $data
* @return EcritureBICIS
*/
public function toValueObject(array $data)
{
$ecritureComptable = new EcritureBATresorerie();

$this->setStandardProperties($ecritureComptable, $data);
$this->setBATresorerieProperties($ecritureComptable, $data);

return $ecritureComptable;
}

/**
* Set the BA Tresorerie specific properties
* @param EcritureBATresorerie $ecritureComptable
* @param array $data
*/
protected function setBATresorerieProperties(EcritureBATresorerie $ecritureComptable, $data)
{
$ecritureComptable->setDateRglt($data['DateRglt']);
$ecritureComptable->setModeRglt($data['ModeRglt']);
$ecritureComptable->setNatOp($data['NatOp']);
}
}
26 changes: 26 additions & 0 deletions Normalizer/BICISNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace A5sys\FecBundle\Normalizer;

use A5sys\FecBundle\ValueObject\EcritureBICIS;

/**
* EN : Normalize input to an assoc array for BIC/IS
* FR : Normalise l'entrée en un tableau associatif pour les déclarations BIC / IS
*/
class BICISNormalizer extends AbstractStandardNormalizer
{
/**
* Normalize one array to an EcritureComptableInterface
* @param array $data
* @return EcritureBICIS
*/
public function toValueObject(array $data)
{
$ecritureComptable = new EcritureBICIS();

$this->setStandardProperties($ecritureComptable, $data);

return $ecritureComptable;
}
}
26 changes: 26 additions & 0 deletions Normalizer/BNCBADroitCommercialNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace A5sys\FecBundle\Normalizer;

use A5sys\FecBundle\ValueObject\EcritureBNCBADroitCommercial;

/**
* EN : Normalize input to an assoc array for BNC/BA trade law
* FR : Normalise l'entrée en un tableau associatif pour les déclarations BNC / BA Droit commercial
*/
class BNCBADroitCommercialNormalizer extends AbstractStandardNormalizer
{
/**
* Normalize one array to an EcritureComptableInterface
* @param array $data
* @return EcritureBICIS
*/
public function toValueObject(array $data)
{
$ecritureComptable = new EcritureBNCBADroitCommercial();

$this->setStandardProperties($ecritureComptable, $data);

return $ecritureComptable;
}
}
Loading

0 comments on commit 17476e7

Please sign in to comment.