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);
            }
        }
        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;
			}
		}