/// <summary> /// Determine the PriceCode value depending of PriceType of the calculated price. /// </summary> private static void DeterminePriceCode(PXCache cache, ref SalesPriceSet salesPriceSet, int?inventoryID) { if (salesPriceSet.PriceType == ID.PriceType.CUSTOMER) { List <object> args = new List <object>(); PXView appointmentRecordsView; BqlCommand customerBql = new Select <Customer, Where < Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >(); appointmentRecordsView = new PXView(cache.Graph, true, customerBql); args.Add(salesPriceSet.CustomerID); Customer customerRow = (Customer)appointmentRecordsView.SelectSingle(args.ToArray()); salesPriceSet.PriceCode = customerRow.AcctCD; } else if (salesPriceSet.PriceType == ID.PriceType.BASE || salesPriceSet.PriceType == ID.PriceType.DEFAULT) { salesPriceSet.PriceCode = string.Empty; } }
public override void Record_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert && ((FSAddress)e.Row).IsDefaultAddress == true) { PXView view = sender.Graph.TypedViews.GetView(_DuplicateSelect, true); view.Clear(); FSAddress previousAddress = (FSAddress)view.SelectSingle(((FSAddress)e.Row).BAccountID, ((FSAddress)e.Row).BAccountAddressID, ((FSAddress)e.Row).RevisionID); if (previousAddress != null) { _KeyToAbort = sender.GetValue(e.Row, _RecordID); object newKey = sender.Graph.Caches[typeof(FSAddress)].GetValue(previousAddress, _RecordID); PXCache cache = sender.Graph.Caches[_ItemType]; foreach (object data in cache.Updated) { object dataKey = cache.GetValue(data, _FieldOrdinal); if (Equals(_KeyToAbort, dataKey)) { cache.SetValue(data, _FieldOrdinal, newKey); } } _KeyToAbort = null; e.Cancel = true; return; } } base.Record_RowPersisting(sender, e); }
public override void SetCurrentYearSetup(object[] key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (key.Length < 1) { throw new ArgumentOutOfRangeException(nameof(key)); } if (key[0] == null) { throw new ArgumentNullException(nameof(key)); } int bookID = (int)key[0]; // TODO: Refactor to call FABookPeriodRepository.FindFABookYearSetup PXView view = new PXView( this, false, new Select < FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABook.bookID> > > >()); view.Clear(); FiscalYearSetup.Current = FiscalYearSetup.Current ?? view.SelectSingle(bookID) as FABookYearSetup; }
private void FieldSelectingOwnerOrWorkgroup <TField>(Events.FieldSelecting <TField> e) where TField : class, IBqlField { if (e.Row == null) { return; } bool isEnabled = true; PXView view = null; foreach (PXSelectorAttribute attribute in e.Cache.GetAttributesOfType <PXSelectorAttribute>(e.Row, typeof(FClassID).Name)) { view = new PXView(Base, true, attribute.PrimarySelect); } if (view == null) { return; } string classID = e.Cache.GetValue <FClassID>(e.Row) as string; CRBaseClass cls = view.SelectSingle(classID) as CRBaseClass; if (cls == null) { return; } isEnabled = cls.DefaultOwner != CRDefaultOwnerAttribute.AssignmentMap || Object.Equals(e.Cache.GetValue <FClassID>(e.Row), e.Cache.GetValueOriginal <FClassID>(e.Row)); e.ReturnState = PXFieldState.CreateInstance(e.ReturnState, null, null, null, null, null, null, null, null, null, null, null, PXErrorLevel.Undefined, isEnabled, null, null, PXUIVisibility.Undefined, null, null, null); }
public void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { EPEmployee employee = null; if (employeeSearch != null) { BqlCommand cmd = BqlCommand.CreateInstance(employeeSearch); PXView view = new PXView(sender.Graph, false, cmd); employee = view.SelectSingle() as EPEmployee; } if (employee != null && !string.IsNullOrEmpty(employee.UnionID)) { HashSet <string> validUnions = new HashSet <string>(); if (projectField != null) { int?projectID = (int?)sender.GetValue(e.Row, projectField.Name); if (ProjectDefaultAttribute.IsProject(sender.Graph, projectID)) { var select = new PXSelect <PMProjectUnion, Where <PMProjectUnion.projectID, Equal <Required <PMProjectUnion.projectID> > > >(sender.Graph); foreach (PMProjectUnion union in select.Select(projectID)) { validUnions.Add(union.UnionID); } } } if (validUnions.Count == 0 || validUnions.Contains(employee.UnionID)) { e.NewValue = employee.UnionID; } } }
private static int?GetAssignmentMapId(PXGraph graph) { BqlCommand search = (BqlCommand)Activator.CreateInstance(BqlCommand.Compose(typeof(Search <>), typeof(TAssignmentMapField))); PXView view = new PXView(graph, true, BqlCommand.CreateInstance(search.GetSelectType())); object row = view.SelectSingle(); return(row.With(_ => (int?)view.Cache.GetValue(_, ((IBqlSearch)search).GetField().Name))); }
public virtual void ResetSendInvoicesToFromBillingCycle(CustomerClass customerClassRow, FSCustomerClassBillingSetup fsCustomerClassBillingSetupRow) { List <object> args = new List <object>(); FSBillingCycle fsBillingCycleRow = null; BqlCommand billingCycleCommand = new Select <FSBillingCycle, Where < FSBillingCycle.billingCycleID, Equal <Required <FSBillingCycle.billingCycleID> > > >(); PXView billingCycleView = new PXView(Base, true, billingCycleCommand); if (customerClassRow != null) { FSxCustomerClass fsxCustomerClassRow = PXCache <CustomerClass> .GetExtension <FSxCustomerClass>(customerClassRow); args.Add(fsxCustomerClassRow.DfltBillingCycleID); fsBillingCycleRow = (FSBillingCycle)billingCycleView.SelectSingle(args.ToArray()); if (fsBillingCycleRow != null) { if (SharedFunctions.IsNotAllowedBillingOptionsModification(fsBillingCycleRow)) { fsxCustomerClassRow.SendInvoicesTo = ID.Send_Invoices_To.BILLING_CUSTOMER_BILL_TO; fsxCustomerClassRow.BillShipmentSource = ID.Ship_To.SERVICE_ORDER_ADDRESS; } } } else if (fsCustomerClassBillingSetupRow != null) { args.Add(fsCustomerClassBillingSetupRow.BillingCycleID); fsBillingCycleRow = (FSBillingCycle)billingCycleView.SelectSingle(args.ToArray()); if (fsBillingCycleRow != null) { if (SharedFunctions.IsNotAllowedBillingOptionsModification(fsBillingCycleRow)) { fsCustomerClassBillingSetupRow.SendInvoicesTo = ID.Send_Invoices_To.BILLING_CUSTOMER_BILL_TO; fsCustomerClassBillingSetupRow.BillShipmentSource = ID.Ship_To.SERVICE_ORDER_ADDRESS; } } } }
public override void CacheAttached(PXCache sender) { base.CacheAttached(sender); BqlCommand search = (BqlCommand)Activator.CreateInstance(BqlCommand.Compose(typeof(Search <>), MigrationModeSetupField)); PXView view = new PXView(sender.Graph, true, BqlCommand.CreateInstance(search.GetSelectType())); object setup = view.SelectSingle(); IsMigrationModeEnabled = (view.Cache.GetValue(setup, MigrationModeSetupField.Name) as bool?) == true; }
protected virtual void TMasterFieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { TMaster row = (TMaster)e.Row; if (row == null || row.ClassID == null) { return; } RelatedEntity pars = this.Caches <RelatedEntity>().Current as RelatedEntity; if (pars == null || pars.Type == null || pars.RefNoteID == null) { return; } EntityHelper helper = new EntityHelper(this); Type entityType = PXBuildManager.GetType(pars.Type, false); var related = new EntityHelper(this).GetEntityRow(entityType, pars.RefNoteID); if (related == null) { return; } Type graphType = helper.GetPrimaryGraphType(entityType, related, true); if (graphType == null) { return; } TMaster copy = PXCache <TMaster> .CreateCopy(row); PXGraph graph = CreateInstance(graphType); Type noteType = EntityHelper.GetNoteType(entityType); PXView view = new PXView(this, false, BqlCommand.CreateInstance(BqlCommand.Compose(typeof(Select <,>), entityType, typeof(Where <,>), noteType, typeof(Equal <>), typeof(Required <>), noteType))); graph.Caches[entityType].Current = view.SelectSingle(pars.RefNoteID); PXCache <TMaster> cache = graph.Caches <TMaster>(); cache.SetDefaultExt(copy, typeof(CRActivity.bAccountID).Name); cache.SetDefaultExt(copy, typeof(CRActivity.contactID).Name); if (copy.BAccountID != null) { row.BAccountID = copy.BAccountID; } if (copy.ContactID != null) { row.ContactID = copy.ContactID; } }
protected virtual void _(Events.FieldDefaulting <FOwnerID> e) { if (e.Row == null) { return; } PXView view = null; foreach (PXSelectorAttribute attribute in e.Cache.GetAttributesOfType <PXSelectorAttribute>(e.Row, typeof(FClassID).Name)) { view = new PXView(Base, true, attribute.PrimarySelect); } if (view == null) { return; } string classID = e.Cache.GetValue <FClassID>(e.Row) as string; CRBaseClass cls = view.SelectSingle(classID) as CRBaseClass; if (cls == null) { return; } switch (cls.DefaultOwner) { case CRDefaultOwnerAttribute.Creator: // if user is not employee it will just clear the field e.NewValue = SelectFrom <Users> .InnerJoin <Contact> .On <Contact.userID.IsEqual <Users.pKID> > .InnerJoin <BAccountR> .On <BAccountR.defContactID.IsEqual <Contact.contactID> .And <BAccountR.parentBAccountID.IsEqual <Contact.bAccountID> > > .Where < Users.pKID.IsEqual <AccessInfo.userID.FromCurrent> > .View.ReadOnly .Select(Base) .FirstOrDefault() ?.GetItem <Users>() ?.PKID; break; default: e.NewValue = null; break; } }
protected virtual string GetBasicNumberingID() { GLWorkBook currentWB = this.WorkBooks.Current; if (currentWB == null || currentWB.Module == null || currentWB.DocType == null) { return(null); } Type numberingField; switch (currentWB.Module) { case BatchModule.CA: numberingField = typeof(CASetup.registerNumberingID); break; case BatchModule.GL: numberingField = BatchModule.NumberingAttribute.GetNumberingIDField(BatchModule.GL); break; case BatchModule.AP: numberingField = AP.APInvoiceType.NumberingAttribute.GetNumberingIDField(currentWB.DocType); if (numberingField == null) { numberingField = AP.APPaymentType.NumberingAttribute.GetNumberingIDField(currentWB.DocType); } break; case BatchModule.AR: numberingField = AR.ARInvoiceType.NumberingAttribute.GetNumberingIDField(currentWB.DocType); if (numberingField == null) { numberingField = AR.ARPaymentType.NumberingAttribute.GetNumberingIDField(currentWB.DocType); } break; default: return(null); } if (numberingField == null) { return(null); } Type select = BqlCommand.Compose( typeof(Select <,>), typeof(CS.Numbering), typeof(Where <,>), typeof(CS.Numbering.numberingID), typeof(Equal <>), typeof(Current <>), numberingField); PXView view = new PXView(this, false, BqlCommand.CreateInstance(select)); var item = view.SelectSingle(); return(((CS.Numbering)item).NumberingID); }
/// <summary> /// Dynamically builds a query in the following format /// PXSelect<TEntity, Where<TRefNoteField, Equal<Required<TRefNoteField>>>> and selects /// single record. /// </summary> private static object GetEntity(PXGraph graph, RefNoteBasedRedirectionInstruction redirectionInstruction, params object[] bqlParameters) { var command = BqlCommand.CreateInstance( typeof(Select <,>), redirectionInstruction.EntityType, typeof(Where <, ,>), redirectionInstruction.ReferenceTypeField, typeof(Equal <>), typeof(Required <>), redirectionInstruction.ReferenceTypeField, typeof(And <,>), redirectionInstruction.ReferenceNumberField, typeof(Equal <>), typeof(Required <>), redirectionInstruction.ReferenceNumberField); var view = new PXView(graph, true, command); return(view.SelectSingle(bqlParameters)); }
public static void SetSupportsApproval(PXGraph sender, SOOrderType row) { if (row == null) { return; } using (new PXConnectionScope()) { PXView view = new PXView(sender, true, SupportsApprovalSelect); var r = view.SelectSingle(row.Behavior); row.SupportsApproval = r != null; } }
protected virtual string GetNewNumber(PXCache sender, Type setupType) { if (_LastNumberCommand == null) { CreateLastNumberCommand(); } PXView view = new PXView(sender.Graph, false, _LastNumberCommand); object row = view.SelectSingle(); if (row == null) { return(null); } string lastNumber = (string)view.Cache.GetValue(row, LastNumberField.Name); char[] symbols = lastNumber.ToCharArray(); for (int i = symbols.Length - 1; i >= 0; i--) { if (!char.IsDigit(symbols[i])) { break; } if (symbols[i] < '9') { symbols[i]++; break; } symbols[i] = '0'; } lastNumber = new string(symbols); view.Cache.SetValue(row, LastNumberField.Name, lastNumber); PXCache setupCache = sender.Graph.Caches[setupType]; setupCache.Update(row); setupCache.PersistUpdated(row); if (!string.IsNullOrEmpty(Prefix)) { lastNumber = Prefix + lastNumber; } return(lastNumber); }
public override void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { if (e.Row == null || e.NewValue == null) { return; } string module = (string)sender.GetValue(e.Row, _moduleField.Name); string documentType = (string)sender.GetValue(e.Row, _docTypeField.Name); BqlCommand relevantDocumentsSelect; if (module == BatchModule.AR) { relevantDocumentsSelect = new Select < ARRegister, Where < ARRegister.docType, Equal <Required <ARRegister.docType> >, And <ARRegister.refNbr, Equal <Required <ARRegister.refNbr> >, And <Where <ARInvoice.drSchedCntr, Less <ARInvoice.lineCntr>, Or <ARInvoice.drSchedCntr, IsNull> > > > > >(); if (ExcludeUnreleased) { relevantDocumentsSelect = relevantDocumentsSelect.WhereAnd <Where <ARRegister.released, Equal <True> > >(); } } else { base.FieldVerifying(sender, e); return; } PXView relevantDocuments = new PXView(_Graph, true, relevantDocumentsSelect); if (relevantDocuments.SelectSingle(documentType, e.NewValue) == null) { throwNoItem( restricted: null, external: true, value: e.NewValue); } }
protected virtual void _(Events.RowPersisting <TMaster> e) { if (e.Row == null || Object.Equals(e.Cache.GetValue <FClassID>(e.Row), e.Cache.GetValueOriginal <FClassID>(e.Row))) { return; } PXView view = null; foreach (PXSelectorAttribute attribute in e.Cache.GetAttributesOfType <PXSelectorAttribute>(e.Row, typeof(FClassID).Name)) { view = new PXView(Base, true, attribute.PrimarySelect); } if (view == null) { return; } string classID = e.Cache.GetValue <FClassID>(e.Row) as string; CRBaseClass cls = view.SelectSingle(classID) as CRBaseClass; if (cls == null) { return; } switch (cls.DefaultOwner) { case CRDefaultOwnerAttribute.AssignmentMap: var processor = PXGraph.CreateInstance <EPAssignmentProcessor <TMaster> >(); var copy = e.Cache.CreateCopy(e.Row) as TMaster; processor.Assign(copy, cls.DefaultAssignmentMapID); e.Cache.SetValueExt <FOwnerID>(e.Row, copy.OwnerID); e.Cache.SetValueExt <FWorkgroupID>(e.Row, copy.WorkgroupID); break; } }
public override void CacheAttached(PXCache sender) { base.CacheAttached(sender); var table = sender.GetItemType(); var command = BqlCommand.CreateInstance( typeof(Select <,>), table, typeof(Where <,>), _valueField, typeof(Equal <>), typeof(Required <>), _valueField); var view = new PXView(sender.Graph, true, command); sender.Graph.FieldSelecting.AddHandler(table, _FieldName, (cache, args) => { var row = view.SelectSingle(args.ReturnValue); var text = cache.GetValue(row, _textField.Name); args.ReturnValue = text; }); }
public void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { EPEmployee employee = null; if (employeeSearch != null) { BqlCommand cmd = BqlCommand.CreateInstance(employeeSearch); PXView view = new PXView(sender.Graph, false, cmd); employee = view.SelectSingle() as EPEmployee; } if (employee != null) { int? projectID = (int?)sender.GetValue(e.Row, projectField.Name); string earningType = (string)sender.GetValue(e.Row, earningTypeField.Name); e.NewValue = GetDefaultLaborItem(sender.Graph, employee, earningType, projectID); } }
public override void CacheAttached(PXCache sender) { base.CacheAttached(sender); if (IsMigrationModeEnabledSetupField != null) { BqlCommand search = (BqlCommand)Activator.CreateInstance(BqlCommand.Compose(typeof(Search <>), IsMigrationModeEnabledSetupField)); PXView view = new PXView(sender.Graph, true, BqlCommand.CreateInstance(search.GetSelectType())); object setup = view.SelectSingle(); IsMigrationModeEnabled = view.Cache.GetValue(setup, IsMigrationModeEnabledSetupField.Name) as bool?; } if (IsMigrationModeEnabled != true) { _ChildType = sender.GetItemType(); _persisted = new Dictionary <long?, object>(); sender.Graph.RowPersisting.AddHandler <CATran>(CATran_RowPersisting); sender.Graph.RowPersisted.AddHandler <CATran>(CATran_RowPersisted); } }
public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { object key = sender.GetValue(e.Row, _FieldOrdinal); if (key != null) { PXCache cache = sender.Graph.Caches[_RecordType]; if (Convert.ToInt32(key) < 0) { foreach (object data in cache.Inserted) { object dataKey = cache.GetValue(data, _RecordID); if (Equals(key, dataKey)) { if (((FSAddress)data).IsDefaultAddress == true) { PXView view = sender.Graph.TypedViews.GetView(_DuplicateSelect, true); view.Clear(); FSAddress previousAddress = (FSAddress)view.SelectSingle(((FSAddress)data).BAccountID, ((FSAddress)data).BAccountAddressID, ((FSAddress)data).RevisionID); if (previousAddress != null) { _KeyToAbort = sender.GetValue(e.Row, _FieldOrdinal); object id = sender.Graph.Caches[typeof(FSAddress)].GetValue(previousAddress, _RecordID); sender.SetValue(e.Row, _FieldOrdinal, id); } } break; } } } } base.RowPersisting(sender, e); }
public IYearSetup FindFABookYearSetup(FABook book, bool clearQueryCache = false) { BqlCommand selectCommand; if (book.UpdateGL == true) { selectCommand = new Select <FinYearSetup>(); } else { selectCommand = new Select < FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABook.bookID> > > >(); } PXView view = new PXView(Graph, true, selectCommand); if (clearQueryCache) { view.Clear(); } return(view.SelectSingle(book.BookID) as IYearSetup); }
public override void CacheAttached(PXCache sender) { BqlCommand command = null; Type autoNumberingField = null; if (typeof(IBqlSearch).IsAssignableFrom(_AutoNumberingField)) { command = BqlCommand.CreateInstance(_AutoNumberingField); autoNumberingField = ((IBqlSearch)command).GetField(); } else { command = BqlCommand.CreateInstance(typeof(Search <>), _AutoNumberingField); autoNumberingField = _AutoNumberingField; } PXView view = new PXView(sender.Graph, true, command); object row = view.SelectSingle(); if (row != null) { _AutoNumbering = (bool)view.Cache.GetValue(row, autoNumberingField.Name); } }