Browse Source

TaxRate : refactoring

feature/rotating_product
Guillaume Bourgeois 5 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



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


if ($model->load(\Yii::$app->request->post()) && $model->save()) { if ($model->load(\Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe créée.'); $this->setFlash('success', 'Taxe créée.');


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

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

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


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

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

</tr> </tr>


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

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



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


/**
* @inheritdoc
*/
public function rules() public function rules()
{ {
return [ return [
]; ];
} }


/**
* @inheritdoc
*/
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
'value' => 'Valeur (0.2 pour 20%)', '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



return $taxRate; return $taxRate;
} }

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

$this->saveCreate($taxRate);

return $taxRate;
}
} }

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

<?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