namespace yii_app\services;
use PhpOffice\PhpSpreadsheet\IOFactory;
+use yii\helpers\Json;
use yii_app\records\ExportImportTable;
use yii_app\records\Motivation;
use yii_app\records\MotivationValue;
$monthEnd = date("Y-m-t 23:59:59", strtotime($year . '-' . $month . '-1'));
$motivation = Motivation::find()->where(['store_id' => $store_id, 'year' => $year, 'month' => $month])->one();
+ $exportImportTable = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $store_id, 'export_id' => 1])->one();
+ /** @var $exportImportTable ExportImportTable */
foreach (range(1, 5) as $ind) {
$weekStart = date("Y-m-d 00:00:00", strtotime("+" . (($ind - 1) * 7) . ' days', strtotime($monthStart)));
if ($weekEnd > $monthEnd) {
$weekEnd = $monthEnd;
}
+ if ($weekStart > $monthEnd) {
+ continue;
+ }
$motivationValueGroup = MotivationValueGroup::find()->where(['alias' => 'week' . $ind])->one();
- $eit = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'city_store', 'entity_id' => $store_id, 'export_id' => 1])->one();
- /** @var $eit ExportImportTable */
- if ($eit) {
+ if ($exportImportTable) {
$writeOffs = WriteOffs::find()->select(['sum(summ) as total', 'type'])
->where(['between', 'date', $weekStart, $weekEnd])
- ->andWhere(['store_id' => $eit->export_val])
+ ->andWhere(['store_id' => $exportImportTable->export_val])
->groupBy(['type'])
->indexBy('type')
->asArray()->all();
$motivationValue->value_float = $data['total'];
$motivationValue->save();
if ($motivationValue->getErrors()) {
- var_dump($motivationValue->getErrors());
- die;
+ throw new \Exception(Json::encode($motivationValue->getErrors()));
}
}
}
}
}
+
+ $motivation->save();
+ if ($motivation->getErrors()) {
+ throw new \Exception(Json::encode($motivation->getErrors()));
+ }
}
}