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.'); |
</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"> |
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; | |||||
} | |||||
} | } |
return $taxRate; | return $taxRate; | ||||
} | } | ||||
public function createTaxRate(): TaxRate | |||||
{ | |||||
$taxRate = $this->instanciateTaxRate(); | |||||
$this->saveCreate($taxRate); | |||||
return $taxRate; | |||||
} | |||||
} | } |
<?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; | |||||
} | |||||
} |