<commit_before>import {Component, Output, OnInit, EventEmitter, DoCheck, Input, ViewEncapsulation} from "@angular/core";
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
import {CustomerService} from "../../../customer/customer-common/api/customer.service";
import {CustomerResource} from "../../../customer/customer-common/api/resources/customer.resource";
import {Router} from "@angular/router";
import {ShipmentResource} from "../../shipment-common/api/resources/shipment.resource";
import {Cargo} from "../../shipment-common/api/datastructures/cargo.datastructure";
import {ShipmentServices} from "../../shipment-common/api/datastructures/services.datastructure";
import {EditorMode} from "../../../shared/ui/enums/editor-mode.enum";
import {SaveShipmentEvent} from "./events/save-shipment.event";

@Component({
    selector: "educama-shipment-capture",
    templateUrl: "./shipment-capture.component.html",
    styleUrls: ["./shipment-capture.component.scss"],
    encapsulation: ViewEncapsulation.None
})
export class ShipmentCaptureComponent implements OnInit, DoCheck {

    @Input()
    public shipment: ShipmentResource;

    @Output()
    public createShipmentCancellationEvent = new EventEmitter();

    @Output()
    public saveShipmentEvent: EventEmitter<SaveShipmentEvent> = new EventEmitter<SaveShipmentEvent>();

    public shipmentCaptureForm: FormGroup;
    public customerSuggestions: CustomerResource[];

    public editorMode: EditorMode;
    private _isInitialized = false;

    public senderStreet: string;
    public senderStreetNo: string;
    public senderZipCode: string;
    public senderCity: string;
    public senderUUID: string;
    public trackingId: string;

    public receiverStreet: string;
    public receiverStreetNo: string;
    public receiverZipCode: string;
    public receiverCity: string;
    public receiverUUID: string;

    public dangerousCheck = false;
    public exportInsuranceCheck = false;
    public exportClearanceCheck = false;
    public preCarriageCheck = false;
    public flightCheck = true;
    public onCarriageCheck = false;
    public importInsuranceCheck = false;
    public importClearanceCheck = false;
    public customerTypeEnum = "SENDER";

    constructor(private _formBuilder: FormBuilder,
                private _customerService: CustomerService,
                private _router: Router) {
    }

    public ngOnInit() {
        this.shipmentCaptureForm = this._formBuilder.group({
            sender: ["", [Validators.required]],
            receiver: ["", [Validators.required]],
            numberPackages: ["", [Validators.pattern("[0-9]+")]],
            totalWeight: ["", [Validators.pattern("[0-9]+")]],
            totalCapacity: ["", [Validators.pattern("[0-9]+")]],
            cargoDescription: [""],
            dangerousGoods: [""],
            preCarriage: [""],
            exportInsurance: [""],
            exportCustomsClearance: [""],
            flight: [""],
            importInsurance: [""],
            importCustomsClearance: [""],
            onCarriage: [""],
            customerTypeEnum: [""],
        });
    }

