Skip to content

Commit

Permalink
afup#1428 calcul de TVA
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Jan 22, 2024
1 parent 5f11bb8 commit 398ea39
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
6 changes: 5 additions & 1 deletion sources/Afup/Comptabilite/Comptabilite.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,11 @@ function extraireComptaDepuisCSVBanque(Importer $importer)
'',
$operationQualified['evenement'],
$operationQualified['numero_operation'],
$operationQualified['attachmentRequired']
$operationQualified['attachmentRequired'],
$operationQualified['montant_ht_soumis_tva_0'],
$operationQualified['montant_ht_soumis_tva_5_5'],
$operationQualified['montant_ht_soumis_tva_10'],
$operationQualified['montant_ht_soumis_tva_20']
);
} else {
$modifier = false;
Expand Down
10 changes: 10 additions & 0 deletions sources/AppBundle/Compta/Importer/AutoQualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function qualify(Operation $operation): array
break;
}

// init VAT
$operationQualified['montant_ht_soumis_tva_0'] = null;
$operationQualified['montant_ht_soumis_tva_5_5'] = null;
$operationQualified['montant_ht_soumis_tva_10'] = null;
$operationQualified['montant_ht_soumis_tva_20'] = null;

foreach($this->rules as $rule) {
if (($operation->isCredit() === (bool) $rule['is_credit']) || is_null($rule['is_credit'])) {
if (0 === strpos($operationQualified['description'], $rule['condition'])) {
Expand All @@ -63,6 +69,10 @@ public function qualify(Operation $operation): array
if (null !== $rule['mode_regl_id']) {
$operationQualified['idModeReglement'] = $rule['mode_regl_id'];
}
if (null !== $rule['vat']) {
$tx = ['0' => 0, '5_5' => 0.055, '10' => 0.1, '20' => 0.2];
$operationQualified['montant_ht_soumis_tva_'.$rule['vat']] = round($operationQualified['montant'] / (1+$tx[$rule['vat']]), 2);
}
break;
}
}
Expand Down
42 changes: 23 additions & 19 deletions tests/units/AppBundle/Compta/Importer/AutoQualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,52 @@ public function qualifierData(): array
{
return [
'sprd.net' => ['VIR SEPA sprd.net AG blablabla', Operation::CREDIT,
ComptaModeReglement::VIREMENT, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::GOODIES, 1],
ComptaModeReglement::VIREMENT, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::GOODIES, 1, 100, 'montant_ht_soumis_tva_0'],
'COM AFUP' => ['*CB COM AFUP blablabla', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, TestedClass::DEFAULT_ATTACHMENT],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, TestedClass::DEFAULT_ATTACHMENT, 94.79, 'montant_ht_soumis_tva_5_5'],
'COTIS ASSOCIATIS' => ['* COTIS ASSOCIATIS ESSENTIEL blablabla', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, TestedClass::DEFAULT_ATTACHMENT],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, TestedClass::DEFAULT_ATTACHMENT, 90.91, 'montant_ht_soumis_tva_10'],
'URSSAF' => ['PRLV URSSAF blablabla', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::CHARGES_SOCIALES, TestedClass::DEFAULT_ATTACHMENT],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::CHARGES_SOCIALES, TestedClass::DEFAULT_ATTACHMENT, 83.33, 'montant_ht_soumis_tva_20'],
'DGFIP' => ['PRLV B2B DGFIP', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::PRELEVEMENT_SOURCE, TestedClass::DEFAULT_ATTACHMENT],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::PRELEVEMENT_SOURCE, TestedClass::DEFAULT_ATTACHMENT, null, null],
'RETRAITE' => ['PRLV A3M - RETRAITE - MALAKOFF HUMANIS blablabla', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::CHARGES_SOCIALES, TestedClass::DEFAULT_ATTACHMENT],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::CHARGES_SOCIALES, TestedClass::DEFAULT_ATTACHMENT, null, null],
'Online.net' => ['PRLV Online SAS - blablabla', Operation::DEBIT,
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1],
ComptaModeReglement::PRELEVEMENT, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1, null, null],
'meetup.org' => ['CB MEETUP ORG blablabla', Operation::DEBIT,
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::MEETUP, 1],
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::MEETUP, 1, null, null],
'POINT TRANSACTION' => ['PRLV POINT TRANSACTION SYSTEM - blablabla',
Operation::DEBIT, ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, 1],
Operation::DEBIT, ComptaModeReglement::PRELEVEMENT, ComptaEvenement::GESTION, ComptaCategorie::FRAIS_DE_COMPTE, 1, null, null],
'Mailchimp' => ['CB MAILCHIMP FACT blablabla', Operation::DEBIT,
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::MAILCHIMP, 1],
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::MAILCHIMP, 1, null, null],
'AWS' => ['CB AWS EMEA FACT blablabla', Operation::DEBIT,
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1],
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1, null, null],
'gandi.net' => ['CB GANDI FACT blablabla', Operation::DEBIT,
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::GANDI, 1],
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::GANDI, 1, null, null],
'Twilio' => ['CB Twilio blablabla', Operation::DEBIT,
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1],
ComptaModeReglement::CB, ComptaEvenement::ASSOCIATION_AFUP, ComptaCategorie::OUTILS, 1, null, null],
];
}

