Exemplo n.º 1
0
        protected virtual void PMTran_InventoryID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMTran row = (PMTran)e.Row;

            if (row?.InventoryID == null)
            {
                return;
            }
            InventoryItem inventory = PXSelect <InventoryItem,
                                                Where <InventoryItem.inventoryID, Equal <Required <PMTran.inventoryID> > > > .Select(this, row.InventoryID);

            if (inventory != null)
            {
                row.Description = inventory.Descr;

                PMProject project = PXSelect <PMProject,
                                              Where <PMProject.contractID, Equal <Required <PMTran.projectID> > > > .Select(this, row.ProjectID);

                if (project != null && project.CustomerID != null)
                {
                    Customer customer = PXSelect <Customer,
                                                  Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(this, project.CustomerID);

                    if (customer != null && !string.IsNullOrEmpty(customer.LocaleName))
                    {
                        row.Description = PXDBLocalizableStringAttribute.GetTranslation(Caches[typeof(InventoryItem)], inventory, nameof(InventoryItem.Descr), customer.LocaleName);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void InsertDefaultProject(PMSetup row)
        {
            PMProject rec = new PMProject();

            rec.CustomerID  = null;
            rec.ContractCD  = row.NonProjectCode;
            rec.Description = PXLocalizer.Localize(Messages.NonProjectDescription);
            PXDBLocalizableStringAttribute.SetTranslationsFromMessage <PMProject.description>
                (Caches[typeof(PMProject)], rec, Messages.NonProjectDescription);
            rec.StartDate       = new DateTime(DateTime.Now.Year, 1, 1);
            rec.CuryID          = Company.Current.BaseCuryID;
            rec.IsActive        = true;
            rec.Status          = ProjectStatus.Active;
            rec.ServiceActivate = false;
            rec.VisibleInAP     = true;
            rec.VisibleInAR     = true;
            rec.VisibleInCA     = true;
            rec.VisibleInCR     = true;
            rec.VisibleInEA     = true;
            rec.VisibleInGL     = true;
            rec.VisibleInIN     = true;
            rec.VisibleInPO     = true;
            rec.VisibleInSO     = true;
            rec.VisibleInTA     = true;
            rec = DefaultProject.Insert(rec);
        }
        protected virtual void OnPMDetailInventoryIDFieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMDetail row = e.Row as PMDetail;

            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, row.InventoryID);

            if (item != null && row != null)
            {
                row.UOM         = item.SalesUnit;
                row.ItemFee     = item.BasePrice;
                row.Description = item.Descr;

                if (Task.Current != null && Task.Current.CustomerID != null)
                {
                    Customer customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Current <PMTask.customerID> > > > .Select(this);

                    if (customer != null && !string.IsNullOrEmpty(customer.LocaleName))
                    {
                        row.Description = PXDBLocalizableStringAttribute.GetTranslation(Caches[typeof(InventoryItem)], item, nameof(InventoryItem.Descr), customer.LocaleName);
                    }
                }

                sender.SetDefaultExt <PMDetail.curyItemFee>(e.Row);
            }
        }
        protected virtual void OnPMDetailInventoryIDFieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            PMDetail row = (PMDetail)e.Row;

            if (row == null)
            {
                return;
            }

            InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, row.InventoryID);

            if (item != null)
            {
                row.UOM         = item.SalesUnit;
                row.ItemFee     = item.BasePrice;
                row.Description = item.Descr;
                PMProject project = PXSelectorAttribute.Select <PMTran.projectID>(sender, e.Row) as PMProject;

                if (project != null && project.CustomerID != null)
                {
                    AR.Customer customer = PXSelectReadonly <AR.Customer, Where <AR.Customer.bAccountID, Equal <Required <AR.Customer.bAccountID> > > > .Select(this, project.CustomerID);

                    if (!string.IsNullOrEmpty(customer?.LocaleName))
                    {
                        row.Description = PXDBLocalizableStringAttribute.GetTranslation(Caches[typeof(InventoryItem)], item, nameof(InventoryItem.Descr), customer.LocaleName);
                    }
                }
                sender.SetDefaultExt <PMDetail.curyItemFee>(e.Row);
            }
        }
        /// <summary>The FieldDefaulting2 event handler for the <see cref="Detail.Descr" /> field.</summary>
        /// <param name="e">Parameters of the event.</param>
        protected virtual void _(Events.FieldDefaulting <Detail, Detail.descr> e)
        {
            Document doc      = Documents.Current;
            Customer customer = PXSelectReadonly <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(Base, doc.BAccountID);

            InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <Detail.inventoryID>(Details.Cache, e.Row);

            e.NewValue = PXDBLocalizableStringAttribute.GetTranslation(Base.Caches[typeof(InventoryItem)],
                                                                       item, nameof(InventoryItem.Descr), customer?.LocaleName);
        }
        public virtual void RedefaultTasksFromTemplate(PMQuote quote, Action <PMQuote> baseHandler)
        {
            Base.Tasks.Cache.ClearQueryCache();
            var tasks = ProjectTaskDataProvider.GetProjectTasks(Base, quote.TemplateID);

            foreach (var task in tasks)
            {
                var quoteTask = InsertQuoteTask(quote, task);
                PXDBLocalizableStringAttribute.CopyTranslations <PMTask.description, PMQuoteTask.description>(
                    Base.Caches <PMTask>(), task, Base.Tasks.Cache, quoteTask);
            }
        }
        private PaymentMethodDetail addDefaultsToDetails(CreditCardAttributes.AttributeName aAttr, string aDescr)
        {
            PaymentMethodDetail det = new PaymentMethodDetail();

            ImportDefaults(det, aAttr);
            det.Descr  = aDescr;
            det.UseFor = PaymentMethodDetailUsage.UseForARCards;
            det        = (PaymentMethodDetail)this.Details.Cache.Insert(det);
            if (PXDBLocalizableStringAttribute.IsEnabled)
            {
                PXDBLocalizableStringAttribute.DefaultTranslationsFromMessage(this.Details.Cache, det, "Descr", aDescr);
            }
            return(det);
        }
        protected virtual void ContractDetail_ContractItemID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            ContractDetail row = e.Row as ContractDetail;

            ContractItem item = PXSelect <ContractItem, Where <ContractItem.contractItemID, Equal <Required <ContractItem.contractItemID> > > > .Select(this, row.ContractItemID);

            if (item != null && row != null)
            {
                row.Description = item.Descr;
                PXDBLocalizableStringAttribute.CopyTranslations <ContractItem.descr, ContractDetail.description>
                    (Caches[typeof(ContractItem)], item, Caches[typeof(ContractDetail)], row);
                row.Qty = item.DefaultQty;
            }
        }
        protected virtual OrganizationFinPeriod GenerateAdjustmentOrganizationFinPeriod(int organizationID, OrganizationFinPeriod prevFinPeriod)
        {
            (string masterYearNumber, string masterPeriodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID);
            MasterFinYear masterFinYear = FinPeriodRepository.FindMasterFinYearByID(masterYearNumber, clearQueryCache: true);
            string        adjustmentMasterFinPeriodID = $"{masterYearNumber:0000}{masterFinYear.FinPeriods:00}";

            (string yearNumber, string periodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID);
            periodNumber = $"{int.Parse(periodNumber) + 1:00}";
            OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod
            {
                OrganizationID    = organizationID,
                FinPeriodID       = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber),
                MasterFinPeriodID = adjustmentMasterFinPeriodID,
                FinYear           = yearNumber,
                PeriodNbr         = periodNumber,
                Custom            = prevFinPeriod.Custom,
                DateLocked        = prevFinPeriod.DateLocked,
                StartDate         = prevFinPeriod.EndDate,
                EndDate           = prevFinPeriod.EndDate,

                Status   = prevFinPeriod.Status,
                ARClosed = prevFinPeriod.ARClosed,
                APClosed = prevFinPeriod.APClosed,
                FAClosed = prevFinPeriod.FAClosed,
                CAClosed = prevFinPeriod.CAClosed,
                INClosed = prevFinPeriod.INClosed,

                Descr = Messages.AdjustmentPeriod,
            };

            MasterFinPeriod masterFinPeriod = FinPeriodRepository.FindMasterFinPeriodByID(adjustmentMasterFinPeriodID);

            PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod);

            return(orgFinPeriod);
        }
        /// <summary>
        /// TODO: Share function in <see cref="OrganizationMaint.CreateOrganizationCalendar"/> function
        /// </summary>
        /// <param name="organizationID"></param>
        /// <param name="masterFinPeriod"></param>
        /// <returns></returns>
        protected virtual OrganizationFinPeriod CopyOrganizationFinPeriodFromMaster(
            int organizationID,
            MasterFinPeriod masterFinPeriod,
            FinPeriod orgFinPeriodStatusSource,
            string yearNumber   = null,
            string periodNumber = null)
        {
            bool   isCentralizedManagement = PXAccess.FeatureInstalled <FeaturesSet.centralizedPeriodsManagement>();
            string organizationFinPeriodID = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber) ?? masterFinPeriod.FinPeriodID;

            OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod
            {
                OrganizationID    = organizationID,
                FinPeriodID       = organizationFinPeriodID,
                MasterFinPeriodID = masterFinPeriod.FinPeriodID,
                FinYear           = yearNumber ?? masterFinPeriod.FinYear,
                PeriodNbr         = periodNumber ?? masterFinPeriod.PeriodNbr,
                Custom            = masterFinPeriod.Custom,
                DateLocked        = masterFinPeriod.DateLocked,
                StartDate         = masterFinPeriod.StartDate,
                EndDate           = masterFinPeriod.EndDate,

                Status   = isCentralizedManagement ? masterFinPeriod.Status : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.Status : FinPeriod.status.Inactive,
                ARClosed = isCentralizedManagement ? masterFinPeriod.ARClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.ARClosed : false,
                APClosed = isCentralizedManagement ? masterFinPeriod.APClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.APClosed : false,
                FAClosed = isCentralizedManagement ? masterFinPeriod.FAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.FAClosed : false,
                CAClosed = isCentralizedManagement ? masterFinPeriod.CAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.CAClosed : false,
                INClosed = isCentralizedManagement ? masterFinPeriod.INClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.INClosed : false,

                Descr = masterFinPeriod.Descr,
            };

            PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod);

            return(orgFinPeriod);
        }
		public virtual void CreateUpdateMatrixItems(InventoryItemMaintBase graph, InventoryItem templateItem, IEnumerable<MatrixInventoryItem> itemsToCreateUpdate, bool create,
			Action<MatrixInventoryItem, InventoryItem> beforeSave = null)
		{
			Dictionary<string, string> templateAttrValues =
				PXSelectReadonly<CSAnswers, Where<CSAnswers.refNoteID, Equal<Required<InventoryItem.noteID>>>>
				.Select(graph, templateItem.NoteID)
				.RowCast<CSAnswers>()
				.ToDictionary(a => a.AttributeID, a => a.Value, StringComparer.OrdinalIgnoreCase);
			IEnumerable<POVendorInventory> templateVendorInvs =
				graph.VendorItems.View.SelectMultiBound(new[] { templateItem })
				.RowCast<POVendorInventory>()
				.ToArray();
			IEnumerable<INUnit> templateItemConvs =
				graph.itemunits.View.SelectMultiBound(new[] { templateItem })
				.RowCast<INUnit>()
				.ToArray();
			IEnumerable<INItemCategory> templateItemCategs =
				graph.Category.View.SelectMultiBound(new[] { templateItem })
				.RowCast<INItemCategory>()
				.ToArray();
			IEnumerable<INItemBoxEx> templateBoxes = null;
			InventoryItemMaint stockItemGraph = null;
			if (templateItem.StkItem == true)
			{
				stockItemGraph = (InventoryItemMaint)graph;
				templateBoxes = stockItemGraph.Boxes.View.SelectMultiBound(new[] { templateItem })
					.RowCast<INItemBoxEx>()
					.ToArray();
			}

			foreach (MatrixInventoryItem itemToCreateUpdate in itemsToCreateUpdate)
			{
				graph.Clear();

				InventoryItem item;
				if (create)
				{
					item = new InventoryItem
					{
						InventoryCD = itemToCreateUpdate.InventoryCD
					};
					item = graph.Item.Insert(item);
				}
				else
				{
					item = graph.Item.Current = graph.Item.Search<InventoryItem.inventoryCD>(itemToCreateUpdate.InventoryCD);
				}
				if (item == null)
				{
					throw new PXInvalidOperationException();
				}

				if (create)
				{
					item = AssignInventoryField<InventoryItem.descr>(graph, item, itemToCreateUpdate.Descr);
					PXDBLocalizableStringAttribute.CopyTranslations<MatrixInventoryItem.descr, InventoryItem.descr>(graph, itemToCreateUpdate, item);
				}
				item = AssignInventoryField<InventoryItem.itemClassID>(graph, item, templateItem.ItemClassID);
				item = AssignInventoryField<InventoryItem.postClassID>(graph, item, templateItem.PostClassID);
				AssignConversionsSettings(graph, item, templateItem);
				item = AssignRestInventoryFields(graph, item, templateItem);
				item = AssignInventoryField<InventoryItem.templateItemID>(graph, item, templateItem.InventoryID);

				AssignInventoryAttributes(graph, itemToCreateUpdate, templateAttrValues);
				AssignVendorInventory(graph, templateVendorInvs);
				AssignInventoryConversions(graph, templateItemConvs);
				AssignInventoryCategories(graph, templateItemCategs);
				if (templateItem.StkItem == true)
					AssignInventoryBoxes(stockItemGraph, templateBoxes);

				beforeSave?.Invoke(itemToCreateUpdate, item);

				graph.Save.Press();

				itemToCreateUpdate.InventoryID = item.InventoryID;
			}
		}
        public static void X_InventoryID_FieldUpdated <DAC, SubItemID,
                                                       SiteID, SiteLocationID, UOM,
                                                       EstimatedDuration, EstimatedQty, BillingRule,
                                                       ActualDuration, ActualQty>(
            PXCache cache,
            PXFieldUpdatedEventArgs e,
            int?branchLocationID,
            Customer billCustomerRow,
            bool useActualFields)
            where DAC : class, IBqlTable, IFSSODetBase, new()
            where SubItemID : class, IBqlField
            where SiteID : class, IBqlField
            where SiteLocationID : class, IBqlField
            where UOM : class, IBqlField
            where EstimatedDuration : class, IBqlField
            where EstimatedQty : class, IBqlField
            where BillingRule : class, IBqlField
            where ActualDuration : class, IBqlField
            where ActualQty : class, IBqlField
        {
            if (e.Row == null)
            {
                return;
            }

            var row = (DAC)e.Row;

            // This is required in Inventory FieldUpdated events
            if (e.ExternalCall)
            {
                row.CuryUnitPrice = 0m;
            }


            if (IsInventoryLine(row.LineType) == false ||
                (row.InventoryID == null && row.LineType != ID.LineType_All.PICKUP_DELIVERY))
            {
                // Clear fields for non-inventory lines

                row.IsBillable  = false;
                row.ManualPrice = false;

                row.TranDesc       = null;
                row.SubItemID      = null;
                row.SiteID         = null;
                row.SiteLocationID = null;

                cache.SetDefaultExt <FSSODet.uOM>(e.Row);

                cache.RaiseExceptionHandling <UOM>(e.Row, null, null);

                row.SetDuration(FieldType.EstimatedField, 0, cache, false);
                row.SetQty(FieldType.EstimatedField, 0, cache, false);

                if (useActualFields == true)
                {
                    row.SetDuration(FieldType.ActualField, 0, cache, false);
                    row.SetQty(FieldType.ActualField, 0, cache, false);
                }

                row.BillingRule = ID.BillingRule.NONE;

                return;
            }

            InventoryItem inventoryItemRow = SharedFunctions.GetInventoryItemRow(cache.Graph, row.InventoryID);

            row.TranDesc = null;
            if (inventoryItemRow != null)
            {
                row.TranDesc = PXDBLocalizableStringAttribute.GetTranslation(cache.Graph.Caches[typeof(InventoryItem)], inventoryItemRow, "Descr", billCustomerRow?.LocaleName);
            }


            // UOM is assigned to null here to avoid price calculation while duration and qty fields are defaulted.
            row.UOM = null;
            cache.RaiseExceptionHandling <UOM>(e.Row, null, null);

            cache.SetDefaultExt <SubItemID>(e.Row);
            cache.SetDefaultExt <SiteID>(e.Row);

            if (inventoryItemRow != null)
            {
                if (row.SiteID == null)
                {
                    row.SiteID = inventoryItemRow.DfltSiteID;
                }

                if (row.SiteID == null)
                {
                    //TODO: this query may return multiple records
                    INItemSite inItemSiteRow = PXSelect <INItemSite,
                                                         Where <
                                                             INItemSite.inventoryID, Equal <Required <INItemSite.inventoryID> > > >
                                               .Select(cache.Graph, inventoryItemRow.InventoryID);

                    if (inItemSiteRow != null)
                    {
                        row.SiteID = inItemSiteRow.SiteID;
                    }
                }
            }

            cache.SetDefaultExt <SiteLocationID>(e.Row);

            if (inventoryItemRow != null)
            {
                if (row.SiteLocationID == null && row.LineType == ID.LineType_All.INVENTORY_ITEM)
                {
                    row.SiteLocationID = inventoryItemRow.DfltShipLocationID;
                }
            }

            int?   defaultSubItemID = row.SubItemID;
            object newValue         = null;

            cache.RaiseFieldDefaulting <UOM>(e.Row, out newValue);
            string defaultUOM    = (string)newValue;
            int?   defaultSiteID = row.SiteID;

            CompleteItemInfoUsingBranchLocation(
                cache.Graph,
                branchLocationID,
                inventoryItemRow != null ? inventoryItemRow.DefaultSubItemOnEntry : false,
                ref defaultSubItemID,
                ref defaultUOM,
                ref defaultSiteID);
            row.SubItemID = defaultSubItemID;

            if (defaultSiteID != null)
            {
                cache.SetValueExt <SiteID>(e.Row, defaultSiteID);
            }

            cache.SetValueExt <UOM>(e.Row, defaultUOM);

            row.SetDuration(FieldType.EstimatedField, 0, cache, false);

            // EstimatedQty MUST be assigned after BillingRule BUT before EstimatedDuration.

            if (row.LineType == ID.LineType_All.SERVICE && inventoryItemRow != null)
            {
                FSxService fsxServiceRow = PXCache <InventoryItem> .GetExtension <FSxService>(inventoryItemRow);

                cache.SetValueExt <BillingRule>(e.Row, fsxServiceRow.BillingRule);
                cache.SetDefaultExt <EstimatedQty>(e.Row);

                cache.SetValueExt <EstimatedDuration>(e.Row, fsxServiceRow.EstimatedDuration ?? 0);
            }
            else
            {
                cache.SetValueExt <BillingRule>(e.Row, ID.BillingRule.FLAT_RATE);
                cache.SetDefaultExt <EstimatedQty>(e.Row);
            }

            if (useActualFields == true)
            {
                cache.SetDefaultExt <ActualQty>(e.Row);
                cache.SetDefaultExt <ActualDuration>(e.Row);
            }
        }