->andWhere(['product_id' => array_keys($products1c)])
->asArray()->one();
- $motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'week' . $ind])->one();
- $motivationCostsItem = MotivationCostsItem::find()->where(['name' => 'Услуги по сборке'])->one();
- /** @var $motivationCostsItem MotivationCostsItem */
$motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one();
if ($motivation) {
- $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id,
- 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one();
- if (!$motivationValue) {
- $motivationValue = new MotivationValue;
- $motivationValue->motivation_id = $motivation->id;
- $motivationValue->motivation_group_id = $motivationValueGroup->id;
- $motivationValue->value_id = $motivationCostsItem->code;
- $motivationValue->value_type = $motivationCostsItem->data_type;
- }
- $motivationValue->value_float = $salesProduct['total'];
- $motivationValue->save();
- //var_dump($motivationValue); die;
- if ($motivationValue->getErrors()) {
- throw new \Exception(Json::encode($motivationValue->getErrors()));
- }
+ self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, self::CODE_ASSEMBLY_SERVICES,
+ 'float', ($salesProduct['total'] ?? 0));
}
// Ищем продажи по продуктовым гуидам по каталог-гуидам категории service_delivery
->select(['SUM(summ) as total'])
->where(['check_id' => $salesIds])
->andWhere(['NOT IN', 'check_id', $returnSalesIds])
- ->andWhere(['product_id' => array_keys($products1c)])
+ ->andWhere(['product_id' => array_keys($products1cDelivery)])
->asArray()->one();
$motivationCostsItem = MotivationCostsItem::find()->where(['name' => 'Услуги по доставке'])->one();
/** @var $motivationCostsItem MotivationCostsItem */
if ($motivation) {
- $motivationValue = MotivationValue::find()->where(['motivation_id' => $motivation->id,
- 'motivation_group_id' => $motivationValueGroup->id, 'value_id' => $motivationCostsItem->code])->one();
- if (!$motivationValue) {
- $motivationValue = new MotivationValue;
- $motivationValue->motivation_id = $motivation->id;
- $motivationValue->motivation_group_id = $motivationValueGroup->id;
- $motivationValue->value_id = $motivationCostsItem->code;
- $motivationValue->value_type = $motivationCostsItem->data_type;
- }
- $motivationValue->value_float = $salesProduct['total'];
- $motivationValue->save();
- if ($motivationValue->getErrors()) {
- throw new \Exception(Json::encode($motivationValue->getErrors()));
- }
+ self::saveOrUpdateMotivationValue($motivation->id, 'week' . $ind, self::CODE_DELIVERY_SERVICES,
+ 'float', ($salesProduct['total'] ?? 0));
}
}
}