# copy-BMO-trans

set-strictmode -version 2.0
function defineFlowTask([Flow]$flow,[Task]$task) {
  #--- define
  $def = new-module -asCustomObject -scriptBlock {
    function getTaskDesc([Task]$task) {
      return "This copies the files from the download area on HM22 to the processing area on HZ03."
    }

    # ---------- define task parameters
    function params([Task]$task) {
      $parms = @{};
      $parms.brief    = "$($task.statlocn)"
      $parms.name     = "$($task.name)"
      $parms.trap     = "$null"
      return  $parms
    }

    # ---------- define task parameters
    function options([Object]$task) {
      $opts = @();
      return  ,$opts
    }

    function runScript([object]$task, [hashtable]$parms, [hashtable]$status) {
      $tfs = $task.tfs;
      $appDir = "$($tfs.globMap.citGlobs.curDir)";
      $year = "$($tfs.globMap.citGlobs.year)"
      $bankSrc = "$($tfs.globMap.citGlobs.bankSrc)"

      hlogBoth("Running $($task.name) srcDir $($task.form.appGbl.bankSrc) year $year")
      #hlog("$($task.name) copy trans from $bankSrc")
      $src   = $bankSrc
      $nextYr = "$(([int]$year) + 1)"
      $curY  = $year.substring(3)
      $nxtY  = $nextYr.substring(3)
      $dest  = "$($appDir)\bank"
      $edest = "$($appDir)\estmts"
      $cdest  = "$($appDir)\chelps"
      hlog("$curY $nextYr $nxtY")
      # 1054-323, 1054-331, 4608-095
      $cgb = $tfs.globMap.citGlobs;
      forEach($set in $cgb.accts) {
        $set = $set -replace "-","."
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)1??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)2??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)3??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)4??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)5??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)6??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)7??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)8??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)9??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)a??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)b??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($curY)c??.$($set).ofx" "$dest")
        (copyFile "$($src)\$($year)\bmo.church\bmo.$($nxtY)1??.$($set).ofx" "$dest")
      }
      # e-statements
      forEach($set in $cgb.accts) {
        (copyFile "$($src)\$($year)\bmo.church\estmts\$($set)\eStatement_$($year)-*.pdf" "$edest\$($set)")
      }
      # NOTE: as convenience, also copy Canada Helps transactions
      (copyFile "d:\1\CharityDataDownload-$($year)-???.csv" "$cdest")
    }

    function copyFile([string]$src,[string]$targ) {
      #hlog("copy $src to $dest")
      (copy-item -path $src -force -destination $targ -passthru)
      "`r`n$src copied`r`n"
    }

    Export-ModuleMember -Variable * -Function *
  }
  return $def;
}



X
PSEC - Powershell Enhanced Capability
1.2.1
  src: psec-snippets-copy-files-example-copy-files-example-def.psm1

Copyright © 2018-2021, 2022, Rexcel System Inc.