Пример #1
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));
        }
Пример #2
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
        }
Пример #3
0
        public async void GetVatOSS(DateTime fromDate, DateTime toDate)
        {
            SetDateTime(txtDateFrm, txtDateTo);

            busyIndicator.IsBusy = true;
            List <PropValuePair> propValPair = new List <PropValuePair>();

            if (fromDate != DateTime.MinValue || toDate != DateTime.MinValue)
            {
                string filter;
                if (fromDate != DateTime.MinValue)
                {
                    filter = String.Format("{0:d}..", fromDate);
                }
                else
                {
                    filter = "..";
                }
                if (toDate != DateTime.MinValue)
                {
                    filter += String.Format("{0:d}", toDate);
                }
                var prop = PropValuePair.GenereteWhereElements("Date", typeof(DateTime), filter);
                propValPair.Add(prop);
            }

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

            var vatEUList = glVatCache.Where(s => s._TypeSales == CreateVatOSSFile.VATTYPE_MOSS).Select(x => x._Vat).Distinct();

            if (vatEUList != null && vatEUList.Count() > 0)
            {
                var strLst = string.Join(";", vatEUList);
                propValPair.Add(PropValuePair.GenereteWhereElements(nameof(DebtorInvoiceLines.Vat), typeof(string), strLst));
            }
            var listOfDebInvLines = await api.Query <DebtorInvoiceLines>(propValPair);

            List <VatOSSTable> vatOSSlst = new List <VatOSSTable>();

            if (listOfDebInvLines != null && listOfDebInvLines.Length != 0)
            {
                vatOSSlst            = UpdateValues(listOfDebInvLines);
                busyIndicator.IsBusy = false;
            }
            else
            {
                var vatOSS = new VatOSSTable();
                vatOSS._CompanyId    = api.CompanyId;
                vatOSS._Date         = DefaultFromDate;
                vatOSS.MOSSType      = vatOSSReportType == 0 ? CreateVatOSSFile.MOSSTYPE_008 : vatOSSReportType == 1 ? CreateVatOSSFile.MOSSTYPE_021 : CreateVatOSSFile.MOSSTYPE_031;
                vatOSS._MOSSTypeName = GetMOSSTypeName(vatOSS.MOSSType);
                vatOSS.Compressed    = true;
                vatOSSlst.Add(vatOSS);

                busyIndicator.IsBusy = false;
                compressed           = true;
            }

            var sort = new VatOSSTableTypeSort();

            vatOSSlst.Sort(sort);
            dgVatOSSGrid.ItemsSource = vatOSSlst;
            dgVatOSSGrid.Visibility  = Visibility.Visible;
        }
        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());
            }
        }
Пример #5
0
        public async void GetInvoiceEuSale(DateTime fromDate, DateTime toDate)
        {
            SetDateTime(txtDateFrm, txtDateTo);

            busyIndicator.IsBusy = true;
            List <PropValuePair> propValPair = new List <PropValuePair>();

            if (fromDate != DateTime.MinValue || toDate != DateTime.MinValue)
            {
                string filter;
                if (fromDate != DateTime.MinValue)
                {
                    filter = String.Format("{0:d}..", fromDate);
                }
                else
                {
                    filter = "..";
                }
                if (toDate != DateTime.MinValue)
                {
                    filter += String.Format("{0:d}", toDate);
                }
                var prop = PropValuePair.GenereteWhereElements("Date", typeof(DateTime), filter);
                propValPair.Add(prop);
            }

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

            var vatEUList = glVatCache.Where(s => s._TypeSales == "s3" || s._TypeSales == "s4" || s._TypeSales == "s7").Select(x => x._Vat).Distinct();

            if (vatEUList != null && vatEUList.Count() > 0)
            {
                var strLst = string.Join(";", vatEUList);
                propValPair.Add(PropValuePair.GenereteWhereElements(nameof(DebtorInvoiceLines.Vat), typeof(string), strLst));
            }
            var listOfDebInvLines = await api.Query <DebtorInvoiceLines>(propValPair);

            List <EUSaleWithoutVAT> listdeb;

            if (listOfDebInvLines != null && listOfDebInvLines.Length != 0)
            {
                listdeb = UpdateValues(listOfDebInvLines);
            }
            else
            {
                listdeb = new List <EUSaleWithoutVAT>();
            }

            busyIndicator.IsBusy = false;

            if (listdeb.Count == 0)
            {
                UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("zeroRecords"), Uniconta.ClientTools.Localization.lookup("Warning"));
            }

            dgEUSalesWithoutVATGrid.ItemsSource = listdeb;
            dgEUSalesWithoutVATGrid.Visibility  = Visibility.Visible;
        }