async void setTask(Uniconta.DataModel.Project project, ProjectJournalLineLocal 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");
     }
 }
示例#2
0
        async void setTask(Uniconta.DataModel.Project project, ProjectJournalLineLocal rec)
        {
            if (api.CompanyEntity.ProjectTask)
            {
                if (project != null)
                {
                    var tasks = project.Tasks ?? await project.LoadTasks(api);

                    rec.taskSource = tasks?.Where(s => s.Ended == false && (rec._WorkSpace == null || s._WorkSpace == rec._WorkSpace));
                }
                else
                {
                    rec.taskSource = null;
                    rec.Task       = null;
                }
                rec.NotifyPropertyChanged("TaskSource");
            }
        }
示例#3
0
        public async Task <List <TMJournalLineError> > ValidateLines(List <TMJournalLineClient> lines,
                                                                     DateTime startDate,
                                                                     DateTime endDate,
                                                                     Uniconta.DataModel.Employee employee)
        {
            var t = LoadingTask;

            if (t != null && !t.IsCompleted)
            {
                await t;
            }

            checkErrors = new List <TMJournalLineError>();

            this.employee = employee;
            var approveDate = employee._TMApproveDate;

            this.startDate = approveDate >= startDate?approveDate.AddDays(1) : startDate;

            this.endDate = endDate;
            string lastProjNo  = null;
            string lastPayroll = null;
            string lastTaskId  = null;

            foreach (var rec in lines)
            {
                rec.ErrorInfo = string.Empty;
                err           = false;

                if (lastPayroll != rec.PayrollCategory)
                {
                    lastPayroll = rec.PayrollCategory;
                    payrollCat  = (EmpPayrollCategory)payrollCategoryCache.Get(lastPayroll);
                    prCategory  = (Uniconta.DataModel.PrCategory)prCategoryCache.Get(payrollCat?._PrCategory);
                }

                if (lastProjNo != rec._Project)
                {
                    lastProjNo = rec._Project;
                    proj       = (Uniconta.DataModel.Project)projectCache.Get(lastProjNo);
                    projGroup  = (Uniconta.DataModel.ProjectGroup)projectGrpCache.Get(proj?._Group);

                    if (proj != null && comp.ProjectTask && proj.Tasks == null)
                    {
                        await proj.LoadTasks(api);
                    }
                }

                if (rec._Project != null && rec._Task != null && lastTaskId != string.Concat(rec._Project, rec._Task))
                {
                    lastTaskId = string.Concat(rec._Project, rec._Task);
                    prTask     = proj.Tasks != null?proj.Tasks.FirstOrDefault(s => s.Task == rec.Task) : null;
                }

                ValidateGeneral(rec);
                ValidateProject(rec);
                ValidateTask(rec);
                ValidateProjectCategory(rec);
                ValidatePrice(rec);

                if (!err)
                {
                    rec.ErrorInfo = VALIDATE_OK;
                }
            }

            return(checkErrors);
        }
示例#4
0
        public Tuple <double, double> GetEmplPrice(IList <EmpPayrollCategoryEmployeeClient> empPriceLst,
                                                   SQLTableCache <Uniconta.DataModel.EmpPayrollCategory> empPayrollCatLst,
                                                   SQLTableCache <Uniconta.DataModel.ProjectGroup> projGroupLst,
                                                   Uniconta.DataModel.Employee employee,
                                                   Uniconta.DataModel.Project project,
                                                   DateTime priceDate,
                                                   string payrollCategory = null)
        {
#if !SILVERLIGHT
            if (employee == null)
            {
                return(new Tuple <double, double>(0, 0));
            }

            this.empPriceLst = empPriceLst;
            var projGroup = projGroupLst.Get(project._Group);

            EmpPayrollCategory payrollCat;
            bool isMileagePrice;
            bool invoiceable;
            if (payrollCategory == null)
            {
                payrollCat      = null;
                isMileagePrice  = false;
                invoiceable     = projGroup._Invoiceable;
                payrollCategory = string.Empty;
            }
            else
            {
                payrollCat     = empPayrollCatLst.Get(payrollCategory);
                isMileagePrice = payrollCat._InternalType == InternalType.Mileage;
                invoiceable    = projGroup._Invoiceable && payrollCat._Invoiceable;
            }


            if (empPriceLst != null && empPriceLst.Count > 0 && empPriceLst.Any(s => s._Employee != employee._Number)) // it contains other employees, remove them
            {
                empPriceLst = empPriceLst.Where(s => s._Employee == employee._Number).ToList();
            }

            if (isMileagePrice)
            {
                invoiceable = projGroup._Invoiceable;
            }

            double salesPrice = 0, costPrice = 0;

            if (empPriceLst != null && empPriceLst.Count > 0)
            {
                var defaultPayrollCategory = empPayrollCatLst.Where(s => s._PrCategory == null && s.KeyStr == "Default").FirstOrDefault();

                var prices = PriceMatrix(priceDate, 1, project, payrollCategory);

                if (prices != null && prices._Project == null && prices._DCAccount == null)
                {
                    prices = PriceMatrix(priceDate, 1, project, defaultPayrollCategory?.KeyStr, true) ?? prices;
                }
                else if (prices == null && defaultPayrollCategory != null)
                {
                    prices = PriceMatrix(priceDate, 1, project, defaultPayrollCategory.KeyStr);
                }

                if (prices != null)
                {
                    salesPrice = prices._SalesPrice;
                    costPrice  = prices._CostPrice;
                }
            }

            if (payrollCat != null)
            {
                if (salesPrice == 0)
                {
                    salesPrice = payrollCat._SalesPrice;
                }
                if (costPrice == 0)
                {
                    costPrice = payrollCat._Rate;
                }
            }

            if (!isMileagePrice)  //Always fallback to Employee for cost and sales prices
            {
                if (salesPrice == 0)
                {
                    salesPrice = employee._SalesPrice;
                }
                if (costPrice == 0)
                {
                    costPrice = employee._CostPrice;
                }
            }

            return(new Tuple <double, double>(costPrice, invoiceable ? salesPrice : 0));
#endif
            return(new Tuple <double, double>(0, 0));
        }
