x12_alt 0.1.0

Data types for X12 EDI
Documentation
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
use std::fmt;
use serde::{de, Deserialize, ser, Serialize};
/**353

See docs at <https://www.stedi.com/edi/x12/element/353>*/
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TransactionSetPurposeCode {
    ///00 - Original
    Original,
    ///01 - Cancellation
    Cancellation,
    ///02 - Add
    Add,
    ///03 - Delete
    Delete,
    ///04 - Change
    Change,
    ///05 - Replace
    Replace,
    ///5C - Chargeable Resubmission
    ChargeableResubmission,
    ///06 - Confirmation
    Confirmation,
    ///07 - Duplicate
    Duplicate,
    ///08 - Status
    Status,
    ///10 - Not Found
    NotFound,
    ///11 - Response
    Response,
    ///12 - Not Processed
    NotProcessed,
    ///13 - Request
    Request,
    ///14 - Advance Notification
    AdvanceNotification,
    ///15 - Re-Submission
    ReSubmission,
    ///16 - Proposed
    Proposed,
    ///17 - Cancel, to be Reissued
    Code17,
    ///18 - Reissue
    Reissue,
    ///19 - Seller initiated change
    SellerInitiatedChange,
    ///20 - Final Transmission
    FinalTransmission,
    ///21 - Transaction on Hold
    TransactionOnHold,
    ///22 - Information Copy
    InformationCopy,
    ///24 - Draft
    Draft,
    ///25 - Incremental
    Incremental,
    ///26 - Replace - Specified Buyers Parts Only
    ReplaceSpecifiedBuyersPartsOnly,
    ///27 - Verify
    Verify,
    ///28 - Query
    Query,
    ///30 - Renewal
    Renewal,
    ///31 - Allowance/Addition
    AllowanceAddition,
    ///32 - Recovery/Deduction
    RecoveryDeduction,
    ///33 - Request for Payment
    RequestForPayment,
    ///34 - Payment Declined
    PaymentDeclined,
    ///35 - Request Authority
    RequestAuthority,
    ///36 - Authority to Deduct (Reply)
    Code36,
    ///37 - Authority Declined (Reply)
    Code37,
    ///38 - No Financial Value
    NoFinancialValue,
    ///39 - Response to Proposed Trip Plan
    ResponseToProposedTripPlan,
    ///40 - Commitment Advice
    CommitmentAdvice,
    ///41 - Corrected and Verified
    CorrectedAndVerified,
    ///42 - Temporary Record
    TemporaryRecord,
    ///43 - Request Permission to Service
    RequestPermissionToService,
    ///44 - Rejection
    Rejection,
    ///45 - Follow-up
    FollowUp,
    ///46 - Cancellation with Refund
    CancellationWithRefund,
    ///47 - Transfer
    Transfer,
    ///48 - Suspended
    Suspended,
    ///49 - Original - No Response Necessary
    OriginalNoResponseNecessary,
    ///50 - Register
    Register,
    ///51 - Historical Inquiry
    HistoricalInquiry,
    ///52 - Response to Historical Inquiry
    ResponseToHistoricalInquiry,
    ///53 - Completion
    Completion,
    ///54 - Approval
    Approval,
    ///55 - Excavation
    Excavation,
    ///56 - Expiration Notification
    ExpirationNotification,
    ///57 - Initial
    Initial,
    ///77 - Simulation Exercise
    SimulationExercise,
    ///CN - Completion Notification
    CompletionNotification,
    ///CO - Corrected
    Corrected,
    ///DA - Delegate to Alternative
    DelegateToAlternative,
    ///ED - Exhibit Disposition
    ExhibitDisposition,
    ///ER - Exhibit Receipt
    ExhibitReceipt,
    ///EX - Final Loading Configuration
    FinalLoadingConfiguration,
    ///FA - Forward to Action Point
    ForwardToActionPoint,
    ///FC - Forward to Contractor
    ForwardToContractor,
    ///FS - Forward to Support Point
    ForwardToSupportPoint,
    ///GR - Granted
    Granted,
    ///MD - Materiel Disposition
    MaterielDisposition,
    ///PR - Proposed Loading Configuration
    ProposedLoadingConfiguration,
    ///RH - Release Hold
    ReleaseHold,
    ///RO - Re-open
    ReOpen,
    ///RR - Reply Rebuttal
    ReplyRebuttal,
    ///RV - Revised Loading Configuration
    RevisedLoadingConfiguration,
    ///SB - Scan Based Trading
    ScanBasedTrading,
    ///SU - Status Update
    StatusUpdate,
    ///ZZ - Mutually Defined
    MutuallyDefined,
}
impl TransactionSetPurposeCode {
    pub fn code(&self) -> &str {
        {
            use TransactionSetPurposeCode::*;
            match self {
                Original => "00",
                Cancellation => "01",
                Add => "02",
                Delete => "03",
                Change => "04",
                Replace => "05",
                ChargeableResubmission => "5C",
                Confirmation => "06",
                Duplicate => "07",
                Status => "08",
                NotFound => "10",
                Response => "11",
                NotProcessed => "12",
                Request => "13",
                AdvanceNotification => "14",
                ReSubmission => "15",
                Proposed => "16",
                Code17 => "17",
                Reissue => "18",
                SellerInitiatedChange => "19",
                FinalTransmission => "20",
                TransactionOnHold => "21",
                InformationCopy => "22",
                Draft => "24",
                Incremental => "25",
                ReplaceSpecifiedBuyersPartsOnly => "26",
                Verify => "27",
                Query => "28",
                Renewal => "30",
                AllowanceAddition => "31",
                RecoveryDeduction => "32",
                RequestForPayment => "33",
                PaymentDeclined => "34",
                RequestAuthority => "35",
                Code36 => "36",
                Code37 => "37",
                NoFinancialValue => "38",
                ResponseToProposedTripPlan => "39",
                CommitmentAdvice => "40",
                CorrectedAndVerified => "41",
                TemporaryRecord => "42",
                RequestPermissionToService => "43",
                Rejection => "44",
                FollowUp => "45",
                CancellationWithRefund => "46",
                Transfer => "47",
                Suspended => "48",
                OriginalNoResponseNecessary => "49",
                Register => "50",
                HistoricalInquiry => "51",
                ResponseToHistoricalInquiry => "52",
                Completion => "53",
                Approval => "54",
                Excavation => "55",
                ExpirationNotification => "56",
                Initial => "57",
                SimulationExercise => "77",
                CompletionNotification => "CN",
                Corrected => "CO",
                DelegateToAlternative => "DA",
                ExhibitDisposition => "ED",
                ExhibitReceipt => "ER",
                FinalLoadingConfiguration => "EX",
                ForwardToActionPoint => "FA",
                ForwardToContractor => "FC",
                ForwardToSupportPoint => "FS",
                Granted => "GR",
                MaterielDisposition => "MD",
                ProposedLoadingConfiguration => "PR",
                ReleaseHold => "RH",
                ReOpen => "RO",
                ReplyRebuttal => "RR",
                RevisedLoadingConfiguration => "RV",
                ScanBasedTrading => "SB",
                StatusUpdate => "SU",
                MutuallyDefined => "ZZ",
            }
        }
    }
    pub fn from_code(code: &[u8]) -> Option<TransactionSetPurposeCode> {
        use TransactionSetPurposeCode::*;
        match code {
            b"00" => Some(Original),
            b"01" => Some(Cancellation),
            b"02" => Some(Add),
            b"03" => Some(Delete),
            b"04" => Some(Change),
            b"05" => Some(Replace),
            b"5C" => Some(ChargeableResubmission),
            b"06" => Some(Confirmation),
            b"07" => Some(Duplicate),
            b"08" => Some(Status),
            b"10" => Some(NotFound),
            b"11" => Some(Response),
            b"12" => Some(NotProcessed),
            b"13" => Some(Request),
            b"14" => Some(AdvanceNotification),
            b"15" => Some(ReSubmission),
            b"16" => Some(Proposed),
            b"17" => Some(Code17),
            b"18" => Some(Reissue),
            b"19" => Some(SellerInitiatedChange),
            b"20" => Some(FinalTransmission),
            b"21" => Some(TransactionOnHold),
            b"22" => Some(InformationCopy),
            b"24" => Some(Draft),
            b"25" => Some(Incremental),
            b"26" => Some(ReplaceSpecifiedBuyersPartsOnly),
            b"27" => Some(Verify),
            b"28" => Some(Query),
            b"30" => Some(Renewal),
            b"31" => Some(AllowanceAddition),
            b"32" => Some(RecoveryDeduction),
            b"33" => Some(RequestForPayment),
            b"34" => Some(PaymentDeclined),
            b"35" => Some(RequestAuthority),
            b"36" => Some(Code36),
            b"37" => Some(Code37),
            b"38" => Some(NoFinancialValue),
            b"39" => Some(ResponseToProposedTripPlan),
            b"40" => Some(CommitmentAdvice),
            b"41" => Some(CorrectedAndVerified),
            b"42" => Some(TemporaryRecord),
            b"43" => Some(RequestPermissionToService),
            b"44" => Some(Rejection),
            b"45" => Some(FollowUp),
            b"46" => Some(CancellationWithRefund),
            b"47" => Some(Transfer),
            b"48" => Some(Suspended),
            b"49" => Some(OriginalNoResponseNecessary),
            b"50" => Some(Register),
            b"51" => Some(HistoricalInquiry),
            b"52" => Some(ResponseToHistoricalInquiry),
            b"53" => Some(Completion),
            b"54" => Some(Approval),
            b"55" => Some(Excavation),
            b"56" => Some(ExpirationNotification),
            b"57" => Some(Initial),
            b"77" => Some(SimulationExercise),
            b"CN" => Some(CompletionNotification),
            b"CO" => Some(Corrected),
            b"DA" => Some(DelegateToAlternative),
            b"ED" => Some(ExhibitDisposition),
            b"ER" => Some(ExhibitReceipt),
            b"EX" => Some(FinalLoadingConfiguration),
            b"FA" => Some(ForwardToActionPoint),
            b"FC" => Some(ForwardToContractor),
            b"FS" => Some(ForwardToSupportPoint),
            b"GR" => Some(Granted),
            b"MD" => Some(MaterielDisposition),
            b"PR" => Some(ProposedLoadingConfiguration),
            b"RH" => Some(ReleaseHold),
            b"RO" => Some(ReOpen),
            b"RR" => Some(ReplyRebuttal),
            b"RV" => Some(RevisedLoadingConfiguration),
            b"SB" => Some(ScanBasedTrading),
            b"SU" => Some(StatusUpdate),
            b"ZZ" => Some(MutuallyDefined),
            _ => None,
        }
    }
    fn description(&self) -> &str {
        use TransactionSetPurposeCode::*;
        match self {
            Original => "Original",
            Cancellation => "Cancellation",
            Add => "Add",
            Delete => "Delete",
            Change => "Change",
            Replace => "Replace",
            ChargeableResubmission => "Chargeable Resubmission",
            Confirmation => "Confirmation",
            Duplicate => "Duplicate",
            Status => "Status",
            NotFound => "Not Found",
            Response => "Response",
            NotProcessed => "Not Processed",
            Request => "Request",
            AdvanceNotification => "Advance Notification",
            ReSubmission => "Re-Submission",
            Proposed => "Proposed",
            Code17 => "Cancel, to be Reissued",
            Reissue => "Reissue",
            SellerInitiatedChange => "Seller initiated change",
            FinalTransmission => "Final Transmission",
            TransactionOnHold => "Transaction on Hold",
            InformationCopy => "Information Copy",
            Draft => "Draft",
            Incremental => "Incremental",
            ReplaceSpecifiedBuyersPartsOnly => "Replace - Specified Buyers Parts Only",
            Verify => "Verify",
            Query => "Query",
            Renewal => "Renewal",
            AllowanceAddition => "Allowance/Addition",
            RecoveryDeduction => "Recovery/Deduction",
            RequestForPayment => "Request for Payment",
            PaymentDeclined => "Payment Declined",
            RequestAuthority => "Request Authority",
            Code36 => "Authority to Deduct (Reply)",
            Code37 => "Authority Declined (Reply)",
            NoFinancialValue => "No Financial Value",
            ResponseToProposedTripPlan => "Response to Proposed Trip Plan",
            CommitmentAdvice => "Commitment Advice",
            CorrectedAndVerified => "Corrected and Verified",
            TemporaryRecord => "Temporary Record",
            RequestPermissionToService => "Request Permission to Service",
            Rejection => "Rejection",
            FollowUp => "Follow-up",
            CancellationWithRefund => "Cancellation with Refund",
            Transfer => "Transfer",
            Suspended => "Suspended",
            OriginalNoResponseNecessary => "Original - No Response Necessary",
            Register => "Register",
            HistoricalInquiry => "Historical Inquiry",
            ResponseToHistoricalInquiry => "Response to Historical Inquiry",
            Completion => "Completion",
            Approval => "Approval",
            Excavation => "Excavation",
            ExpirationNotification => "Expiration Notification",
            Initial => "Initial",
            SimulationExercise => "Simulation Exercise",
            CompletionNotification => "Completion Notification",
            Corrected => "Corrected",
            DelegateToAlternative => "Delegate to Alternative",
            ExhibitDisposition => "Exhibit Disposition",
            ExhibitReceipt => "Exhibit Receipt",
            FinalLoadingConfiguration => "Final Loading Configuration",
            ForwardToActionPoint => "Forward to Action Point",
            ForwardToContractor => "Forward to Contractor",
            ForwardToSupportPoint => "Forward to Support Point",
            Granted => "Granted",
            MaterielDisposition => "Materiel Disposition",
            ProposedLoadingConfiguration => "Proposed Loading Configuration",
            ReleaseHold => "Release Hold",
            ReOpen => "Re-open",
            ReplyRebuttal => "Reply Rebuttal",
            RevisedLoadingConfiguration => "Revised Loading Configuration",
            ScanBasedTrading => "Scan Based Trading",
            StatusUpdate => "Status Update",
            MutuallyDefined => "Mutually Defined",
        }
    }
    fn from_description(description: &str) -> Option<TransactionSetPurposeCode> {
        {
            use TransactionSetPurposeCode::*;
            match description {
                "Original" => Some(Original),
                "Cancellation" => Some(Cancellation),
                "Add" => Some(Add),
                "Delete" => Some(Delete),
                "Change" => Some(Change),
                "Replace" => Some(Replace),
                "Chargeable Resubmission" => Some(ChargeableResubmission),
                "Confirmation" => Some(Confirmation),
                "Duplicate" => Some(Duplicate),
                "Status" => Some(Status),
                "Not Found" => Some(NotFound),
                "Response" => Some(Response),
                "Not Processed" => Some(NotProcessed),
                "Request" => Some(Request),
                "Advance Notification" => Some(AdvanceNotification),
                "Re-Submission" => Some(ReSubmission),
                "Proposed" => Some(Proposed),
                "Cancel, to be Reissued" => Some(Code17),
                "Reissue" => Some(Reissue),
                "Seller initiated change" => Some(SellerInitiatedChange),
                "Final Transmission" => Some(FinalTransmission),
                "Transaction on Hold" => Some(TransactionOnHold),
                "Information Copy" => Some(InformationCopy),
                "Draft" => Some(Draft),
                "Incremental" => Some(Incremental),
                "Replace - Specified Buyers Parts Only" => {
                    Some(ReplaceSpecifiedBuyersPartsOnly)
                }
                "Verify" => Some(Verify),
                "Query" => Some(Query),
                "Renewal" => Some(Renewal),
                "Allowance/Addition" => Some(AllowanceAddition),
                "Recovery/Deduction" => Some(RecoveryDeduction),
                "Request for Payment" => Some(RequestForPayment),
                "Payment Declined" => Some(PaymentDeclined),
                "Request Authority" => Some(RequestAuthority),
                "Authority to Deduct (Reply)" => Some(Code36),
                "Authority Declined (Reply)" => Some(Code37),
                "No Financial Value" => Some(NoFinancialValue),
                "Response to Proposed Trip Plan" => Some(ResponseToProposedTripPlan),
                "Commitment Advice" => Some(CommitmentAdvice),
                "Corrected and Verified" => Some(CorrectedAndVerified),
                "Temporary Record" => Some(TemporaryRecord),
                "Request Permission to Service" => Some(RequestPermissionToService),
                "Rejection" => Some(Rejection),
                "Follow-up" => Some(FollowUp),
                "Cancellation with Refund" => Some(CancellationWithRefund),
                "Transfer" => Some(Transfer),
                "Suspended" => Some(Suspended),
                "Original - No Response Necessary" => Some(OriginalNoResponseNecessary),
                "Register" => Some(Register),
                "Historical Inquiry" => Some(HistoricalInquiry),
                "Response to Historical Inquiry" => Some(ResponseToHistoricalInquiry),
                "Completion" => Some(Completion),
                "Approval" => Some(Approval),
                "Excavation" => Some(Excavation),
                "Expiration Notification" => Some(ExpirationNotification),
                "Initial" => Some(Initial),
                "Simulation Exercise" => Some(SimulationExercise),
                "Completion Notification" => Some(CompletionNotification),
                "Corrected" => Some(Corrected),
                "Delegate to Alternative" => Some(DelegateToAlternative),
                "Exhibit Disposition" => Some(ExhibitDisposition),
                "Exhibit Receipt" => Some(ExhibitReceipt),
                "Final Loading Configuration" => Some(FinalLoadingConfiguration),
                "Forward to Action Point" => Some(ForwardToActionPoint),
                "Forward to Contractor" => Some(ForwardToContractor),
                "Forward to Support Point" => Some(ForwardToSupportPoint),
                "Granted" => Some(Granted),
                "Materiel Disposition" => Some(MaterielDisposition),
                "Proposed Loading Configuration" => Some(ProposedLoadingConfiguration),
                "Release Hold" => Some(ReleaseHold),
                "Re-open" => Some(ReOpen),
                "Reply Rebuttal" => Some(ReplyRebuttal),
                "Revised Loading Configuration" => Some(RevisedLoadingConfiguration),
                "Scan Based Trading" => Some(ScanBasedTrading),
                "Status Update" => Some(StatusUpdate),
                "Mutually Defined" => Some(MutuallyDefined),
                _ => None,
            }
        }
    }
}
impl Serialize for TransactionSetPurposeCode {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: ser::Serializer,
    {
        let value = if serializer.is_human_readable() {
            self.description()
        } else {
            self.code()
        };
        serializer.serialize_str(value)
    }
}
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
    type Value = TransactionSetPurposeCode;
    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("Transaction Set Purpose Code")
    }
    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        TransactionSetPurposeCode::from_description(v)
            .ok_or_else(|| E::custom(
                format!("Invalid Transaction Set Purpose Code: {}", v),
            ))
    }
    fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
    where
        E: de::Error,
    {
        TransactionSetPurposeCode::from_code(v)
            .ok_or_else(|| E::custom(
                format!(
                    "Invalid Transaction Set Purpose Code: {}", std::str::from_utf8(v)
                    .unwrap()
                ),
            ))
    }
}
impl<'de> Deserialize<'de> for TransactionSetPurposeCode {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        if deserializer.is_human_readable() {
            deserializer.deserialize_str(Visitor)
        } else {
            deserializer.deserialize_bytes(Visitor)
        }
    }
}