|
@@ -0,0 +1,304 @@
|
|
|
|
+(function() {
|
|
|
|
+
|
|
|
|
+ openerp.widgetInstanceStatementCashBoxOutput = null;
|
|
|
|
+ openerp.parentInstanceStatementCashBoxOutput = {};
|
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
|
+
|
|
|
|
+ openerp.EiruStatementCashBoxOutput = openerp.Widget.extend({
|
|
|
|
+ template: 'EiruStatementUtility.CashBoxOutput',
|
|
|
|
+ id: undefined,
|
|
|
|
+ buttons: undefined,
|
|
|
|
+ bankStatement: [],
|
|
|
|
+ statementConfig: [],
|
|
|
|
+ resUser: [],
|
|
|
|
+ /* init */
|
|
|
|
+ init: function(parent) {
|
|
|
|
+ this._super(parent);
|
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
|
+ },
|
|
|
|
+ /* start */
|
|
|
|
+ start: function () {
|
|
|
|
+ var self = this
|
|
|
|
+ this.$el.click(function() {
|
|
|
|
+ self.fetchInitial();
|
|
|
|
+ });
|
|
|
|
+ self.buttons.click(function(e) {
|
|
|
|
+ /* C (Crear) */
|
|
|
|
+ if (e.target.accessKey === 'C')
|
|
|
|
+ self.$el.css('display','none');
|
|
|
|
+ /* E (Editar) */
|
|
|
|
+ if (e.target.accessKey === 'E')
|
|
|
|
+ self.$el.css('display','none');
|
|
|
|
+ /* S (Guarrdar) */
|
|
|
|
+ if (e.target.accessKey === 'S')
|
|
|
|
+ self.$el.css('display','flex');
|
|
|
|
+ /* D (Cancelar) */
|
|
|
|
+ if (e.target.accessKey === 'D')
|
|
|
|
+ self.$el.css('display','flex');
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* Actualizar Id de la visat actual */
|
|
|
|
+ updateId: function(id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.id = id;
|
|
|
|
+ },
|
|
|
|
+ /* Reload Page*/
|
|
|
|
+ reloadPage: function() {
|
|
|
|
+ openerp.parentInstanceStatementCashBoxOutput.reload();
|
|
|
|
+ },
|
|
|
|
+ /* Description: Función para remover el modal */
|
|
|
|
+ removeModal: function() {
|
|
|
|
+ $('.expired-account-modal').remove();
|
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
|
+ },
|
|
|
|
+ /*Get User*/
|
|
|
|
+ fetchGetUserLogin: function(){
|
|
|
|
+ var bankStatementUser = new instanceWeb.Model('account.bank.statement');
|
|
|
|
+ return bankStatementUser.call('eiru_transfers_get_user', {
|
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* statement Config */
|
|
|
|
+ fetchStatementConfigTransfer: function() {
|
|
|
|
+ var fields = ['id','name','output_cash_box_user_id','output_cash_box_statement_ids','output_negative_amount'];
|
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
|
+ var statementConfig = new openerp.web.Model('account.bank.statement.config');
|
|
|
|
+ return statementConfig.query(fields).filter(domain).all();
|
|
|
|
+ },
|
|
|
|
+ /* Método inicial */
|
|
|
|
+ fetchInitial: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.fetchBankStatement(self.id).then(function(bankStatement) {
|
|
|
|
+ return bankStatement;
|
|
|
|
+ }).then(function(bankStatement) {
|
|
|
|
+ self.bankStatement = bankStatement;
|
|
|
|
+ return self.fetchStatementConfigTransfer();
|
|
|
|
+ }).then(function(statementConfig) {
|
|
|
|
+ self.statementConfig = statementConfig;
|
|
|
|
+ return self.fetchGetUserLogin();
|
|
|
|
+ }).then(function(resUser) {
|
|
|
|
+ self.resUser = resUser;
|
|
|
|
+
|
|
|
|
+ if (!self.statementConfig.length) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "No fue posible localizar las configuración de las caja.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!self.resUser.length) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "No fue posible localizar el usuario.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!!self.bankStatement.length) {
|
|
|
|
+ var statementConfig = self.statementConfig[0];
|
|
|
|
+ var resUser = self.resUser[0];
|
|
|
|
+ var statementUser = self.bankStatement[0];
|
|
|
|
+ /* Verificar si el tipo caja tiene permiso para la transferencia */
|
|
|
|
+ if (!(_.contains(statementConfig.output_cash_box_statement_ids, statementUser.typeStatement))) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El tipo caja no tiene permiso para sacar dinero.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ /* Verificar si el usuario tiene permiso para la transferencia*/
|
|
|
|
+ if (!(_.contains(statementConfig.output_cash_box_user_id, resUser.id))) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El usuario no tiene permiso para sacar dinero .");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (statementUser.amount <= 0) {
|
|
|
|
+ if (!statementConfig) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La caja seleccionada no tiene saldo disponible.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!statementConfig.output_negative_amount) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "La caja seleccionada no tiene saldo disponible.");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return self.showModalCashBox();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* Account bank Statement */
|
|
|
|
+ fetchBankStatement: function(id) {
|
|
|
|
+ var bankStatement = new instanceWeb.Model('account.bank.statement');
|
|
|
|
+ return bankStatement.call('get_account_bank_statement_utility',[id], {
|
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ // /*Modal Transfer */
|
|
|
|
+ showModalCashBox: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer =$.Deferred();
|
|
|
|
+ var results = true;
|
|
|
|
+ var bankStatement = self.bankStatement[0];
|
|
|
|
+ var statement = [];
|
|
|
|
+ var currency ;
|
|
|
|
+ if (!!bankStatement) {
|
|
|
|
+ currency = bankStatement.currencystatement;
|
|
|
|
+ statement = [{
|
|
|
|
+ 'amount': accounting.formatNumber(bankStatement.amount, currency.decimalPlaces, currency.thousandsSeparator, currency.decimalSeparator),
|
|
|
|
+ 'symbol': bankStatement.currencystatement.symbol
|
|
|
|
+ }];
|
|
|
|
+ }
|
|
|
|
+ var header = [{
|
|
|
|
+ 'title': 'Sacar dinero de caja '
|
|
|
|
+ }];
|
|
|
|
+ var modal = QWeb.render('ModalStatementUtility.CashBox',{
|
|
|
|
+ 'header':header,
|
|
|
|
+ 'statement': statement
|
|
|
|
+ });
|
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
|
+
|
|
|
|
+ $('.expired-account-modal').find('.is_output').css('display','flex');
|
|
|
|
+ var refCashBox = $('.expired-account-modal').find('.ref-cash-box');
|
|
|
|
+ var amountCashBox = $('.expired-account-modal').find('.amount-cash-box');
|
|
|
|
+ var amountTotalCash = $('.expired-account-modal').find('.amount-total-cash');
|
|
|
|
+ /* button */
|
|
|
|
+ var buttonCashBox = $('.expired-account-modal').find('.button-cash-box');
|
|
|
|
+ refCashBox.keyup(function(e) {
|
|
|
|
+ if (e.keyCode === 13)
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ });
|
|
|
|
+ /*Monto del chque */
|
|
|
|
+ amountCashBox.keyup(function(e) {
|
|
|
|
+ var amount_add = Math.abs(accounting.unformat(amountCashBox.val(),currency.decimalSeparator));
|
|
|
|
+ amountCashBox.val(accounting.formatNumber(amount_add, 0, currency.thousandsSeparator, currency.decimalSeparator));
|
|
|
|
+ amountCashBox.css('border-color','#ccc');
|
|
|
|
+ if (e.keyCode === 13)
|
|
|
|
+ buttonCashBox.focus();
|
|
|
|
+ });
|
|
|
|
+ /*Monto del cheque */
|
|
|
|
+ amountCashBox.focusout(function(e) {
|
|
|
|
+ var amount_add = (accounting.unformat(amountCashBox.val(),currency.decimalSeparator));
|
|
|
|
+ var amountTotal = (accounting.unformat(amountTotalCash.val(),currency.decimalSeparator));
|
|
|
|
+
|
|
|
|
+ if (amount_add <= 0) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El monto no puede ser 0.");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!self.statementConfig.length) {
|
|
|
|
+ if (amount_add > amountTotal) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor que quieres retirar supera el saldo disponible en la caja");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!self.statementConfig[0].output_negative_amount) {
|
|
|
|
+ if (amount_add > amountTotal) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor que quieres retirar supera el saldo disponible en la caja");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ amountCashBox.css('border-color','#ccc');
|
|
|
|
+ amountCashBox.val(accounting.formatNumber(amount_add, currency.decimalPlaces, currency.thousandsSeparator, currency.decimalSeparator));
|
|
|
|
+ });
|
|
|
|
+ /*Click buttonSave*/
|
|
|
|
+ buttonCashBox.click(function(e) {
|
|
|
|
+ var amount = (accounting.unformat(amountCashBox.val(),currency.decimalSeparator));
|
|
|
|
+ var amountTotal = (accounting.unformat(amountTotalCash.val(),currency.decimalSeparator));
|
|
|
|
+
|
|
|
|
+ /* Ref transfer */
|
|
|
|
+ if (!refCashBox.val()) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Debes de ingresar un motivo.");
|
|
|
|
+ refCashBox.css('border-color','red');
|
|
|
|
+ refCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ refCashBox.css('border-color','#ccc');
|
|
|
|
+
|
|
|
|
+ /* ammount transfer*/
|
|
|
|
+ if (amount <= 0) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor debe ser mayor a cero.");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if (!self.statementConfig.length) {
|
|
|
|
+ if (amount > amountTotal) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor que quieres retirar supera el saldo disponible en la caja");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!self.statementConfig[0].output_negative_amount) {
|
|
|
|
+ if (amount > amountTotal) {
|
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "El valor que quieres retirar supera el saldo disponible en la caja");
|
|
|
|
+ amountCashBox.css('border-color','red');
|
|
|
|
+ amountCashBox.focus();
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ amountCashBox.css('border-color','#ccc');
|
|
|
|
+
|
|
|
|
+ var input = {
|
|
|
|
+ 'statementId': self.id,
|
|
|
|
+ 'ref': !!refCashBox.val() ? refCashBox.val() :'',
|
|
|
|
+ 'amount': amount,
|
|
|
|
+ 'type': 'output'
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Save Payments */
|
|
|
|
+ self.StatementCreateCashBox(input).then(function(resultsInput) {
|
|
|
|
+ return resultsInput;
|
|
|
|
+ }).then(function(resultsInput) {
|
|
|
|
+ self.reloadPage();
|
|
|
|
+ self.removeModal(e);
|
|
|
|
+ if (!resultsInput)
|
|
|
|
+ results = false;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ /* Click Cerrar */
|
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function(e) {
|
|
|
|
+ results = false;
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ self.removeModal(e);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ /*Create CashBox Input */
|
|
|
|
+ StatementCreateCashBox: function(values) {
|
|
|
|
+ var bankStatement = new instanceWeb.Model('account.bank.statement');
|
|
|
|
+ return bankStatement.call('create_cash_box_input_output',[values], {
|
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (openerp.web && openerp.web.FormView) {
|
|
|
|
+ openerp.web.FormView.include({
|
|
|
|
+ load_record: function(record) {
|
|
|
|
+ this._super.apply(this, arguments);
|
|
|
|
+
|
|
|
|
+ if (this.model !== 'account.bank.statement')
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ openerp.parentInstanceStatementCashBoxOutput = this;
|
|
|
|
+
|
|
|
|
+ if (openerp.widgetInstanceStatementCashBoxOutput) {
|
|
|
|
+ openerp.widgetInstanceStatementCashBoxOutput.updateId(record.id);
|
|
|
|
+ if (this.$el.find('.button-statement-casbox-output').length !== 0 )
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.$el.find('.button-statement-casbox-output').length !== 0 )
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ openerp.widgetInstanceStatementCashBoxOutput = new openerp.EiruStatementCashBoxOutput(this);
|
|
|
|
+ var element =this.$el.find('.oe_form').find('.eiru-statement-utility');
|
|
|
|
+
|
|
|
|
+ openerp.widgetInstanceStatementCashBoxOutput.appendTo(element[0]);
|
|
|
|
+ openerp.widgetInstanceStatementCashBoxOutput.updateId(record.id);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+})();
|