diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index 8cb8b35323fc48fe11181a4c1471c2daec662dbd..7783a3837fd265810f8d30123160411765477fda 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -758,35 +758,33 @@ CREATE PROCEDURE `GetRatesForGroupByStage`
 NO SQL
 BEGIN
     SELECT  view_disciplines_students.StudentID,
-      view_disciplines_students.LastName As LastName,
-      view_disciplines_students.FirstName As FirstName,
-      view_disciplines_students.SecondName As SecondName,
-      SUM(rating_table.Rate*(view_roadmap.ModuleType = 'regular')) AS 'regular',
-      SUM(rating_table.Rate*(view_roadmap.ModuleType = 'bonus')) AS 'bonus',
-      SUM(rating_table.Rate*(view_roadmap.ModuleType = 'extra')) AS 'extra',
-      SUM(rating_table.Rate*(view_roadmap.ModuleType = 'exam')) AS 'exam',
-      COALESCE(exam_period_options.Type) As 'option'
+        view_disciplines_students.LastName As 'LastName',
+        view_disciplines_students.FirstName As 'FirstName',
+        view_disciplines_students.SecondName As 'SecondName',
+        SUM(rating_table.Rate*(view_roadmap.ModuleType = 'regular')) AS 'Semester',
+        SUM(rating_table.Rate*(view_roadmap.ModuleType = 'bonus')) AS 'Bonus',
+        SUM(rating_table.Rate*(view_roadmap.ModuleType = 'extra')) AS 'Extra',
+        SUM(rating_table.Rate*(view_roadmap.ModuleType = 'exam')*(view_roadmap.SubmoduleOrderNum = pMilestone)) AS 'Exam',
+        MAX(rating_table.Rate*(view_roadmap.ModuleType = 'exam')*(view_roadmap.SubmoduleOrderNum < pMilestone)) AS 'PreviousExam',
+        MAX(IF(view_roadmap.SubmoduleOrderNum = pMilestone, exam_period_options.TYPE, NULL)) As 'Option',
+        MAX(IF(exam_period_options.TYPE = 'pass', 1, 0)) As 'AutoPassed'
     FROM `view_disciplines_students`
-      LEFT JOIN `view_roadmap` ON view_roadmap.DisciplineID = view_disciplines_students.DisciplineID
-      LEFT JOIN `rating_table` ON rating_table.StudentID = view_disciplines_students.StudentID AND
-                                  rating_table.SubmoduleID = view_roadmap.SubmoduleID
-      LEFT JOIN `exam_period_options` ON exam_period_options.submoduleID = view_roadmap.SubmoduleID AND
-                                         exam_period_options.StudentID = view_disciplines_students.StudentID
+        LEFT JOIN `view_roadmap` ON view_roadmap.DisciplineID = view_disciplines_students.DisciplineID
+        LEFT JOIN `rating_table` ON rating_table.StudentID = view_disciplines_students.StudentID AND
+                              rating_table.SubmoduleID = view_roadmap.SubmoduleID
+        LEFT JOIN `exam_period_options` ON exam_period_options.submoduleID = view_roadmap.SubmoduleID AND
+                                     exam_period_options.StudentID = view_disciplines_students.StudentID
     WHERE   view_disciplines_students.DisciplineID = pDisciplineID AND
-            view_disciplines_students.GroupID = pGroupID AND
-            NOT view_disciplines_students.AttachType <=> 'detach' AND
-            (   view_roadmap.ModuleType = 'regular' OR view_roadmap.ModuleType = 'bonus' OR
-                (view_roadmap.ModuleType = 'exam' AND view_roadmap.SubmoduleOrderNum = pMilestone) OR
-                (view_roadmap.ModuleType = 'extra' AND view_roadmap.SubmoduleOrderNum < pMilestone )
-            )
+        view_disciplines_students.GroupID = pGroupID AND
+        NOT view_disciplines_students.AttachType <=> 'detach' AND
+        (   view_roadmap.ModuleType <> 'extra'  OR
+            (view_roadmap.ModuleType = 'extra' AND view_roadmap.SubmoduleOrderNum < pMilestone )
+        )
     GROUP BY view_disciplines_students.StudentID
     ORDER BY LastName ASC, FirstName ASC, SecondName ASC;
 END //
 
 
