Przeglądaj źródła

[ADD] Save Payments

adrielso 7 lat temu
rodzic
commit
43f86d181a

+ 149 - 3
controllers/main.py

@@ -4,7 +4,6 @@ from openerp.http import request
 from werkzeug.wrappers import Response
 from werkzeug.datastructures import Headers
 from datetime import datetime
-from StringIO import StringIO
 from gzip import GzipFile
 from StringIO import StringIO as IO
 import simplejson as json
@@ -12,13 +11,15 @@ import gzip
 import logging
 
 LOGGER = logging.getLogger(__name__)
+DATE_FORMAT = '%Y-%m-%d'
+GZIP_COMPRESSION_LEVEL = 9
 
 class PaymentsSales(http.Controller):
     '''
         Get server date
     '''
     def get_server_date(self):
-        return datetime.now().strftime('%y-%m-%d')
+        return datetime.now().strftime(DATE_FORMAT)
 
     '''
         Get partner customer
@@ -205,7 +206,7 @@ class PaymentsSales(http.Controller):
     '''
     def make_gzip_response(self, data=None, status=200):
         gzip_buffer = IO()
-        with GzipFile(mode='wb', compresslevel=9, fileobj=gzip_buffer) as gzip_file:
+        with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
             gzip_file.write(json.dumps(data))
 
         contents = gzip_buffer.getvalue()
@@ -238,3 +239,148 @@ class PaymentsSales(http.Controller):
             'journals': self.get_journals(),
             'currencies': self.get_currency()
         })
+
+    '''
+        Get the current period
+    '''
+    def get_period(self, date_server):
+        return request.env['account.period'].search([('date_start','<=', date_server), ('date_stop', '>=', datetime.now().strftime(DATE_FORMAT))])
+
+    '''
+        Get Invoice
+    '''
+    def get_invoice(self, invoice_id):
+        return request.env['account.invoice'].search([('id', '=', invoice_id)])
+
+    '''
+        Create Voucher
+    '''
+    def create_voucher(self, period, invoice, company_id, amountPayments, date_server, journalId, move_line_Ids, customerId):
+        # get Journal / Currency
+        journal_id = request.env['account.journal'].browse(int(journalId))
+        currency_id = journal_id.default_credit_account_id.currency_id.id or journal_id.default_credit_account_id.company_currency_id.id
+        # Get Move Lines
+        move_line = request.env['account.move.line'].browse(move_line_Ids).sorted(key=lambda r: r.id)
+        # get customer
+        customerId = request.env['res.partner'].browse(customerId)
+
+        # Create Line  Voucher
+        line_cr_ids = []
+        amount = float(amountPayments)
+
+        for line in move_line:
+            line_cr_ids.append([0, False, {
+                'date_due': line.date_maturity,
+                'account_id': line.account_id.id,
+                'date_original': line.move_id.date,
+                'move_line_id': line.id,
+                'amount_original': abs(line.credit or line.debit or 0.0),
+                'amount_unreconciled': abs(line.amount_residual),
+                'amount': min(abs(amount), line.amount_residual),
+                'reconcile': line.move_id.date <= line.date_maturity,
+                'currency_id': currency_id
+            }])
+            amount -= min(abs(amount), line.amount_residual)
+
+        values = {
+                'reference': invoice.number,
+                'type': 'receipt',
+                'journal_id': journal_id.id,
+                'company_id': company_id,
+                'pre_line': True,
+                'amount': float(amountPayments),
+                'period_id': period.id,
+                'date': date_server,
+                'partner_id': customerId.id,
+                'account_id': journal_id.default_credit_account_id.id,
+                'currency_id': currency_id,
+                'line_cr_ids': line_cr_ids
+            }
+        account_voucher = request.env['account.voucher'].create(values)
+        account_voucher.action_move_line_create()
+
+        return account_voucher
+
+    '''
+        close invoice
+    '''
+    def close_invoice(self, invoiceid):
+        invoice = request.env['account.invoice'].search([('id', '=', invoiceid)])
+
+        if invoice.residual <= 0:
+            invoice.write({
+                'state': 'paid'
+            })
+        return invoice
+
+    '''
+        Create bank Statement
+    '''
+    def create_bank_statement(self, date_server, user_id, account_voucher):
+        # Get bank Statamente
+        bank_statement = request.env['account.bank.statement'].search([('journal_id', '=', account_voucher.journal_id.id), ('date', '=', date_server)])
+        # Create line bank
+        bank_statement_line = [[0, False, {
+            'name': account_voucher.reference,
+            'partner_id': account_voucher.partner_id.id,
+            'amount': account_voucher.amount,
+            'voucher_id': account_voucher.id,
+            'journal_id': account_voucher.journal_id.id,
+            'account_id': account_voucher.account_id.id,
+            'journal_entry_id': account_voucher.move_id.id,
+            'currency_id': account_voucher.currency_id.id,
+            'ref': 'NP'
+        }]]
+
+        bank = {
+            'journal_id': account_voucher.journal_id.id,
+            'period_id': account_voucher.period_id.id,
+            'date': date_server,
+            'user_id': user_id,
+            'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft',
+            'line_ids': bank_statement_line
+        }
+
+        if bank_statement:
+            if len(bank_statement) == 1:
+                 bank_statement.write(bank)
+            else:
+                bank_statement[len(bank_statement) -1].write(bank)
+        else:
+            bank_statement = bank_statement.create(bank)
+
+        return bank_statement
+
+    '''
+        Payment process
+    '''
+    @http.route('/eiru_payments/payment_process', type='json', auth='user', methods=['POST'], cors='*')
+    def payment_process(self, **kw):
+        self.make_info_log('Processing payments...')
+        # Get Date Server
+        date_server = datetime.now().strftime(DATE_FORMAT)
+        #Get Periodo
+        period = self.get_period(date_server)
+        self.make_info_log('[OK] Getting period')
+        # Get invoice
+        invoice = self.get_invoice(kw.get('invoiceId'))
+        self.make_info_log('[OK] Getting invoice')
+        # Get User - company
+        user_id = request.env.user.id
+        self.make_info_log('[OK] Getting user')
+        # Get Company
+        company_id = request.env.user.company_id.id
+        self.make_info_log('[OK] Getting Company')
+        # create voucher
+        voucher = self.create_voucher(period, invoice, company_id, kw.get('amountPayments', 0), date_server, kw.get('journalId'), kw.get('moveLines'), kw.get('customerId'))
+        self.make_info_log('[OK] creating voucher...')
+        # close invoice
+        close_invoice = self.close_invoice(kw.get('invoiceId'))
+        self.make_info_log('[OK] closing invoice...')
+        #  Create bank statement
+        bank_statement = self.create_bank_statement(date_server, user_id, voucher)
+        self.make_info_log('[OK] creating bank statement')
+
+        return {
+            'process': True
+        }

