给 SuiteCRM 其他模块添加 PDF 打印功能

功能实现:创建了一个用于记录内部生产问题的模块。SuiteCRM 有一个内置Case模块,可以轻松地在模块构建器中创建该模块的版本。作为其中的一部分,我们需要一种临时打印 PDF 的方法,把Case模块的数据生成一份PDF。

在你开始之前…

将所有 [CUSTOM MODULE NAME] 替换为您的模块名称,将 [PACKAGE NAME] 替换为您的包名称。所有文件都应归 www-data 所有,为此,请在您创建的所有新文件上运行“chown www-data:www-data”。

配置用于打印 PDF 的模块。

1. 将目录更改为自定义模块目录

 /var/www/html/suitecrm/custom/modulebuilder/packages/[PACKAGE NAME]/modules/[CUSTOM MODULE NAME] 

2. 在metadata/detailviewdefs.php中添加以下行

4 => array ( 'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');" value="{$MOD.LBL_PRINT_AS_PDF}">')
below

        'buttons' =>

        array (

          0 => 'EDIT',

          1 => 'DUPLICATE',

          2 => 'DELETE',

          3 => 'FIND_DUPLICATES',

3. 在 vi​​m language/en_us.lang.php 中确保该行

'LBL_PRINT_AS_PDF' => 'Print as PDF',

4.在模块目录下制作目录视图

mkdir views 
chown www-data:www-data views

5.在views/view.detail.php中添加以下代码

<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');


require_once('include/MVC/View/views/view.detail.php');


class remed_RemedialsViewDetail extends ViewDetail {

        function __construct(){

                parent::__construct();

        }


    /**

     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead

     */

    function remed_RemedialsViewDetail(){

        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';

        if(isset($GLOBALS['log'])) {

            $GLOBALS['log']->deprecated($deprecatedMessage);

        }

        else {

            trigger_error($deprecatedMessage, E_USER_DEPRECATED);

        }

        self::__construct();

    }



        function display(){


                if(empty($this->bean->id)){

                        global $app_strings;

                        sugar_die($app_strings['ERROR_NO_RECORD']);

                }

              require_once('modules/AOS_PDF_Templates/formLetter.php');

              formLetter::DVPopupHtml('remed_Remedials');


              $this->dv->process();


                if(ACLController::checkAccess('Contacts', 'edit', true)) {

                        $push_billing = $this->generatePushCode('billing');

                        $push_shipping = $this->generatePushCode('shipping');

                } else {

                        $push_billing = '';

                        $push_shipping = '';

                }

                $this->ss->assign("custom_code_billing", $push_billing);

                $this->ss->assign("custom_code_shipping", $push_shipping);


        if(empty($this->bean->id)){

                        global $app_strings;

                        sugar_die($app_strings['ERROR_NO_RECORD']);

                }

                echo $this->dv->display();

        }

 

        function generatePushCode($param)

        {

            global $mod_strings;

            $address_fields = array('street', 'city', 'state', 'postalcode','country');

 

    //        $html = '<input class="button" title="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_LABEL'] .

                     '" type="button" onclick=\'open_contact_popup("Contacts", 600, 600, "&account_name=' .

                     $this->bean->name . '&html=change_address';

 

            foreach ($address_fields as $value) {

                $field_name = $param.'_address_'.$value;

     //           $html .= '&primary_address_'.$value.'='.str_replace(array("\rn", "\r", "\n"), array('','','<br>'), urlencode($this->bean->$field_name)) ;

            }

 

          //  $html .= '", true, false);\' value="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_TITLE']. '">';

          //  return $html;

        }

}


<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

 

require_once('include/MVC/View/views/view.detail.php');

 

class remed_RemedialsViewDetail extends ViewDetail {

 

        function __construct(){

                parent::__construct();

        }


    /**

     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead

     */

    function remed_RemedialsViewDetail(){

        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';

        if(isset($GLOBALS['log'])) {

            $GLOBALS['log']->deprecated($deprecatedMessage);

        }

        else {

            trigger_error($deprecatedMessage, E_USER_DEPRECATED);

        }

        self::__construct();

    }



        function display(){


                if(empty($this->bean->id)){

                        global $app_strings;

                        sugar_die($app_strings['ERROR_NO_RECORD']);

                }

 

              require_once('modules/AOS_PDF_Templates/formLetter.php');

              formLetter::DVPopupHtml('remed_Remedials');


              $this->dv->process();


                if(ACLController::checkAccess('Contacts', 'edit', true)) {

                        $push_billing = $this->generatePushCode('billing');

                        $push_shipping = $this->generatePushCode('shipping');

                } else {

                        $push_billing = '';

                        $push_shipping = '';

                }


                $this->ss->assign("custom_code_billing", $push_billing);

                $this->ss->assign("custom_code_shipping", $push_shipping);


        if(empty($this->bean->id)){

                        global $app_strings;

                        sugar_die($app_strings['ERROR_NO_RECORD']);

                }

                echo $this->dv->display();

        }

 

        function generatePushCode($param)

        {

            global $mod_strings;

            $address_fields = array('street', 'city', 'state', 'postalcode','country');

 

    //        $html = '<input class="button" title="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_LABEL'] .

                     '" type="button" onclick=\'open_contact_popup("Contacts", 600, 600, "&account_name=' .

                     $this->bean->name . '&html=change_address';

 

            foreach ($address_fields as $value) {

                $field_name = $param.'_address_'.$value;

     //           $html .= '&primary_address_'.$value.'='.str_replace(array("\rn", "\r", "\n"), array('','','<br>'), urlencode($this->bean->$field_name)) ;

            }

 

          //  $html .= '", true, false);\' value="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_TITLE']. '">';

          //  return $html;

        }

}

配置用于打印批量 PDF 的模块

按照前面步骤中的步骤 1、3 和 4 在模块中创建单个 PDF 函数。

1. 使用以下内容创建一个views.list.php

require_once('include/MVC/View/views/view.list.php');

require_once('modules/[CUSTOM MODULE NAME]/[CUSTOM MODULE NAME]ListViewSmarty.php');

 

class [CUSTOM MODULE NAME]ViewList extends ViewList

{

    /**

     * @see ViewList::preDisplay()

     */

    public function preDisplay(){

        require_once('modules/AOS_PDF_Templates/formLetter.php');

        formLetter::LVPopupHtml('[CUSTOM MODULE NAME]');

        parent::preDisplay();

 

        $this->lv = new [CUSTOM MODULE NAME]ListViewSmarty();

    }

}

2. 使用以下内容创建 [modulename]ListViewSmarty.php

require_once('include/ListView/ListViewSmarty.php');

require_once('modules/AOS_PDF_Templates/formLetter.php');

 

 

class [CUSTOM MODULE NAME]ListViewSmarty extends ListViewSmarty {

 

        function __construct(){

 

                parent::__construct();

                $this->targetList = true;

 

        }

 

    /**

     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead

     */

    function [CUSTOM MODULE NAME]ListViewSmarty(){

        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';

        if(isset($GLOBALS['log'])) {

            $GLOBALS['log']->deprecated($deprecatedMessage);

        }

        else {

            trigger_error($deprecatedMessage, E_USER_DEPRECATED);

        }

        self::__construct();

    }

 

 

    /**

     *

     * @param file $file Template file to use

     * @param array $data from ListViewData

     * @param string $htmlVar the corresponding html public in xtpl per row

     * @return bool|void

     */

    public function process($file, $data, $htmlVar)

    {

        $configurator = new Configurator();

        if ($configurator->isConfirmOptInEnabled()) {

            $this->actionsMenuExtraItems[] = $this->buildSendConfirmOptInEmailToPersonAndCompany();

        }

 

        $ret = parent::process($file, $data, $htmlVar);

 

        if (!ACLController::checkAccess($this->seed->module_dir, 'export', true) || !$this->export) {

            $this->ss->assign('exportLink', $this->buildExportLink());

        }

 

        return $ret;

    }

 

    function buildExportLink($id = 'export_link'){

                global $app_strings;

                global $sugar_config;

 

                $script = "";

                if(ACLController::checkAccess($this->seed->module_dir,'export',true)) {

                        if($this->export) {

                                $script = parent::buildExportLink($id);

                        }

                }

 

            $script .= "

                    " onclick=\"return sListView.send_form(true, 'jjwg_Maps', " .

                    "'index.php?entryPoint=jjwg_Maps&display_module={$_REQUEST['module']}', " .

                    "'{$app_strings['LBL_LISTVIEW_NO_SELECTED']}')\">{$app_strings['LBL_MAP']}";

 

                return formLetter::LVSmarty().$script;

        }

 

}

创建 PDF 模板

从这里,您需要将模块添加到下拉列表“pdf_template_type_dom”中,并在“PDF – 模板”中创建模板。

补充:

As with the single version you have to go to your module path

/var/www/html/suitecrm/custom/modulebuilder/packages/[PACKAGE NAME]/modules/[CUSTOM MODULE NAME]

Also, before you begin…

Replace all [CUSTOM MODULE NAME] with your module name and [PACKAGE NAME] with your package name. All files should be owned by www-data, to do this run ‘chown www-data:www-data’ on any and all new files you create.

1. Create a views.list.php with the following

lv = new [CUSTOM MODULE NAME]ListViewSmarty();
    }
}

