예제 #1
0
        private void PayerPersonnel(string employe, int codeEmploye, string debut, string fin, string date, ComboBox cptePaiement,
                                    string tresoriere, TextBox montant)
        {
            string cptePaie   = cptePaiement.GetItemText(cptePaiement.SelectedItem);
            int    codeCompte = Convert.ToInt32(cptePaiement.SelectedValue.ToString());

            if (Validation.VerifierChampsMontant(montant.Text))
            {
                if (RemunerationPasEncorePayePourLaPeriod(codeEmploye))
                {
                    if (Tresorerie.IlYaAssezDeFondsDansLeCompte(cptePaiement, montant))
                    {
                        EvePaiementEmploye paiement = new EvePaiementEmploye
                        {
                            CodeEmployePaye = codeEmploye,
                            DeCetteDate     = DateTime.Parse(debut),
                            ACetteDate      = DateTime.Parse(fin)
                        };

                        db.EvePaiementEmployes.Add(paiement);
                        db.SaveChanges();

                        EveDecaissement decaiss = new EveDecaissement
                        {
                            DateDecaissement    = DateTime.Parse(date),
                            CodePaiementEmploye = paiement.CodePaiementEmploye,
                            CodeCompte          = codeCompte,
                            Description         = "Paiment rémunération de " + employe + " pour la période du " + debut + " au " + fin,
                            CodeEmploye         = int.Parse(tresoriere),
                            Montant             = int.Parse(montant.Text)
                        };

                        db.EveDecaissements.Add(decaiss);
                        db.SaveChanges();

                        MessageBox.Show($"Le paiement de {employe} a été enregistré pour la période du {debut} au {fin}.");
                    }
                }
                else
                {
                    MessageBox.Show($"{employe} a déjà été payé pour la période selectionnée.");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Le montant entré n'est pas valide.");
                return;
            }
        }
        private void PayerTransportMatierePremiere(EveReceptionDonsMatieresPremiere don)
        {
            if (int.Parse(txtTransport.Text) > 0)
            {
                EveDecaissement decaiss = new EveDecaissement
                {
                    DateDecaissement = don.DateReception,
                    Montant          = int.Parse(txtTransport.Text),
                    Description      = "Transport don matière premiere",
                    CodeCompte       = int.Parse(cbxCompte.GetItemText(cbxCompte.SelectedValue)),
                    //CodeReceptionMatierePremiere = don.CodeReceptionDonMatierePremiere
                };

                db.EveDecaissements.Add(decaiss);
                db.SaveChanges();
            }
        }
예제 #3
0
        private void BtnEnregistrerTransfert_Click(object sender, EventArgs e)
        {
            var codeCpteDebiteur  = int.Parse(cbxCompteDebit.SelectedValue.ToString());
            var codeCpteCrediteur = int.Parse(cbxCompteCredit.SelectedValue.ToString());

            var employe     = cbxEmploye.GetItemText(cbxEmploye.SelectedItem);
            var codeEmploye = (from em in db.AgeEmployes
                               where em.PrenomNom == employe
                               select em.CodeEmploye).FirstOrDefault();

            if (Validation.MontantEstValide(txtMontant.Text))
            {
                if (ComptesDifferents(codeCpteDebiteur, codeCpteCrediteur))
                {
                    if (Tresorerie.IlYaAssezDeFondsDansLeCompte(cbxCompteDebit, txtMontant))
                    {
                        if (txtDescription.Text.Trim().Length > 0)
                        {
                            EveDecaissement decaissement = new EveDecaissement
                            {
                                DateDecaissement    = dtpDateOperation.Value.Date,
                                Description         = txtDescription.Text,
                                Montant             = int.Parse(txtMontant.Text),
                                DecaissementInterne = true,
                                CodeEmploye         = codeEmploye,
                                CodeCompte          = codeCpteDebiteur
                            };

                            db.EveDecaissements.Add(decaissement);
                            db.SaveChanges();

                            EveEncaissement encaissement = new EveEncaissement
                            {
                                CodeCompte  = codeCpteCrediteur,
                                CodeEmploye = codeEmploye,
                            };

                            db.EveEncaissements.Add(encaissement);
                            db.SaveChanges();

                            EveEncaissementsAutre autreEnc = new EveEncaissementsAutre
                            {
                                CodeEncaissement = encaissement.CodeEncaissement,
                                DateEncaissement = dtpDateOperation.Value.Date,
                                Description      = txtDescription.Text,
                                MontantEncaisse  = int.Parse(txtMontant.Text)
                            };

                            db.EveEncaissementsAutres.Add(autreEnc);
                            db.SaveChanges();

                            var cpteDebiteur  = cbxCompteDebit.GetItemText(cbxCompteDebit.SelectedText);
                            var cpteCrediteur = cbxCompteCredit.GetItemText(cbxCompteCredit.SelectedText);

                            MessageBox.Show($"Le transfert de fonds du compte {cpteDebiteur} au compte {cpteCrediteur} a été enregistré avec succès.");
                            txtDescription.Clear();
                            txtMontant.Clear();

                            Tresorerie.AfficherSoldeTresorerie(cbxCompteDebit, txtSoldeCompte);
                        }
                        else
                        {
                            MessageBox.Show("Veuillez ajouter une description à ce mouvement de compte à compte.");
                            return;
                        }
                    }
                }
            }
        }
        /********************************************
         * HELPERS
         *********************************************/

        private void MettreTransactionAJour()
        {
            using (CasaDBEntities db = new CasaDBEntities())
            {
                try
                {
                    var  transaction   = db.EveAcquisitionServicesFournitures.Where(afs => afs.CodeAcquisitionServiceFourniture == _codeTransaction).FirstOrDefault();
                    bool montantValide = Validation.QuantiteSuperieurAZero(Conversion.EnleverEspaces(txtMontantServFourn.Text));

                    // La date a changé
                    if (transaction.Date != dtpDateAchatServFourn.Value)
                    {
                        transaction.Date = dtpDateAchatServFourn.Value.Date;
                    }

                    // Le fournisseur a changé
                    if (cbxNomFournServFourn.Text != transaction.AgeFournisseursServicesFourniture.NomFournisseurServiceFourniture)
                    {
                        transaction.CodeFournisseurServiceFourniture = int.Parse(cbxNomFournServFourn.SelectedValue.ToString());
                    }

                    // Le nom du service/fourniture a changé
                    if (cbxNomServFourniture.Text != transaction.ResServicesFourniture.NomServiceFourniture)
                    {
                        transaction.CodeServiceFourniture = int.Parse(cbxNomServFourniture.SelectedValue.ToString());
                    }
                    // La description a changé

                    if (!string.IsNullOrEmpty(txtDescription.Text) && transaction.Description != txtDescription.Text)
                    {
                        transaction.Description = txtDescription.Text;
                    }

                    // Le montant de la transaction a changé
                    if (transaction.Montant.ToString() != Conversion.EnleverEspaces(txtMontantServFourn.Text))
                    {
                        transaction.Montant = decimal.Parse(Conversion.EnleverEspaces(txtMontantServFourn.Text));
                    }

                    int codeFournisseur = transaction.AgeFournisseursServicesFourniture.CodeFournisseurServiceFourniture;
                    var decaissement    = transaction.EveDecaissements.Where(f => f.CodeFournisseurService == codeFournisseur).FirstOrDefault();

                    // S'Il y'avait un décaissement au moment de l'enregistrement de la transaction
                    if (decaissement != null)
                    {
                        int.TryParse(Conversion.EnleverEspaces(txtMontantPayeServFourn.Text), out int montantPaye);
                        int.TryParse(cbxComptePaiement.SelectedValue.ToString(), out int codeCompte);

                        // Le montant payé a changé
                        if (decaissement.Montant != montantPaye)
                        {
                            decaissement.Montant = montantPaye;
                        }

                        // Le compte de trésorerie utilisé pour le paiment a changé
                        if (decaissement.CodeCompte != codeCompte)
                        {
                            decaissement.CodeCompte = codeCompte;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(txtMontantPayeServFourn.Text))
                        {
                            int.TryParse(Conversion.EnleverEspaces(txtMontantPayeServFourn.Text), out int montantPaye);
                            int.TryParse(cbxComptePaiement.SelectedValue.ToString(), out int codeCompte);
                            int codeTresoriere = int.Parse(cbxTresorieres.SelectedValue.ToString());

                            var newDecaissement = new EveDecaissement
                            {
                                CodeAcquisitionServiceFourniture = transaction.CodeAcquisitionServiceFourniture,
                                Montant                = montantPaye,
                                CodeCompte             = codeCompte,
                                CodeFournisseurService = transaction.CodeFournisseurServiceFourniture,
                                CodeEmploye            = codeTresoriere,
                                Description            = txtDescription.Text
                            };

                            db.EveDecaissements.Add(newDecaissement);
                        }
                    }

                    db.SaveChanges();
                    MessageBox.Show("La transaction a été mise à jour.");
                }
                catch (Exception)
                {
                    MessageBox.Show("Erreur: La transaction n'a pas été mise à jour.");
                }
            }
        }
예제 #5
0
        private void MettreTransactionAJour()
        {
            using (CasaDBEntities db = new CasaDBEntities())
            {
                try
                {
                    var  transaction    = db.EveReceptionMatieresPremieres.Where(rmp => rmp.CodeReceptionMatierePremiere == _codeTransaction).FirstOrDefault();
                    bool montantValide  = Validation.QuantiteSuperieurAZero(Conversion.EnleverEspaces(txtMontantAchat.Text));
                    bool quantiteValide = Validation.QuantiteSuperieurAZero(Conversion.EnleverEspaces(txtQuantite.Text));

                    // La date a changé
                    if (transaction.DateReception != dtpDateApprovisionnement.Value)
                    {
                        transaction.DateReception = dtpDateApprovisionnement.Value.Date;
                    }

                    // Le fournisseur a changé
                    if (cbxFournisseurMPrem.Text != transaction.AgeFournisseursMatieresPremiere.Nom)
                    {
                        transaction.CodeFournisseurMatierePremiere = int.Parse(cbxFournisseurMPrem.SelectedValue.ToString());
                    }

                    // Le nom de la matière première, de l'emballage ou de l'étiquette a changé
                    if (cbxNomMatierePremiere.Text != transaction.ResStockMatieresPremiere.NomMatiere)
                    {
                        transaction.CodeMatierePremiere = int.Parse(cbxNomMatierePremiere.SelectedValue.ToString());
                    }
                    // La quantité a changé

                    if (int.Parse(transaction.Quantite.ToString()) != int.Parse(Conversion.EnleverEspaces(txtQuantite.Text)))
                    {
                        transaction.Quantite = int.Parse(Conversion.EnleverEspaces(txtQuantite.Text));
                    }

                    // Le montant de la transaction a changé
                    if (decimal.Parse(transaction.Montant.ToString()) != decimal.Parse(Conversion.EnleverEspaces(txtMontantAchat.Text)))
                    {
                        transaction.Montant = decimal.Parse(Conversion.EnleverEspaces(txtMontantAchat.Text));
                    }

                    // Le montant du transport a changé
                    if (decimal.Parse(transaction.TransportMatierePremiere.ToString()) != decimal.Parse(Conversion.EnleverEspaces(txtTransportMatierePremiere.Text)))
                    {
                        transaction.TransportMatierePremiere = decimal.Parse(Conversion.EnleverEspaces(txtTransportMatierePremiere.Text));
                    }

                    int codeFournisseur = transaction.AgeFournisseursMatieresPremiere.CodeFournisseurMatierePremiere;
                    var decaissement    = transaction.EveDecaissements.Where(f => f.CodeFournisseurMatierePremiere == codeFournisseur).FirstOrDefault();

                    // S'Il y'avait un décaissement au moment de l'enregistrement de la transaction
                    if (decaissement != null)
                    {
                        int.TryParse(Conversion.EnleverEspaces(txtMontantPaye.Text), out int montantPaye);
                        int.TryParse(cbxComptePaiement.SelectedValue.ToString(), out int codeCompte);

                        // Le montant payé a changé
                        if (decaissement.Montant != montantPaye)
                        {
                            decaissement.Montant = montantPaye;
                        }

                        // Le compte de trésorerie utilisé pour le paiment a changé
                        if (decaissement.CodeCompte != codeCompte)
                        {
                            decaissement.CodeCompte = codeCompte;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(txtMontantPaye.Text))
                        {
                            int.TryParse(Conversion.EnleverEspaces(txtMontantPaye.Text), out int montantPaye);
                            int.TryParse(cbxComptePaiement.SelectedValue.ToString(), out int codeCompte);
                            int codeTresoriere = int.Parse(cbxTresoriere.SelectedValue.ToString());

                            var newDecaissement = new EveDecaissement
                            {
                                CodeReceptionMatierePremiere = transaction.CodeReceptionMatierePremiere,
                                Montant    = montantPaye,
                                CodeCompte = codeCompte,
                                CodeFournisseurMatierePremiere = transaction.CodeFournisseurMatierePremiere,
                                CodeEmploye = codeTresoriere,
                                Description = $"Achat de {transaction.ResStockMatieresPremiere.NomMatiere}"
                            };

                            db.EveDecaissements.Add(newDecaissement);
                        }
                    }

                    db.SaveChanges();
                    MessageBox.Show("La transaction a été mise à jour.");
                }
                catch (Exception)
                {
                    MessageBox.Show("Erreur: La transaction n'a pas été mise à jour.");
                }
            }
        }