icDebtorCode | input | character | |
icDeductionCatCode | input | character | |
icDeductionCatType | input | character | |
icDInvoiceDeductionComment | input | character | |
icDInvoiceDeductionCustRef | input | character | |
icDInvoiceDeductionStatus | input | character | Deduction Status ● It is allowed to provide multiple status, separated them by comma. ● The values are “PENDING”,”AUTOWRITEOFF”,”CREDITED”,”APPROVEDCREDIT” |
itDInvoicePostingDateFrom | input | date | |
itDInvoicePostingDateTo | input | date | |
icDomainCode | input | character | Required. |
ilDeductionDetailIsWithFull | input | logical | |
tApiGetDeductions | output | temp-table | Deduction invoice and detail line info. Deduction Catgory info. |
icDeductionDetailEntity | input | character | |
icCurrencyCode | input | character | |
idDeductionAmount | input | decimal | |
iiDInvoiceID | input | integer | |
iiDInvoiceDeductionID | input | integer | |
ilDInvoiceIsOpen | input | logical | |
icPromotionCode | input | character | |
oiReturnStatus | output | integer | Return status of the method. |
assign oiReturnStatus = -98. /*==========================================*/ /*Validate and init the parameters */ /*==========================================*/ empty temp-table tApiGetDeductions. /* Deduction Type should be "STANDARD" OR "PROMOTION" error */ if icDeductionCatType <> ? and icDeductionCatType <> "" and icDeductionCatType <> {&DEDUCTIONCATTYPE-STANDARD} and icDeductionCatType <> {&DEDUCTIONCATTYPE-PROMOTION} then do: assign oiReturnStatus = -82 vcMessage = trim(substitute(#T-4'Deduction Type should be &1 or &2.':255(316027637)T-4#,{&DEDUCTIONCATTYPE-STANDARD},{&DEDUCTIONCATTYPE-PROMOTION})). <M-60 run SetMessage (input vcMessage (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-151913':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. /* Deduction Status should be "PENDING" or "AUTOWRITEOFF" or "", warning 81 */ assign vcDedStatusList = icDInvoiceDeductionStatus. assign viComma = index(vcDedStatusList,',':U). if viComma = 0 then do: if vcDedStatusList <> ? and vcDedStatusList <> '':U and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT} and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-APPROVEWRITEOFF} and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-CREDITED} and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-PENDING} and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-REJECTED} and vcDedStatusList <> {&INVOICEDEDUCTSTATUS-WRITE-OFF} then do: assign vcMessage = trim(substitute(#T-79'Deduction Status should be &1,&2,&3,&4,&5,&6.':150(656236821)T-79#, {&INVOICEDEDUCTSTATUS-PENDING}, {&INVOICEDEDUCTSTATUS-WRITE-OFF}, {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT}, {&INVOICEDEDUCTSTATUS-CREDITED}, {&INVOICEDEDUCTSTATUS-APPROVEWRITEOFF}, {&INVOICEDEDUCTSTATUS-REJECTED})) oiReturnStatus = -83. <M-22 run SetMessage (input vcMessage (icMessage), input ? (icArguments), input ? (icFieldName), input ? (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-966838':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. end. else do: do while viComma > 0: vcDedStatus = substring(vcDedStatusList,1, viComma - 1, 'CHARACTER'). if vcDedStatus <> {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT} and vcDedStatus <> {&INVOICEDEDUCTSTATUS-APPROVEWRITEOFF} and vcDedStatus <> {&INVOICEDEDUCTSTATUS-CREDITED} and vcDedStatus <> {&INVOICEDEDUCTSTATUS-PENDING} and vcDedStatus <> {&INVOICEDEDUCTSTATUS-REJECTED} and vcDedStatus <> {&INVOICEDEDUCTSTATUS-WRITE-OFF} then do: assign vcMessage = trim(substitute(#T-660'Deduction Status should be &1,&2,&3,&4,&5,&6.':150(656236821)T-660#, {&INVOICEDEDUCTSTATUS-PENDING}, {&INVOICEDEDUCTSTATUS-WRITE-OFF}, {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT}, {&INVOICEDEDUCTSTATUS-CREDITED}, {&INVOICEDEDUCTSTATUS-APPROVEWRITEOFF}, {&INVOICEDEDUCTSTATUS-REJECTED})) oiReturnStatus = -83. <M-75 run SetMessage (input vcMessage (icMessage), input ? (icArguments), input ? (icFieldName), input ? (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-829906':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. vcDedStatusList = substring(vcDedStatusList, viComma + 1, length(vcDedStatusList,'CHARACTER') - viComma, 'CHARACTER'). viComma = index(vcDedStatusList,',':U). end. end. /* Domain code doesn't exist. */ if icDomainCode <> ? and icDomainCode <> '':U then do: <Q-11 run DomainsByCode (all) (Read) (NoCache) (input ?, (DomainID) input icDomainCode, (DomainCode) output dataset tqDomainsByCode) in BDomain> if not can-find(first tqDomainsByCode) then do: assign oiReturnStatus = -84 vcMessage = trim(substitute(#T-42'the Domain Code &1 is not found in the system.':50(169913853)T-42#,icDomainCode)). <M-47 run SetMessage (input vcMessage (icMessage), input ? (icArguments), input ? (icFieldName), input ? (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-140039':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. end. if icDebtorCode <> ? and icDebtorCode <> '':U then do: /* Debtor Code doesn't exist. */ <Q-95 run DebtorByDebtorCodes (all) (Read) (NoCache) (input 0, (CompanyId) input icDebtorCode, (DebtorCode) output dataset tqDebtorByDebtorCodes) in BDebtor> find first tqDebtorByDebtorCodes no-lock no-error. if not available tqDebtorByDebtorCodes then do: assign oiReturnStatus = -85. <M-70 run SetMessage (input #T-74'Customers are not found in the system.':255(180383686)T-74# (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-108211':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. end. /*Deduction Code doesn't exist. */ if icDeductionCatCode <> ? and icDeductionCatCode <> "" then do: <Q-13 run DeductionCatByCodes (all) (Read) (NoCache) (input icDeductionCatCode, (DeductionCatCode) output dataset tqDeductionCatByCodes) in BDeductionCat> find first tqDeductionCatByCodes no-lock no-error. if not available tqDeductionCatByCodes then do: assign oiReturnStatus = -86 vcMessage = trim(#T-2'The Deduction Category Codes are not found in the system.':255(64726748)T-2#). <M-26 run SetMessage (input vcMessage (icMessage), input ? (icArguments), input ? (icFieldName), input icDeductionCatCode (icFieldValue), input 'E':U (icType), input 3 (iiSeverity), input ? (icRowid), input 'qadfin-874837':U (icFcMsgNumber), input ? (icFcExplanation), input ? (icFcIdentification), input ? (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BDInvoice> return. end. end. /*==========================================*/ /*Get the output record set */ /*==========================================*/ /* <Q-80 run DInvoiceDeductionByFilters (all) (Read) (NoCache) (input ?, (CompanyId) output dataset tqDInvoiceDeductionByFilters) in BDInvoice> */ empty temp-table tFilter. if ilDInvoiceIsOpen <> ? then do: if ilDInvoiceIsOpen then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceIsOpen' tFilter.tcDataType = 'l':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = 'true':U. end. else do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceIsOpen' tFilter.tcDataType = 'l':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = 'false':U. end. end. if itDInvoicePostingDateFrom <> ? and itDInvoicePostingDateTo <> ? and itDInvoicePostingDateFrom = itDInvoicePostingDateTo then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceDate' tFilter.tcDataType = 't':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = string(year(itDInvoicePostingDateFrom) * 10000 + month(itDInvoicePostingDateFrom) * 100 + day(itDInvoicePostingDateFrom)). end. else do: if itDInvoicePostingDateFrom <> ? then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceDate' tFilter.tcDataType = 't':U tFilter.tcOperator = '>=':U tFilter.tcParameterValue = string(year(itDInvoicePostingDateFrom) * 10000 + month(itDInvoicePostingDateFrom) * 100 + day(itDInvoicePostingDateFrom)). end. if itDInvoicePostingDateTo <> ? then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceDate' tFilter.tcDataType = 't':U tFilter.tcOperator = '<=':U tFilter.tcParameterValue = string(year(itDInvoicePostingDateTo) * 10000 + month(itDInvoicePostingDateTo) * 100 + day(itDInvoicePostingDateTo)). end. end. if iiDInvoiceID > 0 then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoice_ID' tFilter.tcDataType = 'i':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = string(iiDInvoiceID). end. create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.DInvoiceIsWithDeduction' tFilter.tcDataType = 'l':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = 'yes':U. if icDomainCode <> ? and icDomainCode <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDomains.DomainCode' tFilter.tcDataType = 'c':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = icDomainCode. end. if icDebtorCode <> ? and icDebtorCode <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDebtor.DebtorCode' tFilter.tcDataType = 'c':U tFilter.tcOperator = 'can-do':U tFilter.tcParameterValue = icDebtorCode. end. if iiDInvoiceDeductionID > 0 then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeduction_ID' tFilter.tcDataType = 'i':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = string(iiDInvoiceDeductionID). end. if icDInvoiceDeductionStatus <> ? and icDInvoiceDeductionStatus <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeductionStatus' tFilter.tcDataType = 'c':U tFilter.tcOperator = 'can-do':U tFilter.tcParameterValue = icDInvoiceDeductionStatus. end. if icDInvoiceDeductionCustRef <> ? and icDInvoiceDeductionCustRef <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeductionCustRef' tFilter.tcDataType = 'c':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = icDInvoiceDeductionCustRef. end. if icDInvoiceDeductionComment <> ? and icDInvoiceDeductionComment <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeductionComment' tFilter.tcDataType = 'c':U tFilter.tcOperator = 'matches':U tFilter.tcParameterValue = icDInvoiceDeductionComment. end. if idDeductionAmount <> ? and idDeductionAmount > 0 then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeductionTC' tFilter.tcDataType = 'd':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = string(idDeductionAmount). end. if icDeductionCatCode <> ? and icDeductionCatCode <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDeductionCat.DeductionCatCode' tFilter.tcDataType = 'c':U tFilter.tcOperator = 'can-do':U tFilter.tcParameterValue = icDeductionCatCode. end. if icDeductionCatType <> ? and icDeductionCatType <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDeductionCat.DeductionCatType' tFilter.tcDataType = 'c':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = icDeductionCatType. end. if icCurrencyCode <> ? and icCurrencyCode <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tCurrency.CurrencyCode' tFilter.tcDataType = 'c':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = icCurrencyCode. end. if icPromotionCode <> ? and icPromotionCode <> '':U then do: create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoiceDeduction.DInvoiceDeductionPromotionCode' tFilter.tcDataType = 'c':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = icPromotionCode. end. if icDeductionDetailEntity <> ? and icDeductionDetailEntity <> '':U then do: viEntityCount = num-entries(icDeductionDetailEntity,',':U). empty temp-table tDInvoiceDeductionByFiltersTmp. /* start to loop entity list */ do viIndex = 1 to viEntityCount: vcEntityCodeTmp = entry(viIndex,icDeductionDetailEntity). for each tFilter where tFilter.tcBusinessFieldName = 'tDInvoice.Company_ID' : delete tFilter. end. create tFilter. assign tFilter.tcBusinessFieldName = 'tDInvoice.Company_ID' tFilter.tcDataType = 'i':U tFilter.tcOperator = '=':U tFilter.tcParameterValue = vcEntityCodeTmp. <Q-36 run api/bdinvoice/dinvoicedeductionbyfilters.p (input ? (icApiLogin), input ? (icApiPassword), input ? (icApiExtra), input viSessionID (iiApiSessionId), input 'A':U (icRange), input ? (icRowid), input 0 (iiRowNum), input 0 (iiNumber), input '':U (icSortColumns), input false (ilCountOnly), input yes (ilForwardRead), input 0 (iiMaximumBrowseRecordsToCount), input DataSet tFilter (izFilterDS), output viApiQueryCount (oiCount), output vlEndOfQuery (olEndOfQuery), output dataset tqDInvoiceDeductionByFilters (ozResultsetDS), output dataset tFcMessages (ozFcMessagesDS), output viFcReturnSuper (oiReturnStatus))> /* buffer-copy dataresult of each entity to the final result table: tDInvoiceDeductionByFiltersTmp */ for each tqDInvoiceDeductionByFilters: create tDInvoiceDeductionByFiltersTmp. buffer-copy tqDInvoiceDeductionByFilters to tDInvoiceDeductionByFiltersTmp. end. end. end. else do: <Q-81 run api/bdinvoice/dinvoicedeductionbyfilters.p (input ? (icApiLogin), input ? (icApiPassword), input ? (icApiExtra), input viSessionID (iiApiSessionId), input 'A':U (icRange), input ? (icRowid), input 0 (iiRowNum), input 0 (iiNumber), input '':U (icSortColumns), input false (ilCountOnly), input yes (ilForwardRead), input 0 (iiMaximumBrowseRecordsToCount), input DataSet tFilter (izFilterDS), output viApiQueryCount (oiCount), output vlEndOfQuery (olEndOfQuery), output dataset tqDInvoiceDeductionByFilters (ozResultsetDS), output dataset tFcMessages (ozFcMessagesDS), output viFcReturnSuper (oiReturnStatus))> /* buffer-copy dataresult of each entity to the final result table: tDInvoiceDeductionByFiltersTmp */ for each tqDInvoiceDeductionByFilters: create tDInvoiceDeductionByFiltersTmp. buffer-copy tqDInvoiceDeductionByFilters to tDInvoiceDeductionByFiltersTmp. end. end. if not ilDeductionDetailIsWithFull then do: for each tDInvoiceDeductionByFiltersTmp: create tApiGetDeductions. buffer-copy tDInvoiceDeductionByFiltersTmp to tApiGetDeductions. end. /* make sure the sequence is like 1,2,3... */ for each tApiGetDeductions where tApiGetDeductions.tiDInvoiceDeductionSequence >=1000: tApiGetDeductions.tiDInvoiceDeductionSequence = tApiGetDeductions.tiDInvoiceDeductionSequence / 1000. end. assign oiReturnStatus = 0. return. end. assign vcDInvoiceIdList = '':U. for each tDInvoiceDeductionByFiltersTmp: if vcDInvoiceIdList = '':U then vcDInvoiceIdList = string(tDInvoiceDeductionByFiltersTmp.tiDInvoice_ID). else if lookup (string(tDInvoiceDeductionByFiltersTmp.tiDInvoice_ID),vcDInvoiceIdList,',':U) = 0 then vcDInvoiceIdList = vcDInvoiceIdList + ',':U + string (tDInvoiceDeductionByFiltersTmp.tiDInvoice_ID). end. if vcDInvoiceIdList = '':U then do: assign oiReturnStatus = 0. return. end. <Q-45 run DInvoiceDeductionByFilters2 (all) (Read) (NoCache) (input 0, (CompanyId) input vcDInvoiceIdList, (DInvoiceIds) output dataset tqDInvoiceDeductionByFilters2) in BDInvoice> /* Copy all data into the tApiGetDeductions */ for each tqDInvoiceDeductionByFilters2: create tApiGetDeductions. buffer-copy tqDInvoiceDeductionByFilters2 to tApiGetDeductions. end. /* make sure the sequence is like 1,2,3... */ for each tApiGetDeductions where tApiGetDeductions.tiDInvoiceDeductionSequence >=1000: tApiGetDeductions.tiDInvoiceDeductionSequence = tApiGetDeductions.tiDInvoiceDeductionSequence / 1000. end. assign oiReturnStatus = 0.
define temp-table ttContext no-undo field propertyQualifier as character field propertyName as character field propertyValue as character index entityContext is primary unique propertyQualifier propertyName index propertyQualifier propertyQualifier. define dataset dsContext for ttContext. define variable vhContextDS as handle no-undo. define variable vhExceptionDS as handle no-undo. define variable vhServer as handle no-undo. define variable vhInputDS as handle no-undo. define variable vhInputOutputDS as handle no-undo. define variable vhOutputDS as handle no-undo. define variable vhParameter as handle no-undo. /* Create context */ create ttContext. assign ttContext.propertyName = "programName" ttContext.propertyValue = "BDInvoice". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "ApiGetDeductions". create ttContext. assign ttContext.propertyName = "applicationId" ttContext.propertyValue = "fin". create ttContext. assign ttContext.propertyName = "entity" ttContext.propertyValue = "1000". create ttContext. assign ttContext.propertyName = "userName" ttContext.propertyValue = "mfg". create ttContext. assign ttContext.propertyName = "password" ttContext.propertyValue = "". /* Create input dataset */ create dataset vhInputDS. vhInputDS:read-xmlschema("file", "xml/bdinvoice.apigetdeductions.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icDebtorCode = <parameter value> vhParameter::icDeductionCatCode = <parameter value> vhParameter::icDeductionCatType = <parameter value> vhParameter::icDInvoiceDeductionComment = <parameter value> vhParameter::icDInvoiceDeductionCustRef = <parameter value> vhParameter::icDInvoiceDeductionStatus = <parameter value> vhParameter::itDInvoicePostingDateFrom = <parameter value> vhParameter::itDInvoicePostingDateTo = <parameter value> vhParameter::icDomainCode = <parameter value> vhParameter::ilDeductionDetailIsWithFull = <parameter value> vhParameter::icDeductionDetailEntity = <parameter value> vhParameter::icCurrencyCode = <parameter value> vhParameter::idDeductionAmount = <parameter value> vhParameter::iiDInvoiceID = <parameter value> vhParameter::iiDInvoiceDeductionID = <parameter value> vhParameter::ilDInvoiceIsOpen = <parameter value> vhParameter::icPromotionCode = <parameter value>. /* Connect the AppServer */ create server vhServer. vhServer:connect("-URL <appserver-url>"). if not vhServer:connected() then do: message "Could not connect AppServer" view-as alert-box error title "Error". return. end. /* Run */ assign vhContextDS = dataset dsContext:handle. run program/rpcrequestservice.p on vhServer (input-output dataset-handle vhContextDS by-reference, output dataset-handle vhExceptionDS, input dataset-handle vhInputDS by-reference, input-output dataset-handle vhInputOutputDS by-reference, output dataset-handle vhOutputDS). /* Handle output however you want, in this example, we dump it to xml */ if valid-handle(vhExceptionDS) then vhExceptionDS:write-xml("file", "Exceptions.xml", true). if valid-handle(vhOutputDS) then vhOutputDS:write-xml("file", "Output.xml", true). /* Cleanup */ vhServer:disconnect(). assign vhServer = ?. if valid-handle(vhInputDS) then delete object vhInputDS. if valid-handle(vhOutputDS) then delete object vhOutputDS. if valid-handle(vhExceptionDS) then delete object vhExceptionDS.