Browse Source

Adaptations prix spécifiques

refactoring
Guillaume 3 years ago
parent
commit
b49c6044d6
9 changed files with 90 additions and 49 deletions
  1. +23
    -5
      backend/controllers/DistributionController.php
  2. +0
    -24
      backend/controllers/DocumentController.php
  3. +18
    -2
      backend/views/document/_download_product_line.php
  4. +3
    -13
      backend/views/document/_form.php
  5. +11
    -4
      backend/views/document/download.php
  6. +1
    -1
      backend/views/invoice/index.php
  7. +15
    -0
      backend/web/js/vuejs/document-form.js
  8. +5
    -0
      common/models/Document.php
  9. +14
    -0
      common/models/Order.php

+ 23
- 5
backend/controllers/DistributionController.php View File



if($firstOrder->pointSale->id_user) { if($firstOrder->pointSale->id_user) {
$deliveryNote->id_user = $firstOrder->pointSale->id_user; $deliveryNote->id_user = $firstOrder->pointSale->id_user;
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
} }
else { else {
$user = new User ; $user = new User ;
$deliveryNote->id_user = $user->id; $deliveryNote->id_user = $user->id;
} }


if(!isset($user)) {
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
}
$deliveryNote->address = $user->getFullAddress() ; $deliveryNote->address = $user->getFullAddress() ;
$deliveryNote->save(); $deliveryNote->save();
} }
]) ; ]) ;
} }


if(!isset($user) || !$user) {
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
$userProducer = UserProducer::searchOne([
'id_user' => $deliveryNote->id_user,
'id_producer' => GlobalParam::getCurrentProducerId()
]) ;
}

// affectation du BL aux commandes // affectation du BL aux commandes
foreach ($idOrders as $idOrder) { foreach ($idOrders as $idOrder) {
$order = Order::searchOne([ $order = Order::searchOne([
$order->id_delivery_note = $deliveryNote->id; $order->id_delivery_note = $deliveryNote->id;
$order->save(); $order->save();
} }

// init invoice price
$order = Order::searchOne(['id' => $idOrder]) ;
if($order) {
$order->initInvoicePrices([
'user' => $user,
'user_producer' => $userProducer,
'point_sale' => $firstOrder->pointSale
]) ;
}
} }


return [ return [

+ 0
- 24
backend/controllers/DocumentController.php View File

], [ ], [
'id_delivery_note' => $idDeliveryNote 'id_delivery_note' => $idDeliveryNote
]) ; ]) ;

// mise à jour des prix facturés
$ordersArray = Order::searchAll([
'id_invoice' => $model->id
], [
'join_with' => ['distribution', 'user', 'user.userUserGroup', 'user.userProducer', 'pointSale', 'productOrder', 'productOrder.product', 'productOrder.product.productPrice']
]) ;

foreach($ordersArray as $order) {
$userProducer = UserProducer::searchOne([
'id_user' => $model->id_user,
'id_producer' => $order->distribution->id_producer,
]) ;
foreach($order->productOrder as $productOrder) {
if($productOrder->product) {
$productOrder->invoice_price = $productOrder->product->getPrice([
'user' => $model->user,
'user_producer' => $userProducer,
'point_sale' => $order->pointSale
]) ;
$productOrder->save() ;
}
}
}
} }
} }
} }

+ 18
- 2
backend/views/document/_download_product_line.php View File

<br /><small><?= Html::encode($productOrder->product->description) ?></small> <br /><small><?= Html::encode($productOrder->product->description) ?></small>
<?php endif; ?> <?php endif; ?>
</td> </td>

<?php
$price = $productOrder->getPrice() ;
if($document->isInvoicePrice() && $productOrder->getInvoicePrice()) {
$price = $productOrder->getInvoicePrice() ;
}
?>

<?php if($displayPrices): ?> <?php if($displayPrices): ?>
<td class="align-center"><?= Price::format($productOrder->getPrice()) ?></td>
<td class="align-center">
<?= Price::format($price) ?>
</td>
<?php endif; ?> <?php endif; ?>
<td class="align-center"><?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?></td> <td class="align-center"><?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?></td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td> <td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?> <?php if(GlobalParam::getCurrentProducer()->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"><?= Price::format($productOrder->getPrice() * $productOrder->quantity) ?></td>
<td class="align-center">
<?php if($document->getClass() == ''): ?>
<?= Price::format($price * $productOrder->quantity) ?>
<?php else: ?>
<?= Price::format($price * $productOrder->quantity) ?>
<?php endif; ?>
</td>
<?php endif; ?> <?php endif; ?>
</tr> </tr>

+ 3
- 13
backend/views/document/_form.php View File

<th>Prix (unité)</th> <th>Prix (unité)</th>
<th>Quantité</th> <th>Quantité</th>
<th v-if="taxRateProducer != 0">TVA</th> <th v-if="taxRateProducer != 0">TVA</th>
<th v-if="taxRateProducer != 0">Total TTC</th>
<th v-if="taxRateProducer != 0">Total HT</th>
<th v-else>Total</th> <th v-else>Total</th>
<th>Supprimer</th> <th>Supprimer</th>
</tr> </tr>
</ul> </ul>
</td> </td>
<td class="col-md-2"> <td class="col-md-2">
<span v-if="(document.class == 'Invoice' || document.class == 'DeliveryNote') && productOrder.invoice_price">
{{ formatPrice(productOrder.invoice_price) }}
</span>
<span v-else>
{{ formatPrice(productOrder.price) }}
</span>
{{ formatPrice(getProductOrderPrice(productOrder)) }}
</td> </td>
<td class="col-md-2">{{ productOrder.quantity }}</td> <td class="col-md-2">{{ productOrder.quantity }}</td>
<td class="col-md-1" v-if="taxRateProducer != 0"> <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">
<span v-if="(document.class == 'Invoice' || document.class == 'DeliveryNote') && productOrder.invoice_price">
{{ formatPrice(productOrder.quantity * productOrder.invoice_price) }}
</span>
<span v-else-if="document.class == 'Quotation'">
{{ formatPrice(productOrder.quantity * productOrder.price) }}
</span>
{{ formatPrice(productOrder.quantity * getProductOrderPrice(productOrder)) }}
</td> </td>
<td class="col-md-1"> <td class="col-md-1">
<a class="btn btn-default" @click="deleteProductOrder(productOrder.id)"> <a class="btn btn-default" @click="deleteProductOrder(productOrder.id)">

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

</tr> </tr>
<?php foreach($order->productOrder as $productOrder): ?> <?php foreach($order->productOrder as $productOrder): ?>
<?= $this->render('_download_product_line', [ <?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder, 'productOrder' => $productOrder,
'displayOrders' => true, 'displayOrders' => true,
'displayPrices' => $displayPrices 'displayPrices' => $displayPrices
<?php foreach($document->getProductsOrders() as $product): ?> <?php foreach($document->getProductsOrders() as $product): ?>
<?php foreach($product as $productOrder): ?> <?php foreach($product as $productOrder): ?>
<?= $this->render('_download_product_line', [ <?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder, 'productOrder' => $productOrder,
'displayPrices' => $displayPrices 'displayPrices' => $displayPrices
]) ?> ]) ?>
<?php endif; ?> <?php endif; ?>
<?php if($displayPrices): ?> <?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?> <?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>

<?php $typeAmount = $document->isInvoicePrice() ? Order::INVOICE_AMOUNT_TOTAL : Order::AMOUNT_TOTAL ; ?>

<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($typeAmount)); ?>
</td>
</tr> </tr>
<tr> <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"><?= Price::format($document->getAmountWithTax() - $document->getAmount()) ?></td>
<td class="align-center"><?= Price::format($document->getAmountWithTax($typeAmount) - $document->getAmount($typeAmount)) ?></td>
</tr> </tr>
<tr> <tr>
<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($typeAmount)) ?></td>
</tr> </tr>
<?php else: ?> <?php else: ?>
<tr> <tr>
<strong>Total</strong><br /> <strong>Total</strong><br />
TVA non applicable TVA non applicable
</td> </td>
<td class="align-center"><?= Price::format($document->getAmount()) ?></td>
<td class="align-center"><?= Price::format($document->getAmount($typeAmount)) ?></td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>

+ 1
- 1
backend/views/invoice/index.php View File

'attribute' => 'amount', 'attribute' => 'amount',
'header' => 'Montant', 'header' => 'Montant',
'value' => function($invoice) { 'value' => function($invoice) {
return $invoice->getAmountWithTax(Order::AMOUNT_TOTAL, true) ;
return $invoice->getAmountWithTax(Order::INVOICE_AMOUNT_TOTAL, true) ;
} }
], ],
[ [

+ 15
- 0
backend/web/js/vuejs/document-form.js View File

var documentClass = $('#app-document-form').attr('data-class-document') ; var documentClass = $('#app-document-form').attr('data-class-document') ;
return documentClass ; return documentClass ;
}, },
getProductOrderPrice: function(productOrder) {
var documentClass = this.getDocumentClass() ;
var price = 0 ;
if(documentClass == 'DeliveryNote' || documentClass == 'Invoice') {
price = productOrder.invoice_price ;
if(!price) {
price = productOrder.price ;
}
}
else {
price = productOrder.price ;
}

return price ;
},
changeUser: function() { changeUser: function() {
var app = this ; var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-user-infos",{params: { axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-user-infos",{params: {

+ 5
- 0
common/models/Document.php View File

return Yii::getAlias('@app/web/pdf/'.$this->getType().'-' . $this->reference. '.pdf') ; return Yii::getAlias('@app/web/pdf/'.$this->getType().'-' . $this->reference. '.pdf') ;
} }


public function isInvoicePrice()
{
return $this->getClass() == 'Invoice' || $this->getClass() == 'DeliveryNote' ;
}

} }

+ 14
- 0
common/models/Order.php View File

return $username ; return $username ;
} }


public function initInvoicePrices($params = [])
{
foreach($this->productOrder as $productOrder) {
if($productOrder->product) {
$productOrder->invoice_price = $productOrder->product->getPrice([
'user' => isset($params['user']) ? $params['user'] : null,
'user_producer' => isset($params['user_producer']) ? $params['user_producer'] : null,
'point_sale' => isset($params['point_sale']) ? $params['point_sale'] : null
]) ;
$productOrder->save() ;
}
}
}

} }

Loading…
Cancel
Save