payslip_payments_ipsc.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. (function() {
  2. openerp.widgetInstancePayslipPaymentsIPSC = null;
  3. openerp.parentInstancePayslipPaymentsIPSC = null;
  4. var Qweb = openerp.web.qweb;
  5. var instance = openerp;
  6. openerp.PayslipPaymentsIPSC = instance.Widget.extend({
  7. template: 'eiru_payslip_payments.IPSC',
  8. id: undefined,
  9. payslipIpsc: [],
  10. init: function(parent) {
  11. this._super(parent);
  12. this.buttons = parent.$buttons;
  13. },
  14. start: function() {
  15. var self = this;
  16. this.$el.click(function(){
  17. self.fectchInitial()
  18. });
  19. self.buttons.click(function(e) {
  20. /* E (Editar) */
  21. if (e.target.accessKey === 'E')
  22. self.$el.css('display','none');
  23. /* S (Guarrdar) */
  24. if (e.target.accessKey === 'S')
  25. self.$el.css('display','flex');
  26. /* D (Cancelar) */
  27. if (e.target.accessKey === 'D')
  28. self.$el.css('display','flex');
  29. });
  30. },
  31. updateId: function(id) {
  32. var self = this;
  33. self.id = id;
  34. },
  35. /* Remover */
  36. removeModal: function() {
  37. $('.expired-account-modal').remove();
  38. $('.modal-backdrop').remove();
  39. },
  40. /* Metodo Inicial */
  41. fectchInitial: function() {
  42. var self = this;
  43. self.fetchPayslipPaymentsIpsc(self.id).then(function(payslipIpsc) {
  44. return payslipIpsc;
  45. }).then(function(payslipIpsc) {
  46. self.payslipIpsc = payslipIpsc;
  47. return self.fetchAccountJournal();
  48. }).then(function(accountJournal) {
  49. self.accountJournal = accountJournal;
  50. if (!self.payslipIpsc.length){
  51. instance.web.notification.do_warn("Atención","No existe registro de I.P.S. Patronal a reconciliar.");
  52. return false;
  53. }
  54. return self.showPaymentsIpse()
  55. });
  56. },
  57. /* IPSC */
  58. fetchPayslipPaymentsIpsc: function(id) {
  59. var payslipRun = new openerp.web.Model('hr.payslip.run');
  60. return payslipRun.call('eiru_get_payslip_payments_ipsc',[id],{
  61. context: new openerp.web.CompoundContext()
  62. });
  63. },
  64. // Account Journal
  65. fetchAccountJournal: function(id) {
  66. var payslip = new openerp.web.Model('hr.payslip.run');
  67. return payslip.call('eiru_get_payslip_account_journal',{
  68. context: new openerp.web.CompoundContext()
  69. });
  70. },
  71. /* Get Account Journal Select */
  72. getAccountJournal: function(){
  73. var self = this;
  74. var journal = [];
  75. _.each(self.accountJournal, function(item) {
  76. journal.push({
  77. 'id': item.id,
  78. 'name': item.name,
  79. });
  80. });
  81. if (journal.length) {
  82. journal.unshift({
  83. 'id': '',
  84. 'name': ''
  85. });
  86. }
  87. return journal
  88. },
  89. /* Filter Journal select */
  90. filterAccountJournal: function(id){
  91. var self = this;
  92. return _.filter(self.accountJournal, function(item){
  93. return item.id === id;
  94. });
  95. },
  96. /* Modal */
  97. showPaymentsIpse: function(payslip, currency, journal) {
  98. var self = this;
  99. var defer = $.Deferred();
  100. var state = true;
  101. var payslispRun = self.payslipIpsc[0];
  102. var currency = payslispRun.currency;
  103. var accountJournal = self.getAccountJournal();
  104. var ipsPayments = []
  105. var header = [];
  106. if (payslispRun) {
  107. header.push({
  108. 'title': "Procesamiento "+ moment(payslispRun.date_start).format('DD/MM/YYYY')+" - "+moment(payslispRun.date_end).format('DD/MM/YYYY')
  109. })
  110. }
  111. var modal = Qweb.render('eiruPayslipPayments.IPSCModal',{
  112. 'header': header,
  113. 'journal': accountJournal,
  114. });
  115. $('.openerp_webclient_container').after(modal);
  116. $('.expired-account-modal').modal();
  117. // /* amount */
  118. var ipsTotal = $('.expired-account-modal').find('.amount-total');
  119. // /* journal && statement */
  120. var journalSelected = $('.expired-account-modal').find('.journal-selected');
  121. var statementSelected = $('.expired-account-modal').find('.statement-selected');
  122. var refPaymsntIps = $('.expired-account-modal').find('.ref-paymsnt-ips');
  123. /* button */
  124. var buttonAccept = $('.expired-account-modal').find('.button-accept');
  125. $('.expired-account-modal').find('.ref-payments-ips-select').text("Nóminas a reconciliar\t"+ payslispRun.slipLine.length);
  126. ipsTotal.val(openerp.web.formatCurrency(payslispRun.amount, currency))
  127. $('.expired-account-modal').find('.amount-symbol-payslip').text(currency[0].symbol);
  128. /* Journal Change */
  129. journalSelected.change(function(e){
  130. $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','none');
  131. statementSelected.empty();
  132. if (!!journalSelected.val()) {
  133. var statementjournal = self.filterAccountJournal(parseInt(journalSelected.val())).shift();
  134. var statementOpen = statementjournal.statementOpen;
  135. if (!!statementOpen.length){
  136. $('.expired-account-modal').find('.paymnet-payslip-statement-open').css('display','flex');
  137. statementSelected.append('<option value=""></option>');
  138. _.each(statementOpen, function(item) {
  139. statementSelected.append('<option value="' + item.id + '">' + item.name+" - "+moment(item.date).format("DD-MM-YYYY")+ '</option>');
  140. });
  141. }
  142. }
  143. });
  144. buttonAccept.click(function(e) {
  145. if (!journalSelected.val()) {
  146. instance.web.notification.do_warn("Atención","Tienes que seleccionar un método de pago para continuar.");
  147. journalSelected.css('border-color','red');
  148. journalSelected.focus();
  149. return false;
  150. }
  151. journalSelected.css('border-color','#ccc');
  152. var statementjournal = self.filterAccountJournal(parseInt(journalSelected.val())).shift();
  153. var statementOpen = statementjournal.statementOpen;
  154. if (!!statementOpen.length && !statementSelected.val()) {
  155. instance.web.notification.do_warn("Atención","Tienes que seleccionar una caja para continuar.");
  156. statementSelected.css('border-color','red');
  157. statementSelected.focus();
  158. return false;
  159. }
  160. statementSelected.css('border-color','#ccc');
  161. if (!refPaymsntIps.val().trim()) {
  162. instance.web.notification.do_warn("Atención","Debes ingresar una referencia de pago para continuar.");
  163. refPaymsntIps.css('border-color','red');
  164. refPaymsntIps.focus();
  165. return false;
  166. }
  167. refPaymsntIps.css('border-color','#ccc');
  168. var paymenstIps = {
  169. 'runId': self.id,
  170. 'journalId': parseInt(journalSelected.val()),
  171. 'statementId': parseInt(statementSelected.val()),
  172. 'refPayments': refPaymsntIps.val().trim(),
  173. 'amount': payslispRun.amount,
  174. 'partnerId': payslispRun.partnerId
  175. }
  176. /* Guardar */
  177. $('.expired-account-modal').find('.widget-content.widget-loading-payments-ips').css('display','flex');
  178. self.paymentsPayslipIpsc(paymenstIps).then(function(paymentsIps){
  179. return paymentsIps;
  180. }).then(function(paymentsIps) {
  181. if (!paymentsIps.state) {
  182. instance.web.notification.do_warn("Atención", paymentsIps.message, true);
  183. }
  184. $('.expired-account-modal').find('.widget-content.widget-loading-payments-ips').css('display','none');
  185. self.removeModal(e);
  186. defer.resolve(paymentsIps)
  187. });
  188. });
  189. /* Click Cerrar */
  190. $('.expired-account-modal').on('hidden.bs.modal', function (e) {
  191. defer.resolve(false);
  192. self.removeModal(e);
  193. });
  194. return defer;
  195. },
  196. /*Pagar nominas */
  197. paymentsPayslipIpsc: function(paymenstIps) {
  198. var payslipRun = new instance.web.Model('hr.payslip.run');
  199. return payslipRun.call('eiru_payslip_payments_ipsc', [paymenstIps],{
  200. context: new instance.web.CompoundContext()
  201. });
  202. },
  203. });
  204. if (instance.web && instance.web.FormView) {
  205. instance.web.FormView.include({
  206. load_record: function(record) {
  207. this._super.apply(this, arguments);
  208. if (this.model !== 'hr.payslip.run')
  209. return;
  210. openerp.parentInstancePayslipPaymentsIPSC = this;
  211. if (openerp.widgetInstancePayslipPaymentsIPSC) {
  212. openerp.widgetInstancePayslipPaymentsIPSC.updateId(record.id);
  213. if (this.$el.find('.payslip-payments-ipsc').length !== 0){
  214. return
  215. }
  216. }
  217. if (this.$el.find('.payslip-payments-ipsc').length !== 0 )
  218. return;
  219. openerp.widgetInstancePayslipPaymentsIPSC = new openerp.PayslipPaymentsIPSC(this);
  220. var elemento = this.$el.find('.oe_form').find('.eiru-payslip-payments');
  221. openerp.widgetInstancePayslipPaymentsIPSC.appendTo(elemento);
  222. openerp.widgetInstancePayslipPaymentsIPSC.updateId(record.id);
  223. },
  224. });
  225. }
  226. })();