|
中断了,不知道为啥,求解
rs3.Open "select distinct t1.CustomsDeclarationNum,t1.DeclarationDate,Supplier,t6.CNDeclaration,Declaration, " & _
"t8.IsTax,t7.Tariff,t6.PCS,t2.Quality DeclarationQty, " & _
" sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)AS [totalAmount(含税)/品名], " & _
" sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16 AS[(不含税/)], " & _
"sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16*0.16 AS[(进项税额/)], " & _
"sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16*(-t7.Tariff) AS[(退税额/)], " & _
"sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16*(0.16+t7.Tariff) AS[(进项转成本/)] " & _
"from OC_CustomsDeclaration t1 " & _
"inner join OC_CustomsDeclaration_Item t2 on t1.ID=t2.CustomsDeclarationId " & _
"inner join WH_Shipment t3 on t1.ContainerNo=t3.ContainerNo " & _
"inner join ( " & _
"select ShipmentNo,Product,LadingBillItemID,sum(Quantity) TransferQty from WH_Shipment_Detail group by ShipmentNo,Product,LadingBillItemID " & _
") t4 on t3.ShipmentNo=t4.ShipmentNo " & _
"inner join OC_Product_Info t5 on t4.Product=t5.SKU " & _
"inner join OC_Declaration_Info t6 on t5.DeclarationInfoID=t6.ID " & _
"inner join ( " & _
"select * from OC_DeclarationInfo_Item where Country='CN' " & _
") t7 on t6.ID=t7.DeclarationID and t7.HScode=t2.HSCode " & _
"inner join OC_LadingBill_Item t8 on t4.LadingBillItemID=t8.LadingBillItemID " & _
"where t1.CustomsDeclarationNum='" & Sheets("workstation").Range("B2") & "' and Supplier like '%" & Sheets("workstation").Range("B4") & "%'", con, 1, 1
Sheets("TempVAT(YH)").Range("Supplier") = rs3("Supplier")
If rs3.RecordCount = 1 Then
Sheets("TempVAT(YH)").Range("A8") = rs3("t6.CNDeclaration")
Sheets("TempVAT(YH)").Range("D8") = rs3("t6.PCS")
Sheets("TempVAT(YH)").Range("E8") = rs3("t2.Quality")
Sheets("TempVAT(YH)").Range("G8") = rs3("sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16")
Else
Sheets("TempVAT(YH)").Range("9:" & 9 + rs3.RecordCount - 2).Insert
i = 0
Do While Not rs3.EOF
Sheets("TempVAT(YH)").Range("A" & 8 + i) = rs3("t6.CNDeclaration")
Sheets("TempVAT(YH)").Range("D" & 8 + i) = rs3("t6.PCS")
Sheets("TempVAT(YH)").Range("E" & 8 + i) = rs3("t2.Quality")
Sheets("TempVAT(YH)").Range("G" & 8 + i) = rs3("sum(t8.UnitPrice*t4.TransferQty)over(partition by t6.CNDeclaration)/1.16")
rs3.MoveNext
i = i + 1
Loop
End If
Dim sht As Worksheet
Set sht = Sheets("TempVAT(YH)")
sht.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\VAT-" & "YH-" & Range("B2") & Range("B4") & ".pdf"
|
|