Browse Source

Taxes : gestion de la TVA à 0% (auto entrepreneurs) #187

dev
Guillaume Bourgeois 4 years ago
parent
commit
25320bdd8a
7 changed files with 82 additions and 32 deletions
  1. +3
    -3
      backend/controllers/DocumentController.php
  2. +34
    -22
      backend/views/document/_form.php
  3. +26
    -4
      backend/views/document/download.php
  4. +3
    -1
      backend/views/product/_form.php
  5. +3
    -1
      backend/web/js/backend.js
  6. +3
    -1
      backend/web/js/vuejs/document-form.js
  7. +10
    -0
      common/models/Product.php

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



return [ return [
'return' => 'success', 'return' => 'success',
'tax_rate_producer' => GlobalParam::getCurrentProducer()->taxRate->value,
'document' => array_merge($document->getAttributes(), [ 'document' => array_merge($document->getAttributes(), [
'html_label' => $document->getHtmlLabel(), 'html_label' => $document->getHtmlLabel(),
'class' => $document->getClass() 'class' => $document->getClass()
]), ]),
'idUser' => $document->user->id,
'id_user' => $document->user->id,
'products' => ArrayHelper::map($productsArray, 'id', function ($product) { 'products' => ArrayHelper::map($productsArray, 'id', function ($product) {
return array_merge($product->getAttributes(), [ return array_merge($product->getAttributes(), [
'price_with_tax' => $product->price_with_tax, 'price_with_tax' => $product->price_with_tax,
$productOrder->price = (float)$price; $productOrder->price = (float)$price;
$productOrder->unit = $product->unit; $productOrder->unit = $product->unit;
$productOrder->step = $product->step; $productOrder->step = $product->step;
$productOrder->id_tax_rate = $productOrder->id_tax_rate ?
$product->taxRate->id : GlobalParam::getCurrentProducer()->taxRate->id;
$productOrder->id_tax_rate = $product->taxRate->id ;
$productOrder->save(); $productOrder->save();


return [ return [

+ 34
- 22
backend/views/document/_form.php View File

<tr> <tr>
<?php if($action == 'create'): ?><th></th><?php endif; ?> <?php if($action == 'create'): ?><th></th><?php endif; ?>
<th>Libellé</th> <th>Libellé</th>
<th>Montant (TTC)</th>
<th v-if="taxRateProducer != 0">Montant (TTC)</th>
<th v-else>Montant</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<div id="" class="info-box"> <div id="" class="info-box">
<span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span> <span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span>
<div class="info-box-content"> <div class="info-box-content">
<span class="info-box-text">Total (TTC)</span>
<span class="info-box-text">Total<span v-if="taxRateProducer != 0"> (TTC)</span></span>
<span class="info-box-number">{{ formatPrice(total_with_tax) }}</span> <span class="info-box-number">{{ formatPrice(total_with_tax) }}</span>
</div> </div>
</div> </div>
<input type="text" class="form-control input-price" <input type="text" class="form-control input-price"
v-model="productAddPrice" @change="formatProductAddPrice"/> v-model="productAddPrice" @change="formatProductAddPrice"/>
<span class="input-group-addon"><span <span class="input-group-addon"><span
class="glyphicon glyphicon-euro"></span> TTC</span>
class="glyphicon glyphicon-euro"></span> <span v-if="taxRateProducer != 0">TTC</span></span>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<input type="text" class="form-control input-price" readonly <input type="text" class="form-control input-price" readonly
:value="formatPrice(productAddPrice * productAddQuantity)"/> :value="formatPrice(productAddPrice * productAddQuantity)"/>
<span class="input-group-addon"><span <span class="input-group-addon"><span
class="glyphicon glyphicon-euro"></span> TTC</span>
class="glyphicon glyphicon-euro"></span> <span v-if="taxRateProducer != 0">TTC</span></span>
</div> </div>
<button class="btn btn-primary" value="Ajouter" <button class="btn btn-primary" value="Ajouter"
@click="submitProductAdd">Ajouter @click="submitProductAdd">Ajouter
<th>Nom</th> <th>Nom</th>
<th>Prix (unité)</th> <th>Prix (unité)</th>
<th>Quantité</th> <th>Quantité</th>
<th>TVA</th>
<th>Total TTC</th>
<th v-if="taxRateProducer != 0">TVA</th>
<th v-if="taxRateProducer != 0">Total TTC</th>
<th v-else>Total</th>
<th>Supprimer</th> <th>Supprimer</th>
</tr> </tr>
</thead> </thead>
</td> </td>
<td class="col-md-2">{{ formatPrice(productOrder.price) }}</td> <td class="col-md-2">{{ formatPrice(productOrder.price) }}</td>
<td class="col-md-2">{{ productOrder.quantity }}</td> <td class="col-md-2">{{ productOrder.quantity }}</td>
<td class="col-md-1">
<td class="col-md-1" v-if="taxRateProducer != 0">
{{ productsArray[productOrder.id_product].tax_rate * 100 }} % {{ productsArray[productOrder.id_product].tax_rate * 100 }} %
</td> </td>
<td class="col-md-2"> <td class="col-md-2">
</td> </td>
</tr> </tr>
</template> </template>
<tr>
<td colspan="4"><strong>Total HT</strong></td>
<td><strong>{{ formatPrice(total) }} HT</strong></td>
<td></td>
</tr>
<tr>
<td colspan="4"><strong>Montant TVA</strong></td>
<td><strong>{{ formatPrice(total_with_tax - total) }}</strong></td>
<td></td>
</tr>
<tr>
<td colspan="4"><strong>Total TTC</strong></td>
<td><strong>{{ formatPrice(total_with_tax) }} TTC</strong></td>
<td></td>
</tr>
<template v-if="taxRateProducer != 0">
<tr>
<td colspan="4"><strong>Total HT</strong></td>
<td><strong>{{ formatPrice(total) }} HT</strong></td>
<td></td>
</tr>
<tr>
<td colspan="4"><strong>Montant TVA</strong></td>
<td><strong>{{ formatPrice(total_with_tax - total) }}</strong></td>
<td></td>
</tr>
<tr>
<td colspan="4"><strong>Total TTC</strong></td>
<td><strong>{{ formatPrice(total_with_tax) }} TTC</strong></td>
<td></td>
</tr>
</template>
<template v-else>
<tr>
<td colspan="3"><strong>Total</strong></td>
<td><strong>{{ formatPrice(total) }}</strong></td>
<td></td>
</tr>
</template>

</tbody> </tbody>
</table> </table>
<div v-else class="alert alert-info"> <div v-else class="alert alert-info">

+ 26
- 4
backend/views/document/download.php View File

<thead> <thead>
<tr> <tr>
<th class="align-left">Produit</th> <th class="align-left">Produit</th>
<th>Prix unitaire HT</th>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value == 0): ?>
<th>Prix unitaire</th>
<?php else: ?>
<th>Prix unitaire HT</th>
<?php endif; ?>
<th>Quantité</th> <th>Quantité</th>
<th>Unité</th> <th>Unité</th>
<th>TVA</th>
<th>Prix HT</th>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value == 0): ?>
<th>Prix</th>
<?php else: ?>
<th>TVA</th>
<th>Prix HT</th>
<?php endif; ?>

</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<td class="align-center"><?= Price::format($productOrder->getPrice()) ?></td> <td class="align-center"><?= Price::format($productOrder->getPrice()) ?></td>
<td class="align-center"><?= $productOrder->quantity ?></td> <td class="align-center"><?= $productOrder->quantity ?></td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> <td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
<td class="align-center"><?= $productOrder->product->taxRate->value * 100 ?> %</td>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>
<td class="align-center"><?= $productOrder->taxRate->value * 100 ?> %</td>
<?php endif; ?>
<td class="align-center"><?= Price::format($productOrder->getPrice() * $productOrder->quantity) ?></td> <td class="align-center"><?= Price::format($productOrder->getPrice() * $productOrder->quantity) ?></td>

</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>
<tr> <tr>
<td class="align-right" colspan="5"><strong>Total HT</strong></td> <td class="align-right" colspan="5"><strong>Total HT</strong></td>
<td class="align-center"><?= Price::format($document->getAmount()) ?></td> <td class="align-center"><?= Price::format($document->getAmount()) ?></td>
<td class="align-right" colspan="5"><strong>Total TTC</strong></td> <td class="align-right" colspan="5"><strong>Total TTC</strong></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax()) ?></td> <td class="align-center"><?= Price::format($document->getAmountWithTax()) ?></td>
</tr> </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()) ?></td>
</tr>
<?php endif; ?>
</tbody> </tbody>
</table> </table>
<?php else : ?> <?php else : ?>

+ 3
- 1
backend/views/product/_form.php View File



?> ?>


<?= $form->field($model, 'id_tax_rate')->dropDownList($taxRateNamesArray, ['options' => $taxRateValuesArrayFormatted])->label('Taxe'); ?>
<?php if($taxRateDefault->value != 0): ?>
<?= $form->field($model, 'id_tax_rate')->dropDownList($taxRateNamesArray, ['options' => $taxRateValuesArrayFormatted])->label('Taxe'); ?>
<?php endif; ?>


<?= $form->field($model, 'price', [ <?= $form->field($model, 'price', [
'template' => ' 'template' => '

+ 3
- 1
backend/web/js/backend.js View File



function opendistrib_products_event_price_with_tax() { function opendistrib_products_event_price_with_tax() {
taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value'); taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');

if(typeof taxRateSelected == 'undefined') {
taxRateSelected = 0 ;
}
$('#product-price-with-tax').val(getPriceWithTax($('#product-price').val(), taxRateSelected)); $('#product-price-with-tax').val(getPriceWithTax($('#product-price').val(), taxRateSelected));
//formattage des prix //formattage des prix
$('#product-price').val(parseFloat($('#product-price').val()).toFixed(2)); $('#product-price').val(parseFloat($('#product-price').val()).toFixed(2));

+ 3
- 1
backend/web/js/vuejs/document-form.js View File

var app = new Vue({ var app = new Vue({
el: '#app-document-form', el: '#app-document-form',
data: { data: {
taxRateProducer: null,
document: [], document: [],
deliveryNotes: [], deliveryNotes: [],
idDocument: 0, idDocument: 0,
.then(function(response) { .then(function(response) {
if(response.data.return == 'success') { if(response.data.return == 'success') {
app.document = response.data.document ; app.document = response.data.document ;
app.idUser = response.data.idUser ;
app.taxRateProducer = response.data.tax_rate_producer ;
app.idUser = response.data.id_user ;
app.productsArray = response.data.products ; app.productsArray = response.data.products ;
app.ordersArray = response.data.orders ; app.ordersArray = response.data.orders ;
app.total = response.data.total ; app.total = response.data.total ;

+ 10
- 0
common/models/Product.php View File

return Price::getPriceWithTax($this->price, $this->taxRate->value); return Price::getPriceWithTax($this->price, $this->taxRate->value);
} }


public function getTheTaxRate()
{
if($this->id_tax_rate) {
return $this->id_tax_rate ;
}
else {
return GlobalParam::getCurrentProducer()->taxRate->id;
}
}



} }

Loading…
Cancel
Save