|
|
@@ -9,6 +9,7 @@ using PX.Objects.GL;
|
|
|
using PX.Objects.IN;
|
|
|
using PX.Objects.PM;
|
|
|
|
|
|
+//AR202000 use sale prices. Price Code is the customer. Customer is the project customer. Qty * Price= Amount
|
|
|
namespace ProjectEntryLaborAdjust
|
|
|
{
|
|
|
|
|
|
@@ -16,11 +17,10 @@ namespace ProjectEntryLaborAdjust
|
|
|
public class ProjectEntryExt : PXGraphExtension<ProjectEntry>
|
|
|
{
|
|
|
private const string SlotLaborUpdate = "RevBudSetLabor"; // <-- new flag
|
|
|
- private const string LaborInvCD = "L023";
|
|
|
- private const string ExcludedBranchCD = "301";
|
|
|
- private static readonly HashSet<string> ExcludedBranchCDs = new HashSet<string>{"301","112"};
|
|
|
+ private const string LaborInvCD = "L023"; //"L023";
|
|
|
+ private static readonly HashSet<string> ExcludedBranchCDs = new HashSet<string>{"301"};
|
|
|
+ private static readonly HashSet<string> ExcludedTemplateCDs = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "ENVIRONMENTAL" };
|
|
|
private const string ExcludedBillRule = "PROGRESS";
|
|
|
- private const decimal PMRate = 90m;
|
|
|
private int? _laborInvID;
|
|
|
private int? LaborInvID
|
|
|
{
|
|
|
@@ -71,13 +71,14 @@ namespace ProjectEntryLaborAdjust
|
|
|
{
|
|
|
var c = Base.RevenueBudget.Cache;
|
|
|
|
|
|
- if (laborLine.Qty != pmHours)
|
|
|
+ bool qtyChanged = laborLine.Qty != pmHours;
|
|
|
+ if (qtyChanged)
|
|
|
c.SetValueExt<PMRevenueBudget.qty>(laborLine, pmHours);
|
|
|
|
|
|
- if (laborLine.CuryUnitRate != PMRate)
|
|
|
- c.SetValueExt<PMRevenueBudget.curyUnitRate>(laborLine, PMRate);
|
|
|
+ // Re-run pricing defaults so rate comes from AR prices
|
|
|
+ if (qtyChanged)
|
|
|
+ c.SetDefaultExt<PMRevenueBudget.curyUnitRate>(laborLine);
|
|
|
|
|
|
- // DO NOT set curyAmount – let the formula do it.
|
|
|
c.Update(laborLine);
|
|
|
}
|
|
|
else
|
|
|
@@ -87,8 +88,8 @@ namespace ProjectEntryLaborAdjust
|
|
|
taskID: row.ProjectTaskID,
|
|
|
accountGroupID: row.AccountGroupID,
|
|
|
qty: pmHours,
|
|
|
- rate: PMRate,
|
|
|
- amount: pmHours * PMRate,
|
|
|
+ // rate: PMRate,
|
|
|
+ // amount: pmHours * PMRate,
|
|
|
uom: row.UOM,
|
|
|
description: "Auto-added PM Labor"
|
|
|
);
|
|
|
@@ -113,15 +114,6 @@ namespace ProjectEntryLaborAdjust
|
|
|
if (row == null || e.Operation == PXDBOperation.Delete) return;
|
|
|
if (Skip || PXContext.GetSlot<bool?>(SlotLaborUpdate) == true) return;
|
|
|
|
|
|
- if (LaborInvID != null && row.InventoryID == LaborInvID)
|
|
|
- {
|
|
|
- // ensure both currency and base rates are correct right before save
|
|
|
- decimal baseRate;
|
|
|
- PXCurrencyAttribute.CuryConvBase<PMRevenueBudget.curyUnitRate>(e.Cache, row, PMRate, out baseRate);
|
|
|
-
|
|
|
- if (row.CuryUnitRate != PMRate)
|
|
|
- e.Cache.SetValue<PMRevenueBudget.curyUnitRate>(row, PMRate);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -130,6 +122,31 @@ namespace ProjectEntryLaborAdjust
|
|
|
PMProject proj = Base.Project.Current;
|
|
|
if (proj == null) return false;
|
|
|
|
|
|
+
|
|
|
+ if (proj.TemplateID != null)
|
|
|
+ {
|
|
|
+ // Any of these 3 options work;
|
|
|
+ // 1) PK.Find (newer builds):
|
|
|
+ PMProject tmpl = PMProject.PK.Find(Base, proj.TemplateID);
|
|
|
+
|
|
|
+ // 2) Fluent BQL (uncomment if you prefer):
|
|
|
+ // PMProject tmpl = SelectFrom<PMProject>
|
|
|
+ // .Where<PMProject.contractID.IsEqual<@P.AsInt>>.View
|
|
|
+ // .Select(Base, proj.TemplateID);
|
|
|
+
|
|
|
+ // 3) Classic PXSelectReadonly (also fine):
|
|
|
+ // PMProject tmpl = PXSelectReadonly<PMProject,
|
|
|
+ // Where<PMProject.contractID, Equal<Required<PMProject.contractID>>>>
|
|
|
+ // .Select(Base, proj.TemplateID)
|
|
|
+ // ?.FirstOrDefault()?.GetItem<PMProject>();
|
|
|
+
|
|
|
+ if (tmpl?.ContractCD != null &&
|
|
|
+ ExcludedTemplateCDs.Contains(tmpl.ContractCD.Trim()))
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// Branch check (BranchCD = 301) --------------------------------
|
|
|
if (proj.DefaultBranchID != null)
|
|
|
{
|
|
|
@@ -263,15 +280,11 @@ namespace ProjectEntryLaborAdjust
|
|
|
if (qty != null)
|
|
|
cache.SetValueExt<PMRevenueBudget.qty>(line, qty);
|
|
|
|
|
|
- if (rate != null)
|
|
|
- cache.SetValueExt<PMRevenueBudget.curyUnitRate>(line, rate);
|
|
|
-
|
|
|
- if (amount != null)
|
|
|
- cache.SetValueExt<PMRevenueBudget.curyAmount>(line, amount);
|
|
|
-
|
|
|
if (!string.IsNullOrEmpty(description))
|
|
|
cache.SetValueExt<PMRevenueBudget.description>(line, description);
|
|
|
|
|
|
+ cache.SetDefaultExt<PMRevenueBudget.curyUnitRate>(line);
|
|
|
+
|
|
|
// Final update so cache/state is consistent
|
|
|
line = (PMRevenueBudget)cache.Update(line);
|
|
|
|