0

I have been try to convert template to PDF with DOMPDF in phalconPHP with angularJS at the front. But I am getting 500 internal server error response from it. DOMPDF is included fine in the controller as I loaded static HTML in load_html() function, it worked fine. Below is the report action from ReportsController. Don't bother with the whole code and just skip to the DOMPDF related code at the end. And $patients is the array that contains all the data which the template is going to need.

ReportController's reportAction:

    public function reportAction()
{
    $patientsModel = new Patients();
    $patients = array();
    $patients['data'] = array();

    $tmpfilters = $this->queryfilters;
    unset($tmpfilters['limit']);

    $tmpfilters2 = array();
    $tmpfilters2['models'] = "PRM\\Models\\Patients";
    if( isset( $tmpfilters['conditions'] ) )
    {
        $tmpCondition = preg_replace("/[^0-9]/", '', $tmpfilters['conditions']);
        $tmpfilters2['conditions'] = "clinic = " . $tmpCondition . " AND status = 24";
    }
    else
    {
        $tmpfilters2['conditions'] = "status = 24";
    }
    $tmpActivePatients = new Patients();
    $tmpActivePatients = $tmpActivePatients->find($tmpfilters2);
    $patients['activeTotal'] = $tmpActivePatients->count();

    $tmpfilters3 = array();
    $tmpfilters3['models']['m'] = "PRM\\Models\\Activity";
    $tmpfilters3['models']['s'] = "PRM\\Models\\Patients";
    if( isset( $tmpfilters['conditions'] ) )
    {
        $tmpCondition2 = preg_replace("/[^0-9]/", '', $tmpfilters['conditions']);
        $tmpfilters3['conditions'] = "m.clinic = " . $tmpCondition2 . " AND " . "s.clinic = " . $tmpCondition2 . " AND m.patient=s.id AND m.duration > 1";
    }
    else
    {
        $tmpfilters3['conditions'] = "m.patient = s.id AND m.duration > 1";
    }
    $tmpPatientDuration = new Query($tmpfilters3);
    $tmpPatientDuration = $tmpPatientDuration->getQuery()->execute();
    //$builder = $this->modelsManager->createBuilder();
    $patients['billableTotal'] = $tmpPatientDuration->count();
    //$builder->addFrom('PRM\\Models\\Activity', 'a')->innerJoin('PRM\\Models\\Patients', 'p.id=a.patient', 'p')->where('a.duration > 1 AND p.status = 24');
    //$result = $builder->getQuery()->execute();
    //$patients['billableTotal'] = $result->count();

    foreach ($tmpPatientDuration as $patient) {
        array_push($patients['data'], array(
            'id' => $patient->id,
            'firstname' => $patient->s->firstname,
            'lastname' => $patient->s->lastname,
            'duration' => $patient->m->duration,
            'billingCode' => "CPT 99490"));
            /*'icd1' => Ccm::findFirstById($patient->icd1)->icdcode,
            //'icd2' => Ccm::findFirstById($patient->icd2)->icdcode,
            //'clinic' => Clinics::findFirstById($patient->clinic)->name,
            'duration' => Activity::sum([
                "column" => "duration",
                "conditions" => "patient = '{$patient->id}'",
            ]),
            'response' => Activity::findFirst([
                "conditions" => "patient = '{$patient->id}' and activity='Communication' ",
                "order" => "id desc"
            ])->description,
            'status' => Status::findFirstById($patient->status)->name));*/
    }


    $html = $this->view->getRender("reports", "report", $patients);
    $dompdf = new domPdf();
    $dompdf->load_html($html);
    $dompdf->setPaper('A4', 'landscape');
    $dompdf->render();


    //$this->response->setJsonContent($patients);
    $this->response->setContentType('application/pdf');
    $this->response->setContent($dompdf->stream());
    $this->response->send();
}

Here is the angularJS controller's code:

    $http.get('common/reports/report', {responseType: 'arraybuffer'}).success(
        function (data) {
            var file = new Blob([data], {type: 'application/pdf'});
            var fileURL = URL.createObjectURL(file);
            window.open(fileURL);
        }).error(
        function (data) {
            angular.forEach(data, function (error) {
                $scope.error[error.field] = error.message;
                console.log(error.field);
            });
            $alert({title: 'Error!', content: data.flash.message, placement: 'top-right', type: data.flash.class , duration: 10, container: '.site-alert'});
        }
    );

error logs: error log for the above problem

0 Answers0