
sub dcb_trackntrace {
	
	my ($waybillNumber) = @_ ;
	
	our $soapenvelope = qq~<?xml version="1.0" encoding="utf-8"?>
			<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
			  <soap:Body>
				<TracknTrace xmlns="http://tempuri.org/">
					<!-- Optional -->
					<request>
						<enPassword xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></enPassword>
						<enUsername xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></enUsername>
						<waybillNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$waybillNumber</waybillNumber>
					</request>
				</TracknTrace>
			  </soap:Body>
			</soap:Envelope>~ ;
			
	&common_debug("[API] dcb_trackntrace : [soapenvelope=$soapenvelope]") ;
		
	&dcb_send_it('TracknTrace') ;
	&dcb_parse_it ;
	&dcb_read_it('TracknTrace') ;
	
	# $returnxml = qq~<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    # <s:Body>
        # <TracknTraceResponse xmlns="http://tempuri.org/">
            # <TracknTraceResult xmlns:a="http://schemas.datacontract.org/2004/07/OMSIntegrate.Response" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                # <a:ErrorCode i:nil="true"/>
                # <a:ErrorMessage>Completed</a:ErrorMessage>
                # <a:Waybill>
                    # <a:BookingDate/>
                    # <a:Comments i:nil="true"></a:Comments>
                    # <a:ConsigneeName>DEV</a:ConsigneeName>
                    # <a:ConsignorName>DARREN</a:ConsignorName>
                    # <a:CurrentStatus>Proof of delivery</a:CurrentStatus>
                    # <a:DeliveryDate>08052023</a:DeliveryDate>
                    # <a:InsuredValue>0.00</a:InsuredValue>
                    # <a:NumberOfParcels>1</a:NumberOfParcels>
                    # <a:ReceiverAddressLine1>15 SIM ROAD</a:ReceiverAddressLine1>
                    # <a:ReceiverAddressLine2>.</a:ReceiverAddressLine2>
                    # <a:ReceiverCity>KEMPTON PARK</a:ReceiverCity>
                    # <a:ReceiverContactName>DARREN</a:ReceiverContactName>
                    # <a:ReceiverContactTel1>0834752596</a:ReceiverContactTel1>
                    # <a:ReceiverName i:nil="true">ReceiverName TESTING</a:ReceiverName>
                    # <a:ReceiverPostalCode>1619</a:ReceiverPostalCode>
                    # <a:ReceiverSuburb>POMONA</a:ReceiverSuburb>
                    # <a:SenderAddressLine1></a:SenderAddressLine1>
                    # <a:SenderAddressLine2>.</a:SenderAddressLine2>
                    # <a:SenderCity>KEMPTON PARK</a:SenderCity>
                    # <a:SenderContactName>DEV</a:SenderContactName>
                    # <a:SenderContactTel>0112302085</a:SenderContactTel>
                    # <a:SenderPostalCode>1619</a:SenderPostalCode>
                    # <a:SenderSuburb>POMONA</a:SenderSuburb>
                    # <a:ServiceTypeCode>EC</a:ServiceTypeCode>
                    # <a:ShipmentIsInsured>YES</a:ShipmentIsInsured>
                    # <a:ShipperReference/>
                    # <a:accNr>DCBDEVLP</a:accNr>
                    # <a:additionalInformation xmlns:b="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
                        # <b:AdditionalInformation>
                            # <b:additionalInfoCode>overrideDefaultSubcontractor</b:additionalInfoCode>
                            # <b:additionalInfoValue>no</b:additionalInfoValue>
                            # <b:waybillNumber>Dn230505</b:waybillNumber>
                        # </b:AdditionalInformation>
                    # </a:additionalInformation>
                    # <a:pod xmlns:b="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities"/>
                    # <a:trackingDetail xmlns:b="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
                        # <b:TrackingDetail>
                            # <b:eventCode>PODCRE</b:eventCode>
                            # <b:eventDate>09052023</b:eventDate>
                            # <b:eventDescription>Waybill has been PODed</b:eventDescription>
                            # <b:eventHubCode>JNB</b:eventHubCode>
                            # <b:eventTime>0719</b:eventTime>
                        # </b:TrackingDetail>
                        # <b:TrackingDetail>
                            # <b:eventCode>WBLCRE</b:eventCode>
                            # <b:eventDate>05052023</b:eventDate>
                            # <b:eventDescription>Waybill Dn230505 created in import</b:eventDescription>
                            # <b:eventHubCode>JNB</b:eventHubCode>
                            # <b:eventTime>0718</b:eventTime>
                        # </b:TrackingDetail>
                    # </a:trackingDetail>
                    # <a:waybillDate>05052023</a:waybillDate>
                    # <a:waybillNumber>Dn230505</a:waybillNumber>
                # </a:Waybill>
            # </TracknTraceResult>
        # </TracknTraceResponse>
    # </s:Body>
# </s:Envelope>~ ;

} #-------------------------------------------------------------------------------

