protected virtual void refreshDistributionCenters() { PXResultset <KCDistributionCenter> existingDistributionCenters = DistributionCenters.Select(); List <string> existingNames = new List <string>(); List <KCAPIDistributionCenter> newCenters = new List <KCAPIDistributionCenter>(); KCSiteMaster connection = Connection.SelectSingle(); KCARestClient client = new KCARestClient(connection); KCInventoryItemAPIHelper helper = new KCInventoryItemAPIHelper(client); FillDistributionCentersFromCA(helper, newCenters); existingDistributionCenters.RowCast <KCDistributionCenter>().ForEach(x => existingNames.Add(x.DistributionCenterName)); foreach (KCAPIDistributionCenter newCenter in newCenters) { if (!existingNames.Contains(newCenter.Name)) { DistributionCenters.Insert(new KCDistributionCenter() { DistributionCenterID = newCenter.ID, DistributionCenterName = newCenter.Name, Code = newCenter.Code }); } } this.Persist(typeof(KCDistributionCenter), PXDBOperation.Insert); foreach (string existingName in existingNames) { if (!newCenters.Any(x => x.Name == existingName)) { KCDistributionCenter item = DistributionCenterByName.SelectSingle(existingName); DistributionCenters.Delete(item); KCInventoryManagement deletedMapping = Mapping.Select().RowCast <KCInventoryManagement>().FirstOrDefault(x => x.DistributionCenterID == item.DistributionCenterID); if (deletedMapping != null) { Mapping.Delete(deletedMapping); } } } bool defaultDcDeleted = DistributionCenters.Cache.Deleted.RowCast <KCDistributionCenter>().Any(x => x.DistributionCenterID == InventoryTrackingRule.Current.DefaultDistributionCenterID); if (InventoryTrackingRule.Current.InventoryTrackingRule == null) { InventoryTrackingRule.Current.InventoryTrackingRule = KCInventoryTrackingRulesConstants.Consolidate; } if (InventoryTrackingRule.Current.DefaultDistributionCenterID == null || defaultDcDeleted) { InventoryTrackingRule.Current.DefaultDistributionCenterID = GetDefaultDistributionCenter(helper, newCenters); } InventoryTrackingRule.Update(InventoryTrackingRule.Current); InventoryTrackingRule.Cache.SetStatus(InventoryTrackingRule.Current, PXEntryStatus.Updated); Connection.Cache.SetStatus(connection, PXEntryStatus.Notchanged); Actions.PressSave(); }
private void WarnIfMissingTaxID(GLTran tran) { bool needWarning = false; if (tran != null && tran.AccountID != null && tran.SubID != null && tran.TaxID == null) { PXResultset <TX.Tax> taxset = PXSelect <TX.Tax, Where2 <Where <TX.Tax.purchTaxAcctID, Equal <Required <GLTran.accountID> >, And <TX.Tax.purchTaxSubID, Equal <Required <GLTran.subID> > > >, Or <Where <TX.Tax.salesTaxAcctID, Equal <Required <GLTran.accountID> >, And <TX.Tax.salesTaxSubID, Equal <Required <GLTran.subID> > > > > > > .Select(JournalEntry, tran.AccountID, tran.SubID, tran.AccountID, tran.SubID); if (taxset.Count > 0 && tran.TaxID == null) { needWarning = true; } } if (tran != null) { if (needWarning) { GLTranCache.RaiseExceptionHandling <GLTran.taxID>(tran, null, new PXSetPropertyException(Messages.TaxIDMissingForAccountAssociatedWithTaxes, PXErrorLevel.Warning)); } else { GLTranCache.RaiseExceptionHandling <GLTran.taxID>(tran, null, null); } } }
public static bool IsCCPIDFilled(PXGraph graph, int?PMInstanceID) { if (PMInstanceID == null || PMInstanceID.Value < 0) { return(false); } CustomerPaymentMethod cpm = PXSelect <CustomerPaymentMethod, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(graph, PMInstanceID); if (cpm == null) { return(false); } PXResultset <PaymentMethodDetail> paymentMethodDetail = PXSelectJoin <PaymentMethodDetail, LeftJoin <CustomerPaymentMethodDetail, On <CustomerPaymentMethodDetail.paymentMethodID, Equal <PaymentMethodDetail.paymentMethodID>, And <CustomerPaymentMethodDetail.detailID, Equal <PaymentMethodDetail.detailID>, And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>, And <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > > > >, Where <PaymentMethodDetail.isCCProcessingID, Equal <True>, And <PaymentMethodDetail.paymentMethodID, Equal <Required <PaymentMethodDetail.paymentMethodID> > > > > .Select(graph, PMInstanceID, cpm.PaymentMethodID); PaymentMethodDetail pmIDDetail = paymentMethodDetail.Count > 0 ? paymentMethodDetail[0].GetItem <PaymentMethodDetail>() : null; CustomerPaymentMethodDetail ccpIDDetail = paymentMethodDetail.Count > 0 ? paymentMethodDetail[0].GetItem <CustomerPaymentMethodDetail>() : null; if (IsTokenizedPaymentMethod(graph, PMInstanceID) && pmIDDetail == null) { throw new PXException(Messages.PaymentMethodNotConfigured); } return(ccpIDDetail != null && !string.IsNullOrEmpty(ccpIDDetail.Value)); }
public void Fill(PXGraph graph) { PXResultset <CRValidationRules> source = PXSelect <CRValidationRules> .Select(graph); Rules = new List <CRValidationRules>(); Contacts = new List <CRValidationRules>(); Accounts = new List <CRValidationRules>(); TypeRules = new Dictionary <string, List <CRValidationRules> >(); foreach (CRValidationRules rule in source) { Rules.Add(rule); if (!TypeRules.ContainsKey(rule.ValidationType)) { TypeRules[rule.ValidationType] = new List <CRValidationRules>(); } TypeRules[rule.ValidationType].Add(rule); switch (rule.ValidationType) { case ValidationTypesAttribute.LeadContact: Contacts.Add(rule); break; case ValidationTypesAttribute.LeadAccount: Accounts.Add(rule); Contacts.Add(rule); break; case ValidationTypesAttribute.Account: Accounts.Add(rule); break; } } }
public virtual void PrimaryDriver_FieldUpdated_Handler(PXCache cache, FSAppointmentEmployee fsAppointmentEmployeeRow) { PXResultset <FSAppointmentEmployee> employeeRows = AppointmentServiceEmployees.Select(); foreach (FSAppointmentEmployee row in employeeRows.RowCast <FSAppointmentEmployee>() .Where(_ => _.EmployeeID == fsAppointmentEmployeeRow.EmployeeID)) { row.PrimaryDriver = fsAppointmentEmployeeRow.PrimaryDriver; if (cache.GetStatus(row) == PXEntryStatus.Notchanged) { cache.SetStatus(row, PXEntryStatus.Updated); } } if (fsAppointmentEmployeeRow.PrimaryDriver == true) { foreach (FSAppointmentEmployee row in employeeRows.RowCast <FSAppointmentEmployee>() .Where(_ => _.EmployeeID != fsAppointmentEmployeeRow.EmployeeID && _.PrimaryDriver == true)) { row.PrimaryDriver = false; if (cache.GetStatus(row) == PXEntryStatus.Notchanged) { cache.SetStatus(row, PXEntryStatus.Updated); } } } AppointmentServiceEmployees.View.RequestRefresh(); }
protected FABookYear SelectSingleBookYear(PrevNextYear direction, string year) { this.Caches[typeof(FABookYear)].ClearQueryCache(); PXResultset <FABookYear> query = SelectFrom <FABookYear> .Where < FABookYear.bookID.IsEqual <FABookYear.bookID.FromCurrent> .And <FABookYear.organizationID.IsEqual <FABookYear.organizationID.FromCurrent> > > .View.ReadOnly.Select(this); if (direction == PrevNextYear.Next) { return(query .OrderBy(row => ((FABookYear)row).Year) .Where(row => String.Compare(((FABookYear)row).Year, year) > 0) .ReadOnly() .FirstOrDefault()); } else if (direction == PrevNextYear.Previous) { return(query .OrderByDescending(row => ((FABookYear)row).Year) .Where(row => String.Compare(((FABookYear)row).Year, year) < 0) .ReadOnly() .FirstOrDefault()); } else { return(query .Where(row => String.Compare(((FABookYear)row).Year, year) == 0) .ReadOnly() .FirstOrDefault()); } }
protected int?GetInstanceId(V2.TranProfile input) { int? instanceID = PaymentTranExtConstants.NewPaymentProfile; PXCache cpmCache = Base.Caches[typeof(CustomerPaymentMethod)]; cpmCache.ClearQueryCacheObsolete(); PXSelectBase <CustomerPaymentMethod> query = new PXSelectReadonly2 <CustomerPaymentMethod, InnerJoin <CustomerPaymentMethodDetail, On <CustomerPaymentMethod.pMInstanceID, Equal <CustomerPaymentMethodDetail.pMInstanceID> >, InnerJoin <PaymentMethodDetail, On <CustomerPaymentMethodDetail.detailID, Equal <PaymentMethodDetail.detailID>, And <CustomerPaymentMethodDetail.paymentMethodID, Equal <PaymentMethodDetail.paymentMethodID> > > > >, Where <CustomerPaymentMethod.cCProcessingCenterID, Equal <Required <CustomerPaymentMethod.cCProcessingCenterID> >, And <CustomerPaymentMethod.customerCCPID, Equal <Required <CustomerPaymentMethod.customerCCPID> >, And <PaymentMethodDetail.isCCProcessingID, Equal <True>, And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards> > > > > >(Base); PXResultset <CustomerPaymentMethod> queryResult = query.Select(SelectedProcessingCenter, input.CustomerProfileId); foreach (PXResult <CustomerPaymentMethod, CustomerPaymentMethodDetail> item in queryResult) { CustomerPaymentMethodDetail checkCpmd = (CustomerPaymentMethodDetail)item; if (checkCpmd.Value == input.PaymentProfileId) { instanceID = checkCpmd.PMInstanceID; break; } } CustomerPaymentMethod cpm = NewCpm.Select(); if (cpm != null && cpm.PMInstanceID != null && cpm.PMInstanceID >= 0) { instanceID = cpm.PMInstanceID.Value; } return(instanceID); }
protected V2.TranProfile GetCustomerProfileFromDoc(ICCPayment pDoc) { V2.TranProfile ret = null; if (pDoc.PMInstanceID > 0) { var query = new PXSelectJoin <CustomerPaymentMethod, InnerJoin <CustomerPaymentMethodDetail, On <CustomerPaymentMethodDetail.pMInstanceID, Equal <CustomerPaymentMethod.pMInstanceID> >, InnerJoin <PaymentMethodDetail, On <PaymentMethodDetail.detailID, Equal <CustomerPaymentMethodDetail.detailID> > > >, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> >, And <PaymentMethodDetail.isCCProcessingID, Equal <True> > > >(Base); PXResultset <CustomerPaymentMethod> result = query.Select(pDoc.PMInstanceID); foreach (PXResult <CustomerPaymentMethod, CustomerPaymentMethodDetail> item in result) { CustomerPaymentMethod cpm = (CustomerPaymentMethod)item; CustomerPaymentMethodDetail cpmDet = (CustomerPaymentMethodDetail)item; ret = new V2.TranProfile() { CustomerProfileId = cpm.CustomerCCPID, PaymentProfileId = cpmDet.Value }; break; } } return(ret); }
public static ITaxProvider CreateTaxProvider(PXGraph graph, TaxPlugin plugin) { ITaxProvider service = null; if (!string.IsNullOrEmpty(plugin.PluginTypeName)) { try { Type taxType = PXBuildManager.GetType(plugin.PluginTypeName, true); service = (ITaxProvider)Activator.CreateInstance(taxType); PXSelectBase <TaxPluginDetail> select = new PXSelect <TaxPluginDetail, Where <TaxPluginDetail.taxPluginID, Equal <Required <TaxPluginDetail.taxPluginID> > > >(graph); PXResultset <TaxPluginDetail> resultset = select.Select(plugin.TaxPluginID); var list = new List <ITaxProviderSetting>(resultset.Count); foreach (TaxPluginDetail item in resultset) { list.Add(item); } service.Initialize(list); } catch (Exception ex) { throw new PXException(Messages.FailedToCreateTaxPlugin, ex.Message); } } return(service); }
private void ProcessPMResultset(PXResultset <PMHistory> resultset) { foreach (PXResult <PMHistory, PMTask> result in resultset) { var hist = (PMHistory)result; var task = (PMTask)result; var key = new PMHistoryKeyTuple(hist.ProjectID.Value, task.TaskCD, hist.AccountGroupID.Value, hist.InventoryID.Value); Dictionary <string, PMHistory> keyData; if (_pmhistoryPeriodsByKey.TryGetValue(key, out keyData)) { keyData.Add(hist.PeriodID, hist); } else { _pmhistoryPeriodsByKey.Add(key, new Dictionary <string, PMHistory> { { hist.PeriodID, hist } }); } _historySegments.Add(new PMHistoryKeyTuple(0, String.Empty, hist.AccountGroupID.Value, 0)); _historySegments.Add(new PMHistoryKeyTuple(hist.ProjectID.Value, String.Empty, hist.AccountGroupID.Value, 0)); _historySegments.Add(new PMHistoryKeyTuple(hist.ProjectID.Value, task.TaskCD, hist.AccountGroupID.Value, 0)); } }
private void CreateCustomerPaymentMethodDetailRecord(CustomerPaymentMethod customerPM, CCSynchronizeCard syncCard) { PXResultset <PaymentMethodDetail> details = GetPaymentMethodDetailParams(customerPM.PaymentMethodID); PXCache customerPaymentMethodDetailCache = Caches[typeof(CustomerPaymentMethodDetail)]; CustomerPaymentMethodDetail customerPaymentDetails; foreach (PaymentMethodDetail detail in details) { customerPaymentDetails = customerPaymentMethodDetailCache.CreateInstance() as CustomerPaymentMethodDetail; customerPaymentDetails.DetailID = detail.DetailID; customerPaymentDetails.PMInstanceID = customerPM.PMInstanceID; customerPaymentDetails.PaymentMethodID = customerPM.PaymentMethodID; if (customerPaymentDetails.DetailID == CreditCardAttributes.CardNumber) { Match match = new Regex("[\\d]+").Match(syncCard.CardNumber); if (match.Success) { string cardNum = match.Value.PadLeft(8, 'X'); customerPaymentDetails.Value = cardNum; } } if (customerPaymentDetails.DetailID == CreditCardAttributes.CCPID) { customerPaymentDetails.Value = syncCard.PaymentCCPID; } customerPaymentMethodDetailCache.Insert(customerPaymentDetails); customerPaymentMethodDetailCache.Persist(PXDBOperation.Insert); } }
public virtual void RenumberAll(IComparer <PXResult> comparer) { PXResultset <Table> res = Select(); List <PXResult> list = new List <PXResult>(res.Count); foreach (PXResult item in res) { list.Add(item); } list.Sort(comparer); int sortorder = 0; foreach (PXResult item in list) { sortorder++; Table line = PXResult.Unwrap <Table>(item); if (line.SortOrder != sortorder) { Cache.SetValue(line, nameof(ISortOrder.SortOrder), sortorder); Cache.SmartSetStatus(line, PXEntryStatus.Updated); Cache.IsDirty = true; } } View.Clear(); //clears stored cache so that grid lines are reordered. }
public virtual IEnumerable Right(PXAdapter adapter) { INCategory current = Item.SelectWindowed(0, 1, CurrentSelected.FolderID); if (current != null) { int currentItemIndex; PXResultset <INCategory> items = SelectSiblings(current.ParentID, current.CategoryID, out currentItemIndex); if (currentItemIndex > 0) { INCategory prev = items[currentItemIndex - 1]; items = SelectSiblings(prev.CategoryID); int index = 1; if (items.Count > 0) { INCategory last = items[items.Count - 1]; index = (last.SortOrder ?? 0) + 1; } current = (INCategory)Items.Cache.CreateCopy(current); current.ParentID = prev.CategoryID; current.SortOrder = index; Items.Update(current); PXSelect <INCategory, Where <INCategory.parentID, Equal <Required <INCategory.categoryID> > > > .Clear(this); } } return(adapter.Get()); }
private bool SearchForMatchingChild(Guid?GroupID) { PXResultset <GLBudgetTree> childGroups = PXSelect <GLBudgetTree, Where <GLBudgetTree.parentGroupID, Equal <Required <GLBudgetTree.parentGroupID> >, And <GLBudgetTree.isGroup, Equal <True> > > > .Select(this, GroupID); if (PXSelect <GLBudgetTree, Where <GLBudgetTree.groupID, Equal <Required <GLBudgetTree.groupID> >, And <Match <Current <AccessInfo.userName> > > > > .Select(this, GroupID).Count == 0) { if (PXSelect <GLBudgetTree, Where <GLBudgetTree.parentGroupID, Equal <Required <GLBudgetTree.parentGroupID> >, And <Match <Current <AccessInfo.userName> > > > > .Select(this, GroupID).Count == 0) { foreach (GLBudgetTree childGroup in childGroups) { if (SearchForMatchingChild(childGroup.GroupID)) { return(true); } } } else { return(true); } } else { return(true); } return(false); }
protected virtual IEnumerable classificationMapping() { PXResultset <KNSIKCClassificationsMapping> existingMapping = PXSelect <KNSIKCClassificationsMapping> .Select(this); PXResultset <INItemClass> allItemClasses = PXSelect <INItemClass> .Select(this); List <int?> existingItemClasses = new List <int?>(); allItemClasses.RowCast <INItemClass>().ForEach(x => existingItemClasses.Add(x.ItemClassID)); foreach (KNSIKCClassificationsMapping clasMapping in existingMapping) { if (!existingItemClasses.Contains(clasMapping.ItemClassID)) { ClassificationMapping.Delete(clasMapping); } } foreach (INItemClass itemClass in allItemClasses) { if (existingMapping.RowCast <KNSIKCClassificationsMapping>().Any(x => x.ItemClassID == itemClass.ItemClassID)) { yield return(existingMapping.RowCast <KNSIKCClassificationsMapping>().Where(x => x.ItemClassID == itemClass.ItemClassID).FirstOrDefault()); } else { yield return(ClassificationMapping.Insert(new KNSIKCClassificationsMapping() { ItemClassID = itemClass.ItemClassID, IsMapped = null, ClassificationID = null })); } } }
/// <summary> /// Returns the set of contacts of a customer. /// </summary> private static PXResultset <Contact> ReturnsContactList(PXGraph graph, int?appointmentID) { FSServiceOrder fsServiceOrderRow = (FSServiceOrder)PXSelectJoin <FSServiceOrder, InnerJoin <FSAppointment, On < FSServiceOrder.sOID, Equal <FSAppointment.sOID>, And < FSServiceOrder.srvOrdType, Equal <FSAppointment.srvOrdType> > > >, Where < FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > > .Select(graph, appointmentID); if (fsServiceOrderRow == null || fsServiceOrderRow.CustomerID == null) { return(null); } PXResultset <Contact> bqlResultSet = PXSelect <Contact, Where < Contact.bAccountID, Equal <Required <Contact.bAccountID> >, And < Contact.contactType, Equal <ContactTypesAttribute.person>, And < Contact.isActive, Equal <True> > > > > .Select(graph, fsServiceOrderRow.CustomerID); return(bqlResultSet); }
protected virtual void Ledger_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { Ledger ledger = e.Row as Ledger; if (ledger != null && ledger.LedgerID.HasValue) { //Type and Currency are forbidden for changses for the used accounts bool hasHistory = GLUtility.IsLedgerHistoryExist(this, ledger.LedgerID); PXUIFieldAttribute.SetEnabled <Ledger.balanceType>(LedgerRecords.Cache, ledger, !hasHistory); PXUIFieldAttribute.SetEnabled <Ledger.baseCuryID>(LedgerRecords.Cache, ledger, !hasHistory && PXAccess.FeatureInstalled <FeaturesSet.multicurrency>()); } if (ledger != null) { PXUIFieldAttribute.SetEnabled <Ledger.postInterCompany>(cache, e.Row, ledger.BalanceType == LedgerBalanceType.Actual && ledger.DefBranchID != null); PXUIFieldAttribute.SetEnabled <Ledger.defBranchID>(cache, e.Row, ledger.BalanceType == LedgerBalanceType.Actual); if (ledger.BalanceType == LedgerBalanceType.Actual && ledger.DefBranchID != null) { using (new PXReadBranchRestrictedScope()) { GLHistory hist = PXSelectReadonly <GLHistory, Where <GLHistory.ledgerID, Equal <Current <Ledger.ledgerID> >, And <GLHistory.branchID, Equal <Current <Ledger.defBranchID> > > > > .SelectWindowed(this, 0, 1); PXResultset <GLHistory> hist2 = PXSelectGroupBy <GLHistory, Where <GLHistory.ledgerID, Equal <Current <Ledger.ledgerID> > >, Aggregate <GroupBy <GLHistory.branchID> > > .Select(this); PXUIFieldAttribute.SetEnabled <Ledger.postInterCompany>(cache, e.Row, (hist2.Count <= 1)); PXUIFieldAttribute.SetEnabled <Ledger.defBranchID>(cache, e.Row, (hist == null)); } } } }
protected virtual bool IsAttributeDefaultRowColumnAttribute(CSAttributeGroup attributeGroup, out string templateIDs) { const int MaxTemplates = 10; const string Separator = ", "; if (attributeGroup?.EntityType != typeof(InventoryItem).FullName) { templateIDs = null; return(false); } PXResultset <InventoryItem> template = PXSelect <InventoryItem, Where <InventoryItem.isTemplate, Equal <True>, And <InventoryItem.itemClassID, Equal <Required <CSAttributeGroup.entityClassID> >, And <Where <InventoryItem.defaultColumnMatrixAttributeID, Equal <Required <CSAttributeGroup.attributeID> >, Or <InventoryItem.defaultRowMatrixAttributeID, Equal <Required <CSAttributeGroup.attributeID> > > > > > > > .SelectWindowed(Base, 0, MaxTemplates, attributeGroup.EntityClassID, attributeGroup.AttributeID, attributeGroup.AttributeID); if (template.Count == 0) { templateIDs = null; return(false); } templateIDs = string.Join(Separator, template.RowCast <InventoryItem>().Select(s => s.InventoryCD)); return(true); }
public static string PeriodPlusPeriod(PXGraph graph, string FiscalPeriodID, int counter, int?BookID) { FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .Select(graph, BookID); IYearSetup setup; if (book.UpdateGL == true) { setup = (FinYearSetup)PXSelect <FinYearSetup> .Select(graph); } else { setup = (FABookYearSetup)PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABookYearSetup.bookID> > > > .Select(graph, BookID); } IPeriodSetup periodsInYear; if (book.UpdateGL == true) { periodsInYear = (FinPeriodSetup)PXSelectGroupBy <FinPeriodSetup, Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >, Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(graph); } else { periodsInYear = (FABookPeriodSetup)PXSelectGroupBy <FABookPeriodSetup, Where <FABookPeriodSetup.endDate, Greater <FABookPeriodSetup.startDate>, And <FABookPeriodSetup.bookID, Equal <Required <FABookPeriodSetup.bookID> > > >, Aggregate <Max <FABookPeriodSetup.periodNbr> > > .Select(graph, BookID); } if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) && periodsInYear != null && periodsInYear.PeriodNbr != null) { return(OffsetPeriod(graph, FiscalPeriodID, counter, Convert.ToInt32(periodsInYear.PeriodNbr))); } else if (counter > 0) { PXResultset <FABookPeriod> res = PXSelect <FABookPeriod, Where <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> > > > >, OrderBy <Asc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, counter, FiscalPeriodID, BookID); if (res.Count < counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else if (counter < 0) { PXResultset <FABookPeriod> res = PXSelect <FABookPeriod, Where <FABookPeriod.finPeriodID, Less <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> > > > >, OrderBy <Desc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, -counter, FiscalPeriodID, BookID); if (res.Count < -counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else { return(FiscalPeriodID); } }
protected virtual void INKitSpecNonStkDet_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { INKitSpecNonStkDet row = e.Row as INKitSpecNonStkDet; if (row == null) { return; } if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete) { return; } PXSelectBase <INKitSpecNonStkDet> select = new PXSelect <INKitSpecNonStkDet, Where <INKitSpecNonStkDet.kitInventoryID, Equal <Current <INKitSpecHdr.kitInventoryID> >, And <INKitSpecNonStkDet.revisionID, Equal <Current <INKitSpecHdr.revisionID> >, And <INKitSpecNonStkDet.compInventoryID, Equal <Required <INKitSpecStkDet.compInventoryID> > > > > >(this); PXResultset <INKitSpecNonStkDet> res = select.Select(row.CompInventoryID); if (res.Count > 1) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, row.CompInventoryID); if (sender.RaiseExceptionHandling <INKitSpecNonStkDet.compInventoryID>(e.Row, item.InventoryCD, new PXException(Messages.KitItemMustBeUnique))) { throw new PXRowPersistingException(typeof(INKitSpecNonStkDet.compInventoryID).Name, item.InventoryCD, Messages.KitItemMustBeUnique); } } }
protected virtual IEnumerable resultRecords() { InventoryTranByAcctEnqFilter filter = Filter.Current; int startRow = 0; int totalRows = 0; PXResultset <InventoryTranByAcctEnqResult> usortedList = InternalResultRecords.Select(); if (usortedList.Count == 0) { return(usortedList); } decimal beginBalance = ((InventoryTranByAcctEnqResult)usortedList[0]).BegBalance ?? 0m; List <object> list = InternalResultRecords.View.Select(PXView.Currents, PXView.Parameters, new object[PXView.SortColumns.Length], PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, 0, ref totalRows); foreach (PXResult <InventoryTranByAcctEnqResult> item in list) { InventoryTranByAcctEnqResult it = (InventoryTranByAcctEnqResult)item; it.BegBalance = beginBalance; decimal?debit = it.Debit; decimal?credit = it.Credit; beginBalance += (debit ?? 0m) - (credit ?? 0m); it.EndBalance = beginBalance; } return(list); }
private CurrencyRate FindCurrencyRate(string fromCury, string toCury, string rateType, DateTime effectiveDate) { ConcurrentBag <CurrencyRate> rates = GetCachedCurrencyRates(); CM.CurrencyRate foundRate = FindCurrencyRate(rates, fromCury, toCury, rateType, (DateTime)effectiveDate); if (foundRate == null) { PXGraph graph = new PXGraph(); PXResultset <CurrencyRate> currencyRates = PXSelect <CurrencyRate, Where <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >, And <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >, And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >, And <CurrencyRate.curyEffDate, GreaterEqual <Required <CurrencyRate.curyEffDate> > > > > >, OrderBy <Asc <CM.CurrencyRate.curyEffDate> > > .SelectWindowed(graph, 0, 100, fromCury, toCury, rateType, effectiveDate); if (currencyRates.Count == 0) { currencyRates = PXSelect <CurrencyRate, Where <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >, And <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >, And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >, And <CurrencyRate.curyEffDate, Less <Required <CurrencyRate.curyEffDate> > > > > >, OrderBy <Desc <CurrencyRate.curyEffDate> > > .SelectWindowed(graph, 0, 1, fromCury, toCury, rateType, effectiveDate); } foreach (CurrencyRate rate in currencyRates) { ((IProducerConsumerCollection <CurrencyRate>)rates).TryAdd(rate); } foundRate = FindCurrencyRate(rates, fromCury, toCury, rateType, (DateTime)effectiveDate); } return(foundRate); }
/// <summary> Get Current Value to Report Parameter </summary> public Dictionary <string, string> GetCurrentRowToParameter(bool isOutter = false) { var _CurrentRow = this.GetCacheCurrent <LumShipmentPlan>().Current; PXResultset <InventoryItem> data = SelectFrom <InventoryItem> .LeftJoin <INItemXRef> .On <INItemXRef.inventoryID.IsEqual <InventoryItem.inventoryID> > .LeftJoin <CSAnswers> .On <InventoryItem.noteID.IsEqual <CSAnswers.refNoteID> > .Where <InventoryItem.inventoryID.IsEqual <P.AsInt> > .View.Select(this, _CurrentRow.InventoryID); PXResult <AMProdItem, SOLine> soData = (PXResult <AMProdItem, SOLine>)SelectFrom <AMProdItem> .LeftJoin <SOLine> .On <AMProdItemExt.usrSOLineNbr.IsEqual <SOLine.lineNbr> .And <AMProdItemExt.usrSOOrderNbr.IsEqual <SOLine.orderNbr> > .And <AMProdItemExt.usrSOOrderType.IsEqual <SOLine.orderType> > > .Where <AMProdItem.prodOrdID.IsEqual <P.AsString> > .View.Select(this, _CurrentRow.ProdOrdID); var ENDCDescr = new PXGraph().Select <CSAttributeDetail>().Where(x => x.ValueID == _CurrentRow.Customer).FirstOrDefault()?.Description; ENDCDescr = ENDCDescr ?? _CurrentRow.Customer; Dictionary <string, string> parameters = new Dictionary <string, string> { ["ShipmentPlanID"] = _CurrentRow.ShipmentPlanID, ["ProdOrdID"] = _CurrentRow.ProdOrdID, ["Customer"] = ENDCDescr, ["CustomerPartNo"] = soData.GetItem <SOLine>()?.AlternateID, ["Description"] = data.FirstOrDefault().GetItem <InventoryItem>().Descr, ["Resistor"] = data.RowCast <CSAnswers>().Where(x => x.AttributeID == "RESISTOR").FirstOrDefault()?.Value, ["DATE"] = _CurrentRow.PlannedShipDate?.ToString("yyyy/MM/dd") }; return(parameters); }
public virtual void IIProductLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { IIProductLine cfg = e.Row as IIProductLine; if ((cfg == null) || (cfg.ProductLineID == null)) { return; } PXResultset <IIProductLineFilter> rsFilters = PXSelect <IIProductLineFilter, Where <IIProductLineFilter.productLineID, Equal <Current <IIProductLine.productLineID> > >, OrderBy <Asc <IIProductLineFilter.sortOrder> > > .Select(this, cfg.ProductLineID); foreach (ItemPickerMapping im in ItemPickerMappings.Select()) { if ( (rsFilters?.Count >= 1) && (im.Column1 == "" || im.Column1 == null) || (rsFilters?.Count >= 2) && (im.Column2 == "" || im.Column2 == null) || (rsFilters?.Count >= 3) && (im.Column3 == "" || im.Column3 == null) || (rsFilters?.Count >= 4) && (im.Column4 == "" || im.Column4 == null) || (rsFilters?.Count >= 5) && (im.Column5 == "" || im.Column5 == null) || (rsFilters?.Count >= 6) && (im.Column6 == "" || im.Column6 == null) || (rsFilters?.Count >= 7) && (im.Column7 == "" || im.Column7 == null) || (rsFilters?.Count >= 8) && (im.Column8 == "" || im.Column8 == null) || (rsFilters?.Count >= 9) && (im.Column9 == "" || im.Column9 == null) ) { throw new PXException("All values in mapping columns must be specified. Provide correct values for mapping and then save the form."); } } }
protected virtual void INTran_ProjectID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { INTran row = e.Row as INTran; if (row == null) { return; } if (PM.ProjectAttribute.IsPMVisible(this, BatchModule.IN)) { if (row.LocationID != null) { PXResultset <INLocation> result = PXSelectJoin <INLocation, LeftJoin <PMProject, On <PMProject.contractID, Equal <INLocation.projectID> > >, Where <INLocation.siteID, Equal <Required <INLocation.siteID> >, And <INLocation.locationID, Equal <Required <INLocation.locationID> > > > > .Select(sender.Graph, row.SiteID, row.LocationID); foreach (PXResult <INLocation, PMProject> res in result) { PMProject project = (PMProject)res; if (project != null && project.ContractCD != null && project.VisibleInIN == true) { e.NewValue = project.ContractCD; return; } } } } }
protected virtual void INTran_TaskID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { INTran row = e.Row as INTran; if (row == null) { return; } if (PM.ProjectAttribute.IsPMVisible(this, BatchModule.IN)) { if (row.LocationID != null) { PXResultset <INLocation> result = PXSelectJoin <INLocation, LeftJoin <PMTask, On <PMTask.projectID, Equal <INLocation.projectID>, And <PMTask.taskID, Equal <INLocation.taskID> > > >, Where <INLocation.siteID, Equal <Required <INLocation.siteID> >, And <INLocation.locationID, Equal <Required <INLocation.locationID> > > > > .Select(sender.Graph, row.SiteID, row.LocationID); foreach (PXResult <INLocation, PMTask> res in result) { PMTask task = (PMTask)res; if (task != null && task.TaskCD != null && task.VisibleInIN == true && task.IsActive == true) { e.NewValue = task.TaskCD; return; } } } } }
public static ICarrierService CreateCarrierService(PXGraph graph, CarrierPlugin plugin) { ICarrierService service = null; if (!string.IsNullOrEmpty(plugin.PluginTypeName)) { try { Type carrierType = PXBuildManager.GetType(plugin.PluginTypeName, true); service = (ICarrierService)Activator.CreateInstance(carrierType); PXSelectBase <CarrierPluginDetail> select = new PXSelect <CarrierPluginDetail, Where <CarrierPluginDetail.carrierPluginID, Equal <Required <CarrierPluginDetail.carrierPluginID> > > >(graph); PXResultset <CarrierPluginDetail> resultset = select.Select(plugin.CarrierPluginID); IList <ICarrierDetail> list = new List <ICarrierDetail>(resultset.Count); foreach (CarrierPluginDetail item in resultset) { list.Add(item); } service.LoadSettings(list); } catch (Exception ex) { throw new PXException(Messages.FailedToCreateCarrierPlugin, ex.Message); } } return(service); }
public virtual IEnumerable Right(PXAdapter adapter) { EPCompanyTreeMaster current = Item.SelectWindowed(0, 1, CurrentSelected.FolderID); if (current != null) { int currentItemIndex; PXResultset <EPCompanyTreeMaster> items = SelectSiblings(current.ParentWGID, current.WorkGroupID, out currentItemIndex); if (currentItemIndex > 0) { EPCompanyTreeMaster prev = items[currentItemIndex - 1]; items = SelectSiblings(prev.WorkGroupID); int index = 1; if (items.Count > 0) { EPCompanyTreeMaster last = items[items.Count - 1]; index = (last.SortOrder ?? 0) + 1; } current = (EPCompanyTreeMaster)Items.Cache.CreateCopy(current); current.ParentWGID = prev.WorkGroupID; current.SortOrder = index; Items.Update(current); } } return(adapter.Get()); }
public virtual void CopyOrderProc(SOOrder order, CopyParamFilter copyFilter, CopyOrderProcDelegate baseMethod) { RUTROT rutrotRecord = null; PXResultset <RUTROTDistribution> rutrotDistribution = null; SOOrderRUTROT orderRR = RUTROTHelper.GetExtensionNullable <SOOrder, SOOrderRUTROT>(order); if (RUTROTHelper.IsRUTROTcompatibleType(order.OrderType) && orderRR?.IsRUTROTDeductible == true) { rutrotRecord = Rutrots.SelectSingle(); rutrotDistribution = RRDistribution.Select(); } baseMethod(order, copyFilter); if (RUTROTHelper.IsRUTROTcompatibleType(copyFilter.OrderType) && rutrotRecord != null && rutrotDistribution != null) { rutrotRecord = (RUTROT)Rutrots.Cache.CreateCopy(rutrotRecord); rutrotRecord.RefNbr = Base.Document.Current.OrderNbr; rutrotRecord.DocType = Base.Document.Current.OrderType; rutrotRecord.CuryDistributedAmt = 0m; rutrotRecord.CuryUndistributedAmt = 0m; rutrotRecord = Rutrots.Update(rutrotRecord); foreach (RUTROTDistribution distribution in rutrotDistribution) { RUTROTDistribution new_distribution = (RUTROTDistribution)RRDistribution.Cache.CreateCopy(distribution); new_distribution.RefNbr = null; new_distribution.DocType = null; RRDistribution.Insert(new_distribution); } } else { Base.Document.Cache.SetValueExt <SOOrderRUTROT.isRUTROTDeductible>(Base.Document.Current, false); Base.Document.Update(Base.Document.Current); } }
protected virtual IEnumerable lines() { if (Vendor.Current == null || Vendor.Current.VendorLocationID == null) { yield break; } using (ReadOnlyScope scope = new ReadOnlyScope(Lines.Cache)) { bool reset = !Bidding.Cache.IsDirty; PXResultset <RQRequisitionLineBidding> list = PXSelectJoin <RQRequisitionLineBidding, LeftJoin <RQBidding, On <RQBidding.reqNbr, Equal <RQRequisitionLineBidding.reqNbr>, And <RQBidding.lineNbr, Equal <RQRequisitionLineBidding.lineNbr>, And <RQBidding.vendorID, Equal <Current <RQBiddingVendor.vendorID> >, And <RQBidding.vendorLocationID, Equal <Current <RQBiddingVendor.vendorLocationID> > > > > > >, Where <RQRequisitionLineBidding.reqNbr, Equal <Current <RQBiddingVendor.reqNbr> > > > .Select(this); if (reset) { Lines.Cache.Clear(); } foreach (PXResult <RQRequisitionLineBidding, RQBidding> item in list) { RQRequisitionLineBidding result = PrepareRQRequisitionLineBiddingInViewDelegate(item); yield return(result); } } }
public virtual void InvoiceOrder(DateTime invoiceDate, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset<SOShipLine, SOLine> details, Customer customer, DocumentList<ARInvoice, SOInvoice> list) { ARInvoice newdoc; SOOrder soOrder = order; SOOrderType ordertype = order; decimal ApprovedBalance = 0; decimal PrevDocBal = 0; PXRowUpdated ApprovedBalanceCollector = delegate(PXCache sender, PXRowUpdatedEventArgs e) { ARInvoice ARDoc = (ARInvoice)e.Row; if ((decimal)ARDoc.DocBal > (decimal)ARDoc.ApprovedCreditAmt) { if ((bool)((SOOrder)order).ApprovedCredit && (decimal)ARDoc.DocBal > PrevDocBal) { ApprovedBalance += (decimal)ARDoc.DocBal - PrevDocBal; ARDoc.ApprovedCreditAmt = ApprovedBalance; } ARDoc.ApprovedCredit = (ApprovedBalance == (decimal)ARDoc.DocBal ? true : false); PrevDocBal = (decimal)ARDoc.DocBal; } }; this.RowUpdated.AddHandler(typeof(ARInvoice), ApprovedBalanceCollector); if (list != null) { bool iscc = false; DateTime? orderInvoiceDate = (sosetup.Current.UseShipDateForInvoiceDate == true ? ((SOOrderShipment)order).ShipDate : soOrder.InvoiceDate); if (soOrder.BillSeparately == false) { iscc = PXSelectReadonly<CCProcTran, Where<CCProcTran.origDocType, Equal<Required<CCProcTran.origDocType>>, And<CCProcTran.origRefNbr, Equal<Required<CCProcTran.origRefNbr>>, And<CCProcTran.refNbr, IsNull>>>>.Select(this, soOrder.OrderType, soOrder.OrderNbr).Count > 0; } if (soOrder.PaymentCntr == 0 && soOrder.BillSeparately == false && iscc == false) { if(soOrder.PaymentMethodID == null && soOrder.CashAccountID == null) newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); else if (soOrder.CashAccountID == null) newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.pMInstanceID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.PMInstanceID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); else newdoc = list.Find<ARInvoice.docType, ARInvoice.docDate, ARInvoice.branchID, ARInvoice.customerID, ARInvoice.customerLocationID, SOInvoice.billAddressID, SOInvoice.billContactID, SOInvoice.pMInstanceID, SOInvoice.cashAccountID, SOInvoice.extRefNbr, ARInvoice.curyID, ARInvoice.termsID, ARInvoice.hidden>(((SOOrderType)order).ARDocType, orderInvoiceDate ?? invoiceDate, soOrder.BranchID, soOrder.CustomerID, soOrder.CustomerLocationID, soOrder.BillAddressID, soOrder.BillContactID, soOrder.PMInstanceID, soOrder.CashAccountID, soOrder.ExtRefNbr, soOrder.CuryID, soOrder.TermsID, false) ?? (ARInvoice)new ARInvoice(); } else { newdoc = list.Find<ARInvoice.hidden, ARInvoice.hiddenOrderType, ARInvoice.hiddenOrderNbr>(true, soOrder.OrderType, soOrder.OrderNbr); if (newdoc == null) { newdoc = new ARInvoice(); newdoc.HiddenOrderType = soOrder.OrderType; newdoc.HiddenOrderNbr = soOrder.OrderNbr; newdoc.Hidden = true; } } if (newdoc.RefNbr != null) { Document.Current = this.Document.Search<ARInvoice.refNbr>(newdoc.RefNbr, newdoc.DocType); } else { this.Clear(); string docType = ((SOOrderType)order).ARDocType; if (((SOOrderShipment)order).Operation == ((SOOrderType)order).DefaultOperation) { newdoc.DocType = docType; } else { //for RMA switch document type if previous shipment was not invoiced previously in the current run, i.e. list.Find() returned null newdoc.DocType = docType == ARDocType.Invoice ? ARDocType.CreditMemo : docType == ARDocType.DebitMemo ? ARDocType.CreditMemo : docType == ARDocType.CreditMemo ? ARDocType.Invoice : docType == ARDocType.CashSale ? ARDocType.CashReturn : docType == ARDocType.CashReturn ? ARDocType.CashSale : null; } newdoc.DocDate = orderInvoiceDate ?? invoiceDate; if (string.IsNullOrEmpty(soOrder.FinPeriodID) == false) { newdoc.FinPeriodID = soOrder.FinPeriodID; } if (soOrder.InvoiceNbr != null) { newdoc.RefNbr = soOrder.InvoiceNbr; newdoc.RefNoteID = soOrder.NoteID; } if (((SOOrderType)order).UserInvoiceNumbering == true && string.IsNullOrEmpty(newdoc.RefNbr)) { throw new PXException(ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName<SOOrder.invoiceNbr>(soorder.Cache)); } AutoNumberAttribute.SetNumberingId<ARInvoice.refNbr>(Document.Cache, ((SOOrderType)order).ARDocType, ((SOOrderType)order).InvoiceNumberingID); newdoc = (ARInvoice)Document.Cache.CreateCopy(this.Document.Insert(newdoc)); newdoc.BranchID = soOrder.BranchID; newdoc.CustomerID = ((SOOrder)order).CustomerID; newdoc.CustomerLocationID = ((SOOrder)order).CustomerLocationID; newdoc.TermsID = ((SOOrder)order).TermsID; newdoc.DiscDate = ((SOOrder)order).DiscDate; newdoc.DueDate = ((SOOrder)order).DueDate; newdoc.TaxZoneID = ((SOOrder)order).TaxZoneID; newdoc.AvalaraCustomerUsageType = ((SOOrder)order).AvalaraCustomerUsageType; newdoc.SalesPersonID = ((SOOrder)order).SalesPersonID; newdoc.DocDesc = ((SOOrder)order).OrderDesc; newdoc.InvoiceNbr = ((SOOrder)order).CustomerOrderNbr; newdoc.CuryID = ((SOOrder)order).CuryID; newdoc.ProjectID = ((SOOrder)order).ProjectID ?? PM.ProjectDefaultAttribute.NonProject(this); newdoc.Hold = ordertype.InvoiceHoldEntry; if (((SOOrderType)order).MarkInvoicePrinted == true) { newdoc.Printed = true; } if (((SOOrderType)order).MarkInvoiceEmailed == true) { newdoc.Emailed = true; } if (soOrder.PMInstanceID != null || string.IsNullOrEmpty(soOrder.PaymentMethodID) == false) { newdoc.PMInstanceID = soOrder.PMInstanceID; newdoc.PaymentMethodID = soOrder.PaymentMethodID; newdoc.CashAccountID = soOrder.CashAccountID; } newdoc = this.Document.Update(newdoc); if (soOrder.PMInstanceID != null || string.IsNullOrEmpty(soOrder.PaymentMethodID) == false) { SODocument.Current.PMInstanceID = soOrder.PMInstanceID; SODocument.Current.PaymentMethodID = soOrder.PaymentMethodID; SODocument.Current.CashAccountID = soOrder.CashAccountID; if(SODocument.Current.CashAccountID == null) SODocument.Cache.SetDefaultExt<SOInvoice.cashAccountID>(SODocument.Current); SODocument.Current.ExtRefNbr = soOrder.ExtRefNbr; //clear error in case invoice currency different from default cash account for customer SODocument.Cache.RaiseExceptionHandling<SOInvoice.cashAccountID>(SODocument.Current, null, null); } foreach (CurrencyInfo info in this.currencyinfo.Select()) { if (((SOOrder)order).InvoiceDate != null) { PXCache<CurrencyInfo>.RestoreCopy(info, (CurrencyInfo)order); info.CuryInfoID = newdoc.CuryInfoID; } } AddressAttribute.CopyRecord<ARInvoice.billAddressID>(this.Document.Cache, newdoc, (SOAddress)order, true); ContactAttribute.CopyRecord<ARInvoice.billContactID>(this.Document.Cache, newdoc, (SOContact)order, true); } } else { newdoc = (ARInvoice)Document.Cache.CreateCopy(Document.Current); if (Transactions.SelectSingle() == null) { newdoc.CustomerID = ((SOOrder)order).CustomerID; newdoc.ProjectID = ((SOOrder)order).ProjectID; newdoc.CustomerLocationID = ((SOOrder)order).CustomerLocationID; newdoc.SalesPersonID = ((SOOrder)order).SalesPersonID; newdoc.TaxZoneID = ((SOOrder)order).TaxZoneID; newdoc.AvalaraCustomerUsageType = ((SOOrder)order).AvalaraCustomerUsageType; newdoc.DocDesc = ((SOOrder)order).OrderDesc; newdoc.InvoiceNbr = ((SOOrder)order).CustomerOrderNbr; newdoc.TermsID = ((SOOrder)order).TermsID; foreach (CurrencyInfo info in this.currencyinfo.Select()) { PXCache<CurrencyInfo>.RestoreCopy(info, (CurrencyInfo)order); info.CuryInfoID = newdoc.CuryInfoID; newdoc.CuryID = info.CuryID; } } newdoc = this.Document.Update(newdoc); AddressAttribute.CopyRecord<ARInvoice.billAddressID>(this.Document.Cache, newdoc, (SOAddress)order, true); ContactAttribute.CopyRecord<ARInvoice.billContactID>(this.Document.Cache, newdoc, (SOContact)order, true); } PXSelectBase<SOInvoiceDiscountDetail> selectInvoiceDiscounts = new PXSelect<SOInvoiceDiscountDetail, Where<SOInvoiceDiscountDetail.tranType, Equal<Current<SOInvoice.docType>>, And<SOInvoiceDiscountDetail.refNbr, Equal<Current<SOInvoice.refNbr>>, And<SOInvoiceDiscountDetail.orderType, Equal<Required<SOInvoiceDiscountDetail.orderType>>, And<SOInvoiceDiscountDetail.orderNbr, Equal<Required<SOInvoiceDiscountDetail.orderNbr>>>>>>>(this); foreach (SOInvoiceDiscountDetail detail in selectInvoiceDiscounts.Select(((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { DiscountDetails.Delete(detail); } TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(this.Transactions.Cache, null, TaxCalc.ManualCalc); if (details != null) { foreach (SOShipLine shipline in details) { this.Caches[typeof(SOShipLine)].Insert(shipline); } } DateTime? origInvoiceDate = null; foreach (PXResult<SOShipLine, SOLine, SOOrderTypeOperation, ARTran> res in PXSelectJoin<SOShipLine, InnerJoin<SOLine, On<SOLine.orderType, Equal<SOShipLine.origOrderType>, And<SOLine.orderNbr, Equal<SOShipLine.origOrderNbr>, And<SOLine.lineNbr, Equal<SOShipLine.origLineNbr>>>>, InnerJoin<SOOrderTypeOperation, On<SOOrderTypeOperation.orderType, Equal<SOLine.orderType>, And<SOOrderTypeOperation.operation, Equal<SOLine.operation>>>, LeftJoin<ARTran, On<ARTran.sOShipmentNbr, Equal<SOShipLine.shipmentNbr>, And<ARTran.sOShipmentType, Equal<SOShipLine.shipmentType>, And<ARTran.sOShipmentLineNbr, Equal<SOShipLine.lineNbr>, And<ARTran.sOOrderType, Equal<SOShipLine.origOrderType>, And<ARTran.sOOrderNbr, Equal<SOShipLine.origOrderNbr>, And<ARTran.sOOrderLineNbr, Equal<SOShipLine.origLineNbr>>>>>>>>>>, Where<SOShipLine.shipmentNbr, Equal<Required<SOShipLine.shipmentNbr>>, And<SOShipLine.origOrderType, Equal<Required<SOShipLine.origOrderType>>, And<SOShipLine.origOrderNbr, Equal<Required<SOShipLine.origOrderNbr>>, And<ARTran.refNbr, IsNull>>>>>.Select(this, ((SOOrderShipment)order).ShipmentNbr, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOLine orderline = (SOLine)res; SOShipLine shipline = (SOShipLine)res; if (Math.Abs((decimal)shipline.BaseShippedQty) < 0.0000005m) { continue; } if (origInvoiceDate == null && orderline.InvoiceDate != null) origInvoiceDate = orderline.InvoiceDate; ARTran newtran = new ARTran(); newtran.BranchID = orderline.BranchID; newtran.AccountID = orderline.SalesAcctID; newtran.SubID = orderline.SalesSubID; newtran.SOOrderType = shipline.OrigOrderType; newtran.SOOrderNbr = shipline.OrigOrderNbr; newtran.SOOrderLineNbr = shipline.OrigLineNbr; newtran.SOShipmentNbr = shipline.ShipmentNbr; newtran.SOShipmentType = shipline.ShipmentType; newtran.SOShipmentLineNbr = shipline.LineNbr; newtran.LineType = orderline.LineType; newtran.InventoryID = shipline.InventoryID; newtran.SiteID = orderline.SiteID; newtran.UOM = shipline.UOM; newtran.Qty = shipline.ShippedQty; newtran.BaseQty = shipline.BaseShippedQty; newtran.Commissionable = orderline.Commissionable; newtran.GroupDiscountRate = orderline.GroupDiscountRate; decimal shippedQtyInBaseUnits = INUnitAttribute.ConvertToBase(Transactions.Cache, newtran.InventoryID, shipline.UOM, shipline.ShippedQty.Value, INPrecision.QUANTITY); decimal shippedQtyInOrderUnits = INUnitAttribute.ConvertFromBase(Transactions.Cache, newtran.InventoryID, orderline.UOM, shippedQtyInBaseUnits, INPrecision.QUANTITY); if (shippedQtyInOrderUnits != orderline.OrderQty || shipline.UOM != orderline.UOM) { decimal curyUnitPriceInBaseUnits = INUnitAttribute.ConvertFromBase(Transactions.Cache, newtran.InventoryID, orderline.UOM, orderline.CuryUnitPrice.Value, INPrecision.UNITCOST); decimal curyUnitPriceInShippedUnits = INUnitAttribute.ConvertToBase(Transactions.Cache, newtran.InventoryID, shipline.UOM, curyUnitPriceInBaseUnits, INPrecision.UNITCOST); if (arsetup.Current.LineDiscountTarget == LineDiscountTargetType.SalesPrice) { decimal? salesPriceAfterDiscount = curyUnitPriceInShippedUnits * (1m - orderline.DiscPct / 100m); newtran.CuryTranAmt = shipline.ShippedQty * PXCurrencyAttribute.Round(Transactions.Cache, newtran, salesPriceAfterDiscount ?? 0, CMPrecision.TRANCURY); } else { decimal? curyTranAmt = shipline.ShippedQty * curyUnitPriceInShippedUnits * (1m - orderline.DiscPct / 100m); newtran.CuryTranAmt = PXCurrencyAttribute.Round(Transactions.Cache, newtran, curyTranAmt ?? 0, CMPrecision.TRANCURY); } newtran.CuryUnitPrice = curyUnitPriceInShippedUnits; newtran.CuryDiscAmt = (shipline.ShippedQty * curyUnitPriceInShippedUnits) - newtran.CuryTranAmt; } else { newtran.CuryUnitPrice = orderline.CuryUnitPrice; newtran.CuryTranAmt = orderline.CuryLineAmt; newtran.CuryDiscAmt = orderline.CuryDiscAmt; } if (newdoc.DocType == ((SOOrderType)order).ARDocType && ((SOOrderType)order).DefaultOperation != ((SOOrderTypeOperation)res).Operation) { //keep BaseQty positive for PXFormula newtran.Qty = -newtran.Qty; newtran.CuryDiscAmt = -newtran.CuryDiscAmt; newtran.CuryTranAmt = -newtran.CuryTranAmt; } newtran.ProjectID = orderline.ProjectID; newtran.TaskID = orderline.TaskID; newtran.TranDesc = orderline.TranDesc; newtran.SalesPersonID = orderline.SalesPersonID; newtran.TaxCategoryID = orderline.TaxCategoryID; newtran.DiscPct = orderline.DiscPct; newtran.ManualDisc = orderline.ManualDisc == true || orderline.IsFree == true; newtran.FreezeManualDisc = true; newtran.DiscountID = orderline.DiscountID; newtran.DiscountSequenceID = orderline.DiscountSequenceID; newtran.DetDiscIDC1 = orderline.DetDiscIDC1; newtran.DetDiscIDC2 = orderline.DetDiscIDC2; newtran.DetDiscSeqIDC1 = orderline.DetDiscSeqIDC1; newtran.DetDiscSeqIDC2 = orderline.DetDiscSeqIDC2; newtran.DetDiscApp = orderline.DetDiscApp; newtran.DocDiscIDC1 = orderline.DocDiscIDC1; newtran.DocDiscIDC2 = orderline.DocDiscIDC2; newtran.DocDiscSeqIDC1 = orderline.DocDiscSeqIDC1; newtran.DocDiscSeqIDC2 = orderline.DocDiscSeqIDC2; foreach (ARTran existing in Transactions.Cache.Inserted) { if (Transactions.Cache.ObjectsEqual<ARTran.sOShipmentNbr, ARTran.sOShipmentType, ARTran.sOShipmentLineNbr, ARTran.sOOrderType, ARTran.sOOrderNbr, ARTran.sOOrderLineNbr>(newtran, existing)) { Transactions.Cache.RestoreCopy(newtran, existing); break; } } if (newtran.LineNbr == null) { newtran = this.Transactions.Insert(newtran); if (((SOOrderType)order).CopyLineNotesToInvoice == true) { if (((SOOrderType)order).CopyLineNotesToInvoiceOnlyNS == false || orderline.LineType == SOLineType.NonInventory) { PXNoteAttribute.SetNote(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetNote(Caches[typeof(SOLine)], orderline)); } } if (((SOOrderType)order).CopyLineFilesToInvoice == true) { if (((SOOrderType)order).CopyLineFilesToInvoiceOnlyNS == false || orderline.LineType == SOLineType.NonInventory) { PXNoteAttribute.SetFileNotes(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetFileNotes(Caches[typeof(SOLine)], orderline)); } } } else { newtran = this.Transactions.Update(newtran); TaxAttribute.Calculate<ARTran.taxCategoryID>(Transactions.Cache, new PXRowUpdatedEventArgs(newtran, null, true)); } } PXSelectBase<ARTran> cmd = new PXSelect<ARTran, Where<ARTran.tranType, Equal<Current<ARInvoice.docType>>, And<ARTran.refNbr, Equal<Current<ARInvoice.refNbr>>, And<ARTran.sOOrderType, Equal<Current<SOMiscLine2.orderType>>, And<ARTran.sOOrderNbr, Equal<Current<SOMiscLine2.orderNbr>>, And<ARTran.sOOrderLineNbr, Equal<Current<SOMiscLine2.lineNbr>>>>>>>>(this); foreach (SOMiscLine2 orderline in PXSelect<SOMiscLine2, Where<SOMiscLine2.orderType, Equal<Required<SOMiscLine2.orderType>>, And<SOMiscLine2.orderNbr, Equal<Required<SOMiscLine2.orderNbr>>, And<Where<SOMiscLine2.curyUnbilledAmt, Greater<decimal0>, Or<SOMiscLine2.curyLineAmt, LessEqual<decimal0>>>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { if (cmd.View.SelectSingleBound(new object[] { Document.Current, orderline }) == null) { ARTran newtran = new ARTran(); newtran.BranchID = orderline.BranchID; newtran.AccountID = orderline.SalesAcctID; newtran.SubID = orderline.SalesSubID; newtran.SOOrderType = orderline.OrderType; newtran.SOOrderNbr = orderline.OrderNbr; newtran.SOOrderLineNbr = orderline.LineNbr; newtran.SOShipmentNbr = ((SOOrderShipment)order).ShipmentNbr; newtran.SOShipmentType = ((SOOrderShipment)order).ShipmentType; newtran.SOShipmentLineNbr = null; newtran.LineType = SOLineType.MiscCharge; newtran.InventoryID = orderline.InventoryID; newtran.TaskID = orderline.TaskID; newtran.SalesPersonID = orderline.SalesPersonID; newtran.Commissionable = orderline.Commissionable; newtran.UOM = orderline.UOM; newtran.Qty = orderline.UnbilledQty; newtran.BaseQty = orderline.BaseUnbilledQty; newtran.CuryUnitPrice = orderline.CuryUnitPrice; newtran.CuryDiscAmt = orderline.CuryDiscAmt; newtran.CuryTranAmt = orderline.CuryUnbilledAmt; newtran.TranDesc = orderline.TranDesc; newtran.TaxCategoryID = orderline.TaxCategoryID; newtran.DiscPct = orderline.DiscPct; newtran.ManualDisc = orderline.ManualDisc == true || orderline.IsFree == true; newtran.FreezeManualDisc = true; newtran.DiscountID = orderline.DiscountID; newtran.DiscountSequenceID = orderline.DiscountSequenceID; newtran.DetDiscIDC1 = orderline.DetDiscIDC1; newtran.DetDiscIDC2 = orderline.DetDiscIDC2; newtran.DetDiscSeqIDC1 = orderline.DetDiscSeqIDC1; newtran.DetDiscSeqIDC2 = orderline.DetDiscSeqIDC2; newtran.DetDiscApp = orderline.DetDiscApp; newtran.DocDiscIDC1 = orderline.DocDiscIDC1; newtran.DocDiscIDC2 = orderline.DocDiscIDC2; newtran.DocDiscSeqIDC1 = orderline.DocDiscSeqIDC1; newtran.DocDiscSeqIDC2 = orderline.DocDiscSeqIDC2; newtran = this.Transactions.Insert(newtran); if (((SOOrderType)order).CopyLineNotesToInvoice == true) { PXNoteAttribute.SetNote(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetNote(Caches[typeof(SOMiscLine2)], orderline)); } if (((SOOrderType)order).CopyLineFilesToInvoice == true) { PXNoteAttribute.SetFileNotes(Caches[typeof(ARTran)], newtran, PXNoteAttribute.GetFileNotes(Caches[typeof(SOMiscLine2)], orderline)); } } } SODocument.Current = (SOInvoice)SODocument.Select() ?? (SOInvoice)SODocument.Cache.Insert(); SODocument.Current.BillAddressID = soOrder.BillAddressID; SODocument.Current.BillContactID = soOrder.BillContactID; SODocument.Current.ShipAddressID = soOrder.ShipAddressID; SODocument.Current.ShipContactID = soOrder.ShipContactID; SODocument.Current.IsCCCaptured = soOrder.IsCCCaptured; SODocument.Current.IsCCCaptureFailed = soOrder.IsCCCaptureFailed; SODocument.Current.PaymentProjectID = PM.ProjectDefaultAttribute.NonProject(this); if (soOrder.IsCCCaptured == true) { SODocument.Current.CuryCCCapturedAmt = soOrder.CuryCCCapturedAmt; SODocument.Current.CCCapturedAmt = soOrder.CCCapturedAmt; } SODocument.Current.RefTranExtNbr = soOrder.RefTranExtNbr; SOOrderShipment shipment = PXCache<SOOrderShipment>.CreateCopy((SOOrderShipment)order); shipment.InvoiceType = SODocument.Current.DocType; shipment.InvoiceNbr = SODocument.Current.RefNbr; shipmentlist.Cache.Update(shipment); FillFreightDetails((SOOrder)order, shipment); /*In case Discounts were not recalculated add prorated Doc discounts */ if (ordertype.RecalculateDiscOnPartialShipment != true) { //add prorated document discount details from invoice: PXSelectBase<SOOrderDiscountDetail> selectOrderDocGroupDiscounts = new PXSelect<SOOrderDiscountDetail, Where<SOOrderDiscountDetail.orderType, Equal<Required<SOOrderDiscountDetail.orderType>>, And<SOOrderDiscountDetail.orderNbr, Equal<Required<SOOrderDiscountDetail.orderNbr>>>>>(this); decimal? rate = 1m; if (soOrder.LineTotal > 0m) rate = shipment.LineTotal / soOrder.LineTotal; foreach (SOOrderDiscountDetail docGroupDisc in selectOrderDocGroupDiscounts.Select(((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOInvoiceDiscountDetail dd = new SOInvoiceDiscountDetail(); dd.Type = docGroupDisc.Type; dd.DiscountID = docGroupDisc.DiscountID; dd.DiscountSequenceID = docGroupDisc.DiscountSequenceID; dd.OrderType = docGroupDisc.OrderType; dd.OrderNbr = docGroupDisc.OrderNbr; dd.TranType = newdoc.DocType; dd.RefNbr = newdoc.RefNbr; dd.DiscountPct = docGroupDisc.DiscountPct; dd.FreeItemID = docGroupDisc.FreeItemID; dd.FreeItemQty = docGroupDisc.FreeItemQty; if (docGroupDisc.Type == DiscountType.Group) { SOOrderEntry soOrderQ = (SOOrderEntry)PXGraph.CreateInstance(typeof(SOOrderEntry)); soOrderQ.Document.Current = order; Dictionary<DiscountSequenceKey, DiscountEngine<SOLine>.DiscountDetailToLineCorrelation<SOOrderDiscountDetail>> grLinesOrderCorrelation = DiscountEngine<SOLine>.CollectGroupDiscountToLineCorrelation(soOrderQ.Transactions.Cache, soOrderQ.Transactions, soOrderQ.DiscountDetails, soOrder.CustomerLocationID, (DateTime)soOrder.OrderDate, false); foreach (KeyValuePair<DiscountSequenceKey, DiscountEngine<SOLine>.DiscountDetailToLineCorrelation<SOOrderDiscountDetail>> dsGroup in grLinesOrderCorrelation) { if (dsGroup.Key.DiscountID == docGroupDisc.DiscountID && dsGroup.Key.DiscountSequenceID == docGroupDisc.DiscountSequenceID) { decimal invoicedGroupAmt = 0m; foreach (SOLine soLine in dsGroup.Value.listOfApplicableLines) { foreach (ARTran tran in Transactions.Select()) { if (soLine.LineNbr == tran.SOOrderLineNbr) invoicedGroupAmt += (tran.CuryLineAmt ?? 0m); } } rate = (invoicedGroupAmt / (decimal)dsGroup.Value.discountDetailLine.CuryDiscountableAmt); } } } SOInvoiceDiscountDetail located = DiscountDetails.Locate(dd); if (located != null) { located.DiscountAmt += docGroupDisc.DiscountAmt * rate; located.CuryDiscountAmt += docGroupDisc.CuryDiscountAmt * rate; located.DiscountableAmt += docGroupDisc.DiscountableAmt * rate; located.CuryDiscountableAmt += docGroupDisc.CuryDiscountableAmt * rate; located.DiscountableQty += docGroupDisc.DiscountableQty * rate; DiscountDetails.Update(located); } else { dd.DiscountAmt = docGroupDisc.DiscountAmt * rate; dd.CuryDiscountAmt = docGroupDisc.CuryDiscountAmt * rate; dd.DiscountableAmt = docGroupDisc.DiscountableAmt * rate; dd.CuryDiscountableAmt = docGroupDisc.CuryDiscountableAmt * rate; dd.DiscountableQty = docGroupDisc.DiscountableQty * rate; DiscountDetails.Insert(dd); } } } else { //Recalculate all discounts foreach (ARTran tran in Transactions.Select()) { RecalculateDiscounts(this.Transactions.Cache, tran); } } RecalculateTotalDiscount(); foreach (PXResult<SOTaxTran, Tax> res in PXSelectJoin<SOTaxTran, InnerJoin<Tax, On<SOTaxTran.taxID, Equal<Tax.taxID>>>, Where<SOTaxTran.orderType, Equal<Required<SOTaxTran.orderType>>, And<SOTaxTran.orderNbr, Equal<Required<SOTaxTran.orderNbr>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { SOTaxTran tax = (SOTaxTran)res; ARTaxTran newtax = new ARTaxTran(); newtax.Module = BatchModule.AR; Taxes.Cache.SetDefaultExt<ARTaxTran.origTranType>(newtax); Taxes.Cache.SetDefaultExt<ARTaxTran.origRefNbr>(newtax); Taxes.Cache.SetDefaultExt<ARTaxTran.lineRefNbr>(newtax); newtax.TranType = Document.Current.DocType; newtax.RefNbr = Document.Current.RefNbr; newtax.TaxID = tax.TaxID; newtax.TaxRate = 0m; this.Taxes.Delete(newtax); newtax = this.Taxes.Insert(newtax); } decimal? CuryApplAmt = 0m; bool Calculated = false; foreach (SOAdjust soadj in PXSelectJoin<SOAdjust, InnerJoin<AR.ARPayment, On<AR.ARPayment.docType, Equal<SOAdjust.adjgDocType>, And<AR.ARPayment.refNbr, Equal<SOAdjust.adjgRefNbr>>>>, Where<SOAdjust.adjdOrderType, Equal<Required<SOAdjust.adjdOrderType>>, And<SOAdjust.adjdOrderNbr, Equal<Required<SOAdjust.adjdOrderNbr>>, And<AR.ARPayment.openDoc, Equal<True>>>>>.Select(this, ((SOOrderShipment)order).OrderType, ((SOOrderShipment)order).OrderNbr)) { ARAdjust prev_adj = null; bool found = false; foreach (ARAdjust adj in Adjustments.Select()) { if (Calculated) { CuryApplAmt -= adj.CuryAdjdAmt; } if (string.Equals(adj.AdjgDocType, soadj.AdjgDocType) && string.Equals(adj.AdjgRefNbr, soadj.AdjgRefNbr)) { if (soadj.CuryAdjdAmt > 0m) { ARAdjust copy = PXCache<ARAdjust>.CreateCopy(adj); copy.CuryAdjdAmt += (soadj.CuryAdjdAmt > adj.CuryDocBal) ? adj.CuryDocBal : soadj.CuryAdjdAmt; copy.AdjdOrderType = soadj.AdjdOrderType; copy.AdjdOrderNbr = soadj.AdjdOrderNbr; prev_adj = Adjustments.Update(copy); } found = true; if (Calculated) { CuryApplAmt += adj.CuryAdjdAmt; break; } } CuryApplAmt += adj.CuryAdjdAmt; } //if soadjust is not available in adjustments mark as billed if (!found) { /* soadj.Billed = true; soadjustments.Cache.SetStatus(soadj, PXEntryStatus.Updated); */ } Calculated = true; if (!IsExternalTax) { if (CuryApplAmt > Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt && prev_adj != null) { prev_adj = PXCache<ARAdjust>.CreateCopy(prev_adj); if (prev_adj.CuryAdjdAmt > (CuryApplAmt - (Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt))) { prev_adj.CuryAdjdAmt -= (CuryApplAmt - (Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt)); CuryApplAmt = Document.Current.CuryDocBal - Document.Current.CuryOrigDiscAmt; } else { CuryApplAmt -= prev_adj.CuryAdjdAmt; prev_adj.CuryAdjdAmt = 0m; } prev_adj = Adjustments.Update(prev_adj); } } } newdoc = (ARInvoice)Document.Cache.CreateCopy(Document.Current); newdoc.OrigDocDate = origInvoiceDate; SOInvoice socopy = (SOInvoice)SODocument.Cache.CreateCopy(SODocument.Current); PXFormulaAttribute.CalcAggregate<ARAdjust.curyAdjdAmt>(Adjustments.Cache, SODocument.Current, false); Document.Cache.RaiseFieldUpdated<SOInvoice.curyPaymentTotal>(SODocument.Current, null); PXDBCurrencyAttribute.CalcBaseValues<SOInvoice.curyPaymentTotal>(SODocument.Cache, SODocument.Current); SODocument.Cache.RaiseRowUpdated(SODocument.Current, socopy); List<string> ordersdistinct = new List<string>(); foreach (SOOrderShipment shipments in PXSelect<SOOrderShipment, Where<SOOrderShipment.invoiceType, Equal<Current<ARInvoice.docType>>, And<SOOrderShipment.invoiceNbr, Equal<Current<ARInvoice.refNbr>>>>>.Select(this)) { string key = string.Format("{0}|{1}", shipments.OrderType, shipments.OrderNbr); if (!ordersdistinct.Contains(key)) { ordersdistinct.Add(key); } if (ordersdistinct.Count > 1) { newdoc.InvoiceNbr = null; newdoc.SalesPersonID = null; newdoc.DocDesc = null; break; } #region Update FreeItemQty for DiscountDetails based on shipments PXSelectBase<SOShipmentDiscountDetail> selectShipmentDiscounts = new PXSelect<SOShipmentDiscountDetail, Where<SOShipmentDiscountDetail.orderType, Equal<Required<SOShipmentDiscountDetail.orderType>>, And<SOShipmentDiscountDetail.orderNbr, Equal<Required<SOShipmentDiscountDetail.orderNbr>>, And<SOShipmentDiscountDetail.shipmentNbr, Equal<Required<SOShipmentDiscountDetail.shipmentNbr>>>>>>(this); foreach (SOShipmentDiscountDetail sdd in selectShipmentDiscounts.Select(shipments.OrderType, shipments.OrderNbr, shipments.ShipmentNbr)) { SOInvoiceDiscountDetail idd = PXSelect<SOInvoiceDiscountDetail, Where<SOInvoiceDiscountDetail.tranType, Equal<Current<ARInvoice.docType>>, And<SOInvoiceDiscountDetail.refNbr, Equal<Current<ARInvoice.refNbr>>, And<SOInvoiceDiscountDetail.orderType, Equal<Required<SOInvoiceDiscountDetail.orderType>>, And<SOInvoiceDiscountDetail.orderNbr, Equal<Required<SOInvoiceDiscountDetail.orderNbr>>, And<SOInvoiceDiscountDetail.discountID, Equal<Required<SOInvoiceDiscountDetail.discountID>>, And<SOInvoiceDiscountDetail.discountSequenceID, Equal<Required<SOInvoiceDiscountDetail.discountSequenceID>>>>>>>>>.Select(this, shipments.OrderType, shipments.OrderNbr, sdd.DiscountID, sdd.DiscountSequenceID); if (idd != null) { if (idd.FreeItemID == null) { idd.FreeItemID = sdd.FreeItemID; idd.FreeItemQty = sdd.FreeItemQty; } else idd.FreeItemQty = sdd.FreeItemQty; DiscountDetails.Update(idd); } else { idd = new SOInvoiceDiscountDetail(); idd.Type = DiscountType.Line; idd.TranType = newdoc.DocType; idd.RefNbr = newdoc.RefNbr; idd.OrderType = sdd.OrderType; idd.OrderNbr = sdd.OrderNbr; idd.DiscountID = sdd.DiscountID; idd.DiscountSequenceID = sdd.DiscountSequenceID; idd.FreeItemID = sdd.FreeItemID; idd.FreeItemQty = sdd.FreeItemQty; DiscountDetails.Insert(idd); } } #endregion } this.Document.Update(newdoc); if (list != null) { if (Transactions.Search<ARTran.sOOrderType, ARTran.sOOrderNbr, ARTran.sOShipmentType, ARTran.sOShipmentNbr>(shipment.OrderType, shipment.OrderNbr, shipment.ShipmentType, shipment.ShipmentNbr).Count > 0) { try { this.Document.Current.ApplyPaymentWhenTaxAvailable = true; this.Save.Press(); } finally { this.Document.Current.ApplyPaymentWhenTaxAvailable = false; } if (list.Find(this.Document.Current) == null) { list.Add(this.Document.Current, this.SODocument.Current); } } else { this.Clear(); } } this.RowUpdated.RemoveHandler(typeof(ARInvoice), ApprovedBalanceCollector); }
public virtual IEnumerable AddShipment(PXAdapter adapter) { bool RequireControlTotal = ARSetup.Current.RequireControlTotal == true; foreach (SOOrderShipment shipment in shipmentlist.Cache.Updated) { if (shipment.Selected == true) { foreach (PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType, SOOrderTypeOperation> order in PXSelectJoin<SOOrderShipment, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderShipment.orderType>, And<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>>>, InnerJoin<CurrencyInfo, On<CurrencyInfo.curyInfoID, Equal<SOOrder.curyInfoID>>, InnerJoin<SOAddress, On<SOAddress.addressID, Equal<SOOrder.billAddressID>>, InnerJoin<SOContact, On<SOContact.contactID, Equal<SOOrder.billContactID>>, InnerJoin<SOOrderType, On<SOOrderType.orderType, Equal<SOOrder.orderType>>, InnerJoin<SOOrderTypeOperation, On<SOOrderTypeOperation.orderType, Equal<SOOrder.orderType>, And<SOOrderTypeOperation.operation, Equal<SOOrderShipment.operation>>>>>>>>>, Where<SOOrderShipment.shipmentNbr, Equal<Current<SOOrderShipment.shipmentNbr>>, And<SOOrderShipment.shipmentType, Equal<Current<SOOrderShipment.shipmentType>>, And<SOOrderShipment.orderType, Equal<Current<SOOrderShipment.orderType>>, And<SOOrderShipment.orderNbr, Equal<Current<SOOrderShipment.orderNbr>>>>>>>.SelectMultiBound(this, new object[] { shipment })) { ARSetup.Current.RequireControlTotal = false; this.InvoiceOrder((DateTime)this.Accessinfo.BusinessDate, order, customer.Current, null); ARSetup.Current.RequireControlTotal = RequireControlTotal; continue; } foreach (PXResult<SOOrderReceipt, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType, SOOrderTypeOperation, Customer> res in PXSelectJoin<SOOrderReceipt, InnerJoin<SOOrder, On<SOOrder.orderType, Equal<SOOrderReceipt.orderType>, And<SOOrder.orderNbr, Equal<SOOrderReceipt.orderNbr>>>, InnerJoin<CurrencyInfo, On<CurrencyInfo.curyInfoID, Equal<SOOrder.curyInfoID>>, InnerJoin<SOAddress, On<SOAddress.addressID, Equal<SOOrder.billAddressID>>, InnerJoin<SOContact, On<SOContact.contactID, Equal<SOOrder.billContactID>>, InnerJoin<SOOrderType, On<SOOrderType.orderType, Equal<SOOrder.orderType>>, InnerJoin<SOOrderTypeOperation, On<SOOrderTypeOperation.orderType, Equal<SOOrder.orderType>, And<SOOrderTypeOperation.operation, Equal<Current<SOOrderShipment.operation>>>>, InnerJoin<Customer, On<Customer.bAccountID, Equal<SOOrder.customerID>>>>>>>>>, Where<SOOrderReceipt.receiptNbr, Equal<Current<SOOrderShipment.shipmentNbr>>, And<SOShipmentType.dropShip, Equal<Current<SOOrderShipment.shipmentType>>, And<SOOrderReceipt.orderType, Equal<Current<SOOrderShipment.orderType>>, And<SOOrderReceipt.orderNbr, Equal<Current<SOOrderShipment.orderNbr>>>>>>>.SelectMultiBound(this, new object[] { shipment })) { SOOrderReceipt receipt = res; SOOrder order = res; PXResultset<SOShipLine, SOLine> details = new PXResultset<SOShipLine, SOLine>(); foreach (PXResult<POReceiptLine, SOLine> line in PXSelectJoin<POReceiptLine, InnerJoin<SOLine, On<SOLine.pOType, Equal<POReceiptLine.pOType>, And<SOLine.pONbr, Equal<POReceiptLine.pONbr>, And<SOLine.pOLineNbr, Equal<POReceiptLine.pOLineNbr>>>>>, Where2<Where<POReceiptLine.lineType, Equal<POLineType.goodsForDropShip>, Or<POReceiptLine.lineType, Equal<POLineType.nonStockForDropShip>>>, And<POReceiptLine.receiptNbr, Equal<Current<SOOrderReceipt.receiptNbr>>, And<SOLine.orderType, Equal<Current<SOOrderReceipt.orderType>>, And<SOLine.orderNbr, Equal<Current<SOOrderReceipt.orderNbr>>>>>>>.SelectMultiBound(this, new object[] { receipt })) { details.Add(new PXResult<SOShipLine, SOLine>((SOShipLine)line, line)); } shipmentlist.Cache.SetStatus(shipment, PXEntryStatus.Notchanged); shipmentlist.Cache.Remove(shipment); ARSetup.Current.RequireControlTotal = false; this.InvoiceOrder((DateTime)this.Accessinfo.BusinessDate, new PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType, SOOrderTypeOperation>((PXResult<SOOrderReceipt, SOOrder>)res, order, (CurrencyInfo)res, (SOAddress)res, (SOContact)res, (SOOrderType)res, (SOOrderTypeOperation)res), details, (Customer)res, null); ARSetup.Current.RequireControlTotal = RequireControlTotal; } } else if (shipment.InvoiceNbr == null) { shipmentlist.Cache.SetStatus(shipment, PXEntryStatus.Notchanged); shipmentlist.Cache.Remove(shipment); } } shipmentlist.View.Clear(); //shipmentlist.Cache.Clear(); return adapter.Get(); }