    public ngDoCheck() {

        // Determine editor mode based on existence of a passed in shipment
        this.editorMode = this.shipment ? EditorMode.update : EditorMode.create;

        if (this.editorMode === EditorMode.update && !this._isInitialized) {
            this.shipmentCaptureForm.get("cargoDescription").setValue(this.shipment.shipmentCargo.cargoDescription);
            this.shipmentCaptureForm.get("flight").setValue(this.shipment.shipmentServices.flight);
            this.shipmentCaptureForm.get("numberPackages").setValue(this.shipment.shipmentCargo.numberPackages);
            this.shipmentCaptureForm.get("totalWeight").setValue(this.shipment.shipmentCargo.totalWeight);
            this.shipmentCaptureForm.get("totalCapacity").setValue(this.shipment.shipmentCargo.totalCapacity);
            this.shipmentCaptureForm.get("dangerousGoods").setValue(this.shipment.shipmentCargo.dangerousGoods);
            this.shipmentCaptureForm.get("preCarriage").setValue(this.shipment.shipmentServices.preCarriage);
            this.shipmentCaptureForm.get("exportInsurance").setValue(this.shipment.shipmentServices.exportInsurance);
            this.shipmentCaptureForm.get("exportCustomsClearance").setValue(this.shipment.shipmentServices.exportCustomsClearance);
            this.shipmentCaptureForm.get("importInsurance").setValue(this.shipment.shipmentServices.importInsurance);
            this.shipmentCaptureForm.get("importCustomsClearance").setValue(this.shipment.shipmentServices.importCustomsClearance);
            this.shipmentCaptureForm.get("onCarriage").setValue(this.shipment.shipmentServices.onCarriage);
            this.shipmentCaptureForm.get("customerTypeEnum").setValue(this.shipment.customerTypeEnum);
            this.shipmentCaptureForm.get("sender").setValue(this.shipment.sender.name);
            this.shipmentCaptureForm.get("receiver").setValue(this.shipment.receiver.name);

            this.senderUUID = this.shipment.sender.uuid;
            this.senderStreet = this.shipment.sender.address.street;
            this.senderStreetNo = this.shipment.sender.address.streetNo;
            this.senderCity = this.shipment.sender.address.city;
            this.senderZipCode = this.shipment.sender.address.zipCode;
            this.receiverUUID = this.shipment.sender.uuid;
            this.receiverStreet = this.shipment.receiver.address.street;
            this.receiverStreetNo = this.shipment.receiver.address.streetNo;
            this.receiverCity = this.shipment.receiver.address.city;
            this.receiverZipCode = this.shipment.receiver.address.zipCode;

            this._isInitialized = true;
        }
    }

    // ***************************************************
    // Event Handler
    // ***************************************************

    public loadUserSuggestions(event: any) {
        this._customerService.findCustomerSuggestions(event.query)
            .subscribe(customerSuggestionResource => this.customerSuggestions = customerSuggestionResource.customers);
    }

    public createNewCustomer() {
        this._router.navigate(["/customers/capture"]);
    }<commit_msg>ECM-190: The Sender Address overwrites the Receiver address at Create Invoice task<commit_after>import {Component, Output, OnInit, EventEmitter, DoCheck, Input, ViewEncapsulation} from "@angular/core";
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
import {CustomerService} from "../../../customer/customer-common/api/customer.service";
import {CustomerResource} from "../../../customer/customer-common/api/resources/customer.resource";
import {Router} from "@angular/router";
import {ShipmentResource} from "../../shipment-common/api/resources/shipment.resource";
import {Cargo} from "../../shipment-common/api/datastructures/cargo.datastructure";
import {ShipmentServices} from "../../shipment-common/api/datastructures/services.datastructure";
import {EditorMode} from "../../../shared/ui/enums/editor-mode.enum";
import {SaveShipmentEvent} from "./events/save-shipment.event";

@Component({
    selector: "educama-shipment-capture",
    templateUrl: "./shipment-capture.component.html",
    styleUrls: ["./shipment-capture.component.scss"],
    encapsulation: ViewEncapsulation.None
})
export class ShipmentCaptureComponent implements OnInit, DoCheck {

    @Input()
    public shipment: ShipmentResource;

    @Output()
    public createShipmentCancellationEvent = new EventEmitter();

    @Output()
    public saveShipmentEvent: EventEmitter<SaveShipmentEvent> = new EventEmitter<SaveShipmentEvent>();

    public shipmentCaptureForm: FormGroup;
    public customerSuggestions: CustomerResource[];

    public editorMode: EditorMode;
    private _isInitialized = false;

    public senderStreet: string;
    public senderStreetNo: string;
    public senderZipCode: string;
    public senderCity: string;
    public senderUUID: string;
    public trackingId: string;

    public receiverStreet: string;
    public receiverStreetNo: string;
    public receiverZipCode: string;
    public receiverCity: string;
    public receiverUUID: string;

    public dangerousCheck = false;
    public exportInsuranceCheck = false;
    public exportClearanceCheck = false;
    public preCarriageCheck = false;
    public flightCheck = true;
    public onCarriageCheck = false;
    public importInsuranceCheck = false;
    public importClearanceCheck = false;
    public customerTypeEnum = "SENDER";

