2016-07-23 2 views
0

Ich versuche, eine Rechnung in yii2 zu drucken. Es gibt zwei Tische, an denen ich zwei Tische berühre. Eines ist prodfin - wo das totalamount gespeichert ist und prodsummary, wo die Produkte und Mengen gespeichert werden. Jetzt möchte ich diese zu meiner Ansicht weitergeben und mit mpdf nach pdf drucken. Ich benutze prodfin als primäres Modell und hole prodsummary Daten dazu. Mein Haupthindernis ist jetzt, prodsummary Details zu übergeben, d. H. Produktcode, Produktname, Menge, Rate, Menge an Stelle Reihe für Reihe. Ich befestige eine Probe damit.Bekannte unbekannte Eigenschaft: Frontend Module Printinvoice Modelle Prodfin :: Produktcode

Was ich versuche zu erreichen -

enter image description here

Meine Controller Aktion

public function actionPrintinvoice($id) { 
     $model = $this->findModel($id); 
     $searchModel = new ProdfinSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 
     $data   = Prodfin::findOne($id); 
     $dataProvider = new ActiveDataProvider([ 
      'query' => Prodsummary::find()->select(['productcode','productname','qty','rate','amount'])->where(['prfinid' => $id]), 
      'pagination' => [ 
      'pageSize' => 20, 
       ], 
     ]); 
     $posts = $dataProvider->getModels(); 
     $content = $this->renderPartial('_printInvoice', [ 
      'model' => $model, 
      'dataProvider' => $dataProvider, 
      'searchModel' => $searchModel, 
      'data'=> $data, 

      ]); 
     $pdf = new Pdf([ 
      'mode'=> Pdf::MODE_UTF8, 
      'format'=> Pdf::FORMAT_A4, 
      'destination'=> Pdf::DEST_BROWSER, 
      //'destination' => Pdf::DEST_DOWNLOAD, 
      'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
      // any css to be embedded if required 
      'cssInline' => '.kv-heading-1{font-size:18px}', 
      // set mPDF properties on the fly 
      'options' => ['title' => 'Print Invoice'], 
      // call mPDF methods on the fly 
      'methods' => [ 
       'SetHeader'=>['Private and Confidential'], 
       'SetFooter'=>['This Payslip is computer generated.'], 
      ], 
      'content' => $content, 

     ]); 
     return $pdf->render(); 
     //return $this->render('_printSalarystatement', ['s_period' => $s_period]); 

    } 

Mein view.php (partialview)

<?php 

use yii\helpers\Html; 
use yii\widgets\DetailView; 

/* @var $this yii\web\View */ 
/* @var $model frontend\modules\printinvoice\models\Prodfin */ 

$this->title = $model->prfinslno; 
$this->params['breadcrumbs'][] = ['label' => 'Prodfins', 'url' => ['index']]; 
$this->params['breadcrumbs'][] = $this->title; 
?> 
<div class="ps-details"> 
    <div style="width:38%; float:left;border:1px solid black;"> 
      <h3 style="margin-bottom:0;margin-bottom:0;margin-top:2;margin-left:2;"><strong><p class="text-left">M/S. My Company</p></strong></h3> 
      <h5 style="margin-bottom:0;margin-top:0;margin-left:2;"><p class="text-left">My details</p></h5> 
      <h5 style="margin-bottom:0;margin-top:0;margin-left:2;"><p class="text-left">My Address</p></h5> 
    </div> 
     <div style="width:61.25%; float:right;border:1px solid black;"> 
      <table style="width:100%"> 
      <tr> 
       <td>PAN No.</td> 
       <td>AGZPD/2365A</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
      </tr> 
      <tr> 
       <td>Invoice No.</td> 
       <td><?php echo $model['invoiceno'];?></td> 
       <td>Date : </td> 
       <td><?php echo $model['date'];?></td> 
      </tr> 
      <tr> 
       <td>Challan No.</td> 
       <td><?php echo $model['challanno'];?></td> 
       <td>Date : </td> 
       <td><?php echo $model['date'];?></td> 
      </tr> 
      <tr> 
       <td>Order No.</td> 
       <td><?php echo $model['orderno'];?></td> 
       <td>Date : </td> 
       <td><?php echo $model['date'];?></td> 
      </tr> 
     </table> 
     </div> 
</div> 
<div class="orient-details"> 
    <div style="width:100%; float:center;border:1px solid black;"> 
      <h3 style="margin-bottom:0;margin-top:2;margin-left:2;"><strong><p class="text-center">My Company</p></strong></h3> 
      <h5 style="margin-bottom:0;margin-top:0;margin-left:2;"><p class="text-center">A Division of My Company</p></h5> 
      <h5 style="margin-bottom:0;margin-top:0;margin-left:2;"><p class="text-center">My Address</p></h5> 
    </div> 
</div> 
<div class="product-details"> 
    <?= DetailView::widget([ 
    'model' => $model, 
    'attributes' => [ 
     //'id', 
     'productcode', 
     'productname', 
     'qty', 
     'rate', 
     'amount:ntext' 
     //'ativo', 
    ], 
]) ?> 
</div> 
<div class="prodfin-view"> 

    <!-- <h1><?= Html::encode($this->title) ?></h1> --> 


<!-- <strong>Using display: inline-block; </strong><br> 
    <table style="border:1px solid black;border-collapse:collapse;width:100%" class="inlineTable"> 
     <tr> 
      <td style="border-right: 1px solid";><font face="Calibri";size="72">M/S P.S. Enterprise</font></td> 
      <td>This One will contain the Invoice details</td> 
     </tr> 
    </table> --> 
    <?= DetailView::widget([ 
     'model' => $model, 
     'attributes' => [ 
      'prfinslno', 
      'invoiceno', 
      'challanno', 
      'orderno', 
      'amount', 
      'date', 
     ], 
    ]) ?> 

