public CwTransportRegistration(TMJournalLineClientLocal tmJournalLine, CrudAPI _crudApi)
        {
            crudApi     = _crudApi;
            journalline = tmJournalLine;
            Returning   = true;
            company     = crudApi.CompanyEntity;
            employee    = tmJournalLine.EmployeeRef;
            intializeProperties();
            this.DataContext = this;
            InitializeComponent();
            lePayType.api = leProject.api = leProjectTask.api = leWorkSpace.api = crudApi;
            this.Title    = string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("Mileage"), Uniconta.ClientTools.Localization.lookup("ProjectRegistration"));

            payrollCache = crudApi.GetCache(typeof(Uniconta.DataModel.EmpPayrollCategory));
            projectCache = crudApi.GetCache(typeof(Uniconta.DataModel.Project));

            debtor = tmJournalLine.ProjectRef?.Debtor;
            txtProjectName.Text = tmJournalLine.ProjectRef?._Name;
            installation        = tmJournalLine.ProjectRef?.InstallationRef;

            if (!company.ProjectTask)
            {
                lblProjectTask.Visibility = Visibility.Collapsed;
                leProjectTask.Visibility  = Visibility.Collapsed;
            }

            LoadControls();

            lePayType.cacheFilter = new MileagePayrollFilter(payrollCache);
            SetProjectTask();
        }
 public CwTransportRegistration(TMJournalLineClientLocal tmJournalLine, CrudAPI _crudApi, double mileageTotal, bool returning, bool _addMileage = false)
 {
     crudApi     = _crudApi;
     journalline = tmJournalLine;
     Returning   = returning;
     intializeProperties();
     this.DataContext = this;
     InitializeComponent();
     lePayType.api = leProject.api = crudApi;
     this.Title    = string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("Mileage"), Uniconta.ClientTools.Localization.lookup("ProjectRegistration"));
     employee      = tmJournalLine.EmployeeRef;
     company       = crudApi.CompanyEntity;
     if (journalline.RowId != 0 && journalline._RegistrationType == RegistrationType.Mileage)
     {
         chkReturning.IsEnabled = false;
     }
     else
     {
         debtor = tmJournalLine.ProjectRef?.Debtor;
         txtProjectName.Text = tmJournalLine.ProjectRef?._Name;
         installation        = tmJournalLine.ProjectRef?.InstallationRef;
     }
     addMileage        = _addMileage;
     this.mileageTotal = mileageTotal;
     LoadControls();
     this.DataContext = this;
 }
예제 #3
0
        public List <TMJournalLineError> ValidateLinesMileage(IEnumerable <TMJournalLineClientLocal> lines,
                                                              DateTime startDate,
                                                              DateTime endDate,
                                                              IList <EmpPayrollCategoryEmployeeClient> empPriceLst,
                                                              SQLTableCache <Uniconta.DataModel.EmpPayrollCategory> empPayrollCatList,
                                                              SQLTableCache <Uniconta.ClientTools.DataModel.ProjectClient> projCache,
                                                              SQLTableCache <Uniconta.DataModel.ProjectGroup> projGroupList,
                                                              Uniconta.DataModel.Employee employee)
        {
            checkErrors = new List <TMJournalLineError>();

            this.empPayrollCatList = empPayrollCatList;
            this.projGroupList     = projGroupList;
            this.projCache         = projCache;
            this.comp        = api.CompanyEntity;
            this.empPriceLst = empPriceLst;
            this.employee    = employee;
            var approveDate = employee._TMApproveDate;

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

            this.endDate = endDate;

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

                ValidateMileageGeneral(rec);
                ValidateMileageProject(rec);
                ValidateMileageProjectCategory(rec);

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

            if (!err)
            {
                ValidateHoursPrice(lines);
            }

            return(checkErrors);
        }
        protected override Task <ErrorCodes> saveGrid()
        {
            var t = base.saveGrid();

            if (master != null)
            {
                Uniconta.DataModel.Employee emp = master as Uniconta.DataModel.Employee;
                if (emp != null)
                {
                    emp.EmpPrices = null;
                }
                else
                {
                    Uniconta.DataModel.EmpPayrollCategory pay = master as Uniconta.DataModel.EmpPayrollCategory;
                    if (pay != null)
                    {
                        pay.Rates = null;
                    }
                }
            }

            return(t);
        }
예제 #5
0
 public Task EmployeeChanged(Uniconta.DataModel.Employee employee)
 {
     this.employee = employee;
     return(LoadingTask = LoadBaseData(api));
 }
예제 #6
0
 public TMJournalLineHelper(CrudAPI api, Uniconta.DataModel.Employee employee)
 {
     this.api      = api;
     this.employee = employee;
     LoadingTask   = LoadBaseData(api);
 }
예제 #7
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);
        }
예제 #8
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));
        }
예제 #9
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
        }
예제 #10
0
 public TMJournalLineHelper(CrudAPI api, Uniconta.DataModel.Employee employee)
 {
     this.api      = api;
     this.employee = employee;
 }