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.8 -r1.9 --- openacs-4/packages/invoices/www/invoice-send.tcl 14 Dec 2005 16:24:22 -0000 1.8 +++ openacs-4/packages/invoices/www/invoice-send.tcl 27 Dec 2005 16:39:35 -0000 1.9 @@ -5,6 +5,9 @@ @creation-date 2005-06-21 } { invoice_id:integer + {opening_p 0} + {invoice_p 1} + {copy_p 0} {file_ids ""} } -properties { context:onevalue @@ -15,32 +18,60 @@ set page_title "[_ invoices.iv_invoice_send]" db_1row invoice_data {} -set locale [lang::user::site_wide_locale -user_id $recipient_id] +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_text "{[_ invoices.iv_invoice_email]}" + set invoice_text "{#invoices.iv_invoice_email#}" set subject [lang::util::localize "#invoices.iv_invoice_email_subject#" $locale] set template "InvoiceTemplate" - set file_title "Invoice_${invoice_nr}.pdf" + 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_text "{[_ invoices.iv_invoice_credit_email]}" + set invoice_text "{#invoices.iv_invoice_credit_email#}" set subject [lang::util::localize "#invoices.iv_invoice_credit_email_subject#" $locale] set template "CreditTemplate" - set file_title "Credit_${invoice_nr}.pdf" + 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_text "{[_ invoices.iv_invoice_cancel_email]}" + set invoice_text "{#invoices.iv_invoice_cancel_email#}" set subject [lang::util::localize "#invoices.iv_invoice_cancel_email_subject#" $locale] set template "CancelTemplate" - set file_title "Cancellation_${invoice_nr}.pdf" + set invoice_title [lang::util::localize "#invoices.file_invoice_cancel#_${invoice_nr}.pdf" $locale] + if {$invoice_p} { + lappend document_types cancel + } } -set invoice_text [iv::invoice::parse_data -invoice_id $invoice_id -recipient_id $recipient_id -template $template -locale $locale] +if {$copy_p} { + lappend document_types invoice_copy +} +if {[empty_string_p [cc_email_from_party $recipient_id]]} { + ad_return_error "No Recipient" "The recipient does not have a valid e-mail address. Please go back and make sure that you provide an e-mail address first." + ad_script_abort +} + +# 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 project_id [lindex [application_data_link::get_linked -from_object_id $invoice_id -to_object_type content_item] 0] if {![empty_string_p $project_id]} { acs_object::get -object_id $project_id -array project @@ -50,19 +81,35 @@ set return_url [export_vars -base invoice-list {organization_id}] } -if {[empty_string_p $file_ids]} { - set pdf_file [text_templates::create_pdf_from_html -html_content "$invoice_text"] - if {![empty_string_p $pdf_file]} { - set file_size [file size $pdf_file] - set file_ids [cr_import_content -title $file_title -description "PDF version of this invoice" $invoice_id $pdf_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] - set return_url [export_vars -base invoice-pdf {invoice_id {file_id $file_ids}}] +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] + + set file_id [cr_import_content -title $file_title -description "PDF version of this invoice" $invoice_id $document_file $file_size application/pdf "[clock seconds]-[expr round([ns_rand]*100000)]"] + content::item::set_live_revision -revision_id $file_id + + lappend file_ids $file_id + db_dml set_publish_status {} + } +} + +if {[llength $file_ids] > 0} { + set return_url [export_vars -base invoice-pdf {invoice_id {file_id $file_ids}}] } else { set return_url [export_vars -base invoice-list {organization_id}] } -if {[empty_string_p [cc_email_from_party $recipient_id]]} { - ad_return_error "No Recipient" "The recipient does not have a valid e-mail address. Please go back and make sure that you provide an e-mail address first." -} - ad_return_template