﻿<?xml version="1.0" encoding="utf-16"?>
<JiwaDocument xmlns:jiwa="http://www.jiwa.com.au/xml/schemas" Type="JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin">
  <RecID>c29a0f14-4da2-459f-9f0f-dc53a021ce4c</RecID>
  <Name>Work Order Allocations</Name>
  <Description>Shows how to examine work order allocations on save of a work order, and make decisions based on if any inputs or outputs are not fully allocated</Description>
  <IsEnabled>true</IsEnabled>
  <IsIsolatedToOwnAppDomain>false</IsIsolatedToOwnAppDomain>
  <ExecutionOrder>0</ExecutionOrder>
  <Author>Jiwa Financials</Author>
  <Version>7.2.1.0</Version>
  <Code>using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using JiwaFinancials.Jiwa;

#region "BusinessLogicPlugin"
public class BusinessLogicPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogicPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
		JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder = (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)JiwaBusinessLogic;
		workOrder.SaveStart += WorkOrder_SaveStart;
    }
	
	private void WorkOrder_SaveStart(object sender, System.EventArgs e)
	{
		JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder = (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)sender;
		
		foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem outputItem in workOrder.OutputItems)
		{
			foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.SOH.LineDetail&lt;JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem&gt; outputLineDetail in outputItem.LineDetails)
			{
				if (workOrder.Allocations.get_TotalQuantityOutputUnAllocated(outputLineDetail) &gt; 0)
				{
					throw new Exception(String.Format("Output item {0} has a line detail not fully allocated.", outputItem.Inventory.PartNo));
				}
								
				// workOrder.Allocations.get_TotalQuantityOutputAllocated(outputLineDetail) returns the total allocated (as opposed to unallocated)
				// And there are also other methods for input items:
				// workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem)
				// workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail)
				// workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem, outputLineDetail)
				// workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputItem)
				// workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputLineDetail)
			}
		}
	}
}
#endregion
</Code>
  <ExceptionPolicy>Abort</ExceptionPolicy>
  <Language>CSharp</Language>
  <BusinessLogicCollection>
    <BusinessLogic>
      <RecID>0648d51b-0e7f-4ba3-9a13-3b278172d24b</RecID>
      <Description>Work Order</Description>
      <ClassName>JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder</ClassName>
      <Assembly>JiwaBillOfMaterials, Version=7.2.1.27, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</Assembly>
    </BusinessLogic>
  </BusinessLogicCollection>
  <ReferenceCollection>
    <Reference>
      <RecID>06ac3b23-19da-4401-8503-f57e4a53f8ef</RecID>
      <AssemblyFullName>JiwaApplication, Version=7.2.1.27, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaApplication.dll</AssemblyName>
      <AssemblyLocation>C:\VSTS\Jiwa 7\MikesV7JiwaBranch\Built Files\JiwaApplication.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>1b1acdc7-1309-4dfb-b2df-75b396a5d4fc</RecID>
      <AssemblyFullName>mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>mscorlib.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a1fcc3ba-241a-472e-a0d0-d154fd30092f</RecID>
      <AssemblyFullName>System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>0cb507d3-d74c-416f-b876-a4ecd0c6355f</RecID>
      <AssemblyFullName>System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Drawing.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>28988bc5-de21-462f-bdf9-7819edd96b13</RecID>
      <AssemblyFullName>JiwaODBC, Version=7.2.1.27, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaODBC.dll</AssemblyName>
      <AssemblyLocation>C:\VSTS\Jiwa 7\MikesV7JiwaBranch\Built Files\JiwaODBC.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>f50afd12-533d-4a59-9721-04a2ad82c924</RecID>
      <AssemblyFullName>System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Data.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7b483de1-17ef-4330-aa70-92cd7fd02429</RecID>
      <AssemblyFullName>System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>6ec0e0f8-3786-4528-bffc-ca87702ec150</RecID>
      <AssemblyFullName>System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Core.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>03b63eeb-4897-4d9a-a8d3-37f8b82d493c</RecID>
      <AssemblyFullName>JiwaBillOfMaterials, Version=7.2.1.27, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaBillOfMaterials.dll</AssemblyName>
      <AssemblyLocation>C:\VSTS\Jiwa 7\MikesV7JiwaBranch\Built Files\JiwaBillOfMaterials.dll</AssemblyLocation>
    </Reference>
  </ReferenceCollection>
</JiwaDocument>