Beispiel #1
0
        private void UpdatePrices()
        {
            var cwUpdateBjt = new CwCreateUpdateBudget(api, 1);

#if !SILVERLIGHT
            cwUpdateBjt.DialogTableId = 2000000178;
#endif
            cwUpdateBjt.Closed += async delegate
            {
                if (cwUpdateBjt.DialogResult == true)
                {
                    var projLst = dgProjectGrid.GetVisibleRows() as IList <Uniconta.DataModel.Project>;

                    BudgetAPI budgetApi = new BudgetAPI(api);
                    var       result    = await budgetApi.UpdatePrices(CwCreateUpdateBudget.FromDate, CwCreateUpdateBudget.ToDate, CwCreateUpdateBudget.Employee, CwCreateUpdateBudget.Payroll,
                                                                       CwCreateUpdateBudget.PrCategory, CwCreateUpdateBudget.Group, CwCreateUpdateBudget.PrWorkSpace, cwUpdateBjt.InclProjectTask, projLst);

                    if (result != ErrorCodes.Succes)
                    {
                        UtilDisplay.ShowErrorCode(result);
                    }
                    else
                    {
                        UnicontaMessageBox.Show(string.Concat(Uniconta.ClientTools.Localization.lookup("Prices"), " ", Uniconta.ClientTools.Localization.lookup("Updated").ToLower()),
                                                Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK);
                    }
                }
            };
            cwUpdateBjt.Show();
        }
        private void CreateBudget()
        {
            var cwCreateBjt = new CwCreateUpdateBudget(api);

#if !SILVERLIGHT
            cwCreateBjt.DialogTableId = 2000000100;
#endif
            cwCreateBjt.Closed += async delegate
            {
                if (cwCreateBjt.DialogResult == true)
                {
                    BudgetAPI budgetApi = new BudgetAPI(api);
                    var       result    = await budgetApi.CreateBudget(CwCreateUpdateBudget.FromDate, CwCreateUpdateBudget.ToDate, CwCreateUpdateBudget.Employee, CwCreateUpdateBudget.Payroll,
                                                                       CwCreateUpdateBudget.PrCategory, CwCreateUpdateBudget.Group, CwCreateUpdateBudget.BudgetMethod, CwCreateUpdateBudget.BudgetName,
                                                                       CwCreateUpdateBudget.PrWorkSpace, cwCreateBjt.DeleteBudget, cwCreateBjt.InclProjectTask, null);

                    if (result != ErrorCodes.Succes)
                    {
                        UtilDisplay.ShowErrorCode(result);
                    }
                    else
                    {
                        UnicontaMessageBox.Show(string.Concat(Uniconta.ClientTools.Localization.lookup("Budget"), " ", Uniconta.ClientTools.Localization.lookup("Created").ToLower()),
                                                Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK);
                    }
                }
            };
            cwCreateBjt.Show();
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        private void UpdatePrices()
        {
            var cwUpdateBjt = new CwCreateUpdateBudget(api, 1);

#if !SILVERLIGHT
            cwUpdateBjt.DialogTableId = 2000000073;
#endif

            cwUpdateBjt.Closed += async delegate
            {
                if (cwUpdateBjt.DialogResult == true)
                {
                    DateTime dFromDateUpd   = CwCreateUpdateBudget.FromDate;
                    DateTime dToDateUpd     = CwCreateUpdateBudget.ToDate;
                    string   dEmplNumber    = CwCreateUpdateBudget.Employee;
                    string   dProject       = CwCreateUpdateBudget.Project;
                    string   dBudgetGroup   = CwCreateUpdateBudget.Group;
                    string   dBudgetComment = CwCreateUpdateBudget.Comment;

                    if (string.IsNullOrEmpty(CwCreateUpdateBudget.Group))
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("BudgetGroup")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    if (dFromDateUpd == DateTime.MinValue)
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("FromDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    if (dToDateUpd == DateTime.MinValue)
                    {
                        UnicontaMessageBox.Show(FieldCannotBeEmpty(Uniconta.ClientTools.Localization.lookup("ToDate")), Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                        return;
                    }

                    var master = new List <UnicontaBaseEntity>();
                    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;
                    }

                    master.Add(budgetGrp);

                    busyIndicator.IsBusy = true;


                    if (!string.IsNullOrEmpty(dEmplNumber))
                    {
                        master.Add(employeeCache.Get(dEmplNumber));
                    }

                    if (!string.IsNullOrEmpty(dProject))
                    {
                        master.Add(projectCache.Get(dProject));
                    }

                    List <PropValuePair> pairTrans = new List <PropValuePair>();
                    pairTrans.Add(PropValuePair.GenereteWhereElements(nameof(ProjectBudgetLineClient._Date), typeof(DateTime), String.Format("{0:d}..{1:d}", dFromDateUpd, dToDateUpd)));

                    var empPriceLst = await api.Query <EmpPayrollCategoryEmployeeClient>(master, pairTrans);

                    var budgetLineLst = await api.Query <ProjectBudgetLineClient>(master, pairTrans);

                    var cntUpdate = 0;
                    var tmHelper  = new TMJournalLineHelper(api);
                    foreach (var rec in budgetLineLst)
                    {
                        cntUpdate++;
                        var prices = tmHelper.GetEmplPrice(empPriceLst, payrollCache, projGroupCache, employeeCache?.Get(rec._Employee), projectCache.Get(rec._Project), rec._Date, rec._PayrollCategory);
                        rec._CostPrice  = prices.Item1;
                        rec._SalesPrice = prices.Item2;
                        rec._Text       = string.Concat("(", TMJournalLineHelper.GetTimeStamp(), ") ", Uniconta.ClientTools.Localization.lookup("PriceUpdate"));
                    }

                    ErrorCodes res;
                    if (cntUpdate > 0)
                    {
                        res = await api.Update(budgetLineLst);
                    }

                    busyIndicator.IsBusy = false;

                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cntUpdate, string.Empty), Uniconta.ClientTools.Localization.lookup("Information"), MessageBoxButton.OK);
                }
            };
            cwUpdateBjt.Show();
        }