|
@@ -0,0 +1,376 @@
|
|
|
+(function() {
|
|
|
+
|
|
|
+ openerp.widgetInstanceStatementCashBoxDeleted = null;
|
|
|
+ openerp.parentInstanceStatementCashBoxDeleted = {};
|
|
|
+ var QWeb = openerp.web.qweb;
|
|
|
+ var instanceWeb = openerp.web;
|
|
|
+
|
|
|
+ openerp.EiruStatementCashBoxDeleted = openerp.Widget.extend({
|
|
|
+ template: 'EiruStatementUtility.CasBoxDeleted',
|
|
|
+ id: undefined,
|
|
|
+ buttons: undefined,
|
|
|
+ bankStatement: [],
|
|
|
+ cashBoxInput: [],
|
|
|
+ cashBoxOutput: [],
|
|
|
+ statementConfig: [],
|
|
|
+ resUser: [],
|
|
|
+ /* init */
|
|
|
+ init: function(parent) {
|
|
|
+ this._super(parent);
|
|
|
+ this.buttons = parent.$buttons;
|
|
|
+ },
|
|
|
+ /* start */
|
|
|
+ start: function () {
|
|
|
+ var self = this
|
|
|
+ this.$el.click(function() {
|
|
|
+ // self.showModal()
|
|
|
+ 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.parentInstanceStatementCashBoxDeleted.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', 'delete_input_user_ids', 'delete_output_user_ids'];
|
|
|
+ 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.fetchCashBoxInput(self.id);
|
|
|
+ }).then(function(cashBoxInput) {
|
|
|
+ self.cashBoxInput = cashBoxInput;
|
|
|
+ return self.fetchCashBoxOutput(self.id);
|
|
|
+ }).then(function(cashBoxOutput) {
|
|
|
+ self.cashBoxOutput = cashBoxOutput;
|
|
|
+ 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 estas autorizado a realizar esta operación, no existe configuración de caja.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!self.resUser.length) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!self.bankStatement.length) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "No estas autorizado a realizar esta operación.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return self.showModal();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* 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()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* cash_box_Input*/
|
|
|
+ fetchCashBoxInput: function(id) {
|
|
|
+ var cashBoxInput = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return cashBoxInput.call('eiru_get_cash_box_in',[id], {
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* cash_box_output*/
|
|
|
+ fetchCashBoxOutput: function(id) {
|
|
|
+ var cashBoxOutput = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return cashBoxOutput.call('eiru_get_cash_box_out',[id], {
|
|
|
+ context: new instanceWeb.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /*filter line transfer selected*/
|
|
|
+ filterRowSelected: function(id, type){
|
|
|
+ var self = this;
|
|
|
+ if (type === 'input') {
|
|
|
+ return _.filter(self.cashBoxInput, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (type === 'output') {
|
|
|
+ return _.filter(self.cashBoxOutput, function(item){
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /*Modal Transfer */
|
|
|
+ showModal: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer =$.Deferred();
|
|
|
+ var results = true;
|
|
|
+ var rowSelected = [];
|
|
|
+ var statementBank = self.bankStatement[0]
|
|
|
+ var modal = QWeb.render('ModalStatementUtility.CasBoxDeleted',{
|
|
|
+ 'boxInput': self.cashBoxInput,
|
|
|
+ 'boxOutput': self.cashBoxOutput
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
+ $('.expired-account-modal').modal();
|
|
|
+
|
|
|
+ /*Table*/
|
|
|
+ var tableInput = $('.expired-account-modal').find('.tbody-input').find('tr');
|
|
|
+ var tableOutput = $('.expired-account-modal').find('.tbody-output').find('tr');
|
|
|
+ /* selectr type cash*/
|
|
|
+ var cashInput = $('.expired-account-modal').find('.cash-input');
|
|
|
+ $('.expired-account-modal').find('.messege-is-cash-input').text("Tienes "+self.cashBoxInput.length+" registro de entrada de dinero");
|
|
|
+ if (!self.cashBoxInput.length) {
|
|
|
+ cashInput.attr("disabled", true);
|
|
|
+ $('.expired-account-modal').find('.messege-is-cash-input').text("No existe registros.");
|
|
|
+ }
|
|
|
+ var cashOutput = $('.expired-account-modal').find('.cash-output');
|
|
|
+ $('.expired-account-modal').find('.messege-is-cash-output').text("Tienes "+self.cashBoxOutput.length+" registro de extracción de dinero");
|
|
|
+ if (!self.cashBoxOutput.length) {
|
|
|
+ cashOutput.attr("disabled", true);
|
|
|
+ $('.expired-account-modal').find('.messege-is-cash-output').text("No existe registros.");
|
|
|
+ }
|
|
|
+
|
|
|
+ var cashInputSelected = null;
|
|
|
+ var cashOutputSelected = null;
|
|
|
+ /* */
|
|
|
+ var casboxRef = $('.expired-account-modal').find('.casbox-ref');
|
|
|
+ var casboxAmount = $('.expired-account-modal').find('.casbox-amount');
|
|
|
+ var casboxAmountSymbol = $('.expired-account-modal').find('.casbox-amount-symbol');
|
|
|
+ casboxAmountSymbol.text(statementBank.currencystatement.symbol);
|
|
|
+ var casboxRefDeleted = $('.expired-account-modal').find('.casbox-ref-deleted');
|
|
|
+ /* Button*/
|
|
|
+ var buttonDeleted = $('.expired-account-modal').find('.button-deleted');
|
|
|
+ buttonDeleted.attr("disabled", true);
|
|
|
+
|
|
|
+ /* Entrada */
|
|
|
+ cashInput.click(function(e) {
|
|
|
+ $('.expired-account-modal').find('.is-cash-input').css('background','#ffffff');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-input').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.is-cash-output').css('background','#ffffff');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-output').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.is-selectd-cashbox').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.warning-message').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.message-error').text("");
|
|
|
+ cashInputSelected = e.target;
|
|
|
+ casboxRef.val('');
|
|
|
+ casboxAmount.val('0');
|
|
|
+ casboxRefDeleted.val('');
|
|
|
+ buttonDeleted.attr("disabled", true);
|
|
|
+ rowSelected = [];
|
|
|
+ tableInput.removeClass('table-row-select');
|
|
|
+ tableOutput.removeClass('table-row-select');
|
|
|
+
|
|
|
+ if (this.checked) {
|
|
|
+ if (!(_.contains(self.statementConfig[0].delete_input_user_ids, self.resUser[0].id))){
|
|
|
+ $('.expired-account-modal').find('.warning-message').css('display','flex');
|
|
|
+ $('.expired-account-modal').find('.message-error').text("No tienes autorización para eliminar las entradas de dinero..");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $('.expired-account-modal').find('.is-cash-input').css('background','#d4e2f3');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-input').css('display','flex');
|
|
|
+ $('.expired-account-modal').find('.is-selectd-cashbox').css('display','flex');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /* Salida */
|
|
|
+ cashOutput.click(function(e){
|
|
|
+ cashOutputSelected = e.target;
|
|
|
+ $('.expired-account-modal').find('.is-cash-output').css('background','#ffffff');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-output').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.is-cash-input').css('background','#ffffff');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-input').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.is-selectd-cashbox').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.warning-message').css('display','none');
|
|
|
+ $('.expired-account-modal').find('.message-error').text("");
|
|
|
+ casboxRef.val('');
|
|
|
+ casboxAmount.val('0');
|
|
|
+ casboxRefDeleted.val('');
|
|
|
+ buttonDeleted.attr("disabled", true);
|
|
|
+ rowSelected = [];
|
|
|
+ tableInput.removeClass('table-row-select');
|
|
|
+ tableOutput.removeClass('table-row-select');
|
|
|
+
|
|
|
+ if (this.checked) {
|
|
|
+ if (!(_.contains(self.statementConfig[0].delete_output_user_ids, self.resUser[0].id))){
|
|
|
+ $('.expired-account-modal').find('.warning-message').css('display','flex');
|
|
|
+ $('.expired-account-modal').find('.message-error').text("No tienes autorización para eliminar las salidas de dinero.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $('.expired-account-modal').find('.is-cash-output').css('background','#d4e2f3');
|
|
|
+ $('.expired-account-modal').find('.boby-cash-output').css('display','flex');
|
|
|
+ $('.expired-account-modal').find('.is-selectd-cashbox').css('display','flex');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /* table input */
|
|
|
+ tableInput.click(function(e){
|
|
|
+ /* clear */
|
|
|
+ casboxRef.val('');
|
|
|
+ casboxAmount.val('0');
|
|
|
+ casboxRefDeleted.val('');
|
|
|
+ buttonDeleted.attr("disabled", true);
|
|
|
+
|
|
|
+ tableInput.removeClass('table-row-select');
|
|
|
+ tableOutput.removeClass('table-row-select');
|
|
|
+ $(e.target).closest('tr').addClass('table-row-select');
|
|
|
+
|
|
|
+ var idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ rowSelected = self.filterRowSelected(idRow, 'input').shift();
|
|
|
+
|
|
|
+ if (!!rowSelected) {
|
|
|
+ casboxRef.val(rowSelected.ref);
|
|
|
+ casboxAmount.val(accounting.formatNumber(rowSelected.amount, rowSelected.statement.currency.decimalPlaces, rowSelected.statement.currency.thousandsSeparator,rowSelected.statement.currency.decimalSeparator));
|
|
|
+ buttonDeleted.removeAttr("disabled");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /* table output*/
|
|
|
+ tableOutput.click(function(e){
|
|
|
+ /* clear */
|
|
|
+ casboxRef.val('');
|
|
|
+ casboxAmount.val('0');
|
|
|
+ casboxRefDeleted.val('');
|
|
|
+ buttonDeleted.attr("disabled", true);
|
|
|
+
|
|
|
+ tableInput.removeClass('table-row-select');
|
|
|
+ tableOutput.removeClass('table-row-select');
|
|
|
+ $(e.target).closest('tr').addClass('table-row-select');
|
|
|
+
|
|
|
+ var idRow = parseInt(($(e.target).closest('tr').children()[0].textContent).trim());
|
|
|
+ rowSelected = self.filterRowSelected(idRow, 'output').shift();
|
|
|
+
|
|
|
+ if (!!rowSelected) {
|
|
|
+ casboxRef.val(rowSelected.ref);
|
|
|
+ casboxAmount.val(accounting.formatNumber(rowSelected.amount, rowSelected.statement.currency.decimalPlaces, rowSelected.statement.currency.thousandsSeparator,rowSelected.statement.currency.decimalSeparator));
|
|
|
+ buttonDeleted.removeAttr("disabled");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ casboxRefDeleted.keyup(function(e){
|
|
|
+ if (e.keyCode === 13) {
|
|
|
+ buttonDeleted.focus();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ casboxRefDeleted.focusout(function(e){
|
|
|
+ if (!casboxRefDeleted.val()) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Debes de ingresar un motivo para continuar.");
|
|
|
+ casboxRefDeleted.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /* button click */
|
|
|
+ buttonDeleted.click(function(e) {
|
|
|
+ if (!rowSelected){
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Debes de seleccionar un ítem para continuar");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!casboxRefDeleted.val()) {
|
|
|
+ instanceWeb.notification.do_warn("Atencion", "Debes de ingresar un motivo para continuar.");
|
|
|
+ buttonDeleted.css('border-color','red');
|
|
|
+ buttonDeleted.focus();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ buttonDeleted.css('border-color','#ccc');
|
|
|
+
|
|
|
+ var cashbox = {
|
|
|
+ 'cashboxID': rowSelected.id,
|
|
|
+ 'statementId': self.id,
|
|
|
+ 'type': rowSelected.type,
|
|
|
+ 'message': casboxRefDeleted.val()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.unlinkCashBox(cashbox).then(function(cashboxUnlink){
|
|
|
+ return cashboxUnlink;
|
|
|
+ }).then(function(cashboxUnlink){
|
|
|
+ self.reloadPage();
|
|
|
+ self.removeModal(e);
|
|
|
+ if (!cashboxUnlink)
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+ /* Unlink Cash Box */
|
|
|
+ unlinkCashBox: function(values){
|
|
|
+ var bankStatementTransfer = new instanceWeb.Model('account.bank.statement');
|
|
|
+ return bankStatementTransfer.call('unlink_cashbox_in_out',[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.parentInstanceStatementCashBoxDeleted = this;
|
|
|
+
|
|
|
+ if (openerp.widgetInstanceStatementCashBoxDeleted) {
|
|
|
+ openerp.widgetInstanceStatementCashBoxDeleted.updateId(record.id);
|
|
|
+ if (this.$el.find('.button-statement-cashbox-deleted').length !== 0 )
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$el.find('.button-statement-cashbox-deleted').length !== 0 )
|
|
|
+ return;
|
|
|
+
|
|
|
+ openerp.widgetInstanceStatementCashBoxDeleted = new openerp.EiruStatementCashBoxDeleted(this);
|
|
|
+ var element =this.$el.find('.oe_form').find('.eiru-statement-utility');
|
|
|
+
|
|
|
+ openerp.widgetInstanceStatementCashBoxDeleted.appendTo(element[0]);
|
|
|
+ openerp.widgetInstanceStatementCashBoxDeleted.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+})();
|