Browse Source

TaxRate : refactoring

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
6e951f8565
5 changed files with 57 additions and 26 deletions
  1. +3
    -7
      backend/controllers/TaxRateAdminController.php
  2. +1
    -1
      backend/views/document/download.php
  3. +29
    -9
      domain/Config/TaxRate/TaxRate.php
  4. +0
    -9
      domain/Config/TaxRate/TaxRateBuilder.php
  5. +24
    -0
      domain/Config/TaxRate/TaxRateManager.php

+ 3
- 7
backend/controllers/TaxRateAdminController.php View File

@@ -88,7 +88,7 @@ class TaxRateAdminController extends BackendController

public function actionCreate()
{
$model = $this-> getTaxRateModule()->instanciateTaxRate();
$model = $this->getTaxRateModule()->getBuilder()->instanciateTaxRate();

if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe créée.');
@@ -116,19 +116,15 @@ class TaxRateAdminController extends BackendController

public function actionDelete(int $id)
{
$taxRateModule = $this-> getTaxRateModule();
$taxRate = $this->findModel($id);
$taxRateModule->delete($taxRate);

$taxRate->delete();
$this->setFlash('success', 'Taxe supprimé');

return $this->redirect(['tax-rate-admin/index']);
}

protected function findModel($id)
{
$taxRateModule = $this-> getTaxRateModule();
if (($taxRate = $taxRateModule->findOneTaxRateById($id)) !== null) {
if (($taxRate = $this->getTaxRateModule()->getRepository()->findOneTaxRateById($id)) !== null) {
return $taxRate;
} else {
throw new NotFoundHttpException('The requested page does not exist.');

+ 1
- 1
backend/views/document/download.php View File

@@ -173,7 +173,7 @@ $documentPriceDecimals = (int) $producerModule->getConfig('option_document_price
</tr>

<?php
$taxRateArray = $this-> getTaxRateModule()->findTaxRatesAsArray();
$taxRateArray = $this-> getTaxRateModule()->getRepository()->findTaxRatesAsArray();
foreach ($documentModule->getTotalVatArray($document, $typeAmount) as $idTaxRate => $totalVat): ?>
<tr>
<td class="align-right" colspan="4">

+ 29
- 9
domain/Config/TaxRate/TaxRate.php View File

@@ -6,17 +6,11 @@ use common\components\ActiveRecordCommon;

class TaxRate extends ActiveRecordCommon
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'tax_rate';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
@@ -25,9 +19,6 @@ class TaxRate extends ActiveRecordCommon
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
@@ -36,4 +27,33 @@ class TaxRate extends ActiveRecordCommon
'value' => 'Valeur (0.2 pour 20%)',
];
}

/* Getters / Setters */

public function getId(): ?int
{
return $this->id;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): self
{
$this->name = $name;
return $this;
}

public function getValue(): ?float
{
return $this->value;
}

public function setValue(?float $value): self
{
$this->value = $value;
return $this;
}
}

+ 0
- 9
domain/Config/TaxRate/TaxRateBuilder.php View File

@@ -12,13 +12,4 @@ class TaxRateBuilder extends AbstractBuilder

return $taxRate;
}

public function createTaxRate(): TaxRate
{
$taxRate = $this->instanciateTaxRate();

$this->saveCreate($taxRate);

return $taxRate;
}
}

+ 24
- 0
domain/Config/TaxRate/TaxRateManager.php View File

@@ -0,0 +1,24 @@
<?php

namespace domain\Config\TaxRate;

use domain\_\AbstractManager;

class TaxRateManager extends AbstractManager
{
protected TaxRateBuilder $taxRateBuilder;

public function loadDependencies(): void
{
$this->taxRateBuilder = $this->loadService(TaxRateBuilder::class);
}

public function createTaxRate(string $name, float $value): TaxRate
{
$taxRate = $this->taxRateBuilder->instanciateTaxRate();
$taxRate->setName($name);
$taxRate->setValue($value);
$taxRate->save();
return $taxRate;
}
}

Loading…
Cancel
Save