project QadFinancials > class BDInvoice > method ValidateComponentAllShipTo

validation procedure

Description

This method is a submethod of ValidateComponentAll.

This method validates the Ship To Code.


Parameters


blStartDebtorShipToPriminput-outputlogicalis query tqDebtorShipToPrim already started or not ?
blStartLsMstrByAddrDomainTypeinput-outputlogicalis query tqLsMstrByAddrDomainType already started or not ?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ValidateComponentAll


program code (program5/bdinvoice.p)

/* ======================================================================== */
/* IMPORTANT: This method is run from ValidateComponentAll                  */
/* The code in this method is nested within the for each t_sDInvoice        */
/* This can only work when both methods are defined in the same segment (5) */
/* ======================================================================== */

if (t_sDInvoice.tc_Status = "N":U or t_sDInvoice.tc_Status = "C":U) and
   (t_sDInvoice.DInvoiceShipToCode <> "":U and t_sDInvoice.DInvoiceShipToCode <> ?)
then do:
    assign vlShipToCodeAvailable = false.    

    if not blStartDebtorShipToPrim
    then do:
        <Q-55 run DebtorShipToPrim  (Start) in BDebtorShipTo > 
        assign blStartDebtorShipToPrim = true.
    end.
    <Q-54 run DebtorShipToPrim (all) (Read) (NoCache)
       (input ?, (DebtorShiptoID)
        input t_sDinvoice.DInvoiceShiptoCode, (DebtorShiptoCode)
        input viCompanyID, (CompanyId)
        output dataset tqDebtorShipToPrim) in BDebtorShipTo>    
        
    
    if t_sDinvoice.DInvoiceIsExternal
    then do:
         /* so long as the shipto exists for any customer its ok for external orders */
        for first tqDebtorShipToPrim 
            where tqDebtorShipToPrim.tcDebtorShipToCode = t_sDInvoice.DInvoiceShipToCode:            
            assign vlShipToCodeAvailable = true.             
        end. /* for each tqDebtorShiptoByDebtor */
    end.
    else do:
        for first tqDebtorShipToPrim 
            where tqDebtorShipToPrim.tcDebtorShipToCode = t_sDInvoice.DInvoiceShipToCode 
              and tqDebtorShipToPrim.tiDebtor_ID = t_sDInvoice.SoldToDebtor_ID:            
            assign vlShipToCodeAvailable = true.             
        end. /* for each tqDebtorShiptoByDebtor */
    end.

    if vlShipToCodeAvailable = false
    then do:
         /* External invoices can have any customer as a valid shipto */
        <Q-50 assign vlFcQueryRecordsAvailable = DebtorByDebtor (NoCache)
           (input viCompanyId, (CompanyId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
            input t_sDInvoice.SoldToDebtor_ID, (DebtorId)
            input t_sDInvoice.tcSoldToDebtorCode, (DebtorCode)) in BDebtor >
        if vlFcQueryRecordsAvailable and 
            ((t_sDInvoice.tcSoldToDebtorCode = t_sDInvoice.DInvoiceShipToCode) or t_sDInvoice.DInvoiceIsExternal)
        then assign vlShipToCodeAvailable = true.
      
    end. /* if vlShipToCodeAvailable = false */

    if vlShipToCodeAvailable = false
    then do:
         /* Check and see if the shipto is a dock. Note docks are stored at the domain level */
         /* Note the dock should exist in the primary domain of the current entity */         
         if not blStartLsMstrByAddrDomainType
         then do:
             <Q-56 run LsMstrByAddrDomainType  (Start) in BMfgAddressListDetail >
             assign blStartLsMstrByAddrDomainType = true.
         end.

         <Q-53 run LsMstrByAddrDomainType (all) (Read) (NoCache)
            (input vcDomainCode, (Domain)
             input t_sDinvoice.DinvoiceShiptoCode, (Addr)
             input {&ADDRESSTYPECODESYSTEM-DOCK}, (Type)
             output dataset tqLsMstrByAddrDomainType) in BMfgAddressListDetail >
         for first tqLsMstrByAddrDomainType
             where tqLsMstrByAddrDomainType.tcls_addr = t_sDinvoice.DinvoiceShiptoCode 
               and tqLsMstrByAddrDomainType.tcls_domain = vcDomainCode
               and tqLsMstrByAddrDomainType.tcls_type = {&ADDRESSTYPECODESYSTEM-DOCK}:
            assign vlShipToCodeAvailable = true.
         end.
    end.

    if vlShipToCodeAvailable = false
    then do:
         /* Check and see if the shipto is an end-user. Note end users are stored at the domain level */
         /* Note the end user should exist in the primary domain of the current entity */         
         if not blStartLsMstrByAddrDomainType
         then do:
             <Q-57 run LsMstrByAddrDomainType  (Start) in BMfgAddressListDetail >
             assign blStartLsMstrByAddrDomainType = true.
         end.

         <Q-58 run LsMstrByAddrDomainType (all) (Read) (NoCache)
            (input vcDomainCode, (Domain)
             input t_sDinvoice.DinvoiceShiptoCode, (Addr)
             input {&ADDRESSTYPECODESYSTEM-ENDUSER}, (Type)
             output dataset tqLsMstrByAddrDomainType) in BMfgAddressListDetail >
         for first tqLsMstrByAddrDomainType
             where tqLsMstrByAddrDomainType.tcls_addr = t_sDinvoice.DinvoiceShiptoCode 
               and tqLsMstrByAddrDomainType.tcls_domain = vcDomainCode
               and tqLsMstrByAddrDomainType.tcls_type = {&ADDRESSTYPECODESYSTEM-ENDUSER}:
            assign vlShipToCodeAvailable = true.
         end.
    end.

    if vlShipToCodeAvailable = false
    then do:
        assign oiReturnStatus = -1
               vcMsg = trim(substitute(#T-46'The ship-to code (&1) specified is not defined in the system.':60(69447)t-46#, t_sDInvoice.DInvoiceShipToCode)).
        <M-39 run SetMessage
           (input  vcMsg (icMessage), 
            input  '':U (icArguments), 
            input  'tDInvoice.DInvoiceShipToCode':U (icFieldName), 
            input  t_sDInvoice.DInvoiceShipToCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sDInvoice.tc_Rowid (icRowid), 
            input  'QadFin-8090':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    end. /* if vlShipToCodeAvailable = false */
end. /* if t_sDInvoice.DInvoiceShipToCode <> "":U */