breakupxls.blade.php 6.06 KB
<?php
if(Input::has("report"))
{
    $view_path = Config::get('view.paths'); 
    include_once($view_path[0].'/layout/module/dialer/reporthead.blade.php');

    $userId     =(isset($_GET['userId']))  ? $_GET['userId']  : "All";
    if($userId != 'All')   $alist->where('c.user_id','=',Input::get('userId'));

    switch (Input::get("report")) {
        case 'contactability':      
            $alist->whereIn('c.userstatus', array("Contacted", "Not Contacted", "FORCEDCLOSE"));
            if(Input::get("column") != 'Total')
            {
                $col_array = explode('||', Input::get('column'));
                $alist->where('c.userstatus', '=',$col_array[0]);
                if($col_array[0] != $col_array[1]) {
                    $alist->where('c.action_code','=',$col_array[1]);   
                }
            }
            break;
        case 'productivity':        
            if(Input::get("column") != 'Total')
            {
                $alist->where('c.resultCode','=',Input::get('column'));
            }
            break;
        case 'nextaction':          
            $alist->where('c.resultCode','=','PTP');
            if(Input::get("column") != 'PTP')
            {
                $alist->where('c.nextActionCode','=',Input::get('column'));
            }
            break;
    }

    if(!$joined) $alist=$alist->leftJoin('records as r', 'c.crm_id', '=', 'r.id');
    $alist=$alist->get();

    if(Input::get("report") != 'nextaction' || Input::get("column") != 'PU')
    $reporthead=array(  
        '#'=>'#',
        'lan'=>'LAN',
        'customerName'=>'Customer Name',
        'emi'=>'EMI',
        'pos'=>'POS',
        //'#'=>'OD Days',
        'bounceCharge'=>'Bounce Charge',
        //'penalMTD'=>'Penal Charges',
        'overdueAmount'=>'OD Amount',
        'product'=>'Product',
        'number'=>'Mobile',
        'duedate'=>'Due Date',
        //'reasonForLastBounce'=>'Last Bounce',
        'residenceAddress'=>'Residence Address',
        //'altphone1'=>'Residence Phone No.',
        'officeAddress'=>'Office Address',
        //'altphone2'=>'Office Phone No.',
        //'pickup_address_type'=>'Pickup Address Type',
        //'pickup_address'=>'Pickup Address',
        //'pickup_address_phone'=>'Pickup Address Phone No.',
        'lastMonthPaymentAmount'=>'Last Month Payment Amount',
        'lastMonthPaymentDate'=>'Last Month Payment Date',
        'installmentAmountOverdue'=>'Installment OD Amount',
        'user_id'=>'Telecaller', 
        //'ptp_amt'=>'PTP Amount',
        'nextActionDateTime'=>'PTP Date',
        //'payment_mode'=>'Payment Mode',
        'depositer_name'=>'Depositer Name',
        );
    else
    $reporthead=array(  
        'pickup_collection_date'=>'Date of PU',//cc
        'pickup_collection_time'=>'PU Time',//cc
        'user_id'=>'Agent Name',//cc
        'state'=>'State',//re
        'location'=>'City',//re
        'product'=>'Prod Type',//re
        'lan'=>'LAN',//re
        'customerName'=>'Customer Name',//re
        'pickup_contact_person_name'=>'PU Contact Person',//cc
        'pickup_contact_person_mobile'=>'Contact Person #',//cc
        'pos'=>'POS',//re
        'pickup_emi_amount'=>'EMI Amount',//cc
        'pickup_bnp_amount'=>'B&P Amount',//cc
        'pi_total'=>'Total PU Amt',//Cal from cc
        'pickup_payment_mode'=>'Payment Mode',//cc
        'pickup_address'=>'PU Address',//cc
        );

    include_once(app_path().'/lib/phpexcel/PHPExcel.php');
    
    $inputFileType = "Excel5";
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load("assets/extras/blank.xls");
    $baseRow = 2;


    $index_count = 0;
    if(Input::get("report") != 'nextaction' || Input::get("column") != 'PU')
    $headerRow = $reporthead;
    else
    $headerRow = array_merge($reporthead, 
        array('vendor_name' =>'Vendor Name',
            'vendor_id'     =>'Vendor ID',
            'coallocated_id'=>'Coallocated Id',
            'fos_name'      =>'Fos Name',
            'receipt_no'    =>'Receipt No.',
            'receipt_date'  =>'Receipt Date',
            'receipt_amt'   =>'Receipt Amt',
            'vpayment_mode' =>'Mode of Payment',
            'cheque_dd_date'=>'Cheque/DD Date',
            'cheque_dd'     =>'Cheque/DD #',
            'drawn_on_bank' =>'Drawn on Bank',
            'vendor_remarks'=>'Remarks'
            ));
    foreach($headerRow AS $key => $val){
        $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
        $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $val);
        $index_count++;
    }

    foreach($alist as $aline)
    {
        $row = $baseRow++;
        $index_count = 0;
        $col = 0;
        
        foreach($reporthead AS $key => $val){
            $sr_no = $row-1;
            switch ($key) {
                case '#':               $cellval = $sr_no;                                              break;
                case 'user_id':         $cellval = $userarr[$aline->user_id]->telecaller;               break;
                case 'pickup_collection_date': 
                    $cellval = ($aline->pickup_collection_date != '0000-00-00 00:00:00') ?
                        date('Y-m-d', strtotime($aline->pickup_collection_date)) : '0000-00-00';        break;
                case 'pickup_collection_time': 
                    $cellval = date('H:i:s', strtotime($aline->pickup_collection_date));                break;
                case 'pi_total':        $cellval = $aline->pickup_emi_amount+$aline->pickup_bnp_amount; break;
                default:                $cellval = $aline->$key;                                        break;
            }

            $colstr=PHPExcel_Cell::stringFromColumnIndex($index_count);
            $objPHPExcel->getActiveSheet()->setCellValue($colstr.$row, $cellval);
            $index_count++;
        }
    }

    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="Breakup.xls"');
    header('Cache-Control: max-age=0');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
    $objWriter->save('php://output');
    
    return ;
}
?>