瀏覽代碼

[Backend] Documents : correctif export pdf

refactoring
Guillaume Bourgeois 2 年之前
父節點
當前提交
8cd27c22ac
共有 4 個檔案被更改,包括 161 行新增158 行删除
  1. +1
    -1
      backend/views/document/_download_product_line.php
  2. +156
    -152
      backend/views/document/download.php
  3. +1
    -1
      backend/views/site/index.php
  4. +3
    -4
      common/models/Document.php

+ 1
- 1
backend/views/document/_download_product_line.php 查看文件

</td> </td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> <td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
<?php if($displayPrices): ?> <?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>
<?php if($producer->taxRate->value != 0): ?>
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td> <td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>
<?php endif; ?> <?php endif; ?>
<td class="align-center"> <td class="align-center">

+ 156
- 152
backend/views/document/download.php 查看文件

<?php <?php


$displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$app->controller->getClass() == 'DeliveryNote' && Producer::getConfig('document_display_prices_delivery_note')) ;
$displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$app->controller->getClass() == 'DeliveryNote' && Producer::getConfig('document_display_prices_delivery_note'));
$displayProductDescription = Producer::getConfig('document_display_product_description'); $displayProductDescription = Producer::getConfig('document_display_product_description');


?> ?>


<div class="document-download"> <div class="document-download">


<div id="block-addresses">
<div class="producer">
<?php if(strlen($producer->logo)) : ?>
<div class="logo">
<img style="max-height: 80px;" src="<?= $producer->getUrlLogo() ?>" />
</div>
<?php endif; ?>
<div class="address"><?= $producer->getFullAddress(true) ; ?></div>
</div>
<div class="user">
<?php if($document->address && strlen($document->address) > 0): ?>
<?= nl2br($document->address) ?>
<?php else: ?>
<?= $document->user->getFullAddress(true) ; ?>
<?php endif; ?>
<div id="block-addresses">
<div class="producer">
<?php if (strlen($producer->logo)) : ?>
<div class="logo">
<img style="max-height: 80px;" src="<?= $producer->getUrlLogo() ?>"/>
</div> </div>
<?php endif; ?>
<div class="address"><?= $producer->getFullAddress(true); ?></div>
</div> </div>

<div id="block-infos-document">
<div class="date">
Le <?= strftime('%d %B %Y', strtotime($document->date)) ?>
</div>
<div class="reference">
<?php if(strlen($document->reference)) : ?>
<?= $document->getType(); ?> N°<?= $document->reference ; ?>
<?php else: ?>
<div class="block-is-draft"><?= $document->getType(); ?> non validé<?= ($document->getType() == 'Facture') ? 'e' : '' ?></div>
<?php endif; ?>
</div>
<div class="name">
<strong>Libellé : </strong><?= $document->name ; ?>
</div>
<div class="user">
<?php if ($document->address && strlen($document->address) > 0): ?>
<?= nl2br($document->address) ?>
<?php else: ?>
<?= $document->user->getFullAddress(true); ?>
<?php endif; ?>
</div> </div>
</div>


<?php if(strlen($document->comment)): ?>
<div class="block-infos">
<strong>Commentaire</strong><br />
<?= Html::encode($document->comment) ?>
</div>
<?php endif; ?>

<div id="block-products">
<?php if(count($document->orders) > 0) : ?>
<table class="table table-bordered">
<thead>
<tr>
<th class="align-left">Produit</th>
<?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value == 0): ?>
<th>Prix unitaire</th>
<?php else: ?>
<th>Prix unitaire HT</th>
<?php endif; ?>
<?php endif; ?>
<th>Quantité</th>
<th>Unité</th>
<?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value == 0): ?>
<th>Prix</th>
<?php else: ?>
<th>TVA</th>
<th>Prix HT</th>
<?php endif; ?>
<?php endif; ?>
<div id="block-infos-document">
<div class="date">
Le <?= strftime('%d %B %Y', strtotime($document->date)) ?>
</div>
<div class="reference">
<?php if (strlen($document->reference)) : ?>
<?= $document->getType(); ?> N°<?= $document->reference; ?>
<?php else: ?>
<div class="block-is-draft"><?= $document->getType(); ?> non
validé<?= ($document->getType() == 'Facture') ? 'e' : '' ?></div>
<?php endif; ?>
</div>
<div class="name">
<strong>Libellé : </strong><?= $document->name; ?>
</div>
</div>


