| |
60 |
60 |
|
| |
61 |
61 |
if {$copy_p} { |
| |
62 |
62 |
lappend document_types invoice_copy |
| |
63 |
63 |
} |
| |
64 |
64 |
|
| |
65 |
65 |
# substitute variables in invoice text |
| |
66 |
66 |
# and return the content of all necessary document files |
| |
67 |
67 |
# (opening, invoice/credit/cancellation, copy) |
| |
68 |
68 |
set documents [iv::invoice::parse_data -invoice_id $invoice_id -types $document_types -email_text ""] |
| |
69 |
69 |
|
| |
70 |
70 |
# We want to get the odt file only |
| |
71 |
71 |
if {$odt_p} { |
| |
72 |
72 |
set file [lindex $documents 1] |
| |
73 |
73 |
ad_returnredirect [export_vars -base "invoice.odt" -url {file}] |
| |
74 |
74 |
ad_script_abort |
| |
75 |
75 |
} |
| |
76 |
76 |
|
| |
77 |
77 |
multirow create documents file_id file_title file_url |
| |
78 |
78 |
set files {} |
| |
79 |
79 |
set documents [lreplace $documents 0 0] |
| |
|
80 |
if {[llength $document_types] > 1} { |
| |
80 |
81 |
foreach document_file $documents type $document_types { |
| |
81 |
82 |
switch $type { |
| |
82 |
83 |
opening { |
| |
83 |
84 |
set file_title [lang::util::localize "#invoices.file_invoice_opening#_${invoice_nr}.pdf" $locale] |
| |
84 |
85 |
} |
| |
85 |
86 |
invoice_copy { |
| |
86 |
87 |
set file_title [lang::util::localize "#invoices.file_invoice_copy#_${invoice_nr}.pdf" $locale] |
| |
87 |
88 |
} |
| |
88 |
89 |
default { set file_title $invoice_title } |
| |
89 |
90 |
} |
| |
90 |
91 |
|
| |
91 |
92 |
if {![empty_string_p $document_file]} { |
| |
92 |
93 |
set file_size [file size $document_file] |
| |
93 |
94 |
util_unlist [contact::oo::import_oo_pdf -oo_file $document_file -printer_name "pdfconv" -title $file_title -parent_id $invoice_id -no_import] file_mime_type file_name |
| |
94 |
95 |
|
| |
95 |
96 |
lappend files $file_name |
| |
96 |
97 |
} |
| |
97 |
98 |
} |
| |
98 |
|
|
| |
99 |
99 |
set file_id [contact::oo::join_pdf -filenames $files -title $invoice_title -parent_id $invoice_id] |
| |
|
100 |
} else { |
| |
|
101 |
set type $document_types |
| |
|
102 |
set document_file $documents |
| |
|
103 |
|
| |
|
104 |
switch $type { |
| |
|
105 |
opening { |
| |
|
106 |
set file_title [lang::util::localize "#invoices.file_invoice_opening#_${invoice_nr}.pdf" $locale] |
| |
|
107 |
} |
| |
|
108 |
invoice_copy { |
| |
|
109 |
set file_title [lang::util::localize "#invoices.file_invoice_copy#_${invoice_nr}.pdf" $locale] |
| |
|
110 |
} |
| |
|
111 |
default { set file_title $invoice_title } |
| |
|
112 |
} |
| |
|
113 |
|
| |
|
114 |
if {![empty_string_p $document_file]} { |
| |
|
115 |
set file_id [contact::oo::import_oo_pdf -oo_file $document_file -printer_name "pdfconv" -title $file_title -parent_id $invoice_id] |
| |
|
116 |
} |
| |
|
117 |
} |
| |
|
118 |
|
| |
100 |
119 |
multirow append documents $file_id $invoice_title [export_vars -base "/tracking/download/$invoice_title" {file_id}] |
| |
101 |
120 |
|
| |
102 |
121 |
# delete old files |
| |
103 |
122 |
foreach one_file $files { |
| |
104 |
123 |
ns_unlink $one_file |
| |
105 |
124 |
} |
| |
106 |
125 |
|
| |
107 |
126 |
if {[multirow size documents] > 0} { |
| |
108 |
127 |
|
| |
109 |
128 |
# an invoice has been generated. |
| |
110 |
129 |
# Store this fact as "Billed" in the system. |
| |
111 |
130 |
|
| |
112 |
131 |
if {$status == "new" || [empty_string_p $status]} { |
| |
113 |
132 |
iv::invoice::set_status -invoice_id $invoice_id -status "billed" |
| |
114 |
133 |
} |
| |
115 |
134 |
|
| |
116 |
135 |
# move files to invoice_folder |
| |
117 |
136 |
set root_folder_id [lindex [application_data_link::get_linked -from_object_id $organization_id -to_object_type content_folder] 0] |
| |
118 |
137 |
set invoice_folder_id [fs::get_folder -name "invoices_${root_folder_id}" -parent_id $root_folder_id] |
| |
119 |
138 |
if {[empty_string_p $invoice_folder_id]} { |