Các bước thực hiện lần lượt như sau:
1. Thêm quyền
Vào menu Maintenance-> Roles. Thêm dòng sau vào Role mà bạn muốn cho xem báo cáo mà bạn sắp tạo ra:
<class name="/com/openbravo/reports/customerslist.bs"/>
File customerslist.bs làm gì thì tôi đã giới thiệu trong bài viết trước nên tôi không giải thích lại.
2. Thêm tên report vào danh sách menu hệ thống:
Chon menu Maintenance -> Resources.Thêm dòng sau vào Menu.Root, bên dưới phần
submenu.addTitle("Menu.Customers.Reports");
submenu.addPanel("/com/openbravo/images/appointment.png", "Menu.CustomerslistReport", "/com/openbravo/reports/customerslist.bs");
3. Thêm tên Report vào file pos_messages.properties:
Phần này để tạo tên trong nhiều gói ngôn ngữ khác nhau
Menu.CustomerslistReport=Danh sách khách hàng
4. Tạo file customerslist.bs:
Tạo file customerslist.bs có nội dung như sau và lưu vào thư mục reports/com/openbravo/reports
report = new com.openbravo.pos.reports.PanelReportBean(); report.setTitleKey("Menu.CustomerslistReport"); report.setReport("/com/openbravo/reports/customerslist"); report.setResourceBundle("com/openbravo/reports/customerslist_messages"); report.setSentence("SELECT ID, TAXID, NAME, EMAIL, PHONE, CARD, MAXDEBT, CURDATE, CURDEBT " + "FROM CUSTOMERS " + "WHERE VISIBLE = " + app.getSession().DB.TRUE() + " AND ?(QBF_FILTER)" +" order by taxid"); report.addParameter("ID"); report.addParameter("NAME"); report.addQBFFilter(new com.openbravo.pos.reports.JParamsCustomer()); report.addField("ID", com.openbravo.data.loader.Datas.STRING); report.addField("TAXID", com.openbravo.data.loader.Datas.STRING); report.addField("NAME", com.openbravo.data.loader.Datas.STRING); report.addField("EMAIL", com.openbravo.data.loader.Datas.STRING); report.addField("PHONE", com.openbravo.data.loader.Datas.STRING); report.addField("CARD", com.openbravo.data.loader.Datas.STRING); report.addField("MAXDEBT", com.openbravo.data.loader.Datas.DOUBLE); report.addField("CURDATE", com.openbravo.data.loader.Datas.TIMESTAMP); report.addField("CURDEBT", com.openbravo.data.loader.Datas.DOUBLE); report;
5. Tạo file customerslist_messages.properties:
Bạn tạo file customerslist_messages.properties có nội dung như sau và lưu vào thư mục reports/com/openbravo/reports:
label.title=Customerslist
label.maxdebt=Max debt
label.curdebt=Debt current
label.curdate=Debt date
label.taxid=Tax ID
6. Tạo file customerslist.jrxml:
Bạn tạo file customerslist.jrxml có nội dung như sau và lưu vào thư mục reports/com/openbravo/reports của thư mục cài đặt OB POS
Cái này bạn nên dùng phần mềm Jreport mà tôi giới thiệu ở bài trước!
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="customers" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<property name="ireport.zoom" value="2.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<queryString>
<![CDATA[SELECT
ID,
NAME,
CARD,
MAXDEBT,
CURDATE,
CURDEBT,
EMAIL,
PHONE,
TAXID
FROM
`CUSTOMERS` CUSTOMERS
WHERE
VISIBLE = TRUE
AND CARD IS NOT NULL
AND null > '']]>
</queryString>
<field name="ID" class="java.lang.String"/>
<field name="NAME" class="java.lang.String"/>
<field name="CARD" class="java.lang.String"/>
<field name="MAXDEBT" class="java.lang.Double"/>
<field name="CURDATE" class="java.sql.Timestamp"/>
<field name="CURDEBT" class="java.lang.Double"/>
<field name="EMAIL" class="java.lang.String"/>
<field name="PHONE" class="java.lang.String"/>
<field name="TAXID" class="java.lang.String"/>
<background>
<band/>
</background>
<title>
<band height="72">
<frame>
<reportElement mode="Opaque" x="0" y="-20" width="535" height="92" backcolor="#FFFFFF"/>
<image scaleImage="FillFrame">
<reportElement x="0" y="0" width="534" height="92"/>
<imageExpression class="java.awt.Image"><![CDATA[com.openbravo.data.loader.ImageUtils.readImageFromResource("/com/openbravo/images/banner Report.gif")]]></imageExpression>
</image>
<staticText>
<reportElement mode="Transparent" x="7" y="8" width="223" height="20" forecolor="#0066FF"/>
<textElement>
<font size="13" isBold="true" isItalic="false" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[Công ty cổ phần tin học Lạc Việt]]></text>
</staticText>
<line>
<reportElement x="33" y="28" width="128" height="1" forecolor="#FFFF33"/>
</line>
<staticText>
<reportElement x="13" y="40" width="383" height="43" forecolor="#FF6600"/>
<textElement>
<font fontName="SansSerif" size="34" isBold="true"/>
</textElement>
<text><![CDATA[Danh sách khách hàng]]></text>
</staticText>
</frame>
</band>
</title>
<pageHeader>
<band height="13"/>
</pageHeader>
<columnHeader>
<band height="21">
<line>
<reportElement x="0" y="20" width="535" height="1" forecolor="#666666"/>
</line>
<staticText>
<reportElement mode="Opaque" x="1" y="0" width="101" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Họ và tên]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="103" y="0" width="69" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Thẻ]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="174" y="0" width="104" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Email]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="279" y="0" width="56" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Điện thoại]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="335" y="0" width="61" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Nợ tối đa]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="397" y="0" width="58" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Còn nợ]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="456" y="0" width="79" height="20" forecolor="#006699" backcolor="#E6E6E6"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<text><![CDATA[Ngày nợ]]></text>
</staticText>
<line>
<reportElement x="-1" y="0" width="535" height="1" forecolor="#666666"/>
</line>
</band>
</columnHeader>
<detail>
<band height="20">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="19" width="535" height="1"/>
<graphicElement>
<pen lineStyle="Dotted"/>
</graphicElement>
</line>
<textField isStretchWithOverflow="true">
<reportElement x="103" y="0" width="69" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{CARD}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="279" y="0" width="55" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{PHONE}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="102" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="335" y="0" width="61" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[com.openbravo.format.Formats.CURRENCY.formatValue($F{MAXDEBT})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="397" y="0" width="58" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[com.openbravo.format.Formats.CURRENCY.formatValue($F{CURDEBT})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="456" y="0" width="78" height="19"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[com.openbravo.format.Formats.CURRENCY.formatValue($F{CURDATE})]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="174" y="0" width="104" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{EMAIL}]]></textFieldExpression>
</textField>
<line>
<reportElement x="172" y="-21" width="1" height="39"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="278" y="-21" width="1" height="39"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="334" y="-21" width="1" height="39"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="396" y="-21" width="1" height="40"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="534" y="-21" width="1" height="40"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="-1" y="-21" width="1" height="41"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="455" y="-21" width="1" height="39"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<line>
<reportElement x="102" y="-21" width="1" height="40"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="17">
<textField>
<reportElement mode="Opaque" x="0" y="4" width="494" height="13" backcolor="#0099CC"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA["Trang "+$V{PAGE_NUMBER}+" / Tổng"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="494" y="4" width="40" height="13" backcolor="#0099CC"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="4" width="100" height="13"/>
<textElement/>
<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
Còn đây là hình ảnh một báo cáo danh sách khách hàng mà mình vừa design (bổ sung thêm phần Số thứ tự thay cho mã khách hàng):
Bây giờ quá trình tạo mới report đã hoàn thành! Chúc các bạn thành công!
-----------------------------------------------------------------------------
Mọi thắc mắc xin để lại comment hoặc gửi tới ncm2312@gmail.com
0 Nhận xét:
Đăng nhận xét
Rất mong các ý kiến của các bạn khi đọc bài viết này !