Exemple #1
0
        /// <summary>
        /// Validate - Task
        /// </summary>
        void ValidateTask(TMJournalLineClient rec)
        {
            if (err)
            {
                return;
            }

            if (prTask != null)
            {
                if (prTask._Ended)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = Uniconta.ClientTools.Localization.lookup("TaskIsEnded"),
                        RowId   = rec.RowId
                    });

                    err = true;
                }

                if (!err && rec._WorkSpace != null && prTask._WorkSpace != null && rec._WorkSpace != prTask._WorkSpace)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Concat(Uniconta.ClientTools.Localization.lookup("CombinationNotAllowed"), " ",
                                                Uniconta.ClientTools.Localization.lookup("Workspace"), "/",
                                                Uniconta.ClientTools.Localization.lookup("Task")),
                        RowId = rec.RowId
                    });

                    err = true;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Validate - Prices
        /// </summary>
        void ValidatePrice(TMJournalLineClient line)
        {
            if (!err)
            {
                int dayOfWeekStart = startDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)startDate.DayOfWeek;
                int dayOfWeekEnd   = endDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)endDate.DayOfWeek;
                var isMileageTrans = payrollCat._InternalType == InternalType.Mileage ? true : false;

                for (int x = dayOfWeekStart; x <= dayOfWeekEnd; x++)
                {
                    if (line.GetHoursDayN(x) == 0)
                    {
                        continue;
                    }

                    var salesPrice = line.GetSalesPricesDayN(x);
                    var costPrice  = line.GetCostPricesDayN(x);

                    if (salesPrice == 0)
                    {
                        if (costPrice == 0)
                        {
                            checkErrors.Add(new TMJournalLineError()
                            {
                                Message = Uniconta.ClientTools.Localization.lookup("NoRatesEmployee"),
                                RowId   = line.RowId
                            });
                            err = true;
                        }
                        else if (line._Invoiceable && !isMileageTrans)
                        {
                            checkErrors.Add(new TMJournalLineError()
                            {
                                Message = string.Format("{0} ({1}: {2})",
                                                        Uniconta.ClientTools.Localization.lookup("NoSalesPrice"),
                                                        Uniconta.ClientTools.Localization.lookup("Date"),
                                                        startDate.AddDays(x - 1).ToString("dd.MM.yyyy")),
                                RowId = line.RowId
                            });
                            err = true;
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Validate - Project
        /// </summary>
        void ValidateProject(TMJournalLineClient rec)
        {
            if (err)
            {
                return;
            }

            if (proj._Blocked)
            {
                checkErrors.Add(new TMJournalLineError()
                {
                    Message = Uniconta.ClientTools.Localization.lookup("ProjectIsBlocked"),
                    RowId   = rec.RowId
                });

                err = true;
            }
        }
Exemple #4
0
        /// <summary>
        /// Validate - Project Category
        /// </summary>
        void ValidateProjectCategory(TMJournalLineClient rec)
        {
            if (err)
            {
                return;
            }

            if (payrollCat?._PrCategory == null)
            {
                checkErrors.Add(new TMJournalLineError()
                {
                    Message = fieldCannotBeEmpty("ProjectCategory"),
                    RowId   = rec.RowId
                });

                err = true;
            }

            if (err)
            {
                return;
            }

            if (rec._RegistrationType == RegistrationType.Hours)
            {
                if (projGroup._Invoiceable && !prCategory._Invoiceable)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Concat(Uniconta.ClientTools.Localization.lookup("CombinationNotAllowed"), " ",
                                                Uniconta.ClientTools.Localization.lookup("Project"), " (",
                                                Uniconta.ClientTools.Localization.lookup("Invoiceable"), ")/",
                                                Uniconta.ClientTools.Localization.lookup("ProjectCategory"), " (",
                                                Uniconta.ClientTools.Localization.lookup("NotInvoiceable"), ")"),
                        RowId = rec.RowId
                    });

                    err = true;
                }
                else if (!projGroup._Invoiceable && prCategory._Invoiceable)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Concat(Uniconta.ClientTools.Localization.lookup("CombinationNotAllowed"), " ",
                                                Uniconta.ClientTools.Localization.lookup("Project"), " (",
                                                Uniconta.ClientTools.Localization.lookup("NotInvoiceable"), ")/",
                                                Uniconta.ClientTools.Localization.lookup("ProjectCategory"), " (",
                                                Uniconta.ClientTools.Localization.lookup("Invoiceable"), ")"),
                        RowId = rec.RowId
                    });

                    err = true;
                }
                else if (!projGroup._Invoiceable && !prCategory._Invoiceable && rec._Invoiceable)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Concat(Uniconta.ClientTools.Localization.lookup("Project"), " (",
                                                Uniconta.ClientTools.Localization.lookup("NotInvoiceable"), ")"),
                        RowId = rec.RowId
                    });

                    err = true;
                }


                if (payrollCat._InternalType == InternalType.Mileage)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Format(Uniconta.ClientTools.Localization.lookup("ActionNotAllowedObj"),
                                                Uniconta.ClientTools.Localization.lookup("ProjectRegistration"),
                                                Uniconta.ClientTools.Localization.lookup("Mileage").ToLower()),
                        RowId = rec.RowId
                    });

                    err = true;
                }

                if (payrollCat._InternalType != InternalType.None && rec.Project != payrollCat._InternalProject)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Concat(Uniconta.ClientTools.Localization.lookup("CombinationNotAllowed"), " ",
                                                Uniconta.ClientTools.Localization.lookup("Project"), "/",
                                                Uniconta.ClientTools.Localization.lookup("PayrollCategory")),
                        RowId = rec.RowId
                    });
                    err = true;
                }
            }
            else
            {
                if (payrollCat._Rate == 0)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Format(Uniconta.ClientTools.Localization.lookup("MissingOBJ"), string.Concat(Uniconta.ClientTools.Localization.lookup("Rate"), " ", Uniconta.ClientTools.Localization.lookup("Mileage").ToLower())),
                        RowId   = rec.RowId
                    });

                    err = true;
                }

                if (payrollCat._InternalType != InternalType.Mileage)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Format(Uniconta.ClientTools.Localization.lookup("Interntype"), "=",
                                                Uniconta.ClientTools.Localization.lookup("Mileage")),
                        RowId = rec.RowId
                    });

                    err = true;
                }

                if (payrollCat._InternalProject != null && rec._Project != payrollCat._InternalProject)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = string.Format(Uniconta.ClientTools.Localization.lookup("ActionNotAllowedObj"),
                                                string.Concat(Uniconta.ClientTools.Localization.lookup("Project"), "'", rec._Project, "'"),
                                                Uniconta.ClientTools.Localization.lookup("Mileage").ToLower()),
                        RowId = rec.RowId
                    });

                    err = true;
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Validate - General
        /// </summary>
        void ValidateGeneral(TMJournalLineClient rec)
        {
            if (err)
            {
                return;
            }

            if (rec.Project == null)
            {
                checkErrors.Add(new TMJournalLineError()
                {
                    Message = fieldCannotBeEmpty("ProjectNumber"),
                    RowId   = rec.RowId
                });

                err = true;
            }

            if (projGroup == null)
            {
                checkErrors.Add(new TMJournalLineError()
                {
                    Message = fieldCannotBeEmpty("ProjectGroup"),
                    RowId   = rec.RowId
                });

                err = true;
            }

            if (rec.PayrollCategory == null)
            {
                checkErrors.Add(new TMJournalLineError()
                {
                    Message = fieldCannotBeEmpty("PayrollCategory"),
                    RowId   = rec.RowId
                });

                err = true;
            }

            if (rec._RegistrationType == RegistrationType.Mileage)
            {
                if (rec.AddressFrom == null)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = fieldCannotBeEmpty("AddressFrom"),
                        RowId   = rec.RowId
                    });

                    err = true;
                }

                if (rec.AddressTo == null)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = fieldCannotBeEmpty("AddressTo"),
                        RowId   = rec.RowId
                    });

                    err = true;
                }

                if (rec.Text == null)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = fieldCannotBeEmpty("Purpose"),
                        RowId   = rec.RowId
                    });

                    err = true;
                }

                if (rec.VechicleRegNo == null)
                {
                    checkErrors.Add(new TMJournalLineError()
                    {
                        Message = fieldCannotBeEmpty("VechicleRegNo"),
                        RowId   = rec.RowId
                    });

                    err = true;
                }
            }
        }
        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());
            }
        }