-
Notifications
You must be signed in to change notification settings - Fork 4
/
X12_811_Export.php
1384 lines (1120 loc) · 43.4 KB
/
X12_811_Export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
This script is intended to be used for outputting an
ANSI ASC X12.811 (Financial Series [FIN]) Consolidated Service Invoice/Statement (version 004010)
- A .txt file is output as 1 continuous string of characters
- You can change the linefeed switch to make the output file more readable (see PARAMETERS section below)
- If there are no errors, and the invoice count is greater than zero, a summary email is output
- If there are no errors, and the invoice count is zero, a warning email is output
- If there are errors an error email is output
For debugging, uncomment out the echo commands.
*/
/* ************************************************************************************************ */
// Iteration levels:
// 1. Store
// 2. Invoice
// 3. Item IT1
// 4. Sub-Line Item SLN
/********** PARAMETERS **********/
// Set filename to the full path and filename of the file to be output.
$filename='C:\\EDI__Test\\X12__811.txt';
// Set linefeed to "\n" to make the output file somewhat 'human readable' by inserting a linefeed between each segment
// or set to "" for production
//$linefeed="";
$linefeed="\n";
/********************************/
/* Message strings for logs/email notifications */
$infomsg="";
$errormsg="";
/* Counts for logs/email summaries */
$check__count=0;
$claim__count=0;
$proc__count=0;
$charges=0;
$net__amount=0;
$total__NumberofIncludedSegments=0;
$X12__811__File = fopen($filename,'w');
/* ************************************************************************************************ */
// ISA - INTERCHANGE CONTROL HEADER
//
// NOTE: All elements of the ISA are Mandatory
//
$ISA01__AuthorInfoQual="00";
// 00 = No Authorization Information Present (No Meaningful Information in I02)
// 03 = Additional Data Identification
$ISA02__AuthorInformation=" ";
$ISA03__SecurityInfoQual="00";
// 00 = No Security Information Present (No Meaningful Information in I04)
// 03 = Password
$ISA04__SecurityInformation=" ";
$ISA05__InterchangeIDQual="ZZ";
// 01 Duns (Dun & Bradstreet)
// 14 Duns Plus Suffix
// 20 Health Industry Number (HIN) CODE SOURCE 121: Health Industry Number
// 27 Carrier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 28 Fiscal Intermediary Identification Number as assigned by Health Care Financing Administration (HCFA)
// 29 Medicare Provider and Supplier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 30 U.S. Federal Tax Identification Number
// 33 National Association of Insurance Commissioners Company Code (NAIC)
// ZZ Mutually Defined
$ISA06__InterchangeSenderID="XXXXXXXXXXXXXXX";
// ??? Your ADVANTIS Userid
$ISA07__InterchangeIDQual="ZZ";
// 01 Duns (Dun & Bradstreet)
// 14 Duns Plus Suffix
// 20 Health Industry Number (HIN) CODE SOURCE 121: Health Industry Number
// 27 Carrier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 28 Fiscal Intermediary Identification Number as assigned by Health Care Financing Administration (HCFA)
// 29 Medicare Provider and Supplier Identification Number as assigned by Health Care Financing Administration (HCFA)
// 30 U.S. Federal Tax Identification Number
// 33 National Association of Insurance Commissioners Company Code (NAIC)
// ZZ Mutually Defined
$ISA08__InterchangeReceiverID="SAFL SAFL107";
// ID for SAFELITE
$ISA09__InterchangeDate=date("ymd");
$ISA10__InterchangeTime=date("hm");
$ISA11__InterchangeStandardID="U";
$ISA12__InterchangeControlVersionID="00401";
$ISA13__InterchangeControlNumber="0".date("mdHi");
$ISA14__InterchangeAckRequested="0";
// 0 No Interchange Acknowledgement Requested
// 1 Interchange Acknowledgement Requested (TA1)
$ISA15__TestIndicator="T";
// P=Production, T=test
$ISA16__SubElementSeperator=">";
// echo "__ ISA\n";
fwrite($X12__811__File, "ISA*"
.$ISA01__AuthorInfoQual."*"
.$ISA02__AuthorInformation."*"
.$ISA03__SecurityInfoQual."*"
.$ISA04__SecurityInformation."*"
.$ISA05__InterchangeIDQual."*"
.$ISA06__InterchangeSenderID."*"
.$ISA07__InterchangeIDQual."*"
.$ISA08__InterchangeReceiverID."*"
.$ISA09__InterchangeDate."*"
.$ISA10__InterchangeTime."*"
.$ISA11__InterchangeStandardID."*"
.$ISA12__InterchangeControlVersionID."*"
.$ISA13__InterchangeControlNumber."*"
.$ISA14__InterchangeAckRequested."*"
.$ISA15__TestIndicator."*"
.$ISA16__SubElementSeperator
."~".$linefeed);
/* ************************************************************************************************ */
// GS - FUNCTIONAL GROUP HEADER
//
// NOTE: All elements of the GS are Mandatory
//
$GS01__FunctionalIdentifierCode="CI";
// CI = Consolidated Service Invoice/Statement (811)
$GS02__ApplicationSendersCode="SGC3PINV";
$GS03__ApplicationReceiversCode="SAFL SAFL107";
$GS04__GroupDate=date("Ymd");
$GS05__GroupTime=date("hm");
$GS06__GroupControlNumber="123456789";
// ???
$GS07__ResponsibleAgencyCode="X";
// X = Accredited Standards Committee X12
$GS08__VersionRelease="004010";
// 005010X221A1 Standards Approved for Publication by ASC X12 Procedures Review Board through October 2003
// echo "__ GS\n";
fwrite($X12__811__File, "GS*".
$GS01__FunctionalIdentifierCode."*".
$GS02__ApplicationSendersCode."*".
$GS03__ApplicationReceiversCode."*".
$GS04__GroupDate."*".
$GS05__GroupTime."*".
$GS06__GroupControlNumber."*".
$GS07__ResponsibleAgencyCode."*".
$GS08__VersionRelease.
"~".$linefeed);
/* ************************************************************************************************ */
// ST - TRANSACTION SET HEADER
$ST01__TransactionSetId="811";
$ST02__TransactionSetControlNumber="0001000001";
// echo "__ ST\n";
fwrite($X12__811__File, "ST*".
$ST01__TransactionSetId."*".
$ST02__TransactionSetControlNumber.
"~".$linefeed);
$TransactionSegmentCount=1;
/* ************************************************************************************************ */
// BIG Beginning Segment for Invoice
$BIG01__InvoiceDate="20".$dom->getElement('InvoiceDate');
$BIG02__BatchNumber=$dom->getElement('InvoiceNumber');
// echo "__ BIG\n";
fwrite($X12__811__File, "BIG*".
$BIG01__InvoiceDate."*".
$BIG02__BatchNumber.
"~".$linefeed);
$TransactionSegmentCount=1;
/* ************************************************************************************************ */
// N1 - SUBMITTTER
$N101__EntityIdentifierCode="41";
// Mandatory
// 41 Submitter
$N102__Name=$dom->getElement('OriginationCompanyID');
// ???
// Mandatory
// echo "N1 - 41\n";
fwrite($X12__811__File, "N1*".
$N101__EntityIdentifierCode."*".
$N102__Name.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N1 - RECEIVER
$N101__EntityIdentifierCode="40";
// Mandatory
// 40 Receiver
$N102__Name=="SAFELITE";
// Mandatory
// echo "N1 - 40\n";
fwrite($X12__811__File, "N1*".
$N101__EntityIdentifierCode."*".
$N102__Name.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// HL - 1 Service Provider
$HL01__HeirarchicalNumber="1";
$HL02__HeirarchicalParentIDNumber="";
$HL03__HeirarchicalLevelCode="1";
// Service Provider
// echo "HL - 1\n";
fwrite($X12__811__File, "HL*".
$HL01__HeirarchicalNumber."*".
$HL02__HeirarchicalParentIDNumber."*".
$HL03__HeirarchicalLevelCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// NM1 - Service Provider
$NM101__EntityIdentifierCode="SJ";
// Mandatory
// SJ - Service Provider
$NM102__EntityTypeQualifier="2";
// Mandatory
// 1 Person
// 2 Non-Person Entity
$NM103__NameLast=$dom->getElement('OriginationPID');
// ???
// Optional
// echo "NM1*SJ\n";
fwrite($X12__811__File, "NM1*".
$NM101__EntityIdentifierCode."*".
$NM102__EntityTypeQualifier."*".
$NM103__NameLast.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - BAI - Business Identification Number
$REF01__ReferenceNumberQualifier="BAI";
$REF02__ReferenceNumber=$dom->getElement('VendorIDCode');
// '09nnnn' Parent Number as assigned by Safelite
// ???
// echo "REF*BAI\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// HL - 2 Billing Arrangement
$HL01__HeirarchicalNumber="2";
$HL02__HeirarchicalParentIDNumber="1";
$HL03__HeirarchicalLevelCode="2";
// Billing Arrangement
// echo "HL - 2\n";
fwrite($X12__811__File, "HL*".
$HL01__HeirarchicalNumber."*".
$HL02__HeirarchicalParentIDNumber."*".
$HL03__HeirarchicalLevelCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// NM1 - Billing Arrangement
$NM101__EntityIdentifierCode="RI";
// Mandatory
// RI - Remit To
$NM102__EntityTypeQualifier="2";
// Mandatory
// 1 Person
// 2 Non-Person Entity
$NM103__NameLast=$dom->getElement('???');
// ???
// Optional
$NM104__NameFirst="";
// Optional
$NM105__NameMiddle="";
// Optional
$NM106__NamePrefix="";
// Not used by Safelite
$NM107__NameSuffix="";
// Optional
$NM108__IDCodeQualifier="FI";
// Mandatory
// FI Federal Taxpayer’s Identification Number
$NM109__IDCode=$dom->getElement('???');
// ???
// Mandatory
// echo "NM1*RI\n";
fwrite($X12__811__File, "NM1*".
$NM101__EntityIdentifierCode."*".
$NM102__EntityTypeQualifier."*".
$NM103__NameLast."*".
$NM104__NameFirst."*".
$NM105__NameMiddle."*".
$NM106__NamePrefix."*".
$NM107__NameSuffix."*".
$NM108__IDCodeQualifier."*".
$NM109__IDCode.
"~".$linefeed);
$TransactionSegmentCount++;
$GE01__NumberofTransactionSetsIncluded=0;
$TransactionSetControlNumber=0;
/* ************************************************************************************************ */
// Iterate thru the entire dataset
while($dataset!="EOF") //???
{
/* ************************************************************************************************ */
// HL - 3 Provider Information
$HL01__HeirarchicalNumber="3";
$HL02__HeirarchicalParentIDNumber="2";
$HL03__HeirarchicalLevelCode="19";
// Provider Information
// echo "HL - 2\n";
fwrite($X12__811__File, "HL*".
$HL01__HeirarchicalNumber."*".
$HL02__HeirarchicalParentIDNumber."*".
$HL03__HeirarchicalLevelCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// NM1 - Store Name
$NM101__EntityIdentifierCode="SN";
// Mandatory
// SN - Store Name
$NM102__EntityTypeQualifier="2";
// Mandatory
// 1 Person
// 2 Non-Person Entity
$NM103__NameLast=$dom->getElement('RetailerName');
// ???
// Optional
$NM104__NameFirst="";
// Optional
$NM105__NameMiddle="";
// Optional
$NM106__NamePrefix="";
// Not used by Safelite
$NM107__NameSuffix="";
// Optional
$NM108__IDCodeQualifier="FA";
// Mandatory
// FA Facility Identification
$NM109__IDCode=$dom->getElement('ShopTaxNumber');
// ???
// Mandatory
// echo "NM1*RI\n";
fwrite($X12__811__File, "NM1*".
$NM101__EntityIdentifierCode."*".
$NM102__EntityTypeQualifier."*".
$NM103__NameLast."*".
$NM104__NameFirst."*".
$NM105__NameMiddle."*".
$NM106__NamePrefix."*".
$NM107__NameSuffix."*".
$NM108__IDCodeQualifier."*".
$NM109__IDCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N2 - Store Number
// ???
if($dom->getElement('StoreNumber') != "")
{
$N201__Name=$dom->getElement('StoreNumber');
// echo "N2\n";
fwrite($X12__811__File, "N2*".
$N201__Name.
"~".$linefeed);
$TransactionSegmentCount++;
}
/* ************************************************************************************************ */
// N3 - Address
$N302__AddressLine1=$dom->getElement('RetailerAddress');
$N302__AddressLine2="";
// echo "N3\n";
if($N302__AddressLine2=="")
{ fwrite($X12__811__File, "N3*".$N301__AddressLine1."~".$linefeed); }
else
{ fwrite($X12__811__File, "N3*".$N301__AddressLine1."*".$N302__AddressLine2."~".$linefeed); }
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N4 - Geographic Location
$N401__city=$dom->getElement('RetailerCity');
// Mandatory
$N402__state=$dom->getElement('RetailerState');
// Mandatory
$N403__zip=$dom->getElement('RetailerZip');
// Mandatory
// echo "N4\n";
fwrite($X12__811__File, "N4*".
$N401__city."*".
$N402__state."*".
$N403__zip.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// PER - Contact Name
$PER01__ContactFunctionCode="CN";
// Mandatory
// CN Contact Name
$PER02__Name=$dom->getElement('RetailerContact');
// Optional
$PER03__CommunicationNumberQualifier="TE";
// Optional
// EM Electronic Mail
// FX Facsimile
// TE Telephone
$PER04__CommunicationNumber=$dom->getElement('RetailerTelephone');
// Optional
// echo "PER*CN\n";
fwrite($X12__811__File, "PER*".
$PER01__ContactFunctionCode."*".
$PER02__Name."*".
$PER03__CommunicationNumberQualifier."*".
$PER04__CommunicationNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// Iterate Invoices
while($dataset!="EOF" && $invoice != "EOInvoice") //???
{
/* ************************************************************************************************ */
// HL - 4
$HL01__HeirarchicalNumber="4";
$HL02__HeirarchicalParentIDNumber="3";
$HL03__HeirarchicalLevelCode="3";
// Insured and Vehicle Information
// echo "HL - 4\n";
fwrite($X12__811__File, "HL*".
$HL01__HeirarchicalNumber."*".
$HL02__HeirarchicalParentIDNumber."*".
$HL03__HeirarchicalLevelCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// LX - Assigned Number
$LX01__AssignedNumber=1;
// Mandatory
// echo "LX\n";
fwrite($X12__811__File, "LX*".
$LX01__AssignedNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// VEH - Vehicle Information
$VEH01__AssignedNumber="";
// Optional
$VEH02__VIN=$dom->getElement('VehicleIDNumber');
// ???
// Optional
$VEH03__Year=$dom->getElement('VehicleYear');
// ???
// Optional
$VEH04__AgencyIDCode="NG";
// NG = NAGS database
// Mandatory
$VEH05__Make=$dom->getElement('VehicleMake');
// ???
// Mandatory - Maximum 12 Characters
$VEH06__Model=$dom->getElement('VehicleModel');
// ???
// Mandatory - Maximum 12 Characters
$VEH07__Style=$dom->getElement('VehicleStyle');
// ???
// Mandatory - Maximum 12 Characters
// echo "VEH\n";
fwrite($X12__811__File, "VEH*".
$VEH01__AssignedNumber."*".
$VEH02__VIN."*".
$VEH03__Year."*".
$VEH04__AgencyIDCode."*".
$VEH05__Make."*".
$VEH06__Model."*".
$VEH07__Style.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - IV - Invoice Number
$REF01__ReferenceNumberQualifier="IV";
$REF02__ReferenceNumber=$dom->getElement('InvoiceNumber');
// ???
// echo "REF*IV\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - QY - Mobile Flag
$REF01__ReferenceNumberQualifier="QY";
if($dom->getElement('MobileIndicator')=="S") // S = Store ???
{ $REF02__ReferenceNumber="N"; }
else
{ $REF02__ReferenceNumber="Y"; }
// ???
// echo "REF*QY\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - IG - Policy Number
$REF01__ReferenceNumberQualifier="IV";
$REF02__ReferenceNumber=$dom->getElement('PolicyNumber');
// ???
// echo "REF*IG\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - D9 - Claim Number
$REF01__ReferenceNumberQualifier="D9";
$REF02__ReferenceNumber=$dom->getElement('ClaimNumber');
// ???
// echo "REF*D9\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - PO - Safelite Referral Number
$REF01__ReferenceNumberQualifier="PO";
$REF02__ReferenceNumber=$dom->getElement('ReferralNumber');
// ???
// echo "REF*PO\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - ZZ - Signed Copy of Invoice on File
$REF01__ReferenceNumberQualifier="ZZ";
if($dom->getElement('SignedInvoiceOnFile')=="S")
{ $REF02__ReferenceNumber="Y"; }
else
{ $REF02__ReferenceNumber="N"; }
// ???
// echo "REF*ZZ\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - 6O - GlassMate Car ID Number
$REF01__ReferenceNumberQualifier="6O";
$REF02__ReferenceNumber=$dom->getElement('CarIDNumber');
// ???
// echo "REF*6O\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// AMT - Invoice Amount
$AMT01__AmountQualCode="BD";
$AMT02__MonetaryAmount=number_format($dom->getElement('InvoiceNetAmount'),2,'.','');
// echo "AMT*BD\n";
fwrite($X12__811__File, "AMT*".
$AMT01__AmountQualCode."*".
$AMT02__MonetaryAmount.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// DTM - Invoice DATE
$DTM01__DateTimeQualifier="003";
// Mandatory
// 003 Invoice Date
$DTM02__Date="20".$dom->getElement('InvoiceDate');
// Mandatory
// echo "DTM*003\n";
fwrite($X12__811__File, "DTM*".
$DTM01__DateTimeQualifier."*".
$DTM02__Date.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// DTM - Install/Completion DATE
$DTM01__DateTimeQualifier="198";
// Mandatory
// 198 Install/Completion Date
$DTM02__Date="20".$dom->getElement('InstallationDate');
// Mandatory
// echo "DTM*198\n";
fwrite($X12__811__File, "DTM*".
$DTM01__DateTimeQualifier."*".
$DTM02__Date.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// DTM - Referral/Assigned DATE
$DTM01__DateTimeQualifier="141";
// Mandatory
// 141 Referral/Assigned Date
$DTM02__Date="20".$dom->getElement('ReferralDate');
// ???
// Mandatory
// echo "DTM*141\n";
fwrite($X12__811__File, "DTM*".
$DTM01__DateTimeQualifier."*".
$DTM02__Date.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// DTM - Referral/Assigned DATE
$DTM01__DateTimeQualifier="142";
// Mandatory
// 142 Date Of Loss
$DTM02__Date="20".$dom->getElement('DateOfLoss');
// Mandatory
// echo "DTM*142\n";
fwrite($X12__811__File, "DTM*".
$DTM01__DateTimeQualifier."*".
$DTM02__Date.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// TXI - Tax Information
$TXI01__TaxTypeCode="TX";
// Mandatory
// TX - All Taxes
$TXI02__Amount=number_format($dom->getElement('TaxAmount'),2,'.','');
// Mandatory
// echo "TXI\n";
fwrite($X12__811__File, "TXI*".
$TXI01__TaxTypeCode."*".
$TXI02__Amount.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// NM1 - Insured's Name
$NM101__EntityIdentifierCode="IL";
// Mandatory
// IL - Insured's name
$NM102__EntityTypeQualifier="1";
// Mandatory
// 1 Person
// 2 Non-Person Entity
$NM103__NameLast=$dom->getElement('InsuredOrClaimantLastName');
// ???
// Mandatory
$NM104__NameFirst=$dom->getElement('InsuredOrClaimantFirstName');
// ???
// Optional
// echo "NM1*IL\n";
fwrite($X12__811__File, "NM1*".
$NM101__EntityIdentifierCode."*".
$NM102__EntityTypeQualifier."*".
$NM103__NameLast."*".
$NM104__NameFirst.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N3 - Address
$N302__AddressLine1=$dom->getElement('InsuredAddress1');
$N302__AddressLine2=$dom->getElement('InsuredAddress2');
// echo "N3\n";
if($N302__AddressLine2=="")
{ fwrite($X12__811__File, "N3*".$N301__AddressLine1."~".$linefeed); }
else
{ fwrite($X12__811__File, "N3*".$N301__AddressLine1."*".$N302__AddressLine2."~".$linefeed); }
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// N4 - Geographic Location
$N401__city=$dom->getElement('InsuredCity');
// Mandatory
$N402__state=$dom->getElement('InsuredState');
// Mandatory
$N403__zip=$dom->getElement('InsuredZip');
// Mandatory
// echo "N4\n";
fwrite($X12__811__File, "N4*".
$N401__city."*".
$N402__state."*".
$N403__zip.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// PER - Contact Name
$PER01__ContactFunctionCode="CN";
// Mandatory
// CN Contact Name
$PER02__Name="";
// Optional
$PER03__CommunicationNumberQualifier="HP";
// Mandatory
// HP Home Phone
$PER04__CommunicationNumber=$dom->getElement('InsuredOrClaimantTelephone');
// Mandatory
// echo "PER*CN\n";
fwrite($X12__811__File, "PER*".
$PER01__ContactFunctionCode."*".
$PER02__Name."*".
$PER03__CommunicationNumberQualifier."*".
$PER04__CommunicationNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// ITA - Allowance, Charge or Service
$ITA01__AllowanceOrCharge="A";
// Mandatory
// A = Allowance
// C = Charge
// S = Service
$ITA02__AgencyQualCode="";
// Not used by Safelite
$ITA03__SpecialServiceCode="";
// Not used by Safelite
$ITA04__MethodOfHandling="06";
// Mandatory
// 06 - Paid by customer or insured
// (amount to be collected by glass store)
$ITA05__AllowanceOrCharge="";
// Not used by Safelite
$ITA06__AllowanceOrCharge="";
// Not used by Safelite
$ITA07__AllowanceOrChargeTotal=number_format($dom->getElement('DeductibleAmount'),2,'','');
// Optional
$ITA08__AllowanceOrChargePercentQual="";
// Not used by Safelite
$ITA09__AllowanceOrChargePercent="";
// Not used by Safelite
$ITA10__AllowanceOrChargeQuantity="";
// Not used by Safelite
$ITA11__UnitBasisMeasure="";
// Not used by Safelite
$ITA12__Quantity="";
// Not used by Safelite
$ITA13__Description="";
// Not used by Safelite
$ITA14__SpecialChargeCode="DED";
// Mandatory
// DED = Deductible
// echo "ITA*A\n";
fwrite($X12__811__File, "PER*".
$ITA01__AllowanceOrCharge."*".
$ITA02__AgencyQualCode."*".
$ITA03__SpecialServiceCode."*".
$ITA04__MethodOfHandling."*".
$ITA05__AllowanceOrCharge."*".
$ITA06__AllowanceOrCharge."*".
$ITA07__AllowanceOrChargeTotal."*".
$ITA08__AllowanceOrChargePercentQual."*".
$ITA09__AllowanceOrChargePercent."*".
$ITA10__AllowanceOrChargeQuantity."*".
$ITA11__UnitBasisMeasure."*".
$ITA12__Quantity."*".
$ITA13__Description."*".
$ITA14__SpecialChargeCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// HL - 5
$HL01__HeirarchicalNumber="5";
$HL02__HeirarchicalParentIDNumber="4";
$HL03__HeirarchicalLevelCode="V";
// Address Level
// echo "HL - 5\n";
fwrite($X12__811__File, "HL*".
$HL01__HeirarchicalNumber."*".
$HL02__HeirarchicalParentIDNumber."*".
$HL03__HeirarchicalLevelCode.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// NM1 - Insurer Name
$NM101__EntityIdentifierCode="IN";
// Mandatory
// IN - Insurer's name
$NM102__EntityTypeQualifier="2";
// Mandatory
// 1 Person
// 2 Non-Person Entity
$NM103__NameLast=$dom->getElement('InsurerName');
// ???
// Mandatory
// echo "NM1*IN\n";
fwrite($X12__811__File, "NM1*".
$NM101__EntityIdentifierCode."*".
$NM102__EntityTypeQualifier."*".
$NM103__NameLast.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - PID - Program ID Number
// This element contains the Program ID Number assigned to this insurance company for
// this invoice; will be the value that is sent on the 272 or Fax.
$REF01__ReferenceNumberQualifier="PID";
$REF02__ReferenceNumber=$dom->getElement('ProgramIDNumber');
// ???
// echo "REF*PID\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - 5E - Consumer Identification
// This element will contain ‘Y’ when a premium part is used and proof of purchase
// documents are available at the installing glass shop.
$REF01__ReferenceNumberQualifier="5E";
$REF02__ReferenceNumber=$dom->getElement('PremiumPartIndicator');
// ???
// echo "REF*5E\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
/* ************************************************************************************************ */
// REF - MR - Merchandise Type Code
// This element will contain ‘Y’ when a OEM part is used and proof of purchase documents
// are available at the installing glass shop.
$REF01__ReferenceNumberQualifier="MR";
$REF02__ReferenceNumber=$dom->getElement('OEMPartUsedIndicator');
// ???
// echo "REF*MR\n";
fwrite($X12__811__File, "REF*".
$REF01__ReferenceNumberQualifier."*".
$REF02__ReferenceNumber.
"~".$linefeed);
$TransactionSegmentCount++;
$HL01__HeirarchicalNumber=5;
$HL02__HeirarchicalParentIDNumber=4;
$IT101__AssignedID=0;
/* ************************************************************************************************ */
// Iterate Invoices Items
while($dataset!="EOF" && $invoice != "EOInvoice") //???
{
/* ************************************************************************************************ */
// HL
$HL01__HeirarchicalNumber++;