【发布时间】:2020-02-04 20:37:56
【问题描述】:
我们在 Acumatica 中使用自定义装箱单报告,该报告适用于所有不同类型的承运人(UPS、FedEx、USPS 等),并且需要没有任何旋转的运输标签图像。
通过 Stamps.com 和 FedEx 检索的运输标签图像没有任何旋转,但通过 UPS 承运人集成的运输标签图像在开箱后顺时针旋转 270 度,并且不适合在指定区域(粘合剂)固定/报告。
【问题讨论】:
标签: c# acumatica acumatica-kb
我们在 Acumatica 中使用自定义装箱单报告,该报告适用于所有不同类型的承运人(UPS、FedEx、USPS 等),并且需要没有任何旋转的运输标签图像。
通过 Stamps.com 和 FedEx 检索的运输标签图像没有任何旋转,但通过 UPS 承运人集成的运输标签图像在开箱后顺时针旋转 270 度,并且不适合在指定区域(粘合剂)固定/报告。
【问题讨论】:
标签: c# acumatica acumatica-kb
UPS 运输标签 API 没有选项来指定运输标签图像的旋转度数。我们将通过自定义ShipmentEntry graph/BLC 和Shipment Entry screen (SO302000) 来解决这个问题。
当前工作流程不会有任何变化(最终用户视角)。当在 Acumatica 中确认货件时,会生成标签并从 UPS 检索,在此过程中,我们的自定义将顺时针旋转检索到的标签(仅当 Ship-Via on Shipment 使用 UPS 插件且标签格式为 GIF 时)顺时针 90 度。此 UPS 标签将与通过其他插件(FedEx 和 Stamps.com)生成的标签对齐。并且不需要在报告级别进行调整。
运输标签是通过ShipmentEntry Graph/BLC 中的ShipPackages 虚拟方法生成的。因此,我们将在 ShipmentEntry Graph/BLC 的 Graph/BLC 扩展中覆盖 ShipPackages 虚拟方法。
public class SOShipmentEntryRotateGIFLabelExt : PXGraphExtension<SOShipmentEntry>
{
public delegate void ShipPackagesBaseDelegate(SOShipment shiporder);
[PXOverride]
public void ShipPackages(SOShipment shiporder, ShipPackagesBaseDelegate BaseInvoke)
{
//Custom code to rotate image if carrier is UPS and label format is GIF
//Invoke base method
BaseInvoke(shiporder);
}
}
Acumatica 中的文件附件是通过UploadFileMaintenance Graph/BLC 执行的。
我们将通过将UploadFileRevision DAC 的RowInserted 事件处理程序添加到UploadFileMaintenance 图表来扩展逻辑。
因为UploadFileMaintenance BLC 实例是在ShipPackages 中创建的,并且在执行之前不可用,我们将向PXGraph 类的静态InstanceCreated 集合添加一个委托。
在初始化UploadFileMaintenance BLC 实例时执行的委托中,我们将向UploadFileMaintenance Graph/BLC 实例的RowInserted 集合添加一个事件处理程序。
public class SOShipmentEntryRotateGIFLabelExt : PXGraphExtension<SOShipmentEntry>
{
public delegate void ShipPackagesBaseDelegate(SOShipment shiporder);
[PXOverride]
public void ShipPackages(SOShipment shiporder, ShipPackagesBaseDelegate BaseInvoke)
{
#region Custom-code-to-rotate-retrieved-Label
PXGraph.InstanceCreated.AddHandler<UploadFileMaintenance>((fileGraph) =>
{
fileGraph.RowInserted.AddHandler<UploadFileRevision>((sender, e) =>
{
UploadFileRevision fileData = (UploadFileRevision)e.Row;
});
});
#endregion
//Invoke base method
BaseInvoke(shiporder);
}
}
在RowInserted 事件处理程序中,我们获取正在处理的UploadFileRevision 数据记录并检索运输标签图像并旋转它。
最后我们调用基础方法。
using PX.Data;
using PX.Objects.CS;
using PX.Objects.SO;
using PX.SM;
using System.Drawing;
using System.IO;
namespace PX.RotateUPSLabelImage.Ext
{
public class SOShipmentEntryRotateGIFLabelExt : PXGraphExtension<SOShipmentEntry>
{
public delegate void ShipPackagesBaseDelegate(SOShipment shiporder);
[PXOverride]
public void ShipPackages(SOShipment shiporder, ShipPackagesBaseDelegate BaseInvoke)
{
#region Custom-code-to-rotate-retrieved-Label
//Identify specified Ship-Via/Carrier Shipment is working with
var carrier = Carrier.PK.Find(Base, shiporder.ShipVia);
//If specified Ship-Via/Carrier is API/Plug-In based
if (carrier?.IsExternal == true)
{
//Identify Connected Carrier Plug-In
var plugin = CarrierPlugin.PK.Find(Base, carrier.CarrierPluginID);
//If Plug-In is working with UPS
if (plugin?.PluginTypeName?.Trim() == typeof(PX.UpsCarrier.UpsCarrier).FullName)
{
PXGraph.InstanceCreated.AddHandler<UploadFileMaintenance>((fileGraph) =>
{
fileGraph.RowInserted.AddHandler<UploadFileRevision>((sender, e) =>
{
UploadFile fileInfo = (UploadFile)sender.Graph.Caches<UploadFile>()?.Current;
if (fileInfo != null)
{
if (fileInfo.Name.StartsWith("Label #") && (fileInfo.Extansion.ToUpper() == "GIF"))
{
UploadFileRevision fileData = (UploadFileRevision)e.Row;
using (MemoryStream fileMemoryStream = new MemoryStream(fileData?.Data))
{
Image labelImage = Image.FromStream(fileMemoryStream);
if (labelImage != null)
{
labelImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
ImageConverter imgConverter = new ImageConverter();
fileData.Data = (byte[])imgConverter.ConvertTo(labelImage, typeof(byte[]));
}
}
}
}
});
});
}
}
#endregion
//Invoke base method
BaseInvoke(shiporder);
}
}
}
Download Acumatica Customization deployment package
以下帮助文章可以参考Acumatica定制指南
【讨论】: