Преглед на файлове

[ADD] Validacion el Selecionar y eliminar las cuota

adrielso преди 7 години
родител
ревизия
89f0dd31a4
променени са 3 файла, в които са добавени 60 реда и са изтрити 18 реда
  1. 12 8
      src/components/move/MoveContainer/MoveCard.vue
  2. 21 8
      src/components/move/MoveLinesContainer/MoveLinesItem.vue
  3. 27 2
      src/store/modules/paymentsMoveLines.js

+ 12 - 8
src/components/move/MoveContainer/MoveCard.vue

@@ -1,6 +1,6 @@
 <template lang="pug">
-    .move-card-wrapper(@click="selectMoveline(item)")
-        .move-card
+    .move-card-wrapper(@click="selectMoveline(item)" )
+        .move-card(v-bind:class="{'move-card-disable': moveDisable() }")
             h2.move-maturity Vencimiento {{ getDate() }}
             .move-debit-wrapper
                 h2.move-debit-label Total
@@ -28,12 +28,18 @@
             'selectedPartner',
             'selectedMoveline',
             'haSelectedMoveline',
-            'selectedInvoices'
+            'selectedInvoices',
+            'moveLines'
         ]),
         methods: {
             ...mapActions([
                 'selectMoveline'
             ]),
+            moveDisable() {
+                let date_maturity = moment(this.item.date_maturity).valueOf()
+                let dates = this.moveLines.map(item => { return moment(item.date_maturity).valueOf()})
+                return dates.findIndex(item => item >= date_maturity) !== 0 ? true : false
+            },
             getDate() {
                 return !!this.item.date_maturity ? moment(this.item.date_maturity).format("DD-MM-YYYY") : ''
             },
@@ -62,16 +68,14 @@
         display: inline-block
         position: relative
 
-        // &.selected-Line
-        //     transition-duration: 3s
-        //     opacity: 1
-        //     transform: translate3d(1176px, 0px, 0px)
-
         .move-card
             width: 100%
             height: 100%
             position: absolute
 
+            &.move-card-disable
+                background: #e6e6e6
+
             .move-maturity
                 width: 240px
                 height: 30px

+ 21 - 8
src/components/move/MoveLinesContainer/MoveLinesItem.vue

@@ -1,8 +1,8 @@
 <template lang="pug">
     li.move-lines-item
-        h3.move-lines-item-maturity Vencimiento {{ item.date_maturity}} {{ item.id }}
+        h3.move-lines-item-maturity Vencimiento {{ getDateMaturity()  }}
         span.move-lines-item-subtotal {{ formatTotal() }} {{ getSymbol() }}
-        .move-lines-item-options-wrapper(class="fa fa-trash" @click="remove(item)")
+        .move-lines-item-options-wrapper(class="fa fa-trash" @click="remove(item)" v-bind:class="{'fa-trash-disable': lineDisable()}")
 </template>
 
 <script>
@@ -19,23 +19,30 @@
             }
         },
         computed: mapGetters([
-            'selectedInvoices'
+            'selectedInvoices',
+            'addMove'
         ]),
         methods: {
             remove(item) {
                 this.removeLine(item)
             },
-            ...mapActions([
-                'removeLine'
-            ]),
+            getDateMaturity() {
+                return moment(this.item.date_maturity).format("DD-MM-YYYY")
+            },
+            lineDisable(){
+                let dateMax = moment(moment.max(this.addMove.map(item => { return moment(item.date_maturity)}))).valueOf()
+                return dateMax > moment(this.item.date_maturity).valueOf() ? true : false
+            },
             formatTotal() {
                 return accounting.format(this.item.amount_residual,0,'.',',')
             },
             getSymbol() {
                 return this.selectedInvoices.currency_symbol
-            }
+            },
+            ...mapActions([
+                'removeLine'
+            ])
         }
-
     }
 </script>
 
@@ -95,4 +102,10 @@
             &.fa-trash:hover
                 color: #f44336
 
+            &.fa-trash-disable
+                color: #e6e6e6
+
+                &:hover
+                    color: #e6e6e6
+
 </style>

+ 27 - 2
src/store/modules/paymentsMoveLines.js

@@ -43,6 +43,10 @@ const mutations = {
         if (finded) return
 
         state.movelineSelect =[payload.moveselect, ...state.movelineSelect]
+
+        state.movelineSelect.sort((a, b) => {
+            return a.date_maturity > b.date_maturity
+        })
     },
 
     calculateTotal(state) {
@@ -68,6 +72,10 @@ const mutations = {
         if (finded) return
 
         state.moveLines = [payload.moveLine, ...state.moveLines]
+
+        state.moveLines.sort((a, b) => {
+            return a.date_maturity > b.date_maturity
+        })
     },
     addMoveCard(state, payload) {
         payload.moveLine.forEach(moveLine => {
@@ -75,6 +83,10 @@ const mutations = {
             if (finded) return
 
             state.moveLines = [moveLine, ...state.moveLines]
+
+            state.moveLines.sort((a, b) => {
+                return a.date_maturity > b.date_maturity
+            })
         })
     },
     remoMovelineSelectALL(state,payload) {
@@ -87,7 +99,13 @@ const actions = {
         commit('pushMovelines', payload)
     },
 
-    selectMoveline({ commit, dispatch}, payload) {
+    selectMoveline({ commit, dispatch, getters}, payload) {
+        let dateMin = moment(moment.min(getters.moveLines.map(item => { return moment(item.date_maturity)}))).valueOf()
+
+        if (dateMin < moment(payload.date_maturity).valueOf())
+            return dispatch('notify', 'Cuota no permitida')
+            // return dispatch('notify', 'Ops, no podes seleccionar esta cuota, debes seleccionar la cuota pendiente permitida')
+
         commit('selectMoveline',{
             moveline: payload
         })
@@ -100,7 +118,14 @@ const actions = {
         commit('calculateTotal')
     },
 
-    removeLine({ commit, dispatch}, payload) {
+    removeLine({ commit, dispatch, state}, payload) {
+
+        let dateMax = moment(moment.max(state.movelineSelect.map(item => { return moment(item.date_maturity)}))).valueOf()
+
+        if (dateMax > moment(payload.date_maturity).valueOf())
+            return dispatch('notify', 'No podes eliminar esta cuota')
+            // return dispatch('notify', 'Ops, no podes suprimir este registro, primero debes eliminar las cuota con fecha de vencimiento superior')
+
         commit('removeLine',{
             movedelet: payload
         })