From: Vladimir Fomichev Date: Tue, 26 Aug 2025 13:35:38 +0000 (+0300) Subject: Вывод остатков X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=184a9cf911622c40428aaa29c4a46c45948162bc;p=erp24_rep%2Fyii-erp24%2F.git Вывод остатков --- diff --git a/erp24/controllers/MarketplaceOrdersController.php b/erp24/controllers/MarketplaceOrdersController.php index 07c89f42..a56526cc 100644 --- a/erp24/controllers/MarketplaceOrdersController.php +++ b/erp24/controllers/MarketplaceOrdersController.php @@ -4,12 +4,14 @@ namespace app\controllers; use app\records\OrdersUnion; +use OpenAPI\Client\Configuration; use OpenAPI\Client\ObjectSerializer; use Yii; use yii\base\Exception; use yii\data\ArrayDataProvider; use yii\db\Expression; use yii\db\Query; +use yii\helpers\ArrayHelper; use yii_app\helpers\DataHelper; use yii_app\models\FlowwowOrdersForm; use yii_app\records\MarketplaceOrderDelivery; @@ -22,6 +24,7 @@ use yii\filters\VerbFilter; use yii_app\records\MarketplaceOrderStatusHistory; use yii_app\records\MarketplaceOrderStatusTypes; use yii_app\records\MarketplaceStore; +use yii_app\records\MatrixErp; use yii_app\records\Prices; use yii_app\records\PricesDynamic; use yii_app\records\Products1c; @@ -809,6 +812,74 @@ class MarketplaceOrdersController extends Controller } return $this->redirect(['index']); } + + + public function actionYandexStocks() { + + + $infoForMarketplace = MarketplaceService::infoForMarketplace(2); + + $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id') + ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all(); + $matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all(); + $matrixErpByGuid = []; + $hiddenOfferings = []; + foreach ($matrixErp as $matrix) { + /* @var $matrix MatrixErp */ + $matrixErpByGuid[$matrix->guid] = $matrix; + $hiddenOfferings [] = [ + "offerId" => $matrix->guid, + ]; + } + + $campaignIds = ArrayHelper::map(MarketplaceStore::find()->where(['warehouse_id' => 2])->all(), 'warehouse_guid', 'guid'); + $skus = []; + foreach (array_keys($campaignIds) as $campaignId) { + foreach ($infoForMarketplace as $storeId => $guidsWithCnt) { + if ($campaignIds[$campaignId] != $storeId) { + continue; + } + + foreach ($guidsWithCnt as $guid => $cnt) { + $skus[$campaignId][] = [ + "sku" => $guid, + "items" => [ + [ + "count" => $cnt, + "updatedAt" => date("c"), + ] + ] + ]; + } + } + } + //var_dump($skus);die(); + $flattenSkus = []; + foreach ($skus as $campaignId => $sku) { + foreach ($sku as $item) { + $flattenSkus[] = [ + "guid" => $item['sku'], + "count" => $item['items'][0]['count'], + "campaignId" => $campaignId, + ]; + } + } + $dataProvider = new ArrayDataProvider([ + 'allModels' => $flattenSkus, + 'sort' => [ + 'attributes' => ['guid', 'count', 'campaignId'], + ], + 'pagination' => [ + 'pageSize' => 200, + ], + ]); + + return $this->render('yandex-stocks', ['dataProvider' => $dataProvider]); + + + + } + /** * Deletes an existing MarketplaceOrders model. * If deletion is successful, the browser will be redirected to the 'index' page. diff --git a/erp24/views/marketplace-orders/index.php b/erp24/views/marketplace-orders/index.php index a2461d54..5eaf7bf9 100644 --- a/erp24/views/marketplace-orders/index.php +++ b/erp24/views/marketplace-orders/index.php @@ -43,6 +43,7 @@ YiiAsset::register($this); 'btn btn-success']) ?> 'btn btn-success']) ?> 'btn btn-success']) ?> + 'btn btn-success']) ?>

diff --git a/erp24/views/marketplace-orders/yandex-stocks.php b/erp24/views/marketplace-orders/yandex-stocks.php new file mode 100644 index 00000000..c91d7943 --- /dev/null +++ b/erp24/views/marketplace-orders/yandex-stocks.php @@ -0,0 +1,53 @@ +title = 'Остатки Яндекса'; +$this->params['breadcrumbs'][] = $this->title; +YiiAsset::register($this); +?> +
+ 'btn btn-primary my-4']) ?> +

title) ?>

+ + + $dataProvider, + 'responsive' => true, + 'hover' => true, + 'columns' => [ + [ + 'attribute' => 'guid', + 'value' => function ($model) { + $product = Products1c::find()->where(['id' => $model['guid']])->one(); + return $product->name . " (" . $model['guid'] . ")"; + } + ], + 'count', + [ + 'attribute' => 'campaignId', + 'value' => function ($model) { + $store = MarketplaceStore::find()->where(['warehouse_guid' => $model['campaignId']])->one(); + $storeName = $store->name; + return $storeName . " (" . $model['campaignId'] . ")"; + } + ], + ] + + ]); ?> + + +