</tr>
</thead>
<tbody>
<?php if (strlen($document->comment)): ?>
<div class="block-infos">
<strong>Commentaire</strong><br/>
<?= Html::encode($document->comment) ?>
</div>
<?php endif; ?>


<?php if($document->isDisplayOrders()): ?>
<?php foreach($document->orders as $order): ?>
<tr>
<td>
<strong><?= Html::encode($order->getUsername()) ; ?></strong>
<?php if($order->distribution): ?>
le <?= date('d/m/Y', strtotime($order->distribution->date)) ?>
<?php endif; ?>
</td>
<?php if($displayPrices): ?>
<td class="align-center"></td>
<?php endif; ?>
<td></td>
<td></td>
<?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>
<td class="align-center"></td>
<?php endif; ?>
<td class="align-center"></td>
<?php endif; ?>
</tr>
<?php foreach($order->productOrder as $productOrder): ?>
<?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder,
'displayOrders' => true,
'displayPrices' => $displayPrices,
'displayProductDescription' => $displayProductDescription
]) ?>
<?php endforeach; ?>
<?php endforeach; ?>
<div id="block-products">
<?php if (count($document->orders) > 0) : ?>
<table class="table table-bordered">
<thead>
<tr>
<th class="align-left">Produit</th>
<?php if ($displayPrices): ?>
<?php if ($producer->taxRate->value == 0): ?>
<th>Prix unitaire</th>
<?php else: ?> <?php else: ?>
<?php foreach($document->getProductsOrders() as $product): ?>
<?php foreach($product as $productOrder): ?>
<?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder,
'displayPrices' => $displayPrices,
'displayProductDescription' => $displayProductDescription
]) ?>
<?php endforeach; ?>
<?php endforeach; ?>
<th>Prix unitaire HT</th>
<?php endif; ?> <?php endif; ?>
<?php if($displayPrices): ?>
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL ; ?>
<?php endif; ?>
<th>Quantité</th>
<th>Unité</th>
<?php if ($displayPrices): ?>
<?php if ($producer->taxRate->value == 0): ?>
<th>Prix</th>
<?php else: ?>
<th>TVA</th>
<th>Prix HT</th>
<?php endif; ?>
<?php endif; ?>


<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>
</tr>
</thead>
<tbody>


<tr>
<td class="align-right" colspan="5"><strong>Total HT</strong></td>
<td class="align-center">
<?= Price::format($document->getAmount($typeAmount)); ?>
</td>
</tr>
<?php if ($document->isDisplayOrders()): ?>
<?php foreach ($document->orders as $order): ?>
<tr>
<td>
<strong><?= Html::encode($order->getUsername()); ?></strong>
<?php if ($order->distribution): ?>
le <?= date('d/m/Y', strtotime($order->distribution->date)) ?>
<?php endif; ?>
</td>
<?php if ($displayPrices): ?>
<td class="align-center"></td>
<?php endif; ?>
<td></td>
<td></td>
<?php if ($displayPrices): ?>
<?php if ($producer->taxRate->value != 0): ?>
<td class="align-center"></td>
<?php endif; ?>
<td class="align-center"></td>
<?php endif; ?>
</tr>
<?php foreach ($order->productOrder as $productOrder): ?>
<?= $this->render('_download_product_line', [
'producer' => $producer,
'document' => $document,
'productOrder' => $productOrder,
'displayOrders' => true,
'displayPrices' => $displayPrices,
'displayProductDescription' => $displayProductDescription
]) ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php else: ?>
<?php foreach ($document->getProductsOrders() as $product): ?>
<?php foreach ($product as $productOrder): ?>
<?= $this->render('_download_product_line', [
'producer' => $producer,
'document' => $document,
'productOrder' => $productOrder,
'displayPrices' => $displayPrices,
'displayProductDescription' => $displayProductDescription
]) ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($displayPrices): ?>
<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL; ?>


