yii2で請求書を印刷しようとしています。私は2つのテーブルに触れている2つのテーブルがあります。 1つはprodfinで、合計金額は保管され、製品と数量が保管される場所はprodsummaryです。今私はこれらを私の視点に渡し、mpdfを使ってpdfにプリントしたいと思います。私はプライマリモデルとしてprodfinを使用しており、prodummaryデータを添付しています。私の主な障害は、製品コード、製品名、数量、レート、金額を列ごとに所定の場所に渡すことです。私はこれでサンプルを添付しています。不明なプロパティを取得する:frontend modules printinvoice models Prodfin :: productcode
私は何を達成しようとしている -
私のコントローラのアクション
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]);
}
マイ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> </td>
<td> </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>
ことは私はどのようにお聞かせください真ん中の図の細かいところでグリッドビューを設定します。
モデル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',
];
}
}
モデル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',
];
}
}
を使用する必要があり、データプロバイダ内のすべてのモデルを表示したい場合 ですから、
を使用shoudlはい。私はそれをどうやって行うのかは分かりません。あなたは教えていただけますか? – Tanmay
もちろん、私はあなたに私の個人的な好奇心を取り除くべきです。なぜ複雑な問題に取り組んで、フレームワークの知識があるのか(私の意見では)かなり控えめなのです...あなたの質問に投稿されたコードはほんとうに分かっているようです。これらのことを知りたいのですが.. – scaisEdge