這範本主要是要介紹4gl 中如何使用java 的JAR . 來幫助我們快速產生電子發票交換資料.
,BDL,4gl,turnkey,A0101
需求 BDL 2.4 以上.(沒記錯應是 2.2以上就有支援JAVA了.
第一要先把環境設定好. CLASSPATH 要設.
以下就是產生 A0101 的程式範本.
###########################################################
#程式開始
###########################################################
IMPORT JAVA com.fourjs.fgl.lang.FglDecimal
IMPORT JAVA java.lang.Number
IMPORT JAVA java.lang.Long
#import java com.thoughtworks.xstream.annotations.XStreamAlias
#import JAVA com.thoughtworks.xstream.annotations.XStreamAsAttribute
import JAVA com.tradevan.gateway.client.einv.parse.ParserHelper
import JAVA com.tradevan.gateway.client.util.annotat.DataObjectAble
import JAVA com.tradevan.gateway.client.einv.transform.TransformHelper
import JAVA com.tradevan.gateway.client.einv.util.EINVVersion
#import JAVA com.tradevan.gateway.client.einv.parse.proc.LineParser
import JAVA com.tradevan.gateway.client.einv.parse.proc.Parser
#import JAVA com.tradevan.gateway.client.einv.parse.proc.XMLParser
#import JAVA com.tradevan.gateway.client.einv.util.EINVConfig
import JAVA com.tradevan.gateway.client.einv.util.EncodingType
#import JAVA com.tradevan.gateway.client.einv.util.InvoiceUtil
#import JAVA com.tradevan.gateway.client.log.GatewayLogger
import JAVA com.tradevan.gateway.client.log.GatewayLoggerHandler
import JAVA com.tradevan.gateway.einv.msg.EINVMessage
import JAVA com.tradevan.gateway.einv.msg.EINVPayload
#import JAVA com.tradevan.commons.io.FileUtil
import JAVA com.tradevan.gateway.client.einv.parse.ParserHelper
import JAVA com.tradevan.gateway.client.util.GatewayUtil
import JAVA com.tradevan.gateway.einv.msg.EINVPayload
import JAVA com.tradevan.gateway.einv.msg.v31.A0101
import JAVA com.tradevan.gateway.einv.msg.v31.A0101Body.AmountType
import JAVA com.tradevan.gateway.einv.msg.v31.A0101Body.DetailsType
import JAVA com.tradevan.gateway.einv.msg.v31.A0101Body.MainType
import JAVA com.tradevan.gateway.einv.msg.v31.A0101Body.ProductItem
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.BuyerRemarkEnum
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.CurrencyCodeEnum
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.CustomsClearanceMarkEnum
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.DonateMarkEnum
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.InvoiceTypeEnum
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.RoleDescriptionType
import JAVA com.tradevan.gateway.einv.msg.v31.UtilBody.TaxTypeEnum
import JAVA com.tradevan.gateway.client.einv.parse.ParserException
import JAVA java.io.Serializable
import JAVA java.io.BufferedReader
import JAVA java.io.File
import JAVA java.io.FileReader
import JAVA java.io.PrintStream
import JAVA java.io.BufferedReader
import JAVA java.io.File
import JAVA java.io.FileReader
import JAVA java.io.PrintStream
import JAVA java.lang.reflect.Method
import JAVA java.util.ArrayList
import JAVA java.util.Date
import JAVA java.util.List
import JAVA java.math.BigDecimal
DATABASE ds
Main
DEFINE j_a0101 com.tradevan.gateway.einv.msg.v31.A0101;
DEFINE j_main MainType;
DEFINE j_seller RoleDescriptionType;
DEFINE j_buyer RoleDescriptionType;
DEFINE j_detail DetailsType;
DEFINE j_item ProductItem;
DEFINE j_dec java.math.BigDecimal;
DEFINE j_amount AmountType;
DEFINE j_parser ParserHelper;
DEFINE outXML string;
DEFINE b01,b02, b03 Long;
Define d Date
let d = today
call A0101.create() RETURNING j_a0101;
call MainType.create() RETURNING j_main;
call j_main.setInvoiceNumber("0123456789");
call j_main.setInvoiceDate( '20170201' );
call j_main.setInvoiceTime('08:30:22' );
call RoleDescriptionType.create() RETURNING j_seller;
call RoleDescriptionType.create() RETURNING j_buyer;
call j_seller.setIdentifier("0123456789");
call j_seller.setName("012345678901234567890123456789012345678901234567890123456789");
call j_seller.setAddress("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
call j_seller.setPersonInCharge("012345678901");
call j_seller.setTelephoneNumber("012345678901234");
call j_seller.setFacsimileNumber("012345678901234");
call j_seller.setEmailAddress("123@123.123.123");
call j_seller.setCustomerNumber("01234566789789456123");
call j_seller.setRoleRemark("20 20 20 20 202 0212");
call j_main.setSeller(j_seller);
call j_buyer.setIdentifier("0123456789");
call j_buyer.setName("012345678901234567890123456789012345678901234567890123456789");
call j_buyer.setAddress("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
call j_buyer.setPersonInCharge("012345678901");
call j_buyer.setTelephoneNumber("012345678901234");
call j_buyer.setFacsimileNumber("012345678901234");
call j_buyer.setEmailAddress("123@123.123.123");
call j_buyer.setCustomerNumber("01234566789789456123");
call j_buyer.setRoleRemark("20 20 20 20 202 0212");
call j_main.setBuyer(j_buyer);
call j_main.setCheckNumber("1023456789");
call j_main.setBuyerRemark(BuyerRemarkEnum.DeductableExpense);
call j_main.setMainRemark("mainremark");
call j_main.setCustomsClearanceMark(CustomsClearanceMarkEnum.NotViaCustoms);
call j_main.setTaxCenter("taxcenter");
call j_main.setPermitDate('20170214');
call j_main.setPermitWord("permitword");
call j_main.setPermitNumber("permitnumber");
call j_main.setCategory("ca");
call j_main.setRelateNumber("relatenumber");
call j_main.setInvoiceType(InvoiceTypeEnum.ComputerType);
call j_main.setGroupMark("1");
call j_main.setDonateMark(DonateMarkEnum.Donated);
call j_main.setAttachment("attachment");
call j_a0101.setMain(j_main);
call DetailsType.create() returning j_detail;
call ProductItem.create() returning j_item;
call j_item.setDescription("description2");
call j_item.setQuantity( "2.0" );
call j_item.setUnit("unit");
call j_item.setUnitPrice("6.5");
call j_item.setAmount("5.2");
call j_item.setSequenceNumber("223");
call j_item.setRemark("remark");
call j_item.setRelateNumber("relatenumber");
call j_detail.addProductItem(j_item);
call ProductItem.create() returning j_item;
call j_item.setDescription("description3");
call j_item.setQuantity( "3.0" );
call j_item.setUnit("unit");
call j_item.setUnitPrice("6.5");
call j_item.setAmount("5.3");
call j_item.setSequenceNumber("333");
call j_item.setRemark("remark");
call j_item.setRelateNumber("relatenumber");
call j_detail.addProductItem(j_item);
call j_a0101.setDetails(j_detail);
call AmountType.create() returning j_amount;
call j_amount.setTaxType(TaxTypeEnum.HybridTaxType);
call j_amount.setTaxRate("789.215")
call j_amount.setOriginalCurrencyAmount("123456.852");
call j_amount.setExchangeRate("0123456789.22");
call j_amount.setCurrency(CurrencyCodeEnum.AED);
call j_a0101.setAmount(j_amount);
call ParserHelper.create() returning j_parser ;
call j_parser.marshalToXML(j_a0101) returning outXML ;
#我只顥示在console .沒存成檔這個可以自己作
DISPLAY outXML
end Main
#################################################
#使用後產出的XML
#################################################
<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:GEINV:eInvoiceMessage:A0101:3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:GEINV:eInvoiceMessage:A0101: 3.1 A0101.xsd">
<Main>
<InvoiceNumber>0123456789</InvoiceNumber>
<InvoiceDate>20170201</InvoiceDate>
<InvoiceTime>08:30:22</InvoiceTime>
<Seller>
<Identifier>0123456789</Identifier>
<Name>012345678901234567890123456789012345678901234567890123456789</Name>
<Address>0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789</Address>
<PersonInCharge>012345678901</PersonInCharge>
<TelephoneNumber>012345678901234</TelephoneNumber>
<FacsimileNumber>012345678901234</FacsimileNumber>
<EmailAddress>123@123.123.123</EmailAddress>
<CustomerNumber>01234566789789456123</CustomerNumber>
<RoleRemark>20 20 20 20 202 0212</RoleRemark>
</Seller>
<Buyer>
<Identifier>0123456789</Identifier>
<Name>012345678901234567890123456789012345678901234567890123456789</Name>
<Address>0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789</Address>
<PersonInCharge>012345678901</PersonInCharge>
<TelephoneNumber>012345678901234</TelephoneNumber>
<FacsimileNumber>012345678901234</FacsimileNumber>
<EmailAddress>123@123.123.123</EmailAddress>
<CustomerNumber>01234566789789456123</CustomerNumber>
<RoleRemark>20 20 20 20 202 0212</RoleRemark>
</Buyer>
<CheckNumber>1023456789</CheckNumber>
<BuyerRemark>1</BuyerRemark>
<MainRemark>mainremark</MainRemark>
<CustomsClearanceMark>1</CustomsClearanceMark>
<TaxCenter>taxcenter</TaxCenter>
<PermitDate>20170214</PermitDate>
<PermitWord>permitword</PermitWord>
<PermitNumber>permitnumber</PermitNumber>
<Category>ca</Category>
<RelateNumber>relatenumber</RelateNumber>
<InvoiceType>05</InvoiceType>
<GroupMark>1</GroupMark>
<DonateMark>1</DonateMark>
<Attachment>attachment</Attachment>
</Main>
<Details>
<ProductItem>
<Description>description2</Description>
<Quantity>2.0</Quantity>
<Unit>unit</Unit>
<UnitPrice>6.5</UnitPrice>
<Amount>5.2</Amount>
<SequenceNumber>223</SequenceNumber>
<Remark>remark</Remark>
<RelateNumber>relatenumber</RelateNumber>
</ProductItem>
<ProductItem>
<Description>description3</Description>
<Quantity>3.0</Quantity>
<Unit>unit</Unit>
<UnitPrice>6.5</UnitPrice>
<Amount>5.3</Amount>
<SequenceNumber>333</SequenceNumber>
<Remark>remark</Remark>
<RelateNumber>relatenumber</RelateNumber>
</ProductItem>
</Details>
<Amount>
<TaxType>9</TaxType>
<TaxRate>789.215</TaxRate>
<TaxAmount>123321</TaxAmount>
<TotalAmount>99999</TotalAmount>
<DiscountAmount>3019203</DiscountAmount>
<OriginalCurrencyAmount>123456.852</OriginalCurrencyAmount>
<ExchangeRate>123456789.22</ExchangeRate>
<Currency>AED</Currency>
</Amount>
</Invoice>
請問這個JAR如何取得?
回覆刪除jar 在安裝trunkey 中的目錄下就有.
刪除