[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5741] trunk/LedgerSMB



Revision: 5741
          http://sourceforge.net/p/ledger-smb/code/5741
Author:   einhverfr
Date:     2013-05-03 06:24:18 +0000 (Fri, 03 May 2013)
Log Message:
-----------
Adding 997, functional acknowledgement generation, for simple 997's only, and only one per doc

Modified Paths:
--------------
    trunk/LedgerSMB/X12/EDI850.pm
    trunk/LedgerSMB/X12.pm

Modified: trunk/LedgerSMB/X12/EDI850.pm
===================================================================
--- trunk/LedgerSMB/X12/EDI850.pm	2013-05-02 10:45:06 UTC (rev 5740)
+++ trunk/LedgerSMB/X12/EDI850.pm	2013-05-03 06:24:18 UTC (rev 5741)
@@ -56,7 +56,46 @@
                 my @elements = split(/\Q$sep\E/, $segment);
                 $sender_idx = $elements[5];
                 $sender_id = $elements[6];
+                $form->{edi_isa} = ..hidden..;
+                my @new_elements = (
+                   $elements[0],
+                   $elements[1],
+                   $elements[2],
+                   $elements[3],
+                   $elements[4],
+                   $elements[7],
+                   $elements[8],
+                   $elements[5],
+                   $elements[6],
+                   $elements[9],
+                   $elements[10],
+                   $elements[11],
+                   $elements[12],
+                   $elements[13],
+                   $elements[14],
+                   $elements[15],
+                   $elements[16],
+                );
+                $form->{edi_isa_return} = join $sep, @new_elements;
             }
+            when ('ST'){
+                my ($segment) = $self->parser->get_loop_segments;
+                my @elements = split(/\Q$sep\E/, $segment);
+                $form->{edi_st_id} = $elements[2];
+                $form->{edi_spec} = '850';
+            }
+            when ('GS'){
+                my ($segment) = $self->parser->get_loop_segments;
+                my @elements = split(/\Q$sep\E/, $segment);
+                $form->{edi_gs} = ..hidden..;
+                $form->{edi_f_id} = $elements[1];
+                $form->{edi_g_cc} = $elements[6];
+            }
+            when ('GE'){
+                my ($segment) = $self->parser->get_loop_segments;
+                my @elements = split(/\Q$sep\E/, $segment);
+                $form->{edi_ge} = ..hidden..;
+            }
             when ('BEG'){
                 my ($segment) = $self->parser->get_loop_segments;
                 my @elements = split(/\Q$sep\E/, $segment);

Modified: trunk/LedgerSMB/X12.pm
===================================================================
--- trunk/LedgerSMB/X12.pm	2013-05-02 10:45:06 UTC (rev 5740)
+++ trunk/LedgerSMB/X12.pm	2013-05-03 06:24:18 UTC (rev 5741)
@@ -31,7 +31,13 @@
 use Moose;
 use X12::Parser;
 use LedgerSMB::Sysconfig;
+use DateTime;
 
+my $counter = 1000; #for 997 generation
+my $dt = DateTime->now;
+my $date = sprintf('%04d%02d%02d', $dt->year, $dt->month, $dt->day);
+my $time = sprintf('%02d%02d', $dt->hour, $dt->min);
+
 =head1 REQUIRED PROPERTIES FOR PARSING
 
 =head2 message
@@ -184,6 +190,34 @@
     $self->parser->{_SEGMENT_SEPARATOR} = $sep;
 }
 
+=item write_997($form, $success)
+
+Returns the test of a 997 document from the current document.
+
+=cut
+
+sub write_997{
+    my ($self, $form, $success) = @_;
+     my $status;
+    if ($success){
+       $status = 'A';
+    } else {
+       $status = 'R';
+    }
+    my $sep = $self->parser->get_element_separator;
+    my $seg = $self->parser->{_SEGMENT_SEPARATOR}; 
+    my $x12_997 = "$form->{edi_isa_return}$seg";
+    $x12_997 .= "GS${sep}FA${sep}$form->{edi_gs}->[3]${sep}$form->{edi_gs}->[2]${sep}${date}${sep}${time}${sep}1${sep}X${sep}$form->{edi_gs}->[8]$seg"
+             .  "ST${sep}997${sep}${counter}${seg}"
+             .  "AK1${sep}$form->{edi_f_id}${sep}$form->{edi_g_cc}${seg}"
+             .  "AK9${sep}${status}${sep}1${sep}${success}${sep}$form->{edi_ge}->[1]${seg}"
+             .  "SE${sep}4${sep}${counter}$seg"
+             .  "GE${sep}1${sep}1$seg"
+             .  "IEA${sep}1${sep}$form->{edi_isa}->[13]$seg";
+   
+    return $x12_997;
+}
+
 =back
 
 =head1 COPYRIGHT

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.