`;
}
function setDeductions( data ) {
var render = $this.getRender(); //get render, should be a table
var headerRow = getHeaderThreeColumn();
var args = {
col1: $.i18n._( 'Deductions' ),
col2: $.i18n._( 'Note' ),
col3: $.i18n._( 'Amount' ),
col4: $.i18n._( 'YTD Amount' )
};
var template = _.template( headerRow );
$( render ).append( template( args ) );
$this.rows_widgets_array.push( true );
for ( var i = 0; i < _.size( data ); i++ ) {
if ( Global.isSet( data[i] ) ) {
var row = data[i];
row.type_id = 20;
$this.addRow( row );
}
}
$( render ).append( '
' );
$this.rows_widgets_array.push( true );
}
function setNetPay( data ) {
var render = $this.getRender(); //get render, should be a table
if ( data ) {
// data.type_id = 40;
$this.addRow( data );
}
$( render ).append( '
' );
$this.rows_widgets_array.push( true );
}
function setMiscellaneous( data ) {
var render = $this.getRender(); //get render, should be a table
var headerRow = getHeaderThreeColumn();
var args = {
col1: $.i18n._( 'Miscellaneous' ),
col2: $.i18n._( 'Note' ),
col3: $.i18n._( 'Amount' ),
col4: $.i18n._( 'YTD Amount' )
};
var template = _.template( headerRow );
$( render ).append( template( args ) );
$this.rows_widgets_array.push( true );
for ( var i in data ) {
$this.addRow( data[i] );
}
$( render ).append( '
' );
$this.rows_widgets_array.push( true );
}
function setEmployerContributions( data ) {
var render = $this.getRender(); //get render, should be a table
var headerRow = getHeaderThreeColumn();
var args = {
col1: $.i18n._( 'Employer Contributions' ),
col2: $.i18n._( 'Note' ),
col3: $.i18n._( 'Amount' ),
col4: $.i18n._( 'YTD Amount' )
};
var template = _.template( headerRow );
$( render ).append( template( args ) );
$this.rows_widgets_array.push( true );
for ( var i = 0; i < _.size( data ); i++ ) {
if ( Global.isSet( data[i] ) ) {
var row = data[i];
row.type_id = 30;
$this.addRow( row );
}
}
$( render ).append( '
' );
$this.rows_widgets_array.push( true );
}
function setAccrual( data ) {
var render = $this.getRender(); //get render, should be a table
var headerRow = getHeaderThreeColumn();
var args = {
col1: $.i18n._( 'Accrual' ),
col2: $.i18n._( 'Note' ),
col3: $.i18n._( 'Amount' ),
col4: $.i18n._( 'Balance' )
};
var template = _.template( headerRow );
$( render ).append( template( args ) );
$this.rows_widgets_array.push( true );
for ( var i = 0; i < _.size( data ); i++ ) {
if ( Global.isSet( data[i] ) ) {
var row = data[i];
row.type_id = 50;
$this.addRow( row );
}
}
$( render ).append( '
' );
$this.rows_widgets_array.push( true );
}
if ( this.parent_controller.isEditMode() == true || this.parent_controller.checkForNonHeaderData( val[10] ) ) {
setEarnings( val[10] );
}
if ( this.parent_controller.isEditMode() == true || this.parent_controller.checkForNonHeaderData( val[20] ) ) {
setDeductions( val[20] );
}
setNetPay( val[40] );
if ( this.parent_controller.isEditMode() == true || this.parent_controller.checkForNonHeaderData( val[80] ) ) {
setMiscellaneous( val[80] );
}
if ( this.parent_controller.isEditMode() == true || this.parent_controller.checkForNonHeaderData( val[30] ) ) {
setEmployerContributions( val[30] );
}
if ( this.parent_controller.isEditMode() == true || this.parent_controller.checkForNonHeaderData( val[50] ) ) {
setAccrual( val[50] );
}
if ( this.parent_controller.editor.transaction_data ) {
this.parent_controller.editor.insideTransactionEditorSetValue( this.parent_controller.editor.transaction_data );
}
if ( this.parent_controller.copied_record_id && TTUUID.isUUID( this.parent_controller.copied_record_id ) ) {
this.parent_controller.copied_record_id = '';
}
this.calcTotal();
}
checkForNonHeaderData( data ) {
for ( var n in data ) {
if ( TTUUID.isUUID( data[n].id ) == true ) {
return true;
}
}
return false;
}
insideEntryEditorAddRow( data, index ) {
var $this = this;
if ( !data ) {
$this.addRow( {}, index );
} else {
if ( typeof index != 'undefined' && typeof this.rows_widgets_array[index].ytd_amount != 'undefined' && !data['type_id'] ) {
data['type_id'] = this.rows_widgets_array[index].ytd_amount.attr( 'type_id' );
}
function renderColumns( data, type, index ) {
var render = $this.getRender(); //get render, should be a table
var widgets = {}; //Save each row's widgets
var row; //Get Row render
var widgetContainer = $( '' );
var right_label;
var args = { filter_data: {} };
var pay_stub_amendment_id = '', user_expense_id = '';
var pay_stub_status_id = $this.parent_controller['current_edit_record']['status_id'];
var is_add = false;
if ( ( !$this.parent_controller['current_edit_record']['id'] && !$this.parent_controller.copied_record_id ) || ( !data.id ) ) {
is_add = true;
}
if ( pay_stub_status_id == 40 || pay_stub_status_id == 100 ) {
is_add = false;
}
if ( TTUUID.isUUID( data['pay_stub_amendment_id'] ) && data['pay_stub_amendment_id'] != TTUUID.zero_id ) {
pay_stub_amendment_id = data['pay_stub_amendment_id'];
}
if ( TTUUID.isUUID( data['user_expense_id'] ) && data['user_expense_id'] != TTUUID.zero_id ) {
user_expense_id = data['user_expense_id'];
}
if ( $this.parent_controller.copied_record_id ) {
pay_stub_amendment_id = '';
user_expense_id = '';
}
var row_enabled = true;
// if the pay_stub_amendment_id and user_expense_id all >0 how to display the right label?
if ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) {
right_label = $( ' (' + $.i18n._( 'Amendment' ) + ')' );
row_enabled = false;
} else if ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) {
right_label = $( ' (' + $.i18n._( 'Expense' ) + ')' );
row_enabled = false;
}
if ( type == 10 ) {
row = $( `
` );
} else {
row = $( `
` );
}
// Pay Stub Account
var form_item_name_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_name_input.AComboBox( {
api_class: TTAPI.APIPayStubEntryAccount,
width: 132,
is_static_width: 132,
allow_multiple_selection: false,
layout_name: 'global_PayStubAccount',
show_search_inputs: true,
set_empty: true,
field: 'pay_stub_entry_name_id'
} );
form_item_name_input.setValue( data.pay_stub_entry_name_id );
form_item_name_input.setEnabled( row_enabled );
form_item_name_input.unbind( 'formItemChange' ).bind( 'formItemChange', function( e, target ) {
$this.onFormItemChange( target );
} );
var form_item_name_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_name_text.TText( { field: 'name' } );
form_item_name_text.setValue( data.name ? ( ( data['type_id'] != 40 ) ? ' ' + data.name : data.name ) : '' );
// Note(description)
var form_item_note_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_note_input.TTextInput( { field: 'description', width: 300, display_na: false } );
form_item_note_input.setValue( data.description );
form_item_note_input.attr( 'editable', true );
var form_item_note_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_note_text.TText( { field: 'description', display_na: false } );
form_item_note_text.setValue( data.description ? data.description : ' ' );
// Rate
var form_item_rate_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_rate_input.TTextInput( { field: 'rate', width: 60, hasKeyEvent: true } );
form_item_rate_input.setValue( Global.removeTrailingZeros( data.rate ) );
form_item_rate_input.attr( 'editable', true );
form_item_rate_input.unbind( 'formItemKeyUp' ).bind( 'formItemKeyUp', function( e, target ) {
$this.onFormItemKeyUp( target );
} );
form_item_rate_input.unbind( 'formItemKeyDown' ).bind( 'formItemKeyDown', function( e, target ) {
$this.onFormItemKeyDown( target );
} );
form_item_rate_input.unbind( 'formItemChange' ).bind( 'formItemChange', function( e, target ) {
$this.onFormItemChange( target );
} );
var form_item_rate_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_rate_text.TText( { field: 'rate' } );
form_item_rate_text.setValue( Global.removeTrailingZeros( data.rate ) );
// Hrs/Units
var form_item_units_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_units_input.TTextInput( { field: 'units', width: 60, hasKeyEvent: true } );
form_item_units_input.setValue( Global.removeTrailingZeros( data.units ) );
form_item_units_input.attr( 'editable', true );
form_item_units_input.unbind( 'formItemKeyUp' ).bind( 'formItemKeyUp', function( e, target ) {
$this.onFormItemKeyUp( target );
} );
form_item_units_input.unbind( 'formItemKeyDown' ).bind( 'formItemKeyDown', function( e, target ) {
$this.onFormItemKeyDown( target );
} );
form_item_units_input.unbind( 'formItemChange' ).bind( 'formItemChange', function( e, target ) {
$this.onFormItemChange( target );
} );
var form_item_units_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_units_text.TText( { field: 'units' } );
form_item_units_text.setValue( Global.removeTrailingZeros( data.units ) );
// Amount
var form_item_amount_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_amount_input.TTextInput( { field: 'amount', width: 60 } );
form_item_amount_input.setValue( Global.removeTrailingZeros( data.amount ) );
form_item_amount_input.unbind( 'formItemKeyUp' ).bind( 'formItemKeyUp', function( e, target ) {
$this.onFormItemKeyUp( target );
} );
form_item_amount_input.unbind( 'formItemKeyDown' ).bind( 'formItemKeyDown', function( e, target ) {
$this.onFormItemKeyDown( target );
} );
form_item_amount_input.unbind( 'formItemChange' ).bind( 'formItemChange', function( e, target ) {
$this.onFormItemChange( target );
} );
var form_item_amount_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_amount_text.TText( { field: 'amount' } );
form_item_amount_text.setValue( Global.removeTrailingZeros( data.amount ) );
// YTD Amount
var form_item_ytd_amount_text = Global.loadWidgetByName( FormItemType.TEXT );
form_item_ytd_amount_text.TText( { field: 'ytd_amount' } );
form_item_ytd_amount_text.setValue( Global.removeTrailingZeros( data.ytd_amount ) );
form_item_ytd_amount_text.attr( {
'pay_stub_entry_id': ( data.id && $this.parent_controller.current_edit_record.id ) ? data.id : '',
'type_id': data['type_id'],
'original_amount': data['amount'] ? data['amount'] : '0.00',
'original_ytd_amount': data['ytd_amount'] ? data['ytd_amount'] : '0.00',
'pay_stub_entry_name_id': data['pay_stub_entry_name_id'] ? data['pay_stub_entry_name_id'] : null
} );
// if ( !$this.parent_controller.copied_record_id ) {
form_item_ytd_amount_text.attr( 'pay_stub_amendment_id', pay_stub_amendment_id );
form_item_ytd_amount_text.attr( 'user_expense_id', user_expense_id );
// }
if ( parseFloat( data['ytd_amount'] ) != 0 ) {
} else if ( pay_stub_status_id == 40 || pay_stub_status_id == 100 || data.total_row === true ) {
form_item_ytd_amount_text.text( '-' );
}
if ( data.rate && parseFloat( data.rate ) != 0 && !$this.parent_controller.copied_record_id ) {
form_item_amount_input.setReadOnly( true );
} else if ( pay_stub_status_id == 40 || pay_stub_status_id == 100 || data.total_row === true ) {
form_item_rate_text.text( '-' );
}
if ( data.units && parseFloat( data.units ) != 0 && !$this.parent_controller.copied_record_id ) {
form_item_amount_input.setReadOnly( true );
} else if ( pay_stub_status_id == 40 || pay_stub_status_id == 100 || data.total_row === true ) {
form_item_units_text.text( '-' );
}
// name
if ( type == 40 || data.total_row === true ) {
if ( data['type_id'] == 40 || data.total_row === true ) {
form_item_name_text.css( 'font-weight', 'bold' );
}
widgets[form_item_name_text.getField()] = form_item_name_text;
widgetContainer.append( form_item_name_text );
widgetContainer.append( right_label );
row.children().eq( 0 ).append( widgetContainer );
} else {
if ( $this.parent_controller.isEditMode() == true || index ) {
if ( data['type_id'] == 40 || data.total_row === true ) {
form_item_name_text.css( 'font-weight', 'bold' );
widgets[form_item_name_text.getField()] = form_item_name_text;
widgetContainer.append( form_item_name_text );
widgetContainer.append( right_label );
row.children().eq( 0 ).append( widgetContainer );
} else {
args['filter_data']['type_id'] = [type];
form_item_name_input.setDefaultArgs( args );
widgets[form_item_name_input.getField()] = form_item_name_input;
widgetContainer.append( form_item_name_input );
widgetContainer.append( right_label );
row.children().eq( 0 ).append( widgetContainer );
}
} else {
if ( data['type_id'] == 40 || data.total_row === true ) {
form_item_name_text.css( 'font-weight', 'bold' );
}
widgets[form_item_name_text.getField()] = form_item_name_text;
widgetContainer.append( form_item_name_text );
widgetContainer.append( right_label );
row.children().eq( 0 ).append( widgetContainer );
}
}
// Note
if ( ( data['type_id'] == type.toString() || data['type_id'] === type ) && type != 40 && !data.total_row ) {
if ( $this.parent_controller.isEditMode() == true ) {
if ( ( ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) || ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) ) ) {
form_item_note_input.setReadOnly( true );
}
widgets[form_item_note_input.getField()] = form_item_note_input;
row.children().eq( 1 ).append( form_item_note_input );
} else {
widgets[form_item_note_text.getField()] = form_item_note_text;
row.children().eq( 1 ).append( form_item_note_text );
}
} else {
if ( Global.isSet( index ) || is_add || ( _.size( data ) === 1 && ( $this.parent_controller.isEditMode() == true ) ) ) {
if ( ( data['type_id'] == 40 || data.total_row === true ) ) {
} else {
widgets[form_item_note_input.getField()] = form_item_note_input;
row.children().eq( 1 ).append( form_item_note_input );
}
} else if ( type == 20 || type == 30 || type == 50 || type == 80 ) {
widgets[form_item_note_text.getField()] = form_item_note_text;
row.children().eq( 1 ).append( form_item_note_text );
}
}
// amount
if ( ( data['type_id'] === type.toString() || data['type_id'] === type ) && type != 40 && !data.total_row ) {
if ( $this.parent_controller.isEditMode() == true ) {
if ( ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) || ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) ) {
form_item_amount_input.setReadOnly( true );
}
widgets[form_item_amount_input.getField()] = form_item_amount_input;
if ( type == 10 ) {
row.children().eq( 4 ).append( form_item_amount_input );
} else {
row.children().eq( 2 ).append( form_item_amount_input );
}
} else {
widgets[form_item_amount_text.getField()] = form_item_amount_text;
if ( type == 10 ) {
row.children().eq( 4 ).append( form_item_amount_text );
} else {
row.children().eq( 2 ).append( form_item_amount_text );
}
}
} else {
if ( ( Global.isSet( index ) || is_add || ( _.size( data ) === 1 && ( $this.parent_controller.isEditMode() == true ) ) ) && type != 40 && !data.total_row ) {
if ( data['type_id'] == 40 ) {
form_item_amount_text.css( 'font-weight', 'bold' );
widgets[form_item_amount_text.getField()] = form_item_amount_text;
if ( type == 10 ) {
row.children().eq( 4 ).append( form_item_amount_text );
} else {
row.children().eq( 2 ).append( form_item_amount_text );
}
} else {
widgets[form_item_amount_input.getField()] = form_item_amount_input;
if ( type == 10 ) {
row.children().eq( 4 ).append( form_item_amount_input );
} else {
row.children().eq( 2 ).append( form_item_amount_input );
}
}
} else {
if ( ( data['type_id'] == 40 || data.total_row ) && type == 30 ) {
form_item_amount_text.css( 'font-weight', 'bold' );
} else {
form_item_amount_text.css( 'font-weight', 'bold' );
}
widgets[form_item_amount_text.getField()] = form_item_amount_text;
if ( type == 10 ) {
row.children().eq( 4 ).append( form_item_amount_text );
} else {
row.children().eq( 2 ).append( form_item_amount_text );
}
}
}
// Ytd amount
if ( data['type_id'] == 40 || data.total_row ) {
form_item_ytd_amount_text.css( 'font-weight', 'bold' );
}
if ( ( Global.isSet( index ) || is_add || _.size( data ) === 1 ) && type != 40 ) {
form_item_ytd_amount_text.text( '-' );
}
widgets[form_item_ytd_amount_text.getField()] = form_item_ytd_amount_text;
if ( type == 10 ) {
row.children().eq( 5 ).append( form_item_ytd_amount_text );
} else {
row.children().eq( 3 ).append( form_item_ytd_amount_text );
}
if ( type == 10 ) { // && !data.total_row ) {
// rate
if ( data['type_id'] == 10 && !data.total_row ) {
if ( $this.parent_controller.isEditMode() == true ) {
if ( ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) || ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) ) {
form_item_rate_input.setReadOnly( true );
}
widgets[form_item_rate_input.getField()] = form_item_rate_input;
row.children().eq( 2 ).append( form_item_rate_input );
} else {
widgets[form_item_rate_text.getField()] = form_item_rate_text;
row.children().eq( 2 ).append( form_item_rate_text );
}
} else {
if ( Global.isSet( index ) || is_add ) {
if ( data['type_id'] == 40 || data.total_row ) {
} else {
widgets[form_item_rate_input.getField()] = form_item_rate_input;
row.children().eq( 2 ).append( form_item_rate_input );
}
}
}
// units
if ( data['type_id'] == 10 && !data.total_row ) {
if ( $this.parent_controller.isEditMode() == true ) {
if ( ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) || ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) ) {
form_item_units_input.setReadOnly( true );
}
widgets[form_item_units_input.getField()] = form_item_units_input;
row.children().eq( 3 ).append( form_item_units_input );
} else {
widgets[form_item_units_text.getField()] = form_item_units_text;
row.children().eq( 3 ).append( form_item_units_text );
}
} else {
if ( Global.isSet( index ) || is_add ) {
if ( data['type_id'] == 40 || data.total_row ) {
form_item_units_text.css( 'font-weight', 'bold' );
widgets[form_item_units_text.getField()] = form_item_units_text;
row.children().eq( 3 ).append( form_item_units_text );
} else {
widgets[form_item_units_input.getField()] = form_item_units_input;
row.children().eq( 3 ).append( form_item_units_input );
}
} else {
form_item_units_text.css( 'font-weight', 'bold' );
widgets[form_item_units_text.getField()] = form_item_units_text;
row.children().eq( 3 ).append( form_item_units_text );
}
}
}
//Build row widgets
if ( ( TTUUID.isUUID( pay_stub_amendment_id ) && pay_stub_amendment_id != TTUUID.zero_id ) || ( TTUUID.isUUID( user_expense_id ) && user_expense_id != TTUUID.zero_id ) ) {
row.children().last().find( '.minus-icon ' ).hide();
}
if ( data['total_row'] == true ) {
widgets['total_row'] = true;
}
if ( typeof data['type_id'] != 'undefined' ) {
widgets['type_id'] = data['type_id'];
}
if ( data['pay_stub_entry_account_id'] == $this.parent_controller.pseal_link.net_pay_entry_account_id ) {
widgets['pay_stub_entry_account_id'] = $this.parent_controller.pseal_link.net_pay_entry_account_id;
}
if ( typeof index !== 'undefined' ) {
row.insertAfter( $( render ).find( 'tr' ).eq( index ) );
$this.rows_widgets_array.splice( ( index + 1 ), 0, widgets );
} else {
$( render ).append( row );
$this.rows_widgets_array.push( widgets );
}
if ( $this.parent_controller.isEditMode() == true ) {
$this.addIconsEvent( row ); //Bind event to add and minus icon
} else {
row.children().last().empty();
}
if ( data.total_row || data.type_id == 40 ) {
row.find( '.plus-icon' ).remove();
row.find( '.minus-icon' ).remove();
}
}
if ( data['type_id'] == 10 ) {
renderColumns( data, 10, index );
} else if ( data['type_id'] == 20 ) {
renderColumns( data, 20, index );
} else if ( data['type_id'] == 30 ) {
renderColumns( data, 30, index );
} else if ( data['type_id'] == 40 ) {
renderColumns( data, 40, index );
} else if ( data['type_id'] == 50 ) {
renderColumns( data, 50, index );
} else if ( data['type_id'] == 80 ) {
renderColumns( data, 80, index );
}
}
}
insideEntryEditorRemoveRow( row ) {
var index = row[0].rowIndex;
if ( this.rows_widgets_array[index].ytd_amount ) {
var remove_id = this.rows_widgets_array[index].ytd_amount.attr( 'pay_stub_entry_id' );
var type_id = this.rows_widgets_array[index].ytd_amount.attr( 'type_id' );
if ( TTUUID.isUUID( remove_id ) ) {
this.delete_ids.push( remove_id );
}
row.remove();
if ( this.rows_widgets_array[index - 1] === true && ( this.rows_widgets_array[index + 1]['total_row'] === true || this.rows_widgets_array[index + 1] === true ) ) {
this.addRow( { id: '', type_id: type_id }, index - 1 );
this.rows_widgets_array.splice( index + 1, 1 ); //Remove from the array used in calcTotal()
} else {
this.rows_widgets_array.splice( index, 1 ); //Remove from the array used in calcTotal()
}
}
this.calcTotal();
}
savePayStub( record, callbackFunction ) {
// when the user create a new pay stub record have them can send entries to api.
if ( this.include_pay_stub_accounts ) {
var entries = this.saveInsideEntryEditorData();
var transactions = this.saveInsideTransactionEditorData();
if ( entries.length > 0 ) {
record['entries'] = entries;
}
if ( transactions.length > 0 ) {
record['transactions'] = transactions;
}
}
callbackFunction();
}
onSaveClick( ignoreWarning ) {
if ( this.is_mass_editing ) {
this.include_pay_stub_accounts = false;
}
super.onSaveClick( ignoreWarning );
}
doSaveAPICall( record, ignoreWarning, callback ) {
this.savePayStub( record, () => {
super.doSaveAPICall( record, true, callback );
} );
}
onSaveDone( result ) {
this.current_edit_record = null;
return true;
}
saveInsideTransactionEditorData( callBack ) {
//called by validation function
var $this = this;
var data = this.editor.insideTransactionEditorGetValue( $this.current_edit_record.id ? $this.current_edit_record.id : '' );
if ( this.editor.delete_transaction_ids.length > 0 ) {
for ( var i = 0; i < this.editor.delete_transaction_ids.length; i++ ) {
for ( var n = 0; n < data.length; n++ ) {
if ( this.editor.delete_transaction_ids[i] == data[n].id ) {
data[n].deleted = 1;
}
}
}
}
return data;
}
onCopyAsNewClick() {
var $this = this;
var reload_entries = false;
this.setCurrentEditViewState( 'new' );
LocalCacheData.current_doing_context_action = 'copy_as_new';
if ( Global.isSet( this.edit_view ) ) {
// for ( var i = 0; i < this.editor.rows_widgets_array.length; i++ ) {
// if ( this.editor.rows_widgets_array[i] === true ) {
// continue;
// }
// this.editor.rows_widgets_array[i].ytd_amount.attr( 'pay_stub_entry_id', '' );
// this.editor.rows_widgets_array[i].ytd_amount.removeAttr( 'pay_stub_amendment_id' );
// this.editor.rows_widgets_array[i].ytd_amount.removeAttr( 'user_expense_id' );
// }
this.copied_record_id = this.current_edit_record.id;
this.current_edit_record.id = '';
this.edit_view_ui_dic.user_id.setEnabled( true );
if ( this.current_edit_record.status_id != 25 ) {
this.current_edit_record.status_id = 25;
this.edit_view_ui_dic.status_id.setValue( 25 );
// this.editor.show_cover = false;
// this.include_pay_stub_accounts = true;
// reload_entries = true;
}
this.editor.show_cover = false;
// this.editor.removeCover();
var navigation_div = this.edit_view.find( '.navigation-div' );
navigation_div.css( 'display', 'none' );
this.setEditMenu();
this.setTabStatus();
this.is_changed = false;
// reset the entries data.
// if ( reload_entries ) {
this.editor.removeAllRows( true );
this.initInsideEntryEditorData();
// }
ProgressBar.closeOverlay();
} else {
var filter = {};
var grid_selected_id_array = this.getGridSelectIdArray();
var grid_selected_length = grid_selected_id_array.length;
var selectedId;
if ( grid_selected_length > 0 ) {
selectedId = grid_selected_id_array[0];
filter.filter_data = {};
filter.filter_data.id = [selectedId];
this.api['get' + this.api.key_name]( filter, {
onResult: function( result ) {
$this.onCopyAsNewResult( result );
}
} );
} else {
TAlertManager.showAlert( $.i18n._( 'No selected record' ) );
}
}
}
initEditView() {
this.original_status_id = this.current_edit_record.status_id;
super.initEditView();
}
onSubViewRemoved() {
this.search();
if ( !this.edit_view ) {
this.setDefaultMenu();
} else {
this.setEditMenu();
}
}
onCopyAsNewResult( result ) {
var $this = this;
var result_data = result.getResult();
if ( !result_data ) {
TAlertManager.showAlert( $.i18n._( 'Record does not exist' ) );
$this.onCancelClick();
return;
}
$this.openEditView(); // Put it here is to avoid if the selected one is not existed in data or have deleted by other pragram. in this case, the edit view should not be opend.
result_data = result_data[0];
this.copied_record_id = result_data.id;
result_data.id = '';
if ( $this.sub_view_mode && $this.parent_key ) {
result_data[$this.parent_key] = $this.parent_value;
}
if ( result_data.status_id != 25 ) {
result_data.status_id = 25; // If its status is not open then set it to open status.
}
$this.current_edit_record = result_data;
$this.editor.show_cover = false;
$this.initEditView();
}
onSaveAndContinue( ignoreWarning ) {
var $this = this;
if ( !Global.isSet( ignoreWarning ) ) {
ignoreWarning = false;
}
this.is_changed = false;
this.is_add = false;
LocalCacheData.current_doing_context_action = 'save_and_continue';
var record = this.current_edit_record;
this.original_status_id = record.status_id;
record = this.uniformVariable( record );
this.savePayStub( record, function() {
$this.api['set' + $this.api.key_name]( record, false, ignoreWarning, {
onResult: function( result ) {
$this.onSaveAndContinueResult( result );
}
} );
} );
}
onCancelClick() {
TTPromise.reject( 'PayStubViewController', 'insideEditorDataLoaded' );
super.onCancelClick();
}
openEditView() {
if ( this.editor ) {
this.editor.transaction_data = false;
}
TTPromise.reject( 'PayStubViewController', 'insideEditorDataLoaded' );
super.openEditView();
}
onMassEditClick() {
var $this = this;
$this.is_add = false;
$this.is_viewing = false;
$this.is_mass_editing = true;
LocalCacheData.current_doing_context_action = 'mass_edit';
$this.openEditView();
var filter = {};
var grid_selected_id_array = this.getGridSelectIdArray();
var grid_selected_length = grid_selected_id_array.length;
this.mass_edit_record_ids = [];
$.each( grid_selected_id_array, function( index, value ) {
$this.mass_edit_record_ids.push( value );
} );
filter.filter_data = {};
filter.filter_data.id = this.mass_edit_record_ids;
this.api['getCommon' + this.api.key_name + 'Data']( filter, {
onResult: function( result ) {
var result_data = result.getResult();
if ( !result_data ) {
result_data = [];
}
$this.api['getOptions']( 'unique_columns', {
onResult: function( result ) {
$this.unique_columns = result.getResult();
$this.api['getOptions']( 'linked_columns', {
onResult: function( result1 ) {
$this.linked_columns = result1.getResult();
if ( $this.sub_view_mode && $this.parent_key ) {
result_data[$this.parent_key] = $this.parent_value;
}
$this.current_edit_record = result_data;
$this.initEditView();
}
} );
}
} );
}
} );
}
onSaveAndContinueResult( result ) {
var $this = this;
if ( result.isValid() ) {
var result_data = result.getResult();
if ( result_data === true ) {
$this.refresh_id = $this.current_edit_record.id;
} else if ( TTUUID.isUUID( result_data ) && result_data != TTUUID.zero_id && result_data != TTUUID.not_exist_id ) {
$this.refresh_id = result_data;
}
$this.search( false );
$this.editor.show_cover = false;
$this.onEditClick( $this.refresh_id, true );
$this.onSaveAndContinueDone( result );
} else {
$this.setErrorTips( result );
$this.setErrorMenu();
}
}
// onSaveAndNextResult( result ) {
// var $this = this;
// if ( result.isValid() ) {
// var result_data = result.getResult();
// if ( result_data === true ) {
// $this.refresh_id = $this.current_edit_record.id;
// } else if ( TTUUID.isUUID( result_data ) && result_data != TTUUID.zero_id && result_data != TTUUID.not_exist_id ) {
// $this.refresh_id = result_data;
// }
// $this.editor.show_cover = true;
// $this.onRightArrowClick();
// $this.search( false );
// $this.onSaveAndNextDone( result );
//
// } else {
// $this.setErrorTips( result );
// $this.setErrorMenu();
// }
// },
saveInsideEntryEditorData( callBack ) {
//called by validation function
var $this = this;
var data = this.editor.getValue( $this.current_edit_record.id ? $this.current_edit_record.id : '' );
if ( this.editor.delete_ids.length > 0 ) {
for ( var i = 0; i < this.editor.delete_ids.length; i++ ) {
for ( var n = 0; n < data.length; n++ ) {
if ( this.editor.delete_ids[i] == data[n].id ) {
data[n].deleted = 1;
}
}
}
}
if ( callBack && typeof callBack == 'function' ) {
callBack();
}
return data;
}
insideEntryEditorGetValue( current_edit_item_id ) {
var len = this.rows_widgets_array.length;
var result = [];
if ( this.cover && this.cover.length > 0 ) {
return result;
}
for ( var i = 0; i < len; i++ ) {
var row = this.rows_widgets_array[i];
var data = {};
if ( row === true || _.isArray( row ) ) {
continue;
}
// var pay_stub_amendment_id = row['ytd_amount'].attr( 'pay_stub_amendment_id' );
// var user_expense_id = row['ytd_amount'].attr( 'user_expense_id' );
//
// if ( pay_stub_amendment_id > 0 || user_expense_id > 0 ) {
// continue;
// }
data['id'] = row['ytd_amount'].attr( 'pay_stub_entry_id' );
if ( row['ytd_amount'].attr( 'type_id' ) ) {
data['type'] = row['ytd_amount'].attr( 'type_id' );
}
data['rate'] = row['rate'] ? row['rate'].getValue() : '';
data['units'] = row['units'] ? row['units'].getValue() : '';
data['amount'] = row['amount'] ? row['amount'].getValue() : '';
if ( Global.isSet( row['ytd_amount'] ) ) {
data['ytd_amount'] = row['ytd_amount'].getValue();
}
data['description'] = row['description'] ? row['description'].getValue() : '';
if ( Global.isSet( row['pay_stub_entry_name_id'] ) ) {
data['pay_stub_entry_name_id'] = row['pay_stub_entry_name_id'].getValue();
} else {
data['pay_stub_entry_name_id'] = row['ytd_amount'].attr( 'pay_stub_entry_name_id' );
}
// return back to the server with the same data get from API.
data['pay_stub_amendment_id'] = row['ytd_amount'].attr( 'pay_stub_amendment_id' );
data['user_expense_id'] = row['ytd_amount'].attr( 'user_expense_id' );
data['pay_stub_id'] = current_edit_item_id;
if ( row['total_row'] != true && TTUUID.isUUID( data['pay_stub_entry_name_id'] )
&& ( data['pay_stub_entry_name_id'] != TTUUID.zero_id
|| ( data['description'] != undefined && data['description'].length > 0 )
|| ( data['rate'] != undefined && data['rate'].length > 0 && parseFloat( data['rate'] ) != 0 )
|| ( data['units'] != undefined && data['units'].length > 0 && parseFloat( data['units'] ) != 0 )
|| ( data['amount'] != undefined && data['amount'].length > 0 && parseFloat( data['amount'] ) != 0 )
) ) {
result.push( data );
}
}
return result;
}
getFilterColumnsFromDisplayColumns() {
var column_filter = {};
column_filter.is_owner = true;
column_filter.id = true;
column_filter.user_id = true;
column_filter.is_child = true;
column_filter.in_use = true;
column_filter.first_name = true;
column_filter.last_name = true;
column_filter.start_date = true;
column_filter.end_date = true;
column_filter.pay_period_id = true;
// Error: Unable to get property 'getGridParam' of undefined or null reference
var display_columns = [];
if ( this.grid ) {
display_columns = this.grid.getGridParam( 'colModel' );
}
if ( display_columns ) {
var len = display_columns.length;
for ( var i = 0; i < len; i++ ) {
var column_info = display_columns[i];
column_filter[column_info.name] = true;
}
}
return column_filter;
}
onFormItemChange( target, doNotValidate ) {
var $this = this;
this.setIsChanged( target );
this.setMassEditingFieldsWhenFormChange( target );
var key = target.getField();
var c_value = target.getValue();
this.current_edit_record[key] = c_value;
switch ( key ) {
// case 'status_id':
// if ( c_value == 40 || c_value == 100 ) {
// this.include_pay_stub_accounts = false;
// }
// break;
case 'user_id':
if ( this.is_add ) {
var transaction_rows = $this.editor.rows_widgets_array[$this.editor.rows_widgets_array.length - 2];
var user_id = $this.edit_view_ui_dic.user_id.getValue();
for ( var t in transaction_rows ) {
if ( Global.isArray( transaction_rows ) && transaction_rows[t].remittance_destination_account_id ) {
transaction_rows[t].remittance_destination_account_id.setDefaultArgs( { filter_data: { user_id: user_id } } );
transaction_rows[t].remittance_destination_account_id.setValue( TTUUID.zero_id );
}
}
}
break;
case 'country':
var widget = this.edit_view_ui_dic['province'];
widget.setValue( null );
break;
case 'pay_period_id':
var filter = {};
filter.filter_data = {};
filter.filter_data.id = c_value;
this.pay_period_api['get' + this.pay_period_api.key_name]( filter, {
onResult: function( res ) {
//Error: Uncaught TypeError: Cannot read property 'start_date' of undefined in interface/html5/#!m=PayStub&a=new&tab=PayStub line 1836
if ( res.isValid() && res.getResult()[0] ) {
var result = res.getResult()[0];
var start_date = Global.strToDate( result.start_date ).format();
var end_date = Global.strToDate( result.end_date ).format();
var transaction_date = Global.strToDate( result.transaction_date ).format();
$this.current_edit_record['start_date'] = start_date;
$this.current_edit_record['end_date'] = end_date;
$this.current_edit_record['transaction_date'] = transaction_date;
$this.edit_view_ui_dic['start_date'].setValue( start_date );
$this.edit_view_ui_dic['end_date'].setValue( end_date );
$this.edit_view_ui_dic['transaction_date'].setValue( transaction_date );
if ( !doNotValidate ) {
$this.validate();
}
}
}
} );
break;
default:
if ( !doNotValidate ) {
$this.validate();
}
break;
}
if ( key === 'country' || key === 'pay_period_id' ) {
return;
}
if ( !doNotValidate ) {
this.validate();
}
}
onSetSearchFilterFinished() {
if ( this.search_panel.getSelectTabIndex() === 1 ) {
var combo = this.adv_search_field_ui_dic['country'];
var select_value = combo.getValue();
this.setProvince( select_value );
}
}
onBuildAdvUIFinished() {
this.adv_search_field_ui_dic['country'].change( $.proxy( function() {
var combo = this.adv_search_field_ui_dic['country'];
var selectVal = combo.getValue();
this.setProvince( selectVal );
this.adv_search_field_ui_dic['province'].setValue( null );
}, this ) );
}
setProvince( val, m ) {
var $this = this;
if ( !val || val === '-1' || val === '0' ) {
$this.province_array = [];
this.adv_search_field_ui_dic['province'].setSourceData( [] );
} else {
this.company_api.getOptions( 'province', val, {
onResult: function( res ) {
res = res.getResult();
if ( !res ) {
res = [];
}
$this.province_array = Global.buildRecordArray( res );
$this.adv_search_field_ui_dic['province'].setSourceData( $this.province_array );
}
} );
}
}
eSetProvince( val, refresh ) {
var $this = this;
var province_widget = $this.edit_view_ui_dic['province'];
if ( !val || val === '-1' || val === '0' ) {
$this.e_province_array = [];
province_widget.setSourceData( [] );
} else {
this.company_api.getOptions( 'province', val, {
onResult: function( res ) {
res = res.getResult();
if ( !res ) {
res = [];
}
$this.e_province_array = Global.buildRecordArray( res );
if ( refresh && $this.e_province_array.length > 0 ) {
$this.current_edit_record.province = $this.e_province_array[0].value;
province_widget.setValue( $this.current_edit_record.province );
}
province_widget.setSourceData( $this.e_province_array );
}
} );
}
}
validate() {
var $this = this;
var record = {};
var transaction_record = {};
if ( this.is_mass_editing ) {
for ( var key in this.edit_view_ui_dic ) {
if ( !this.edit_view_ui_dic.hasOwnProperty( key ) ) {
continue;
}
var widget = this.edit_view_ui_dic[key];
if ( Global.isSet( widget.isChecked ) ) {
if ( widget.isChecked() && widget.getEnabled() ) {
record[key] = widget.getValue();
}
}
}
} else {
record = this.current_edit_record;
}
record = this.uniformVariable( record );
if ( this.include_pay_stub_accounts ) {
var entries = $this.saveInsideEntryEditorData();
var transactions = $this.saveInsideTransactionEditorData();
if ( typeof entries == 'object' ) {
record['entries'] = entries;
}
if ( typeof transactions == 'object' ) {
record['transactions'] = transactions;
}
}
this.api['validate' + this.api.key_name]( record, {
onResult: function( result ) {
$this.validateResult( result );
}
} );
}
buildEditViewUI() {
super.buildEditViewUI();
var $this = this;
var tab_model = {
'tab_pay_stub': {
'label': $.i18n._( 'Pay Stub' ), 'is_multi_column': true,
'html_template': this.getPayStubTabHtml()
},
'tab_audit': true,
};
this.setTabModel( tab_model );
this.navigation.AComboBox( {
api_class: TTAPI.APIPayStub,
id: this.script_name + '_navigation',
allow_multiple_selection: false,
layout_name: 'global_pay_stub',
navigation_mode: true,
show_search_inputs: true
} );
this.setNavigation();
//Tab 0 start
var tab_pay_stub = this.edit_view_tab.find( '#tab_pay_stub' );
var tab_pay_stub_column1 = tab_pay_stub.find( '.first-column' );
var tab_pay_stub_column2 = tab_pay_stub.find( '.second-column' );
// var tab_pay_stub_column3 = tab_pay_stub.find( '.third-column' );
var form_item_input;
this.edit_view_tabs[0] = [];
this.edit_view_tabs[0].push( tab_pay_stub_column1 );
// Employee
form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APIUser,
allow_multiple_selection: false,
layout_name: 'global_user',
show_search_inputs: true,
set_empty: false,
field: 'user_id'
} );
this.addEditFieldToColumn( $.i18n._( 'Employee' ), form_item_input, tab_pay_stub_column1 );
// Status
form_item_input = Global.loadWidgetByName( FormItemType.COMBO_BOX );
form_item_input.TComboBox( { field: 'status_id', set_empty: false } );
form_item_input.setSourceData( $this.filtered_status_array );
this.addEditFieldToColumn( $.i18n._( 'Status' ), form_item_input, tab_pay_stub_column1 );
// Type
form_item_input = Global.loadWidgetByName( FormItemType.COMBO_BOX );
form_item_input.TComboBox( { field: 'type_id', set_empty: false } );
form_item_input.setSourceData( $this.type_array );
this.addEditFieldToColumn( $.i18n._( 'Type' ), form_item_input, tab_pay_stub_column1 );
// Currency
form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APICurrency,
allow_multiple_selection: false,
layout_name: 'global_currency',
show_search_inputs: true,
set_empty: true,
field: 'currency_id'
} );
this.addEditFieldToColumn( $.i18n._( 'Currency' ), form_item_input, tab_pay_stub_column1 );
// Pay Period
form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APIPayPeriod,
allow_multiple_selection: false,
layout_name: 'global_Pay_period',
show_search_inputs: true,
set_empty: true,
field: 'pay_period_id'
} );
this.addEditFieldToColumn( $.i18n._( 'Pay Period' ), form_item_input, tab_pay_stub_column2 );
// Payroll Run
form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_input.TTextInput( { field: 'run_id', width: 20 } );
this.addEditFieldToColumn( $.i18n._( 'Payroll Run' ), form_item_input, tab_pay_stub_column2 );
// Pay Start Date
form_item_input = Global.loadWidgetByName( FormItemType.DATE_PICKER );
form_item_input.TDatePicker( { field: 'start_date' } );
this.addEditFieldToColumn( $.i18n._( 'Pay Start Date' ), form_item_input, tab_pay_stub_column2 );
// Pay End Date
form_item_input = Global.loadWidgetByName( FormItemType.DATE_PICKER );
form_item_input.TDatePicker( { field: 'end_date' } );
this.addEditFieldToColumn( $.i18n._( 'Pay End Date' ), form_item_input, tab_pay_stub_column2 );
// Payment Date
form_item_input = Global.loadWidgetByName( FormItemType.DATE_PICKER );
form_item_input.TDatePicker( { field: 'transaction_date' } );
this.addEditFieldToColumn( $.i18n._( 'Payment Date' ), form_item_input, tab_pay_stub_column2, '' );
//Inside pay stub entries editor
var inside_pay_stub_entry_editor_div = tab_pay_stub.find( '.inside-pay-stub-entry-editor-div' );
this.editor = Global.loadWidgetByName( FormItemType.INSIDE_EDITOR );
this.editor.InsideEditor( {
addRow: this.insideEntryEditorAddRow,
removeRow: this.insideEntryEditorRemoveRow,
getValue: this.insideEntryEditorGetValue,
setValue: this.insideEntryEditorSetValue,
parent_controller: this,
api: this.pay_stub_entry_api,
render: getRender(),
render_args: {},
render_inline_html: true,
row_render: getRowRender()
} );
function getRender() {
return `