<?php
$ref_doc_stmt = '';
$action_a = [ 'Entered' => 'No Action'];

$lgr = new gl_ledger;
if (!empty($$class->gl_journal_header_id)) {
 $readonly1 = 1;
 $ledger = $lgr->findBy_id($$class->ledger_id);
 $coa = coa::find_by_structure($ledger->coa_structure_id);
 $$class->coa_id = $coa->coa_id;
 $gp = new gl_period();
 $gp_i = $gp->findBy_id($$class->period_id);
 $all_open_periods = $gp->find_all_periods($$class->ledger_id, 'OPEN');
 $period_name_stmt = form::select_field_from_object('period_id', $all_open_periods, 'gl_period_id', 'period_name', $$class->period_id, 'gl_period_id', 1, '', '', $readonly1);

 //action array
 if ($$class->status == 'REVERSED') {
	$mode = 2;
 } elseif ($$class->status == 'POSTED') {
	$action_a = [ 'REVERSED' => 'Reverse'];
	$mode = 2;
 } elseif ($$class->status == 'ENTERED') {
	$action_a = [ 'POSTED' => 'Post', 'APPROVED' => 'Approve'];
 } elseif ($$class->status == 'APPROVED') {
	$action_a = [ 'POSTED' => 'Post', 'UNPOSTED' => 'Un Approve'];
 }

 //allow to change period for Reversed Journals
 if ($$class->journal_category == 'GL_REVERSAL') {
	$period_name_stmt = form::select_field_from_object('period_id', $all_open_periods, 'gl_period_id', 'period_name', $$class->period_id, 'gl_period_id', '', '', '', '');
 }
 
 //view reference statement
 if((!empty($$class->reference_type)) && (!empty($$class->reference_key_name)) && (!empty($$class->reference_key_value))){
	$ref_doc_stmt = show_reference_doc($$class->reference_key_name, $$class->reference_key_value);
//	$ref_doc_stmt = '<a href=\'form.php?class_name='. $$class->reference_key_name . '&gl_journal_header_id=' . $$class->reference_key_value. '&mode=2\'>View Reference Doc</a>';
 } 
} else {
 $period_name_stmt = form::text_field('period_id', 'Select Ledger', 14, '', 1, '', 'period_id', 1);
  if(empty($$class->status)){
  $$class->status = 'ENTERED';
 }
}

if(empty($$class->doc_currency) && !empty($$class->currency)){
 $$class->doc_currency = $$class->currency;
}

if(empty($$class->document_date)){
 $$class->document_date = current_time(true);
}

$$class->set_module_default();

?>