瀏覽代碼

Amélioration fonction installation système de TVA #165

dev
Guillaume Bourgeois 4 年之前
父節點
當前提交
7912a8fc80
共有 3 個檔案被更改,包括 18 行新增25 行删除
  1. +16
    -23
      backend/controllers/ProducerAdminController.php
  2. +1
    -1
      backend/views/product/index.php
  3. +1
    -1
      common/models/Product.php

+ 16
- 23
backend/controllers/ProducerAdminController.php 查看文件

@@ -186,33 +186,26 @@ class ProducerAdminController extends BackendController
$productsArray = Product::searchAll([
'id_producer' => $idProducer
]) ;

$connection = Yii::$app->getDb();
foreach($productsArray as $product) {
$product->price = $product->price / (1 + $product->taxRate->value) ;
$product->price = round($product->price / (1 + $product->taxRate->value), 2) ;
$product->save() ;

$command = $connection->createCommand("
UPDATE `product_order`
SET price = ROUND(price / (1 + :tax_value), 2)
WHERE id_product = :id_product",
[
':id_product' => $product->id,
':tax_value' => $product->taxRate->value
]);

$result = $command->query();
}
// product_order
$ordersArray = Order::searchAll([
'distribution.id_producer' => $idProducer
]) ;
foreach($ordersArray as $order) {
foreach($order->productOrder as $productOrder) {
$productOrder->price = $productOrder->price / (1 + $productOrder->taxRate->value) ;
$productOrder->save() ;
}
}
// product_subscription
$subscriptionsArray = Subscription::searchAll([
'subscription.id_producer' => $idProducer
]) ;
foreach($subscriptionsArray as $subscription) {
foreach($subscription->productSubscription as $productSubscription) {
$productSubscription->price = $productSubscription->price / (1 + $productSubscription->taxRate->value) ;
$productSubscription->save() ;
}
}

echo 'ok' ;
}

/**

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

@@ -102,7 +102,7 @@ $this->addButton(['label' => 'Nouveau produit <span class="glyphicon glyphicon-p
'value' => function ($model) {
$return = '';
if ($model->price) {
$return = Price::format($model->price) . ' (' . Product::strUnit($model->unit, 'wording_unit', true) . ')';
$return = Price::format($model->getPriceWithTax()) . ' (' . Product::strUnit($model->unit, 'wording_unit', true) . ')';
}

return $return;

+ 1
- 1
common/models/Product.php 查看文件

@@ -118,7 +118,7 @@ class Product extends ActiveRecordCommon
public function rules()
{
return [
[['name', 'id_producer', 'id_tax_rate'], 'required'],
[['name', 'id_producer'], 'required'],
[['active', 'order', 'quantity_max', 'id_producer', 'id_tax_rate'], 'integer'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions'], 'boolean'],
[['price', 'weight', 'step'], 'number'],

Loading…
取消
儲存