Work Order Print  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Work Order Print

Postby Riyaz » Thu Feb 01, 2024 10:37 pm

Hi There

Trying to call the print of a particular work order report on a custom button click under utility. Unable to find the print function of the work order, below is an example what I found for SalesOrder , can you pls guide me towards an equivalent for WorkOrder

public static void PrintInvoice(SalesOrder salesOrder, string formatName)
{
foreach (SalesOrderReport salesOrderReport in salesOrder.GetCandidateReportsToPrint())
{
if (salesOrderReport.Name == formatName && salesOrderReport.BillingType == salesOrder.BillType)
{
salesOrder.Print(new JiwaCollection<SalesOrderReport>() { salesOrderReport });
return;
}
}

}
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Work Order Print  Topic is solved

Postby Mike.Sheen » Tue Feb 06, 2024 1:23 pm

Riyaz wrote:Hi There

Trying to call the print of a particular work order report on a custom button click under utility. Unable to find the print function of the work order, below is an example what I found for SalesOrder , can you pls guide me towards an equivalent for WorkOrder

public static void PrintInvoice(SalesOrder salesOrder, string formatName)
{
foreach (SalesOrderReport salesOrderReport in salesOrder.GetCandidateReportsToPrint())
{
if (salesOrderReport.Name == formatName && salesOrderReport.BillingType == salesOrder.BillType)
{
salesOrder.Print(new JiwaCollection<SalesOrderReport>() { salesOrderReport });
return;
}
}

}


Sales orders is totally different, as there are different report types (invoice, delivery docket, et cetera) so isn't the best comparison.

Every Maintenance.UserInterface type form (which the work order form is) has a PrintRecord method - just invoke that, passing as a parameter the ReportDefinition to print.

The form also has a ReportDefinitionCollection property which is the list of defined reports for that form - so one of those items is what you want to pass as the ReportDefinition to the PrintRecord method.

For example, the following will print the first report defined in the report definition collection:

Code: Select all
workOrderForm.PrintRecord(workOrderForm.ReportDefinitionCollection(1))


Obviously you will want to locate which report using some other way, so a bit of Linq will do the job there:

Code: Select all
// Print report with description "test"
JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition reportDefinition = workOrderForm.ReportDefinitionCollection.Cast<JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition>().Where(x => x.Description == "test").FirstOrDefault();


Example plugin attached adds a ribbon to the Work Order form "Custom Print" and when pressed prints a report where the Description is "test". The print method also has commented out other criteria for which report to print.
Attachments
Plugin Print work order example.xml
(10.76 KiB) Downloaded 59 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Work Order Print

Postby Riyaz » Tue Feb 06, 2024 5:50 pm

Hi Mike

Thanks for this and the explanation, just another question please, is it possible to call the report of another form, am trying to call a specific report of the work order of a batch (in batch production) at the click of a button from Batch Production screen,
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: Work Order Print

Postby Mike.Sheen » Tue Feb 06, 2024 7:16 pm

Riyaz wrote:Hi Mike

Thanks for this and the explanation, just another question please, is it possible to call the report of another form, am trying to call a specific report of the work order of a batch (in batch production) at the click of a button from Batch Production screen,


I think I know what you're trying to do, but it's still not very clear.

If you use a disassembler you'll see the PrintRecord of the Work Order form looks like this:

Code: Select all
Public Overrides Sub PrintRecord(ByVal ReportDefinition As JiwaApplication.PrintGroup.FormReports.ReportDefinition)
    OnPrintStarting(ReportDefinition)
    Dim PrintUIObject As JiwaApplication.JiwaPrintReportUI.MainForm
    Dim MyLoop As Integer

    PrintUIObject = Manager.CreateReport(ReportDefinition, Me, 1, True, False, True)
    If Not (PrintUIObject Is Nothing) Then
        For MyLoop = 1 To PrintUIObject.PrintReportObject.JiwaReportRangeCollection.Count
            If UCase(PrintUIObject.PrintReportObject.JiwaPrintFormulaCollection(PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).FormulaKey).Name) = UCase("Pass_SP_StartingWorkOrderNo") Or UCase(PrintUIObject.PrintReportObject.JiwaPrintFormulaCollection(PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).FormulaKey).Name) = UCase("Pass_SP_EndingWorkOrderNo") Then
                PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).Value = WorkOrder.WorkOrderNo
            End If
        Next MyLoop

        PrintUIObject.UpdateReport()
        PrintUIObject.chkDrill.Checked = True
        PrintUIObject.PrintReportToScreen()
        PrintUIObject.Show()
    End If
    OnPrintEnd(ReportDefinition)
