Bläddra i källkod

Adaptations prix spécifiques

refactoring
Guillaume 3 år sedan
förälder
incheckning
b49c6044d6
9 ändrade filer med 90 tillägg och 49 borttagningar
  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 Visa fil

@@ -1300,6 +1300,9 @@ class DistributionController extends BackendController

if($firstOrder->pointSale->id_user) {
$deliveryNote->id_user = $firstOrder->pointSale->id_user;
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
}
else {
$user = new User ;
@@ -1328,11 +1331,6 @@ class DistributionController extends BackendController
$deliveryNote->id_user = $user->id;
}

if(!isset($user)) {
$user = User::searchOne([
'id' => $deliveryNote->id_user
]) ;
}
$deliveryNote->address = $user->getFullAddress() ;
$deliveryNote->save();
}
@@ -1345,6 +1343,16 @@ class DistributionController extends BackendController
]) ;
}

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
foreach ($idOrders as $idOrder) {
$order = Order::searchOne([
@@ -1354,6 +1362,16 @@ class DistributionController extends BackendController
$order->id_delivery_note = $deliveryNote->id;
$order->save();
}

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

return [

+ 0
- 24
backend/controllers/DocumentController.php Visa fil

@@ -111,30 +111,6 @@ class DocumentController extends BackendController
], [
'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 Visa fil

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

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

<?php if($displayPrices): ?>
<td class="align-center"><?= Price::format($productOrder->getPrice()) ?></td>
<td class="align-center">
<?= Price::format($price) ?>
</td>
<?php endif; ?>
<td class="align-center"><?= $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'] ?></td>
<td class="align-center"><?= Product::strUnit($productOrder->unit, 'wording') ?></td>
@@ -17,6 +27,12 @@
<?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">
<?php if($document->getClass() == ''): ?>
<?= Price::format($price * $productOrder->quantity) ?>
<?php else: ?>
<?= Price::format($price * $productOrder->quantity) ?>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>

+ 3
- 13
backend/views/document/_form.php Visa fil

@@ -245,7 +245,7 @@ use common\models\Producer;
<th>Prix (unité)</th>
<th>Quantité</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>Supprimer</th>
</tr>
@@ -262,24 +262,14 @@ use common\models\Producer;
</ul>
</td>
<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 class="col-md-2">{{ productOrder.quantity }}</td>
<td class="col-md-1" v-if="taxRateProducer != 0">
{{ productsArray[productOrder.id_product].tax_rate * 100 }} %
</td>
<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 class="col-md-1">
<a class="btn btn-default" @click="deleteProductOrder(productOrder.id)">

+ 11
- 4
backend/views/document/download.php Visa fil

@@ -85,6 +85,7 @@ $displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$a
</tr>
<?php foreach($order->productOrder as $productOrder): ?>
<?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder,
'displayOrders' => true,
'displayPrices' => $displayPrices
@@ -95,6 +96,7 @@ $displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$a
<?php foreach($document->getProductsOrders() as $product): ?>
<?php foreach($product as $productOrder): ?>
<?= $this->render('_download_product_line', [
'document' => $document,
'productOrder' => $productOrder,
'displayPrices' => $displayPrices
]) ?>
@@ -103,17 +105,22 @@ $displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$a
<?php endif; ?>
<?php if($displayPrices): ?>
<?php if(GlobalParam::getCurrentProducer()->taxRate->value != 0): ?>

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

<tr>
<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>
<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>
<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>
<?php else: ?>
<tr>
@@ -121,7 +128,7 @@ $displayPrices = Yii::$app->controller->getClass() != 'DeliveryNote' || (Yii::$a
<strong>Total</strong><br />
TVA non applicable
</td>
<td class="align-center"><?= Price::format($document->getAmount()) ?></td>
<td class="align-center"><?= Price::format($document->getAmount($typeAmount)) ?></td>
</tr>
<?php endif; ?>
<?php endif; ?>

+ 1
- 1
backend/views/invoice/index.php Visa fil

@@ -96,7 +96,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'attribute' => 'amount',
'header' => 'Montant',
'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 Visa fil

@@ -90,6 +90,21 @@ var app = new Vue({
var documentClass = $('#app-document-form').attr('data-class-document') ;
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() {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-user-infos",{params: {

+ 5
- 0
common/models/Document.php Visa fil

@@ -378,4 +378,9 @@ class Document extends ActiveRecordCommon
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 Visa fil

@@ -951,4 +951,18 @@ class Order extends ActiveRecordCommon
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() ;
}
}
}

}

Laddar…
Avbryt
Spara