示例#5
0
        private EmpPayrollCategoryEmployeeClient PriceMatrix(DateTime date, int dayIdx, Uniconta.DataModel.Project project, string payrollCat, bool continueSearch = false)
        {
            if (payrollCat == null)
            {
                return(null);
            }

            var ProjectNr  = project?._Number;
            var ProjectAcc = project?._DCAccount;
            EmpPayrollCategoryEmployeeClient found = null;
            var dt = date.AddDays(dayIdx - 1);

            foreach (var rate in empPriceLst)
            {
                if (rate._ValidFrom != DateTime.MinValue && rate._ValidFrom > dt)
                {
                    continue;
                }
                if (rate._ValidTo != DateTime.MinValue && rate._ValidTo < dt)
                {
                    continue;
                }
                if (rate._PayrollCategory != payrollCat)
                {
                    continue;
                }

                if (rate._Project == ProjectNr)
                {
                    return(rate);          // best fit, we exit
                }
                if (rate._Project != null) // no match
                {
                    continue;
                }
                if (rate._DCAccount == ProjectAcc)
                {
                    if (found?._DCAccount == null) // better fit
                    {
                        found = rate;
                    }
                }
                else if (rate._DCAccount == null && found == null && !continueSearch)
                {
                    found = rate; // a fit, but weakest fit.
                }
            }
            return(found);
        }
        private async Task IncludeTimeJournals()
        {
            if (!InclTimeJournals || timeTransFound)
            {
                return;
            }

            ProjectClient  proj = null;
            EmployeeClient emp  = null;

            if (master != null)
            {
                emp = master as EmployeeClient;
                if (emp == null)
                {
                    proj = master as ProjectClient;
                }
                if (proj == null)
                {
                    var WIPreport = master as UnicontaClient.Pages.ProjectTransLocalClient;
                    if (WIPreport != null)
                    {
                        proj = WIPreport.ProjectRef;
                    }
                }
            }

            if (timetransLst == null && (master == null || emp != null || proj != null))
            {
                timetransLst         = new List <ProjectTransClient>();
                timeTransFound       = true;
                busyIndicator.IsBusy = true;

                var pairTM = new List <PropValuePair>();

                if (emp != null)
                {
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Employee), typeof(string), emp._Number));
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), emp._TMApproveDate, CompareOperator.GreaterThanOrEqual));
                }
                else if (proj != null)
                {
                    if (projLst == null)
                    {
                        var strb = StringBuilderReuse.Create();
                        strb.Append(proj._Number);
                        foreach (var x in Projects)
                        {
                            if (x._MasterProject == proj._Number)
                            {
                                strb.Append(';').Append(x._Number);
                            }
                        }
                        projLst = strb.ToString();
                        strb.Release();
                    }

                    var projselected = includeSubProject ? projLst : proj._Number;
                    pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Project), typeof(string), projselected));
                    var minApproveDate = Employees.Where(x => x._TMApproveDate != DateTime.MinValue && x._Terminated == DateTime.MinValue).Min(x => x._TMApproveDate as DateTime?) ?? DateTime.MinValue;
                    if (minApproveDate != DateTime.MinValue)
                    {
                        pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), minApproveDate, CompareOperator.GreaterThanOrEqual));
                    }
                }
                else
                {
                    var minApproveDate = Employees.Where(x => x._TMApproveDate != DateTime.MinValue && x._Terminated == DateTime.MinValue).Min(x => x._TMApproveDate as DateTime?) ?? DateTime.MinValue;
                    if (minApproveDate != DateTime.MinValue)
                    {
                        pairTM.Add(PropValuePair.GenereteWhereElements(nameof(TMJournalLineClient.Date), minApproveDate, CompareOperator.GreaterThanOrEqual));
                    }
                }

                var tmJourLines = await api.Query <TMJournalLineClient>(pairTM);

                var tmLines = tmJourLines.Where(s => (s.Project != null &&
                                                      s.PayrollCategory != null &&
                                                      s.Date > Employees.First(z => z._Number == s.Employee)._TMApproveDate)).ToArray();

                var search = new TMJournalLineClient();
                var sort   = new TMJournalEmpDateSort();
                int pos    = 0;
                Array.Sort(tmLines, sort);

                string                     lastEmployee = null;
                string                     lastPayroll  = null;
                string                     lastProject  = null;
                EmpPayrollCategory         payrollCat   = null;
                Uniconta.DataModel.Project project      = null;
                var grpEmpDate = tmLines.GroupBy(x => new { x.Employee, x.Date }).Select(g => new { g.Key.Employee, g.Key.Date, EmployeeTable = Employees.Get(g.Key.Employee) });
                foreach (var rec in grpEmpDate)
                {
                    if (lastEmployee != rec.Employee)
                    {
                        lastEmployee = rec.Employee;
                        await priceLookup.EmployeeChanged(rec.EmployeeTable);
                    }

                    search._Employee = rec.Employee;
                    search._Date     = rec.Date;
                    pos = Array.BinarySearch(tmLines, search, sort);
                    if (pos < 0)
                    {
                        pos = ~pos;
                    }
                    while (pos < tmLines.Length)
                    {
                        var s = tmLines[pos++];
                        if (s._Employee != rec.Employee || s._Date != rec.Date)
                        {
                            break;
                        }

                        if (s.Total != 0)
                        {
                            if (lastPayroll != s._PayrollCategory)
                            {
                                payrollCat  = (Uniconta.DataModel.EmpPayrollCategory)Payrolls?.Get(s._PayrollCategory);
                                lastPayroll = s._PayrollCategory;
                            }

                            var line = new ProjectTransClient();
                            line.IsTimeJournal    = true;
                            line._Project         = s._Project;
                            line._Employee        = s._Employee;
                            line._PayrollCategory = s._PayrollCategory;
                            line._PrCategory      = payrollCat?._PrCategory;
                            line._Task            = s._Task;
                            line._Invoiceable     = s._Invoiceable;
                            line._Date            = s._Date;

                            if (s._RegistrationType == RegistrationType.Hours)
                            {
                                line._Text = s._Text;
                                line._Unit = (byte)ItemUnit.Hours;
                                if (payrollCat != null && (payrollCat._InternalType == Uniconta.DataModel.InternalType.OverTime || payrollCat._InternalType == Uniconta.DataModel.InternalType.FlexTime))
                                {
                                    line._Qty = payrollCat._Factor == 0 ? s.Total : s.Total * payrollCat._Factor;
                                }
                                else
                                {
                                    line._Qty = s.Total;
                                }
                            }
                            else
                            {
                                line._Text = TMJournalLineClient.GetMileageFormattedText(s._Text, s._AddressFrom, s._AddressTo, s._VechicleRegNo);
                                line._Unit = (byte)ItemUnit.km;
                                line._Qty  = s.Total;
                            }

                            s.Day1 = s.Total;
                            s.Day2 = s.Day3 = s.Day4 = s.Day5 = s.Day6 = s.Day7 = 0;
                            await priceLookup.GetEmployeePrice(s);

                            line._CostPrice  = s.GetCostPricesDayN(1);
                            line._SalesPrice = s.GetSalesPricesDayN(1);

                            if (api.CompanyEntity._DimFromProject)
                            {
                                if (lastProject != s._Project)
                                {
                                    project     = (Uniconta.DataModel.Project)Projects.Get(s._Project);
                                    lastProject = s._Project;
                                }

                                line._Dim1 = project._Dim1;
                                line._Dim2 = project._Dim2;
                                line._Dim3 = project._Dim3;
                                line._Dim4 = project._Dim4;
                                line._Dim5 = project._Dim5;
                            }
                            else
                            {
                                line._Dim1 = rec.EmployeeTable._Dim1;
                                line._Dim2 = rec.EmployeeTable._Dim2;
                                line._Dim3 = rec.EmployeeTable._Dim3;
                                line._Dim4 = rec.EmployeeTable._Dim4;
                                line._Dim5 = rec.EmployeeTable._Dim5;
                            }
                            timetransLst.Add(line);
                        }
                    }
                }

                busyIndicator.IsBusy = false;
            }

            if (timetransLst != null)
            {
                var transLst = ((IEnumerable <ProjectTransClient>)dgProjectTransaction.ItemsSource).ToList();
                transLst.AddRange(timetransLst);
                dgProjectTransaction.SetSource(transLst.ToArray());
            }
        }
