TimeTrex Community Edition v16.2.0
This commit is contained in:
@ -0,0 +1,97 @@
|
||||
import { Wizard } from '@/global/widgets/wizard/Wizard';
|
||||
|
||||
export class ProcessTransactionsWizard extends Wizard {
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
el: $( '.process_transactions_wizard' ),
|
||||
current_step: false,
|
||||
wizard_name: $.i18n._( 'Process Transactions' ),
|
||||
|
||||
selected_transaction_ids: [],
|
||||
|
||||
wizard_id: 'ProcessTransactionsWizard',
|
||||
_step_map: {
|
||||
'home': { // TODO: Webpack: Investigate how this works/does not work with Webpack
|
||||
script_path: 'views/payroll/process_transactions_wizard/ProcessTransactionsWizardStepHome.js',
|
||||
object_name: 'ProcessTransactionsWizardStepHome'
|
||||
}
|
||||
|
||||
},
|
||||
api: null,
|
||||
|
||||
} );
|
||||
|
||||
super( options );
|
||||
}
|
||||
|
||||
setTransactionIds( data ) {
|
||||
this.selected_transaction_ids = data;
|
||||
if ( this.selected_transaction_ids.length > 0 ) {
|
||||
$( '.process_transactions_wizard .done-btn' ).removeClass( 'disable-image' );
|
||||
} else {
|
||||
$( '.process_transactions_wizard .done-btn' ).addClass( 'disable-image' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param e
|
||||
*/
|
||||
onDone( e ) {
|
||||
if ( e && $( e.target ).hasClass( 'disable-image' ) == false ) {
|
||||
var $this = LocalCacheData.current_open_wizard_controllers.find( wizard => wizard.wizard_id === this.wizard_id );
|
||||
|
||||
var data = { filter_data: {} };
|
||||
var external_data = $this.getExternalData();
|
||||
if ( external_data ) {
|
||||
if ( !external_data.filter_data ) {
|
||||
data.filter_data = external_data;
|
||||
} else {
|
||||
data.filter_data = external_data.filter_data;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !data || !data.filter_data ) {
|
||||
data.filter_data = {};
|
||||
}
|
||||
|
||||
if ( !data.filter_data.remittance_source_account_id ) {
|
||||
data.filter_data.remittance_source_account_id = [];
|
||||
}
|
||||
|
||||
if ( !data.filter_data.setup_last_check_number ) {
|
||||
data.setup_last_check_number = {};
|
||||
}
|
||||
|
||||
var table_rows = $( '#process_transactions_wizard_source_account_table tr' );
|
||||
if ( table_rows.length > 0 ) {
|
||||
for ( var x = 0; x < table_rows.length; x++ ) {
|
||||
var row = $( table_rows[x] );
|
||||
if ( row.find( '[type="checkbox"]' ).is( ':checked' ) ) {
|
||||
data.filter_data.remittance_source_account_id.push( row.find( '[type="checkbox"]' ).val() );
|
||||
data.setup_last_check_number[row.find( '[type="checkbox"]' ).val()] = row.find( 'input.last_transaction_number' ).val();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( data.filter_data.remittance_source_account_id.length > 0 ) {
|
||||
$( e.target ).addClass( 'disable-image' );
|
||||
var post_data = { 0: data, 1: true, 2: 'export_transactions' };
|
||||
var api = TTAPI.APIPayStub;
|
||||
Global.APIFileDownload( api.className, 'getPayStub', post_data );
|
||||
} else {
|
||||
Debug.Text( 'No source accounts selected', 'ProcessTransactionsWizard.js', 'ProcessTransactionsWizard', 'onDone', 10 );
|
||||
}
|
||||
$this.onCloseClick( true );
|
||||
}
|
||||
}
|
||||
|
||||
onCloseClick( e ) {
|
||||
if ( e === true || ( e && $( e.target ).hasClass( 'disable-image' ) == false ) ) {
|
||||
//if process payroll wizard is minimized, click it.
|
||||
if ( $( '#min_tab_ProcessPayrollWizard' )[0] ) {
|
||||
$( $( '#min_tab_ProcessPayrollWizard' )[0] ).click();
|
||||
}
|
||||
this.cleanUp();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<div class="wizard process_transactions_wizard">
|
||||
<span class="title">Process Transactions</span>
|
||||
<div class="progress-bar">
|
||||
<div class="title-1-div">
|
||||
<div class="logo"></div>
|
||||
<span class="title-1">Process Transactions</span>
|
||||
</div>
|
||||
<div class="clear-both-div"></div>
|
||||
<!--
|
||||
<progress class="progress" max="10" value="0">
|
||||
</progress>
|
||||
<span class="steps"></span>
|
||||
-->
|
||||
</div>
|
||||
<div class="content">
|
||||
</div>
|
||||
<div class="download_warning">
|
||||
</div>
|
||||
<div class="bottom-actions">
|
||||
<div class="confirm-buttons-div">
|
||||
<button class="done-btn disable-image"></button>
|
||||
<button class="close-btn"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,29 @@
|
||||
import { ProcessTransactionsWizard } from '@/views/payroll/process_transactions_wizard/ProcessTransactionsWizard';
|
||||
|
||||
export class ProcessTransactionsWizardController extends BaseWindowController {
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
el: '.process_transactions_wizard',
|
||||
|
||||
wizard_obj: null
|
||||
} );
|
||||
|
||||
super( options );
|
||||
}
|
||||
|
||||
init( external_data ) {
|
||||
var $this = this;
|
||||
|
||||
var wizard_id = 'ProcessTransactionsWizard';
|
||||
//LocalCacheData[this.wizard_id] is set when the wizard is minimized due to external navigation
|
||||
if ( !$this.wizard_obj && LocalCacheData[wizard_id] ) {
|
||||
$this.wizard_obj = LocalCacheData[wizard_id];
|
||||
delete LocalCacheData[wizard_id];
|
||||
} else {
|
||||
$this.wizard_obj = new ProcessTransactionsWizard( {
|
||||
el: $( '.process_transactions_wizard' ),
|
||||
external_data: external_data
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
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 <button class="done-btn"></button> 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 = $( '<div></div>' );
|
||||
var form = $( '<form id="process_transactions_wizard_select_accounts_form"></form>' ).appendTo( container );
|
||||
|
||||
var table = $( '<table id="process_transactions_wizard_source_account_table"></table>' );
|
||||
var header_row = $( '<tr></tr>' );
|
||||
header_row.html( '<th colspan="7">' + instruction_text + '<br><br></th>' );
|
||||
var column_header_row = $( '<tr></tr>' );
|
||||
var th_chk = $( '<th></th>' ).appendTo( column_header_row );
|
||||
var th_name = $( '<th></th>' ).html( $.i18n._( 'Source Account' ) ).appendTo( column_header_row );
|
||||
var th_format = $( '<th></th>' ).html( $.i18n._( 'Type' ) ).appendTo( column_header_row );
|
||||
var th_last_check = $( '<th></th>' ).html( $.i18n._( 'Last #' ) ).appendTo( column_header_row );
|
||||
var th_next_check = $( '<th></th>' ).html( $.i18n._( 'Next #' ) ).appendTo( column_header_row );
|
||||
var th_amount = $( '<th></th>' ).html( $.i18n._( 'Amount' ) ).appendTo( column_header_row );
|
||||
var th_transactions = $( '<th></th>' ).html( $.i18n._( 'Transactions' ) ).appendTo( column_header_row );
|
||||
table.append( header_row );
|
||||
table.append( column_header_row );
|
||||
for ( var n in this.source_accounts ) {
|
||||
var item = this.source_accounts[n];
|
||||
var row = $( '<tr></tr>' );
|
||||
var chk = $( '<input type="checkbox" value="' + item.id + '" tabIndex="' + tab_index + '" checked></input>' );
|
||||
tab_index++;
|
||||
|
||||
chk.on( 'change', function( e ) {
|
||||
e.preventDefault();
|
||||
$this.onCheck();
|
||||
} );
|
||||
|
||||
var td_chk = $( '<td></td>' ).append( chk ).appendTo( row );
|
||||
var td_name = $( '<td></td>' ).html( item.name ).appendTo( row );
|
||||
var td_format = $( '<td></td>' ).html( $.i18n._( item.type ) ).appendTo( row );
|
||||
var last_transaction_input = $( '<input value="' + item.last_transaction_number + '" class="last_transaction_number" type="text" style="width:60px" tabIndex="' + tab_index + '">' );
|
||||
tab_index++;
|
||||
|
||||
last_transaction_input.on( 'keydown', function( e ) {
|
||||
$this.onCheckNoKeyDown( e );
|
||||
} );
|
||||
|
||||
last_transaction_input.on( 'keyup', function( e ) {
|
||||
var result_element = $( e.target ).parents( 'tr' ).find( '.next_transaction_number' );
|
||||
result_element.val( parseInt( $( e.target ).val() ) + 1 );
|
||||
} );
|
||||
|
||||
var next_transaction_input = $( '<input value="' + ( parseInt( item.last_transaction_number ) + 1 ) + '" class="next_transaction_number" type="text" style="width:60px" tabIndex="' + tab_index + '">' );
|
||||
tab_index++;
|
||||
|
||||
next_transaction_input.on( 'keydown', function( e ) {
|
||||
$this.onCheckNoKeyDown( e );
|
||||
} );
|
||||
|
||||
next_transaction_input.on( 'keyup', function( e ) {
|
||||
var result_element = $( e.target ).parents( 'tr' ).find( '.last_transaction_number' );
|
||||
result_element.val( parseInt( $( e.target ).val() ) - 1 );
|
||||
} );
|
||||
|
||||
var td_last_check = $( '<td></td>' ).append( last_transaction_input ).appendTo( row );
|
||||
var td_last_check = $( '<td></td>' ).append( next_transaction_input ).appendTo( row );
|
||||
var td_last_check = $( '<td></td>' ).html( item.total_amount ).appendTo( row );
|
||||
var td_last_check = $( '<td></td>' ).html( item.total_transactions ).appendTo( row );
|
||||
|
||||
row.appendTo( table );
|
||||
}
|
||||
|
||||
form.append( table );
|
||||
$( this.getWizardObject().el ).find( '.content' ).html( container );
|
||||
$( this.getWizardObject().el ).find( '.done-btn' ).removeClass( 'disable-image' );
|
||||
//reset preload data
|
||||
this.source_accounts = null;
|
||||
this.filter = null;
|
||||
} else {
|
||||
$( this.getWizardObject().el ).find( '.content' ).html( 'No transactions to process.' );
|
||||
$( this.getWizardObject().el ).find( '.done-btn' ).addClass( 'disable-image' );
|
||||
}
|
||||
|
||||
this.onCheck(); //ensure that the done button is enabled by default
|
||||
TTPromise.resolve( 'processTransactionsWizard', 'render' );
|
||||
}
|
||||
|
||||
onCheckNoKeyDown( e ) {
|
||||
//only allow digits, delete, backspace and arrows
|
||||
if ( isNaN( e.key ) && [9, 8, 46, 37, 39].indexOf( e.keyCode ) == -1 ) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
onCheck() {
|
||||
var checkboxes = $( this.getWizardObject().el ).find( '.content input[type="checkbox"]' ).filter( ':checked' );
|
||||
if ( checkboxes.length > 0 ) {
|
||||
var data = [];
|
||||
checkboxes.each( function() {
|
||||
data.push( $( this ).val() );
|
||||
} );
|
||||
this.getWizardObject().setTransactionIds( data );
|
||||
|
||||
$( this.getWizardObject().el ).find( '.done-btn' ).removeClass( 'disable-image' );
|
||||
} else {
|
||||
this.getWizardObject().setTransactionIds( [] );
|
||||
$( this.getWizardObject().el ).find( '.done-btn' ).addClass( 'disable-image' );
|
||||
}
|
||||
}
|
||||
|
||||
setFilterData( data ) {
|
||||
this.filter_data = data;
|
||||
TTPromise.resolve( 'ProcessTransactionsWizardStepHome', 'init_filter' );
|
||||
}
|
||||
|
||||
getFilterData() {
|
||||
return this.filter_data;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user