$weekRange = Motivation::getWeekRangeForDate();
-
if ((date('d') % 7 == 0 || date('t') == date('d'))) {
-
foreach (Firms::getInn() as $key => $firm) {
for ($week = Motivation::getWeek(); $week >= 1; $week--) {
sleep(1);
$date = strtotime("{$day}-{$month}-{$year}");
$weekRange = Motivation::getWeekRangeForDate($date);
- $model = new ApiCronBuh();
- $model->date = date('Y-m-d H:i:s');
- $model->request_id = strval(strtotime($model->date) . '_' . $key);
-
- $model->json_post = Json::encode([
- 'request_id' => $model->request_id,
- 'cost_items' => [
- 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
- 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
- ]
- ]);
- $model->inn = $key;
- try {
- $model->save();
- } catch (Exception $e) {
- throw new Exception($e);
- }
+ createApiCron($key, $weekRange);
}
}
} else {
foreach (Firms::getInn() as $key => $firm) {
- $model = new ApiCronBuh();
- $model->date = date('Y-m-d H:i:s');
- $model->request_id = strval(strtotime($model->date) . '_' . $key);
- $model->json_post = Json::encode([
- 'request_id' => $model->request_id,
- 'cost_items' => [
- 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
- 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
- ]
- ]);
- $model->inn = $key;
- try {
- $model->save();
- } catch (Exception $e) {
- throw new Exception($e);
- }
-
+ createApiCron($key, $weekRange);
}
}
- if (!in_array(Admin::findOne([Yii::$app->user->id])->group_id, [AdminGroup::GROUP_IT])) {
- return $this->render('/site/index');
- }
-
$info = ' ================ test Task ' . $taskNum . ' stop ================';
echo $info;
$validate = $schedulerTaskLog->validate();
if ($validate) {
$schedulerTaskLog->save();
+}
+
+function createApiCron($key, $weekRange) {
+ $model = new ApiCronBuh();
+ $model->date = date('Y-m-d H:i:s');
+ $model->request_id = strval(strtotime($model->date) . '_' . $key);
+ $model->json_post = Json::encode([
+ 'request_id' => $model->request_id,
+ 'cost_items' => [
+ 'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
+ 'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
+ ]
+ ]);
+ $model->inn = $key;
+ try {
+ $model->save();
+ } catch (Exception $e) {
+ throw new Exception($e);
+ }
}
\ No newline at end of file
$motivationValue = new MotivationValue();
$motivationValue->setAttributes([
'motivation_id' => $motivation->id,
- 'motivation_group_id' => $value->id,
+ 'motivation_group_id' => $value->motivation_group_id,
'value_id' => $value->value_id,
'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
'value_float' => $value->value_float,
$alias = $validate === 'month' ? 'month' : 'week' . $week;
$motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]);
- $storeBuhIds = ArrayHelper::map(StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(), 'store_guid', 'store_id');
- $motivationCostsItems = ArrayHelper::map(MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(), 'name', 'code');
+ $storeBuhIds = ArrayHelper::map(
+ StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(),
+ 'store_guid', 'store_id');
+ $motivationCostsItems = ArrayHelper::map(
+ MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(),
+ 'name', 'code');
if (!empty($data['cost_items'])) {
foreach ($data['cost_items'] as $stores) {
if (!$storeBuh) {
LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE));
- return;
+ continue;
}
$storeId = $storeBuhIds[$storeData['store_guid']];
if (!$value) {
LogService::apiErrorLog(json_encode(["error_id" => 46, "error" => $item['name']], JSON_UNESCAPED_UNICODE));
- return;
+ continue;
}
$motivationBuh = MotivationBuh::findOne([
'motivation_buh_id' => $motivationBuh->id,
'store_id' => $storeId,
'motivation_group_id' => $motivationValueGroup->id,
- 'value_id' => $motivationCostsItems[$storeData['items']],
+ 'value_id' => $motivationCostsItems[$item['name']],
'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
]);
'motivation_buh_id' => $motivationBuh->id,
'store_id' => $storeId,
'motivation_group_id' => $motivationValueGroup->id,
- 'value_id' => $motivationCostsItems[$storeData['items']],
+ 'value_id' => $motivationCostsItems[$item['name']],
'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
'value_float' => $item['summ']
]);
'header' => 'Неделя 1<br>(1-7)',
'value' => function ($model) {
- return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : " ";
-
+ return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : "0";
},
],
[
'header' => 'Неделя 2<br>(8-14)',
'value' => function ($model) {
- return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : " ";
-
+ return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : "0";
},
],
'header' => 'Неделя 3<br>(15-21)',
'value' => function ($model) {
- return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : " ";
-
+ return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : "0";
},
],
'header' => 'Неделя 4<br>(22-28)',
'value' => function ($model) {
- return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : " ";
-
+ return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : "0";
},
],
'header' => $week5Header,
'value' => function ($model) {
- return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : " ";
-
+ return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : "0";
},
],
[