+ 2 - 2
models/account_voucher.py

@@ -55,8 +55,8 @@ class AccountVoucher(models.Model):
                 'line_cr_ids': line_cr_ids
             }
 
-        account_voucher = self.create(values)
-        account_voucher.action_move_line_create()
+        account_voucher.create(values)
+        # account_voucher.action_move_line_create()
 
         # Si no tiene deuda actualizar  la factura  a pagada
         if  invoice.residual <= 0:

+ 15 - 10
src/Payments.vue

@@ -1,22 +1,22 @@
 <template lang="pug">
 	.payments
-		form-wizard(title="" subtitle="" finishButtonText="Finalizar" color="#8c9bad" backButtonText="Volver" nextButtonText="Continuar" transition="fade" @on-complete="completePayment()" @on-change="(prev, next) => removeMovePaymentsAll(prev > next && prev >= 2)")
-			//- form-wizard(title="" subtitle="" finishButtonText="Finalizar" color="#8c9bad" backButtonText="Volver" nextButtonText="Continuar" transition="fade" @on-complete="completePayment()")
-			tab-content(title="Quien es el cliente?")
-				Customers
-			tab-content(title="Cual es la factura?")
+		form-wizard(title="" subtitle="" finishButtonText="Finalizar" color="#7c7bad" backButtonText="Volver" nextButtonText="Continuar" transition="fade" @on-complete="paymentProcess()" @on-change="(prev, next) => removeMovePaymentsAll(prev > next && next < 2)")
+			tab-content(title="Quien es el cliente?" :beforeChange="checkCustomer")
+				customers
+			tab-content(title="Cual es la factura?" :beforeChange="checkInvoice")
 				invoices
-			tab-content(title="Que cuota es?")
+			tab-content(title="Que cuota es?" :beforeChange="checkMove")
 				move-line
-			tab-content(title="Como quieres pagar?" )
+			tab-content(title="Como quieres pagar?" :beforeChange="checkPayments")
 				payments
 </template>
 
 <script>
 
 	import { mapActions } from 'vuex'
