Created
June 18, 2020 09:44
-
-
Save saturov/68f1e18519199da089cdb1611d32018d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _applyTemplateData( | |
Map<Organization, List<Account>> organizationsToAccountsMap, | |
) { | |
if (_templateBuy != null) { | |
_applyTemplateDataBuy(organizationsToAccountsMap, _templateBuy); | |
} else if (_templateSell != null) { | |
_applyTemplateDataSell(organizationsToAccountsMap, _templateSell); | |
} | |
} | |
void _applyTemplateDataBuy( | |
Map<Organization, List<Account>> organizationsToAccountsMap, | |
CurrencyBuyDocument _template, | |
) { | |
Organization organization = organizationsToAccountsMap.keys.firstWhere( | |
(Organization o) => o.id == _template.organizationId, | |
orElse: () => null, | |
); | |
if (organization != null) { | |
_setOrganization(organization); | |
_reloadPayerInfo(organization.id); | |
_reloadPreFilledData(); | |
} | |
// нужно чтобы отработали подписчики изменения организации до изменения счетов | |
Future(() { | |
List<Account> accounts; | |
if (organization != null) { | |
accounts = organizationsToAccountsMap[organization]; | |
} | |
if (accounts != null) { | |
Account paymentAccount = accounts.firstWhereOrNull( | |
(Account a) => _template.payerAccountNumber == a.number, | |
); | |
if (paymentAccount != null) _setPaymentAccount(paymentAccount); | |
Account enrollmentAccount = accounts.firstWhereOrNull( | |
(Account a) => _template.receiverAccountNumber == a.number, | |
); | |
if (enrollmentAccount != null) _setEnrollmentAccount(enrollmentAccount); | |
} | |
}); | |
onSelectRosbankDatePickerController.accept(_template.date); | |
_setControllerText( | |
PaymentIds.currencySum, | |
rubSumFormatText(_template.sum.sum.toString()), | |
); | |
} | |
void _applyTemplateDataSell( | |
Map<Organization, List<Account>> organizationsToAccountsMap, | |
CurrencySellDocument _template, | |
) { | |
Organization organization = organizationsToAccountsMap.keys.firstWhere( | |
(Organization o) => o.id == _template.organizationId, | |
orElse: () => null, | |
); | |
if (organization != null) { | |
_setOrganization(organization); | |
_reloadPayerInfo(organization.id); | |
_reloadPreFilledData(); | |
} | |
// нужно чтобы отработали подписчики изменения организации до изменения счетов | |
Future(() { | |
List<Account> accounts; | |
if (organization != null) { | |
accounts = organizationsToAccountsMap[organization]; | |
} | |
if (accounts != null) { | |
Account paymentAccount = accounts.firstWhereOrNull( | |
(Account a) => _template.payerAccountNumber == a.number, | |
); | |
if (paymentAccount != null) _setPaymentAccount(paymentAccount); | |
Account enrollmentAccount = accounts.firstWhereOrNull( | |
(Account a) => _template.receiverAccountNumber == a.number, | |
); | |
if (enrollmentAccount != null) _setEnrollmentAccount(enrollmentAccount); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment