Index: openacs-4/packages/invoices/invoices.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/invoices.info,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/invoices.info 16 Aug 2005 20:04:30 -0000 1.1
@@ -0,0 +1,38 @@
+
+
+
+
+ Invoices
+ Invoices
+ f
+ t
+
+
+ Timo Hentschel
+ Invoices package that will collect costs to invoice items in invoices and store data about received payment.
+ 2005-06-06
+ Cognovis
+ Collect costs to invoice items and invoices, store payment information.
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml 16 Aug 2005 20:04:30 -0000 1.1
@@ -0,0 +1,262 @@
+
+
+
+ Akzeptiert am
+ Admin
+ Kategorien verwalten
+ Betrag
+ bezahlt
+ Betrag
+ Gesamtsumme
+ Mehrwertsteuer?
+ Abzurechnende Projekte
+ Abbrechen
+ Abbrechen und zur�ck
+ Abgebrochen?
+ Fortfahren mit Angebot akzeptieren
+ Fortfahren mit l�schen
+ Kosten
+ Kostengrund
+ Kosteneintrag
+ Kostennummer
+ Kosten
+ W�hrung
+ bezahlte W�hrung
+ Kunde
+ L�schen
+ F�lligkeit
+ �ndern
+ Fileanzahl
+ Timing
+ Fixkisten?
+ Rechnung
+ Rechnungsposition
+ Positionsnummer
+ Rechnungspositionen
+ Rechnungsnummer
+ Verweis auf Rechnung
+ Rechnungen
+ Rechnungen
+ Kosten
+ Kosten
+ Add Cost
+ Apply VAT?
+ Cost number
+ Currency
+ Delete Cost
+ Description
+ Edit Cost
+ Number of units
+ New Cost
+ Create New Cost
+ Cost cause
+ Customer
+ Price per unit
+ Title
+ Fixed cost?
+ View Cost
+ Preisliste anzeigen
+ Rechnung
+ Rechnungen
+ Rechnung "%organization_name%"
+ Rechnung hinzuf�gen
+ Rabatt
+ offener Betrag
+ Summe
+ Storno
+ Storno hinzuf�gen
+ <html><body><h3>Storno</h3>%invoice_text%</html></body>
+ beendet am
+ berechnete Positonen
+ Positionsanzahl
+ erstellt am
+ erstellt von
+ Gutschrift
+ Gutschrift erstellen
+ <html><body><h3>Gutschrift</h3>%invoice_text%</html></body>
+ Neue Gutschrift
+ Neue Gutschrift erstellen
+ W�hrung
+ Rechnung l�schen
+ Beschreibung
+ Rechnungsdatum
+ Rechnung �ndern
+ Sie d�rfen keine bezahlte oder stornierte Rechnung �ndern.
+ <html><body><h3>Rechnung</h3>%invoice_text%</html></body>
+ Rechnungsnummer
+ Rechnungsposition
+ Rechnungspositionen
+ Rechnungsposition hinzuf�gen
+ Rechnungsposition l�schen
+ Beschreibung
+ Rechnungsposition �ndern
+ Rechnung
+ Positionsnummer
+ Anzahl Stunden
+ Neue Rechnungsposition
+ Neue Rechnungsposition erstellen
+ Bezug auf Position
+ Stundenpreis
+ Rabatt
+ Nummer
+ Titel
+ Mehrwertsteuer
+ Rechnungsposition ansehen
+ Neue Rechnung
+ Neue Rechnung erstellen
+ Kunde
+ bezahlter Betrag
+ bezahlte W�hrung
+ Rechnungsbezug
+ Zahlungsziel (Tage)
+ Beschreibung
+ Projekt Nummer
+ Titel
+ Nicht komplett abgerechnete Projekte
+ Rabatt
+ Maximaler Rabatt %open_rebate% %currency%
+ Rechnungsempf�nger
+ Verschicken
+ Titel
+ Gesamtsumme
+ Mehrwertsteuer
+ Mehrwertsteuersatz
+ Rechnung ansehen
+ Kostenaufstellung
+ Kostenaufstellungen
+ Angebot akzeptieren
+ Akzeptiert am
+ <html><body><h3>Angebotsbest�tigung</h3>%offer_text%</html></body>
+ Kostenaufstellung f�r "%organization_name%"
+ Neue Kostenaufstellung hinzuf�gen
+ Rabatt
+ Summe
+ Gesamtsumme
+ Kommentar
+ Anzahl Positionen
+ erstellt am
+ erstellt von
+ W�hrung
+ Kostenaufstellung l�schen
+ Beschreibung
+ Description of the cost sheet
+ Kostenaufstellung �ndern
+ Sie d�rfen keine akzeptierte oder berechnete Kostenaufstellung �ndern.
+ <html><body><h3>Angebot</h3>%offer_text%</html></body>
+ Timing Datum
+ Timing Uhrzeit
+ Kostenposition
+ Kostenpositionen
+ Kostenposition hinzuf�gen
+ Betrag
+ Typ
+ Kommentar
+ Kostenposition l�schen
+ Beschreibung
+ Kostenposition �ndern
+ Dateianzahl
+ Dateien
+ Kostenaufstellung
+ Anzahl Stunden
+ Neue Kostenposition
+ Neue Kostenposition erstellen
+ Positionsnummer
+ Seitenzahl
+ Seiten
+ Bezug auf Kostenposition
+ Stundenpreis
+ Rabatt
+ Nummer
+ Titel
+ Mehrwertsteuer
+ Kostenposition ansehen
+ Kostenaufstellungen
+ Neue Kostenaufstellung
+ Neue Kostenaufstellung hinzuf�gen
+ Angebotsnummer
+ Nummer der Kostenaufstellung
+ Kunde
+ Name des Kunden
+ Zahlungsziel (Tage)
+ Projekt
+ Beschreibung
+ Projekt Nummer
+ Titel
+ Angebot schicken
+ Auftragsbest�tigung schicken
+ Angebotsvorlage
+ Titel
+ Titel des Angebots
+ Mehrwertsteuer
+ Mehrwertsteuersatz
+ Kostenaufstellung ansehen
+ Zahlung
+ Zahlungen
+ Zahlung hinzuf�gen
+ Betrag
+ W�hrung
+ Zahlung l�schen
+ Beschreibung
+ Zahlung �ndern
+ Rechnung
+ Neue Zahlung
+ Neue Zahlung hinzuf�gen
+ Kunden
+ erhalten am
+ Titel
+ Zahlung ansehen
+ Preis
+ Preise
+ Betrag
+ Preiskategorie
+ Preise �ndern
+ Preisliste
+ Preisliste
+ Preislisten
+ Preisliste hinzuf�gen
+ W�hrung
+ Preisliste l�schen
+ Beschreibung
+ Preisliste �ndern
+ Neue Preisliste
+ Neue Preisliste hinzuf�gen
+ Customer
+ Titel
+ Preisliste ansehen
+ Preis ansehen
+ Anwendungen verlinken
+ Nein
+ Keine
+ Anzahl Stunden
+ Kostenaufstellung
+ Angebotsposition
+ Positionsnummer
+ Angebotspositionen
+ Angebotsnummer
+ Kostenaufstellungen
+ Kostenaufstellungen
+ Seitenyahl
+ Bezug auf Rechnungsposition
+ Bezug auf Kostenposition
+ Zahlung
+ Zahlungsziel (Tage)
+ Zahlungen
+ Preis
+ Preiskategorie
+ Preisliste
+ Preisliste
+ Preislisten
+ Stundenpreis
+ Preise
+ Projekte
+ Rabatt
+ erhalten am
+ Empf�nger
+ Nummer
+ Gesamtsumme
+ h
+ Unmounted
+ Mehrwertsteuersatz
+ Mehrwertsteuer
+ Ja
+
Index: openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 16 Aug 2005 20:04:30 -0000 1.1
@@ -0,0 +1,262 @@
+
+
+
+ Accepted on
+ Admin
+ Categories Administration
+ Amount
+ Amount paid
+ Amount sum
+ Total Amount
+ Apply VAT?
+ Billable Projects
+ Cancel
+ Cancel and Return
+ Cancelled?
+ Continue with Offer Acceptance
+ Continue with Delete
+ Cost
+ Cost cause
+ Cost item
+ Cost number
+ Costs
+ Currency
+ Currency paid
+ Customer
+ Delete
+ Due date
+ Edit
+ Number of files
+ Finish date
+ Fixed cost?
+ Invoice
+ Invoice Item
+ Invoice item number
+ Invoice Items
+ Invoice number
+ Invoice reference
+ Invoices
+ Invoices
+ Cost
+ Costs
+ Add Cost
+ Apply VAT?
+ Cost number
+ Currency
+ Delete Cost
+ Description
+ Edit Cost
+ Number of units
+ New Cost
+ Create New Cost
+ Cost cause
+ Customer
+ Price per unit
+ Title
+ Fixed cost?
+ View Cost
+ Display price list
+ Invoice
+ Invoices
+ Invoice "%organization_name%"
+ Add Invoice
+ Rebate
+ Open amount
+ Amount sum
+ Cancellation
+ Add invoice cancellation
+ <html><body><h3>Cancellation</h3>%invoice_text%</html></body>
+ Finished on
+ Billed items
+ Total items
+ Created on
+ Created by
+ Credit
+ Add invoice credit
+ <html><body><h3>Credit</h3>%invoice_text%</html></body>
+ New Credit
+ Create New Credit
+ Currency
+ Delete Invoice
+ Description
+ Invoice date
+ Edit Invoice
+ You are not allowed to edit a paid or cancelled invoice
+ <html><body><h3>Invoice</h3>%invoice_text%</html></body>
+ Invoice number
+ Invoice Item
+ Invoice Items
+ Add Invoice Item
+ Delete Invoice Item
+ Description
+ Edit Invoice Item
+ Invoice
+ Invoice item number
+ Number of units
+ New Invoice Item
+ Create New Invoice Item
+ Parent Item
+ Price per unit
+ Rebate
+ Sort order
+ Title
+ VAT
+ View Invoice Item
+ New Invoice
+ Create New Invoice
+ Customer
+ Amount paid
+ Currency paid
+ Invoice reference
+ Payment after .. days
+ Description
+ Project ID
+ Title
+ Projects not completely billed
+ Rebate
+ Maximum rebate %open_rebate% %currency%
+ Invoice Recipient
+ Send
+ Title
+ Total amount
+ VAT
+ %VAT
+ View Invoice
+ Cost Sheet
+ Cost Sheets
+ Accept Offer
+ Accepted on
+ <html><body><h3>Accepted Offer</h3>%offer_text%</html></body>
+ Cost Sheet for "%organization_name%"
+ Add Cost Sheet
+ Rebate
+ Amount sum
+ Total amount
+ Comment
+ Total items
+ Created on
+ Created by
+ Currency
+ Delete Cost Sheet
+ Description
+ Description of the cost sheet
+ Edit Cost Sheet
+ You are not allowed to edit an accepted or invoiced cost sheet
+ <html><body><h3>Offer</h3>%offer_text%</html></body>
+ Finish on
+ Finish time
+ Cost Item
+ Cost Items
+ Add Cost Item
+ Amount
+ Type
+ Comment
+ Delete Cost Item
+ Description
+ Edit Cost Item
+ Number of files
+ files
+ Cost Sheet
+ Number of units
+ New Cost Item
+ Create New Cost Item
+ Cost Item number
+ Number of pages
+ pages
+ Parent Item
+ Price per unit
+ Rebate
+ Sort order
+ Title
+ VAT
+ View Cost Item
+ Cost Sheets
+ New Cost Sheet
+ Create New Cost Sheet
+ Offer number
+ Cost sheet number
+ Customer
+ Organization Name
+ Payment after .. days
+ Project
+ Description
+ Project ID
+ Title
+ Send Offer
+ Send confirmation
+ Template des Angebots
+ Title
+ Title of the offer
+ VAT
+ %VAT
+ View Cost Sheet
+ Payment
+ Payments
+ Add Payment
+ Amount
+ Currency
+ Delete Payment
+ Description
+ Edit Payment
+ Invoice
+ New Payment
+ Create New Payment
+ Customer
+ Received on
+ Title
+ View Payment
+ Price
+ Prices
+ Amount
+ Price category
+ Edit Prices
+ Price List
+ Price List
+ Price Lists
+ Add Price List
+ Currency
+ Delete Price List
+ Description
+ Edit Price List
+ New Price List
+ Create New Price List
+ Customer
+ Title
+ View Price List
+ View Price
+ Link package instances
+ No
+ None
+ Number of units
+ Cost Sheet
+ Offer Item
+ Offer item number
+ Offer Items
+ Offer number
+ Cost Sheets
+ Cost Sheets
+ Number of pages
+ Parent invoice item
+ Parent cost item
+ Payment
+ Payment after .. days
+ Payments
+ Price
+ Price category
+ Price List
+ Price list
+ Price Lists
+ Price per unit
+ Prices
+ Projects
+ Rebate
+ Received on
+ Recipient
+ Sort order
+ Total amount
+ h
+ Unmounted
+ %VAT
+ VAT amount
+ Yes
+
Index: openacs-4/packages/invoices/lib/invoice-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/invoice-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/invoice-list.adp 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1 @@
+
Index: openacs-4/packages/invoices/lib/invoice-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/invoice-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/invoice-list.tcl 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,155 @@
+if {![info exists format]} {
+ set format "normal"
+}
+if {![info exists orderby]} {
+ set orderby ""
+}
+if {![info exists page_size]} {
+ set page_size "25"
+}
+
+if {![info exists package_id]} {
+ set package_id [ad_conn package_id]
+}
+
+if {![info exists base_url]} {
+ set base_url [apm_package_url_from_id $package_id]
+}
+
+
+foreach optional_param {organization_id row_list} {
+ if {![info exists $optional_param]} {
+ set $optional_param {}
+ }
+}
+
+set dotlrn_club_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type "dotlrn_club"] 0]
+set pm_base_url [apm_package_url_from_id [dotlrn_community::get_package_id_from_package_key -package_key "project-manager" -community_id $dotlrn_club_id]]
+
+
+#set package_id [ad_conn package_id]
+set date_format [lc_get formbuilder_date_format]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+set actions [list "[_ invoices.iv_invoice_New]" [export_vars -base invoice-add {organization_id}] "[_ invoices.iv_invoice_New2]" "[_ invoices.iv_invoice_credit_New]" [export_vars -base invoice-credit {organization_id}] "[_ invoices.iv_invoice_credit_New2]" "[_ invoices.iv_offer_2]" [export_vars -base offer-list {organization_id}] "[_ invoices.iv_offer_2]" "[_ invoices.projects]" $pm_base_url "[_ invoices.projects]"]
+
+template::list::create \
+ -name iv_invoice \
+ -key invoice_id \
+ -no_data "[_ invoices.None]" \
+ -selected_format $format \
+ -elements {
+ invoice_nr {
+ label {[_ invoices.iv_invoice_invoice_nr]}
+ }
+ title {
+ label {[_ invoices.iv_invoice_1]}
+ link_url_eval {[export_vars -base "invoice-ae" {invoice_id {mode display}}]}
+ }
+ description {
+ label {[_ invoices.iv_invoice_Description]}
+ }
+ total_amount {
+ label {[_ invoices.iv_invoice_total_amount]}
+ display_template {@iv_invoice.total_amount@ @iv_invoice.currency@}
+ }
+ paid_amount {
+ label {[_ invoices.iv_invoice_paid_amount]}
+ display_template {@iv_invoice.paid_amount@ @iv_invoice.paid_currency@}
+ }
+ creation_user {
+ label {[_ invoices.iv_invoice_creation_user]}
+ display_template {@iv_invoice.first_names@ @iv_invoice.last_name@}
+ }
+ creation_date {
+ label {[_ invoices.iv_invoice_creation_date]}
+ }
+ due_date {
+ label {[_ invoices.iv_invoice_due_date]}
+ }
+ action {
+ display_template {#invoices.Edit# #invoices.Cancel# #invoices.Delete#}
+ }
+ } -actions $actions -sub_class narrow \
+ -orderby {
+ default_value invoice_nr
+ invoice_nr {
+ label {[_ invoices.iv_invoice_invoice_nr]}
+ orderby {t.invoice_nr}
+ default_direction desc
+ }
+ title {
+ label {[_ invoices.iv_invoice_1]}
+ orderby_desc {lower(cr.title) desc, t.due_date}
+ orderby_asc {lower(cr.title) asc, t.due_date}
+ default_direction asc
+ }
+ description {
+ label {[_ invoices.iv_invoice_Description]}
+ orderby_desc {lower(cr.description) desc, t.due_date}
+ orderby_asc {lower(cr.description) asc, t.due_date}
+ default_direction asc
+ }
+ total_amount {
+ label {[_ invoices.iv_invoice_total_amount]}
+ orderby_desc {t.total_amount desc, t.due_date}
+ orderby_asc {t.total_amount asc, t.due_date}
+ default_direction desc
+ }
+ paid_amount {
+ label {[_ invoices.iv_invoice_paid_amount]}
+ orderby_desc {t.paid_amount desc, t.due_date}
+ orderby_asc {t.paid_amount asc, t.due_date}
+ default_direction desc
+ }
+ creation_user {
+ label {[_ invoices.iv_invoice_creation_user]}
+ orderby_desc {lower(p.last_name) desc, lower(p.first_names) desc}
+ orderby_asc {lower(p.last_name) asc, lower(p.first_names) asc}
+ default_direction asc
+ }
+ creation_date {
+ label {[_ invoices.iv_invoice_creation_date]}
+ orderby {o.creation_date}
+ default_direction desc
+ }
+ due_date {
+ label {[_ invoices.iv_invoice_due_date]}
+ orderby {t.due_date}
+ default_direction desc
+ }
+ } -orderby_name orderby -html {width 100%} \
+ -page_size_variable_p 1 \
+ -page_size $page_size \
+ -page_flush_p 0 \
+ -page_query_name iv_invoice_paginated \
+ -filters {organization_id {}} \
+ -formats {
+ normal {
+ label "[_ invoices.Table]"
+ layout table
+ row $row_list
+ }
+ csv {
+ label "[_ invoices.CSV]"
+ output csv
+ page_size 0
+ row $row_list
+ }
+ }
+
+
+db_multirow -extend {creator_link edit_link cancel_link delete_link} iv_invoice iv_invoice {} {
+ # Ugly hack. We should find out which contact package is linked
+ set creator_link "/contacts/$creation_user"
+ set edit_link [export_vars -base "${base_url}invoice-ae" {invoice_id}]
+ set cancel_link [export_vars -base "${base_url}invoice-cancellation" {organization_id {parent_id $invoice_rev_id}}]
+ set delete_link [export_vars -base "${base_url}invoice-delete" {invoice_id}]
+ if {[empty_string_p $total_amount]} {
+ set total_amount 0
+ }
+ set total_amount [format "%.2f" $total_amount]
+ if {![empty_string_p $paid_amount]} {
+ set paid_amount [format "%.2f" $paid_amount]
+ }
+}
Index: openacs-4/packages/invoices/lib/invoice-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/invoice-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/invoice-list.xql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+ select cr.item_id as invoice_id, cr.title, cr.description,
+ t.invoice_nr, t.total_amount, t.currency, t.paid_amount,
+ t.paid_currency, p.first_names, p.last_name, o.creation_user,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.due_date, :date_format) as due_date, t.parent_invoice_id,
+ t.invoice_id as invoice_rev_id, t.cancelled_p
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_invoices t,
+ acs_objects o, persons p
+ where cr.revision_id = ci.latest_revision
+ and t.invoice_id = cr.revision_id
+ and t.organization_id = :organization_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ and o.object_id = t.invoice_id
+ and p.person_id = o.creation_user
+ [template::list::filter_where_clauses -and -name iv_invoice]
+ [template::list::orderby_clause -name iv_invoice -orderby]
+
+
+
+
+
+
+
+ select cr.item_id as invoice_id
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_invoices t,
+ acs_objects o, persons p
+ where cr.revision_id = ci.latest_revision
+ and t.invoice_id = cr.revision_id
+ and t.organization_id = :organization_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ and o.object_id = t.invoice_id
+ and p.person_id = o.creation_user
+ [template::list::filter_where_clauses -and -name iv_invoice]
+ [template::list::orderby_clause -name iv_invoice -orderby]
+
+
+
+
+
+
Index: openacs-4/packages/invoices/lib/offer-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/offer-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/offer-list.adp 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1 @@
+
Index: openacs-4/packages/invoices/lib/offer-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/offer-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/offer-list.tcl 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,177 @@
+set required_param_list [list]
+set optional_param_list [list orderby elements base_url package_id]
+set optional_unset_list [list organization_id]
+
+foreach required_param $required_param_list {
+ if {![info exists $required_param]} {
+ return -code error "$required_param is a required parameter."
+ }
+}
+
+foreach optional_param $optional_param_list {
+ if {![info exists $optional_param]} {
+ set $optional_param {}
+ }
+}
+
+foreach optional_unset $optional_unset_list {
+ if {[info exists $optional_unset]} {
+ if {[empty_string_p [set $optional_unset]]} {
+ unset $optional_unset
+ }
+ }
+}
+
+if {![info exists format]} {
+ set format "normal"
+}
+if {![info exists page_size]} {
+ set page_size "25"
+}
+
+if {[empty_string_p $package_id]} {
+ set package_id [apm_package_id_from_key "invoices"]
+}
+
+if {[empty_string_p $base_url]} {
+ set base_url [apm_package_url_from_id $package_id]
+}
+
+foreach element $elements {
+ append row_list "$element {}\n"
+}
+
+set dotlrn_club_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type "dotlrn_club"] 0]
+
+if {$dotlrn_club_id > 0} {
+ set pm_base_url [apm_package_url_from_id [dotlrn_community::get_package_id_from_package_key -package_key "project-manager" -community_id $dotlrn_club_id]]
+}
+
+#set package_id [ad_conn package_id]
+set date_format [lc_get formbuilder_date_format]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+if {[exists_and_not_null organization_id]} {
+ set price_list_id [iv::price_list::get_list_id -organization_id $organization_id]
+ set actions [list "[_ invoices.iv_offer_New]" [export_vars -base "${base_url}offer-ae" {organization_id}] "[_ invoices.iv_offer_New2]" "[_ invoices.iv_invoice_2]" [export_vars -base "${base_url}invoice-list" {organization_id}] "[_ invoices.iv_invoice_2]" "[_ invoices.iv_price_list]" [export_vars -base "${base_url}price_list" {{list_id $price_list_id}}] "[_ invoices.iv_display_price_list]"]
+ if {[exists_and_not_null pm_base_url]} {
+ lappend actions "[_ project-manager.Projects]" $pm_base_url "[_ project-manager.Projects]"
+ }
+} else {
+ set actions ""
+}
+
+template::list::create \
+ -name iv_offer \
+ -key offer_id \
+ -no_data "[_ invoices.None]" \
+ -selected_format $format \
+ -elements {
+ offer_nr {
+ label {[_ invoices.iv_offer_offer_nr]}
+ }
+ title {
+ label {[_ invoices.iv_offer_1]}
+ display_template {@iv_offer.title@}
+ }
+ description {
+ label {[_ invoices.iv_offer_Description]}
+ }
+ amount_total {
+ label {[_ invoices.iv_offer_amount_total]}
+ display_template {@iv_offer.amount_total@ @iv_offer.currency@}
+ }
+ creation_user {
+ label {[_ invoices.iv_offer_creation_user]}
+ display_template {@iv_offer.first_names@ @iv_offer.last_name@}
+ }
+ creation_date {
+ label {[_ invoices.iv_offer_creation_date]}
+ }
+ finish_date {
+ label {[_ invoices.iv_offer_finish_date]}
+ }
+ accepted_date {
+ label {[_ invoices.iv_offer_accepted_date]}
+ }
+ action {
+ display_template {#invoices.Edit# #invoices.Delete#}
+ }
+ } -actions $actions -sub_class narrow \
+ -orderby {
+ default_value offer_nr
+ offer_nr {
+ label {[_ invoices.iv_offer_offer_nr]}
+ orderby {t.offer_nr}
+ default_direction desc
+ }
+ title {
+ label {[_ invoices.iv_offer_1]}
+ orderby {lower(cr.title)}
+ default_direction asc
+ }
+ description {
+ label {[_ invoices.iv_offer_Description]}
+ orderby {lower(cr.description)}
+ default_direction asc
+ }
+ amount_total {
+ label {[_ invoices.iv_offer_amount_total]}
+ orderby {t.amount_total}
+ default_direction desc
+ }
+ creation_user {
+ label {[_ invoices.iv_offer_creation_user]}
+ orderby_desc {lower(p.last_name) desc, lower(p.first_names) desc}
+ orderby_asc {lower(p.last_name) asc, lower(p.first_names) asc}
+ default_direction asc
+ }
+ creation_date {
+ label {[_ invoices.iv_offer_creation_date]}
+ orderby {o.creation_date}
+ default_direction desc
+ }
+ finish_date {
+ label {[_ invoices.iv_offer_finish_date]}
+ orderby {t.finish_date}
+ default_direction desc
+ }
+ finish_date {
+ label {[_ invoices.iv_offer_accepted_date]}
+ orderby {t.accepted_date}
+ default_direction desc
+ }
+ } -orderby_name orderby -html {width 100%} \
+ -page_size_variable_p 1 \
+ -page_size $page_size \
+ -page_flush_p 0 \
+ -page_query_name iv_offer_paginated \
+ -filters {
+ organization_id {
+ where_clause {t.organization_id = :organization_id}
+ }
+ } \
+ -formats {
+ normal {
+ label "[_ invoices.Table]"
+ layout table
+ row $row_list
+ }
+ csv {
+ label "[_ invoices.CSV]"
+ output csv
+ page_size 0
+ row $row_list
+ }
+ }
+
+
+db_multirow -extend {creator_link edit_link delete_link title_link} iv_offer iv_offer {} {
+
+ # Ugly hack. We should find out which contact package is linked
+ # aso. asf.
+ set creator_link "/contacts/$creation_user"
+ set edit_link [export_vars -base "${base_url}offer-ae" {offer_id}]
+ set title_link [export_vars -base "${base_url}offer-ae" {offer_id {mode display}}]
+ set delete_link [export_vars -base "${base_url}offer-delete" {offer_id}]
+}
Index: openacs-4/packages/invoices/lib/offer-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/offer-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/offer-list.xql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+ select cr.item_id as offer_id, cr.title, cr.description,
+ t.offer_nr, t.amount_total, t.amount_sum, t.currency,
+ p.first_names, p.last_name, o.creation_user,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.accepted_date, :timestamp_format) as accepted_date,
+ to_char(t.finish_date, :timestamp_format) as finish_date
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_offers t,
+ acs_objects o, persons p
+ where cr.revision_id = ci.latest_revision
+ and t.offer_id = cr.revision_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ and o.object_id = t.offer_id
+ and p.person_id = o.creation_user
+ [template::list::filter_where_clauses -and -name iv_offer]
+ [template::list::orderby_clause -name iv_offer -orderby]
+
+
+
+
+
+
+
+ select cr.item_id as offer_id
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_offers t,
+ acs_objects o, persons p
+ where cr.revision_id = ci.latest_revision
+ and t.offer_id = cr.revision_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ and o.object_id = t.offer_id
+ and p.person_id = o.creation_user
+ [template::list::filter_where_clauses -and -name iv_offer]
+ [template::list::orderby_clause -name iv_offer -orderby]
+
+
+
+
+
+
Index: openacs-4/packages/invoices/lib/price-list-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/price-list-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/price-list-postgresql.xql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,20 @@
+
+
+ postgresql7.3
+
+
+
+
+ select coalesce(cn.name, cc.default_name) as currency_name
+ from cr_revisions r, cr_items i, iv_price_lists l, currencies cc
+ left outer join currency_names cn on (cc.codeA = cn.codeA
+ and cn.language_code = :language)
+ where r.revision_id = i.latest_revision
+ and i.item_id = :list_id
+ and l.list_id = r.revision_id
+ and cc.codeA = l.currency
+
+
+
+
+
Index: openacs-4/packages/invoices/lib/price-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/price-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/price-list.adp 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1 @@
+
Index: openacs-4/packages/invoices/lib/price-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/price-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/price-list.tcl 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,68 @@
+set package_id [ad_conn package_id]
+set language [lang::conn::language]
+db_1row currency_name {}
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+set actions [list "[_ invoices.iv_price_Edit]" [export_vars -base "price-ae" {list_id}] "[_ invoices.iv_price_Edit]"]
+
+template::list::create \
+ -name iv_price \
+ -key category_id \
+ -no_data "[_ invoices.None]" \
+ -pass_properties {list_id} \
+ -elements {
+ tree_name {
+ label {}
+ }
+ category_name {
+ label {[_ invoices.iv_price_category_id]}
+ display_template {@iv_price.category_name;noquote@}
+ }
+ amount {
+ label {[_ invoices.iv_price_amount]}
+ }
+ currency {
+ label {[_ invoices.iv_price_list_currency]}
+ }
+ } -actions $actions
+
+
+set category_list [list]
+foreach tree [category_tree::get_mapped_trees $container_objects(price_id)] {
+ util_unlist $tree tree_id tree_name subtree_id
+
+ foreach cat [category_tree::get_tree -all -subtree_id $subtree_id $tree_id] {
+ util_unlist $cat category_id category_name deprecated_p level
+
+ lappend category_list $category_id
+ set category_data($category_id) [list $tree_id $tree_name $category_name $level]
+ }
+}
+
+db_foreach all_prices {} {
+ if {[info exists category_data($category_id)]} {
+ lappend category_data($category_id) $amount
+ }
+}
+
+multirow create iv_price category_id tree_name category_name amount currency
+set old_tree_id ""
+
+foreach category_id $category_list {
+ util_unlist $category_data($category_id) tree_id tree_name category_name level amount
+
+ if {$old_tree_id == $tree_id} {
+ set tree_name ""
+ }
+ set old_tree_id $tree_id
+
+ if {$level > 1} {
+ set category_name "[string repeat " " [expr {2 * $level - 4}]]..$category_name"
+ }
+ if {[empty_string_p $amount]} {
+ set amount "0.00"
+ }
+ set amount [format "%.2f" $amount]
+
+ multirow append iv_price $category_id $tree_name $category_name $amount $currency_name
+}
Index: openacs-4/packages/invoices/lib/price-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/price-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/price-list.xql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ select p.category_id, p.amount
+ from iv_prices p, cr_items i
+ where p.list_id = :list_id
+ and p.price_id = i.latest_revision
+
+
+
+
+
Index: openacs-4/packages/invoices/lib/projects-billable.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/projects-billable.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/projects-billable.adp 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1 @@
+
Index: openacs-4/packages/invoices/lib/projects-billable.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/projects-billable.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/projects-billable.tcl 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,162 @@
+set required_param_list [list organization_id]
+set optional_param_list [list orderby elements base_url package_id]
+set optional_unset_list [list]
+
+foreach required_param $required_param_list {
+ if {![info exists $required_param]} {
+ return -code error "$required_param is a required parameter."
+ }
+}
+
+foreach optional_param $optional_param_list {
+ if {![info exists $optional_param]} {
+ set $optional_param {}
+ }
+}
+
+foreach optional_unset $optional_unset_list {
+ if {[info exists $optional_unset]} {
+ if {[empty_string_p [set $optional_unset]]} {
+ unset $optional_unset
+ }
+ }
+}
+
+foreach element $elements {
+ append row_list "$element {}\n"
+}
+
+if {![info exists format]} {
+ set format "normal"
+}
+if {![info exists orderby]} {
+ set orderby ""
+}
+if {![info exists page_size]} {
+ set page_size "25"
+}
+
+if {[empty_string_p $package_id]} {
+ set package_id [apm_package_id_from_key invoices]
+}
+
+if {[empty_string_p $base_url]} {
+ set base_url [apm_package_url_from_id $package_id]
+}
+
+set dotlrn_club_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type "dotlrn_club"] 0]
+set pm_base_url [apm_package_url_from_id [dotlrn_community::get_package_id_from_package_key -package_key "project-manager" -community_id $dotlrn_club_id]]
+
+set p_closed_id [pm::project::default_status_closed]
+set t_closed_id [pm::task::default_status_closed]
+set date_format [lc_get formbuilder_date_format]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+set currency [iv::price_list::get_currency -organization_id $organization_id]
+set contacts_url [apm_package_url_from_key contacts]
+
+set actions [list "[_ invoices.iv_invoice_New]" "${base_url}invoice-ae" "[_ invoices.iv_invoice_New2]" ]
+
+template::list::create \
+ -name projects \
+ -key project_id \
+ -no_data "[_ invoices.None]" \
+ -selected_format $format \
+ -pass_properties {currency} \
+ -elements {
+ project_id {
+ label {[_ invoices.iv_invoice_project_id]}
+ }
+ name {
+ label {[_ invoices.Customer]}
+ display_template {@projects.name@}
+ }
+ title {
+ label {[_ invoices.iv_invoice_project_title]}
+ display_template {@projects.title@}
+ }
+ description {
+ label {[_ invoices.iv_invoice_project_descr]}
+ }
+ amount_open {
+ label {[_ invoices.iv_invoice_amount_open]}
+ display_template {@projects.amount_open@ @currency@}
+ }
+ count_total {
+ label {[_ invoices.iv_invoice_count_total]}
+ }
+ count_billed {
+ label {[_ invoices.iv_invoice_count_billed]}
+ }
+ creation_date {
+ label {[_ invoices.iv_invoice_closed_date]}
+ }
+ } -bulk_actions $actions \
+ -bulk_action_export_vars {organization_id} \
+ -sub_class narrow \
+ -orderby {
+ default_value project_id
+ project_id {
+ label {[_ invoices.iv_invoice_project_id]}
+ orderby {r.item_id}
+ default_direction desc
+ }
+ title {
+ label {[_ invoices.iv_invoice_project_title]}
+ orderby_desc {lower(r.title) desc, r.item_id}
+ orderby_asc {lower(r.title) asc, r.item_id}
+ default_direction asc
+ }
+ description {
+ label {[_ invoices.iv_invoice_project_descr]}
+ orderby_desc {lower(r.description) desc, r.item_id}
+ orderby_asc {lower(r.description) asc, r.item_id}
+ default_direction asc
+ }
+ amount_open {
+ label {[_ invoices.iv_invoice_amount_open]}
+ orderby_desc {sub.amount_open desc, r.item_id}
+ orderby_asc {sub.amount_open asc, r.item_id}
+ default_direction desc
+ }
+ count_total {
+ label {[_ invoices.iv_invoice_count_total]}
+ orderby_desc {total.count_total desc, r.item_id}
+ orderby_asc {total.count_total asc, r.item_id}
+ default_direction desc
+ }
+ count_billed {
+ label {[_ invoices.iv_invoice_count_billed]}
+ orderby_desc {billed.count_billed desc, total.count_total desc, r.item_id}
+ orderby_asc {billed.count_billed asc, total.count_total asc, r.item_id}
+ default_direction desc
+ }
+ creation_date {
+ label {[_ invoices.iv_invoice_closed_date]}
+ orderby {sub.creation_date}
+ default_direction desc
+ }
+ } -orderby_name orderby -html {width 100%} \
+ -filters {
+ organization_id {
+ where_clause {sub.customer_id = :organization_id}
+ }
+ } \
+ -formats {
+ normal {
+ label "[_ invoices.Table]"
+ layout table
+ row $row_list
+ }
+ csv {
+ label "[_ invoices.CSV]"
+ output csv
+ page_size 0
+ row $row_list
+ }
+ }
+
+
+db_multirow -extend {project_link} projects projects_to_bill {} {
+ set project_link [export_vars -base "${pm_base_url}one" {{project_item_id $project_id}}]
+ set amount_open [format "%.2f" $amount_open]
+}
Index: openacs-4/packages/invoices/lib/projects-billable.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/lib/projects-billable.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/lib/projects-billable.xql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+ select r.item_id as project_id, r.title, r.description, sub.amount_open,
+ to_char(sub.creation_date, :timestamp_format) as creation_date, total.count_total, billed.count_billed, name
+ from (
+ select oi.item_id as offer_id, pr.revision_id, o.creation_date,
+ sum(ofi.item_units * ofi.price_per_unit * (1-(ofi.rebate/100))) as amount_open,
+ p.customer_id , (oz.name ) as name
+ from cr_items pi, cr_revisions pr, pm_projects p,
+ acs_objects o, acs_rels r, iv_offer_items ofi,
+ acs_objects oo, cr_items oi , organizations oz
+ where pi.latest_revision = pr.revision_id
+ and p.project_id = pr.revision_id
+ and o.object_id = p.project_id
+ and r.object_id_one = pi.item_id
+ and r.object_id_two = oi.item_id
+ and r.rel_type = 'application_data_link'
+ and p.status_id = :p_closed_id
+ and ofi.offer_id = oi.latest_revision
+ and oo.object_id = oi.item_id
+ and oo.package_id = :package_id
+ and p.customer_id = oz.organization_id
+ and not exists (select 1
+ from iv_invoice_items ii, iv_invoices i
+ where ii.offer_item_id = ofi.offer_item_id
+ and i.invoice_id = ii.invoice_id
+ and i.cancelled_p = 'f')
+ group by oi.item_id, pr.revision_id, o.creation_date, p.customer_id, oz.name
+ ) sub, (
+ select count(*) as count_total, oi.item_id
+ from cr_items oi, iv_offer_items ofi
+ where ofi.offer_id = oi.latest_revision
+ group by oi.item_id
+ ) total, (
+ select count(i.invoice_id) as count_billed, oi.item_id
+ from cr_items oi, iv_offer_items ofi
+ left outer join iv_invoice_items ii
+ on (ii.offer_item_id = ofi.offer_item_id)
+ left outer join iv_invoices i
+ on (ii.invoice_id = i.invoice_id
+ and i.cancelled_p = 'f')
+ where ofi.offer_id = oi.latest_revision
+ group by oi.item_id
+ ) billed, cr_revisions r
+ where r.revision_id = sub.revision_id
+ and total.item_id = sub.offer_id
+ and billed.item_id = sub.offer_id
+ [template::list::filter_where_clauses -and -name projects]
+ [template::list::orderby_clause -name projects -orderby]
+
+
+
+
+
Index: openacs-4/packages/invoices/sql/postgresql/invoices-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/invoices-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,302 @@
+--
+-- Invoices Package
+--
+-- @author Timo Hentschel (timo@timohentschel.de)
+-- @creation-date 2005-06-06
+--
+
+-- title, description
+-- linked organization
+
+create table iv_price_lists (
+ list_id integer
+ constraint iv_price_lists_pk
+ primary key
+ constraint iv_price_lists_id_fk
+ references cr_revisions,
+ currency char(3)
+ constraint iv_prices_currency_fk
+ references currencies(codeA)
+);
+
+create index iv_price_lists_currency_idx on iv_price_lists(currency);
+
+create table iv_prices (
+ price_id integer
+ constraint iv_prices_pk
+ primary key
+ constraint iv_prices_id_fk
+ references cr_revisions,
+ list_id integer
+ constraint iv_prices_list_fk
+ references cr_items,
+ category_id integer
+ constraint iv_prices_category_fk
+ references categories,
+ amount numeric(12,3)
+);
+
+-- categories: type, vat_type
+-- use general comments
+-- title, description
+
+create table iv_costs (
+ cost_id integer
+ constraint iv_costs_pk
+ primary key
+ constraint iv_costs_fk
+ references cr_revisions,
+ cost_nr varchar(400)
+ constraint iv_costs_nr_nn
+ not null,
+ -- Nr is a current number to provide a unique
+ -- identifier of cost item for backup/restore.
+ organization_id integer
+ constraint iv_costs_organization_nn
+ not null
+ constraint iv_costs_organization_fk
+ references organizations,
+ -- who pays?
+ cost_object_id integer
+ constraint im_costs_object_fk
+ references acs_objects,
+ -- reference to object that caused this cost
+ item_units numeric(12,1),
+ price_per_unit numeric(12,3),
+ currency char(3)
+ constraint iv_costs_currency_fk
+ references currencies(codeA),
+ apply_vat_p char(1) default 't'
+ constraint iv_costs_apply_vat_p
+ check (apply_vat_p in ('t','f')),
+ -- include in VAT calculation?
+ variable_cost_p char(1)
+ constraint iv_costs_var_ck
+ check (variable_cost_p in ('t','f'))
+ -- variable or fixed costs
+ -- A variable cost is calculated by multiplying
+ -- with logger units. A fixed cost a fixed single amount
+);
+
+create index iv_costs_object_idx on iv_costs(cost_object_id);
+create index iv_costs_organization_idx on iv_costs(organization_id);
+create index iv_costs_currency_idx on iv_costs(currency);
+
+create sequence iv_offer_seq start with 1000;
+
+create table iv_offers (
+ offer_id integer
+ constraint iv_offers_pk
+ primary key
+ constraint iv_offers_id_fk
+ references cr_revisions,
+ offer_nr varchar(80),
+ organization_id integer not null
+ constraint iv_offers_organization_fk
+ references organizations,
+ -- who pays?
+ comment text,
+ amount_total numeric(12,2),
+ amount_sum numeric(12,2),
+ currency char(3)
+ constraint iv_offers_currency_fk
+ references currencies(codeA),
+ finish_date timestamptz,
+ payment_days integer,
+ vat_percent numeric(12,5) default 0,
+ -- %VAT
+ vat numeric(12,2) default 0,
+ -- VAT amount
+ accepted_date timestamptz
+ -- offer accepted by customer?
+);
+
+-- offers are linked to a project via cr_items.parent_id
+-- if it's a preliminary offer, it's linked to the customer project
+-- if it's a final project, it's linked to the actual project
+
+create index iv_offers_organization_idx on iv_offers(organization_id);
+create index iv_offers_currency_idx on iv_offers(currency);
+create index iv_offers_finish_idx on iv_offers(finish_date);
+create index iv_offers_accepted_idx on iv_offers(accepted_date);
+
+create table iv_offer_items (
+ offer_item_id integer
+ constraint iv_offer_items_pk
+ primary key
+ constraint iv_offers_items_id_fk
+ references cr_revisions,
+ item_nr varchar(200),
+ offer_id integer not null
+ constraint iv_offer_items_offer_fk
+ references iv_offers,
+ comment text,
+ item_units numeric(12,1),
+ price_per_unit numeric(12,3),
+ rebate numeric(12,2),
+ file_count integer,
+ page_count integer,
+ sort_order integer,
+ vat numeric(12,3) default 0,
+ -- VAT amount
+ parent_item_id integer
+ constraint iv_offer_items_parent_fk
+ references iv_offer_items
+ -- Points to its parent
+);
+
+create index iv_offer_items_offer_idx on iv_offer_items(offer_id);
+create index iv_offer_items_sort_idx on iv_offer_items(sort_order);
+create index iv_offer_items_parent_idx on iv_offer_items(parent_item_id);
+
+-- linked file (for the real invoice)
+-- categories: payment_method
+-- title, description
+-- should we link organization here?
+
+create sequence iv_invoice_seq start with 1000;
+
+create table iv_invoices (
+ invoice_id integer
+ constraint iv_invoices_pk
+ primary key
+ constraint iv_invoices_id_fk
+ references cr_revisions,
+ invoice_nr varchar(80),
+ parent_invoice_id integer
+ constraint iv_invoices_parent_id_fk
+ references iv_invoices,
+ -- to reference a storno,
+ organization_id integer not null
+ constraint iv_invoices_organization_fk
+ references organizations,
+ -- who pays?
+ recipient_id integer not null
+ constraint iv_invoices_recipient_fk
+ references parties,
+ -- who receives invoice?
+ total_amount numeric(12,2),
+ amount_sum numeric(12,2),
+ currency char(3)
+ constraint iv_invoices_currency_fk
+ references currencies(codeA),
+ paid_amount numeric(12,2),
+ -- coming from table iv_payments
+ paid_currency char(3)
+ constraint iv_invoices_paid_currency_fk
+ references currencies(codeA),
+ due_date timestamptz,
+ payment_days integer,
+ vat_percent numeric(12,5) default 0,
+ -- %VAT
+ vat numeric(12,2) default 0,
+ -- VAT amount
+ cancelled_p char(1) default 'f'
+ constraint iv_invoices_cancelled_p
+ check (cancelled_p in ('t','f'))
+ -- is this invoice already cancelled?
+);
+
+create index iv_invoices_parent_idx on iv_invoices(parent_invoice_id);
+create index iv_invoices_organization_idx on iv_invoices(organization_id);
+create index iv_invoices_recipient_idx on iv_invoices(recipient_id);
+create index iv_invoices_currency_idx on iv_invoices(currency);
+create index iv_invoices_paid_currency_idx on iv_invoices(paid_currency);
+create index iv_invoices_due_idx on iv_invoices(due_date);
+
+-- linked project_item_id
+-- categories: type, status
+-- title, description
+
+create table iv_invoice_items (
+ iv_item_id integer
+ constraint iv_invoice_items_pk
+ primary key
+ constraint iv_invoice_items_id_fk
+ references cr_revisions,
+ item_nr varchar(200),
+ invoice_id integer not null
+ constraint iv_invoice_items_invoice_fk
+ references iv_invoices,
+ offer_item_id integer
+ constraint iv_invoice_items_offer_fk
+ references iv_offer_items,
+ item_units numeric(12,1),
+ price_per_unit numeric(12,3),
+ rebate numeric(12,2),
+ amount_total numeric(12,2),
+ sort_order integer,
+ vat numeric(12,3) default 0,
+ -- VAT amount
+ parent_item_id integer
+ constraint iv_invoice_items_parent_fk
+ references iv_invoice_items
+ -- Points to its parent
+);
+
+create index iv_invoice_items_invoice_idx on iv_invoice_items(invoice_id);
+create index iv_invoice_items_offer_idx on iv_invoice_items(offer_item_id);
+create index iv_invoice_items_parent_idx on iv_invoice_items(parent_item_id);
+
+-- categories type, status
+-- with general comments
+-- title, description
+-- should we link organization here?
+
+create table iv_payments (
+ payment_id integer not null
+ constraint iv_payments_pk
+ primary key
+ constraint iv_payments_id_fk
+ references cr_revisions,
+ invoice_id integer
+ constraint iv_payments_invoice_fk
+ references iv_invoices,
+ -- what is paid?
+ organization_id integer not null
+ constraint iv_payments_organization_fk
+ references organizations,
+ -- who pays?
+ received_date timestamptz,
+ amount numeric(12,2),
+ currency char(3)
+ constraint iv_payments_currency_fk
+ references currencies(codeA)
+);
+
+create index iv_payments_invoice_idx on iv_payments(invoice_id);
+create index iv_payments_organization_idx on iv_payments(organization_id);
+create index iv_payments_currency_idx on iv_payments(currency);
+create index iv_payments_date_idx on iv_payments(received_date);
+
+create table iv_default_objects (
+ package_id integer
+ constraint iv_default_objects_pk
+ primary key
+ constraint iv_default_objects_fk
+ references apm_packages,
+ list_id integer
+ constraint iv_default_objects_list_fk
+ references acs_objects,
+ price_id integer
+ constraint iv_default_objects_price_fk
+ references acs_objects,
+ cost_id integer
+ constraint iv_default_objects_cost_fk
+ references acs_objects,
+ offer_id integer
+ constraint iv_default_objects_offer_fk
+ references acs_objects,
+ offer_item_id integer
+ constraint iv_default_objects_offer_item_fk
+ references acs_objects,
+ invoice_id integer
+ constraint iv_default_objects_invoice_fk
+ references acs_objects,
+ invoice_item_id integer
+ constraint iv_default_objects_invoice_item_fk
+ references acs_objects,
+ payment_id integer
+ constraint iv_default_objects_payment_fk
+ references acs_objects
+);
Index: openacs-4/packages/invoices/sql/postgresql/invoices-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/invoices-drop.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/invoices-drop.sql 16 Aug 2005 20:04:31 -0000 1.1
@@ -0,0 +1,15 @@
+--
+-- Invoices Package
+--
+-- @author Timo Hentschel (timo@timohentschel.de)
+-- @creation-date 2005-06-06
+--
+
+
+drop table iv_default_objects;
+drop table iv_payments cascade;
+drop table iv_invoice_items cascade;
+drop table iv_invoices cascade;
+drop table iv_costs cascade;
+drop table iv_prices cascade;
+drop table iv_price_lists cascade;
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d1-0.01d2.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d1-0.01d2.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d1-0.01d2.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,68 @@
+create table iv_offers (
+ offer_id integer
+ constraint iv_offers_pk
+ primary key
+ constraint iv_offers_id_fk
+ references cr_revisions,
+ offer_nr varchar(80),
+ organization_id integer not null
+ constraint iv_offers_organization_fk
+ references organizations,
+ -- who pays?
+ amount_total numeric(12,2),
+ amount_sum numeric(12,2),
+ currency char(3)
+ constraint iv_offers_currency_fk
+ references currencies(codeA),
+ finish_date timestamptz,
+ payment_days integer,
+ vat_percent numeric(12,5) default 0,
+ -- %VAT
+ vat numeric(12,2) default 0,
+ -- VAT amount
+ accepted_p char(1) default 'f'
+ constraint iv_offers_accepted_p
+ check (accepted_p in ('t','f'))
+ -- offer accepted by customer?
+);
+
+-- offers are linked to a project via cr_items.parent_id
+-- if it's a preliminary offer, it's linked to the customer project
+-- if it's a final project, it's linked to the actual project
+
+create index iv_offers_organization_idx on iv_offers(organization_id);
+create index iv_offers_currency_idx on iv_offers(currency);
+
+create table iv_offer_items (
+ offer_item_id integer
+ constraint iv_offer_items_pk
+ primary key
+ constraint iv_offers_items_id_fk
+ references cr_revisions,
+ item_nr varchar(200),
+ offer_id integer not null
+ constraint iv_offer_items_offer_fk
+ references iv_offers,
+ item_units numeric(12,1),
+ price_per_unit numeric(12,3),
+ rebate numeric(12,2),
+ sort_order integer,
+ vat numeric(12,3) default 0,
+ -- VAT amount
+ parent_item_id integer
+ constraint iv_offer_items_parent_fk
+ references iv_offer_items
+ -- Points to its parent
+);
+
+create index iv_offer_items_offer_idx on iv_offer_items(offer_id);
+create index iv_offer_items_sort_idx on iv_offer_items(sort_order);
+create index iv_offer_items_parent_idx on iv_offer_items(parent_item_id);
+
+alter table iv_default_objects add column offer_id integer constraint iv_default_objects_offer_fk references acs_objects;
+
+alter table iv_default_objects add column offer_item_id integer constraint iv_default_objects_offer_item_fk references acs_objects;
+
+alter table iv_invoice_items add column offer_item_id integer constraint iv_invoice_items_offer_fk references iv_offer_items;
+
+create index iv_invoice_items_offer_idx on iv_invoice_items(offer_item_id);
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d2-0.01d3.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d2-0.01d3.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d2-0.01d3.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,6 @@
+alter table iv_offers add column accepted_date timestamptz;
+
+create index iv_offers_finish_idx on iv_offers(finish_date);
+create index iv_offers_accepted_idx on iv_offers(accepted_date);
+
+create index iv_invoices_due_idx on iv_invoices(due_date);
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d3-0.01d4.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d3-0.01d4.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d3-0.01d4.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,2 @@
+alter table iv_invoice_items add column rebate numeric(12,2);
+alter table iv_invoice_items add column amount_total numeric(12,2);
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d4-0.01d5.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d4-0.01d5.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d4-0.01d5.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,8 @@
+alter table iv_invoice_items add column file_count integer;
+alter table iv_invoice_items add column page_count integer;
+alter table iv_invoices add column cancelled_p char(1) constraint iv_invoices_cancelled_p check (cancelled_p in ('t','f'));
+alter table iv_invoices alter column cancelled_p set default 'f';
+update iv_invoices set cancelled_p = 'f';
+
+create sequence iv_offer_seq start with 1000;
+create sequence iv_invoice_seq start with 1000;
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d5-0.01d6.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d5-0.01d6.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d5-0.01d6.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,5 @@
+alter table iv_invoices add column amount_sum numeric(12,2);
+update iv_invoices set amount_sum = total_amount;
+
+alter table iv_invoices add column recipient_id integer constraint iv_invoices_recipient_fk references parties;
+create index iv_invoices_recipient_idx on iv_invoices(recipient_id);
Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d6-0.01d7.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d6-0.01d7.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-0.01d6-0.01d7.sql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,2 @@
+alter table iv_offers add column comment text;
+alter table iv_offer_items add column comment text;
Index: openacs-4/packages/invoices/tcl/cost-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/cost-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/cost-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,96 @@
+ad_library {
+ Cost procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::cost {}
+
+ad_proc -public iv::cost::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-cost_nr ""}
+ {-organization_id ""}
+ {-cost_object_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-currency ""}
+ {-apply_vat_p "t"}
+ {-variable_cost_p "t"}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Cost
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_cost_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_cost} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_cost} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list cost_nr $cost_nr] \
+ [list organization_id $organization_id] \
+ [list cost_object_id $cost_object_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list currency $currency] \
+ [list apply_vat_p $apply_vat_p] \
+ [list variable_cost_p $variable_cost_p] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::cost::edit {
+ -cost_item_id:required
+ {-title ""}
+ {-description ""}
+ {-cost_nr ""}
+ {-organization_id ""}
+ {-cost_object_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-currency ""}
+ {-apply_vat_p "t"}
+ {-variable_cost_p "t"}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Cost
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $cost_item_id \
+ -content_type {iv_cost} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list cost_nr $cost_nr] \
+ [list organization_id $organization_id] \
+ [list cost_object_id $cost_object_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list currency $currency] \
+ [list apply_vat_p $apply_vat_p] \
+ [list variable_cost_p $variable_cost_p] ] ]
+ }
+
+ return $new_rev_id
+}
+
Index: openacs-4/packages/invoices/tcl/invoice-item-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/invoice-item-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/invoice-item-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,103 @@
+ad_library {
+ Invoice Item procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::invoice_item {}
+
+ad_proc -public iv::invoice_item::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-item_nr ""}
+ {-invoice_id ""}
+ {-offer_item_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-rebate ""}
+ {-amount_total ""}
+ {-sort_order ""}
+ {-vat ""}
+ {-parent_item_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Invoice Item
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_invoice_item_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_invoice_item} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_invoice_item} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list item_nr $item_nr] \
+ [list invoice_id $invoice_id] \
+ [list offer_item_id $offer_item_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list rebate $rebate] \
+ [list amount_total $amount_total] \
+ [list sort_order $sort_order] \
+ [list vat $vat] \
+ [list parent_item_id $parent_item_id] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::invoice_item::edit {
+ -iv_item_item_id:required
+ {-title ""}
+ {-description ""}
+ {-item_nr ""}
+ {-invoice_id ""}
+ {-offer_item_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-rebate ""}
+ {-amount_total ""}
+ {-sort_order ""}
+ {-vat ""}
+ {-parent_item_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Invoice Item
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $iv_item_item_id \
+ -content_type {iv_invoice_item} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list item_nr $item_nr] \
+ [list invoice_id $invoice_id] \
+ [list offer_item_id $offer_item_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list rebate $rebate] \
+ [list amount_total $amount_total] \
+ [list sort_order $sort_order] \
+ [list vat $vat] \
+ [list parent_item_id $parent_item_id] ] ]
+ }
+
+ return $new_rev_id
+}
Index: openacs-4/packages/invoices/tcl/invoice-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/invoice-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/invoice-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,262 @@
+ad_library {
+ Invoice procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::invoice {}
+
+ad_proc -public iv::invoice::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-invoice_nr ""}
+ {-parent_invoice_id ""}
+ {-organization_id ""}
+ {-recipient_id ""}
+ {-total_amount ""}
+ {-amount_sum ""}
+ {-currency ""}
+ {-paid_amount ""}
+ {-paid_currency ""}
+ {-due_date ""}
+ {-payment_days ""}
+ {-vat_percent ""}
+ {-vat ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Invoice
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_invoice_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_invoice} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_invoice} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list invoice_nr $invoice_nr] \
+ [list parent_invoice_id $parent_invoice_id] \
+ [list organization_id $organization_id] \
+ [list recipient_id $recipient_id] \
+ [list total_amount $total_amount] \
+ [list amount_sum $amount_sum] \
+ [list currency $currency] \
+ [list paid_amount $paid_amount] \
+ [list paid_currency $paid_currency] \
+ [list due_date $due_date] \
+ [list payment_days $payment_days] \
+ [list vat_percent $vat_percent] \
+ [list vat $vat] \
+ [list cancelled_p f] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::invoice::edit {
+ -invoice_item_id:required
+ {-title ""}
+ {-description ""}
+ {-invoice_nr ""}
+ {-parent_invoice_id ""}
+ {-organization_id ""}
+ {-recipient_id ""}
+ {-total_amount ""}
+ {-amount_sum ""}
+ {-currency ""}
+ {-paid_amount ""}
+ {-paid_currency ""}
+ {-due_date ""}
+ {-payment_days ""}
+ {-vat_percent ""}
+ {-vat ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Invoice
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $invoice_item_id \
+ -content_type {iv_invoice} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list invoice_nr $invoice_nr] \
+ [list parent_invoice_id $parent_invoice_id] \
+ [list organization_id $organization_id] \
+ [list recipient_id $recipient_id] \
+ [list total_amount $total_amount] \
+ [list amount_sum $amount_sum] \
+ [list currency $currency] \
+ [list paid_amount $paid_amount] \
+ [list paid_currency $paid_currency] \
+ [list due_date $due_date] \
+ [list payment_days $payment_days] \
+ [list vat_percent $vat_percent] \
+ [list vat $vat] \
+ [list cancelled_p f] ] ]
+ }
+
+ return $new_rev_id
+}
+
+ad_proc -public iv::invoice::data {
+ -invoice_id:required
+ -invoice_array:required
+ -recipient_array:required
+ -item_multirow:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Create array and multirow in callers context with invoice data, invoice items
+} {
+ set package_id [ad_conn package_id]
+ set date_format [lc_get formbuilder_date_format]
+ set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+ upvar $invoice_array invoice
+ upvar $recipient_array recipient
+
+ # Get the invoice data
+ db_1row get_data {} -column_array invoice
+ set invoice(creator_name) "$invoice(first_names) $invoice(last_name)"
+ set invoice(vat_percent) [format "%.1f" $invoice(vat_percent)]
+ set invoice(vat) [format "%.2f" $invoice(vat)]
+ set invoice(amount_sum) [format "%.2f" $invoice(amount_sum)]
+ set invoice(amount_diff) [format "%.2f" [expr $invoice(total_amount) - $invoice(amount_sum)]]
+ set invoice(total_amount) [format "%.2f" $invoice(total_amount)]
+ set invoice(recipient_name) "$invoice(rep_first_names) $invoice(rep_last_name)"
+
+ # Get recipient information
+ set recipient(recipient_name) "$invoice(rep_first_names) $invoice(rep_last_name)"
+
+ db_multirow -upvar_level 1 -extend {amount_sum amount_total category} $item_multirow invoice_items {} {
+ set price_per_unit [format "%.2f" $price_per_unit]
+ set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]]
+ set amount_total [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]]
+ set rebate [format "%.1f" $rebate]
+ set category [lang::util::localize [category::get_name $category_id]]
+ }
+}
+
+ad_proc -public iv::invoice::parse_data {
+ -invoice_id:required
+ -recipient_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Create array and multirow in callers context with invoice data, invoice items
+} {
+ set package_id [ad_conn package_id]
+ set date_format [lc_get formbuilder_date_format]
+ set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+ # Get the invoice data
+ db_1row get_data {} -column_array invoice
+ set invoice(creator_name) "$invoice(first_names) $invoice(last_name)"
+ set invoice(vat_percent) [format "%.1f" $invoice(vat_percent)]
+ set invoice(vat) [format "%.2f" $invoice(vat)]
+ set invoice(amount_sum) [format "%.2f" $invoice(amount_sum)]
+ set invoice(amount_diff) [format "%.2f" [expr $invoice(total_amount) - $invoice(amount_sum)]]
+ set invoice(total_amount) [format "%.2f" $invoice(total_amount)]
+ set name [contact::name -party_id $recipient_id]
+ set first_names [lindex $name 0]
+ set last_name [lindex $name 1]
+ set rec_organization_id [contact::util::get_employee_organization -employee_id $invoice(recipient_id)]
+ set mailing_address [contact::message::mailing_address -party_id $rec_organization_id -format "text/html"]
+ set organization_name [contact::name -party_id $rec_organization_id]
+
+ db_multirow -local -extend {amount_sum amount_total category} invoice_items invoice_items {} {
+ set price_per_unit [format "%.2f" $price_per_unit]
+ set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]]
+ set amount_total [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]]
+ set rebate [format "%.1f" $rebate]
+ set category [lang::util::localize [category::get_name $category_id]]
+ }
+
+ set file [open "/web/document.html"]
+ fconfigure $file -translation binary
+ set content [read $file]
+
+
+ # parse template and replace placeholders
+ eval [template::adp_compile -string $content]
+ set final_content $__adp_output
+
+ return $final_content
+}
+
+ad_proc -public iv::invoice::text {
+ -invoice_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Generate invoice text
+} {
+ iv::invoice::data -invoice_id $invoice_id -invoice_array invoice -item_multirow invoice_items
+
+ set mail_text "
+ [_ invoices.iv_invoice_recipient]: $invoice(recipient_name)
+ [_ invoices.iv_invoice_Title]: $invoice(title)
+ [_ invoices.iv_invoice_Description]: $invoice(description)
+ [_ invoices.iv_invoice_invoice_nr]: $invoice(invoice_nr)
+ [_ invoices.iv_invoice_due_date]: $invoice(due_date)
+ [_ invoices.iv_invoice_payment_days]: $invoice(payment_days)
"
+
+ template::multirow foreach invoice_items {
+
+ set item_name "- $item_nr, $category
$title"
+ if {![empty_string_p $description]} {
+ append item_name " ("
+ if {![empty_string_p $page_count]} {
+ append item_name "$page_count [_ invoices.iv_offer_item_pages]; "
+ }
+ if {![empty_string_p $file_count]} {
+ append item_name "$file_count [_ invoices.iv_offer_item_files]; "
+ }
+ append item_name "$description)"
+ }
+ append item_name "
$item_units x $price_per_unit $invoice(currency) = $amount_sum $invoice(currency)"
+ if {$rebate > 0} {
+ append item_name " - $rebate% [_ invoices.iv_invoice_item_rebate] = $amount_total $invoice(currency)"
+ }
+ append item_name " \n"
+
+ append mail_text $item_name
+ }
+
+ append mail_text "
"
+
+ if {$invoice(amount_diff) < 0} {
+ append mail_text "
+ [_ invoices.iv_invoice_amount_sum]: $invoice(amount_sum) $invoice(currency)
+ [_ invoices.iv_invoice_amount_diff]: $invoice(amount_diff) $invoice(currency)
+ "
+ }
+
+ append mail_text "
+ [_ invoices.iv_invoice_total_amount]: $invoice(total_amount) $invoice(currency)
+ [_ invoices.iv_invoice_vat]: $invoice(vat) $invoice(currency) ($invoice(vat_percent)%)
+ "
+
+ return $mail_text
+}
Index: openacs-4/packages/invoices/tcl/invoice-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/invoice-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/invoice-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+ select t.invoice_id as invoice_rev_id, r.title, r.description,
+ t.invoice_nr, t.total_amount, t.vat, t.vat_percent,
+ o.creation_user, p.first_names, p.last_name, t.amount_sum,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.due_date, :timestamp_format) as due_date,
+ t.payment_days, t.currency, t.organization_id, t.recipient_id
+ from iv_invoices t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.invoice_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :invoice_id
+ and o.object_id = t.invoice_id
+ and p.person_id = o.creation_user
+
+
+
+
+
+
+
+ select r.title, r.description, r.item_id, ii.offer_item_id,
+ ii.item_units, ii.price_per_unit, ii.item_nr,
+ ii.rebate, ii.vat, m.category_id, ofi.file_count, ofi.page_count
+ from iv_offer_items ofi, cr_items oi, cr_revisions r,
+ category_object_map m, iv_invoice_items ii
+ where oi.latest_revision = ii.invoice_id
+ and r.revision_id = ii.iv_item_id
+ and oi.item_id = :invoice_id
+ and m.object_id = ofi.offer_item_id
+ and ofi.offer_item_id = ii.offer_item_id
+ order by ii.sort_order
+
+
+
+
+
+
+
+ select t.invoice_id as invoice_rev_id, r.title, r.description,
+ t.invoice_nr, t.total_amount, t.vat, t.vat_percent,
+ o.creation_user, p.first_names, p.last_name, t.amount_sum,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.due_date, :timestamp_format) as due_date,
+ t.payment_days, t.currency, t.organization_id, t.recipient_id
+ from iv_invoices t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.invoice_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :invoice_id
+ and o.object_id = t.invoice_id
+ and p.person_id = o.creation_user
+
+
+
+
+
+
+
+ select r.title, r.description, r.item_id, ii.offer_item_id,
+ ii.item_units, ii.price_per_unit, ii.item_nr,
+ ii.rebate, ii.vat, m.category_id, ofi.file_count, ofi.page_count
+ from iv_offer_items ofi, cr_items oi, cr_revisions r,
+ category_object_map m, iv_invoice_items ii
+ where oi.latest_revision = ii.invoice_id
+ and r.revision_id = ii.iv_item_id
+ and oi.item_id = :invoice_id
+ and m.object_id = ofi.offer_item_id
+ and ofi.offer_item_id = ii.offer_item_id
+ order by ii.sort_order
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,205 @@
+ad_library {
+ Invoices Package install callbacks
+
+ Procedures that deal with installing.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+ad_proc -public -callback pm::project_new -impl invoices {
+ {-package_id:required}
+ {-project_id:required}
+ {-data:required}
+} {
+ Set parent_id of offer to new project
+} {
+ array set callback_data $data
+ if {[info exists callback_data(offer_id)]} {
+ set offer_id $callback_data(offer_id)
+ application_data_link::new -this_object_id $offer_id -target_object_id $project_id
+ }
+}
+
+ad_proc -public -callback pm::task_close -impl invoices {
+ {-package_id:required}
+ {-task_id:required}
+} {
+ Create new cost every time a project task is closed
+} {
+ set task_rev_id [pm::task::get_revision_id -task_item_id $task_id]
+ set project_rev_id [pm::project::get_project_id -project_item_id [pm::task::project_item_id -task_item_id $task_id]]
+
+ db_1row task_data {
+ select r.title as task_title, r.description as task_description,
+ t.actual_hours_worked as amount, p.customer_id
+ from cr_revisions r, pm_tasks_revisions t, pm_projects p
+ where r.revision_id = :task_rev_id
+ and t.task_revision_id = r.revision_id
+ and p.project_id = :project_rev_id
+ }
+
+ foreach iv_package_id [application_link::get_linked -from_package_id $package_id -to_package_key "invoices"] {
+
+ array set price [iv::price::get -organization_id $customer_id -object_id $task_rev_id -package_id $iv_package_id]
+
+ if {![info exists price(currency)]} {
+ # no price entry found
+ set price(amount) 1
+ set price(currency) [parameter::get -parameter "DefaultCurrency" -default "EUR" -package_id $iv_package_id]
+ }
+
+ if {[empty_string_p $amount]} {
+ set amount 0
+ }
+
+ db_1row check_cost_exists {
+ select max(cr.item_id) as cost_id
+ from iv_costs c, cr_revisions cr, cr_revisions tr,
+ acs_objects o
+ where tr.item_id = :task_id
+ and tr.revision_id = c.cost_object_id
+ and c.cost_id = cr.revision_id
+ and o.object_id = c.cost_id
+ and o.package_id = :iv_package_id
+ }
+
+ if {[empty_string_p $cost_id]} {
+ # no cost entry found for this task
+ set new_cost_id [iv::cost::new \
+ -package_id $iv_package_id \
+ -title $task_title \
+ -description $task_description \
+ -cost_nr $task_id \
+ -organization_id $customer_id \
+ -cost_object_id $task_rev_id \
+ -item_units $amount \
+ -price_per_unit $price(amount) \
+ -currency $price(currency) ]
+ } else {
+ # create new revision of existing cost entry
+ set new_cost_id [iv::cost::edit \
+ -cost_item_id $cost_id \
+ -title $task_title \
+ -description $task_description \
+ -cost_nr $task_id \
+ -organization_id $customer_id \
+ -cost_object_id $task_rev_id \
+ -item_units $amount \
+ -price_per_unit $price(amount) \
+ -currency $price(currency) ]
+ }
+
+ array unset price
+ }
+}
+
+ad_proc -public -callback pm::project_links -impl invoices {
+ {-project_id:required}
+} {
+} {
+ upvar project_links project_links
+ set invoice_base_url [site_node::get_package_url -package_key invoices]
+ set offer_id [lindex [application_data_link::get_linked -from_object_id $project_id -to_object_type content_item] 0]
+
+ if {![empty_string_p $offer_id]} {
+ # link to linked offer
+ append project_links " [_ invoices.iv_offer_View]"
+ } else {
+ # link to offer-list
+ db_1row get_project_organization {
+ select p.customer_id as organization_id
+ from pm_projects p, cr_items i
+ where i.item_id = :project_id
+ and p.project_id = i.latest_revision
+ }
+
+ append project_links " [_ invoices.iv_offer_list]"
+ }
+}
+
+ad_proc -public -callback contacts::populate::organization::customer_attributes -impl invoices {
+ {-list_id:required}
+} {
+ register customer attributes payment_days, vat_percent
+} {
+ set attribute_id [attribute::new \
+ -object_type "organization" \
+ -attribute_name "payment_days" \
+ -datatype "number" \
+ -pretty_name "Payment after .. days" \
+ -pretty_plural "Payments after .. days" \
+ -if_does_not_exist]
+
+ ams::attribute::new \
+ -attribute_id $attribute_id \
+ -widget "select" \
+ -dynamic_p "t"
+
+ ams::list::attribute::map \
+ -list_id $list_id \
+ -attribute_id $attribute_id \
+ -sort_order "100" \
+ -required_p "f" \
+ -section_heading ""
+
+ set option_id [ams::option::new \
+ -attribute_id $attribute_id \
+ -option "30"]
+
+ set option_id [ams::option::new \
+ -attribute_id $attribute_id \
+ -option "60"]
+
+ set option_id [ams::option::new \
+ -attribute_id $attribute_id \
+ -option "90"]
+
+ set attribute_id [attribute::new \
+ -object_type "organization" \
+ -attribute_name "vat_percent" \
+ -datatype "number" \
+ -pretty_name "%VAT" \
+ -pretty_plural "%VAT" \
+ -if_does_not_exist]
+
+ ams::attribute::new \
+ -attribute_id $attribute_id \
+ -widget "select" \
+ -dynamic_p "t"
+
+ ams::list::attribute::map \
+ -list_id $list_id \
+ -attribute_id $attribute_id \
+ -sort_order "110" \
+ -required_p "f" \
+ -section_heading ""
+
+ set option_id [ams::option::new \
+ -attribute_id $attribute_id \
+ -option "7"]
+
+ set option_id [ams::option::new \
+ -attribute_id $attribute_id \
+ -option "16"]
+}
+
+ad_proc -public -callback pm::install::after_instantiate -impl invoices {
+ {-package_id:required}
+} {
+ link new project manager with invoices instance
+} {
+ if {[db_0or1row invoice_package_ids "select package_id as invoices_package_id from apm_packages where package_key = 'invoices'"]} {
+ application_link::new -this_package_id $package_id -target_package_id $invoices_package_id
+ }
+}
+
+ad_proc -public -callback contacts::after_instantiate -impl invoices {
+ {-package_id:required}
+} {
+ link new contacts with invoices instance
+} {
+ if {[db_0or1row invoice_package_ids "select package_id as invoices_package_id from apm_packages where package_key = 'invoices'"]} {
+ application_link::new -this_package_id $package_id -target_package_id $invoices_package_id
+ }
+}
Index: openacs-4/packages/invoices/tcl/iv-install-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/iv-install-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/iv-install-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,288 @@
+ad_library {
+ Invoices Package install callbacks
+
+ Procedures that deal with installing.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::install {}
+
+ad_proc -public iv::install::create_install {
+} {
+ Creates the content types and adds the attributes.
+} {
+ content::type::new -content_type {iv_price_list} -supertype {content_revision} -pretty_name {[_ invoices.Price_List]} -pretty_plural {[_ invoices.Price_Lists]} -table_name {iv_price_lists} -id_column {list_id}
+ content::type::new -content_type {iv_price} -supertype {content_revision} -pretty_name {[_ invoices.Price]} -pretty_plural {[_ invoices.Prices]} -table_name {iv_prices} -id_column {price_id}
+ content::type::new -content_type {iv_cost} -supertype {content_revision} -pretty_name {[_ invoices.Cost]} -pretty_plural {[_ invoices.Costs]} -table_name {iv_costs} -id_column {cost_id}
+ content::type::new -content_type {iv_offer} -supertype {content_revision} -pretty_name {[_ invoices.Offer]} -pretty_plural {[_ invoices.Offers]} -table_name {iv_offers} -id_column {offer_id}
+ content::type::new -content_type {iv_offer_item} -supertype {content_revision} -pretty_name {[_ invoices.Offer_Item]} -pretty_plural {[_ invoices.Offer_Items]} -table_name {iv_offer_items} -id_column {offer_item_id}
+ content::type::new -content_type {iv_invoice} -supertype {content_revision} -pretty_name {[_ invoices.Invoice]} -pretty_plural {[_ invoices.Invoices]} -table_name {iv_invoices} -id_column {invoice_id}
+ content::type::new -content_type {iv_invoice_item} -supertype {content_revision} -pretty_name {[_ invoices.Invoice_Item]} -pretty_plural {[_ invoices.Invoice_Items]} -table_name {iv_invoice_items} -id_column {iv_item_id}
+ content::type::new -content_type {iv_payment} -supertype {content_revision} -pretty_name {[_ invoices.Payment]} -pretty_plural {[_ invoices.Payments]} -table_name {iv_payments} -id_column {payment_id}
+
+ # Price List
+ content::type::attribute::new -content_type {iv_price_list} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+
+ # Price
+ content::type::attribute::new -content_type {iv_price} -attribute_name {list_id} -datatype {number} -pretty_name {[_ invoices.Price_list]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_price} -attribute_name {category_id} -datatype {number} -pretty_name {[_ invoices.Price_category]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_price} -attribute_name {amount} -datatype {number} -pretty_name {[_ invoices.Amount]} -column_spec {numeric(12,3)}
+
+ # Cost
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {cost_nr} -datatype {string} -pretty_name {[_ invoices.Cost_number]} -column_spec {varchar(400)}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {organization_id} -datatype {number} -pretty_name {[_ invoices.Customer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {cost_object_id} -datatype {number} -pretty_name {[_ invoices.Cost_cause]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {item_units} -datatype {number} -pretty_name {[_ invoices.Number_of_units]} -column_spec {numeric(12,1)}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {price_per_unit} -datatype {number} -pretty_name {[_ invoices.Price_per_unit]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {apply_vat_p} -datatype {boolean} -pretty_name {[_ invoices.Apply_VAT]} -column_spec {char(1)}
+ content::type::attribute::new -content_type {iv_cost} -attribute_name {variable_cost_p} -datatype {boolean} -pretty_name {[_ invoices.Fixed_cost]} -column_spec {char(1)}
+
+ # Offer
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {offer_nr} -datatype {string} -pretty_name {[_ invoices.Offer_number]} -column_spec {varchar(80)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {organization_id} -datatype {number} -pretty_name {[_ invoices.Customer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {comment} -datatype {text} -pretty_name {[_ invoices.Comment]} -column_spec {text}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {amount_total} -datatype {number} -pretty_name {[_ invoices.Amount_total]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {amount_sum} -datatype {number} -pretty_name {[_ invoices.Amount_sum]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {finish_date} -datatype {date} -pretty_name {[_ invoices.Finish_date]} -column_spec {timestamptz}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {payment_days} -datatype {number} -pretty_name {[_ invoices.Payment_after__days]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {vat_percent} -datatype {number} -pretty_name {[_ invoices.VAT]} -column_spec {numeric(12,5)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {accepted_date} -datatype {date} -pretty_name {[_ invoices.Accepted_date]} -column_spec {timestamptz}
+
+ # Offer Item
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {item_nr} -datatype {string} -pretty_name {[_ invoices.Offer_item_number]} -column_spec {varchar(200)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {offer_id} -datatype {number} -pretty_name {[_ invoices.Offer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {comment} -datatype {text} -pretty_name {[_ invoices.Comment]} -column_spec {text}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {item_units} -datatype {number} -pretty_name {[_ invoices.Number_of_units]} -column_spec {numeric(12,1)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {price_per_unit} -datatype {number} -pretty_name {[_ invoices.Price_per_unit]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {rebate} -datatype {number} -pretty_name {[_ invoices.Rebate]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {file_count} -datatype {number} -pretty_name {[_ invoices.File_count]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {page_count} -datatype {number} -pretty_name {[_ invoices.Page_count]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {sort_order} -datatype {number} -pretty_name {[_ invoices.Sort_order]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {parent_item_id} -datatype {number} -pretty_name {[_ invoices.Parent_offer_item]} -column_spec {integer}
+
+ # Invoice
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {invoice_nr} -datatype {string} -pretty_name {[_ invoices.Invoice_number]} -column_spec {varchar(80)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {parent_invoice_id} -datatype {number} -pretty_name {[_ invoices.Invoice_reference]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {organization_id} -datatype {number} -pretty_name {[_ invoices.Customer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {recipient_id} -datatype {number} -pretty_name {[_ invoices.Recipient]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {total_amount} -datatype {number} -pretty_name {[_ invoices.Total_amount]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {amount_sum} -datatype {number} -pretty_name {[_ invoices.Amount_sum]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {paid_amount} -datatype {number} -pretty_name {[_ invoices.Amount_paid]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {paid_currency} -datatype {string} -pretty_name {[_ invoices.Currency_paid]} -column_spec {char(3)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {due_date} -datatype {date} -pretty_name {[_ invoices.Due_date]} -column_spec {timestamptz}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {payment_days} -datatype {number} -pretty_name {[_ invoices.Payment_after__days]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {vat_percent} -datatype {number} -pretty_name {[_ invoices.VAT]} -column_spec {numeric(12,5)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {cancelled_p} -datatype {boolean} -pretty_name {[_ invoices.Cancelled]} -column_spec {char(1)}
+
+ # Invoice Item
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {item_nr} -datatype {string} -pretty_name {[_ invoices.Invoice_item_number]} -column_spec {varchar(200)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {invoice_id} -datatype {number} -pretty_name {[_ invoices.Invoice]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {offer_item_id} -datatype {number} -pretty_name {[_ invoices.Offer_item]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {item_units} -datatype {number} -pretty_name {[_ invoices.Number_of_units]} -column_spec {numeric(12,1)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {price_per_unit} -datatype {number} -pretty_name {[_ invoices.Price_per_unit]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {rebate} -datatype {number} -pretty_name {[_ invoices.Rebate]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {amount_total} -datatype {number} -pretty_name {[_ invoices.Amount_total]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {sort_order} -datatype {number} -pretty_name {[_ invoices.Sort_order]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {parent_item_id} -datatype {number} -pretty_name {[_ invoices.Parent_invoice_item]} -column_spec {integer}
+
+ # Payment
+ content::type::attribute::new -content_type {iv_payment} -attribute_name {invoice_id} -datatype {number} -pretty_name {[_ invoices.Invoice]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_payment} -attribute_name {organization_id} -datatype {number} -pretty_name {[_ invoices.Customer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_payment} -attribute_name {received_date} -datatype {date} -pretty_name {[_ invoices.Received_on]} -column_spec {timestamptz}
+ content::type::attribute::new -content_type {iv_payment} -attribute_name {amount} -datatype {number} -pretty_name {[_ invoices.Amount]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_payment} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+}
+
+ad_proc -public iv::install::package_instantiate {
+ -package_id:required
+} {
+ Define folders
+} {
+ # create a content folder
+ set folder_id [content::folder::new -name "invoices_$package_id" -package_id $package_id]
+ # register the allowed content types for a folder
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_price_list} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_price} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_cost} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_offer} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_offer_item} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_invoice} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_invoice_item} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_payment} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {content_revision} -include_subtypes f
+
+ set list_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Price Lists Default Object"]] acs_object]
+ set price_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Prices Default Object"]] acs_object]
+ set cost_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Costs Default Object"]] acs_object]
+ set offer_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Offers Default Object"]] acs_object]
+ set offer_item_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Offer Items Default Object"]] acs_object]
+ set invoice_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Invoices Default Object"]] acs_object]
+ set invoice_item_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Invoice Items Default Object"]] acs_object]
+ set payment_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Payments Default Object"]] acs_object]
+
+ iv::util::set_default_objects \
+ -package_id $package_id \
+ -list_id $list_id \
+ -price_id $price_id \
+ -cost_id $cost_id \
+ -offer_id $offer_id \
+ -offer_item_id $offer_item_id \
+ -invoice_id $invoice_id \
+ -invoice_item_id $invoice_item_id \
+ -payment_id $payment_id
+}
+
+ad_proc -public iv::install::after_upgrade {
+ {-from_version_name:required}
+ {-to_version_name:required}
+} {
+ apm_upgrade_logic \
+ -from_version_name $from_version_name \
+ -to_version_name $to_version_name \
+ -spec {
+ 0.01d1 0.01d2 {
+ content::type::new -content_type {iv_offer} -supertype {content_revision} -pretty_name {[_ invoices.Offer]} -pretty_plural {[_ invoices.Offers]} -table_name {iv_offers} -id_column {offer_id}
+ content::type::new -content_type {iv_offer_item} -supertype {content_revision} -pretty_name {[_ invoices.Offer_Item]} -pretty_plural {[_ invoices.Offer_Items]} -table_name {iv_offer_items} -id_column {offer_item_id}
+
+ # Offer
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {offer_nr} -datatype {string} -pretty_name {[_ invoices.Offer_number]} -column_spec {varchar(80)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {organization_id} -datatype {number} -pretty_name {[_ invoices.Customer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {amount_total} -datatype {number} -pretty_name {[_ invoices.Amount_total]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {amount_sum} -datatype {number} -pretty_name {[_ invoices.Amount_sum]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {finish_date} -datatype {date} -pretty_name {[_ invoices.Finish_date]} -column_spec {timestamptz}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {payment_days} -datatype {number} -pretty_name {[_ invoices.Payment_after__days]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {vat_percent} -datatype {number} -pretty_name {[_ invoices.VAT]} -column_spec {numeric(12,5)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {accepted_p} -datatype {boolean} -pretty_name {[_ invoices.Accepted]} -column_spec {char(1)}
+
+ # Offer Item
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {item_nr} -datatype {string} -pretty_name {[_ invoices.Offer_item_number]} -column_spec {varchar(200)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {offer_id} -datatype {number} -pretty_name {[_ invoices.Offer]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {item_units} -datatype {number} -pretty_name {[_ invoices.Number_of_units]} -column_spec {numeric(12,1)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {price_per_unit} -datatype {number} -pretty_name {[_ invoices.Price_per_unit]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {sort_order} -datatype {number} -pretty_name {[_ invoices.Sort_order]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {vat} -datatype {number} -pretty_name {[_ invoices.VAT_amount]} -column_spec {numeric(12,3)}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {parent_item_id} -datatype {number} -pretty_name {[_ invoices.Parent_offer_item]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {rebate} -datatype {number} -pretty_name {[_ invoices.Rebate]} -column_spec {numeric(12,2)}
+
+ # Invoice Item
+ content::type::attribute::delete -content_type {iv_invoice_item} -attribute_name {cost_id} -drop_column t
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {offer_item_id} -datatype {number} -pretty_name {[_ invoices.Offer_item]} -column_spec {integer}
+
+ foreach package_id [apm_package_id_from_key invoices] {
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_offer} -include_subtypes t
+ content::folder::register_content_type -folder_id $folder_id -content_type {iv_offer_item} -include_subtypes t
+
+ set offer_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Offers Default Object"]] acs_object]
+ set offer_item_id [package_instantiate_object -package_name acs_object -var_list [list [list new__context_id $package_id] [list new__package_id $package_id] [list new__title "Offer Items Default Object"]] acs_object]
+
+ db_dml update_default_objects {}
+ }
+ }
+ 0.01d2 0.01d3 {
+ content::type::attribute::delete -content_type {iv_offer} -attribute_name {accepted_p} -drop_column t
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {accepted_date} -datatype {date} -pretty_name {[_ invoices.Accepted_date]} -column_spec {timestamptz}
+ }
+ 0.01d3 0.01d4 {
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {rebate} -datatype {number} -pretty_name {[_ invoices.Rebate]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice_item} -attribute_name {amount_total} -datatype {number} -pretty_name {[_ invoices.Amount_total]} -column_spec {numeric(12,2)}
+ }
+ 0.01d4 0.01d5 {
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {file_count} -datatype {number} -pretty_name {[_ invoices.File_count]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {page_count} -datatype {number} -pretty_name {[_ invoices.Page_count]} -column_spec {integer}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {cancelled_p} -datatype {boolean} -pretty_name {[_ invoices.Cancelled]} -column_spec {char(1)}
+ }
+ 0.01d5 0.01d6 {
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {amount_sum} -datatype {number} -pretty_name {[_ invoices.Amount_sum]} -column_spec {numeric(12,2)}
+ content::type::attribute::new -content_type {iv_invoice} -attribute_name {recipient_id} -datatype {number} -pretty_name {[_ invoices.Recipient]} -column_spec {integer}
+ }
+ 0.01d6 0.01d7 {
+ content::type::attribute::new -content_type {iv_offer} -attribute_name {comment} -datatype {text} -pretty_name {[_ invoices.Comment]} -column_spec {text}
+ content::type::attribute::new -content_type {iv_offer_item} -attribute_name {comment} -datatype {text} -pretty_name {[_ invoices.Comment]} -column_spec {text}
+ }
+ }
+}
+
+ad_proc -public -callback pm::task_close -impl invoices {
+ {-package_id:required}
+ {-task_id:required}
+} {
+ Create new cost every time a project task is closed
+} {
+ set task_rev_id [pm::task::get_revision_id -task_item_id $task_id]
+ set project_rev_id [pm::project::get_project_id -project_item_id [pm::task::project_item_id -task_item_id $task_id]]
+
+ db_1row task_data {
+ select r.title as task_title, r.description as task_description,
+ t.actual_hours_worked as amount, p.customer_id
+ from cr_revisions r, pm_tasks_revisions t, pm_projects p
+ where r.revision_id = :task_rev_id
+ and t.task_revision_id = r.revision_id
+ and p.project_id = :project_rev_id
+ }
+
+ foreach iv_package_id [application_link::get_linked -from_package_id $package_id -to_package_key "invoices"] {
+
+ array set price [iv::price::get -organization_id $customer_id -object_id $task_rev_id -package_id $iv_package_id]
+
+ if {![info exists price(currency)]} {
+ # no price entry found
+ set price(amount) 1
+ set price(currency) [parameter::get -parameter "DefaultCurrency" -default "EUR" -package_id $iv_package_id]
+ }
+
+ if {![empty_string_p $amount]} {
+
+ db_1row check_cost_exists {
+ select max(cr.item_id) as cost_id
+ from iv_costs c, cr_revisions cr, cr_revisions tr,
+ acs_objects o
+ where tr.item_id = :task_id
+ and tr.revision_id = c.cost_object_id
+ and c.cost_id = cr.revision_id
+ and o.object_id = c.cost_id
+ and o.package_id = :iv_package_id
+ }
+
+ if {[empty_string_p $cost_id]} {
+ # no cost entry found for this task
+ set new_cost_id [iv::cost::new \
+ -package_id $iv_package_id \
+ -title $task_title \
+ -description $task_description \
+ -cost_nr $task_id \
+ -organization_id $customer_id \
+ -cost_object_id $task_rev_id \
+ -item_units $amount \
+ -price_per_unit $price(amount) \
+ -currency $price(currency) ]
+ } else {
+ # create new revision of existing cost entry
+ set new_cost_id [iv::cost::edit \
+ -cost_item_id $cost_id \
+ -title $task_title \
+ -description $task_description \
+ -cost_nr $task_id \
+ -organization_id $customer_id \
+ -cost_object_id $task_rev_id \
+ -item_units $amount \
+ -price_per_unit $price(amount) \
+ -currency $price(currency) ]
+ }
+ }
+
+ array unset price
+ }
+}
+
Index: openacs-4/packages/invoices/tcl/iv-install-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/iv-install-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/iv-install-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+ update iv_default_objects
+ set offer_id = :offer_id,
+ offer_item_id = :offer_item_id
+ where package_id = :package_id
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/offer-item-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/offer-item-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/offer-item-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,107 @@
+ad_library {
+ Offer Item procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-19
+}
+
+namespace eval iv::offer_item {}
+
+ad_proc -public iv::offer_item::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-comment ""}
+ {-item_nr ""}
+ {-offer_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-rebate ""}
+ {-file_count ""}
+ {-page_count ""}
+ {-sort_order ""}
+ {-vat ""}
+ {-parent_item_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-19
+
+ New Offer Item
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_offer_item_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_offer_item} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_offer_item} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list comment $comment] \
+ [list item_nr $item_nr] \
+ [list offer_id $offer_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list rebate $rebate] \
+ [list file_count $file_count] \
+ [list page_count $page_count] \
+ [list sort_order $sort_order] \
+ [list vat $vat] \
+ [list parent_item_id $parent_item_id] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::offer_item::edit {
+ -offer_item_id:required
+ {-title ""}
+ {-description ""}
+ {-comment ""}
+ {-item_nr ""}
+ {-offer_id ""}
+ {-item_units ""}
+ {-price_per_unit ""}
+ {-rebate ""}
+ {-file_count ""}
+ {-page_count ""}
+ {-sort_order ""}
+ {-vat ""}
+ {-parent_item_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-19
+
+ Edit Offer Item
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $offer_item_id \
+ -content_type {iv_offer_item} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list comment $comment] \
+ [list item_nr $item_nr] \
+ [list offer_id $offer_id] \
+ [list item_units $item_units] \
+ [list price_per_unit $price_per_unit] \
+ [list rebate $rebate] \
+ [list file_count $file_count] \
+ [list page_count $page_count] \
+ [list sort_order $sort_order] \
+ [list vat $vat] \
+ [list parent_item_id $parent_item_id] ] ]
+ }
+
+ return $new_rev_id
+}
Index: openacs-4/packages/invoices/tcl/offer-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/offer-procs-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/offer-procs-postgresql.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,18 @@
+
+
+
+ postgresql7.3
+
+
+
+
+ update iv_offers
+ set accepted_date = now()
+ where offer_id = (select latest_revision
+ from cr_items
+ where item_id = :offer_id)
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/offer-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/offer-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/offer-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,267 @@
+ad_library {
+ Offer procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-18
+}
+
+namespace eval iv::offer {}
+
+ad_proc -public iv::offer::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-comment ""}
+ {-offer_nr ""}
+ {-organization_id ""}
+ {-amount_total ""}
+ {-amount_sum ""}
+ {-currency ""}
+ {-finish_date ""}
+ {-payment_days ""}
+ {-vat_percent ""}
+ {-vat ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-18
+
+ New Offer
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_offer_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_offer} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_offer} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list comment $comment] \
+ [list offer_nr $offer_nr] \
+ [list organization_id $organization_id] \
+ [list amount_total $amount_total] \
+ [list amount_sum $amount_sum] \
+ [list currency $currency] \
+ [list finish_date $finish_date] \
+ [list payment_days $payment_days] \
+ [list vat_percent $vat_percent] \
+ [list vat $vat] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::offer::edit {
+ -offer_id:required
+ {-title ""}
+ {-description ""}
+ {-comment ""}
+ {-offer_nr ""}
+ {-organization_id ""}
+ {-amount_total ""}
+ {-amount_sum ""}
+ {-currency ""}
+ {-finish_date ""}
+ {-payment_days ""}
+ {-vat_percent ""}
+ {-vat ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-18
+
+ Edit Offer
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $offer_id \
+ -content_type {iv_offer} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list comment $comment] \
+ [list offer_nr $offer_nr] \
+ [list organization_id $organization_id] \
+ [list amount_total $amount_total] \
+ [list amount_sum $amount_sum] \
+ [list currency $currency] \
+ [list finish_date $finish_date] \
+ [list payment_days $payment_days] \
+ [list vat_percent $vat_percent] \
+ [list vat $vat] ] ]
+ }
+
+ return $new_rev_id
+}
+
+ad_proc -public iv::offer::accept {
+ -offer_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-19
+
+ Accept Offer
+} {
+ db_dml accept {}
+}
+
+ad_proc -public iv::offer::data {
+ -offer_id:required
+ -offer_array:required
+ -item_multirow:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Create array and multirow in callers context with offer data, offer items
+} {
+ set package_id [ad_conn package_id]
+ set date_format [lc_get formbuilder_date_format]
+ set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+ upvar $offer_array offer
+ db_1row get_data {} -column_array offer
+
+ set offer(creator_name) "$offer(first_names) $offer(last_name)"
+ set offer(vat_percent) [format "%.1f" $offer(vat_percent)]
+ set offer(vat) [format "%.2f" $offer(vat)]
+ set offer(amount_sum) [format "%.2f" $offer(amount_sum)]
+ set offer(amount_diff) [format "%.2f" [expr $offer(amount_total) - $offer(amount_sum)]]
+ set offer(amount_total) [format "%.2f" $offer(amount_total)]
+ set offer(offer_id) $offer_id
+
+ db_multirow -upvar_level 1 -extend {amount_sum amount_total category} $item_multirow offer_items {} {
+ set price_per_unit [format "%.2f" $price_per_unit]
+ set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]]
+ set amount_total [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]]
+ set rebate [format "%.1f" $rebate]
+ set category [lang::util::localize [category::get_name $category_id]]
+ }
+}
+
+ad_proc -public iv::offer::parse_data {
+ -offer_id:required
+ -recipient_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Create array and multirow in callers context with offer data, offer items
+} {
+ set package_id [ad_conn package_id]
+ set date_format [lc_get formbuilder_date_format]
+ set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+ db_1row get_data {} -column_array offer
+
+ set name [contact::name -party_id $recipient_id]
+ set first_names [lindex $name 0]
+ set last_name [lindex $name 1]
+ set mailing_address [contact::message::mailing_address -party_id $offer(organization_id) -format "text/html"]
+ set organization_name [contact::name -party_id $offer(organization_id)]
+ set offer(creator_name) "$offer(first_names) $offer(last_name)"
+ set offer(vat_percent) [format "%.1f" $offer(vat_percent)]
+ set offer(vat) [format "%.2f" $offer(vat)]
+ set offer(amount_sum) [format "%.2f" $offer(amount_sum)]
+ set offer(amount_diff) [format "%.2f" [expr $offer(amount_total) - $offer(amount_sum)]]
+ set offer(amount_total) [format "%.2f" $offer(amount_total)]
+ set offer(offer_id) $offer_id
+
+ db_multirow -local -extend {amount_sum amount_total category} offer_items offer_items {} {
+ set price_per_unit [format "%.2f" $price_per_unit]
+ set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]]
+ set amount_total [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]]
+ set rebate [format "%.1f" $rebate]
+ set category [lang::util::localize [category::get_name $category_id]]
+ }
+
+ set file [open "/web/document.html"]
+ fconfigure $file -translation binary
+ set content [read $file]
+
+
+ # parse template and replace placeholders
+ eval [template::adp_compile -string $content]
+ set final_content $__adp_output
+
+ return $final_content
+
+}
+
+ad_proc -public iv::offer::text {
+ -offer_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+
+ Generate offer text
+} {
+ iv::offer::data -offer_id $offer_id -offer_array offer -item_multirow offer_items
+
+ set mail_text "
+ [_ invoices.iv_offer_Title]: $offer(title)
+ [_ invoices.iv_offer_Description]: $offer(description)
+ [_ invoices.iv_offer_offer_nr]: $offer(offer_nr)
+ "
+
+ if {![empty_string_p $offer(finish_date)]} {
+ append mail_text "[_ invoices.iv_offer_finish_date]: $offer(finish_date)
"
+ }
+
+ if {![empty_string_p $offer(accepted_date)]} {
+ append mail_text "[_ invoices.iv_offer_accepted_date]: $offer(accepted_date)
"
+ }
+
+ append mail_text "[_ invoices.iv_offer_payment_days]: $offer(payment_days)
"
+
+ template::multirow foreach offer_items {
+
+ set item_name "- $item_nr, $category
$title"
+ set extra_descr {}
+ if {![empty_string_p $page_count]} {
+ append item_name "$page_count [_ invoices.iv_offer_item_pages]; "
+ }
+ if {![empty_string_p $file_count]} {
+ append item_name "$file_count [_ invoices.iv_offer_item_files]; "
+ }
+ if {![empty_string_p $description]} {
+ lappend extra_descr $description
+ }
+
+ if {![empty_string_p $extra_descr]} {
+ append item_name " ([join $extra_descr "; "])"
+ }
+
+ append item_name "
$item_units x $price_per_unit $offer(currency) = $amount_sum $offer(currency)"
+ if {$rebate > 0} {
+ append item_name " - $rebate% [_ invoices.iv_offer_item_rebate] = $amount_total $offer(currency)"
+ }
+ append item_name " \n"
+
+ append mail_text $item_name
+ }
+
+ append mail_text "
"
+
+ if {$offer(amount_diff) < 0} {
+ append mail_text "
+ [_ invoices.iv_offer_amount_sum]: $offer(amount_sum) $offer(currency)
+ [_ invoices.iv_offer_amount_diff]: $offer(amount_diff) $offer(currency)
+ "
+ }
+
+ append mail_text "
+ [_ invoices.iv_offer_amount_total]: $offer(amount_total) $offer(currency)
+ [_ invoices.iv_offer_vat]: $offer(vat) $offer(currency) ($offer(vat_percent)%)
+ "
+
+ return $mail_text
+}
Index: openacs-4/packages/invoices/tcl/offer-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/offer-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/offer-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+ select t.offer_id as offer_rev_id, r.title, r.description,
+ t.offer_nr, t.amount_total, t.vat, t.vat_percent, t.comment,
+ to_char(t.finish_date, 'YYYY-MM-DD HH24:MI:SS') as finish_ansi,
+ to_char(t.finish_date, :timestamp_format) as finish_date,
+ o.creation_user, p.first_names, p.last_name,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.accepted_date, :timestamp_format) as accepted_date,
+ t.amount_sum as amount_sum_, t.payment_days,
+ t.currency, t.organization_id, t.amount_sum
+ from iv_offers t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.offer_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :offer_id
+ and o.object_id = t.offer_id
+ and p.person_id = o.creation_user
+
+
+
+
+
+
+
+ select t.offer_id as offer_rev_id, r.title, r.description,
+ t.offer_nr, t.amount_total, t.vat, t.vat_percent, t.comment,
+ to_char(t.finish_date, 'YYYY-MM-DD HH24:MI:SS') as finish_ansi,
+ to_char(t.finish_date, :timestamp_format) as finish_date,
+ o.creation_user, p.first_names, p.last_name,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.accepted_date, :timestamp_format) as accepted_date,
+ t.amount_sum as amount_sum_, t.payment_days,
+ t.currency, t.organization_id, t.amount_sum
+ from iv_offers t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.offer_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :offer_id
+ and o.object_id = t.offer_id
+ and p.person_id = o.creation_user
+
+
+
+
+
+
+
+ select r.title, r.description, r.item_id, ofi.offer_item_id,
+ ofi.item_units, ofi.price_per_unit, ofi.item_nr, ofi.comment,
+ ofi.rebate, ofi.vat, m.category_id, ofi.file_count, ofi.page_count
+ from iv_offer_items ofi, cr_items oi, acs_objects o, cr_revisions r,
+ category_object_map m
+ where o.object_id = ofi.offer_id
+ and o.package_id = :package_id
+ and oi.latest_revision = ofi.offer_id
+ and r.revision_id = ofi.offer_item_id
+ and oi.item_id = :offer_id
+ and m.object_id = ofi.offer_item_id
+ order by ofi.sort_order
+
+
+
+
+
+
+
+ select r.title, r.description, r.item_id, ofi.offer_item_id,
+ ofi.item_units, ofi.price_per_unit, ofi.item_nr, ofi.comment,
+ ofi.rebate, ofi.vat, m.category_id, ofi.file_count, ofi.page_count
+ from iv_offer_items ofi, cr_items oi, acs_objects o, cr_revisions r,
+ category_object_map m
+ where o.object_id = ofi.offer_id
+ and o.package_id = :package_id
+ and oi.latest_revision = ofi.offer_id
+ and r.revision_id = ofi.offer_item_id
+ and oi.item_id = :offer_id
+ and m.object_id = ofi.offer_item_id
+ order by ofi.sort_order
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/payment-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/payment-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/payment-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,84 @@
+ad_library {
+ Payment procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::payment {}
+
+ad_proc -public iv::payment::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-invoice_id ""}
+ {-organization_id ""}
+ {-received_date ""}
+ {-amount ""}
+ {-currency ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Payment
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_payment_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_payment} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_payment} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list invoice_id $invoice_id] \
+ [list organization_id $organization_id] \
+ [list received_date $received_date] \
+ [list amount $amount] \
+ [list currency $currency] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::payment::edit {
+ -payment_item_id:required
+ {-title ""}
+ {-description ""}
+ {-invoice_id ""}
+ {-organization_id ""}
+ {-received_date ""}
+ {-amount ""}
+ {-currency ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Payment
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $payment_item_id \
+ -content_type {iv_payment} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list invoice_id $invoice_id] \
+ [list organization_id $organization_id] \
+ [list received_date $received_date] \
+ [list amount $amount] \
+ [list currency $currency] ] ]
+ }
+
+ return $new_rev_id
+}
+
Index: openacs-4/packages/invoices/tcl/price-list-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/price-list-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/price-list-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,107 @@
+ad_library {
+ Price List procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::price_list {}
+
+ad_proc -public iv::price_list::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-currency ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Price List
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_price_list_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_price_list} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_price_list} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list currency $currency] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::price_list::edit {
+ -list_item_id:required
+ {-title ""}
+ {-description ""}
+ {-currency ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Price List
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $list_item_id \
+ -content_type {iv_price_list} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list currency $currency] ] ]
+ }
+
+ return $new_rev_id
+}
+
+ad_proc -public iv::price_list::get_currency {
+ -organization_id:required
+ {-package_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-09
+
+ Get currency of customer
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+
+ if {[db_0or1row check_customer_price_list {}] || [db_0or1row check_default_price_list {}]} {
+ return $currency
+ } else {
+ return [parameter::get -parameter "DefaultCurrency" -default "EUR" -package_id $package_id]
+ }
+}
+
+ad_proc -public iv::price_list::get_list_id {
+ -organization_id:required
+ {-package_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-07-01
+
+ Get id of customer price list (or default)
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+
+ if {[db_0or1row check_customer_price_list {}] || [db_0or1row check_default_price_list {}]} {
+ return $list_id
+ } else {
+ return ""
+ }
+}
Index: openacs-4/packages/invoices/tcl/price-list-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/price-list-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/price-list-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+ select l.currency
+ from acs_objects o, acs_rels r, iv_price_lists l, cr_items li
+ where o.object_id = l.list_id
+ and o.package_id = :package_id
+ and l.list_id = li.latest_revision
+ and r.object_id_one = li.item_id
+ and r.object_id_two = :organization_id
+ and r.rel_type = 'application_data_link'
+
+
+
+
+
+
+
+ select l.currency
+ from acs_objects o, iv_price_lists l, cr_items li
+ where o.object_id = l.list_id
+ and o.package_id = :package_id
+ and l.list_id = li.latest_revision
+ and not exists (select 1
+ from acs_rels r, acs_objects o
+ where r.object_id_one = li.item_id
+ and r.object_id_two = o.object_id
+ and r.rel_type = 'application_data_link'
+ and o.object_type = 'organization')
+
+
+
+
+
+
+
+ select li.item_id as list_id
+ from acs_objects o, acs_rels r, iv_price_lists l, cr_items li
+ where o.object_id = l.list_id
+ and o.package_id = :package_id
+ and l.list_id = li.latest_revision
+ and r.object_id_one = li.item_id
+ and r.object_id_two = :organization_id
+ and r.rel_type = 'application_data_link'
+
+
+
+
+
+
+
+ select li.item_id as list_id
+ from acs_objects o, iv_price_lists l, cr_items li
+ where o.object_id = l.list_id
+ and o.package_id = :package_id
+ and l.list_id = li.latest_revision
+ and not exists (select 1
+ from acs_rels r, acs_objects o
+ where r.object_id_one = li.item_id
+ and r.object_id_two = o.object_id
+ and r.rel_type = 'application_data_link'
+ and o.object_type = 'organization')
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/price-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/price-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/price-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,96 @@
+ad_library {
+ Price procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::price {}
+
+ad_proc -public iv::price::new {
+ {-name ""}
+ {-package_id ""}
+ {-title ""}
+ {-description ""}
+ {-list_id ""}
+ {-category_id ""}
+ {-amount ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ New Price
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+ set folder_id [content::folder::get_folder_from_package -package_id $package_id]
+
+ db_transaction {
+ set item_id [db_nextval acs_object_id_seq]
+ if {[empty_string_p $name]} {
+ set name "iv_price_$item_id"
+ }
+ set item_id [content::item::new -parent_id $folder_id -content_type {iv_price} -name $name -package_id $package_id -item_id $item_id]
+
+ set new_id [content::revision::new \
+ -item_id $item_id \
+ -content_type {iv_price} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list list_id $list_id] \
+ [list category_id $category_id] \
+ [list amount $amount] ] ]
+ }
+
+ return $new_id
+}
+
+ad_proc -public iv::price::edit {
+ -price_item_id:required
+ {-title ""}
+ {-description ""}
+ {-list_id ""}
+ {-category_id ""}
+ {-amount ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Edit Price
+} {
+ db_transaction {
+ set new_rev_id [content::revision::new \
+ -item_id $price_item_id \
+ -content_type {iv_price} \
+ -title $title \
+ -description $description \
+ -attributes [list \
+ [list list_id $list_id] \
+ [list category_id $category_id] \
+ [list amount $amount] ] ]
+ }
+
+ return $new_rev_id
+}
+
+ad_proc -public iv::price::get {
+ {-organization_id:required}
+ {-object_id:required}
+ {-package_id ""}
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-07
+ @return array of amount and currency if price found
+
+ Get price for categories mapped to given object.
+ Use customer price list if available.
+} {
+ if {[empty_string_p $package_id]} {
+ set package_id [ad_conn package_id]
+ }
+
+ if {(![empty_string_p $organization_id] && [db_0or1row check_customer_price {} -column_array price]) || [db_0or1row check_default_price {} -column_array price]} {
+ return [array get price]
+ }
+}
Index: openacs-4/packages/invoices/tcl/price-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/price-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/price-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+ select p.amount, l.currency
+ from iv_prices p, cr_items pi, acs_objects o, acs_rels r,
+ iv_price_lists l, cr_items li, category_object_map cm
+ where p.price_id = pi.latest_revision
+ and cm.category_id = p.category_id
+ and cm.object_id = :object_id
+ and o.object_id = p.price_id
+ and o.package_id = :package_id
+ and p.list_id = li.item_id
+ and l.list_id = li.latest_revision
+ and r.object_id_one = li.item_id
+ and r.object_id_two = :organization_id
+ and r.rel_type = 'application_data_link'
+
+
+
+
+
+
+
+ select p.amount, l.currency
+ from iv_prices p, cr_items pi, acs_objects o, iv_price_lists l,
+ category_object_map cm, cr_items li
+ where p.price_id = pi.latest_revision
+ and cm.category_id = p.category_id
+ and cm.object_id = :object_id
+ and o.object_id = p.price_id
+ and o.package_id = :package_id
+ and p.list_id = li.item_id
+ and l.list_id = li.latest_revision
+ and not exists (select 1
+ from acs_rels r, acs_objects o
+ where r.object_id_one = li.item_id
+ and r.object_id_two = o.object_id
+ and r.rel_type = 'application_data_link'
+ and o.object_type = 'organization')
+
+
+
+
+
Index: openacs-4/packages/invoices/tcl/util-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/util-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/util-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,50 @@
+ad_library {
+ Util procs
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+}
+
+namespace eval iv::util {}
+
+ad_proc -public iv::util::get_default_objects {
+ -package_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Returns the cached array list of default objects to map category trees to.
+} {
+ return [util_memoize [list iv::util::get_default_objects_not_cached -package_id $package_id]]
+}
+
+ad_proc -private iv::util::get_default_objects_not_cached {
+ -package_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Returns the array list of default objects to map category trees to.
+} {
+ db_1row default_object {} -column_array objects
+
+ return [array get objects]
+}
+
+ad_proc -private iv::util::set_default_objects {
+ -package_id:required
+ -list_id:required
+ -price_id:required
+ -cost_id:required
+ -offer_id:required
+ -offer_item_id:required
+ -invoice_id:required
+ -invoice_item_id:required
+ -payment_id:required
+} {
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+
+ Inserts default objects to map category trees to.
+} {
+ db_dml set_default_objects {}
+}
Index: openacs-4/packages/invoices/tcl/util-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/tcl/util-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/tcl/util-procs.xql 16 Aug 2005 20:04:32 -0000 1.1
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+ select list_id, price_id, cost_id, offer_id, offer_item_id,
+ invoice_id, invoice_item_id, payment_id
+ from iv_default_objects
+ where package_id = :package_id
+
+
+
+
+
+
+
+ insert into iv_default_objects
+ (package_id, list_id, price_id, cost_id, offer_id,
+ offer_item_id, invoice_id, invoice_item_id, payment_id)
+ values
+ (:package_id, :list_id, :price_id, :cost_id, :offer_id,
+ :offer_item_id, :invoice_id, :invoice_item_id, :payment_id)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/index.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/index.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,14 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+ #invoices.admin#
+
+
+
+
Index: openacs-4/packages/invoices/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/index.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/index.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,18 @@
+ad_page_contract {
+ Index page.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set admin_p [permission::permission_p -object_id [ad_conn package_id] -privilege admin]
+
+set page_title "[_ invoices.invoices]"
+set context [list]
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-add.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-add.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-add.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,7 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/invoice-add.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-add.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-add.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,23 @@
+ad_page_contract {
+ Form to select projects to bill in a new Invoice.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-09
+} {
+ {format:optional "normal"}
+ {orderby:optional ""}
+ {page_size:optional 25}
+ {organization_id:integer}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set organization_name [organizations::name -organization_id $organization_id]
+set page_title "[_ invoices.iv_invoice_Add]"
+set context [list [list "invoice-list" "[_ invoices.iv_invoice_2]"] $page_title]
+
+set row_list {checkbox {} project_id {} title {} description {} amount_open {} count_total {} count_billed {} creation_date {}}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-ae-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-ae-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-ae-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,61 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
+
+
+ select sum(o.amount_sum - o.amount_total) as open_rebate
+ from iv_offers o, acs_rels r, cr_items co
+ where r.object_id_one in ([join $project_id ,])
+ and r.object_id_two = co.item_id
+ and r.rel_type = 'application_data_link'
+ and co.latest_revision = o.offer_id
+
+
+
+
+
+
+
+ select i.invoice_id, i.amount_sum - i.total_amount as given_rebate
+ from acs_rels r, cr_items co, iv_offer_items oi,
+ iv_invoice_items ii, iv_invoices i, cr_items ci
+ where i.invoice_id <> :invoice_rev_id
+ and i.parent_invoice_id is null
+ and ci.latest_revision = i.invoice_id
+ and i.invoice_id in (select ii.invoice_id
+ from iv_invoice_items ii, iv_offer_items oi,
+ cr_items co, acs_rels r
+ where oi.offer_id = co.latest_revision
+ and r.object_id_one in ([join $project_id ,])
+ and r.object_id_two = co.item_id
+ and r.rel_type = 'application_data_link'
+ and oi.offer_item_id = ii.offer_item_id)
+
+
+
+
+
+
+
+ select to_char(now(),'YYYY-MM-DD') from dual
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-ae.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-ae.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,315 @@
+ad_page_contract {
+ Form to add/edit Invoice.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ invoice_id:integer,optional
+ {organization_id:integer,optional ""}
+ {project_id:multiple,optional ""}
+ {offer_item_ids:array,optional}
+ {__new_p 0}
+ {mode edit}
+ {send:optional}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set date_format "YYYY-MM-DD"
+set has_submit 0
+set has_edit 0
+if {![info exists invoice_id] || $__new_p} {
+ set page_title "[_ invoices.iv_invoice_Add2]"
+ set _invoice_id 0
+ set invoice_rev_id 0
+ set cur_total_amount 0
+ set currency [iv::price_list::get_currency -organization_id $organization_id]
+} else {
+ db_1row get_organization_and_currencies {}
+ set cur_vat_percent [format "%.1f" $cur_vat_percent]
+ if {$cancelled_p == "t"} {
+ set has_edit 1
+ }
+ if {$mode == "edit" && ![info exists send]} {
+ if {![empty_string_p $paid_currency] || $cancelled_p == "t"} {
+ # do not allow to edit a paid invoice
+ ad_return_complaint 1 "[_ invoices.iv_invoice_edit_error]"
+ }
+ set page_title "[_ invoices.iv_invoice_Edit]"
+ } else {
+ set page_title "[_ invoices.iv_invoice_View]"
+ set has_submit 1
+ set date_format [lc_get formbuilder_date_format]
+ }
+ set _invoice_id [content::item::get_latest_revision -item_id $invoice_id]
+}
+
+if {[info exists send]} {
+ ad_returnredirect [export_vars -base invoice-send {organization_id invoice_id}]
+ ad_script_abort
+}
+
+set organization_name [organizations::name -organization_id $organization_id]
+set context [list [list "invoice-list" "[_ invoices.iv_invoice_2]"] [list [export_vars -base invoice-add {organization_id}] "[_ invoices.iv_invoice_Add]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+if {$_invoice_id} {
+ set project_id [db_list projects {}]
+}
+
+set language [lang::conn::language]
+set currency_options [db_list_of_lists currencies {}]
+
+if {[exists_and_not_null parent_invoice_id]} {
+ # cancellation: get recipients from parent invoice
+ set recipient_options [db_list_of_lists cancellation_recipients {}]
+} elseif {$cur_total_amount < 0} {
+ # credit: get recipients from organization
+ set recipient_options [db_list_of_lists credit_recipients {}]
+} else {
+ # normal invoice: get recipients from projects
+ set recipient_options [db_list_of_lists recipients {}]
+}
+
+
+ad_form -name iv_invoice_form -action invoice-ae -mode $mode -has_submit $has_submit -has_edit $has_edit -export {organization_id project_id} -form {
+ {invoice_id:key}
+ {organization_name:text(inform) {label "[_ invoices.iv_invoice_organization]"} {value $organization_name} {help_text "[_ invoices.iv_invoice_organization_help]"}}
+ {recipient_id:integer(select),optional {label "[_ invoices.iv_invoice_recipient]"} {options $recipient_options} {help_text "[_ invoices.iv_invoice_recipient_help]"}}
+ {title:text {label "[_ invoices.iv_invoice_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_invoice_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_invoice_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_invoice_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(invoice_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(invoice_id) -categorized_object_id $_invoice_id -form_name iv_invoice_form
+}
+
+ad_form -extend -name iv_invoice_form -form {
+ {invoice_nr:text {label "[_ invoices.iv_invoice_invoice_nr]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_invoice_invoice_nr_help]"}}
+}
+
+if {$has_submit} {
+ # we are just displaying an invoice
+ ad_form -extend -name iv_invoice_form -form {
+ {invoice_rebate:float {label "[_ invoices.iv_invoice_rebate]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_invoice_rebate_help2]"} {after_html $currency}}
+ {total_amount:integer,optional {label "[_ invoices.iv_invoice_total_amount]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_invoice_total_amount_help]"} {after_html $currency}}
+ {vat:float {label "[_ invoices.iv_invoice_vat]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_invoice_vat_help]"} {after_html "$currency ($cur_vat_percent%)"}}
+ }
+
+ if {![empty_string_p $paid_currency]} {
+ ad_form -extend -name iv_invoice_form -form {
+ {paid_amount:integer,optional {label "[_ invoices.iv_invoice_paid_amount]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_invoice_paid_amount_help]"} {after_html $paid_currency}}
+ }
+ }
+
+ ad_form -extend -name iv_invoice_form -form {
+ {creator_name:text,optional {label "[_ invoices.iv_invoice_creation_user]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_invoice_creation_user_help]"}}
+ {creation_date:text,optional {label "[_ invoices.iv_invoice_creation_date]"} {html {size 12 maxlength 10}} {help_text "[_ invoices.iv_invoice_creation_date_help]"}}
+ {due_date:text,optional {label "[_ invoices.iv_invoice_due_date]"} {html {size 12 maxlength 10}} {help_text "[_ invoices.iv_invoice_due_date_help]"}}
+ }
+
+} else {
+
+ # we are adding/editing data
+ ad_form -extend -name iv_invoice_form -form {
+ {currency:text(select) {mode display} {label "[_ invoices.iv_invoice_currency]"} {options $currency_options} {help_text "[_ invoices.iv_invoice_currency_help]"}}
+ {due_date:text,optional {label "[_ invoices.iv_invoice_due_date]"} {html {size 12 maxlength 10 id sel1}} {help_text "[_ invoices.iv_invoice_due_date_help]"} {after_html { \[y-m-d \]}}}
+ }
+}
+
+ad_form -extend -name iv_invoice_form -form {
+ {payment_days:integer,optional {label "[_ invoices.iv_invoice_payment_days]"} {html {size 5 maxlength 5}} {help_text "[_ invoices.iv_invoice_payment_days_help]"}}
+}
+
+if {!$has_submit} {
+ # we are adding/editing data
+ ad_form -extend -name iv_invoice_form -form {
+ {vat_percent:float {label "[_ invoices.iv_invoice_vat_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_invoice_vat_percent_help]"} {after_html {%}}}
+ }
+
+ db_1row get_open_rebate {}
+ if {$open_rebate > 0} {
+ set open_rebate [format "%.2f" $open_rebate]
+ ad_form -extend -name iv_invoice_form -form {
+ {invoice_rebate:float {label "[_ invoices.iv_invoice_rebate]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_invoice_rebate_help]"} {after_html $currency}}
+ }
+ }
+}
+
+if {!$_invoice_id} {
+ # adding a new invoice
+ if {![empty_string_p $project_id]} {
+ if {$__new_p} {
+ set project_id [string trim $project_id "{}"]
+ }
+
+ db_foreach offer_items {} -column_array offer {
+ set offer(price_per_unit) [format "%.2f" $offer(price_per_unit)]
+ set offer(amount_sum) [format "%.2f" [expr $offer(item_units) * $offer(price_per_unit)]]
+ set offer(amount) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(amount_sum)]]
+ set offer(rebate) [format "%.1f" $offer(rebate)]
+ set offer(category) [lang::util::localize [category::get_name $offer(category_id)]]
+
+ set offer_name "$offer(category): $offer(item_units) x $offer(price_per_unit) $currency = $offer(amount_sum) $currency"
+ if {$offer(rebate) > 0} {
+ append offer_name " - $offer(rebate)% [_ invoices.iv_offer_item_rebate] = $offer(amount) $currency"
+ }
+ if {![empty_string_p $offer(description)]} {
+ append offer_name " ($offer(description))"
+ }
+
+ set offers($offer(offer_item_id)) [array get offer]
+
+ ad_form -extend -name iv_invoice_form -form \
+ [list [list "offer_item_ids.${offer(offer_item_id)}:text(checkbox),optional" \
+ [list label "$offer(item_nr), $offer(title)"] \
+ [list options [list [list "$offer_name" t]]] \
+ [list values [list t]] \
+ [list section "$offer(project_id) $offer(project_title)"] ] ]
+ }
+ }
+} else {
+ # edit or display existing invoice
+ db_foreach invoice_items {} -column_array offer {
+ set offer(price_per_unit) [format "%.2f" $offer(price_per_unit)]
+ set offer(amount_sum) [format "%.2f" [expr $offer(item_units) * $offer(price_per_unit)]]
+ set offer(amount) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(amount_sum)]]
+ set offer(rebate) [format "%.1f" $offer(rebate)]
+ set offer(category) [lang::util::localize [category::get_name $offer(category_id)]]
+
+ set offer_name "$offer(category): $offer(item_units) x $offer(price_per_unit) $currency = $offer(amount_sum) $currency"
+ if {$offer(rebate) > 0} {
+ append offer_name " - $offer(rebate)% [_ invoices.iv_offer_item_rebate] = $offer(amount) $currency"
+ }
+ if {![empty_string_p $offer(description)]} {
+ append offer_name " ($offer(description))"
+ }
+
+ set offers($offer(iv_item_id)) [array get offer]
+
+ if {$mode == "edit"} {
+ # edit: use checkboxes
+ ad_form -extend -name iv_invoice_form -form \
+ [list [list "offer_item_ids.${offer(iv_item_id)}:text(checkbox)" \
+ [list label "$offer(item_nr), $offer(title)"] \
+ [list options [list [list "$offer_name" t]]] \
+ [list values [list t]] \
+ [list section "$offer(project_id) $offer(project_title)"] ] ]
+ } else {
+ # display: no checkboxes
+ ad_form -extend -name iv_invoice_form -form \
+ [list [list "offer_item_ids.${offer(iv_item_id)}:text(inform)" \
+ [list label "$offer(title), $offer(item_nr)"] \
+ [list value "$offer_name"] \
+ [list section "$offer(project_id) $offer(project_title)"] ] ]
+ }
+ }
+}
+
+if {$mode == "display"} {
+ ad_form -extend -name iv_invoice_form -form {
+ {send:text(submit) {label "[_ invoices.iv_invoice_send]"} {value t}}
+ }
+}
+
+
+ad_form -extend -name iv_invoice_form -new_request {
+ set description [join [db_list project_titles {}] ",\n"]
+ set due_date [db_string today {}]
+ set title "[_ invoices.iv_invoice_1] $organization_name $due_date"
+ set invoice_nr [db_nextval iv_invoice_seq]
+
+ db_1row offer_data {}
+ set vat_percent [format "%.1f" $vat_percent]
+ set invoice_rebate $open_rebate
+} -edit_request {
+ db_1row get_data {}
+ set creator_name "$first_names $last_name"
+ set vat_percent [format "%.1f" $vat_percent]
+ set vat [format "%.2f" $vat]
+ set total_amount [format "%.2f" $total_amount]
+ set invoice_rebate [format "%.2f" [expr $amount_sum - $total_amount]]
+ if {![empty_string_p $paid_amount]} {
+ set paid_amount [format "%.2f" $paid_amount]
+ }
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(invoice_id)]
+} -new_data {
+ db_transaction {
+ set total_amount 0.
+ foreach offer_item_id [array names offer_item_ids] {
+ array set offer $offers($offer_item_id)
+ set total_amount [expr $total_amount + $offer(amount)]
+ }
+ set total_amount [format "%.2f" $total_amount]
+ set amount_sum $total_amount
+ if {[exists_and_not_null invoice_rebate]} {
+ set total_amount [expr $total_amount - $invoice_rebate]
+ }
+ set total_amount [format "%.2f" $total_amount]
+ set vat [format "%.2f" [expr $total_amount * $vat_percent / 100.]]
+
+ set new_invoice_rev_id [iv::invoice::new \
+ -title $title \
+ -description $description \
+ -recipient_id $recipient_id \
+ -invoice_nr $invoice_nr \
+ -organization_id $organization_id \
+ -total_amount $total_amount \
+ -amount_sum $amount_sum \
+ -currency $currency \
+ -due_date $due_date \
+ -payment_days $payment_days \
+ -vat_percent $vat_percent \
+ -vat $vat]
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_invoice_rev_id $category_ids
+ }
+
+ set counter 0
+ foreach offer_item_id [array names offer_item_ids] {
+ incr counter
+ array set offer $offers($offer_item_id)
+ set offer(vat) [expr $vat_percent * $offer(vat) / 100.]
+
+ set new_item_rev_id [iv::invoice_item::new \
+ -invoice_id $new_invoice_rev_id \
+ -title $offer(title) \
+ -description $offer(description) \
+ -item_nr $offer(item_nr) \
+ -offer_item_id $offer_item_id \
+ -item_units $offer(item_units) \
+ -price_per_unit $offer(price_per_unit) \
+ -rebate $offer(rebate) \
+ -amount_total $offer(amount) \
+ -sort_order $counter \
+ -vat $offer(vat) ]
+ }
+ }
+} -edit_data {
+ db_transaction {
+ set new_invoice_rev_id [iv::invoice::edit \
+ -invoice_item_id $invoice_id \
+ -title $title \
+ -description $description \
+ -invoice_nr $invoice_nr \
+ -organization_id $organization_id \
+ -currency $currency \
+ -due_date $due_date \
+ -payment_days $payment_days \
+ -vat_percent $vat_percent ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_invoice_rev_id $category_ids
+ }
+ }
+} -after_submit {
+ ad_returnredirect [export_vars -base invoice-list {organization_id}]
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-ae.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,177 @@
+
+
+
+
+
+
+ select t.organization_id, t.currency, t.paid_currency,
+ t.vat_percent as cur_vat_percent, t.cancelled_p,
+ t.invoice_id as invoice_rev_id, t.parent_invoice_id,
+ t.total_amount as cur_total_amount
+ from iv_invoices t, cr_items i
+ where i.latest_revision = t.invoice_id
+ and i.item_id = :invoice_id
+
+
+
+
+
+
+
+ select cp.item_id
+ from cr_items ci, cr_items co, cr_items cp, iv_invoice_items ii,
+ iv_offer_items oi, pm_projects p, acs_rels r
+ where ci.item_id = :invoice_id
+ and ii.invoice_id = ci.latest_revision
+ and oi.offer_item_id = ii.offer_item_id
+ and oi.offer_id = co.latest_revision
+ and r.object_id_one = co.item_id
+ and r.object_id_two = cp.item_id
+ and r.rel_type = 'application_data_link'
+ and p.project_id = cp.latest_revision
+
+
+
+
+
+
+
+ select p.first_names || ' ' || p.last_name, p.person_id
+ from persons p, iv_invoices i
+ where i.invoice_id = :parent_invoice_id
+ and p.person_id = i.recipient_id
+ order by lower(p.last_name), lower(p.first_names)
+
+
+
+
+
+
+
+ select p.first_names || ' ' || p.last_name, p.person_id
+ from persons p, acs_rels r
+ where r.object_id_one = p.person_id
+ and r.object_id_two = :organization_id
+ and r.rel_type = 'contact_rels_ir'
+ order by lower(p.last_name), lower(p.first_names)
+
+
+
+
+
+
+
+ select p.first_names || ' ' || p.last_name, p.person_id
+ from persons p, pm_projects pj, cr_items i
+ where i.item_id in ([join $project_id ,])
+ and i.latest_revision = pj.project_id
+ and pj.recipient_id = p.person_id
+ order by lower(p.last_name), lower(p.first_names)
+
+
+
+
+
+
+
+ select cr.title, cr.description, ofi.offer_item_id, ofi.item_units,
+ ofi.price_per_unit, ofi.item_nr, pi.item_id as project_id,
+ pr.title as project_title, ofi.vat, ofi.rebate, m.category_id
+ from iv_offer_items ofi, cr_items oi, cr_revisions cr,
+ cr_items pi, cr_revisions pr, acs_objects o, acs_rels r,
+ category_object_map m
+ where o.object_id = ofi.offer_id
+ and o.package_id = :package_id
+ and oi.latest_revision = ofi.offer_id
+ and r.object_id_one = pi.item_id
+ and r.object_id_two = oi.item_id
+ and r.rel_type = 'application_data_link'
+ and pr.revision_id = pi.latest_revision
+ and pi.item_id in ([join $project_id ,])
+ and cr.revision_id = ofi.offer_item_id
+ and m.object_id = ofi.offer_item_id
+ and not exists (select 1
+ from iv_invoice_items ii, iv_invoices i
+ where ii.offer_item_id = ofi.offer_item_id
+ and i.invoice_id = ii.invoice_id
+ and i.cancelled_p = 'f')
+ order by pi.item_id, ofi.item_nr
+
+
+
+
+
+
+
+ select ir.title, ir.description, i.iv_item_id, i.item_units,
+ i.price_per_unit, i.item_nr, pi.item_id as project_id,
+ pr.title as project_title, i.vat as old_vat,
+ i.rebate, m.category_id
+ from cr_items oi, iv_offer_items ofi, iv_invoice_items i,
+ cr_revisions ir, cr_items pi, cr_revisions pr,
+ cr_items vi, cr_items ii, acs_rels r, category_object_map m
+ where oi.latest_revision = ofi.offer_id
+ and i.offer_item_id = ofi.offer_item_id
+ and i.iv_item_id = ir.revision_id
+ and ir.revision_id = ii.latest_revision
+ and i.invoice_id = vi.latest_revision
+ and vi.item_id = :invoice_id
+ and r.object_id_one = pi.item_id
+ and r.object_id_two = oi.item_id
+ and r.rel_type = 'application_data_link'
+ and pr.revision_id = pi.latest_revision
+ and m.object_id = ofi.offer_item_id
+ order by pi.item_id, i.item_nr
+
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where r.revision_id = i.latest_revision
+ and i.item_id in ([join $project_id ,])
+
+
+
+
+
+
+
+ select min(o.payment_days) as payment_days,
+ max(o.vat_percent) as vat_percent,
+ sum(o.vat) as vat,
+ sum(o.amount_total) as amount_total,
+ sum(o.amount_sum) as amount_sum
+ from iv_offers o, cr_items i, acs_rels r
+ where o.offer_id = i.latest_revision
+ and r.object_id_one in ([join $project_id ,])
+ and r.object_id_two = i.item_id
+ and r.rel_type = 'application_data_link'
+
+
+
+
+
+
+
+ select t.invoice_id as invoice_rev_id, r.title, r.description,
+ t.invoice_nr, t.parent_invoice_id, t.total_amount,
+ t.paid_amount, t.payment_days, t.vat, t.vat_percent,
+ to_char(t.due_date, :date_format) as due_date, t.amount_sum,
+ o.creation_user, p.first_names, p.last_name, t.recipient_id,
+ to_char(o.creation_date, :timestamp_format) as creation_date
+ from iv_invoices t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.invoice_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :invoice_id
+ and o.object_id = t.invoice_id
+ and p.person_id = o.creation_user
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-cancellation-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-cancellation-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-cancellation-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
+
+
+ select to_char(now(),'YYYY-MM-DD') from dual
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-cancellation.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-cancellation.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-cancellation.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-cancellation.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-cancellation.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-cancellation.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,95 @@
+ad_page_contract {
+ Form to add an invoice cancellation.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ invoice_id:integer,optional
+ {organization_id:integer,optional ""}
+ {parent_id:integer}
+ {__new_p 0}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set date_format "YYYY-MM-DD"
+
+set page_title "[_ invoices.iv_invoice_cancel_Add]"
+set _invoice_id 0
+set currency [iv::price_list::get_currency -organization_id $organization_id]
+set organization_name [organizations::name -organization_id $organization_id]
+
+set context [list [list "invoice-list" "[_ invoices.iv_invoice_2]"] [list [export_vars -base invoice-add {organization_id}] "[_ invoices.iv_invoice_Add]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+set language [lang::conn::language]
+set currency_options [db_list_of_lists currencies {}]
+set recipient_options [db_list_of_lists cancellation_recipients {}]
+
+
+ad_form -name iv_invoice_cancel_form -action invoice-cancellation -export {organization_id parent_id} -form {
+ {invoice_id:key}
+ {organization_name:text(inform) {label "[_ invoices.iv_invoice_organization]"} {value $organization_name} {help_text "[_ invoices.iv_invoice_organization_help]"}}
+ {recipient_id:integer(select),optional {label "[_ invoices.iv_invoice_recipient]"} {options $recipient_options} {help_text "[_ invoices.iv_invoice_recipient_help]"}}
+ {title:text {label "[_ invoices.iv_invoice_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_invoice_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_invoice_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_invoice_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(invoice_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(invoice_id) -categorized_object_id $_invoice_id -form_name iv_invoice_cancel_form
+}
+
+ad_form -extend -name iv_invoice_cancel_form -form {
+ {invoice_nr:text {label "[_ invoices.iv_invoice_invoice_nr]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_invoice_invoice_nr_help]"}}
+ {currency:text(select) {mode display} {label "[_ invoices.iv_invoice_currency]"} {options $currency_options} {help_text "[_ invoices.iv_invoice_currency_help]"}}
+ {due_date:text,optional {label "[_ invoices.iv_invoice_due_date]"} {html {size 12 maxlength 10 id sel1}} {help_text "[_ invoices.iv_invoice_due_date_help]"} {after_html { \[y-m-d \]}}}
+ {vat_percent:float(inform) {label "[_ invoices.iv_invoice_vat_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_invoice_vat_percent_help]"} {after_html {%}}}
+ {total_amount:float(inform),optional {label "[_ invoices.iv_invoice_total_amount]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_invoice_total_amount_help]"} {after_html $currency}}
+}
+
+ad_form -extend -name iv_invoice_cancel_form -new_request {
+ db_1row parent_invoice_data {}
+
+ set description ""
+ set due_date [db_string today {}]
+ set title "[_ invoices.iv_invoice_cancel_1] $parent_invoice_nr $organization_name $due_date"
+ set invoice_nr [db_nextval iv_invoice_seq]
+ set vat_percent [format "%.1f" $vat_percent]
+ set total_amount [format "%.2f" $total_amount]
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(invoice_id)]
+} -new_data {
+ db_transaction {
+ set total_amount [format "%.2f" [expr -1. * $total_amount]]
+ set vat [expr $total_amount * $vat_percent / 100.]
+ set vat [format "%.2f" $vat]
+
+ set new_invoice_rev_id [iv::invoice::new \
+ -parent_invoice_id $parent_id \
+ -title $title \
+ -description $description \
+ -invoice_nr $invoice_nr \
+ -organization_id $organization_id \
+ -recipient_id $recipient_id \
+ -total_amount $total_amount \
+ -currency $currency \
+ -due_date $due_date \
+ -vat_percent $vat_percent \
+ -vat $vat]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_invoice_rev_id $category_ids
+ }
+
+ db_dml mark_cancelled {}
+ }
+} -after_submit {
+ ad_returnredirect [export_vars -base invoice-list {organization_id}]
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-cancellation.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-cancellation.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-cancellation.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+ select p.first_names || ' ' || p.last_name, p.person_id
+ from persons p, iv_invoices i
+ where i.invoice_id = :parent_id
+ and p.person_id = i.recipient_id
+ order by lower(p.last_name), lower(p.first_names)
+
+
+
+
+
+
+
+ select vat_percent, total_amount, invoice_nr as parent_invoice_nr
+ from iv_invoices
+ where invoice_id = :parent_id
+
+
+
+
+
+
+
+ update iv_invoices
+ set cancelled_p = 't'
+ where invoice_id in (:parent_id, :new_invoice_rev_id)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-credit-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-credit-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-credit-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
+
+
+ select to_char(now(),'YYYY-MM-DD') from dual
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-credit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-credit.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-credit.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-credit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-credit.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-credit.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,97 @@
+ad_page_contract {
+ Form to add an invoice credit.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ invoice_id:integer,optional
+ {organization_id:integer,optional ""}
+ {__new_p 0}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set date_format "YYYY-MM-DD"
+
+set page_title "[_ invoices.iv_invoice_credit_Add]"
+set _invoice_id 0
+set currency [iv::price_list::get_currency -organization_id $organization_id]
+set organization_name [organizations::name -organization_id $organization_id]
+
+set context [list [list "invoice-list" "[_ invoices.iv_invoice_2]"] [list [export_vars -base invoice-add {organization_id}] "[_ invoices.iv_invoice_Add]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+set language [lang::conn::language]
+set currency_options [db_list_of_lists currencies {}]
+set recipient_options [db_list_of_lists credit_recipients {}]
+
+
+ad_form -name iv_invoice_credit_form -action invoice-credit -export {organization_id} -form {
+ {invoice_id:key}
+ {organization_name:text(inform) {label "[_ invoices.iv_invoice_organization]"} {value $organization_name} {help_text "[_ invoices.iv_invoice_organization_help]"}}
+ {recipient_id:integer(select),optional {label "[_ invoices.iv_invoice_recipient]"} {options $recipient_options} {help_text "[_ invoices.iv_invoice_recipient_help]"}}
+ {title:text {label "[_ invoices.iv_invoice_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_invoice_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_invoice_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_invoice_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(invoice_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(invoice_id) -categorized_object_id $_invoice_id -form_name iv_invoice_credit_form
+}
+
+ad_form -extend -name iv_invoice_credit_form -form {
+ {invoice_nr:text {label "[_ invoices.iv_invoice_invoice_nr]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_invoice_invoice_nr_help]"}}
+ {currency:text(select) {mode display} {label "[_ invoices.iv_invoice_currency]"} {options $currency_options} {help_text "[_ invoices.iv_invoice_currency_help]"}}
+ {due_date:text,optional {label "[_ invoices.iv_invoice_due_date]"} {html {size 12 maxlength 10 id sel1}} {help_text "[_ invoices.iv_invoice_due_date_help]"} {after_html { \[y-m-d \]}}}
+ {vat_percent:float {label "[_ invoices.iv_invoice_vat_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_invoice_vat_percent_help]"} {after_html {%}}}
+ {total_amount:float,optional {label "[_ invoices.iv_invoice_total_amount]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_invoice_total_amount_help]"} {after_html $currency}}
+}
+
+ad_form -extend -name iv_invoice_credit_form -new_request {
+ set description ""
+ set due_date [db_string today {}]
+ set title "[_ invoices.iv_invoice_credit_1] $organization_name $due_date"
+ set invoice_nr [db_nextval iv_invoice_seq]
+ set total_amount ""
+ set vat_percent "16.0"
+ # set contacts_package_id [lindex [application_link::get_linked -from_package_id $package_id -to_package_key contacts] 0]
+ # array set org_data [contacts::get_values \
+# -group_name "#acs-translation.Customers#" \
+# -object_type "organization" \
+# -party_id $organization_id \
+# -contacts_package_id $contacts_package_id]
+ # set vat_percent [format "%.1f" $org_data(vat_percent)]
+ set vat_percent [format "%.1f" $vat_percent]
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(invoice_id)]
+} -new_data {
+ db_transaction {
+ set total_amount [format "%.2f" [expr -1. * $total_amount]]
+ set vat [expr $total_amount * $vat_percent / 100.]
+ set vat [format "%.2f" $vat]
+
+ set new_invoice_rev_id [iv::invoice::new \
+ -title $title \
+ -description $description \
+ -invoice_nr $invoice_nr \
+ -organization_id $organization_id \
+ -recipient_id $recipient_id \
+ -total_amount $total_amount \
+ -currency $currency \
+ -due_date $due_date \
+ -vat_percent $vat_percent \
+ -vat $vat]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_invoice_rev_id $category_ids
+ }
+ }
+} -after_submit {
+ ad_returnredirect [export_vars -base invoice-list {organization_id}]
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-credit.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-credit.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-credit.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ select p.first_names || ' ' || p.last_name, p.person_id
+ from persons p, acs_rels r
+ where r.object_id_one = p.person_id
+ and r.object_id_two = :organization_id
+ and r.rel_type = 'contact_rels_ir'
+ order by lower(p.last_name), lower(p.first_names)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-delete.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-delete.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-delete.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-delete.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,34 @@
+ad_page_contract {
+ Delete Invoice.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ invoice_id
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_invoice_Delete]"
+set context [list [list "invoice-list" "[_ invoices.iv_invoice_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_delete]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name delete_confirm -action invoice-delete -form {
+ {invoice_id:key}
+ {title:text(inform) {label "[_ invoices.Delete]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ db_dml mark_deleted {}
+ }
+} -after_submit {
+ ad_returnredirect "invoice-list"
+ ad_script_abort
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/invoice-delete.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-delete.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-delete.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :invoice_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id = :invoice_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/invoice-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-list.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,7 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/invoice-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-list.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,22 @@
+ad_page_contract {
+ List of Invoices.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ {format:optional "normal"}
+ {orderby:optional ""}
+ {page_size:optional 25}
+ {organization_id:optional "1302"}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_invoice_2]"
+set context [list $page_title]
+
+set row_list {invoice_nr {} title {} description {} total_amount {} creation_user {} creation_date {} due_date {} action {}}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-send.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-send.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-send.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/invoice-send.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-send.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-send.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,51 @@
+ad_page_contract {
+ Form to send an invoice.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+} {
+ invoice_id:integer
+ {file_ids ""}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_invoice_send]"
+
+db_1row invoice_data {}
+
+set context [list [list [export_vars -base invoice-list {organization_id}] "[_ invoices.iv_invoice_2]"] [list [export_vars -base invoice-ae {invoice_id}] "[_ invoices.iv_invoice_View]"] $page_title]
+
+set invoice_text [iv::invoice::parse_data -invoice_id $invoice_id -recipient_id $recipient_id]
+
+if {$total_amount > 0} {
+ # send invoice
+ set invoice_text "{[_ invoices.iv_invoice_email]}"
+} elseif {[empty_string_p $parent_invoice_id]} {
+ # send credit
+ set invoice_text "{[_ invoices.iv_invoice_credit_email]}"
+} else {
+ # send cancellation
+ set invoice_text "{[_ invoices.iv_invoice_cancel_email]}"
+}
+
+set party_ids [contact::util::get_employees -organization_id $organization_id]
+set return_url [export_vars -base invoice-list {organization_id}]
+
+set parties_new [list]
+foreach party_id $party_ids {
+
+ # Check if the party has a valid e-mail address
+ if {![empty_string_p [cc_email_from_party $party_id]]} {
+ lappend parties_new $party_id
+ }
+}
+
+if {[empty_string_p $parties_new]} {
+ ad_return_error "No Recipient" "None of the recipients has a valid e-mail address. Please go back and make sure that you provide an e-mail address first."
+} else {
+ set party_ids $parties_new
+}
+ad_return_template
Index: openacs-4/packages/invoices/www/invoice-send.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-send.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/invoice-send.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ select i.invoice_nr, i.organization_id, i.parent_invoice_id,
+ i.total_amount, i.recipient_id
+ from iv_invoices i, cr_items ii
+ where ii.latest_revision = i.invoice_id
+ and ii.item_id = :invoice_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-accept-2.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept-2.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept-2.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,9 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/offer-accept-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept-2.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept-2.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,50 @@
+ad_page_contract {
+ Form to send an accepted offer.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+} {
+ offer_id:integer
+ {file_ids ""}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_offer_send]"
+
+db_1row offer_data {}
+
+set party_ids [contact::util::get_employees -organization_id $organization_id]
+
+set context [list [list [export_vars -base offer-list {organization_id}] "[_ invoices.iv_offer_2]"] [list [export_vars -base offer-ae {offer_id}] "[_ invoices.iv_offer_View]"] $page_title]
+
+# set offer_text [iv::offer::text -offer_id $offer_id]
+
+set offer_text [iv::offer::parse_data -offer_id $offer_id -recipient_id [lindex $party_ids 0]]
+
+set offer_text "{[_ invoices.iv_offer_accepted_email]}"
+
+
+set parties_new [list]
+foreach party_id $party_ids {
+
+ # Check if the party has a valid e-mail address
+ if {![empty_string_p [cc_email_from_party $party_id]]} {
+ lappend parties_new $party_id
+ }
+}
+
+if {[empty_string_p $parties_new]} {
+ ad_return_error "No Recipient" "None of the recipients has a valid e-mail address. Please go back and make sure that you provide an e-mail address first."
+} else {
+ set party_ids $parties_new
+}
+
+set cancel_url [export_vars -base offer-list {organization_id}]
+set invoice_url [site_node::get_package_url -package_key invoices]
+set return_url [export_vars -base "${invoice_url}offer-ae" {offer_id {mode display}}]
+set extra_data [list offer_id $offer_id]
+
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-accept-2.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept-2.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept-2.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ select o.offer_nr, o.organization_id
+ from iv_offers o, cr_items oi
+ where oi.latest_revision = o.offer_id
+ and oi.item_id = :offer_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-accept.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,7 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-accept.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,38 @@
+ad_page_contract {
+ Accept Offer.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+} {
+ offer_id
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_offer_accept]"
+set context [list [list "offer-list" "[_ invoices.iv_offer_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_accept]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name accept_confirm -action offer-accept -form {
+ {offer_id:key}
+ {title:text(inform) {label "[_ invoices.iv_offer_accept]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ iv::offer::accept -offer_id $offer_id
+ }
+} -after_submit {
+ if {$confirmation} {
+ ad_returnredirect [export_vars -base offer-accept-2 {offer_id}]
+ ad_script_abort
+ } else {
+ ad_returnredirect [export_vars -base offer-ae {offer_id {mode display}}]
+ ad_script_abort
+ }
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-accept.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-accept.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-accept.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :offer_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-ae-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-ae-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-ae-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
+
+
+ select to_char(now(),'YYYY-MM-DD') from dual
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-ae.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,69 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-ae.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,615 @@
+ad_page_contract {
+ Form to add/edit an offer.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ offer_id:integer,optional
+ {organization_id:integer,optional ""}
+ {item_nr:array,optional}
+ {item_title:array,optional}
+ {item_description:array,optional}
+ {item_files:array,optional}
+ {item_pages:array,optional}
+ {item_category:array,optional}
+ {item_units:array,optional}
+ {item_price:array,optional}
+ {item_rebate:array,optional}
+ {offer_item_id:array,optional}
+ {__new_p 0}
+ {mode edit}
+ {accept:optional}
+ {send:optional}
+ {send_accepted:optional}
+ {project_id:optional}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set date_format "YYYY-MM-DD"
+set has_submit 0
+set has_edit 0
+if {![info exists offer_id] || $__new_p} {
+ set page_title "[_ invoices.iv_offer_Add2]"
+ set _offer_id 0
+ set currency [iv::price_list::get_currency -organization_id $organization_id]
+} else {
+ db_1row get_organization_and_currencies {}
+ set cur_vat_percent [format "%.1f" $cur_vat_percent]
+ if {$mode == "edit"} {
+ db_1row check_invoices {}
+ if {$invoice_count>0 && ![info exists send]} {
+ # do not allow to edit an invoiced offer
+ ad_return_complaint 1 "[_ invoices.iv_offer_edit_error]"
+ }
+ set page_title "[_ invoices.iv_offer_Edit]"
+ } else {
+ set page_title "[_ invoices.iv_offer_View]"
+ set has_submit 1
+ set date_format [lc_get formbuilder_date_format]
+ set has_edit 1
+ }
+ set _offer_id [content::item::get_latest_revision -item_id $offer_id]
+}
+
+if {[info exists accept]} {
+ ad_returnredirect [export_vars -base offer-accept {organization_id offer_id}]
+ ad_script_abort
+}
+if {[info exists send]} {
+ ad_returnredirect [export_vars -base offer-send {organization_id offer_id}]
+ ad_script_abort
+}
+if {[info exists send_accepted]} {
+ ad_returnredirect [export_vars -base offer-accept-2 {offer_id}]
+ ad_script_abort
+}
+
+
+set organization_name [organizations::name -organization_id $organization_id]
+set context [list [list "[export_vars -base "offer-list" {organization_id}]" "[_ invoices.iv_offer_2]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+set timestamp_format "$date_format [lc_get formbuilder_time_format]"
+
+set language [lang::conn::language]
+set currency_options [db_list_of_lists currencies {}]
+
+set list_id [iv::price_list::get_list_id -organization_id $organization_id]
+db_multirow pricelist all_prices {}
+
+
+ad_form -name iv_offer_form -action offer-ae -mode $mode -has_submit $has_submit -has_edit $has_edit -export {organization_id} -form {
+ {offer_id:key}
+ {organization_namex:text(inform) {label "[_ invoices.iv_offer_organization]"} {value "$organization_name"} {help_text "[_ invoices.iv_offer_organization_help]"}}
+ {title:text {label "[_ invoices.iv_offer_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_offer_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_offer_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_offer_Description_help]"}}
+ {comment:text(textarea),optional {label "[_ invoices.iv_offer_comment]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_offer_comment_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(offer_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(offer_id) -categorized_object_id $_offer_id -form_name iv_offer_form
+}
+
+ad_form -extend -name iv_offer_form -form {
+ {offer_nr:text {label "[_ invoices.iv_offer_offer_nr]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_offer_offer_nr_help]"}}
+}
+
+if {$_offer_id} {
+ # we are editing/displaying data
+ set _project_id [lindex [application_data_link::get_linked -from_object_id $offer_id -to_object_type content_item] 0]
+}
+
+if {[exists_and_not_null _project_id]} {
+ # display linked project
+
+ db_1row get_project {}
+ set dotlrn_club_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type "dotlrn_club"] 0]
+ set pm_base_url [apm_package_url_from_id [dotlrn_community::get_package_id_from_package_key -package_key "project-manager" -community_id $dotlrn_club_id]]
+ set project_name "$project_name"
+
+ ad_form -extend -name iv_offer_form -form {
+ {project:text(inform),optional {label "[_ invoices.iv_offer_project]"} {value $project_name} {help_text "[_ invoices.iv_offer_project_help]"}}
+ }
+} elseif {!$has_submit} {
+ # let user assign project if not displaying data
+
+ set project_options [concat [list [list "" ""]] [db_list_of_lists open_projects {}]]
+ if {[llength $project_options] > 1} {
+ ad_form -extend -name iv_offer_form -form {
+ {project_id:text(select),optional {label "[_ invoices.iv_offer_project]"} {options $project_options} {help_text "[_ invoices.iv_offer_project_help]"}}
+ }
+ }
+}
+
+if {$has_submit} {
+ # we are just displaying an offer
+
+ ad_form -extend -name iv_offer_form -form {
+ {creator_name:text,optional {label "[_ invoices.iv_offer_creation_user]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_offer_creation_user_help]"}}
+ {creation_date:text,optional {label "[_ invoices.iv_offer_creation_date]"} {html {size 12 maxlength 10}} {help_text "[_ invoices.iv_offer_creation_date_help]"}}
+ {finish_date:text,optional {label "[_ invoices.iv_offer_finish_date]"} {html {size 12 maxlength 10}} {help_text "[_ invoices.iv_offer_finish_date_help]"}}
+ }
+
+ if {![empty_string_p $accepted_date]} {
+ ad_form -extend -name iv_offer_form -form {
+ {accepted_date:text,optional {label "[_ invoices.iv_offer_accepted_date]"} {html {size 12 maxlength 10}} {help_text "[_ invoices.iv_offer_accepted_date_help]"}}
+ }
+ }
+
+} else {
+ # we are adding/editing data
+
+ ad_form -extend -name iv_offer_form -form {
+ {currency:text(select) {mode display} {label "[_ invoices.iv_offer_currency]"} {options $currency_options} {help_text "[_ invoices.iv_offer_currency_help]"}}
+ {finish_date:text,optional {label "[_ invoices.iv_offer_finish_date]"} {html {size 12 maxlength 10 id sel1}} {help_text "[_ invoices.iv_offer_finish_date_help]"} {after_html { \[y-m-d \]}}}
+ {finish_time:date,optional {label "[_ invoices.iv_offer_finish_time]"} {format {[lc_get formbuilder_time_format]}} {help_text "[_ invoices.iv_offer_finish_time_help]"}}
+ }
+}
+
+ad_form -extend -name iv_offer_form -form {
+ {payment_days:integer,optional {label "[_ invoices.iv_offer_payment_days]"} {html {size 5 maxlength 5}} {help_text "[_ invoices.iv_offer_payment_days_help]"}}
+}
+
+if {!$has_submit} {
+ # we are adding/editing data
+ ad_form -extend -name iv_offer_form -form {
+ {vat_percent:float {label "[_ invoices.iv_offer_vat_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_offer_vat_percent_help]"} {after_html {%}}}
+ {amount_sum:float,optional {label "[_ invoices.iv_offer_amount_sum]"} {html {size 10 maxlength 10 disabled t}} {help_text "[_ invoices.iv_offer_amount_sum_help]"} {after_html $currency}}
+ {amount_total:float,optional {label "[_ invoices.iv_offer_amount_total]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_amount_total_help]"} {after_html $currency}}
+ }
+}
+
+
+if {$_offer_id} {
+ # edit or display existing offer
+ set i 0
+ set amount_sum 0.
+
+ db_foreach offer_items {} -column_array item {
+ incr i
+ set item(price_per_unit) [format "%.2f" $item(price_per_unit)]
+ set item(amount_sum) [format "%.2f" [expr $item(item_units) * $item(price_per_unit)]]
+ set item(amount_total) [format "%.2f" [expr (1. - ($item(rebate) / 100.)) * $item(amount_sum)]]
+ set item(rebate) [format "%.1f" $item(rebate)]
+ set item(category) [lang::util::localize [category::get_name $item(category_id)]]
+
+ set item_name "$item(category): $item(item_units) x $item(price_per_unit) $currency = $item(amount_sum) $currency"
+ if {$item(rebate) > 0} {
+ append item_name " - $item(rebate)% [_ invoices.iv_offer_item_rebate] = $item(amount_total) $currency"
+ }
+ set extra_descr {}
+ if {![empty_string_p $item(page_count)]} {
+ lappend extra_descr "$item(page_count) [_ invoices.iv_offer_item_pages]"
+ }
+ if {![empty_string_p $item(file_count)]} {
+ lappend extra_descr "$item(file_count) [_ invoices.iv_offer_item_files]"
+ }
+ if {![empty_string_p $item(description)]} {
+ lappend extra_descr $item(description)
+ }
+ if {![empty_string_p $item(comment)]} {
+ lappend extra_descr "$item(comment)"
+ }
+
+ if {![empty_string_p $extra_descr]} {
+ append item_name " ([join $extra_descr "; "])"
+ }
+
+ set amount_sum [expr $amount_sum + $item(amount_total)]
+
+ if {$mode == "edit"} {
+ # edit: use checkboxes
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "offer_item_id.${i}:text(hidden)" \
+ [list value $item(item_id)] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_nr.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_nr]"] \
+ [list html [list size 10 maxlength 10]] \
+ [list value $item(item_nr)] \
+ [list help_text "[_ invoices.iv_offer_item_nr_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_title.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_Title]"] \
+ [list html [list size 80 maxlength 1000]] \
+ [list value $item(title)] \
+ [list help_text "[_ invoices.iv_offer_item_Title_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_description.${i}:text(textarea),optional" \
+ [list label "[_ invoices.iv_offer_item_Description]"] \
+ [list html [list rows 5 cols 80]] \
+ [list value $item(description)] \
+ [list help_text "[_ invoices.iv_offer_item_Description_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_comment.${i}:text(textarea),optional" \
+ [list label "[_ invoices.iv_offer_item_comment]"] \
+ [list html [list rows 5 cols 80]] \
+ [list value $item(comment)] \
+ [list help_text "[_ invoices.iv_offer_item_comment_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_pages.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_page_count]"] \
+ [list html [list size 3 maxlength 3]] \
+ [list value $item(page_count)] \
+ [list help_text "[_ invoices.iv_offer_item_page_count_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_files.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_file_count]"] \
+ [list html [list size 3 maxlength 3]] \
+ [list value $item(file_count)] \
+ [list help_text "[_ invoices.iv_offer_item_file_count_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_category.${i}:text(category),optional" \
+ [list label "[_ invoices.iv_offer_item_category]"] \
+ [list value [list $item(offer_item_id) $container_objects(offer_item_id)]] \
+ [list help_text "[_ invoices.iv_offer_item_category_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_units.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_item_units]"] \
+ [list html [list size 5 maxlength 5 onChange calculateItemAmount(${i})]] \
+ [list value $item(item_units)] \
+ [list help_text "[_ invoices.iv_offer_item_item_units_help]"] \
+ [list after_html "[_ invoices.units]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_price.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_price_per_unit]"] \
+ [list html [list size 7 maxlength 7 onChange calculateItemAmount(${i})]] \
+ [list value $item(price_per_unit)] \
+ [list help_text "[_ invoices.iv_offer_item_price_per_unit_help]"] \
+ [list after_html $currency] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "amount_sum.${i}:float(inform)" \
+ [list label "[_ invoices.iv_offer_item_amount]"] \
+ [list html [list size 10 maxlength 10]] \
+ [list value $item(amount_sum)] \
+ [list help_text "[_ invoices.iv_offer_item_amount_help]"] \
+ [list after_html $currency] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_rebate.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_rebate]"] \
+ [list html [list size 5 maxlength 5 onChange calculateTotalAmount()]] \
+ [list value $item(rebate)] \
+ [list help_text "[_ invoices.iv_offer_item_rebate_help]"] \
+ [list after_html "%"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ } else {
+ # display: no checkboxes
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "offer_item_ids.${item(offer_item_id)}:text(inform)" \
+ [list label "$item(item_nr), $item(title)"] \
+ [list value "$item_name"] ] ]
+ }
+ }
+}
+
+if {!$has_submit} {
+ # adding/editing an offer
+
+ if {!$_offer_id} {
+ set start 1
+ } else {
+ incr i
+ set start $i
+ }
+
+ for {set i $start} {$i < [expr $start + 5] } {incr i} {
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_nr.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_nr]"] \
+ [list html [list size 10 maxlength 10]] \
+ [list value $i] \
+ [list help_text "[_ invoices.iv_offer_item_nr_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_title.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_Title]"] \
+ [list html [list size 80 maxlength 1000]] \
+ [list help_text "[_ invoices.iv_offer_item_Title_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_description.${i}:text(textarea),optional" \
+ [list label "[_ invoices.iv_offer_item_Description]"] \
+ [list html [list rows 5 cols 80]] \
+ [list help_text "[_ invoices.iv_offer_item_Description_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_comment.${i}:text(textarea),optional" \
+ [list label "[_ invoices.iv_offer_item_comment]"] \
+ [list html [list rows 5 cols 80]] \
+ [list help_text "[_ invoices.iv_offer_item_comment_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_pages.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_page_count]"] \
+ [list html [list size 3 maxlength 3]] \
+ [list help_text "[_ invoices.iv_offer_item_page_count_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_files.${i}:text,optional" \
+ [list label "[_ invoices.iv_offer_item_file_count]"] \
+ [list html [list size 3 maxlength 3]] \
+ [list help_text "[_ invoices.iv_offer_item_file_count_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_category.${i}:text(category),optional" \
+ [list label "[_ invoices.iv_offer_item_category]"] \
+ [list html [list onChange setItemPrice(${i})]] \
+ [list value [list 0 $container_objects(offer_item_id)]] \
+ [list help_text "[_ invoices.iv_offer_item_category_help]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_units.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_item_units]"] \
+ [list html [list size 5 maxlength 5 onChange calculateItemAmount(${i})]] \
+ [list help_text "[_ invoices.iv_offer_item_item_units_help]"] \
+ [list after_html "[_ invoices.units]"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_price.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_price_per_unit]"] \
+ [list html [list size 7 maxlength 7 onChange calculateItemAmount(${i})]] \
+ [list help_text "[_ invoices.iv_offer_item_price_per_unit_help]"] \
+ [list after_html $currency] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "amount_sum.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_amount]"] \
+ [list html [list size 10 maxlength 10 disabled t]] \
+ [list help_text "[_ invoices.iv_offer_item_amount_help]"] \
+ [list value "0.00"] \
+ [list after_html $currency] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ ad_form -extend -name iv_offer_form -form \
+ [list [list "item_rebate.${i}:float,optional" \
+ [list label "[_ invoices.iv_offer_item_rebate]"] \
+ [list html [list size 5 maxlength 5 onChange calculateTotalAmount()]] \
+ [list help_text "[_ invoices.iv_offer_item_rebate_help]"] \
+ [list value 0] \
+ [list after_html "%"] \
+ [list section "[_ invoices.iv_offer_item_1] $i"] ] ]
+ }
+}
+
+
+if {$has_submit} {
+ # we are just displaying an offer
+
+ if {$sum_total_diff < 0} {
+ ad_form -extend -name iv_offer_form -form {
+ {amount_sum:integer,optional {label "[_ invoices.iv_offer_amount_sum]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_amount_sum_help]"} {after_html $currency}}
+ {amount_diff:integer,optional {label "[_ invoices.iv_offer_amount_diff]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_amount_diff_help]"} {after_html $currency}}
+ }
+ }
+
+ ad_form -extend -name iv_offer_form -form {
+ {amount_total:float,optional {label "[_ invoices.iv_offer_amount_total]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_amount_total_help]"} {after_html $currency}}
+ {vat:float {label "[_ invoices.iv_offer_vat]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_offer_vat_help]"} {after_html "$currency ($cur_vat_percent%)"}}
+ }
+
+ if {[empty_string_p $accepted_date]} {
+ ad_form -extend -name iv_offer_form -form {
+ {accept:text(submit) {label "[_ invoices.iv_offer_accept]"} {value t}}
+ {send:text(submit) {label "[_ invoices.iv_offer_send]"} {value t}}
+ }
+ } else {
+ ad_form -extend -name iv_offer_form -form {
+ {send_accepted:text(submit) {label "[_ invoices.iv_offer_send_accepted]"} {value t}}
+ }
+ }
+}
+
+ad_form -extend -name iv_offer_form -new_request {
+ set description ""
+ set today [db_string today {}]
+ set finish_date ""
+ set finish_time ""
+ set title "[_ invoices.iv_offer_1] $organization_name $today"
+ set offer_nr [db_nextval iv_offer_seq]
+ set amount_sum "0.00"
+ set amount_total "0.00"
+
+ # get this from organization_id
+ set payment_days ""
+ set vat_percent "16.0"
+ # set contacts_package_id [lindex [application_link::get_linked -from_package_id $package_id -to_package_key contacts] 0]
+ # array set org_data [contacts::get_values \
+# -group_name "#acs-translation.Customers#" \
+# -object_type "organization" \
+# -party_id $organization_id \
+# -contacts_package_id $contacts_package_id]
+ # set payment_days $org_data(payment_days)
+ # set vat_percent [format "%.1f" $org_data(vat_percent)]
+} -edit_request {
+ db_1row get_data {}
+ set creator_name "$first_names $last_name"
+ set vat_percent [format "%.1f" $vat_percent]
+ set vat [format "%.2f" $vat]
+ if {$amount_total == 0} {
+ set amount_total $amount_sum
+ }
+
+ set amount_total [format "%.2f" $amount_total]
+
+ if {$has_submit} {
+ set amount_sum [format "%.2f" $amount_sum_]
+ set amount_diff [format "%.2f" [expr $amount_total - $amount_sum]]
+ } else {
+ set finish_time [template::util::date::from_ansi $finish_ansi [lc_get formbuilder_time_format]]
+ set finish_date [lindex $finish_date 0]
+ }
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(offer_id)]
+
+ set finish_date_list [split $finish_date "-"]
+ append finish_date_list " [lrange $finish_time 3 5]"
+
+ set item_sum 0.
+ foreach i [array names item_nr] {
+ if {[exists_and_not_null item_category($i)] && [exists_and_not_null item_units($i)]} {
+ set item(nr) $item_nr($i)
+ set item(title) $item_title($i)
+ set item(description) $item_description($i)
+ set item(comment) $item_comment($i)
+ set item(category) $item_category($i)
+ set item(units) $item_units($i)
+ set item(price) $item_price($i)
+ set item(rebate) $item_rebate($i)
+ set item(page_count) $item_pages($i)
+ set item(file_count) $item_files($i)
+
+ if {[empty_string_p $item(price)]} {
+ set item(sum) "0"
+ } else {
+ set item(sum) [expr $item(units) * $item(price)]
+ }
+ set item(total) [expr (1. - ($item(rebate)/100.)) * $item(sum)]
+ set item(vat) [expr $vat_percent * $item(total) / 100.]
+ set items($i) [array get item]
+
+ set item_sum [expr $item_sum + $item(total)]
+ }
+ }
+ if {[empty_string_p $amount_total]} {
+ set amount_total $amount_sum
+ }
+ set vat [format "%.2f" [expr $vat_percent * $amount_total / 100.]]
+ set item_sum [format "%.2f" $item_sum]
+
+} -new_data {
+ db_transaction {
+ if {[empty_string_p $amount_total]} {
+ set amount_total $amount_sum
+ }
+ set new_offer_rev_id [iv::offer::new \
+ -title $title \
+ -description $description \
+ -comment $comment \
+ -offer_nr $offer_nr \
+ -organization_id $organization_id \
+ -amount_total $amount_total \
+ -amount_sum $item_sum \
+ -currency $currency \
+ -finish_date $finish_date \
+ -payment_days $payment_days \
+ -vat_percent $vat_percent \
+ -vat $vat]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_offer_rev_id $category_ids
+ }
+
+ set counter 0
+ foreach i [array names items] {
+ incr counter
+ array set item $items($i)
+
+ set new_item_rev_id [iv::offer_item::new \
+ -offer_id $new_offer_rev_id \
+ -title $item(title) \
+ -description $item(description) \
+ -comment $item(comment) \
+ -item_nr $item(nr) \
+ -item_units $item(units) \
+ -price_per_unit $item(price) \
+ -rebate $item(rebate) \
+ -page_count $item(page_count) \
+ -file_count $item(file_count) \
+ -sort_order $counter \
+ -vat $item(vat) ]
+
+ category::map_object -object_id $new_item_rev_id $item(category)
+ }
+ set offer_id [pm::project::get_project_item_id -project_id $new_offer_rev_id]
+ }
+} -edit_data {
+ db_transaction {
+ set new_offer_rev_id [iv::offer::edit \
+ -offer_id $offer_id \
+ -title $title \
+ -description $description \
+ -comment $comment \
+ -offer_nr $offer_nr \
+ -organization_id $organization_id \
+ -amount_total $amount_total \
+ -amount_sum $item_sum \
+ -currency $currency \
+ -finish_date $finish_date \
+ -payment_days $payment_days \
+ -vat_percent $vat_percent \
+ -vat $vat]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_offer_rev_id $category_ids
+ }
+
+ set counter 0
+ foreach i [array names items] {
+ incr counter
+ array set item $items($i)
+
+ if {[info exists offer_item_id($i)]} {
+ # new revision of existing item
+ set new_item_rev_id [iv::offer_item::edit \
+ -offer_item_id $offer_item_id($i) \
+ -offer_id $new_offer_rev_id \
+ -title $item(title) \
+ -description $item(description) \
+ -comment $item(comment) \
+ -item_nr $item(nr) \
+ -item_units $item(units) \
+ -price_per_unit $item(price) \
+ -rebate $item(rebate) \
+ -page_count $item(page_count) \
+ -file_count $item(file_count) \
+ -sort_order $counter \
+ -vat $item(vat) ]
+ } else {
+ # add new item
+ set new_item_rev_id [iv::offer_item::new \
+ -offer_id $new_offer_rev_id \
+ -title $item(title) \
+ -description $item(description) \
+ -comment $item(comment) \
+ -item_nr $item(nr) \
+ -item_units $item(units) \
+ -price_per_unit $item(price) \
+ -rebate $item(rebate) \
+ -page_count $item(page_count) \
+ -file_count $item(file_count) \
+ -sort_order $counter \
+ -vat $item(vat) ]
+ }
+
+ category::map_object -object_id $new_item_rev_id $item(category)
+ }
+ }
+} -after_submit {
+ if {[exists_and_not_null project_id]} {
+ application_data_link::new -this_object_id $offer_id -target_object_id $project_id
+ }
+ if {![empty_string_p $finish_date]} {
+ db_dml set_finish_date {
+ update iv_offers
+ set finish_date = to_timestamp(:finish_date_list,'YYYY MM DD HH24 MI SS')
+ where offer_id = :new_offer_rev_id
+ }
+ }
+
+ ad_returnredirect [export_vars -base offer-ae {offer_id {mode display}}]
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-ae.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+ select t.organization_id, t.currency, t.accepted_date,
+ t.vat_percent as cur_vat_percent, t.offer_id as offer_rev_id,
+ (t.amount_total - t.amount_sum) as sum_total_diff
+ from iv_offers t, cr_items i
+ where i.latest_revision = t.offer_id
+ and i.item_id = :offer_id
+
+
+
+
+
+
+
+ select count(*) as invoice_count
+ from iv_invoice_items ii, iv_offer_items oi
+ where ii.offer_item_id = oi.offer_item_id
+ and oi.offer_id = :offer_rev_id
+
+
+
+
+
+
+
+ select '#' || r.item_id || ' ' || r.title as title, r.item_id
+ from cr_revisions r, cr_items i, pm_projects p, acs_rels ar
+ where ar.object_id_one = :organization_id
+ and ar.object_id_two = r.revision_id
+ and ar.rel_type = 'application_data_link'
+ and i.latest_revision = r.revision_id
+ and p.project_id = r.revision_id
+ and i.item_id not in (select ar2.object_id_one
+ from acs_rels ar2, cr_items oi, iv_offers o
+ where ar2.object_id_two = oi.item_id
+ and ar2.rel_type = 'application_data_link'
+ and oi.latest_revision = o.offer_id)
+ order by r.item_id desc
+
+
+
+
+
+
+
+ select p.category_id, p.amount
+ from iv_prices p, cr_items i
+ where p.list_id = :list_id
+ and p.price_id = i.latest_revision
+
+
+
+
+
+
+
+ select '#' || r.item_id || ' ' || r.title as project_name, r.item_id
+ from cr_revisions r, cr_items i, pm_projects p, acs_rels ar
+ where ar.object_id_one = :offer_id
+ and ar.object_id_two = i.item_id
+ and ar.rel_type = 'application_data_link'
+ and i.latest_revision = r.revision_id
+ and p.project_id = r.revision_id
+
+
+
+
+
+
+
+ select r.title, r.description, r.item_id, ofi.offer_item_id,
+ ofi.item_units, ofi.price_per_unit, ofi.item_nr, ofi.comment,
+ ofi.rebate, ofi.vat, m.category_id, ofi.file_count, ofi.page_count
+ from iv_offer_items ofi, cr_items oi, acs_objects o, cr_revisions r,
+ category_object_map m
+ where o.object_id = ofi.offer_id
+ and o.package_id = :package_id
+ and oi.latest_revision = ofi.offer_id
+ and r.revision_id = ofi.offer_item_id
+ and oi.item_id = :offer_id
+ and m.object_id = ofi.offer_item_id
+ order by ofi.sort_order
+
+
+
+
+
+
+
+ select t.offer_id as offer_rev_id, r.title, r.description,
+ t.offer_nr, t.amount_total, t.vat, t.vat_percent, t.comment,
+ to_char(t.finish_date, 'YYYY-MM-DD HH24:MI:SS') as finish_ansi,
+ to_char(t.finish_date, :timestamp_format) as finish_date,
+ o.creation_user, p.first_names, p.last_name,
+ to_char(o.creation_date, :timestamp_format) as creation_date,
+ to_char(t.accepted_date, :timestamp_format) as accepted_date,
+ t.amount_sum as amount_sum_, t.payment_days
+ from iv_offers t, cr_revisions r, cr_items i, acs_objects o,
+ persons p
+ where r.revision_id = t.offer_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :offer_id
+ and o.object_id = t.offer_id
+ and p.person_id = o.creation_user
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-delete.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-delete.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,7 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-delete.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-delete.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,33 @@
+ad_page_contract {
+ Delete Offer.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-18
+} {
+ offer_id
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_offer_Delete]"
+set context [list [list "offer-list" "[_ invoices.iv_offer_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_delete]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name delete_confirm -action offer-delete -form {
+ {offer_id:key}
+ {title:text(inform) {label "[_ invoices.Delete]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ db_dml mark_deleted {}
+ }
+} -after_submit {
+ ad_returnredirect "offer-list"
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-delete.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-delete.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-delete.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :offer_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id = :offer_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/offer-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-list.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,7 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/offer-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-list.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,22 @@
+ad_page_contract {
+ List of Offers.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-18
+} {
+ {format:optional "normal"}
+ {orderby:optional ""}
+ {page_size:optional 25}
+ {organization_id:optional ""}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_offer_2]"
+set context [list $page_title]
+
+set row_list {offer_nr {} title {} description {} amount_total {} creation_user {} creation_date {} finish_date {} accepted_date {} action {}}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-send.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-send.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-send.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/offer-send.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-send.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-send.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,47 @@
+ad_page_contract {
+ Form to send an offer.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-21
+} {
+ offer_id:integer
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_offer_send]"
+
+db_1row offer_data {}
+
+set context [list [list [export_vars -base offer-list {organization_id}] "[_ invoices.iv_offer_2]"] [list [export_vars -base offer-ae {offer_id}] "[_ invoices.iv_offer_View]"] $page_title]
+
+set offer_text [iv::offer::text -offer_id $offer_id]
+
+if {[empty_string_p $accepted_date]} {
+ # send pending offer
+ set offer_text "{[_ invoices.iv_offer_email]}"
+} else {
+ # send accepted offer
+ set offer_text "{[_ invoices.iv_offer_accepted_email]}"
+}
+
+set party_ids [contact::util::get_employees -organization_id $organization_id]
+set return_url [export_vars -base offer-list {organization_id}]
+set file_ids [db_string get_files {} -default ""]
+set parties_new [list]
+foreach party_id $party_ids {
+
+ # Check if the party has a valid e-mail address
+ if {![empty_string_p [cc_email_from_party $party_id]]} {
+ lappend parties_new $party_id
+ }
+}
+
+if {[empty_string_p $parties_new]} {
+ ad_return_error "No Recipient" "None of the recipients has a valid e-mail address. Please go back and make sure that you provide an e-mail address first."
+} else {
+ set party_ids $parties_new
+}
+ad_return_template
Index: openacs-4/packages/invoices/www/offer-send.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/offer-send.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/offer-send.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+ select o.offer_nr, o.organization_id, o.accepted_date
+ from iv_offers o, cr_items oi
+ where oi.latest_revision = o.offer_id
+ and oi.item_id = :offer_id
+
+
+
+
+
+
+
+ select max(item_id) as file_ids
+ from cr_items ci
+ where parent_id = :offer_id
+ and ci.storage_type = 'file'
+
+
+
+
Index: openacs-4/packages/invoices/www/price-ae-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-ae-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-ae-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,21 @@
+
+
+ postgresql7.3
+
+
+
+
+ select r.title as list_title, l.list_id as list_rev_id,
+ coalesce(cn.name, cc.default_name) as currency_name
+ from cr_revisions r, cr_items i, iv_price_lists l, currencies cc
+ left outer join currency_names cn on (cc.codeA = cn.codeA
+ and cn.language_code = :language)
+ where r.revision_id = i.latest_revision
+ and i.item_id = :list_id
+ and l.list_id = r.revision_id
+ and cc.codeA = l.currency
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-ae.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-ae.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,103 @@
+ad_page_contract {
+ Form to add/edit Price.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ amounts:float,array,optional
+ {list_id:notnull}
+ {__new_p 0}
+ {mode edit}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set has_submit 0
+if {$mode != "edit"} {
+ set has_submit 1
+}
+
+set language [lang::conn::language]
+db_1row list_data {}
+set page_title "[_ invoices.iv_price_Edit]"
+set context [list [list "price-list-list" "[_ invoices.iv_price_list_2]"] [list [export_vars -base price-list {list_id}] $list_title] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+
+ad_form -name iv_prices_form -action price-ae -mode $mode -has_submit $has_submit -form {
+ {list_id:key}
+}
+
+set category_list [list]
+foreach tree [category_tree::get_mapped_trees $container_objects(price_id)] {
+ util_unlist $tree tree_id tree_name subtree_id
+
+ foreach cat [category_tree::get_tree -all -subtree_id $subtree_id $tree_id] {
+ util_unlist $cat category_id category_name deprecated_p level
+
+ lappend category_list $category_id
+ set category_data($category_id) [list $tree_id $tree_name $category_name $level]
+ }
+}
+
+db_foreach all_prices {} {
+ if {[info exists category_data($category_id)]} {
+ lappend category_data($category_id) $amount
+ }
+}
+
+foreach category_id $category_list {
+ util_unlist $category_data($category_id) tree_id tree_name category_name level amount
+
+ if {$level > 1} {
+ set category_name "[string repeat ".." [expr {2 * $level - 2}]]$category_name"
+ }
+
+ if {[empty_string_p $amount]} {
+ set amount "0.00"
+ }
+
+ ad_form -extend -name iv_prices_form -form \
+ [list [list "amounts.${category_id}:float" \
+ [list label $category_name] \
+ [list html [list size 10 maxlength 10]] \
+ [list value [format "%.2f" $amount]] \
+ [list after_html $currency_name] \
+ [list section $tree_name] ] ]
+}
+
+ad_form -extend -name iv_prices_form -edit_request {
+} -edit_data {
+ db_transaction {
+ db_foreach old_prices {} {
+ set old_price($category_id) $item_id
+ }
+
+ db_dml invalidate_prices {}
+
+ foreach category_id [array names amounts] {
+ if {[info exists old_price($category_id)]} {
+ # new revision of old price
+ set new_price_rev_id [iv::price::edit \
+ -price_item_id $old_price($category_id) \
+ -list_id $list_id \
+ -category_id $category_id \
+ -amount $amounts($category_id) ]
+ } else {
+ # new price
+ set new_price_rev_id [iv::price::new \
+ -list_id $list_id \
+ -category_id $category_id \
+ -amount $amounts($category_id) ]
+ }
+ }
+ }
+} -after_submit {
+ ad_returnredirect [export_vars -base price-list {list_id}]
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/price-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-ae.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+ select p.category_id, p.amount
+ from iv_prices p, cr_items i
+ where p.list_id = :list_id
+ and p.price_id = i.latest_revision
+
+
+
+
+
+
+
+ select price_id, item_id, category_id
+ from iv_pricesi
+ where list_id = :list_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id in (select item_id
+ from iv_pricesi
+ where list_id = :list_id)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-ae-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-ae-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-ae-postgresql.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-ae.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-ae.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,102 @@
+ad_page_contract {
+ Form to add/edit Price List.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ list_id:integer,optional
+ {__new_p 0}
+ {mode edit}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set has_submit 0
+set organization_values ""
+if {![info exists list_id] || $__new_p} {
+ set page_title "[_ invoices.iv_price_list_Add]"
+ set _list_id 0
+} else {
+ if {$mode == "edit"} {
+ set page_title "[_ invoices.iv_price_list_Edit]"
+ set organization_values [application_data_link::get_linked -from_object_id $list_id -to_object_type organization]
+ } else {
+ set page_title "[_ invoices.iv_price_list_View]"
+ set has_submit 1
+ }
+ set _list_id [content::item::get_latest_revision -item_id $list_id]
+}
+
+set context [list [list "price-list-list" "[_ invoices.iv_price_list_2]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+set language [lang::conn::language]
+set organization_options [db_list_of_lists organization_list {}]
+set currency_options [db_list_of_lists currencies {}]
+
+ad_form -name iv_price_list_form -action price-list-ae -mode $mode -has_submit $has_submit -form {
+ {list_id:key}
+}
+
+ad_form -extend -name iv_price_list_form -form {
+ {title:text {label "[_ invoices.iv_price_list_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_price_list_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_price_list_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_price_list_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(list_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(list_id) -categorized_object_id $_list_id -form_name iv_price_list_form
+}
+
+ad_form -extend -name iv_price_list_form -form {
+ {organization_id:text(multiselect),optional,multiple {label "[_ invoices.iv_price_list_organization]"} {options $organization_options} {help_text "[_ invoices.iv_price_list_organization_help]"} {values {$organization_values}}}
+ {currency:text(select) {label "[_ invoices.iv_price_list_currency]"} {options $currency_options} {help_text "[_ invoices.iv_price_list_currency_help]"}}
+} -new_request {
+ set title ""
+ set description ""
+ set organization_id ""
+ set currency [parameter::get -parameter "DefaultCurrency" -default "EUR"]
+} -edit_request {
+ db_1row get_data {}
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(list_id)]
+} -new_data {
+ db_transaction {
+ set new_list_rev_id [iv::price_list::new \
+ -title $title \
+ -description $description \
+ -currency $currency ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_list_rev_id $category_ids
+ }
+ }
+} -edit_data {
+ db_transaction {
+ set new_list_rev_id [iv::price_list::edit \
+ -list_item_id $list_id \
+ -title $title \
+ -description $description \
+ -currency $currency ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_list_rev_id $category_ids
+ }
+ }
+} -after_submit {
+ if {[exists_and_not_null organization_id]} {
+ db_1row new_list_id {}
+
+ application_data_link::delete_links -object_id $new_list_id
+ foreach o_id $organization_id {
+ application_data_link::new -this_object_id $new_list_id -target_object_id $o_id
+ }
+ }
+
+ ad_returnredirect price-list-list
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/price-list-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-ae.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+ select o.name, o.organization_id
+ from organizations o
+ order by o.name
+
+
+
+
+
+
+
+ select r.title, r.description, t.list_id as list_rev_id,
+ t.currency
+ from iv_price_lists t, cr_revisions r, cr_items i
+ where r.revision_id = t.list_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :list_id
+
+
+
+
+
+
+
+ select item_id as new_list_id
+ from cr_revisions
+ where revision_id = :new_list_rev_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-delete.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-delete.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-delete.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-delete.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,34 @@
+ad_page_contract {
+ Delete Price List.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ {list_id:notnull}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_price_list_Delete]"
+set context [list [list "price-list-list" "[_ invoices.iv_price_list_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_delete]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name delete_confirm -action price-list-delete -form {
+ {list_id:key}
+ {title:text(inform) {label "[_ invoices.Delete]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ db_dml mark_deleted {}
+ }
+} -after_submit {
+ ad_returnredirect "price-list-list"
+ ad_script_abort
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/price-list-delete.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-delete.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-delete.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :list_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id = :list_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-list.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,6 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
Index: openacs-4/packages/invoices/www/price-list-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-list.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,40 @@
+ad_page_contract {
+ List of Price Lists.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_price_list_2]"
+set context [list $page_title]
+set package_id [ad_conn package_id]
+
+set actions [list "[_ invoices.iv_price_list_New]" price-list-ae "[_ invoices.iv_price_list_New2]"]
+
+template::list::create \
+ -name iv_price_list \
+ -key list_id \
+ -no_data "[_ invoices.None]" \
+ -elements {
+ title {
+ label {[_ invoices.iv_price_list_1]}
+ link_url_eval {[export_vars -base "price-list" {list_id}]}
+ }
+ action {
+ display_template {#invoices.Edit# #invoices.Delete#}
+
+ }
+ } -actions $actions
+
+db_multirow -extend {edit_link delete_link} iv_price_list iv_price_list {} {
+ set edit_link [export_vars -base "price-list-ae" {list_id}]
+ set delete_link [export_vars -base "price-list-delete" {list_id}]
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/price-list-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list-list.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ select cr.item_id as list_id, cr.title
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_price_lists t
+ where cr.revision_id = ci.latest_revision
+ and t.list_id = cr.revision_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ order by cr.title
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/price-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list.adp 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,5 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/price-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list.tcl 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,18 @@
+ad_page_contract {
+ List of Prices.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ {list_id:notnull}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+db_1row list_title {}
+set page_title $list_title
+set context [list [list "price-list-list" "[_ invoices.iv_price_list_2]"] $page_title]
+
+ad_return_template
Index: openacs-4/packages/invoices/www/price-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/price-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/price-list.xql 16 Aug 2005 20:04:34 -0000 1.1
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ select r.title as list_title
+ from cr_revisions r, cr_items i
+ where r.revision_id = i.latest_revision
+ and i.item_id = :list_id
+
+
+
+
+
Index: openacs-4/packages/invoices/www/admin/categories-admin.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/categories-admin.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/categories-admin.adp 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,14 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/admin/categories-admin.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/categories-admin.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/categories-admin.tcl 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,30 @@
+ad_page_contract {
+ Aministrate category trees.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.admin_categories]"
+set context [list $page_title]
+set package_id [ad_conn package_id]
+
+set categories_node_id [db_string get_category_node_id {}]
+set categories_url [site_node::get_url -node_id $categories_node_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+set list_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(list_id)}}]"
+set price_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(price_id)}}]"
+set cost_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(cost_id)}}]"
+set offer_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(offer_id)}}]"
+set offer_item_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(offer_item_id)}}]"
+set invoice_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(invoice_id)}}]"
+set invoice_item_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(invoice_item_id)}}]"
+set payment_url "$categories_url[export_vars -base cadmin/one-object {{object_id $container_objects(payment_id)}}]"
+
+ad_return_template
Index: openacs-4/packages/invoices/www/admin/categories-admin.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/categories-admin.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/categories-admin.xql 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+ select n.node_id
+ from site_nodes n, site_nodes top, apm_packages p
+ where top.parent_id is null
+ and n.parent_id = top.node_id
+ and p.package_id = n.object_id
+ and p.package_key = 'categories'
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/admin/index.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/index.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/index.adp 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/admin/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/index.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/index.tcl 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,18 @@
+ad_page_contract {
+ Admin Index page.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-07
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.admin]"
+set context [list]
+set categories_url "categories-admin"
+set linking_url "linking"
+
+ad_return_template
Index: openacs-4/packages/invoices/www/admin/linking.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/linking.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/linking.adp 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,5 @@
+
+@title;noquote@
+@context;noquote@
+
+
Index: openacs-4/packages/invoices/www/admin/linking.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/linking.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/linking.tcl 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,62 @@
+ad_page_contract {
+
+ Links package instances with invoices
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-07
+ @cvs-id $Id: linking.tcl,v 1.1 2005/08/16 20:04:35 timoh Exp $
+} {
+ {keys:array,optional}
+}
+
+set user_id [auth::require_login]
+set title "[_ invoices.Link_instances]"
+set context [list $title]
+set this_package_id [ad_conn package_id]
+set package_key [ad_conn package_key]
+
+# todo: get this list from callbacks
+set package_key_list [list contacts project-manager]
+
+ad_form -name linking
+
+foreach key $package_key_list {
+ if {![db_0or1row package_pretty_name {}]} {
+ continue
+ }
+
+ set options_list [list [list "" ""]]
+ db_foreach package_instances {} {
+ set urls [join [site_node::get_url_from_object_id -object_id $package_id] ", "]
+ if {[empty_string_p $urls]} {
+ set urls "[_ invoices.Unmounted]"
+ }
+
+ lappend options_list [list "$instance_name ($urls)" $package_id]
+ }
+
+ set current_link [lindex [application_link::get_linked -from_package_id $this_package_id -to_package_key $key] 0]
+ regsub -all -- {-} $key {_} key
+
+ ad_form -extend -name linking -form [list [list keys.$key\:text(select) [list label $package_pretty_name] [list options $options_list] [list value $current_link]]]
+}
+
+ad_form -extend -name linking -on_request {
+} -on_submit {
+ db_transaction {
+ application_link::delete_links -package_id $this_package_id
+
+ foreach one_key [array names keys] {
+ set target_package_id $keys($one_key)
+
+ if {![empty_string_p $target_package_id]} {
+ application_link::new -this_package_id $this_package_id -target_package_id $target_package_id
+ }
+ }
+ }
+} -after_submit {
+ ad_returnredirect .
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/admin/linking.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/admin/linking.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/admin/linking.xql 16 Aug 2005 20:04:35 -0000 1.1
@@ -0,0 +1,21 @@
+
+
+
+
+
+ select i.pretty_name as package_pretty_name
+ from apm_package_version_info i, apm_enabled_package_versions e
+ where i.version_id = e.version_id
+ and e.package_key = :key
+
+
+
+
+
+ select instance_name, package_id
+ from apm_packages
+ where package_key = :key
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-ae-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-ae-postgresql.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-ae-postgresql.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+ postgresql7.3
+
+
+
+
+ select cc.curname, cc.codeA
+ from (select coalesce(n.name, c.default_name) as curname, c.codeA
+ from currencies c
+ left outer join currency_names n
+ on (c.codeA = n.codeA
+ and language_code = :language)) cc
+ order by lower(cc.curname)
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-ae.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-ae.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,118 @@
+ad_page_contract {
+ Form to add/edit Cost.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ cost_id:integer,optional
+ {__new_p 0}
+ {mode edit}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set has_submit 0
+if {![info exists cost_id] || $__new_p} {
+ set page_title "[_ invoices.iv_cost_Add]"
+ set _cost_id 0
+} else {
+ if {$mode == "edit"} {
+ set page_title "[_ invoices.iv_cost_Edit]"
+ } else {
+ set page_title "[_ invoices.iv_cost_View]"
+ set has_submit 1
+ }
+ set _cost_id [content::item::get_latest_revision -item_id $cost_id]
+}
+
+set context [list [list "cost-list" "[_ invoices.iv_cost_2]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+set language [lang::conn::language]
+set organization_options [db_list_of_lists organization_list {}]
+set currency_options [db_list_of_lists currencies {}]
+set boolean_options [list [list "[_ invoices.yes]" t] [list "[_ invoices.no]" f]]
+
+ad_form -name iv_cost_form -action cost-ae -mode $mode -has_submit $has_submit -form {
+ {cost_id:key}
+}
+
+ad_form -extend -name iv_cost_form -form {
+ {title:text {label "[_ invoices.iv_cost_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_cost_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_cost_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_cost_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(cost_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(cost_id) -categorized_object_id $_cost_id -form_name iv_cost_form
+}
+
+ad_form -extend -name iv_cost_form -form {
+ {cost_nr:text {label "[_ invoices.iv_cost_cost_nr]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_cost_cost_nr_help]"}}
+ {organization_id:text(select),optional {label "[_ invoices.iv_cost_organization]"} {options $organization_options} {help_text "[_ invoices.iv_cost_organization_help]"}}
+ {cost_object_id:integer,optional {label "[_ invoices.iv_cost_object_id]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_cost_object_id_help]"}}
+ {item_units:integer,optional {label "[_ invoices.iv_cost_item_units]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_cost_item_units_help]"}}
+ {price_per_unit:integer {label "[_ invoices.iv_cost_price_per_unit]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_cost_price_per_unit_help]"}}
+ {currency:text(select),optional {label "[_ invoices.iv_cost_currency]"} {options $currency_options} {help_text "[_ invoices.iv_cost_currency_help]"}}
+ {apply_vat_p:text(select),optional {label "[_ invoices.iv_cost_apply_vat_p]"} {options $boolean_options} {help_text "[_ invoices.iv_cost_apply_vat_p_help]"}}
+ {variable_cost_p:text(select) {label "[_ invoices.iv_cost_variable_cost_p]"} {options $boolean_options} {help_text "[_ invoices.iv_cost_variable_cost_p_help]"}}
+} -new_request {
+ set title ""
+ set description ""
+ set cost_nr ""
+ set organization_id ""
+ set cost_object_id ""
+ set item_units ""
+ set price_per_unit ""
+ set currency ""
+ set apply_vat_p "t"
+ set variable_cost_p "t"
+} -edit_request {
+ db_1row get_data {}
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(cost_id)]
+} -new_data {
+ db_transaction {
+ set new_cost_rev_id [iv::cost::new \
+ -title $title \
+ -description $description \
+ -cost_nr $cost_nr \
+ -organization_id $organization_id \
+ -cost_object_id $cost_object_id \
+ -item_units $item_units \
+ -price_per_unit $price_per_unit \
+ -currency $currency \
+ -apply_vat_p $apply_vat_p \
+ -variable_cost_p $variable_cost_p ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_cost_rev_id $category_ids
+ }
+ }
+} -edit_data {
+ db_transaction {
+ set new_cost_rev_id [iv::cost::edit \
+ -cost_item_id $cost_id \
+ -title $title \
+ -description $description \
+ -cost_nr $cost_nr \
+ -organization_id $organization_id \
+ -cost_object_id $cost_object_id \
+ -item_units $item_units \
+ -price_per_unit $price_per_unit \
+ -currency $currency \
+ -apply_vat_p $apply_vat_p \
+ -variable_cost_p $variable_cost_p ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_cost_rev_id $category_ids
+ }
+ }
+} -after_submit {
+ ad_returnredirect cost-list
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/util/cost-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-ae.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+ select o.name, o.organization_id
+ from organizations o
+ order by o.name
+
+
+
+
+
+
+
+ select t.cost_id as cost_rev_id, r.title, r.description,
+ t.cost_nr, t.organization_id, t.cost_object_id,
+ t.item_units, t.price_per_unit, t.currency,
+ t.apply_vat_p, t.variable_cost_p
+ from iv_costs t, cr_revisions r, cr_items i
+ where r.revision_id = t.cost_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :cost_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-delete.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-delete.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-delete.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-delete.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,34 @@
+ad_page_contract {
+ Delete Cost.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ cost_id
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_cost_Delete]"
+set context [list [list "cost-list" "[_ invoices.iv_cost_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_delete]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name delete_confirm -action cost-delete -form {
+ {cost_id:key}
+ {title:text(inform) {label "[_ invoices.Delete]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ db_dml mark_deleted {}
+ }
+} -after_submit {
+ ad_returnredirect "cost-list"
+ ad_script_abort
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/util/cost-delete.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-delete.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-delete.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :cost_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id = :cost_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-list.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,6 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
Index: openacs-4/packages/invoices/www/util/cost-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-list.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,40 @@
+ad_page_contract {
+ List of Costs.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_cost_2]"
+set context [list $page_title]
+set package_id [ad_conn package_id]
+
+set actions [list "[_ invoices.iv_cost_New]" cost-ae "[_ invoices.iv_cost_New2]"]
+
+template::list::create \
+ -name iv_cost \
+ -key cost_id \
+ -no_data "[_ invoices.None]" \
+ -elements {
+ title {
+ label {[_ invoices.iv_cost_1]}
+ link_url_eval {[export_vars -base "cost-ae" {cost_id {mode display}}]}
+ }
+ action {
+ display_template {#invoices.Edit# #invoices.Delete#}
+
+ }
+ } -actions $actions
+
+db_multirow -extend {edit_link delete_link} iv_cost iv_cost {} {
+ set edit_link [export_vars -base "cost-ae" {cost_id}]
+ set delete_link [export_vars -base "cost-delete" {cost_id}]
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/util/cost-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/cost-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/cost-list.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ select cr.item_id as cost_id, cr.title
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_costs t
+ where cr.revision_id = ci.latest_revision
+ and t.cost_id = cr.revision_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ order by cr.title, cr.item_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-ae.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-ae.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-ae.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-ae.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-ae.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-ae.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,103 @@
+ad_page_contract {
+ Form to add/edit Payment.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ payment_id:integer,optional
+ {__new_p 0}
+ {mode edit}
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set has_submit 0
+if {![info exists payment_id] || $__new_p} {
+ set page_title "[_ invoices.iv_payment_Add]"
+ set _payment_id 0
+} else {
+ if {$mode == "edit"} {
+ set page_title "[_ invoices.iv_payment_Edit]"
+ } else {
+ set page_title "[_ invoices.iv_payment_View]"
+ set has_submit 1
+ }
+ set _payment_id [content::item::get_latest_revision -item_id $payment_id]
+}
+
+set context [list [list "payment-list" "[_ invoices.iv_payment_2]"] $page_title]
+set package_id [ad_conn package_id]
+array set container_objects [iv::util::get_default_objects -package_id $package_id]
+
+set currency_options [list]
+
+ad_form -name iv_payment_form -action payment-ae -mode $mode -has_submit $has_submit -form {
+ {payment_id:key}
+}
+
+ad_form -extend -name iv_payment_form -form {
+ {title:text {label "[_ invoices.iv_payment_Title]"} {html {size 80 maxlength 1000}} {help_text "[_ invoices.iv_payment_Title_help]"}}
+ {description:text(textarea),optional {label "[_ invoices.iv_payment_Description]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_payment_Description_help]"}}
+}
+
+if {![empty_string_p [category_tree::get_mapped_trees $container_objects(payment_id)]]} {
+ category::ad_form::add_widgets -container_object_id $container_objects(payment_id) -categorized_object_id $_payment_id -form_name iv_payment_form
+}
+
+ad_form -extend -name iv_payment_form -form {
+ {invoice_id:integer {label "[_ invoices.iv_payment_invoice_id]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_payment_invoice_id_help]"}}
+ {organization_id:integer {label "[_ invoices.iv_payment_organization_id]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_payment_organization_id_help]"}}
+ {received_date:text {label "[_ invoices.iv_payment_received_date]"} {html {size 80 maxlength 200}} {help_text "[_ invoices.iv_payment_received_date_help]"}}
+ {amount:integer {label "[_ invoices.iv_payment_amount]"} {html {size 10 maxlength 10}} {help_text "[_ invoices.iv_payment_amount_help]"}}
+ {currency:text(select) {label "[_ invoices.iv_payment_currency]"} {options $currency_options} {help_text "[_ invoices.iv_payment_currency_help]"}}
+} -new_request {
+ set title ""
+ set description ""
+ set invoice_id ""
+ set organization_id ""
+ set received_date ""
+ set amount ""
+ set currency ""
+} -edit_request {
+ db_1row get_data {}
+} -on_submit {
+ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(payment_id)]
+} -new_data {
+ db_transaction {
+ set new_payment_rev_id [iv::payment::new \
+ -title $title \
+ -description $description \
+ -invoice_id $invoice_id \
+ -organization_id $organization_id \
+ -received_date $received_date \
+ -amount $amount \
+ -currency $currency ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_payment_rev_id $category_ids
+ }
+ }
+} -edit_data {
+ db_transaction {
+ set new_payment_rev_id [iv::payment::edit \
+ -payment_item_id $payment_id \
+ -title $title \
+ -description $description \
+ -invoice_id $invoice_id \
+ -organization_id $organization_id \
+ -received_date $received_date \
+ -amount $amount \
+ -currency $currency ]
+
+ if {[exists_and_not_null category_ids]} {
+ category::map_object -object_id $new_payment_rev_id $category_ids
+ }
+ }
+} -after_submit {
+ ad_returnredirect payment-list
+ ad_script_abort
+}
+
+ad_return_template
Index: openacs-4/packages/invoices/www/util/payment-ae.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-ae.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-ae.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ select t.payment_id as payment_rev_id, r.title, r.description,
+ t.invoice_id, t.organization_id, t.received_date,
+ t.amount, t.currency
+ from iv_payments t, cr_revisions r, cr_items i
+ where r.revision_id = t.payment_id
+ and i.latest_revision = r.revision_id
+ and i.item_id = :payment_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-delete.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-delete.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,8 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-delete.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-delete.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-delete.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,34 @@
+ad_page_contract {
+ Delete Payment.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+ payment_id
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_payment_Delete]"
+set context [list [list "payment-list" "[_ invoices.iv_payment_2]"] $page_title]
+
+set confirm_options [list [list "[_ invoices.continue_with_delete]" t] [list "[_ invoices.cancel_and_return]" f]]
+
+ad_form -name delete_confirm -action payment-delete -form {
+ {payment_id:key}
+ {title:text(inform) {label "[_ invoices.Delete]"}}
+ {confirmation:text(radio) {label " "} {options $confirm_options} {value f}}
+} -select_query_name {title} \
+-on_submit {
+ if {$confirmation} {
+ db_dml mark_deleted {}
+ }
+} -after_submit {
+ ad_returnredirect "payment-list"
+ ad_script_abort
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/util/payment-delete.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-delete.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-delete.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ select r.title
+ from cr_revisions r, cr_items i
+ where i.latest_revision = r.revision_id
+ and i.item_id = :payment_id
+
+
+
+
+
+
+
+ update cr_items
+ set latest_revision = null,
+ live_revision = null
+ where item_id = :payment_id
+
+
+
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-list.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-list.adp,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-list.adp 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,6 @@
+
+@page_title;noquote@
+@context;noquote@
+
+
+
Index: openacs-4/packages/invoices/www/util/payment-list.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-list.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-list.tcl 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,40 @@
+ad_page_contract {
+ List of Payments.
+
+ @author Timo Hentschel (timo@timohentschel.de)
+ @creation-date 2005-06-06
+} {
+} -properties {
+ context:onevalue
+ page_title:onevalue
+}
+
+set user_id [auth::require_login]
+set page_title "[_ invoices.iv_payment_2]"
+set context [list $page_title]
+set package_id [ad_conn package_id]
+
+set actions [list "[_ invoices.iv_payment_New]" payment-ae "[_ invoices.iv_payment_New2]"]
+
+template::list::create \
+ -name iv_payment \
+ -key payment_id \
+ -no_data "[_ invoices.None]" \
+ -elements {
+ title {
+ label {[_ invoices.iv_payment_1]}
+ link_url_eval {[export_vars -base "payment-ae" {payment_id {mode display}}]}
+ }
+ action {
+ display_template {#invoices.Edit# #invoices.Delete#}
+
+ }
+ } -actions $actions
+
+db_multirow -extend {edit_link delete_link} iv_payment iv_payment {} {
+ set edit_link [export_vars -base "payment-ae" {payment_id}]
+ set delete_link [export_vars -base "payment-delete" {payment_id}]
+}
+
+ad_return_template
+
Index: openacs-4/packages/invoices/www/util/payment-list.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/util/payment-list.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/invoices/www/util/payment-list.xql 16 Aug 2005 20:04:36 -0000 1.1
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ select cr.item_id as payment_id, cr.title
+ from cr_folders cf, cr_items ci, cr_revisions cr, iv_payments t
+ where cr.revision_id = ci.latest_revision
+ and t.payment_id = cr.revision_id
+ and ci.parent_id = cf.folder_id
+ and cf.package_id = :package_id
+ order by cr.title
+
+
+
+
+
+