-	import { REMOVE_MOVE_PAYMENTS_ALL } from '@/constants/actionTypes'
-	import {FormWizard, TabContent } from 'vue-form-wizard'
+	import { REMOVE_MOVE_PAYMENTS_ALL, PAYMENTS_PROCESS, CHECK_CUSTOMER, CHECK_INVOICE, CHECK_MOVE, CHECK_PAYMENTS } from '@/constants/actionTypes'
+
+	import { FormWizard, TabContent } from 'vue-form-wizard'
 	import 'vue-form-wizard/dist/vue-form-wizard.min.css'
 
 	import Customers from '@@/steps/Partner'
@@ -36,7 +36,12 @@
 
 		methods: mapActions([
 			'initPayments',
-			REMOVE_MOVE_PAYMENTS_ALL
+			REMOVE_MOVE_PAYMENTS_ALL,
+			PAYMENTS_PROCESS,
+			CHECK_CUSTOMER,
+			CHECK_INVOICE,
+			CHECK_MOVE,
+			CHECK_PAYMENTS
 			// 'notify',
 			// 'completePayment',
 			// 'removeLineAll',

+ 11 - 10
src/components/froms/CustomerDetails.vue

@@ -24,10 +24,10 @@
                 hr
             .form-item-payments
                 label.form-label Débito
-                input.form-input(:value="getCurrencyFormat(customer.credit) || '0'" readonly)
+                input.form-input(:value="customer.credit | currency(currencyCompany.symbol, symbolPosition)" readonly)
             .form-item-payments
                 label.form-label Crédito
-                input.form-input(:value="getCurrencyFormat(customer.creditLimit) || '0'" readonly)
+                input.form-input(:value="customer.creditLimit | currency(currencyCompany.symbol)" readonly)
 </template>
 
 <script>
@@ -43,10 +43,11 @@
                     mobile: '',
                     email: '',
                     credit: 0,
-                    creditLimit: 0
+                    creditLimit: 0,
+                    symbolPosition: 'before'
                 }
             },
-            currency: {
+            currencyCompany: {
                 type: Object,
                 default: {
                     name: '',
@@ -58,12 +59,12 @@
                 }
             }
         },
-        methods: {
-            getCurrencyFormat(item) {
-                // return  item.toFixed(0).replace(".", ",").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1'+'.')
-                return this.currency.symbol+" "+item.toFixed(this.currency.decimalPlaces).replace(".", ",").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1'+this.currency.thousandsSeparator)
-            },
-        }
+        // methods: {
+        //     // getCurrencyFormat(item) {
+        //     //     // return  item.toFixed(0).replace(".", ",").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1'+'.')
+        //     //     // return this.currency.symbol+" "+item.toFixed(this.currency.decimalPlaces).replace(".", ",").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1'+this.currency.thousandsSeparator)
+        //     // },
+        // }
     }
 </script>
 

+ 13 - 2
src/components/invoices/InvoiceCard.vue

@@ -5,10 +5,10 @@
         .invoice-amount
             .invoice-total
                 h2.amount-label Total
-                h2.invoice-total-value {{ amountTotal }}
+                h2.invoice-total-value {{ amountTotal | currency(currencyCompany.symbol) }}
             .invoice-total
                 h2.amount-label  Saldo
-                h2.invoice-saldo-value {{ residual }}
+                h2.invoice-saldo-value {{ residual | currency(currencyCompany.symbol)}}
 </template>
 
 <script>
@@ -33,6 +33,17 @@
             isSelected: {
                 type: Boolean,
                 default: true
+            },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
             }
         },
         methods: {

+ 12 - 1
src/components/invoices/InvoicesGrid.vue

@@ -1,7 +1,7 @@
 <template lang="pug">
     .card-grid-wrapper
         card-grid
-            card(v-for='item in items' :key='item.id' :dateInvoice ='item.dateInvoice' :number='item.number' :amountTotal='item.amountTotal' :residual='item.residual' :isSelected='item.id === selectedId' @onClick='onClickCard(item)')
+            card(v-for='item in items' :key='item.id' :dateInvoice ='item.dateInvoice' :number='item.number' :amountTotal='item.amountTotal' :residual='item.residual' :isSelected='item.id === selectedId' @onClick='onClickCard(item)' :currencyCompany='currencyCompany')
 </template>
 
 <script>
@@ -14,6 +14,17 @@
                 type: Array,
                 default: []
             },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
