Browse Source

Documents : méthode de calcul TVA #478

refactoring
Guillaume Bourgeois 2 years ago
parent
commit
6049868897
3 changed files with 30 additions and 29 deletions
  1. +3
    -1
      backend/controllers/DocumentController.php
  2. +27
    -26
      common/models/Document.php
  3. +0
    -2
      console/migrations/m220916_062206_add_column_document_tax_calculation_method.php

+ 3
- 1
backend/controllers/DocumentController.php View File

); );


foreach($validatedDocumentsArray as $document) { foreach($validatedDocumentsArray as $document) {
$document->generatePdf(Pdf::DEST_FILE);
if(!file_exists($document->getFilenameComplete())) {
$document->generatePdf(Pdf::DEST_FILE);
}
} }
} }



+ 27
- 26
common/models/Document.php View File

{ {
$filenameComplete = $this->getFilenameComplete(); $filenameComplete = $this->getFilenameComplete();


if(!file_exists($filenameComplete)) {
if (!file_exists($filenameComplete)) {
$this->generatePdf(Pdf::DEST_FILE); $this->generatePdf(Pdf::DEST_FILE);
} }


if(file_exists($filenameComplete)) {
return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline'=>true]);
}
else {
throw new ErrorException('File '.$filenameComplete.' not found');
if (file_exists($filenameComplete)) {
return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline' => true]);
} else {
throw new ErrorException('File ' . $filenameComplete . ' not found');
} }
} }


if ($ordersArray && count($ordersArray)) { if ($ordersArray && count($ordersArray)) {
foreach ($ordersArray as $order) { foreach ($ordersArray as $order) {
foreach ($order->productOrder as $productOrder) { foreach ($order->productOrder as $productOrder) {
$indexProductOrder = $productOrder->product->order;
$newProductOrder = clone $productOrder;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
if ($theProductOrder->unit == $productOrder->unit
&& ((!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price)
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price)
)) {

$theProductOrder->quantity += $productOrder->quantity;
$productOrderMatch = true;
if ($productOrder->product) {
$indexProductOrder = $productOrder->product->order;
$newProductOrder = clone $productOrder;

if (!isset($productsOrdersArray[$indexProductOrder])) {
$productsOrdersArray[$indexProductOrder] = [$newProductOrder];
} else {
$productOrderMatch = false;
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) {
if ($theProductOrder->unit == $productOrder->unit
&& ((!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price)
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price)
)) {

$theProductOrder->quantity += $productOrder->quantity;
$productOrderMatch = true;
}
}
if (!$productOrderMatch) {
$productsOrdersArray[$indexProductOrder][] = $newProductOrder;
} }
}
if (!$productOrderMatch) {
$productsOrdersArray[$indexProductOrder][] = $newProductOrder;
} }
} }
} }


public function getAliasDirectoryBase() public function getAliasDirectoryBase()
{ {
return '@app/web/pdf/'.$this->id_producer.'/';
return '@app/web/pdf/' . $this->id_producer . '/';
} }


public function initDirectoryPdf() public function initDirectoryPdf()
{ {
$aliasDirectoryBase = $this->getAliasDirectoryBase(); $aliasDirectoryBase = $this->getAliasDirectoryBase();
$directoryPdf = Yii::getAlias($aliasDirectoryBase); $directoryPdf = Yii::getAlias($aliasDirectoryBase);
if(!file_exists($directoryPdf)) {
if (!file_exists($directoryPdf)) {
mkdir($directoryPdf, 0755); mkdir($directoryPdf, 0755);
} }
} }

+ 0
- 2
console/migrations/m220916_062206_add_column_document_tax_calculation_method.php View File

$columnTaxCalculationMethod = 'tax_calculation_method'; $columnTaxCalculationMethod = 'tax_calculation_method';
foreach(self::$tableDocumentArray as $tableName) { foreach(self::$tableDocumentArray as $tableName) {
$this->addColumn($tableName, $columnTaxCalculationMethod, $schemaTaxCalculationMethod); $this->addColumn($tableName, $columnTaxCalculationMethod, $schemaTaxCalculationMethod);
// méthode appliquée jusqu'à maintenant
$this->execute('UPDATE `'.$tableName.'` SET `'.$columnTaxCalculationMethod.'` = \''.Document::TAX_CALCULATION_METHOD_SUM_OF_ROUNDINGS.'\'');
} }
} }



Loading…
Cancel
Save