From 1e665869cabe594ecd2ed8996fbd07cc7e0b5e19 Mon Sep 17 00:00:00 2001
From: "a.schindlbeck" <a.schindlbeck@adito.de>
Date: Thu, 21 Mar 2019 13:24:22 +0100
Subject: [PATCH] #1035775 "Angebot drucken"-Button bei 0 Posten ausgeblendet

---
 entity/Offer_entity/Offer_entity.aod             |  1 +
 .../entityfields/printoffer/stateProcess.js      | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 entity/Offer_entity/entityfields/printoffer/stateProcess.js

diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod
index b34f568982..25b019bc22 100644
--- a/entity/Offer_entity/Offer_entity.aod
+++ b/entity/Offer_entity/Offer_entity.aod
@@ -249,6 +249,7 @@
       <title>Print Offer</title>
       <onActionProcess>%aditoprj%/entity/Offer_entity/entityfields/printoffer/onActionProcess.js</onActionProcess>
       <iconId>VAADIN:FILE_TEXT_O</iconId>
+      <stateProcess>%aditoprj%/entity/Offer_entity/entityfields/printoffer/stateProcess.js</stateProcess>
     </entityActionField>
     <entityField>
       <name>CONTACT_ORG_ID</name>
diff --git a/entity/Offer_entity/entityfields/printoffer/stateProcess.js b/entity/Offer_entity/entityfields/printoffer/stateProcess.js
new file mode 100644
index 0000000000..4b34993e70
--- /dev/null
+++ b/entity/Offer_entity/entityfields/printoffer/stateProcess.js
@@ -0,0 +1,16 @@
+import("system.logging");
+import("system.result");
+import("system.db");
+import("Sql_lib");
+import("system.neon");
+
+var itemcount = db.cell(SqlCondition.begin()
+                    .andPrepareVars("OFFERITEM.OFFER_ID", "$field.OFFERID")
+                    .buildSql("select count(*) from OFFERITEM", "1=2"));
+                    
+logging.log("itemcount: "+itemcount);
+                    
+if(itemcount == "0")
+    result.string(neon.COMPONENTSTATE_DISABLED);
+else
+    result.string(neon.COMPONENTSTATE_AUTO);
\ No newline at end of file
-- 
GitLab