</div> 

Bitte lassen Sie mich wissen, wie um die Gridview mit den Details in der Mitte im Bild zu setzen.

Modell Prodfin -

<?php 

namespace frontend\modules\printinvoice\models; 

use Yii; 

/** 
* This is the model class for table "prodfin". 
* 
* @property string $prfinslno 
* @property string $invoiceno 
* @property string $challanno 
* @property string $orderno 
* @property string $amount 
* @property string $date 
*/ 
class Prodfin extends \yii\db\ActiveRecord 
{ 
    /** 
    * @inheritdoc 
    */ 
    public static function tableName() 
    { 
     return 'prodfin'; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['date'], 'safe'], 
      [['invoiceno', 'challanno', 'orderno', 'amount'], 'string', 'max' => 40], 
     ]; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function attributeLabels() 
    { 
     return [ 
      'prfinslno' => 'Prfinslno', 
      'invoiceno' => 'Invoiceno', 
      'challanno' => 'Challanno', 
      'orderno' => 'Orderno', 
      'amount' => 'Amount', 
      'date' => 'Date', 
     ]; 
    } 
} 

Modell Prodsummary

<?php 

namespace frontend\modules\printinvoice\models; 

use Yii; 

/** 
* This is the model class for table "prodsummary". 
* 
* @property string $prid 
* @property string $productiondate 
* @property string $invoiceno 
* @property string $challanno 
* @property string $orderno 
* @property string $productcode 
* @property string $productname 
* @property string $unit 
* @property string $qty 
* @property string $rate 
* @property string $amount 
*/ 
class Prodsummary extends \yii\db\ActiveRecord 
{ 
    /** 
    * @inheritdoc 
    */ 
    public static function tableName() 
    { 
     return 'prodsummary'; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function rules() 
    { 
     return [ 
      [['productiondate'], 'safe'], 
      [['invoiceno', 'challanno', 'orderno'], 'string', 'max' => 40], 
      [['productcode', 'amount'], 'string', 'max' => 15], 
      [['productname'], 'string', 'max' => 80], 
      [['unit', 'qty', 'rate'], 'string', 'max' => 10], 
     ]; 
    } 

    /** 
    * @inheritdoc 
    */ 
    public function attributeLabels() 
    { 
     return [ 
      'prid' => 'Prid', 
      'productiondate' => 'Productiondate', 
      'invoiceno' => 'Invoiceno', 
      'challanno' => 'Challanno', 
      'orderno' => 'Orderno', 
      'productcode' => 'Productcode', 
      'productname' => 'Productname', 
      'unit' => 'Unit', 
      'qty' => 'Qty', 
      'rate' => 'Rate', 
      'amount' => 'Amount', 
     ]; 
    } 
} 

Antwort

0

Sie erhalten die Productdatenprovider auf Basis von Prodsummary

$dataProvider = new ActiveDataProvider([ 
     'query' => Prodsummary::find()->select(['productcode','productname','qty','rate','amount'])->where(['prfinid' => $id]), 
.. 

aber Sie verwenden das Feld Productcode in einer Detailansicht ein mit $ model .. das $ model var enthält nicht die Klasse Prodsummary sondern scheint fr zu kommen $model = $this->findModel($id); om

<div class="product-details"> 
    <?= DetailView::widget([ 
    'model' => $model, 
    'attributes' => [ 
     //'id', 
     'productcode', 
     'productname', 
     'qty', 
     'rate', 
     'amount:ntext' 
     //'ativo', 
    ], 
]) ?> 
</div> 

so sollten Sie den richtigen Wert für das Detail passieren

Sie den te Blick auf Prodsummary die $ datProvider Zusammenhang bestanden haben. Ein Datenprovider gibt eine Sammlung von Modellen zurück, aber Sie möchten diese Daten in einem Widget verwenden, das nur ein einzelnes Modell anzeigt. Also, wenn Sie nur das erste Modell der Datenprovider zeigen wollen shoudl Sie

<div class="product-details"> 
    <?= DetailView::widget([ 
    'model' => $dataProvider[0], 
    'attributes' => [ 
     //'id', 
     'productcode', 
     'productname', 
     'qty', 
     'rate', 
     'amount:ntext' 
     //'ativo', 
    ], 
]) ?> 
</div> 

verwenden, wenn Sie alle Modelle in Datenanbieter stattdessen zeigen wollen, sollten dann eine Iteration

foreach ($dataProvider as $key => $model) { 

    echo DetailView::widget([ 
    'model' => $model, 
    'attributes' => [ 
     //'id', 
     'productcode', 
     'productname', 
     'qty', 
     'rate', 
     'amount:ntext' 
     //'ativo', 
     ], 
    ]) ; 
} 
+0

Ja verwenden. Ich bin nicht so sicher, wie es geht. Kannst du es bitte erzählen? – Tanmay

+0

Ja, natürlich, aber ich sage dir später, zuerst solltest du meine persönliche Neugier ablegen. Warum Probleme ziemlich komplex angehen und artikulieren mit einer Kenntnis des Rahmens yii2 (meiner Meinung nach) ziemlich bescheiden .. es scheint, dass Sie sehr wenig wissen den Code, der in Ihren Fragen geschrieben .. Ich möchte diese Dinge wissen .. – scaisEdge

Verwandte Themen