* REPORT.SCX.SRC
* Form "report.scx"
* C:\PROGRAM FILES (X86)\ABAQUE\FICSAMPLES\FICTUTO\PROGS\FORMS\REPORT.SCX.SRC (included in c:\program files (x86)\abaque\ficsamples\fictuto\fictuto.exe)
* (682 lines before localization)
* ========================================================================================================================

PUBLIC oreport

SET CLASSLIB TO ab\aw\samples\fic\classe\ficsample.vcx ADDITIVE

oreport=NEWOBJECT("report")
oreport.Show
RETURN

  **************************************************
*-- Form: report (ab\aw\samples\fic\fictuto\progs\forms\report.scx)
*-- ParentClass: ficfrm (ab\aw\samples\fic\classe\ficsample.vcx)
*-- BaseClass: form
*-- Time Stamp: 09/01/21 11:13:13 PM

#INCLUDE "ab\ab.h"
DEFINE CLASS report AS ficfrm

  Height = 477
  Width = 815
  DoCreate = .T.
  Caption = "Reporting"
  Name = "Report"
  cntOK.opgStyle.optClassic.Value = 1
  cntOK.opgStyle.optClassic.Left = 0
  cntOK.opgStyle.optClassic.Top = 0
  cntOK.opgStyle.optClassic.Name = "optClassic"
  cntOK.opgStyle.optBS.Left = 0
  cntOK.opgStyle.optBS.Top = 30
  cntOK.opgStyle.optBS.Name = "optBS"
  cntOK.opgStyle.Top = 145
  cntOK.opgStyle.Name = "opgStyle"
  cntOK.cmdOK.Name = "cmdOK"
  cntOK.imgSrce.Top = 45
  cntOK.imgSrce.Name = "imgSrce"
  cntOK.imgHelp.Top = 95
  cntOK.imgHelp.Name = "imgHelp"
  cntOK.Top = 5
  cntOK.Left = 710
  cntOK.Height = 211
  cntOK.ZOrderSet = 1
  cntOK.Name = "cntOK"
  waitpic.Left = -5
  waitpic.Top = 0
  waitpic.ZOrderSet = 3
  waitpic.Name = "waitpic"
  lblFiC.Height = 15
  lblFiC.Left = 10
  lblFiC.Top = 460
  lblFiC.Width = 305
  lblFiC.ZOrderSet = 4
  lblFiC.Name = "lblFiC"
  lblTime.Height = 15
  lblTime.Left = 408
  lblTime.Top = 459
  lblTime.Width = 338
  lblTime.ZOrderSet = 7
  lblTime.Name = "lblTime"

  ADD OBJECT tutoinfoboxfic AS ficebxsrcecode WITH ;
    Anchor = 30, ;
    Height = 125, ;
    Left = 10, ;
    Top = 325, ;
    Width = 790, ;
    ZOrderSet = 0, ;
    Name = "tutoInfoBoxFiC"

  ADD OBJECT chkdisable AS ficchk WITH ;
    Top = 10, ;
    Left = 565, ;
    Height = 17, ;
    Width = 129, ;
    FontName = "Consolas", ;
    Anchor = 9, ;
    Alignment = 1, ;
    Caption = "Disabled", ;
    ZOrderSet = 2, ;
    wcpropsave = "Caption", ;
    Name = "chkDisable"

  ADD OBJECT lblorders AS ficlbl WITH ;
    FontBold = .T., ;
    FontSize = 12, ;
    Anchor = 41, ;
    Caption = "Orders", ;
    Height = 17, ;
    Left = 341, ;
    Top = 7, ;
    Width = 214, ;
    ZOrderSet = 5, ;
    wbsctag = "h3", ;
    Name = "lblOrders"

  ADD OBJECT opginto AS ficopg WITH ;
    ButtonCount = 3, ;
    Anchor = 56, ;
    BorderStyle = 0, ;
    Value = 1, ;
    Height = 29, ;
    Left = 181, ;
    Top = 230, ;
    Width = 146, ;
    ZOrderSet = 6, ;
    wbsclbllinked = "lblInto", ;
    Name = "opgInto", ;
    Ficopt1.FontName = "Consolas", ;
    Ficopt1.Anchor = 130, ;
    Ficopt1.Caption = "Form", ;
    Ficopt1.Value = 1, ;
    Ficopt1.Height = 29, ;
    Ficopt1.Left = -1, ;
    Ficopt1.Style = 1, ;
    Ficopt1.Top = 0, ;
    Ficopt1.Width = 46, ;
    Ficopt1.Name = "optForm", ;
    Ficopt2.FontName = "Consolas", ;
    Ficopt2.Anchor = 160, ;
    Ficopt2.Caption = "Tab", ;
    Ficopt2.Height = 29, ;
    Ficopt2.Left = 48, ;
    Ficopt2.Style = 1, ;
    Ficopt2.Top = 0, ;
    Ficopt2.Width = 47, ;
    Ficopt2.Name = "optPage", ;
    Ficopt3.Anchor = 40, ;
    Ficopt3.Caption = "Win", ;
    Ficopt3.Height = 29, ;
    Ficopt3.Left = 98, ;
    Ficopt3.Style = 1, ;
    Ficopt3.Top = 0, ;
    Ficopt3.Width = 47, ;
    Ficopt3.Name = "optWin"

  ADD OBJECT grdcustomer AS ficgrd WITH ;
    Anchor = 195, ;
    AllowHeaderSizing = .F., ;
    DeleteMark = .F., ;
    Height = 190, ;
    Left = 10, ;
    RecordSource = "customer_lcad", ;
    Top = 30, ;
    Width = 320, ;
    ZOrderSet = 8, ;
    AllowCellSelection = .F., ;
    Name = "grdCustomer"

  ADD OBJECT grdorders AS ficgrd WITH ;
    Anchor = 105, ;
    AllowHeaderSizing = .F., ;
    DeleteMark = .F., ;
    Height = 190, ;
    Left = 340, ;
    RecordSource = "orders", ;
    ScrollBars = 2, ;
    Top = 30, ;
    Width = 358, ;
    ZOrderSet = 9, ;
    AllowCellSelection = .F., ;
    wbsclbllinked = "lblOrders", ;
    Name = "grdOrders"

  ADD OBJECT cmdrptasync AS ficcmd WITH ;
    Top = 275, ;
    Left = 640, ;
    Height = 31, ;
    Width = 163, ;
    FontName = "Consolas", ;
    FontSize = 8, ;
    Anchor = 146, ;
    Caption = "Print!", ;
    ZOrderSet = 10, ;
    Name = "cmdRptAsync"

  ADD OBJECT cmdrptsync AS ficcmd WITH ;
    Top = 227, ;
    Left = 640, ;
    Height = 31, ;
    Width = 163, ;
    FontName = "Consolas", ;
    FontSize = 8, ;
    Anchor = 146, ;
    Caption = "Print!", ;
    ZOrderSet = 10, ;
    Name = "cmdRptSync"

  ADD OBJECT opgprint AS ficopg WITH ;
    ButtonCount = 3, ;
    Anchor = 176, ;
    BorderStyle = 0, ;
    Value = 0, ;
    Height = 29, ;
    Left = 401, ;
    Top = 227, ;
    Width = 223, ;
    ZOrderSet = 11, ;
    Name = "opgPrint", ;
    Ficopt1.FontName = "Consolas", ;
    Ficopt1.Anchor = 130, ;
    Ficopt1.Caption = "FoxyPreviewer", ;
    Ficopt1.Height = 29, ;
    Ficopt1.Left = -1, ;
    Ficopt1.Style = 1, ;
    Ficopt1.Top = 0, ;
    Ficopt1.Width = 105, ;
    Ficopt1.Name = "optFoxy", ;
    Ficopt2.FontName = "Consolas", ;
    Ficopt2.Anchor = 160, ;
    Ficopt2.Caption = "XFRX", ;
    Ficopt2.Height = 29, ;
    Ficopt2.Left = 105, ;
    Ficopt2.Style = 1, ;
    Ficopt2.Top = 0, ;
    Ficopt2.Width = 48, ;
    Ficopt2.Name = "optXFRX", ;
    Ficopt3.FontName = "Consolas", ;
    Ficopt3.Anchor = 40, ;
    Ficopt3.Caption = "FRX2any", ;
    Ficopt3.Height = 29, ;
    Ficopt3.Left = 155, ;
    Ficopt3.Style = 1, ;
    Ficopt3.Top = 0, ;
    Ficopt3.Width = 66, ;
    Ficopt3.Name = "optFRX2any"

  ADD OBJECT lblcust AS ficlbl WITH ;
    FontBold = .T., ;
    FontSize = 12, ;
    Anchor = 131, ;
    Caption = "Customers", ;
    Height = 17, ;
    Left = 10, ;
    Top = 7, ;
    Width = 205, ;
    ZOrderSet = 12, ;
    wbsctag = "h3", ;
    Name = "lblCust"

  ADD OBJECT lblinto AS ficlbl WITH ;
    FontBold = .T., ;
    Anchor = 176, ;
    Alignment = 2, ;
    Caption = "Print PDF report into", ;
    Height = 17, ;
    Left = 15, ;
    Top = 237, ;
    Width = 156, ;
    ZOrderSet = 13, ;
    Name = "lblInto"

  ADD OBJECT lblwith AS ficlbl WITH ;
    FontBold = .T., ;
    Anchor = 176, ;
    Alignment = 2, ;
    Caption = "using", ;
    Height = 17, ;
    Left = 340, ;
    Top = 235, ;
    Width = 52, ;
    ZOrderSet = 14, ;
    Name = "lblWith"

  ADD OBJECT cmdcust AS ficcmd WITH ;
    Top = 6, ;
    Left = 229, ;
    Height = 21, ;
    Width = 100, ;
    Anchor = 161, ;
    Caption = "Update", ;
    Name = "cmdCust"

  PROCEDURE Load
    set database to tastrade && required for DBgetProp()

    set deleted on

    set filter to indexseek(customer.customer_ID, .F., 'orders', 'customer_i') in customer
    set filter to indexseek(customer_lcad.customer_ID, .F., 'orders', 'customer_i') in customer_lcad

    return DoDefault()
  ENDPROC

  PROCEDURE chkdisable.refresh_
    lparameters void_parameter_reminder_implement_your_Refresh_code_in_this_method

    this.Caption = cRefAppend(this.Caption, Iif(Cast(this.Value as L), 'on', 'off'), .T.)
  ENDPROC

  PROCEDURE chkdisable.Click
    lparameters nButton, nShift, nXcoord, nYcoord && doc in Parent Code

    if thisform.wlHTMLgen
      return
    endif

    this.Parent.grdOrders.Enabled = !Cast(this.Value as L)
    this.Refresh
  ENDPROC

  PROCEDURE opginto.Valid
    if thisform.wlHTMLgen
      return
    endif

    if InList(m.this.Value, 2, 3) and !this.Buttons(m.this.Value).lPopupAck && lPopupAck: see this.Init

      thisForm.wMessageBox(;
         ICase(;
          thisForm.wcLangUser = 'fr',  [Cette option nécessite que l'utilisateur autorise les popups sur ce site (selon le navigateur)],; && copy-paste this line to add another language support
                                      [This option requires that user allows popups on this site (browser dependent)]; && default: English
          );
        , 64;
        )

      this.Buttons(m.this.Value).lPopupAck = .T.

    endif
  ENDPROC

  PROCEDURE opginto.Init
    local instantiate
    instantiate = m.thisForm.wlWeb and DoDefault()

    if m.instantiate

      this.optPage.AddProperty('lPopupAck')
      this.optWin.AddProperty('lPopupAck')

      store ICase(;
        thisForm.wcLangUser = 'fr',  [Nécessite que l'utilisateur autorise les popups sur ce site],; && copy-paste this line to add another language support
                                    [Requires that user allows popups on this site]; && default: English
        ) to this.optPage.ToolTipText, this.optWin.ToolTipText
    endif

    return m.instantiate
  ENDPROC

  PROCEDURE grdorders.wafterrowchange
    LPARAMETERS tuRow && see documentation in awGrd.wAfterRowChange()

    if thisForm.wlHTMLgen
      return .F.
    endif

    return DoDefault(@m.tuRow)
  ENDPROC

  PROCEDURE cmdrptasync.Click
    IF (Type('m.thisForm.wlHTMLgen') == 'L' AND m.thisForm.wlHTMLgen) && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34

      local cScriptJS
      text to cScriptJS textmerge noshow flags 1 pretext 7
        var oGrid = jQuery("#<<thisForm.grdCustomer.wcID>>").prop('oGrid');
        jQuery.ajax('custOrderReport.tuto', {
         data:{
           "custID": oGrid.getRowProperty('tuRow', oGrid.getCurrentRow())
         , "PDFengine": jQuery("#<<thisForm.opgPrint.wcID>>").find("input[type=radio]:checked").next().text()
         }
        , success: function(data, status){
            jQuery.notify({
             title: ''
            , message: (data.success ? 'Your report is ready! Click to display' : 'Your report failed because ' + data.result)
            , url: (data.success ? data.result : '')
            , target: '_blank'
            }
            , {
             delay: 10000
            , element: '#<<thisForm.wcID>>'
            }
            )
          }
        , error: function(jqXHR, status, error){
            console.log(error);
          }
        , complete: function(){
         jQuery(this).find('i').hide()
        }
        , context: this
        });
        jQuery(this).find('i').show()
      endtext

      RETURN m.cScriptJS

    ENDIF && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34
  ENDPROC

  PROCEDURE cmdrptasync.Init
    return thisForm.wlWeb and DoDefault()
  ENDPROC

  PROCEDURE cmdrptasync.refresh_
    && .Refresh_() is the FoxInCloud replacement for .Refresh() code
    && Your code should still call .Refresh(), and your .Refresh() code should move into .Refresh_(), leaving .refresh() EMPTY
    && If your .Refresh() code has parameters, .Refresh_() will accept the same.
    && To get an idea how this works, just take a look at the code in aw.vcx!aw*.Refresh()
    &&
    &&
    &&

    this.Caption = ICase(;
      thisForm.wcLangUser = 'fr',  [Impression asynchrone],; && copy-paste this line to add another language support
                                  [Asynchronous report]; && default: English
      );
      + ' <i class="fa fa-refresh fa-spin text-success" style="display:none;"></i>'
  ENDPROC

  PROCEDURE cmdrptsync.refresh_
    && .Refresh_() is the FoxInCloud replacement for .Refresh() code
    && Your code should still call .Refresh(), and your .Refresh() code should move into .Refresh_(), leaving .refresh() EMPTY
    && If your .Refresh() code has parameters, .Refresh_() will accept the same.
    && To get an idea how this works, just take a look at the code in aw.vcx!aw*.Refresh()
    &&
    &&
    &&

    this.Enabled = !thisForm.wlWeb or this.Parent.opgPrint.Value > 0

    this.Caption = ICase(;
      thisForm.wcLangUser = 'fr',  [Impression synchrone],; && copy-paste this line to add another language support
                                  [Synchronous report]; && default: English
      );
  ENDPROC

  PROCEDURE cmdrptsync.Init
    if thisForm.wlLAN
      this.Left = this.Parent.grdOrders.Left
      this.Width = this.Parent.grdOrders.Width
    endif

    return DoDefault()
  ENDPROC

  PROCEDURE cmdrptsync.Click
    IF (Type('m.thisForm.wlHTMLgen') == 'L' AND m.thisForm.wlHTMLgen) && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34

      #if .f. && ========= Implementation documentation ==========

        Value returned indicates to FoxInCloud Application Server how browser should handle this event:
          RETURN .T. && EXECUTE THIS VFP EVENT CODE (on FoxInCloud server)
          RETURN <JavaScript code> && EXECUTE THIS JAVASCRIPT CODE (run in browser only, don't notify the FoxInCloud server automatically)
          RETURN .F. && IGNORE EVENT

        For more details and options, see code inherited from aw*

      #endif && ======= / Implementation documentation ==========

      RETURN .T.&& Process event on server (code after next ENDIF)

    ENDIF && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34

    && MANUAL FIC adaptation: reporting process differs in LAN/desktop mode and Web mode
    &&

    local success as Boolean;
    , result; && returned by PDF engine
    , abSelect as abSelect of abData.prg;
    , customerID; && ID of current customer in left grid
    , company; && name of current customer
    , nSeconds; && Seconds() before starting report
    , lcPDFout; && output PDF file's full address
    , lcPDFengine; && PDF engine selected by user

    success = .T.
    abSelect = abSelect(thisForm.grdCustomer.RecordSource)
    customerID = Trim(customer_ID)
    company = Trim(company_name)
    nSeconds = Seconds()

    if thisForm.wlWeb && APPLICATION RUNS IN WEB MODE (ELSE is desktop mode)

     && Manual FIC adaptation: report to PDF in Web mode using a PDF generator
     &&

      lcPDFengine = ICase(;
        this.parent.opgPrint.Value = 1,;
          'FoxyPreviewer',;
        this.parent.opgPrint.Value = 2,;
          'XFRX',;
          'FRX2any';
        )

     * Generate PDF using the appropriate generator
      success = custOrderReport(; && generates a customer-orders PDF report && see tutoSets.prg
         @m.result; && @
        ,@m.lcPDFout; && @
        , m.customerID;
        , m.lcPDFengine;
        )

     * Now display generated PDF to the User
      do case
      case !m.success

      case thisForm.opgInto.Value = 1 && child form - no popup blocker issue
         thisForm.wForm(;
           'reportChild.scx';
          , .F.; && modeless
          , m.lcPDFout;
          )

        && as we no longer use the 'DO FORM' command,
        && project manager is no longer able to figure out that the 'reportChild.scx' form
        && should be added/included into the project; this instructions works around this.
        &&
        &&
        &&
        external form reportChild

      otherwise && new tab or window - user needs to accept popup on this site
        success = thisForm.wFileSaveAs(; && delivers the file to the user in a new browser tab affiche le fichier dans un nouvel onglet du navigateur
             m.lcPDFout;
            ,@m.result;
            , Iif(m.thisForm.opgInto.Value = 3;
              , 'TastradeReport'; && Window name
              , ''; && Tab
              );
            )

      endcase

      thisForm.wMessageBox(Iif(m.success;
        , Textmerge('';
          + [FoxInCloud generated an order report for customer '<<m.company>>'] + ' ';
          + [using the '<<m.lcPDFengine>>' PDF generator,] + ' ';
          + [and displayed it into a ];
          + ICase(;
            thisForm.opgInto.Value = 1,;
              [child form within the same browser Tab],;
            thisForm.opgInto.Value = 2,;
              [new browser Tab],;
            thisForm.opgInto.Value = 3,;
              [new browser Window],;
              [];
              ) + [, ];
          + [all in <<cSeconds(m.nSeconds)>>]; && modify command abDate
          );
        , m.result;
        ))

      && at this point, in Web mode, if 'output into a window' was chosen above,
      && FoxInCloud Application Server displays 2 new windows inside the browser
      &&
      &&

    else && APPLICATION RUNS IN LAN/DESKTOP MODE

     report form customer for customer_ID = m.customerID preview && runs in a private datasession

    endif

    return m.success
  ENDPROC

  PROCEDURE opgprint.Init
    && Member Classes (Visual FoxPro)
    && ... Note
    && On an .scx form, if you add instantiation code to the member class's Init event,
    && Visual FoxPro disregards that code and only the Init code for the member class definition runs.
    && However, with visual class library (.vcx) forms, Visual FoxPro creates a true subclass.

    this.optFoxy.Enabled = Type('_screen.oFoxyPreviewer') == 'O' && .F. and - test
    this.optXFRX.Enabled = File('xfrx.fxp') or File('xfrx.app')
    this.optFRX2any.Enabled = File('FRX2Any.vcx') or lDevMode() and File('FRX2Any.app')

    local iOpt as Integer, oOpt as awOpt of aw.vcx

    for iOpt = 1 to this.ButtonCount
      oOpt = m.this.Buttons(m.iOpt)
      if m.oOpt.Enabled
        this.Value = Evl(m.this.Value, m.iOpt) && m.oOpt.Value
      else
        m.oOpt.ToolTipText = ICase(;
          thisForm.wcLangUser = 'fr',  [cette option de génération de PDF est soit non installée, soit sa version des démonstration est incompatible avec le fonctionnement de VFP en mode COM],; && copy-paste this line to add another language support
                                      [this PDF generation option is not installed and/or its demo version does not support VFP running as a COM object];
          )
      endif
    endfor

    return m.thisForm.wlWeb and DoDefault()
  ENDPROC

  PROCEDURE opgprint.Valid
    if m.thisForm.wlHTMLgen
      return
    endif

    thisForm.Refresh
  ENDPROC

  PROCEDURE lblinto.Init
    local success as Boolean
    success = m.thisForm.wlWeb and DoDefault()
    if m.success and thisForm.wBSlHTMLgen and .F. && ne marche pas :(
      this.Left = this.Parent.opgInto.Left
      this.Top = this.Parent.opgInto.Top - 5
      this.Parent.opgInto.Top = this.Top + this.Height + 1
    endif
    return m.success
  ENDPROC

  PROCEDURE lblwith.Init
    local success as Boolean
    success = m.thisForm.wlWeb and DoDefault()
    if m.success and thisForm.wBSlHTMLgen and .F. && ne marche pas :(
      this.Left = this.Parent.opgInto.Left
      this.Top = this.Parent.opgInto.Top - 5
      this.Parent.opgInto.Top = this.Top + this.Height + 1
    endif
    return m.success
  ENDPROC

  PROCEDURE cmdcust.refresh_
    && .Refresh_() is the FoxInCloud replacement for .Refresh() code
    && Your code should still call .Refresh(), and your .Refresh() code should move into .Refresh_(), leaving .refresh() EMPTY
    && If your .Refresh() code has parameters, .Refresh_() will accept the same.
    && To get an idea how this works, just take a look at the code in aw.vcx!aw*.Refresh()
    &&
    &&
    &&

    this.Caption = ICase(;
      thisForm.wcLangUser = 'fr',  [Modifier],; && copy-paste this line to add another language support
                                  [Update]; && default: English
      );
  ENDPROC

  PROCEDURE cmdcust.Click
    lparameters nButton, nShift, nXcoord, nYcoord && doc in Parent Code

    IF (Type('m.thisForm.wlHTMLgen') == 'L' AND m.thisForm.wlHTMLgen) && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34
      RETURN .T.&& Process event on server (code after next ENDIF)
    ENDIF && Added by FoxInCloud Adaptation Assistant version 2.00 (source mode) on 11/07/13 15:37:34

    thisForm.wForm('dataUpdate.scx')

    external form dataUpdate
  ENDPROC

ENDDEFINE
*-- EndDefine: report
**************************************************