Permalink
Browse files

fixed delete an order

  • Loading branch information...
1 parent 8781570 commit a20dcdbc4c6fae8776e81de8b091cd8d2d191b50 Iuri Sampaio committed May 2, 2012
@@ -9,13 +9,13 @@
<implements-subsite-p>f</implements-subsite-p>
<inherit-templates-p>f</inherit-templates-p>
- <version name="0.10d" url="http://openacs.org/repository/download/apm/cnauto-import-0.10d.apm">
+ <version name="0.11d" url="http://openacs.org/repository/download/apm/cnauto-import-0.11d.apm">
<owner url="mailto:iuri.sampaio@cnauto.com.br">iuri sampaio</owner>
<summary>Package for import management</summary>
<description format="text/html">Package for import management</description>
<maturity>0</maturity>
- <provides url="cnauto-import" version="0.10d"/>
+ <provides url="cnauto-import" version="0.11d"/>
<requires url="cnauto-core" version="0.1d"/>
<requires url="cnauto-resources" version="0.1d"/>
@@ -75,10 +75,11 @@ CREATE OR REPLACE FUNCTION cn_import_order__delete (
BEGIN
- DELETE FROM cn_import_orders WHERE order_id = p_order_id;
PERFORM acs_object__delete(p_order_id);
+ DELETE FROM cn_import_orders WHERE order_id = p_order_id;
+
RETURN 0;
END;' language 'plpgsql';
@@ -0,0 +1,17 @@
+-- /packages/cnauto-import/sql/postgtresql/upgrade/upgrade-0.10d-0.11d.sql
+
+CREATE OR REPLACE FUNCTION cn_import_order__delete (
+ integer -- order_id
+) RETURNS integer AS '
+ DECLARE
+ p_order_id ALIAS FOR $1;
+
+ BEGIN
+
+
+ PERFORM acs_object__delete(p_order_id);
+
+ DELETE FROM cn_import_orders WHERE order_id = p_order_id;
+
+ RETURN 0;
+ END;' language 'plpgsql';
@@ -0,0 +1,16 @@
+
+CREATE OR REPLACE FUNCTION cn_import_order__delete (
+ integer -- order_id
+) RETURNS integer AS '
+ DECLARE
+ p_order_id ALIAS FOR $1;
+
+ BEGIN
+
+
+ PERFORM acs_object__delete(p_order_id);
+
+ DELETE FROM cn_import_orders WHERE order_id = p_order_id;
+
+ RETURN 0;
+ END;' language 'plpgsql';
@@ -12,7 +12,28 @@ namespace eval cn_import {}
### Orders
##########################
namespace eval cn_import::order {}
+ad_proc -public cn_import::order::delete {
+ {-order_id}
+} {
+
+ Deletes an order
+} {
+ # Delete its children first
+ db_foreach select_child {
+ SELECT order_id AS child_id FROM cn_import_orders WHERE parent_id = :order_id
+ } {
+ db_exec_plsql delete_order {
+ SELECT cn_import_order__delete (:chldd_id)
+ }
+ }
+
+ db_exec_plsql delete_order {
+ SELECT cn_import_order__delete (:order_id)
+ }
+
+ return
+}
ad_proc -public cn_import::order::new {
{-cnimp_number:required}
{-parent_id ""}
@@ -2,10 +2,10 @@
<property name="context">@context_bar;noquote@</property>
<property name="title">#cnauto-import.Confirm_room_delete#</property>
-<form method="post" action="order-delete-2">
+<form method="post" action="order-delete">
<p>#cnauto-import.Are_you_sure_you_want_to_delete#?</p>
<multiple name="orders">
-@orders.code@<br>
+@orders.cnimp_number;noquote@<br>
</multiple>
<div>
@@ -30,7 +30,7 @@ foreach element $order_ids {
set order_ids [join $order_ids ","]
db_multirow orders orders "
- SELECT order_id, code FROM cn_orders WHERE order_id IN ($order_ids)
+ SELECT order_id, cnimp_number FROM cn_import_orders WHERE order_id IN ($order_ids)
"
set hidden_vars [export_form_vars order_id return_url]
@@ -0,0 +1,23 @@
+
+ad_page_contract {
+ Delete orders.
+} {
+ order_id:notnull
+ {return_url ""}
+ {cancel.x:optional}
+}
+
+
+if {![info exists cancel.x]} {
+
+
+ foreach element $order_id {
+# ad_require_permission $element order_delete
+ if { [catch { cn_import::order::delete -order_id $element } errmsg] } {
+ ad_return_complaint 1 "[_ cn-order.Delete_order_failed]: $errmsg"
+ }
+ }
+}
+ad_returnredirect $return_url
+
+

0 comments on commit a20dcdb

Please sign in to comment.