From c205c173f8cb6dde09a9f99f3189ea6a907363a1 Mon Sep 17 00:00:00 2001
From: Bernat Exposito Domenech <bernat.verdnatura@gmail.com>
Date: Mon, 18 May 2020 10:28:33 +0200
Subject: [PATCH] invoiceOut descriptor popover in ticket summary

---
 modules/ticket/back/methods/ticket/summary.js |  6 ++++++
 modules/ticket/front/routes.json              |  2 +-
 modules/ticket/front/summary/index.html       | 11 +++++++++--
 modules/ticket/front/summary/index.js         |  6 ++++++
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js
index b0a612bf38..3a73c85830 100644
--- a/modules/ticket/back/methods/ticket/summary.js
+++ b/modules/ticket/back/methods/ticket/summary.js
@@ -101,6 +101,12 @@ module.exports = Self => {
                             fields: ['name']
                         }
                     }
+                },
+                {
+                    relation: 'invoiceOut',
+                    scope: {
+                        fields: ['id']
+                    }
                 }
             ],
             where: {id: ticketFk}
diff --git a/modules/ticket/front/routes.json b/modules/ticket/front/routes.json
index 6f54a8efd2..cfb2d07c95 100644
--- a/modules/ticket/front/routes.json
+++ b/modules/ticket/front/routes.json
@@ -3,7 +3,7 @@
     "name": "Tickets",
     "icon": "icon-ticket",
     "validations": true,
-    "dependencies": ["worker", "item", "client", "route"],
+    "dependencies": ["worker", "item", "client", "route", "invoiceOut"],
     "menus": {
         "main": [
             {"state": "ticket.index", "icon": "icon-ticket"},
diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html
index 948fa91734..cf8255294b 100644
--- a/modules/ticket/front/summary/index.html
+++ b/modules/ticket/front/summary/index.html
@@ -37,8 +37,12 @@
                     {{$ctrl.summary.routeFk}}
                 </span>
             </vn-label-value>
-            <vn-label-value label="Invoice" 
-                value="{{$ctrl.summary.refFk}}">
+            <vn-label-value label="Invoice">
+                <span 
+                    ng-click="$ctrl.showInvoiceOutDescriptor($event)"
+                    class="link">
+                    {{$ctrl.summary.refFk | dashIfEmpty}}
+                </span>
             </vn-label-value>
         </vn-one>
         <vn-one>
@@ -235,3 +239,6 @@
     vn-id="descriptor"
     quicklinks="$ctrl.quicklinks">
 </vn-item-descriptor-popover>
+<vn-invoice-out-descriptor-popover
+    vn-id="invoice-out-descriptor">
+</vn-invoice-out-descriptor-popover>
\ No newline at end of file
diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js
index e240cdfc03..fd7e48f1fd 100644
--- a/modules/ticket/front/summary/index.js
+++ b/modules/ticket/front/summary/index.js
@@ -44,6 +44,12 @@ class Controller extends Section {
         this.$.routeDescriptor.show();
     }
 
+    showInvoiceOutDescriptor(event) {
+        this.$.invoiceOutDescriptor.invoiceOutId = this.summary.invoiceOut.id;
+        this.$.invoiceOutDescriptor.parent = event.target;
+        this.$.invoiceOutDescriptor.show();
+    }
+
     showDescriptor(event, sale) {
         this.quicklinks = {
             btnThree: {