<?php
$taxRateArray = TaxRate::getTaxRateArray();
foreach($document->getTotalVatArray($typeAmount) as $idTaxRate => $totalVat): ?>
<tr>
<td class="align-right" colspan="5"><strong>TVA <?= $taxRateArray[$idTaxRate]->value * 100 ?> %</strong></td>
<td class="align-center">
<?= Price::format($totalVat); ?>
</td>
</tr>
<?php endforeach; ?>
<?php if ($producer->taxRate->value != 0): ?>


<!--<tr>
<tr>
<td class="align-right" colspan="5"><strong>Total HT</strong></td>
<td class="align-center">
<?= Price::format($document->getAmount($typeAmount)); ?>
</td>
</tr>

<?php
$taxRateArray = TaxRate::getTaxRateArray();
foreach ($document->getTotalVatArray($typeAmount) as $idTaxRate => $totalVat): ?>
<tr>
<td class="align-right" colspan="5">
<strong>TVA <?= $taxRateArray[$idTaxRate]->value * 100 ?> %</strong></td>
<td class="align-center">
<?= Price::format($totalVat); ?>
</td>
</tr>
<?php endforeach; ?>

<!--<tr>
<td class="align-right" colspan="5"><strong>TVA</strong></td> <td class="align-right" colspan="5"><strong>TVA</strong></td>
<td class="align-center"> <td class="align-center">
<?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($typeAmount)) ?> <?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($typeAmount)) ?>
</td> </td>
</tr>--> </tr>-->
<tr>
<td class="align-right" colspan="5"><strong>Total TTC</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax($typeAmount)) ?></td>
</tr>
<?php else: ?>
<tr>
<td class="align-right" colspan="4">
<strong>Total</strong><br />
TVA non applicable
</td>
<td class="align-center"><?= Price::format($document->getAmount($typeAmount)) ?></td>
</tr>
<?php endif; ?>
<?php endif; ?>
</tbody>
</table>
<?php else : ?>
<div id="block-no-product">
<strong>Aucun produit</strong>
</div>
<tr>
<td class="align-right" colspan="5"><strong>Total TTC</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax($typeAmount)) ?></td>
</tr>
<?php else: ?>
<tr>
<td class="align-right" colspan="4">
<strong>Total</strong><br/>
TVA non applicable
</td>
<td class="align-center"><?= Price::format($document->getAmount($typeAmount)) ?></td>
</tr>
<?php endif; ?>
<?php endif; ?> <?php endif; ?>
</div>
</tbody>
</table>
<?php else : ?>
<div id="block-no-product">
<strong>Aucun produit</strong>
</div>
<?php endif; ?>
</div>


<?php
$fieldProducerDocumentInfo = 'document_infos_'.str_replace('deliverynote','delivery_note',strtolower($document->getClass())) ; ?>
<?php if(strlen($producer->$fieldProducerDocumentInfo)): ?>
<?php
$fieldProducerDocumentInfo = 'document_infos_' . str_replace('deliverynote', 'delivery_note', strtolower($document->getClass())); ?>
<?php if (strlen($producer->$fieldProducerDocumentInfo)): ?>
<div class="block-infos"> <div class="block-infos">
<strong>Informations</strong><br />
<?= nl2br(Html::encode($producer->$fieldProducerDocumentInfo)) ?>
<strong>Informations</strong><br/>
<?= nl2br(Html::encode($producer->$fieldProducerDocumentInfo)) ?>
</div> </div>
<?php endif; ?>
<?php endif; ?>
</div> </div>

+ 1
- 1
backend/views/site/index.php 查看文件



use yii\helpers\Html ; use yii\helpers\Html ;


$this->title = 'Tableau de bord';
$this->setTitle('Tableau de bord');


?> ?>
<div class="site-index"> <div class="site-index">

+ 3
- 4
common/models/Document.php 查看文件

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


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


if (file_exists($filenameComplete)) { if (file_exists($filenameComplete)) {
return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline' => true]); return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline' => true]);


public function generatePdf($destination) public function generatePdf($destination)
{ {
$producer = GlobalParam::getCurrentProducer();
$producer = $this->producer;
$content = Yii::$app->controller->renderPartial('/document/download', [ $content = Yii::$app->controller->renderPartial('/document/download', [
'producer' => $producer, 'producer' => $producer,
'document' => $this 'document' => $this

Loading…
取消
儲存