sub dcb_postalcode {
	
	our $soapenvelope = qq~<?xml version="1.0" encoding="utf-8"?>
			<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
			  <soap:Body>
				<PostalCode xmlns="http://tempuri.org/">
					<request>
						<PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$postal_code</PostalCode>
						<Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$suburb</Suburb>
					</request>
				</PostalCode>
			  </soap:Body>
			</soap:Envelope>~ ;
			
	&common_debug("[API] dcb_postalcode : [soapenvelope=$soapenvelope]") ;
		
	&dcb_send_it('PostalCode') ;
	&dcb_parse_it ;
	&dcb_read_it('PostalCode') ;

} #-------------------------------------------------------------------------------

sub dcb_savewabill {
	
	my ($venue,$ft,$ev_id) = @_ ;
	
	my $system_loc           = $i{"system_location_$ft\_$ev_id"} ;
	my $supplier             = $i{"logistics_supplier_id_$ft\_$ev_id"} ;
	my $status               = $i{"status_$ft\_$ev_id"} ;
	my $waybill_nr           = $i{"waybill_nr_$ft\_$ev_id"} ;
	my $items                = $i{"item_$ft\_$ev_id"} ;
	my $poc                  = $i{"poc_$ft\_$ev_id"} ;
	my $special_instructions = $i{"special_instructions_$ft\_$ev_id"} ;
	
	# my $dest = ($ft eq 'to') ? $db{organisations}{$venue}{name} : $db{logistics_locations}{$system_loc}{location} ;
	# my $orig = ($ft eq 'from') ? $db{organisations}{$venue}{name} : $db{logistics_locations}{$system_loc}{location} ;
	
	my $dest = ($ft eq 'from') ? $db{logistics_locations}{$system_loc}{location} : ($routeCode) ? substr($routeCode,0,3) : $db{organisations}{$venue}{region_code} ;
	my $orig = ($ft eq 'to') ? $db{logistics_locations}{$system_loc}{location} : ($routeCode) ? substr($routeCode,0,3) : $db{organisations}{$venue}{region_code} ;
	
	my ($poc_name,$poc_nr) = split(/\_/,$poc) ; 
	
	if    ($dest =~ /ITV/) { $dest =~ s/\ITV//g ; $dest =~ s/ //g ; } 
	elsif ($orig =~ /ITV/) { $orig =~ s/\ITV//g ; $orig =~ s/ //g ;	}
	
	# my $accountnumber = ($testdcd) ? 'DCBMAILBAG' : 'DI31F' ;
	my $accountnumber = ($testdcd) ? 'DCBMAILBAG' : 'DI31' ;
	
	our $soapenvelope = qq~<?xml version="1.0" encoding="utf-8"?>
	<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
		<soap:Body>
			<savewabill xmlns="http://tempuri.org/">
				<!-- Optional -->
				<request>
					<AccNr xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$accountnumber</AccNr>
					<AddressLine1 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$address1</AddressLine1>
					<AddressLine2 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$address2</AddressLine2>
					<AddressLine3 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$address3</AddressLine3>
					<AddressLine4 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$address4</AddressLine4>
					<ContactNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$poc_nr</ContactNumber>
					<ContactPerson xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$poc_name</ContactPerson>
					<CustomerReferenceNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></CustomerReferenceNumber>
					<Date xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$dcbdate</Date>
					<DestHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$dest</DestHub>
					<Number xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$waybill_nr</Number>
					<OriginHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$orig</OriginHub>
					<PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$postal_code</PostalCode>
					<Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$suburb</Suburb>
					<Reciever xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$db{organisations}{$venue}{name}</Reciever>
					<RouteCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$routeCode</RouteCode>
					<SpecialInstructions xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$special_instructions</SpecialInstructions>
					<serviceType xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">1</serviceType>
				</request>
			</savewabill>
		</soap:Body>
	</soap:Envelope>~ ;
	
	&common_debug("[API] dcb_savewabill : [soapenvelope=$soapenvelope]") ;
		
	&dcb_send_it('savewabill') ;
	&dcb_parse_it ;
	&dcb_read_it('savewabill') ;

} #-------------------------------------------------------------------------------

sub dcb_upload_oms_waybill {
	
	my ($venue,$ft,$ev_id) = @_ ;
	
	my $tbl_log_loc          = 'logistics_locations' ;
	my $tbl_org              = 'organisations' ;
	my $system_loc           = $i{"system_location_$ft\_$ev_id"} ;
	my $supplier             = $i{"logistics_supplier_id_$ft\_$ev_id"} ;
	my $status               = $i{"status_$ft\_$ev_id"} ;
	my $waybill_nr           = $i{"waybill_nr_$ft\_$ev_id"} ;
	my $items                = $i{"item_$ft\_$ev_id"} ;
	my $poc                  = $i{"poc_$ft\_$ev_id"} ; my ($poc_name,$poc_nr) = split(/\_/,$poc) ; 
	# my $special_instructions = $i{"special_instructions_$ft\_$ev_id"} ;
	
	my $start_end            = ($ft eq 'from') ? 'end' : 'start' ;
	my $special_instructions = "Event $start_end : $dcbdate. " . $i{"special_instructions_$ft\_$ev_id"} ;
	
	$rec{address1}           = $address1 ;
	$rec{address1}          .= ', ' if $address1 && $address2 ;
	$rec{address1}          .= $address2 if $address2 ;
	$rec{address2}           = $address3 ;
	$rec{address2}          .= ', ' if $address3 && $address4 ;
	$rec{address2}          .= $address4 if $address4 ;
	$rec{city}               = $city ;
	$rec{suburb}             = $suburb ;
	$rec{postal_code}        = $postal_code ;
	$rec{poc_name}           = $poc_name ;
	$rec{poc_nr}             = $poc_nr ;
	$rec{name}               = $db{$tbl_org}{$venue}{name} ;
	$rec{routecode}          = $routeCode ;
						   
	$send{address1}          = $db{$tbl_log_loc}{$system_loc}{address_line_1} ;
	$send{address1}         .= ', ' if $db{$tbl_log_loc}{$system_loc}{address_line_1} && $db{$tbl_log_loc}{$system_loc}{address_line_2} ;
	$send{address1}         .= $db{$tbl_log_loc}{$system_loc}{address_line_2} if $db{$tbl_log_loc}{$system_loc}{address_line_2} ;
	$send{address2}          = $db{$tbl_log_loc}{$system_loc}{address_line_3} ;
	$send{address2}         .= ', ' if $db{$tbl_log_loc}{$system_loc}{address_line_3} && $db{$tbl_log_loc}{$system_loc}{address_line_4} ;
	$send{address2}         .= $db{$tbl_log_loc}{$system_loc}{address_line_4} if $db{$tbl_log_loc}{$system_loc}{address_line_4} ;
	$send{city}              = $db{$tbl_log_loc}{$system_loc}{city} ;
	$send{suburb}            = $db{$tbl_log_loc}{$system_loc}{suburb} ;
	$send{postal_code}       = $db{$tbl_log_loc}{$system_loc}{postal_code} ;
	$send{poc_name}          = $db{$tbl_log_loc}{$system_loc}{poc_name} ;
	$send{poc_nr}            = $db{$tbl_log_loc}{$system_loc}{poc_nr} ;
	$send{name}              = $db{$tbl_log_loc}{$system_loc}{location} ;
	$send{routecode}         = $db{$tbl_log_loc}{$system_loc}{dcb_route_code} ;
	
	# my $dest = ($ft eq 'from') ? $db{$tbl_log_loc}{$system_loc}{location} : ($routeCode) ? substr($routeCode,0,3) : $db{$tbl_log_loc}{$venue}{region_code} ;
	# my $orig = ($ft eq 'to') ? $db{$tbl_log_loc}{$system_loc}{location} : ($routeCode) ? substr($routeCode,0,3) : $db{$tbl_log_loc}{$venue}{region_code} ;
	
	if ($ft eq 'from') {
		foreach (keys %rec) {
			my $rec   = $rec{$_} ;
			$rec{$_}  = $send{$_} ;
			$send{$_} = $rec ;
		}
	}
	
	# if    ($dest =~ /ITV/) { $dest =~ s/\ITV//g ; $dest =~ s/ //g ; } 
	# elsif ($orig =~ /ITV/) { $orig =~ s/\ITV//g ; $orig =~ s/ //g ;	}
	
	# our $soapenvelope = qq~<?xml version="1.0" encoding="utf-8"?>
	# <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    # <Body>
        # <UploadOMSWaybill xmlns="http://tempuri.org/">
            # <request>
                # <accountNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DCBMAILBAG</accountNumber>
				# <numParcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$items_cnt</numParcels>~; 
				
	# my $accountnumber = ($testdcd) ? 'DCBMAILBAG' : 'DI31F' ;
	my $accountnumber = ($testdcd) ? 'DCBMAILBAG' : 'DI31' ;
				
	our $soapenvelope = qq~<?xml version="1.0" encoding="utf-8"?>
	<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <UploadOMSWaybill xmlns="http://tempuri.org/">
            <request>
                <accountNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$accountnumber</accountNumber>
				<invoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
                    <WaybillInvoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
                        <InvAmount></InvAmount>
                        <InvDescription></InvDescription>
                        <InvNum></InvNum>
                        <InvUnits></InvUnits>
                        <WaybillId>0</WaybillId>
                    </WaybillInvoices>
                </invoices>
                <numParcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$items_cnt</numParcels>~; 
				
	for my $parcel_cnt (1 .. $items_cnt) {
		my $parcel_qty  = ($db{logistics_items}{$items[$parcel_cnt-1]}{qty}) ? $db{logistics_items}{$items[$parcel_cnt-1]}{qty} : 1 ;
		my $parcel_desc = ($db{logistics_items}{$items[$parcel_cnt-1]}{name}) ? $db{logistics_items}{$items[$parcel_cnt-1]}{name} : 1 ;
		$soapenvelope  .= qq~ 
				<parcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
                    <WaybillParcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
                        <LoadType>STD</LoadType>
                        <RateType>G</RateType>
                        <WaybillId>0</WaybillId>
                        <breadth>1</breadth>
                        <description>$parcel_desc</description>
                        <height>1</height>
                        <length>1</length>
                        <mass>1</mass>
                        <parcelNumber>$parcel_cnt</parcelNumber>
                        <qty>$parcel_qty</qty>
                    </WaybillParcels>
                </parcels>~;
	}
	
	$soapenvelope .= qq~
				<recieversAddress1 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{address1}</recieversAddress1>
                <recieversAddress2 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{address2}</recieversAddress2>
                <recieversCity xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{city}</recieversCity>
                <recieversContactPerson xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{poc_name}</recieversContactPerson>
                <recieversContactTel xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{poc_nr}</recieversContactTel>
                <recieversName xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{name}</recieversName>
                <recieversPostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{postal_code}</recieversPostalCode>
                <recieversRouteCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{routecode}</recieversRouteCode>
                <recieversSuburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$rec{suburb}</recieversSuburb>
                <sendersAddress1 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{address1}</sendersAddress1>
                <sendersAddress2 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{address2}</sendersAddress2>
                <sendersCity xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{city}</sendersCity>
                <sendersContactPerson xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{poc_name}</sendersContactPerson>
                <sendersContactTelephone xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{poc_nr}</sendersContactTelephone>
                <sendersName xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{name}</sendersName>
                <sendersPostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{postal_code}</sendersPostalCode>
                <sendersRouteCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{routecode}</sendersRouteCode>
                <sendersSuburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$send{suburb}</sendersSuburb>
                <serviceType xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">OE</serviceType>
                <specialInstructions xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$special_instructions</specialInstructions>
                <waybillNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$waybill_nr</waybillNumber>
            </request>
        </UploadOMSWaybill>
    </Body>
</Envelope>~ ;
	
	&common_debug("[API] dcb_upload_oms_waybill : [soapenvelope=$soapenvelope]") ;
		
	&dcb_send_it('UploadOMSWaybill') ;
	&dcb_parse_it ;
	&dcb_read_it('UploadOMSWaybill') ;

} #-------------------------------------------------------------------------------

sub dcb_send_it {
	
	my ($soapaction) = @_ ;
	
	my $environment = ($testdcd) ? 'APIUAT' : 'API' ;
	
	my $header_soapaction = "http://tempuri.org/IOMSIntegrate/$soapaction" ;
	my $host              = "https://dcboms.co.za/$environment/OMSIntegrate.svc" ;
	
	&common_write_log("dcb/xml_send_$now_year\_$now_mm.log","$now_ccyymmddhrmnsc|$now_ccyy_mm_ddT$now_hh_min_sec|$soapaction|$host|$header_soapaction|$soapenvelope|");
	
	&common_debug("[API] dcb_send_it : [host=$host]") ;
	&common_debug("[API] dcb_send_it : [soapaction=$header_soapaction]") ;
	
	if ($testing == 1 && $useropts{it}{$username} && $soapaction ne 'PostalCode') { &common_debug(">>>>>> *** TESTING, $soapaction API call NOT SENT *** <<<<<<") ; return ; }

	my $userAgent = LWP::UserAgent->new();
	my $request = HTTP::Request->new(POST => $host);
	$request->header(SOAPAction => "$header_soapaction");
	$request->content($soapenvelope);
	$request->content_type("text/xml; charset=utf-8");
	my $response = $userAgent->request($request);
		
	# Check response
	my $response_code    = $response -> code ;
	my $response_content = $response -> content ;
	
	&common_debug("[API] dcb_send_it : [response_code=$response_code]") ;
	&common_debug("[API] response_content : [response_content=$response_content]") ;

	$returnxml = $response_content ;
	
	&common_write_log("dcb/xml_response_$now_year\_$now_mm.log","$now_ccyymmddhrmnsc|$now_ccyy_mm_ddT$now_hh_min_sec|$soapaction|$response_code|$returnxml|");

} #-------------------------------------------------------------------------------

sub dcb_parse_it {

	# use Data::Dumper;
	# print Dumper(\$returnxml);
	# exit;

	$returnxml =~ s/[\x80-\xFF]/?/g ;
	my $xml = new XML::Simple or die "Cant instantiate object XML::Simple $!" ;
	# my $xmldata = $xml->XMLin($returnxml) or die "Cant open xmldata $!" ;
	$xmldata = $xml->XMLin($returnxml, forcearray => 1) or die "Cant open xmldata $!";
 
	if ($debug) {
		use Data::Dumper;
		print Dumper(\$xmldata);
		# exit ;
    }

} #-------------------------------------------------------------------------------

sub dcb_read_it {
	
	my ($soapaction) = @_ ;
	
	# my $result = '' ;
	
	if ($soapaction eq 'UploadOMSWaybill') {
		our $uploadwaybillresult = $xmldata->{'s:Body'}->[0]->{'UploadOMSWaybillResponse'}->[0]->{'UploadOMSWaybillResult'}->[0] ;
	} elsif ($soapaction eq 'savewabill') {
		our $savewabillResult = $xmldata->{'s:Body'}->[0]->{'savewabillResponse'}->[0]->{'savewabillResult'}->[0] ;
	} elsif ($soapaction eq 'PostalCode') {
		our $routeCode = '' ; # our $routeCode = '' ;
		foreach my $hashref (@{$xmldata->{'s:Body'}->[0]->{'PostalCodeResponse'}->[0]->{'PostalCodeResult'}->[0]->{'a:ArrayOfpostalCode'} } ) {
			foreach $address (@{$hashref}{'a:postalCode'}) {	
				$routeCode = ${$hashref}{'a:postalCode'}->[0]->{'a:routeCode'}->[0] ;
			}
		}
		# $routeCode = substr($routeCode,0,3) ;	
	}  elsif ($soapaction eq 'TracknTrace') {
		
		
		foreach my $hashref (@{$xmldata->{'s:Body'}->[0]->{'TracknTraceResponse'}->[0]->{'TracknTraceResult'}->[0]->{'a:Waybill'} } ) {

			$trackntrace{booking_date}				= (ref(${$hashref}{'a:BookingDate'}->[0]) eq 'HASH') ? '' : ${$hashref}{'a:BookingDate'}->[0] ;	
			$trackntrace{comments}         			= ${$hashref}{'a:Comments'}->[0]->{'content'} ;	
			$trackntrace{consignee_name}         	= (ref(${$hashref}{'a:ConsigneeName'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:ConsigneeName'}->[0] ;	 
			$trackntrace{consignor_name}         	= (ref(${$hashref}{'a:ConsignorName'}->[0])			eq 'HASH') ? '' : ${$hashref}{'a:ConsignorName'}->[0] ;	
			$trackntrace{current_status}         	= (ref(${$hashref}{'a:CurrentStatus'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:CurrentStatus'}->[0] ;	
			$trackntrace{delivery_date}          	= (ref(${$hashref}{'a:DeliveryDate'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:DeliveryDate'}->[0] ;	
			$trackntrace{insured_value}	        	= (ref(${$hashref}{'a:InsuredValue'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:InsuredValue'}->[0] ;	
			$trackntrace{number_of_parcels}      	= (ref(${$hashref}{'a:NumberOfParcels'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:NumberOfParcels'}->[0] ;	
			$trackntrace{receiver_address_line_1}	= (ref(${$hashref}{'a:ReceiverAddressLine1'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ReceiverAddressLine1'}->[0] ;	
			$trackntrace{receiver_address_line_2}	= (ref(${$hashref}{'a:ReceiverAddressLine2'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ReceiverAddressLine2'}->[0] ;	
			$trackntrace{receiver_city}          	= (ref(${$hashref}{'a:ReceiverCity'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:ReceiverCity'}->[0] ;	
			$trackntrace{receiver_contact_name} 	= (ref(${$hashref}{'a:ReceiverContactName'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ReceiverContactName'}->[0] ;	
			$trackntrace{receiver_contact_tel_1}  	= (ref(${$hashref}{'a:ReceiverContactTel1'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ReceiverContactTel1'}->[0] ;	
			$trackntrace{receiver_name}          	= ${$hashref}{'a:ReceiverName'}->[0]->{'content'} ;	
			$trackntrace{receiver_postal_code}   	= (ref(${$hashref}{'a:ReceiverPostalCode'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ReceiverPostalCode'}->[0] ;	
			$trackntrace{receiver_suburb}        	= (ref(${$hashref}{'a:ReceiverSuburb'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:ReceiverSuburb'}->[0] ;	 
			$trackntrace{sender_address_line_1}		= (ref(${$hashref}{'a:SenderAddressLine1'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:SenderAddressLine1'}->[0] ;
			$trackntrace{sender_address_line_2}  	= (ref(${$hashref}{'a:SenderAddressLine2'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:SenderAddressLine2'}->[0] ;	
			$trackntrace{sender_city}            	= (ref(${$hashref}{'a:SenderCity'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:SenderCity'}->[0] ;	
			$trackntrace{sender_contact_name}    	= (ref(${$hashref}{'a:SenderContactName'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:SenderContactName'}->[0] ;	
			$trackntrace{sender_contact_tel}     	= (ref(${$hashref}{'a:SenderContactTel'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:SenderContactTel'}->[0] ;	
			$trackntrace{sender_postal_code}     	= (ref(${$hashref}{'a:SenderPostalCode'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:SenderPostalCode'}->[0] ;
			$trackntrace{sender_suburb}          	= (ref(${$hashref}{'a:SenderSuburb'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:SenderSuburb'}->[0] ;	
			$trackntrace{service_type_code}      	= (ref(${$hashref}{'a:ServiceTypeCode'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:ServiceTypeCode'}->[0] ;	
			$trackntrace{shipment_is_insured}    	= (ref(${$hashref}{'a:ShipmentIsInsured'}->[0]) 	eq 'HASH') ? '' : ${$hashref}{'a:ShipmentIsInsured'}->[0] ;	
			$trackntrace{shipper_reference}      	= (ref(${$hashref}{'a:ShipperReference'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:ShipperReference'}->[0]->{''} ;	
			$trackntrace{account_nr}             	= (ref(${$hashref}{'a:accNr'}->[0]) 				eq 'HASH') ? '' : ${$hashref}{'a:accNr'}->[0] ;	
			$trackntrace{pod}                    	= ${$hashref}{'a:pod'}->[0]->{'xmlns:b'} ;	
			$trackntrace{waybill_date}           	= (ref(${$hashref}{'a:waybillDate'}->[0]) 			eq 'HASH') ? '' : ${$hashref}{'a:waybillDate'}->[0] ;	
			$trackntrace{waybill_number}         	= (ref(${$hashref}{'a:waybillNumber'}->[0]) 		eq 'HASH') ? '' : ${$hashref}{'a:waybillNumber'}->[0] ;	
			
			my $additional_info = $hashref->{'a:additionalInformation'}->[0]->{'b:AdditionalInformation'}->[0];
			$trackntrace{additional_information}{additional_info_code}  = (ref($additional_info->{'b:additionalInfoCode'}->[0]) eq 'HASH') ? '' : $additional_info->{'b:additionalInfoCode'}->[0];
			$trackntrace{additional_information}{additional_info_value} = (ref($additional_info->{'b:additionalInfoValue'}->[0]) eq 'HASH') ? '' : $additional_info->{'b:additionalInfoValue'}->[0];
			$trackntrace{additional_information}{waybill_number}        = (ref($additional_info->{'b:waybillNumber'}->[0]) eq 'HASH') ? '' : $additional_info->{'b:waybillNumber'}->[0];

			my $tracking_details = $hashref->{'a:trackingDetail'}->[0]->{'b:TrackingDetail'};
			for my $i (0..$#$tracking_details) {
				my $event_index = $i + 1;
				$trackntrace{tracking_detail}{event_code}{$event_index}        = (ref($tracking_details->[$i]->{'b:eventCode'}->[0]) eq 'HASH') ? '' : $tracking_details->[$i]->{'b:eventCode'}->[0];
				$trackntrace{tracking_detail}{event_date}{$event_index}        = (ref($tracking_details->[$i]->{'b:eventDate'}->[0]) eq 'HASH') ? '' : $tracking_details->[$i]->{'b:eventDate'}->[0];
				$trackntrace{tracking_detail}{event_description}{$event_index} = (ref($tracking_details->[$i]->{'b:eventDescription'}->[0]) eq 'HASH') ? '' : $tracking_details->[$i]->{'b:eventDescription'}->[0];
				$trackntrace{tracking_detail}{event_hub_code}{$event_index}    = (ref($tracking_details->[$i]->{'b:eventHubCode'}->[0]) eq 'HASH') ? '' : $tracking_details->[$i]->{'b:eventHubCode'}->[0];
				$trackntrace{tracking_detail}{event_time}{$event_index}        = (ref($tracking_details->[$i]->{'b:eventTime'}->[0]) eq 'HASH') ? '' : $tracking_details->[$i]->{'b:eventTime'}->[0];
			}	
			
			# $trackntrace{additional_information}{additional_info_code} 	= ${$hashref}{'a:additionalInformation'}->[0]->{'b:AdditionalInformation'}->[0]->{'b:additionalInfoCode'}->[0] ;	
			# $trackntrace{additional_information}{additional_info_value} = ${$hashref}{'a:additionalInformation'}->[0]->{'b:AdditionalInformation'}->[0]->{'b:additionalInfoValue'}->[0] ;	
			# $trackntrace{additional_information}{waybill_number} 		= ${$hashref}{'a:additionalInformation'}->[0]->{'b:AdditionalInformation'}->[0]->{'b:waybillNumber'}->[0] ;	
			
			# $trackntrace{tracking_detail}{event_code}{1} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[0]->{'b:eventCode'}->[0] ;
			# $trackntrace{tracking_detail}{event_date}{1} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[0]->{'b:eventDate'}->[0] ;
			# $trackntrace{tracking_detail}{event_description}{1}	= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[0]->{'b:eventDescription'}->[0] ;
			# $trackntrace{tracking_detail}{event_hub_code}{1} 	= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[0]->{'b:eventHubCode'}->[0] ;
			# $trackntrace{tracking_detail}{event_time}{1} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[0]->{'b:eventTime'}->[0] ;
			
			# $trackntrace{tracking_detail}{event_code}{2} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[1]->{'b:eventCode'}->[0] ;
			# $trackntrace{tracking_detail}{event_date}{2} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[1]->{'b:eventDate'}->[0] ;
			# $trackntrace{tracking_detail}{event_description}{2}	= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[1]->{'b:eventDescription'}->[0] ;
			# $trackntrace{tracking_detail}{event_hub_code}{2} 	= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[1]->{'b:eventHubCode'}->[0] ;
			# $trackntrace{tracking_detail}{event_time}{2} 		= ${$hashref}{'a:trackingDetail'}->[0]->{'b:TrackingDetail'}->[1]->{'b:eventTime'}->[0] ;
			
		}
		
	}
	
	# return ($result) ;
	
	# print "\n" . $xmldata->{'s:Body'}->[0]->{'savewabillResponse'}->[0]->{'savewabillResult'}->[0] ;
	
	# return unless $event_id ;
	# return unless $from_to ;
		
	# &db_min_ro("event_quotes","1,logistics_dcb_waybill","`id`='$event_id'","","") ;
	
	# my @waybill_nrs = split(/\-/,$db{event_quotes}{1}{logistics_waybill_nrs}) ; 
	# my @dcb_waybill = split(/\-/,$logistics_dcb_waybill) ; 
	
	# my $dcb_waybill = ($from_to eq 'to') ? "$dcb_waybill[0]-1" : "1-$dcb_waybill[1]"  ;
	
	# $ii{$event_id}{logistics_dcb_waybill} = $dcb_waybill ;
	
	# our $testing = 1 ;
	
	# &db_min_upd('event_quotes',"`id`='$event_id'") ;
	# &db_min_upd('event_quotes',"`id`='5136'") ;
			
} #-------------------------------------------------------------------------------

# sub dcb_send_it_get_route_code {
	
	# my ($postal_code,$suburb) = @_ ;
	
	# my $message = qq~<?xml version="1.0" encoding="utf-8"?>
		# <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
		  # <soap:Body>
			# <PostalCode xmlns="http://tempuri.org/">
				# <request>
					# <PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$postal_code</PostalCode>
					# <Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$suburb</Suburb>
				# </request>
			# </PostalCode>
		  # </soap:Body>
		# </soap:Envelope>
	# ~ ;
	
	# if ($debug) {
		# print $message;
    # }

	# my $userAgent = LWP::UserAgent->new();
	# my $request = HTTP::Request->new(POST => 'https://dcboms.co.za/APIUAT/OMSIntegrate.svc');
	# $request->header(SOAPAction => '"http://tempuri.org/IOMSIntegrate/savewabill"');
	# $request->content($message);
	# $request->content_type("text/xml; charset=utf-8");
	# my $response = $userAgent->request($request);
		
	# # Check response
	# my $response_code    = $response -> code ;
	# my $response_content = $response -> content ;

	# $returnxml = $response_content ;

# } #-------------------------------------------------------------------------------


1 ;