2016-08-19 59 views
0

這是我的第一篇文章,非常抱歉,以防我會犯一些錯誤。我因爲這個功能正從今天上午瘋狂:創建並保存後在CakePhp上顯示pdf

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正在處理重定向思維以找到一個稱爲文件的控制器!

這很奇怪,因爲如果我把計算功能直接放在viewpdf0函數中,它就起作用了。

下面的create_remittance功能的一部分:

公共職能create_remittance($ AGENT_ID = NULL,$月= NULL,$年= NULL){$ 劑= $這個 - >登記處送交> 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); 
} 
+0

如果您正在收到'Missing Controller'錯誤,則說明您的路由有問題。我建議你使用正確的路由。 [見文檔](http://book.cakephp.org/2.0/en/development/routing.html)。 – BadHorsie

+0

您正在'create_remittance'函數中定義'$ agent',但是當您調用重定向時,則會在函數外部使用它。很奇怪,你沒有得到一個未定義的錯誤或類似 – arilia

+0

如果我寫這個:$ this-> redirect('http://crm0.convieneonline.it/files/remittances/STAT_'.str_pad($ month,2,' 0',STR_PAD_LEFT)。'_'。str_pad($ year,0,'0',STR_PAD_LEFT)。'_'。$ agent ['Registry'] ['hash'] .'_ TEMP.pdf');我得到一個奇怪的網址,如http://crm0.convieneonline.it/http://crm0.convieneonline.it ... – leele144

回答

0

我剛剛解決了在插入功能create_remittance和功能viewpdf0我固定在這樣一個數組的回報問題:

$匯款= $這個 - > create_remittance($ AGENT_ID,$月份, $年);

謝謝。