Index: openacs-4/packages/invoices/invoices.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/invoices.info,v diff -u -r1.20 -r1.21 --- openacs-4/packages/invoices/invoices.info 15 Mar 2006 17:05:05 -0000 1.20 +++ openacs-4/packages/invoices/invoices.info 2 Apr 2006 22:08:02 -0000 1.21 @@ -7,15 +7,15 @@ <initial-install-p>f</initial-install-p> <singleton-p>t</singleton-p> - <version name="1.0d2" url="http://openacs.org/repository/download/apm/invoices-1.0d2.apm"> + <version name="1.0d3" url="http://openacs.org/repository/download/apm/invoices-1.0d3.apm"> <owner url="mailto:timo@timohentschel.de">Timo Hentschel</owner> <summary>Invoices package that will collect costs to invoice items in invoices and store data about received payment.</summary> <release-date>2005-11-15</release-date> <vendor url="http://www.cognovis.de">Cognovis</vendor> <description format="text/plain">Collect costs to invoice items and invoices, store payment information.</description> <maturity>0</maturity> - <provides url="invoices" version="1.0d2"/> + <provides url="invoices" version="1.0d3"/> <requires url="acs-content-repository" version="5.1.4d3"/> <requires url="acs-kernel" version="5.0d13"/> <requires url="acs-templating" version="5.1.5d1"/> 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.28 -r1.29 --- openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 15 Mar 2006 17:05:05 -0000 1.28 +++ openacs-4/packages/invoices/catalog/invoices.en_US.ISO-8859-1.xml 2 Apr 2006 22:08:02 -0000 1.29 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1"?> -<message_catalog package_key="invoices" package_version="1.0d1" locale="en_US" charset="ISO-8859-1"> +<message_catalog package_key="invoices" package_version="1.0d2" locale="en_US" charset="ISO-8859-1"> <msg key="accepted">Order confirmation</msg> <msg key="Accepted_date">Accepted on</msg> @@ -116,6 +116,8 @@ <msg key="iv_invoice_cancel_Add">Add invoice cancellation</msg> <msg key="iv_invoice_cancel_email"><html><body><h3>Cancellation</h3>%data.contact_salutation%,<p>see attached invoice cancellation %data.invoice_nr%.<p>Best wishes,<br>WIENERS + WIENERS GmbH<br></html></body></msg> <msg key="iv_invoice_cancel_email_subject">Cancellation # %invoice_nr%</msg> + <msg key="iv_invoice_cancellation">Canceled by</msg> + <msg key="iv_invoice_cancelled_invoice">Cancelled invoice</msg> <msg key="iv_invoice_closed_date">Finished on</msg> <msg key="iv_invoice_contact">Invoice Contact</msg> <msg key="iv_invoice_contact_help">Email recipient of this invoice</msg> @@ -140,6 +142,7 @@ <msg key="iv_invoice_edit_error">You are not allowed to edit a paid or cancelled invoice</msg> <msg key="iv_invoice_email"><html><body><h3>Invoice</h3>%data.contact_salutation%,<p>see attached invoice %data.invoice_nr%.<p>Best wishes,<br>WIENERS + WIENERS GmbH<br></html></body></msg> <msg key="iv_invoice_email_subject">Invoice # %invoice_nr%</msg> + <msg key="iv_invoice_end_date">End date</msg> <msg key="iv_invoice_invoice_nr">Invoice number</msg> <msg key="iv_invoice_invoice_nr_help">Number of the Invoice. Needs to be unique for accounting purposes.</msg> <msg key="iv_invoice_item_1">Invoice Item</msg> @@ -162,6 +165,7 @@ <msg key="iv_invoice_item_View">View Invoice Item</msg> <msg key="iv_invoice_New">New Invoice</msg> <msg key="iv_invoice_New2">Create New Invoice</msg> + <msg key="iv_invoice_no_invoice">Subprojects without invoice</msg> <msg key="iv_invoice_opening_p">Send Opening Page</msg> <msg key="iv_invoice_organization">Customer</msg> <msg key="iv_invoice_organization_help">Client for whom to create the invoice</msg> @@ -185,6 +189,7 @@ <msg key="iv_invoice_send">Send</msg> <msg key="iv_invoice_specialities">Invoice Specialities</msg> <msg key="iv_invoice_specialities_help">Invoice specialities to take into account</msg> + <msg key="iv_invoice_start_date">Start date</msg> <msg key="iv_invoice_status">Status</msg> <msg key="iv_invoice_status_billed">Billed</msg> <msg key="iv_invoice_status_cancelled">Cancelled</msg> @@ -193,6 +198,8 @@ <msg key="iv_invoice_Title">Title</msg> <msg key="iv_invoice_Title_help">Title for the invoice</msg> <msg key="iv_invoice_total_amount">Total amount</msg> + <msg key="iv_invoice_url">Invoices</msg> + <msg key="iv_invoice_url2">Rechnungen, Preislisten, Reports</msg> <msg key="iv_invoice_vat">VAT</msg> <msg key="iv_invoice_vat_percent">%VAT</msg> <msg key="iv_invoice_vat_percent_help">Percentage of VAT added in the invoice</msg> @@ -208,7 +215,7 @@ <msg key="iv_offer_accept">Accept Offer</msg> <msg key="iv_offer_accepted_date">Accepted on</msg> <msg key="iv_offer_accepted_date_help">Accepted date</msg> - <msg key="iv_offer_accepted_email"><html><body>%data.contact_salutation%, <p>thank you for your order! You'll find the details in the attached PDF file.<p>With best regards<p>@am_name@<br>Customer service</html></body></msg> + <msg key="iv_offer_accepted_email"><html><body>%data.contact_salutation%, <p>thank you for your order! You'll find the details in the attached PDF file.<p>With best regards<p>%am_name;noquote%<br>Customer service</html></body></msg> <msg key="iv_offer_accepted_email_subject">Order confirmation # %offer_nr%</msg> <msg key="iv_offer_accepted_thanks">Thank you for accepting our offer. We will contact you as soon as possible.</msg> <msg key="iv_offer_Add">Cost Sheet for "%organization_name%"</msg> @@ -236,10 +243,11 @@ <msg key="iv_offer_Description_help">Description of the cost sheet</msg> <msg key="iv_offer_Edit">Edit Cost Sheet</msg> <msg key="iv_offer_edit_error">You are not allowed to edit an accepted or invoiced cost sheet</msg> - <msg key="iv_offer_email"><html><body>%data.contact_salutation%,<p>you'll find the requested offer in the attached PDF file.<p>To accept this offer, please klick <a href="%accept_link%">here</a>.<p>With best regards<p>%am_name%<br>Kundenberatung</html></body></msg> + <msg key="iv_offer_email"><html><body>%data.contact_salutation%,<p>you'll find the requested offer in the attached PDF file.<p>To accept this offer, please klick <a href="%accept_link%">here</a>.<p>With best regards<p>%am_name;noquote%<br>Kundenberatung</html></body></msg> <msg key="iv_offer_email_subject">Offer # %offer_nr%</msg> <msg key="iv_offer_file">File upload</msg> <msg key="iv_offer_file_delete">Delete Files</msg> + <msg key="iv_offer_file_help">File Help</msg> <msg key="iv_offer_file_view">Files</msg> <msg key="iv_offer_finish_date">Finish on</msg> <msg key="iv_offer_finish_date_help">Deadline until which the project has to be delivered to the client</msg> @@ -297,6 +305,7 @@ <msg key="iv_offer_payment_days_help">How many days has the customer until the invoice has to be paid</msg> <msg key="iv_offer_project">Project</msg> <msg key="iv_offer_project_contact">Contact</msg> + <msg key="iv_offer_project_customer">Customer</msg> <msg key="iv_offer_project_date">Project deadline</msg> <msg key="iv_offer_project_date_help">Deadline to finish the project</msg> <msg key="iv_offer_project_descr">Description</msg> @@ -305,6 +314,7 @@ <msg key="iv_offer_project_title">Title</msg> <msg key="iv_offer_send">Send Offer</msg> <msg key="iv_offer_send_accepted">Send confirmation</msg> + <msg key="iv_offer_subproject_finish_date_help">Interne Deadline des Subprojektes</msg> <msg key="iv_offer_template">Template des Angebots</msg> <msg key="iv_offer_Title">Title</msg> <msg key="iv_offer_Title_help">Title of the offer</msg> @@ -372,12 +382,14 @@ <msg key="Offers">Cost Sheets</msg> <msg key="offers">Cost Sheets</msg> <msg key="Offers_items">Offers Items</msg> + <msg key="ok">Ok</msg> <msg key="Page_count">Number of pages</msg> <msg key="Parent_invoice_item">Parent invoice item</msg> <msg key="Parent_offer_item">Parent cost item</msg> <msg key="Payment">Payment</msg> <msg key="Payment_after__days">Payment after .. days</msg> <msg key="Payments">Payments</msg> + <msg key="Preview">Preview</msg> <msg key="Price">Price</msg> <msg key="Price_category">Price category</msg> <msg key="Price_List">Price List</msg> @@ -389,22 +401,31 @@ <msg key="Rebate">Rebate</msg> <msg key="Received_on">Received on</msg> <msg key="Recipient">Recipient</msg> + <msg key="show_all_offer_projects">All projects</msg> + <msg key="show_all_offers">All Offers</msg> + <msg key="show_all_offers2">Show all offers</msg> + <msg key="show_own_offer_projects">Own projects</msg> + <msg key="show_own_offers">My Offers</msg> + <msg key="show_own_offers2">Show only my own offers</msg> <msg key="Sort_order">Sort order</msg> <msg key="Status">Status</msg> <msg key="Table">Table</msg> + <msg key="template_cancelled_invoice_number">Cancelled invoice</msg> <msg key="template_invoice">Invoice</msg> <msg key="template_invoice_cancel">Invoice cancellation</msg> <msg key="template_invoice_credit">Credit</msg> <msg key="template_invoice_number">Invoice-Nr.</msg> <msg key="template_offer">Offer</msg> <msg key="template_offer_accepted">Order confirmation</msg> <msg key="Total">Total</msg> + <msg key="Total2">Total</msg> <msg key="Total_amount">Total amount</msg> <msg key="Total_offers">Total Offers</msg> <msg key="units">h</msg> <msg key="Unmounted">Unmounted</msg> <msg key="VAT">%VAT</msg> <msg key="VAT_amount">VAT amount</msg> + <msg key="vat_number">VAT number</msg> <msg key="year">Year</msg> <msg key="yes">Yes</msg> <msg key="You_have_selected_more">You have selected more than one customer. This is not allowed (how would you bill two different customers with the same invoice)</msg> 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.12 -r1.13 --- openacs-4/packages/invoices/lib/invoice-list.tcl 15 Mar 2006 17:05:05 -0000 1.12 +++ openacs-4/packages/invoices/lib/invoice-list.tcl 2 Apr 2006 22:08:02 -0000 1.13 @@ -33,6 +33,20 @@ } } +set start_where_clause "1 = 1" +if {[exists_and_not_null start_date] && $start_date != "YYYY-MM-DD" && [regexp {^([0-9]+)\-([0-9]+)\-([0-9]+)} $start_date match year month day]} { + set start_where_clause "o.creation_date >= to_timestamp(:start_date, 'YYYY-MM-DD')" +} elseif {[info exists start_date]} { + unset start_date +} + +set end_where_clause "1 = 1" +if {[exists_and_not_null end_date] && $end_date != "YYYY-MM-DD" && [regexp {^([0-9]+)\-([0-9]+)\-([0-9]+)} $end_date match year month day]} { + append end_where_clause " and o.creation_date <= to_timestamp(:end_date, 'YYYY-MM-DD')" +} elseif {[info exists end_date]} { + unset end_date +} + set user_id [ad_conn user_id] set timestamp_format "YYYY-MM-DD HH24:MI:SS" set bulk_actions [list "[_ invoices.iv_invoice_send]" "${base_url}invoices-view" "[_ invoices.iv_invoice_send]" "[_ invoices.iv_invoice_pay]" "${base_url}invoice-pay" "[_ invoices.iv_invoice_pay]"] @@ -50,6 +64,8 @@ } } +lappend actions "[_ invoices.iv_invoice_url]" $base_url "[_ invoices.iv_invoice_url2]" + if {$invoice_cancel_p} { lappend actions "[_ invoices.iv_journal_check]" "${base_url}journal-check" "[_ invoices.iv_journal_check]" } @@ -72,6 +88,7 @@ } description { label {[_ invoices.iv_invoice_Description]} + display_template {@iv_invoice.description;noquote@} } total_amount { label {[_ invoices.iv_invoice_total_amount]} @@ -100,7 +117,14 @@ display_template {[_ invoices.iv_invoice_status_@iv_invoice.status@]} } action { - display_template {<if @iv_invoice.status@ eq new><a href="@iv_invoice.edit_link@">#invoices.Edit#</a> </if><else><if @invoice_cancel_p@ true><a href="@iv_invoice.cancel_link@">#invoices.Invoice_Cancel#</a> </if></else><if @iv_invoice.status@ ne billed and @iv_invoice.status@ ne paid><a href="@iv_invoice.delete_link@">#invoices.Delete#</a></if> <a href="@iv_invoice.preview_link@">#invoices.Preview#</a>} + display_template { + <if @iv_invoice.status@ eq new><a href="@iv_invoice.edit_link@">#invoices.Edit#</a> </if> + <else><if @invoice_cancel_p@ true and @iv_invoice.cancelled_p@ eq f><a href="@iv_invoice.cancel_link@">#invoices.Invoice_Cancel#</a> </if></else> + <if @iv_invoice.status@ ne billed and @iv_invoice.status@ ne paid><a href="@iv_invoice.delete_link@">#invoices.Delete#</a> </if> + <if @iv_invoice.status@ eq new><a href="@iv_invoice.preview_link@">#invoices.Preview#</a>  <a href="@iv_invoice.create_link@">#invoices.View_invoice#</a></if> + <elseif @iv_invoice.cancelled_p@ ne t><a href="@iv_invoice.copy_link@">#invoices.View_copy#</a></elseif> + <elseif @iv_invoice.parent_invoice_id@ not nil><a href="@iv_invoice.copy_link@">#invoices.View_cancel#</a></elseif> + } } } -actions $actions -sub_class narrow \ -bulk_actions $bulk_actions \ @@ -155,6 +179,7 @@ } -orderby_name orderby -html {width 100%} \ -page_size_variable_p 1 \ -page_size $page_size \ + -page_groupsize 10 \ -page_flush_p 1 \ -page_query_name iv_invoice_paginated \ -pass_properties {invoice_cancel_p} \ @@ -163,6 +188,12 @@ where_clause {t.organization_id = :organization_id} } page_num {} + start_date { + where_clause $start_where_clause + } + end_date { + where_clause $end_where_clause + } } \ -formats { normal { @@ -181,18 +212,22 @@ set time_format "[lc_get d_fmt] %X" set date_format [lc_get d_fmt] set contacts_p [apm_package_installed_p contacts] +set contacts_package_id [apm_package_id_from_key contacts] +set return_url "[ad_conn url]?[ad_conn query]" -db_multirow -extend {creator_link edit_link display_link cancel_link delete_link preview_link recipient} iv_invoice iv_invoice {} { +db_multirow -extend {creator_link edit_link display_link cancel_link delete_link preview_link create_link copy_link recipient} iv_invoice iv_invoice {} { # Ugly hack. We should find out which contact package is linked set creation_date [lc_time_fmt $creation_date $time_format] set due_date [lc_time_fmt $due_date $date_format] set display_link [export_vars -base "${base_url}invoice-ae" {invoice_id {mode display}}] - set edit_link [export_vars -base "${base_url}invoice-ae" {invoice_id}] - set cancel_link [export_vars -base "${base_url}invoice-cancellation" {{organization_id $orga_id} {parent_id $invoice_rev_id}}] - set delete_link [export_vars -base "${base_url}invoice-delete" {invoice_id}] + set edit_link [export_vars -base "${base_url}invoice-ae" {invoice_id return_url}] + set cancel_link [export_vars -base "${base_url}invoice-cancellation" {{organization_id $orga_id} {parent_id $invoice_rev_id} return_url}] + set delete_link [export_vars -base "${base_url}invoice-delete" {invoice_id return_url}] set preview_link [export_vars -base "${base_url}invoice-preview" {invoice_id}] + set create_link [export_vars -base "${base_url}invoice-send-1" {invoice_id return_url}] + set copy_link [export_vars -base "${base_url}invoice-preview" {invoice_id {invoice_p 0}}] if {[empty_string_p $total_amount]} { set total_amount 0 } @@ -202,9 +237,16 @@ } if { $contacts_p } { - set recipient "<a href=\"[contact::url -party_id $recipient_id]\">[contact::name -party_id $recipient_id]</a>" - set creator_link "[contact::url -party_id $creation_user]" + set recipient "<a href=\"[contact::url -package_id $contacts_package_id -party_id $recipient_id]\">[contact::name -party_id $recipient_id]</a>" + set creator_link "[contact::url -package_id $contacts_package_id -party_id $creation_user]" } else { set recipient [person::name -person_id $recipient_id] } + + set desc_list {} + foreach project_id [split $description ,] { + set project_id [string trim $project_id] + lappend desc_list "<a href=\"[export_vars -base "${base_url}project-search" {project_id}]\">$project_id</a>" + } + set description [join $desc_list ", "] } 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 -r1.12 -r1.13 --- openacs-4/packages/invoices/lib/projects-billable.tcl 15 Mar 2006 17:05:05 -0000 1.12 +++ openacs-4/packages/invoices/lib/projects-billable.tcl 2 Apr 2006 22:08:02 -0000 1.13 @@ -74,6 +74,9 @@ set row_list "checkbox {}\n $row_list" } +set normal_actions [list "[_ invoices.iv_invoice_url]" $base_url "[_ invoices.iv_invoice_url2]"] + + template::list::create \ -name projects \ -key project_id \ @@ -113,21 +116,23 @@ } } -bulk_actions $actions \ -bulk_action_export_vars $bulk_id_list \ + -actions $normal_actions \ -sub_class narrow \ -groupby { label "[_ invoices.Group_by]:" type multivar values { {[_ invoices.Customer] { {groupby name } {orderby project_id,asc }}}} } -orderby { - default_value name + default_value project_id name { label {[_ invoices.Customer]} - orderby {name} + orderby {lower(name)} default_direction asc } project_id { label {[_ invoices.iv_invoice_project_id]} - orderby {r.item_id} + orderby_desc {lower(name) asc, sub.customer_id asc, r.item_id desc} + orderby_asc {lower(name) asc, sub.customer_id asc, r.item_id asc} default_direction desc } title { @@ -195,6 +200,7 @@ set time_format "[lc_get d_fmt] %X" set tot_amount_open 0 +set contacts_package_id [apm_package_id_from_key contacts] db_multirow -extend {project_link recipient currency} projects projects_to_bill {} { set amount_open [format "%.2f" $amount_open] @@ -203,8 +209,8 @@ set creation_date [lc_time_fmt $creation_date $time_format] if { $contacts_p } { - set recipient "<a href=\"[contact::url -party_id $recipient_id]\">[contact::name -party_id $recipient_id]</a>" - set name "<a href=\"[contact::url -party_id $org_id]\">[contact::name -party_id $org_id]</a>" + set recipient "<a href=\"[contact::url -package_id $contacts_package_id -party_id $recipient_id]\">[contact::name -party_id $recipient_id]</a>" + set name "<a href=\"[contact::url -package_id $contacts_package_id -party_id $org_id]\">[contact::name -party_id $org_id]</a>" } else { set recipient [person::name -person_id $recipient_id] set name $recipient 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 -r1.7 -r1.8 --- openacs-4/packages/invoices/lib/projects-billable.xql 19 Dec 2005 20:08:28 -0000 1.7 +++ openacs-4/packages/invoices/lib/projects-billable.xql 2 Apr 2006 22:08:02 -0000 1.8 @@ -40,6 +40,7 @@ and r.object_id_one = pi.item_id and r.object_id_two = oi.item_id and p.status_id = :p_closed_id + and p.invoice_p = true and ofi.offer_id = oi.latest_revision and oo.object_id = oi.item_id and oo.package_id = :package_id 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.10 -r1.11 --- openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 15 Mar 2006 17:05:06 -0000 1.10 +++ openacs-4/packages/invoices/sql/postgresql/invoices-create.sql 2 Apr 2006 22:08:02 -0000 1.11 @@ -98,6 +98,7 @@ references organizations, -- who pays? comment text, + reservation text, amount_total numeric(12,2), amount_sum numeric(12,2), currency char(3) @@ -203,7 +204,7 @@ vat numeric(12,2) default 0, -- VAT amount status varchar(10) default 'new', - -- new, cancelled, billed, paid + -- new, sent, 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/sql/postgresql/upgrade/upgrade-1.0d1-1.0d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-1.0d1-1.0d2.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-1.0d1-1.0d2.sql 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,19 @@ +create table iv_journals ( + file_id integer + constraint iv_journals_pk + primary key, + creation_date timestamptz + constraint iv_journals_date_nn + not null +); + +create table iv_journal_country_codes ( + iso_code char(2) + constraint iv_journal_country_codes_pk + primary key + constraint iv_journal_country_codes_iso_code_fk + references countries, + journal_code varchar(4) + constraint iv_journal_country_codes_journal_code_nn + not null +); Index: openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-1.0d2-1.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-1.0d2-1.0d3.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/sql/postgresql/upgrade/upgrade-1.0d2-1.0d3.sql 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1 @@ +alter table iv_offers add column reservation text; 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.20 -r1.21 --- openacs-4/packages/invoices/tcl/invoice-procs.tcl 15 Mar 2006 17:05:06 -0000 1.20 +++ openacs-4/packages/invoices/tcl/invoice-procs.tcl 2 Apr 2006 22:08:02 -0000 1.21 @@ -198,6 +198,7 @@ set data(creator_name) "$data(first_names) $data(last_name)" set data(amount_diff) [format "%.2f" [expr abs($data(total_amount) - $data(amount_sum))]] set total_amount_diff $data(amount_diff) + set total_amount $data(total_amount) set data(amount_diff) [lc_numeric $data(amount_diff) "" $locale] set data(final_amount) [lc_numeric [format "%.2f" [expr $data(total_amount)+$data(vat)]] "" $locale] set data(vat) [lc_numeric [format "%.2f" $data(vat)] "" $locale] @@ -250,6 +251,22 @@ } } + if {[db_0or1row payment_method {}]} { + set data(payment_method) $payment_method + } else { + set data(payment_method) transfer + } + + set multiplier 1 + if {![empty_string_p $data(parent_invoice_id)]} { + # this is a cancellation, so show invoice-items of cancelled invoice + set parent_invoice_id $data(parent_invoice_id) + db_1row parent_data {} -column_array parent + set invoice_id $parent(invoice_id) + # show negative amounts + set multiplier -1 + } + # get the invoice item data set sum 0. set project_sum 0. @@ -265,7 +282,7 @@ set project_sum 0. } set item_units [format "%.2f" [expr $item_units * (1. + ($credit_percent / 100.))]] - set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]] + set amount_sum [format "%.2f" [expr $multiplier * $item_units * $price_per_unit]] set amount_total [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]] set sum [expr $sum + $amount_total] set project_sum [expr $project_sum + $amount_total] @@ -281,10 +298,13 @@ set contact_name [contact::name -party_id $contact_id] } - # It is possible that you have an invoice without items, e.g. a credit invoice + # It is possible that you have an invoice without items, e.g. a credit invoice if {$sum ne "0."} { set data(amount_sum) $sum - set data(total_amount) [expr $sum - $total_amount_diff] + set data(total_amount) $total_amount + # set data(total_amount) [expr $sum - $total_amount_diff] + set data(amount_diff) [format "%.2f" [expr abs($data(total_amount) - $data(amount_sum))]] + set data(amount_diff) [lc_numeric $data(amount_diff) "" $locale] set data(vat) [expr $data(vat_percent) * $data(total_amount) / 100.] set data(final_amount) [lc_numeric [format "%.2f" [expr $data(total_amount)+$data(vat)]] "" $locale] set data(vat) [lc_numeric [format "%.2f" $data(vat)] "" $locale] @@ -324,8 +344,8 @@ } # parse invoice email text - eval [template::adp_compile -string [lang::util::localize $email_text $contact_locale]] - set final_content [list $__adp_output] + eval [template::adp_compile -string $email_text] + set final_content [lang::util::localize [list $__adp_output] $contact_locale] # create and parse all invoice documents foreach document_type $types { 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.10 -r1.11 --- openacs-4/packages/invoices/tcl/invoice-procs.xql 30 Jan 2006 12:50:39 -0000 1.10 +++ openacs-4/packages/invoices/tcl/invoice-procs.xql 2 Apr 2006 22:08:02 -0000 1.11 @@ -70,7 +70,7 @@ to_char(t.due_date, 'YYYY-MM-DD HH24:MI:SS') as invoice_date, to_char(t.due_date + cast(t.payment_days || ' days' as interval), 'YYYY-MM-DD HH24:MI:SS') as due_date, t.payment_days, t.currency, t.organization_id, t.recipient_id, - t.contact_id + t.contact_id, t.parent_invoice_id from iv_invoices t, cr_revisions r, cr_items i, acs_objects o, persons p where r.revision_id = t.invoice_id @@ -82,6 +82,31 @@ </querytext> </fullquery> +<fullquery name="iv::invoice::parse_data.payment_method"> + <querytext> + + select ot.option as payment_method + from ams_option_types ot, ams_options o, ams_attribute_values v, ams_attributes a + where v.object_id = :rec_orga_revision_id + and v.attribute_id = a.attribute_id + and a.attribute_name = 'payment_method' + and v.value_id = o.value_id + and o.option_id = ot.option_id + + </querytext> +</fullquery> + +<fullquery name="iv::invoice::parse_data.parent_data"> + <querytext> + + select i.item_id as invoice_id, t.invoice_nr + from cr_items i, iv_invoices t + where i.latest_revision = t.invoice_id + and t.invoice_id = :parent_invoice_id + + </querytext> +</fullquery> + <fullquery name="iv::invoice::parse_data.invoice_items"> <querytext> @@ -104,7 +129,7 @@ and pi.latest_revision = pr.revision_id and pr.revision_id = p.project_id and o.offer_id = ofi.offer_id - order by pr.title, ofi.sort_order + order by pr.title, ii.item_nr </querytext> </fullquery> 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.13 -r1.14 --- openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl 15 Mar 2006 17:05:06 -0000 1.13 +++ openacs-4/packages/invoices/tcl/invoices-callback-procs.tcl 2 Apr 2006 22:08:02 -0000 1.14 @@ -109,7 +109,7 @@ # check if invoice exists db_foreach invoices { - select cri.item_id as invoice_id, r.title as invoice_title + select cri.item_id as invoice_id, r.title as invoice_title, i.invoice_nr from iv_invoice_items ii, iv_offer_items oi, iv_invoices i, cr_items cri, cr_items cro, cr_revisions r where ii.offer_item_id = oi.offer_item_id @@ -124,9 +124,9 @@ where ci.parent_invoice_id = i.invoice_id and i.cancelled_p = 't' and cri.latest_revision = ci.invoice_id) - group by cri.item_id, r.title + group by cri.item_id, r.title, i.invoice_nr } { - append project_links "<li> <a href=\"[export_vars -base "${invoice_base_url}invoice-ae" {invoice_id {mode display}}]\">$invoice_title</a></li>" + append project_links "<li> <a href=\"[export_vars -base "${invoice_base_url}invoice-ae" {invoice_id {mode display}}]\">\#\invoices.Invoice# $invoice_nr</a></li>" } } else { 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.10 -r1.11 --- openacs-4/packages/invoices/tcl/iv-install-procs.tcl 27 Dec 2005 16:39:35 -0000 1.10 +++ openacs-4/packages/invoices/tcl/iv-install-procs.tcl 2 Apr 2006 22:08:02 -0000 1.11 @@ -45,6 +45,7 @@ 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 {reservation} -datatype {text} -pretty_name {[_ invoices.Reservation]} -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)} @@ -264,6 +265,9 @@ 0.01d21 0.01d22 { content::type::attribute::new -content_type {iv_invoice} -attribute_name {contact_id} -datatype {number} -pretty_name {[_ invoices.Contact]} -column_spec {integer} } + 1.0d2 1.0d3 { + content::type::attribute::new -content_type {iv_offer} -attribute_name {reservation} -datatype {text} -pretty_name {[_ invoices.Reservation]} -column_spec {text} + } } } 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.19 -r1.20 --- openacs-4/packages/invoices/tcl/offer-procs.tcl 15 Mar 2006 17:05:06 -0000 1.19 +++ openacs-4/packages/invoices/tcl/offer-procs.tcl 2 Apr 2006 22:08:02 -0000 1.20 @@ -12,6 +12,7 @@ {-title ""} {-description ""} {-comment ""} + {-reservation ""} {-offer_nr ""} {-organization_id ""} {-amount_total ""} @@ -48,6 +49,7 @@ -description $description \ -attributes [list \ [list comment $comment] \ + [list reservation $reservation] \ [list offer_nr $offer_nr] \ [list organization_id $organization_id] \ [list amount_total $amount_total] \ @@ -82,6 +84,7 @@ {-title ""} {-description ""} {-comment ""} + {-reservation ""} {-offer_nr ""} {-organization_id ""} {-amount_total ""} @@ -109,6 +112,7 @@ -description $description \ -attributes [list \ [list comment $comment] \ + [list reservation $reservation] \ [list offer_nr $offer_nr] \ [list organization_id $organization_id] \ [list amount_total $amount_total] \ @@ -222,6 +226,9 @@ set orga_revision_id [content::item::get_best_revision -item_id $data(organization_id)] set contact_revision_id [content::item::get_best_revision -item_id $data(contact_id)] set rec_client_id [ams::value -attribute_name "client_id" -object_id $orga_revision_id -locale $locale] + if {[empty_string_p $data(credit_percent)]} { + set data(credit_percent) 0 + } # offer contact data contact::employee::get -employee_id $data(contact_id) -array contact_data @@ -251,6 +258,7 @@ # data of offer items db_multirow -local -extend {amount_sum amount_total category} items offer_items {} { + set item_units [format "%.2f" [expr $item_units * (1. + ($data(credit_percent) / 100.))]] set amount_sum [format "%.2f" [expr $item_units * $price_per_unit]] set amount_total [lc_numeric [format "%.2f" [expr (1. - ($rebate / 100.)) * $amount_sum]] "" $locale] set amount_sum [lc_numeric $amount_sum "" $locale] @@ -289,8 +297,8 @@ } # parse offer email text - eval [template::adp_compile -string [lang::util::localize $email_text $locale]] - set final_content [list $__adp_output] + eval [template::adp_compile -string $email_text] + set final_content [lang::util::localize [list $__adp_output] $locale] # get the url to the document template set template_path [parameter::get -parameter OfferTemplate] 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.9 -r1.10 --- openacs-4/packages/invoices/tcl/offer-procs.xql 25 Jan 2006 16:58:32 -0000 1.9 +++ openacs-4/packages/invoices/tcl/offer-procs.xql 2 Apr 2006 22:08:02 -0000 1.10 @@ -47,7 +47,7 @@ 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 + t.currency, t.organization_id, t.amount_sum, t.reservation from iv_offers t, cr_revisions r, cr_items i, acs_objects o, persons p where r.revision_id = t.offer_id @@ -72,7 +72,7 @@ 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, pp.contact_id + pp.project_code, pi.item_id as project_id, pp.contact_id, t.reservation from iv_offers t, cr_revisions cr, cr_items ci, acs_objects o, persons p, acs_data_links r, cr_items pi, cr_revisions pr, pm_projects pp where cr.revision_id = t.offer_id Index: openacs-4/packages/invoices/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/index.adp,v diff -u -r1.4 -r1.5 --- openacs-4/packages/invoices/www/index.adp 18 Dec 2005 15:34:54 -0000 1.4 +++ openacs-4/packages/invoices/www/index.adp 2 Apr 2006 22:08:02 -0000 1.5 @@ -16,4 +16,5 @@ <li><a href="offer-items">#invoices.Offers_items#</a></li> <li><a href="offer-items-reports">#invoices.Offer_Items_Reports#</a></li> <li><a href="invoice-items-reports">#invoices.Invoice_Items_Reports#</a></li> +<li><a href="@fs_folder_url@">#invoices.iv_journal#</a></li> </ul> Index: openacs-4/packages/invoices/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/index.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/invoices/www/index.tcl 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/index.tcl 2 Apr 2006 22:08:02 -0000 1.2 @@ -15,4 +15,10 @@ set page_title "[_ invoices.invoices]" set context [list] +set folder_id [parameter::get -parameter "JournalFolderID"] +acs_object::get -object_id $folder_id -array folder +set fs_package_id $folder(package_id) +set fs_package_url [site_node::get_url_from_object_id -object_id $fs_package_id] +set fs_folder_url [export_vars -base "${fs_package_url}index" {folder_id {orderby name,desc}}] + ad_return_template 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.27 -r1.28 --- openacs-4/packages/invoices/www/invoice-ae.tcl 15 Mar 2006 17:05:06 -0000 1.27 +++ openacs-4/packages/invoices/www/invoice-ae.tcl 2 Apr 2006 22:08:02 -0000 1.28 @@ -68,6 +68,7 @@ } } +set current_url "[ad_conn url]?[ad_conn query]" set package_id [ad_conn package_id] set user_id [auth::require_login] set date_format "YYYY-MM-DD" @@ -148,13 +149,46 @@ set contact_options $recipient_options } else { # normal invoice: get recipients from projects - # We only want to offer invoice recipients that have actually been assigned in the project - # The other query would show all of them. - set contact_options [db_list_of_lists contacts {}] + # We want to mark invoice recipients that have actually been assigned in the project + set project_contacts [db_list contacts {}] + set contact_id [lindex $project_contacts 0] + set contact_options {} + + # add all invoice-recipients of customer to recipient list + # mark project recipients as bold + set project_recipients [db_list recipients {}] + set recipient_id [lindex $project_recipients 0] + set recipients [db_list invoice_recipients {}] set recipient_options {} - db_foreach recipients {} { - lappend recipient_options [list [contact::name -party_id $rec_id -reverse_order] $rec_id] + + foreach recipient $recipients { + set recipient_name [contact::name -party_id $recipient -reverse_order] + if {[lsearch -exact $project_recipients $recipient] == -1 || $mode == "display"} { + lappend recipient_options [list $recipient_name $recipient] + } else { + lappend recipient_options [list "* $recipient_name *" $recipient] + } } + + # add all employees of customer to recipient-list + foreach employee_id [contact::util::get_employees -organization_id $organization_id] { + if {[lsearch -exact $recipients $employee_id] == -1} { + set employee_name [contact::name -party_id $employee_id -reverse_order] + if {[lsearch -exact $project_recipients $employee_id] == -1 || $mode == "display"} { + lappend recipient_options [list $employee_name $employee_id] + } else { + lappend recipient_options [list "* $employee_name *" $employee_id] + } + } + + if {[lsearch -exact $project_contacts $employee_id] == -1 || $mode == "display"} { + lappend contact_options [list $employee_name $employee_id] + } else { + lappend contact_options [list "* $employee_name *" $employee_id] + } + } + + set contact_options [lsort -dictionary $contact_options] set recipient_options [lsort -dictionary $recipient_options] } @@ -170,7 +204,7 @@ {contact_id:integer(select),optional {label "[_ invoices.iv_invoice_contact]"} {options $contact_options} {help_text "[_ invoices.iv_invoice_contact_help]"}} {recipient_id:integer(select),optional {label "[_ invoices.iv_invoice_recipient]"} {options $recipient_options} {help_text "[_ invoices.iv_invoice_recipient_help]"}} {title:text(inform) {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]"}} + {description:text(inform),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)]]} { @@ -238,7 +272,7 @@ } 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]"}} + {payment_days:integer(inform),optional {label "[_ invoices.iv_invoice_payment_days]"} {html {size 5 maxlength 5}} {help_text "[_ invoices.iv_invoice_payment_days_help]"}} } if {!$has_submit} { @@ -261,8 +295,30 @@ if {!$_invoice_id} { # adding a new invoice if {![empty_string_p $project_id]} { - + + # get all subprojects marked for no invoice to display warning + foreach main_project_id $project_id { + set subprojects [wieners::process::subprojects -project_id $main_project_id] + + db_foreach not_invoiceable_subprojects {} { + set offer_url [export_vars -base offer-ae {offer_id {mode display}}] + lappend no_invoice($main_project_id) "<a href=\"$offer_url\">$offer_title</a>" + } + } + + set project_title 0 db_foreach offer_items {} -column_array offer { + + # check if project changed in loop over offer-items + # show warning of subprojects without invoice if necessary + if {$project_title != $offer(project_title) && $project_title != "0" && [exists_and_not_null no_invoice($old_project_id)]} { + ad_form -extend -name iv_invoice_form -form \ + [list [list "no_invoice.${old_project_id}:text(inform),optional" \ + [list label "<font color=red>\#invoices.iv_invoice_no_invoice\#</font>"] \ + [list value "<ul><li>[join $no_invoice($old_project_id) "</li><li>"]</li></ul>"] \ + [list section "<a href=\"$offer_url\">[_ invoices.iv_invoice_project_title] $project_title</a>"] ] ] + } + 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)]] @@ -290,14 +346,27 @@ } set offers($offer(offer_item_id)) [array get offer] + set offer_url [export_vars -base offer-ae {{offer_id $offer(offer_cr_item_id)} {mode display} {return_url $current_url}}] + set project_title $offer(project_title) + set old_project_id $offer(project_id) 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 "[_ invoices.iv_invoice_project_title] $offer(project_title)"] ] ] + [list section "<a href=\"$offer_url\">[_ invoices.iv_invoice_project_title] $project_title</a>"] ] ] } + + # check if project changed in loop over offer-items + # show warning of subprojects without invoice if necessary + if {[exists_and_not_null offer(project_title)] && [exists_and_not_null no_invoice($old_project_id)]} { + ad_form -extend -name iv_invoice_form -form \ + [list [list "no_invoice.${old_project_id}:text(inform),optional" \ + [list label "<font color=red>\#invoices.iv_invoice_no_invoice\#</font>"] \ + [list value "<ul><li>[join $no_invoice($old_project_id) "</li><li>"]</li></ul>"] \ + [list section "<a href=\"$offer_url\">[_ invoices.iv_invoice_project_title] $project_title</a>"] ] ] + } } } else { # edit or display existing invoice @@ -329,6 +398,7 @@ } set offers($offer(iv_item_id)) [array get offer] + set offer_url [export_vars -base offer-ae {{offer_id $offer(offer_cr_item_id)} {mode display} {return_url $current_url}}] if {$mode == "edit"} { # edit: use checkboxes @@ -337,14 +407,14 @@ [list label "$offer(item_nr), $offer(title)"] \ [list options [list [list "$offer_name" t]]] \ [list values [list t]] \ - [list section "[_ invoices.iv_invoice_project_title] $offer(project_title)"] ] ] + [list section "<a href=\"$offer_url\">[_ invoices.iv_invoice_project_title] $offer(project_title)</a>"] ] ] } 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 "[_ invoices.iv_invoice_project_title] $offer(project_title)"] ] ] + [list section "<a href=\"$offer_url\">[_ invoices.iv_invoice_project_title] $offer(project_title)</a>"] ] ] } } } @@ -364,6 +434,16 @@ db_1row offer_data {} set vat_percent [format "%.1f" $vat_percent] set invoice_rebate $open_rebate + + 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)] + } } -edit_request { db_1row get_data {} set creator_name "$first_names $last_name" 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.13 -r1.14 --- openacs-4/packages/invoices/www/invoice-ae.xql 15 Mar 2006 17:05:06 -0000 1.13 +++ openacs-4/packages/invoices/www/invoice-ae.xql 2 Apr 2006 22:08:02 -0000 1.14 @@ -71,7 +71,7 @@ <fullquery name="contacts"> <querytext> - select p.first_names || ' ' || p.last_name, p.person_id + select 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 @@ -92,6 +92,17 @@ </querytext> </fullquery> +<fullquery name="invoice_recipients"> + <querytext> + + select r.object_id_one + from acs_rels r + where r.object_id_two = :organization_id + and r.rel_type = 'contact_rels_ir' + + </querytext> +</fullquery> + <fullquery name="check_cancelled_invoice"> <querytext> @@ -118,12 +129,28 @@ </querytext> </fullquery> +<fullquery name="not_invoiceable_subprojects"> + <querytext> + + select io.item_id as offer_id, ro.title as offer_title + from iv_offers o, cr_items io, cr_revisions ro, acs_data_links r, cr_items ip, pm_projects p + where o.offer_id = ro.revision_id + and ro.revision_id = io.latest_revision + and r.object_id_one = ip.item_id + and r.object_id_two = io.item_id + and ip.item_id in ([join $subprojects ,]) + and p.project_id = ip.latest_revision + and p.invoice_p = false + + </querytext> +</fullquery> + <fullquery name="offer_items"> <querytext> 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, of.credit_percent, - pr.title as project_title, ofi.vat, ofi.rebate, m.category_id + pr.title as project_title, ofi.vat, ofi.rebate, m.category_id, oi.item_id as offer_cr_item_id from cr_items oi, cr_revisions cr, cr_items pi, cr_revisions pr, acs_objects o, acs_data_links r, iv_offers of, iv_offer_items ofi left outer join category_object_map m on (m.object_id = ofi.offer_item_id) @@ -154,7 +181,7 @@ 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, - of.credit_percent + of.credit_percent, oi.item_id as offer_cr_item_id from cr_items oi, iv_invoice_items i, cr_revisions ir, cr_items pi, cr_revisions pr, iv_offers of, cr_items vi, cr_items ii, acs_data_links r, pm_projects p, iv_offer_items ofi 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.5 -r1.6 --- openacs-4/packages/invoices/www/invoice-cancellation.tcl 15 Mar 2006 17:05:06 -0000 1.5 +++ openacs-4/packages/invoices/www/invoice-cancellation.tcl 2 Apr 2006 22:08:02 -0000 1.6 @@ -8,6 +8,7 @@ {organization_id:integer,optional ""} {parent_id:integer} {__new_p 0} + {return_url:optional ""} } -properties { context:onevalue page_title:onevalue @@ -38,7 +39,7 @@ set recipient_options [lsort -dictionary $recipient_options] -ad_form -name iv_invoice_cancel_form -action invoice-cancellation -export {organization_id parent_id} -form { +ad_form -name iv_invoice_cancel_form -action invoice-cancellation -export {organization_id parent_id return_url} -form { {invoice_id:key} {organization_name:text(inform) {label "[_ invoices.iv_invoice_organization]"} {value $organization_name} {help_text "[_ invoices.iv_invoice_organization_help]"}} {contact_id:integer(select),optional {label "[_ invoices.iv_invoice_contact]"} {options $contact_options} {help_text "[_ invoices.iv_invoice_contact_help]"}} @@ -122,7 +123,11 @@ db_dml mark_cancelled {} } } -after_submit { - ad_returnredirect [export_vars -base invoice-list {organization_id}] + if {[empty_string_p $return_url]} { + ad_returnredirect [export_vars -base invoice-list {organization_id}] + } else { + ad_returnredirect $return_url + } ad_script_abort } 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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-delete.tcl 16 Aug 2005 20:04:34 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-delete.tcl 2 Apr 2006 22:08:02 -0000 1.2 @@ -5,6 +5,7 @@ @creation-date 2005-06-06 } { invoice_id + {return_url:optional ""} } -properties { context:onevalue page_title:onevalue @@ -16,7 +17,7 @@ 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 { +ad_form -name delete_confirm -action invoice-delete -export {return_url} -form { {invoice_id:key} {title:text(inform) {label "[_ invoices.Delete]"}} {confirmation:text(radio) {label " "} {options $confirm_options} {value f}} @@ -26,7 +27,11 @@ db_dml mark_deleted {} } } -after_submit { - ad_returnredirect "invoice-list" + if {[empty_string_p $return_url]} { + ad_returnredirect "invoice-list" + } else { + ad_returnredirect $return_url + } ad_script_abort } Index: openacs-4/packages/invoices/www/invoice-documents.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-documents.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/invoice-documents.adp 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,5 @@ +<master> +<property name="title">@page_title;noquote@</property> +<property name="context">@context;noquote@</property> + +<listtemplate name="documents"></listtemplate> Index: openacs-4/packages/invoices/www/invoice-documents.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-documents.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/invoice-documents.tcl 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,132 @@ +ad_page_contract { + List to display all invoice documents. + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-06-21 +} { + invoice_id:integer + {opening_p 0} + {invoice_p 1} + {copy_p 0} + {file_ids ""} + {return_url:optional ""} +} -properties { + context:onevalue + page_title:onevalue +} + +set user_id [auth::require_login] +set page_title "[_ invoices.iv_invoice_documents]" + +db_1row invoice_data {} + +# We are only getting the invoice_nr here. +if {[string eq $invoice_nr ""]} { + set invoice_nr [db_nextval iv_invoice_seq] + db_dml set_invoice_nr {} +} + +set locale [lang::user::site_wide_locale -user_id $contact_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 document_types {} +if {$opening_p} { + lappend document_types opening +} + +if {$total_amount >= 0} { + # send invoice + set invoice_title [lang::util::localize "#invoices.file_invoice#_${invoice_nr}.pdf" $locale] + if {$invoice_p} { + lappend document_types invoice + } +} elseif {[empty_string_p $parent_invoice_id]} { + # send credit + set invoice_title [lang::util::localize "#invoices.file_invoice_credit#_${invoice_nr}.pdf" $locale] + if {$invoice_p} { + lappend document_types credit + } +} else { + # send cancellation + set invoice_title [lang::util::localize "#invoices.file_invoice_cancel#_${invoice_nr}.pdf" $locale] + if {$invoice_p} { + lappend document_types cancel + } +} + +if {$copy_p} { + lappend document_types invoice_copy +} + +# substitute variables in invoice text +# and return the content of all necessary document files +# (opening, invoice/credit/cancellation, copy) +set documents [iv::invoice::parse_data -invoice_id $invoice_id -types $document_types -email_text ""] + +multirow create documents file_id file_title file_url +set file_ids {} +set documents [lreplace $documents 0 0] +foreach document_file $documents type $document_types { + switch $type { + opening { + set file_title [lang::util::localize "#invoices.file_invoice_opening#_${invoice_nr}.pdf" $locale] + } + invoice_copy { + set file_title [lang::util::localize "#invoices.file_invoice_copy#_${invoice_nr}.pdf" $locale] + } + default { set file_title $invoice_title } + } + + if {![empty_string_p $document_file]} { + set file_size [file size $document_file] + set file_id [contact::oo::import_oo_pdf -oo_file $document_file -printer_name "pdfconv" -title $file_title -parent_id $invoice_id] + + multirow append documents $file_id $file_title [export_vars -base "/tracking/download/$file_title" {file_id}] + lappend file_ids $file_id + } +} + +if {[multirow size documents] > 0} { + + # an invoice has been generated. + # Store this fact as "Billed" in the system. + + 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 [fs::get_folder -name "invoices_${root_folder_id}" -parent_id $root_folder_id] + if {[empty_string_p $invoice_folder_id]} { + # use folder of party if no invoice-folder exists + set invoice_folder_id $organization_id + } + + db_transaction { + # move files to invoice_folder + foreach one_file $file_ids { + application_data_link::new -this_object_id $invoice_id -target_object_id $one_file + db_dml set_publish_status_and_parent {} + db_dml set_context_id {} + } + if {$status == "new" || [empty_string_p $status]} { + iv::invoice::set_status -invoice_id $invoice_id -status "billed" + } + } +} + +if {[empty_string_p $return_url]} { + set return_url [export_vars -base invoice-list {organization_id}] +} + +set actions [list "[_ invoices.ok]" $return_url "[_ invoices.ok]"] + +template::list::create \ + -name documents \ + -key file_id \ + -no_data "[_ invoices.None]" \ + -elements { + file_id { + label {[_ invoices.iv_invoice_file]} + display_template {<a href="@documents.file_url@">@documents.file_title@</a>} + } + } -actions $actions -sub_class narrow + +ad_return_template Index: openacs-4/packages/invoices/www/invoice-documents.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-documents.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/invoice-documents.xql 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<queryset> + +<fullquery name="invoice_data"> + <querytext> + + select i.invoice_nr, i.organization_id, i.parent_invoice_id, + i.total_amount, i.recipient_id, i.contact_id, i.organization_id, i.status + from iv_invoices i, cr_items ii + where ii.latest_revision = i.invoice_id + and ii.item_id = :invoice_id + + </querytext> +</fullquery> + +<fullquery name="set_invoice_nr"> + <querytext> + + update iv_invoices + set invoice_nr = :invoice_nr, + due_date = now() + where invoice_id = (select latest_revision from cr_items where item_id = :invoice_id) + + </querytext> +</fullquery> + +<fullquery name="set_publish_status_and_parent"> + <querytext> + + update cr_items + set publish_status = 'live', + parent_id = :invoice_folder_id + where item_id = :one_file + + </querytext> +</fullquery> + +<fullquery name="set_context_id"> + <querytext> + + update acs_objects + set context_id = :invoice_folder_id + where object_id = :one_file + + </querytext> +</fullquery> + +</queryset> 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 -r1.4 -r1.5 --- openacs-4/packages/invoices/www/invoice-list.adp 15 Mar 2006 17:05:06 -0000 1.4 +++ openacs-4/packages/invoices/www/invoice-list.adp 2 Apr 2006 22:08:02 -0000 1.5 @@ -2,6 +2,40 @@ <property name="title">@page_title;noquote@</property> <property name="context">@context;noquote@</property> +<table width="100%"> +<tr> +<td> +<form action="@current_url@"> + @export_vars;noquote@ + <table> + <tr> + <td>#invoices.iv_invoice_start_date# <input type=text name="start_date" size=12 value="@start_date@"></td> + <td>#invoices.iv_invoice_end_date# <input type=text name="end_date" size=12 value="@end_date@"</td> + <td><input type=submit name="submit" value="#invoices.ok#"></td> + </tr> + <if @clear_p@ eq 1> + <tr> + <td><a href="@clear_link@">#invoices.clear#</a></td> + </tr> + </if> + </table> +</form> +</td> + +<td align=right> +<form action="/invoices/invoice-search"> + <table> + <tr> + <td>#invoices.iv_invoice_invoice_nr# <input type=text name="invoice_nr" size=10></td> + <td><input type=submit name="submit" value="#invoices.ok#"></td> + </tr> + </table> +</form> +</td> +</tr> +</table> + <include src="/packages/invoices/lib/invoice-list" organization_id="@organization_id@" row_list="@row_list@" page="@page@" - orderby="@orderby@" format="@format@" page_size="@page_size@"> + orderby="@orderby@" format="@format@" page_size="@page_size@" + start_date="@start_date@" end_date="@end_date@"> 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 -r1.6 -r1.7 --- openacs-4/packages/invoices/www/invoice-list.tcl 15 Mar 2006 17:05:06 -0000 1.6 +++ openacs-4/packages/invoices/www/invoice-list.tcl 2 Apr 2006 22:08:02 -0000 1.7 @@ -9,6 +9,8 @@ {page:optional 1} {page_size:optional 25} {organization_id ""} + {start_date "YYYY-MM-DD"} + {end_date "YYYY-MM-DD"} } -properties { context:onevalue page_title:onevalue @@ -24,7 +26,15 @@ set page_title "[_ invoices.iv_invoice_2]" set context [list $page_title] +set current_url [ad_conn url] +set clear_link [export_vars -base $current_url {page orderby organization_id}] +set export_vars [export_vars -form {page orderby organization_id}] +set clear_p 1 +if {$start_date == "YYYY-MM-DD" && $end_date == "YYYY-MM-DD"} { + set clear_p 0 +} + set row_list {checkbox {} invoice_nr {} title {} description {} recipient {} total_amount {} creation_date {} due_date {} action {}} ad_return_template Index: openacs-4/packages/invoices/www/invoice-preview.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-preview.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-preview.tcl 27 Jan 2006 16:22:46 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-preview.tcl 2 Apr 2006 22:08:02 -0000 1.2 @@ -20,39 +20,28 @@ set document_types {} -if {$total_amount > 0} { +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 invoice_title [lang::util::localize "#invoices.file_invoice#_${invoice_nr}.pdf" $locale] if {$invoice_p} { set document_types invoice + } else { + set document_types invoice_copy } } 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 invoice_title [lang::util::localize "#invoices.file_invoice_credit#_${invoice_nr}.pdf" $locale] - if {$invoice_p} { - set document_types credit - } + set document_types credit } else { # send cancellation - set invoice_text "#invoices.iv_invoice_cancel_email#" - set subject [lang::util::localize "#invoices.iv_invoice_cancel_email_subject#" $locale] set invoice_title [lang::util::localize "#invoices.file_invoice_cancel#_${invoice_nr}.pdf" $locale] - if {$invoice_p} { - set document_types cancel - } + set document_types cancel } # substitute variables in invoice text # and return the content of all necessary document files # (opening, invoice/credit/cancellation, copy) -set documents [iv::invoice::parse_data -invoice_id $invoice_id -types $document_types -email_text $invoice_text] - -set invoice_text [lindex $documents 0] - +set documents [iv::invoice::parse_data -invoice_id $invoice_id -types $document_types -email_text ""] set documents [lreplace $documents 0 0] set file_title $invoice_title Index: openacs-4/packages/invoices/www/invoice-send-1.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-send-1.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/invoices/www/invoice-send-1.adp 27 Dec 2005 16:39:35 -0000 1.1 +++ openacs-4/packages/invoices/www/invoice-send-1.adp 2 Apr 2006 22:08:02 -0000 1.2 @@ -2,6 +2,10 @@ <property name="title">@page_title;noquote@</property> <property name="context">@context;noquote@</property> +<if @sent_p@> + <font color=red>#invoices.invoice_warning_sent#</font><p> +</if> + <blockquote> <formtemplate id="invoice_send"></formtemplate> </blockquote> Index: openacs-4/packages/invoices/www/invoice-send-1.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-send-1.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/invoices/www/invoice-send-1.tcl 4 Jan 2006 08:06:48 -0000 1.3 +++ openacs-4/packages/invoices/www/invoice-send-1.tcl 2 Apr 2006 22:08:02 -0000 1.4 @@ -5,6 +5,7 @@ @creation-date 2005-12-24 } { invoice_id:integer + {return_url:optional ""} } -properties { context:onevalue page_title:onevalue @@ -23,12 +24,18 @@ set rec_organization_id $recipient_id } +# warn if invoice already got sent +set sent_p 0 +if {![empty_string_p $invoice_nr]} { + set sent_p 1 +} + set rec_orga_revision_id [content::item::get_best_revision -item_id $rec_organization_id] set invoice_copy [ams::value -attribute_name "invoice_copy" -object_id $rec_orga_revision_id] set boolean_options [list [list "[_ invoices.yes]" 1] [list "[_ invoices.no]" 0]] -ad_form -name invoice_send -action invoice-send-1 -form { +ad_form -name invoice_send -action invoice-send-1 -export {return_url} -form { {invoice_id:key} } @@ -41,15 +48,26 @@ ad_form -extend -name invoice_send -form { {invoice_p:text(radio) {label "[_ invoices.iv_invoice_p]"} {options $boolean_options}} {copy_p:text(radio) {label "[_ invoices.iv_invoice_copy_p]"} {options $boolean_options}} + {email_p:text(radio) {label "[_ invoices.iv_invoice_email_p]"} {options $boolean_options}} } -edit_request { set opening_p 0 set invoice_p 1 + set email_p 0 set copy_p [ad_decode $invoice_copy t 1 0] if {[empty_string_p $copy_p]} { set copy_p 0 } + if {$sent_p} { + # if invoice is already sent, let user send copy by default + set invoice_p 0 + set copy_p 1 + } } -after_submit { - ad_returnredirect [export_vars -base "invoice-send" {invoice_id opening_p invoice_p copy_p}] + if {$email_p} { + ad_returnredirect [export_vars -base "invoice-send" {invoice_id opening_p invoice_p copy_p return_url}] + } else { + ad_returnredirect [export_vars -base "invoice-documents" {invoice_id opening_p invoice_p copy_p return_url}] + } ad_script_abort } 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.15 -r1.16 --- openacs-4/packages/invoices/www/invoice-send.tcl 15 Mar 2006 17:05:06 -0000 1.15 +++ openacs-4/packages/invoices/www/invoice-send.tcl 2 Apr 2006 22:08:02 -0000 1.16 @@ -9,6 +9,7 @@ {invoice_p 1} {copy_p 0} {file_ids ""} + {return_url:optional ""} } -properties { context:onevalue page_title:onevalue @@ -34,7 +35,7 @@ lappend document_types opening } -if {$total_amount > 0} { +if {$total_amount >= 0} { # send invoice set invoice_text "#invoices.iv_invoice_email#" set subject [lang::util::localize "#invoices.iv_invoice_email_subject#" $locale] @@ -80,9 +81,9 @@ 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}}] + # 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}] + # set return_url [export_vars -base invoice-list {organization_id}] } set file_ids {} @@ -119,28 +120,34 @@ 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}}] + # 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}] + # set return_url [export_vars -base invoice-list {organization_id}] } 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 [fs::get_folder -name "invoices_${root_folder_id}" -parent_id $root_folder_id] + if {[empty_string_p $invoice_folder_id]} { + # use folder of party if no invoice-folder exists + set invoice_folder_id $organization_id + } + db_transaction { # move files to invoice_folder foreach one_file $file_id { - content::item::move -item_id $one_file -target_folder_id $invoice_folder_id application_data_link::new -this_object_id $invoice_id -target_object_id $one_file - db_dml set_publish_status {} + db_dml set_publish_status_and_parent {} db_dml set_context_id {} } - if {$status != "paid"} { + if {$status == "new" || [empty_string_p $status]} { iv::invoice::set_status -invoice_id $invoice_id -status "billed" } } } - -set return_url [export_vars -base invoice-list {organization_id}] +if {[empty_string_p $return_url]} { + set return_url [export_vars -base invoice-list {organization_id}] +} + 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 -r1.7 -r1.8 --- openacs-4/packages/invoices/www/invoice-send.xql 15 Mar 2006 17:05:06 -0000 1.7 +++ openacs-4/packages/invoices/www/invoice-send.xql 2 Apr 2006 22:08:02 -0000 1.8 @@ -17,17 +17,19 @@ <querytext> update iv_invoices - set invoice_nr = :invoice_nr + set invoice_nr = :invoice_nr, + due_date = now() where invoice_id = (select latest_revision from cr_items where item_id = :invoice_id) </querytext> </fullquery> -<fullquery name="set_publish_status"> +<fullquery name="set_publish_status_and_parent"> <querytext> update cr_items - set publish_status = 'live' + set publish_status = 'live', + parent_id = :invoice_folder_id where item_id = :one_file </querytext> Index: openacs-4/packages/invoices/www/journal-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/journal-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/journal-add.tcl 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,267 @@ +ad_page_contract { + Export invoices and changes in customer data + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2006-01-27 +} { +} + +set user_id [auth::require_login] +set ip_addr [ad_conn peeraddr] +set folder_id [parameter::get -parameter "JournalFolderID"] +acs_object::get -object_id $folder_id -array folder +set fs_package_id $folder(package_id) +set fs_package_url [site_node::get_url_from_object_id -object_id $fs_package_id] + +db_1row last_checkout {} +db_1row today {} +set date_format [lc_get d_fmt] +set today_pretty [lc_time_fmt $today_pretty $date_format] + +# set last_checkout "2006-02-28 18:27:00" + +db_foreach country_codes {} { + set country_codes($iso_code) $journal_code +} + +######## +# customer changes +######## + +set customer_group_id [group::get_id -group_name "Customers"] +set new_customers [db_list_of_lists new_customers {}] + +set customer_text "" +foreach customer $new_customers { + + util_unlist $customer organization_id orga_revision_id email + + contacts::postal_address::get -attribute_name "company_address" -party_id $organization_id -array address_array + + if {[exists_and_not_null address_array(postal_code)]} { + set zip_code [string trim $address_array(postal_code)] + } else { + set zip_code "" + } + + set client_id [ams::value -attribute_name "client_id" -object_id $orga_revision_id] + + if {[empty_string_p $client_id]} { + # dont list customers without client_id + continue + } + + set company_name [string trim [ams::value -attribute_name "name" -object_id $orga_revision_id]] + set company_name_ext [string trim [ams::value -attribute_name "company_name_ext" -object_id $orga_revision_id]] + set payment_days [string trim [ams::value -attribute_name "payment_days" -object_id $orga_revision_id]] + set ust_id_nr [string trim [ams::value -attribute_name "VAT_ident_number" -object_id $orga_revision_id]] + set company_phone [string trim [ams::value -attribute_name "company_phone" -object_id $orga_revision_id]] + set company_fax [string trim [ams::value -attribute_name "company_fax" -object_id $orga_revision_id]] + + regexp {<a href=[^>]+>([^<]+)</a>} $company_phone match company_phone + regexp {<a href=[^>]+>([^<]+)</a>} $company_fax match company_fax + + # country_code + if {[exists_and_not_null address_array(country_code)]} { + set country_code [string trim $country_codes($address_array(country_code))] + } else { + set country_code "" + } + + if {[exists_and_not_null address_array(municipality)]} { + set municipality [string trim [string range $address_array(municipality) 0 39]] + } else { + set municipality "" + } + + if {[exists_and_not_null address_array(delivery_address)]} { + set address [string trim [string range $address_array(delivery_address) 0 39]] + } else { + set address "" + } + + set company_name [string trim [string range $company_name 0 34]] + set company_name_ext [string trim [string range $company_name_ext 0 39]] + set zip_and_municipality [string range "$zip_code $municipality" 0 34] + set email [string range $email 0 49] + array unset address_array + + set new_line "S;0;D;$client_id;;$company_name;$zip_and_municipality;$ust_id_nr;1200;;;;0;;;;;;0;;;;;;;;$company_name;$company_name_ext;;$address;$zip_code;$municipality;;;;$company_phone;$company_fax;;;;;;;;;;;;$email;;$country_code" + + set new_line [string map {{&} {&} {\n} {} {\x0a} {}} $new_line] + + append customer_text "$new_line\n" +} + +######## +# invoices +######## + +set new_invoices [db_list_of_lists new_invoices {}] + +set financial_text "" +foreach invoice $new_invoices { + + util_unlist $invoice invoice_nr parent_invoice_id recipient_id total_amount currency payment_days vat vat_percent invoice_period invoice_name invoice_date + + if {[person::person_p -party_id $recipient_id]} { + # recipient is person, so get employer organization + set organization_id [lindex [lindex [contact::util::get_employers -employee_id $recipient_id] 0] 0] + } else { + # recipient is organization + set organization_id $recipient_id + } + + set orga_revision_id [content::item::get_best_revision -item_id $organization_id] + contacts::postal_address::get -attribute_name "company_address" -party_id $organization_id -array address_array + set client_id [string trim [ams::value -attribute_name "client_id" -object_id $orga_revision_id]] + set ust_id_nr [string trim [ams::value -attribute_name "VAT_ident_number" -object_id $orga_revision_id]] + set invoice_name [string range $invoice_name 0 29] + set invoice_type "AR" + set final_amount [lc_numeric [format "%.2f" [expr $total_amount + $vat]]] + if {$total_amount < 0 || ![string eq $parent_invoice_id ""]} { + # use AG for cancellations and credit + set invoice_type "AG" + } + + if {![string eq $parent_invoice_id ""]} { + db_1row parent_invoice_nr {} + set invoice_name "Storno Beleg $parent_invoice_nr" + } elseif {$total_amount < 0} { + set invoice_name "Gutschrift" + } else { + set invoice_name "Ausgangsrechnung" + } + + # country_code + if {[exists_and_not_null address_array(country_code)]} { + set country_code $country_codes($address_array(country_code)) + } else { + set country_code "" + } + array unset address_array + + if {![empty_string_p $vat_percent] && $vat_percent > 0} { + set tax_account 4410 + set tax_type 40 + } else { + set tax_account 4690 + set tax_type 10 + } + + append financial_text "F;0;940;;;$invoice_type;$invoice_date;$invoice_period;$invoice_nr;;$client_id;$tax_account;$tax_type;;$final_amount;$invoice_name;;;$currency;$country_code;$ust_id_nr;;;0;0\n" +} + +######## +# journal +######## + +set new_invoices [db_list_of_lists new_invoice_journal {}] + +set total_sum 0. +set vat_sum 0. +set final_sum 0. +set journal_text "" +set journal_text2 "<html><body><h2>Rechnungsbuch $today_pretty</h2>\n<table width=100%>\n<tr><th align=left>Rechnung </th><th align=left>Datum </th><th align=left>Kunde </th><th align=left>Netto </th><th align=left>MWSt </th><th align=left>Brutto </th><th align=left>Währung</th></tr>\n" +foreach invoice $new_invoices { + + util_unlist $invoice invoice_nr recipient_id total_amount currency amount_sum vat invoice_date + + if {[person::person_p -party_id $recipient_id]} { + # recipient is person, so get employer organization + set organization_id [lindex [lindex [contact::util::get_employers -employee_id $recipient_id] 0] 0] + } else { + # recipient is organization + set organization_id $recipient_id + } + + set orga_revision_id [content::item::get_best_revision -item_id $organization_id] + set client_id [ams::value -attribute_name "client_id" -object_id $orga_revision_id] + set final_amount [format "%.2f" [expr $total_amount + $vat]] + + set total_sum [expr $total_sum + $total_amount] + set vat_sum [expr $vat_sum + $vat] + set final_sum [expr $final_sum + $final_amount] + + set final_amount [lc_numeric $final_amount] + set vat [lc_numeric $vat] + set total_amount [lc_numeric $total_amount] + set invoice_date [lc_time_fmt $invoice_date $date_format] + + append journal_text "$invoice_nr,$invoice_date,$client_id,$total_amount,$vat,$final_amount,$currency\n" + append journal_text2 "<tr><td align=left>$invoice_nr</td><td align=left>$invoice_date</td><td align=left>$client_id</td><td align=left>$total_amount</td><td align=left>$vat</td><td align=left>$final_amount</td><td align=left>$currency</td></tr>\n" +} + +set total_sum [lc_numeric [format "%.2f" $total_sum]] +set vat_sum [lc_numeric [format "%.2f" $vat_sum]] +set final_sum [lc_numeric [format "%.2f" $final_sum]] + +append journal_text2 "<tr><td align=left> </td><td align=left> </td><td align=left> </td><td align=left> </td><td align=left> </td><td align=left> </td><td align=left> </td></tr>\n" +append journal_text2 "<tr><td align=left> </td><td align=left> </td><td align=left> </td><td align=left><b>$total_sum</b></td><td align=left><b>$vat_sum</b></td><td align=left><b>$final_sum</b></td><td align=left> </td></tr>\n" +append journal_text2 "</table></body></html>" + +set data(customer) $customer_text +set data(financial) $financial_text +set data(journal) $journal_text2 + +###### +# create zip +###### + +# create tmp-folder for zip +set tmp_path [ns_tmpnam] +file mkdir $tmp_path +set zip_path [ns_tmpnam] +file mkdir $zip_path +set zip_file_id [db_nextval acs_object_id_seq] +set item_name "journal_${today}.zip" +set file_mime_type [cr_filename_to_mime_type -create zip] +set zip_file [file join ${zip_path} $item_name] +set zip_bin "/usr/bin/zip" +set cmd "exec $zip_bin -j $zip_file" + +foreach type [array names data] { + switch $type { + customer { + set filename "debitoren" + set extension "s" + } + financial { + set filename "fibu" + set extension "ER2" + } + journal { + set filename "journal" + set extension "html" + } + } + set file "${tmp_path}/${filename}_${today}.${extension}" + set f [open $file w] + fconfigure $f -encoding iso8859-1 + puts $f $data($type) + flush $f + close $f + append cmd " \"$file\"" +} + +# create zip-file +catch { eval $cmd } errmsg + +fs::add_file \ + -name $item_name \ + -item_id $zip_file_id \ + -parent_id $folder_id \ + -tmp_filename $zip_file \ + -creation_user $user_id \ + -creation_ip $ip_addr \ + -title $item_name \ + -package_id $fs_package_id \ + -mime_type $file_mime_type \ + -no_callback + +exec rm -rf $tmp_path +exec rm -rf $zip_path + +db_dml mark_journal_creation {} + +ad_returnredirect [export_vars -base "${fs_package_url}index" {folder_id {orderby name,desc}}] Index: openacs-4/packages/invoices/www/journal-add.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/journal-add.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/journal-add.xql 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,101 @@ +<?xml version="1.0"?> +<queryset> + +<fullquery name="last_checkout"> + <querytext> + + select max(to_char(creation_date, 'YYYY-MM-DD HH24:MI:SS')) as last_checkout + from iv_journals + + </querytext> +</fullquery> + +<fullquery name="today"> + <querytext> + + select to_char(now(), 'YYYYMMDD_HH24MI') as today, to_char(now(), 'YYYY-MM-DD HH24:MI:SS') as today_pretty + + </querytext> +</fullquery> + +<fullquery name="country_codes"> + <querytext> + + select iso_code, journal_code + from iv_journal_country_codes + + </querytext> +</fullquery> + +<fullquery name="new_customers"> + <querytext> + + select o.organization_id, oi.latest_revision as orga_revision_id, p.email + from organizations o, cr_items oi, parties p, acs_objects oo, group_member_map g + where oi.item_id = o.organization_id + and p.party_id = o.organization_id + and oo.object_id = oi.latest_revision + and oo.creation_date > to_timestamp(:last_checkout, 'YYYY-MM-DD HH24:MI:SS') + and g.member_id = o.organization_id + and g.group_id = :customer_group_id + and o.organization_id in (select distinct i.recipient_id + from iv_invoices i, cr_items ii, acs_objects o + where i.invoice_id = ii.latest_revision + and o.object_id = ii.item_id + and i.status in ('billed', 'cancelled', 'paid') + and o.creation_date > to_timestamp(:last_checkout, 'YYYY-MM-DD HH24:MI:SS')) + + </querytext> +</fullquery> + +<fullquery name="new_invoices"> + <querytext> + + select i.invoice_nr, i.parent_invoice_id, i.recipient_id, i.total_amount, i.currency, + i.payment_days, i.vat, i.vat_percent, to_char(o.creation_date, 'MMYYYY') as invoice_period, + r.title as invoice_name, to_char(o.creation_date, 'DDMMYYYY') as invoice_date + from iv_invoices i, cr_revisions r, cr_items ii, acs_objects o + where i.invoice_id = r.revision_id + and r.revision_id = ii.latest_revision + and o.object_id = ii.item_id + and i.status in ('billed', 'cancelled', 'paid') + and o.creation_date > to_timestamp(:last_checkout, 'YYYY-MM-DD HH24:MI:SS') + + </querytext> +</fullquery> + +<fullquery name="new_invoice_journal"> + <querytext> + + select i.invoice_nr, i.recipient_id, i.total_amount, i.currency, i.amount_sum, i.vat, + to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as invoice_date + from iv_invoices i, cr_items ii, acs_objects o + where i.invoice_id = ii.latest_revision + and o.object_id = ii.item_id + and i.status in ('billed', 'cancelled') + and o.creation_date > to_timestamp(:last_checkout, 'YYYY-MM-DD HH24:MI:SS') + order by i.invoice_nr + + </querytext> +</fullquery> + +<fullquery name="parent_invoice_nr"> + <querytext> + + select invoice_nr as parent_invoice_nr + from iv_invoices + where invoice_id = :parent_invoice_id + + </querytext> +</fullquery> + +<fullquery name="mark_journal_creation"> + <querytext> + + insert into iv_journals (file_id, creation_date) + values (:zip_file_id, now()) + + </querytext> +</fullquery> + +</queryset> Index: openacs-4/packages/invoices/www/journal-check.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/journal-check.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/journal-check.adp 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,7 @@ +<master> +<property name="title">@page_title;noquote@</property> +<property name="context">@context;noquote@</property> + +<blockquote> + <formtemplate id="journal_confirm"></formtemplate> +</blockquote> Index: openacs-4/packages/invoices/www/journal-check.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/journal-check.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/journal-check.tcl 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,28 @@ +ad_page_contract { + Check before creation of journal + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2006-01-30 +} { +} -properties { + context:onevalue + page_title:onevalue +} + +set user_id [auth::require_login] +set page_title "[_ invoices.iv_journal_check]" +set context [list [list [export_vars -base invoice-list {organization_id}] "[_ invoices.iv_invoice_2]"] $page_title] + +set confirm_options [list [list "[_ invoices.continue_with_journal]" t] [list "[_ invoices.cancel_and_return]" f]] + +ad_form -name journal_confirm -action journal-check -form { + {user_id:key} + {confirmation:text(radio) {label " "} {options $confirm_options} {value f}} +} -edit_request { +} -on_submit { +} -after_submit { + ad_returnredirect "journal-add" + ad_script_abort +} + +ad_return_template 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.21 -r1.22 --- openacs-4/packages/invoices/www/offer-ae.tcl 15 Mar 2006 17:05:06 -0000 1.21 +++ openacs-4/packages/invoices/www/offer-ae.tcl 2 Apr 2006 22:08:02 -0000 1.22 @@ -131,6 +131,7 @@ {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]"}} + {reservation:text(textarea),optional {label "[_ invoices.iv_offer_reservation]"} {html {rows 5 cols 80}} {help_text "[_ invoices.iv_offer_reservation_help]"}} } if {![empty_string_p [category_tree::get_mapped_trees $container_objects(offer_id)]]} { @@ -273,6 +274,13 @@ } else { # we are just displaying an offer + if {![empty_string_p $_credit_percent] && $_credit_percent > 0} { + set _credit_percent [format "%.1f" $_credit_percent] + ad_form -extend -name iv_offer_form -form { + {credit_percent:float {label "[_ invoices.iv_offer_credit_percent]"} {html {size 5 maxlength 10}} {help_text "[_ invoices.iv_offer_credit_percent_help]"} {value $_credit_percent} {after_html {%}}} + } + } + # display uploaded files if {[exists_and_not_null files]} { ad_form -extend -name iv_offer_form -form { @@ -686,6 +694,7 @@ -title $title \ -description $description \ -comment $comment \ + -reservation $reservation \ -offer_nr $offer_nr \ -organization_id $organization_id \ -amount_total $amount_total \ @@ -730,8 +739,9 @@ set new_offer_rev_id [iv::offer::edit \ -offer_id $offer_id \ -title $title \ - -description $description \ + -description $description \ -comment $comment \ + -reservation $reservation \ -offer_nr $offer_nr \ -organization_id $organization_id \ -amount_total $amount_total \ 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.10 -r1.11 --- openacs-4/packages/invoices/www/offer-ae.xql 15 Mar 2006 17:05:06 -0000 1.10 +++ openacs-4/packages/invoices/www/offer-ae.xql 2 Apr 2006 22:08:02 -0000 1.11 @@ -136,7 +136,7 @@ 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, - o.creation_user, p.first_names, p.last_name, + o.creation_user, p.first_names, p.last_name, t.reservation, to_char(o.creation_date, 'YYYY-MM-DD HH24:MI:SS') as creation_ansi, to_char(t.accepted_date, 'YYYY-MM-DD HH24:MI:SS') as accepted_ansi, t.amount_sum as amount_sum_, t.payment_days, t.date_comment Index: openacs-4/packages/invoices/www/project-search.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/project-search.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/project-search.tcl 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,28 @@ +ad_page_contract { + Page to redirect to project. + + @author Timo Hentschel (timo@timohentschel.de) + @creation-date 2005-06-06 +} { + project_id +} + +set match_projects [db_list_of_lists get_projects { }] +set match_length [llength $match_projects] + +if { [string equal $match_length 0] } { + # No Match just redirect + ad_returnredirect $return_url + +} else { + set project_item_id [lindex [lindex $match_projects 0] 0] + set object_package_id [lindex [lindex $match_projects 0] 2] + + # We get the node_id from the package_id and use it + # to get the url of the project-manager + set pm_node_id [site_node::get_node_id_from_object_id -object_id $object_package_id] + set pm_url [site_node::get_url -node_id $pm_node_id] + + # Just redirect to the pm_url and project_item_id + ad_returnredirect "${pm_url}one?project_item_id=$project_item_id" +} Index: openacs-4/packages/invoices/www/project-search.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/project-search.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/project-search.xql 2 Apr 2006 22:08:02 -0000 1.1 @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<queryset> + +<fullquery name="get_projects"> + <querytext> + select + distinct + item_id, + object_title, + object_package_id + from + pm_projectsx + where + lower(object_title) like '%${project_id}%' + or lower(project_code) like '%${project_id}%' + order by + object_title asc + </querytext> +</fullquery> + +</queryset> Index: openacs-4/packages/invoices/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/doc/index.html,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/doc/index.html 2 Apr 2006 22:08:03 -0000 1.1 @@ -0,0 +1,7 @@ +<html><head><title></title></head> +<body> +<h3>Invoices</h3> +-special permission invoice_cancel, invoice_export + +</body> +</html> Index: openacs-4/packages/invoices/www/download/index.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/download/index.vuh,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/invoices/www/download/index.vuh 2 Apr 2006 22:08:03 -0000 1.1 @@ -0,0 +1,25 @@ +# packages/invoices/www/download/index.vuh + +ad_page_contract { + + Virtual URL handler for file downloads + + @author Kevin Scaldeferri (kevin@arsdigita.com) + @author Don Baccus (simplified it by using cr utility) + @creation-date 18 December 2000 + @cvs-id $Id: index.vuh,v 1.1 2006/04/02 22:08:03 timoh Exp $ +} { + item_id:integer,optional + version_id:integer,optional +} + +if {![exists_and_not_null version_id]} { + set version_id [item::get_live_revision $item_id] +} + +set user_id [ad_conn user_id] + +ad_require_permission $version_id "read" + +# cr_write_content -revision_id $version_id +cr_write_content -item_id $item_id