1// Generated by CoffeeScript 1.12.7 2(function() { 3 var EditExchangeHistoryController, ExchangeHistoryController, ExchangeHistoryGridController, ExchangeHistoryItemController, ExchangeHistoryStepController, ExchangeLedgerLineController, ExchangeMemCalcController, ExchangeNoteDialogController, ExchangeStepNoteDialogController, base, hedgeRemovalConfirmationController, module, 4 indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 5 6 module = this.angular.module('snExchangeHistory'); 7 8 EditExchangeHistoryController = function($scope, ExchangeModalityModel, LoanModalityModel, CustomerBankModel, WarrantyModel, ExchangeHistoryModel, InstallmentsService, $timeout, feedback, ConfigurationService, UserModel, ExchangeQuotationModel, ExchangeValidationService) { 9 var EDIT_EXCHANGE_INSTALLMENTS_FLOW, EDIT_EXCHANGE_PAYMENTS_FLOW, EXCHANGE_HISTORY_GENERATED, addEditFlowHint, checkInitialAndOutlayAreWeekdays, dates, editExchangePaymentsFlowContinuation, editPaymentsFlow, editPaymentsFlowContinuation, eventBus, events, fillIdentifier, fromForm, getBank, getBranches, initNdfTerm, initPronto, labels, loadAccounts, loadBranches, numbers, rateDecimals, saveExchangeHistoryContinuation, saveExchangeHistoryDirect, saveExchangeHistoryDirectContinuation, saveExchangeHistoryError, saveExchangeHistorySuccess, saveOrEditFlow, savingExchangeHistory, setHistory, toForm, validateExchangeFlowValidations, validateExchangeHistory, validateIdentifier; 10 dates = spreadnet.utils.dates; 11 numbers = spreadnet.utils.numbers; 12 labels = spreadnet.utils.labels; 13 eventBus = spreadnet.eventBus; 14 events = spreadnet.events; 15 EXCHANGE_HISTORY_GENERATED = events.EXCHANGE_HISTORY_GENERATED; 16 EDIT_EXCHANGE_PAYMENTS_FLOW = events.EDIT_EXCHANGE_PAYMENTS_FLOW; 17 EDIT_EXCHANGE_INSTALLMENTS_FLOW = events.EDIT_EXCHANGE_INSTALLMENTS_FLOW; 18 $scope.branches = []; 19 $scope.accounts = []; 20 $scope.config = {}; 21 savingExchangeHistory = false; 22 $scope.exchangeModalities = function() { 23 return ExchangeModalityModel.ndfTermCollection; 24 }; 25 getBank = function(id) { 26 return CustomerBankModel.byId(id); 27 }; 28 $scope.dummy = 10; 29 $scope.saving = function() { 30 return savingExchangeHistory || ExchangeHistoryModel.pendingHistorySave(); 31 }; 32 $scope.processing = function() { 33 return ConfigurationService.identifierPendingRequest() || ExchangeValidationService.pendingFlowValidation(); 34 }; 35 initPronto = function() { 36 var pronto; 37 pronto = { 38 workDays: 2, 39 rate: 0, 40 referenceRateSelection: { 41 selection: "R", 42 rate: 0 43 } 44 }; 45 return pronto; 46 }; 47 initNdfTerm = function() { 48 var ndfTerm; 49 ndfTerm = { 50 warranties: { 51 main: "S GAR", 52 pctMain: 0, 53 extra1: "", 54 pctExtra1: 0, 55 extra2: "", 56 pctExtra2: 0 57 }, 58 initialRateSelection: { 59 selection: "R", 60 rate: 0 61 }, 62 steps: [], 63 stepType: "", 64 initialPmtDate: "", 65 stepDayOfMonth: 1, 66 stepInterval: 30 67 }; 68 return ndfTerm; 69 }; 70 $scope.exchangeHistoryForm = { 71 operationLabel: "", 72 status: "Fechada", 73 bank: "", 74 loadedBank: "", 75 branch: "", 76 loadedBranch: "", 77 account: "", 78 contractNumber: "", 79 modality: "", 80 currency: "US$", 81 operation: "B", 82 value: 0, 83 tac: 0, 84 issueDate: "", 85 outlayDate: "", 86 dueDate: "", 87 numberOfSteps: 0, 88 term: 0, 89 termInWorkDays: 0, 90 settled: "", 91 totalSpread: 0, 92 attachments: [], 93 pronto: initPronto(), 94 ndfTerm: initNdfTerm(), 95 ndfTermOutlayDateDisabled: true, 96 identifier: "", 97 note: "", 98 hedgeOperation: sn.u.resetHedgeOperation() 99 }; 100 $scope.exchangeHistoryForm.ndfTermOutlayDateDisabled = true; 101 $scope.modality = function() { 102 var ref; 103 return (ref = $scope.exchangeHistoryForm) != null ? ref.modality : void 0; 104 }; 105 $scope.currency = function() { 106 var ref; 107 return (ref = $scope.exchangeHistoryForm) != null ? ref.currency : void 0; 108 }; 109 $scope.isDollar = function() { 110 var ref; 111 return ((ref = $scope.exchangeHistoryForm) != null ? ref.currency : void 0) === "US$"; 112 }; 113 $scope.isDolarCurrency = function() { 114 var ref; 115 return ((ref = $scope.exchangeHistoryForm) != null ? ref.currency : void 0) === "US$"; 116 }; 117 $scope.isEuroCurrency = function() { 118 var ref; 119 return ((ref = $scope.exchangeHistoryForm) != null ? ref.currency : void 0) === "â¬"; 120 }; 121 $scope.isExchangeModalityPronto = function() { 122 var ref; 123 return ((ref = $scope.exchangeHistoryForm) != null ? ref.modality : void 0) === "PRO"; 124 }; 125 $scope.isExchangeModalityNdfOrTerm = function() { 126 var ref, ref1; 127 return (ref = (ref1 = $scope.exchangeHistoryForm) != null ? ref1.modality : void 0) === "NDF" || ref === "TER"; 128 }; 129 $scope.changeModality = function() {}; 130 $scope.customerBanks = function() { 131 var banks; 132 banks = CustomerBankModel.collection; 133 if (banks.length === 1 && ($scope.exchangeHistoryForm != null)) { 134 $scope.exchangeHistoryForm.bank = banks[0]._id; 135 loadBranches(); 136 } 137 return banks; 138 }; 139 $scope.selectBank = function() { 140 var form; 141 form = $scope.exchangeHistoryForm; 142 if (form.bank !== form.loadedBank) { 143 form.branch = ""; 144 form.account = ""; 145 form.loadedBank = form.bank; 146 form.loadedBranch = ""; 147 return loadBranches(); 148 } 149 }; 150 loadBranches = function() { 151 var bankId, branch, i, len1, ref; 152 $scope.branches = []; 153 $scope.accounts = []; 154 bankId = $scope.exchangeHistoryForm.bank; 155 if (bankId !== "") { 156 ref = getBranches(bankId); 157 for (i = 0, len1 = ref.length; i < len1; i++) { 158 branch = ref[i]; 159 $scope.branches.push(branch); 160 } 161 } 162 if ($scope.branches.length === 1) { 163 $scope.exchangeHistoryForm.branch = $scope.branches[0]._id; 164 return loadAccounts(); 165 } 166 }; 167 getBranches = function(bankId) { 168 var bank; 169 bank = getBank(bankId); 170 if (bank != null) { 171 return bank.branches; 172 } else { 173 return []; 174 } 175 }; 176 $scope.selectBranch = function() { 177 var form; 178 form = $scope.exchangeHistoryForm; 179 if (form.branch !== form.loadedBranch) { 180 form.account = ""; 181 form.loadedBranch = form.branch; 182 return loadAccounts(); 183 } 184 }; 185 loadAccounts = function() { 186 var branch, form, i, len1, ref; 187 $scope.accounts = []; 188 form = $scope.exchangeHistoryForm; 189 if (form.branch !== "") { 190 ref = getBranches(form.bank); 191 for (i = 0, len1 = ref.length; i < len1; i++) { 192 branch = ref[i]; 193 if (branch._id === form.branch) { 194 $scope.accounts = branch.accounts; 195 if ($scope.accounts.length === 1) { 196 $scope.exchangeHistoryForm.account = $scope.accounts[0].number; 197 } 198 return; 199 } 200 } 201 } 202 }; 203 rateDecimals = function() { 204 return 6; 205 }; 206 $scope.ratePlaceholder = function() { 207 return "0,000000"; 208 }; 209 $scope.rateNumericInputOptions = function() { 210 return "{decimals: " + (rateDecimals()) + "}"; 211 }; 212 $scope.issueDate = function() { 213 var ref; 214 if ((((ref = $scope.exchangeHistoryForm) != null ? ref.issueDate : void 0) != null) && $scope.exchangeHistoryForm.issueDate !== "") { 215 return $scope.exchangeHistoryForm.issueDate.toDate(); 216 } else { 217 return ""; 218 } 219 }; 220 $scope.showPayments = function() { 221 return $scope.isExchangeModalityPronto(); 222 }; 223 $scope.showRateUnit = function() { 224 if ($scope.exchangeHistoryForm != null) { 225 return true; 226 } else { 227 return false;
228 } 229 }; 230 $scope.changeMainWarranty = function() { 231 var ref, ref1; 232 if (((ref = $scope.exchangeHistoryForm) != null ? ref.ndfTerm.warranties.main : void 0) === 'S GAR') { 233 return (ref1 = $scope.exchangeHistoryForm) != null ? ref1.ndfTerm.warranties.pctMain = 0 : void 0; 234 } 235 }; 236 $scope.warranties = function() { 237 return WarrantyModel.collection; 238 }; 239 $scope.extraWarranties = function() { 240 var i, len1, ref, results, w; 241 ref = WarrantyModel.collection; 242 results = []; 243 for (i = 0, len1 = ref.length; i < len1; i++) { 244 w = ref[i]; 245 if (w.code !== 'S GAR') { 246 results.push(w); 247 } 248 } 249 return results; 250 }; 251 fromForm = function() { 252 var exchangeHistory, form, identifier, ndfTerm, pronto; 253 form = $scope.exchangeHistoryForm; 254 exchangeHistory = { 255 goal: "", 256 contractNumber: $scope.exchangeHistoryForm.contractNumber 257 }; 258 if ((form._id != null)) { 259 exchangeHistory._id = form._id; 260 } 261 identifier = form.status === "Fechada" ? form.identifier : ""; 262 exchangeHistory.exchange = { 263 status: form.status, 264 bank: { 265 id: form.bank, 266 branch: form.branch, 267 account: form.account 268 }, 269 modality: form.modality, 270 currency: form.currency, 271 operation: form.operation, 272 value: form.value, 273 term: form.term, 274 termInWorkDays: form.termInWorkDays, 275 numberOfSteps: form.numberOfSteps, 276 issueDate: form.issueDate, 277 outlayDate: form.outlayDate, 278 totalSpread: form.totalSpread || 0, 279 tac: form.tac, 280 settled: form.settled, 281 attachments: form.attachments, 282 identifier: identifier, 283 note: form.note, 284 hedgeOperation: angular.copy(form.hedgeOperation) 285 }; 286 ndfTerm = void 0; 287 pronto = void 0; 288 if ($scope.isExchangeModalityPronto()) { 289 exchangeHistory.exchange.outlayDate = form.outlayDate = form.issueDate; 290 exchangeHistory.exchange.numberOfSteps = form.numberOfSteps = 1; 291 pronto = { 292 workDays: form.pronto.workDays, 293 rate: form.pronto.rate, 294 referenceRateSelection: { 295 selection: form.pronto.referenceRateSelection.selection, 296 rate: form.pronto.referenceRateSelection.rate 297 } 298 }; 299 } else { 300 ndfTerm = { 301 warranties: { 302 main: form.ndfTerm.warranties.main || '', 303 pctMain: form.ndfTerm.warranties.main !== 'S GAR' ? form.ndfTerm.warranties.pctMain : 0, 304 extra1: form.ndfTerm.warranties.main !== 'S GAR' ? form.ndfTerm.warranties.extra1 : '', 305 pctExtra1: form.ndfTerm.warranties.extra1 && form.ndfTerm.warranties.main !== 'S GAR' ? form.ndfTerm.warranties.pctExtra1 : 0, 306 extra2: form.ndfTerm.warranties.main !== 'S GAR' ? form.ndfTerm.warranties.extra2 : '', 307 pctExtra2: form.ndfTerm.warranties.extra2 && form.ndfTerm.warranties.main !== 'S GAR' ? form.ndfTerm.warranties.pctExtra2 : 0 308 }, 309 initialRateSelection: { 310 selection: form.ndfTerm.initialRateSelection.selection, 311 rate: form.ndfTerm.initialRateSelection.rate 312 }, 313 stepType: form.ndfTerm.stepType, 314 initialPmtDate: form.ndfTerm.initialPmtDate, 315 stepDayOfMonth: form.ndfTerm.stepDayOfMonth, 316 stepInterval: form.ndfTerm.stepInterval 317 }; 318 ndfTerm.steps = angular.copy(form.ndfTerm.steps); 319 } 320 exchangeHistory.exchange.ndfTerm = ndfTerm; 321 exchangeHistory.exchange.pronto = pronto; 322 if (form.exchangeId) { 323 exchangeHistory.exchange._id = form.exchangeId; 324 } 325 return exchangeHistory; 326 }; 327 $scope.nextIdentifier = function() { 328 return ConfigurationService.nextIdentifier().then(function(result) { 329 return $scope.exchangeHistoryForm.identifier = result.trim(); 330 }); 331 }; 332 fillIdentifier = function() { 333 if ($scope.exchangeHistoryForm.status === "Fechada" && $scope.exchangeHistoryForm.identifier.trim() === "" && $scope.config.contractNumbering.automatic) { 334 return $scope.nextIdentifier(); 335 } 336 }; 337 toForm = function(exchangeHistory) { 338 var ndfTerm, pronto; 339 $scope.exchangeHistoryForm = { 340 operationLabel: "Edição", 341 _id: exchangeHistory._id, 342 exchangeId: exchangeHistory.exchange._id, 343 status: exchangeHistory.exchange.status, 344 bank: exchangeHistory.exchange.bank.id, 345 contractNumber: exchangeHistory.contractNumber, 346 modality: exchangeHistory.exchange.modality, 347 currency: exchangeHistory.exchange.currency, 348 operation: exchangeHistory.exchange.operation, 349 value: exchangeHistory.exchange.value, 350 tac: exchangeHistory.exchange.tac, 351 term: exchangeHistory.exchange.term, 352 termInWorkDays: exchangeHistory.exchange.termInWorkDays,
353 issueDate: exchangeHistory.exchange.issueDate, 354 outlayDate: exchangeHistory.exchange.outlayDate, 355 numberOfSteps: exchangeHistory.exchange.numberOfSteps || void 0, 356 spreadResult: exchangeHistory.exchange.spreadResult, 357 attachments: exchangeHistory.exchange.attachments || [], 358 identifier: exchangeHistory.exchange.identifier, 359 note: exchangeHistory.exchange.note, 360 hedgeOperation: angular.copy(exchangeHistory.exchange.hedgeOperation) 361 }; 362 if (exchangeHistory.exchange.modality === "PRO") { 363 pronto = { 364 workDays: exchangeHistory.exchange.pronto.workDays, 365 rate: exchangeHistory.exchange.pronto.rate, 366 referenceRateSelection: { 367 selection: exchangeHistory.exchange.pronto.referenceRateSelection.selection, 368 rate: exchangeHistory.exchange.pronto.referenceRateSelection.rate 369 } 370 }; 371 ndfTerm = initNdfTerm(); 372 } else { 373 pronto = initPronto(); 374 ndfTerm = { 375 warranties: { 376 pctMain: exchangeHistory.exchange.ndfTerm.warranties.pctMain, 377 main: exchangeHistory.exchange.ndfTerm.warranties.main, 378 pctExtra1: exchangeHistory.exchange.ndfTerm.warranties.pctExtra1, 379 extra1: exchangeHistory.exchange.ndfTerm.warranties.extra1, 380 pctExtra2: exchangeHistory.exchange.ndfTerm.warranties.pctExtra2, 381 extra2: exchangeHistory.exchange.ndfTerm.warranties.extra2 382 }, 383 initialRateSelection: { 384 selection: exchangeHistory.exchange.ndfTerm.initialRateSelection.selection, 385 rate: exchangeHistory.exchange.ndfTerm.initialRateSelection.rate 386 }, 387 stepType: exchangeHistory.exchange.ndfTerm.stepType, 388 initialPmtDate: exchangeHistory.exchange.ndfTerm.initialPmtDate, 389 stepDayOfMonth: exchangeHistory.exchange.ndfTerm.stepDayOfMonth, 390 stepInterval: exchangeHistory.exchange.ndfTerm.stepInterval 391 }; 392 ndfTerm.steps = angular.copy(exchangeHistory.exchange.ndfTerm.steps); 393 } 394 $scope.exchangeHistoryForm.pronto = pronto; 395 $scope.exchangeHistoryForm.ndfTerm = ndfTerm; 396 $scope.selectBank(); 397 $scope.exchangeHistoryForm.branch = exchangeHistory.exchange.bank.branch; 398 $scope.selectBranch(); 399 $scope.exchangeHistoryForm.account = exchangeHistory.exchange.bank.account; 400 return $scope.onOutlayDateChange(); 401 }; 402 $scope.referenceRateOptionHasChangedTo = function(which) { 403 if (which === $scope.exchangeHistoryForm.pronto.referenceRateSelection.selection) { 404 return true; 405 } 406 }; 407 $scope.initialRateOptionHasChangedTo = function(which) { 408 if (which === $scope.exchangeHistoryForm.ndfTerm.initialRateSelection.selection) { 409 return true; 410 } 411 }; 412 $scope.issueDateInput = function() { 413 var ref; 414 if (!((((ref = $scope.exchangeHistoryForm) != null ? ref.outlayDate : void 0) != null) && $scope.exchangeHistoryForm.outlayDate !== "")) { 415 return $scope.exchangeHistoryForm.outlayDate = $scope.exchangeHistoryForm.issueDate; 416 } 417 }; 418 $scope.indexersHelpText = function() { 419 return $('#interestCalcDescription').html(); 420 }; 421 validateExchangeHistory = function(exchangeHistory) { 422 var validMsg; 423 validMsg = ExchangeHistoryModel.validate(exchangeHistory); 424 if (validMsg !== ExchangeHistoryModel.OK()) { 425 return validMsg; 426 } 427 }; 428 editPaymentsFlow = function(exchangeHistory) { 429 return $scope.inPaymentsFlowMode(exchangeHistory, "new_exchange_history"); 430 }; 431 addEditFlowHint = function(errorMsg) { 432 var ref; 433 if (errorMsg && (((ref = $scope.exchangeHistoryForm) != null ? ref.operationLabel : void 0) === "Edição")) { 434 return errorMsg + "\n\n Use 'Editar Fluxo' para corrigir."; 435 } else { 436 return errorMsg; 437 } 438 }; 439 checkInitialAndOutlayAreWeekdays = function(exchangeToBeSaved, callback) { 440 var checkedWeekdays, exchangeDates, param; 441 if ($scope.isExchangeModalityPronto() || $scope.isExchangeModalityNdfOrTerm()) { 442 if ($scope.isExchangeModalityPronto()) {
443 exchangeDates = [exchangeToBeSaved.exchange.issueDate]; 444 } else { 445 exchangeDates = [exchangeToBeSaved.exchange.issueDate, exchangeToBeSaved.exchange.outlayDate]; 446 } 447 param = { 448 dates: exchangeDates 449 }; 450 checkedWeekdays = InstallmentsService.checkWeekdays(param); 451 return checkedWeekdays.$promise.then(function() { 452 var checkedIssueDate, checkedOutlayDate, invalidDates, invalidIssueDate, invalidOutlayDate, msg; 453 invalidDates = ""; 454 checkedIssueDate = checkedWeekdays.dates[0]; 455 if (!checkedIssueDate.workDay) { 456 invalidIssueDate = spreadnet.utils.dates.dateToDMY(checkedIssueDate.date.toDate()); 457 msg = "A data da operação (" + invalidIssueDate + ") não é dia útil. "; 458 if (invalidDates !== "") { 459 invalidDates += "<br/><br/>"; 460 } 461 invalidDates += msg; 462 } 463 if ($scope.isExchangeModalityNdfOrTerm()) { 464 checkedOutlayDate = checkedWeekdays.dates[1]; 465 if (!checkedOutlayDate.workDay) { 466 invalidOutlayDate = spreadnet.utils.dates.dateToDMY(checkedOutlayDate.date.toDate()); 467 msg = "A data de inÃcio (" + invalidOutlayDate + ") não é dia útil. "; 468 if (invalidDates !== "") { 469 invalidDates += "<br/><br/>"; 470 } 471 invalidDates += msg; 472 } 473 } 474 if (invalidDates !== "") { 475 feedback.timedError(invalidDates); 476 return savingExchangeHistory = false; 477 } else { 478 return callback(exchangeToBeSaved); 479 } 480 }); 481 } 482 }; 483 saveOrEditFlow = function(exchangeHistory) { 484 if ($scope.isExchangeModalityPronto()) { 485 return ExchangeHistoryModel.save(exchangeHistory, saveExchangeHistorySuccess, saveExchangeHistoryError); 486 } else { 487 savingExchangeHistory = false; 488 return editPaymentsFlow(exchangeHistory); 489 } 490 }; 491 validateExchangeFlowValidations = function(exchangeHistory, callback) { 492 var isEditMode, onFlowValidated, onValidationError, ref; 493 isEditMode = ((ref = $scope.exchangeHistoryForm) != null ? ref.operationLabel : void 0) === "Edição"; 494 onFlowValidated = function() { 495 return callback(exchangeHistory); 496 }; 497 onValidationError = function() { 498 return savingExchangeHistory = false; 499 }; 500 return ExchangeValidationService.validateExchangeFlowValidations({ 501 exchangeHistory: exchangeHistory 502 }, 'exchange_history', isEditMode, onFlowValidated, onValidationError, true); 503 }; 504 saveExchangeHistoryDirect = function(exchangeHistory) { 505 return ExchangeHistoryModel.save(exchangeHistory, saveExchangeHistorySuccess, saveExchangeHistoryError); 506 }; 507 saveExchangeHistoryDirectContinuation = function(exchangeHistory) { 508 return checkInitialAndOutlayAreWeekdays(exchangeHistory, function(validated) { 509 if ($scope.isExchangeModalityNdfOrTerm()) { 510 return validateExchangeFlowValidations(validated, saveExchangeHistoryDirect); 511 } else { 512 return saveExchangeHistoryDirect(validated); 513 } 514 }); 515 }; 516 saveExchangeHistoryContinuation = function(exchangeHistory) { 517 return checkInitialAndOutlayAreWeekdays(exchangeHistory, saveOrEditFlow); 518 }; 519 editPaymentsFlowContinuation = function(exchangeHistory) { 520 if ($scope.isExchangeModalityNdfOrTerm()) { 521 savingExchangeHistory = false; 522 return editPaymentsFlow(exchangeHistory); 523 } else { 524 return ExchangeHistoryModel.save(exchangeHistory, saveExchangeHistorySuccess, saveExchangeHistoryError); 525 } 526 }; 527 editExchangePaymentsFlowContinuation = function(exchangeHistory) { 528 return checkInitialAndOutlayAreWeekdays(exchangeHistory, editPaymentsFlowContinuation); 529 }; 530 validateIdentifier = function(exchangeHistory, callback) { 531 var id, identifierInfo; 532 if (exchangeHistory.exchange.status === "Fechada" && exchangeHistory.exchange.identifier.trim() !== "") { 533 id = exchangeHistory._id != null ? exchangeHistory._id.$oid : "_"; 534 identifierInfo = { 535 id: id,
536 identifier: exchangeHistory.exchange.identifier 537 }; 538 return ConfigurationService.identifierAlreadyInUse(identifierInfo).then(function(result) { 539 if (result.trim() === "YES") { 540 feedback.timedError("O identificador " + exchangeHistory.exchange.identifier + " já está em uso. Favor alterar o identificador."); 541 return savingExchangeHistory = false; 542 } else { 543 return callback(exchangeHistory); 544 } 545 }); 546 } else { 547 return callback(exchangeHistory); 548 } 549 }; 550 $scope.saveExchangeHistory = function() { 551 var continuation, exchangeHistory, msg, ref, save; 552 savingExchangeHistory = true; 553 exchangeHistory = fromForm(); 554 if (msg = validateExchangeHistory(exchangeHistory)) { 555 feedback.timedError(msg); 556 return savingExchangeHistory = false; 557 } else { 558 continuation = ((ref = $scope.exchangeHistoryForm) != null ? ref.operationLabel : void 0) === "Edição" ? saveExchangeHistoryDirectContinuation : saveExchangeHistoryContinuation; 559 if (exchangeHistory.exchange.hedgeOperation.status !== exchangeHistory.exchange.status && exchangeHistory.exchange.hedgeOperation.status !== "") { 560 save = function() { 561 exchangeHistory.exchange.hedgeOperation = sn.u.resetHedgeOperation(); 562 return validateIdentifier(exchangeHistory, continuation); 563 }; 564 return eventBus.fire('exchangeHedgeRemovalConfirmation', exchangeHistory.exchange.hedgeOperation.status, save, feedback.reset); 565 } else { 566 return validateIdentifier(exchangeHistory, continuation); 567 } 568 } 569 }; 570 $scope.editExchangePaymentsFlow = function() { 571 var exchangeHistory, msg; 572 savingExchangeHistory = true; 573 exchangeHistory = fromForm(); 574 if (msg = validateExchangeHistory(exchangeHistory)) { 575 feedback.timedError(msg); 576 return savingExchangeHistory = false; 577 } else { 578 return validateIdentifier(exchangeHistory, editExchangePaymentsFlowContinuation); 579 } 580 }; 581 saveExchangeHistorySuccess = function(savedExchangeHistory) { 582 $timeout(function() { 583 return eventBus.fire(EXCHANGE_HISTORY_GENERATED, null); 584 }); 585 $scope.inGridMode(); 586 feedback.timedSuccess("Histórico de NDF, Termo salvo com sucesso."); 587 return savingExchangeHistory = false; 588 }; 589 saveExchangeHistoryError = function() { 590 feedback.timedServerError; 591 return savingExchangeHistory = false; 592 }; 593 $scope.updateNdfTermOutlayDateDisabled = function() { 594 var outlayDateInPresentOrFuture, ref; 595 if ($scope.isExchangeModalityNdfOrTerm()) { 596 if ((((ref = $scope.exchangeHistoryForm) != null ? ref.outlayDate : void 0) != null) && $scope.exchangeHistoryForm.outlayDate !== "") { 597 outlayDateInPresentOrFuture = $scope.exchangeHistoryForm.outlayDate >= dates.today().toYMD(); 598 if (outlayDateInPresentOrFuture) { 599 $scope.exchangeHistoryForm.ndfTerm.initialRateSelection.selection = "R"; 600 } 601 $scope.exchangeHistoryForm.ndfTermOutlayDateDisabled = outlayDateInPresentOrFuture; 602 return outlayDateInPresentOrFuture; 603 } else { 604 $scope.exchangeHistoryForm.ndfTermOutlayDateDisabled = false; 605 return false; 606 } 607 } else { 608 $scope.exchangeHistoryForm.ndfTermOutlayDateDisabled = false; 609 return false; 610 } 611 }; 612 $scope.ndfTermOutlayDateDisabledClass = function() { 613 var outlayDateInPresentOrFuture, ref; 614 if ($scope.isExchangeModalityNdfOrTerm()) { 615 if ((((ref = $scope.exchangeHistoryForm) != null ? ref.outlayDate : void 0) != null) && $scope.exchangeHistoryForm.outlayDate !== "") { 616 outlayDateInPresentOrFuture = $scope.exchangeHistoryForm.outlayDate >= dates.today().toYMD(); 617 if (outlayDateInPresentOrFuture) { 618 return "disabled"; 619 } else { 620 return ""; 621 } 622 } else { 623 return ""; 624 } 625 } else { 626 return ""; 627 } 628 }; 629 $scope.onOutlayDateChange = function() { 630 return $scope.updateNdfTermOutlayDateDisabled(); 631 }; 632 $scope.getOperationDateLabel = function() { 633 var ref; 634 if (((ref = $scope.exchangeHistoryForm) != null ? ref.status : void 0) === 'Cotação') { 635 return 'Data da cotação'; 636 } else { 637 return 'Data da operação'; 638 } 639 }; 640 $scope.submitMessage = function() { 641 var getSaveMessage, ref; 642 getSaveMessage = function() { 643 var ref; 644 if (((ref = $scope.exchangeHistoryForm) != null ? ref.status : void 0) === "Fechada") { 645 return 'Salvar operação'; 646 } else { 647 return 'Salvar cotação'; 648 } 649 }; 650 if (((ref = $scope.exchangeHistoryForm) != null ? ref.operationLabel : void 0) === "Edição") { 651 return getSaveMessage(); 652 } else { 653 if (!$scope.isExchangeModalityPronto()) { 654 return 'Avançar'; 655 } else { 656 return getSaveMessage(); 657 } 658 } 659 }; 660 $scope.cancelEditExchangeHistory = function() { 661 feedback.reset(); 662 return $scope.inGridMode(); 663 }; 664 $scope.isClosedQuotation = function() { 665 return $scope.exchangeHistoryForm.status === 'Fechada'; 666 }; 667 $scope.isManualNumbering = function() { 668 var ref, ref1; 669 if ((ref = $scope.config) != null ? (ref1 = ref.contractNumbering) != null ? ref1.automatic : void 0 : void 0) { 670 return false;
671 } else { 672 return true; 673 } 674 }; 675 $scope.isStatusDisabled = function() { 676 return !UserModel.hasCustomerModule('N'); 677 }; 678 $scope.changeStatus = function() { 679 return fillIdentifier(); 680 }; 681 $scope.isNewIdentifierButtonDisabled = function() { 682 return $scope.exchangeHistoryForm.identifier.trim() !== ''; 683 }; 684 $scope.newIdentifierButtonClass = function() { 685 if ($scope.isNewIdentifierButtonDisabled()) { 686 return "button dark ml10 disabled"; 687 } else { 688 return "button dark ml10"; 689 } 690 }; 691 setHistory = function() { 692 if ($scope.$parent.wasInIncludeMode) { 693 if ($scope.exchangeCurrentHistory) { 694 toForm($scope.exchangeCurrentHistory); 695 $scope.exchangeHistoryForm.operationLabel = "Inclusão"; 696 } else { 697 $scope.exchangeHistoryForm.operationLabel = "Inclusão"; 698 } 699 } else if ($scope.exchangeCurrentHistory) { 700 toForm($scope.exchangeCurrentHistory); 701 } else { 702 $scope.exchangeHistoryForm.operationLabel = "Inclusão"; 703 } 704 return fillIdentifier(); 705 }; 706 ConfigurationService.load().$promise.then(function(config) { 707 $scope.config = config; 708 return setHistory(); 709 }); 710 $scope.exchangeHedgeDialog = function() { 711 return eventBus.fire('exchangeHedgeDialog', $scope.exchangeHistoryForm); 712 }; 713 $scope.isLoanHedge = function() { 714 return $scope.exchangeHistoryForm.hedgeOperation.kind === "ExchangeHedge"; 715 }; 716 $scope.getBankName = function() { 717 return getBank($scope.exchangeHistoryForm.hedgeOperation.bankId).name; 718 }; 719 $scope.getHedgeValue = function() { 720 var currency, value; 721 currency = LoanModalityModel.currencyFor($scope.exchangeHistoryForm.hedgeOperation.modality); 722 value = ($scope.exchangeHistoryForm.hedgeOperation.value > 0) ? currency + " " + (numbers.format($scope.exchangeHistoryForm.hedgeOperation.value, 2)) : ""; 723 return value; 724 }; 725 $scope.getHedgeModality = function(modality) { 726 var ref; 727 return ((ref = labels.loanModality[modality]) != null ? ref.short : void 0) || ''; 728 }; 729 return $scope.changeHedgeKind = function() { 730 var kind; 731 kind = $scope.exchangeHistoryForm.hedgeOperation.kind; 732 if (kind !== "ExchangeHedge") { 733 return $scope.exchangeHistoryForm.hedgeOperation = sn.u.resetHedgeOperation(kind); 734 } 735 }; 736 }; 737 738 (function() { 739 var config; 740 config = ['$scope', 'ExchangeModalityModel', 'LoanModalityModel', 'CustomerBankModel', 'WarrantyModel', 'ExchangeHistoryModel', 'InstallmentsService', '$timeout', 'feedback', 'ConfigurationService', 'UserModel', 'ExchangeQuotationModel', 'ExchangeValidationService', EditExchangeHistoryController]; 741 return module.controller('spreadnet.exchangeHistoryEditCtrl', config); 742 })(); 743 744 if (this.spreadnet == null) { 745 this.spreadnet = {}; 746 } 747 748 this.spreadnet.exchangeFilesDialogCtrl = function($scope, $http, Upload, $window, $timeout, ExchangeHistoryModel, ExchangeModalityModel, CustomerBankModel, BanksModel, PendingRequests, feedback, $q, MessiService) { 749 var alreadyNames, attachmentByName, editionFocus, emptyExchange, eventBus, exchangeHistoryItem, finishScreen, hide, nextSDtimeout, nextUEWtimeout, save, signalDeleted, triggerUploadErrorWarning, uploadErrorWarning; 750 eventBus = spreadnet.eventBus; 751 editionFocus = spreadnet.editionFocus; 752 emptyExchange = { 753 attachments: [] 754 }; 755 alreadyNames = []; 756 exchangeHistoryItem = {}; 757 $scope.exchange = emptyExchange; 758 $scope.attachments = []; 759 $scope.showing = false; 760 $scope.show = function(item) { 761 exchangeHistoryItem = item; 762 $scope.exchange = (item != null ? item.exchange : void 0) || emptyExchange; 763 $scope.attachments = angular.copy($scope.exchange.attachments); 764 return $scope.showing = true; 765 }; 766 $scope.splitJoin = function(str, len) { 767 var re; 768 re = new RegExp(".{1," + len + "}", 'g'); 769 return str.match(re).join('\u200B'); 770 }; 771 save = function() { 772 var failedUploads, performSave; 773 failedUploads = function() { 774 var attachment, i, len1, ref; 775 ref = $scope.attachments; 776 for (i = 0, len1 = ref.length; i < len1; i++) { 777 attachment = ref[i]; 778 if (attachment.status === 'uploadError') { 779 return true; 780 } 781 } 782 }; 783 performSave = function() { 784 var attachment, newAttachments; 785 newAttachments = (function() { 786 var i, len1, ref, results; 787 ref = $scope.attachments; 788 results = []; 789 for (i = 0, len1 = ref.length; i < len1; i++) { 790 attachment = ref[i]; 791 if (!attachment.status) { 792 results.push({ 793 _id: attachment._id, 794 name: attachment.name.replaceCharsForUpload(), 795 date: attachment.date 796 }); 797 } 798 } 799 return results; 800 })(); 801 newAttachments.sort(function(a, b) { 802 var s; 803 s = function(a, b) { 804 if (a === b) { 805 return 0; 806 } else if (a < b) { 807 return -1; 808 } else { 809 return 1; 810 } 811 }; 812 return s(a.name, b.name); 813 }); 814 exchangeHistoryItem.exchange.attachments = newAttachments; 815 return ExchangeHistoryModel.save(exchangeHistoryItem, function(savedExchangeHistory) { 816 exchangeHistoryItem = savedExchangeHistory; 817 finishScreen(); 818 return feedback.timedSuccess("Documentos atualizados com sucesso."); 819 }); 820 }; 821 if (failedUploads()) { 822 return MessiService.confirmDialog("Os arquivos cujo carregamento falharam serão excluÃdos. Continuar?").then(function(answer) { 823 if (answer) { 824 return performSave(); 825 } 826 }); 827 } else { 828 return performSave(); 829 } 830 }; 831 $scope.ok = function() { 832 return save(); 833 }; 834 finishScreen = function() { 835 hide(); 836 return $timeout(function() { 837 $scope.exchange = emptyExchange; 838 $scope.attachments = []; 839 return exchangeHistoryItem = {}; 840 }); 841 }; 842 $scope.cancel = function() { 843 return finishScreen(); 844 }; 845 hide = function() { 846 $scope.showing = false;
847 return editionFocus.close(); 848 }; 849 eventBus.subscribe('exchangeFilesDialog', $scope.show, $scope); 850 $scope.header = function() { 851 var currBank, currency, date, modality, ref, value; 852 if (!exchangeHistoryItem.exchange) { 853 return ''; 854 } else { 855 currBank = function() { 856 var bank, id; 857 id = exchangeHistoryItem.exchange.bank.id; 858 bank = CustomerBankModel.byId(id); 859 if (!bank._id) { 860 bank = BanksModel.byId(id); 861 } 862 return bank; 863 }; 864 currency = exchangeHistoryItem.exchange.currency; 865 value = sn.n.format(exchangeHistoryItem.exchange.value, 2); 866 modality = ((ref = ExchangeModalityModel.byCode(exchangeHistoryItem.exchange.modality)) != null ? ref.title : void 0) || ''; 867 date = exchangeHistoryItem.exchange.outlayDate.toDate().toDMY(); 868 return currency + " " + value + " | " + modality + " | " + (currBank().name) + " | " + date; 869 } 870 }; 871 $scope.uploading = function() { 872 return PendingRequests.pending(function(url) { 873 return url === 'upload'; 874 }); 875 }; 876 $scope.notDeleted = function(attachment) { 877 var ref; 878 return (ref = attachment.status) !== 'deleted' && ref !== 'deleted2'; 879 }; 880 attachmentByName = function(name) { 881 var att, i, len1, ref; 882 ref = $scope.attachments; 883 for (i = 0, len1 = ref.length; i < len1; i++) { 884 att = ref[i]; 885 if (att.name === name) { 886 return att; 887 } 888 } 889 }; 890 $scope.onFileSelect = function($files) { 891 var file, largeFiles, largeFilesStr, message, uploadFiles; 892 if (!$files) { 893 return; 894 } 895 uploadFiles = function() { 896 var file, i, inputFile, len1, process, results, upload; 897 results = []; 898 for (i = 0, len1 = $files.length; i < len1; i++) { 899 inputFile = $files[i]; 900 if (!(inputFile.size <= 15728640)) { 901 continue; 902 } 903 file = new File([inputFile], inputFile.name.replaceCharsForUpload()); 904 upload = function(file, already) { 905 var addToAttachments, upItem; 906 addToAttachments = function() { 907 var att, withUploadError, withoutUploadError; 908 $scope.attachments.unshift({ 909 _id: sn.u.UUID(), 910 name: file.name, 911 date: sn.d.fileLastModifiedDate(file).toYMD() 912 }); 913 withUploadError = (function() { 914 var j, len2, ref, results1; 915 ref = $scope.attachments; 916 results1 = []; 917 for (j = 0, len2 = ref.length; j < len2; j++) { 918 att = ref[j]; 919 if (att.status === 'uploadError') { 920 results1.push(att); 921 } 922 } 923 return results1; 924 })(); 925 withoutUploadError = (function() { 926 var j, len2, ref, results1; 927 ref = $scope.attachments; 928 results1 = []; 929 for (j = 0, len2 = ref.length; j < len2; j++) { 930 att = ref[j]; 931 if (att.status !== 'uploadError') { 932 results1.push(att); 933 } 934 } 935 return results1; 936 })(); 937 if (withUploadError.length) { 938 return $scope.attachments = withUploadError.concat(withoutUploadError); 939 } 940 }; 941 return upItem = Upload.upload({ 942 url: 'upload', 943 data: { 944 offerId: exchangeHistoryItem._id.$oid, 945 date: sn.d.fileLastModifiedDate(file).toYMD() 946 }, 947 file: file 948 }).success(function() { 949 var att; 950 if (!already) { 951 addToAttachments(); 952 } 953 if (att = attachmentByName(file.name)) { 954 return att.status = ''; 955 } 956 }).error(function() { 957 var att; 958 if (!already) { 959 addToAttachments(); 960 } 961 if (att = attachmentByName(file.name)) { 962 att.status = 'uploadError'; 963 } 964 return triggerUploadErrorWarning(); 965 }); 966 }; 967 results.push((process = function(file) { 968 var att, attachment, confirmReplace, invalidCharMsg, ref, ref1; 969 alreadyNames = (function() { 970 var j, len2, ref, results1; 971 ref = $scope.attachments; 972 results1 = []; 973 for (j = 0, len2 = ref.length; j < len2; j++) { 974 att = ref[j]; 975 results1.push(att.name); 976 } 977 return results1; 978 })(); 979 attachment = attachmentByName(file.name); 980 confirmReplace = function() { 981 return MessiService.confirmDialog("Já existe o arquivo " + file.name + ". Deseja substituÃ-lo?").then(function(answer) { 982 if (answer) { 983 return upload(file, true); 984 } 985 }); 986 }; 987 invalidCharMsg = function() { 988 if (inputFile.name !== file.name) { 989 return MessiService.alertDialog("<b>Foram alterados caracteres não permitidos no nome do arquivo</b><br><br><b>Nome anterior:</b><br>" + inputFile.name + "<br><br><b>Nome novo:</b><br>" + file.name); 990 } 991 }; 992 if (ref = file.name, indexOf.call(alreadyNames, ref) >= 0) { 993 if (attachment.status === 'deleted') { 994 MessiService.confirmDialog("O arquivo " + file.name + " foi removido. Deseja restaurá-lo?").then(function(answer) { 995 if (answer) { 996 attachment.status = ''; 997 return confirmReplace(); 998 } 999 }); 1000 } else if ((ref1 = attachment.status) === 'deleted2' || ref1 === 'uploadError') { 1001 upload(file, true); 1002 } else if (!attachment.status) { 1003 confirmReplace(); 1004 } 1005 } else { 1006 upload(file); 1007 } 1008 return invalidCharMsg(); 1009 })(file)); 1010 } 1011 return results; 1012 }; 1013 largeFiles = (function() { 1014 var i, len1, results; 1015 results = []; 1016 for (i = 0, len1 = $files.length; i < len1; i++) { 1017 file = $files[i]; 1018 if (file.size > 15728640) { 1019 results.push(file.name.replaceCharsForUpload()); 1020 } 1021 } 1022 return results; 1023 })(); 1024 if (largeFiles.length) { 1025 largeFilesStr = largeFiles.join("<br/>"); 1026 message = largeFiles.length > 1 ? "Os arquivos<br/>" + largeFilesStr + "<br/>tem mais de 15MB e não serão carregados." : "O arquivo<br/>" + largeFiles[0] + "<br/>tem mais de 15MB e não será carregado."; 1027 feedback.timedWarning(message); 1028 } 1029 return uploadFiles(); 1030 }; 1031 uploadErrorWarning = false;
1032 nextUEWtimeout = ''; 1033 triggerUploadErrorWarning = function() { 1034 uploadErrorWarning = true; 1035 if (nextUEWtimeout) { 1036 $timeout.cancel(nextUEWtimeout); 1037 } 1038 return nextUEWtimeout = $timeout((function() { 1039 return uploadErrorWarning = false; 1040 }), 5000); 1041 }; 1042 $scope.uploadError = function(att) { 1043 return att.status === 'uploadError'; 1044 }; 1045 $scope.uploadErrorWarning = function() { 1046 return uploadErrorWarning; 1047 }; 1048 $scope.removeAttachment = function(todel) { 1049 var att, i, len1, ref, results; 1050 ref = $scope.attachments; 1051 results = []; 1052 for (i = 0, len1 = ref.length; i < len1; i++) { 1053 att = ref[i]; 1054 if (att._id === todel._id) { 1055 if (att.status === 'uploadError') { 1056 results.push(att.status = 'deleted2'); 1057 } else { 1058 att.status = 'deleted'; 1059 results.push(signalDeleted(att)); 1060 } 1061 } 1062 } 1063 return results; 1064 }; 1065 $scope.lastDeleted = {}; 1066 nextSDtimeout = ''; 1067 signalDeleted = function(att) { 1068 if (nextSDtimeout) { 1069 $timeout.cancel(nextSDtimeout); 1070 } 1071 $scope.lastDeleted = att; 1072 return nextSDtimeout = $timeout((function() { 1073 return $scope.lastDeleted = {}; 1074 }), 5000); 1075 }; 1076 $scope.recoverDeleted = function() { 1077 if ($scope.lastDeleted._id) { 1078 $scope.lastDeleted.status = ''; 1079 return $scope.lastDeleted = {}; 1080 } 1081 }; 1082 $scope.downloadUrl = ''; 1083 $scope.download = function(att) { 1084 var downloadErrorResponse, param; 1085 downloadErrorResponse = function() { 1086 return feedback.timedError("Erro na obtenção do arquivo " + att.name + "."); 1087 }; 1088 if (!att.status) { 1089 param = { 1090 offerId: exchangeHistoryItem._id.$oid, 1091 name: att.name 1092 }; 1093 return $http.post('download', param).success(function(data) { 1094 var link, trimmedData; 1095 trimmedData = (data != null ? data.trim() : void 0) || ''; 1096 if (/^http/.test(trimmedData)) { 1097 link = $("#attachmentDownload"); 1098 link.attr('href', data); 1099 return link[0].click(); 1100 } else { 1101 return downloadErrorResponse(); 1102 } 1103 }).error(function() { 1104 return downloadErrorResponse(); 1105 }); 1106 } 1107 }; 1108 return $scope.mostraAtt = function() { 1109 return console.log($scope.attachments); 1110 }; 1111 }; 1112 1113 if (this.spreadnet == null) { 1114 this.spreadnet = {}; 1115 } 1116 1117 this.spreadnet.exchangeHedgeDialogCtrl = function($scope, $window, HistoryModel, cellWidth, $q, feedback) { 1118 var cellWidths, editionFocus, eventBus, exchangeHistoryItem, findLoan, hide, hm, labels; 1119 eventBus = spreadnet.eventBus; 1120 editionFocus = spreadnet.editionFocus; 1121 labels = spreadnet.utils.labels; 1122 $scope.showing = false; 1123 $scope.selected = { 1124 selected: "" 1125 }; 1126 hm = HistoryModel; 1127 exchangeHistoryItem = {}; 1128 $scope.initSelected = function() { 1129 return $scope.selected.selected = findLoan($scope.exchangeHistoryForm.hedgeOperation.id); 1130 }; 1131 findLoan = function(id) { 1132 var i, item, len1, ref; 1133 ref = hm != null ? hm.collection : void 0; 1134 for (i = 0, len1 = ref.length; i < len1; i++) { 1135 item = ref[i]; 1136 if (item._id.$oid === id) { 1137 return item; 1138 } 1139 } 1140 return ""; 1141 }; 1142 hide = function() { 1143 $scope.showing = false; 1144 return editionFocus.close(); 1145 }; 1146 $scope.show = function(item) { 1147 $scope.initSelected(); 1148 exchangeHistoryItem = item; 1149 return $scope.showing = true; 1150 }; 1151 $scope.ok = function() { 1152 if ($scope.exchangeHistoryForm.hedgeOperation.id === $scope.selected.selected._id.$oid) { 1153 return hide(); 1154 } else { 1155 $scope.exchangeHistoryForm.hedgeOperation.kind = "ExchangeHedge"; 1156 $scope.exchangeHistoryForm.hedgeOperation.id = $scope.selected.selected._id.$oid; 1157 $scope.exchangeHistoryForm.hedgeOperation.modality = $scope.selected.selected.offer.loanModality; 1158 $scope.exchangeHistoryForm.hedgeOperation.creditDate = $scope.selected.selected.offer.outlayDate.toDate().toXDate(
1158).toString("dd/MM/yy"); 1159 $scope.exchangeHistoryForm.hedgeOperation.bankId = $scope.selected.selected.offer.bank.id; 1160 $scope.exchangeHistoryForm.hedgeOperation.value = $scope.selected.selected.offer.value; 1161 $scope.exchangeHistoryForm.hedgeOperation.contractNumber = $scope.selected.selected.contractNumber; 1162 $scope.exchangeHistoryForm.hedgeOperation.identifier = $scope.selected.selected.offer.identifier; 1163 $scope.exchangeHistoryForm.hedgeOperation.status = $scope.selected.selected.offer.status; 1164 return hide(); 1165 } 1166 }; 1167 $scope.cancel = function() { 1168 return hide(); 1169 }; 1170 $scope.modality = function(modality) { 1171 var ref; 1172 return ((ref = labels.loanModality[modality]) != null ? ref.short : void 0) || ''; 1173 }; 1174 $scope.checkStatus = function(offer) { 1175 return $scope.exchangeHistoryForm.status === offer.status && offer.hedgeOperations[0].kind !== "SwapHedge"; 1176 }; 1177 cellWidths = [[5, 5], [5, 5], [6, 6], [5, 5], [5, 5], [5, 5], [6, 6], [6, 6], [1, 1], [2, 2]]; 1178 $scope.cellWidthPopUp = cellWidth.setWidths(cellWidths, function() { 1179 return false; 1180 }); 1181 eventBus.subscribe('exchangeHedgeDialog', $scope.show, $scope); 1182 return $scope.$on('initHedgeDialog', $scope.initSelected, $scope); 1183 }; 1184 1185 module = this.angular.module('snExchangeHistory'); 1186 1187 ExchangeHistoryController = function($scope, $location, ExchangeHistoryModel, ExchangeHistorySettings, feedback) { 1188 var EDIT_EXCHANGE_PAYMENTS_FLOW, editionFocus, eventBus, events, labels, memCalcEdit, memCalcEditFlow, scroller; 1189 labels = spreadnet.utils.labels; 1190 events = spreadnet.events; 1191 eventBus = spreadnet.eventBus; 1192 scroller = spreadnet.utils.scroll.Scroller(); 1193 editionFocus = spreadnet.editionFocus; 1194 EDIT_EXCHANGE_PAYMENTS_FLOW = events.EDIT_EXCHANGE_PAYMENTS_FLOW; 1195 $scope.mode = "grid"; 1196 $scope.calculating = false; 1197 $scope.exporting = false; 1198 $scope.exchangeCurrentHistory = null; 1199 $scope.settings = ExchangeHistorySettings; 1200 $scope.stepDetailsSwitch = ExchangeHistorySettings.stepDetailsSwitch; 1201 $scope.exchangeHistoryPresent = true; 1202 $scope.startCalculation = function() { 1203 return $scope.calculating = true; 1204 }; 1205 $scope.stopCalculation = function() { 1206 return $scope.calculating = false; 1207 }; 1208 $scope.exchangeMemCalcMode = function() { 1209 return $scope.pathInfo.subpath === '/exchangememcalc'; 1210 }; 1211 $scope.newExchangeHistory = function() { 1212 $scope.kmqRecord("Histórico de NDF, Termo criado"); 1213 $scope.exchangeCurrentHistory = null; 1214 $scope.mode = "include"; 1215 $scope.wasInIncludeMode = true; 1216 if ($scope.gridMode) { 1217 scroller.saveTop(); 1218 } 1219 return editionFocus.show(); 1220 }; 1221 $scope.errorCallback = function(err) { 1222 return feedback.timedError(err); 1223 }; 1224 $scope.editExchangeHistory = function(exchangeHistory) { 1225 $scope.exchangeCurrentHistory = exchangeHistory; 1226 return $scope.inEditMode(); 1227 }; 1228 $scope.inEditMode = function() { 1229 if ($scope.gridMode) { 1230 scroller.saveTop(); 1231 } 1232 $scope.mode = "edit"; 1233 $scope.wasInIncludeMode = false; 1234 return editionFocus.show(); 1235 }; 1236 $scope.backToEditOrInclude = function() { 1237 if ($scope.wasInIncludeMode) { 1238 $scope.mode = "include"; 1239 } else { 1240 $scope.mode = "edit"; 1241 } 1242 if ($scope.gridMode) { 1243 scroller.saveTop(); 1244 } 1245 return editionFocus.show(); 1246 }; 1247 $scope.inGridMode = function() { 1248 editionFocus.close(); 1249 if ($scope.editMode) { 1250 scroller.restore(); 1251 } 1252 return $scope.mode = "grid"; 1253 }; 1254 $scope.inPaymentsFlowMode = function(exchangeHistory, oper) { 1255 $scope.exchangeCurrentHistory = exchangeHistory; 1256 $scope.pmtsCfg = { 1257 opr: oper, 1258 data: exchangeHistory 1259 }; 1260 return $scope.mode = "pmts"; 1261 }; 1262 $scope.getExchangeModalityShort = function(modality) { 1263 var ref; 1264 return (ref = ExchangeModalityModel.byCode(modality)) != null ? ref.title : void 0; 1265 }; 1266 memCalcEdit = function(exchangeHistory) { 1267 var returnToMemCalc; 1268 returnToMemCalc = true; 1269 $location.path("/exchangehistory"); 1270 return $scope.toForm(exchangeHistory); 1271 };
1272 memCalcEditFlow = function(exchangeHistory) { 1273 $scope.inPaymentsFlowMode(); 1274 $location.path("/exchangehistory"); 1275 return eventBus.fire(EDIT_EXCHANGE_PAYMENTS_FLOW, 'exchangememcalc', exchangeHistory); 1276 }; 1277 $scope.memCalcDelete = function(exchangeHistory) { 1278 ExchangeHistoryModel["delete"](exchangeHistory, $scope.deleteExchangeHistorySuccess, feedback.timedServerError); 1279 return $location.path("/exchangehistory"); 1280 }; 1281 $scope.deleteExchangeHistorySuccess = function(index) { 1282 return feedback.timedSuccess("Histórico de NDF, Termo removido com sucesso."); 1283 }; 1284 $scope.inMemCalc = function(exchangeHistory, stepIndex) { 1285 var location; 1286 if (stepIndex == null) { 1287 stepIndex = -1; 1288 } 1289 location = "/exchangehistory/exchangememcalc/" + exchangeHistory._id.$oid; 1290 if (stepIndex >= 0) { 1291 location += "/step/" + stepIndex; 1292 } 1293 return $location.path(location); 1294 }; 1295 return $scope["export"] = function() { 1296 $scope.exporting = ExchangeHistoryModel.calculating; 1297 return ExchangeHistoryModel.reportFile().then(function(result) { 1298 var link, trimmedResult; 1299 trimmedResult = (result != null ? result.trim() : void 0) || ''; 1300 if (/^http/.test(trimmedResult)) { 1301 link = $("#exchangeHistoryFileDownload"); 1302 link.attr('href', result); 1303 link[0].click(); 1304 return $scope.exporting = false; 1305 } 1306 }); 1307 }; 1308 }; 1309 1310 (function() { 1311 var config; 1312 config = ['$scope', '$location', 'ExchangeHistoryModel', 'ExchangeHistorySettings', 'feedback', ExchangeHistoryController]; 1313 return module.controller('spreadnet.exchangeHistoryCtrl', config); 1314 })(); 1315 1316 module = this.angular.module('snExchangeHistory'); 1317 1318 ExchangeHistoryGridController = function($scope, ExchangeHistoryModel, feedback, $timeout, ExchangeModalityModel, ExchangeHistorySettings, UserModel, Debounce, cellWidth) { 1319 var EXCHANGE_HISTORY_GENERATED, cellWidths, dates, eventBus, events, filterError, filterIsEmpty, initExchangeHistory, reorder, updateFilterClass; 1320 dates = spreadnet.utils.dates; 1321 eventBus = spreadnet.eventBus; 1322 events = spreadnet.events; 1323 EXCHANGE_HISTORY_GENERATED = events.EXCHANGE_HISTORY_GENERATED; 1324 $scope.model = ExchangeHistoryModel; 1325 $scope.settings = ExchangeHistorySettings; 1326 $scope.stepDetailsSwitch = ExchangeHistorySettings.stepDetailsSwitch; 1327 $scope.previousContractNo = ""; 1328 $scope.filterChanged = ExchangeHistoryModel.filterChanged; 1329 $scope.filterParams = ExchangeHistoryModel.filterParams; 1330 $scope.filterSpec = ExchangeHistoryModel.filterSpec; 1331 $scope.filterFirstTime = true; 1332 $scope.isAllCustomers = function() { 1333 return UserModel.isAllCustomers(); 1334 }; 1335 $scope.filterHeightClass = function() { 1336 if ($scope.isAllCustomers()) { 1337 return 'filter cf flexColumn flexAroundSpacing w1226 h130'; 1338 } else { 1339 return 'filter cf flexColumn flexAroundSpacing w1226 h90'; 1340 } 1341 }; 1342 $scope.verticalDividerClass = function() { 1343 if ($scope.isAllCustomers()) { 1344 return 'verticalDivider h128'; 1345 } else { 1346 return 'verticalDivider h88'; 1347 } 1348 }; 1349 $scope.bankSelectClass = function() { 1350 if ($scope.isAllCustomers()) { 1351 return 'field cf pt5'; 1352 } else { 1353 return 'field cf'; 1354 } 1355 }; 1356 (updateFilterClass = function() { 1357 return $scope.filterClass = $scope.filterChanged ? "button" : "button dark"; 1358 })(); 1359 $scope.contractFilter = function(item) { 1360 return true; 1361 }; 1362 $scope.filter = function() { 1363 if (!UserModel.hasCustomerModule('N')) { 1364 $scope.filterSpec.status = ['Fechada']; 1365 } 1366 $scope.startCalculation(); 1367 $scope.filterParams.status = $scope.filterSpec.status != null ? $scope.filterSpec.status : []; 1368 $scope.filterParams.bank = $scope.filterSpec.bank != null ? $scope.filterSpec.bank : []; 1369 $scope.filterParams.modality = $scope.filterSpec.modality != null ? $scope.filterSpec.modality : ['NDF', 'TER']; 1370 $scope.filterParams.contractBillNumber = $scope.filterSpec.contractBillNumber != null ? $scope.filterSpec.contractBillNumber : ''; 1371 $scope.filterParams.dateType = $scope.filterSpec.dateType; 1372 $scope.filterParams.refDate = $scope.filterSpec.refDate; 1373 $scope.filterParams.customers = $scope.isAllCustomers() ? $scope.filterSpec.customers : []; 1374 $scope.filterChanged = false;
1375 updateFilterClass(); 1376 return $timeout(function() { 1377 return ExchangeHistoryModel.filterByParam($scope.filterParams, initExchangeHistory, filterError); 1378 }); 1379 }; 1380 $scope.filterButtonClick = function() { 1381 return $scope.filter(); 1382 }; 1383 filterIsEmpty = function() { 1384 return ($scope.filterParams.status === null || $scope.filterParams.status.length === 0) && ($scope.filterParams.bank === null || $scope.filterParams.bank.length === 0) && ($scope.filterParams.modality === null || $scope.filterParams.modality.length === 0) && $scope.filterParams.contractBillNumber === "" && ($scope.filterParams.dateType === '' || $scope.filterParams.dateType === "0"); 1385 }; 1386 filterError = function() { 1387 $scope.stopCalculation(); 1388 $scope.filterFirstTime = false; 1389 return feedback.timedServerError(); 1390 }; 1391 initExchangeHistory = function(list) { 1392 $scope.settings.orderedBy = $scope.isAllCustomers() ? "customerName" : "outlayDate"; 1393 $scope.settings.lastOrderedBy = $scope.settings.orderedBy; 1394 reorder(); 1395 $scope.exchangeHistoryPresent = ExchangeHistoryModel.collection.length > 0 || !filterIsEmpty(); 1396 $scope.stepDetailsSwitch = ExchangeHistorySettings.stepDetailsSwitch = {}; 1397 $scope.filterFirstTime = false; 1398 return $scope.stopCalculation(); 1399 }; 1400 $scope.changeFilter = function() { 1401 $scope.filterChanged = true; 1402 return updateFilterClass(); 1403 }; 1404 $scope.changeContractBillNo = function() { 1405 if ($scope.filterSpec.contractBillNumber !== $scope.previousContractNo) { 1406 $scope.previousContractNo = $scope.filterSpec.contractBillNumber; 1407 return $scope.changeFilter(); 1408 } 1409 }; 1410 $scope.changeContractBillNoWithLag = Debounce($scope.changeContractBillNo, 1000); 1411 $scope.changeOrder = function(order) { 1412 $scope.settings.orderedBy = order; 1413 if ($scope.settings.lastOrderedBy === $scope.settings.orderedBy) { 1414 $scope.settings.lastOrderedBy = ""; 1415 ExchangeHistoryModel.orderBy(order, 1); 1416 } else { 1417 $scope.settings.lastOrderedBy = $scope.settings.orderedBy; 1418 ExchangeHistoryModel.orderBy(order, -1); 1419 } 1420 return $scope.stopCalculation(); 1421 }; 1422 $scope.currency = function(exchange) { 1423 return exchange.currency; 1424 }; 1425 reorder = function() { 1426 var sign; 1427 sign = $scope.settings.lastOrderedBy ? -1 : 1; 1428 return ExchangeHistoryModel.orderBy($scope.settings.orderedBy, sign); 1429 }; 1430 eventBus.subscribe(EXCHANGE_HISTORY_GENERATED, reorder, $scope); 1431 $scope.exchangeHistorySize = function() { 1432 var filtered, length; 1433 filtered = _.filter(ExchangeHistoryModel.collection, $scope.contractFilter); 1434 length = filtered.length; 1435 if (_.isNumber(length)) { 1436 if (length !== 1) { 1437 return length + " operações"; 1438 } else { 1439 return "1 operação"; 1440 } 1441 } else { 1442 return "0 operações"; 1443 } 1444 }; 1445 $scope["delete"] = function(exchangeHistory) { 1446 return ExchangeHistoryModel["delete"](exchangeHistory, $scope.deleteExchangeHistorySuccess, feedback.timedServerError); 1447 }; 1448 $scope.deleteExchangeHistorySuccess = function(index) { 1449 return feedback.timedSuccess("Operação de NDF, Termo removida com sucesso."); 1450 }; 1451 $scope.getFormattedValue = function(item) { 1452 if (item !== '') { 1453 return numbers.format(parseFloat(item.replace(',', '.')), 2); 1454 } else { 1455 return ''; 1456 } 1457 }; 1458 $scope.getThClass = function(order) { 1459 if (order === $scope.settings.orderedBy) { 1460 return 'orderedBy'; 1461 } else { 1462 return ''; 1463 } 1464 }; 1465 $scope.getIconOrderClass = function() { 1466 if ($scope.settings.lastOrderedBy) { 1467 return 'fa fa-caret-up'; 1468 } else { 1469 return 'fa fa-caret-down'; 1470 } 1471 }; 1472 $scope.pendingHistoryPage = ExchangeHistoryModel.pendingHistoryPage; 1473 cellWidths = [[9, 0], [5, 5], [5, 5], [7, 7], [7, 7], [7, 7], [2, 2], [8, 8], [4, 4], [5, 5], [5, 5], [7, 7], [4, 4], [6, 6], [3, 3], [2, 2]]; 1474 return $scope.cellWidth = cellWidth.setWidths(cellWidths, $scope.isAllCustomers); 1475 }; 1476 1477 (function() { 1478 var config;
1479 config = ['$scope', 'ExchangeHistoryModel', 'feedback', '$timeout', 'ExchangeModalityModel', 'ExchangeHistorySettings', 'UserModel', 'Debounce', 'cellWidth', ExchangeHistoryGridController]; 1480 return module.controller('spreadnet.exchangeHistoryGridCtrl', config); 1481 })(); 1482 1483 module = this.angular.module('snExchangeHistory'); 1484 1485 ExchangeHistoryItemController = function($scope, CustomerBankModel, ExchangeModalityModel, ExchangeHistoryModel, LoanModalityModel, ExchangeHistorySettings, BanksModel, UserModel, feedback) { 1486 var dates, duplicateError, duplicateSuccess, eventBus, events, hasAttachment, hasContractNumber, hasIdentifier, item, labels, numbers; 1487 numbers = spreadnet.utils.numbers; 1488 dates = spreadnet.utils.dates; 1489 events = spreadnet.events; 1490 eventBus = spreadnet.eventBus; 1491 labels = spreadnet.utils.labels; 1492 item = $scope.item; 1493 $scope.issueDate = item.exchange.issueDate.toDate().toDMY(); 1494 $scope.settings = ExchangeHistorySettings; 1495 $scope.stepDetailsSwitch = ExchangeHistorySettings.stepDetailsSwitch; 1496 $scope.logItem = function() { 1497 console.log('exchangeHistory'); 1498 return console.log($scope.item); 1499 }; 1500 $scope.isAllCustomers = function() { 1501 return UserModel.isAllCustomers(); 1502 }; 1503 $scope.customerName = function() { 1504 return UserModel.customerName(item.customerId.$oid); 1505 }; 1506 $scope.editItem = function() { 1507 return $scope.editExchangeHistory($scope.item); 1508 }; 1509 $scope.duplicateItem = function() { 1510 $scope.startCalculation(); 1511 return ExchangeHistoryModel.duplicate(item, duplicateSuccess, duplicateError); 1512 }; 1513 duplicateSuccess = function() { 1514 $scope.stopCalculation(); 1515 return feedback.timedSuccess("Operação duplicada com sucesso"); 1516 }; 1517 duplicateError = function() { 1518 $scope.stopCalculation(); 1519 return feedback.timedError("Erro ao duplicar operação"); 1520 }; 1521 $scope.deleteItem = function() { 1522 var bank, modality, outlayDate, ref, value; 1523 modality = ((ref = ExchangeModalityModel.byCode($scope.item.exchange.modality)) != null ? ref.title : void 0) || ''; 1524 value = item.exchange.currency + ' ' + numbers.format(item.exchange.value, 2); 1525 outlayDate = dates.longToDMY(item.exchange.outlayDate); 1526 bank = (function() { 1527 var id; 1528 id = item.exchange.bank.id; 1529 bank = CustomerBankModel.byId(id); 1530 if (!bank._id) { 1531 bank = BanksModel.byId(id); 1532 } 1533 return bank; 1534 })(); 1535 return eventBus.fire(events.MODAL, { 1536 ok: function() { 1537 return $scope.$parent["delete"]($scope.item); 1538 }, 1539 okLabel: 'Excluir operação', 1540 cancelLabel: 'Cancelar', 1541 title: 'Exclusão de operação', 1542 html: "Ao excluir uma operação de NDF, Termo, todos seus dados serão permanentemente removidos.<br/>\nTem certeza que deseja excluir a operação de <strong>" + modality + "</strong>, de <strong>" + value + "</strong>,\ndo banco <strong>" + bank.name + "</strong>, de <strong>" + outlayDate + "</strong>?" 1543 }); 1544 }; 1545 $scope.operationValue = function() { 1546 switch (item.exchange.operation) { 1547 case "B": 1548 return "C"; 1549 case "S": 1550 return "V"; 1551 default: 1552 return ""; 1553 } 1554 }; 1555 $scope.exchangeClasses = function() { 1556 var classes; 1557 classes = []; 1558 if ($scope.item.exchange.status === 'Fechada') { 1559 classes.push('exchangeClosed'); 1560 } 1561 return classes; 1562 }; 1563 $scope.stepDetails = function() { 1564 var ref; 1565 if ((ref = item.exchange.modality) === "NDF" || ref === "TER") { 1566 return item.exchange.ndfTerm.steps; 1567 } else { 1568 return []; 1569 } 1570 }; 1571 $scope.editFlow = function() { 1572 return $scope.inPaymentsFlowMode($scope.item, "exchange_history"); 1573 }; 1574 $scope.showMemCalc = function() { 1575 var ref; 1576 return (ref = item.exchange.modality) === "NDF" || ref === "TER"; 1577 }; 1578 $scope.showSteps = function() { 1579 var ref; 1580 return (ref = item.exchange.modality) === "NDF" || ref === "TER"; 1581 }; 1582 $scope.showStepDetails = function() { 1583 return $scope.showSteps() && item.exchange.numberOfSteps >= 1; 1584 }; 1585 $scope.showEdit = function() { 1586 return !isReadOnlyUserOrAllCustomers(); 1587 }; 1588 $scope.showDelete = function() { 1589 return !isReadOnlyUserOrAllCustomers(); 1590 }; 1591 $scope.memCalc = function() { 1592 $scope.kmqRecord('Memória de Cálculo'); 1593 return $scope.inMemCalc(item); 1594 }; 1595 $scope.filesDialog = function() { 1596 $scope.kmqRecord('Documentos'); 1597 return eventBus.fire('exchangeFilesDialog', item); 1598 }; 1599 $scope.endDate = function() { 1600 var ref, ref1, ref2, ref3; 1601 if (item.exchange.settled) { 1602 return ((ref = item.exchange) != null ? (ref1 = ref.settled) != null ? ref1.toDate().toXDate(
1602).toString("dd/MM/yy") : void 0 : void 0) || ""; 1603 } else { 1604 return ((ref2 = item.exchange) != null ? (ref3 = ref2.dueDate) != null ? ref3.toDate().toXDate().toString("dd/MM/yy") : void 0 : void 0) || ""; 1605 } 1606 }; 1607 $scope.spreadUnit = function() { 1608 if (item.exchange.modality === "PRO") { 1609 return "Flat"; 1610 } else { 1611 return "a.a."; 1612 } 1613 }; 1614 $scope.exchangeItemsClass = function() { 1615 var exchangeItemsClass; 1616 exchangeItemsClass = "row row_nn rowExchange cf"; 1617 if ($scope.showStepDetails()) { 1618 if ($scope.stepDetailsSwitch[$scope.item._id.$oid] != null) { 1619 if ($scope.stepDetailsSwitch[$scope.item._id.$oid]) { 1620 exchangeItemsClass += " rowExpanded"; 1621 } 1622 } 1623 } 1624 return exchangeItemsClass; 1625 }; 1626 $scope.stepDetailsClass = function() { 1627 var stepDetailsClass; 1628 stepDetailsClass = "text1 textRight"; 1629 if ($scope.showStepDetails()) { 1630 stepDetailsClass += " link"; 1631 } 1632 return stepDetailsClass; 1633 }; 1634 $scope.toggleStepDetails = function(event) { 1635 if ($scope.showStepDetails()) { 1636 if ($scope.stepDetailsSwitch[$scope.item._id.$oid] != null) { 1637 if ($scope.stepDetailsSwitch[$scope.item._id.$oid]) { 1638 $scope.stepDetailsSwitch[$scope.item._id.$oid] = false; 1639 return $scope.$broadcast('hideSteps'); 1640 } else { 1641 $scope.$broadcast('showSteps'); 1642 return $scope.stepDetailsSwitch[$scope.item._id.$oid] = true; 1643 } 1644 } else { 1645 $scope.$broadcast('showSteps'); 1646 return $scope.stepDetailsSwitch[$scope.item._id.$oid] = true; 1647 } 1648 } 1649 }; 1650 $scope.settledMessage = function() { 1651 var today; 1652 if (item.exchange.settled) { 1653 return "Liq. Antec."; 1654 } else { 1655 today = dates.today(); 1656 if (item.exchange.dueDate && (item.exchange.dueDate.toDate() < today)) { 1657 return "Liquidado"; 1658 } else { 1659 return ""; 1660 } 1661 } 1662 }; 1663 hasAttachment = function() { 1664 var ref, ref1; 1665 return (ref = $scope.item.exchange) != null ? (ref1 = ref.attachments) != null ? ref1.length : void 0 : void 0; 1666 }; 1667 hasContractNumber = function() { 1668 var ref; 1669 return (ref = $scope.item.contractNumber) != null ? ref.length : void 0; 1670 }; 1671 hasIdentifier = function() { 1672 var ref, ref1; 1673 return (ref = $scope.item.exchange) != null ? (ref1 = ref.identifier) != null ? ref1.length : void 0 : void 0; 1674 }; 1675 $scope.warningMessages = []; 1676 $scope.buildWarningMessages = function() { 1677 if ($scope.item.exchange.status !== "Fechada") { 1678 return; 1679 } 1680 $scope.warningMessages = []; 1681 if (!hasContractNumber()) { 1682 $scope.warningMessages.push({ 1683 label: "# de contrato", 1684 action: function() { 1685 return eventBus.fire('editFieldDialog', item, { 1686 mode: 'exchangeHistory', 1687 field: 'contractNumber', 1688 title: 'Número do Contrato' 1689 }); 1690 } 1691 }); 1692 } 1693 if (!hasAttachment()) { 1694 return $scope.warningMessages.push({ 1695 label: "Arquivo de contrato", 1696 action: function() { 1697 return $scope.filesDialog(); 1698 } 1699 }); 1700 } 1701 }; 1702 $scope.getTooltipHtml = function() { 1703 var html; 1704 $scope.buildWarningMessages(); 1705 if ($scope.warningMessages.length) { 1706 html = "<b>Pendente:</b><br />"; 1707 html += $scope.warningMessages.map(function(msg, idx) { 1708 return "<span class='link' ng-click='warningMessages[" + idx + "].action()'>- " + msg.label + "</span>"; 1709 }).join("<br />"); 1710 return html; 1711 } else { 1712 return ""; 1713 } 1714 }; 1715 $scope.getHedgeModality = function(modality) { 1716 var ref; 1717 return ((ref = labels.loanModality[modality]) != null ? ref.short : void 0) || ''; 1718 }; 1719 $scope.hedgeKindMessage = function() { 1720 if (item.exchange.hedgeOperation.kind === "Speculative") { 1721 return "Especulativo"; 1722 } else if (item.exchange.hedgeOperation.kind === "Other") { 1723 return "Hedge outros"; 1724 } else if (item.exchange.hedgeOperation.kind === "ExchangeHedge") { 1725 return "Hedge crédito"; 1726 } 1727 }; 1728 $scope.hedgeMessage = function() { 1729 var bank, currency, value; 1730 if ($scope.item.exchange.hedgeOperation.kind === "ExchangeHedge") { 1731 bank = (function() { 1732 var id; 1733 id = $scope.item.exchange.hedgeOperation.bankId; 1734 bank = CustomerBankModel.byId(id); 1735 if (!bank._id) { 1736 bank = BanksModel.byId(id); 1737 } 1738 return bank; 1739 })(); 1740 currency = LoanModalityModel.currencyFor($scope.item.exchange.hedgeOperation.modality); 1741 value = currency + " " + (numbers.format(parseFloat($scope.item.exchange.hedgeOperation.value), 2)); 1742 return "Data de inÃcio: " + $scope.item.exchange.hedgeOperation.creditDate + "</br>\nBanco: " + bank.name + "</br>
1742\nModalidade : " + ($scope.getHedgeModality(item.exchange.hedgeOperation.modality)) + "</br>\nValor: " + value + "</br>\n#CTO: " + $scope.item.exchange.hedgeOperation.contractNumber + "</br>\nIdentificador: " + $scope.item.exchange.hedgeOperation.identifier; 1743 } else { 1744 return ""; 1745 } 1746 }; 1747 return $scope.exchangeNoteDialog = function() { 1748 if (!$scope.isReadOnlyUserOrAllCustomers()) { 1749 $scope.kmqRecord('Observações NDF, Termo'); 1750 return eventBus.fire('exchangeNoteDialog', item); 1751 } 1752 }; 1753 }; 1754 1755 (function() { 1756 var config; 1757 config = ['$scope', 'CustomerBankModel', 'ExchangeModalityModel', 'ExchangeHistoryModel', 'LoanModalityModel', 'ExchangeHistorySettings', 'BanksModel', 'UserModel', 'feedback', ExchangeHistoryItemController]; 1758 return module.controller('spreadnet.exchangeHistoryItemCtrl', config); 1759 })(); 1760 1761 if ((base = this.spreadnet).services == null) { 1762 base.services = this.angular.module('spreadnetServices', ['ngResource']); 1763 } 1764 1765 this.spreadnet.services.factory('ExchangeHistorySettings', function() { 1766 return (function() { 1767 return { 1768 orderedBy: "outlayDate", 1769 lastOrderedBy: "outlayDate", 1770 stepDetailsSwitch: {} 1771 }; 1772 })(); 1773 }); 1774 1775 module = this.angular.module('snExchangeHistory'); 1776 1777 ExchangeHistoryStepController = function($scope, UserModel, feedback) { 1778 var dates, eventBus, events, hasBillAttachment, hasBillNumber, item, numbers; 1779 numbers = spreadnet.utils.numbers; 1780 dates = spreadnet.utils.dates; 1781 events = spreadnet.events; 1782 eventBus = spreadnet.eventBus; 1783 item = $scope.item; 1784 $scope.logItem = function() { 1785 console.log('exchangeHistoryStep'); 1786 return console.log($scope.item); 1787 }; 1788 $scope.isAllCustomers = function() { 1789 return UserModel.isAllCustomers(); 1790 }; 1791 $scope.stepDetails = function() { 1792 var ref; 1793 if ((ref = item.exchange.modality) === "NDF" || ref === "TER") { 1794 return item.exchange.ndfTerm.steps; 1795 } else { 1796 return []; 1797 } 1798 }; 1799 $scope.rateText = function() { 1800 return numbers.format($scope.stepDetail.rate, 6); 1801 }; 1802 $scope.rateUnitText = function() { 1803 return "R$/" + $scope.item.exchange.currency; 1804 }; 1805 $scope.showMemCalc = function() { 1806 var ref; 1807 return (ref = item.exchange.modality) === "NDF" || ref === "TER"; 1808 }; 1809 $scope.showSteps = function() { 1810 var ref; 1811 return (ref = item.exchange.modality) === "NDF" || ref === "TER"; 1812 }; 1813 $scope.showStepDetails = function() { 1814 return $scope.showSteps() && item.exchange.numberOfSteps >= 1; 1815 }; 1816 $scope.canShowStepDetails = function() { 1817 if (($scope.stepDetailsSwitch != null) && ($scope.stepDetailsSwitch[$scope.item._id.$oid] != null)) { 1818 return $scope.stepDetailsSwitch[$scope.item._id.$oid] && $scope.showStepDetails(); 1819 } else { 1820 return false; 1821 } 1822 }; 1823 hasBillAttachment = function() { 1824 var ref; 1825 return $scope.showStepDetails() && ((ref = $scope.stepDetail.attachments) != null ? ref.length : void 0); 1826 }; 1827 hasBillNumber = function() { 1828 var ref; 1829 return $scope.showStepDetails() && ((ref = $scope.stepDetail.billNumber) != null ? ref.length : void 0); 1830 }; 1831 $scope.warningMessages = []; 1832 $scope.buildWarningMessages = function() { 1833 if ($scope.item.exchange.status !== "Fechada") { 1834 return; 1835 } 1836 $scope.warningMessages = []; 1837 if (!hasBillNumber()) { 1838 $scope.warningMessages.push({ 1839 label: "# de nota", 1840 action: function() { 1841 return eventBus.fire('editFieldDialog', item, { 1842 mode: 'exchangeHistoryStep', 1843 billIndex: $scope.$index, 1844 title: 'Número da Nota' 1845 }); 1846 } 1847 }); 1848 } 1849 if (!hasBillAttachment()) { 1850 return $scope.warningMessages.push({ 1851 label: "Arquivo de nota", 1852 action: function() { 1853 return $scope.filesDialog(); 1854 } 1855 }); 1856 } 1857 }; 1858 $scope.getTooltipHtml = function() { 1859 var html; 1860 $scope.buildWarningMessages(); 1861 if ($scope.warningMessages.length) { 1862 html = "<b>Pendente:</b><br />"; 1863 html += $scope.warningMessages.map(function(msg, idx) { 1864 return "<span class='link' ng-click='warningMessages[" + idx + "].action()'>- " + msg.label + "</span>"; 1865 }).join("<br />"); 1866 return html; 1867 } else { 1868 return ""; 1869 } 1870 }; 1871 $scope.memCalc = function() { 1872 $scope.kmqRecord('Memória de Cálculo'); 1873 return $scope.inMemCalc(item, $scope.$index); 1874 }; 1875 $scope.filesDialog = function() { 1876 $scope.kmqRecord('Documentos'); 1877 return eventBus.fire('exchangeStepFilesDialog', item, $scope.stepDetail); 1878 }; 1879 sn.u.subscribeOn($scope, 'showSteps', function() {}); 1880 sn.u.subscribeOn($scope, 'hideSteps', function() {}); 1881 return $scope.exchangeStepNoteDialog = function() { 1882 if (!$scope.isReadOnlyUserOrAllCustomers()) { 1883 $scope.kmqRecord('Observações de nota de NDF, Termo'); 1884 return eventBus.fire('exchangeStepNoteDialog', item, $scope.stepDetail); 1885 } 1886 }; 1887 }; 1888 1889 (function() { 1890 var config; 1891 config = ['$scope', 'UserModel', 'feedback', ExchangeHistoryStepController]; 1892 return module.controller('spreadnet.exchangeHistoryStepCtrl', config); 1893 })(); 1894 1895 module = this.angular.module('snExchangeHistory'); 1896 1897 ExchangeLedgerLineController = function($scope, $sce) { 1898 var dates, formatValue, isExchangeDate, noContent, numbers, redStar; 1899 numbers = spreadnet.utils.numbers; 1900 dates = spreadnet.utils.dates; 1901 noContent = " "; 1902 isExchangeDate = false;
1903 redStar = '<span style="color: red;">*</span>'; 1904 $scope.step = $scope.line.step != null ? isExchangeDate ? $sce.trustAsHtml($scope.line.step + redStar) : $scope.line.step : isExchangeDate ? $sce.trustAsHtml(redStar) : noContent; 1905 $scope.lineType = function() { 1906 if (!$scope.$index) { 1907 return 'rowTotal'; 1908 } 1909 }; 1910 $scope.date = dates.longToDMY($scope.line.date); 1911 $scope.openingBalance = numbers.format($scope.line.openingBalance, 2); 1912 $scope.openingBalanceInReal = numbers.format($scope.line.openingBalanceInReal, 2); 1913 formatValue = function(value, precision) { 1914 if (value != null) { 1915 return numbers.format(value, precision); 1916 } else { 1917 return noContent; 1918 } 1919 }; 1920 $scope.rate = formatValue($scope.line.rate, 6); 1921 $scope.liquidation = formatValue($scope.line.liquidation, 2); 1922 $scope.closingBalance = formatValue($scope.line.closingBalance, 2); 1923 $scope.liquidationInReal = formatValue($scope.line.liquidationInReal, 2); 1924 $scope.closingBalanceInReal = formatValue($scope.line.closingBalanceInReal, 2); 1925 $scope.openingMarketValueInReal = formatValue($scope.line.openingMarketValueInReal, 2); 1926 $scope.closingMarketValueInReal = formatValue($scope.line.closingMarketValueInReal, 2); 1927 $scope.adjustmentInReal = formatValue($scope.line.adjustmentInReal, 2); 1928 $scope.balanceInReal = formatValue($scope.line.balanceInReal, 2); 1929 $scope.stepValue = numbers.format($scope.line.value, 2); 1930 $scope.stepValueInReal = numbers.format($scope.line.valueInReal, 2); 1931 $scope.stepMarketValueInReal = numbers.format($scope.line.marketValueInReal, 2); 1932 $scope.stepAdjustmentInReal = numbers.format($scope.line.adjustmentInReal, 2); 1933 return $scope.stepBalanceInReal = numbers.format($scope.line.balanceInReal, 2); 1934 }; 1935 1936 (function() { 1937 var config; 1938 config = ['$scope', '$sce', ExchangeLedgerLineController]; 1939 return module.controller('spreadnet.exchangeLedgerLineCtrl', config); 1940 })(); 1941 1942 module = this.angular.module('snExchangeHistory'); 1943 1944 ExchangeMemCalcController = function($scope, $rootScope, $location, $timeout, CustomerBankModel, ExchangeModalityModel, ExchangeMemCalcService, ExchangeHistoryModel, WarrantyModel, ExchangeQuotationModel, ExchangeOfferService, feedback) { 1945 var EXCHANGE_MEM_CALC, EXCHANGE_MEM_CALC_DELETE, baseLedger, calcLedgers, calcMethod, calcTypeMap, calcTypes, dailyLedger, dataLoader, dateToDMY, dates, endOfMonth, endOfMonthLedger, eventBus, events, exchange, exchangeHistory, exchangeOffer, exchangeStepRate, fromForm, getBranch, handleError, hasExchange, inMode, interestFmt, pathChanged, recalc, receiveMemCalc, regexExchangeStep, reload, reloadExchangeOffer, savedExchange, savedExchangeOffer, show, showMode, stepItem, stepLedger, stepsOrEndOfMonthLedger, toForm, warr; 1946 events = spreadnet.events; 1947 eventBus = spreadnet.eventBus; 1948 dataLoader = spreadnet.dataLoader; 1949 dates = spreadnet.utils.dates; 1950 calcTypes = spreadnet.utils.calcTypes; 1951 interestFmt = spreadnet.utils.interestFmt; 1952 calcMethod = spreadnet.utils.calcTypes.calcMethod; 1953 regexExchangeStep = /^([^\/]+)(\/step\/)?(\d*)$/; 1954 EXCHANGE_MEM_CALC = events.EXCHANGE_MEM_CALC; 1955 EXCHANGE_MEM_CALC_DELETE = events.EXCHANGE_MEM_CALC_DELETE; 1956 $scope.calculating = false; 1957 $scope.memCalcMode = function() { 1958 return $rootScope.pathInfo.subpath === '/exchangememcalc'; 1959 }; 1960 exchangeOffer = {}; 1961 exchangeHistory = {}; 1962 exchange = {}; 1963 dailyLedger = []; 1964 endOfMonthLedger = []; 1965 stepLedger = []; 1966 stepsOrEndOfMonthLedger = []; 1967 baseLedger = []; 1968 $scope.memcalcKind = ""; 1969 $scope.cancelURL = "#exchangehistory"; 1970 hasExchange = function() { 1971 return exchange && Object.keys(exchange).length > 0; 1972 }; 1973 $scope.currency = hasExchange() ? exchange.currency : "US$"; 1974 exchangeStepRate = 0.0; 1975 $scope.exchangeDate = ""; 1976 $scope.stepNumber = -1; 1977 $scope.isExchangeStepMemCalc = function() { 1978 return $scope.stepNumber >= 0; 1979 }; 1980 $scope.isExchangeMemCalc = function() { 1981 return $scope.stepNumber === -1; 1982 }; 1983 $scope.calcTypeNames = function() { 1984 return calcTypes.names; 1985 }; 1986 calcTypeMap = calcTypes.types; 1987 endOfMonth = function(date) { 1988 return dates.isEndOfMonth(dates.ymdToDate(date)); 1989 }; 1990 stepItem = function(step) { 1991 return (step != null) && step !== ""; 1992 }; 1993 calcLedgers = function() { 1994 var i, isEndOfMonth, isStepItem, len1, line, ref, results; 1995 endOfMonthLedger = []; 1996 stepLedger = []; 1997 stepsOrEndOfMonthLedger = []; 1998 if (dailyLedger.length) { 1999 endOfMonthLedger[0] = dailyLedger[0]; 2000 stepLedger[0] = dailyLedger[0]; 2001 stepsOrEndOfMonthLedger[0] = dailyLedger[0]; 2002 ref = dailyLedger.slice(1); 2003 results = []; 2004 for (i = 0, len1 = ref.length; i < len1; i++) { 2005 line = ref[i]; 2006 isEndOfMonth = endOfMonth(line.date); 2007 isStepItem = stepItem(line.step); 2008 if (isEndOfMonth) { 2009 endOfMonthLedger.push(line); 2010 } 2011 if (isStepItem) { 2012 stepLedger.push(line); 2013 } 2014 if (isEndOfMonth || isStepItem) { 2015 results.push(stepsOrEndOfMonthLedger.push(line)); 2016 } else { 2017 results.push(void 0); 2018 } 2019 } 2020 return results; 2021 } 2022 }; 2023 $scope.filterMemCalc = function() {
2024 dailyLedger = baseLedger; 2025 return calcLedgers(); 2026 }; 2027 receiveMemCalc = function(data) { 2028 $scope.stepNumber = data.stepNumber; 2029 baseLedger = data.ledger; 2030 exchangeStepRate = data.exchangeStepRate; 2031 $scope.exchangeDate = data.exchangeDate; 2032 $scope.filterMemCalc(); 2033 return $scope.stopCalculation(); 2034 }; 2035 $scope.showExchangeStepRate = function() { 2036 return exchangeStepRate !== 0.0; 2037 }; 2038 $scope.exchangeStepRate = function() { 2039 return exchangeStepRate; 2040 }; 2041 handleError = function(error) { 2042 $scope.stopCalculation(); 2043 dailyLedger = []; 2044 calcLedgers(); 2045 return feedback.timedServerError; 2046 }; 2047 reload = function(exchangeHistory, stepNumber) { 2048 if (stepNumber == null) { 2049 stepNumber = -1; 2050 } 2051 $scope.startCalculation(); 2052 return ExchangeMemCalcService.memcalc(exchangeHistory, $scope.memcalcKind, stepNumber).success(receiveMemCalc).error(handleError); 2053 }; 2054 reloadExchangeOffer = function(exchangeOffer, stepNumber) { 2055 if (stepNumber == null) { 2056 stepNumber = -1; 2057 } 2058 $scope.startCalculation(); 2059 return ExchangeMemCalcService.memcalc(exchangeOffer, $scope.memcalcKind, stepNumber).success(receiveMemCalc).error(handleError); 2060 }; 2061 fromForm = function() {}; 2062 savedExchange = function(result) { 2063 exchange.totalSpread = result.totalSpread; 2064 return reload(result); 2065 }; 2066 savedExchangeOffer = function(result) { 2067 exchangeOffer.exchangeHistory.exchange.totalSpread = result.spreadResult.totalSpread; 2068 return reloadExchangeOffer(result); 2069 }; 2070 recalc = function() { 2071 if (hasExchange()) { 2072 $scope.startCalculation(); 2073 fromForm(); 2074 if ($scope.memcalcKind === "exchangeHistory") { 2075 return ExchangeHistoryModel.save(exchangeHistory, reload, feedback.timedServerError); 2076 } else if ($scope.memcalcKind === "exchangeOffer") { 2077 return ExchangeOfferService.saveAndCalc(exchangeOffer).success(savedExchangeOffer).error; 2078 } 2079 } 2080 }; 2081 toForm = function() {}; 2082 dateToDMY = function(date) { 2083 if (date) { 2084 return dates.dateToDMY(date.toDate()); 2085 } else { 2086 return ''; 2087 } 2088 }; 2089 $scope.changed = function() { 2090 return recalc(); 2091 }; 2092 $scope.editExchangeHistory = function() { 2093 return $scope.$parent.editExchangeHistory(exchangeHistory); 2094 }; 2095 $scope.editExchangeFlow = function() { 2096 return $scope.inPaymentsFlowMode(exchangeHistory, "exchange_history"); 2097 }; 2098 $scope.deleteExchangeHistory = function() { 2099 var bank, modality, ref, value; 2100 bank = CustomerBankModel.byId(exchangeHistory.exchange.bank.id); 2101 value = exchangeHistory.exchange.currency + " " + (sn.n.format(exchangeHistory.exchange.value, 2)); 2102 modality = ((ref = ExchangeModalityModel.byCode(exchangeHistory.exchange.modality)) != null ? ref.title : void 0) || ''; 2103 return eventBus.fire(events.MODAL, { 2104 ok: function() { 2105 return $scope.memCalcDelete(exchangeHistory); 2106 }, 2107 okLabel: 'Excluir operação', 2108 cancelLabel: 'Cancelar', 2109 title: 'Exclusão de operação', 2110 html: "Ao excluir uma operação, todos seus dados serão permanentemente removidos.<br/>\nTem certeza que deseja excluir a operação <strong>" + modality + "</strong>, de <strong>" + value + "</strong>,\ndo banco <strong>" + bank.name + "</strong>, de <strong>" + (exchange.outlayDate.toDate().toDMY()) + "</strong>?" 2111 }); 2112 }; 2113 $scope.canEditExchangeFlow = function() { 2114 var ref; 2115 if (exchangeHistory != null) { 2116 return ((ref = exchangeHistory.exchange.modality) === "NDF" || ref === "TER") && !$scope.isExchangeStepMemCalc(); 2117 } else { 2118 return false; 2119 } 2120 }; 2121 $scope.ledgerMode = "step"; 2122 $scope.ledgerLines = function() { 2123 switch ($scope.ledgerMode) { 2124 case "daily": 2125 return dailyLedger; 2126 case "endOfMonth": 2127 return endOfMonthLedger; 2128 case "step": 2129 return stepLedger; 2130 case "stepsOrEndOfMonth": 2131 return stepsOrEndOfMonthLedger; 2132 default: 2133 return []; 2134 } 2135 }; 2136 showMode = function(mode) { 2137 var delay, setMode;
2138 delay = mode === "daily" ? 2000 : 500; 2139 $scope.startCalculation(); 2140 setMode = function() { 2141 $scope.ledgerMode = mode; 2142 return $timeout($scope.stopCalculation, delay); 2143 }; 2144 return $timeout(setMode, 200); 2145 }; 2146 inMode = function(mode) { 2147 if ($scope.ledgerMode === mode) { 2148 return "active"; 2149 } else { 2150 return ""; 2151 } 2152 }; 2153 $scope.showDaily = function() { 2154 return showMode("daily"); 2155 }; 2156 $scope.inDailyMode = function() { 2157 return inMode("daily"); 2158 }; 2159 $scope.showSteps = function() { 2160 return showMode("step"); 2161 }; 2162 $scope.inStepMode = function() { 2163 return inMode("step"); 2164 }; 2165 $scope.showEndOfMonth = function() { 2166 return showMode("endOfMonth"); 2167 }; 2168 $scope.inEndOfMonthMode = function() { 2169 return inMode("endOfMonth"); 2170 }; 2171 $scope.showStepsOrEndOfMonth = function() { 2172 return showMode("stepsOrEndOfMonth"); 2173 }; 2174 $scope.inStepsOrEndOfMonthMode = function() { 2175 return inMode("stepsOrEndOfMonth"); 2176 }; 2177 $scope.gridModeMessage = function() { 2178 switch ($scope.ledgerMode) { 2179 case "daily": 2180 return "Mostrando todos os " + dailyLedger.length + " dias"; 2181 case "endOfMonth": 2182 return "Mostrando apenas finais de mês"; 2183 case "step": 2184 return "Mostrando apenas dias das etapas"; 2185 case "stepsOrEndOfMonth": 2186 return "Mostrando dias das etapas ou finais de mês"; 2187 default: 2188 return ""; 2189 } 2190 }; 2191 $scope.isCurrentSection = function() { 2192 return $rootScope.currentSection === "/exchangememcalc"; 2193 }; 2194 show = function(kind, _arg, stepNumber) { 2195 if (stepNumber == null) { 2196 stepNumber = -1; 2197 } 2198 $scope.memcalcKind = kind; 2199 if (kind === "exchangeHistory" && _arg) { 2200 exchangeHistory = _arg; 2201 exchangeOffer = {}; 2202 exchange = exchangeHistory.exchange; 2203 } else if (kind === "exchangeOffer" && _arg) { 2204 exchangeHistory = {}; 2205 exchangeOffer = _arg; 2206 exchange = exchangeOffer.exchangeHistory.exchange; 2207 } else if (kind === "exchange") { 2208 exchangeHistory = {}; 2209 exchangeOffer = {}; 2210 exchange = _arg; 2211 } 2212 $scope.currency = exchange.currency; 2213 toForm(); 2214 if (kind === "exchangeHistory" && _arg) { 2215 return reload(exchangeHistory, stepNumber); 2216 } else if (kind === "exchangeOffer" && _arg) { 2217 return reloadExchangeOffer(exchangeOffer, stepNumber); 2218 } 2219 }; 2220 $scope.bankName = function() { 2221 var bank; 2222 if (hasExchange()) { 2223 bank = CustomerBankModel.byId(exchange.bank.id); 2224 return bank.name + " (" + bank.number + ")"; 2225 } else { 2226 return ""; 2227 } 2228 }; 2229 getBranch = function(bankInfo) { 2230 var branch; 2231 if (bankInfo.branch) { 2232 branch = CustomerBankModel.branchById(bankInfo.id, bankInfo.branch); 2233 if (branch.number != null) { 2234 return branch.number; 2235 } else { 2236 return ""; 2237 } 2238 } else { 2239 return ""; 2240 } 2241 }; 2242 $scope.branchAccount = function() { 2243 var aTxt, account, bTxt, branch, txts; 2244 if (hasExchange()) { 2245 branch = getBranch(exchange.bank); 2246 account = exchange.bank.account; 2247 txts = []; 2248 bTxt = branch ? txts.push("AG " + branch) : void 0; 2249 aTxt = account ? txts.push("CC " + account) : void 0; 2250 return txts.join(" / ") || ""; 2251 } else { 2252 return ""; 2253 } 2254 }; 2255 $scope.contractNumber = function() { 2256 var ref; 2257 if ($scope.memcalcKind === "exchangeHistory" && (exchangeHistory != null ? (ref = exchangeHistory.contractNumber) != null ? ref.length : void 0 : void 0) > 0) { 2258 return "# CTO " + exchangeHistory.contractNumber; 2259 } else { 2260 return ""; 2261 } 2262 }; 2263 $scope.value = function() { 2264 if (hasExchange()) { 2265 if ($scope.isExchangeMemCalc()) { 2266 return exchange.value; 2267 } else if ($scope.isExchangeStepMemCalc()) { 2268 return exchange.ndfTerm.steps[$scope.stepNumber].value; 2269 } else { 2270 return "0"; 2271 } 2272 } else { 2273 return "0"; 2274 } 2275 }; 2276 $scope.modality = function() { 2277 var modality; 2278 if (hasExchange()) { 2279 modality = ExchangeModalityModel.byCode(exchange.modality); 2280 if (modality.title != null) { 2281 return modality.title; 2282 } else { 2283 return ""; 2284 } 2285 } else { 2286 return ""; 2287 } 2288 }; 2289 $scope.operation = function() { 2290 if (hasExchange()) { 2291 switch (exchange.operation) { 2292 case "B": 2293 return "Compra"; 2294 case "S": 2295 return "Venda"; 2296 default: 2297 return ""; 2298 } 2299 } else { 2300 return ""; 2301 } 2302 }; 2303 $scope.issued = function() { 2304 if (hasExchange()) {
2305 return dateToDMY(exchange.issueDate); 2306 } else { 2307 return ""; 2308 } 2309 }; 2310 $scope.credited = function() { 2311 if (hasExchange()) { 2312 return dateToDMY(exchange.outlayDate); 2313 } else { 2314 return ""; 2315 } 2316 }; 2317 warr = function(pct, nm) { 2318 if (pct) { 2319 return pct + "% " + nm; 2320 } else { 2321 return ""; 2322 } 2323 }; 2324 $scope.warranties = function() { 2325 var extra1Warr, extra2Warr, mainWarr, ref, result; 2326 if (hasExchange() && ((ref = exchange.modality) === "NDF" || ref === "TER")) { 2327 mainWarr = warr(exchange.ndfTerm.warranties.pctMain, exchange.ndfTerm.warranties.main); 2328 extra1Warr = warr(exchange.ndfTerm.warranties.pctExtra1, exchange.ndfTerm.warranties.extra1); 2329 extra2Warr = warr(exchange.ndfTerm.warranties.pctExtra2, exchange.ndfTerm.warranties.extra2); 2330 result = mainWarr + (extra1Warr ? " + " + extra1Warr : ""); 2331 result = result + (extra2Warr ? " + " + extra2Warr : ""); 2332 if (result) { 2333 return result; 2334 } else { 2335 return "S GAR"; 2336 } 2337 } else { 2338 return ""; 2339 } 2340 }; 2341 $scope.tac = function() { 2342 if (hasExchange()) { 2343 return exchange.tac; 2344 } else { 2345 return 0; 2346 } 2347 }; 2348 $scope.ending = function() { 2349 if (hasExchange()) { 2350 if ($scope.isExchangeStepMemCalc()) { 2351 return dateToDMY(exchange.ndfTerm.steps[$scope.stepNumber].date); 2352 } else { 2353 return dateToDMY(exchange.dueDate); 2354 } 2355 } else { 2356 return ""; 2357 } 2358 }; 2359 $scope.term = function() { 2360 if (hasExchange()) { 2361 if ($scope.isExchangeStepMemCalc()) { 2362 return exchange.ndfTerm.steps[$scope.stepNumber].term; 2363 } else { 2364 return exchange.term; 2365 } 2366 } else { 2367 return 0; 2368 } 2369 }; 2370 $scope.numberOfStepsOrStepBillNumber = function() { 2371 if (hasExchange()) { 2372 if ($scope.isExchangeMemCalc()) { 2373 return "Número de notas: " + exchange.numberOfSteps; 2374 } else if ($scope.isExchangeStepMemCalc()) { 2375 return "# Nota: " + exchange.ndfTerm.steps[$scope.stepNumber].billNumber; 2376 } else { 2377 return ""; 2378 } 2379 } else { 2380 return ""; 2381 } 2382 }; 2383 $scope.cancelUrlClick = function() {}; 2384 pathChanged = function(pathInfo) { 2385 var exchangeOfferMemCalcInit, memCalcInit, ref, ref1; 2386 if (pathInfo.path === "/exchangehistory" && pathInfo.subpath === "/exchangememcalc") { 2387 $scope.startCalculation(); 2388 memCalcInit = { 2389 load: function() { 2390 var exchangeHistoryId, parsed, stepNumber; 2391 parsed = regexExchangeStep.exec(pathInfo.param); 2392 exchangeHistoryId = parsed[1]; 2393 stepNumber = (parsed[3] != null) && parsed[3] !== "" ? parsed[3] : -1; 2394 exchangeHistory = ExchangeHistoryModel.byId(exchangeHistoryId); 2395 if (exchangeHistory != null) { 2396 exchange = exchangeHistory.exchange; 2397 return show('exchangeHistory', exchangeHistory, stepNumber); 2398 } else { 2399 $scope.stopCalculation(); 2400 return $location.path("/exchangehistory"); 2401 } 2402 } 2403 }; 2404 $scope.cancelURL = "#exchangehistory"; 2405 if (((ref = ExchangeHistoryModel.collection) != null ? ref[0] : void 0) != null) { 2406 return memCalcInit.load(); 2407 } else { 2408 return dataLoader.loadModels([ExchangeHistoryModel, memCalcInit]); 2409 } 2410 } else if (pathInfo.path === "/exchangequotation" && pathInfo.subpath === "/exchangememcalc") { 2411 $scope.startCalculation(); 2412 exchangeOfferMemCalcInit = { 2413 load: function() { 2414 var exchangeId, parsed, stepNumber; 2415 parsed = regexExchangeStep.exec(pathInfo.param); 2416 exchangeId = parsed[1]; 2417 stepNumber = (parsed[3] != null) && parsed[3] !== "" ? parsed[3] : -1; 2418 exchangeOffer = ExchangeQuotationModel.byExchangeId(exchangeId); 2419 if (exchangeOffer != null) { 2420 return show('exchangeOffer', exchangeOffer, stepNumber); 2421 } else { 2422 $scope.stopCalculation(); 2423 return $location.path("/exchangequotation"); 2424 } 2425 } 2426 }; 2427 $scope.cancelURL = "#exchangequotation"; 2428 if (((ref1 = ExchangeQuotationModel.collection) != null ? ref1[0] : void 0) != null) { 2429 return exchangeOfferMemCalcInit.load(); 2430 } else { 2431 return dataLoader.loadModels([ExchangeQuotationModel, exchangeOfferMemCalcInit]); 2432 } 2433 } 2434 }; 2435 return pathChanged($rootScope.pathInfo); 2436 }; 2437 2438 (function() { 2439 var config; 2440 config = ['$scope', '$rootScope', '$location', '$timeout', 'CustomerBankModel', 'ExchangeModalityModel', 'ExchangeMemC
2440alcService', 'ExchangeHistoryModel', 'WarrantyModel', 'ExchangeQuotationModel', 'ExchangeOfferService', 'feedback', ExchangeMemCalcController]; 2441 return module.controller('spreadnet.exchangeMemCalcCtrl', config); 2442 })(); 2443 2444 module = this.angular.module('snExchangeHistory'); 2445 2446 ExchangeNoteDialogController = function($scope, ExchangeHistoryModel, feedback) { 2447 var eventBus, exchangeHistory, inputFocus, saveExchangeHistoryError, saveExchangeHistorySuccess, validNote; 2448 eventBus = spreadnet.eventBus; 2449 inputFocus = false; 2450 $scope.noteDescription = ""; 2451 $scope.showing = false; 2452 exchangeHistory = {}; 2453 $scope.inputFocus = function() { 2454 var former; 2455 former = inputFocus; 2456 inputFocus = false; 2457 return former; 2458 }; 2459 $scope.show = function(item) { 2460 exchangeHistory = item; 2461 $scope.noteDescription = exchangeHistory.exchange.note ? exchangeHistory.exchange.note : ""; 2462 return $scope.showing = true; 2463 }; 2464 validNote = function() { 2465 return true; 2466 }; 2467 $scope.save = function() { 2468 if (validNote()) { 2469 exchangeHistory.exchange.note = $scope.noteDescription; 2470 return ExchangeHistoryModel.save(exchangeHistory, saveExchangeHistorySuccess, saveExchangeHistoryError); 2471 } else { 2472 return feedback.timedError("Observações de NDF, Termo inválidas. Corrija a descrição das observações de NDF, Termo."); 2473 } 2474 }; 2475 $scope.cancel = function() { 2476 return $scope.showing = false; 2477 }; 2478 saveExchangeHistorySuccess = function() { 2479 feedback.timedSuccess("As observações de NDF, Termo foram salvas"); 2480 return $scope.showing = false; 2481 }; 2482 saveExchangeHistoryError = function() { 2483 return feedback.timedError("Erro ao salvar observações de NDF, Termo"); 2484 }; 2485 return eventBus.subscribe('exchangeNoteDialog', $scope.show, $scope); 2486 }; 2487 2488 (function() { 2489 var config; 2490 config = ['$scope', 'ExchangeHistoryModel', 'feedback', ExchangeNoteDialogController]; 2491 return module.controller('spreadnet.ExchangeNoteController', config); 2492 })(); 2493 2494 if (this.spreadnet == null) { 2495 this.spreadnet = {}; 2496 } 2497 2498 this.spreadnet.exchangeStepFilesDialogCtrl = function($scope, $http, Upload, $window, $timeout, ExchangeHistoryModel, ExchangeModalityModel, CustomerBankModel, BanksModel, PendingRequests, feedback, $q, MessiService) { 2499 var alreadyNames, attachmentByName, editionFocus, emptyExchangeStep, eventBus, exchangeHistoryItem, exchangeHistoryStep, findStepIndex, finishScreen, hide, nextSDtimeout, nextUEWtimeout, save, signalDeleted, triggerUploadErrorWarning, uploadErrorWarning; 2500 eventBus = spreadnet.eventBus; 2501 editionFocus = spreadnet.editionFocus; 2502 emptyExchangeStep = { 2503 attachments: [] 2504 }; 2505 alreadyNames = []; 2506 exchangeHistoryItem = {}; 2507 exchangeHistoryStep = {}; 2508 $scope.exchangeStep = emptyExchangeStep; 2509 $scope.attachments = []; 2510 $scope.showing = false; 2511 findStepIndex = function(steps, stepDate) { 2512 var i, ref, results, stepIndex; 2513 results = []; 2514 for (stepIndex = i = 0, ref = steps.length; 0 <= ref ? i < ref : i > ref; stepIndex = 0 <= ref ? ++i : --i) { 2515 if (steps[stepIndex].date === stepDate) { 2516 results.push(stepIndex); 2517 } 2518 } 2519 return results; 2520 }; 2521 $scope.show = function(item, step) { 2522 exchangeHistoryItem = item; 2523 exchangeHistoryStep = step; 2524 $scope.exchangeStep = step; 2525 if ($scope.exchangeStep.attachments == null) { 2526 $scope.exchangeStep.attachments = []; 2527 } 2528 $scope.attachments = angular.copy($scope.exchangeStep.attachments); 2529 return $scope.showing = true; 2530 }; 2531 $scope.splitJoin = function(str, len) { 2532 var re; 2533 re = new RegExp(".{1," + len + "}", 'g'); 2534 return str.match(re).join('\u200B'); 2535 }; 2536 save = function() { 2537 var failedUploads, performSave; 2538 failedUploads = function() { 2539 var attachment, i, len1, ref; 2540 ref = $scope.attachments; 2541 for (i = 0, len1 = ref.length; i < len1; i++) { 2542 attachment = ref[i]; 2543 if (attachment.status === 'uploadError') { 2544 return true; 2545 } 2546 } 2547 }; 2548 performSave = function() { 2549 var attachment, newAttachments, stepIndex; 2550 newAttachments = (function() { 2551 var i, len1, ref, results; 2552 ref = $scope.attachments; 2553 results = []; 2554 for (i = 0, len1 = ref.length; i < len1; i++) { 2555 attachment = ref[i]; 2556 if (!attachment.status) { 2557 results.push({ 2558 _id: attachment._id, 2559 name: attachment.name.replaceCharsForUpload(), 2560 date: attachment.date 2561 }); 2562 } 2563 } 2564 return results; 2565 })(); 2566 newAttachments.sort(function(a, b) { 2567 var s; 2568 s = function(a, b) { 2569 if (a === b) { 2570 return 0; 2571 } else if (a < b) { 2572 return -1; 2573 } else { 2574 return 1; 2575 } 2576 }; 2577 return s(a.name, b.name); 2578 }); 2579 stepIndex = findStepIndex(exchangeHistoryItem.exchange.ndfTerm.steps, exch
2579angeHistoryStep.date); 2580 exchangeHistoryItem.exchange.ndfTerm.steps[stepIndex].attachments = newAttachments; 2581 return ExchangeHistoryModel.save(exchangeHistoryItem, function(savedExchangeHistory) { 2582 exchangeHistoryItem = savedExchangeHistory; 2583 finishScreen(); 2584 return feedback.timedSuccess("Documentos da nota atualizados com sucesso."); 2585 }); 2586 }; 2587 if (failedUploads()) { 2588 return MessiService.confirmDialog("Os arquivos cujo carregamento falhou serão excluÃdos. Continuar?").then(function(answer) { 2589 if (answer) { 2590 return performSave(); 2591 } 2592 }); 2593 } else { 2594 return performSave(); 2595 } 2596 }; 2597 $scope.ok = function() { 2598 return save(); 2599 }; 2600 finishScreen = function() { 2601 hide(); 2602 return $timeout(function() { 2603 $scope.exchangeStep = emptyExchangeStep; 2604 $scope.attachments = []; 2605 exchangeHistoryItem = {}; 2606 return exchangeHistoryStep = {}; 2607 }); 2608 }; 2609 $scope.cancel = function() { 2610 return finishScreen(); 2611 }; 2612 hide = function() { 2613 $scope.showing = false; 2614 return editionFocus.close(); 2615 }; 2616 eventBus.subscribe('exchangeStepFilesDialog', $scope.show, $scope); 2617 $scope.header = function() { 2618 var billNumber, currBank, currency, date, modality, numSteps, rate, ref, stepIndex, value; 2619 if (!exchangeHistoryItem.exchange) { 2620 return ''; 2621 } else { 2622 currBank = function() { 2623 var bank, id; 2624 id = exchangeHistoryItem.exchange.bank.id; 2625 bank = CustomerBankModel.byId(id); 2626 if (!bank._id) { 2627 bank = BanksModel.byId(id); 2628 } 2629 return bank; 2630 }; 2631 currency = exchangeHistoryItem.exchange.currency; 2632 value = sn.n.format(exchangeHistoryStep.value, 2); 2633 rate = sn.n.format(exchangeHistoryStep.rate, 6); 2634 modality = ((ref = ExchangeModalityModel.byCode(exchangeHistoryItem.exchange.modality)) != null ? ref.title : void 0) || ''; 2635 billNumber = exchangeHistoryStep.billNumber; 2636 date = exchangeHistoryStep.date.toDate().toDMY(); 2637 stepIndex = parseInt(findStepIndex(exchangeHistoryItem.exchange.ndfTerm.steps, exchangeHistoryStep.date), 10) + 1; 2638 numSteps = exchangeHistoryItem.exchange.ndfTerm.steps.length; 2639 return currency + " " + value + " | R$/" + currency + " " + rate + " | " + stepIndex + "/" + numSteps + " | " + billNumber + " | " + modality + " | " + (currBank().name) + " | " + date; 2640 } 2641 }; 2642 $scope.uploading = function() { 2643 return PendingRequests.pending(function(url) { 2644 return url === 'upload'; 2645 }); 2646 }; 2647 $scope.notDeleted = function(attachment) { 2648 var ref; 2649 return (ref = attachment.status) !== 'deleted' && ref !== 'deleted2'; 2650 }; 2651 attachmentByName = function(name) { 2652 var att, i, len1, ref; 2653 ref = $scope.attachments; 2654 for (i = 0, len1 = ref.length; i < len1; i++) { 2655 att = ref[i]; 2656 if (att.name === name) { 2657 return att; 2658 } 2659 } 2660 }; 2661 $scope.onFileSelect = function($files) { 2662 var file, largeFiles, largeFilesStr, message, uploadFiles; 2663 if (!$files) { 2664 return; 2665 } 2666 uploadFiles = function() { 2667 var file, i, inputFile, len1, process, results, upload; 2668 results = []; 2669 for (i = 0, len1 = $files.length; i < len1; i++) { 2670 inputFile = $files[i]; 2671 if (!(inputFile.size <= 15728640)) { 2672 continue; 2673 } 2674 file = new File([inputFile], inputFile.name.replaceCharsForUpload()); 2675 upload = function(file, already) { 2676 var addToAttachments, upItem; 2677 addToAttachments = function() { 2678 var att, withUploadError, withoutUploadError; 2679 $scope.attachments.unshift({ 2680 _id: sn.u.UUID(), 2681 name: file.name, 2682 date: sn.d.fileLastModifiedDate(file).toYMD() 2683 }); 2684 withUploadError = (function() { 2685 var j, len2, ref, results1; 2686 ref = $scope.attachments; 2687 results1 = []; 2688 for (j = 0, len2 = ref.length; j < len2; j++) { 2689 att = ref[j]; 2690 if (att.status === 'uploadError') { 2691 results1.push(att); 2692 } 2693 } 2694 return results1; 2695 })(); 2696 withoutUploadError = (function() { 2697 var j, len2, ref, results1; 2698 ref = $scope.attachments; 2699 results1 = []; 2700 for (j = 0, len2 = ref.length; j < len2; j++) { 2701 att = ref[j]; 2702 if (att.status !== 'uploadError') { 2703 results1.push(att); 2704 } 2705 } 2706 return results1; 2707 })(); 2708 if (withUploadError.length) { 2709 return $scope.attachments = withUploadError.concat(withoutUploadError); 2710 } 2711 }; 2712 return upItem = Upload.upload({ 2713 url: 'upload', 2714 data: { 2715 offerId: exchangeHistoryItem._id.$oid, 2716 date: sn.d.fileLastModifiedDate(file).toYMD(), 2717 stepDate: exchangeHistoryStep.date 2718 }, 2719 file: file 2720 }).success(function() { 2721 var att;
2722 if (!already) { 2723 addToAttachments(); 2724 } 2725 if (att = attachmentByName(file.name)) { 2726 return att.status = ''; 2727 } 2728 }).error(function() { 2729 var att; 2730 if (!already) { 2731 addToAttachments(); 2732 } 2733 if (att = attachmentByName(file.name)) { 2734 att.status = 'uploadError'; 2735 } 2736 return triggerUploadErrorWarning(); 2737 }); 2738 }; 2739 results.push((process = function(file) { 2740 var att, attachment, confirmReplace, invalidCharMsg, ref, ref1; 2741 alreadyNames = (function() { 2742 var j, len2, ref, results1; 2743 ref = $scope.attachments; 2744 results1 = []; 2745 for (j = 0, len2 = ref.length; j < len2; j++) { 2746 att = ref[j]; 2747 results1.push(att.name); 2748 } 2749 return results1; 2750 })(); 2751 attachment = attachmentByName(file.name); 2752 confirmReplace = function() { 2753 return MessiService.confirmDialog("Já existe o arquivo " + file.name + ". Deseja substituÃ-lo?").then(function(answer) { 2754 if (answer) { 2755 return upload(file, true); 2756 } 2757 }); 2758 }; 2759 invalidCharMsg = function() { 2760 if (inputFile.name !== file.name) { 2761 return MessiService.alertDialog("<b>Foram alterados caracteres não permitidos no nome do arquivo</b><br><br><b>Nome anterior:</b><br>" + inputFile.name + "<br><br><b>Nome novo:</b><br>" + file.name); 2762 } 2763 }; 2764 if (ref = file.name, indexOf.call(alreadyNames, ref) >= 0) { 2765 if (attachment.status === 'deleted') { 2766 MessiService.confirmDialog("O arquivo " + file.name + " foi removido. Deseja restaurá-lo?").then(function(answer) { 2767 if (answer) { 2768 attachment.status = ''; 2769 return confirmReplace(); 2770 } 2771 }); 2772 } else if ((ref1 = attachment.status) === 'deleted2' || ref1 === 'uploadError') { 2773 upload(file, true); 2774 } else if (!attachment.status) { 2775 confirmReplace(); 2776 } 2777 } else { 2778 upload(file); 2779 } 2780 return invalidCharMsg(); 2781 })(file)); 2782 } 2783 return results; 2784 }; 2785 largeFiles = (function() { 2786 var i, len1, results; 2787 results = []; 2788 for (i = 0, len1 = $files.length; i < len1; i++) { 2789 file = $files[i]; 2790 if (file.size > 15728640) { 2791 results.push(file.name.replaceCharsForUpload()); 2792 } 2793 } 2794 return results; 2795 })(); 2796 if (largeFiles.length) { 2797 largeFilesStr = largeFiles.join("<br/>"); 2798 message = largeFiles.length > 1 ? "Os arquivos<br/>" + largeFilesStr + "<br/>tem mais de 15MB e não serão carregados." : "O arquivo<br/>" + largeFiles[0] + "<br/>tem mais de 15MB e não será carregado."; 2799 feedback.timedWarning(message); 2800 } 2801 return uploadFiles(); 2802 }; 2803 uploadErrorWarning = false; 2804 nextUEWtimeout = ''; 2805 triggerUploadErrorWarning = function() { 2806 uploadErrorWarning = true; 2807 if (nextUEWtimeout) { 2808 $timeout.cancel(nextUEWtimeout); 2809 } 2810 return nextUEWtimeout = $timeout((function() { 2811 return uploadErrorWarning = false; 2812 }), 5000); 2813 }; 2814 $scope.uploadError = function(att) { 2815 return att.status === 'uploadError'; 2816 }; 2817 $scope.uploadErrorWarning = function() { 2818 return uploadErrorWarning; 2819 }; 2820 $scope.removeAttachment = function(todel) { 2821 var att, i, len1, ref, results; 2822 ref = $scope.attachments; 2823 results = []; 2824 for (i = 0, len1 = ref.length; i < len1; i++) { 2825 att = ref[i]; 2826 if (att._id === todel._id) { 2827 if (att.status === 'uploadError') { 2828 results.push(att.status = 'deleted2'); 2829 } else { 2830 att.status = 'deleted'; 2831 results.push(signalDeleted(att)); 2832 } 2833 } 2834 } 2835 return results; 2836 }; 2837 $scope.lastDeleted = {}; 2838 nextSDtimeout = ''; 2839 signalDeleted = function(att) { 2840 if (nextSDtimeout) { 2841 $timeout.cancel(nextSDtimeout); 2842 } 2843 $scope.lastDeleted = att; 2844 return nextSDtimeout = $timeout((function() { 2845 return $scope.lastDeleted = {}; 2846 }), 5000); 2847 }; 2848 $scope.recoverDeleted = function() { 2849 if ($scope.lastDeleted._id) { 2850 $scope.lastDeleted.status = ''; 2851 return $scope.lastDeleted = {}; 2852 } 2853 }; 2854 $scope.downloadUrl = ''; 2855 $scope.download = function(att) { 2856 var downloadErrorResponse, param; 2857 downloadErrorResponse = function() { 2858 return feedback.timedError("Erro na obtenção do arquivo " + att.name + "."); 2859 }; 2860 if (!att.status) { 2861 param = { 2862 offerId: exchangeHistoryItem._id.$oid, 2863 name: att.name, 2864 stepDate: exchangeHistoryStep.date 2865 }; 2866 return $http.post('download', param).success(function(data) { 2867 var link, trimmedData; 2868 trimmedData = (data != null ? data.trim() : void 0) || ''; 2869 if (/^http/.test(trimmedData)) { 2870 link = $("#attachmentDownload"); 2871 link.attr('href', data); 2872 return link[0].click(); 2873 } else { 2874 return downloadErrorResponse(); 2875 } 2876 }).error(function() { 2877 return downloadErrorResponse(); 2878 }); 2879 } 2880 }; 2881 return $scope.mostraAtt = function() { 2882 return console.log($scope.attachments); 2883 }; 2884 }; 2885 2886 module = this.angular.module('snExchangeHistory'); 2887 2888 ExchangeStepNoteDialogController = function($scope, ExchangeHistoryModel, feedback) { 2889 var eventBus, exchangeHistoryItem, exchangeHistoryStep, findStepIndex, inputFocus, saveExchangeHistoryError, saveExchangeHistorySuccess, validNote; 2890 eventBus = spreadnet.eventBus; 2891 inputFocus = false;
2892 $scope.noteDescription = ""; 2893 $scope.showing = false; 2894 exchangeHistoryItem = {}; 2895 exchangeHistoryStep = {}; 2896 $scope.inputFocus = function() { 2897 var former; 2898 former = inputFocus; 2899 inputFocus = false; 2900 return former; 2901 }; 2902 $scope.show = function(item, step) { 2903 exchangeHistoryItem = item; 2904 exchangeHistoryStep = step; 2905 $scope.noteDescription = exchangeHistoryStep.note ? exchangeHistoryStep.note : ""; 2906 return $scope.showing = true; 2907 }; 2908 validNote = function() { 2909 return true; 2910 }; 2911 findStepIndex = function(steps, stepDate) { 2912 var i, ref, results, stepIndex; 2913 results = []; 2914 for (stepIndex = i = 0, ref = steps.length; 0 <= ref ? i < ref : i > ref; stepIndex = 0 <= ref ? ++i : --i) { 2915 if (steps[stepIndex].date === stepDate) { 2916 results.push(stepIndex); 2917 } 2918 } 2919 return results; 2920 }; 2921 $scope.save = function() { 2922 var stepIndex; 2923 if (validNote()) { 2924 exchangeHistoryStep.note = $scope.noteDescription; 2925 stepIndex = findStepIndex(exchangeHistoryItem.exchange.ndfTerm.steps, exchangeHistoryStep.date); 2926 exchangeHistoryItem.exchange.ndfTerm.steps[stepIndex].note = exchangeHistoryStep.note; 2927 return ExchangeHistoryModel.save(exchangeHistoryItem, saveExchangeHistorySuccess, saveExchangeHistoryError); 2928 } else { 2929 return feedback.timedError("Observações de nota de NDF, Termo inválidas. Corrija a descrição das observações de nota de NDF, Termo."); 2930 } 2931 }; 2932 $scope.cancel = function() { 2933 return $scope.showing = false; 2934 }; 2935 saveExchangeHistorySuccess = function() { 2936 feedback.timedSuccess("As observações de nota de NDF, Termo foram salvas"); 2937 return $scope.showing = false; 2938 }; 2939 saveExchangeHistoryError = function() { 2940 return feedback.timedError("Erro ao salvar observações de nota de NDF, Termo"); 2941 }; 2942 return eventBus.subscribe('exchangeStepNoteDialog', $scope.show, $scope); 2943 }; 2944 2945 (function() { 2946 var config; 2947 config = ['$scope', 'ExchangeHistoryModel', 'feedback', ExchangeStepNoteDialogController]; 2948 return module.controller('spreadnet.ExchangeStepNoteController', config); 2949 })(); 2950 2951 module = this.angular.module('snExchangeHistory'); 2952 2953 hedgeRemovalConfirmationController = function($scope) { 2954 var posAdvance, posCancel; 2955 $scope.showing = 0; 2956 $scope.formerExchangeStatus = 0; 2957 posCancel = ''; 2958 posAdvance = ''; 2959 $scope.show = function(formerStatus, advance, cancel) { 2960 $scope.formerExchangeStatus = formerStatus === "Cotação" ? "em Cotação" : "Fechada"; 2961 posCancel = cancel; 2962 posAdvance = advance; 2963 return $scope.showing = 1; 2964 }; 2965 $scope.cancel = function() { 2966 $scope.showing = 0; 2967 return posCancel(); 2968 }; 2969 $scope.advance = function() { 2970 $scope.showing = 0; 2971 return posAdvance(); 2972 }; 2973 return sn.eventBus.subscribe('exchangeHedgeRemovalConfirmation', $scope.show, $scope); 2974 }; 2975 2976 (function() { 2977 var config; 2978 config = ['$scope', hedgeRemovalConfirmationController]; 2979 return module.controller('spreadnet.exchangeHedgeRemovalConfirmationController', config); 2980 })(); 2981 2982}).call(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.