Index: openacs-4/packages/invoices/invoices.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/invoices.info,v diff -u -r1.6 -r1.7 --- openacs-4/packages/invoices/invoices.info 16 Sep 2005 21:54:53 -0000 1.6 +++ openacs-4/packages/invoices/invoices.info 11 Oct 2005 15:23:27 -0000 1.7 @@ -7,15 +7,15 @@ 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 - + @@ -31,8 +31,12 @@ + + - + + + 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml 5 Oct 2005 12:08:24 -0000 1.5 +++ openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml 11 Oct 2005 15:23:28 -0000 1.6 @@ -73,6 +73,7 @@ Storno Storno hinzuf�gen <html><body><h3>Storno</h3>%invoice_text%</html></body> + Stornorechnung # %invoice_nr% beendet am berechnete Positonen Anzahl Positionen @@ -81,6 +82,7 @@ Gutschrift Gutschrift erstellen <html><body><h3>Gutschrift</h3>%invoice_text%</html></body> + Gutschrift # %invoice_nr% Neue Gutschrift Neue Gutschrift erstellen W�hrung @@ -90,6 +92,7 @@ Rechnung �ndern Sie d�rfen keine bezahlte oder stornierte Rechnung �ndern. <html><body><h3>Rechnung</h3>%invoice_text%</html></body> + Rechnung # %invoice_nr% Rechnungsnummer Rechnungsposition Rechnungspositionen @@ -115,6 +118,7 @@ bezahlter Betrag bezahlte W�hrung Rechnungsbezug + Rechnungen bezahlt Zahlungsziel (Tage) Beschreibung Projekt Nummer @@ -124,6 +128,11 @@ Maximaler Rabatt %open_rebate% %currency% Rechnungsempf�nger Verschicken + Status + berechnet + storniert + zu berechnen + bezahlt Titel Gesamtsumme Mehrwertsteuer @@ -135,7 +144,8 @@ Projektaufstellungen Angebot akzeptieren Akzeptiert am - <html><body><h3>Angebotsbest�tigung</h3>%offer_text%</html></body> + <html><body><h3>Auftragsbest�tigung</h3>%offer_text%</html></body> + Auftragsbest�tigung # %offer_nr% Kostenaufstellung f�r "%organization_name%" Neue Projektaufstellung hinzuf�gen Rabatt @@ -156,6 +166,7 @@ Projektaufstellung �ndern Sie d�rfen keine akzeptierte oder berechnete Kostenaufstellung �ndern. <html><body><h3>Angebot</h3>%offer_text%<p>Um dieses Angebot anzunehmen, klicken Sie bitte <a href="%accept_link%">hier</a>.</html></body> + Angebot # %offer_nr% Timing Datum Abgabetermin zu dem das Projekt an den Kunden ausgeliefert werden muss Timing Uhrzeit @@ -286,6 +297,7 @@ erhalten am Empf�nger Nummer + Status Gesamtsumme h Unmounted 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 5 Oct 2005 12:08:24 -0000 1.5 +++ openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 11 Oct 2005 15:23:28 -0000 1.6 @@ -75,6 +75,7 @@ Cancellation Add invoice cancellation <html><body><h3>Cancellation</h3>%invoice_text%</html></body> + Cancellation # %invoice_nr% Finished on Billed items Total items @@ -83,6 +84,7 @@ Credit Add invoice credit <html><body><h3>Credit</h3>%invoice_text%</html></body> + Credit # %invoice_nr% New Credit Create New Credit Currency @@ -92,6 +94,7 @@ Edit Invoice You are not allowed to edit a paid or cancelled invoice <html><body><h3>Invoice</h3>%invoice_text%</html></body> + Invoice # %invoice_nr% Invoice number Invoice Item Invoice Items @@ -117,6 +120,7 @@ Amount paid Currency paid Invoice reference + Pay invoices Payment after .. days Description Project ID @@ -126,6 +130,11 @@ Maximum rebate %open_rebate% %currency% Invoice Recipient Send + Status + Billed + Cancelled + Unbilled + Paid Title Total amount VAT @@ -138,6 +147,7 @@ Accept Offer Accepted on <html><body><h3>Accepted Offer</h3>%offer_text%</html></body> + Offer acceptance # %offer_nr% Thank you for accepted our offer. We will contact you as soon as possible. Cost Sheet for "%organization_name%" Add Cost Sheet @@ -159,6 +169,7 @@ Edit Cost Sheet You are not allowed to edit an accepted or invoiced cost sheet <html><body><h3>Offer</h3>%offer_text%<p>To accept this offer, click <a href="%accept_link%">here</a>.</html></body> + Offer # %offer_nr% Finish on Deadline until which the project has to be delivered to the client Finish time @@ -290,6 +301,7 @@ Received on Recipient Sort order + Status Table Total amount h 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/lib/invoice-list.tcl 8 Sep 2005 20:45:06 -0000 1.3 +++ openacs-4/packages/invoices/lib/invoice-list.tcl 11 Oct 2005 15:23:28 -0000 1.4 @@ -26,12 +26,19 @@ 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 user_id [ad_conn user_id] set date_format [lc_get formbuilder_date_format] set timestamp_format "$date_format [lc_get formbuilder_time_format]" +set bulk_actions [list "[_ invoices.iv_invoice_pay]" "${base_url}invoice-pay" "[_ invoices.iv_invoice_pay]"] +set invoice_cancel_p [permission::permission_p -party_id $user_id -object_id $package_id -privilege invoice_cancel] + set actions [list] if { ![empty_string_p $organization_id] } { - 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]" "[_ invoices.iv_reports]" [export_vars -base invoice-reports {organization_id}]] + if {$invoice_cancel_p} { + 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]" "[_ invoices.iv_reports]" [export_vars -base invoice-reports {organization_id}]] + } else { + set actions [list "[_ invoices.iv_invoice_New]" [export_vars -base invoice-add {organization_id}] "[_ invoices.iv_invoice_New2]" "[_ invoices.iv_offer_2]" [export_vars -base offer-list {organization_id}] "[_ invoices.iv_offer_2]" "[_ invoices.projects]" $pm_base_url "[_ invoices.projects]" "[_ invoices.iv_reports]" [export_vars -base invoice-reports {organization_id}]] + } } template::list::create \ @@ -68,10 +75,15 @@ due_date { label {[_ invoices.iv_invoice_due_date]} } + status { + label {[_ invoices.iv_invoice_status]} + display_template {[_ invoices.iv_invoice_status_@iv_invoice.status@]} + } action { - display_template {#invoices.Edit# #invoices.Cancel# #invoices.Delete#} + display_template {#invoices.Edit# #invoices.Cancel# #invoices.Delete#} } } -actions $actions -sub_class narrow \ + -bulk_actions $bulk_actions \ -orderby { default_value invoice_nr invoice_nr { @@ -124,6 +136,7 @@ -page_size $page_size \ -page_flush_p 0 \ -page_query_name iv_invoice_paginated \ + -pass_properties {invoice_cancel_p} \ -filters {organization_id {}} \ -formats { normal { 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 -r1.2 -r1.3 --- openacs-4/packages/invoices/lib/invoice-list.xql 8 Sep 2005 20:45:06 -0000 1.2 +++ openacs-4/packages/invoices/lib/invoice-list.xql 11 Oct 2005 15:23:28 -0000 1.3 @@ -9,7 +9,7 @@ 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 + t.invoice_id as invoice_rev_id, t.cancelled_p, t.status 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 @@ -19,6 +19,7 @@ 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::page_where_clause -and -name iv_invoice -key cr.item_id] [template::list::orderby_clause -name iv_invoice -orderby] 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 -r1.4 -r1.5 --- openacs-4/packages/invoices/lib/offer-list.tcl 19 Sep 2005 11:10:35 -0000 1.4 +++ openacs-4/packages/invoices/lib/offer-list.tcl 11 Oct 2005 15:23:28 -0000 1.5 @@ -111,7 +111,7 @@ label {[_ invoices.iv_offer_accepted_date]} } action { - display_template {#invoices.Edit# #invoices.Delete#} + display_template {#invoices.Edit# #invoices.Delete#} } } -actions $actions -sub_class narrow \ -orderby { 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 -r1.4 -r1.5 --- openacs-4/packages/invoices/lib/offer-list.xql 5 Oct 2005 12:08:24 -0000 1.4 +++ openacs-4/packages/invoices/lib/offer-list.xql 11 Oct 2005 15:23:28 -0000 1.5 @@ -20,7 +20,7 @@ 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, - pi.item_id as project_id, pr.title as project_title + pi.item_id as project_id, pr.title as project_title, t.status from cr_folders cf, cr_revisions cr, iv_offers t, acs_objects o, persons p, cr_items ci, acs_rels r, cr_items pi, cr_revisions pr, pm_projects pp 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 -r1.2 -r1.3 --- openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 6 Sep 2005 22:57:52 -0000 1.2 +++ openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 11 Oct 2005 15:23:28 -0000 1.3 @@ -16,7 +16,9 @@ references cr_revisions, currency char(3) constraint iv_prices_currency_fk - references currencies(codeA) + references currencies(codeA), + credit_percent numeric(12,5) default 0 + -- %credit ); create index iv_price_lists_currency_idx on iv_price_lists(currency); @@ -108,6 +110,10 @@ -- %VAT vat numeric(12,2) default 0, -- VAT amount + credit_percent numeric(12,5) default 0 + -- %credit + status varchar(10) default 'new', + -- new, accepted, billed, credit accepted_date timestamptz -- offer accepted by customer? ); @@ -192,6 +198,8 @@ -- %VAT vat numeric(12,2) default 0, -- VAT amount + status varchar(10) default 'new', + -- new, cancelled, billed, paid cancelled_p char(1) default 'f' constraint iv_invoices_cancelled_p check (cancelled_p in ('t','f')) 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/tcl/invoice-procs.tcl 20 Sep 2005 05:45:40 -0000 1.5 +++ openacs-4/packages/invoices/tcl/invoice-procs.tcl 11 Oct 2005 15:23:28 -0000 1.6 @@ -116,6 +116,18 @@ return $new_rev_id } +ad_proc -public iv::invoice::set_status { + -invoice_id:required + {-status "new"} +} { + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-10-04 + + Edit Invoice status +} { + db_dml update_status {} +} + ad_proc -public iv::invoice::data { -invoice_id:required -invoice_array:required @@ -142,7 +154,7 @@ 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)" + set invoice(final_amount) [format "%.2f" [expr $invoice(total_amount)+$invoice(vat)]] # Get recipient information set recipient(recipient_name) "$invoice(rep_first_names) $invoice(rep_last_name)" @@ -159,49 +171,57 @@ ad_proc -public iv::invoice::parse_data { -invoice_id:required -recipient_id:required + -template:required + -locale: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 invoice(amount_diff) [lc_numeric [format "%.2f" [expr $invoice(total_amount) - $invoice(amount_sum)]] "" $locale] + set invoice(final_amount) [lc_numeric [format "%.2f" [expr $invoice(total_amount)+$invoice(vat)]] "" $locale] + set invoice(vat_percent) [lc_numeric [format "%.1f" $invoice(vat_percent)] "" $locale] + set invoice(vat) [lc_numeric [format "%.2f" $invoice(vat)] "" $locale] + set invoice(amount_sum) [lc_numeric [format "%.2f" $invoice(amount_sum)] "" $locale] + set invoice(total_amount) [lc_numeric [format "%.2f" $invoice(total_amount)] "" $locale] + + set time_format [lc_get -locale $locale d_fmt] + set invoice(creation_date) [lc_time_fmt $invoice(creation_date) $time_format] + set invoice(due_date) [lc_time_fmt $invoice(due_date) $time_format] + set name [contact::name -party_id $recipient_id] - set first_names [lindex $name 0] - set last_name [lindex $name 1] + set invoice(rep_first_names) [lindex $name 0] + set invoice(rep_last_name) [lindex $name 1] + set invoice(recipient_name) "$invoice(rep_first_names) $invoice(rep_last_name)" 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] + set invoice(mailing_address) [contact::message::mailing_address -party_id $invoice(organization_id) -format "text/html"] + set invoice(organization_name) [contact::name -party_id $invoice(organization_id)] + # set locale [lang::user::site_wide_locale -user_id $invoice(recipient_id)] + # set locale de_DE 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 amount_total [lc_numeric [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]] "" $locale] + set amount_sum [lc_numeric $amount_sum "" $locale] + set price_per_unit [lc_numeric [format "%.2f" $price_per_unit] "" $locale] + set item_units [lc_numeric [format "%.2f" $item_units] "" $locale] + set rebate [lc_numeric [format "%.1f" $rebate] "" $locale] set category [lang::util::localize [category::get_name $category_id]] } - set file_url [parameter::get -parameter InvoiceTemplate] + set file_url [parameter::get -parameter $template] - # We need to add the locale to the InvoiceTemplate name, but for the time being we don't care. if {![empty_string_p $file_url]} { - set file [open "[acs_root_dir]/$file_url"] - fconfigure $file -translation binary - set content [read $file] + set content [iv::invoice::template_file -template $file_url -locale $locale] - # parse template and replace placeholders - eval [template::adp_compile -string $content] + # parse template and replace placeholders + eval [template::adp_compile -string $content] set final_content $__adp_output } else { set final_content "" @@ -210,6 +230,38 @@ return $final_content } +ad_proc -public iv::invoice::template_file { + -template:required + -locale:required +} { + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-10-07 + + Get template file matching locale +} { + set filename "[acs_root_dir]/$template" + set system_locale [lang::system::site_wide_locale] + set language_locale [lang::util::default_locale_from_lang [lindex [split $locale "_"] 0]] + + if {[file exists "${filename}_${locale}.html"]} { + # file found directly + set filename "${filename}_${locale}.html" + } elseif {[file exists "${filename}_${language_locale}.html"]} { + # file found for language locale + set filename "${filename}_${language_locale}.html" + } else { + # take default file + set filename "${filename}_${system_locale}.html" + } + + set file [open $filename] + fconfigure $file -translation binary + set content [read $file] + close $file + + return $content +} + ad_proc -public iv::invoice::text { -invoice_id:required } { 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/tcl/invoice-procs.xql 16 Aug 2005 20:04:32 -0000 1.1 +++ openacs-4/packages/invoices/tcl/invoice-procs.xql 11 Oct 2005 15:23:28 -0000 1.2 @@ -1,6 +1,18 @@ + + + + update iv_invoices + set status = :status + where offer_id = (select latest_revision + from cr_items + where item_id = :invoice_id) + + + + @@ -24,16 +36,25 @@ - select r.title, r.description, r.item_id, ii.offer_item_id, + select cr.title, cr.description, cr.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 + ii.rebate, ii.vat, m.category_id, ofi.file_count, + ofi.page_count, pr.title as project_title, p.project_code, + pi.item_id as project_id + from iv_offer_items ofi, cr_items ci, cr_revisions cr, + category_object_map m, iv_invoice_items ii, cr_revisions oor, + acs_rels r, cr_items pi, cr_revisions pr, pm_projects p + where ci.latest_revision = ii.invoice_id + and cr.revision_id = ii.iv_item_id + and ci.item_id = :invoice_id and m.object_id = ofi.offer_item_id and ofi.offer_item_id = ii.offer_item_id + and oor.revision_id = ofi.offer_id + and r.object_id_two = oor.item_id + and r.object_id_one = pi.item_id + and r.rel_type = 'application_data_link' + and pi.latest_revision = pr.revision_id + and pr.revision_id = p.project_id order by ii.sort_order @@ -45,8 +66,8 @@ 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, + to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as creation_date, + to_char(t.due_date, 'YYYY-MM-DD HH24:MI:SS') 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 @@ -62,16 +83,25 @@ - select r.title, r.description, r.item_id, ii.offer_item_id, + select cr.title, cr.description, cr.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 + ii.rebate, ii.vat, m.category_id, ofi.file_count, + ofi.page_count, pr.title as project_title, p.project_code, + pi.item_id as project_id + from iv_offer_items ofi, cr_items ci, cr_revisions cr, + category_object_map m, iv_invoice_items ii, cr_revisions oor, + acs_rels r, cr_items pi, cr_revisions pr, pm_projects p + where ci.latest_revision = ii.invoice_id + and cr.revision_id = ii.iv_item_id + and ci.item_id = :invoice_id and m.object_id = ofi.offer_item_id and ofi.offer_item_id = ii.offer_item_id + and oor.revision_id = ofi.offer_id + and r.object_id_two = oor.item_id + and r.object_id_one = pi.item_id + and r.rel_type = 'application_data_link' + and pi.latest_revision = pr.revision_id + and pr.revision_id = p.project_id order by ii.sort_order 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/tcl/iv-install-procs.tcl 6 Sep 2005 22:59:05 -0000 1.3 +++ openacs-4/packages/invoices/tcl/iv-install-procs.tcl 11 Oct 2005 15:23:28 -0000 1.4 @@ -24,6 +24,7 @@ # Price List content::type::attribute::new -content_type {iv_price_list} -attribute_name {currency} -datatype {string} -pretty_name {[_ invoices.Currency]} -column_spec {char(3)} + content::type::attribute::new -content_type {iv_price_list} -attribute_name {credit_percent} -datatype {number} -pretty_name {[_ invoices.Credit]} -column_spec {numeric(12,5)} # Price content::type::attribute::new -content_type {iv_price} -attribute_name {list_id} -datatype {number} -pretty_name {[_ invoices.Price_list]} -column_spec {integer} @@ -52,6 +53,8 @@ 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 {credit_percent} -datatype {number} -pretty_name {[_ invoices.Credit]} -column_spec {numeric(12,5)} + content::type::attribute::new -content_type {iv_offer} -attribute_name {status} -datatype {string} -pretty_name {[_ invoices.Status]} -column_spec {varchar(10)} content::type::attribute::new -content_type {iv_offer} -attribute_name {accepted_date} -datatype {date} -pretty_name {[_ invoices.Accepted_date]} -column_spec {timestamptz} # Offer Item @@ -81,6 +84,7 @@ 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 {status} -datatype {string} -pretty_name {[_ invoices.Status]} -column_spec {varchar(10)} content::type::attribute::new -content_type {iv_invoice} -attribute_name {cancelled_p} -datatype {boolean} -pretty_name {[_ invoices.Cancelled]} -column_spec {char(1)} # Invoice Item @@ -218,6 +222,12 @@ 0.01d8 0.01d9 { apm_parameter_register "MailSendBoxFileP" "Location of the file for prefilling the mail send box." "invoices" "" "string" } + 0.01d10 0.01d11 { + content::type::attribute::new -content_type {iv_price_list} -attribute_name {credit_percent} -datatype {number} -pretty_name {[_ invoices.Credit]} -column_spec {numeric(12,5)} + content::type::attribute::new -content_type {iv_offer} -attribute_name {credit_percent} -datatype {number} -pretty_name {[_ invoices.Credit]} -column_spec {numeric(12,5)} + content::type::attribute::new -content_type {iv_offer} -attribute_name {status} -datatype {string} -pretty_name {[_ invoices.Status]} -column_spec {varchar(10)} + content::type::attribute::new -content_type {iv_invoice} -attribute_name {status} -datatype {string} -pretty_name {[_ invoices.Status]} -column_spec {varchar(10)} + } } } 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/tcl/offer-procs-postgresql.xql 16 Aug 2005 20:04:32 -0000 1.1 +++ openacs-4/packages/invoices/tcl/offer-procs-postgresql.xql 11 Oct 2005 15:23:28 -0000 1.2 @@ -7,7 +7,8 @@ update iv_offers - set accepted_date = now() + set accepted_date = now(), + status = 'accepted' 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/tcl/offer-procs.tcl 20 Sep 2005 17:35:19 -0000 1.5 +++ openacs-4/packages/invoices/tcl/offer-procs.tcl 11 Oct 2005 15:23:28 -0000 1.6 @@ -22,6 +22,7 @@ {-payment_days ""} {-vat_percent ""} {-vat ""} + {-credit_percent 0} } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2005-06-18 @@ -56,7 +57,8 @@ [list date_comment $date_comment] \ [list payment_days $payment_days] \ [list vat_percent $vat_percent] \ - [list vat $vat] ] ] + [list vat $vat] \ + [list credit_percent $credit_percent] ] ] } return $new_id @@ -77,13 +79,15 @@ {-payment_days ""} {-vat_percent ""} {-vat ""} + {-credit_percent 0} } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2005-06-18 Edit Offer } { db_transaction { + set status [iv::offer::get_status -offer_id $offer_id] set old_rev_id [content::item::get_best_revision -item_id $offer_id] set new_rev_id [content::revision::new \ -item_id $offer_id \ @@ -100,14 +104,39 @@ [list finish_date $finish_date] \ [list date_comment $date_comment] \ [list payment_days $payment_days] \ + [list status $status] \ [list vat_percent $vat_percent] \ - [list vat $vat] ] ] + [list vat $vat] \ + [list credit_percent $credit_percent] ] ] db_dml set_accepted_date {} } return $new_rev_id } +ad_proc -public iv::offer::set_status { + -offer_id:required + {-status "new"} +} { + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-10-04 + + Edit Offer status +} { + db_dml update_status {} +} + +ad_proc -public iv::offer::get_status { + -offer_id:required +} { + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-10-04 + + Get Offer status +} { + db_1row offer_status {} +} + ad_proc -public iv::offer::accept { -offer_id:required } { @@ -156,48 +185,61 @@ ad_proc -public iv::offer::parse_data { -offer_id:required -recipient_id:required + -template:required + -locale:required + {-accept_link ""} } { @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]" + # Get the offer data 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 + set offer(amount_diff) [lc_numeric [format "%.2f" [expr $offer(amount_total) - $offer(amount_sum)]] "" $locale] + set offer(final_amount) [lc_numeric [format "%.2f" [expr $offer(amount_total)+$offer(vat)]] "" $locale] + set offer(vat_percent) [lc_numeric [format "%.1f" $offer(vat_percent)] "" $locale] + set offer(vat) [lc_numeric [format "%.2f" $offer(vat)] "" $locale] + set offer(amount_sum) [lc_numeric [format "%.2f" $offer(amount_sum)] "" $locale] + set offer(amount_total) [lc_numeric [format "%.2f" $offer(amount_total)] "" $locale] + set revision_id [contact::live_revision -party_id $recipient_id] + # set offer(salutation) [ams::value -attribute_name "salutation" -object_id $revision_id -locale $locale] + set offer(salutation) "Sehr geehrter" + set time_format "[lc_get -locale $locale d_fmt] [lc_get -locale $locale t_fmt]" + set offer(finish_date) [lc_time_fmt $offer(finish_date) $time_format] + set offer(creation_date) [lc_time_fmt $offer(creation_date) $time_format] + set offer(accepted_date) [lc_time_fmt $offer(accepted_date) $time_format] + + set offer(recipient_id) $recipient_id + set offer(name) [contact::name -party_id $recipient_id] + set offer(rep_first_names) [lindex $offer(name) 0] + set offer(rep_last_name) [lindex $offer(name) 1] + set offer(recipient_name) "$offer(rep_first_names) $offer(rep_last_name)" + set rec_organization_id [contact::util::get_employee_organization -employee_id $offer(recipient_id)] + set offer(mailing_address) [contact::message::mailing_address -party_id $offer(organization_id) -format "text/html"] + set offer(organization_name) [contact::name -party_id $offer(organization_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 amount_total [lc_numeric [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]] "" $locale] + set amount_sum [lc_numeric $amount_sum "" $locale] + set price_per_unit [lc_numeric [format "%.2f" $price_per_unit] "" $locale] + set item_units [lc_numeric [format "%.2f" $item_units] "" $locale] + set rebate [lc_numeric [format "%.1f" $rebate] "" $locale] set category [lang::util::localize [category::get_name $category_id]] } - set file_url [parameter::get -parameter MailSendBoxFileP] - if { ![empty_string_p $file_url] } { - set file [open "$file_url"] - fconfigure $file -translation binary - set content [read $file] + set file_url [parameter::get -parameter $template] + + if {![empty_string_p $file_url]} { + set content [iv::invoice::template_file -template $file_url -locale $locale] - - # parse template and replace placeholders - eval [template::adp_compile -string $content] + # parse template and replace placeholders + eval [template::adp_compile -string $content] set final_content $__adp_output } else { set final_content "" 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/tcl/offer-procs.xql 19 Sep 2005 21:25:23 -0000 1.3 +++ openacs-4/packages/invoices/tcl/offer-procs.xql 11 Oct 2005 15:23:28 -0000 1.4 @@ -1,6 +1,29 @@ + + + + update iv_offers + set status = :status + where offer_id = (select latest_revision + from cr_items + where item_id = :offer_id) + + + + + + + + select o.status + from iv_offers o, cr_items i + where i.item_id = :offer_id + and i.latest_revision = o.offer_id + + + + @@ -39,22 +62,28 @@ - select t.offer_id as offer_rev_id, r.title, r.description, + select t.offer_id as offer_rev_id, cr.title, cr.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, + to_char(t.finish_date, 'YYYY-MM-DD HH24:MI:SS') 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.date_comment, - 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 + to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as creation_date, + to_char(t.accepted_date, 'YYYY-MM-DD HH24:MI:SS') as accepted_date, + t.amount_sum, t.payment_days, t.date_comment, t.currency, + t.organization_id, pr.title as project_title, ci.item_id as offer_id, + pp.project_code, pi.item_id as project_id + from iv_offers t, cr_revisions cr, cr_items ci, acs_objects o, + persons p, acs_rels r, cr_items pi, cr_revisions pr, pm_projects pp + where cr.revision_id = t.offer_id + and ci.latest_revision = cr.revision_id + and ci.item_id = :offer_id and o.object_id = t.offer_id and p.person_id = o.creation_user + and r.object_id_two = ci.item_id + and r.object_id_one = pi.item_id + and r.rel_type = 'application_data_link' + and pi.latest_revision = pr.revision_id + and pr.revision_id = pp.project_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 -r1.1 -r1.2 --- openacs-4/packages/invoices/tcl/price-list-procs.tcl 16 Aug 2005 20:04:32 -0000 1.1 +++ openacs-4/packages/invoices/tcl/price-list-procs.tcl 11 Oct 2005 15:23:28 -0000 1.2 @@ -12,6 +12,7 @@ {-title ""} {-description ""} {-currency ""} + {-credit_percent "0"} } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2005-06-06 @@ -36,7 +37,8 @@ -title $title \ -description $description \ -attributes [list \ - [list currency $currency] ] ] + [list currency $currency] \ + [list credit_percent $credit_percent] ] ] } return $new_id @@ -47,6 +49,7 @@ {-title ""} {-description ""} {-currency ""} + {-credit_percent "0"} } { @author Timo Hentschel (timo@timohentschel.de) @creation-date 2005-06-06 @@ -60,7 +63,8 @@ -title $title \ -description $description \ -attributes [list \ - [list currency $currency] ] ] + [list currency $currency] \ + [list credit_percent $credit_percent] ] ] } return $new_rev_id 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/www/invoice-ae.tcl 28 Sep 2005 17:19:12 -0000 1.5 +++ openacs-4/packages/invoices/www/invoice-ae.tcl 11 Oct 2005 15:23:29 -0000 1.6 @@ -16,11 +16,15 @@ page_title:onevalue } +set package_id [ad_conn package_id] 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} { + if {$__new_p} { + set project_id [string trim $project_id "{}"] + } set page_title "[_ invoices.iv_invoice_Add2]" set _invoice_id 0 set invoice_rev_id 0 @@ -34,7 +38,7 @@ set has_edit 1 } if {$mode == "edit" && ![info exists send]} { - if {![empty_string_p $paid_currency] || $cancelled_p == "t"} { + if {![empty_string_p $paid_currency] || $cancelled_p == "t" || $status != "new"} { # do not allow to edit a paid invoice ad_return_complaint 1 "[_ invoices.iv_invoice_edit_error]" } @@ -54,7 +58,6 @@ 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]" @@ -74,7 +77,7 @@ } else { # normal invoice: get recipients from projects # set recipient_options [db_list_of_lists recipients {}] - set recipient_options [translation::get_recipients -customer_id $organization_id] + set recipient_options [wieners::get_recipients -customer_id $organization_id] } @@ -152,9 +155,6 @@ 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)] @@ -219,7 +219,7 @@ } } -if {$mode == "display"} { +if {$mode == "display" && $status == "new"} { ad_form -extend -name iv_invoice_form -form { {send:text(submit) {label "[_ invoices.iv_invoice_send]"} {value t}} } @@ -343,6 +343,32 @@ } } } -after_submit { + db_transaction { + # get all offer_ids + set offer_ids {} + foreach iv_item_id [array names offers] { + array set offer $offers($iv_item_id) + if {[lsearch -exact $offer_ids $offer(offer_id)] == -1} { + lappend offer_ids $offer(offer_id) + } + } + + # foreach offer_id: check if there's an item that's not billed -> status new, else status billed + foreach offer_id $offer_ids { + db_0or1row check_offer_status {} + + if {$unbilled_items == 0} { + # all offer items billed + set status billed + } else { + # there are still unbilled offer items + set status new + } + + db_dml set_status {} + } + } + ad_returnredirect [export_vars -base invoice-list {organization_id}] ad_script_abort } 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 -r1.4 -r1.5 --- openacs-4/packages/invoices/www/invoice-ae.xql 28 Sep 2005 17:19:12 -0000 1.4 +++ openacs-4/packages/invoices/www/invoice-ae.xql 11 Oct 2005 15:23:29 -0000 1.5 @@ -7,7 +7,7 @@ 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, + t.total_amount as cur_total_amount, t.status, t.amount_sum as cur_amount_sum from iv_invoices t, cr_items i where i.latest_revision = t.invoice_id @@ -75,7 +75,7 @@ - select cr.title, cr.description, ofi.offer_item_id, ofi.item_units, + select cr.title, cr.description, ofi.offer_item_id, ofi.item_units, ofi.offer_id, 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, @@ -105,7 +105,7 @@ select ir.title, ir.description, ir.item_id as iv_item_id, - i.item_units, i.price_per_unit, i.item_nr, + i.item_units, i.price_per_unit, i.item_nr, ofi.offer_id, pi.item_id as project_id, pr.title as project_title, i.vat as old_vat, i.rebate, m.category_id, i.offer_item_id from cr_items oi, iv_offer_items ofi, iv_invoice_items i, @@ -175,4 +175,29 @@ + + + + select count(*) as unbilled_items + from iv_offers o, iv_offer_items ofi + where o.offer_id = :offer_id + and ofi.offer_id = o.offer_id + and not exists (select 1 + from iv_invoice_items ii + where ii.offer_item_id = ofi.offer_item_id) + group by o.offer_id + + + + + + + + update iv_offers + set status = :status + where offer_id = :offer_id + + + + 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-cancellation.tcl 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-cancellation.tcl 11 Oct 2005 15:23:29 -0000 1.2 @@ -13,7 +13,9 @@ page_title:onevalue } +set package_id [ad_conn package_id] set user_id [auth::require_login] +permission::require_permission -party_id $user_id -object_id $package_id -privilege invoice_cancel set date_format "YYYY-MM-DD" set page_title "[_ invoices.iv_invoice_cancel_Add]" @@ -22,7 +24,6 @@ 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]" 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-cancellation.xql 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-cancellation.xql 11 Oct 2005 15:23:29 -0000 1.2 @@ -27,7 +27,8 @@ update iv_invoices - set cancelled_p = 't' + set cancelled_p = 't', + status = 'cancelled' where invoice_id in (:parent_id, :new_invoice_rev_id) 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-credit.tcl 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-credit.tcl 11 Oct 2005 15:23:29 -0000 1.2 @@ -12,7 +12,9 @@ page_title:onevalue } +set package_id [ad_conn package_id] set user_id [auth::require_login] +permission::require_permission -party_id $user_id -object_id $package_id -privilege invoice_cancel set date_format "YYYY-MM-DD" set page_title "[_ invoices.iv_invoice_credit_Add]" @@ -21,7 +23,6 @@ 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]" 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-send.adp 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-send.adp 11 Oct 2005 15:23:29 -0000 1.2 @@ -4,5 +4,5 @@ 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/www/invoice-send.tcl 5 Oct 2005 16:17:57 -0000 1.5 +++ openacs-4/packages/invoices/www/invoice-send.tcl 11 Oct 2005 15:23:29 -0000 1.6 @@ -15,33 +15,47 @@ set page_title "[_ invoices.iv_invoice_send]" db_1row invoice_data {} +set locale [lang::user::site_wide_locale -user_id $recipient_id] 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]}" + set subject [lang::util::localize "#invoices.iv_invoice_email_subject#" $locale] + set template "InvoiceTemplate" +} elseif {[empty_string_p $parent_invoice_id]} { + # send credit + # set invoice_text "{[_ invoices.iv_invoice_credit_email]}" + set subject [lang::util::localize "#invoices.iv_invoice_credit_email_subject#" $locale] + set template "CreditTemplate" +} else { + # send cancellation + # set invoice_text "{[_ invoices.iv_invoice_cancel_email]}" + set subject [lang::util::localize "#invoices.iv_invoice_cancel_email_subject#" $locale] + set template "CancelTemplate" +} +set invoice_text [iv::invoice::parse_data -invoice_id $invoice_id -recipient_id $recipient_id -template $template -locale $locale] + +set project_id [lindex [application_data_link::get_linked -from_object_id $invoice_id -to_object_type content_item] 0] +if {![empty_string_p $project_id]} { + acs_object::get -object_id $project_id -array project + set pm_url [lindex [site_node::get_url_from_object_id -object_id $project(package_id)] 0] + set return_url [export_vars -base "${pm_url}one" {{project_item_id $project_id}}] +} else { + set return_url [export_vars -base invoice-list {organization_id}] +} + if {[empty_string_p $file_ids]} { set pdf_file [text_templates::create_pdf_from_html -html_content "$invoice_text"] if {![empty_string_p $pdf_file]} { set file_size [file size $pdf_file] - set root_folder_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type content_folder] 0] - set invoice_folder_id [lindex [application_data_link::get_linked -from_object_id $root_folder_id -to_object_type content_folder] 0] - - set file_ids [cr_import_content -title "Invoice $invoice_id" -description "PDF version of this offer" $invoice_folder_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] - application_data_link::new -this_object_id $invoice_id -target_object_id $file_ids + set file_ids [cr_import_content -title "Invoice_${invoice_id}.pdf" -description "PDF version of this offer" $invoice_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"]] + set return_url [export_vars -base invoice-pdf {invoice_id {file_id $file_ids}}] } } -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 return_url [export_vars -base invoice-list {organization_id}] set party_ids [contact::util::get_employees -organization_id $organization_id] 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-send.xql 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-send.xql 11 Oct 2005 15:23:29 -0000 1.2 @@ -5,7 +5,7 @@ select i.invoice_nr, i.organization_id, i.parent_invoice_id, - i.total_amount, i.recipient_id + i.total_amount, i.recipient_id, i.organization_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 -r1.2 -r1.3 --- openacs-4/packages/invoices/www/offer-accept-2.adp 6 Sep 2005 23:01:24 -0000 1.2 +++ openacs-4/packages/invoices/www/offer-accept-2.adp 11 Oct 2005 15:23:29 -0000 1.3 @@ -4,6 +4,6 @@ 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/www/offer-accept-2.tcl 8 Sep 2005 18:30:50 -0000 1.3 +++ openacs-4/packages/invoices/www/offer-accept-2.tcl 11 Oct 2005 15:23:29 -0000 1.4 @@ -20,24 +20,22 @@ set project_id [lindex [application_data_link::get_linked -from_object_id $offer_id -to_object_type content_item] 0] db_1row project_data {} +set locale [lang::user::site_wide_locale -user_id $contact_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 subject [lang::util::localize "#invoices.iv_offer_accepted_email_subject#" $locale] +set template "OfferAcceptedTemplate" +set offer_text [iv::offer::parse_data -offer_id $offer_id -recipient_id $contact_id -template $template -locale $locale] -set offer_text [iv::offer::parse_data -offer_id $offer_id -recipient_id [lindex $party_ids 0]] - if {[empty_string_p $file_ids]} { set pdf_file [text_templates::create_pdf_from_html -html_content "$offer_text"] if {![empty_string_p $pdf_file]} { set file_size [file size $pdf_file] - set file_ids [cr_import_content -title "Offer $offer_id" -description "PDF version of this offer" $offer_id $pdf_file $file_size application/pdf "Offer $offer_id"] + set file_ids [cr_import_content -title "Accepted_Offer_${offer_id}.pdf" -description "PDF version of this offer" $offer_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] } } -set offer_text "{[_ invoices.iv_offer_accepted_email]}" - - set parties_new [list] foreach party_id $party_ids { 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 -r1.2 -r1.3 --- openacs-4/packages/invoices/www/offer-accept-2.xql 6 Sep 2005 23:01:24 -0000 1.2 +++ openacs-4/packages/invoices/www/offer-accept-2.xql 11 Oct 2005 15:23:29 -0000 1.3 @@ -15,11 +15,10 @@ - select p.title as project_title, p.project_code + select p.title as project_title, p.project_code, contact_id from pm_projectsx p, cr_items oi where oi.latest_revision = p.project_id and oi.item_id = :project_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 -r1.2 -r1.3 --- openacs-4/packages/invoices/www/offer-ae-postgresql.xql 6 Sep 2005 23:01:24 -0000 1.2 +++ openacs-4/packages/invoices/www/offer-ae-postgresql.xql 11 Oct 2005 15:23:29 -0000 1.3 @@ -38,7 +38,8 @@ update iv_offers - set accepted_date = now() + set accepted_date = now(), + status = 'accepted' where offer_id = :new_offer_rev_id and accepted_date is null 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/offer-send.adp 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/offer-send.adp 11 Oct 2005 15:23:29 -0000 1.2 @@ -4,5 +4,5 @@ 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 -r1.5 -r1.6 --- openacs-4/packages/invoices/www/offer-send.tcl 5 Oct 2005 16:17:57 -0000 1.5 +++ openacs-4/packages/invoices/www/offer-send.tcl 11 Oct 2005 15:23:29 -0000 1.6 @@ -14,26 +14,34 @@ set page_title "[_ invoices.iv_offer_send]" db_1row offer_data {} +set project_id [lindex [application_data_link::get_linked -from_object_id $offer_id -to_object_type content_item] 0] +db_1row project_data {} +set locale [lang::user::site_wide_locale -user_id $contact_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 x [iv::util::get_x_field -offer_id $offer_rev_id] set accept_link [export_vars -base "[ad_url][ad_conn package_url]offer-accepted" {x {offer_id $offer_rev_id}}] content::item::set_live_revision -revision_id $offer_rev_id if {[empty_string_p $accepted_date]} { # send pending offer - set offer_text "{[_ invoices.iv_offer_email]}" + # set offer_text "{[_ invoices.iv_offer_email]}" + set subject [lang::util::localize "#invoices.iv_offer_email_subject#" $locale] + set template "OfferTemplate" } else { # send accepted offer - set offer_text "{[_ invoices.iv_offer_accepted_email]}" + # set offer_text "{[_ invoices.iv_offer_accepted_email]}" + set subject [lang::util::localize "#invoices.iv_offer_accepted_email_subject#" $locale] + set template "OfferAcceptedTemplate" } +set offer_text [iv::offer::parse_data -offer_id $offer_id -recipient_id $contact_id -template $template -locale $locale -accept_link $accept_link] + set pdf_file [text_templates::create_pdf_from_html -html_content "$offer_text"] if {![empty_string_p $pdf_file]} { set file_size [file size $pdf_file] - set file_ids [cr_import_content -title "Offer $offer_id" -description "PDF version of this offer" $offer_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] + set file_ids [cr_import_content -title "Offer_${offer_id}.pdf" -description "PDF version of this offer" $offer_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] } else { set file_ids "" } @@ -48,7 +56,6 @@ } set party_ids [contact::util::get_employees -organization_id $organization_id] -set file_ids [concat $file_ids [db_string get_files {} -default ""]] set parties_new [list] foreach party_id $party_ids { 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/www/offer-send.xql 5 Oct 2005 16:17:57 -0000 1.3 +++ openacs-4/packages/invoices/www/offer-send.xql 11 Oct 2005 15:23:29 -0000 1.4 @@ -12,13 +12,14 @@ - + - select max(item_id) as file_ids - from cr_items ci - where parent_id = :offer_id - and ci.storage_type = 'file' + select p.title as project_title, p.project_code, contact_id + from pm_projectsx p, cr_items oi + where oi.latest_revision = p.project_id + and oi.item_id = :project_id + 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/price-list-ae.tcl 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/price-list-ae.tcl 11 Oct 2005 15:23:29 -0000 1.2 @@ -53,21 +53,25 @@ 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]"}} + {credit_percent:float {label "[_ invoices.iv_price_list_credit_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_price_list_credit_percent_help]"} {after_html {%}}} } -new_request { set title "" set description "" set organization_id "" set currency [parameter::get -parameter "DefaultCurrency" -default "EUR"] + set credit_percent 0 } -edit_request { db_1row get_data {} + set credit_percent [format "%.1f" $credit_percent] } -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 ] + -currency $currency \ + -credit_percent $credit_percent] if {[exists_and_not_null category_ids]} { category::map_object -object_id $new_list_rev_id $category_ids @@ -79,7 +83,8 @@ -list_item_id $list_id \ -title $title \ -description $description \ - -currency $currency ] + -currency $currency \ + -credit_percent $credit_percent] if {[exists_and_not_null category_ids]} { category::map_object -object_id $new_list_rev_id $category_ids 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/price-list-ae.xql 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/price-list-ae.xql 11 Oct 2005 15:23:29 -0000 1.2 @@ -15,7 +15,7 @@ select r.title, r.description, t.list_id as list_rev_id, - t.currency + t.currency, t.credit_percent 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