|  | @@ -15,6 +15,10 @@
 | 
	
		
			
				|  |  |                      td
 | 
	
		
			
				|  |  |                          th Fecha de Pago
 | 
	
		
			
				|  |  |                          th Monto a pagar
 | 
	
		
			
				|  |  | +                tbody
 | 
	
		
			
				|  |  | +                    tr(v-for="line in totalLines")
 | 
	
		
			
				|  |  | +                        td {{ line.date }}
 | 
	
		
			
				|  |  | +                        td {{ line.total }}
 | 
	
		
			
				|  |  |  </template>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  <script>
 | 
	
	
		
			
				|  | @@ -30,24 +34,74 @@
 | 
	
		
			
				|  |  |                      value = accounting.unformat(value, ',')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      this.changeAmountPaid(value)
 | 
	
		
			
				|  |  | +                    this.computeAmounts(value)
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  |              ...mapGetters([
 | 
	
		
			
				|  |  |                  'total',
 | 
	
		
			
				|  |  |                  'currencySymbol',
 | 
	
		
			
				|  |  | -                'amountPaid'
 | 
	
		
			
				|  |  | +                'amountPaid',
 | 
	
		
			
				|  |  | +                'selectedPaymentTerm',
 | 
	
		
			
				|  |  | +                'company'
 | 
	
		
			
				|  |  |              ])
 | 
	
		
			
				|  |  |          },
 | 
	
		
			
				|  |  |          methods: {
 | 
	
		
			
				|  |  |              formatTotal() {
 | 
	
		
			
				|  |  |                  return accounting.formatMoney(this.total, this.currencySymbol, 0, '.', ',')
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  | +            computeAmounts(value) {
 | 
	
		
			
				|  |  | +                this.totalLines = []
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                let percentPaid = value / this.total
 | 
	
		
			
				|  |  | +                let distributePercent = -(percentPaid / this.selectedPaymentTerm.lines.length)
 | 
	
		
			
				|  |  | +                let totals = []
 | 
	
		
			
				|  |  | +                let residual = this.total
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                for (let line of this.selectedPaymentTerm.lines) {
 | 
	
		
			
				|  |  | +                    let dueDate = moment(this.company.today).add(line.days + line.days2, 'days').format('YYYY-MM-DD')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    if (percentPaid) {
 | 
	
		
			
				|  |  | +                        totals.push([this.company.today, percentPaid])
 | 
	
		
			
				|  |  | +                        percentPaid = 0
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        if (dueDate === this.company.today) {
 | 
	
		
			
				|  |  | +                            distributePercent = -((this.totals[0] - line.value_amount) / (this.selectedPaymentTerm.lines.length - 1))
 | 
	
		
			
				|  |  | +                            continue
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    if (line.value !== 'balance') {
 | 
	
		
			
				|  |  | +                        totals.push([dueDate, line.value_amount + distributePercent])
 | 
	
		
			
				|  |  | +                        continue
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    totals.push([dueDate, line.value_amount])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    for (let line of totals) {
 | 
	
		
			
				|  |  | +                        let currentPrice = (this.total * line[1]).toFixed(2)
 | 
	
		
			
				|  |  | +                        residual = residual - currentPrice
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        this.totalLines.push({
 | 
	
		
			
				|  |  | +                            date: line[0], 
 | 
	
		
			
				|  |  | +                            total: currentPrice !== parseFloat(0).toFixed(2) ? currentPrice : residual.toFixed(2)
 | 
	
		
			
				|  |  | +                        })
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    totals = []
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            },
 | 
	
		
			
				|  |  |              ...mapActions([
 | 
	
		
			
				|  |  |                  'changeAmountPaid'
 | 
	
		
			
				|  |  |              ])
 | 
	
		
			
				|  |  |          },
 | 
	
		
			
				|  |  | +        data() {
 | 
	
		
			
				|  |  | +            return {
 | 
	
		
			
				|  |  | +                totalLines: []
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  |          mounted() {
 | 
	
		
			
				|  |  |              this.changeAmountPaid(0)
 | 
	
		
			
				|  |  | +            console.log(this.totalLines)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  </script>
 | 
	
	
		
			
				|  | @@ -92,19 +146,23 @@
 | 
	
		
			
				|  |  |                  width: 100%
 | 
	
		
			
				|  |  |                  height: 250px
 | 
	
		
			
				|  |  |                  border: 1px solid #d3d3d3
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  table
 | 
	
		
			
				|  |  |                      width: 100%
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    td
 | 
	
		
			
				|  |  | -                        height: 35px
 | 
	
		
			
				|  |  |                      thead
 | 
	
		
			
				|  |  |                          th
 | 
	
		
			
				|  |  |                              line-height: 35px
 | 
	
		
			
				|  |  |                              padding-left: 10px
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                          th:nth-child(1)
 | 
	
		
			
				|  |  |                              width: 250px
 | 
	
		
			
				|  |  |                          th:nth-child(2)
 | 
	
		
			
				|  |  |                              width: 200px
 | 
	
		
			
				|  |  | +                    tbody
 | 
	
		
			
				|  |  | +                        td
 | 
	
		
			
				|  |  | +                            height: 35px
 | 
	
		
			
				|  |  | +                            padding-left: 10px
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        td:nth-child(1)
 | 
	
		
			
				|  |  | +                            width: 250px
 | 
	
		
			
				|  |  | +                        td:nth-child(2)
 | 
	
		
			
				|  |  | +                            width: 200px
 | 
	
		
			
				|  |  |  </style>
 |