<?php
    $dRange = $_POST['dRange']  ;
    $reportInfo=['Date:  '.$dRange];
    $general->getFromToFromString($dRange,$from,$to);
    $rData=[];
    $sr=1;

    $visit_list =$db->selectAll('doctor_visit','where entry_time between '.$from.' and '.$to.' and createdBy='.USER_ID);
    if(!empty($visit_list)){
        $doctor_ids=[];
        foreach($visit_list as $vl){
            $doctor_ids[$vl['doctor_id']]=$vl['doctor_id'];
        }
        $doctors = $db->selectAll('doctor','where id in ('.implode(',',$doctor_ids).')','id,code,name');
        $general->arrayIndexChange($doctors);
        foreach($visit_list as $vl){
            $rData[]=[
                's'=>$sr++,
                'd'=>$general->make_date($vl['entry_time'],'time'),
                'v'=>$doctors[$vl['doctor_id']]['name'],
                'p'=>$vl['prescription'],
                'r'=>$general->content_show($vl['note']),
                'de'=>'<a href="'.APP_URL.'/?mdl=doctor-visit-details&id='.$vl['id'].'" class="btn btn-success">Details</a>',
            ];
        }
    }
    $head=[
        ['title'=>'SL'          ,'key'=>'s','hw'=>5],
        ['title'=>'Date'        ,'key'=>'d'],
        ['title'=>'Doctor'    ,'key'=>'v'],
        ['title'=>'Prescription'    ,'key'=>'p'],
        ['title'=>'Note'        ,'key'=>'r' ],
        ['title'=>'Details'     ,'key'=>'de'],
    ];
    $fileName='customer_visit_list_'.TIME.rand(0,999).'.txt';
    $report_data=[
        'name'      => 'doctor_visit_list',
        'title'     => 'doctor visit list',
        'info'      => $reportInfo,
        'head'=>$head,
        'data'=>$rData
    ];
    $gAr['report_data']= $report_data;
    textFileWrite(json_encode($report_data),ROOT_DIR.'/print_file/'.$fileName);
    $jArray['html']     = $general->fileToVariable(ROOT_DIR.'/ajax/report.phtml');
    $jArray['status']=1;