+            }
         },
         components: {
             card

+ 13 - 2
src/components/moveLine/MoveLineCard.vue

@@ -4,10 +4,10 @@
         .move-amount
             .move-total
                 h2.move-amount-label Total
-                h2.move-total-value {{ debit }}
+                h2.move-total-value {{ debit | currency(currencyCompany.symbol)}}
             .move-total
                 h2.move-amount-label  Saldo
-                h2.move-saldo-value {{ amountResidual }}
+                h2.move-saldo-value {{ amountResidual | currency(currencyCompany.symbol)}}
 </template>
 
 <script>
@@ -28,6 +28,17 @@
             isSelected: {
                 type: Boolean,
                 default: true
+            },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '₲',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
             }
         },
         methods: {

+ 12 - 10
src/components/moveLine/MovePaymentsCard.vue

@@ -1,9 +1,8 @@
 <template lang="pug">
     li.move-lines-item
         h3.move-lines-item-maturity Venc. {{ item.dateMaturity }}
-        span.move-lines-item-subtotal {{ item.amountResidual }}
+        span.move-lines-item-subtotal {{ item.amountResidual | currency(currencyCompany.symbol)}}
         .move-lines-item-options-wrapper(class="fa fa-trash" @click='onClickDelete')
-        //- .move-lines-item-options-wrapper(class="fa fa-trash" @click="onClick" :class="{'fa-trash-disable': lineDisable()}")
 </template>
 
 <script>
@@ -11,14 +10,6 @@
 
     export default {
         props: {
-            // dateMaturity: {
-            //     type: String,
-            //     default: ''
-            // },
-            // amount: {
-            //     type: Number,
-            //     default: 0
-            // },
             isDelect: {
                 type: Boolean,
                 default: true
@@ -31,6 +22,17 @@
             item: {
                 type: Object,
                 default: null
+            },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '₲',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
             }
         },
         methods: {

+ 11 - 3
src/components/moveLine/MovesGrid.vue

@@ -14,14 +14,22 @@
                 type: Array,
                 default: []
             },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
+            }
         },
         components: {
             card
         },
         methods: {
-            // getDescription(item) {
-            //     return (!!this.description && item[this.description]) || ''
-            // },
             onClickCard(item) {
                 this.selectedId = item.id
                 this.$emit('onSelect', item)

+ 14 - 5
src/components/moveLine/SelectedMovesGrid.vue

@@ -1,12 +1,10 @@
 <template lang="pug">
     .move-Lines-wrapper
         .move-line-Card-items
-            card(v-for='(item, index) in items' :key='index' :index='index' :item='item'  @onClickDelete="onDeleteIntem")
+            card(v-for='(item, index) in items' :key='index' :index='index' :item='item'  @onClickDelete="onDeleteIntem" )
         .move-line-payments-total
             label.form-label-move-payments Total
-            input.form-input-move-payments(:value="total || 0 " readonly)
-            //- card(v-for='item in items' :key='item.id' :amount='item.amountResidual' :dateMaturity='item.dateMaturity' @onClickDelete="onDeleteIntem")
-                //-  :isSelected='item.id === selectedId' @onClick='onClickCard(item)')
+            input.form-input-move-payments(:value="total | currency" readonly)
 </template>
 
 <script>
@@ -22,7 +20,18 @@
             total: {
                 type: Number,
                 default: 0
-            }
+            },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '₲',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
+            },
         },
         components: {
             card

+ 15 - 4
src/components/payments/VoucherTicket.vue

@@ -17,16 +17,16 @@
                 .voucher-ticket-from-grid
                     .voucher-ticket-from-grid-item(v-for="line in items")
                         label.voucher-ticket-from-grid-item-left {{ line.dateMaturity }}
-                        label.voucher-ticket-from-grid-item-right {{ line.amountResidual }}
+                        label.voucher-ticket-from-grid-item-right {{ line.amountResidual | currency(currencyCompany.symbol) }}
                 .voucher-ticket-from-item-total
                     label.voucher-ticket-from-label-total Total
-                    label.voucher-ticket-from-input-total {{ totalPayments || 0 }}
+                    label.voucher-ticket-from-input-total {{ totalPayments | currency(currencyCompany.symbol) }}
                 .voucher-ticket-from-item-total
                     label.voucher-ticket-from-label-total Pagado
-                    label.voucher-ticket-from-input-total {{ paymentTotal || 0 }}
+                    label.voucher-ticket-from-input-total {{ paymentTotal | currency(currencyCompany.symbol) }}
                 .voucher-ticket-from-item-total
                     label.voucher-ticket-from-label-total Saldo
-                    label.voucher-ticket-from-input-total {{ paymentBalance || 0 }}
+                    label.voucher-ticket-from-input-total {{ paymentBalance | currency(currencyCompany.symbol) }}
 </template>
 
 <script>
@@ -55,6 +55,17 @@
             items: {
                 type: [],
                 default: []
+            },
+            currencyCompany: {
+                type: Object,
+                default: {
+                    name: '',
+                    symbol: '',
+                    rateSilent: 0,
+                    thousandsSeparator: '.',
+                    decimalSeparator: ',',
+                    decimalPlaces: 0
+                }
             }
         }
     }

