Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //----------------------------------------------------------------------------------------------------
  2. // REGISTRO DE LA PROPIEDAD DE PR
  3. // POR: INVID LLC
  4. // PROPOSITO:
  5. // Maneja la vista madre para todas las vistas de Minuta.
  6. //----------------------------------------------------------------------------------------------------
  7. var MinutaView = BaseView.extend({
  8.     reloadClass: MinutaView,
  9.     events: {
  10.         "click .btn-save-minuta": function () {
  11.             if (app.views.mainView.currentMinuta.Minuta.EstatusId == 3 && !app.views.mainView.currentMinuta.Minuta.DocumentoLey216) {
  12.                 this.checkCartaCredito()
  13.             } else {
  14.                 this.save()
  15.             }
  16.         },
  17.         "click .btn-close": "close",
  18.         "click .historial-asiento": "showHistorico",
  19.         "click .manejo-notificaciones": "showManejoNotificaciones",
  20.         "click .notificacion-caducar": "caducarDocumento",
  21.  
  22.         "click .notificacion-suspender": "suspenderNotificacion",
  23.         "click .notificacion-suspender-recalificacion": "suspenderNotificacionRecalificar",
  24.         "click .notificacion-suspender-noprocede": "suspenderNotificacionNoProcede",
  25.  
  26.         "click .btn-print": "printReceipt",
  27.         "click .btn-new": "new",
  28.         "click .btn-new-reuse-presentante": "newReuse",
  29.         "click .btn-leave": "leave",
  30.         "click .btn-retirar": "retirarConfirm",
  31.         "click .btn-negar-retiro": "negarConfirm",
  32.         "click .devolver-minuta": "beforeDevolver",
  33.         "click .btn-devolver": "devolverDocumento",
  34.         "click .btn-denegar": "denegarTemp",
  35.  
  36.         "click .despachar-minuta": "verificarEstatus"
  37.     },
  38.  
  39.     bindings: {
  40.         ".asiento-diario": "value:AsientoDiario",
  41.         ".asiento-segmento": "value:AsientoSegmento",
  42.         ".asiento-section": "value:AsientoSection",
  43.         ".motivo-denegar": "value:MotivoDenegar",
  44.         ".motivo-devolver": "value:MotivoDevolver",
  45.     },
  46.  
  47.     initialize: function () {
  48.         MinutaView.__super__.initialize.apply(this, arguments)
  49.        
  50.     },
  51.  
  52.     generateCartaCredito: false,
  53.  
  54.     init: function () {
  55.         var template = Handlebars.compile($("#minuta").html())
  56.  
  57.         this.views = {}
  58.  
  59.         $(this.el)
  60.         .html(template(this.model.toJSON()))
  61.         .addClass("minuta-block active")
  62.  
  63.         this.workingEl = ".btn-save-minuta"
  64.  
  65.         this.applyBindings()
  66.  
  67.         this.delegateEvents()
  68.  
  69.         $(this.el).find(".asiento-diario").inputmask("mask", { "mask": "999[9]" })
  70.  
  71.         this.$el.find("#nav-container").onePageNav({
  72.             currentClass: 'current',
  73.             changeHash: false,
  74.             scrollSpeed: 750,
  75.             scrollThreshold: 0.5,
  76.             topOffset: 0,
  77.             $elToScroll: this.$el.find("section#content"),
  78.             filter: '',
  79.             easing: 'swing'
  80.         });
  81.  
  82.         _.bindAll(this, "render", "beforeRetirar", "beforeNegar", "retirar", "negar",
  83.                 "beforeDevolver", "devolverDocumento", "checkCartaCredito");
  84.         _.bindAll(this, "render", "beforeNegar");
  85.  
  86.         this.startingScrollspy(100);
  87.     },
  88.  
  89.     moveMainPanel: function (ev) {
  90.         var el = $(ev.currentTarget).find("a").attr("href")
  91.  
  92.         this.$el.find("section#content").animate({ "top": "100px" }, 300)
  93.     },
  94.  
  95.     retirarConfirm: function () {
  96.         this.confirm = new ConfirmView()
  97.         this.confirm.hideOnCancel = false
  98.         this.confirm.show("¿Desea retirar el documento?", this.beforeRetirar)
  99.     },
  100.  
  101.     verificarEstatus: function () {
  102.         var currEstatus = this.model.get("EstatusId")
  103.         if (currEstatus == 7 || currEstatus == 8 || currEstatus == 2 || currEstatus == 3)
  104.         {
  105.             var url = "despacho.html?minutaId=" + this.model.get("Id") + "&aid=" + this.model.get("AsientoId") + "";
  106.             window.open(url, '_blank');
  107.         } else {
  108.            
  109.             msg = "Debe suspender el documento, para poder despacharlo"
  110.             var aviso = new MessageView()
  111.             aviso.setSize("modal-sm")
  112.             aviso.show(msg, "Aviso", null)
  113.         }        
  114.     },
  115.  
  116.     denegarTemp: function () {
  117.  
  118.     },
  119.  
  120.     negar: function () {
  121.         var self = this
  122.  
  123.         if (this.isWorking)
  124.             return
  125.  
  126.         this.workingEl = ".btn-denegar"
  127.         this.startWorking()
  128.  
  129.         var model = new GlobalEmptyModel()
  130.  
  131.         model.set("AsientoId", this.model.get("AsientoId"))
  132.         model.set("MotivoDenegar", this.model.get("MotivoDenegar"))
  133.  
  134.         model.customUrl = ("/api/retiroDocumento/denegar/asiento/" + this.model.get("AsientoId"))
  135.         model.save({ Motivo: model.get("MotivoDenegar") }, {
  136.             success: function (err, response) {
  137.                 self.stopWorking()
  138.                 $(".modal-backdrop").remove()
  139.                 if (response) {
  140.                     (new MessageView().show("Se ha denegado la solicitud de retiro.", null, function () {
  141.                         self.leaveToQueue()
  142.                     }))
  143.                 }
  144.             },
  145.             error: this.xhrError,
  146.             beforeSend: this.beforeSend
  147.         })
  148.  
  149.     },
  150.  
  151.     beforeDevolver: function () {
  152.         var self = this
  153.         this.confirm = new ConfirmView()
  154.         this.confirm.hideOnCancel = false
  155.         this.confirm.show("¿Desea devolver el documento al técnico?", function () {
  156.             self.$el.find(".modal.fade.devolver-modal").modal({ backdrop: 'static', keyboard: false });
  157.         })
  158.     },
  159.  
  160.  
  161.     beforeNegar: function () {
  162.         var self = this
  163.         var dardeo = new DarDeoView()
  164.         dardeo.parent = self
  165.         dardeo.show(this.negar)
  166.     },
  167.  
  168.     negarConfirm: function () {
  169.         var self = this
  170.         this.confirm = new ConfirmView()
  171.         this.confirm.hideOnCancel = false
  172.         this.confirm.show("¿Desea denegar la solicitud de retiro?", function () {
  173.             self.beforeNegar()
  174.         })
  175.     },
  176.  
  177.     beforeRetirar: function () {
  178.         var self = this
  179.         var dardeo = new DarDeoView()
  180.         dardeo.parent = self
  181.         dardeo.show(this.retirar)
  182.     },
  183.  
  184.     devolverDocumento: function () {
  185.         var self = this
  186.  
  187.         if (this.isWorking)
  188.             return
  189.  
  190.         self.workingEl = ".btn-devolver"
  191.  
  192.         self.startWorking()
  193.  
  194.         var model = new GlobalEmptyModel()
  195.  
  196.         model.set("AsientoId", self.model.get("AsientoId"))
  197.         model.set("MotivoDevolver", self.model.get("MotivoDevolver"))
  198.         model.set("TecnicoEmail", self.model.get("CreadoEmail"))
  199.         model.set("Asiento", self.model.get("Asiento"))
  200.  
  201.         var data = {
  202.             AsientoId: model.get("AsientoId"),
  203.             Motivo: model.get("MotivoDevolver"),
  204.             TecnicoEmail: model.get("TecnicoEmail"),
  205.             Asiento: model.get("Asiento")
  206.         }
  207.  
  208.         model.customUrl = ("/api/minuta/asiento/" + data.AsientoId + "/devolver")
  209.         model.save(data, {
  210.             success: function (err, response) {
  211.                 if (response) {
  212.                     self.stopWorking()
  213.                     $(".modal-backdrop").remove()
  214.                     new MessageView().show("Se ha devuelto el documento exitosamente.", null, function () {
  215.                         setTimeout(function () {
  216.                             window.location.assign("#")
  217.                         }, 50)
  218.                     })
  219.                 }
  220.             },
  221.             error: self.xhrError,
  222.             beforeSend: self.beforeSend
  223.         })
  224.     },
  225.     retirar: function () {
  226.         var self = this
  227.  
  228.         if (this.isWorking)
  229.             return
  230.         this.workingEl = ".ok"
  231.  
  232.         var model = new GlobalEmptyModel()
  233.  
  234.         this.model.set("Id", this.model.get("AsientoId"))
  235.  
  236.         model.customUrl = ("/api/retiroDocumento/asiento/" + this.model.get("AsientoId"))
  237.         model.save({}, {
  238.             success: function (err, response) {
  239.                 var confirm = new ConfirmView()
  240.                 confirm.show("El documento ha sido retirado")
  241.                 $(self.$el).find(".btn-retirar").addClass("hidden")
  242.                 $(self.$el).find(".btn-negar-retiro").addClass("hidden")
  243.                 self.leaveToQueue()
  244.             },
  245.             error: this.xhrError,
  246.             beforeSend: this.beforeSend
  247.         })
  248.     },
  249.     loadViewsByRoles: function () {
  250.         var $container = $(this.el).find(".left-col .main-accordion"),
  251.             $rightContainer = $(this.el).find(".right-col .right-accordion"),
  252.             minuta = app.views.mainView.currentMinuta.Minuta
  253.  
  254.         if (!minuta.PuedoVer) {
  255.             window.location.assign('#')
  256.             return
  257.         }
  258.  
  259.         this.views.documentTypeManagementView = new DocumentTypeManagementView()
  260.         this.views.documentTypeManagementView.parent = this
  261.         this.views.fincaListView = new FincaListView()
  262.         this.views.titularListView = new TitularListView()
  263.         this.views.transaccionListView = new TransaccionListView()
  264.         // this.views.planoListView = new PlanoListView()
  265.         // this.views.planoListView.parent = this
  266.         this.views.documentosComplementariosListView = new DocumentosComplementariosListView()
  267.         this.views.minutaArancelListView = new MinutaArancelListView({
  268.             attributes: { hideDefaultArancel: (!minuta.DocumentoLey216) ? false : true }, forMinuta: true,
  269.             for216: minuta.DocumentoLey216
  270.         })
  271.         this.views.carritoManagementView = new CarritoManagementView()
  272.         this.views.carritoManagementView.parent = this
  273.  
  274.         this.views.notificacionesView = new NotificacionManagementView()
  275.  
  276.         $container.append(this.views.notificacionesView.render().el)
  277.  
  278.         $container.append(this.views.documentTypeManagementView.render().el)
  279.  
  280.         var obj = {
  281.             minuta:minuta,
  282.             presentante:this.minutaObj.Presentante,
  283.             notarioEmail:this.minutaObj.NotarioEmail,
  284.             otroNombreCompleto:this.minutaObj.OtroNombreApellido
  285.         }
  286.  
  287.         if (!minuta.DocumentoLey216 && !minuta.DocumentoEnAtraso) {
  288.             // var s = {minuta,}
  289.             this.views.presentanteView = new PresentanteView(obj)
  290.             // this.views.presentanteView.minuta = minuta
  291.  
  292.             $container.append(this.views.presentanteView.render().el)
  293.         }
  294.  
  295.         $container.append(this.views.titularListView.render().el)
  296.         $container.append(this.views.fincaListView.render().el)
  297.         $container.append(this.views.transaccionListView.render().el)
  298.  
  299.         $container.append(this.views.minutaArancelListView.render().el)
  300.  
  301.         // if (!minuta.DocumentoLey216 && !minuta.DocumentoEnAtraso)
  302.         //     $container.append(this.views.planoListView.render().el)
  303.  
  304.         if (!minuta.DocumentoLey216)
  305.             $container.append(this.views.documentosComplementariosListView.render().el)
  306.  
  307.         this.views.notificacionesListView = new NotificacionListView()
  308.         $container.prepend(this.views.notificacionesListView.render().el)
  309.  
  310.         var estatusId = app.views.mainView.currentMinuta.Minuta.EstatusId
  311.  
  312.         switch (true) {
  313.             case (estatusId == 1):
  314.                 if (!minuta.DocumentoEnAtraso && !minuta.DocumentoLey216) {
  315.                     this.views.minutaDocumentoView = new MinutaDocumentoView()
  316.  
  317.                     $container.append(this.views.minutaDocumentoView.render().el)
  318.                 }
  319.                 break
  320.             case (estatusId == 2):
  321.                 if (app.views.mainView.currentMinuta.CantidadDerechosVigentes > 0) {
  322.                     //this.$el.find(".derechos-vigentes-callout").removeClass("hidden")
  323.                 }
  324.                 break
  325.         }
  326.  
  327.         $container.append(this.views.carritoManagementView.render().el)
  328.  
  329.         this.nameActionButton()
  330.  
  331.         if (!minuta.EsMio) {
  332.             this.setReadOnly()
  333.             this.views.notificacionesListView.removeReadOnly()
  334.         }
  335.         this.$el.find(".main-accordion").collapse()
  336.  
  337.         this.$el.fadeIn()
  338.  
  339.         if (minuta.DocumentoEnAtraso) {
  340.             var presentacion = this.$el.find(".presentacion-row").text().trim()
  341.  
  342.             this.$el.find(".presentacion-row").text(presentacion + "*")
  343.         }
  344.     },
  345.     showHistorico: function () {
  346.         var asiento = this.model.get("AsientoId")
  347.  
  348.         window.open('historialAsiento.html?asiento=' + asiento, '_blank');
  349.     },
  350.     showManejoNotificaciones: function () {
  351.         this.views.notificacionesView.applyBindings()
  352.         this.views.notificacionesView.loadDestinatarios()
  353.         this.views.notificacionesView.puedeEditarse = true
  354.         this.$el.find(".minuta-notificacion-block:last").modal({ backdrop: 'static', keyboard: false })
  355.     },
  356.     nameActionButton: function () {
  357.         var name = "Guardar"
  358.  
  359.         switch (app.views.mainView.currentMinuta.Minuta.EstatusId) {
  360.             case 1:
  361.                 name = "Presentar"
  362.                 this.saveAction = "presentar"
  363.                 this.customUrl = "/api/minuta/" + this.getMinutaId() + "/" + this.saveAction
  364.                 break
  365.             case 2:
  366.                 name = "Enviar al Registrador"
  367.                 this.saveAction = "calificar"
  368.                 this.customUrl = "/api/minuta/" + this.getMinutaId() +
  369.                                  "/asiento/" + app.views.mainView.currentMinuta.Minuta.AsientoId +
  370.                                  "/" + this.saveAction
  371.                 break
  372.             case 3:
  373.                 name = "Inscribir"
  374.                 this.saveAction = "inscribir"
  375.                 this.customUrl = "/api/minuta/" + this.getMinutaId() +
  376.                                  "/asiento/" + app.views.mainView.currentMinuta.Minuta.AsientoId +
  377.                                  "/" + this.saveAction
  378.  
  379.                 break
  380.             case 7:
  381.                 name = "Enviar al Registrador"
  382.                 this.saveAction = "calificar"
  383.                 this.customUrl = "/api/minuta/" + this.getMinutaId() +
  384.                                  "/asiento/" + app.views.mainView.currentMinuta.Minuta.AsientoId +
  385.                                  "/" + this.saveAction
  386.                 break
  387.             case 8:
  388.                 name = "Enviar al Registrador"
  389.                 this.saveAction = "calificar"
  390.                 this.customUrl = "/api/minuta/" + this.getMinutaId() +
  391.                                  "/asiento/" + app.views.mainView.currentMinuta.Minuta.AsientoId +
  392.                                  "/" + this.saveAction
  393.                 break
  394.             case 12:
  395.                 name = "Extender Asiento"
  396.         }
  397.  
  398.         var $el = $(this.el).find(".btn-save-minuta .text")
  399.  
  400.         $el.text(name)
  401.         $el.attr({
  402.             "title": name
  403.         })
  404.  
  405.         $(this.el).find(".btn-save-minuta").attr({
  406.             "title": name
  407.         })
  408.     },
  409.     loadMinutaData: function (cb) {
  410.         var minutaId = Utils.UrlManagement.querystring("minutaId"),
  411.             asientoId = Utils.UrlManagement.querystring("aid"),
  412.             self = this
  413.  
  414.  
  415.         if (minutaId) {
  416.             this.model = new MinutaModel()
  417.             this.model.customUrl = "/api/minuta/" + minutaId
  418.  
  419.             // importante: si hay mas de un asiento para la minuta hay que especificar el asiento.
  420.             if (parseInt(asientoId) > 0) {
  421.                 this.model.customUrl += "/asiento/" + asientoId
  422.             }
  423.  
  424.             this.model.idAttribute = "MinutaId"
  425.             this.model.fetch(
  426.             {
  427.                 success: function (err, response) {
  428.                     //Load minuta
  429.                     self.BandejaFiltros = app.views.mainView.currentMinuta.BandejaFiltros
  430.  
  431.                     var minuta = app.views.mainView.currentMinuta = response
  432.  
  433.                     self.minutaObj = minuta
  434.                     var estatus = app.views.mainView.currentMinuta.Minuta.EstatusId
  435.                     self.model = new MinutaModel(minuta.Minuta)
  436.  
  437.                     if (self.model.soloMinutaNotario()) {
  438.                         window.location.replace('#minutanot?minutaId=' + minutaId + "&aid=" + asientoId)
  439.                         return;
  440.                     }
  441.  
  442.                     self.model.set("ArancelLst", minuta.ArancelLst)
  443.                     self.model.set("DocumentoComplementarioLst", minuta.DocumentoComplementarioLst)
  444.                     self.model.set("PersonaLst", minuta.PersonaLst)
  445.                     self.model.set("PropiedadLst", minuta.PropiedadLst)
  446.                     self.model.set("TransaccionLst", minuta.TransaccionLst)
  447.                     self.model.set("Presentante", minuta.Presentante)
  448.                     self.model.set("NotificacionLst", minuta.NotificacionLst)
  449.                     self.model.set("LeyEspecial", minuta.LeyEspecial)
  450.                     self.model.set("Secciones", minuta.Secciones)
  451.                     self.model.set("EstatusId", estatus)
  452.                    
  453.                    
  454.  
  455.                     cb()
  456.                 },
  457.                 error: this.xhrError,
  458.                 beforeSend: this.beforeSend
  459.             })
  460.         } else {
  461.             cb()
  462.         }
  463.      
  464.  
  465.     },
  466.     getDespachadosMismaFinca:function(cb){ // Buscar otros documentos despachados con la misma finca
  467.         var model = new GlobalEmptyModel(),
  468.             fincas = "",
  469.             msgHtml = "<h3>Hay documentos despachados con las siguientes fincas:</h3><ul>",
  470.             self = this;
  471.  
  472.         _.each(this.model.get("PropiedadLst"), function(value){
  473.             fincas += value.Id + "|"
  474.         })
  475.  
  476.         model.customUrl = "/api/minuta/despachados/mismasFincas?fincas=" + fincas
  477.  
  478.         model.fetch({
  479.             success:function(err, response){
  480.                 if(response.length > 0){
  481.                    
  482.                     var link = window.location.origin +  "/client/#minuta?"
  483.  
  484.                     _.each(self.model.get("PropiedadLst"), function(value){
  485.                        
  486.                         var documentosPorFinca = _.where(response, { "PropiedadId": value.Id });
  487.  
  488.                         msgHtml += "<h4>Propiedad: " + documentosPorFinca[0].NumeroPropiedad
  489.                                 + " Demarcación: " + documentosPorFinca[0].CodigoDemarcacion
  490.                                 + "</h4>"
  491.                        
  492.                         _.each(documentosPorFinca, function(value){
  493.                             var hLink = link + "minutaId=" + value.MinutaId + "&aid=" + value.AsientoId
  494.  
  495.                             msgHtml += "<li>" + value.Asiento
  496.                                     + ": <a target='_blank', href='" + hLink + "'>Ver documento</a>"
  497.                                     + "</li>"
  498.                         });
  499.  
  500.  
  501.                         msgHtml += "</ul>"
  502.  
  503.                         var confirm = new ConfirmView()
  504.  
  505.                         confirm.cancelcb = cb
  506.                         confirm.setSize("modal-lg")
  507.                         confirm.show(msgHtml, cb)
  508.                     });
  509.                 } else{
  510.                     cb()
  511.                 }
  512.             },
  513.             error:this.xhrError,
  514.             beforeSend:this.beforeSend
  515.         })
  516.     },
  517.     save: function () {
  518.         if (this.isWorking) return
  519.  
  520.         var self = this, minuta = app.views.mainView.currentMinuta.Minuta
  521.  
  522.         var afterSave = function () {
  523.             self.startWorking()
  524.  
  525.             var data = {},
  526.                 views = app.views.mainView.views.minutaView.views,
  527.                 msg = "",
  528.                 role = _.first(app.roles)
  529.  
  530.             if (role != 3) {
  531.  
  532.                 switch (minuta.EstatusId) {
  533.                     case 1:
  534.                         if (minuta.DocumentoEnAtraso || minuta.DocumentoLey216) {
  535.  
  536.                             data.Asiento = self.model.get("Asiento")
  537.  
  538.                             self.customUrl = "/api/minuta/" + self.model.get("MinutaId") +
  539.                                               "/presentar/asiento/" + data.Asiento +
  540.                                               "/tipoDocumento/" + ((minuta.DocumentoEnAtraso) ? "atrasado" : "ley216")
  541.  
  542.                             msg = "Documento pasado a despacho"
  543.  
  544.                         }
  545.  
  546.                         break
  547.                     case 2:
  548.                         if (minuta.DocumentoLey216) {
  549.                             self.customUrl = "/api/minuta/" + self.model.get("MinutaId") +
  550.                                               "/asiento/" + self.model.get("AsientoId") +
  551.                                               "/extender/tipoDocumento/ley216"
  552.                         }
  553.  
  554.                         break
  555.                     case 3:
  556.                         self.customUrl = "/api/minuta/" + self.getMinutaId() +
  557.                                  "/asiento/" + app.views.mainView.currentMinuta.Minuta.AsientoId +
  558.                                  "/" + self.saveAction + "/generarCredito/" + self.generateCartaCredito
  559.                     case 12:
  560.                         if (minuta.DocumentoLey216) {
  561.                             self.customUrl = "/api/minuta/" + self.model.get("MinutaId") +
  562.                                               "/asiento/" + self.model.get("AsientoId") +
  563.                                               "/inscribir/tipoDocumento/ley216"
  564.                         }
  565.  
  566.                         break
  567.                 }
  568.  
  569.                 var model = new GlobalEmptyModel()
  570.  
  571.  
  572.                 model.customUrl = self.customUrl
  573.  
  574.                 model.save({
  575.                     data: data
  576.                 }, {
  577.                     success: function (err, response) {
  578.                         self.stopWorking()
  579.  
  580.                         if (response.Message) {
  581.                             var confirm = new ConfirmView()
  582.  
  583.                             confirm.setSize("modal-lg")
  584.                             confirm.show(Utils.ErrorManagement.returnErrorHtml(response.Message), null, "Error")
  585.                         } else {
  586.                             if (msg) {
  587.                                 (new MessageView().show(msg))
  588.                             }
  589.  
  590.                             if ((minuta.DocumentoEnAtraso || minuta.DocumentoLey216) && minuta.EstatusId == 1) {
  591.                                 self.render()
  592.                             } else {
  593.                                 //Solo ensenar seccion de recibo si ha sido presentada la minuta
  594.                                 if (minuta.EstatusId == 1) {
  595.                                     //Show         
  596.                                     self.$el.find(".new-document").modal({ backdrop: 'static', keyboard: false })
  597.                                 } else {
  598.                                     self.getDespachadosMismaFinca(function(){
  599.                                        
  600.                                         self.leaveToQueue(self.BandejaFiltros)
  601.  
  602.                                         // var propiedadNum = _.first(self.model.get("PropiedadLst"));
  603.                                         // self.leaveToQueue(propiedadNum.NumeroPropiedad)
  604.  
  605.                                         // if (minuta.EstatusId > 2)
  606.                                         //     self.leaveToQueue()
  607.                                         // else if(minuta.EstatusId == 2){
  608.                                         //     var propiedadNum = _.first(self.model.get("PropiedadLst"));
  609.  
  610.                                         //     if(role == 1 || role == 2)
  611.                                         //         self.leaveToQueue(propiedadNum.NumeroPropiedad)
  612.                                         //     else
  613.                                         //         self.leaveToQueue()
  614.                                         // }
  615.                                         // else
  616.                                         //     self.leave()
  617.                                     })
  618.                                 }
  619.                             }
  620.                         }
  621.                     },
  622.                     error: function (err, response) {
  623.                         if (self.saveAction == "presentar" && response.responseJSON == "SUBMISSIONTIMEERROR") {
  624.                             self.timeOutError("No se puede presentar fuera del horario establecido.")
  625.  
  626.                             var confirm = new ConfirmView(),
  627.                                 msg = "El horario para presentación personal es de 8:00 am a 12:00 pm y de 1:00 pm a 4:00 pm."
  628.  
  629.                             confirm.setSize("modal-lg")
  630.  
  631.                             confirm.show(msg, null, "Aviso")
  632.                         }
  633.                     },
  634.                     beforeSend: self.beforeSend
  635.                 })
  636.  
  637.  
  638.  
  639.             } else {
  640.  
  641.                 // self.stopWorking()
  642.  
  643.                 self.validarPaga(function(){
  644.                     var model = new GlobalEmptyModel()
  645.  
  646.                     model.customUrl = "/api/cesta/aranceles/" + self.model.get("MinutaId") + "/exento/" + self.model.get("Exento")
  647.  
  648.                     model.fetch(
  649.                     {
  650.                         success: function (err, response) {
  651.                             $(self.el).find(".carrito-management-block").modal({ backdrop: 'static', keyboard: false })
  652.  
  653.                             self.views.carritoManagementView.prepCarrito();
  654.  
  655.                             self.views.carritoManagementView.achHide();
  656.  
  657.                             self.stopWorking()
  658.                         },
  659.                         error: self.xhrError,
  660.                         beforeSend: self.beforeSend
  661.                     })
  662.                 })
  663.             }
  664.         }
  665.  
  666.         var validarFincas = function(){
  667.             var model = new GlobalEmptyModel()
  668.  
  669.             model.customUrl = "/api/propiedad/despacho/validarFincas/minutaId/"
  670.                             + minuta.Id
  671.                             + "/asientoId/"
  672.                             + minuta.AsientoId
  673.  
  674.             model.fetch({
  675.                 success:function(err,response){
  676.                     var role = _.first(app.roles),
  677.                         list = []
  678.  
  679.                     if(role == 1){
  680.                         list = _.where(response, { "InscripcionMarcadoTecnico": false });
  681.                     } else if(role == 2){
  682.                         list = _.where(response, { "InscripcionMarcadoRegistrador": false });
  683.                     }
  684.  
  685.                     if(list.length > 0){
  686.                         var aviso = new MessageView(),
  687.                             msg = 'Las siguientes fincas faltan por ser verificadas. Debe marcarlas como "Verificado" en cada finca en el Despacho:'
  688.  
  689.                         msg += "<br><br><ul>"
  690.  
  691.                         _.each(response, function(value){
  692.                             msg += "<li>Demarcación: " + value.CodigoDemarcacion + " Finca: " + value.NumeroPropiedad + "</li>"
  693.                         });
  694.  
  695.                         msg += "</ul>"
  696.  
  697.                         aviso.setSize("modal-lg")
  698.                         aviso.show(msg, "Aviso", null)
  699.                     } else{
  700.                         bioValidate()
  701.                     }
  702.                 },
  703.                 error:self.xhrError,
  704.                 beforeSend:self.beforeSend
  705.             })
  706.         }
  707.  
  708.         var bioValidate = function () {
  709.             var role = _.first(app.roles)
  710.  
  711.             if (minuta.EstatusId == 3 || minuta.EstatusId == 12 && role == 2) {
  712.                 (new ConfirmView()).show("¿Desea firmar este documento?", function () {
  713.                     var dardeo = new DarDeoView()
  714.                     dardeo.parent = self
  715.                     dardeo.show(afterSave)
  716.                 })
  717.             } else {
  718.                 afterSave()
  719.             }
  720.         }
  721.  
  722.         if(minuta.EstatusId > 1)
  723.             // this.isValid(validarFincas)
  724.             this.isValid(bioValidate)
  725.         else
  726.             this.isValid(bioValidate)
  727.        
  728.     },
  729.     validarPaga:function(cb){
  730.         var self = this,
  731.             rol = app.roles[0]
  732.         var model = new GlobalEmptyModel()
  733.  
  734.         model.customUrl = "/api/cesta/minuta/" + this.model.get("MinutaId") + "/pagada"
  735.  
  736.         model.fetch(
  737.         {
  738.             success: function (err, response) {
  739.                 if(!response)
  740.                     cb()
  741.                 else{
  742.                     self.stopWorking()
  743.                     self.saveNotario()
  744.                 }
  745.             },
  746.             error: self.xhrError,
  747.             beforeSend: self.beforeSend
  748.         })
  749.     },
  750.     saveNotario: function () {
  751.         var self = this,
  752.             data = {}
  753.         msg = ""
  754.  
  755.         if(this.isWorking)
  756.             return
  757.  
  758.         this.startWorking()
  759.  
  760.         this.customUrl = "/api/minuta/" + this.getMinutaId() + "/presentar"
  761.  
  762.         var model = new GlobalEmptyModel()
  763.  
  764.         model.customUrl = this.customUrl
  765.  
  766.         model.save({
  767.             data: data
  768.         }, {
  769.             success: function (err, response) {
  770.                 self.stopWorking()
  771.  
  772.                 if (response.Message) {
  773.                     var confirm = new ConfirmView()
  774.  
  775.                     confirm.setSize("modal-lg")
  776.                     confirm.show(Utils.ErrorManagement.returnErrorHtml(response.Message), null, "Error")
  777.                 } else {
  778.                     if (msg) {
  779.                         (new MessageView().show(msg))
  780.                     }
  781.  
  782.                     self.$el.find(".new-document").modal({ backdrop: 'static', keyboard: false })
  783.                 }
  784.             },
  785.             error: self.xhrError,
  786.             beforeSend: self.beforeSend
  787.         })
  788.     },
  789.     printReceipt: function () {
  790.         if (this.isWorking) return
  791.  
  792.         var self = this
  793.  
  794.         this.workingEl = ".btn-print"
  795.  
  796.         this.startWorking()
  797.  
  798.         this.$el.find("iframe.receipt-frame").attr("src", app.GlobalApiPath + "/stream/reciboPresentacion/" + self.model.get("MinutaId") + "/" + app.token)
  799.  
  800.         setTimeout(function () {
  801.             self.stopWorking()
  802.         }, 5000)
  803.     },
  804.     newReuse: function () {
  805.         //Esto se hace para que se llene la informacion del presentante con la data de la ultima presentacion  
  806.         app.currentPresentanteData = this.views.presentanteView.model.toJSON()
  807.  
  808.         this.new()
  809.     },
  810.     new: function () {
  811.         if (this.isWorking) return
  812.  
  813.         var self = this, model = new StartingPointModel(),
  814.             minuta = app.views.mainView.currentMinuta.Minuta
  815.  
  816.         this.workingEl = ".btn-new"
  817.  
  818.         this.startWorking()
  819.  
  820.         if (minuta.DocumentoLey216 || minuta.DocumentoEnAtraso) {
  821.             var tipoDocument = (this.DocumentoEnAtraso) ? 1 : 2
  822.  
  823.             model.customUrl = "/api/minuta/tipoDocumento/" + tipoDocument
  824.         } else {
  825.             model.customUrl = "/api/minuta/false"
  826.         }
  827.  
  828.         model.save({}, {
  829.             success: function (err, response) {
  830.                 var returnObj = Utils.EncriptionManagement.convertStrToJson(response)
  831.  
  832.                 $(".modal-backdrop").remove()
  833.                 self.$el.find(".new-document").modal("hide")
  834.                 self.$el.remove()
  835.  
  836.                 self.stopWorking()
  837.  
  838.                 window.location.assign('#minuta?minutaId=' + returnObj.MinutaId)
  839.             },
  840.             error: this.xhrError,
  841.             beforeSend: this.beforeSend
  842.         })
  843.     },
  844.     leave: function () {
  845.         this.$el.find(".new-document").modal("hide")
  846.  
  847.         window.location.assign('#')
  848.     },
  849.  
  850.     leaveToQueue: function (bandejaFiltros) {
  851.         this.$el.find(".new-document").modal("hide")
  852.  
  853.        
  854.         if(bandejaFiltros){
  855.             var qStr = "?finca=" + bandejaFiltros.FiltroFinca
  856.                         + "&tipoDoc=" + bandejaFiltros.FiltroPresentacion
  857.                         + "&estado=" + bandejaFiltros.FiltroEstado
  858.                         + "&demarcacion=" + bandejaFiltros.FiltroDemarcacion
  859.             window.location.assign('#documentQueue' + qStr)
  860.         }
  861.         else
  862.             window.location.assign('#documentQueue')
  863.     },
  864.     isValid: function (cb) {
  865.         var views = app.views.mainView.views.minutaView.views,
  866.             errors = [],
  867.             isValid = true,
  868.             minuta = app.views.mainView.currentMinuta.Minuta,
  869.             role = _.first(app.roles)
  870.  
  871.         var isExterno = role == 3 || role == 11 ? true : false
  872.  
  873.         //***Shared Validations
  874.         //Tipo document exists
  875.         //Tipo documento notarial exists
  876.         if (!views.documentTypeManagementView.isValid())
  877.             errors.push("Debe especificar información del documento")
  878.  
  879.         //At least one a favor de
  880.         if (views.titularListView.hasEmptyItem())
  881.             errors.push("Debe haber por lo menos un a favor de")
  882.  
  883.         //At least one finca
  884.         if (views.fincaListView.hasEmptyItem())
  885.             errors.push("Debe haber por lo menos una finca")
  886.  
  887.         //At least one transaction
  888.         if (views.transaccionListView.hasEmptyItem())
  889.             errors.push("Debe haber por lo menos una transaccion")
  890.  
  891.         if (!isExterno) {
  892.             // tarea #1050 segun solicitado por bethzaida y jessica no se deben validar los aranceles ni en 216 ni en prekaribe. -- el dario.
  893.             if (!this.model.get("Exento") && !minuta.DocumentoEnAtraso && !minuta.DocumentoLey216) {
  894.                 if (!views.minutaArancelListView.isValid())
  895.                     errors.push("No se entraron los aranceles necesarios")
  896.             }
  897.         }
  898.  
  899.         if (!minuta.DocumentoLey216 && !minuta.DocumentoEnAtraso) {
  900.             if (!views.presentanteView.isValid()) {
  901.                 errors.push("No se entró la información de presentante")
  902.             }
  903.         }
  904.  
  905.         switch (true) {
  906.             case (minuta.EstatusId == 1):
  907.                 if (!minuta.DocumentoEnAtraso && !minuta.DocumentoLey216) {
  908.                     if (!views.minutaDocumentoView.hasFile())
  909.                         errors.push("Debe especificar el documento a presentar")
  910.                 }
  911.  
  912.                 if (minuta.DocumentoEnAtraso || minuta.DocumentoLey216) {
  913.                     //Asiendo es provisto por el usuario
  914.                     var asientoDiario = this.model.get("AsientoDiario")
  915.                     asientoSegmento = this.model.get("AsientoSegmento")
  916.                     asientoSection = this.model.get("AsientoSection")
  917.  
  918.  
  919.                     if ((asientoDiario == "" || !asientoDiario) ||
  920.                         (asientoSegmento == "" || !asientoSegmento) ||
  921.                         (asientoSection == "" || !asientoSection)) {
  922.                         errors.push("Debe llenar el numero de asiento")
  923.                     }
  924.                 }
  925.  
  926.                 break          
  927.         }
  928.  
  929.         var confirm = new ConfirmView()
  930.  
  931.         if (errors.length > 0) {
  932.             var errorHtml = "",
  933.                 isValid = false
  934.  
  935.             _.each(errors, function (item) {
  936.                 errorHtml = errorHtml + Utils.ErrorManagement.returnErrorHtml(item)
  937.             })
  938.  
  939.             confirm.setSize("modal-lg")
  940.             confirm.show(errorHtml, null, "Error")
  941.         } else {
  942.             var model = new GlobalEmptyModel(),
  943.                 self = this
  944.  
  945.             if (!this.model.get("Exento") && !isExterno) {
  946.                 model.customUrl = "/api/minuta/" + self.getMinutaId() +
  947.                                   "/arancelObligatorio/" + ((minuta.DocumentoEnAtraso || minuta.DocumentoLey216) ? false : true) +
  948.                                   "/validacion/"
  949.  
  950.                 model.save({}, {
  951.                     success: function (err, response) {
  952.                         if (response == false) {
  953.                             confirm.setSize("modal-lg")
  954.                             confirm.show(
  955.                                 Utils.ErrorManagement.returnErrorHtml("No se especificaron todos los aranceles"),
  956.                                 null,
  957.                                 "Error"
  958.                             )
  959.                         } else {
  960.                             if (typeof cb == "function") cb()
  961.                         }
  962.                     },
  963.                     error: this.xhrError,
  964.                     beforeSend: this.beforeSend
  965.                 })
  966.             } else {
  967.                 if (typeof cb == "function") cb()
  968.             }
  969.         }
  970.     },
  971.     caducarDocumento: function () {
  972.         var self = this
  973.         var confirm = new ConfirmView()
  974.         confirm.show("¿Seguro que desea caducar este documento?", function () {
  975.             var model = new GlobalEmptyModel()
  976.             model.id = self.model.get("AsientoId")
  977.             model.attributes = self.model.attributes
  978.             model.idAttibute = "AsientoId"
  979.             model.customUrl = "/api/notificacion/caducar"
  980.             model.save({},
  981.             {
  982.                 success: function (err, response) {
  983.                     app.router.navigate("#main", { trigger: true })
  984.                 },
  985.                 error: self.xhrError,
  986.                 beforeSend: self.beforeSend
  987.             })
  988.         })
  989.     },
  990.  
  991.     suspenderNotificacion: function () {
  992.         var self = this
  993.         var confirm = new ConfirmView()
  994.         confirm.show("Suspender?", function () {
  995.             var model = new GlobalEmptyModel()
  996.             model.id = self.model.get("AsientoId")
  997.             model.attributes = self.model.attributes
  998.             model.idAttibute = "AsientoId"
  999.             model.customUrl = "/api/notificacion/suspender/S/"
  1000.             model.save({},
  1001.             {
  1002.                 success: function (err, response) {
  1003.                     self.close()
  1004.                 },
  1005.                 error: self.xhrError,
  1006.                 beforeSend: self.beforeSend
  1007.             })
  1008.         })
  1009.     },
  1010.     suspenderNotificacionRecalificar: function () {
  1011.         var self = this
  1012.         var confirm = new ConfirmView()
  1013.         confirm.show("Suspender?", function () {
  1014.             var model = new GlobalEmptyModel()
  1015.             model.id = self.model.get("AsientoId")
  1016.             model.attributes = self.model.attributes
  1017.             model.idAttibute = "AsientoId"
  1018.             model.customUrl = "/api/notificacion/suspender/R/"
  1019.             model.save({},
  1020.             {
  1021.                 success: function (err, response) {
  1022.                     self.close()
  1023.                 },
  1024.                 error: self.xhrError,
  1025.                 beforeSend: self.beforeSend
  1026.             })
  1027.         })
  1028.     },
  1029.     suspenderNotificacionNoProcede: function () {
  1030.         var self = this
  1031.         var confirm = new ConfirmView()
  1032.         confirm.show("Al desistir de la notificación no podrá recuperla. ¿Desea continuar?", function () {
  1033.             var model = new GlobalEmptyModel()
  1034.             model.id = self.model.get("AsientoId")
  1035.             model.attributes = self.model.attributes
  1036.             model.idAttibute = "AsientoId"
  1037.             model.customUrl = "/api/notificacion/suspender/N/"
  1038.             model.save({},
  1039.             {
  1040.                 success: function (err, response) {
  1041.                     self.close()
  1042.                 },
  1043.                 error: self.xhrError,
  1044.                 beforeSend: self.beforeSend
  1045.             })
  1046.         })
  1047.     },
  1048.     close: function () {
  1049.         var self = this;
  1050.  
  1051.         (new ConfirmView()).show("Salir?", function () {
  1052.             app.views.mainView.currentMinuta = {}
  1053.  
  1054.             self.$el.fadeOut(function () {
  1055.                 self.$el.remove()
  1056.  
  1057.                 window.location.assign('#')
  1058.             })
  1059.         })
  1060.     },
  1061.     checkCartaCredito: function () {
  1062.         var self = this,
  1063.             asientoId = Utils.UrlManagement.querystring("aid")
  1064.  
  1065.         var model = new GlobalEmptyModel()
  1066.  
  1067.         model.customUrl = "/api/cartacredito/verificarCantidad/" + asientoId
  1068.  
  1069.         model.fetch(
  1070.         {
  1071.             success: function (err, response) {
  1072.                 if (response.hasSobrante) {
  1073.  
  1074.                     var confirm = new ConfirmView()
  1075.                     confirm.setSize("modal-lg")
  1076.                     confirm.cancelcb = function () {
  1077.                         self.save()
  1078.                     }
  1079.                     confirm.show("¿Este asiento tiene un sobrante, desea generar una carta de crédito por la cantidad de $" + response.Cantidad + "?", function () {
  1080.                         self.generateCartaCredito = true
  1081.                         self.save()
  1082.                     })
  1083.                 } else {
  1084.                     self.save()
  1085.                 }
  1086.             },
  1087.             error: this.xhrError,
  1088.             beforeSend: this.beforeSend
  1089.         })
  1090.     },
  1091.     render: function () {
  1092.         var self = this
  1093.  
  1094.         Utils.TemplateManagement.loadHtmlTemplate("#minuta", "minuta",
  1095.         function () {
  1096.             self.loadMinutaData(function () {
  1097.                 self.init()
  1098.                 self.loadViewsByRoles()
  1099.  
  1100.                 self.$el.removeClass("hidden").fadeIn()
  1101.  
  1102.                
  1103.             })
  1104.         })
  1105.  
  1106.         return this
  1107.  
  1108.     }
  1109. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement