$shiftTransfer = ShiftTransfer::findOne($shiftTransferId);
$storeId = array_flip(array_map('strval', CityStore::getAllActiveGuidId()))[$shiftTransfer->store_guid];
$productSelfCost = SelfCostProduct::findOne(['product_guid' => $productGuid, 'date' => $shiftTransfer->date, 'store_id' => $storeId]);
+
$productReplacement = ArrayHelper::map(
- Product1cReplacement::find()
- ->andWhere(['in', 'guid_replacement', ShiftTransfer::find()
- ->select('product_replacement_id')
- ])
- ->andWhere(['guid' => $productGuid])
- ->select('guid_replacement')
- ->column(),
- 'id', 'name'
- );
+ Products1c::find()
+ ->andWhere(['id' => Product1cReplacement::find()
+ ->andWhere(['deleted_at' => null])
+ ->andWhere(['guid' => $productGuid])
+ ->andWhere(['guid_replacement' => ShiftRemains::find()
+ ->andWhere(['shift_transfer_id' => $shiftTransferId])
+ ->andWhere(['<>', 'fact_and_1c_diff', 0])
+ ->select('product_guid')
+ ->column()])
+ ->select(['guid'])
+ ->column()])
+ ->all(),
+ 'id', 'name');
if (!$productPrice || !$productReplacement || !$productSelfCost) {
throw new \Exception('У данного товара нет цены либо замен!');