2. Create a [modulename]ListViewSmarty.php with the following

targetList = true;

        }

    /**
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
     */
    function [CUSTOM MODULE NAME]ListViewSmarty(){
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
        if(isset($GLOBALS['log'])) {
            $GLOBALS['log']->deprecated($deprecatedMessage);
        }
        else {
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
        }
        self::__construct();
    }


    /**
     *
     * @param file $file Template file to use
     * @param array $data from ListViewData
     * @param string $htmlVar the corresponding html public in xtpl per row
     * @return bool|void
     */
    public function process($file, $data, $htmlVar)
    {
        $configurator = new Configurator();
        if ($configurator->isConfirmOptInEnabled()) {
            $this->actionsMenuExtraItems[] = $this->buildSendConfirmOptInEmailToPersonAndCompany();
        }

        $ret = parent::process($file, $data, $htmlVar);

        if (!ACLController::checkAccess($this->seed->module_dir, 'export', true) || !$this->export) {
            $this->ss->assign('exportLink', $this->buildExportLink());
        }

        return $ret;
    }

    function buildExportLink($id = 'export_link'){
                global $app_strings;
                global $sugar_config;

                $script = "";
                if(ACLController::checkAccess($this->seed->module_dir,'export',true)) {
                        if($this->export) {
                                $script = parent::buildExportLink($id);
                        }
                }

            $script .= "{$app_strings['LBL_MAP']}";

                return formLetter::LVSmarty().$script;
        }

}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

滚动至顶部