<?php

if (!empty($$class->ar_revenue_schedule_id)) {
 $mode = 2;
 $readonly = 1;
}
$class_second = 'ar_transaction_line';
$$class_second = &$ar_transaction_line;

$$class->document_type = 'Batch';
$$class->reference_type = 'table';

if (!empty($_GET['org_id'])) {
 $$class->org_id = filter_input(INPUT_GET, 'org_id', FILTER_SANITIZE_NUMBER_INT);
}



if (!empty($_GET['ar_transaction_header_id'])) {
 $ar_transaction_header_id = filter_input(INPUT_GET, 'ar_transaction_header_id', FILTER_SANITIZE_NUMBER_INT);
 $ar_trnx_h = ar_transaction_header::find_by_id($ar_transaction_header_id);
} else if (!empty($_GET["transaction_number"])) {
 $transaction_number = filter_input(INPUT_GET, 'transaction_number', FILTER_SANITIZE_NUMBER_INT);
 $ar_trnx_h_arr = ar_transaction_header::find_by_ColumnNameVal('transaction_number', $transaction_number, '', '', true);
 $ar_trnx_h = array_pop($ar_trnx_h_arr);
 $ar_transaction_header_id = $ar_trnx_h->ar_transaction_header_id;
} else if (!empty($$class->ar_transaction_header_id)) {
 $ar_transaction_header_id = $$class->ar_transaction_header_id;
 $ar_trnx_h = ar_transaction_header::find_by_id($ar_transaction_header_id);
}

if (!empty($ar_transaction_header_id) && empty($$class->ar_revenue_schedule_id)) {
 $$class->ar_transaction_header_id = $ar_transaction_header_id;
 $$class->transaction_number = $ar_trnx_h->transaction_number;
 $ar_trnx_line_object = ar_transaction_line::find_by_parent_id($ar_transaction_header_id);
 if (count($ar_trnx_line_object) == 0) {
  $ar_trnx_line_object = [new ar_transaction_line()];
 }
} else if (!empty($ar_transaction_header_id) && !empty($$class->ar_revenue_schedule_id)) {
 $$class->transaction_number = $ar_trnx_h->transaction_number;
 $ar_trnx_line_object = [$$class];
 if (count($ar_trnx_line_object) == 0) {
  $ar_trnx_line_object = [new ar_transaction_line()];
 }
}

if (!empty($ar_trnx_h)) {
 $$class->transaction_type = $ar_trnx_h->transaction_type;
 $$class->transaction_class = $ar_trnx_h->transaction_class;
 $$class->transaction_number = $ar_trnx_h->transaction_number;
 $$class->document_owner = $ar_trnx_h->document_owner;
 $$class->trnx_description = $ar_trnx_h->description;
 $$class->currency = $ar_trnx_h->currency;
 $$class->doc_currency = $ar_trnx_h->doc_currency;
 $$class->exchange_rate_type = $ar_trnx_h->exchange_rate_type;
 $$class->trnx_exchange_rate = $ar_trnx_h->exchange_rate;
 $$class->transaction_status = $ar_trnx_h->transaction_status;
 $$class->document_date = $ar_trnx_h->document_date;
 $$class->document_number = $ar_trnx_h->document_number;
 $$class->ledger_id = $ar_trnx_h->ledger_id;
 $$class->trnx_period_id = $ar_trnx_h->period_id;
}


if ((!empty($ar_transaction_header_id)) && !empty($ar_trnx_line_object)) {
 $transaction_line_stament = '<select class=" select transaction_line_seq large" name="ar_transaction_line_id[]">';
 $transaction_line_stament .= '<option></option>';
 foreach ($ar_trnx_line_object as $array) {
  $transaction_line_stament .='<option ';
  $transaction_line_stament .=' data-ar_transaction_line_id ="' . $array->ar_transaction_line_id . '"';
  $transaction_line_stament .=' data-ar_transaction_header_id ="' . $array->ar_transaction_header_id . '"';
  $transaction_line_stament .=' data-line_number ="' . $array->line_number . '"';
  $transaction_line_stament .=' data-item_id_m ="' . $array->item_id_m . '"';
  $transaction_line_stament .=' data-item_description ="' . $array->item_description . '"';
  $transaction_line_stament .=' data-inv_line_quantity ="' . $array->inv_line_quantity . '"';
  $transaction_line_stament .=' data-inv_unit_price ="' . $array->inv_unit_price . '"';
  $transaction_line_stament .=' data-inv_line_price ="' . $array->inv_line_price . '"';
  $transaction_line_stament .=' data-line_type ="' . $array->line_type . '"';
  $transaction_line_stament .=' data-line_description ="' . $array->line_description . '"';
  $transaction_line_stament .=' value="' . $array->ar_transaction_line_id . '" >';
  $transaction_line_stament .= 'Line-' . $array->line_number . ' | ' . $array->item_description . ' | ' . $array->line_description;
  $transaction_line_stament .= '</option>';
 }
 $transaction_line_stament .= '</select>';
}
if ((!empty($ar_transaction_header_id))) {
 $adjustment_line_object = ar_revenue_schedule::find_by_parent_id($ar_transaction_header_id);
} else {
 $adjustment_line_object = null;
}

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




$$class->adjustment_type = 'ADJ';
?>