private IEnumerable <ApproveInfo> GetEmployeesByFilter(Table item, EPRule rule, List <EPRuleBaseCondition> conditions) { Type resultViewType = typeof(Select5 < EPEmployee, LeftJoin <Address, On <Address.addressID, Equal <EPEmployee.defAddressID> >, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> >, LeftJoin <EPCompanyTreeMember, On <EPCompanyTreeMember.userID, Equal <EPEmployee.userID> > > > >, Aggregate <GroupBy <EPEmployee.bAccountID> > >); PXView itemView = new PXView(this, false, BqlCommand.CreateInstance(resultViewType)); PXFilterRow[] filters = GenerateFilters(item, conditions).ToArray <PXFilterRow>(); int startRow = 0; int totalRows = 0; using (new PXFieldScope(itemView)) { IEnumerable <PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember> > resultset = itemView .Select(null, null, null, null, null, filters, ref startRow, 0, ref totalRows) .Select(_ => (PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember>)_); foreach (PXResult <EPEmployee, Address, Contact, EPCompanyTreeMember> res in resultset) { EPEmployee employee = res; EPCompanyTreeMember treeMember = res; yield return(new ApproveInfo() { OwnerID = employee.UserID, WorkgroupID = rule.WorkgroupID, RuleID = rule.RuleID, StepID = rule.StepID, WaitTime = rule.WaitTime }); } } }
protected virtual void _(Events.RowUpdated <EPActivityApprove> e) { if (e.Row.Date.GetValueOrDefault() != e.OldRow.Date.GetValueOrDefault() || e.Row.EarningTypeID != e.OldRow.EarningTypeID || e.Row.ProjectID.GetValueOrDefault() != e.OldRow.ProjectID.GetValueOrDefault() || e.Row.ProjectTaskID.GetValueOrDefault() != e.OldRow.ProjectTaskID.GetValueOrDefault() || e.Row.CostCodeID != e.OldRow.CostCodeID || e.Row.UnionID != e.OldRow.UnionID || e.Row.LabourItemID != e.OldRow.LabourItemID || e.Row.CertifiedJob.GetValueOrDefault() != e.OldRow.CertifiedJob.GetValueOrDefault() || e.Row.OwnerID.GetValueOrDefault() != e.OldRow.OwnerID.GetValueOrDefault()) { EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(this, e.Row.OwnerID); if (employee != null) { var cost = CostEngine.CalculateEmployeeCost(null, e.Row.EarningTypeID, e.Row.LabourItemID, e.Row.ProjectID, e.Row.ProjectTaskID, e.Row.CertifiedJob, e.Row.UnionID, employee.BAccountID, e.Row.Date.Value); e.Row.EmployeeRate = cost?.Rate; } } }
private bool IsEmployeeInWorkgroup(EPEmployee employee, EPAssignmentRule rule) { PXFilterRow filter = new PXFilterRow( typeof(EPCompanyTree.description).Name, (PXCondition)rule.Condition.Value, rule.FieldValue, null); PXSelectBase <EPCompanyTree> select = new PXSelectJoin <EPCompanyTree, InnerJoin <EPCompanyTreeMember, On <EPCompanyTree.workGroupID, Equal <EPCompanyTreeMember.workGroupID> > >, Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> >, And <EPCompanyTreeMember.active, Equal <True> > > >(this); int startRow = 0; int totalRows = 0; List <object> result = select.View.Select(null, new object[] { employee.UserID }, null, null, null, new PXFilterRow[] { filter }, ref startRow, 1, ref totalRows); //select.SelectSingle(employee.UserID, workgroupID); return(result.Count > 0); }
public virtual int?GetLaborClass(PMTimeActivity activity, EPEmployee employee, CRCase refCase) { if (employee == null) { throw new ArgumentNullException("employee", Messages.EmptyEmployeeID); } int?laborClassID = null; if (refCase != null) { CRCaseClass caseClass = (CRCaseClass)PXSelectorAttribute.Select <CRCase.caseClassID>(graph.Caches[typeof(CRCase)], refCase); if (caseClass.PerItemBilling == BillingTypeListAttribute.PerActivity) { laborClassID = CRCaseClassLaborMatrix.GetLaborClassID(graph, caseClass.CaseClassID, activity.EarningTypeID); } } if (laborClassID == null && activity.LabourItemID != null) { laborClassID = activity.LabourItemID; } if (laborClassID == null && activity.ProjectID != null && employee.BAccountID != null) { laborClassID = EPContractRate.GetProjectLaborClassID(graph, (int)activity.ProjectID, (int)employee.BAccountID, activity.EarningTypeID); } if (laborClassID == null) { laborClassID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, activity.EarningTypeID); } if (laborClassID == null) { laborClassID = employee.LabourItemID; } return(laborClassID); }
protected virtual void EPExpenseClaimDetails_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e) { EPExpenseClaimDetails row = e.Row as EPExpenseClaimDetails; EPExpenseClaimDetails oldRow = e.OldRow as EPExpenseClaimDetails; if (row == null || oldRow == null) { return; } if (row.RefNbr != oldRow.RefNbr || row.TaxCategoryID != oldRow.TaxCategoryID || row.TaxCalcMode != oldRow.TaxCalcMode || row.TaxZoneID != oldRow.TaxZoneID) { EPClaimReceiptController.DeleteLegacyTaxRows(this, row.RefNbr); } if (e.ExternalCall && !this.IsMobile) { if (row.TaxZoneID != oldRow.TaxZoneID && !string.IsNullOrEmpty(row.TaxZoneID)) { EPEmployee employee = Employee.Select(); string taxZoneID = employee.ReceiptAndClaimTaxZoneID; if (string.IsNullOrEmpty(taxZoneID)) { Location location = PXSelect <Location, Where <Location.locationID, Equal <Required <EPEmployee.defLocationID> > > > .Select(this, employee.DefLocationID); taxZoneID = location?.VTaxZoneID; } if (row.TaxZoneID != taxZoneID) { Employee.Current = employee; TaxZoneUpdateAskView.View.AskExt(); } } } }
protected virtual void EPExpenseClaimDetails_SalesSubID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { if (((EPExpenseClaimDetails)e.Row).SalesAccountID != null) { object value = null; if (((EPExpenseClaimDetails)e.Row).Billable == true) { InventoryItem item = (InventoryItem)PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, ((EPExpenseClaimDetails)e.Row).InventoryID); Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <EPExpenseClaimDetails.branchID> > > > .Select(this); Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(this, ((EPExpenseClaimDetails)e.Row).ContractID); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(this, ((EPExpenseClaimDetails)e.Row).ContractID, ((EPExpenseClaimDetails)e.Row).TaskID); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(sender, e.Row); EPEmployee employee = (EPEmployee)PXSelect <EPEmployee> .Search <EPEmployee.bAccountID>(this, e.Row != null?((EPExpenseClaimDetails)e.Row).EmployeeID : null); int?employee_SubID = (int?)Caches[typeof(EPEmployee)].GetValue <EPEmployee.salesSubID>(employee); int?item_SubID = (int?)Caches[typeof(InventoryItem)].GetValue <InventoryItem.salesSubID>(item); int?company_SubID = (int?)Caches[typeof(Location)].GetValue <Location.cMPSalesSubID>(companyloc); int?project_SubID = (int?)Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)Caches[typeof(Location)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); value = SubAccountMaskAttribute.MakeSub <EPSetup.salesSubMask>(this, epsetup.Current.SalesSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.salesSubID), typeof(InventoryItem.salesSubID), typeof(Location.cMPSalesSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); } sender.RaiseFieldUpdating <EPExpenseClaimDetails.salesSubID>(e.Row, ref value); e.NewValue = (int?)value; e.Cancel = true; } }
public virtual int?GetLaborClass(CR.EPActivity activity) { int?laborClassID = null; CR.CRCase refCase = PXSelect <CR.CRCase, Where <CR.CRCase.noteID, Equal <Required <CR.EPActivity.refNoteID> > > > .Select(graph, activity.RefNoteID); if (refCase != null) { CR.CRCaseClass caseClass = (CR.CRCaseClass)PXSelectorAttribute.Select <CR.CRCase.caseClassID>(graph.Caches[typeof(CR.CRCase)], refCase); laborClassID = CR.CRCaseClassLaborMatrix.GetLaborClassID(graph, caseClass.CaseClassID, activity.EarningTypeID); } EPEmployee employee = PXSelect <EPEmployee> .Search <EPEmployee.userID>(graph, activity.Owner); if (employee == null) { throw new Exception(Messages.EmptyEmployeeID); } if (laborClassID == null && activity.ProjectID != null && employee.BAccountID != null) { laborClassID = EPContractRate.GetProjectLaborClassID(graph, (int)activity.ProjectID, (int)employee.BAccountID, activity.EarningTypeID); } if (laborClassID == null) { laborClassID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, activity.EarningTypeID); } if (laborClassID == null) { laborClassID = employee.LabourItemID; } return(laborClassID); }
protected virtual void CurrencyInfo_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { CurrencyInfo info = e.Row as CurrencyInfo; if (info != null && ClaimDetails.Current != null) { bool rateenabled = info.AllowUpdate(ClaimDetails.Cache) && ClaimDetails.Current.EmployeeID != null; if (rateenabled) { CurrencyList curyList = (CurrencyList)PXSelectorAttribute.Select <CurrencyInfo.curyID>(cache, info); if (curyList != null && curyList.IsFinancial == true) { EPEmployee employee = (EPEmployee)PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Current <EPExpenseClaimDetails.employeeID> > > > .SelectSingleBound(this, new object[] { ClaimDetails.Current }); rateenabled = employee != null && employee.AllowOverrideRate == true; } } PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyRateTypeID>(cache, info, rateenabled); PXUIFieldAttribute.SetEnabled <CurrencyInfo.curyEffDate>(cache, info, rateenabled); PXUIFieldAttribute.SetEnabled <CurrencyInfo.sampleCuryRate>(cache, info, rateenabled); PXUIFieldAttribute.SetEnabled <CurrencyInfo.sampleRecipRate>(cache, info, rateenabled); } }
public static DateTime?GetNextActivityStartDate <Activity>(PXGraph graph, PXResultset <Activity> res, PMTimeActivity row, int?fromWeekId, int?tillWeekId, PXCache tempDataCache, Type tempDataField) where Activity : PMTimeActivity, new() { DateTime?date; if (fromWeekId != null || tillWeekId != null) { date = PXWeekSelector2Attribute.GetWeekStartDate(graph, (int)(fromWeekId ?? tillWeekId)); } else { date = graph.Accessinfo.BusinessDate.GetValueOrDefault(DateTime.Now).Date; } EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, row.OwnerID); EPEmployeeClass employeeClass = PXSelect <EPEmployeeClass, Where <EPEmployeeClass.vendorClassID, Equal <Required <EPEmployee.vendorClassID> > > > .Select(graph, employee != null?employee.VendorClassID : null); var calendarId = CRActivityMaint.GetCalendarID(graph, row); if (employeeClass != null && EPEmployeeClass.defaultDateInActivity.LastDay == employeeClass.DefaultDateInActivity) { DateTime?val = tempDataCache.GetValue(tempDataCache.Current, tempDataField.Name) as DateTime?; if (val != null) { int week = PXWeekSelector2Attribute.GetWeekID(graph, (DateTime)val); if ((fromWeekId == null || week >= fromWeekId) && (tillWeekId == null || tillWeekId >= week)) { date = val; } } } else { DateTime weekDate = (DateTime)date; DateTime?newDate = null; date = res != null && res.Count > 0 ? res.Max(_ => ((Activity)_).Date) : null ?? date; for (int curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate); tillWeekId == null || curentWeek <= tillWeekId; curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate)) { PXWeekSelector2Attribute.WeekInfo week1 = PXWeekSelector2Attribute.GetWeekInfo(graph, PXWeekSelector2Attribute.GetWeekID(graph, weekDate)); foreach (KeyValuePair <DayOfWeek, PXWeekSelector2Attribute.DayInfo> pair in week1.Days.OrderBy(_ => _.Value.Date)) { if (pair.Value.Date >= date && (CalendarHelper.IsWorkDay(graph, calendarId, (DateTime)pair.Value.Date) || string.IsNullOrEmpty(calendarId) && pair.Key != DayOfWeek.Saturday && pair.Key != DayOfWeek.Sunday)) { newDate = (DateTime)pair.Value.Date; break; } weekDate = weekDate.AddDays(1D); } if (newDate != null) { date = ((DateTime)newDate).Date; break; } } } if (!string.IsNullOrEmpty(calendarId) && date != null) { DateTime startDate; DateTime endDate; CalendarHelper.CalculateStartEndTime(graph, calendarId, (DateTime)date, out startDate, out endDate); date = startDate; } return(date); }
public virtual List <APRegister> ReleaseClaimDetails <TAPDocument, TInvoiceMapping, TGraph, TAPDocumentGraphExtension> (ExpenseClaimEntry expenseClaimGraph, EPExpenseClaim claim, IEnumerable <EPExpenseClaimDetails> receipts, string receiptGroupPaidWithType) where TGraph : PXGraph, new() where TAPDocument : InvoiceBase, new() where TInvoiceMapping : IBqlMapping where TAPDocumentGraphExtension : PX.Objects.Common.GraphExtensions.Abstract.InvoiceBaseGraphExtension <TGraph, TAPDocument, TInvoiceMapping> { #region prepare required variable var docgraph = PXGraph.CreateInstance <TGraph>(); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph); TAPDocumentGraphExtension apDocumentGraphExtension = docgraph.FindImplementation <TAPDocumentGraphExtension>(); List <List <EPExpenseClaimDetails> > receiptsForDocument = new List <List <EPExpenseClaimDetails> >(); if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.PersonalAccount) { receiptsForDocument = receipts.GroupBy(item => new { item.TaxZoneID, item.TaxCalcMode }) .Select(group => group.ToList()) .ToList(); } else if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardCompanyExpense) { if (epsetup.PostSummarizedCorpCardExpenseReceipts == true) { receiptsForDocument = receipts.GroupBy(item => new { item.TaxZoneID, item.TaxCalcMode, item.CorpCardID, item.ExpenseDate, item.ExpenseRefNbr }) .Select(group => group.ToList()) .ToList(); } else { receiptsForDocument = receipts.Select(receipt => receipt.SingleToList()).ToList(); } } else if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardPersonalExpense) { receiptsForDocument = new List <List <EPExpenseClaimDetails> >() { receipts.ToList() }; } else { throw new NotImplementedException(); } if (!receiptsForDocument.Any()) { receiptsForDocument.Add(new List <EPExpenseClaimDetails>()); } APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph); EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID); Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID); List <APRegister> doclist = new List <APRegister>(); expenseClaimGraph.SelectTimeStamp(); if (claim.FinPeriodID != null) { FinPeriodUtils.ValidateFinPeriod(claim.SingleToArray()); } #endregion foreach (var receiptGroup in receiptsForDocument) { if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardCompanyExpense && receiptGroup.Count > 1) { EPExpenseClaimDetails[] matchedReceipts = receiptGroup.Where(receipt => receipt.BankTranDate != null).Take(11).ToArray(); if (matchedReceipts.Any()) { PXResult <EPExpenseClaimDetails, CABankTranMatch, CABankTran>[] rows = PXSelectJoin <EPExpenseClaimDetails, InnerJoin <CABankTranMatch, On <CABankTranMatch.docModule, Equal <BatchModule.moduleEP>, And <CABankTranMatch.docType, Equal <EPExpenseClaimDetails.docType>, And <CABankTranMatch.docRefNbr, Equal <EPExpenseClaimDetails.claimDetailCD> > > >, InnerJoin <CABankTran, On <CABankTran.tranID, Equal <CABankTranMatch.tranID> > > >, Where <EPExpenseClaimDetails.claimDetailCD, In <Required <EPExpenseClaimDetails.claimDetailCD> > > > .Select(expenseClaimGraph, matchedReceipts.Select(receipt => receipt.ClaimDetailCD).ToArray()) .Cast <PXResult <EPExpenseClaimDetails, CABankTranMatch, CABankTran> >() .ToArray(); throw new PXException(Messages.ExpenseReceiptCannotBeSummarized, rows.Select(row => String.Concat(PXMessages.LocalizeNoPrefix(Messages.Receipt), " ", ((EPExpenseClaimDetails)row).ClaimDetailCD, " - ", ((CABankTran)row).GetFriendlyKeyImage(Caches[typeof(CABankTran)]))) .ToArray() .JoinIntoStringForMessageNoQuotes(maxCount: 10)); } } docgraph.Clear(PXClearOption.ClearAll); docgraph.SelectTimeStamp(); apDocumentGraphExtension.Contragent.Current = apDocumentGraphExtension.Contragent.Cache.GetExtension <Contragent>(employee); apDocumentGraphExtension.Location.Current = emplocation; CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID); CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal); info.CuryInfoID = null; info = apDocumentGraphExtension.CurrencyInfo.Insert(info); #region CreateInvoiceHeader var invoice = new TAPDocument(); CABankTranMatch bankTranMatch = null; if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.PersonalAccount) { invoice.DocType = receiptGroup.Sum(_ => _.ClaimCuryTranAmtWithTaxes) < 0 ? APInvoiceType.DebitAdj : APInvoiceType.Invoice; } else if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardCompanyExpense) { EPExpenseClaimDetails receipt = receiptGroup.First(); invoice.DocType = APDocType.QuickCheck; CACorpCard card = CACorpCard.PKID.Find(this, receipt.CorpCardID); PaymentMethodAccount paymentMethodAccount = PXSelect <PaymentMethodAccount, Where <PaymentMethodAccount.cashAccountID, Equal <Required <PaymentMethodAccount.cashAccountID> > > > .Select(this, card.CashAccountID); invoice.CashAccountID = card.CashAccountID; invoice.PaymentMethodID = paymentMethodAccount.PaymentMethodID; invoice.ExtRefNbr = receipt.ExpenseRefNbr; if (receiptGroup.Count == 1) { bankTranMatch = PXSelect <CABankTranMatch, Where <CABankTranMatch.docModule, Equal <BatchModule.moduleEP>, And <CABankTranMatch.docType, Equal <EPExpenseClaimDetails.docType>, And <CABankTranMatch.docRefNbr, Equal <Required <CABankTranMatch.docRefNbr> > > > > > .Select(expenseClaimGraph, receipt.ClaimDetailCD); if (bankTranMatch != null) { CABankTran bankTran = CABankTran.PK.Find(expenseClaimGraph, bankTranMatch.TranID); invoice.ClearDate = bankTran.ClearDate; invoice.Cleared = true; } } } else if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardPersonalExpense) { invoice.DocType = APDocType.DebitAdj; } else { throw new NotImplementedException(); } invoice.CuryInfoID = info.CuryInfoID; invoice.Hold = true; invoice.Released = false; invoice.Printed = invoice.DocType == APDocType.QuickCheck; invoice.OpenDoc = true; invoice.HeaderDocDate = claim.DocDate; invoice.FinPeriodID = claim.FinPeriodID; invoice.InvoiceNbr = claim.RefNbr; invoice.DocDesc = claim.DocDesc; invoice.ContragentID = claim.EmployeeID; invoice.CuryID = info.CuryID; invoice.ContragentLocationID = claim.LocationID; invoice.ModuleAccountID = emplocation != null ? emplocation.APAccountID : null; invoice.ModuleSubID = emplocation != null ? emplocation.APSubID : null; invoice.TaxCalcMode = receiptGroup.Any() ? receiptGroup.First().TaxCalcMode: claim.TaxCalcMode; invoice.BranchID = claim.BranchID; invoice.OrigModule = BatchModule.EP; if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardCompanyExpense && receiptGroup.Count == 1) { invoice.OrigDocType = EPExpenseClaimDetails.DocType; invoice.OrigRefNbr = receiptGroup.Single().ClaimDetailCD; } else { invoice.OrigDocType = EPExpenseClaim.DocType; invoice.OrigRefNbr = claim.RefNbr; } bool reversedDocument = invoice.DocType == APInvoiceType.DebitAdj && receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.PersonalAccount; decimal signOperation = reversedDocument ? -1 : 1; invoice = apDocumentGraphExtension.Documents.Insert(invoice); (apDocumentGraphExtension.Documents.Cache as PXModelExtension <TAPDocument>)?.UpdateExtensionMapping(invoice, MappingSyncDirection.BaseToExtension); invoice.TaxZoneID = receiptGroup.Any() ? receiptGroup.First().TaxZoneID : claim.TaxZoneID; invoice = apDocumentGraphExtension.Documents.Update(invoice); PXCache <CurrencyInfo> .RestoreCopy(info, infoOriginal); info.CuryInfoID = invoice.CuryInfoID; PXCache claimcache = docgraph.Caches[typeof(EPExpenseClaim)]; PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)]; PXNoteAttribute.CopyNoteAndFiles(claimcache, claim, apDocumentGraphExtension.Documents.Cache, invoice, epsetup.GetCopyNoteSettings <PXModule.ap>()); #endregion TaxAttribute.SetTaxCalc <InvoiceTran.taxCategoryID>(apDocumentGraphExtension.InvoiceTrans.Cache, null, TaxCalc.ManualCalc); decimal?claimCuryTaxRoundDiff = 0m; decimal?claimTaxRoundDiff = 0m; foreach (EPExpenseClaimDetails claimdetail in receiptGroup) { #region AddDetails decimal tipQty; if (reversedDocument == claimdetail.ClaimCuryTranAmtWithTaxes < 0) { tipQty = 1; } else { tipQty = -1; } Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <EPExpenseClaimDetails.contractID> > > > .SelectSingleBound(docgraph, null, claimdetail.ContractID); if (claimdetail.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseClaimGraph, claimdetail.TaskID); if (task != null && !(bool)task.VisibleInAP) { throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP); } } InvoiceTran tran = new InvoiceTran(); tran.InventoryID = claimdetail.InventoryID; tran.TranDesc = claimdetail.TranDesc; decimal unitCost; decimal amount; decimal taxableAmt; decimal taxAmt; if (CurrencyHelper.IsSameCury(expenseClaimGraph, claimdetail.CuryInfoID, claimdetail.ClaimCuryInfoID)) { unitCost = claimdetail.CuryUnitCost ?? 0m; amount = claimdetail.CuryTaxableAmt ?? 0m; taxableAmt = claimdetail.CuryTaxableAmtFromTax ?? 0m; taxAmt = claimdetail.CuryTaxAmt ?? 0m; } else { if (claimdetail.CuryUnitCost == null || claimdetail.CuryUnitCost == 0m) { unitCost = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.UnitCost, out unitCost); } if (claimdetail.CuryTaxableAmt == null || claimdetail.CuryTaxableAmt == 0m) { amount = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxableAmt, out amount); } if (claimdetail.CuryTaxableAmtFromTax == null || claimdetail.CuryTaxableAmtFromTax == 0m) { taxableAmt = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxableAmtFromTax, out taxableAmt); } if (claimdetail.CuryTaxAmt == null || claimdetail.CuryTaxAmt == 0m) { taxAmt = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxAmt, out taxAmt); } } tran.ManualPrice = true; tran.CuryUnitCost = unitCost; tran.Qty = claimdetail.Qty * signOperation; tran.UOM = claimdetail.UOM; tran.NonBillable = claimdetail.Billable != true; claimCuryTaxRoundDiff += (claimdetail.ClaimCuryTaxRoundDiff ?? 0m) * signOperation; claimTaxRoundDiff += (claimdetail.ClaimTaxRoundDiff ?? 0m) * signOperation; tran.Date = claimdetail.ExpenseDate; if (contract.BaseType == CT.CTPRType.Project) { tran.ProjectID = claimdetail.ContractID; } else { tran.ProjectID = ProjectDefaultAttribute.NonProject(); } tran.TaskID = claimdetail.TaskID; tran.CostCodeID = claimdetail.CostCodeID; if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardPersonalExpense) { CACorpCard card = CACorpCard.PKID.Find(this, claimdetail.CorpCardID); CashAccount cashAccount = CashAccount.PK.Find(this, card.CashAccountID); tran.AccountID = cashAccount.AccountID; tran.SubID = cashAccount.SubID; } else { tran.AccountID = claimdetail.ExpenseAccountID; tran.SubID = claimdetail.ExpenseSubID; } tran.BranchID = claimdetail.BranchID; tran = InsertInvoiceTransaction(apDocumentGraphExtension.InvoiceTrans.Cache, tran, new InvoiceTranContext { EPClaim = claim, EPClaimDetails = claimdetail }); if (claimdetail.PaidWith == EPExpenseClaimDetails.paidWith.CardPersonalExpense) { claimdetail.APLineNbr = tran.LineNbr; } tran.CuryLineAmt = amount * signOperation; tran.CuryTaxAmt = 0; tran.CuryTaxableAmt = taxableAmt * signOperation; tran.CuryTaxAmt = taxAmt * signOperation; tran.TaxCategoryID = claimdetail.TaxCategoryID; tran = UpdateInvoiceTransaction(apDocumentGraphExtension.InvoiceTrans.Cache, tran, new InvoiceTranContext { EPClaim = claim, EPClaimDetails = claimdetail }); if ((claimdetail.CuryTipAmt ?? 0) != 0) { InvoiceTran tranTip = new InvoiceTran(); if (epsetup.NonTaxableTipItem == null) { throw new PXException(Messages.TipItemIsNotDefined); } IN.InventoryItem tipItem = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(docgraph, epsetup.NonTaxableTipItem); if (tipItem == null) { string fieldname = PXUIFieldAttribute.GetDisplayName <EPSetup.nonTaxableTipItem>(docgraph.Caches[typeof(EPSetup)]); throw new PXException(ErrorMessages.ValueDoesntExistOrNoRights, fieldname, epsetup.NonTaxableTipItem); } tranTip.InventoryID = epsetup.NonTaxableTipItem; tranTip.TranDesc = tipItem.Descr; if (CurrencyHelper.IsSameCury(expenseClaimGraph, claimdetail.CuryInfoID, claimdetail.ClaimCuryInfoID)) { tranTip.CuryUnitCost = Math.Abs(claimdetail.CuryTipAmt ?? 0m); tranTip.CuryTranAmt = claimdetail.CuryTipAmt * signOperation; } else { decimal tipAmt; PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TipAmt, out tipAmt); tranTip.CuryUnitCost = Math.Abs(tipAmt); tranTip.CuryTranAmt = tipAmt * signOperation; } tranTip.Qty = tipQty; tranTip.UOM = tipItem.BaseUnit; tranTip.NonBillable = claimdetail.Billable != true; tranTip.Date = claimdetail.ExpenseDate; tranTip.BranchID = claimdetail.BranchID; tranTip = InsertInvoiceTipTransaction(apDocumentGraphExtension.InvoiceTrans.Cache, tranTip, new InvoiceTranContext { EPClaim = claim, EPClaimDetails = claimdetail }); if (epsetup.UseReceiptAccountForTips == true) { tranTip.AccountID = claimdetail.ExpenseAccountID; tranTip.SubID = claimdetail.ExpenseSubID; } else { tranTip.AccountID = tipItem.COGSAcctID; Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <APInvoice.branchID> > > > .Select(docgraph); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(docgraph, claimdetail.ContractID, claimdetail.TaskID); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(claimdetailcache, claimdetail); int?employee_SubID = (int?)docgraph.Caches[typeof(EPEmployee)].GetValue <EPEmployee.expenseSubID>(employee); int?item_SubID = (int?)docgraph.Caches[typeof(IN.InventoryItem)].GetValue <IN.InventoryItem.cOGSSubID>(tipItem); int?company_SubID = (int?)docgraph.Caches[typeof(Location)].GetValue <Location.cMPExpenseSubID>(companyloc); int?project_SubID = (int?)docgraph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)docgraph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)docgraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); object value = SubAccountMaskAttribute.MakeSub <EPSetup.expenseSubMask>(docgraph, epsetup.ExpenseSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.expenseSubID), typeof(IN.InventoryItem.cOGSSubID), typeof(Location.cMPExpenseSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); docgraph.Caches[typeof(APTran)].RaiseFieldUpdating <APTran.subID>(tranTip, ref value); tranTip.SubID = (int?)value; } tranTip = UpdateInvoiceTipTransactionAccounts(apDocumentGraphExtension.InvoiceTrans.Cache, tranTip, new InvoiceTranContext { EPClaim = claim, EPClaimDetails = claimdetail }); tranTip.TaxCategoryID = tipItem.TaxCategoryID; tranTip.ProjectID = tran.ProjectID; tranTip.TaskID = tran.TaskID; tranTip = AddTaxes <TAPDocument, TInvoiceMapping, TGraph, TAPDocumentGraphExtension>(apDocumentGraphExtension, docgraph, expenseClaimGraph, invoice, signOperation, claimdetail, tranTip, true); tranTip = UpdateInvoiceTipTransactionTaxesAndProject(apDocumentGraphExtension.InvoiceTrans.Cache, tranTip, new InvoiceTranContext { EPClaim = claim, EPClaimDetails = claimdetail }); } PXNoteAttribute.CopyNoteAndFiles(claimdetailcache, claimdetail, apDocumentGraphExtension.InvoiceTrans.Cache, tran, epsetup.GetCopyNoteSettings <PXModule.ap>()); claimdetail.Released = true; expenseClaimGraph.ExpenseClaimDetails.Update(claimdetail); #endregion if (receiptGroupPaidWithType != EPExpenseClaimDetails.paidWith.CardPersonalExpense) { tran = AddTaxes <TAPDocument, TInvoiceMapping, TGraph, TAPDocumentGraphExtension>(apDocumentGraphExtension, docgraph, expenseClaimGraph, invoice, signOperation, claimdetail, tran, false); } } #region legacy taxes foreach (EPTaxAggregate tax in PXSelectReadonly <EPTaxAggregate, Where <EPTaxAggregate.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr)) { #region Add taxes GenericTaxTran new_aptax = apDocumentGraphExtension.TaxTrans.Search <GenericTaxTran.taxID>(tax.TaxID); if (new_aptax == null) { new_aptax = new GenericTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = apDocumentGraphExtension.TaxTrans.Insert(new_aptax); if (new_aptax != null) { new_aptax = (GenericTaxTran)apDocumentGraphExtension.TaxTrans.Cache.CreateCopy(new_aptax); new_aptax.CuryTaxableAmt = 0m; new_aptax.CuryTaxAmt = 0m; new_aptax.CuryExpenseAmt = 0m; new_aptax = apDocumentGraphExtension.TaxTrans.Update(new_aptax); } } if (new_aptax != null) { new_aptax = (GenericTaxTran)apDocumentGraphExtension.TaxTrans.Cache.CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = (new_aptax.CuryTaxableAmt ?? 0m) + tax.CuryTaxableAmt * signOperation; new_aptax.CuryTaxAmt = (new_aptax.CuryTaxAmt ?? 0m) + tax.CuryTaxAmt * signOperation; new_aptax.CuryExpenseAmt = (new_aptax.CuryExpenseAmt ?? 0m) + tax.CuryExpenseAmt * signOperation; new_aptax = apDocumentGraphExtension.TaxTrans.Update(new_aptax); } #endregion } #endregion invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoice.CuryTaxAmt = invoice.CuryTaxTotal; invoice.Hold = false; apDocumentGraphExtension.SuppressApproval(); apDocumentGraphExtension.Documents.Update(invoice); if (receiptGroupPaidWithType != EPExpenseClaimDetails.paidWith.CardPersonalExpense) { invoice.CuryTaxRoundDiff = invoice.CuryRoundDiff = invoice.CuryRoundDiff = claimCuryTaxRoundDiff; invoice.TaxRoundDiff = invoice.RoundDiff = claimTaxRoundDiff; bool inclusive = PXSelectJoin <APTaxTran, InnerJoin <Tax, On <APTaxTran.taxID, Equal <Tax.taxID> > >, Where <APTaxTran.refNbr, Equal <Required <APInvoice.refNbr> >, And <APTaxTran.tranType, Equal <Required <APInvoice.docType> >, And <Tax.taxCalcLevel, Equal <CSTaxCalcLevel.inclusive> > > > > .Select(docgraph, invoice.RefNbr, invoice.DocType).Count > 0; if ((invoice.TaxCalcMode == TaxCalculationMode.Gross && PXSelectJoin <APTaxTran, InnerJoin <Tax, On <APTaxTran.taxID, Equal <Tax.taxID> > >, Where <APTaxTran.refNbr, Equal <Required <APInvoice.refNbr> >, And <APTaxTran.tranType, Equal <Required <APInvoice.docType> >, And <Tax.taxCalcLevel, Equal <CSTaxCalcLevel.calcOnItemAmt> > > > > .Select(docgraph, invoice.RefNbr, invoice.DocType).Count > 0) || inclusive) { decimal curyAdditionalDiff = -(invoice.CuryTaxRoundDiff ?? 0m) + (invoice.CuryTaxAmt ?? 0m) - (invoice.CuryDocBal ?? 0m); decimal additionalDiff = -(invoice.TaxRoundDiff ?? 0m) + (invoice.TaxAmt ?? 0m) - (invoice.DocBal ?? 0m); foreach (InvoiceTran line in apDocumentGraphExtension.InvoiceTrans.Select()) { curyAdditionalDiff += (line.CuryTaxableAmt ?? 0m) == 0m ? (line.CuryTranAmt ?? 0m) : (line.CuryTaxableAmt ?? 0m); additionalDiff += (line.TaxableAmt ?? 0m) == 0m ? (line.TranAmt ?? 0m) : (line.TaxableAmt ?? 0m); } invoice.CuryTaxRoundDiff += curyAdditionalDiff; invoice.TaxRoundDiff += additionalDiff; } } invoice = apDocumentGraphExtension.Documents.Update(invoice); docgraph.Actions.PressSave(); if (receiptGroupPaidWithType == EPExpenseClaimDetails.paidWith.CardCompanyExpense && receiptGroup.Count == 1 && bankTranMatch != null) { CABankTransactionsMaint.RematchFromExpenseReceipt(this, bankTranMatch, invoice.CATranID, invoice.ContragentID, receiptGroup.Single()); } foreach (EPExpenseClaimDetails claimdetail in receiptGroup) { claimdetail.APDocType = invoice.DocType; claimdetail.APRefNbr = invoice.RefNbr; expenseClaimGraph.ExpenseClaimDetails.Update(claimdetail); } claim.Status = EPExpenseClaimStatus.ReleasedStatus; claim.Released = true; expenseClaimGraph.ExpenseClaim.Update(claim); #region EP History Update EPHistory hist = new EPHistory(); hist.EmployeeID = invoice.ContragentID; hist.FinPeriodID = invoice.FinPeriodID; hist = (EPHistory)expenseClaimGraph.Caches[typeof(EPHistory)].Insert(hist); hist.FinPtdClaimed += invoice.DocBal; hist.FinYtdClaimed += invoice.DocBal; if (invoice.FinPeriodID == invoice.HeaderTranPeriodID) { hist.TranPtdClaimed += invoice.DocBal; hist.TranYtdClaimed += invoice.DocBal; } else { EPHistory tranhist = new EPHistory(); tranhist.EmployeeID = invoice.ContragentID; tranhist.FinPeriodID = invoice.HeaderTranPeriodID; tranhist = (EPHistory)expenseClaimGraph.Caches[typeof(EPHistory)].Insert(tranhist); tranhist.TranPtdClaimed += invoice.DocBal; tranhist.TranYtdClaimed += invoice.DocBal; } expenseClaimGraph.Views.Caches.Add(typeof(EPHistory)); #endregion expenseClaimGraph.Save.Press(); Actions.PressSave(); doclist.Add((APRegister)apDocumentGraphExtension.Documents.Current.Base); } return(doclist); }
protected virtual void EPExpenseClaimDetails_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EPExpenseClaimDetails row = (EPExpenseClaimDetails)e.Row; if (row != null) { EPExpenseClaim claim = (EPExpenseClaim)PXSelect <EPExpenseClaim, Where <EPExpenseClaim.refNbr, Equal <Required <EPExpenseClaimDetails.refNbr> > > > .SelectSingleBound(this, new object[] { null }, row.RefNbr); bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null; bool legacyClaim = row.LegacyReceipt == true && !String.IsNullOrEmpty(row.RefNbr); bool enabledEditReceipt = (row.Hold == true || !enabledApprovalReceipt) && !legacyClaim; bool enabledRefNbr = true; bool enabledEmployeeAndBranch = enabledEditReceipt && !(row.ClaimCuryInfoID == null && cache.AllowUpdate && !string.IsNullOrEmpty(row.RefNbr)); bool enabledFinancialDetails = (row.Rejected != true) && (row.Released != true); bool NonProject = (CurrentContract.SelectSingle()?.ContractCD ?? PMSetup.DefaultNonProjectCode).Trim() == PMSetup.DefaultNonProjectCode; bool claimReleased = false; if (claim != null) { bool enabledEditClaim = (row.HoldClaim == true); enabledEditReceipt = enabledEditReceipt && enabledEditClaim; enabledRefNbr = enabledEditClaim; enabledEmployeeAndBranch = false; enabledFinancialDetails = enabledFinancialDetails && enabledEditClaim; claimReleased = claim.Released == true; } enabledRefNbr = enabledRefNbr && row.LegacyReceipt == false; Approval.AllowSelect = enabledApprovalReceipt; Delete.SetEnabled(enabledEditReceipt && claim == null); PXUIFieldAttribute.SetEnabled(cache, row, enabledEditReceipt); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.claimDetailID>(cache, row, true); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.refNbr>(cache, row, enabledRefNbr); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.employeeID>(cache, row, enabledEmployeeAndBranch); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.branchID>(cache, row, enabledEmployeeAndBranch); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseAccountID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseSubID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesAccountID>(cache, row, enabledFinancialDetails && (row.Billable == true)); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesSubID>(cache, row, enabledFinancialDetails && (row.Billable == true)); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCategoryID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.customerID>(cache, row, NonProject && !claimReleased); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.customerLocationID>(cache, row, NonProject && !claimReleased); action.SetEnabled("Submit", cache.GetStatus(row) != PXEntryStatus.Inserted && row.Hold == true); if (row.ContractID != null && (bool)row.Billable && row.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(this, row.TaskID); if (task != null && !(bool)task.VisibleInAP) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>(e.Row, task.TaskCD, new PXSetPropertyException(PM.Messages.TaskInvisibleInModule, task.TaskCD, GL.BatchModule.AP)); } } CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Current <EPExpenseClaimDetails.curyInfoID> > > > .SelectSingleBound(this, new object[] { row }); if (info != null && info.CuryRateTypeID != null && info.CuryEffDate != null && row.ExpenseDate != null && info.CuryEffDate < row.ExpenseDate) { CurrencyRateType ratetype = (CurrencyRateType)PXSelectorAttribute.Select <CurrencyInfo.curyRateTypeID>(currencyinfo.Cache, info); if (ratetype != null && ratetype.RateEffDays > 0 && ((TimeSpan)(row.ExpenseDate - info.CuryEffDate)).Days > ratetype.RateEffDays) { PXRateIsNotDefinedForThisDateException exc = new PXRateIsNotDefinedForThisDateException(info.CuryRateTypeID, info.BaseCuryID, info.CuryID, (DateTime)row.ExpenseDate); cache.RaiseExceptionHandling <EPExpenseClaimDetails.expenseDate>(e.Row, ((EPExpenseClaimDetails)e.Row).ExpenseDate, exc); } } string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyID>(currencyinfo.Cache, info); if (string.IsNullOrEmpty(message) && info != null && info.CuryRate == null) { message = CM.Messages.RateNotFound; } if (string.IsNullOrEmpty(message)) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, null); } else { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, new PXSetPropertyException(message, PXErrorLevel.Warning)); } bool allowEdit = this.Accessinfo.UserID == row.CreatedByID; if (Employee.Current != null) { if (!allowEdit && this.Accessinfo.UserID == Employee.Current.UserID) { allowEdit = true; } if (!allowEdit) { EPWingman wingMan = PXSelectJoin <EPWingman, InnerJoin <EPEmployee, On <EPWingman.wingmanID, Equal <EPEmployee.bAccountID> > >, Where <EPWingman.employeeID, Equal <Required <EPWingman.employeeID> >, And <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > > .Select(this, row.EmployeeID, Accessinfo.UserID); if (wingMan != null) { allowEdit = true; } } } //Another conditions in automation steps if (!allowEdit) { action.SetEnabled(MsgNotLocalizable.PutOnHold, false); } bool taxSettingsEnabled = enabledEditReceipt && (epsetup.Current.AllowMixedTaxSettingInClaims == true || CurrentClaimDetails.Current.RefNbr == null); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxZoneID>(cache, row, taxSettingsEnabled); ValidateProjectAndProjectTask(row); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCalcMode>(cache, row, taxSettingsEnabled); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCategoryID>(cache, row, enabledEditReceipt); PXUIFieldAttribute.SetVisible <EPExpenseClaimDetails.curyTipAmt>(ClaimDetails.Cache, null, epsetup.Current.NonTaxableTipItem.HasValue || (row.CuryTipAmt ?? 0) != 0); Taxes.Cache.SetAllEditPermissions(enabledEditReceipt); RaiseOrHideError <EPExpenseClaimDetails.refNbr>(cache, row, legacyClaim && row.Released == false, Messages.LegacyClaim, PXErrorLevel.Warning, row.RefNbr); RaiseOrHideError <EPExpenseClaimDetails.claimDetailID>(cache, row, row.LegacyReceipt == true && row.Released == false && !String.IsNullOrEmpty(row.TaxZoneID), Messages.LegacyReceipt, PXErrorLevel.Warning); EPEmployee employeeRow = Employee.Select(); string taxZoneID = EPClaimReceiptController.GetTaxZoneID(this, employeeRow); bool notMatchtaxZone = String.IsNullOrEmpty(row.TaxZoneID) && !String.IsNullOrEmpty(taxZoneID); RaiseOrHideError <EPExpenseClaimDetails.taxZoneID>(cache, row, notMatchtaxZone && row.Released == false, Messages.TaxZoneEmpty, PXErrorLevel.Warning); if (UseTaxes.Select().Count != 0) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyTaxTotal>(row, row.CuryTaxTotal, new PXSetPropertyException(TX.Messages.UseTaxExcludedFromTotals, PXErrorLevel.Warning)); } else { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyTaxTotal>(row, row.CuryTaxTotal, null); } } }
///NO CRM Mode public static PMTran CreateContractUsage(RegisterEntry graph, int?contractID, PMTimeActivity timeActivity, int billableMinutes) { if (timeActivity.ApprovalStatus == ActivityStatusListAttribute.Canceled) { return(null); } if (timeActivity.IsBillable != true) { return(null); } Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(graph, contractID); if (contract == null) { return(null); //activity has no contract and will be billed through Project using the cost-transaction. Contract-Usage is not created in this case. } int?laborItemID = GetContractLaborClassID(graph, contractID, timeActivity);; if (laborItemID == null) { EPEmployee employeeSettings = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, timeActivity.OwnerID); if (employeeSettings != null) { laborItemID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employeeSettings.BAccountID, timeActivity.EarningTypeID) ?? employeeSettings.LabourItemID; } } InventoryItem laborItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(graph, laborItemID); if (laborItem == null) { throw new PXException(PX.Objects.CR.Messages.LaborNotConfigured); } //save the sign of the value and do the rounding against absolute value. //reuse sign later when setting value to resulting transaction. int sign = billableMinutes < 0 ? -1 : 1; billableMinutes = Math.Abs(billableMinutes); if (billableMinutes > 0) { PMTran newLabourTran = new PMTran(); newLabourTran.ProjectID = contractID; newLabourTran.InventoryID = laborItem.InventoryID; newLabourTran.AccountGroupID = contract.ContractAccountGroup; newLabourTran.OrigRefID = timeActivity.NoteID; newLabourTran.BAccountID = contract.CustomerID; newLabourTran.LocationID = contract.LocationID; newLabourTran.Description = timeActivity.Summary; newLabourTran.StartDate = timeActivity.Date; newLabourTran.EndDate = timeActivity.Date; newLabourTran.Date = timeActivity.Date; newLabourTran.UOM = laborItem.SalesUnit; newLabourTran.Qty = sign * Convert.ToDecimal(TimeSpan.FromMinutes(billableMinutes).TotalHours); newLabourTran.BillableQty = newLabourTran.Qty; newLabourTran.Released = true; newLabourTran.Allocated = true; newLabourTran.IsQtyOnly = true; newLabourTran.BillingID = contract.BillingID; return(graph.Transactions.Insert(newLabourTran)); } else { return(null); } }
public static bool RecordCostTrans(RegisterEntry registerEntry, List <EPActivityApprove> activities, out bool activityAdded) { registerEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); //restriction should be applicable only for budgeting. EmployeeCostEngine costEngine = new EmployeeCostEngine(registerEntry); registerEntry.Views.Caches.Add(typeof(EPActivityApprove)); PXCache activityCache = registerEntry.Caches <EPActivityApprove>(); registerEntry.Document.Cache.Insert(); bool success = true; activityAdded = false; for (int i = 0; i < activities.Count; i++) { //Check the UNMERGED state of Released (it could be set to true just now by the calling code): EPActivityApprove activity = PXSelect <EPActivityApprove> .Search <EPActivityApprove.noteID>(registerEntry, activities[i].NoteID); if (activity.Released == true) //activity can be released to PM via Timecard prior to releasing the case. { continue; } try { if (activity.ProjectTaskID != null) //cost transactions are created only if project is set. { EPEmployee employee = PXSelect <EPEmployee> .Search <EPEmployee.userID>(registerEntry, activity.OwnerID); activity.LabourItemID = costEngine.GetLaborClass(activity); if (activity.LabourItemID == null) { throw new PXException(Messages.CannotFindLabor, employee.AcctName); } activityCache.Update(activity); var cost = costEngine.CalculateEmployeeCost(activity.TimeCardCD, activity.EarningTypeID, activity.LabourItemID, activity.ProjectID, activity.ProjectTaskID, activity.CertifiedJob, activity.UnionID, employee.BAccountID, activity.Date.Value); if (cost == null) { throw new PXException(Messages.EmployeeCostRateNotFound); } EPSetup epsetup = PXSelect <EPSetup> .Select(registerEntry); if (epsetup.PostingOption != EPPostOptions.DoNotPost) { registerEntry.CreateTransaction(activity, employee.BAccountID, activity.Date.Value, activity.TimeSpent, activity.TimeBillable, cost.Rate, cost.OvertimeMultiplier); } activity.EmployeeRate = cost.Rate; activityAdded = true; } activity.Released = true; activity.ApprovalStatus = ActivityStatusAttribute.Released; if (activity.RefNoteID != null) { PXUpdate < Set <CRActivity.isLocked, True>, CRActivity, Where <CRActivity.noteID, Equal <Required <CRActivity.noteID> > > > .Update(registerEntry, activity.RefNoteID); } activityCache.Update(activity); } catch (Exception e) { PXProcessing <EPActivityApprove> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message); success = false; } } if (activityAdded) { registerEntry.Save.Press(); } else { activityCache.Persist(PXDBOperation.Update); registerEntry.SelectTimeStamp(); } return(success); }
private static void ClaimDetail(List <EPExpenseClaimDetails> details, bool isApiContext, bool singleOperation) { ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>(); PXSetup <EPSetup> epsetup = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry))); bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null; bool isError = false; bool notAllApproved = false; Dictionary <string, EPExpenseClaim> result = new Dictionary <string, EPExpenseClaim>(); IEnumerable <Receipts> List; if (epsetup.Current.AllowMixedTaxSettingInClaims == true) { List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy( item => new { item.EmployeeID, item.BranchID, item.CustomerID, item.CustomerLocationID, ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item) }, (key, item) => new Receipts { employee = key.EmployeeID, branch = key.BranchID, customer = key.CustomerID, customerLocation = key.CustomerLocationID, claimCuryID = key.ClaimCuryID, details = item } ); } else { List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy( item => new { item.EmployeeID, item.BranchID, item.CustomerID, item.CustomerLocationID, item.TaxZoneID, item.TaxCalcMode, ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item) }, (key, item) => new Receipts { employee = key.EmployeeID, branch = key.BranchID, customer = key.CustomerID, customerLocation = key.CustomerLocationID, claimCuryID = key.ClaimCuryID, details = item } ); } string errorMessage = null; foreach (Receipts item in List) { isError = false; notAllApproved = false; using (PXTransactionScope ts = new PXTransactionScope()) { expenseClaimEntry.Clear(); expenseClaimEntry.SelectTimeStamp(); EPExpenseClaim expenseClaim = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance(); expenseClaim.EmployeeID = item.employee; expenseClaim.BranchID = item.branch; expenseClaim.CustomerID = item.customer; expenseClaim.DocDesc = EP.Messages.SubmittedReceipt; expenseClaim = expenseClaimEntry.ExpenseClaim.Update(expenseClaim); expenseClaim.CuryID = item.claimCuryID; expenseClaim = expenseClaimEntry.ExpenseClaim.Update(expenseClaim); expenseClaim.CustomerLocationID = item.customerLocation; expenseClaim.TaxCalcMode = item.details.First().TaxCalcMode; expenseClaim.TaxZoneID = item.details.First().TaxZoneID; foreach (EPExpenseClaimDetails detail in item.details) { PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail); if (detail.Approved ?? false) { try { if (detail.IsPaidWithCard) { EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > .Select(expenseClaimEntry, item.employee); if (employee.AllowOverrideCury != true && detail.CardCuryID != employee.CuryID) { errorMessage = PXMessages.Localize(Messages.ClaimCannotBeCreatedForReceiptBecauseCuryCannotBeOverriden); isError = true; } } if (!isError && detail.TipAmt != 0 && epsetup.Current.NonTaxableTipItem == null) { errorMessage = Messages.TipItemIsNotDefined; isError = true; } if (!isError) { expenseClaimEntry.ReceiptEntryExt.SubmitReceiptExt(expenseClaimEntry.ExpenseClaim.Cache, expenseClaimEntry.ExpenseClaimDetails.Cache, expenseClaimEntry.ExpenseClaim.Current, detail); expenseClaimEntry.Save.Press(); if (!result.ContainsKey(expenseClaim.RefNbr)) { result.Add(expenseClaim.RefNbr, expenseClaim); } detail.RefNbr = expenseClaim.RefNbr; PXProcessing <EPExpenseClaimDetails> .SetProcessed(); } } catch (Exception ex) { errorMessage = ex.Message; isError = true; } } else { errorMessage = enabledApprovalReceipt ? Messages.ReceiptNotApproved : Messages.ReceiptTakenOffHold; notAllApproved = true; } if (errorMessage != null) { PXProcessing <EPExpenseClaimDetails> .SetError(errorMessage); } } if (!isError) { ts.Complete(); } } } if (!isError && !notAllApproved) { if (result.Count == 1 && isApiContext == false) { expenseClaimEntry = CreateInstance <ExpenseClaimEntry>(); PXRedirectHelper.TryRedirect(expenseClaimEntry, result.First().Value, PXRedirectHelper.WindowMode.InlineWindow); } } else { PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null); if (singleOperation) { throw new PXException(errorMessage); } else { throw new PXException(Messages.ErrorProcessingReceipts); } } }
protected void FindOwner(PXGraph graph, IAssign source, out Contact contact, out Users user, out EPEmployee employee) { contact = null; user = null; employee = null; if (source == null || source.OwnerID == null) { return; } FindOwner(graph, source.OwnerID, out contact, out user, out employee); }
public static void ReleaseDoc(EPExpenseClaim claim) { #region prepare required variables APInvoiceEntry docgraph = PXGraph.CreateInstance <APInvoiceEntry>(); ExpenseClaimEntry expenseClaimGraph = PXGraph.CreateInstance <ExpenseClaimEntry>(); var receipts = PXSelect <EPExpenseClaimDetails, Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(expenseClaimGraph, claim.RefNbr).Select( result => (EPExpenseClaimDetails)result).GroupBy( item => Tuple.Create( item.TaxZoneID, item.TaxCalcMode )).ToDictionary(x => x.Key, group => group.ToList()); if (receipts.Count() == 0) { receipts.Add(Tuple.Create(claim.TaxZoneID, claim.TaxCalcMode), new List <EPExpenseClaimDetails>()); } EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph); APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph); EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID); Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID); List <APRegister> doclist = new List <APRegister>(); expenseClaimGraph.SelectTimeStamp(); #endregion using (PXTransactionScope ts = new PXTransactionScope()) { foreach (var res in receipts) { docgraph.Clear(PXClearOption.ClearAll); docgraph.SelectTimeStamp(); docgraph.vendor.Current = employee; docgraph.location.Current = emplocation; CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID); CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal); info.CuryInfoID = null; info = docgraph.currencyinfo.Insert(info); #region CreateInoiceHeader APInvoice invoice = new APInvoice(); bool reversedDocument = false; if (res.Value.Sum(_ => _.ClaimCuryTranAmtWithTaxes) < 0) { invoice.DocType = APInvoiceType.DebitAdj; reversedDocument = true; } else { invoice.DocType = APInvoiceType.Invoice; } decimal signOperation; if (reversedDocument) { signOperation = -1; } else { signOperation = 1; } invoice.CuryInfoID = info.CuryInfoID; invoice.Hold = true; invoice.Released = false; invoice.Printed = false; invoice.OpenDoc = true; invoice.DocDate = claim.DocDate; invoice.FinPeriodID = claim.FinPeriodID; invoice.InvoiceNbr = claim.RefNbr; invoice.DocDesc = claim.DocDesc; invoice.VendorID = claim.EmployeeID; invoice.CuryID = info.CuryID; invoice.VendorLocationID = claim.LocationID; invoice.APAccountID = emplocation != null ? emplocation.APAccountID : null; invoice.APSubID = emplocation != null ? emplocation.APSubID : null; invoice.TaxZoneID = res.Key.Item1; invoice.TaxCalcMode = res.Key.Item2; invoice.BranchID = claim.BranchID; invoice.OrigModule = BatchModule.EP; invoice.OrigRefNbr = claim.RefNbr; invoice = docgraph.Document.Insert(invoice); PXCache <CurrencyInfo> .RestoreCopy(info, infoOriginal); info.CuryInfoID = invoice.CuryInfoID; PXCache claimcache = docgraph.Caches[typeof(EPExpenseClaim)]; PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)]; PXNoteAttribute.CopyNoteAndFiles(claimcache, claim, docgraph.Document.Cache, invoice, epsetup.GetCopyNoteSettings <PXModule.ap>()); #endregion TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); decimal?claimCuryTaxRoundDiff = 0m; decimal?claimTaxRoundDiff = 0m; foreach (EPExpenseClaimDetails claimdetail in res.Value) { #region AddDetails decimal tipQty; if (reversedDocument == claimdetail.ClaimCuryTranAmtWithTaxes < 0) { tipQty = 1; } else { tipQty = -1; } Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <EPExpenseClaimDetails.contractID> > > > .SelectSingleBound(docgraph, null, claimdetail.ContractID); if (claimdetail.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseClaimGraph, claimdetail.TaskID); if (task != null && !(bool)task.VisibleInAP) { throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP); } } APTran tran = new APTran(); tran.InventoryID = claimdetail.InventoryID; tran.TranDesc = claimdetail.TranDesc; decimal unitCost; decimal amount; decimal taxableAmt; decimal taxAmt; if (EPClaimReceiptController.IsSameCury(expenseClaimGraph, claimdetail.CuryInfoID, claimdetail.ClaimCuryInfoID)) { unitCost = claimdetail.CuryUnitCost ?? 0m; amount = claimdetail.CuryTaxableAmt ?? 0m; taxableAmt = claimdetail.CuryTaxableAmtFromTax ?? 0m; taxAmt = claimdetail.CuryTaxAmt ?? 0m; } else { if (claimdetail.CuryUnitCost == null || claimdetail.CuryUnitCost == 0m) { unitCost = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.UnitCost, out unitCost); } if (claimdetail.CuryTaxableAmt == null || claimdetail.CuryTaxableAmt == 0m) { amount = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxableAmt, out amount); } if (claimdetail.CuryTaxableAmtFromTax == null || claimdetail.CuryTaxableAmtFromTax == 0m) { taxableAmt = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxableAmtFromTax, out taxableAmt); } if (claimdetail.CuryTaxAmt == null || claimdetail.CuryTaxAmt == 0m) { taxAmt = 0m; } else { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TaxAmt, out taxAmt); } } tran.ManualPrice = true; tran.CuryUnitCost = unitCost; tran.Qty = claimdetail.Qty * signOperation; tran.UOM = claimdetail.UOM; tran.NonBillable = claimdetail.Billable != true; claimCuryTaxRoundDiff += (claimdetail.ClaimCuryTaxRoundDiff ?? 0m) * signOperation; claimTaxRoundDiff += (claimdetail.ClaimTaxRoundDiff ?? 0m) * signOperation; tran.Date = claimdetail.ExpenseDate; if (contract.BaseType == PMProject.ProjectBaseType.Project) { tran.ProjectID = claimdetail.ContractID; } else { tran.ProjectID = ProjectDefaultAttribute.NonProject(); } tran.TaskID = claimdetail.TaskID; tran.CostCodeID = claimdetail.CostCodeID; tran.AccountID = claimdetail.ExpenseAccountID; tran.SubID = claimdetail.ExpenseSubID; tran.TaxCategoryID = claimdetail.TaxCategoryID; tran.BranchID = claimdetail.BranchID; tran = docgraph.Transactions.Insert(tran); tran.CuryLineAmt = amount * signOperation; tran.CuryTaxAmt = 0; tran.CuryTaxableAmt = taxableAmt * signOperation; tran.CuryTaxAmt = taxAmt * signOperation; tran = docgraph.Transactions.Update(tran); if ((claimdetail.CuryTipAmt ?? 0) != 0) { APTran tranTip = new APTran(); if (epsetup.NonTaxableTipItem == null) { throw new PXException(Messages.TipItemIsNotDefined); } IN.InventoryItem tipItem = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(docgraph, epsetup.NonTaxableTipItem); if (tipItem == null) { string fieldname = PXUIFieldAttribute.GetDisplayName <EPSetup.nonTaxableTipItem>(docgraph.Caches[typeof(EPSetup)]); throw new PXException(ErrorMessages.ValueDoesntExistOrNoRights, fieldname, epsetup.NonTaxableTipItem); } tranTip.InventoryID = epsetup.NonTaxableTipItem; tranTip.TranDesc = tipItem.Descr; if (EPClaimReceiptController.IsSameCury(expenseClaimGraph, claimdetail.CuryInfoID, claimdetail.ClaimCuryInfoID)) { tranTip.CuryUnitCost = Math.Abs(claimdetail.CuryTipAmt ?? 0m); tranTip.CuryTranAmt = claimdetail.CuryTipAmt * signOperation; } else { decimal tipAmt; PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, (decimal)claimdetail.TipAmt, out tipAmt); tranTip.CuryUnitCost = Math.Abs(tipAmt); tranTip.CuryTranAmt = tipAmt * signOperation; } tranTip.Qty = tipQty; tranTip.UOM = tipItem.BaseUnit; tranTip.NonBillable = claimdetail.Billable != true; tranTip.Date = claimdetail.ExpenseDate; tranTip.BranchID = claimdetail.BranchID; tranTip = docgraph.Transactions.Insert(tranTip); if (epsetup.UseReceiptAccountForTips == true) { tranTip.AccountID = claimdetail.ExpenseAccountID; tranTip.SubID = claimdetail.ExpenseSubID; } else { tranTip.AccountID = tipItem.COGSAcctID; Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <APInvoice.branchID> > > > .Select(docgraph); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(docgraph, claimdetail.ContractID, claimdetail.TaskID); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(claimdetailcache, claimdetail); int?employee_SubID = (int?)docgraph.Caches[typeof(EPEmployee)].GetValue <EPEmployee.expenseSubID>(employee); int?item_SubID = (int?)docgraph.Caches[typeof(IN.InventoryItem)].GetValue <IN.InventoryItem.cOGSSubID>(tipItem); int?company_SubID = (int?)docgraph.Caches[typeof(Location)].GetValue <Location.cMPExpenseSubID>(companyloc); int?project_SubID = (int?)docgraph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)docgraph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)docgraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); object value = SubAccountMaskAttribute.MakeSub <EPSetup.expenseSubMask>(docgraph, epsetup.ExpenseSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.expenseSubID), typeof(IN.InventoryItem.cOGSSubID), typeof(Location.cMPExpenseSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); docgraph.Caches[typeof(APTran)].RaiseFieldUpdating <APTran.subID>(tranTip, ref value); tranTip.SubID = (int?)value; } tranTip = docgraph.Transactions.Update(tranTip); tranTip.TaxCategoryID = tipItem.TaxCategoryID; tranTip.ProjectID = tran.ProjectID; tranTip.TaskID = tran.TaskID; tranTip = AddTaxes(docgraph, invoice, signOperation, claimdetail, tranTip, true); tranTip = docgraph.Transactions.Update(tranTip); } PXNoteAttribute.CopyNoteAndFiles(claimdetailcache, claimdetail, docgraph.Transactions.Cache, tran, epsetup.GetCopyNoteSettings <PXModule.ap>()); claimdetail.Released = true; expenseClaimGraph.ExpenseClaimDetails.Update(claimdetail); #endregion tran = AddTaxes(docgraph, invoice, signOperation, claimdetail, tran, false); } #region legacy taxes foreach (EPTaxAggregate tax in PXSelectReadonly <EPTaxAggregate, Where <EPTaxAggregate.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr)) { #region Add taxes APTaxTran new_aptax = docgraph.Taxes.Search <APTaxTran.taxID>(tax.TaxID); if (new_aptax == null) { new_aptax = new APTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = docgraph.Taxes.Insert(new_aptax); if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.CuryTaxableAmt = 0m; new_aptax.CuryTaxAmt = 0m; new_aptax.CuryExpenseAmt = 0m; new_aptax = docgraph.Taxes.Update(new_aptax); } } if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = (new_aptax.CuryTaxableAmt ?? 0m) + tax.CuryTaxableAmt * signOperation; new_aptax.CuryTaxAmt = (new_aptax.CuryTaxAmt ?? 0m) + tax.CuryTaxAmt * signOperation; new_aptax.CuryExpenseAmt = (new_aptax.CuryExpenseAmt ?? 0m) + tax.CuryExpenseAmt * signOperation; new_aptax = docgraph.Taxes.Update(new_aptax); } #endregion } #endregion invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoice.CuryTaxAmt = invoice.CuryTaxTotal; invoice.Hold = false; docgraph.Document.Update(invoice); invoice.CuryTaxRoundDiff = invoice.CuryRoundDiff = invoice.CuryRoundDiff = claimCuryTaxRoundDiff; invoice.TaxRoundDiff = invoice.RoundDiff = claimTaxRoundDiff; bool inclusive = PXSelectJoin <APTaxTran, InnerJoin <Tax, On <APTaxTran.taxID, Equal <Tax.taxID> > >, Where <APTaxTran.refNbr, Equal <Required <APInvoice.refNbr> >, And <APTaxTran.tranType, Equal <Required <APInvoice.docType> >, And <Tax.taxCalcLevel, Equal <CSTaxCalcLevel.inclusive> > > > > .Select(docgraph, invoice.RefNbr, invoice.DocType).Count > 0; if ((invoice.TaxCalcMode == TaxCalculationMode.Gross && PXSelectJoin <APTaxTran, InnerJoin <Tax, On <APTaxTran.taxID, Equal <Tax.taxID> > >, Where <APTaxTran.refNbr, Equal <Required <APInvoice.refNbr> >, And <APTaxTran.tranType, Equal <Required <APInvoice.docType> >, And <Tax.taxCalcLevel, Equal <CSTaxCalcLevel.calcOnItemAmt> > > > > .Select(docgraph, invoice.RefNbr, invoice.DocType).Count > 0) || inclusive) { decimal curyAdditionalDiff = -(invoice.CuryTaxRoundDiff ?? 0m) + (invoice.CuryTaxAmt ?? 0m) - (invoice.CuryDocBal ?? 0m); decimal additionalDiff = -(invoice.TaxRoundDiff ?? 0m) + (invoice.TaxAmt ?? 0m) - (invoice.DocBal ?? 0m); foreach (APTran line in docgraph.Transactions.Select()) { curyAdditionalDiff += (line.CuryTaxableAmt ?? 0m) == 0m ? (line.CuryTranAmt ?? 0m) : (line.CuryTaxableAmt ?? 0m); additionalDiff += (line.TaxableAmt ?? 0m) == 0m ? (line.TranAmt ?? 0m) : (line.TaxableAmt ?? 0m); } invoice.CuryTaxRoundDiff += curyAdditionalDiff; invoice.TaxRoundDiff += additionalDiff; } docgraph.Document.Update(invoice); docgraph.Save.Press(); foreach (EPExpenseClaimDetails claimdetail in res.Value) { claimdetail.APDocType = invoice.DocType; claimdetail.APRefNbr = invoice.RefNbr; expenseClaimGraph.ExpenseClaimDetails.Update(claimdetail); } claim.Status = EPExpenseClaimStatus.ReleasedStatus; claim.Released = true; expenseClaimGraph.ExpenseClaim.Update(claim); #region EP History Update EPHistory hist = new EPHistory(); hist.EmployeeID = invoice.VendorID; hist.FinPeriodID = invoice.FinPeriodID; hist = (EPHistory)expenseClaimGraph.Caches[typeof(EPHistory)].Insert(hist); hist.FinPtdClaimed += invoice.DocBal; hist.FinYtdClaimed += invoice.DocBal; if (invoice.FinPeriodID == invoice.TranPeriodID) { hist.TranPtdClaimed += invoice.DocBal; hist.TranYtdClaimed += invoice.DocBal; } else { EPHistory tranhist = new EPHistory(); tranhist.EmployeeID = invoice.VendorID; tranhist.FinPeriodID = invoice.TranPeriodID; tranhist = (EPHistory)expenseClaimGraph.Caches[typeof(EPHistory)].Insert(tranhist); tranhist.TranPtdClaimed += invoice.DocBal; tranhist.TranYtdClaimed += invoice.DocBal; } expenseClaimGraph.Views.Caches.Add(typeof(EPHistory)); #endregion expenseClaimGraph.Save.Press(); doclist.Add(docgraph.Document.Current); } ts.Complete(); } if ((bool)epsetup.AutomaticReleaseAP == true) { APDocumentRelease.ReleaseDoc(doclist, false); } }
protected void FindOwner(PXGraph graph, Guid?ownerId, out Contact contact, out Users user, out EPEmployee employee) { contact = null; user = null; employee = null; if (ownerId == null) { return; } PXSelectJoin <Users, LeftJoin <EPEmployee, On <EPEmployee.userID, Equal <Users.pKID> >, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > > >, Where <Users.pKID, Equal <Required <Users.pKID> > > > .Clear(graph); var row = (PXResult <Users, EPEmployee, Contact>) PXSelectJoin <Users, LeftJoin <EPEmployee, On <EPEmployee.userID, Equal <Users.pKID> >, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > > >, Where <Users.pKID, Equal <Required <Users.pKID> > > > .Select(graph, ownerId); contact = (Contact)row; user = (Users)row; employee = (EPEmployee)row; }
private IEnumerable <ApproveInfo> ProcessLevel(Table item, int?assignmentMap, PXResultset <EPRule> rules) { foreach (EPRule rule in rules) { if (rule.RuleID == null) { continue; } path.Add(rule.RuleID.Value); bool isSuccessful = true; var filteredItems = ExecuteRule(item, rule, ref isSuccessful); Guid?OwnerID = null; int? WorkgroupID = rule.WorkgroupID; switch (rule.RuleType) { case EPRuleType.Direct: if (!isSuccessful || (filteredItems != null && filteredItems.Count == 0)) { continue; } OwnerID = rule.OwnerID; FillOwnerWorkgroup(ref OwnerID, ref WorkgroupID); if (OwnerID == null && WorkgroupID == null) { continue; } yield return(new ApproveInfo() { OwnerID = OwnerID, WorkgroupID = WorkgroupID, RuleID = rule.RuleID, StepID = rule.StepID, WaitTime = rule.WaitTime }); break; case EPRuleType.Document: if (rule.OwnerSource == null || (filteredItems != null && filteredItems.Count == 0)) { continue; } PXView lineView = null; PXView primaryView = null; Type viewType = null; try { var s = rule.OwnerSource; var viewName = s.Substring(s.LastIndexOf("(") + 1, s.IndexOf(".") - (s.LastIndexOf("(") + 1)); if (String.Equals(viewName, processGraph.PrimaryView, StringComparison.InvariantCultureIgnoreCase)) { primaryView = processGraph.Views[viewName]; viewType = primaryView.GetItemType(); } else { lineView = processGraph.Views[viewName]; viewType = lineView.GetItemType(); } } catch (Exception) { // ignored } bool queryContainsDetails = filteredItems != null && filteredItems.Count > 0 && ((PXResult)filteredItems[0])[viewType] != null; var arrayToIterate = queryContainsDetails ? filteredItems : lineView?.SelectMulti() ?? primaryView.Cache.Current.SingleToList() ?? filteredItems; foreach (object filteredItem in arrayToIterate) { if (filteredItem is PXResult) { var line = ((PXResult)filteredItem)[viewType]; processGraph.Caches[viewType].Current = line; } else { processGraph.Caches[viewType].Current = filteredItem; } string code = PXTemplateContentParser.Instance.Process(rule.OwnerSource, processGraph, viewType, null); EPEmployee emp = PXSelect < EPEmployee, Where <EPEmployee.acctCD, Equal <Required <EPEmployee.acctCD> > > > .SelectWindowed(this, 0, 1, code); OwnerID = emp != null ? emp.UserID : GUID.CreateGuid(code); FillOwnerWorkgroup(ref OwnerID, ref WorkgroupID); if (OwnerID == null && WorkgroupID == null) { continue; } yield return(new ApproveInfo() { OwnerID = OwnerID, WorkgroupID = WorkgroupID, RuleID = rule.RuleID, StepID = rule.StepID, WaitTime = rule.WaitTime }); } break; case EPRuleType.Filter: if (filteredItems == null || filteredItems.Count == 0) { continue; } List <EPRuleBaseCondition> conditions = PXSelectReadonly <EPRuleEmployeeCondition, Where <EPRuleEmployeeCondition.ruleID, Equal <Required <EPRule.ruleID> > > > .Select(this, rule.RuleID) .Select(_ => (EPRuleBaseCondition)_) .ToList(); if (conditions.Count == 0) { break; } foreach (var approveInfo in GetEmployeesByFilter(item, rule, conditions)) { yield return(approveInfo); } break; } if (rule.RuleID != null) { if (path.Contains(rule.RuleID.Value)) { continue; } foreach (var approveInfo in ProcessLevel(item, assignmentMap, PXSelectReadonly <EPRule> .Search <EPRule.ruleID>(this, rule.RuleID))) { yield return(approveInfo); } } PXResultset <EPRule> result = PXSelectReadonly < EPRule, Where < EPRule.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> > >, OrderBy < Asc <EPRule.sequence> > > .Select(this, assignmentMap); foreach (var approveInfo in ProcessLevel(item, assignmentMap, result)) { yield return(approveInfo); } } }
private bool ProcessLevel(Table item, int?assignmentMap, PXResultset <EPAssignmentRoute> routes) { PXSelectReadonly <EPAssignmentRoute, Where <EPAssignmentRoute.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> >, And <EPAssignmentRoute.parent, Equal <Required <EPAssignmentRoute.assignmentRouteID> > > >, OrderBy <Asc <EPAssignmentRoute.sequence> > > rs = new PXSelectReadonly <EPAssignmentRoute, Where <EPAssignmentRoute.assignmentMapID, Equal <Required <EPAssignmentMap.assignmentMapID> >, And <EPAssignmentRoute.parent, Equal <Required <EPAssignmentRoute.assignmentRouteID> > > >, OrderBy <Asc <EPAssignmentRoute.sequence> > >(this); foreach (EPAssignmentRoute route in routes) { if (route.AssignmentRouteID == null) { continue; } path.Add(route.AssignmentRouteID.Value); if (IsPassed(item, route)) { if (route.WorkgroupID != null || route.OwnerID != null || route.OwnerSource != null) { item.WorkgroupID = route.WorkgroupID; item.OwnerID = null; if (route.OwnerSource != null) { PXGraph graph = processGraph; PXCache cache = graph.Caches[typeof(Table)]; string code = PXTemplateContentParser.Instance.Process(route.OwnerSource, graph, typeof(Table), null ); EPEmployee emp = PXSelect <EPEmployee, Where <EPEmployee.acctCD, Equal <Required <EPEmployee.acctCD> > > > .SelectWindowed(this, 0, 1, code); item.OwnerID = emp != null ? emp.UserID : GUID.CreateGuid(code); } if (item.OwnerID == null) { item.OwnerID = route.OwnerID; } if (route.UseWorkgroupByOwner == true && item.WorkgroupID != null && item.OwnerID != null) { EPCompanyTreeMember member = PXSelectJoin <EPCompanyTreeMember, InnerJoin <EPCompanyTreeH, On <EPCompanyTreeH.workGroupID, Equal <EPCompanyTreeMember.workGroupID> >, InnerJoin <EPEmployee, On <EPEmployee.userID, Equal <EPCompanyTreeMember.userID> > > >, Where <EPCompanyTreeH.parentWGID, Equal <Required <EPCompanyTreeH.parentWGID> >, And <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> > > > > .SelectWindowed(this, 0, 1, item.WorkgroupID, item.OwnerID); if (member != null) { item.WorkgroupID = member.WorkGroupID; } } if (item.WorkgroupID != null && item.OwnerID == null) { EPCompanyTreeMember owner = PXSelectJoin <EPCompanyTreeMember, InnerJoin <EPEmployee, On <EPEmployee.userID, Equal <EPCompanyTreeMember.userID> > >, Where <EPCompanyTreeMember.workGroupID, Equal <Required <EPCompanyTreeMember.workGroupID> >, And <EPCompanyTreeMember.isOwner, Equal <boolTrue> > > > .Select(this, item.WorkgroupID); if (owner != null) { item.OwnerID = owner.UserID; } } PXTrace.WriteInformation(Messages.ProcessRouteSequence, route.Sequence); return(true); } if (route.RouteID != null) { return(!path.Contains(route.RouteID.Value) && ProcessLevel(item, assignmentMap, PXSelectReadonly <EPAssignmentRoute> .Search <EPAssignmentRoute.assignmentRouteID>(this, route.RouteID))); } PXResultset <EPAssignmentRoute> result = rs.Select(assignmentMap, route.AssignmentRouteID); return(ProcessLevel(item, assignmentMap, result)); } } return(false); }
private bool PreventEmailRoutingFor(Users user, EPEmployee employee) { return(user?.State == Users.state.Disabled || employee?.Status == BAccount.status.Inactive); }
protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, decimal signOperation, decimal tipQty = 1m, bool isTipTransaction = false) { CurrencyInfo curyInfo = PXSelect <CurrencyInfo> .Search <CurrencyInfo.curyInfoID>(arGraph, row.CuryInfoID); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(arGraph); ARTran tran = arGraph.Transactions.Insert(); if (isTipTransaction) { IN.InventoryItem tipItem = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(arGraph, epsetup.NonTaxableTipItem); tran.InventoryID = epsetup.NonTaxableTipItem; tran.Qty = tipQty; tran.UOM = tipItem.BaseUnit; tran.TranDesc = tipItem.Descr; SetAmount(arGraph, row.CuryTipAmt, row.TipAmt, tipQty, signOperation, curyInfo, tran); tran = arGraph.Transactions.Update(tran); if (epsetup.UseReceiptAccountForTips == true) { tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; } else { Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <ARTran.branchID> > > > .Select(arGraph); Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(this, row.ContractID); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(arGraph, row.ContractID, row.TaskID); EPEmployee employee = (EPEmployee)PXSelect <EPEmployee> .Search <EPEmployee.bAccountID>(this, row != null?row.EmployeeID : null); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(arGraph.Caches[typeof(EPExpenseClaimDetails)], row); int?employee_SubID = (int?)arGraph.Caches[typeof(EPEmployee)].GetValue <EPEmployee.salesSubID>(employee); int?item_SubID = (int?)arGraph.Caches[typeof(IN.InventoryItem)].GetValue <IN.InventoryItem.salesSubID>(tipItem); int?company_SubID = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(companyloc); int?project_SubID = (int?)arGraph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)arGraph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); object value = SubAccountMaskAttribute.MakeSub <EPSetup.salesSubMask>(arGraph, epsetup.SalesSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.salesSubID), typeof(IN.InventoryItem.salesSubID), typeof(Location.cSalesSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); arGraph.Caches[typeof(ARTran)].RaiseFieldUpdating <ARTran.subID>(tran, ref value); tran.SubID = (int?)value; } } else { tran.InventoryID = row.InventoryID; tran.Qty = row.Qty * signOperation; tran.UOM = row.UOM; tran = arGraph.Transactions.Update(tran); tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; tran.TranDesc = row.TranDesc; //For gross taxes we can't put tranAmt. So we should use taxable amount EPTaxTran firstLevelTaxTran = null; foreach (EPTaxTran taxRow in PXSelect <EPTaxTran, Where <EPTaxTran.claimDetailID, Equal <Required <EPTaxTran.claimDetailID> >, And <EPTaxTran.isTipTax, Equal <False> > > > .Select(this, row.ClaimDetailID)) { if (firstLevelTaxTran == null || Math.Abs(firstLevelTaxTran.CuryTaxableAmt ?? 0m) > Math.Abs(taxRow.CuryTaxableAmt ?? 0m)) { firstLevelTaxTran = taxRow; } } decimal?curyAmt = firstLevelTaxTran?.CuryTaxableAmt ?? row.CuryTaxableAmt; decimal?amt = firstLevelTaxTran?.TaxableAmt ?? row.TaxableAmt; SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran); tran = arGraph.Transactions.Update(tran); if (tran.CuryTaxableAmt != 0 && tran.CuryTaxableAmt != curyAmt) // indicates that we have gross/ iclusive taxes. In this case recalculation is required { curyAmt = row.CuryTaxableAmt; amt = row.TaxableAmt; SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran); } } tran.Date = row.ExpenseDate; tran.ManualPrice = true; tran = arGraph.Transactions.Update(tran); PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(EPExpenseClaimDetails)], row, arGraph.Transactions.Cache, tran, Setup.Current.GetCopyNoteSettings <PXModule.ar>()); }
public static void ReleaseDoc(EPExpenseClaim claim) { APInvoiceEntry docgraph = PXGraph.CreateInstance <APInvoiceEntry>(); ExpenseClaimEntry expenseclaim = PXGraph.CreateInstance <ExpenseClaimEntry>(); if (claim.FinPeriodID == null) { throw new PXException(Messages.ReleaseClaimWithoutFinPeriod); } //docgraph.FieldVerifying.AddHandler<APInvoice.vendorLocationID>(APInterceptor); EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID); Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph); APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph); docgraph.vendor.Current = employee; docgraph.location.Current = emplocation; CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID); CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal); info.CuryInfoID = null; info = docgraph.currencyinfo.Insert(info); APInvoice invoice = new APInvoice(); invoice.CuryInfoID = info.CuryInfoID; invoice.Hold = true; invoice.Released = false; invoice.Printed = false; invoice.OpenDoc = true; invoice.DocDate = claim.DocDate; invoice.InvoiceNbr = claim.RefNbr; invoice.DocDesc = claim.DocDesc; invoice.VendorID = claim.EmployeeID; invoice.CuryID = info.CuryID; invoice.VendorLocationID = claim.LocationID; invoice.APAccountID = emplocation != null ? emplocation.APAccountID : null; invoice.APSubID = emplocation != null ? emplocation.APSubID : null; invoice.TaxZoneID = claim.TaxZoneID; invoice = docgraph.Document.Insert(invoice); PXCache claimcache = docgraph.Caches[typeof(EPExpenseClaim)]; PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)]; if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimcache, claim); if (note != null) { PXNoteAttribute.SetNote(docgraph.Document.Cache, invoice, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimcache, claim); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, invoice, files); } } using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); foreach (PXResult <EPExpenseClaimDetails, Contract> res in PXSelectJoin <EPExpenseClaimDetails, LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID> > >, Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr)) { EPExpenseClaimDetails claimdetail = (EPExpenseClaimDetails)res; Contract contract = (Contract)res; if (claimdetail.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseclaim, claimdetail.TaskID); if (task != null && !(bool)task.VisibleInAP) { throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP); } } APTran tran = new APTran(); tran.InventoryID = claimdetail.InventoryID; tran.TranDesc = claimdetail.TranDesc; tran.CuryUnitCost = claimdetail.CuryUnitCost; tran.Qty = claimdetail.Qty; tran.UOM = claimdetail.UOM; tran.NonBillable = claimdetail.Billable != true; tran.CuryLineAmt = claimdetail.CuryTranAmt; tran.Date = claimdetail.ExpenseDate; if (contract.BaseType == PM.PMProject.ProjectBaseType.Project) { tran.ProjectID = claimdetail.ContractID; } else { tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(docgraph); } tran.TaskID = claimdetail.TaskID; tran.AccountID = claimdetail.ExpenseAccountID; tran.SubID = claimdetail.ExpenseSubID; tran.TaxCategoryID = claimdetail.TaxCategoryID; tran = docgraph.Transactions.Insert(tran); if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimdetailcache, claimdetail); if (note != null) { PXNoteAttribute.SetNote(docgraph.Transactions.Cache, tran, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimdetailcache, claimdetail); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Transactions.Cache, tran, files); } } claimdetail.Released = true; expenseclaim.ExpenseClaimDetails.Update(claimdetail); } foreach (EPTaxTran tax in PXSelect <EPTaxTran, Where <EPTaxTran.refNbr, Equal <Required <EPTaxTran.refNbr> > > > .Select(docgraph, claim.RefNbr)) { APTaxTran new_aptax = new APTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = docgraph.Taxes.Insert(new_aptax); if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt; new_aptax.CuryTaxAmt = tax.CuryTaxAmt; new_aptax = docgraph.Taxes.Update(new_aptax); } } invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoice.Hold = false; docgraph.Document.Update(invoice); docgraph.Save.Press(); claim.Status = EPClaimStatus.Released; claim.Released = true; claim.APRefNbr = invoice.RefNbr; claim.APDocType = invoice.DocType; expenseclaim.ExpenseClaim.Update(claim); #region EP History Update EPHistory hist = new EPHistory(); hist.EmployeeID = invoice.VendorID; hist.FinPeriodID = invoice.FinPeriodID; hist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(hist); hist.FinPtdClaimed += invoice.DocBal; hist.FinYtdClaimed += invoice.DocBal; if (invoice.FinPeriodID == invoice.TranPeriodID) { hist.TranPtdClaimed += invoice.DocBal; hist.TranYtdClaimed += invoice.DocBal; } else { EPHistory tranhist = new EPHistory(); tranhist.EmployeeID = invoice.VendorID; tranhist.FinPeriodID = invoice.TranPeriodID; tranhist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(tranhist); tranhist.TranPtdClaimed += invoice.DocBal; tranhist.TranYtdClaimed += invoice.DocBal; } expenseclaim.Views.Caches.Add(typeof(EPHistory)); #endregion expenseclaim.Save.Press(); ts.Complete(); } } if ((bool)epsetup.AutomaticReleaseAP == true) { List <APRegister> doclist = new List <APRegister>(); doclist.Add(docgraph.Document.Current); APDocumentRelease.ReleaseDoc(doclist, false); } }