public static void ReleaseDoc(CABatch aDoc) { if ((bool)aDoc.Released || (bool)aDoc.Hold) { throw new PXException(CA.Messages.CABatchStatusIsNotValidForProcessing); } ARBatchUpdate be = PXGraph.CreateInstance <ARBatchUpdate>(); CABatch doc = be.Document.Select(aDoc.BatchNbr); be.Document.Current = doc; if ((bool)doc.Released || (bool)doc.Hold) { throw new PXException(CA.Messages.CABatchStatusIsNotValidForProcessing); } ARPayment voided = PXSelectReadonly2 <ARPayment, InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <ARPayment.docType>, And <CABatchDetail.origRefNbr, Equal <ARPayment.refNbr>, And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAR> > > > >, Where <CABatchDetail.batchNbr, Equal <Required <CABatch.batchNbr> >, And <ARPayment.voided, Equal <True> > > > .Select(be, doc.BatchNbr); if (voided != null && String.IsNullOrEmpty(voided.RefNbr) == false) { throw new PXException(CA.Messages.CABatchContainsVoidedPaymentsAndConnotBeReleased); } List <ARRegister> unreleasedList = new List <ARRegister>(); PXSelectBase <ARPayment> selectUnreleased = new PXSelectReadonly2 <ARPayment, InnerJoin <CABatchDetail, On <CABatchDetail.origDocType, Equal <ARPayment.docType>, And <CABatchDetail.origRefNbr, Equal <ARPayment.refNbr>, And <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAR> > > > >, Where <CABatchDetail.batchNbr, Equal <Optional <CABatch.batchNbr> >, And <ARPayment.released, Equal <boolFalse> > > >(be); foreach (ARPayment iPmt in selectUnreleased.Select(doc.BatchNbr)) { if (iPmt.Released != true) { unreleasedList.Add(iPmt); } } if (unreleasedList.Count > 0) { ARDocumentRelease.ReleaseDoc(unreleasedList, true); } selectUnreleased.View.Clear(); ARPayment pmt = selectUnreleased.Select(doc.BatchNbr); if (pmt != null) { throw new PXException(CA.Messages.CABatchContainsUnreleasedPaymentsAndCannotBeReleased); } doc.Released = true; doc.DateSeqNbr = CABatchEntry.GetNextDateSeqNbr(be, aDoc); //Nothing AP specific in this static function be.RecalcTotals(); doc = be.Document.Update(doc); be.Actions.PressSave(); }
public virtual IEnumerable DismissAll(PXAdapter adapter) { foreach (CRActivity row in ReminderList.Select()) { UpdateAcitivtyRemindInfo(row.NoteID, reminder => reminder.Dismiss = true); } RefreshActivityReminder(); return(adapter.Get()); }
/// <summary> /// Gets the information of the Appointment and AppointmentInventoryItem using as reference the [appointmentID] and [appointmentInventoryItemID]. /// </summary> private SharedClasses.AppointmentInventoryItemInfo GetAppointmentInventoryItemInfo(int?appointmentID, int?appDetID, int index) { PXResult <FSAppointment, FSServiceOrder, FSSrvOrdType, FSAppointmentInventoryItem, FSAppointmentDet> bqlResult = (PXResult <FSAppointment, FSServiceOrder, FSSrvOrdType, FSAppointmentInventoryItem, FSAppointmentDet>) PXSelectReadonly2 <FSAppointment, InnerJoin <FSServiceOrder, On <FSServiceOrder.sOID, Equal <FSAppointment.sOID>, And <FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > >, InnerJoin <FSSrvOrdType, On <FSSrvOrdType.srvOrdType, Equal <FSAppointment.srvOrdType> >, InnerJoin <FSAppointmentInventoryItem, On <FSAppointmentInventoryItem.appointmentID, Equal <FSAppointment.appointmentID>, And <FSAppointmentInventoryItem.appDetID, Equal <Required <FSAppointmentInventoryItem.appDetID> > > >, InnerJoin <FSAppointmentDet, On <FSAppointmentDet.sODetID, Equal <FSAppointmentInventoryItem.sODetID> > > > > > > .Select(this, appointmentID, appDetID); SharedClasses.AppointmentInventoryItemInfo appointmentInfoToReturn = new SharedClasses.AppointmentInventoryItemInfo(); if (bqlResult != null) { FSAppointment fsAppointmentRow = (FSAppointment)bqlResult; FSServiceOrder fsServiceOrderRow = (FSServiceOrder)bqlResult; FSSrvOrdType fsSrvOrdTypeRow = (FSSrvOrdType)bqlResult; FSAppointmentInventoryItem fsAppointmentInventoryItemRow = (FSAppointmentInventoryItem)bqlResult; FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)bqlResult; appointmentInfoToReturn = new SharedClasses.AppointmentInventoryItemInfo(fsAppointmentRow, fsServiceOrderRow, fsSrvOrdTypeRow, fsAppointmentDetRow, fsAppointmentInventoryItemRow, index); } return(appointmentInfoToReturn); }
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); }
public virtual bool PrepareImportRow(string viewName, IDictionary keys, IDictionary values) { if (string.Compare(viewName, "VendorCatalogue", true) == 0) { string inventoryCD = (string)values[_inventoryID]; var r = (PXResult <InventoryItem, INSubItem>) PXSelectReadonly2 <InventoryItem, LeftJoin <INSubItem, On <INSubItem.subItemCD, Equal <Required <INSubItem.subItemCD> >, Or <Where <Required <INSubItem.subItemCD>, IsNull, And <INSubItem.subItemID, Equal <InventoryItem.defaultSubItemID> > > > > >, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(this, values[_subItemID], values[_subItemID], inventoryCD); InventoryItem item = r; INSubItem subitem = r; if (item != null && item.InventoryID != null) { string uom = (string)values[_uOM] ?? item.PurchaseUnit; if (values[_subItemID] == null) { values[_subItemID] = subitem.SubItemCD; } POVendorInventory old_row = subitem.SubItemID != null ? PXSelect <POVendorInventory, Where <POVendorInventory.vendorID, Equal <Required <POVendorInventory.vendorID> >, And <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >, And <POVendorInventory.inventoryID, Equal <Required <POVendorInventory.inventoryID> >, And <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >, And <Where <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> > > > > > > > > .SelectWindowed(this, 0, 1, this.BAccount.Current.BAccountID, this.BAccount.Current.LocationID, item.InventoryID, uom, subitem.SubItemID) : PXSelect <POVendorInventory, Where <POVendorInventory.vendorID, Equal <Required <POVendorInventory.vendorID> >, And <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >, And <POVendorInventory.inventoryID, Equal <Required <POVendorInventory.inventoryID> >, And <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> >, And <POVendorInventory.subItemID, IsNull> > > > > > .SelectWindowed(this, 0, 1, this.BAccount.Current.BAccountID, this.BAccount.Current.LocationID, item.InventoryID, uom); if (old_row != null) { if (values[_uOM] == null) { values[_uOM] = old_row.PurchaseUnit; } if (keys.Contains(_recordID)) { keys[_recordID] = old_row.RecordID; values[_recordID] = old_row.RecordID; } } } } return(true); }
protected virtual void INTran_TaskID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { INTran row = e.Row as INTran; if (row == null) { return; } if (PM.ProjectAttribute.IsPMVisible(BatchModule.IN)) { if (row.LocationID != null) { PXResultset <INLocation> result = PXSelectReadonly2 <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) { e.NewValue = task.TaskCD; return; } } } } }
public virtual IEnumerable DismissAll(PXAdapter adapter) { foreach (EPActivity row in ReminderList.Select()) { UpdateAcitivtyRemindInfo(row.TaskID, reminder => reminder.Dismiss = true); } return(adapter.Get()); }
public void Prefetch(PXGraph parameter) { var reminderListViewInfo = new PXSelectReadonly2 <EPActivity, LeftJoin <EPView, On <EPView.noteID, Equal <EPActivity.noteID>, And <EPView.userID, Equal <Current <AccessInfo.userID> > > >, ReminderJoin>, ReminderListWhere, OrderBy <Asc <EPActivity.reminderDate> > >(parameter); _reminderList = reminderListViewInfo.Select().ToArray(); }
private IEnumerable <Customer> GetCustomersWithSameCCPID(string processingCenterID, string customerCCPID) { PXSelectBase <Customer> query = new PXSelectReadonly2 <Customer, InnerJoin <CustomerProcessingCenterID, On <Customer.bAccountID, Equal <CustomerProcessingCenterID.bAccountID> > >, Where <CustomerProcessingCenterID.cCProcessingCenterID, Equal <Required <CustomerProcessingCenterID.cCProcessingCenterID> >, And <CustomerProcessingCenterID.customerCCPID, Equal <Required <CustomerProcessingCenterID.customerCCPID> > > > >(_Graph); PXResultset <Customer> customers = query.Select(processingCenterID, customerCCPID); return(customers.RowCast <Customer>()); }
public virtual IEnumerable CloseRoute(PXAdapter adapter) { FSRouteDocument fsRouteDocumentRow = RouteRecords.Current; if (fsRouteDocumentRow != null) { if (AutomaticallyCloseRoute || WebDialogResult.Yes == RouteRecords.Ask( TX.WebDialogTitles.CONFIRM_ROUTE_CLOSING, TX.Messages.ASK_CONFIRM_ROUTE_CLOSING, MessageButtons.YesNo)) { var fsAppointmentSet = PXSelectReadonly2 <FSAppointment, InnerJoin <FSSrvOrdType, On <FSSrvOrdType.srvOrdType, Equal <FSAppointment.srvOrdType> >, InnerJoin <FSAppointmentInventoryItem, On <FSAppointmentInventoryItem.appointmentID, Equal <FSAppointment.appointmentID> >, LeftJoin <FSPostInfo, On <FSPostInfo.postID, Equal <FSAppointmentInventoryItem.postID> > > > >, Where < FSAppointmentInventoryItem.lineType, Equal <ListField_LineType_Pickup_Delivery.Pickup_Delivery>, And <FSAppointment.routeDocumentID, Equal <Current <FSRouteDocument.routeDocumentID> >, And <FSAppointment.status, NotEqual <ListField_Status_Appointment.Canceled>, And <FSSrvOrdType.enableINPosting, Equal <True>, And < Where < FSPostInfo.postID, IsNull, Or <FSPostInfo.iNPosted, Equal <False> > > > > > > > > .Select(this, fsRouteDocumentRow.RouteDocumentID); if (fsAppointmentSet.Count != 0) { throw new PXException(TX.Error.ROUTE_DOCUMENT_APPOINTMENTS_NOT_POSTED); } else { string errorMessage = string.Empty; if (CloseAppointmentsInRoute(ref errorMessage) == false) { throw new PXException(errorMessage); } this.SelectTimeStamp(); RouteRecords.Cache.AllowUpdate = true; fsRouteDocumentRow.Status = ID.Status_Route.CLOSED; RouteRecords.Cache.SetStatus(fsRouteDocumentRow, PXEntryStatus.Updated); Save.Press(); } } } return(adapter.Get()); }
private void EnsureHistoryLoaded(RMDataSourcePM dsPM) { //Unlike RMReportReaderGL, there is no lazy loading for now, given the way PMHistory is structured we need to load whole project history to get balances for a given project //We could do lazy loading by project, but that would be slower if report including a large number of projects (ex: project profitability list) var key = 1; if (!_historyLoaded.Contains(key)) { ProcessPMResultset(PXSelectReadonly2 <PMHistory, InnerJoin <PMTask, On <PMHistory.projectTaskID, Equal <PMTask.taskID> > > > .Select(this.Base)); _historyLoaded.Add(key); } }
private IEnumerable <PXResult <CustomerPaymentMethod, CustomerPaymentMethodDetail> > GetPaymentsProfilesByCustomer(string processingCenterID, string customerCCPID) { 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> > > > > >(this); var result = query.Select(processingCenterID, customerCCPID).Select(i => (PXResult <CustomerPaymentMethod, CustomerPaymentMethodDetail>)i); return(result); }
public static void Update(PXGraph graph, int?vendorID, int?vendorLocationID, string curyID, int?inventoryID, int?subItemID, string uom, decimal curyCost) { if (curyCost <= 0 || string.IsNullOrEmpty(uom) || vendorID == null || vendorLocationID == null) { return; } PXCache cache = graph.Caches[typeof(POVendorInventoryPriceUpdate)]; foreach (PXResult <InventoryItem, Vendor, Company> r in PXSelectReadonly2 <InventoryItem, LeftJoinSingleTable <Vendor, On <Vendor.bAccountID, Equal <Required <Vendor.bAccountID> > >, CrossJoin <Company> >, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > . Select(graph, vendorID, inventoryID)) { InventoryItem item = r; Vendor vendor = r; Company company = r; if (item.InventoryID == null || vendor.BAccountID == null || (item.StkItem == true && subItemID == null)) { continue; } INSetup setup = PXSetupOptional <INSetup> .Select(graph); int?savedSubItemID = item.StkItem == true ? subItemID : null; POVendorInventoryPriceUpdate vendorPrice = (POVendorInventoryPriceUpdate)cache.CreateInstance(); vendorPrice.InventoryID = inventoryID; vendorPrice.SubItemID = savedSubItemID; vendorPrice.VendorID = vendorID; vendorPrice.VendorLocationID = vendorLocationID; vendorPrice.PurchaseUnit = uom; vendorPrice = (POVendorInventoryPriceUpdate)cache.Insert(vendorPrice); if (item.StkItem != true) { vendorPrice.SubItemID = savedSubItemID; } vendorPrice.CuryID = curyID; cache.Normalize(); vendorPrice.Active = true; vendorPrice.LastPrice = curyCost; } }
public PXResultset <ARPayment> GetPrepaymentBySO(PXGraph graph) { if (SOID == null) { return(null); } return(PXSelectReadonly2 <ARPayment, InnerJoin <FSAdjust, On <ARPayment.docType, Equal <FSAdjust.adjgDocType>, And <ARPayment.refNbr, Equal <FSAdjust.adjgRefNbr> > >, InnerJoin <FSServiceOrder, On <FSAdjust.adjdOrderType, Equal <FSServiceOrder.srvOrdType>, And <FSAdjust.adjdOrderNbr, Equal <FSServiceOrder.refNbr> > > > >, Where <FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > > .Select(graph, SOID)); }
protected virtual List <PXResult <CSAnswers, CSAttributeGroup, InventoryItem> > SelectInventoryWithAttributes() { var select = new PXSelectReadonly2 <CSAnswers, InnerJoin <CSAttributeGroup, On <CSAnswers.attributeID, Equal <CSAttributeGroup.attributeID> >, InnerJoin <InventoryItem, On <CSAnswers.refNoteID, Equal <InventoryItem.noteID>, And <CSAttributeGroup.entityClassID, Equal <InventoryItem.itemClassID> > > > >, Where <CSAttributeGroup.isActive, Equal <True>, And <CSAttributeGroup.entityType, Equal <Constants.DACName <InventoryItem> >, And <CSAttributeGroup.attributeCategory, Equal <CSAttributeGroup.attributeCategory.variant>, And <InventoryItem.templateItemID, Equal <Required <EntryHeader.templateItemID> > > > > >, OrderBy <Asc <InventoryItem.inventoryID, Asc <CSAnswers.attributeID> > > >(Base); using (new PXFieldScope(select.View, typeof(InventoryItem.inventoryID), typeof(CSAnswers.attributeID), typeof(CSAnswers.value))) { return(select.Select(GetTemplateID()).Cast <PXResult <CSAnswers, CSAttributeGroup, InventoryItem> >().ToList()); } }
public virtual IEnumerable <AMBomOper> GetOperationsWithoutMaterial(string bomId, string revisionId) { foreach (AMBomOper bomOper in PXSelectReadonly2 <AMBomOper, LeftJoin <AMBomMatl, On <AMBomOper.bOMID, Equal <AMBomMatl.bOMID>, And <AMBomOper.revisionID, Equal <AMBomMatl.revisionID>, And <AMBomOper.operationID, Equal <AMBomMatl.operationID> > > > >, Where <AMBomOper.bOMID, Equal <Required <AMBomOper.bOMID> >, And <AMBomOper.revisionID, Equal <Required <AMBomOper.revisionID> >, And <AMBomMatl.inventoryID, IsNull> > > > .Select(this, bomId, revisionId)) { if (bomOper?.OperationID == null) { continue; } yield return(bomOper); } }
public static ItemCost Fetch(PXGraph graph, int?vendorID, int?vendorLocationID, DateTime?docDate, string curyID, int?inventoryID, int?subItemID, int?siteID, string uom, bool onlyVendor) { PXSelectBase <InventoryItem> vendorCostSelect = new PXSelectReadonly2 <InventoryItem, LeftJoin <INItemCost, On <INItemCost.inventoryID, Equal <InventoryItem.inventoryID> >, LeftJoin <POVendorInventory, On < POVendorInventory.inventoryID, Equal <InventoryItem.inventoryID>, And <POVendorInventory.active, Equal <True>, And <POVendorInventory.vendorID, Equal <Required <Vendor.bAccountID> >, And <POVendorInventory.curyID, Equal <Required <POVendorInventory.curyID> >, And2 <Where <POVendorInventory.subItemID, Equal <Required <POVendorInventory.subItemID> >, Or <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID>, Or <POVendorInventory.subItemID, IsNull, Or <Where <Required <POVendorInventory.subItemID>, IsNull, And <POVendorInventory.subItemID, Equal <True> > > > > > >, And2 <Where <POVendorInventory.purchaseUnit, Equal <Required <POVendorInventory.purchaseUnit> > >, And <Where <POVendorInventory.vendorLocationID, Equal <Required <POVendorInventory.vendorLocationID> >, Or <POVendorInventory.vendorLocationID, IsNull> > > > > > > > > > >, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > >, OrderBy < Asc <Switch <Case <Where <POVendorInventory.purchaseUnit, Equal <InventoryItem.purchaseUnit> >, True>, False>, Asc <Switch <Case <Where <POVendorInventory.subItemID, Equal <InventoryItem.defaultSubItemID> >, True>, False>, Asc <Switch <Case <Where <POVendorInventory.vendorLocationID, IsNull>, True>, False>, Asc <InventoryItem.inventoryCD> > > > > >(graph); Func <string, PXResult <InventoryItem, INItemCost, POVendorInventory> > selectVendorCostByUOM = uomParam => vendorCostSelect .Select(vendorID, curyID, subItemID, subItemID, uomParam, vendorLocationID, inventoryID).AsEnumerable() .FirstOrDefault(r => r.GetItem <POVendorInventory>() != null) as PXResult <InventoryItem, INItemCost, POVendorInventory>; var vendorCostRow = selectVendorCostByUOM(uom); var item = vendorCostRow.GetItem <InventoryItem>(); Func <POVendorInventory, ItemCost> fetchVendorLastCost = vendorPrice => vendorPrice.LastPrice != null && vendorPrice.LastPrice != 0m ? new ItemCost(item, vendorPrice.PurchaseUnit, curyID, vendorPrice.LastPrice.Value, false) : null; return(fetchVendorLastCost(vendorCostRow.GetItem <POVendorInventory>()) ?? fetchVendorLastCost(selectVendorCostByUOM(item.BaseUnit).GetItem <POVendorInventory>()) ?? (onlyVendor ? null : FetchStdCost(graph, item, docDate)) ?? (onlyVendor ? null : FetchSiteLastCost(graph, item, siteID)) ?? new ItemCost(item, vendorCostRow.GetItem <INItemCost>()?.LastCost ?? 0)); }
public virtual IEnumerable CancelInvoice(PXAdapter adapter) { if (Base.Document.Current == null) { return(adapter.Get()); } Base.Save.Press(); EnsureCanCancel(Base.Document.Current, false); var reverseArgs = new ReverseInvoiceArgs { ApplyToOriginalDocument = true }; if (this.CancellationInvoiceCreationOnRelease) { var existingCorrectionInvoiceSet = (PXResult <ARInvoice, CurrencyInfo>) PXSelectReadonly2 <ARInvoice, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <ARInvoice.curyInfoID> > >, Where <ARInvoice.origDocType, Equal <Current <ARInvoice.docType> >, And <ARInvoice.origRefNbr, Equal <Current <ARInvoice.refNbr> >, And <ARInvoice.isCorrection, Equal <True> > > > > .Select(Base); ARInvoice existingCorrectionInvoice = existingCorrectionInvoiceSet; CurrencyInfo currencyInfo = existingCorrectionInvoiceSet; if (existingCorrectionInvoice == null) { throw new RowNotFoundException(Base.Document.Cache, Base.Document.Current.DocType, Base.Document.Current.RefNbr); } reverseArgs.DateOption = ReverseInvoiceArgs.CopyOption.Override; reverseArgs.DocumentDate = existingCorrectionInvoice.DocDate; reverseArgs.DocumentFinPeriodID = existingCorrectionInvoice.FinPeriodID; reverseArgs.CurrencyRateOption = ReverseInvoiceArgs.CopyOption.Override; reverseArgs.CurrencyRate = currencyInfo; reverseArgs.OverrideDocumentHold = false; using (new PXLocaleScope(Base.customer.Current.LocaleName)) { reverseArgs.OverrideDocumentDescr = PXMessages.LocalizeFormatNoPrefixNLA(Messages.CorrectionOfInvoice, Base.Document.Current.RefNbr); } } return(Base.ReverseDocumentAndApplyToReversalIfNeeded(adapter, reverseArgs)); }
public Dictionary <string, CustomerCreditCard> GetUnsynchronizedPaymentProfiles() { Dictionary <string, CustomerCreditCard> paymentProfiles = GetPaymentProfilesFromService(); 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 <PaymentMethodDetail.isCCProcessingID, Equal <True>, And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards> > > > >(graph); PXResultset <CustomerPaymentMethod> lines = query.Select(processingCenterId); foreach (PXResult <CustomerPaymentMethod, CustomerPaymentMethodDetail> line in lines) { FilterPaymentsProfilesFromService(paymentProfiles, line); } return(paymentProfiles); }
protected virtual IEnumerable mailLists() { foreach (PXResult row in MailListsExt.Select()) { var rec = (CRMarketingList)row[typeof(CRMarketingList)]; var mailList = (CRMassMailMarketingList)row[typeof(CRMassMailMarketingList)]; CRMarketingList cache = (CRMarketingList)this.MailLists.Cache.Locate(rec); if (rec.Selected != true && mailList.MailListID != null) { rec.Selected = true; } if (cache != null) { bool?selected = cache.Selected; MailLists.Cache.RestoreCopy(cache, rec); cache.Selected = selected; rec = cache; } yield return(new PXResult <CRMarketingList>(rec)); } }
protected virtual IEnumerable viewSegment(PXAdapter adapter) { var current = Detail.Current; if (current != null) { Segment row; if (current.Inherited == true) { row = (Segment)PXSelectReadonly2 <Segment, InnerJoin <Dimension, On <Dimension.parentDimensionID, Equal <Segment.dimensionID> > >, Where <Dimension.dimensionID, Equal <Required <Dimension.dimensionID> >, And <Segment.segmentID, Equal <Required <Segment.segmentID> > > > > . Select(this, current.DimensionID, current.SegmentID); } else { row = (Segment)PXSelectReadonly <Segment> . Search <Segment.dimensionID, Segment.segmentID>(this, current.DimensionID, current.SegmentID); } PXRedirectHelper.TryRedirect(Caches[typeof(Segment)], row, string.Empty); } return(adapter.Get()); }
public static PXResultset <ARInvoice> GetCustDocs(PX.Objects.AR.ARPaymentEntry.LoadOptions opts, ARPayment currentARPayment, ARSetup currentARSetup, PXGraph graph) { PXSelectBase <ARInvoice> cmd = new PXSelectReadonly2 <ARInvoice, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARInvoice.customerID> >, LeftJoin <ARAdjust, On <ARAdjust.adjdDocType, Equal <ARInvoice.docType>, And <ARAdjust.adjdRefNbr, Equal <ARInvoice.refNbr>, And <ARAdjust.released, Equal <boolFalse>, And <ARAdjust.voided, Equal <boolFalse>, And <Where <ARAdjust.adjgDocType, NotEqual <Required <ARPayment.docType> >, Or <ARAdjust.adjgRefNbr, NotEqual <Required <ARPayment.refNbr> > > > > > > > >, LeftJoin <ARAdjust2, On <ARAdjust2.adjgDocType, Equal <ARInvoice.docType>, And <ARAdjust2.adjgRefNbr, Equal <ARInvoice.refNbr>, And <ARAdjust2.released, Equal <boolFalse>, And <ARAdjust2.voided, Equal <boolFalse> > > > > > > >, Where <ARInvoice.docType, NotEqual <Required <ARPayment.docType> >, And <ARInvoice.released, Equal <boolTrue>, And <ARInvoice.openDoc, Equal <boolTrue>, And <ARAdjust.adjgRefNbr, IsNull, And <ARAdjust2.adjgRefNbr, IsNull> > > > >, OrderBy <Asc <ARInvoice.dueDate, Asc <ARInvoice.refNbr> > > >(graph); if (opts != null) { if (opts.FromDate != null) { cmd.WhereAnd <Where <ARInvoice.docDate, GreaterEqual <Required <PX.Objects.AR.ARPaymentEntry.LoadOptions.fromDate> > > >(); } if (opts.TillDate != null) { cmd.WhereAnd <Where <ARInvoice.docDate, LessEqual <Required <PX.Objects.AR.ARPaymentEntry.LoadOptions.tillDate> > > >(); } if (!string.IsNullOrEmpty(opts.StartRefNbr)) { cmd.WhereAnd <Where <ARInvoice.refNbr, GreaterEqual <Required <PX.Objects.AR.ARPaymentEntry.LoadOptions.startRefNbr> > > >(); } if (!string.IsNullOrEmpty(opts.EndRefNbr)) { cmd.WhereAnd <Where <ARInvoice.refNbr, LessEqual <Required <PX.Objects.AR.ARPaymentEntry.LoadOptions.endRefNbr> > > >(); } } var loadChildDocs = opts == null ? PX.Objects.AR.ARPaymentEntry.LoadOptions.loadChildDocuments.None : opts.LoadChildDocuments; switch (loadChildDocs) { case PX.Objects.AR.ARPaymentEntry.LoadOptions.loadChildDocuments.IncludeCRM: cmd.WhereAnd <Where <ARInvoice.customerID, Equal <Required <ARRegister.customerID> >, Or <Customer.consolidatingBAccountID, Equal <Required <ARRegister.customerID> > > > >(); break; case PX.Objects.AR.ARPaymentEntry.LoadOptions.loadChildDocuments.ExcludeCRM: cmd.WhereAnd <Where <ARInvoice.customerID, Equal <Required <ARRegister.customerID> >, Or <Customer.consolidatingBAccountID, Equal <Required <ARRegister.customerID> >, And <ARInvoice.docType, NotEqual <ARDocType.creditMemo> > > > >(); break; default: cmd.WhereAnd <Where <ARInvoice.customerID, Equal <Required <ARRegister.customerID> > > >(); break; } switch (currentARPayment.DocType) { case ARDocType.Payment: cmd.WhereAnd <Where <ARInvoice.docType, Equal <ARDocType.invoice>, Or <ARInvoice.docType, Equal <ARDocType.debitMemo>, Or <ARInvoice.docType, Equal <ARDocType.creditMemo>, Or <ARInvoice.docType, Equal <ARDocType.finCharge> > > > > >(); break; case ARDocType.Prepayment: case ARDocType.CreditMemo: cmd.WhereAnd <Where <ARInvoice.docType, Equal <ARDocType.invoice>, Or <ARInvoice.docType, Equal <ARDocType.debitMemo>, Or <ARInvoice.docType, Equal <ARDocType.finCharge> > > > >(); break; default: cmd.WhereAnd <Where <True, Equal <False> > >(); break; } List <object> parametrs = new List <object>(); parametrs.Add(currentARPayment.DocType); parametrs.Add(currentARPayment.RefNbr); parametrs.Add(currentARPayment.DocType); if (opts != null) { if (opts.FromDate != null) { parametrs.Add(opts.FromDate); } if (opts.TillDate != null) { parametrs.Add(opts.TillDate); } if (!string.IsNullOrEmpty(opts.StartRefNbr)) { parametrs.Add(opts.StartRefNbr); } if (!string.IsNullOrEmpty(opts.EndRefNbr)) { parametrs.Add(opts.EndRefNbr); } } switch (loadChildDocs) { case PX.Objects.AR.ARPaymentEntry.LoadOptions.loadChildDocuments.IncludeCRM: case PX.Objects.AR.ARPaymentEntry.LoadOptions.loadChildDocuments.ExcludeCRM: parametrs.Add(currentARPayment.CustomerID); parametrs.Add(currentARPayment.CustomerID); break; default: parametrs.Add(currentARPayment.CustomerID); break; } PXResultset <ARInvoice> custdocs = opts == null || opts.MaxDocs == null?cmd.Select(parametrs.ToArray()) : cmd.SelectWindowed(0, (int)opts.MaxDocs, parametrs.ToArray()); custdocs.Sort(new Comparison <PXResult <ARInvoice> >(delegate(PXResult <ARInvoice> a, PXResult <ARInvoice> b) { int aSortOrder = 0; int bSortOrder = 0; if (currentARPayment.CuryOrigDocAmt > 0m) { aSortOrder += (((ARInvoice)a).DocType == ARDocType.CreditMemo ? 0 : 1000); bSortOrder += (((ARInvoice)b).DocType == ARDocType.CreditMemo ? 0 : 1000); } else { aSortOrder += (((ARInvoice)a).DocType == ARDocType.CreditMemo ? 1000 : 0); bSortOrder += (((ARInvoice)b).DocType == ARDocType.CreditMemo ? 1000 : 0); } if (currentARSetup.FinChargeFirst == true) { aSortOrder += (((ARInvoice)a).DocType == ARDocType.FinCharge ? 0 : 100); bSortOrder += (((ARInvoice)b).DocType == ARDocType.FinCharge ? 0 : 100); } DateTime aDueDate = ((ARInvoice)a).DueDate ?? DateTime.MinValue; DateTime bDueDate = ((ARInvoice)b).DueDate ?? DateTime.MinValue; if (opts == null) { aSortOrder += (1 + aDueDate.CompareTo(bDueDate)) / 2; bSortOrder += (1 - aDueDate.CompareTo(bDueDate)) / 2; } else { object aObj; object bObj; switch (opts.OrderBy) { case PX.Objects.AR.ARPaymentEntry.LoadOptions.orderBy.RefNbr: aObj = ((ARInvoice)a).RefNbr; bObj = ((ARInvoice)b).RefNbr; aSortOrder += (1 + ((IComparable)aObj).CompareTo(bObj)) / 2; bSortOrder += (1 - ((IComparable)aObj).CompareTo(bObj)) / 2; break; case PX.Objects.AR.ARPaymentEntry.LoadOptions.orderBy.DocDateRefNbr: aObj = ((ARInvoice)a).DocDate; bObj = ((ARInvoice)b).DocDate; aSortOrder += (1 + ((IComparable)aObj).CompareTo(bObj)) / 2 * 10; bSortOrder += (1 - ((IComparable)aObj).CompareTo(bObj)) / 2 * 10; aObj = ((ARInvoice)a).RefNbr; bObj = ((ARInvoice)b).RefNbr; aSortOrder += (1 + ((IComparable)aObj).CompareTo(bObj)) / 2; bSortOrder += (1 - ((IComparable)aObj).CompareTo(bObj)) / 2; break; default: aSortOrder += (1 + aDueDate.CompareTo(bDueDate)) / 2 * 10; bSortOrder += (1 - aDueDate.CompareTo(bDueDate)) / 2 * 10; aObj = ((ARInvoice)a).RefNbr; bObj = ((ARInvoice)b).RefNbr; aSortOrder += (1 + ((IComparable)aObj).CompareTo(bObj)) / 2; bSortOrder += (1 - ((IComparable)aObj).CompareTo(bObj)) / 2; break; } } return(aSortOrder.CompareTo(bSortOrder)); })); return(custdocs); }
protected virtual void CAEntryType_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { CAEntryType row = (CAEntryType)e.Row; if (row != null) { if (row.Module == GL.BatchModule.CA) { PXUIFieldAttribute.SetEnabled <CAEntryType.referenceID>(this.EntryType.Cache, row, false); PXUIFieldAttribute.SetEnabled <CAEntryType.accountID>(sender, row, true); PXUIFieldAttribute.SetEnabled <CAEntryType.subID>(sender, row, true); } else { PXUIFieldAttribute.SetEnabled <CAEntryType.referenceID>(this.EntryType.Cache, row, true); PXUIFieldAttribute.SetEnabled <CAEntryType.accountID>(sender, row, false); PXUIFieldAttribute.SetEnabled <CAEntryType.subID>(sender, row, false); } PXUIFieldAttribute.SetEnabled <CAEntryType.useToReclassifyPayments>(sender, row, row.Module == GL.BatchModule.CA); bool isInserted = sender.GetStatus(e.Row) == PXEntryStatus.Inserted; PXUIFieldAttribute.SetEnabled <CAEntryType.entryTypeId>(sender, row, isInserted); bool usesCashAccount = false; GL.Account acct = null; CashAccount cashAcct = null; if (row.AccountID != null && row.SubID != null) { cashAcct = PXSelectReadonly <CashAccount, Where <CashAccount.accountID, Equal <Required <CashAccount.accountID> >, And <CashAccount.subID, Equal <Required <CashAccount.subID> > > > > .Select(this, row.AccountID, row.SubID); acct = PXSelectReadonly <GL.Account, Where <GL.Account.accountID, Equal <Required <GL.Account.accountID> > > > .Select(this, row.AccountID); usesCashAccount = (cashAcct != null); } PXUIFieldAttribute.SetEnabled <CAEntryType.accountID>(sender, row, row.UseToReclassifyPayments != true); PXUIFieldAttribute.SetEnabled <CAEntryType.subID>(sender, row, row.UseToReclassifyPayments != true); PXUIFieldAttribute.SetEnabled <CAEntryType.branchID>(sender, row, row.UseToReclassifyPayments != true && usesCashAccount); PXUIFieldAttribute.SetEnabled <CAEntryType.cashAccountID>(sender, row, row.UseToReclassifyPayments == true); if (row.UseToReclassifyPayments == true && acct != null && acct.AccountID.HasValue) { if (!usesCashAccount) { sender.RaiseExceptionHandling <CAEntryType.accountID>(e.Row, acct.AccountCD, new PXSetPropertyException(Messages.CAEntryTypeUsedForPaymentReclassificationMustHaveCashAccount, PXErrorLevel.Error)); } else { PaymentMethodAccount pmAccount = PXSelectReadonly2 <PaymentMethodAccount, InnerJoin <PaymentMethod, On <PaymentMethod.paymentMethodID, Equal <PaymentMethodAccount.paymentMethodID>, And <PaymentMethod.isActive, Equal <True> > > >, Where <PaymentMethodAccount.cashAccountID, Equal <Required <PaymentMethodAccount.cashAccountID> >, And <Where <PaymentMethodAccount.useForAP, Equal <True>, Or <PaymentMethodAccount.useForAR, Equal <True> > > > > > .Select(this, row.CashAccountID); if (pmAccount == null || pmAccount.CashAccountID.HasValue == false) { sender.RaiseExceptionHandling <CAEntryType.cashAccountID>(e.Row, cashAcct.CashAccountCD, new PXSetPropertyException(Messages.EntryTypeCashAccountIsNotConfiguredToUseWithAnyPaymentMethod, PXErrorLevel.Warning)); } else { sender.RaiseExceptionHandling <CAEntryType.accountID>(e.Row, null, null); } } } else { row.CashAccountID = null; sender.RaiseExceptionHandling <CAEntryType.accountID>(e.Row, null, null); } } }
public virtual void Recalculate(InventoryItem template) { if (template == null) { throw new PXArgumentException(nameof(template)); } if (template.InventoryID == null) { throw new PXArgumentException(nameof(template.InventoryID)); } _template = template; DeleteOldRows(); GetAttributes(); _combinations = new Dictionary <string[], int>(new StringArrayComparer()); _numberOfCombination = 0; _lastInventoryID = null; _attributeValues = new string[_templateAttributes.Keys.Count]; _columnAttributeValue = null; _rowAttributeValue = null; var select = new PXSelectReadonly2 <CSAnswers, InnerJoin <CSAttributeGroup, On <CSAnswers.attributeID, Equal <CSAttributeGroup.attributeID> >, InnerJoin <InventoryItem, On <CSAnswers.refNoteID, Equal <InventoryItem.noteID>, And <CSAttributeGroup.entityClassID, Equal <InventoryItem.itemClassID> > > > >, Where <CSAttributeGroup.isActive, Equal <True>, And <CSAttributeGroup.entityType, Equal <Constants.DACName <InventoryItem> >, And <CSAttributeGroup.attributeCategory, Equal <CSAttributeGroup.attributeCategory.variant>, And <InventoryItem.templateItemID, Equal <Required <InventoryItem.inventoryID> > > > > >, OrderBy <Asc <InventoryItem.inventoryID, Asc <CSAttributeGroup.sortOrder, Asc <CSAttributeGroup.attributeID> > > > >(_graph); int attributesAreFilled = 0; using (new PXFieldScope(select.View, typeof(InventoryItem.inventoryID), typeof(CSAnswers.attributeID), typeof(CSAnswers.value))) { foreach (PXResult <CSAnswers, CSAttributeGroup, InventoryItem> result in select.Select(_template.InventoryID)) { InventoryItem inventoryItem = result; CSAnswers answer = result; RecalculateItem(inventoryItem, answer, ref attributesAreFilled); } } }
protected virtual IEnumerable internalResultRecords() { const bool useItemCostHistoryToOptimizeBalanceCalculation = true; // false to debug and ensure that INItemCostHistory corresponds to INCostTran InventoryTranByAcctEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.subItemCD>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.accountID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.subID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.inventoryID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.costAdj>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.finPerNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.tranPerNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.qty>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.unitCost>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay); var resultList = new List <PXResult <InventoryTranByAcctEnqResult, INTran> >(); decimal cumulativeBalance = 0m; if (filter.AccountID == null) { return(resultList); //empty } if (filter.FinPeriodID == null) { return(resultList); //empty } if (useItemCostHistoryToOptimizeBalanceCalculation) { PXSelectBase <INItemCostHist> cmd_CostHist = new PXSelectJoinGroupBy <INItemCostHist, InnerJoin <Sub, On <Sub.subID, Equal <INItemCostHist.subID> > >, Where <INItemCostHist.finPeriodID, Less <Current <InventoryTranByAcctEnqFilter.finPeriodID> > >, Aggregate < Sum <INItemCostHist.tranYtdCost, Sum <INItemCostHist.tranBegCost, Sum <INItemCostHist.finYtdCost, Sum <INItemCostHist.finBegCost> > > > > >(this); //if (filter.AccountID != null) // checked above { cmd_CostHist.WhereAnd <Where <INItemCostHist.accountID, Equal <Current <InventoryTranByAcctEnqFilter.accountID> > > >(); } if (!SubCDUtils.IsSubCDEmpty(filter.SubCD)) { cmd_CostHist.WhereAnd <Where <Sub.subCD, Like <Current <InventoryTranByAcctEnqFilter.subCDWildcard> > > >(); } PXResultset <INItemCostHist> costHistResult = (PXResultset <INItemCostHist>)cmd_CostHist.Select(); if (costHistResult.Count == 1) // 0 is possible too { if (filter.ByFinancialPeriod == true) { cumulativeBalance += (((INItemCostHist)costHistResult[0]).FinYtdCost ?? 0m) - (((INItemCostHist)costHistResult[0]).FinBegCost ?? 0m); } else { cumulativeBalance += (((INItemCostHist)costHistResult[0]).TranYtdCost ?? 0m) - (((INItemCostHist)costHistResult[0]).TranBegCost ?? 0m); } } } PXSelectBase <INTranCost> cmd = new PXSelectReadonly2 <INTranCost, InnerJoin <INTran, On <INTran.tranType, Equal <INTranCost.tranType>, And <INTran.refNbr, Equal <INTranCost.refNbr>, And <INTran.lineNbr, Equal <INTranCost.lineNbr> > > >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INTranCost.inventoryID>, And <Match <InventoryItem, Current <AccessInfo.userName> > > >, InnerJoin <Sub, On <Sub.subID, Equal <INTranCost.invtSubID> >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INTranCost.costSubItemID> >, LeftJoin <INSite, On <INSite.siteID, Equal <INTranCost.costSiteID> >, LeftJoin <INLocation, On <INLocation.locationID, Equal <INTranCost.costSiteID> >, LeftJoin <INCostStatus, On <INTranCost.costID, Equal <INCostStatus.costID> > > > > > > > >, Where <INSite.siteID, IsNull, Or <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranCost.tranDate, Asc <INTranCost.createdDateTime> > > >(this); //if (filter.FinPeriodID != null) // checked above if (filter.ByFinancialPeriod == true) { cmd.WhereAnd <Where <INTranCost.finPeriodID, Equal <Current <InventoryTranByAcctEnqFilter.finPeriodID> > > >(); } else { cmd.WhereAnd <Where <INTranCost.tranPeriodID, Equal <Current <InventoryTranByAcctEnqFilter.finPeriodID> > > >(); } //if (filter.AccountID != null) // checked above { cmd.WhereAnd <Where <INTranCost.invtAcctID, Equal <Current <InventoryTranByAcctEnqFilter.accountID> > > >(); } if (!SubCDUtils.IsSubCDEmpty(filter.SubCD)) { cmd.WhereAnd <Where <Sub.subCD, Like <Current <InventoryTranByAcctEnqFilter.subCDWildcard> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranCost.tranDate, LessEqual <Current <InventoryTranByAcctEnqFilter.endDate> > > >(); } if (filter.InventoryID != null) { cmd.WhereAnd <Where <INTranCost.inventoryID, Equal <Current <InventoryTranByAcctEnqFilter.inventoryID> > > >(); } if (filter.SiteID != null) { cmd.WhereAnd <Where <INTranCost.costSiteID, Equal <Current <InventoryTranByAcctEnqFilter.siteID> > > >(); } int gridLineNbr = 0; foreach (PXResult <INTranCost, INTran, InventoryItem, Sub, INSubItem, INSite, INLocation, INCostStatus> it in cmd.Select()) { INTranCost tc_rec = (INTranCost)it; INTran t_rec = (INTran)it; INSite s_rec = (INSite)it; INLocation l_rec = (INLocation)it; INSubItem si_rec = (INSubItem)it; INCostStatus cs_rec = (INCostStatus)it; decimal rowCost = (tc_rec.InvtMult * tc_rec.TranCost) ?? 0m; if (tc_rec.TranDate < filter.StartDate) { cumulativeBalance += rowCost; } else { if (summaryByDay) { if ((resultList.Count > 0) && (((InventoryTranByAcctEnqResult)resultList[resultList.Count - 1]).TranDate == tc_rec.TranDate)) { InventoryTranByAcctEnqResult lastItem = resultList[resultList.Count - 1]; if (rowCost >= 0) { lastItem.Debit += rowCost; } else { lastItem.Credit -= rowCost; } lastItem.EndBalance += rowCost; resultList[resultList.Count - 1] = new PXResult <InventoryTranByAcctEnqResult, INTran>(lastItem, null); } else { InventoryTranByAcctEnqResult item = new InventoryTranByAcctEnqResult(); item.BegBalance = cumulativeBalance; item.TranDate = tc_rec.TranDate; if (rowCost >= 0) { item.Debit = rowCost; item.Credit = 0m; } else { item.Debit = 0m; item.Credit = -rowCost; } item.EndBalance = item.BegBalance + rowCost; item.GridLineNbr = ++gridLineNbr; item.CreatedDateTime = tc_rec.CreatedDateTime; resultList.Add(new PXResult <InventoryTranByAcctEnqResult, INTran>(item, null)); } cumulativeBalance += rowCost; } else { InventoryTranByAcctEnqResult item = new InventoryTranByAcctEnqResult(); item.BegBalance = cumulativeBalance; item.TranDate = tc_rec.TranDate; if (rowCost >= 0) { item.Debit = rowCost; item.Credit = 0m; } else { item.Debit = 0m; item.Credit = -rowCost; } item.EndBalance = item.BegBalance + rowCost; item.AccountID = tc_rec.InvtAcctID; item.SubID = tc_rec.InvtSubID; item.TranType = tc_rec.TranType; item.DocType = t_rec.DocType; item.DocRefNbr = tc_rec.RefNbr; item.ReceiptNbr = cs_rec.ReceiptNbr; item.InventoryID = tc_rec.InventoryID; item.SubItemCD = si_rec.SubItemCD; if (s_rec.SiteID != null) { item.SiteID = s_rec.SiteID; item.LocationID = null; } else if (l_rec.LocationID != null) //though it's more or less guaranteed { item.SiteID = l_rec.SiteID; item.LocationID = l_rec.LocationID; } item.TranDate = tc_rec.TranDate; item.FinPerNbr = tc_rec.FinPeriodID; item.TranPerNbr = tc_rec.TranPeriodID; item.Qty = tc_rec.Qty * tc_rec.InvtMult; item.UnitCost = (tc_rec.Qty ?? 0m) == 0m ? null : ((tc_rec.TranCost ?? 0m) + (tc_rec.VarCost ?? 0m)) / tc_rec.Qty; item.CostAdj = tc_rec.CostRefNbr != tc_rec.RefNbr; item.GridLineNbr = ++gridLineNbr; item.CreatedDateTime = tc_rec.CreatedDateTime; resultList.Add(new PXResult <InventoryTranByAcctEnqResult, INTran>(item, t_rec)); cumulativeBalance += rowCost; } } } return(resultList); }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.inventoryID>(ResultRecords.Cache, null, false); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.finPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.tranPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.subItemID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.lotSerialNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay); var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran> >(); if (filter.InventoryID == null) { return(resultList); //empty } PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit, InnerJoin <INTran, On <INTran.docType, Equal <INTranSplit.docType>, And <INTran.refNbr, Equal <INTranSplit.refNbr>, And <INTran.lineNbr, Equal <INTranSplit.lineNbr> > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INTranSplit.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INTran.siteID> > > > >, Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranSplit.docType, Asc <INTranSplit.refNbr, Asc <INTranSplit.lineNbr, Asc <INTranSplit.splitLineNbr> > > > > >(this); PXSelectBase <INItemSiteHistByPeriod> cmdBegBalance = new PXSelectReadonly2 <INItemSiteHistByPeriod, InnerJoin <INItemSiteHist, On <INItemSiteHist.inventoryID, Equal <INItemSiteHistByPeriod.inventoryID>, And <INItemSiteHist.siteID, Equal <INItemSiteHistByPeriod.siteID>, And <INItemSiteHist.subItemID, Equal <INItemSiteHistByPeriod.subItemID>, And <INItemSiteHist.locationID, Equal <INItemSiteHistByPeriod.locationID>, And <INItemSiteHist.finPeriodID, Equal <INItemSiteHistByPeriod.lastActivityPeriod> > > > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INItemSiteHistByPeriod.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByPeriod.siteID> > > > >, Where <INItemSiteHistByPeriod.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <INItemSiteHistByPeriod.finPeriodID, Equal <Required <INItemSiteHistByPeriod.finPeriodID> >, And <Match <INSite, Current <AccessInfo.userName> > > > > >(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { cmdBegBalance.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>()) { cmdBegBalance.WhereAnd <Where <INItemSiteHistByPeriod.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmdBegBalance.WhereAnd <Where <INItemSiteHistByPeriod.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); } if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled <FeaturesSet.lotSerialTracking>()) { cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >(); } if (!includeUnreleased) { cmd.WhereAnd <Where <INTranSplit.released, Equal <True> > >(); } decimal cumulativeQty = 0m; string TranPeriodID; DateTime?PeriodStartDate; bool AnyPeriod = false; INSite site = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } int startRow = 0; int totalRows = 0; int maximumRows = 0; if (includeUnreleased) { PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); } foreach (PXResult <INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { foreach (PXResult <INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } } if (filter.StartDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Current <InventoryTranHistEnqFilter.startDate> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, LessEqual <Current <InventoryTranHistEnqFilter.endDate> > > >(); } string[] newSortColumns; bool[] newDescendings; AlterSorts(out newSortColumns, out newDescendings); PXFilterRow[] newFilters = AlterFilters(); //if user clicks last, sorts will be inverted //as it is not possible to calculate beginning balance from the end //we will select without top from the start and then apply reverse order and select top n records //for next page we will ommit startrow to set beginning balance correctly //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0 startRow = 0; maximumRows = !PXView.ReverseOrder ? PXView.StartRow + PXView.MaximumRows : 0; totalRows = 0; PXView selectView = !summaryByDay ? cmd.View : new PXView(this, true, cmd.View.BqlSelect.AggregateNew <Aggregate <GroupBy <INTranSplit.tranDate, Sum <INTranSplit.qtyIn, Sum <INTranSplit.qtyOut> > > > >()); List <object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate }, new string[newSortColumns.Length], newSortColumns, PXView.Descendings, newFilters, ref startRow, maximumRows, ref totalRows); int gridLineNbr = 0; foreach (PXResult <INTranSplit, INTran, INSubItem> it in intermediateResult) { INTranSplit ts_rec = (INTranSplit)it; INTran t_rec = (INTran)it; if (ts_rec.TranDate < filter.StartDate) { cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } else { if (summaryByDay) { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, null)); cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.InventoryID = ts_rec.InventoryID; item.TranType = ts_rec.TranType; item.DocType = ts_rec.DocType; item.DocRefNbr = ts_rec.RefNbr; item.SubItemID = ts_rec.SubItemID; item.SiteID = ts_rec.SiteID; item.LocationID = ts_rec.LocationID; item.LotSerialNbr = ts_rec.LotSerialNbr; item.FinPerNbr = t_rec.FinPeriodID; item.TranPerNbr = t_rec.TranPeriodID; item.Released = t_rec.Released; item.GridLineNbr = ++gridLineNbr; decimal?unitcost; if (filter.ShowAdjUnitCost ?? false) { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m; } else { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m; } item.UnitCost = unitcost; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, t_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } if (!PXView.ReverseOrder) { return(resultList); } return(PXView.Sort(resultList)); }
public static void ReleaseDoc(CABatch aDocument) { if ((bool)aDocument.Released || (bool)aDocument.Hold) { throw new PXException(Messages.CABatchStatusIsNotValidForProcessing); } CABatchUpdate batchEntry = PXGraph.CreateInstance <CABatchUpdate>(); CABatch document = batchEntry.Document.Select(aDocument.BatchNbr); batchEntry.Document.Current = document; if ((bool)document.Released || (bool)document.Hold) { throw new PXException(Messages.CABatchStatusIsNotValidForProcessing); } APRegister voided = PXSelectReadonly2 <APRegister, InnerJoin <CABatchDetail, On <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP>, And <CABatchDetail.origDocType, Equal <APRegister.docType>, And <CABatchDetail.origRefNbr, Equal <APRegister.refNbr> > > > >, Where <CABatchDetail.batchNbr, Equal <Required <CABatch.batchNbr> >, And <APRegister.voided, Equal <True> > > > .Select(batchEntry, document.BatchNbr); if (voided != null && string.IsNullOrEmpty(voided.RefNbr) == false) { throw new PXException(Messages.CABatchContainsVoidedPaymentsAndConnotBeReleased); } List <APRegister> unreleasedList = new List <APRegister>(); PXSelectBase <APPayment> selectUnreleased = new PXSelectReadonly2 <APPayment, InnerJoin <CABatchDetail, On <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP>, And <CABatchDetail.origDocType, Equal <APPayment.docType>, And <CABatchDetail.origRefNbr, Equal <APPayment.refNbr> > > > >, Where <CABatchDetail.batchNbr, Equal <Optional <CABatch.batchNbr> >, And <APPayment.released, Equal <boolFalse> > > >(batchEntry); foreach (APPayment item in selectUnreleased.Select(document.BatchNbr)) { if (item.Released != true) { unreleasedList.Add(item); } } if (unreleasedList.Count > 0) { APDocumentRelease.ReleaseDoc(unreleasedList, true); } selectUnreleased.View.Clear(); APPayment payment = selectUnreleased.Select(document.BatchNbr); if (payment != null) { throw new PXException(Messages.CABatchContainsUnreleasedPaymentsAndCannotBeReleased); } document.Released = true; document.DateSeqNbr = GetNextDateSeqNbr(batchEntry, aDocument); batchEntry.RecalcTotals(); document = batchEntry.Document.Update(document); batchEntry.Actions.PressSave(); }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >(); if (filter.InventoryID == null) { PXDelegateResult emptyResult = new PXDelegateResult(); emptyResult.IsResultFiltered = true; emptyResult.IsResultSorted = true; emptyResult.IsResultTruncated = true; return(emptyResult); //empty } PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit, InnerJoin <INTran, On <INTranSplit.FK.Tran>, InnerJoin <INSubItem, On <INTranSplit.FK.SubItem>, InnerJoin <INSite, On <INTran.FK.Site> > > >, Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranSplit.docType, Asc <INTranSplit.refNbr, Asc <INTranSplit.lineNbr, Asc <INTranSplit.splitLineNbr> > > > > >(this); PXSelectBase <INItemSiteHistByDay> cmdBegBalanceNew = new PXSelectReadonly2 <INItemSiteHistByDay, InnerJoin <INItemSiteHistDay, On <INItemSiteHistDay.inventoryID, Equal <INItemSiteHistByDay.inventoryID>, And <INItemSiteHistDay.siteID, Equal <INItemSiteHistByDay.siteID>, And <INItemSiteHistDay.subItemID, Equal <INItemSiteHistByDay.subItemID>, And <INItemSiteHistDay.locationID, Equal <INItemSiteHistByDay.locationID>, And <INItemSiteHistDay.sDate, Equal <INItemSiteHistByDay.lastActivityDate> > > > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INItemSiteHistByDay.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByDay.siteID> > > > >, Where <INItemSiteHistByDay.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <INItemSiteHistByDay.date, Equal <Required <INItemSiteHistByDay.date> >, And <Match <INSite, Current <AccessInfo.userName> > > > > >(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); cmdBegBalanceNew.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>()) { cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); } if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled <FeaturesSet.lotSerialTracking>()) { cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >(); } if (!includeUnreleased) { cmd.WhereAnd <Where <INTranSplit.released, Equal <True> > >(); } decimal cumulativeQty = 0m; if (filter.StartDate != null) { foreach (PXResult <INItemSiteHistByDay, INItemSiteHistDay> res in cmdBegBalanceNew.Select(filter.StartDate)) { INItemSiteHistByDay byday = res; INItemSiteHistDay hist = res; cumulativeQty += ((byday.LastActivityDate != null && byday.Date != null && byday.Date.Value.Date == byday.LastActivityDate.Value.Date) ? hist.BegQty : hist.EndQty) ?? 0m; } if (includeUnreleased) { INSite site = INSite.PK.Find(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; string TranPeriodID; DateTime?PeriodStartDate; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.released, Equal <False> > >() .AggregateNew <Aggregate < GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); int splitStartRow = 0; int splitTotalRows = 0; foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate.Value }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref splitStartRow, 0, ref splitTotalRows)) { INTranSplit tsRec = res; cumulativeQty += (tsRec.InvtMult * tsRec.BaseQty) ?? 0m; } } } } if (filter.StartDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Current <InventoryTranHistEnqFilter.startDate> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, LessEqual <Current <InventoryTranHistEnqFilter.endDate> > > >(); } AlterSortsAndFilters(out string[] newSortColumns, out bool[] newDescendings, out bool sortsChanged, out PXFilterRow[] newFilters, out bool filtersChanged); //if user clicks last, sorts will be inverted //as it is not possible to calculate beginning balance from the end //we will select without top from the start and then apply reverse order and select top n records //for next page we will ommit startrow to set beginning balance correctly //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0 //Also, user can set a filter or sort by a column from result DAC (sortsChanged = true, filtersChanged = true) and need to get full result set. int startRow = 0; bool allowSelectWithTop = !sortsChanged && !filtersChanged && !PXView.ReverseOrder; int maximumRows = allowSelectWithTop ? PXView.StartRow + PXView.MaximumRows : 0; int totalRows = 0; PXView selectView = !summaryByDay ? cmd.View : new PXView(this, true, cmd.View.BqlSelect .AggregateNew <Aggregate <GroupBy <INTranSplit.tranDate, Sum <INTranSplit.qtyIn, Sum <INTranSplit.qtyOut> > > > >()); List <object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate }, new string[newSortColumns.Length], newSortColumns, newDescendings, newFilters, ref startRow, maximumRows, ref totalRows); int gridLineNbr = 0; foreach (PXResult <INTranSplit, INTran, INSubItem> it in intermediateResult) { INTranSplit ts_rec = (INTranSplit)it; INTran t_rec = (INTran)it; if (summaryByDay) { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, null, null)); cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.DocType = ts_rec.DocType; item.RefNbr = ts_rec.RefNbr; item.LineNbr = ts_rec.LineNbr; item.SplitLineNbr = ts_rec.SplitLineNbr; item.GridLineNbr = ++gridLineNbr; decimal?unitcost; if (filter.ShowAdjUnitCost ?? false) { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m; } else { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m; } item.UnitCost = unitcost; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, t_rec, ts_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } PXDelegateResult delegateResult = new PXDelegateResult(); delegateResult.IsResultFiltered = !filtersChanged; delegateResult.IsResultSorted = !sortsChanged; delegateResult.IsResultTruncated = totalRows > resultList.Count; if (!PXView.ReverseOrder) { delegateResult.AddRange(resultList); } else { var sortedList = PXView.Sort(resultList); delegateResult.AddRange(sortedList.Cast <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >()); delegateResult.IsResultSorted = true; } return(delegateResult); }
/// <summary> /// Process Costs for a BOM. /// Copy standard method and add one more parameter to control qty round-up. /// </summary> protected virtual bool ProcessCost(AMBomItem bomItem, int level, bool isDefault, bool roundup = true) { var successful = true; if (bomItem?.BOMID == null) { return(false); } var bomcostrec = new AMBomCost { InventoryID = bomItem.InventoryID, SubItemID = bomItem.SubItemID, BOMID = bomItem.BOMID, RevisionID = bomItem.RevisionID, SiteID = bomItem.SiteID, MultiLevelProcess = Settings.Current.SnglMlti == RollupSettings.SelectOptSM.Multi, UserID = this.Accessinfo.UserID, Level = level, // Might have to update later for subitem indication - currently only looks at INItemSite default BOM ID IsDefaultBom = isDefault }; var invItem = JAMS.AM.InventoryHelper.CacheQueryInventoryItem(InvItemRecs.Cache, bomcostrec.InventoryID); bomcostrec.ItemClassID = invItem?.ItemClassID; //Set the Current and Pending cost from INItemSite var inItemSite = JAMS.AM.InventoryHelper.CacheQueryINItemSite(ItemSiteRecs.Cache, bomcostrec.InventoryID, bomcostrec.SiteID); bomcostrec.StdCost = inItemSite?.StdCost; bomcostrec.PendingStdCost = inItemSite?.PendingStdCost; // Set Lot Size based on Filter Settings if (Settings.Current.IgnoreMinMaxLotSizeValues == true) { bomcostrec.LotSize = 1; } else if (bomcostrec.BOMID == Settings.Current.BOMID && Settings.Current.LotSize.GetValueOrDefault() != 0 && Settings.Current.IgnoreMinMaxLotSizeValues == false) { bomcostrec.LotSize = Settings.Current.LotSize.GetValueOrDefault(); } else { bomcostrec.LotSize = invItem == null ? JAMS.AM.InventoryHelper.GetMfgReorderQty(this, bomcostrec.InventoryID, bomcostrec.SiteID) : JAMS.AM.InventoryHelper.GetMfgReorderQty(this, invItem, inItemSite); } if (bomcostrec.LotSize.GetValueOrDefault() <= 0) { bomcostrec.LotSize = 1; } bomcostrec.FLaborCost = 0; bomcostrec.VLaborCost = 0; var laborCostAndHours = SetLaborCost(ref bomcostrec, Settings.Current?.IncFixed == true); bomcostrec.MachCost = GetMachineCost(bomcostrec); bomcostrec.ToolCost = GetToolCost(bomcostrec); var allMaterial = PXSelectReadonly2 <AMBomMatl, InnerJoin <InventoryItem, On <AMBomMatl.inventoryID, Equal <InventoryItem.inventoryID> >, LeftJoin <INItemSite, On <AMBomMatl.inventoryID, Equal <INItemSite.inventoryID>, And <INItemSite.siteID, Equal <Required <INItemSite.siteID> > > > > >, Where <AMBomMatl.bOMID, Equal <Required <AMBomMatl.bOMID> >, And <AMBomMatl.revisionID, Equal <Required <AMBomMatl.revisionID> > > > > .Select(this, bomcostrec.SiteID, bomcostrec.BOMID, bomcostrec.RevisionID); //Merge of Regular Material and Subcontract Material (excluding Reference/vendor supplied material) OperationCosts matlTotal = new OperationCosts(); if (allMaterial.Count > 0) { var purchase = new List <PXResult <AMBomMatl, InventoryItem> >(); var manufactured = new List <PXResult <AMBomMatl, InventoryItem> >(); var subcontract = new List <PXResult <AMBomMatl, InventoryItem> >(); var refMaterial = new List <PXResult <AMBomMatl, InventoryItem> >(); foreach (PXResult <AMBomMatl, InventoryItem, INItemSite> result in allMaterial) { var bomMatl = (AMBomMatl)result; if (bomMatl == null || (bomMatl.EffDate != null && bomMatl.EffDate > Accessinfo.BusinessDate) || (bomMatl.ExpDate != null && bomMatl.ExpDate <= Accessinfo.BusinessDate)) { continue; } // Check for COMP BOMID, if exists, item is Manufactured if (bomMatl.CompBOMID != null) { manufactured.Add(result); continue; } if (bomMatl.MaterialType == AMMaterialType.Subcontract && bomMatl.SubcontractSource != AMSubcontractSource.VendorSupplied) { subcontract.Add(result); continue; } if (bomMatl.MaterialType == AMMaterialType.Subcontract && bomMatl.SubcontractSource == AMSubcontractSource.VendorSupplied) { refMaterial.Add(result); continue; } var replenishmentSource = JAMS.AM.InventoryHelper.GetReplenishmentSource((InventoryItem)result, (INItemSite)result); if (replenishmentSource == INReplenishmentSource.Manufactured) { manufactured.Add(result); continue; } if (replenishmentSource == INReplenishmentSource.Purchased) { purchase.Add(result); } } var purchaseCost = GetMaterialCost(bomcostrec, purchase, IsMultiLevel, out var purchaseMatlMessages, roundup); var manufacturedCost = GetMaterialCost(bomcostrec, manufactured, IsMultiLevel, out var manufacturedMatlMessages, roundup); var subcontractCost = GetMaterialCost(bomcostrec, subcontract, IsMultiLevel, out var subContractMatlMessages, roundup); var refmaterialCost = GetMaterialCost(bomcostrec, refMaterial, IsMultiLevel, out var refMaterialMatlMessages, roundup); if (purchaseMatlMessages != null) { foreach (var matlMessage in purchaseMatlMessages) { successful = false; PXTrace.WriteWarning(matlMessage); } } if (manufacturedMatlMessages != null) { foreach (var matlMessage in manufacturedMatlMessages) { successful = false; PXTrace.WriteWarning(matlMessage); } } if (subContractMatlMessages != null) { foreach (var matlMessage in subContractMatlMessages) { successful = false; PXTrace.WriteWarning(matlMessage); } } if (refMaterialMatlMessages != null) { foreach (var matlMessage in refMaterialMatlMessages) { successful = false; PXTrace.WriteWarning(matlMessage); } } bomcostrec.MatlManufacturedCost = manufacturedCost?.TotalCost ?? 0m; bomcostrec.MatlNonManufacturedCost = purchaseCost?.TotalCost ?? 0m; bomcostrec.SubcontractMaterialCost = subcontractCost?.TotalCost ?? 0m; bomcostrec.ReferenceMaterialCost = refmaterialCost?.TotalCost ?? 0m; matlTotal = new OperationCosts(manufacturedCost); matlTotal.Add(purchaseCost, true); matlTotal.Add(subcontractCost, true); } bomcostrec.FOvdCost = 0; bomcostrec.VOvdCost = 0; SetOverheadCosts(ref bomcostrec, Settings.Current.IncFixed.GetValueOrDefault(), matlTotal, laborCostAndHours.Item1, laborCostAndHours.Item2); bomcostrec.TotalCost = bomcostrec.FLaborCost.GetValueOrDefault() + bomcostrec.VLaborCost.GetValueOrDefault() + bomcostrec.MachCost.GetValueOrDefault() + bomcostrec.MatlManufacturedCost.GetValueOrDefault() + bomcostrec.MatlNonManufacturedCost.GetValueOrDefault() + bomcostrec.FOvdCost.GetValueOrDefault() + bomcostrec.VOvdCost.GetValueOrDefault() + bomcostrec.ToolCost.GetValueOrDefault() + bomcostrec.OutsideCost.GetValueOrDefault() + bomcostrec.DirectCost.GetValueOrDefault() + bomcostrec.SubcontractMaterialCost.GetValueOrDefault() + bomcostrec.ReferenceMaterialCost.GetValueOrDefault(); bomcostrec.UnitCost = UomHelper.PriceCostRound(bomcostrec.TotalCost.GetValueOrDefault() / bomcostrec.LotSize.GetValueOrDefault()); try { BomCostRecs.Insert(bomcostrec); } catch (Exception e) { if (e is PXOuterException) { PXTraceHelper.PxTraceOuterException((PXOuterException)e, PXTraceHelper.ErrorLevel.Error); } InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, bomcostrec.InventoryID); if (item == null) { PXTrace.WriteInformation(JAMS.AM.Messages.InvalidInventoryIDOnBOM, bomItem.BOMID); successful = false; } else { throw new PXException(JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.UnableToSaveRecordForInventoryID), JAMS.AM.Messages.GetLocal(JAMS.AM.Messages.BOMCost), item.InventoryCD.Trim(), e.Message); } } return(successful); }