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 -r1.4 -r1.5 --- openacs-4/packages/invoices/www/invoice-documents.tcl 1 Nov 2006 14:27:56 -0000 1.4 +++ openacs-4/packages/invoices/www/invoice-documents.tcl 1 Nov 2006 14:28:49 -0000 1.5 @@ -1,6 +1,7 @@ ad_page_contract { List to display all invoice documents. + @param opening_p @author Timo Hentschel (timo@timohentschel.de) @creation-date 2005-06-21 } { 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.6 -r1.7 --- openacs-4/packages/invoices/www/invoice-send-1.tcl 27 Oct 2006 17:06:33 -0000 1.6 +++ openacs-4/packages/invoices/www/invoice-send-1.tcl 1 Nov 2006 14:28:49 -0000 1.7 @@ -18,8 +18,19 @@ 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] +# Get the organization for the invoice +# Default is the organization associated with the invoice +set rec_organization_id $organization_id + if {[person::person_p -party_id $recipient_id]} { - set rec_organization_id [contact::util::get_employee_organization -employee_id $recipient_id] + set rec_organization_list [contact::util::get_employee_organization -employee_id $recipient_id] + if {[llength $rec_organization_list] > 1} { + if {[lsearch $rec_organization_list $organization_id] > -1} { + set rec_organization_id $organization_id + } else { + set rec_organization_id [lindex $rec_organization_list 0] + } + } } else { set rec_organization_id $recipient_id } Index: openacs-4/packages/invoices/www/mass-invoice.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/mass-invoice.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/invoices/www/mass-invoice.tcl 27 Oct 2006 16:52:27 -0000 1.7 +++ openacs-4/packages/invoices/www/mass-invoice.tcl 1 Nov 2006 14:28:49 -0000 1.8 @@ -39,253 +39,258 @@ ad_progress_bar_begin -title [_ invoices.Create_mass_invoices] -message_1 "[_ invoices.Create_mass_invoices2]" -# We need to catch this so the joined PDF is generated and send. -catch { - - foreach project_item_id $project_id { - - # We need to make sure the whole process runs through smoothly for invoice - # generation. Therefore we put this in transaction. If the transaction fails - # add the project number to a list and notify the user about it later. - - # normal invoice: get recipients from projects - db_1row contacts {} - - # Reset variables - - set project_title 0 - set total_amount 0. - set total_credit 0. - set offer_ids [list] - - ##### INSERT INVOICE ################# - - set due_date [db_string today {}] - set title "[_ invoices.iv_invoice_1] [organizations::name -organization_id $customer_id] $due_date" - - db_1row offer_data {} - - set contacts_package_id [lindex [application_link::get_linked -from_package_id $package_id -to_package_key contacts] 0] - - # Get the recipient information and data. - if {$recipient_id eq ""} { - set rec_organization_id $customer_id - } else { - if {[person::person_p -party_id $recipient_id]} { - set rec_organization_id [contact::util::get_employee_organization -employee_id $recipient_id -package_id $contacts_package_id] - } else { - set rec_organization_id $recipient_id +foreach project_item_id $project_id { + + # We need to make sure the whole process runs through smoothly for invoice + # generation. Therefore we put this in transaction. If the transaction fails + # add the project number to a list and notify the user about it later. + + # normal invoice: get recipients from projects + db_1row contacts {} + + # Reset variables + + set project_title 0 + set total_amount 0. + set total_credit 0. + set offer_ids [list] + + ##### INSERT INVOICE ################# + + set due_date [db_string today {}] + set title "[_ invoices.iv_invoice_1] [organizations::name -organization_id $customer_id] $due_date" + + db_1row offer_data {} + + set contacts_package_id [lindex [application_link::get_linked -from_package_id $package_id -to_package_key contacts] 0] + + # Get the recipient information and data. + if {$recipient_id eq ""} { + set rec_organization_id $customer_id + } else { + if {[person::person_p -party_id $recipient_id]} { + set rec_organization_list [contact::util::get_employee_organization -employee_id $recipient_id -package_id $contacts_package_id] + if {[llength $rec_organization_list] > 1} { + if {[lsearch $rec_organization_list $customer_id] > -1} { + set rec_organization_id $customer_id + } else { + set rec_organization_id [lindex $rec_organization_list 0] + } } + } else { + set rec_organization_id $recipient_id } + } + + # If for whatever the reason we cannot find the organization for the recipient, use the customer + if {![exists_and_not_null rec_organization_id]} { + set rec_organization_id $customer_id + } + + array unset org_data + array set org_data [contacts::get_values \ + -group_name "Customers" \ + -object_type "organization" \ + -party_id $rec_organization_id \ + -contacts_package_id $contacts_package_id] + + if {[info exists org_data(vat_percent)]} { + set vat_percent [format "%.1f" $org_data(vat_percent)] + } else { + set vat_percent [format "%.1f" 0] + } + + set credit_category_id [parameter::get -parameter "CreditCategory"] + set description [lang::util::localize [pm::project::name -project_item_id $project_item_id]] + + # If an invoice exists with this description + + if {[db_string existing_invoice "select 1 from iv_invoicesx where description = :description and status = 'new' limit 1" -default 0]} { + continue + } + + # We are getting the invoice_nr here as we are generating the PDF now. + set invoice_nr [db_nextval iv_invoice_seq] + + set currency [iv::price_list::get_currency -organization_id $rec_organization_id] + + db_transaction { + set new_invoice_rev_id [iv::invoice::new \ + -title $title \ + -description $description \ + -contact_id $contact_id \ + -recipient_id $recipient_id \ + -invoice_nr $invoice_nr \ + -organization_id $rec_organization_id \ + -total_amount $amount_total \ + -amount_sum $amount_sum \ + -currency $currency \ + -due_date $due_date \ + -payment_days $payment_days \ + -vat_percent $vat_percent \ + -vat $vat] - # If for whatever the reason we cannot find the organization for the recipient, use the customer - if {$rec_organization_id eq ""} { - set rec_organization_id $customer_id + set invoice_id [content::revision::item_id -revision_id $new_invoice_rev_id] + if {[exists_and_not_null category_ids]} { + category::map_object -object_id $new_invoice_rev_id $category_ids } - array unset org_data - array set org_data [contacts::get_values \ - -group_name "Customers" \ - -object_type "organization" \ - -party_id $rec_organization_id \ - -contacts_package_id $contacts_package_id] - if {[info exists org_data(vat_percent)]} { - set vat_percent [format "%.1f" $org_data(vat_percent)] - } else { - set vat_percent [format "%.1f" 0] - } + ###### Prepare invoice items ########### - set credit_category_id [parameter::get -parameter "CreditCategory"] - set description [lang::util::localize [pm::project::name -project_item_id $project_item_id]] + set counter 0 - # If an invoice exists with this description - if {[db_string existing_invoice "select 1 from iv_invoicesx where description = :description and status = 'new' limit 1" -default 0]} { - continue - } + # Can't use db_foreach as we are in a transaction + set offer_items_list [db_list_of_lists offer_items {}] - # We are getting the invoice_nr here as we are generating the PDF now. - set invoice_nr [db_nextval iv_invoice_seq] - - set currency [iv::price_list::get_currency -organization_id $rec_organization_id] - - db_transaction { - set new_invoice_rev_id [iv::invoice::new \ - -title $title \ - -description $description \ - -contact_id $contact_id \ - -recipient_id $recipient_id \ - -invoice_nr $invoice_nr \ - -organization_id $rec_organization_id \ - -total_amount $amount_total \ - -amount_sum $amount_sum \ - -currency $currency \ - -due_date $due_date \ - -payment_days $payment_days \ - -vat_percent $vat_percent \ - -vat $vat] + foreach offer_items $offer_items_list { - set invoice_id [content::revision::item_id -revision_id $new_invoice_rev_id] - if {[exists_and_not_null category_ids]} { - category::map_object -object_id $new_invoice_rev_id $category_ids - } + template::util::list_to_array $offer_items offer [list title description offer_item_id item_units offer_id \ + price_per_unit item_nr project_id credit_percent \ + project_title vat rebate category_id offer_cr_item_id + ] - ###### Prepare invoice items ########### + 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)]] + set offer(rebate) [format "%.1f" $offer(rebate)] + set offer(category) [lang::util::localize [category::get_name $offer(category_id)]] - set counter 0 + # Calculate the credit + if {[empty_string_p $offer(credit_percent)]} { + set offer(credit_percent) 0. + } + if {$offer(price_per_unit) > 1.} { + set offer(credit) [format "%.1f" [expr $offer(item_units) * (($offer(credit_percent) + 100.) / 100.)]] + } else { + # do not add credit to items with price of 1 or less + set offer(credit) [format "%.1f" $offer(item_units)] + } + set offer(credit) [format "%.2f" [expr $offer(credit) * $offer(price_per_unit)]] + set offer(credit) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(credit)]] + set offer(credit) [format "%.2f" [expr $offer(credit) - $offer(amount)]] + set offer_name "" + if {![empty_string_p $offer(category)]} { + set offer_name "$offer(category): " + } + append offer_name "$offer(item_units) x $offer(price_per_unit) $currency = $offer(amount_sum) $currency" + if {$offer(rebate) > 0} { + append offer_name " - $offer(rebate)% [_ invoices.iv_offer_item_rebate] = $offer(amount) $currency" + } + if {![empty_string_p $offer(description)]} { + append offer_name " ($offer(description))" + } - # Can't use db_foreach as we are in a transaction - set offer_items_list [db_list_of_lists offer_items {}] + set total_amount [expr $total_amount + $offer(amount) + $offer(credit)] + set total_credit [expr $total_credit + $offer(credit)] - foreach offer_items $offer_items_list { - - template::util::list_to_array $offer_items offer [list title description offer_item_id item_units offer_id \ - price_per_unit item_nr project_id credit_percent \ - project_title vat rebate category_id offer_cr_item_id - ] + # Insert the invoice item + incr counter + set offer(vat) [expr $vat_percent * $offer(vat) / 100.] - - 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)]] - set offer(rebate) [format "%.1f" $offer(rebate)] - set offer(category) [lang::util::localize [category::get_name $offer(category_id)]] - - # Calculate the credit - if {[empty_string_p $offer(credit_percent)]} { - set offer(credit_percent) 0. - } - if {$offer(price_per_unit) > 1.} { - set offer(credit) [format "%.1f" [expr $offer(item_units) * (($offer(credit_percent) + 100.) / 100.)]] - } else { - # do not add credit to items with price of 1 or less - set offer(credit) [format "%.1f" $offer(item_units)] - } - set offer(credit) [format "%.2f" [expr $offer(credit) * $offer(price_per_unit)]] - set offer(credit) [format "%.2f" [expr (1. - ($offer(rebate) / 100.)) * $offer(credit)]] - set offer(credit) [format "%.2f" [expr $offer(credit) - $offer(amount)]] - - set offer_name "" - if {![empty_string_p $offer(category)]} { - set offer_name "$offer(category): " - } - append offer_name "$offer(item_units) x $offer(price_per_unit) $currency = $offer(amount_sum) $currency" - if {$offer(rebate) > 0} { - append offer_name " - $offer(rebate)% [_ invoices.iv_offer_item_rebate] = $offer(amount) $currency" - } - if {![empty_string_p $offer(description)]} { - append offer_name " ($offer(description))" - } - - set total_amount [expr $total_amount + $offer(amount) + $offer(credit)] - set total_credit [expr $total_credit + $offer(credit)] - - # Insert the invoice item - incr counter - set offer(vat) [expr $vat_percent * $offer(vat) / 100.] - - set new_item_rev_id [iv::invoice_item::new \ - -invoice_id $new_invoice_rev_id \ - -title $offer(title) \ - -description $offer(description) \ - -item_nr $offer(item_nr) \ - -offer_item_id $offer(offer_item_id) \ - -item_units $offer(item_units) \ - -price_per_unit $offer(price_per_unit) \ - -rebate $offer(rebate) \ - -amount_total $offer(amount) \ - -sort_order $counter \ - -vat $offer(vat) ] - - # Append the offer_id so we can later on decide - # if the offer/project should be marked as billed. - if {[lsearch $offer_ids $offer(offer_id)] < 0 } { - lappend offer_ids $offer(offer_id) - } - } + set new_item_rev_id [iv::invoice_item::new \ + -invoice_id $new_invoice_rev_id \ + -title $offer(title) \ + -description $offer(description) \ + -item_nr $offer(item_nr) \ + -offer_item_id $offer(offer_item_id) \ + -item_units $offer(item_units) \ + -price_per_unit $offer(price_per_unit) \ + -rebate $offer(rebate) \ + -amount_total $offer(amount) \ + -sort_order $counter \ + -vat $offer(vat) ] - # add credit offer entry - if {$total_credit > 0.} { - set vat_credit [format "%.2f" [expr $total_credit * $vat_percent / 100.]] - db_1row get_credit_offer {} - - # add new offer item - set offer_item_rev_id [iv::offer_item::new \ - -offer_id $credit_offer_rev_id \ - -title $title \ - -description $description \ - -comment "" \ - -item_nr $invoice_id \ - -item_units -$total_credit \ - -price_per_unit 1 \ - -rebate 0 \ - -sort_order $invoice_id \ - -vat $vat_credit] - - category::map_object -object_id $offer_item_rev_id $credit_category_id + # Append the offer_id so we can later on decide + # if the offer/project should be marked as billed. + if {[lsearch $offer_ids $offer(offer_id)] < 0 } { + lappend offer_ids $offer(offer_id) } + } + + # add credit offer entry + if {$total_credit > 0.} { + set vat_credit [format "%.2f" [expr $total_credit * $vat_percent / 100.]] + db_1row get_credit_offer {} - } on_error { + # add new offer item + set offer_item_rev_id [iv::offer_item::new \ + -offer_id $credit_offer_rev_id \ + -title $title \ + -description $description \ + -comment "" \ + -item_nr $invoice_id \ + -item_units -$total_credit \ + -price_per_unit 1 \ + -rebate 0 \ + -sort_order $invoice_id \ + -vat $vat_credit] - lappend failed_project_ids $project_item_id - continue + category::map_object -object_id $offer_item_rev_id $credit_category_id } - ############ PDF Generation ################ + } on_error { - set locale [lang::user::site_wide_locale -user_id $recipient_id] + lappend failed_project_ids $project_item_id + continue + } + + ############ PDF Generation ################ + + set locale [lang::user::site_wide_locale -user_id $recipient_id] + + if {$total_amount >= 0} { - if {$total_amount >= 0} { - - # send invoice - set invoice_title [lang::util::localize "#invoices.file_invoice#_${invoice_nr}.pdf" $locale] - set 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] - set document_types credit - } else { - - # send cancellation - set invoice_title [lang::util::localize "#invoices.file_invoice_cancel#_${invoice_nr}.pdf" $locale] - set document_types cancel - } + # send invoice + set invoice_title [lang::util::localize "#invoices.file_invoice#_${invoice_nr}.pdf" $locale] + set document_types invoice - if {![string eq $recipient_id $contact_id} { - lappend document_types opening - } - - # 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 ""] + } elseif {[empty_string_p $parent_invoice_id]} { - set file_title $invoice_title + # send credit + set invoice_title [lang::util::localize "#invoices.file_invoice_credit#_${invoice_nr}.pdf" $locale] + set document_types credit + } else { - set document_file [lreplace $documents 0 0] + # send cancellation + set invoice_title [lang::util::localize "#invoices.file_invoice_cancel#_${invoice_nr}.pdf" $locale] + set document_types cancel + } + + if {![string eq $recipient_id $contact_id]} { + lappend document_types opening + } + + # 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 ""] + + set file_title $invoice_title + + set document_file [lreplace $documents 0 0] + + # Import the PDF + if {![empty_string_p $document_file]} { + set file_size [file size $document_file] - # Import the PDF - if {![empty_string_p $document_file]} { - set file_size [file size $document_file] - - # We need to keep the file in the filesystem so we can later - # join the files into one PDF for printout. - # Still the single PDF needs to be stored along with the invoice. - - util_unlist [contact::oo::import_oo_pdf -oo_file $document_file -printer_name "pdfconv" -title $file_title -parent_id $invoice_id -return_pdf_with_id] file_item_id file_mime_type file_name - - lappend files $file_name - - # The PDF has been generated. Set it to billed immediately as it will show up in the printout - iv::invoice::set_status -invoice_id $invoice_id -status "billed" - - # an invoice has been generated. Now move it to the folder - + # We need to keep the file in the filesystem so we can later + # join the files into one PDF for printout. + # Still the single PDF needs to be stored along with the invoice. + + util_unlist [contact::oo::import_oo_pdf -oo_file $document_file -printer_name "pdfconv" -title $file_title -parent_id $invoice_id -return_pdf_with_id] file_item_id file_mime_type file_name + + lappend files $file_name + + # The PDF has been generated. Set it to billed immediately as it will show up in the printout + iv::invoice::set_status -invoice_id $invoice_id -status "billed" + + # an invoice has been generated. Now move it to the folder + + if {[catch { set root_folder_id [lindex [application_data_link::get_linked -from_object_id $customer_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]} { @@ -298,7 +303,8 @@ db_dml set_publish_status_and_parent {} db_dml set_context_id {} - + }]} { + ns_log Error "Error in moving the PDF $file_name to the invoice folder" } } } 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.40 -r1.41 --- openacs-4/packages/invoices/www/offer-ae.tcl 25 Oct 2006 21:18:57 -0000 1.40 +++ openacs-4/packages/invoices/www/offer-ae.tcl 1 Nov 2006 14:28:49 -0000 1.41 @@ -730,34 +730,97 @@ ad_script_abort } - set new_offer_rev_id [iv::offer::new \ - -title $title \ - -description $description \ - -comment $comment \ - -reservation $reservation \ - -offer_nr $offer_nr \ - -organization_id $organization_id \ - -amount_total $amount_total \ - -amount_sum $item_sum \ - -currency $currency \ - -finish_date $finish_date \ - -date_comment $date_comment \ - -payment_days $payment_days \ - -show_sum_p $show_sum_p \ - -vat_percent $vat_percent \ - -vat $vat \ - -credit_percent $credit_percent] + set new_offer_rev_id [iv::offer::new \ + -title $title \ + -description $description \ + -comment $comment \ + -reservation $reservation \ + -offer_nr $offer_nr \ + -organization_id $organization_id \ + -amount_total $amount_total \ + -amount_sum $item_sum \ + -currency $currency \ + -finish_date $finish_date \ + -date_comment $date_comment \ + -payment_days $payment_days \ + -show_sum_p $show_sum_p \ + -vat_percent $vat_percent \ + -vat $vat \ + -credit_percent $credit_percent] + + if {[exists_and_not_null category_ids]} { + category::map_object -object_id $new_offer_rev_id $category_ids + } + + set counter 0 + foreach i [array names items] { + incr counter + array set item $items($i) + + set new_item_rev_id [iv::offer_item::new \ + -offer_id $new_offer_rev_id \ + -title $item(title) \ + -description $item(description) \ + -comment $item(comment) \ + -item_nr $item(nr) \ + -item_units $item(units) \ + -price_per_unit $item(price) \ + -rebate $item(rebate) \ + -page_count $item(page_count) \ + -file_count $item(file_count) \ + -sort_order $counter \ + -vat $item(vat) ] + + category::map_object -object_id $new_item_rev_id $item(category) + } + set offer_id [content::revision::item_id -revision_id $new_offer_rev_id] + +} -edit_data { + + if {$amount_total > $item_sum} { + ad_return_error "[_ invoices.negative_rebate]" "[_ invoices.total_mount_less_amount_total]" + ad_script_abort + } - if {[exists_and_not_null category_ids]} { - category::map_object -object_id $new_offer_rev_id $category_ids - } + set new_offer_rev_id [iv::offer::edit \ + -offer_id $offer_id \ + -title $title \ + -description $description \ + -comment $comment \ + -reservation $reservation \ + -offer_nr $offer_nr \ + -organization_id $organization_id \ + -amount_total $amount_total \ + -amount_sum $item_sum \ + -currency $currency \ + -finish_date $finish_date \ + -date_comment $date_comment \ + -payment_days $payment_days \ + -show_sum_p $show_sum_p \ + -vat_percent $vat_percent \ + -vat $vat \ + -credit_percent $credit_percent] + if {$amount_total eq 0} { + ns_log Notice "PA edited. Total amount 0: $offer_id :: $title" + } - set counter 0 - foreach i [array names items] { - incr counter - array set item $items($i) + if {$vat eq 0} { + ns_log Notice "PA edited. VAT 0: $offer_id :: $title" + } - set new_item_rev_id [iv::offer_item::new \ + if {[exists_and_not_null category_ids]} { + category::map_object -object_id $new_offer_rev_id $category_ids + } + + set counter 0 + foreach i [array names items] { + incr counter + array set item $items($i) + + if {[info exists offer_item_id($i)]} { + # new revision of existing item + set new_item_rev_id [iv::offer_item::edit \ + -offer_item_id $offer_item_id($i) \ -offer_id $new_offer_rev_id \ -title $item(title) \ -description $item(description) \ @@ -770,83 +833,26 @@ -file_count $item(file_count) \ -sort_order $counter \ -vat $item(vat) ] - - category::map_object -object_id $new_item_rev_id $item(category) + } else { + # add new item + set new_item_rev_id [iv::offer_item::new \ + -offer_id $new_offer_rev_id \ + -title $item(title) \ + -description $item(description) \ + -comment $item(comment) \ + -item_nr $item(nr) \ + -item_units $item(units) \ + -price_per_unit $item(price) \ + -rebate $item(rebate) \ + -page_count $item(page_count) \ + -file_count $item(file_count) \ + -sort_order $counter \ + -vat $item(vat) ] } - set offer_id [content::revision::item_id -revision_id $new_offer_rev_id] - -} -edit_data { - - if {$amount_total > $item_sum} { - ad_return_error "[_ invoices.negative_rebate]" "[_ invoices.total_mount_less_amount_total]" - ad_script_abort + + category::map_object -object_id $new_item_rev_id $item(category) } - db_transaction { - set new_offer_rev_id [iv::offer::edit \ - -offer_id $offer_id \ - -title $title \ - -description $description \ - -comment $comment \ - -reservation $reservation \ - -offer_nr $offer_nr \ - -organization_id $organization_id \ - -amount_total $amount_total \ - -amount_sum $item_sum \ - -currency $currency \ - -finish_date $finish_date \ - -date_comment $date_comment \ - -payment_days $payment_days \ - -show_sum_p $show_sum_p \ - -vat_percent $vat_percent \ - -vat $vat \ - -credit_percent $credit_percent] - - if {[exists_and_not_null category_ids]} { - category::map_object -object_id $new_offer_rev_id $category_ids - } - - set counter 0 - foreach i [array names items] { - incr counter - array set item $items($i) - - if {[info exists offer_item_id($i)]} { - # new revision of existing item - set new_item_rev_id [iv::offer_item::edit \ - -offer_item_id $offer_item_id($i) \ - -offer_id $new_offer_rev_id \ - -title $item(title) \ - -description $item(description) \ - -comment $item(comment) \ - -item_nr $item(nr) \ - -item_units $item(units) \ - -price_per_unit $item(price) \ - -rebate $item(rebate) \ - -page_count $item(page_count) \ - -file_count $item(file_count) \ - -sort_order $counter \ - -vat $item(vat) ] - } else { - # add new item - set new_item_rev_id [iv::offer_item::new \ - -offer_id $new_offer_rev_id \ - -title $item(title) \ - -description $item(description) \ - -comment $item(comment) \ - -item_nr $item(nr) \ - -item_units $item(units) \ - -price_per_unit $item(price) \ - -rebate $item(rebate) \ - -page_count $item(page_count) \ - -file_count $item(file_count) \ - -sort_order $counter \ - -vat $item(vat) ] - } - - category::map_object -object_id $new_item_rev_id $item(category) - } - } } -after_submit { # upload new file if {![empty_string_p $upload_file]} {