End Sub


You don't need the whole lot - like remove the call to OnPrintStarting and OnPrintEnd as that won't make sense for your context, but most of the rest is needed - and you'll need to work out what the ReportDefinition needs to be - probably create a new one of those populate the properties.

This is to print to screen, in a print preview window. If you want to print direct to PDF or a printer without a preview then there are other ways which I believe are simpler... But you've not said which way you want the report to be presented so I've assumed you wanted it to screen.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Work Order Print

Postby SBarnes » Wed Feb 07, 2024 7:59 am

I don't know if this will help but one thing I have done before is add a system setting as a look up to hold the details of the report all you need to do is the following

In the system settings plugin in the read data section have code like this

Code: Select all
if (SystemSetting.IDKey == "SRep" || SystemSetting.IDKey == "IRep" || SystemSetting.IDKey == "BORep" || SystemSetting.IDKey == "TRep" )
      {         
            if (SystemSetting.Contents.Trim().Length > 0)
            {
            string SQL = "";

            var db = BusinessLogicHost.Manager.Database;
            try
            {
               SQL = @"SELECT SY_ReportSection.Name+' \ ' + SY_Report.FileName as DisplayName FROM SY_Report JOIN SY_ReportSection ON SY_Report.SY_ReportSection_RecID = SY_ReportSection.RecID
                           where SY_Report.RecID = @RecID ";         
               
               
               using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction))
               {
                  SQLParam = new SqlParameter("@RecID", System.Data.SqlDbType.Char);
                  SQLParam.Value = SystemSetting.Contents;
                  SQLCmd.Parameters.Add(SQLParam);

                  SQLReader = db.ExecuteReader(SQLCmd);

                  if (SQLReader.Read() == true)
                  {
                     SystemSetting.DisplayContents = string.Format("{0}", db.Sanitise(SQLReader, "DisplayName"));
                  }
               }

               SQLReader.Close();
            } finally {
               if ((SQLReader != null))
               {
                  SQLReader.Close();
               }
            }            
         }
            
      }      

and then in the button click have code like


Code: Select all
System.Data.SqlClient.SqlParameter SQLParam = null;
      System.Data.SqlClient.SqlDataReader SQLReader = null;
      if (SystemSetting.IDKey == "SRep" || SystemSetting.IDKey == "IRep" || SystemSetting.IDKey == "BORep" || SystemSetting.IDKey == "TRep" )
      {

         var search = BusinessLogicHost.Manager.Search;
         
         search.Clear();
         search.CurrentOption = 1;
         JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes searchMode = JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes.jswReports;
         search.SetDefaultSearch(ref searchMode);
         search.UsePinBoard = false;
         
         if (search.Show(FormObject.Form) == System.Windows.Forms.DialogResult.OK)
         {
            if (search.Results.Count > 0)
            {                  
               var idField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(1);
               SystemSetting.Contents = idField.FieldValue.ToString();
               
               var TitleField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(2);
               var FileNameField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(3);
               
               SystemSetting.DisplayContents = String.Format("{0} / {1}", TitleField.FieldValue.ToString(), FileNameField.FieldValue.ToString());
            }
            else
            {
               throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
            }
         }
         else
         {
            throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
         }      
      }


then read the setting like this
Code: Select all
IRep = JiwaApplicationManager.Database.ReadSysData(PluginName, "IRep", "0").ToString();
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Work Order Print

Postby Riyaz » Mon Feb 12, 2024 11:41 am

Thanks Mike and Stuart

Appreciate the support
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 17 guests

cron