/**
* @dataProvider qualifierData
*/
public function testQualifier($operationDescription, $operationType,
$expectedIdModeReglement, $expectedEvenement, $expectedCategorie, $expectedAttachment)
$expectedIdModeReglement, $expectedEvenement, $expectedCategorie, $expectedAttachment, $expectedHT, $expectedHTKey)
{
$operation = new Operation('2022-02-22', $operationDescription, '123', $operationType, '1234');
$operation = new Operation('2022-02-22', $operationDescription, '100', $operationType, '1234');
$qualifier = new TestedClass($this->fakeBD());
$actual = $qualifier->qualify($operation);

$this->integer($actual['categorie'])->isEqualTo($expectedCategorie);
$this->integer($actual['evenement'])->isEqualTo($expectedEvenement);
$this->integer($actual['idModeReglement'])->isEqualTo($expectedIdModeReglement);
$this->integer($actual['attachmentRequired'])->isEqualTo($expectedAttachment);
if ($expectedHTKey) {
$this->float($actual[$expectedHTKey])->isEqualTo($expectedHT);
}

}

private function fakeBD():array {
Expand All @@ -109,7 +113,7 @@ private function fakeBD():array {
'condition' => 'VIR SEPA sprd.net AG',
'is_credit' => '1',
'mode_regl_id' => ComptaModeReglement::VIREMENT,
'vat' => null,
'vat' => '0',
'category_id' => ComptaCategorie::GOODIES,
'event_id' => ComptaEvenement::ASSOCIATION_AFUP,
'attachment_required' => 1,
Expand All @@ -120,7 +124,7 @@ private function fakeBD():array {
'condition' => '*CB COM AFUP ',
'is_credit' => 0,
'mode_regl_id' => ComptaModeReglement::PRELEVEMENT,
'vat' => null,
'vat' => '5_5',
'category_id' => ComptaCategorie::FRAIS_DE_COMPTE,
'event_id' => ComptaEvenement::GESTION,
'attachment_required' => null,
Expand All @@ -131,7 +135,7 @@ private function fakeBD():array {
'condition' => '* COTIS ASSOCIATIS ESSENTIEL',
'is_credit' => 0,
'mode_regl_id' => ComptaModeReglement::PRELEVEMENT,
'vat' => null,
'vat' => '10',
'category_id' => ComptaCategorie::FRAIS_DE_COMPTE,
'event_id' => ComptaEvenement::GESTION,
'attachment_required' => null,
Expand All @@ -142,7 +146,7 @@ private function fakeBD():array {
'condition' => 'PRLV URSSAF',
'is_credit' => 0,
'mode_regl_id' => ComptaModeReglement::PRELEVEMENT,
'vat' => null,
'vat' => '20',
'category_id' => ComptaCategorie::CHARGES_SOCIALES,
'event_id' => ComptaEvenement::GESTION,
'attachment_required' => null,
Expand Down

0 comments on commit 398ea39

Please sign in to comment.