Commit 92a5a38e authored by Frank Bergmann's avatar Frank Bergmann

- debugged purchase-order creation

- added "select_project" to invoice and po generation
- deletion of invoices and im_trans_invoices now works
parent 78acb835
......@@ -429,7 +429,7 @@ extra_select, extra_where, sort_order, visible_for) values (3017,30,NULL,'Status
insert into im_view_columns (column_id, view_id, group_id, column_name, column_render_tcl,
extra_select, extra_where, sort_order, visible_for) values (3098,30,NULL,'Del',
'[if {[string equal "" $payment_amount]} {
set ttt "<input type=checkbox name=del_invoice value=$invoice_id>"
set ttt "<input type=checkbox name=del_cost value=$invoice_id><input type=hidden name=object_type.$invoice_id value=$object_type>"
}]','','',99,'');
--
......
......@@ -15,8 +15,9 @@ ad_page_contract {
@author frank.bergmann@project-open.com
} {
{ return_url "/intranet-invoices/" }
del_invoice:multiple,optional
del_cost:multiple,optional
cost_status:array,optional
object_type:array,optional
submit
}
......@@ -46,31 +47,25 @@ switch $submit {
}
"Del" {
# "Del" button pressed: delete the marked invoices:
# - Mark the associated im_trans_tasks as "delivered"
# and reset their invoice_id (to be able to
# delete the invoice).
# - Delete the associated im_invoice_items
# - Delete from project-invoice-map
# - Deleter underlying im_cost item
#
set in_clause_list [list]
# Maybe the list of costs was empty...
if {![info exists del_cost]} {
ad_returnredirect $return_url
return
}
# Maybe the list of invoices was empty...
if {![info exists del_invoice]} {
ad_returnredirect $return_url
return
}
foreach invoice_id $del_invoice {
db_dml "
begin
im_trans_invoice.del(:invoice_id);
end;"
}
foreach cost_id $del_cost {
set otype $object_type($cost_id)
# ToDo: Security
db_dml delete_cost_item "
begin
${otype}.del(:cost_id);
end;"
lappend in_clause_list $cost_id
}
set cost_where_list "([join $in_clause_list ","])"
ad_returnredirect $return_url
return
ad_returnredirect $return_url
return
}
default {
......
......@@ -244,6 +244,7 @@ set sql "
select
i.*,
i.invoice_date + i.payment_days as due_date_calculated,
o.object_type,
ii.invoice_amount,
ii.invoice_currency,
to_char(ii.invoice_amount,:cur_format) as invoice_amount_formatted,
......@@ -259,6 +260,7 @@ select
$extra_select
from
im_invoices_active i,
acs_objects o,
im_customers c,
im_customers p,
(select
......@@ -270,7 +272,8 @@ from
) ii
$extra_from
where
i.customer_id=c.customer_id(+)
i.invoice_id = o.object_id
and i.customer_id=c.customer_id(+)
and i.provider_id=p.customer_id(+)
and i.invoice_id=ii.invoice_id(+)
$company_where
......
......@@ -16,7 +16,7 @@ ad_page_contract {
invoice_id:integer
{ customer_id:integer "" }
{ provider_id:integer "" }
{ project_id:integer "" }
{ select_project:integer,multiple {} }
invoice_nr
invoice_date
cost_status_id:integer
......@@ -71,15 +71,15 @@ if {$invoice_or_bill_p && ("" == $payment_method_id || 0 == $payment_method_id)}
return
}
if {"" == $provider_id} { set provider_id [im_customer_internal] }
if {"" == $customer_id} { set customer_id [im_customer_internal] }
set customer_internal [db_string customer_internal "select customer_id from im_customers where lower(customer_path) = 'internal'" -default 0]
if {!$customer_internal} {
ad_return_complaint 1 "<li>Unable to find 'Internal' customer with path 'internal'. <br>Maybe somebody has change the path of the customer?"
return
set project_id ""
if {1 == [llength $select_project]} {
set project_id [lindex $select_project 0]
}
if {"" == $provider_id} { set provider_id $customer_internal }
if {"" == $customer_id} { set customer_id $customer_internal }
# ---------------------------------------------------------------
# Update invoice base data
......@@ -92,28 +92,27 @@ if {!$invoice_exists_p} {
# Let's create the new invoice
db_dml create_invoice "
DECLARE
v_invoice_id integer;
BEGIN
v_invoice_id := im_invoice.new (
invoice_id => :invoice_id,
creation_user => :user_id,
creation_ip => '[ad_conn peeraddr]',
invoice_nr => :invoice_nr,
customer_id => :customer_id,
provider_id => :provider_id,
invoice_date => :invoice_date,
invoice_template_id => :template_id,
invoice_status_id => :cost_status_id,
invoice_type_id => :cost_type_id,
payment_method_id => :payment_method_id,
payment_days => :payment_days,
amount => 0,
vat => :vat,
tax => :tax
);
END;"
DECLARE
v_invoice_id integer;
BEGIN
v_invoice_id := im_invoice.new (
invoice_id => :invoice_id,
creation_user => :user_id,
creation_ip => '[ad_conn peeraddr]',
invoice_nr => :invoice_nr,
customer_id => :customer_id,
provider_id => :provider_id,
invoice_date => :invoice_date,
invoice_template_id => :template_id,
invoice_status_id => :cost_status_id,
invoice_type_id => :cost_type_id,
payment_method_id => :payment_method_id,
payment_days => :payment_days,
amount => 0,
vat => :vat,
tax => :tax
);
END;"
}
# Update the invoice itself
......@@ -148,22 +147,15 @@ where
cost_id = :invoice_id
"
set ttt "
"
# ---------------------------------------------------------------
# Create the im_invoice_items for the invoice
# ---------------------------------------------------------------
# Delete the old items if they exist
db_dml delete_invoice_items "
# Delete the old items if they exist
db_dml delete_invoice_items "
DELETE from im_invoice_items
WHERE invoice_id=:invoice_id
"
"
set item_list [array names item_name]
foreach nr $item_list {
......@@ -181,18 +173,42 @@ foreach nr $item_list {
if {!("" == [string trim $name] && (0 == $units || "" == $units))} {
set item_id [db_nextval "im_invoice_items_seq"]
set insert_invoice_items_sql "
INSERT INTO im_invoice_items (
item_id, item_name, project_id, invoice_id, item_units, item_uom_id,
price_per_unit, currency, sort_order, item_type_id, item_status_id, description
) VALUES (
:item_id, :name, :project_id, :invoice_id, :units, :uom_id,
:rate, :currency, :sort_order, :type_id, null, ''
)"
INSERT INTO im_invoice_items (
item_id, item_name,
project_id, invoice_id,
item_units, item_uom_id,
price_per_unit, currency,
sort_order, item_type_id,
item_status_id, description
) VALUES (
:item_id, :name,
:project_id, :invoice_id,
:units, :uom_id,
:rate, :currency,
:sort_order, :type_id,
null, ''
)"
db_dml insert_invoice_items $insert_invoice_items_sql
}
}
# ---------------------------------------------------------------
# Associate the invoice with the project via acs_rels
# ---------------------------------------------------------------
foreach project_id $select_project {
db_dml insert_acs_rels "
DECLARE
v_rel_id integer;
BEGIN
v_rel_id := acs_rel.new(
object_id_one => :project_id,
object_id_two => :invoice_id
);
END;"
}
# ---------------------------------------------------------------
# Update the invoice amount based on the invoice items
# ---------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment