在数组控制器cakephp上的分页

时间:2019-03-18 21:18:24

标签: cakephp

你好,我正在尝试在板上进行分页。

我在同一视图中检索3个不同的表,我想向某个表添加分页。这是我的控制器:

public function index() {
        $board = array();

        $board[0] = $this->Document->calculate_prices($this->Document->factures());
        $board[1] = $this->Document->calculate_prices($this->Document->devis());
        $board[2] = array();

        $inactive_contracts = $this->Contract->contracts();

        foreach ($inactive_contracts as $contract) {
            if ($contract['Statu'][count($contract['Statu']) - 1]['status'] == 'accepted') {
                $board[2][] = $contract;
            }
        }

        // Calcul des montants
        $sum[0] = array('total' => array(), 'net' => array());
        foreach ($board[0] as $key => $document) {
            $sum[0]['total'][] = $document['Document']['total_price'];
            $sum[0]['net'][] = $document['Document']['net_price'];
        }
        $sum[1] = array('total' => array(), 'net' => array());
        foreach ($board[1] as $key => $document) {
            $sum[1]['total'][] = $document['Document']['total_price'];
            $sum[1]['net'][] = $document['Document']['net_price'];
        }

        $this->set(compact('board'));
        $this->set(compact('sum'));
    }

我的函数calculate_prices:

public function calculate_prices($results, $primary = false) {
        App::import('Model', 'Subdetail');
        $_subdetail = new Subdetail();

        foreach ($results as $key => $document) {
            // Obtention des details
            $details_ids = array();
            foreach ($document['Detail'] as $detail) {
                $details_ids[] = $detail['id'];
            }

            $details = $_subdetail->find('all', array('conditions' => array('Subdetail.detail_id' => $details_ids)));

            // Calcul des prix
            $prices = array();

            foreach ($document['Detail'] as $detail) {
                if ($detail['price'] != null) {
                    $prices[] = floatval(($detail['quantity'] == null ? 1 : $detail['quantity'])) * floatval($detail['price']);
                }
            }
            foreach ($details as $detail) {
                if ($detail['Detail']['price'] == null && $detail['Subdetail']['price'] != null) {
                    $prices[] = floatval(($detail['Subdetail']['quantity'] == null ? 1 : $detail['Subdetail']['quantity'])) * floatval($detail['Subdetail']['price']);
                }
            }

            $final_prices = array();
            $final_prices['total'] = array_sum($prices);
            $final_prices['tva'] = $final_prices['total'] / 100 * floatval($document['Document']['TVA']);
            $final_prices['net'] = $final_prices['total'] + $final_prices['tva'];

            $results[$key]['Document']['total_price'] = $final_prices['total'];
            $results[$key]['Document']['tva_price'] = $final_prices['tva'];
            $results[$key]['Document']['net_price'] = $final_prices['net'];

            // if (is_array($results)) echo 'is_array($results): true'; else 'is_array($results): false';
            // if (is_array($final_prices)) echo 'is_array($final_prices): true'; else 'is_array($final_prices): false';
            // die();

            // debug($document);
            // debug($details);
            // debug($prices);

            unset($details);
            unset($prices);
            unset($final_prices);
        }

        return $results;
    }

我正在尝试在$ board上进行分页[1]

我添加了缺少的功能

我该怎么做?

谢谢您的帮助。

0 个答案:

没有答案