<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\data\SqlDataProvider;


$this->title = 'PatientcrosstabReport';
$this->params['breadcrumbs'][] = $this->title;

$dataProviderAge = new SqlDataProvider([
     'sql' => 'SELECT Distinct "<= 17" As AgeRange,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q4<=17 and corfrm_q5=1) MaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q4<=17 and corfrm_q5=2) FemaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q4<=17 and corfrm_q5=3) HijraCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q4<=17) TotCnt '.
               'FROM cms_registration '.
               'Union '.
              ' SELECT Distinct "18 - 25" As AgeRange,(SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 18 AND 25) and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 18 AND 25) and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 18 AND 25) and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 18 AND 25)) '	.
               'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "26 - 35" As AgeRange,(SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 26 AND 35) and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 26 AND 35) and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 26 AND 35) and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 26 AND 35)) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "36 - 50" As AgeRange,(SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 36 AND 50) and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 36 AND 50) and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 36 AND 50) and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4 BETWEEN 36 AND 50)) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "> 50" As AgeRange,(SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4> 50) and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4> 50) and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4> 50) and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where (corfrm_q4> 50)) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Total" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration ) TotCnt '.
			   'FROM cms_registration ' ,		 
     'params' => [],
 ]);
 
 $dataProviderMarital = new SqlDataProvider([
 'sql' => 'SELECT Distinct "Never Married" As MaritalStatus,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=1 and corfrm_q5=1) MaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=1 and corfrm_q5=2) FemaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=1 and corfrm_q5=3) HijraCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=1) TotCnt '.
               'FROM cms_registration '.
               'Union '.
              ' SELECT Distinct "Currently Married" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=2 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=2 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=2 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=2) '	.
               'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Widowed" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=3 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=3 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=3 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=3) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Divorced" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=4 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=4 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=4 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=4) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Separated" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=5 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=5 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=5 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=5) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Refused" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=998 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=998 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=998 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q6=998) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Total" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration ) TotCnt '.
			   'FROM cms_registration ' ,		 
     'params' => [],
 ]);
 
 $dataProviderEduc = new SqlDataProvider([
 'sql' => 'SELECT Distinct "No school" As EducStatus,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=1 and corfrm_q5=1) MaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=1 and corfrm_q5=2) FemaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=1 and corfrm_q5=3) HijraCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=1) TotCnt '.
               'FROM cms_registration '.
               'Union '.
              ' SELECT Distinct "Primary school (class 1-5)" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=2 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=2 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=2 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=2) '	.
               'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "High school (class 6-12)" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=3 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=3 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=3 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=3) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "High school graduate" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=4 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=4 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=4 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=4) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "College or beyond" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=5 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=5 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=5 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=5) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Refused" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=998 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=998 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=998 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q7=998) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Total" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration ) TotCnt '.
			   'FROM cms_registration ' ,		 
     'params' => [], 
 ]);
 
 $dataProviderEmp = new SqlDataProvider([
 'sql' => 'SELECT Distinct "Unemployed" As EmpStatus,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=1 and corfrm_q5=1) MaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=1 and corfrm_q5=2) FemaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=1 and corfrm_q5=3) HijraCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=1) TotCnt '.
               'FROM cms_registration '.
               'Union '.
              ' SELECT Distinct "Daily wages" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=2 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=2 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=2 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=2) '	.
               'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Weekly wages" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=3 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=3 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=3 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=3) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Monthly wages" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=4 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=4 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=4 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=4) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Refused" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=998 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=998 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=998 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q8=998) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Total" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration ) TotCnt '.
			   'FROM cms_registration ' ,		 
     'params' => [],
 ]);
 
 $dataProviderRef = new SqlDataProvider([
 'sql' => 'SELECT Distinct "Existing client of ICC" As RefStatus,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=1 and corfrm_q5=1) MaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=1 and corfrm_q5=2) FemaleCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=1 and corfrm_q5=3) HijraCnt,
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=1) TotCnt '.
               'FROM cms_registration '.
               'Union '.
              ' SELECT Distinct "Existing client of NGO" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=2 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=2 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=2 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=2) '	.
               'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Friend told me	" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=3 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=3 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=3 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=3) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Saw on street and came in" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=4 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=4 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=4 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=4) ' .
			   'FROM cms_registration '.
			   'Union '.
			   'SELECT Distinct "Referred by private doctor/other lab/CBO" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=5 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=5 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=5 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=5) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Outreach worker" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=6 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=6 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=6 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=6) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Referral SMS" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=7 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=7 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=7 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=7) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Participated in previous YRG survey (e.g., RDS II)" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=8 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=8 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=8 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=8) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Other" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=9 and corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=9 and corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=9 and corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q10=9) ' .
			   'FROM cms_registration ' .
			   'Union '.
			   'SELECT Distinct "Total" ,(SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=1),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=2),
               (SELECT Count(corfrm_id) FROM cms_registration where corfrm_q5=3),
               (SELECT Count(corfrm_id) FROM cms_registration ) TotCnt '.
			   'FROM cms_registration ' ,		 
     'params' => [],
 ]);


?>


<div class="attandance-form">
    <h1><?= Html::encode($this->title) ?></h1>
    <div class="panel panel-default">
        <div class="panel-heading">
            
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                        $form = ActiveForm::begin(['options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);
                        $template = [
                            'labelOptions' => ['class' => 'form-label'],
                            'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
                        ];
                        
                    ?>
                    <?= $form->field($model, 'reptype', $template)->dropDownList($model->type, ['prompt' => $model->getAttributeLabel("reptype")]) ?>
                 
                    <div class="form-group">
                        <div class="col-sm-offset-5 col-sm-7">
                            <?= Html::submitButton(Yii::t('app', 'Go'), ['class' =>'btn btn-success']) ?>
                           
                        </div>
                    </div>
					<div class="row">
					
     <?php if(($model->load(Yii::$app->request->post()) && $model->reptype==1) ) : ?>
        <div class="col-md-12"><?= $this->render('agewisepartsummary', ['dataProvider' => $dataProviderAge]); ?></div>
	<?php elseif(($model->load(Yii::$app->request->post()) && $model->reptype==2) ) : ?>
	    <div class="col-md-12"><?= $this->render('maritalwisepartsummary', ['dataProvider' => $dataProviderMarital]); ?></div>
	<?php elseif(($model->load(Yii::$app->request->post()) && $model->reptype==3) ) : ?>
	    <div class="col-md-12"><?= $this->render('educwisepartsummary', ['dataProvider' => $dataProviderEduc]); ?></div>
    <?php elseif(($model->load(Yii::$app->request->post()) && $model->reptype==4) ) : ?>
	    <div class="col-md-12"><?= $this->render('empwisepartsummary', ['dataProvider' => $dataProviderEmp]); ?></div>
    <?php elseif(($model->load(Yii::$app->request->post()) && $model->reptype==5) ) : ?>
	    <div class="col-md-12"><?= $this->render('refwisepartsummary', ['dataProvider' => $dataProviderRef]); ?></div>		
     <?php endif; ?>  
    </div>
                    <?php ActiveForm::end(); ?>
                </div>
                <!-- /.col-lg-6 (nested) -->
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>