Index: openacs-4/packages/invoices/invoices.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/invoices.info,v diff -u -r1.8 -r1.9 --- openacs-4/packages/invoices/invoices.info 13 Oct 2005 17:10:17 -0000 1.8 +++ openacs-4/packages/invoices/invoices.info 26 Oct 2005 12:00:37 -0000 1.9 @@ -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-10-13 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 -r1.10 -r1.11 --- openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml 23 Oct 2005 13:38:34 -0000 1.10 +++ openacs-4/packages/invoices/catalog/invoices.de_DE.ISO-8859-1.xml 26 Oct 2005 12:00:37 -0000 1.11 @@ -28,6 +28,10 @@ Kostennummer Kosten Z�hlung + Projektgutschriften + Gutschriften + Leeres Projekt zum Sammeln von Projektgutschriften + Gutschriften CSV W�hrung bezahlte W�hrung @@ -37,9 +41,13 @@ L�schen F�lligkeit �ndern + Vorlage Fileanzahl Timing Fixkisten? + Auftragsbest�tigungen + Rechnungen + Angebote Rechnung Rechnungsposition Positionsnummer @@ -163,6 +171,8 @@ Anzahl Positionen erstellt am erstellt von + Aufschlag + Gutschriftbetrag W�hrung Teillieferung Interne Notizen, welche den Abgabetermin, welcher dem Kunden kommuniziert wurde, erl�utern. @@ -261,6 +271,7 @@ Preisliste Preislisten Preisliste hinzuf�gen + Aufschlag W�hrung Preisliste l�schen Beschreibung @@ -307,6 +318,11 @@ Nummer Status Tabelle + Rechnung + Stornorechnung + Gutschrift + Angebot + Auftragsbest�tigung 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.9 -r1.10 --- openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 21 Oct 2005 14:09:46 -0000 1.9 +++ openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 26 Oct 2005 12:00:37 -0000 1.10 @@ -27,6 +27,10 @@ Cost number Costs Count + Credit awarded by projects + Credit + Empty project to collect credit from other projects + Credit CSV Currency Currency paid @@ -35,9 +39,13 @@ Delete Due date Edit + Template Number of files Finish date Fixed cost? + Accepted Offers + Invoices + Offers Invoice Invoice Item Invoice item number @@ -161,6 +169,8 @@ Total items Created on Created by + Credit percent + Credit sum Currency Date Comment: Internal Notes explaining the deadline communicated to the client @@ -259,6 +269,7 @@ Price List Price Lists Add Price List + Credit percent Currency Delete Price List Description @@ -305,6 +316,11 @@ Sort order Status Table + Invoice + Invoice cancellation + Credit + Offer + Accepted Offer Total amount h Unmounted 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.4 -r1.5 --- openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 12 Oct 2005 17:38:15 -0000 1.4 +++ openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 26 Oct 2005 12:00:37 -0000 1.5 @@ -309,3 +309,20 @@ constraint iv_default_objects_payment_fk references acs_objects ); + + +begin; + select acs_privilege__create_privilege('invoice_cancel',null,null); + select acs_privilege__create_privilege('invoice_export',null,null); + + -- add children + select acs_privilege__add_child('admin','invoice_cancel'); + select acs_privilege__add_child('admin','invoice_export'); +end; + + +insert into contact_message_types (message_type,pretty_name) values ('offer','#invoices.template_offer#'); +insert into contact_message_types (message_type,pretty_name) values ('offer_accepted','#invoices.template_offer_accepted#'); +insert into contact_message_types (message_type,pretty_name) values ('invoice','#invoices.template_invoice#'); +insert into contact_message_types (message_type,pretty_name) values ('invoice_cancel','#invoices.template_invoice_cancel#'); +insert into contact_message_types (message_type,pretty_name) values ('invoice_credit','#invoices.template_invoice_credit#'); 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 -r1.6 -r1.7 --- openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl 12 Oct 2005 17:38:15 -0000 1.6 +++ openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl 26 Oct 2005 12:00:37 -0000 1.7 @@ -221,42 +221,54 @@ -varname:required } { } { - upvar elements $varname template_list template_list template_type template_type template_object template_object + upvar $varname elements template_type template_type template_object template_object template_locale template_locale template_package_id template_package_id template_list template_list next_section next_section - if {[exists_and_not_null template_list]} { + if {[exists_and_not_null template_type]} { + + set template_list [list] + db_foreach get_messages { + select CASE WHEN owner_id = :template_package_id THEN 'public' ELSE contact__name(owner_id) END as public_display, + title, item_id + from contact_messages + where (owner_id in ( select party_id from parties ) + or owner_id = :template_package_id) + and message_type = :template_type + order by CASE WHEN owner_id = :template_package_id THEN '000000000' ELSE upper(contact__name(owner_id)) END, message_type, upper(title) + } { + lappend template_list [list "$title ($public_display)" $item_id] + } + append elements { - {template:text(select) - {label "[_ invoices.email_template]"} - {options $template_list} - {section "[_ contacts.Message]"} - } - {template_type:text(hidden) - {value $template_type} - } - {template_object:text(hidden) - {value $template_object} - } + {template_id:text(select) {label "[_ invoices.email_pdf_template]"} {options $template_list} {section "[_ contacts.Message]"}} + {template_type:text(hidden) {value $template_type}} + {template_object:text(hidden) {value $template_object}} + {template_locale:text(hidden) {value $template_locale}} + {template_package_id:text(hidden) {value $template_package_id}} } + set next_section "" } } ad_proc -public -callback acs_mail_lite::files -impl invoices { -varname:required - -recipient_id + -recipient_ids:required } { } { - upvar file_ids $varname template template template_type template_type template_object template_object + upvar $varname file_ids template_id template_id template_type template_type template_object template_object + set recipient_id [lindex $recipient_ids 0] if {[exists_and_not_null template_type] && $template_type == "invoice"} { - switch $template_type { - invoice { set pdf_title "Invoice" } - invoice_cancel { set pdf_title "Cancellation" } - invoice_credit { set pdf_title "Credit" } - offer { set pdf_title "Offer" } - offer_accpeted { set pdf_title "Accepted_Offer" } + if {![db_0or1row get_pretty_type { + select pretty_name + from contact_message_types + where message_type = :template_type + }]} { + return } + set pdf_title [string map {{ } _} [lang::util::localize $pretty_type $locale]] + if {$template_type == "invoice" || $template_type == "invoice_cancel" || $template_type == "invoice_credit"} { set invoice_id $template_object set locale [lang::user::site_wide_locale -user_id $recipient_id] @@ -286,3 +298,39 @@ } } } + +ad_proc -public -callback contact::organization_new_group -impl invoices { + {-organization_id:required} + {-group_id:required} +} { + Callback to create an empty project linked to a new empty credit offer for the customer. +} { + set list_of_create_groups [list "Customers"] + set group_ids [list] + foreach group_name $list_of_create_groups { + lappend group_ids [group::get_id -group_name $group_name] + } + + set already_offer_p [db_0or1row check_for_offer { + select of.offer_id as credit_offer_rev_id + from iv_offers of, cr_items oi, acs_rels r, + pm_projects p, cr_items pi + where r.object_id_one = pi.item_id + and r.object_id_two = oi.item_id + and r.rel_type = 'application_data_link' + and oi.latest_revision = of.offer_id + and of.status = 'credit' + and pi.latest_revision = p.project_id + and p.status_id = 2 + and p.customer_id = :organization_id + }] + + if {[lsearch $group_ids $group_id] >-1 && $!already_offer_p} { + # Create the new project and credit offer + foreach package_id [apm_package_id_from_key invoices] { + iv::offer::new_credit -organization_id $organization_id -package_id $package_id + # add folders invoices, offers, accepted + # callback: test if folder exists + } + } +} 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.4 -r1.5 --- openacs-4/packages/invoices/tcl/iv-install-procs.tcl 11 Oct 2005 15:23:28 -0000 1.4 +++ openacs-4/packages/invoices/tcl/iv-install-procs.tcl 26 Oct 2005 12:00:37 -0000 1.5 @@ -228,6 +228,24 @@ 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)} } + 0.01d14 0.01d15 { + db_transaction { + set organization_ids [db_list { + select g.party_id + from groups g, organizations o + where g.group_name = 'Customers' + and o.organization_id = g.party_id + }] + + set package_ids [apm_package_id_from_key invoices] + foreach organization_id $organization_ids { + foreach package_id $package_ids { + iv::offer::new_credit -organization_id $organization_id -package_id $package_id + iv::offer::pdf_folders -organization_id $organization_id -package_id $package_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.7 -r1.8 --- openacs-4/packages/invoices/tcl/offer-procs.tcl 14 Oct 2005 06:25:03 -0000 1.7 +++ openacs-4/packages/invoices/tcl/offer-procs.tcl 26 Oct 2005 12:00:37 -0000 1.8 @@ -346,4 +346,97 @@ } else { return 0 } -} \ No newline at end of file +} + +ad_proc -public iv::offer::new_credit { + -organization_id:required + {-package_id ""} +} { + @creation-date 2005-10-10 + + Creates an empty and closed project and link a new offer with status credit + for the given organization +} { + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + set user_id [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + set dotlrn_club_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type "dotlrn_club"] 0] + set pm_package_id [dotlrn_community::get_package_id_from_package_key -package_key "project-manager" -community_id $dotlrn_club_id] + set contacts_package_id [lindex [application_link::get_linked -from_package_id $package_id -to_package_key contacts] 0] + + db_transaction { + set project_rev_id [pm::project::new \ + -project_name "#invoices.credit_project_title#" \ + -description "#invoices.credit_project_desc#" \ + -mime_type "text/plain" \ + -status_id 2 \ + -organization_id $organization_id \ + -creation_user $user_id \ + -creation_ip $creation_ip \ + -package_id $pm_package_id] + + set project_id [pm::project::get_project_item_id -project_id $project_rev_id] + + # grant employees read access to project + set employees_group_id [group::get_id -group_name "Employees"] + if { ![empty_string_p $employees_group_id] } { + permission::grant -object_id $project_id -party_id $employees_group_id -privilege read + } + + set currency [iv::price_list::get_currency -organization_id $organization_id] + set vat_percent "16.0" + array set org_data [contacts::get_values \ + -group_name "Customers" \ + -object_type "organization" \ + -party_id $organization_id \ + -contacts_package_id $contacts_package_id] + if {[info exists org_data(vat_percent)]} { + set vat_percent [format "%.1f" $org_data(vat_percent)] + } + + set new_offer_rev_id [iv::offer::new \ + -title "#invoices.credit_offer_title#" \ + -description "#invoices.credit_offer_desc#" \ + -offer_nr [db_nextval iv_offer_seq] \ + -organization_id $organization_id \ + -amount_total 0 \ + -amount_sum 0 \ + -currency $currency \ + -payment_days 0 \ + -vat_percent $vat_percent \ + -vat 0 \ + -credit_percent 0 \ + -package_id $package_id] + + iv::offer::set_status -offer_id $offer_id -status credit + set offer_id [pm::project::get_project_item_id -project_id $new_offer_rev_id] + application_data_link::new -this_object_id $offer_id -target_object_id $project_id + } +} + +ad_proc -public iv::offer::pdf_folders { + -organization_id:required + {-package_id ""} +} { + @creation-date 2005-10-10 + + Creates folders for offers, accepted offers, invoices (including credit and cancellations) +} { + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] + } + + set root_folder_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type content_folder] 0] + + db_transaction { + foreach foldername [list iv_offer iv_accepted iv_invoice] { + set new_folder_id [fs::new_folder \ + -name $foldername \ + -pretty_name "#invoices.folder_$foldername#" \ + -parent_id $root_folder_id \ + -no_callback] + } + } +} 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.4 -r1.5 --- openacs-4/packages/invoices/tcl/offer-procs.xql 11 Oct 2005 15:23:28 -0000 1.4 +++ openacs-4/packages/invoices/tcl/offer-procs.xql 26 Oct 2005 12:00:37 -0000 1.5 @@ -66,7 +66,7 @@ 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, 'YYYY-MM-DD HH24:MI:SS') as finish_date, - o.creation_user, p.first_names, p.last_name, + o.creation_user, p.first_names, p.last_name, t.credit_percent, 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, 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.8 -r1.9 --- openacs-4/packages/invoices/www/invoice-ae.tcl 26 Oct 2005 06:37:32 -0000 1.8 +++ openacs-4/packages/invoices/www/invoice-ae.tcl 26 Oct 2005 12:00:38 -0000 1.9 @@ -174,6 +174,14 @@ set offer(rebate) [format "%.1f" $offer(rebate)] set offer(category) [lang::util::localize [category::get_name $offer(category_id)]] + if {[empty_string_p $offer(credit_percent)]} { + set offer(credit_percent) 0. + } + set offer(credit) [format "%.1f" [expr $offer(item_units) * (($offer(credit_percent) + 100.) / 100.)]] + set offer(credit) [format "%.2f" [expr $offer(credit) * $offer(price_per_unit)]] + set offer(credit) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(credit)]] + set offer(credit) [format "%.2f" [expr $offer(credit) - $offer(amount)]] + 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" @@ -200,6 +208,14 @@ 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)]] + + if {[empty_string_p $offer(credit_percent)]} { + set offer(credit_percent) 0. + } + set offer(credit) [format "%.1f" [expr $offer(item_units) * (($offer(credit_percent) + 100.) / 100.)]] + set offer(credit) [format "%.2f" [expr $offer(credit) * $offer(price_per_unit)]] + set offer(credit) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(credit)]] + set offer(credit) [format "%.2f" [expr $offer(credit) - $offer(amount)]] set offer_name "$offer(category): $offer(item_units) x $offer(price_per_unit) $currency = $offer(amount_sum) $currency" if {$offer(rebate) > 0} { @@ -260,9 +276,11 @@ set category_ids [category::ad_form::get_categories -container_object_id $container_objects(invoice_id)] set total_amount 0. + set total_credit 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_credit [expr $total_credit + $offer(credit)] } set total_amount [format "%.2f" $total_amount] set amount_sum $total_amount @@ -310,6 +328,25 @@ -sort_order $counter \ -vat $offer(vat) ] } + + # add credit offer entry + if {$total_credit > 0.} { + set vat_credit [format "%.2f" [expr $total_credit * $vat_percent / 100.]] + db_1row get_credit_offer {} + + # add new offer item + set offer_item_rev_id [iv::offer_item::new \ + -offer_id $credit_offer_rev_id \ + -title $title \ + -description $description \ + -comment "" \ + -item_nr $invoice_id \ + -item_units 1 \ + -price_per_unit $total_credit \ + -rebate 0 \ + -sort_order $invoice_id \ + -vat $vat_credit] + } } } -edit_data { db_transaction { @@ -352,6 +389,26 @@ -sort_order $counter \ -vat $offer(vat) ] } + + # edit credit offer entry + if {$total_credit > 0.} { + set vat_credit [format "%.2f" [expr $total_credit * $vat_percent / 100.]] + db_1row get_credit_offer_item {} + + # edit offer item + set offer_item_rev_id [iv::offer_item::edit \ + -offer_item_id $credit_offer_item_id \ + -offer_id $credit_offer_rev_id \ + -title $title \ + -description $description \ + -comment "" \ + -item_nr $invoice_id \ + -item_units 1 \ + -price_per_unit $total_credit \ + -rebate 0 \ + -sort_order $invoice_id \ + -vat $vat_credit] + } } } -after_submit { db_transaction { 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.5 -r1.6 --- openacs-4/packages/invoices/www/invoice-ae.xql 11 Oct 2005 15:23:29 -0000 1.5 +++ openacs-4/packages/invoices/www/invoice-ae.xql 26 Oct 2005 12:00:38 -0000 1.6 @@ -76,11 +76,11 @@ 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, + ofi.price_per_unit, ofi.item_nr, pi.item_id as project_id, of.credit_percent, 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 + category_object_map m, iv_offers of where o.object_id = ofi.offer_id and o.package_id = :package_id and oi.latest_revision = ofi.offer_id @@ -91,6 +91,7 @@ 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 of.offer_id = ofi.offer_id and not exists (select 1 from iv_invoice_items ii, iv_invoices i where ii.offer_item_id = ofi.offer_item_id @@ -107,9 +108,10 @@ select ir.title, ir.description, ir.item_id as iv_item_id, 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 + i.vat as old_vat, i.rebate, m.category_id, i.offer_item_id, + of.credit_percent from cr_items oi, iv_offer_items ofi, iv_invoice_items i, - cr_revisions ir, cr_items pi, cr_revisions pr, + cr_revisions ir, cr_items pi, cr_revisions pr, iv_offers of, 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 @@ -122,6 +124,7 @@ and r.rel_type = 'application_data_link' and pr.revision_id = pi.latest_revision and m.object_id = ofi.offer_item_id + and of.offer_id = ofi.offer_id order by pi.item_id, i.item_nr @@ -190,6 +193,50 @@ + + + + select of.offer_id as credit_offer_rev_id + from iv_offers of, cr_items oi, acs_rels r, + acs_objects o, pm_projects p, cr_items pi + where r.object_id_one = pi.item_id + and r.object_id_two = oi.item_id + and r.rel_type = 'application_data_link' + and oi.latest_revision = of.offer_id + and of.status = 'credit' + and o.object_id = of.offer_id + and o.package_id = :package_id + and pi.latest_revision = p.project_id + and p.status_id = 2 + and p.customer_id = :organization_id + + + + + + + + select ofi.offer_id as credit_offer_rev_id, + oi.item_id as credit_offer_item_id + from iv_offers of, cr_items i, acs_objects o, acs_rels r, + iv_offer_items ofi, cr_items oi, pm_projects p, cr_items pi + where r.object_id_one = pi.item_id + and r.object_id_two = i.item_id + and r.rel_type = 'application_data_link' + and o.object_id = of.offer_id + and o.package_id = :package_id + and of.offer_id = ofi.offer_id + and of.status = 'credit' + and i.latest_revision = of.offer_id + and oi.latest_revision = ofi.offer_item_id + and ofi.item_nr = :invoice_id + and pi.latest_revision = p.project_id + and p.status_id = 2 + and p.customer_id = :organization_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.2 -r1.3 --- openacs-4/packages/invoices/www/invoice-credit.tcl 11 Oct 2005 15:23:29 -0000 1.2 +++ openacs-4/packages/invoices/www/invoice-credit.tcl 26 Oct 2005 12:00:38 -0000 1.3 @@ -58,14 +58,15 @@ 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] + 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 "Customers" \ + -object_type "organization" \ + -party_id $organization_id \ + -contacts_package_id $contacts_package_id] + if {[info exists org_data(vat_percent)]} { + set vat_percent [format "%.1f" $org_data(vat_percent)] + } } -on_submit { set category_ids [category::ad_form::get_categories -container_object_id $container_objects(invoice_id)] } -new_data { 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.4 -r1.5 --- openacs-4/packages/invoices/www/offer-accept-2.adp 14 Oct 2005 06:25:03 -0000 1.4 +++ openacs-4/packages/invoices/www/offer-accept-2.adp 26 Oct 2005 12:00:38 -0000 1.5 @@ -6,4 +6,6 @@ party_ids="@contact_id@" content="@offer_text;noquote@" mime_type="text/html" subject="@subject@" export_vars="offer_id" return_url="@return_url;noquote@" - cancel_url="@cancel_url@" file_ids="@file_ids@"> + cancel_url="@cancel_url@" file_ids="@file_ids@" + template_type="offer_accepted" template_object="@offer_id@" + template_locale="@locale@" template_package_id="@contacts_package_id@"> 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.6 -r1.7 --- openacs-4/packages/invoices/www/offer-accept-2.tcl 24 Oct 2005 12:21:35 -0000 1.6 +++ openacs-4/packages/invoices/www/offer-accept-2.tcl 26 Oct 2005 12:00:38 -0000 1.7 @@ -48,5 +48,6 @@ set return_url [export_vars -base "${invoice_url}offer-ae" {offer_id {mode display}}] } set extra_data [list offer_id $offer_id] +set contacts_package_id [apm_package_id_from_key contacts] ad_return_template 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 -r1.2 -r1.3 --- openacs-4/packages/invoices/www/offer-ae.adp 28 Sep 2005 17:19:12 -0000 1.2 +++ openacs-4/packages/invoices/www/offer-ae.adp 26 Oct 2005 12:00:38 -0000 1.3 @@ -50,14 +50,36 @@ function calculateTotalAmount() { var form = document.forms.iv_offer_form; var total = 0.; + var credit_percent = form.credit_percent.value; + var credit = 0.; for (i=1; i<2+@start@; i++) { + units = form["item_units."+i].value + price = form["item_price."+i].value item_amount = form["amount_sum."+i].value item_rebate = form["item_rebate."+i].value - total = total + Math.round( (1*item_amount) * (100-item_rebate) ) /100; + item_total = Math.round( (1*item_amount) * (100-item_rebate) ) /100; + + new_units = Math.round( (1*units) * (100+credit_percent) / 10 ) / 10; + new_amount = Math.round( 100* (1*new_units) * (1*price) ) /100; + new_total = Math.round( (1*new_amount) * (100-item_rebate) ) /100; + + credit = credit + new_total - item_total; + total = total + item_total; } + form.credit_sum.value = formatCurrency(credit); + form.hidden_sum.value = formatCurrency(total); + + calculateFinalAmount(); +} + +function calculateFinalAmount() { + var form = document.forms.iv_offer_form; + + total = form.credit_sum.value + form.hidden_sum.value; + form.amount_sum.value = formatCurrency(total); form.amount_total.value = formatCurrency(total); } 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 -r1.4 -r1.5 --- openacs-4/packages/invoices/www/offer-ae.tcl 24 Oct 2005 12:21:35 -0000 1.4 +++ openacs-4/packages/invoices/www/offer-ae.tcl 26 Oct 2005 12:00:38 -0000 1.5 @@ -30,6 +30,11 @@ page_title:onevalue } +# todo: +# credit offers cannot be edited or deleted +# amount_sum >= total_amount +# offer cannot be edited or deleted if project is closed + set user_id [auth::require_login] set date_format "YYYY-MM-DD" set has_submit 0 @@ -105,8 +110,11 @@ set list_id [iv::price_list::get_list_id -organization_id $organization_id] db_multirow pricelist all_prices {} +if {$_offer_id && !$has_submit} { + # new offer + db_1row credit_percent {} +} - ad_form -name iv_offer_form -action offer-ae -mode $mode -has_submit $has_submit -has_edit $has_edit -export {organization_id return_url} -form { {offer_id:key} {organization_namex:text(inform) {label "[_ invoices.iv_offer_organization]"} {value "$organization_name"}} @@ -182,6 +190,22 @@ # 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 {%}}} + {hidden_sum:text(hidden) {value 0} + } + + if {![empty_string_p $_credit_percent] && $_credit_percent > 0} { + ad_form -extend -name iv_offer_form -form { + {credit_percent:float {label "[_ invoices.iv_offer_credit_percent]"} {html {size 5 maxlength 10 onChange calculateTotalAmount()}} {help_text "[_ invoices.iv_offer_credit_percent_help]"} {after_html {%}}} + {credit_sum:float,optional {label "[_ invoices.iv_offer_credit_sum]"} {html {size 10 maxlength 10 disabled t}} {help_text "[_ invoices.iv_offer_credit_sum_help]"} {after_html $currency}} + } + } else { + ad_form -extend -name iv_offer_form -form { + {credit_percent:text(hidden) {value 0} + {credit_sum:text(hidden) {value 0} + } + } + + ad_form -extend -name iv_offer_form -form { {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}} } @@ -547,7 +571,8 @@ -date_comment $date_comment \ -payment_days $payment_days \ -vat_percent $vat_percent \ - -vat $vat] + -vat $vat \ + -credit_percent $credit_percent] if {[exists_and_not_null category_ids]} { category::map_object -object_id $new_offer_rev_id $category_ids @@ -592,7 +617,8 @@ -date_comment $date_comment \ -payment_days $payment_days \ -vat_percent $vat_percent \ - -vat $vat] + -vat $vat \ + -credit_percent $credit_percent] if {[exists_and_not_null category_ids]} { category::map_object -object_id $new_offer_rev_id $category_ids @@ -624,8 +650,8 @@ set new_item_rev_id [iv::offer_item::new \ -offer_id $new_offer_rev_id \ -title $item(title) \ - -description $item(description) \ - -comment $item(comment) \ + -description $item(description) \ + -comment $item(comment) \ -item_nr $item(nr) \ -item_units $item(units) \ -price_per_unit $item(price) \ 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 -r1.2 -r1.3 --- openacs-4/packages/invoices/www/offer-ae.xql 6 Sep 2005 23:01:24 -0000 1.2 +++ openacs-4/packages/invoices/www/offer-ae.xql 26 Oct 2005 12:00:38 -0000 1.3 @@ -6,7 +6,8 @@ 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 + (t.amount_total - t.amount_sum) as sum_total_diff, + t.credit_percent as _credit_percent from iv_offers t, cr_items i where i.latest_revision = t.offer_id and i.item_id = :offer_id @@ -56,6 +57,16 @@ + + + + select credit_percent as _credit_percent + from iv_price_lists + where list_id = :list_id + + + +