示例#7
0
        async void LoadGrid()
        {
            budgetGroup = cmbBudgetGroup.Text;
            workSpace   = cmbWorkSpace.Text;

            if (string.IsNullOrEmpty(budgetGroup))
            {
                var msgText = string.Concat(Uniconta.ClientTools.Localization.lookup("FieldCannotBeEmpty"), " (", Uniconta.ClientTools.Localization.lookup("Field"), ": ", Uniconta.ClientTools.Localization.lookup("BudgetGroup"), ")");
                UnicontaMessageBox.Show(msgText, Uniconta.ClientTools.Localization.lookup("Warning"), MessageBoxButton.OK);
                return;
            }

            busyIndicator.IsBusy = true;

            if (projects == null)
            {
                projects = await api.LoadCache <Uniconta.DataModel.Project>();
            }

            if (debtors == null)
            {
                debtors = await api.LoadCache <Uniconta.DataModel.Debtor>();
            }

            var projArr = projects.ToArray();

            var lst = new List <TMPlanningCheckLocal>(1000);

            var search = new Uniconta.DataModel.Project();
            var sort   = new SortProjectDebtor();
            int pos;

            Array.Sort(projArr, sort);

            foreach (var rec in debtors)
            {
                if (rec._Blocked)
                {
                    continue;
                }

                search._DCAccount = rec._Account;
                pos = Array.BinarySearch(projArr, search, sort);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                bool found = false;
                while (pos < projArr.Length)
                {
                    var s = projArr[pos++];
                    if (s._DCAccount != rec._Account)
                    {
                        break;
                    }

                    if (s._Blocked || s._Phase == ProjectPhase.Completed || s._Phase == ProjectPhase.ReportedAsFinished || s._Phase == ProjectPhase.Paused)
                    {
                        continue;
                    }

                    found = true;
                    break;
                }

                if (!found)
                {
                    var cur = new TMPlanningCheckLocal()
                    {
                        _CompanyId = api.CompanyId, _Debtor = rec._Account, _ErrorInfo = string.Concat("1. ", Uniconta.ClientTools.Localization.lookup("DebtorNoActiveProjects"))
                    };
                    lst.Add(cur);
                }
            }

            List <PropValuePair> pairBudget = new List <PropValuePair>();

            pairBudget.Add(PropValuePair.GenereteWhereElements(nameof(ProjectBudget._Group), typeof(string), budgetGroup));
            var projBudgetArr = await api.Query <ProjectBudget>(pairBudget);

            var master        = budgetGrpCache.Get(budgetGroup) as ProjectBudgetGroup;
            var budgetLineArr = await api.Query <ProjectBudgetLine>(master);

            List <PropValuePair> pairTask = new List <PropValuePair>();

            pairTask.Add(PropValuePair.GenereteWhereElements(nameof(ProjectTaskClient.WorkSpace), typeof(string), workSpace));

            var projTaskArr = await api.Query <ProjectTaskClient>(pairTask);

            var searchBud = new ProjectBudget();
            var sortBud   = new SortProjectBudget();

            Array.Sort(projBudgetArr, sortBud);

            var searchBudLine = new ProjectBudgetLine();
            var sortBudLine   = new SortProjectBudgetLine();
            int posBudLine;

            Array.Sort(budgetLineArr, sortBudLine);

            var searchTask = new ProjectTask();
            var sortTask   = new SortProjectTask();
            int posTask;

            Array.Sort(projTaskArr, sortTask);

            foreach (var rec in projects)
            {
                if (rec._Blocked || rec._Phase == ProjectPhase.Completed || rec._Phase == ProjectPhase.ReportedAsFinished || rec._Phase == ProjectPhase.Paused)
                {
                    continue;
                }

                searchBud._Project = rec._Number;
                pos = Array.BinarySearch(projBudgetArr, searchBud, sortBud);
                if (pos < 0)
                {
                    pos = ~pos;
                }

                bool found = false;
                while (pos < projBudgetArr.Length)
                {
                    var s = projBudgetArr[pos++];
                    if (s._Project != rec._Number)
                    {
                        break;
                    }

                    #region BudgetLine
                    searchBudLine._Project = rec._Number;
                    posBudLine             = Array.BinarySearch(budgetLineArr, searchBudLine, sortBudLine);
                    if (posBudLine < 0)
                    {
                        posBudLine = ~posBudLine;
                    }

                    bool foundLine = false;
                    while (posBudLine < budgetLineArr.Length)
                    {
                        var sLine = budgetLineArr[posBudLine++];
                        if (sLine._Project != rec._Number)
                        {
                            break;
                        }

                        foundLine = true;
                        break;
                    }

                    if (!foundLine)
                    {
                        var cur = new TMPlanningCheckLocal()
                        {
                            _CompanyId = api.CompanyId, _Project = rec._Number, _ErrorInfo = string.Concat("2. ", Uniconta.ClientTools.Localization.lookup("ProjectMissingBudget"))
                        };
                        lst.Add(cur);
                    }
                    #endregion

                    found = true;
                }

                if (api.CompanyEntity.ProjectTask && workSpace != null)
                {
                    searchTask._Project = rec._Number;
                    posTask             = Array.BinarySearch(projTaskArr, searchTask, sortTask);
                    if (posTask < 0)
                    {
                        posTask = ~posTask;
                    }

                    bool foundLine = false;
                    while (posTask < projTaskArr.Length)
                    {
                        var projTask = projTaskArr[posTask++];
                        if (projTask._Project != rec._Number)
                        {
                            break;
                        }

                        foundLine = true;
                        break;
                    }

                    if (!foundLine)
                    {
                        var cur = new TMPlanningCheckLocal()
                        {
                            _CompanyId = api.CompanyId, _Project = rec._Number, _ErrorInfo = string.Concat("3. ", Uniconta.ClientTools.Localization.lookup("ProjectNoActiveTasks"))
                        };
                        lst.Add(cur);
                    }
                }
            }

            dgTMPlanningCheckGrid.ItemsSource = lst;

            if (dgTMPlanningCheckGrid.tableView != null)
            {
                dgTMPlanningCheckGrid.ShowTotalSummary();
                dgTMPlanningCheckGrid.GroupBy("ErrorInfo");
                dgTMPlanningCheckGrid.Visibility = Visibility.Visible;
            }

            busyIndicator.IsBusy = false;
        }