Custom API service, ODATA actions
// odata or data entity actions
public class CmpyWeighingEntity extends common
{
/// <summary>
/// Updates the base price on purchase allocation lines for a given weight note,
/// joining BFSIndependentWeighingTable since CmpyMasterWeighingPurchAllocationTable
/// does not hold the weight note number directly.
/// </summary>
/// <param name = "_contract">The weighing details contract carrying company, weight note and base price.</param>
/// <returns>The response indicating the success or failure of the operation.</returns>
[SysODataActionAttribute("updatePurchaseLiquidationPrice", false),
SysODataCollectionAttribute("legalEntity", Types::String),
SysODataCollectionAttribute("weightTicketNo", Types::String),
SysODataCollectionAttribute("basePrice", Types::Real)]
public static boolean updatePurchaseLiquidationPrice(DataAreaId legalEntity, str weightTicketNo, Price basePrice)
{
CmpyMasterWeighingResponse response = new CmpyMasterWeighingResponse();
CmpyMasterWeighingTable masterWeighingTable;
CmpyMasterWeighingPurchAllocationTable purchAllocationTable;
BFSIndependentWeighingTable independentWeighingTable;
boolean ret = false;
try
{
if (!legalEntity)
{
throw error("@Nexer:CompanyIDRequired");
}
if (!weightTicketNo)
{
throw error("@Nexer:MasterWeighingRecIdRequired");
}
changecompany(legalEntity)
{
select firstonly RecId, DataAreaId, WeightNoteNum, BFSIndependentWeighID from masterWeighingTable
where masterWeighingTable.WeightNoteNum == weightTicketNo;
if (!masterWeighingTable)
{
throw error(strFmt("@Nexer:MasterWeighingNotFound", weightTicketNo));
}
ttsbegin;
select forupdate purchAllocationTable
where purchAllocationTable.BFSIndependentWeighID == masterWeighingTable.BFSIndependentWeighID
&& purchAllocationTable.Status == BFSPaymentAdviceStatus::Open;
if (purchAllocationTable.RecId)
{
purchAllocationTable.BasePrice = basePrice;
purchAllocationTable.calculatePriceNegotiation();
purchAllocationTable.update();
ret = true;
}
else
{
ret = false;
}
ttscommit;
}
}
catch (Exception::Error)
{
ret = false;
}
catch (Exception::Deadlock)
{
ret = false;
}
return ret;
}
/// <summary>
/// gets the weighing details for a given legal entity and weight ticket number.
/// </summary>
/// <param name = "legalEntity"></param>
/// <param name = "weightTicketNo"></param>
/// <returns></returns>
[SysODataActionAttribute("getPurchaseWeighingDetails", false),
SysODataCollectionAttribute("legalEntity", Types::String),
SysODataCollectionAttribute("weightTicketNo", Types::String)]
public static str getPurchaseWeighingDetails(DataAreaId legalEntity, str weightTicketNo)
{
CmpyPurchaseWeighingDetailsResponse response = new CmpyPurchaseWeighingDetailsResponse();
CmpyMasterWeighingTable masterWeighingTable;
CmpyMultipleWeighingTable multipleWeighingTable;
List weighingDetailList = new List(Types::Class);
CmpyPurchaseWeighingDetailsContract detailsContract;
try
{
if (!legalEntity)
{
throw error("@Nexer:CompanyIDRequired");
}
changecompany(legalEntity)
{
if (weightTicketNo)
{
select firstonly masterWeighingTable
where masterWeighingTable.MasterType == CmpyMasterType::CoffeeReceipt
&& masterWeighingTable.Status == CmpyMasterWeighStatus::Received
&& masterWeighingTable.WeightNoteNum == weightTicketNo;
if (masterWeighingTable)
{
select sum(FirstWeight),
sum(SecondWeight),
sum(GrossWeight),
sum(AbsoluteWeight),
sum(NetWeight),
sum(TareWeight),
sum(PkgQty),
sum(RejectedWeight),
PkgType,
Unit,
MasterWeighRecID
from multipleWeighingTable
group by multipleWeighingTable.IndependentWeighingID,
multipleWeighingTable.PkgType,
multipleWeighingTable.Unit
,multipleWeighingTable.MasterWeighRecID
where multipleWeighingTable.MasterWeighRecID == masterWeighingTable.RecId
&& multipleWeighingTable.CmpyMultipleWeightType == CmpyMultipleWeightType::Weight
&& multipleWeighingTable.IsCancelled != NoYes::Yes;
if (masterWeighingTable && multipleWeighingTable)
{
CmpyPurchaseWeighingDetailsContract details = new CmpyPurchaseWeighingDetailsContract();
// Header fields from CmpyMasterWeighingTable
details.parmScaleType(masterWeighingTable.ScaleType);
details.parmVendName(VendTable::find(masterWeighingTable.VendAccount).name());
details.parmWeighingDate(masterWeighingTable.CreatedDate);
details.parmWeightNoteNum(masterWeighingTable.WeightNoteNum);
details.parmSite(masterWeighingTable.InventSiteID);
details.parmWarehouse(masterWeighingTable.EDF_DestInventLocationId);
details.parmLocation(masterWeighingTable.WMSLocationId);
details.parmProductCode(masterWeighingTable.ItemId);
// Weight fields from CmpyMultipleWeighingTable
details.parmScaleWeight(multipleWeighingTable.FirstWeight);
details.parmTareWeight(multipleWeighingTable.TareWeight);
details.parmNetWeight(multipleWeighingTable.NetWeight);
details.parmNoOfBags(multipleWeighingTable.PkgQty);
details.parmBagUnit(multipleWeighingTable.Unit);
weighingDetailList.addEnd(details);
response.parmSuccess(true);
response.parmWeighingDetailList(weighingDetailList);
}
else
{
response.parmSuccess(false);
}
}
else
{
response.parmSuccess(false);
}
}
else
{
while select masterWeighingTable
where masterWeighingTable.MasterType == CmpyMasterType::CoffeeReceipt
&& masterWeighingTable.Status == CmpyMasterWeighStatus::Received
{
select sum(FirstWeight),
sum(SecondWeight),
sum(GrossWeight),
sum(AbsoluteWeight),
sum(NetWeight),
sum(TareWeight),
sum(PkgQty),
sum(RejectedWeight),
PkgType,
Unit,
MasterWeighRecID
from multipleWeighingTable
group by multipleWeighingTable.IndependentWeighingID,
multipleWeighingTable.PkgType,
multipleWeighingTable.Unit
,multipleWeighingTable.MasterWeighRecID
where multipleWeighingTable.MasterWeighRecID == masterWeighingTable.RecId
&& multipleWeighingTable.CmpyMultipleWeightType == CmpyMultipleWeightType::Weight
&& multipleWeighingTable.IsCancelled != NoYes::Yes;
CmpyPurchaseWeighingDetailsContract details = new CmpyPurchaseWeighingDetailsContract();
// Header fields from CmpyMasterWeighingTable
details.parmScaleType(masterWeighingTable.ScaleType);
details.parmVendName(VendTable::find(masterWeighingTable.VendAccount).name());
details.parmWeighingDate(masterWeighingTable.CreatedDate);
details.parmWeightNoteNum(masterWeighingTable.WeightNoteNum);
details.parmSite(masterWeighingTable.InventSiteID);
details.parmWarehouse(masterWeighingTable.EDF_DestInventLocationId);
details.parmLocation(masterWeighingTable.WMSLocationId);
details.parmProductCode(masterWeighingTable.ItemId);
// Weight fields from CmpyMultipleWeighingTable
details.parmScaleWeight(multipleWeighingTable.FirstWeight);
details.parmTareWeight(multipleWeighingTable.TareWeight);
details.parmNetWeight(multipleWeighingTable.NetWeight);
details.parmNoOfBags(multipleWeighingTable.PkgQty);
details.parmBagUnit(multipleWeighingTable.Unit);
weighingDetailList.addEnd(details);
}
response.parmSuccess(true);
response.parmWeighingDetailList(weighingDetailList);
}
}
}
catch (Exception::Error)
{
response.parmSuccess(false);
}
return FormJsonSerializer::serializeClass(response);
}
}
https://{D365Url}/data/CmpyMasterWeighingDetails/Microsoft.Dynamics.DataEntities.getPurchaseWeighingDetails
Body/Parameters:
{
"legalEntity": "CAR",
"weightTicketNo" : "01-PO-NORM-000000839"
}
https://{D365Url}/data/CmpyMasterWeighingDetails/Microsoft.Dynamics.DataEntities.updatePurchaseLiquidationPrice
Body/Parameters:
{
"legalEntity": "CAR",
"weightTicketNo" : "01-PO-NORM-000000839",
"basePrice" : 1520.65
}
Comments
Post a Comment