網上有各種不同的防偽開票介面版本,有直連ERP資料庫寫視圖表取數的,有連SAP寫RFC呼叫函資料的,也有用文字(TXT)或EX表交換資料的,都是為了把發票資料明細匯入到開票機自動開票。
以下是我們做的一個用友通發票視圖表分享:
IF NOT EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'HaveInvoiceED') Create Table HaveInvoiceED(CustomerID varchar(50) not null, FPHM VARCHAR(50) not null,LX varchar(2) not null, PRIMARY key(CustomerID,FPHM,LX))Go;IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'V_INVOICE_HEAD_FP') DROP VIEW V_INVOICE_HEAD_FPGO;CREATE VIEW V_INVOICE_HEAD_FPAS SELECT A.SBVID AS 單據內碼, A.CSBVCODE AS 單據號, A.CCUSCODE AS 客戶編碼, B.CCUSREGCODE AS 客戶稅號, B.CCUSNAME AS 客戶名稱, ISNULL(B.CCUSADDRESS,'') +' ' + ISNULL(B.CCUSPHONE,'') AS 地址電話, ISNULL(B.CCUSBANK,'') +' ' + ISNULL(B.CCUSACCOUNT,'') AS 銀行賬號, '' AS 備註, '' as 收款人,'' as 複核人,A.DDATE AS 單據日期 FROM SALEBILLVOUCH A, CUSTOMER B WHERE A.CCUSCODE=B.CCUSCODE AND NOT EXISTS(SELECT 0 FROM HAVEINVOICEED D WHERE D.CUSTOMERID=CONVERT(VARCHAR,A.SBVID))GO;
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'V_INVOICE_DETAIL_FP') DROP VIEW V_INVOICE_DETAIL_FPGo;CREATE VIEW V_INVOICE_DETAIL_FPAS SELECT a.SBVID as 單據內碼, a.cInvCode as 產品程式碼, b.cInvName as 產品名稱, b.cInvStd as 產品型號, b.cinvm_unit as 產品單位, a.iQuantity as 產品數量, a.iTaxUnitPrice as 含稅價,a.iSum as 含稅金額,a.iUnitPrice as 不含稅價, a.iMoney as 不含稅金額, a.iTax as 稅額,17 as 稅率 FROM SaleBillVouchs a, Inventory b where a.cInvCode = b.cInvCodeGo;
原作者: 防偽開票介面