private void localMenu_OnItemClicked(string ActionType)
        {
            EmpPayrollCategoryEmployeeClient selectedItem = dgEmpPayCatGrid.SelectedItem as EmpPayrollCategoryEmployeeClient;

            switch (ActionType)
            {
            case "AddRow":
                dgEmpPayCatGrid.AddRow();
                break;

            case "CopyRow":
                dgEmpPayCatGrid.CopyRow();
                break;

            case "SaveGrid":
                dgEmpPayCatGrid.SaveData();
                break;

            case "DeleteRow":
                if (selectedItem != null)
                {
                    dgEmpPayCatGrid.DeleteRow();
                }
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }
Example #2
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);
        }
Example #3
0
        public void SetEmplPrice(IEnumerable <TMJournalLineClientLocal> lst,
                                 IList <EmpPayrollCategoryEmployeeClient> empPriceLst,
                                 SQLTableCache <Uniconta.DataModel.EmpPayrollCategory> empPayrollCatLst,
                                 SQLTableCache <Uniconta.ClientTools.DataModel.ProjectClient> projLst,
                                 DateTime startDate,
                                 DateTime endDate,
                                 Uniconta.DataModel.Employee employee,
                                 bool validate = false)
        {
#if !SILVERLIGHT
            bool foundErr;

            this.employee    = employee;
            this.empPriceLst = empPriceLst;
            int dayOfWeekStart = startDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)startDate.DayOfWeek;
            int dayOfWeekEnd   = endDate.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)endDate.DayOfWeek;

            var defaultPayrollCategory = empPayrollCatLst.Where(s => s._PrCategory == null && s.KeyStr == "Default").FirstOrDefault();

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

            foreach (var trans in lst)
            {
                var isMileageTrans = trans._RegistrationType == RegistrationType.Mileage ? true : false;
                if (isMileageTrans)
                {
                    var projGroup = projGroupList.Get(trans.ProjectRef.Group);
                    if (projGroup != null)
                    {
                        trans._Invoiceable = projGroup._Invoiceable;
                    }
                }

                var payrollCat = empPayrollCatLst.Get(trans._PayrollCategory);
                var Proj       = projLst.Get(trans._Project);

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

                    double salesPrice = 0, costPrice = 0;

                    EmpPayrollCategoryEmployeeClient prices = null;
                    if (empPriceLst != null && empPriceLst.Count > 0)
                    {
                        prices = PriceMatrix(startDate, x, Proj, trans._PayrollCategory);

                        if (prices != null && prices._Project == null && prices._DCAccount == null && !isMileageTrans)
                        {
                            prices = PriceMatrix(startDate, x, Proj, defaultPayrollCategory?.KeyStr, true) ?? prices;
                        }
                        else if (prices == null && defaultPayrollCategory != null && !isMileageTrans)
                        {
                            prices = PriceMatrix(startDate, x, Proj, 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 (!isMileageTrans) //Always fallback to Employee for cost and sales prices
                    {
                        if (salesPrice == 0)
                        {
                            salesPrice = employee._SalesPrice;
                        }
                        if (costPrice == 0)
                        {
                            costPrice = employee._CostPrice;
                        }
                    }

                    trans.SetPricesDayN(x, trans._Invoiceable ? salesPrice : 0, costPrice);

                    if (validate && !foundErr)
                    {
                        if (salesPrice == 0 && costPrice == 0)
                        {
                            if (startDate.AddDays(x - 1) >= employee._Hired)
                            {
                                checkErrors.Add(new TMJournalLineError()
                                {
                                    Message = Uniconta.ClientTools.Localization.lookup("NoRatesEmployee"),
                                    RowId   = trans.RowId
                                });

                                trans.ErrorInfo = string.Empty;
                                err             = true;
                                foundErr        = true;
                            }
                        }
                        else
                        {
                            if (!foundErr && salesPrice == 0 && trans._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 = trans.RowId
                                });

                                trans.ErrorInfo = string.Empty;
                                err             = true;
                                foundErr        = true;
                            }
                        }
                    }
                }
            }
#endif
        }