-
-
-
 DROP PROCEDURE IF EXISTS GetRates//
 CREATE PROCEDURE `GetRates`
     (   IN `pStudentID` INT, IN `pDisciplineID` INT)
diff --git a/~dev_rating/application/classes/Controller/Handler/FileCreator.php b/~dev_rating/application/classes/Controller/Handler/FileCreator.php
index e61a4a9a0dfe8e7f5f7b0e0e3b3642a625b9807c..7e0ffb733e791ebb6122e489695ac565234120c4 100644
--- a/~dev_rating/application/classes/Controller/Handler/FileCreator.php
+++ b/~dev_rating/application/classes/Controller/Handler/FileCreator.php
@@ -6,7 +6,7 @@ class Controller_Handler_FileCreator extends Controller_Handler
     // Параметризация ведется по типу аттестации и по этапу сдачи
     private $ColumnsPositions = array(
         "exam" => array(
-            1 => array (
+            0 => array (
                 'Index' => 'A',
                 'Name' => 'B',
                 'Total' => 'G',
@@ -17,9 +17,20 @@ class Controller_Handler_FileCreator extends Controller_Handler
                 'RateString' => 'K',
                 'RightestColumn' => 'L'
             ),
+            2 => array (
+                'Index' => 'A',
+                'Name' => 'B',
+                'Total' => 'G',
+                'Semester' => 'H',
+                'Bonus' => 'I',
+                'Extra' => 'J',
+                'Exam'=> 'K',
+                'RateString' => 'L',
+                'RightestColumn' => 'M'
+            ),
         ),
         "credit" => array(
-            1 => array (
+            0 => array (
                 'Index' => 'A',
                 'Name' => 'B',
                 'Total' => 'H',
@@ -30,24 +41,31 @@ class Controller_Handler_FileCreator extends Controller_Handler
                 'RateString' => 'K',
                 'RightestColumn' => 'L'
             ),
-        ),
-        "grading_credit" => array(
-            1 => array (
+            2 => array (
                 'Index' => 'A',
                 'Name' => 'B',
                 'Total' => 'H',
                 'Semester' => 'I',
                 'Bonus' => 'J',
-                'Extra' => 0,
+                'Extra' => 'K',
                 'Exam'=> 0,
-                'RateString' => 'K',
-                'RightestColumn' => 'L'
+                'RateString' => 'L',
+                'RightestColumn' => 'M'
             ),
         ),
-    );
+    ); // остальные данные о позициях копируются в функции before()
 
     public function before() {
         $this->setAccessLevel(self::ACCESS_USER);
+
+        // копирование настроек полей для других типов аттестации и этапов
+        $this->ColumnsPositions['exam'][1] = $this->ColumnsPositions['exam'][0];
+        $this->ColumnsPositions['exam'][3] = $this->ColumnsPositions['exam'][2];
+        $this->ColumnsPositions['credit'][1] = $this->ColumnsPositions['credit'][0];
+        $this->ColumnsPositions['credit'][3] = $this->ColumnsPositions['credit'][2];
+        for($i=0;$i<4;++$i)
+            $this->ColumnsPositions['grading_credit'][$i] = $this->ColumnsPositions['credit'][$i];
+
         parent::before();
     }
 
@@ -165,14 +183,25 @@ class Controller_Handler_FileCreator extends Controller_Handler
     // Ведомость
     public function action_GenerateFinalForm()
     {
+        $this->post
+            ->rule('disciplineID', 'not_empty')
+            ->rule('disciplineID', 'digit')
+            ->rule('groupID', 'not_empty')
+            ->rule('groupID', 'digit')
+            ->rule('stage', 'not_empty')
+            ->rule('stage', 'digit', array(0, 1, 2, 3));
+        if(!$this->post->check())
+            throw new HTTP_Exception(417, "Некорректные параметры запроса!");
+
         // parameters
         $disciplineID = $this->post['disciplineID'];
-        $groupID = $this->post['studyGroupID'];
+        $groupID = $this->post['groupID'];
+        $stage = $this->post['stage'];
 
         // make form from template
         $info = Model_Rating::getFinalFormInfo($disciplineID, $groupID)[0];
         $info['DisciplineID'] = $disciplineID;
-        $this->printDisciplineToExcelFile($objPHPExcel, $disciplineID, $groupID, $info);
+        $this->printDisciplineToExcelFile($objPHPExcel, $disciplineID, $groupID, $info, $stage);
 
         // prepare filename
         $grade = $info["GradeNum"];
@@ -186,7 +215,7 @@ class Controller_Handler_FileCreator extends Controller_Handler
         $objWriter->save('php://output');
     }
 
-    public function printDisciplineToExcelFile(&$objPHPExcel, $disciplineID, $groupID, $headerData) {
+    public function printDisciplineToExcelFile(&$objPHPExcel, $disciplineID, $groupID, $headerData, $stage) {
         $useNewForms = true;
         if ($headerData["FacultyID"] == 2)
             $useNewForms = false;
@@ -195,9 +224,11 @@ class Controller_Handler_FileCreator extends Controller_Handler
         if ($type === 'grading_credit')
             $type = 'credit';
 
-        $templateFile = DOCROOT."docs/template $type.xls";
-        if (!$useNewForms)
-            $templateFile = DOCROOT."docs/old template $type.xls";
+        $templateFile = DOCROOT."docs/old template $type.xls";
+        if ($useNewForms) {
+            $stageSuffix = $stage < 2 ? "0 1" : "2 3";
+            $templateFile = DOCROOT . "docs/template $type $stageSuffix.xls";
+        }
 
         if (!file_exists($templateFile)) {
             exit("template wasn't found" . PHP_EOL);
@@ -206,21 +237,16 @@ class Controller_Handler_FileCreator extends Controller_Handler
         $objPHPExcel->setActiveSheetIndex(0);
 
         if ($useNewForms)
-            $this->printNewForm($objPHPExcel, $disciplineID, $groupID, $headerData);
+            $this->printNewForm($objPHPExcel, $disciplineID, $groupID, $headerData, $stage);
         else
             $this->printOldForm($objPHPExcel, $disciplineID, $groupID, $headerData);
     }
 
-    protected function printNewForm(&$objPHPExcel, $disciplineID, $groupID, $headerData) {
+    protected function printNewForm(&$objPHPExcel, $disciplineID, $groupID, $headerData, $stage) {
         // preparation
         $type = $headerData['ExamType'];
-        $stage = 1; // TODO: user should provide stage
         $rates = Model_Rating::getRatesForStudentsGroupByStage($disciplineID, $groupID, $stage);
 
-        $examHold = 1;
-        if ($type === 'exam')
-            $examHold = $this->checkExamIsHold($rates);
-
         // fill header
         $this->prepareSheetHeader($objPHPExcel, $type, $headerData);
 
@@ -231,12 +257,16 @@ class Controller_Handler_FileCreator extends Controller_Handler
         $sheet = $objPHPExcel->getActiveSheet();
 
         foreach($rates as $studentRates) {
-            $this->addStudentToSheetNew($sheet, $type, $studentRates, $rowNumber++, $index++, $stage, $examHold);
+            // проверяем дошел ли студент до этапа $stage или уже сдал
+            if (($stage >=2) &&
+                (((int)$studentRates['PreviousExam'] >= 22) || ((int)$studentRates['AutoPassed'] == 1)))
+                continue; // не пересдавал
+            $this->addStudentToSheetNew($sheet, $type, $studentRates, $rowNumber++, $index++, $stage);
         }
     }
 
     protected function addStudentToSheetNew(PHPExcel_Worksheet &$sheet,
-                                            $type, $studentRates, $rowIndex, $studentIndex, $stage, $examHold) {
+                                            $type, $studentRates, $rowIndex, $studentIndex, $stage) {
 
         $indPosition = $this->ColumnsPositions[$type][$stage]['Index']; // Номер
         $namePosition = $this->ColumnsPositions[$type][$stage]['Name'];  // ФИО
@@ -262,22 +292,22 @@ class Controller_Handler_FileCreator extends Controller_Handler
         $firstName = $studentRates['FirstName'];
         $secondName = $studentRates['SecondName'];
         $fullName = $lastName." ".$firstName." ".$secondName;
-        $ratesSet['semester'] = (int)$studentRates['regular'];
-        $ratesSet['bonus'] = (int)$studentRates['bonus'];
-        $ratesSet['extra'] = (int)$studentRates['extra'];
-        $ratesSet['exam'] = (int)$studentRates['exam'];
-        $ratesSet['option'] = $studentRates['option'];
+        $ratesSet['Semester'] = (int)$studentRates['Semester'];
+        $ratesSet['Bonus'] = (int)$studentRates['Bonus'];
+        $ratesSet['Extra'] = (int)$studentRates['Extra'];
+        $ratesSet['Exam'] = (int)$studentRates['Exam'];
+        $ratesSet['Option'] = $studentRates['Option'];
         list($totalRateStr, $stringRate, $examRateStr) =
-            $this->formStringsForRates($ratesSet, $type, $examHold);
+            $this->formStringsForRates($ratesSet, $type, $stage > 0);
 
         $sheet  ->setCellValue($indPosition.$rowIndex, $studentIndex)
             ->setCellValue($namePosition.$rowIndex, $fullName)
             ->setCellValue($totalRatePosition.$rowIndex, $totalRateStr)
-            ->setCellValue($semesterRatePosition.$rowIndex, $ratesSet['semester'])
-            ->setCellValue($bonusRatePosition.$rowIndex, $ratesSet['bonus'])
+            ->setCellValue($semesterRatePosition.$rowIndex, $ratesSet['Semester'])
+            ->setCellValue($bonusRatePosition.$rowIndex, $ratesSet['Bonus'])
             ->setCellValue($stringRatePosition.$rowIndex, $stringRate);
         if ($extraRatePosition)
-            $sheet->setCellValue($extraRatePosition.$rowIndex, $ratesSet['extra']);
+            $sheet->setCellValue($extraRatePosition.$rowIndex, $ratesSet['Extra']);
         if ($examRatePosition)
             $sheet->setCellValue($examRatePosition.$rowIndex, $examRateStr);
     }
@@ -640,17 +670,17 @@ class Controller_Handler_FileCreator extends Controller_Handler
 	}
 
     protected function formStringsForRates($ratesSet, $type, $examHold){
-        $attestationAdmission = $ratesSet['semester'] + $ratesSet['extra'];
-        $total = $attestationAdmission + $ratesSet['bonus'] + $ratesSet['exam'];
+        $attestationAdmission = $ratesSet['Semester'] + $ratesSet['Extra'];
+        $total = $attestationAdmission + $ratesSet['Bonus'] + $ratesSet['Exam'];
         switch ($type) {
             case 'exam':
-                return $this->formRateOfFive($attestationAdmission, $ratesSet['exam'], $total, $examHold, $ratesSet['option']);
+                return $this->formRateOfFive($attestationAdmission, $ratesSet['Exam'], $total, $examHold, $ratesSet['Option']);
             case 'grading_credit': {
                 // emulate exam to call formRateOfFive
                 $ratesSet['exam'] = 22;
                 $ratesSet['semester'] -= 22;
                 $attestationAdmission -= 22;
-                $res = $this->formRateOfFive($attestationAdmission, $ratesSet['exam'], $total, $examHold);
+                $res = $this->formRateOfFive($attestationAdmission, $ratesSet['Exam'], $total, $examHold);
                 $t = $res[1];
                 switch($t) {
                     case 'неуд':
@@ -719,8 +749,8 @@ class Controller_Handler_FileCreator extends Controller_Handler
 		{
 			if ($examAdmission < 38) { // задолженник
 				//$totalRateStr = ' ';
-				$rateOfFive = 'неуд';
-				$examRateStr = '0';
+				$rateOfFive = 'РЅ/Рґ';
+				$examRateStr = '';
 			}
 		}
 
diff --git a/~dev_rating/application/classes/Controller/Handler/Rating.php b/~dev_rating/application/classes/Controller/Handler/Rating.php
index 70acfa03a1b7e25cd65462f9a54bd5ba0e47763e..6db10f243cbfc8c0a0e80852a403d6d5e842edeb 100644
--- a/~dev_rating/application/classes/Controller/Handler/Rating.php
+++ b/~dev_rating/application/classes/Controller/Handler/Rating.php
@@ -19,7 +19,7 @@ class Controller_Handler_Rating extends Controller_Handler
                     -> rule('submoduleID', 'not_empty')
                     -> rule('submoduleID', 'digit')
                     -> rule('rate', 'digit')
-                    -> rule('rate', 'range', array(':value', 0, 100));
+                    -> rule('rate', 'range', array(':value', -1, 100));
         if($this->post->check()) {
             $result = Model_Rating::SetStudentRate( $this->user['TeacherID'],
                                                     $this->post['studentID'],
diff --git a/~dev_rating/application/classes/Model/Rating.php b/~dev_rating/application/classes/Model/Rating.php
index e284cde8f1f285ff33ec3ec12d6521b600bc2e5e..e085a4c9911d09c9dae4c1f760c2220065f4aca7 100644
--- a/~dev_rating/application/classes/Model/Rating.php
+++ b/~dev_rating/application/classes/Model/Rating.php
@@ -55,28 +55,54 @@ class Model_Rating extends Model
     }
 
     public static function SetStudentRate($teacherID, $studentID, $submoduleID, $rate) {
-        $sql = "SELECT `SetStudentRate`('$teacherID', '$studentID', '$submoduleID', '$rate') AS `Num`;";
-        return DB::query(Database::SELECT, $sql)->execute();
+        if ($rate == -1)
+            unset($rate);
+        $sql = "SELECT `SetStudentRate`(:teacherID, :studentID, :submoduleID, :rate) AS `Num`;";
+        return DB::query(Database::SELECT, $sql)
+            ->parameters([
+                ':teacherID' => $teacherID,
+                ':studentID' => $studentID,
+                ':submoduleID' => $submoduleID,
+                ':rate' => $rate
+            ])->execute();
     }
 
     public static function getRatesForStudentsGroup($disciplineID, $groupID) {
-        $sql = "CALL `GetRatesForGroup`('$disciplineID', '$groupID')";
-        return DB::query(Database::SELECT, $sql)->execute();
+        $sql = "CALL `GetRatesForGroup`(:disciplineID, :groupID)";
+        return DB::query(Database::SELECT, $sql)
+            ->parameters([
+                ':disciplineID' => $disciplineID,
+                ':groupID' => $groupID,
+            ])->execute();
     }
 
     public static function getRatesForStudentsGroupByStage($disciplineID, $groupID, $stage) {
-        $sql = "CALL `GetRatesForGroupByStage`('$disciplineID', '$groupID', '$stage');";
-        return DB::query(Database::SELECT, $sql)->execute();
+        $sql = "CALL `GetRatesForGroupByStage`(:disciplineID, :groupID, :stage);";
+        return DB::query(Database::SELECT, $sql)
+            ->parameters([
+                ':disciplineID' => $disciplineID,
+                ':groupID' => $groupID,
+                ':stage' => $stage
+            ])->execute();
     }
 
     public static function getFinalFormInfo($disciplineID, $groupID) {
-        $sql = "CALL `getFinalFormInfo`('$disciplineID', '$groupID')";
-        return DB::query(Database::SELECT, $sql)->execute();
+        $sql = "CALL `getFinalFormInfo`(:disciplineID, :groupID);";
+        return DB::query(Database::SELECT, $sql)
+            ->parameters([
+                ':disciplineID' => $disciplineID,
+                ':groupID' => $groupID,
+            ])->execute();
     }
 
     public static function setExamPeriodOption($studentID, $submoduleID, $option) {
         // option is absence or pass or null
-        $sql = "SELECT `SetExamPeriodOption`('$studentID', '$submoduleID', '$option') As `ErrorCode`;";
-        return DB::query(Database::SELECT, $sql)->execute()[0];
+        $sql = "SELECT `SetExamPeriodOption`(:studentID, :submoduleID, :option) As `ErrorCode`;";
+        return DB::query(Database::SELECT, $sql)
+            ->parameters([
+                ':studentID' => $studentID,
+                ':submoduleID' => $submoduleID,
+                ':option' => $option
+            ])->execute()[0];
     }
 }
diff --git a/~dev_rating/application/views/teacher/exam.twig b/~dev_rating/application/views/teacher/exam.twig
index 1bba7a0b1c31edaf0cab5f1a1e3c8add4ec738a3..c8f333ca9a833eba743de18eeb8f077801fe57af 100644
--- a/~dev_rating/application/views/teacher/exam.twig
+++ b/~dev_rating/application/views/teacher/exam.twig
@@ -123,6 +123,12 @@
 				<td class="group" colspan="{{ columnsCount }}">
 					{% if group.isAttached == 1 %} {{ group.GradeTitle }} {% endif %}{{ group.GroupNum }} РіСЂСѓРїРїР°.
 					<span class="downloadExcelStatement" id="group_{{ group.GroupID }}">Скачать ведомость</span>
+					<select id="stageSelector_{{ group.GroupID }}" class="stageSelector">
+						<option value="0">До экзамена</option>
+						<option value="1" selected="selected">Экзамен</option>
+						<option value="2">Пересдача 1</option>
+						<option value="3">Пересдача 2</option>
+					</select>
 				</td>
 			</tr>
  
@@ -138,10 +144,10 @@
 						{% set col = col + 1 %}
 						
 						{% if r.ModuleType == 'exam' %}
-							{% set td_class = 'attemptCell' %}
+							{% set td_class = 'commonCell attemptCell' %}
 						{% endif %}
 						{% if r.ModuleType == 'extra' %}
-							{% set td_class = 'additionalCell' %}
+							{% set td_class = 'commonCell additionalCell' %}
 						{% endif %}					
 
 						{% if r.Block == 'True' or (r.ModuleType != 'extra' and student.RateResult < 38) %}
@@ -149,9 +155,10 @@
 								<input type="text" value="{{ r.Rate  }}" disabled="disabled">
 							</td>
 						{% else %}
-							<td class="commonCell {{ td_class }}" id="col_{{ col }}_row_{{ row }}"> 
+							<td class="{{ td_class }}" id="col_{{ col }}_row_{{ row }}">
 								<input type="text" value="{{ r.Rate  }}" 
 									{% if r.ModuleType == 'extra' %}
+										class = "extra"
 										{% if r.MaxRate > 0 %}
 											placeholder="макс. {{r.MaxRate}}" 
 										{% else %} 
diff --git a/~dev_rating/docs/template credit.xls b/~dev_rating/docs/template credit 0 1.xls
similarity index 99%
rename from ~dev_rating/docs/template credit.xls
rename to ~dev_rating/docs/template credit 0 1.xls
index b069b5889a61815c3a43b38f34fa8775c8c731e3..995bcaec860753ce6c713f38f816a19aab141fd9 100644
Binary files a/~dev_rating/docs/template credit.xls and b/~dev_rating/docs/template credit 0 1.xls differ
diff --git a/~dev_rating/docs/template exam.xls b/~dev_rating/docs/template credit 2 3.xls
similarity index 78%
rename from ~dev_rating/docs/template exam.xls
rename to ~dev_rating/docs/template credit 2 3.xls
index 9943271dd566c079781845a426c77d1fa4e6b1a0..6e54b1db3ede36de742942f40112c012e6edd8ee 100644
Binary files a/~dev_rating/docs/template exam.xls and b/~dev_rating/docs/template credit 2 3.xls differ
diff --git a/~dev_rating/docs/template exam 0 1.xls b/~dev_rating/docs/template exam 0 1.xls
new file mode 100644
index 0000000000000000000000000000000000000000..8d0684d1094a86b778b362e9c4deb0422014987b
Binary files /dev/null and b/~dev_rating/docs/template exam 0 1.xls differ
diff --git a/~dev_rating/docs/template exam 2 3.xls b/~dev_rating/docs/template exam 2 3.xls
new file mode 100644
index 0000000000000000000000000000000000000000..60373f5f4e24055abd67e0635e01e78e4381bf24
Binary files /dev/null and b/~dev_rating/docs/template exam 2 3.xls differ
diff --git a/~dev_rating/media/js/rating.js b/~dev_rating/media/js/rating.js
index e03e94f5fa455b7a491f7b40178df1dea4b0f18b..017d7bb75b260e4769e245031207f84c4cc90192 100644
--- a/~dev_rating/media/js/rating.js
+++ b/~dev_rating/media/js/rating.js
@@ -45,6 +45,7 @@ $(function() {
         if ($("#pageType").val() === "exam") {
             var jAutoPassCheckBox = jRow.children(".autoPass").children(".autoPassCheck");
             var jAbsenceCheckBoxes = jRow.children(".absenceCell").children(".absenceCheck");
+            var jExtraInputs = jRow.children(".additionalCell").children(".extra");
             var semesterRate = parseInt(jRow.children(".semesterRateResultCell").text());
             var autopass = jAutoPassCheckBox[0].checked;
             var absence = jAbsenceCheckBoxes[0].checked;
@@ -53,19 +54,53 @@ $(function() {
             else
                 jAutoPassCheckBox.removeAttr("disabled");
 
-            if ((semesterRate < 38) || (autopass))
-                jAbsenceCheckBoxes.attr("disabled", true);
-            else
-                jAbsenceCheckBoxes.removeAttr("disabled");
+            // суммарный добор
+            var extra = 0;
+            jExtraInputs.each(function() {
+                extra += $(this).val();
+            });
+
+            // чекбоксы влияют на соседей
+            var row = parseInt(jRow.attr('id').substr(4)); // одинаковая для всех
+            var otherDisabled = false;
+            var firstInARow = true;
+            jAbsenceCheckBoxes.each(function() {
+                var id = $(this).parent().attr('id');
+                var col = parseInt(id.substr(8));
+                var neighborExam = $("#col_"+col+"_row_"+row);
+
+                $(this).removeAttr("disabled");
+                if (autopass) // автомат
+                    $(this).attr("disabled", true);
+                else if (firstInARow && (semesterRate < 38)) // задолженник
+                    $(this).attr("disabled", true);
+                else if (semesterRate + extra < 38) // задолженник до сих пор
+                    $(this).attr("disabled", true);
+
+                if (($(this)[0].checked) || autopass || otherDisabled) // автомат, неявка или сдал до этого
+                    neighborExam.children().attr("disabled", true);
+                else {
+                    if (firstInARow && (semesterRate < 38)) // задолженник
+                        neighborExam.children().attr("disabled", true);
+                    else if (semesterRate + extra < 38) // задолженник до сих пор
+                        neighborExam.children().attr("disabled", true);
+                    else {
+                        neighborExam.children().removeAttr("disabled");
+                        if (neighborExam.children().val() == "")
+                            otherDisabled = true;
+                    }
+                }
 
-            // TODO: disable CommonCell connected with this exam if absence or autopass checked
+                firstInARow = false;
+            });
         }
     }
 
     function controlVisualization() {
-        $(".row")
+        $(".studentsRate").children().children("tr")
             .each(function () {
-                controlRowVisualization($(this));
+                if (($(this).prop("id") != "") && ($(this).attr("id").substr(0, 3) == "row"))
+                        controlRowVisualization($(this));
             });
     }
 
@@ -261,8 +296,6 @@ $(function() {
         }
 
         if (newRate <= g_submoduleMaxRate) {
-            if (newRate == -1)
-                newRate = null; // TODO: начить setRate принимать null на вход
             $.ajax({
                 type: "POST",
                 url: URLdir + "handler/rating/setRate",
@@ -542,7 +575,7 @@ $(function() {
         }
     });
 
-    // Скачать таблицу оценивания в формате excel
+    // Скачать таблицу оценивания в формате excel // depricated
     $(".downloadExcel").click(function(){
         $.fileDownload(URLdir + 'handler/FileCreator/GenerateExcelRatingTable', {
             httpMethod: "POST",
@@ -561,12 +594,17 @@ $(function() {
 
     // Ведомость в формате excel
     $('body').on('click', '.downloadExcelStatement', function(){
+
+        var groupID = parseInt($(this).attr("id").substr(6))
+        var jStageSelector = $("#stageSelector_"+groupID);
+
         $.fileDownload(URLdir + 'handler/FileCreator/GenerateFinalForm', {
             httpMethod: "POST",
             data:
             {
                 "disciplineID": g_disciplineID,
-                "studyGroupID": parseInt($(this).attr("id").substr(6))
+                "groupID": groupID,
+                "stage": parseInt(jStageSelector.val())
             },
             successCallback: function () {