$productsArray = Product::searchAll([ | $productsArray = Product::searchAll([ | ||||
'id_producer' => $idProducer | 'id_producer' => $idProducer | ||||
]) ; | ]) ; | ||||
$connection = Yii::$app->getDb(); | |||||
foreach($productsArray as $product) { | foreach($productsArray as $product) { | ||||
$product->price = $product->price / (1 + $product->taxRate->value) ; | |||||
$product->price = round($product->price / (1 + $product->taxRate->value), 2) ; | |||||
$product->save() ; | $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' ; | |||||
} | } | ||||
/** | /** |
'value' => function ($model) { | 'value' => function ($model) { | ||||
$return = ''; | $return = ''; | ||||
if ($model->price) { | 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; | return $return; |
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['name', 'id_producer', 'id_tax_rate'], 'required'], | |||||
[['name', 'id_producer'], 'required'], | |||||
[['active', 'order', 'quantity_max', 'id_producer', 'id_tax_rate'], 'integer'], | [['active', 'order', 'quantity_max', 'id_producer', 'id_tax_rate'], 'integer'], | ||||
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions'], 'boolean'], | [['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions'], 'boolean'], | ||||
[['price', 'weight', 'step'], 'number'], | [['price', 'weight', 'step'], 'number'], |