add inventory item changes
This commit is contained in:
73
console/controllers/InventoryConsoleController.php
Normal file
73
console/controllers/InventoryConsoleController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace console\controllers;
|
||||
|
||||
use common\models\Inventory;
|
||||
use common\models\InventoryItem;
|
||||
use common\models\Product;
|
||||
use common\models\Transfer;
|
||||
use yii\console\Controller;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
|
||||
|
||||
class InventoryConsoleController extends Controller{
|
||||
|
||||
|
||||
/**
|
||||
* @param $idInventory
|
||||
*/
|
||||
public function actionFixSold($idInventory){
|
||||
|
||||
$inventory = Inventory::findOne($idInventory);
|
||||
|
||||
|
||||
/** @var /common/models/InventoryItem[] $items */
|
||||
$items = InventoryItem::find()->andWhere(['id_inventory' => $inventory->id_inventory])->all();
|
||||
|
||||
/** @var /common/models/InventoryItem $item */
|
||||
foreach ($items as $item ){
|
||||
|
||||
$prev = $item->inventoryItemPrev;
|
||||
|
||||
if ( !isset($prev)){
|
||||
continue;
|
||||
}
|
||||
$start = $prev->created_at;
|
||||
$end = $item->created_at;
|
||||
|
||||
|
||||
$query = new Query();
|
||||
$query->select([
|
||||
new Expression(" coalesce( sum( transfer.count ),0)")
|
||||
]);
|
||||
$query->from('transfer');
|
||||
$query->innerJoin('sale','sale.id_sale = transfer.id_object');
|
||||
$query->innerJoin('product','sale.id_product = product.id_product');
|
||||
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->andWhere(['in', 'transfer.type', [Transfer::STATUS_NOT_PAID, Transfer::STATUS_PAID]]);
|
||||
$query->andWhere(['product.id_product' => $prev->id_product]);
|
||||
|
||||
$query->andWhere([ '>','transfer.created_at',$start ]);
|
||||
|
||||
$products = $query->scalar();
|
||||
|
||||
$item->count_sold = $products;
|
||||
|
||||
$item->recalculateTotalPriceBrutto();
|
||||
|
||||
echo $item->price_brutto . " - ". $item->productName ."\n";
|
||||
|
||||
$item->save();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user