创建并发送后在 CakePhp 上显示 pdf

问题描述 投票:0回答:1

这是我的第一篇文章,很抱歉,以防我犯一些错误。我从今天早上开始就因为这个功能而生气:

public function viewpdf0($agent_id = null, $month = null, $year = null){

    if(!empty($agent_id)){

        $this->create_remittance($agent_id, $month, $year);

        $this->layout = '/pdf/default';
        $this->render('/Pdf/remittance_0');
        sleep(1);

        $this->redirect('/files/remittances/STAT_'.str_pad($month, 2, '0', STR_PAD_LEFT).'_'.str_pad($year, 0, '0', STR_PAD_LEFT).'_'.$agent['Registry']['hash'].'_TEMP.pdf');

    }
}

当我决定从 viewpdf0 函数中取消计算并将其放入 create_remittance 函数时,问题就开始了。

当我单击“打印 Pdf”按钮时,出现以下错误:

Missind 文件控制器。这意味着 Cakephp 正在处理重定向,并认为找到一个名为 files 的控制器!!!!

这很奇怪,因为如果我再次将计算函数直接放在 viewpdf0 函数中,它就可以工作。

create_remittance 函数的以下部分:

公共函数create_remittance($agent_id = null, $month = null, $year = null) { $agent = $this->注册表->findById($agent_id); $this->set('agent', $agent);

        $conditions = array();

        array_push($conditions , array('Dossier.active' => '1'));

        array_push($conditions , array('Edossier.active' => '1'));

        array_push($conditions , array('OR' =>     
                            array(
                                array(
                                        'Dossier.item_parent_id' => '43'
                                    ),
                                array(        
                                        'Dossier.item_parent_id' => '44'
                                    )
                            )

                        ));

        //20:POLIZZA EMESSA - 17:PERFEZIONATA - 14:ATTESA DOC. ORIGINALI - 18:CARICATA              
        array_push($conditions , array('Dossier.state_id' => array(20,17,14,18)));

        array_push($conditions , array('EXTRACT(MONTH FROM "Edossier"."date_emissione") =' => $month));

        array_push($conditions , array('EXTRACT(YEAR FROM "Edossier"."date_emissione") =' => $year));

        array_push($conditions , array('Dossier.agent_id' => $agent_id));

        $query = array(
                        'fields' => array(  'DISTINCT Dossier.id',
                                            'Agent.surname'                                     
                                            ),

                        'joins' => array(                                         
                                        array('table' => 'items',
                                              'alias' => 'Item',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.item_id = Item.id'),
                                              ),

                                        array('table' => 'edossiers',
                                              'alias' => 'Edossier',
                                              'type' => 'LEFT',
                                              'conditions' => array('Edossier.dossier_id = Dossier.id'),
                                              ),

                                        array('table' => 'registries',
                                              'alias' => 'Registry',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.registry_id = Registry.id'),
                                              ),

                                        array('table' => 'registries',
                                              'alias' => 'Agency',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.insurance_agency_id = Agency.id'),
                                              ),

                                        array('table' => 'registries',
                                              'alias' => 'Company',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.insurance_company_id = Company.id'),
                                              ),

                                        array('table' => 'states',
                                              'alias' => 'State',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.state_id = State.id'),
                                            ),

                                        array('table' => 'categories',
                                              'alias' => 'Product',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.item_parent_id = Product.id'),
                                            ),

                                        array('table' => 'registries',
                                              'alias' => 'Agent',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.agent_id = Agent.id'),
                                            ),

                                        array('table' => 'states',
                                              'alias' => 'RenewedState',
                                              'type' => 'LEFT',
                                              'conditions' => array('Dossier.renewed_state_id = RenewedState.id'),
                                            ),                                  


                                        ),
                        'conditions' => $conditions,
                        'recursive' => -1         
                    ); 

        $dossiers = $this->Dossier->find('all', $query);

        $this->set('dossiers', $dossiers);

        $debug_dossier = '';
        $edossiers = array();
        $edossiers3 = array();
        $dossier_ids = array();
        $total_gross = 0;
        $total_taxes = 0;
        $total_equity = 0;
        $total_fees_gross = 0;
        $total_bill_tax = 0;

        foreach($dossiers as $dossier){

            // Query su type=1 ossia rata di pagamento
            $edossier_all = $this->Edossier->find('all', array(
                'conditions' => array(
                    'Edossier.active' => '1',
                    'Edossier.dossier_id' => $dossier['Dossier']['id'],
                    'Edossier.type' => '1',
                    'Edossier.month' => $month,
                    'Edossier.year' => $year
                ),
                'order' => array(
                    'Edossier.id ASC'
                )
            ));

            // Query su type=2 ossia storno di pagamento
            $edossier3_all = $this->Edossier->find('all', array(
                'conditions' => array(
                    'Edossier.active' => '1',
                    'Edossier.dossier_id' => $dossier['Dossier']['id'],
                    'Edossier.type' => '2',
                    'Edossier.month' => $month,
                    'Edossier.year' => $year
                ),
                'order' => array(
                    'Edossier.id ASC'
                )
            ));



            foreach($edossier_all as $edossier){
                if(!empty($edossier)){
                    $item = $this->Item->findById($edossier['Dossier']['item_id']);
                    $agent_name = $this->Registry->findById($edossier['Dossier']['agent_id']);
                    $state = $this->State->findById($edossier['Dossier']['state_id']);
                    $registry = $this->Registry->findById($edossier['Dossier']['registry_id']);
                    $cashflow = $this->Cashflow->findByHash($edossier['Edossier']['cashflow_hash']);
                    $edossier['Agent'] = $agent_name;
                    $edossier['Item'] = $item;
                    $edossier['State'] = $state;
                    $edossier['Registry'] = $registry;
                    $edossier['Cashflow'] = $cashflow;
                    array_push($edossiers, $edossier);
                    $total_gross = $total_gross + $edossier['Edossier']['gross'];
                    $total_taxes = $total_taxes + $edossier['Edossier']['taxes'];
                    $total_equity = $total_equity + $edossier['Edossier']['equity'];
                    $total_fees_gross = $total_fees_gross + $edossier['Edossier']['fees_gross'];
                    $total_bill_tax = $total_bill_tax + $edossier['Edossier']['bill_tax'];
                }
            }

            foreach($edossier3_all as $edossier3){
                if(!empty($edossier3)){

                    $total_gross = $total_gross - $edossier3['Edossier']['value'];
                    $total_taxes = $total_taxes - $edossier3['Edossier']['taxes'];
                    $total_equity = $total_equity - $edossier3['Edossier']['equity'];
                    $total_fees_gross = $total_fees_gross - $edossier3['Edossier']['fees_gross'];
                    $total_bill_tax = $total_bill_tax - $edossier3['Edossier']['bill_tax'];


                    array_push($edossiers3, $edossier3);
                }
            }               

            array_push($dossier_ids, $dossier['Dossier']['id']);
            $debug_dossier .= $dossier['Dossier']['id'] .',';
        }

        //Trovo tutte le rate pagate per conteggiare il totale pagato, nelle successive righe
        $edossiers2 = $this->Edossier->find('all', array(
            'conditions' => array(
                'Edossier.active' => '1',
                'Edossier.dossier_id' => $dossier_ids,
                'Edossier.payed' => '1',
                'Edossier.month' => $month,
                'Edossier.year' => $year
            )
        ));

        $edossier_ids = array();
        foreach($edossiers as $edossier){
            array_push($edossier_ids, $edossier['Edossier']['id']);
        }


        $total_payed = 0;
        foreach($edossiers2 as $edossier2){
            //$cashflow = $this->Cashflow->findByHash($edossier2['Edossier']['cashflow_hash']);
            //$total_payed = $total_payed + $cashflow['Cashflow']['qty'];

            $cashflows = $this->Cashflow->find('all', array(
                'conditions' => array(
                    'Cashflow.edossier_id' => $edossier2['Edossier']['id'],
                    'Cashflow.active' => '1'
                    )
            ));

            foreach ($cashflows as $cashflow) {

                $total_payed = $total_payed + $cashflow['Cashflow']['qty'];
            }

        }

        $this->set('total_gross', $total_gross);
        $this->set('total_taxes', $total_taxes);
        $this->set('total_equity', $total_equity);
        $this->set('total_fees_gross', $total_fees_gross);
        $this->set('total_bill_tax', $total_bill_tax);

        $this->set('total_payed', $total_payed);
        $this->set('edossiers3', $edossiers3);
        $this->set('edossiers2', $edossiers2);
        $this->set('edossiers', $edossiers);
        $this->set('agent', $agent);
        $this->set('dossier_ids', $dossier_ids);
        $this->set('edossier_ids', $edossier_ids);
        $this->set('month', $month);
        $this->set('year', $year);
        $this->set('debug_dossier', $debug_dossier);
}
php pdf cakephp
1个回答
0
投票

我解决了这个问题,只需在函数 create_remittance 和函数 viewpdf0 中插入一个数组返回,我以这种方式修复:

$remittance = $this->create_remittance($agent_id, $month, $year);

谢谢你。

© www.soinside.com 2019 - 2024. All rights reserved.