+ 3 - 2
src/components/steps/Invoices.vue

@@ -2,7 +2,7 @@
     .payments-step
         .invoice-step
             searcher(:items='invoices' :keys="['number']")
-            grid(:items='invoices' @onSelect='selectInvoice')
+            grid(:items='invoices' @onSelect='selectInvoice' :currencyCompany='currencyCompany')
 </template>
 
 <script>
@@ -18,7 +18,8 @@
             Grid
         },
         computed: mapGetters([
-            'invoices'
+            'invoices',
+            'currencyCompany'
         ]),
         methods: mapActions([
             SELECT_INVOICE

+ 35 - 21
src/components/steps/MethodPayment.vue

@@ -1,7 +1,7 @@
 <template lang="pug">
     .payments-step
         //- .method-payment-step
-        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :paymentBalance='movesPaymentsBalance' :paymentTotal='paidTotal' :totalPayments='movesPaymentsTotal')
+        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :paymentBalance='paymentsResidual' :paymentTotal='paidTotal' :totalPayments='movesPaymentsTotal' :currencyCompany='currencyCompany')
         form.method-payment
             .method-form-separator
                 h3 Detalle de Cliente
@@ -18,20 +18,20 @@
                     option(v-for="journal in journals" :value="journal") {{ journal.displayName }}
             .method-form-item
                 label.method-form-label Total
-                input.method-form-input(readonly :value="movesPaymentsTotal")
+                input.method-form-input(readonly :value="movesPaymentsTotal | currency")
             .method-form-item
                 label.method-form-label  Monto a Pagar
                 input.method-form-input(v-model='paid' autofocus)
             .method-form-item
                 label.method-form-label Monto a Devolver
-                input.method-form-input(readonly :value="0")
+                input.method-form-input(readonly :value='paymentsReturned | currency')
 </template>
 
 <script>
-
     import { mapGetters, mapActions } from 'vuex'
     import Ticket from '@@/payments/VoucherTicket'
-    import { SELECT_JOURNAL }from '@/constants/actionTypes'
+    import { SELECT_JOURNAL, CHANGE_INITIAL_PAID }from '@/constants/actionTypes'
+
     export default {
         components: {
             Ticket,
@@ -47,34 +47,48 @@
             },
             paid: {
                 get() {
-
+                    let formatted = this.$options.filters.currency(this.paidTotal)
+                    return !!this.paidTotal ? formatted : formatted.replace(/\d/, '')
                 },
                 set(value) {
-                    let value2 = this.$options.filters.currency(value)
-                    let value3 = value2.replace(/[\.|,](\d{0,2}$)/, '?$1').split(/\?/)
-                    value3[0] = value3[0].replace(/[^0-9]/g, '')
-                    value3 = Number.parseFloat(value3.join('.')) || 0
+                    value = value.replace(/[\.|,](\d{0,2}$)/, '?$1').split(/\?/)
+                    value[0] = value[0].replace(/[^0-9]/g, '')
+                    value = Number.parseFloat(value.join('.')) || 0
 
-                }
+                    this.changeInitialPaid(value)
+                    this.computePayment(value)
+                },
             },
-
             ...mapGetters([
                 'selectedCustomer',
                 'selectedInvoice',
+                'selectedMoveLine',
+                'journals',
+                'selectedJournal',
+                'currencyCompany',
                 'movesPayments',
-                'movesPaymentsBalance',
                 'movesPaymentsTotal',
                 'paidTotal',
-                'selectedMoveLine',
-                'journals',
-                'selectedJournal'
+                'paymentsReturned',
+                'paymentsResidual',
+            ]),
+        },
+        methods: {
+            computePayment(value) {
+                this.paymentsReturned = value < this.movesPaymentsTotal ? 0 : value - this.movesPaymentsTotal
+                this.paymentsResidual = value > this.movesPaymentsTotal ? 0 : this.movesPaymentsTotal - value
+            },
+            ...mapActions([
+                SELECT_JOURNAL,
+                CHANGE_INITIAL_PAID
             ])
         },
