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 -r1.1 -r1.2 --- openacs-4/packages/invoices/www/journal-add.tcl 2 Apr 2006 22:08:02 -0000 1.1 +++ openacs-4/packages/invoices/www/journal-add.tcl 3 May 2006 05:57:37 -0000 1.2 @@ -18,8 +18,6 @@ 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 } @@ -31,11 +29,26 @@ set customer_group_id [group::get_id -group_name "Customers"] set new_customers [db_list_of_lists new_customers {}] +set orga_ids {} set customer_text "" -foreach customer $new_customers { +foreach recipient_id $new_customers { - util_unlist $customer organization_id orga_revision_id email + 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 + } + if {[lsearch -exact $orga_ids $organization_id] > -1} { + continue + } else { + lappend orga_ids $organization_id + } + + set email [party::email -party_id $organization_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 if {[exists_and_not_null address_array(postal_code)]} { 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 -r1.3 -r1.4 --- openacs-4/packages/invoices/www/journal-add.xql 19 Apr 2006 15:00:03 -0000 1.3 +++ openacs-4/packages/invoices/www/journal-add.xql 3 May 2006 05:57:37 -0000 1.4 @@ -30,18 +30,12 @@ - select o.organization_id, oi.latest_revision as orga_revision_id, p.email - from organizations o, cr_items oi, parties p, group_member_map g - where oi.item_id = o.organization_id - and p.party_id = o.organization_id - 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')) + 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')