async void setTask(ProjectClient project, ProjectBudgetLineLocal rec) { if (api.CompanyEntity.ProjectTask) { if (project != null) { rec.taskSource = project.Tasks ?? await project.LoadTasks(api); } else { rec.taskSource = null; rec.Task = null; } rec.NotifyPropertyChanged("TaskSource"); } }
private void DataControl_CurrentItemChanged(object sender, DevExpress.Xpf.Grid.CurrentItemChangedEventArgs e) { ProjectBudgetLineLocal oldselectedItem = e.OldItem as ProjectBudgetLineLocal; if (oldselectedItem != null) { oldselectedItem.PropertyChanged -= SelectedItem_PropertyChanged; } ProjectBudgetLineLocal selectedItem = e.NewItem as ProjectBudgetLineLocal; if (selectedItem != null) { selectedItem.InsidePropChange = false; selectedItem.PropertyChanged += SelectedItem_PropertyChanged; } }
public override void SetDefaultValues(UnicontaBaseEntity dataEntity, int selectedIndex) { var newRow = (ProjectBudgetLineLocal)dataEntity; var lst = (IList)this.ItemsSource; if (lst == null || lst.Count == 0) { newRow._Date = BasePage.GetSystemDefaultDate().Date; } else { ProjectBudgetLineLocal last = null; ProjectBudgetLineLocal Cur = null; int n = -1; DateTime LastDateTime = DateTime.MinValue; var castItem = lst.Cast <ProjectBudgetLineLocal>(); foreach (var journalLine in castItem) { if (journalLine._Date != DateTime.MinValue && Cur == null) { LastDateTime = journalLine._Date; } n++; if (n == selectedIndex) { Cur = journalLine; } last = journalLine; } if (Cur == null) { Cur = last; } newRow._Date = LastDateTime != DateTime.MinValue ? LastDateTime : BasePage.GetSystemDefaultDate().Date; newRow._Project = last._Project; newRow._PrCategory = last._PrCategory; newRow.PrCategorySource = last.PrCategorySource; } }
void SetItem(ProjectBudgetLineLocal rec) { var item = (InvItem)ItemCache.Get(rec._Item); if (item == null) { return; } if (item._CostPrice != 0d) { if (rec._Qty == 0) { rec.Qty = 1d; } rec.CostPrice = item._CostPrice; } double price = 0d; int pg = PriceGrp; if (pg == 3) { price = item._SalesPrice3; if (price == 0) { pg = 2; } } if (pg == 2) { price = item._SalesPrice2; } if (price == 0) { price = item._SalesPrice1; } if (price != 0d) { if (rec._Qty == 0) { rec.Qty = 1d; } rec.SalesPrice = price; } if (item._Dim1 != null) { rec.Dimension1 = item._Dim1; } if (item._Dim2 != null) { rec.Dimension2 = item._Dim2; } if (item._Dim3 != null) { rec.Dimension3 = item._Dim3; } if (item._Dim4 != null) { rec.Dimension4 = item._Dim4; } if (item._Dim5 != null) { rec.Dimension5 = item._Dim5; } if (item._PrCategory != null) { rec.PrCategory = item._PrCategory; } if (item._PayrollCategory != null) { rec.PayrollCategory = item._PayrollCategory; PayrollCat(rec, false); } if (item._Unit != 0 && rec._Unit != item._Unit) { rec._Unit = item._Unit; rec.NotifyPropertyChanged("Unit"); } globalEvents.NotifyRefreshViewer(NameOfControl, item); }
async void PayrollCat(ProjectBudgetLineLocal rec, bool AddItem) { double costPrice = 0, salesPrice = 0; var emp = (Uniconta.DataModel.Employee)EmployeeCache?.Get(rec._Employee); if (emp != null) { costPrice = emp._CostPrice; salesPrice = emp._SalesPrice; } var pay = (Uniconta.DataModel.EmpPayrollCategory)PayrollCache?.Get(rec._PayrollCategory); if (pay != null) { if (pay._Unit != 0 && rec._Unit != pay._Unit) { rec._Unit = pay._Unit; rec.NotifyPropertyChanged("Unit"); } if (pay._PrCategory != null) { rec.PrCategory = pay._PrCategory; } if (pay._Rate != 0) { costPrice = pay._Rate; } if (pay._SalesPrice != 0) { salesPrice = pay._SalesPrice; } string Item = pay._Item; if (pay._Dim1 != null) { rec.Dimension1 = pay._Dim1; } if (pay._Dim2 != null) { rec.Dimension2 = pay._Dim2; } if (pay._Dim3 != null) { rec.Dimension3 = pay._Dim3; } if (pay._Dim4 != null) { rec.Dimension4 = pay._Dim4; } if (pay._Dim5 != null) { rec.Dimension5 = pay._Dim5; } if (emp != null) { Uniconta.DataModel.EmpPayrollCategoryEmployee found = null; var Rates = pay.Rates ?? await pay.LoadRates(api); foreach (var rate in Rates) { if (rate._ValidFrom != DateTime.MinValue && rate._ValidFrom > rec._Date) { continue; } if (rate._ValidTo != DateTime.MinValue && rate._ValidTo < rec._Date) { continue; } if (rate._Employee != emp._Number) { continue; } if (rate._Project != null) { if (rate._Project == rec._Project) { found = rate; break; } } else if (found == null) { found = rate; } } if (found != null) { if (found._CostPrice != 0d) { costPrice = found._CostPrice; } else if (found._Rate != 0d) { costPrice = found._Rate; } if (found._SalesPrice != 0d) { salesPrice = found._SalesPrice; } if (found._Item != null) { Item = found._Item; } if (found._Dim1 != null) { rec.Dimension1 = found._Dim1; } if (found._Dim2 != null) { rec.Dimension2 = found._Dim2; } if (found._Dim3 != null) { rec.Dimension3 = found._Dim3; } if (found._Dim4 != null) { rec.Dimension4 = found._Dim4; } if (found._Dim5 != null) { rec.Dimension5 = found._Dim5; } } } if (AddItem && Item != null) { rec.Item = Item; } } if (costPrice != 0d) { if (rec._Qty == 0) { rec.Qty = 1d; } rec.CostPrice = costPrice; } if (salesPrice != 0d) { if (rec._Qty == 0) { rec.Qty = 1d; } rec.SalesPrice = salesPrice; } }
private void CreateBudget() { var cwCreateBjt = new CwCreateUpdateBudget(api); #if !SILVERLIGHT cwCreateBjt.DialogTableId = 2000000074; #endif cwCreateBjt.Closed += async delegate { if (cwCreateBjt.DialogResult == true) { int budgetMethod = 0; DateTime dFromDate = CwCreateUpdateBudget.FromDate; DateTime dToDate = CwCreateUpdateBudget.ToDate; string dEmplNumber = CwCreateUpdateBudget.Employee; string dProjectNumber = CwCreateUpdateBudget.Project; string dBudgetGroup = CwCreateUpdateBudget.Group; string dBudgetComment = CwCreateUpdateBudget.Comment; dBudgetComment = string.IsNullOrEmpty(dBudgetComment) ? Uniconta.ClientTools.Localization.lookup("Budget") : dBudgetComment; // if (string.IsNullOrEmpty(CwCreateUpdateBudget.Group)) { UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("BudgetGroup")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK); return; } if (dFromDate == DateTime.MinValue) { UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("FromDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK); return; } if (dToDate == DateTime.MinValue) { UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("ToDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK); return; } ErrorCodes res; var master = new List <UnicontaBaseEntity>(); //Delete Budget Lines >> ProjectBudgetGroup budgetGrp = budgetGroupCache.Get(dBudgetGroup); if (budgetGrp._Blocked) { UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("IsBlockedOBJ"), Uniconta.ClientTools.Localization.lookup("Budget")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK); return; } busyIndicator.IsBusy = true; master.Add(budgetGrp); if (!string.IsNullOrEmpty(dEmplNumber)) { master.Add(employeeCache.Get(dEmplNumber)); } if (!string.IsNullOrEmpty(dProjectNumber)) { master.Add(projectCache.Get(dProjectNumber)); } List <PropValuePair> pairLine = new List <PropValuePair>(); pairLine.Add(PropValuePair.GenereteWhereElements(nameof(ProjectBudgetLine._Date), typeof(DateTime), String.Format("{0:d}..{1:d}", dFromDate, dToDate))); var projBudgetLineDelete = await api.Query <ProjectBudgetLine>(master, pairLine); if (projBudgetLineDelete.Length != 0) { res = await api.Delete(projBudgetLineDelete); } //Delete Budget Lines << List <PropValuePair> pairBudget = new List <PropValuePair>(); pairBudget.Add(PropValuePair.GenereteWhereElements(nameof(ProjectBudget._Group), typeof(string), dBudgetGroup)); var projBudgetLst = await api.Query <ProjectBudget>(pairBudget); var dictProjBudget = new Dictionary <string, ProjectBudget>(); foreach (ProjectBudget rec in projBudgetLst) { ProjectBudget projBudget; bool hasValue = dictProjBudget.TryGetValue(string.Concat(rec._Project, dBudgetGroup), out projBudget); if (!hasValue) { dictProjBudget.Add(string.Concat(rec._Project, dBudgetGroup), rec); } } List <PropValuePair> filterTrans = new List <PropValuePair>(); filterTrans.Add(PropValuePair.GenereteWhereElements(nameof(ProjectTrans._Date), typeof(DateTime), String.Format("{0:d}..{1:d}", dFromDate.AddYears(-1), dToDate.AddYears(-1)))); var transTask = api.Query(new ProjectTransPivotClient(), master, filterTrans); var projTransLst = await transTask; var projTransLstEntity = new List <ProjectTransPivotClient>(); //string lastProj = null; string lastPrCat = null; string lastPayrollCat = null; //Uniconta.DataModel.ProjectGroup projGrp = null; Uniconta.DataModel.PrCategory prCat = null; Uniconta.DataModel.EmpPayrollCategory payrollCat = null; foreach (var x in projTransLst) { //if (lastProj != x._Project) //{ // lastProj = x._Project; // var proj = x.ProjectRef; // projGrp = projGroupCache.Get(proj._Group); //} if (lastPrCat != x._PrCategory) { lastPrCat = x._PrCategory; prCat = x.CategoryRef; } if (lastPayrollCat != x._PayrollCategory) { lastPayrollCat = x._PayrollCategory; payrollCat = x.PayrollCategoryRef; } if (prCat != null && payrollCat != null && prCat._CatType == CategoryType.Labour && payrollCat._Unit == ItemUnit.Hours && payrollCat._InternalType == InternalType.None) { projTransLstEntity.Add(x); } } if (projTransLstEntity == null) { busyIndicator.IsBusy = false; UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), 0, string.Empty), Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK); return; } //Only create budget project with transactions var insertLst = new List <UnicontaBaseEntity>(); var grpProject = projTransLstEntity.GroupBy(x => x._Project); foreach (var rec in grpProject) { ProjectBudget projBudget; bool hasValue = dictProjBudget.TryGetValue(string.Concat(rec.Key, dBudgetGroup), out projBudget); if (!hasValue) { insertLst.Add(new ProjectBudget() { _Project = rec.Key, _Group = dBudgetGroup, _Name = dBudgetComment, _Current = true }); } } if (insertLst.Count > 0) { res = await api.Insert(insertLst); //Create new Budget-Header } //Insert new header in dictionary for fast lookup foreach (ProjectBudget rec in insertLst) { ProjectBudget projBudget; bool hasValue = dictProjBudget.TryGetValue(string.Concat(rec._Project, dBudgetGroup), out projBudget); if (!hasValue) { dictProjBudget.Add(string.Concat(rec._Project, dBudgetGroup), rec); } } ProjectBudgetLineLocal projBudgetLine; var dictProjBudgetLine = new Dictionary <int, ProjectBudgetLineLocal>(); foreach (var trans in projTransLstEntity) { if (dictProjBudgetLine.TryGetValue(GetHashCode(trans, budgetMethod), out projBudgetLine)) { projBudgetLine._Qty += trans._Qty; projBudgetLine._CostTotal += trans.Cost; projBudgetLine._CostPrice = projBudgetLine._Qty != 0 ? Math.Round(projBudgetLine._CostTotal / projBudgetLine._Qty, 2) : 0; projBudgetLine._SalesTotal += trans.Sales; projBudgetLine._SalesPrice = projBudgetLine._Qty != 0 ? Math.Round(projBudgetLine._SalesTotal / projBudgetLine._Qty, 2) : 0; } else { ProjectBudget projBudget; bool hasValue = dictProjBudget.TryGetValue(string.Concat(trans._Project, dBudgetGroup), out projBudget); if (hasValue) { projBudgetLine = new ProjectBudgetLineLocal(); projBudgetLine.SetMaster(projBudget); projBudgetLine._Project = trans._Project; projBudgetLine._Qty = trans._Qty; projBudgetLine._CostTotal += trans.Cost; projBudgetLine._CostPrice = projBudgetLine._Qty != 0 ? Math.Round(projBudgetLine._CostTotal / projBudgetLine._Qty, 2) : 0; projBudgetLine._SalesTotal += trans.Sales; projBudgetLine._SalesPrice = projBudgetLine._Qty != 0 ? Math.Round(projBudgetLine._SalesTotal / projBudgetLine._Qty, 2) : 0; projBudgetLine._Date = GetDate(trans._Date, budgetMethod); projBudgetLine._Employee = trans._Employee; projBudgetLine._PayrollCategory = budgetMethod == 0 || budgetMethod == 1 ? trans._PayrollCategory : null; projBudgetLine._PrCategory = trans._PrCategory; projBudgetLine._Text = string.Concat("(", TMJournalLineHelper.GetTimeStamp(), ") ", Uniconta.ClientTools.Localization.lookup("Created")); dictProjBudgetLine.Add(GetHashCode(trans, budgetMethod), projBudgetLine); } } } if (dictProjBudgetLine.Count > 0) { res = await api.Insert(dictProjBudgetLine.Values); localMenu_OnItemClicked("RefreshGrid"); } busyIndicator.IsBusy = false; UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), dictProjBudgetLine.Count, string.Empty), Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK); } }; cwCreateBjt.Show(); }