Manual BO Release, change printer based on warehouse

Discussions relating to plugin development, and the Jiwa API.

Manual BO Release, change printer based on warehouse

Postby DannyC » Mon Feb 28, 2022 10:58 am

When a manual backorder Release is activated, I want to set the printer for the picking slip. The destination printer will change based on the logical warehouse.

Version 7.2.1 SR8

So far I have code which only ticks picking slips, and I've also worked out (I think) how to change the printer depending on the warehouse.
But when I activate, it prints to my default printer. I want it to print to my selected printer from code.

My code so far looks like
Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaForm is JiwaFinancials.Jiwa.JiwaManualBOBatchUI.MainForm)
   {
      JiwaFinancials.Jiwa.JiwaManualBOBatchUI.MainForm manualBOForm = (JiwaFinancials.Jiwa.JiwaManualBOBatchUI.MainForm)JiwaForm;
      manualBOForm.ManualBOBatch.CreateEnd += ManualBOBatch_RemoveReportPrinting;   
      manualBOForm.ManualBOBatch.SaveStart += ManualBOBatch_CheckIfActivating;
   }
}

public void ManualBOBatch_RemoveReportPrinting(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch ManualBORelease = (JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch) sender;   

   foreach (JiwaFinancials.Jiwa.JiwaManualBOBatch.Report printline in ManualBORelease.Reports)
   {
      if (printline.ReportType != JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReportCollection.SalesOrderPrintReportTypes.e_SalesOrderPrintReportTypePickingSheet)
      {
         printline.PrintFlag = false;
      }
      
   }
   
   
}


private void ManualBOBatch_CheckIfActivating(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch ManualBORelease = (JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch) sender;   

   if (ManualBORelease.Status == JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch.Statuses.Activated && ManualBORelease.OriginalStatus == JiwaFinancials.Jiwa.JiwaManualBOBatch.ManualBOBatch.Statuses.UnActivated)
   {
      //We're activating
      isActivating = true;
      JiwaFinancials.Jiwa.JiwaApplication.Entities.LogicalWarehouse logicalWH =  ManualBORelease.Warehouse;
      JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinter targetPrinter = null;
      
      JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinterCollection logicalPrinters = ManualBORelease.Manager.CollectionFactory.CreateCollection<JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinterCollection, JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinter>();
      
      foreach(JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.Maintenance.LogicalPrinter logicalPrinter in logicalPrinters)
      {
         if (logicalPrinter.Description.Contains("Primo PDF") && logicalWH.Description =="QLD")
         {
            targetPrinter = logicalPrinter;
         }
         
         if (logicalPrinter.Description.Contains("XPS") && logicalWH.Description =="NSW")
         {
            targetPrinter = logicalPrinter;
         }
         
      }         
      foreach (JiwaFinancials.Jiwa.JiwaManualBOBatch.Report printline in ManualBORelease.Reports)
      {
         if (printline.PrintFlag)
         {
            printline.ReportDefinition.LogicalPrinter = targetPrinter;   
         }
      }      
      
      foreach (JiwaFinancials.Jiwa.JiwaManualBOBatch.BatchLine batchLine in ManualBORelease.BatchLines)
      {
         if (batchLine.FulfillBackOrderFlag)
         {
            //  Do I set the printer in here?
         }
      }      
      
   }
   else
   {
      isActivating = false;
   }
}
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Manual BO Release, change printer based on warehouse

Postby SBarnes » Tue Mar 01, 2022 9:22 am

Below is the Activate Record code on the Batch object the printing and processing and it would it would appear is carried out by stdFunction.ProcessBackOrdersForSingleSalesOrderUnattended and in there the orders are created and read in and processed, possibly you could set some flag in form plugin code i.e. a static variable on the plugin and then when the sales order is set up you could possibly attach to the order at that point and go after the printing event and the report definition and change the logical printer, you would also need code in the form to flip the flag back.

I don't like static variables on plugins as a way of doing it as it means you are limited to the one variable for the class but there may be no other choice in this case.

Mike or Scott may have a better idea of how to do it.

Code: Select all
public void ActivateRecord()
        {
            IEnumerator enumerator = null;
            if (this.ChangeFlag)
            {
                throw new Exception("Please save the manual back order release batch first.");
            }
            if (this._OriginalStatus == ManualBOBatch.Statuses.Activated)
            {
                throw new Exception("This manual back order release batch is already activated.");
            }
            if (this.UpdateQuantityAvailable(true))
            {
                throw new Exception("Quantity available, back order amounts and priorities have been checked and variations have been found since this batch was last saved. These changes have now been applied to the lines.\r\n\r\nPlease go back and review the lines before activating again.");
            }
            ManualBOBatch.Statuses status = this._Status;
            bool changeFlag = this.ChangeFlag;
            try
            {
                this._Status = ManualBOBatch.Statuses.Activated;
                this.ChangeFlag = true;
                this.SaveHeader();
                StdFunctions stdFunction = null;
                stdFunction = this.Manager.BusinessLogicFactory.CreateBusinessLogic<StdFunctions>(null);
                stdFunction.ReadsAreUnCommitted = true;
                stdFunction.SetupProcessBackOrdersUnattended();
                try
                {
                    enumerator = this.BatchLines.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        BatchLine current = (BatchLine)enumerator.Current;
                        if (!current.FulfillBackOrderFlag)
                        {
                            continue;
                        }
                        try
                        {
                            string nOnBackOrderOrdersOnBackID = current.IN_OnBackOrder_OrdersOnBackID;
                            string invoiceID = this.SalesOrders[current.SalesOrderItemKey].SalesOrder.InvoiceID;
                            BatchLine batchLine = current;
                            BatchLine batchLine1 = batchLine;
                            string invoiceLineID = batchLine.InvoiceLineID;
                            decimal num = new decimal(current.BackOrderQuantity);
                            string inventoryID = this.InventoryItems[current.InventoryItemKey].Inventory.InventoryID;
                            string partNo = this.InventoryItems[current.InventoryItemKey].Inventory.PartNo;
                            string nLogicalID = this.Warehouse.IN_LogicalID;
                            BatchLine batchLine2 = current;
                            BatchLine batchLine3 = batchLine2;
                            string errorMessage = batchLine2.ErrorMessage;
                            stdFunction.ProcessBackOrdersForSingleSalesOrderUnattended(nOnBackOrderOrdersOnBackID, invoiceID, ref invoiceLineID, num, inventoryID, partNo, nLogicalID, ref errorMessage, true);
                            batchLine3.ErrorMessage = errorMessage;
                            batchLine1.InvoiceLineID = invoiceLineID;
                        }
                        catch (Exception exception)
                        {
                            ProjectData.SetProjectError(exception);
                            ProjectData.ClearProjectError();
                        }
                        current.Save();
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                if (this._Status == ManualBOBatch.Statuses.Activated & this._OriginalStatus == ManualBOBatch.Statuses.UnActivated)
                {
                    this.PrintReports();
                }
                this.ChangeFlag = false;
                this.Read(this.RecID);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                this.ChangeFlag = changeFlag;
                this._Status = status;
                throw;
            }
        }


Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 14 guests

cron