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.10 -r1.11 --- openacs-4/packages/invoices/www/invoice-ae.tcl 27 Oct 2005 17:24:39 -0000 1.10 +++ openacs-4/packages/invoices/www/invoice-ae.tcl 27 Oct 2005 18:11:24 -0000 1.11 @@ -305,6 +305,7 @@ -vat_percent $vat_percent \ -vat $vat] + 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 } 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.2 -r1.3 --- openacs-4/packages/invoices/www/invoice-cancellation.tcl 11 Oct 2005 15:23:29 -0000 1.2 +++ openacs-4/packages/invoices/www/invoice-cancellation.tcl 27 Oct 2005 18:11:24 -0000 1.3 @@ -82,6 +82,30 @@ -vat_percent $vat_percent \ -vat $vat] + # add credit offer entry + set parent_item_id [content::revision::item_id -revision_id $parent_id] + db_1row get_credit_offer {} + + if {[db_0or1row get_old_credit {} && $old_credit > 0.} { + # cancelled invoice has credit + set invoice_id [content::revision::item_id -revision_id $new_invoice_rev_id] + set total_credit "-$old_credit" + set vat_credit [format "%.2f" [expr $total_credit * $vat_percent / 100.]] + + # add new offer item + set offer_item_rev_id [iv::offer_item::new \ + -offer_id $credit_offer_rev_id \ + -title $title \ + -description $description \ + -comment "" \ + -item_nr $invoice_id \ + -item_units 1 \ + -price_per_unit $total_credit \ + -rebate 0 \ + -sort_order $invoice_id \ + -vat $vat_credit] + } + if {[exists_and_not_null category_ids]} { category::map_object -object_id $new_invoice_rev_id $category_ids } Index: openacs-4/packages/invoices/www/invoice-cancellation.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/invoices/www/invoice-cancellation.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/invoices/www/invoice-cancellation.xql 11 Oct 2005 15:23:29 -0000 1.2 +++ openacs-4/packages/invoices/www/invoice-cancellation.xql 27 Oct 2005 18:11:24 -0000 1.3 @@ -23,6 +23,38 @@ + + + + select of.offer_id as credit_offer_rev_id + from iv_offers of, cr_items oi, acs_rels r, + acs_objects o, pm_projects p, cr_items pi + where r.object_id_one = pi.item_id + and r.object_id_two = oi.item_id + and r.rel_type = 'application_data_link' + and oi.latest_revision = of.offer_id + and of.status = 'credit' + and o.object_id = of.offer_id + and o.package_id = :package_id + and pi.latest_revision = p.project_id + and p.status_id = 2 + and p.customer_id = :organization_id + + + + + + + + select ofi.price_per_unit as old_credit + from iv_offer_items ofi, cr_items oi + where ofi.offer_id = :credit_offer_rev_id + and oi.latest_revision = ofi.offer_item_id + and ofi.item_nr = :parent_item_id + + + +