import { WizardStep } from '@/global/widgets/wizard/WizardStep';
export class ProcessTransactionsWizardStepHome extends WizardStep {
constructor( options = {} ) {
_.defaults( options, {
name: 'home',
source_accounts: [],
pay_periods: [],
types: [],
filter_data: null
} );
super( options );
}
init() {
var $this = this;
var external_data = $this.getWizardObject().getExternalData();
if ( external_data.transaction_source_data ) {
$this.source_accounts = [];
$this.normalizeSourceAccounts( external_data.transaction_source_data );
delete external_data.transaction_source_data;
$this.render();
return;
}
var api = TTAPI.APIPayStubTransaction;
var filter_data = {};
if ( external_data ) {
var temp_filter_data = external_data.filter_data;
// Ignore ugliness from report setup data ( We only want to send the filter forward )
var ignore_fields = ['chart', 'columns', 'sort', 'sort_', 'order', 'other', 'template', 'sub_total'];
for ( var n in temp_filter_data ) {
if ( ignore_fields.indexOf( n ) == -1 ) {
filter_data[n] = temp_filter_data[n];
}
}
}
api.getPayPeriodTransactionSummary( filter_data, {
onResult: function( result ) {
var transactions = result.getResult();
$this.normalizeSourceAccounts( transactions );
$this.render();
}
} );
}
normalizeSourceAccounts( data ) {
this.source_accounts = [];
var external_data = this.getWizardObject().getExternalData();
if ( !external_data.filter_data.pay_period_id ) {
external_data.filter_data.pay_period_id = [];
}
for ( var m in data ) {
var item = data[m];
var new_record = {
id: item.remittance_source_account_id,
name: item.remittance_source_account,
type: item.remittance_source_account_type,
last_transaction_number: item.remittance_source_account_last_transaction_number,
total_amount: item.total_amount,
total_transactions: item.total_transactions
};
this.source_accounts.push( new_record );
if ( item.pay_period_id && external_data.filter_data.pay_period_id.indexOf( item.pay_period_id ) == -1 && item.pay_period_id != TTUUID.zero_id ) {
external_data.filter_data.pay_period_id.push( item.pay_period_id );
}
}
this.getWizardObject().setExternalData( external_data );
}
initCardsBlock() {
$( this.wizard_obj.el ).find( '.download_warning' ).html( 'Click the icon to download the transaction file. Be sure to save it to your computer rather than open it' );
}
getNextStepName() {
//This is a single-step wizard. Always return false;
return false;
}
_render() {
this.setTitle( this.getWizardObject().wizard_name );
//If the wizard is closed, it reopens to the home step and must be told what the current step is.
this.getWizardObject().setCurrentStepName( 'home' );
TTPromise.add( 'processTransactionsWizard', 'render' );
var $this = this;
TTPromise.wait( 'processTransactionsWizard', 'render', function() {
$( $this.el ).show();
( $( '.process_transactions_wizard input' )[1] ).focus(); //Select first input field by default.
} );
this.buildForm();
}
buildForm() {
if ( this.source_accounts.length > 0 ) {
var tab_index = 1050;
var instruction_text = $.i18n._( 'Select source accounts to processs transactions for' );
var $this = this;
var container = $( '
' );
var form = $( '' ).appendTo( container );
var table = $( '
' );
var header_row = $( '
' );
header_row.html( '
' + instruction_text + '
' );
var column_header_row = $( '
' );
var th_chk = $( '
' ).appendTo( column_header_row );
var th_name = $( '