Commit 8cf4c7d8 authored by Frank Bergmann's avatar Frank Bergmann

- "Objectified" invoice_items

parent e11a46ac
...@@ -179,8 +179,9 @@ foreach csv_line_fields $values_list_of_lists { ...@@ -179,8 +179,9 @@ foreach csv_line_fields $values_list_of_lists {
set item_uom_id "" set item_uom_id ""
set price_per_unit "" set price_per_unit ""
set item_material_id "" set item_material_id ""
set item_type_id ""
set item_status_id "" set item_type_id [im_invoice_item_type_default]
set item_status_id [im_invoice_item_status_active]
set task_id "" set task_id ""
foreach attribute_name $attribute_names { foreach attribute_name $attribute_names {
...@@ -297,6 +298,9 @@ foreach csv_line_fields $values_list_of_lists { ...@@ -297,6 +298,9 @@ foreach csv_line_fields $values_list_of_lists {
} }
continue continue
} }
# Use the project_id of the cost item also for the invoice items
if {"" eq $project_id} { set project_id [db_string pid "select project_id from im_costs where cost_id = :cost_id" -default ""] }
set item_id [db_string item_id "select min(item_id) from im_invoice_items where invoice_id = :cost_id and item_name = :item_name" -default ""] set item_id [db_string item_id "select min(item_id) from im_invoice_items where invoice_id = :cost_id and item_name = :item_name" -default ""]
if {"" eq $currency} { set currency [db_string cur "select currency from im_costs where cost_id = :cost_id" -default $default_currency] } if {"" eq $currency} { set currency [db_string cur "select currency from im_costs where cost_id = :cost_id" -default $default_currency] }
...@@ -304,22 +308,20 @@ foreach csv_line_fields $values_list_of_lists { ...@@ -304,22 +308,20 @@ foreach csv_line_fields $values_list_of_lists {
# Create a new sort order based on the existing number of invoice_items # Create a new sort order based on the existing number of invoice_items
set sort_order [db_string sort_order "select 1+count(*) from im_invoice_items where invoice_id = :cost_id"] set sort_order [db_string sort_order "select 1+count(*) from im_invoice_items where invoice_id = :cost_id"]
} }
# Item doesn't exist yet - insert
if {"" eq $item_id} { if {"" eq $item_id} {
# Item doesn't exist yet - insert
if {$ns_write_p} { ns_write "<li><font color=green>Going to create line: cost_name='$cost_name', item_name='$item_name'</font></li>" } if {$ns_write_p} { ns_write "<li><font color=green>Going to create line: cost_name='$cost_name', item_name='$item_name'</font></li>" }
db_dml insert_item " set item_id [db_string new_invoice_item "select im_invoice_item__new (
insert into im_invoice_items ( null, 'im_invoice_item', now(), :current_user_id, '[ad_conn peeraddr]', null,
item_id, :item_name, :cost_id, :sort_order,
invoice_id, sort_order, item_name, item_units, item_uom_id, price_per_unit, item_material_id, item_type_id, item_status_id, currency :item_units, :item_uom_id, :price_per_unit, :currency,
) values ( :item_type_id, :item_status_id
nextval('im_invoice_items_seq'), )"]
:cost_id, :sort_order, :item_name, :item_units, :item_uom_id, :price_per_unit, :item_material_id, :item_type_id, :item_status_id, :currency }
)
" # Update - weather it's new or not...
} else { if {$ns_write_p} { ns_write "<li>Going to update line: cost_name='$cost_name', item_name='$item_name'\n" }
# Item already exists - update db_dml update_item "
if {$ns_write_p} { ns_write "<li>Going to update line: cost_name='$cost_name', item_name='$item_name'\n" }
db_dml update_item "
update im_invoice_items set update im_invoice_items set
invoice_id = :cost_id, invoice_id = :cost_id,
sort_order = :sort_order, sort_order = :sort_order,
...@@ -330,11 +332,11 @@ foreach csv_line_fields $values_list_of_lists { ...@@ -330,11 +332,11 @@ foreach csv_line_fields $values_list_of_lists {
item_material_id = :item_material_id, item_material_id = :item_material_id,
item_type_id = :item_type_id, item_type_id = :item_type_id,
item_status_id = :item_status_id, item_status_id = :item_status_id,
project_id = :project_id,
currency = :currency currency = :currency
where where
item_id = :item_id; item_id = :item_id;
" "
}
# Skip the rest of the code dealing with im_invoices # Skip the rest of the code dealing with im_invoices
continue continue
......
...@@ -78,10 +78,12 @@ ...@@ -78,10 +78,12 @@
<a href="http://www.project-open.com/en/object-type-im-invoice" target="_blank">Financial Documents</a> are <a href="http://www.project-open.com/en/object-type-im-invoice" target="_blank">Financial Documents</a> are
<a href="http://www.project-open.com/en/object-type-im-cost" target="_blank">cost items</a> with a header and <a href="http://www.project-open.com/en/object-type-im-cost" target="_blank">cost items</a> with a header and
one more more lines. Financial documents include invoices, quotes, purchase orders and others.<br> one more more lines. Financial documents include invoices, quotes, purchase orders and others.<br>
Financial document lines can be imported together with the headers (please see the example document).<br>
Cost Item <a href="/intranet-dynfield/object-type?object_type=im_invoice">DynFields</a> are also recognized by their "pretty name" or "column name".</p> Cost Item <a href="/intranet-dynfield/object-type?object_type=im_invoice">DynFields</a> are also recognized by their "pretty name" or "column name".</p>
</td> </td>
</tr> </tr>
<!--
<tr> <tr>
<td><%= [im_gif page_white_star] %></td> <td><%= [im_gif page_white_star] %></td>
<td>Financial Document Item</td> <td>Financial Document Item</td>
...@@ -89,6 +91,7 @@ ...@@ -89,6 +91,7 @@
<td align=center><a href="/intranet-reporting/view?report_id=<%=$report_id_export_invoice_items%>"><%= [im_gif database_table] %></a></td> <td align=center><a href="/intranet-reporting/view?report_id=<%=$report_id_export_invoice_items%>"><%= [im_gif database_table] %></a></td>
<td>Allows to import "Items" seperately from headers.</td> <td>Allows to import "Items" seperately from headers.</td>
</tr> </tr>
-->
<tr> <tr>
<td><%= [im_gif [db_string gif "select object_type_gif from acs_object_types where object_type = 'im_project'"]] %></td> <td><%= [im_gif [db_string gif "select object_type_gif from acs_object_types where object_type = 'im_project'"]] %></td>
......
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