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

    $visit_list =$db->selectAll('bazar_visit','where entry_time between '.$from.' and '.$to.' and createdBy='.USER_ID);
    if(!empty($visit_list)){
        $bazar_ids=[];
        foreach($visit_list as $vl){
            $bazar_ids[$vl['bazar_id']]=$vl['bazar_id'];
        }
        $bazars = $db->selectAll('bazar','where id in ('.implode(',',$bazar_ids).')','id,title');
        $general->arrayIndexChange($bazars);
        foreach($visit_list as $vl){
            $rData[]=[
                's'=>$sr++,
                'd'=>$general->make_date($vl['entry_time'],'time'),
                'v'=>$bazars[$vl['bazar_id']]['title'],
                'r'=>$general->content_show($vl['note']),
                'de'=>'<a href="'.APP_URL.'/?mdl=bazar-visit-details&id='.$vl['id'].'" class="btn btn-success">Details</a>',
            ];
        }
    }
    $head=[
        ['title'=>'SL'          ,'key'=>'s','hw'=>5],
        ['title'=>'Date'        ,'key'=>'d'],
        ['title'=>'Bazar'    ,'key'=>'v'],
        ['title'=>'Note'        ,'key'=>'r' ],
        ['title'=>'Details'     ,'key'=>'de'],
    ];
    $fileName='bazar_visit_list_'.TIME.rand(0,999).'.txt';
    $report_data=[
        'name'      => 'bazar_visit_list',
        'title'     => 'Bazar 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;
