Skip to content

Instantly share code, notes, and snippets.

@pdcawley
Created November 28, 2013 08:48

Revisions

  1. pdcawley created this gist Nov 28, 2013.
    41 changes: 41 additions & 0 deletions ProcessTollData.pm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    elsif (!$txn){
    # No records found, maybe it the vehicle was exchanged, so check if there
    # is an exchange record relating to a *CLOSED* RA on record. Again, we
    # can't rely on the data for the currently OPEN records.
    my $exchanges = $exchange_rs->search({
    date => { '>=' => $transaction_date->ymd },
    prev_date_out => { '<=' => $transaction_date->ymd },
    vehicle_in => $vehicle->vehicle_no,
    });
    my $clean_transaction_time = $transaction_time;
    $clean_transaction_time =~ s/://;
    while (my $row = $exchanges->next){
    # Now we need to check the times, we can't use check_valid_data_time
    # as that is designed for checking an RA or Non-Rev against the toll
    my $valid_time = 0;
    if ($row->date->ymd eq $transaction_date->ymd){
    if ($row->time >= $clean_transaction_time){
    $valid_time++;
    }
    }
    else {
    $valid_time++;
    }
    if ($row->prev_date_out->ymd eq $transaction_date->ymd){
    if ($row->prev_time_out <= $clean_transaction_time){
    $valid_time++;
    }
    }
    else {
    $valid_time++;
    }

    if ($valid_time == 2){
    # Retrieve the RA related to this exchange record. If the RA is closed,
    # we can assign it now, else it will be done at close in C+
    my $ra = $ra_rs->find($row->ra_number);
    $txn = $ra if $ra->is_closed;
    }
    }
    }