Answer the question
In order to leave comments, you need to log in
How to make the implementation in a normal way?
Hello.
Please tell me if there is something similar to the normal implementation in this implementation of the code.
There are 4 tables - Indicator(indicators), Indicator_type(name of indicators), Calendar(months), Tarrifs(tariffs).
The models for these tables are created through Gii.
It is necessary to find out the difference in data between the indicators of the current and last months, multiply this difference by the tariff, and display the name of the month and the name of the indicator.
In SiteController.php created actionTally
public function actionTally()
{
// предыдущий месяц
$prevMonth = intval(date("n") - 1) . date("y");
// текущий месяц
$currentMonth = intval(date("n") . date("y"));
// данные предыдущего месяца
$data = Indicator::model()->findAll('month_id=:month_id', array(':month_id' => $prevMonth));
// данные текущего месяца
$model = Indicator::model()->findAll('month_id=:month_id', array(':month_id' => $currentMonth));
// название показателей
$indicators = IndicatorType::model()->findAll();
// тарифы
$tarrifs = Tarrifs::model()->findAll();
// месяц
$calendar = Calendar::model()->findAll('keyMonth=:keyMonth', array(':keyMonth' => $currentMonth));
// название месяца
foreach ($calendar as $vlCalendar) {
$monthly = $vlCalendar->monthly;
}
// текущий месяц
foreach ($model as $type) {
$current[] = $type->value;
}
// прошлый месяц
foreach ($data as $datas) {
$preview[] = $datas->value;
}
// показатели
foreach ($indicators as $vli) {
$indicator[] = $vli->indicator;
}
// тарифы
foreach ($tarrifs as $tarif) {
$unit[] = $tarif->unit;
$amount[] = $tarif->amount;
}
$this->render('tally', array(
'current' => $current,
'preview' => $preview,
'indicator' => $indicator,
'tarrifs' => $tarrifs,
'unit' => $unit,
'amount' => $amount,
'monthly' => $monthly,
));
}
<?php
/**
* Подсчёт данных
*
* @var $this SiteController
*/
?>
<h1> Подсчёт данных за <?php echo $monthly; ?> </h1>
<div class="form">
<?php
for ($tally = 0; $tally < 4; $tally++) {
// разница
$number = $current[$tally] - $preview[$tally];
// массив всех значений
$total[] = $number * $amount[$tally];
// вывод данных
echo $indicator[$tally] . ' - ' . $number . ' ' . $unit[$tally] . ' = <b>' . round($number * $amount[$tally]) . '</b> рублей <br/>';
}
// общая сумма
$sum = array_sum($total);
?>
<br/>
Приблизительная сумма по счётчика = <b> <?php echo round($sum); ?> </b> рублей
</div>
Answer the question
In order to leave comments, you need to log in
Are you offering to do the work for you? Here questions are asked, and not asked to bring to mind.
Besides the structure of the table is not clear. Instead of explaining that Tarrifs are "tariffs", they would indicate the type of data and whether they are unique.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question