    constructor(private _formBuilder: FormBuilder,
                private _customerService: CustomerService,
                private _router: Router) {
    }

    public ngOnInit() {
        this.shipmentCaptureForm = this._formBuilder.group({
            sender: ["", [Validators.required]],
            receiver: ["", [Validators.required]],
            numberPackages: ["", [Validators.pattern("[0-9]+")]],
            totalWeight: ["", [Validators.pattern("[0-9]+")]],
            totalCapacity: ["", [Validators.pattern("[0-9]+")]],
            cargoDescription: [""],
            dangerousGoods: [""],
            preCarriage: [""],
            exportInsurance: [""],
            exportCustomsClearance: [""],
            flight: [""],
            importInsurance: [""],
            importCustomsClearance: [""],
            onCarriage: [""],
            customerTypeEnum: [""],
        });
    }

    public ngDoCheck() {

        // Determine editor mode based on existence of a passed in shipment
        this.editorMode = this.shipment ? EditorMode.update : EditorMode.create;

        if (this.editorMode === EditorMode.update && !this._isInitialized) {
            this.shipmentCaptureForm.get("cargoDescription").setValue(this.shipment.shipmentCargo.cargoDescription);
            this.shipmentCaptureForm.get("flight").setValue(this.shipment.shipmentServices.flight);
            this.shipmentCaptureForm.get("numberPackages").setValue(this.shipment.shipmentCargo.numberPackages);
            this.shipmentCaptureForm.get("totalWeight").setValue(this.shipment.shipmentCargo.totalWeight);
            this.shipmentCaptureForm.get("totalCapacity").setValue(this.shipment.shipmentCargo.totalCapacity);
            this.shipmentCaptureForm.get("dangerousGoods").setValue(this.shipment.shipmentCargo.dangerousGoods);
            this.shipmentCaptureForm.get("preCarriage").setValue(this.shipment.shipmentServices.preCarriage);
            this.shipmentCaptureForm.get("exportInsurance").setValue(this.shipment.shipmentServices.exportInsurance);
            this.shipmentCaptureForm.get("exportCustomsClearance").setValue(this.shipment.shipmentServices.exportCustomsClearance);
            this.shipmentCaptureForm.get("importInsurance").setValue(this.shipment.shipmentServices.importInsurance);
            this.shipmentCaptureForm.get("importCustomsClearance").setValue(this.shipment.shipmentServices.importCustomsClearance);
            this.shipmentCaptureForm.get("onCarriage").setValue(this.shipment.shipmentServices.onCarriage);
            this.shipmentCaptureForm.get("customerTypeEnum").setValue(this.shipment.customerTypeEnum);
            this.shipmentCaptureForm.get("sender").setValue(this.shipment.sender.name);
            this.shipmentCaptureForm.get("receiver").setValue(this.shipment.receiver.name);

            this.senderUUID = this.shipment.sender.uuid;
            this.senderStreet = this.shipment.sender.address.street;
            this.senderStreetNo = this.shipment.sender.address.streetNo;
            this.senderCity = this.shipment.sender.address.city;
            this.senderZipCode = this.shipment.sender.address.zipCode;
            this.receiverUUID = this.shipment.receiver.uuid;
            this.receiverStreet = this.shipment.receiver.address.street;
            this.receiverStreetNo = this.shipment.receiver.address.streetNo;
            this.receiverCity = this.shipment.receiver.address.city;
            this.receiverZipCode = this.shipment.receiver.address.zipCode;

            this._isInitialized = true;
        }
    }

    // ***************************************************
    // Event Handler
    // ***************************************************

    public loadUserSuggestions(event: any) {
        this._customerService.findCustomerSuggestions(event.query)
            .subscribe(customerSuggestionResource => this.customerSuggestions = customerSuggestionResource.customers);
    }

    public createNewCustomer() {
        this._router.navigate(["/customers/capture"]);
    }
{'fraction_non_alphanumeric': 0.13439797612459484, 'fraction_numerical': 0.0011858644952170132, 'mean_word_length': 3.5065906661916637, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2375208', 'n_tokens_mistral': 3440, 'n_tokens_neox': 3399, 'n_words': 517}