PR Header if Material select then same in TDI Purchase Category
var documentTypeID = PR.PurchaseRequisition_TDH.DocumentType; // Replace with the correct property name
var documentType = db.DocumentType_ECH
.FirstOrDefault(dt => dt.DocumentTypeID == documentTypeID);
if (documentType != null)
{
// Get the corresponding PurchaseCategoryCode based on DocumentTypeCode
string purchaseCategoryCode = documentType.DocumentTypeCode == "MReq" ? "M" :
documentType.DocumentTypeCode == "SReq" ? "S" :
documentType.DocumentTypeCode == "PReq" ? "P" : null;
if (!string.IsNullOrEmpty(purchaseCategoryCode))
{
// Retrieve the PurchaseCategoryID based on PurchaseCategoryCode
var purchaseCategory = db.PurchaseCategory_ICH
.FirstOrDefault(pc => pc.PurchaseCategoryCode == purchaseCategoryCode && pc.IsActive == true);
if (purchaseCategory != null)
{
purchaseRequisition_TDI.PurchaseCategoryID = purchaseCategory.PurchaseCategoryID;
}
else
{
throw new Exception("PurchaseCategory not found for code: " + purchaseCategoryCode);
}
}
else
{
throw new Exception("Unknown DocumentTypeCode: " + documentType.DocumentTypeCode);
}
}
else
{
throw new Exception("DocumentType not found for ID: " + documentTypeID);
}
Comments
Post a Comment