import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { OrderServiceProxy, OrderListDto, LocationServiceProxy, LocationListDto, UpdateOrderV2Input, DestinationDetailListDto, ContactListDto, AddressListDto, TagTypeListDto, TagListDto, EmailListDto, PhoneListDto, PostalCodeInAddressListDto, NoteListDto, OrderPackageListDto, ShippingPackageListDto, TagTypeServiceProxy, PostalCodeServiceProxy, ShippingPackageServiceProxy, OrderPackageServiceProxy, CreateOrderV2Input, PickupDetailInput, ContactInput, AddressInput, DestinationDetailInput, PackageInput, PostalCodeListDto, CreateNoteInput, CreateEmailInput, CreatePhoneInput, PackagesServiceProxy, CreateOrderApiInput, TagInput, CreateOrderDefaultInput, AddressTypeServiceProxy, CreatePostalCodeInput, CreateOrEditAddressDto, ContactAddressCheckerInput, CreateOnDemandOrderInput, OrderTypesServiceProxy, GetOrderTypeForViewDto } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import { CreateOrderModalComponent } from './create-order-modal.component'; import { PrimengTableHelper } from '@shared/helpers/PrimengTableHelper'; import * as _ from 'lodash'; import {Location} from '@angular/common'; import { AddressFormComponent } from '@app/shared/layout/form/address-form.component'; import { GooglePlaceDirective } from 'ngx-google-places-autocomplete'; import { Address } from 'ngx-google-places-autocomplete/objects/address'; import { ILatLng, DirectionsMapDirective } from '@app/sprintship/fleet-management/driver-proximities/driver-proximities.directive'; import { GoogleMapsAPIWrapper, MapsAPILoader } from '@agm/core'; import { result } from 'lodash'; import { XmlHttpRequestHelper } from '@shared/helpers/XmlHttpRequestHelper'; import { AppConsts } from '@shared/AppConsts'; declare var KTWizard: any; declare var $: any; declare var KTBootstrapDaterangepicker: any; declare let swal: any; declare var google: any; @Component({ templateUrl: './create-order.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], styleUrls: ['create-order.component.less'], }) export class CreateOrderComponent extends AppComponentBase { @ViewChild(AddressFormComponent, {static:false}) addressForm; saving = false; // createInput: CreateOrderV2Input = new CreateOrderV2Input(); createInput: CreateOrderDefaultInput = new CreateOrderDefaultInput(); postalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput(); destinationPostalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput(); address: CreateOrEditAddressDto = new CreateOrEditAddressDto(); pickupDetailInput: PickupDetailInput = new PickupDetailInput(); pickupContactInput: ContactInput = new ContactInput(); pickupContactAddress: AddressInput = new AddressInput; destinationDetailInput: DestinationDetailInput = new DestinationDetailInput; destinationContactInput: ContactInput = new ContactInput; destinationContactAddress: AddressInput = new AddressInput; locationFilter: LocationListDto = new LocationListDto(); filteredLocation: any; tagTypeFilter: TagTypeListDto = new TagTypeListDto(); filteredTagType: any; tagType: any; packageFilter: ShippingPackageListDto = new ShippingPackageListDto(); filteredPackage: any; filteredLocationPackages: any; packagePrice: any; filteredCountries: any; filteredCities: any; filteredStates: any; filteredPostal: any; filteredDestinationCountries: any; filteredDestinationStates: any; filteredDestinationCities: any; filteredDestinationPostal: any; filteredPickupPostal: any; filteredPackages: any; noteInput: string; packages: Array = []; packageList: Array = []; tagList: Array = []; pickUpTo: any; pickUpFrom: any; deliveryFrom: any; deliveryTo: any; pickupEta: Date; deliveryEta: Date; orderPackageInput: Object = new Object(); addPackage: any; packageQuantity: number; packageNameMessageError: boolean = false; packageQtyMessageError: boolean = false; packageMessageError: boolean = false; tagNameMessageError: boolean = false; tagValueMessageError: boolean = false; tagMessageError: boolean = false; pickuppostalId: PostalCodeListDto = new PostalCodeListDto(); destinationpostalId: PostalCodeListDto = new PostalCodeListDto(); locationInput: number; pickupPhone: string; pickupEmail: string; destinationPhone: string; destinationEmail: string; toAdd: PackageInput; toAddTag = new TagInput; selectedLocation: any; selectedTagType: any; selectedPickupCountry: any; selectedPickupPostalCode: any; selectedPickupState: any; selectedPickupCity: any; selectedDestinationCountry: any; selectedDestinationPostalCode: any; selectedDestinationState: any; selectedDestinationCity: any; filteredAddressType: any; addressTypeId: number; pickupFilterChange = false; destinationFilterChange = false; tagValue: string; city: string; state: string; value: string; country: string; stateFeature: boolean; orderTypeList : GetOrderTypeForViewDto[]; format_address_pickup: string; format_address_deliver: string; options = { componentRestriction: { // types: ['geocode'], // country: 'UA' }, // types: ['cities'], } place_id_pickup: string; place_id_deliver: string; postal_code_pickup: string; postal_code_deliver: string; country_deliver: string; country_pickup: string; state_deliver: string; state_pickup: string; city_deliver: string; city_pickup: string; street_number_pickup: string; street_number_deliver: string; route_pickup: string; route_deliver: string; neighborhood_pickup: string; neighborhood_deliver: string; sublocality_pickup: string; sublocality_deliver: string; addressLine1_pickup: string; addressLine1_deliver: string; map_pickup: any; map_deliver: any; map: any; origin: ILatLng = { latitude: 38.889931, longitude: -77.009003 }; // New York City, NY, USA destination: ILatLng = { latitude: 40.730610, longitude: -73.935242 }; displayDirections = true; zoom_pickup = 18; zoom_deliver = 18; zoom =18; contactAddressChecker: ContactAddressCheckerInput = new ContactAddressCheckerInput(); createOnDemandOrderInput: CreateOnDemandOrderInput = new CreateOnDemandOrderInput(); @ViewChild('placesRef', {static: true}) placesRef : GooglePlaceDirective; @ViewChild('placesRef1', {static: true}) placesRef1 : GooglePlaceDirective; placeExist: boolean = true; routeId: any; addressType_pickup: string; addressType_deliver: string; constructor( injector: Injector, private _orderAppService: OrderServiceProxy, private _locationAppService: LocationServiceProxy, private _tagTypeAppService: TagTypeServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _packageService: ShippingPackageServiceProxy, private _packagesServiceProxy: PackagesServiceProxy, private _location:Location, private router: Router, private _addressTypeService: AddressTypeServiceProxy, private _postalCodeServiceProxy: PostalCodeServiceProxy, private apiloader: MapsAPILoader, private route: ActivatedRoute, private _orderTypeServiceProxy: OrderTypesServiceProxy ) { super(injector); this.route.paramMap.subscribe(params => { this.routeId = params.get("id") }); } saveOrder(): void{ this.createOnDemandOrderInput.noteInput = this.noteInput; this.createOnDemandOrderInput.packageInput = this.packageList; this.createOnDemandOrderInput.routeId = this.routeId; this.createOnDemandOrderInput.orderTypeId = Number((document.getElementById('orderType')).value); // console.log(this.createOnDemandOrderInput); this.spinnerService.show(); this.saving = true; this._orderAppService.createOnDemandOrder(this.createOnDemandOrderInput).subscribe(result =>{ this.notify.info(this.l('SavedSuccessfully')); this.saving = false; this.router.navigateByUrl("/app/sprintship/order"); this.spinnerService.hide(); }); } mapReady_pickup(event?: any) { this.map_pickup=event; } mapReady_deliver(event?: any) { this.map_deliver = event; } mapReady(event?: any) { this.map = event; } public pickUpAddressChange(address: Address) { this.placeExist = true; $('#nextStep').removeAttr("disabled"); this.format_address_pickup = address.formatted_address; this.addressLine1_pickup = ""; this.street_number_pickup = ""; this.route_pickup = ""; this.neighborhood_pickup = ""; this.sublocality_pickup = ""; this.place_id_pickup = address.place_id; let x: ILatLng = { longitude : address.geometry.location.lng(), latitude : address.geometry.location.lat(), } this.origin = x; for(var data in address.address_components){ for (var data2 in address.address_components[data].types){ if(address.address_components[data].types[data2]=="postal_code"){ this.postal_code_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="country"){ this.country_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="administrative_area_level_1"){ this.state_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="locality" || address.address_components[data].types[data2]=="postal_town" || address.address_components[data].types[data2]=="administrative_area_level_3"){ this.city_pickup = address.address_components[data].short_name; } if(address.address_components[data].types[data2]=="route"){ this.route_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="street_number"){ this.street_number_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="neighborhood"){ this.neighborhood_pickup = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="sublocality"){ this.sublocality_pickup = address.address_components[data].long_name; } } } this.street_number_pickup = this.street_number_pickup==undefined || this.route_pickup=="" || this.route_pickup==" "? "" : this.street_number_pickup +" "; this.route_pickup = this.route_pickup==undefined || this.route_pickup=="" || this.route_pickup==" "? "" : "" +this.route_pickup +", "; this.neighborhood_pickup = this.neighborhood_pickup==undefined || this.neighborhood_pickup=="" || this.neighborhood_pickup==" "? "" : "" +this.neighborhood_pickup +", "; this.sublocality_pickup = this.sublocality_pickup==undefined || this.sublocality_pickup=="" || this.sublocality_pickup==" "? "" : "" +this.sublocality_pickup +", "; this.addressLine1_pickup = this.street_number_pickup +this.route_pickup +this.sublocality_pickup +this.neighborhood_pickup; this.createOnDemandOrderInput.formattedAddress_pickup = this.format_address_pickup; this.createOnDemandOrderInput.addressLine1_pickup = this.addressLine1_pickup; this.createOnDemandOrderInput.city_pickup = this.city_pickup; this.createOnDemandOrderInput.country_pickup = this.country_pickup; this.createOnDemandOrderInput.state_pickup= this.state_pickup; this.createOnDemandOrderInput.postalcode_pickup = this.postal_code_pickup; this.createOnDemandOrderInput.latitude_pickup = address.geometry.location.lat(); this.createOnDemandOrderInput.longitude_pickup = address.geometry.location.lng(); this.createOnDemandOrderInput.addressType_pickup = address.types[0]==null ? "" : address.types[0]; // console.log(address); // console.log(this.addressLine1_pickup); // console.log(this.origin); // console.log(this.format_address_pickup); } public deliveryAddressChange(address: Address) { this.placeExist = true; $('#nextStep').removeAttr("disabled"); this.format_address_deliver = address.formatted_address; this.place_id_deliver = address.place_id; this.addressLine1_pickup = ""; this.street_number_deliver = ""; this.route_deliver = ""; this.neighborhood_deliver = ""; this.sublocality_deliver = ""; let y: ILatLng = { longitude : address.geometry.location.lng(), latitude : address.geometry.location.lat(), } this.destination = y; for(var data in address.address_components){ for (var data2 in address.address_components[data].types){ if(address.address_components[data].types[data2]=="postal_code"){ this.postal_code_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="country"){ this.country_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="administrative_area_level_1"){ this.state_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="locality" || address.address_components[data].types[data2]=="postal_town" || address.address_components[data].types[data2]=="administrative_area_level_3"){ this.city_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="route"){ this.route_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="street_number"){ this.street_number_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="neighborhood"){ this.neighborhood_deliver = address.address_components[data].long_name; } if(address.address_components[data].types[data2]=="sublocality"){ this.sublocality_deliver = address.address_components[data].long_name; } } } this.street_number_deliver = this.street_number_deliver==undefined || this.street_number_deliver=="" || this.street_number_deliver==" "? "" : this.street_number_deliver +" "; this.route_deliver = this.route_deliver==undefined || this.route_deliver=="" || this.route_deliver==" "? "" : " " +this.route_deliver +", "; this.neighborhood_deliver = this.neighborhood_deliver==undefined || this.neighborhood_deliver=="" || this.neighborhood_deliver==" "? "" : " " +this.neighborhood_deliver +", "; this.sublocality_deliver = this.sublocality_deliver==undefined || this.sublocality_deliver=="" || this.sublocality_deliver==" "? "" : " " +this.sublocality_deliver +", "; this.addressLine1_deliver = this.street_number_deliver +this.route_deliver +this.sublocality_deliver +this.neighborhood_deliver; this.createOnDemandOrderInput.formattedAddress_deliver = this.format_address_deliver; this.createOnDemandOrderInput.addressLine1_deliver = this.addressLine1_deliver; this.createOnDemandOrderInput.city_deliver = this.city_deliver; this.createOnDemandOrderInput.country_deliver = this.country_deliver; this.createOnDemandOrderInput.state_deliver= this.state_deliver; this.createOnDemandOrderInput.postalcode_deliver = this.postal_code_deliver; this.createOnDemandOrderInput.latitude_deliver = address.geometry.location.lat(); this.createOnDemandOrderInput.longitude_deliver = address.geometry.location.lng(); this.createOnDemandOrderInput.addressType_deliver = address.types[0]==null ? "" : address.types[0]; // console.log(address); // console.log(this.addressLine1_deliver); } getOrderTypes(){ this._orderTypeServiceProxy.getAllOrderTypeForTableDropdown().subscribe(result => { this.orderTypeList = result; }) } ngOnInit() { this.stateFeature = abp.features.isEnabled('App.StateFeature'); // this.ktwizard2(); let maxcount = 1000; // this.filterLocation(); // this.filterTagType(); // this.filterAddressTypes(maxcount); // this.filterPostal(); // this.filterCountries(undefined); this.filterPackage(); $('.kt-select2').select2(); // this.filterLocationPackages(); this.createInput = new CreateOrderDefaultInput(); this.createInput.packageInput = Object(); this.pickuppostalId = new PostalCodeListDto(); this.destinationpostalId = new PostalCodeListDto(); this.locationInput = 0; this.pickupPhone = ""; this.pickupEmail = ""; this.destinationPhone = ""; this.destinationEmail = ""; this.orderPackageInput = new Object(); this.toAdd = new PackageInput(); var that = this; this.getOrderTypes(); $("#packages").change(function () { // this.selectedLocation = $("#packages option:selected").text(); // $("#selectedLocation").text(this.selectedLocation); // console.log(that.filterLocationPackages($("#packages").val(), $("#location").val())); }); $("#TagType").change(function () { this.selectedTagType = $("#TagType option:selected").text(); $("#selectedTagType").text(this.selectedTagType); }); $("#countryPickupSelectInput").change(function () { this.selectedPickupCountry = $("#countryPickupSelectInput option:selected").text(); $("#selectedPickupCountry").text(this.selectedPickupCountry); }); $("#pickupPostalInput").change(function () { this.selectedPickupPostalCode = $("#pickupPostalInput option:selected").text(); $("#selectedPickupPostalCode").text(this.selectedPickupPostalCode); this.selectedPickupPostalCode = this.selectedPickupPostalCode.trim(); that.pickupFilterChange = true; }); $("#pickupStateInput").change(function () { this.selectedPickupState = $("#pickupStateInput option:selected").text(); $("#selectedPickupState").text(this.selectedPickupState); }); $("#pickupCityInput").change(function () { this.selectedPickupCity = $("#pickupCityInput option:selected").text(); $("#selectedPickupCity").text(this.selectedPickupCity); }); $("#destinationCountryInput").change(function () { this.selectedDestinationCountry = $("#destinationCountryInput option:selected").text(); $("#selectedDestinationCountry").text(this.selectedDestinationCountry); }); $("#destinationPostalInput").change(function () { this.selectedDestinationPostalCode = $("#destinationPostalInput option:selected").text(); $("#selectedDestinationPostalCode").text(this.selectedDestinationPostalCode); this.selectedDestinationPostalCode = this.selectedDestinationPostalCode.trim() that.destinationFilterChange = true; }); $("#destinationStateInput").change(function () { this.selectedDestinationState = $("#destinationStateInput option:selected").text(); $("#selectedDestinationState").text(this.selectedDestinationState); }); $("#destinationCityInput").change(function () { this.selectedDestinationCity = $("#destinationCityInput option:selected").text(); $("#selectedDestinationCity").text(this.selectedDestinationCity); }); } ngAfterViewInit() { // { // placeholder: "Select..", // // id: function (data) { return { id: data.id }; } // } $("#countryPickupSelectInput").change(function () { this.selectedPickupCountry = $("#countryPickupSelectInput option:selected").text(); $("#selectedPickupCountry").text(this.selectedPickupCountry); }); $('#kt_daterangepicker_5').daterangepicker({ buttonClasses: ' btn', applyClass: 'btn-primary', cancelClass: 'btn-secondary', singleDatePicker: true, showDropdowns: true, locale: { format: 'MM/DD/YYYY' } }, function (start, end, label) { $('#kt_daterangepicker_5 .form-control').val(start.format('MM/DD/YYYY') + ' / ' + end.format('MM/DD/YYYY')); }); var KTWizard2 = function () { var e, r, i; $(".pickUpFrom input").attr("name", "pickUpFrom"); $(".pickUpTo input").attr("name", "pickUpTo"); $(".deliveryFrom input").attr("name", "deliveryFrom"); $(".deliveryTo input").attr("name", "deliveryTo"); return { init: function () { var t; KTUtil.get("kt_wizard_v2"), e = $("#kt_form"), (i = new KTWizard("kt_wizard_v2", { startStep: 1, clickableSteps: !0 })).on("beforeNext", function (e) { !0 !== r.form() && e.stop() }), i.on("beforePrev", function (e) { !0 !== r.form() && e.stop() }), i.on("change", function (e) { KTUtil.scrollTop() }), r = e.validate({ ignore: ":hidden", rules: { address_pickup: {required: !0 }, deliver_pickup: {required: !0 }, destinationPhoneInput: {required: !0 }, pickupFirstNameInput: { required: !0 }, pickupLastNameInput: { required: !0 }, // pickupEmailInput: { required: !0, email: !0 }, pickupPhoneInput: { required: !0,}, PickupEta: { required: !0 }, pickUpFrom: { required: !0 }, pickUpTo: { required: !0 }, deliveryFrom: { required: !0 }, deliveryTo: { required: !0 }, }, invalidHandler: function (e, r) { // KTUtil.scrollTop(), swal.fire({ // title: "", text: "There are some errors in your submission. Please correct them.", // type: "error", confirmButtonClass: "btn btn-secondary" // }); }, submitHandler: function (e) { } }) } } }(); jQuery(document).ready(function () { KTWizard2.init() }); } save(): void { // this.saving = true; this.pickupContactInput.addressInput = this.pickupContactAddress; this.destinationContactInput.addressInput = this.destinationContactAddress; this.createInput.pickUpEtaStart = moment.utc(moment(this.pickupEta).format('YYYY-MM-DD') + ' ' + moment(this.pickUpFrom).format('HH:mm:ss')); this.createInput.pickUpEtaEnd = moment.utc(moment(this.pickupEta).format('YYYY-MM-DD') + ' ' + moment(this.pickUpTo).format('HH:mm:ss')); this.createInput.destinationEtaStart = moment.utc(moment(this.deliveryEta).format('YYYY-MM-DD') + ' ' + moment(this.deliveryFrom).format('HH:mm:ss')); this.createInput.destinationEtaEnd = moment.utc(moment(this.deliveryEta).format('YYYY-MM-DD') + ' ' + moment(this.deliveryTo).format('HH:mm:ss')); this.createInput.noteInput = this.noteInput; this.createInput.packageInput = this.packageList; this.createInput.tagInput = this.tagList; this.createInput.pickUpContactId = this.pickupDetailInput.contactId; this.createInput.destinationContactId = this.destinationDetailInput.contactId; this.postalCodeInput.country = $('#countryPickupSelectInput').val(); this.destinationPostalCodeInput.city = this.addressForm.city; this.destinationPostalCodeInput.state = this.addressForm.state; this.destinationPostalCodeInput.value = this.addressForm.value; this.destinationPostalCodeInput.country = this.addressForm.country; this.createInput.pickUpAddressTypeId = this.addressTypeId; this.createInput.destinationAddressTypeId = this.address.addressTypeId; this.createInput.destinationAddressLine1 = this.addressForm.address.addressLine1; this.createInput.destinationAddressLine2 = this.addressForm.address.addressLine2; this.createInput.destinationCity = this.addressForm.city; this.createInput.destinationCountry = this.addressForm.country; this.createInput.destinationState = this.addressForm.state; this.createInput.destinationPostalCode = this.addressForm.value; this._postalCodeServiceProxy.createPostalCode(this.postalCodeInput) .pipe() .subscribe(result => { this.createInput.pickUpPostalCodeId = result; this._postalCodeServiceProxy.createPostalCode(this.destinationPostalCodeInput) .pipe() .subscribe(result => { this.createInput.destinationPostalCodeId = result; this._orderAppService.createOrderDefault(this.createInput) .pipe(finalize(() => { })) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.saving = false; this.router.navigateByUrl("/app/sprintship/order"); }); }); }); } filterPackage(): void { this.spinnerService.show(); this._packagesServiceProxy.getAll( undefined, undefined, undefined, undefined, undefined, 1000 ).subscribe(result => { this.filteredPackage = result.items; this.toAdd = new PackageInput(); this.toAdd.packageName = this.filteredPackage[0]['package']['name']; this.toAdd.packageId = this.filteredPackage[0]['package']['id']; this.toAdd.quantity = 1; this.toAdd.price = this.filteredPackage[0]['package']['price']; this.packageList.push(this.toAdd); this.spinnerService.hide(); }); } filterPackages(id): void { this._packagesServiceProxy.getPackageForView(id ).subscribe(result => { this.filteredPackages = result; //console.log(this.filteredPackages['package']['price']); $("#packagePrice").val(this.filteredPackages['package']['price']); }); } addTag() { let key, tagTypeId, tagValue, key2, arrAny = {}; tagTypeId = Number((document.getElementById('tagType')).value); tagValue = $("#tagValue").val(); if ((tagTypeId === 0 || tagTypeId == null) && (tagValue === "" || tagValue == null)) { this.tagNameMessageError = true; this.tagValueMessageError = true; } else if ((tagTypeId === 0 || tagTypeId == null)) { this.tagNameMessageError = true; this.tagValueMessageError = false; } else if ((tagValue === "" || tagValue == null)) { this.tagNameMessageError = false; this.tagValueMessageError = true; } else { for (key in this.filteredTagType) { if (tagTypeId == this.filteredTagType[key].id) { this.toAddTag = new TagInput(); this.toAddTag.tagTypeName = this.filteredTagType[key].name; this.toAddTag.tagTypeId = this.filteredTagType[key].id; this.toAddTag.value = tagValue; this.tagList.push(this.toAddTag) // $("#nextStep").attr("disabled", false); } } this.tagNameMessageError = false; this.tagValueMessageError = false; $("#tagValue").val(0); } } removeTag(tag) { let key; for (key in this.tagList) { if (tag.tagTypeId == this.tagList[key].tagTypeId) { this.tagList.splice(key, 1) } } } addPackageToList() { let key, packageId, packagePrice, tagValue, key2, arrAny = {}; packageId = Number((document.getElementById('packagess')).value); if ((packageId === 0 || packageId == null) && (this.packageQuantity === 0 || this.packageQuantity == null)) { this.packageNameMessageError = true; this.packageQtyMessageError = true; } else if ((packageId === 0 || packageId == null)) { this.packageNameMessageError = true; this.packageQtyMessageError = false; } else if ((this.packageQuantity === 0 || this.packageQuantity == null)) { this.packageNameMessageError = false; this.packageQtyMessageError = true; } else { for (key in this.filteredPackage) { if (packageId === this.filteredPackage[key]['package']['id']) { this.toAdd = new PackageInput(); this.toAdd.packageName = this.filteredPackage[key]['package']['name']; this.toAdd.packageId = this.filteredPackage[key]['package']['id']; this.toAdd.quantity = this.packageQuantity; this.toAdd.price = this.filteredPackage[key]['package']['price']; this.packageList.push(this.toAdd) } this.packageNameMessageError = false; this.packageQtyMessageError = false; } } } removePackageToList(packages) { let key; for (key in this.packageList) { if (packages.packageId == this.packageList[key].packageId) { this.packageList.splice(key, 1) } } } filterAddressTypes(maxcount): void { this._addressTypeService.getAddressType( undefined, undefined, undefined, undefined, maxcount, undefined ).subscribe(result => { this.filteredAddressType = result.items; }); } goBack(){ this._location.back(); } getCurrentLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { if (position) { // this.lat = position.coords.latitude; // this.lng = position.coords.longitude; // this.getAddress = (this.lat, this.lng) this.apiloader.load().then(() => { let geocoder = new google.maps.Geocoder; let latlng = { lat: position.coords.latitude, lng: position.coords.longitude }; geocoder.geocode({ 'location': latlng }, function(results) { if (results[0]) { this.currentLocation = results[0].formatted_address; } else { } }); }); } }) } } onSubmitPickup(): void{ try{ if(this.placesRef.place.address_components==undefined || this.placesRef.place.address_components==null){ this.placeExist = false; }else{ this.placeExist = true; } }catch(e){ this.placeExist = false; } if(!this.placeExist) { $('#nextStep').attr("disabled",""); } } onSubmitDeliver(): void { try{ if(this.placesRef1.place.address_components==undefined || this.placesRef1.place.address_components==null){ this.placeExist = false; }else{ this.placeExist = true; } }catch(e){ this.placeExist = false; } if(!this.placeExist) { $('#nextStep').attr("disabled",""); } } private async geocode(address: string): Promise { return new Promise((resolve, reject) => { new google.maps.Geocoder().geocode({ address }, (results: google.maps.GeocoderResult[], status: google.maps.GeocoderStatus) => { status === google.maps.GeocoderStatus.OK ? resolve(results[0]) : reject(); }); }); } }