Your IP : 216.73.216.124


Current Path : /var/www/html/crm/controllers/
Upload File :
Current File : /var/www/html/crm/controllers/DeliveryorderController.php

<?php

namespace app\controllers;

use Yii;
use app\models\DeliveryOrder;
use app\models\DeliveryOrderSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use yii\helpers\Url;
use app\models\Log;
use app\models\LogSearch;
use app\models\Customer;
use app\models\Company;
use app\models\ParamList;
use kartik\mpdf\Pdf;
use app\models\User;
use app\models\Notes;
use app\models\DeliveryOrderItem;
use app\models\Product;
use app\models\StockLog;
use yii\web\UploadedFile;
use app\models\StockDelivery;

/**
 * DeliveryorderController implements the CRUD actions for DeliveryOrder model.
 */
class DeliveryorderController extends Controller {

    public $menu_id = 45;

    /**
     * {@inheritdoc}
     */
    public function behaviors() {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
            'access' => [
                'class' => \yii\filters\AccessControl::className(),
                'only' => ['index', 'create', 'update', 'view'],
                'rules' => [
                    // allow authenticated users
                    [
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                // everything else is denied
                ],
            ],
        ];
    }

    /**
     * Lists all DeliveryOrder models.
     * @return mixed
     */
    public function actionIndex() {
        $searchModel = new DeliveryOrderSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'menu_id' => $this->menu_id]);
    }

    public function actionLog($uuid) {
        $searchModel = new LogSearch();
        $searchModel->menu_id = $this->menu_id;
        $searchModel->data_uuid = $uuid;
        $dataProvider = $searchModel->log(Yii::$app->request->queryParams);
        return $this->render('log', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'menu_id' => $this->menu_id]);
    }

    /**
     * Displays a single DeliveryOrder model.
     * @param integer $id
     * @param string $uuid
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id, $uuid) {
        return $this->render('view', [
                    'model' => $this->findModel($id, $uuid),
        ]);
    }

    /**
     * Creates a new DeliveryOrder model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate() {
        $Company = new Company();
        $model = new DeliveryOrder();
        $model->doc_dt = date("Y-m-d");
        $model->created_dt = date("Y-m-d H:i:s");
        $model->created_by = Yii::$app->user->identity->id;
        $model->updated_dt = date("Y-m-d H:i:s");
        $model->updated_by = Yii::$app->user->identity->id;
        $model->uuid = Uuid::uuid4();
        $model->status = 'Draft';
        if ($model->load(Yii::$app->request->post())) {
            $countdoc = (int) DeliveryOrder::find()->where(['company_id' => $model->company_id])->count() + 1;
            $model->doc_no = $Company->getshortcode($model->company_id) . '/DO/' . date("y") . '/' . sprintf("%05d", $countdoc);
            if ($model->save()) {
                $Log = new Log();
                $Log->insertlog($this->menu_id, 'create', $model->uuid);
                $this->getView()->registerJs("swal.fire({position: 'center-center',type: 'success',title: 'Data has been saved',showConfirmButton: false,timer: 1500,}).then(function(result){window.location = 'index.php?r=deliveryorder/update&uuid=$model->uuid';});");
            }
        }
        return $this->render('create', ['model' => $model, 'menu_id' => $this->menu_id]);
    }

    /**
     * Updates an existing DeliveryOrder model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @param string $uuid
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($uuid) {
        $model = $this->findModel($uuid);
        $original_status = $model->status;
        $model->updated_dt = date("Y-m-d H:i:s");
        $model->updated_by = Yii::$app->user->identity->id;
        if ($model->load(Yii::$app->request->post())) {
            if (!empty($_POST['item_id']) && $original_status == 'Draft') {
                $model->status = 'In-Transit';
            } else if (empty($_POST['item_id']) && $original_status == 'In-Transit') {
                $model->status = 'Draft';
            }
            if ($model->save()) {
                if (!empty($_POST['item_id'])) {
                    $item_arr = $_POST['item_id'];
                    foreach ($item_arr as $item_id) {
                        if (($modelItem = DeliveryOrderItem::findOne($item_id)) !== null) {
                            $modelItem->uom = $_POST['item_uom_' . $item_id];
                            $modelItem->quantity = $_POST['item_quantity_' . $item_id];
                            $modelItem->unit_price = $_POST['item_unitprice_' . $item_id];
                            $modelItem->discount = $_POST['item_discount_' . $item_id];
                            $modelItem->total = $_POST['item_total_' . $item_id];
                            $modelItem->remarks = $_POST['item_remarks_' . $item_id];
                            $modelItem->owner_type = 'company';
                            $owner_id = '';
                            if ($modelItem->owner_type == 'company')
                                $owner_id = $model->company_id;
                            if ($modelItem->owner_type == 'vendor') {
                                $Product = new Product();
                                $owner_id = $Product->getvendor($modelItem->product_id);
                            }
                            $modelItem->owner_id = $owner_id;
                            if ($modelItem->save()) {
                                if (($modelStockLog = StockLog::findOne(['table_related' => 'delivery_order_item', 'data_id' => $modelItem->id, 'product_id' => $modelItem->product_id])) !== null) {
                                    $modelStockLog->owner_type = $modelItem->owner_type;
                                    $modelStockLog->owner_id = $modelItem->owner_id;
                                    $modelStockLog->save();
                                }
                            }
                        }
                    }
                }

                $Log = new Log();
                $Log->insertlog($this->menu_id, 'update', $model->uuid);
                $this->getView()->registerJs("swal.fire({position: 'center-center',type: 'success',title: 'Data has been saved',showConfirmButton: false,timer: 1500,}).then(function(result){window.location = 'index.php?r=deliveryorder/update&uuid=$model->uuid';});");
            }
        }
        return $this->render('update', ['model' => $model, 'menu_id' => $this->menu_id]);
    }

    public function actionUpload($uuid) {
        $model = $this->findModel($uuid);
        $model->scenario = 'upload';
        $model->updated_dt = date("Y-m-d H:i:s");
        $model->updated_by = Yii::$app->user->identity->id;
        if ($model->load(Yii::$app->request->post())) {
            $model->file = UploadedFile::getInstance($model, 'file');
            if (!empty($model->file)) {
                $file_name = date("YmdHis") . '.' . $model->file->extension;
                if ($model->file->saveAs('uploads/signed_do/' . $file_name)) {
                    $model->uploaded_file = $file_name;
                    $model->status = 'Consigned';
                }
            }
            if ($model->save()) {
                $Log = new Log();
                $Log->insertlog($this->menu_id, 'upload', $model->uuid);
                $this->getView()->registerJs("swal.fire({position: 'center-center',type: 'success',title: 'File has been uploaded',showConfirmButton: false,timer: 1500,}).then(function(result){window.location = 'index.php?r=deliveryorder/index';});");
            }
        }
        return $this->render('upload', ['model' => $model, 'menu_id' => $this->menu_id]);
    }

    /**
     * Deletes an existing DeliveryOrder model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @param string $uuid
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
//    public function actionDelete($id, $uuid) {
//        $this->findModel($id, $uuid)->delete();
//
//        return $this->redirect(['index']);
//    }

    /**
     * Finds the DeliveryOrder model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @param string $uuid
     * @return DeliveryOrder the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($uuid) {
        if (($model = DeliveryOrder::findOne(['uuid' => $uuid])) !== null) {
            return $model;
        }
        throw new NotFoundHttpException('The requested page does not exist.');
    }

    public function actionAddproduct() {
        $output = '';
        $Product = new Product();
        $ParamList = new ParamList();
        $StockLog = new StockLog();
        if (!empty($_POST['items'])) {
            foreach ($_POST['items'] as $item) {
                $model = new DeliveryOrderItem();
                $model->doc_id = $_POST['doc_id'];
                $model->product_id = $item;
                $model->uom = $ParamList->getlabel(9, $Product->getuom($model->product_id));
                $model->quantity = '0';
                $model->unit_price = $Product->getprice($model->product_id);
                $model->discount = '0';
                $model->total = '0';
                $model->created_dt = date("Y-m-d H:i:s");
                $model->created_by = Yii::$app->user->identity->id;
                $model->updated_dt = date("Y-m-d H:i:s");
                $model->updated_by = Yii::$app->user->identity->id;
                $model->owner_type = 'company';
                $model->owner_id = $Product->getvendor($model->product_id);

                if ($model->save()) {
                    $modelStockLog = new StockLog();
                    $modelStockLog->product_id = $model->product_id;
                    $modelStockLog->action_type = 'stockout';
                    $modelStockLog->table_related = 'delivery_order_item';
                    $modelStockLog->data_id = $model->id;
                    //$modelStockLog->company_id = $_POST['company_id'];
                    $modelStockLog->do_no = $StockLog->getdono($modelStockLog->table_related, $modelStockLog->data_id);
                    $modelStockLog->action_by = Yii::$app->user->identity->id;
                    $modelStockLog->action_datetime = date("Y-m-d H:i:s");
                    $modelStockLog->owner_type = $model->owner_type;
                    $modelStockLog->owner_id = $model->owner_id;

                    $modelStockLog->save();

                    $stock_owned_vendor = $StockLog->balancestockbyowner($model->product_id, 'vendor', $Product->getvendor($model->product_id));
                    $stock_owned_com = $StockLog->balancestockbyowner($model->product_id, 'company', $_POST['company_id']);
                    $stock_all = $stock_owned_vendor + $stock_owned_com;

                    $output .= '<tr id="rowItem_' . $model->id . '">
                        <td style="vertical-align:middle;">' . $Product->getsku($model->product_id) . '</td>
                        <td style="vertical-align:middle;">
                            <input type="hidden" value="' . $model->id . '" name="item_id[]">
                            ' . $Product->getname($model->product_id) . '
                        </td>
                        <td>
                            <input type="text" class="form-control" value="' . $model->quantity . '" name="item_quantity_' . $model->id . '" onchange="updatetotal(' . $model->id . ')">
                            <span class="kt-badge kt-badge--inline kt-badge--success mt-2 tooltip-stock" data-toggle="tooltip" data-placement="bottom" data-html="true" title="Vendor : ' . number_format($stock_owned_vendor) . '<br>Company : ' . number_format($stock_owned_com) . '">Current stock : ' . number_format($stock_all) . '</span>
                        </td>
                        <td><input type="text" class="form-control" value="' . $model->uom . '" name="item_uom_' . $model->id . '"></td>
                        <td><input type="text" class="form-control" value="' . $model->unit_price . '" name="item_unitprice_' . $model->id . '" onchange="updatetotal(' . $model->id . ')"></td>
                        <td><input type="text" class="form-control" value="' . $model->discount . '" name="item_discount_' . $model->id . '" onchange="updatetotal(' . $model->id . ')"></td>
                        <td><input type="text" class="form-control" value="' . $model->total . '" name="item_total_' . $model->id . '"></td>
                        <td><input type="text" class="form-control" value="' . $model->remarks . '" name="item_remarks_' . $model->id . '"></td>
                        <td align="center"><i class="fas fa-trash-alt kt-font-danger" style="cursor:pointer;" title="Delete product" onclick="deleteproduct(' . $model->id . ')"></i></td>
                    </tr>';
                }
            }
        }
        return $output;
    }

    public function actionGetproductlist() {
        $com_id = $_POST['com_id'];
        $doc_id = $_POST['doc_id'];
        $product_keyword = $_POST['product_keyword'];
        $output = '';
        $count = 0;
        $modelProduct = Product::find()->where(['com_id' => $com_id])->andwhere(['status' => 1])->andwhere(['like', 'name', $product_keyword])->orderBy(['name' => SORT_ASC])->all();
        if (!empty($modelProduct)) {
            $output .= '<div class="row">';
            foreach ($modelProduct as $rowProduct) {
                if (($modelItem = DeliveryOrderItem::findOne(['doc_id' => $doc_id, 'product_id' => $rowProduct->id])) == null) {
                    $count++;
                    $output .= '<div class="col-6">
                        <label class="kt-checkbox">
                            <input type="checkbox" value="' . $rowProduct->id . '" class="product_id">
                            ' . $rowProduct->name . '<label class="kt-badge kt-badge--inline kt-badge--dark ml-3">' . $rowProduct->sku . '</label>
                            <span></span>
                        </label>
                    </div>';
                }
            }
            $output .= '</div><div class="kt-font-bold kt-font-danger" id="error_message">Please select at least one (1) product</div>';
        }
        if ($count == 0)
            $output = 'All product has been added to the Debit Note or no product found under this company';
        return $output;
    }

    public function actionDeleteproduct() {
        $id = $_POST['id'];
        $status = 'failed';
        if (DeliveryOrderItem::findOne($id)->delete()) {
            if (StockLog::findOne(['action_type' => 'stockout', 'table_related' => 'delivery_order_item', 'data_id' => $id])->delete())
                $status = 'success';
        }
        return $status;
    }

    public function actionDelete() {
        $id = $_POST['id'];
        $status = 'failed';
        $model = DeliveryOrder::findOne($id);
        if (!empty($model)) {
            $model->deleted_status = 1;
            if ($model->save(false)) {
                $Log = new Log();
                $Log->insertlog($this->menu_id, 'delete', $model->uuid);
                $status = 'success';
            }
        }
        return $status;
    }

    public function actionDownload($uuid) {
        $ParamList = new ParamList();
        $User = new User();
        $Notes = new Notes();
        $model = $this->findModel($uuid);
        if (!empty($model)) {
            $modelcom = Company::findOne($model->company_id);
            if (!empty($modelcom)) {
                $header = '<table id="table-header" border="0" width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td><img src="uploads/' . $modelcom->logo . '" height="50"></td>
                        <td align="right"><b>' . strtoupper($modelcom->name) . '</b><br/>' . $modelcom->website . '</td>
                    </tr>
                </table>';
                $content = '<br><table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="50%" valign="top">
                                <br/><b>SHIP TO</b>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td valign="top">Company Name</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_name . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Address</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_address1 . ' ' . $model->customer_address2 . ' ' . $model->customer_postcode . ' ' . $model->customer_city . ' ' . $ParamList->getlabel(3, $model->customer_state) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact Person</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_pic . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact No</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_phone . '</td>
                                    </tr>
                                </table>
                            </td>
                            <td width="50%" valign="top" align="right">
                                <table cellpadding="0" cellspacing="0" style="padding-right:1em;">
                                    <tr><td colspan="3" align="center"><h4><b>DELIVERY ORDER</b></h4><br/><br/></td></tr>
                                    <tr>
                                        <td valign="top">Date</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . date("dS M Y", strtotime($model->doc_dt)) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">DO Number</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $model->doc_no . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Customer PO ref</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $model->po_ref . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Prepared by</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $User->getusername($model->created_by) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact No</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $User->getuserphone($model->created_by) . '</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table><br>';
                $content .= '<table width="100%" cellpadding="5" cellspacing="1" border="0" style="background-color:black;" id="table-product">
                        <thead>
                            <tr>
                                <th width="5%">No</th>
                                <th>SKU</th>
                                <th>Description</th>
                                <th width="10%">UoM</th>
                                <th width="10%">Qty</th>
                                <th>Remarks</th>
                            </tr>
                        </thead>
                        <tbody>';

                $modelItem = DeliveryOrderItem::find()->where(['doc_id' => $model->id])->orderBy(['id' => SORT_ASC])->all();
                $Product = new Product();
                if (!empty($modelItem)) {
                    $countItem = 0;
                    foreach ($modelItem as $rowItem) {
                        $countItem++;
                        $content .= '<tr>
                                <td align="center">' . $countItem . '</td>
                                <td>' . $Product->getsku($rowItem->product_id) . '</td>
                                <td>' . $Product->getname($rowItem->product_id) . '</td>
                                <td>' . $rowItem->uom . '</td>
                                <td>' . number_format($rowItem->quantity) . '</td>
                                <td>' . $rowItem->remarks . '</td>
                            </tr>';
                    }
                } else {
                    $content .= '<tr><td colspan="6">No record found</td></tr>';
                }

                $company_stamp = '<tr><td align="center" height="110"></td><td></td><td></td></tr>';
                if (!empty($modelcom->stamp))
                    $company_stamp = '<tr><td align="center"><img src="uploads/' . $modelcom->stamp . '" height="100"></td><td></td><td></td></tr>';

                $content .= '</tbody></table>';
                $content .= '<br><div style="font-size:8px;line-height:1.7em;">' . $Notes->getnotes('Deliveryorder', $modelcom->id) . '</div>
                    <table width="100%">
                        ' . $company_stamp . '
                        <tr>
                            <td align="center" style="border-top:1px solid black;" width="30%">Authorized Signature</td>
                            <td></td>
                            <td align="center" style="border-top:1px solid black;" width="30%">Customer Chop and sign</td>
                        </tr>
                    </table>';


                $footer = '<table id="table-footer" border="0" width="100%" cellpadding="0" cellspacing="0">
                    <tr><td align="center">' . $modelcom->address1 . ' ' .
                        $modelcom->address2 . ' ' .
                        $modelcom->postcode . ' ' .
                        $modelcom->city . ' ' . $ParamList->getlabel(3, $modelcom->state) . '
                        </td>
                    </tr>
                </table>';

                // setup kartik\mpdf\Pdf component
                $pdf = new Pdf([
                    'mode' => Pdf::MODE_CORE,
                    'filename' => 'Delivery Order (DO) ' . $model->doc_no . '.pdf',
                    'format' => Pdf::FORMAT_A4,
                    'orientation' => Pdf::ORIENT_PORTRAIT,
                    'destination' => Pdf::DEST_BROWSER,
                    'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
                    'cssInline' => 'body,table td{font-size:11px;Arial, Helvetica, sans-serif;line-height:1.7em;}
                        #table-header{padding-bottom:10px;}
                        #table-footer{padding-top:10px;}
                        #table-product th{background-color:black;color:white;text-align:center;}
                        #table-product tr:nth-child(odd) td{background-color:white;}
                        #table-product tr:nth-child(even) td{background-color:whitesmoke;}',
                    'methods' => ['SetHeader' => [$header], 'SetFooter' => $footer],
                    'content' => $content,
                    'options' => ['setAutoTopMargin' => 'stretch'],
                ]);
                return $pdf->render();
            }
        }
    }

    public function actionDownloadfromdelivery($uuid) {
        $ParamList = new ParamList();
        $User = new User();
        $Notes = new Notes();
        $model = $this->findModel($uuid);
        if (!empty($model)) {
            $modelcom = Company::findOne($model->company_id);
            if (!empty($modelcom)) {
                $header = '<table id="table-header" border="0" width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td><img src="uploads/' . $modelcom->logo . '" height="50"></td>
                        <td align="right"><b>' . strtoupper($modelcom->name) . '</b><br/>' . $modelcom->website . '</td>
                    </tr>
                </table>';
                $content = '<br><table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="50%" valign="top">
                                <br/><b>SHIP TO</b>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td valign="top">Company Name</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_name . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Address</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_address1 . ' ' . $model->customer_address2 . ' ' . $model->customer_postcode . ' ' . $model->customer_city . ' ' . $ParamList->getlabel(3, $model->customer_state) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact Person</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_pic . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact No</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top">' . $model->customer_phone . '</td>
                                    </tr>
                                </table>
                            </td>
                            <td width="50%" valign="top" align="right">
                                <table cellpadding="0" cellspacing="0" style="padding-right:1em;">
                                    <tr><td colspan="3" align="center"><h4><b>DELIVERY ORDER</b></h4><br/><br/></td></tr>
                                    <tr>
                                        <td valign="top">Date</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . date("dS M Y", strtotime($model->doc_dt)) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">DO Number</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $model->doc_no . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Customer PO ref</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $model->po_ref . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Prepared by</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $User->getusername($model->created_by) . '</td>
                                    </tr>
                                    <tr>
                                        <td valign="top">Contact No</td>
                                        <td valign="top">&nbsp;&nbsp;:&nbsp;&nbsp;</td>
                                        <td valign="top" align="left">' . $User->getuserphone($model->created_by) . '</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table><br>';
                $content .= '<table width="100%" cellpadding="5" cellspacing="1" border="0" style="background-color:black;" id="table-product">
                        <thead>
                            <tr>
                                <th width="5%">No</th>
                                <th>SKU</th>
                                <th>Description</th>
                                <th width="10%">UoM</th>
                                <th width="10%">Qty</th>
                                <th>Remarks</th>
                            </tr>
                        </thead>
                        <tbody>';

                $modelItem = DeliveryOrderItem::find()->where(['doc_id' => $model->id])->orderBy(['id' => SORT_ASC])->all();
                $Product = new Product();
                if (!empty($modelItem)) {
                    $countItem = 0;
                    foreach ($modelItem as $rowItem) {
                        $countItem++;
                        $content .= '<tr>
                                <td align="center">' . $countItem . '</td>
                                <td>' . $Product->getsku($rowItem->product_id) . '</td>
                                <td>' . $Product->getname($rowItem->product_id) . '</td>
                                <td>' . $rowItem->uom . '</td>
                                <td>' . number_format($rowItem->quantity) . '</td>
                                <td>' . $rowItem->remarks . '</td>
                            </tr>';
                    }
                } else {
                    $content .= '<tr><td colspan="6">No record found</td></tr>';
                }

                $company_stamp = '<tr><td align="center" height="110"></td><td></td><td></td></tr>';
                if (!empty($modelcom->stamp))
                    $company_stamp = '<tr><td align="center"><img src="uploads/' . $modelcom->stamp . '" height="100"></td><td></td><td></td></tr>';

                $content .= '</tbody></table>';
                $content .= '<br><div style="font-size:8px;line-height:1.7em;">' . $Notes->getnotes('Deliveryorder', $modelcom->id) . '</div>
                    <table width="100%">
                        ' . $company_stamp . '
                        <tr>
                            <td align="center" style="border-top:1px solid black;" width="30%">Authorized Signature</td>
                            <td></td>
                            <td align="center" style="border-top:1px solid black;" width="30%">Customer Chop and sign</td>
                        </tr>
                    </table>';


                if (($modeldelivery = StockDelivery::findOne(['do_id' => $model->id])) !== null) {
                    $url = Url::toRoute(['site/updateorder', 'uuid' => $modeldelivery->uuid], true);
                    $content .= '<br><br><br><div style="text-align:center;"><p>Note for rider : Please scan QR code below to update delivery status</p>'
                            . '<img src="https://chart.googleapis.com/chart?cht=qr&choe=UTF-8&chs=150x150&chl=' . urlencode($url) . '"/></div>';
                }


                $footer = '<table id="table-footer" border="0" width="100%" cellpadding="0" cellspacing="0">
                    <tr><td align="center">' . $modelcom->address1 . ' ' .
                        $modelcom->address2 . ' ' .
                        $modelcom->postcode . ' ' .
                        $modelcom->city . ' ' . $ParamList->getlabel(3, $modelcom->state) . '
                        </td>
                    </tr>
                </table>';

                // setup kartik\mpdf\Pdf component
                $pdf = new Pdf([
                    'mode' => Pdf::MODE_CORE,
                    'filename' => 'Delivery Order (DO) ' . $model->doc_no . '.pdf',
                    'format' => Pdf::FORMAT_A4,
                    'orientation' => Pdf::ORIENT_PORTRAIT,
                    'destination' => Pdf::DEST_BROWSER,
                    'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
                    'cssInline' => 'body,table td{font-size:11px;Arial, Helvetica, sans-serif;line-height:1.7em;}
                        #table-header{padding-bottom:10px;}
                        #table-footer{padding-top:10px;}
                        #table-product th{background-color:black;color:white;text-align:center;}
                        #table-product tr:nth-child(odd) td{background-color:white;}
                        #table-product tr:nth-child(even) td{background-color:whitesmoke;}',
                    'methods' => ['SetHeader' => [$header], 'SetFooter' => $footer],
                    'content' => $content,
                    'options' => ['setAutoTopMargin' => 'stretch'],
                ]);
                return $pdf->render();
            }
        }
    }

}