-
-
-        methods: mapActions([
-            SELECT_JOURNAL
-        ])
+        data() {
+            return {
+                paymentsReturned: 0,
+                paymentsResidual: 0
+            }
+        }
     }
 </script>
 

+ 4 - 3
src/components/steps/MoveLine.vue

@@ -1,8 +1,8 @@
 <template lang="pug">
     .payments-step
         .move-step
-            grid(:items='moves' @onSelect='selectMove')
-            select-moves(:items='movesPayments' :total="movesPaymentsTotal" @onDeleteIntem='removeMovePayments')
+            grid(:items='moves' @onSelect='selectMove' :currencyCompany='currencyCompany')
+            select-moves(:items='movesPayments' :total="movesPaymentsTotal" @onDeleteIntem='removeMovePayments' )
 </template>
 <script>
     import Grid from '@@/moveLine/MovesGrid'
@@ -19,7 +19,8 @@
         computed: mapGetters([
             'moves',
             'movesPayments',
-            'movesPaymentsTotal'
+            'movesPaymentsTotal',
+            'currencyCompany',
         ]),
         methods: mapActions([
             SELECT_MOVE,

+ 1 - 1
src/components/steps/Partner.vue

@@ -6,7 +6,7 @@
                 searcher(:items='customers' :keys="['name']")
                 card-grid(:items='customers' :loading='loadingCustomers' @onSelect='selectPaymentsCustomer')
             transition(name="slide-fade")
-                customer-details(v-if='!!selectedCustomer' :customer='selectedCustomer' :currency='currencyCompany')
+                customer-details(v-if='!!selectedCustomer' :customer='selectedCustomer' :currencyCompany='currencyCompany')
 </template>
 
 <script>

+ 13 - 6
src/constants/actionTypes.js

@@ -1,6 +1,7 @@
 const PAYMENTS_NOTIFY = 'paymentsNotify'
 const INIT_PAYMENTS = 'initPayments'
 const EXPLODE_DATA = 'explodeData'
+const PAYMENTS_PROCESS = 'paymentProcess'
 /**
  * [DATE]
  */
@@ -25,25 +26,31 @@ const SELECT_MOVE_INVOICE = 'selectMoveInvoice'
 const SELECT_MOVE = 'selectMove'
 const REMOVE_MOVE_PAYMENTS = 'removeMovePayments'
 const REMOVE_MOVE_PAYMENTS_ALL = 'removeMovePaymentsAll'
-
 /**
  * [JOURNALS]
  */
 const INIT_PAYMENTS_JOURNALS = 'initPaymentsJournals'
 const SELECT_JOURNAL = 'selectJournal'
+const CHANGE_INITIAL_PAID ='changeInitialPaid'
 /**
  * [CURRENCIES]
  */
 const INIT_PAYMENTS_CURRENCIES = 'initPaymentsCurrencies'
-
-
+/*
+    Check
+ */
+ const CHECK_CUSTOMER = 'checkCustomer'
+ const CHECK_INVOICE = 'checkInvoice'
+ const CHECK_MOVE = 'checkMove'
+ const CHECK_PAYMENTS = 'checkPayments'
 export {
-    PAYMENTS_NOTIFY, INIT_PAYMENTS,EXPLODE_DATA, //initial
+    PAYMENTS_NOTIFY, INIT_PAYMENTS, EXPLODE_DATA, PAYMENTS_PROCESS, //initial
     INIT_PAYMENTS_DATE, //date
     INIT_PAYMENTS_USER, INIT_PAYMENTS_COMPANY, //user
     INIT_PAYMENTS_CUSTOMERS, SELECT_PAYMENTS_CUSTOMER, //customer
     SELECT_CUSTOMER_INVOICES, SELECT_INVOICE, ADD_MOVE_IN_INVOICE, //Customer -invoice
     SELECT_MOVE_INVOICE, SELECT_MOVE,REMOVE_MOVE_PAYMENTS, REMOVE_MOVE_PAYMENTS_ALL, //Customer -Move
-    INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL,//Journal
-    INIT_PAYMENTS_CURRENCIES //currency
+    INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL, CHANGE_INITIAL_PAID,//Journal
+    INIT_PAYMENTS_CURRENCIES, //currency
+    CHECK_CUSTOMER, CHECK_INVOICE, CHECK_MOVE, CHECK_PAYMENTS //Check
 }

+ 3 - 1
src/constants/mutationTypes.js

@@ -38,6 +38,8 @@ const SET_TOTAL_MOVE_PAYMENTS = 'setTotalMovePayments'
 const SET_JOURNALS = 'setJournals'
 const SET_LOADING_JOURNALS = 'setLoadingJournals'
 const SET_SELECTED_JOURNAL = 'setSelectedJournal'
+const SET_PAID_TOTAL = 'setPaidTotal'
+
 /**
  * [CURRENCIES]
  * @type {String}
@@ -51,6 +53,6 @@ export {
     SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SELECTED_CUSTOMER, //customer
     SET_INVOICES, SET_SELECTED_INVOICE, SET_SELECTED_CURRENCY_INVOICE, SET_MOVE_IN_INVOICE, //customer - invoice
     SET_MOVES, SET_SELECTED_MOVE_LINE, SET_SELECTED_MOVE_PAYMENTS, REMOVE_MOVE_LINE, REMOVE_PAYMENTS_MOVE, SET_TOTAL_MOVE_PAYMENTS,//customer -Move
-    SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL,//Journal
+    SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL, SET_PAID_TOTAL,//Journal
     SET_CURRENCIES, SET_LOADING_CURRENCIES //Currency
 }

+ 2 - 1
src/constants/resourcePaths.js

@@ -1,7 +1,8 @@
 const BASE_URL = '/eiru_payments'
 
 const INIT_PAYMENTS_URL = `${BASE_URL}/init`
+const PAYMENTS_PROCESS_URL = `${BASE_URL}/payment_process`
 
 export {
-    INIT_PAYMENTS_URL
+    INIT_PAYMENTS_URL, PAYMENTS_PROCESS_URL
 }

+ 66 - 3
src/store/actions.js

@@ -1,7 +1,24 @@
 import axios from 'axios'
-import { INIT_PAYMENTS_URL } from '@/constants/resourcePaths'
-import { PAYMENTS_NOTIFY, INIT_PAYMENTS, EXPLODE_DATA, INIT_PAYMENTS_DATE, INIT_PAYMENTS_USER, INIT_PAYMENTS_CUSTOMERS, INIT_PAYMENTS_JOURNALS, INIT_PAYMENTS_CURRENCIES } from '@/constants/actionTypes'
-// import { INIT_PAYMENTS, NOTIFY, INIT_DATE, INIT_USER, INIT_CUSTOMERS, INIT_JOURNALS, INIT_CURRENCIES, EXPLODE_DATA} from '@/constants/actionTypes'
+import {
+    INIT_PAYMENTS_URL,
+    PAYMENTS_PROCESS_URL
+} from '@/constants/resourcePaths'
+/*Action */
+import {
+    PAYMENTS_NOTIFY,
+    INIT_PAYMENTS,
+    EXPLODE_DATA,
+    INIT_PAYMENTS_DATE,
+    INIT_PAYMENTS_USER,
+    INIT_PAYMENTS_CUSTOMERS,
+    INIT_PAYMENTS_JOURNALS,
+    INIT_PAYMENTS_CURRENCIES,
+    PAYMENTS_PROCESS,
+    CHECK_CUSTOMER,
+    CHECK_INVOICE,
+    CHECK_MOVE,
+    CHECK_PAYMENTS
+} from '@/constants/actionTypes'
 
 const actions = {
     /**
@@ -33,7 +50,53 @@ const actions = {
             dispatch(`initPayments${value[0].toUpperCase()}${value.slice(1)}`,payload[value])
         }
     },
+    /**
+     * [PAYMENTS_PROCESS]
+     * @param {*} param0
+     * @param {*} payload
+     */
+    [PAYMENTS_PROCESS] ({ getters, commit, dispatch }, payload ) {
+        const data = {
+            jsonrpc: '2.0',
+            method: 'call',
+            params: {
+                invoiceId: getters.selectedInvoice.id,
+                journalId: getters.selectedJournal.id,
+                customerId: getters.selectedCustomer.id,
+                amountPayments: getters.paidTotal <= getters.movesPaymentsTotal ? getters.paidTotal : getters.movesPaymentsTotal,
+                moveLines: getters.movesPayments.map(item => {
+                    return item.id
+                })
+            }
+        }
 
+        return axios.post(PAYMENTS_PROCESS_URL, data).then(response => {
+            console.log(response);
+        }).catch(error => {
+            console.log(error);
+        })
+    },
+    /**
+     *
+     */
+    [CHECK_CUSTOMER] ({ getters, dispatch }) {
+        return !!getters.selectedCustomer ||dispatch(PAYMENTS_NOTIFY,'Necesitas seleccionar un cliente para continuar.')
+    },
+    [CHECK_INVOICE] ({ getters, dispatch }) {
+        return !!getters.selectedInvoice ||dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar una factura para continuar.')
+    },
+    [CHECK_MOVE] ({ getters, dispatch }) {
+        return !!getters.movesPayments.length || dispatch(PAYMENTS_NOTIFY,'Necesitas seleccionar al menos una cuota para continuar.')
+    },
+    [CHECK_PAYMENTS] ({ getters, dispatch }) {
+        if (!getters.selectedJournal) {
+             return dispatch(PAYMENTS_NOTIFY, 'Necesitas seleccionar un método de pago')
+        }
+        if (getters.paidTotal <= 0){
+            return dispatch(PAYMENTS_NOTIFY, 'Necesitas ingresar un monto a pagar')
+        }
+        return true
+    }
 }
 
 export default actions

+ 4 - 1
src/store/index.js

@@ -16,6 +16,8 @@ import journals from '@/store/modules/journals'
 /* currency */
 import currency  from '@/store/modules/currency'
 
+import payments  from '@/store/modules/payments'
+
 
 Vue.use(Vuex)
 
@@ -29,7 +31,8 @@ const store = new Vuex.Store({
         invoices,
         moveLines,
         journals,
-        currency
+        currency,
+        payments
     },
     strict: true
 })

+ 3 - 11
src/store/modules/moveLines.js

@@ -7,7 +7,7 @@ const initialState = {
     movesPayments: [],
     movesPaymentsTotal: 0,
     movesPaymentsBalance: 0,
-    paidTotal: 0
+
 }
 
 const state = {
@@ -16,7 +16,7 @@ const state = {
     movesPayments: initialState.movesPayments,
     movesPaymentsTotal: initialState.movesPaymentsTotal,
     movesPaymentsBalance: initialState.movesPaymentsBalance,
-    paidTotal: initialState.paidTotal
+
 }
 
 const getters = {
@@ -59,15 +59,6 @@ const getters = {
      */
     movesPaymentsBalance (state) {
         return state.movesPaymentsBalance
-    },
-    /**
-     * [paidTotal description]
-     * @method paidTotal
-     * @param  {[type]}     state [description]
-     * @return {[type]}     [description]
-     */
-    paidTotal (state) {
-        return state.paidTotal
     }
 }
 
@@ -194,6 +185,7 @@ const actions = {
      * @type {[type]}
      */
     [REMOVE_MOVE_PAYMENTS_ALL] ({commit, dispatch, state}, payload) {
+        console.log(payload);
         if (!payload) return
 
         if (state.movesPayments.length === 0 ) return

+ 67 - 0
src/store/modules/payments.js

@@ -0,0 +1,67 @@
+import { CHANGE_INITIAL_PAID } from '@/constants/actionTypes'
+import { SET_PAID_TOTAL } from '@/constants/mutationTypes'
+
+const initialState = {
+    paidTotal: 0,
+    paymentsReturned: 0,
+    paymentsResidual: 0
+
+}
+const state = {
+    paidTotal: initialState.paidTotal,
+    paymentsReturned: initialState.paymentsReturned,
+    paymentsResidual: initialState.paymentsResidual
+}
+const getters = {
+    /**
+     * [paidTotal description]
+     * @method paidTotal
+     * @param  {[type]}     state [description]
+     * @return {[type]}     [description]
+     */
+    paidTotal (state) {
+        return state.paidTotal
+    },
+    /**
+     * [paymentsReturned description]
+     * @method paymentsReturned
+     * @param  {[type]}         state [description]
+     * @return {[type]}               [description]
+     */
+    paymentsReturned (state) {
+        return state.paymentsReturned
+    },
+    /**
+     * [paymentsResidual description]
+     * @method paymentsResidual
+     * @param  {[type]}         state [description]
+     * @return {[type]}               [description]
+     */
+    paymentsResidual (state) {
+        return state.paymentsResidual
+    }
+}
+const mutations = {
+    /**
+     * [paidTotal description]
+     * @type {[type]}
+     */
+    [SET_PAID_TOTAL] (state, payload) {
+        state.paidTotal =payload
+    }
+}
+const actions = {
+    /**
+     *
+     */
+    [CHANGE_INITIAL_PAID] ({ commit },payload) {
+        commit(SET_PAID_TOTAL, payload)
+    }
+}
+
+export default {
+    state,
+    getters,
+    mutations,
+    actions
+}