Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-ubl
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-ubl
Commits
3d66077b
Commit
3d66077b
authored
Dec 11, 2007
by
eicom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added stuff
parent
a8475b4e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
289 deletions
+108
-289
intranet-ubl-create.sql
sql/postgresql/intranet-ubl-create.sql
+14
-0
intranet-ubl-procs.tcl
tcl/intranet-ubl-procs.tcl
+92
-34
document.xml.tcl
www/document.xml.tcl
+2
-255
No files found.
sql/postgresql/intranet-ubl-create.sql
0 → 100755
View file @
3d66077b
-- /packages/intranet-ubl/sql/postgresql/intranet-ubl-create.sql
--
-- Copyright (c) 2003-2007 ]project-open[
--
-- All rights reserved. Please check
-- http://www.project-open.com/license/ for details.
--
-- @author all@devcon.project-open.com
-----------------------------------------------------------
-- Universal Business Language (UBL) Interface
--
-- This module just exports (future: imports) XML documents
-- in UBL formal
tcl/intranet-ubl-procs.tcl
View file @
3d66077b
...
...
@@ -107,58 +107,116 @@ ad_proc -private im_package_ubl_invoice2ubl_v10_eicom {
if
{
!
[
db_0or1row project_info
"
select c.*,
i.*,
to_char(o.creation_date, 'YYYY-MM-DD') as issue_date_pretty
,
paymeth.category_description as payment_method_desc
,
cust.company_name as customer_name,
ocust.address_line1 as customer_address_line1
,
ocust.address_line2 as customer_address_line2
,
ocust.address_city as customer_address_city,
ocust.address_state as customer_address_state
,
ocust.address_postal_code as customer_address_postal_code
,
upper(ocust.address_country_code) as customer_address_country_code,
cust_countries.country_name as customer_address_country_name
,
cust.main_office_id as customer_main_office_id
,
i.invoice_office_id as invoice_office_id
,
coalesce(
i.company_contact_id
,
cust.accounting_contact_id
,
cust.primary_contact_id
) as cust_contact_id
,
prov.company_name as provider_name,
oprov.address_line1 as provider_address_line1,
oprov.address_line2 as provider_address_line2,
oprov.address_city as provider_address_city,
oprov.address_state as provider_address_state,
oprov.address_postal_code as provider_address_postal_code,
upper(oprov.address_country_code) as provider_address_country_code,
prov_countries.country_name as provider_address_country_name,
im_name_from_user_id(i.company_contact_id) as customer_contact_name,
cust_contact.work_phone as customer_contact_work_phone,
im_name_from_user_id(i.company_contact_id) as provider_contact_name,
prov_contact.work_phone as provider_contact_work_phone,
prov.main_office_id as provider_main_office_id,
coalesce(
prov.accounting_contact_id,
prov.primary_contact_id
) as prov_contact_id,
paymeth.category_description as payment_method_desc
to_char(o.creation_date, 'YYYY-MM-DD') as issue_date_pretty
from
im_costs c,
im_invoices i
LEFT OUTER JOIN im_categories paymeth ON (i.payment_method_id = paymeth.category_id),
acs_objects o,
im_companies cust,
im_companies prov,
im_offices ocust
LEFT OUTER JOIN country_codes cust_countries ON (ocust.address_country_code = cust_countries.iso),
im_offices oprov
LEFT OUTER JOIN country_codes prov_countries ON (oprov.address_country_code = prov_countries.iso),
users_contact cust_contact,
users_contact prov_contact
im_companies prov
where
i.invoice_id = :invoice_id
and i.invoice_id = c.cost_id
and i.invoice_id = o.object_id
and c.customer_id = cust.company_id
and c.provider_id = prov.company_id
and ocust.office_id = i.invoice_office_id
and oprov.office_id = prov.main_office_id
and i.company_contact_id = cust_contact.user_id
and prov.accounting_contact_id = prov_contact.user_id
"
]}
{
# ad_return_complaint 1 [lang::message::lookup "" intranet-ubl.Financial_Document_Not_Found "Didn't find financial document \#%invoice_id%"
]
return
""
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Financial_Document_Not_Found
"Didn't find financial document
\#
%invoice_id%"
]
ad_script_abort
}
set cust_contact_sql
"
select
im_name_from_user_id(uc.user_id) as customer_contact_name,
uc.work_phone as customer_contact_work_phone
from
users_contact uc
where
uc.user_id = :cust_contact_id
"
if
{
!
[
db_0or1row cust_contact
$cust
_contact_sql
]}
{
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Customer_Contact_for_Financial_Document_Not_Found
"Didn't find a Customer Contact for financial document
\#
%invoice_id%"
]
ad_script_abort
}
set prov_contact_sql
"
select
im_name_from_user_id(uc.user_id) as provider_contact_name,
uc.work_phone as provider_contact_work_phone
from
users_contact uc
where
uc.user_id = :prov_contact_id
"
if
{
!
[
db_0or1row prov_contact
$prov
_contact_sql
]}
{
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Provider_Contact_for_Financial_Document_Not_Found
"Didn't find a Provider Contact for financial document
\#
%invoice_id%"
]
ad_script_abort
}
# Office Logic: Take the customers and provider's main office,
# unless there has been a specific delivery office specified for the customer.
set cust_office_id
$customer
_main_office_id
set prov_office_id
$provider
_main_office_id
if
{
""
!=
$invoice
_office_id
}
{
set cust_office_id
$invoice
_office_id
}
set prov_office_sql
"
select
oprov.address_line1 as provider_address_line1,
oprov.address_line2 as provider_address_line2,
oprov.address_city as provider_address_city,
oprov.address_state as provider_address_state,
oprov.address_postal_code as provider_address_postal_code,
upper(oprov.address_country_code) as provider_address_country_code,
prov_countries.country_name as provider_address_country_name
from
im_offices oprov
LEFT OUTER JOIN country_codes prov_countries ON (oprov.address_country_code = prov_countries.iso)
where
oprov.office_id = :prov_office_id
"
if
{
!
[
db_0or1row prov_office
$prov
_office_sql
]}
{
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Provider_Office_for_Financial_Document_Not_Found
"Didn't find Provider's office for financial document
\#
%invoice_id%"
]
ad_script_abort
}
set cust_office_sql
"
select
ocust.address_line1 as customer_address_line1,
ocust.address_line2 as customer_address_line2,
ocust.address_city as customer_address_city,
ocust.address_state as customer_address_state,
ocust.address_postal_code as customer_address_postal_code,
upper(ocust.address_country_code) as customer_address_country_code,
cust_countries.country_name as customer_address_country_name
from
im_offices ocust
LEFT OUTER JOIN country_codes cust_countries ON (ocust.address_country_code = cust_countries.iso)
where
ocust.office_id = :cust_office_id
"
if
{
!
[
db_0or1row cust_office
$cust
_office_sql
]}
{
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Customer_Office_for_Financial_Document_Not_Found
"Didn't find customer office for financial document
\#
%invoice_id%"
]
ad_script_abort
}
...
...
www/document.xml.tcl
View file @
3d66077b
...
...
@@ -26,259 +26,6 @@ set user_id [ad_maybe_redirect_for_registration]
set
today
[
db_string today
"select to_char(now(), 'YYYY-MM-DD')"
]
set
invoice_url
"/intranet-invoices/view?invoice_id=
$invoice
_id"
# rounding precision can be between 2 (USD,EUR, ...
)
# and -5 (Old Turkish Lira, ...
)
.
set
rounding_precision 2
set
required_field
"<font color=red size=+1><B>*</B></font>"
set
rounding_factor
[
expr
exp
(
log
(
10
)
*
$rounding
_precision
)]
set
rf
$rounding
_factor
# Locale
set
locale
"en_US"
# set locale [lang::user::locale
]
set
cur_format
[
im_l10n_sql_currency_format
]
set
vat_format
$cur
_format
set
tax_format
$cur
_format
# ---------------------------------------------------------------
# Get information about the financial document ("invoice"
)
# ---------------------------------------------------------------
if
{
!
[
db_0or1row project_info
"
select c.*,
i.*,
to_char(o.creation_date, 'YYYY-MM-DD') as issue_date_pretty,
cust.company_name as customer_name,
ocust.address_line1 as customer_address_line1,
ocust.address_line2 as customer_address_line2,
ocust.address_city as customer_address_city,
ocust.address_state as customer_address_state,
ocust.address_postal_code as customer_address_postal_code,
ocust.address_country_code as customer_address_country_code,
prov.company_name as provider_name,
oprov.address_line1 as provider_address_line1,
oprov.address_line2 as provider_address_line2,
oprov.address_city as provider_address_city,
oprov.address_state as provider_address_state,
oprov.address_postal_code as provider_address_postal_code,
oprov.address_country_code as provider_address_country_code,
im_name_from_user_id(i.company_contact_id) as customer_contact_name,
cust_contact.work_phone as customer_contact_work_phone,
im_name_from_user_id(i.company_contact_id) as provider_contact_name,
prov_contact.work_phone as provider_contact_work_phone,
paymeth.category_description as payment_method_desc
from
im_costs c,
im_invoices i
LEFT OUTER JOIN im_categories paymeth ON (i.payment_method_id = paymeth.category_id),
acs_objects o,
im_companies cust,
im_companies prov,
im_offices ocust,
im_offices oprov,
users_contact cust_contact,
users_contact prov_contact
where
i.invoice_id = :invoice_id
and i.invoice_id = c.cost_id
and i.invoice_id = o.object_id
and c.customer_id = cust.company_id
and c.provider_id = prov.company_id
and ocust.office_id = i.invoice_office_id
and oprov.office_id = prov.main_office_id
and i.company_contact_id = cust_contact.user_id
and prov.accounting_contact_id = prov_contact.user_id
"
]}
{
ad_return_complaint 1
[
lang::message::lookup
""
intranet-ubl.Financial_Document_Not_Found
"Didn't find financial document
\#
%invoice_id%"
]
return
}
# Calculate grand total based on the same inner SQL
db_1row calc_grand_total
""
set
subtotal_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$subtotal
+0
]
$rounding
_precision
]
""
$locale
]
set
vat_amount_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$vat
_amount+0
]
$rounding
_precision
]
""
$locale
]
set
tax_amount_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$tax
_amount+0
]
$rounding
_precision
]
""
$locale
]
set
grand_total_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$grand
_total+0
]
$rounding
_precision
]
""
$locale
]
set
total_due_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$total
_due+0
]
$rounding
_precision
]
""
$locale
]
set
discount_perc_pretty
$discount
_perc
set
surcharge_perc_pretty
$surcharge
_perc
# Get the right outer tag name, depending on the document type
set
document_type
"error"
switch
$cost
_type_id
{
3700
{
set document_type
"Invoice"
}
3702
{
set document_type
"Quote"
}
3704
{
set document_type
"Invoice"
}
3706
{
set document_type
"Order"
}
3724
{
set document_type
"DelNote"
}
}
# ---------------------------------------------------------------
# Create the XML
# ---------------------------------------------------------------
set
version
"1.12"
set
view_index 0
# ---------------------------------------------------------------
# Main Document Node
set
doc
[
dom createDocument
$document
_type
]
set
main_node
[
$doc
documentElement
]
$main
_node setAttribute xmlns:cbc
"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0"
$main
_node setAttribute xmlns:cac
"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-1.0"
$main
_node setAttribute xmlns:cur
"urn:oasis:names:specification:ubl:schema:xsd:CurrencyCode-1.0"
$main
_node setAttribute xmlns:xsi
"http://www.w3.org/2001/XMLSchema-instance"
$main
_node setAttribute xmlns
"urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0"
$main
_node setAttribute xsi:schemaLocation
"urn:oasis:names:specification:ubl:schema:xsd:Invoice-1.0 ../../xsd/maindoc/UBL-Invoice-1.0.xsd"
$main
_node appendXML
"<ID>
$cost
_name</ID>"
$main
_node appendXML
"<cbc:IssueDate>
$issue
_date_pretty</cbc:IssueDate>"
$main
_node appendXML
"<TaxPointDate>
$issue
_date_pretty</TaxPointDate>"
$main
_node appendXML
"
<cac:OrderReference>
<cac:BuyersID>
$customer
_id</cac:BuyersID>
<cac:SellersID>
$provider
_id</cac:SellersID>
<cbc:IssueDate>
$issue
_date_pretty</cbc:IssueDate>
</cac:OrderReference>"
$main
_node appendXML
"
<cac:BuyerParty>
<cac:Party>
<cac:PartyName>
<cbc:Name>
$customer
_name</cbc:Name>
</cac:PartyName>
<cac:Address>
<cbc:StreetName>
$customer
_address_line1
$customer
_address_line2</cbc:StreetName>
<cbc:CityName>
$customer
_address_city</cbc:CityName>
<cbc:PostalZone>
$customer
_address_postal_code</cbc:PostalZone>
<cac:CountrySubentityCode>
$customer
_address_state</cac:CountrySubentityCode>
</cac:Address>
</cac:Party>
<cac:AccountsContact>
<cbc:Name>
$customer
_contact_name</cbc:Name>
<cbc:Telephone>
$customer
_contact_work_phone</cbc:Telephone>
</cac:AccountsContact>
</cac:BuyerParty>
"
$main
_node appendXML
"
<cac:SellerParty>
<cac:Party>
<cac:PartyName>
<cbc:Name>
$provider
_name</cbc:Name>
</cac:PartyName>
<cac:Address>
<cbc:StreetName>
$provider
_address_line1
$provider
_address_line2</cbc:StreetName>
<cbc:CityName>
$provider
_address_city</cbc:CityName>
<cbc:PostalZone>
$provider
_address_postal_code</cbc:PostalZone>
<cac:CountrySubentityCode>
$provider
_address_state</cac:CountrySubentityCode>
</cac:Address>
</cac:Party>
<cac:AccountsContact>
<cbc:Name>
$provider
_contact_name</cbc:Name>
<cbc:Telephone>
$provider
_contact_work_phone</cbc:Telephone>
</cac:AccountsContact>
</cac:SellerParty>
"
$main
_node appendXML
"
<cac:PaymentTerms>
<cbc:Note>
$payment
_method_desc</cbc:Note>
<cac:ReferenceEventCode>!</cac:ReferenceEventCode>
</cac:PaymentTerms>
"
$main
_node appendXML
"
<cac:TaxTotal>
<cbc:TotalTaxAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$vat
_amount_pretty</cbc:TotalTaxAmount>
<cac:TaxSubTotal>
<cbc:TaxableAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$amount
</cbc:TaxableAmount>
<cbc:TaxAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$vat
_amount_pretty</cbc:TaxAmount>
<cac:TaxCategory>
<cac:ID>STD</cac:ID>
<cbc:Percent>
$vat
</cbc:Percent>
<cac:TaxScheme>
<cac:TaxTypeCode>VAT</cac:TaxTypeCode>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubTotal>
</cac:TaxTotal>
"
$main
_node appendXML
"
<cac:LegalTotal>
<cbc:LineExtensionTotalAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$subtotal
_pretty</cbc:LineExtensionTotalAmount>
<cbc:TaxExclusiveTotalAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$subtotal
_pretty</cbc:TaxExclusiveTotalAmount>
<cbc:TaxInclusiveTotalAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$grand
_total_pretty</cbc:TaxInclusiveTotalAmount>
</cac:LegalTotal>
"
set
ctr 1
db_foreach invoice_items
{}
{
set amount_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$amount
+0
]
$rounding
_precision
]
""
$locale
]
set item_units_pretty
[
lc_numeric
[
expr
$item
_units+0
]
""
$locale
]
set price_per_unit_pretty
[
lc_numeric
[
im_numeric_add_trailing_zeros
[
expr
$price
_per_unit+0
]
$rounding
_precision
]
""
$locale
]
$main
_node appendXML
"
<cac:
${document_type}
Line>
<cac:ID>
$ctr
</cac:ID>
<cbc:InvoicedQuantity quantityUnitCode=
\"
$item
_uom
\"
>
$item
_units_pretty</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
[
string
trim
$amount
_pretty
]
</cbc:LineExtensionAmount>
<cac:OrderLineReference>
<cac:BuyersLineID>
$ctr
</cac:BuyersLineID>
</cac:OrderLineReference>
<cac:Item>
<cbc:Description>
$item
_name</cbc:Description>
<cac:BuyersItemIdentification>
<cac:ID>
$ctr
</cac:ID>
</cac:BuyersItemIdentification>
<cac:SellersItemIdentification>
<cac:ID>32145-12</cac:ID>
</cac:SellersItemIdentification>
<cac:BasePrice>
<cbc:PriceAmount amountCurrencyCodeListVersionID=
\"
0.3
\"
amountCurrencyID=
\"
$currency
\"
>
$price
_per_unit_pretty</cbc:PriceAmount>
</cac:BasePrice>
</cac:Item>
</cac:
${document_type}
Line>
"
incr ctr
}
ns_return 200 text/xxx
[
$doc
asXML -indent 2
]
# ns_return 200 text/xxx [$doc asXML -indent 2 -escapeNonASCII
]
set
xml
[
im_package_ubl_invoice2ubl_v10_eicom -invoice_id
$invoice
_id
]
ns_return 200 text/xxx
$xml
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment