Beispiel #1
0
        public void generateSlipePay(Paie p)
        {
            #region headerPDF
            int PDF_WIDTH = 250;
            int PDF_MARGIN_LEFT=20;
            int NEXT_MARGIN_TOP = 60;
            PdfDocument pdf = new PdfDocument();
            pdf.Info.Title = p.Nom + "_Paie";
            PdfPage page;
            page = pdf.AddPage();
            page.Orientation = PageOrientation.Portrait;
            page.Size = PageSize.A4;
            XGraphics graph = XGraphics.FromPdfPage(page);
            List<LiaisonProjetEmploye> Liaison = new List<LiaisonProjetEmploye>();
            MySqlEmployeService _ServiceMysql = new MySqlEmployeService();
            XFont font = new XFont("Consolas", 10.0); //new XFont("Verdana", 20, XFontStyle.Bold);
            var formatter = new XTextFormatter(graph);
            XPen penn = new XPen(XColors.Black, 1);
            penn.DashStyle = XDashStyle.Dash;

            graph.DrawLine(penn, 0, 3, page.Height, 3);
            graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(95,95,95)), new XRect(0, 3, page.Height, 30));

            var layoutRectangle = new XRect(5, 12.5, page.Width, page.Height);
            formatter.DrawString("GEM-C Rapport de paie de : " + (p.Nom), font, XBrushes.White, layoutRectangle);
            layoutRectangle = new XRect(300, 12.5, page.Width, page.Height);
            formatter.DrawString(("Talon pour la période du : " + p.Periode), font, XBrushes.White, layoutRectangle);

            graph.DrawLine(penn, 0, 33, 800, 33);

            graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(255, 243, 229)), new XRect(0, 34, page.Height, 255));
            layoutRectangle = new XRect(PDF_MARGIN_LEFT, 40, page.Width, page.Height);
            formatter.DrawString("Calcul du salaire :", font, XBrushes.Black, layoutRectangle);
            graph.DrawLine(penn, PDF_MARGIN_LEFT, 55, 150, 55);
            #endregion

            if(p.MontantCommission != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font,layoutRectangle, formatter,"Montant commission : ", Math.Round(p.MontantCommission,2).ToString());
                NEXT_MARGIN_TOP+=10;
            }
            if (p.MontantIndemnite != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant indemnite : ", Math.Round(p.MontantIndemnite,2).ToString());
                NEXT_MARGIN_TOP += 10;
            }
            if (p.MontantPourboire != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant pourboire : ", Math.Round(p.MontantPourboire,2).ToString());
                NEXT_MARGIN_TOP += 10;
            }
            if (p.MontantPrime != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant prime : ", Math.Round(p.MontantPrime,2).ToString());
                NEXT_MARGIN_TOP += 10;
            }
            if (p.MontantAllocations != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant allocations : ", Math.Round(p.MontantAllocations, 2).ToString());
                NEXT_MARGIN_TOP += 10;
            }
            double lesmontants = Math.Round((p.MontantAllocations + p.MontantCommission + p.MontantIndemnite + p.MontantPourboire + p.MontantPrime), 2);
            if (lesmontants != 0)
            {
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "", "--------------", "");
                NEXT_MARGIN_TOP += 10;
                drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Total des montants :  ", lesmontants.ToString());
                NEXT_MARGIN_TOP += 30;
            }

            // ce qui nou intéresse commence

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Heure regulier : ", Math.Round(p.NombreHeure, 2).ToString(), " hr(s)");
            NEXT_MARGIN_TOP += 10;

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Heure suplémentaire : ", Math.Round(p.NombreHeureSupp, 2).ToString(), " hr(s)");
            NEXT_MARGIN_TOP += 10;

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, ("Taux rég : " + p.salaire.ToString() + "$ "), Math.Round((p.NombreHeureSupp*(Convert.ToDouble(p.salaire))),2).ToString());
            NEXT_MARGIN_TOP+=10; supp :
            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Taux supp :  " + Math.Round((Convert.ToDouble(p.salaire) * 1.5), 4).ToString() + " $", Math.Round((p.MontantBrute - lesmontants) - (p.NombreHeure * Convert.ToDouble(p.salaire)), 2).ToString());
            NEXT_MARGIN_TOP += 10;

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "", "--------------", "");
            NEXT_MARGIN_TOP += 10;
            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant brute total :  ", Math.Round((p.MontantBrute), 2).ToString());
            NEXT_MARGIN_TOP += 10;
            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "", "--------------", "");
            NEXT_MARGIN_TOP += 10;

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant impôt combiné (Féd. et prov.): ", "-" + (Math.Round(p.MontantBrute, 2) - Math.Round(p.MontantNet, 2)).ToString());
            NEXT_MARGIN_TOP += 20;

            graph.DrawRectangle(XPens.Black, XBrushes.LightSeaGreen, 5, NEXT_MARGIN_TOP-2.5, page.Width-10, page.Height-825);

            drawPDF(PDF_WIDTH, NEXT_MARGIN_TOP, PDF_MARGIN_LEFT, page, font, layoutRectangle, formatter, "Montant Net du : ", Math.Round(p.MontantNet, 2).ToString());

            graph.DrawLine(XPens.Black, 0, 280, 800, 280);
            #region outputPDF
            StringBuilder b = new StringBuilder();
            b.Append("talon_");
            b.Append(p.Nom.ToString());
            b.Append("_");
            b.Append(String.Format("{0:M/d/yyyy}", Convert.ToDateTime(p.DateGenerationRapport)));
            b.Append(".pdf");
            string pdfFilename = b.ToString().Replace(" ", "_");
            pdf.Save(pdfFilename);
            Process.Start(pdfFilename);
            #endregion
        }
Beispiel #2
0
        // Fin de la classe de test.
        public void GenererPaies()
        {
            MySqlPaieService _service = new MySqlPaieService();
            DataTable Periode;

            float temps;
            try
            {
                // Aller chercher tous les employés
                MySqlEmployeService _emService = new MySqlEmployeService();
                IList<Employe> emp = _emService.RetrieveAll();
                Periode = _service.PeriodeTemps();

                if (Periode.Rows.Count == 0)
                {
                    throw new Exception("Toutes les périodes de paies ont déjà été générer. Allez en rentré de nouvelle pour la nouvelle année.");
                }
                else
                {
                    DateTime start = (DateTime)Periode.Rows[0][0],
                    end = (DateTime)Periode.Rows[0][1];
                    DateTime date = DateTime.Now;
                    PeriodePaie tmpTime = new PeriodePaie(date, date);
                    if(tmpTime.Fin < end)
                    {
                        throw new Exception("La période que vous essayez de générer est en cours.");
                    }
                    float HeureSupp = 0;
                    int compteurTemps = 0;
                    int totalEmp = emp.Count;
                // Pour chaque employé aller chercher leur temps.
                    foreach (Employe em in emp)
                    {
                        {

                            temps = _service.RetrieveCompteurs(em.ID, start, end);
                            // Vérification dans le cas ou personne n'aurais travailler dans cette période.
                            if(temps == 0)
                            {
                                compteurTemps++;
                                if(compteurTemps == totalEmp)
                                {
                                    StringBuilder mess = new StringBuilder();
                                    mess.Append("Aucune employé à travail durant la période. Cette période à été noté comme généré: ");
                                    mess.Append(start.ToString());
                                    mess.Append(end.ToString());
                                    if (!(_service.periodeGenere(start, end)))
                                    {
                                        throw new Exception("Problème avec l'état des périodes de paie, vérifier que votre période courrante est cohérente.");
                                    }
                                    throw new Exception(mess.ToString());
                                }
                            }
                            else
                            {
                                if (temps > supp)
                                {
                                    HeureSupp = temps - supp;
                                    temps = temps - supp;
                                }

                                float Brute = ((float)em.Salaire * temps) + ((float)em.SalaireOver * HeureSupp);
                                TimeSpan t = end - start;
                                Double days = t.TotalDays;
                                days = 365/(days+1);
                                double EstimatedAnnualSalary = days * Brute;
                                float Net = 0;
                                Net = Brute * (1 - tauxCombineQC_CA((double)(days * Brute)));

                                Paie tmpPaie = new Paie() { MontantBrute = Brute, MontantNet = Net, NombreHeure = temps, NombreHeureSupp = HeureSupp };
                                if (!(_service.periodeGenere(start, end)))
                                {
                                    throw new Exception("Problème avec l'état des périodes de paie, vérifier que votre période courrante est cohérente.");
                                }
                                // Appel  de la fonction de génération de paie.
                                if (!(_service.insertPaie(tmpPaie, start, end, em.ID)))
                                {
                                    throw new Exception("Impossible de générer la paie de " + em.Prenom + " , " + em.Nom + " correctements vérifier les dates de vos périodes de paies.");
                                }
                           }
                        }
                    }
                    // change la période paye à terminé.
                    throw new Exception("Réussite de la génération des paies pour la période de :" + (start.Date).ToString("d") + " au " + (end.Date).ToString("d"));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #3
0
        private void GenererRapportEmploye(object sender, RoutedEventArgs e)
        {
            List<Employe> lstEmp = new List<Employe>();
            //Tri nom employé
            foreach (Employe emp in lstRapportEmploye.SelectedItems)
                lstEmp.Add(emp);

            //Tri nom employé
            if((bool)rbtTriNomAZ.IsChecked)
                lstEmp = lstEmp.OrderBy(lst => lst.Nom).ToList();
            else if ((bool)rbtTriNomZA.IsChecked)
                lstEmp = lstEmp.OrderByDescending(lst => lst.Nom).ToList();

            //Tri salaire
            else if ((bool)rbtTriSalaireASC.IsChecked)// ASC
                lstEmp = lstEmp.OrderBy(lst => lst.Salaire).ToList();
            else if ((bool)rbtTriSalaireDESC.IsChecked)// DESC
                lstEmp = lstEmp.OrderByDescending(lst => lst.Salaire).ToList();

            try
            {
                if (Convert.ToSingle(lstEmp.Count.ToString()) > 0)
                {
                    if (chxProjetEmploye.IsChecked.Value || chxInfoGenerale.IsChecked.Value)
                    {
                        PdfDocument pdf = new PdfDocument();
                        pdf.Info.Title = "Rapport Employe";
                        PdfPage page;
                        page = pdf.AddPage();
                        page.Orientation = PageOrientation.Landscape;
                        page.Size = PageSize.A4;
                        XGraphics graph = XGraphics.FromPdfPage(page);
                        List<LiaisonProjetEmploye> Liaison = new List<LiaisonProjetEmploye>();
                        MySqlEmployeService _ServiceMysql = new MySqlEmployeService();
                        XFont font = new XFont("Consolas", 20.0);
                        var formatter = new XTextFormatter(graph);
                        int height = 70;
                        XPen penn = new XPen(XColors.Black, 1);
                        penn.DashStyle = XDashStyle.Dash;

                        string date = DateTime.Now.ToString("dd/MM/yyyy");
                        //Entête
                        graph.DrawLine(penn, 3, 3, 850, 3);
                        graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(95, 95, 95)), new XRect(0, 5, 850, 60));
                        var layoutRectangle = new XRect(5, 25, page.Width, page.Height);
                        formatter.DrawString("GEM-C Rapport des employés", font, XBrushes.Black, layoutRectangle);
                        layoutRectangle = new XRect(600, 25, page.Width, page.Height);
                        formatter.DrawString(("Date : " + date), font, XBrushes.Black, layoutRectangle);
                        graph.DrawLine(penn, 3, 67, 850, 67);
                        graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(255, 243, 229)), new XRect(0, 70, 850, 600));

                        //Table
                        font = new XFont("Consolas", 10.0);

                        graph.DrawRectangle(XPens.Black, new XRect(5, height + 5, 20, 60));
                        layoutRectangle = new XRect(7, height + 5, page.Width, page.Height);
                        formatter.DrawString("ID", font, XBrushes.Black, layoutRectangle);

                        graph.DrawRectangle(XPens.Black, new XRect(25, height + 5, 150, 60));
                        layoutRectangle = new XRect(27, height + 5, page.Width, page.Height);
                        formatter.DrawString("Nom", font, XBrushes.Black, layoutRectangle);

                        layoutRectangle = new XRect(27, height + 20, page.Width, page.Height);
                        formatter.DrawString("Prénom", font, XBrushes.Black, layoutRectangle);

                        if (chxInfoGenerale.IsChecked.Value)
                        {
                            graph.DrawRectangle(XPens.Black, new XRect(175, height + 5, 120, 60));
                            layoutRectangle = new XRect(178, height + 5, page.Width, page.Height);
                            formatter.DrawString("Informations générales", font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(178, height + 20, page.Width, page.Height);
                            formatter.DrawString("-Titre emploi", font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(178, height + 30, page.Width, page.Height);
                            formatter.DrawString("-'Date embauche'", font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(178, height + 40, page.Width, page.Height);
                            formatter.DrawString("-(Statut)", font, XBrushes.Black, layoutRectangle);

                            graph.DrawRectangle(XPens.Black, new XRect(295, height + 5, 130, 60));
                            layoutRectangle = new XRect(298, height + 5, page.Width, page.Height);
                            formatter.DrawString("Détails financiés", font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(298, height + 20, page.Width, page.Height);
                            formatter.DrawString("-Salaire" , font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(298, height + 30, page.Width, page.Height);
                            formatter.DrawString("-(Salaire avec les ", font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(298, height + 40, page.Width, page.Height);
                            formatter.DrawString("heures supplémentaires)", font, XBrushes.Black, layoutRectangle);
                        }

                        if (chxProjetEmploye.IsChecked.Value)
                        {
                            graph.DrawRectangle(XPens.Black, new XRect(175, height + 5, 250, 60));
                            graph.DrawRectangle(XPens.Black, new XRect(425, height + 5, 170, 60));
                            layoutRectangle = new XRect(430, height + 5, page.Width, page.Height);
                            formatter.DrawString("Projet(s) occupé(s)", font, XBrushes.Black, layoutRectangle);

                            graph.DrawRectangle(XPens.Black, new XRect(595, height + 5, 150, 60));
                            layoutRectangle = new XRect(605, height + 5, page.Width, page.Height);
                            formatter.DrawString("Temps travaillé", font, XBrushes.Black, layoutRectangle);
                        }

                        height = 130;
                        foreach (Employe emp in lstEmp)
                        {
                            if (chxProjetEmploye.IsChecked.Value)
                            {
                                Liaison = new List<LiaisonProjetEmploye>(_ServiceMysql.GetLiaison(emp.ID));

                                if (15 * Liaison.Count + height > 530)
                                {
                                    page = pdf.AddPage();
                                    page.Orientation = PageOrientation.Landscape;
                                    graph = XGraphics.FromPdfPage(page);
                                    formatter = new XTextFormatter(graph);
                                    height = 0;
                                    graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(255, 243, 229)), new XRect(0, 0, 850, 600));
                                }
                            }
                            else if (!chxProjetEmploye.IsChecked.Value && height > 550)
                            {
                                page = pdf.AddPage();
                                page.Orientation = PageOrientation.Landscape;
                                graph = XGraphics.FromPdfPage(page);
                                formatter = new XTextFormatter(graph);
                                height = 0;
                                graph.DrawRectangle(new XSolidBrush(XColor.FromArgb(255, 243, 229)), new XRect(0, 0, 850, 600));
                            }

                            int y = height;

                            layoutRectangle = new XRect(7, height += 15 , page.Width, page.Height);
                            formatter.DrawString( emp.ID.ToString(), font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(27, height , page.Width, page.Height);
                            formatter.DrawString(emp.Nom.ToString(), font, XBrushes.Black, layoutRectangle);

                            layoutRectangle = new XRect(27  , height + 15 , page.Width, page.Height);
                            formatter.DrawString(emp.Prenom.ToString(), font, XBrushes.Black, layoutRectangle);

                            //Section info employé
                            if (chxInfoGenerale.IsChecked.Value)
                            {

                                layoutRectangle = new XRect(178, height , page.Width, page.Height);
                                formatter.DrawString(emp.Poste.ToString(), font, XBrushes.Black, layoutRectangle);

                                layoutRectangle = new XRect(178 , height + 15, page.Width, page.Height);
                                formatter.DrawString(("'" + _ServiceMysql.getDateEmbauche(emp.ID) + "'"), font, XBrushes.Black, layoutRectangle);

                                if (!emp.HorsFonction)
                                {
                                    layoutRectangle = new XRect(178 , height + 30, page.Width, page.Height);
                                    formatter.DrawString("(En service)", font, XBrushes.Black, layoutRectangle);
                                }
                                else
                                {
                                    layoutRectangle = new XRect(178 , height + 30, page.Width, page.Height);
                                    formatter.DrawString("(Hors service)", font, XBrushes.Black, layoutRectangle);
                                }

                                layoutRectangle = new XRect(298, height , page.Width, page.Height);
                                formatter.DrawString((Math.Round(Convert.ToSingle(emp.Salaire), 2) + " $"), font, XBrushes.Black, layoutRectangle);
                                layoutRectangle = new XRect(298, height + 15, page.Width, page.Height);
                                formatter.DrawString(("(" + Math.Round( Convert.ToSingle(emp.SalaireOver), 2) + " $)"), font, XBrushes.Black, layoutRectangle);
                            }
                            //Section projets des employés
                            if (chxProjetEmploye.IsChecked.Value)
                            {
                                Liaison = new List<LiaisonProjetEmploye>(_ServiceMysql.GetLiaison(emp.ID));
                                Dictionary<string, float> lstProjHeure = new Dictionary<string, float>();
                                foreach (LiaisonProjetEmploye liaison in Liaison)
                                    lstProjHeure.Add(liaison.ProjNom, Convert.ToInt32(_ServiceMysql.CompteursProjets(emp.ID, liaison.ProjNom)));
                                int count = 0;

                                if (Liaison.Count > 0)
                                {
                                    //Tri nom projet
                                    if ((bool)rbtTriProjetAZ.IsChecked)
                                        lstProjHeure = (Dictionary<string, float>)lstProjHeure.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
                                    else if ((bool)rbtTriProjetZA.IsChecked)
                                        lstProjHeure = (Dictionary<string, float>)lstProjHeure.OrderByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value);

                                    //Tri nb heure
                                    if ((bool)rbtTriNBheureASC.IsChecked)//ASC
                                        lstProjHeure = (Dictionary<string, float>)lstProjHeure.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
                                    else if ((bool)rbtTriNBheureDESC.IsChecked)//DESC
                                        lstProjHeure = (Dictionary<string, float>)lstProjHeure.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

                                    foreach (KeyValuePair<string, float> dict in lstProjHeure)
                                    {
                                        count++;
                                        layoutRectangle = new XRect(425, y += 15, page.Width, page.Height);
                                        formatter.DrawString(count + " - " + dict.Key.ToString(), font, XBrushes.Black, layoutRectangle);

                                        layoutRectangle = new XRect(605 , y, page.Width, page.Height);
                                        formatter.DrawString(dict.Value + " heures", font, XBrushes.Black, layoutRectangle);
                                    }
                                    if (y > height)
                                        height = y;
                                }
                            }
                            height += 30;
                            graph.DrawLine(XPens.Black, 10, height+=20 , 800, height);

                        }
                        StringBuilder fileName = new StringBuilder();
                        fileName.Append("Rapport_Emp_");
                        fileName.Append(DateTime.Now.ToString());
                        fileName.Append(".pdf");
                        fileName.Replace(":", "");
                        fileName.Replace(" ", "_");
                        pdf.Save(fileName.ToString());
                        Process.Start(fileName.ToString());
                    }
                    else
                        MessageBox.Show("Aucune information choisie");
                }
                else
                    MessageBox.Show("Ancun employé sélectionné");
            }
            catch (Exception E)
            {
                 MessageBox.Show("Le fichier est déjà utilisé, veuillez le fermer pour le regénérer");
            }
        }