project QadFinancials > class BERSProcessor > method GetERSLegalDocumentsNoLCQtyDist

Description

Sub-method that finds the pending vouchers attached to a legal document.


Parameters


icDomainCodeinputcharacter
icLegalDocumentNumberinputcharacter
itEffectiveDateinputdate
icSupplierinputcharacter
icPurchaseOrderinputcharacter
iiPurchaseOrderLineinputinteger
ocQtyDistMethodoutputcharacter
oiMaxPrecissionoutputinteger
odTotalReceiptQuantityoutputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BERSProcessor.GetERSLegalDocumentsNoLC


program code (program5/bersprocessor.p)

/* ====================================================================================== *
 * Method       : GetERSLegalDocumentsForLCQtyDist                                        *
 * Description  : This method decides the way, how the quantity entered on the legal      *
 *                document is distributed agaist purchase receipts                        *
 *                - BASED_RECEIPT_QTY  (PREFERRED - more precise, less roudning issues)   *
 *                - PRO_RATA                                                              *
 * ====================================================================================== */

define buffer btqLegalDocPendVoucherForERS for tqLegalDocumentPendVoucherForERS.
 
MAIN_BLOCK:
do on error undo, throw:
    /* Default output parameters */
    assign ocQtyDistMethod        = {&ERSPROCESSOR-QTY-DIST-BASED-RECEIPT}
           oiMaxPrecission        = 0
           odTotalReceiptQuantity = 0.

    /* Execution block */
    for each btqLegalDocPendVoucherForERS where
             btqLegalDocPendVoucherForERS.tclgd_domain      = icDomainCode          and
             btqLegalDocPendVoucherForERS.tclgd_nbr         = icLegalDocumentNumber and
             btqLegalDocPendVoucherForERS.ttlgd_effdate     = itEffectiveDate       and
             btqLegalDocPendVoucherForERS.tcpvo_supplier    = icSupplier            and
             btqLegalDocPendVoucherForERS.tclgdd_order      = icPurchaseOrder       and
             btqLegalDocPendVoucherForERS.tilgdd_order_line = iiPurchaseOrderLine
        break by btqLegalDocPendVoucherForERS.tclgd_domain
              by btqLegalDocPendVoucherForERS.tclgd_nbr
              by btqLegalDocPendVoucherForERS.ttlgd_effdate 
              by btqLegalDocPendVoucherForERS.tcpvo_supplier
              by btqLegalDocPendVoucherForERS.tclgdd_order
              by btqLegalDocPendVoucherForERS.tilgdd_order_line
              by btqLegalDocPendVoucherForERS.tipvo_id 
              by btqLegalDocPendVoucherForERS.tipvod_id_line:

        /* Simulate, like if we would do distribution by "BASED_RECEIPT_QTY" approach */
        if first-of(btqLegalDocPendVoucherForERS.tilgdd_order_line)
        then assign vdTotalInvoiceQuantity = tLgddDetMatForAPMERS.tdlgdd_qty_item_po_uom.

        assign vdInvoiceQuantity      = btqLegalDocPendVoucherForERS.tdpvod_trans_qty
               vdTotalInvoiceQuantity = vdTotalInvoiceQuantity - vdInvoiceQuantity
               odTotalReceiptQuantity = odTotalReceiptQuantity + btqLegalDocPendVoucherForERS.tdpvod_trans_qty.
     
        if last-of(btqLegalDocPendVoucherForERS.tilgdd_order_line) 
        then assign vdInvoiceQuantity      = vdInvoiceQuantity + vdTotalInvoiceQuantity
                    vdTotalInvoiceQuantity = 0.

        /* If there is calculated zero quantity, switch to PRO_RATA approach */
        if vdInvoiceQuantity = 0
        then assign ocQtyDistMethod = {&ERSPROCESSOR-QTY-DIST-PRO-RATA}.
        
        /* Calculate quantity precission */
        assign vcInvoiceQuantityString = string(vdInvoiceQuantity)
               vcInvoiceQuantityString = replace(vcInvoiceQuantityString,session:numeric-separator, "":U)
               viCommaSeparatorIndex   = index(vcInvoiceQuantityString, session:numeric-decimal-point)
               viPrecission            = if viCommaSeparatorIndex > 0
                                         then length(substring(vcInvoiceQuantityString, viCommaSeparatorIndex, -1, "CHARACTER"), "CHARACTER":U)
                                         else 0
               oiMaxPrecission         = max(oiMaxPrecission, viPrecission).        
    end. /* for each btqLegalDocPendVoucherForERS where */    

end. /* MAIN_BLOCK */