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

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