Beispiel #1
0
        public tbl_gnt_creditor ToEntity()
        {
            var db            = DDB.NewContext();
            var creditorsList = db.tbl_gnt_creditor.Where(x => x.gnt_creditor_id == this.gnt_creditor_id);

            if (creditorsList.Count() == 0)
            {
                throw HelperMethods.CreateException("سهامدار یافت نشد.");
            }
            if (creditorsList.Count() > 1)
            {
                throw HelperMethods.CreateException("چند سهامدار یافت شد.");
            }
            return(creditorsList.First());
        }
Beispiel #2
0
        public static void TransferCreditorAccountsToNewfiscalYear(int finePercent, long oldFiscalYearId, long newFiscalYearId)
        {
            try
            {
                var db             = DDB.NewContext();
                var fiscalYearList = db.tbl_glb_fiscal_year.Where(x => x.glb_fiscal_year_id == oldFiscalYearId);
                if (fiscalYearList.Count() == 0)
                {
                    Messages.ErrorMessage(string.Format("سال مبدا با شناسه {0} وجود ندارد", oldFiscalYearId));
                    return;
                }
                var oldFiscalYear = fiscalYearList.First();
                fiscalYearList = db.tbl_glb_fiscal_year.Where(x => x.glb_fiscal_year_id == newFiscalYearId);
                if (fiscalYearList.Count() == 0)
                {
                    Messages.ErrorMessage(string.Format("سال مقصد با شناسه {0} وجود ندارد", newFiscalYearId));
                    return;
                }
                var newFiscalYear = fiscalYearList.First();

                var creditors = db.tbl_gnt_creditor.ToList();
                foreach (var creditor in creditors)
                {
                    var oldOpening = db
                                     .tbl_gnt_creditor_account
                                     .Where
                                     (
                        x =>
                        x.gnt_creditor_account_gnt_creditor_id == creditor.gnt_creditor_id &&
                        x.gnt_creditor_account_glb_fiscal_year_id == newFiscalYear.glb_fiscal_year_id &&
                        x.gnt_creditor_account_is_opening == true
                                     )
                                     .ToList();

                    foreach (var opening in oldOpening)
                    {
                        db.tbl_gnt_creditor_account.DeleteObject(opening);
                    }

                    var creditorAccounts = db
                                           .tbl_gnt_creditor_account
                                           .Where
                                           (
                        x =>
                        x.gnt_creditor_account_gnt_creditor_id == creditor.gnt_creditor_id &&
                        x.gnt_creditor_account_glb_fiscal_year_id == oldFiscalYear.glb_fiscal_year_id
                                           )
                                           .ToList();


                    var sumDebt = creditorAccounts.Sum(x => x.gnt_creditor_account_debt)
                                  - creditorAccounts.Sum(x => x.gnt_creditor_account_credit);


                    var newAccount = new tbl_gnt_creditor_account()
                    {
                        gnt_creditor_account_date               = newFiscalYear.glb_fiscal_year_start_date,
                        gnt_creditor_account_credit             = 0,
                        gnt_creditor_account_glb_fiscal_year_id = newFiscalYearId,
                        gnt_creditor_account_gnt_creditor_id    = creditor.gnt_creditor_id,
                        gnt_creditor_account_gnt_service_id     = null,
                        gnt_creditor_account_is_public_cost     = false,
                        gnt_creditor_account_is_opening         = true
                    };
                    if (sumDebt >= 0)
                    {
                        newAccount.gnt_creditor_account_debt  = RoundPrice(sumDebt * (1 + (double)finePercent / 100));
                        newAccount.gnt_creditor_account_title = "مانده بدهی سال " + oldFiscalYear.glb_fiscal_year_name;
                    }
                    else
                    {
                        newAccount.gnt_creditor_account_credit = -sumDebt;
                        newAccount.gnt_creditor_account_title  = "مانده بستانکاری سال " + oldFiscalYear.glb_fiscal_year_name;
                    }
                    db.tbl_gnt_creditor_account.AddObject(newAccount);
                }
                db.SaveChanges();
            }
            catch (Exception exception)
            {
                while (exception.InnerException != null)
                {
                    exception = exception.InnerException;
                }
                throw new Exception("خطا در انتقال حساب سهامدران به سال جدید. متن خطا : \n" + exception.Message);
            }
        }
Beispiel #3
0
        public void UpdateAccountForPublicCosts()
        {
            try
            {
                SahaamEntities db         = DDB.NewContext();
                var            creditor   = db.tbl_gnt_creditor.First(x => x.gnt_creditor_id == this.gnt_creditor_id);
                var            fiscalYear = db.tbl_glb_fiscal_year.First(x => x.glb_fiscal_year_id == GlobalVariables.current_fiscal_year_id);

                var publicCosts = db.tbl_gnt_cost_type.Where
                                  (
                    x =>
                    x.gnt_cost_type_glb_fiscal_year_id == fiscalYear.glb_fiscal_year_id &&
                    x.gnt_cost_type_is_public == true
                                  ).ToList();

                if (publicCosts.Count == 0)
                {
                    throw new Exception("در دوره انتخاب شده هزینه عمومی تعریف نشده است");
                }

                var creditorAccounts =
                    db
                    .tbl_gnt_creditor_account
                    .Where
                    (
                        x =>
                        x.gnt_creditor_account_gnt_creditor_id == creditor.gnt_creditor_id &&
                        x.gnt_creditor_account_is_public_cost == true &&
                        x.gnt_creditor_account_glb_fiscal_year_id == fiscalYear.glb_fiscal_year_id
                    )
                    .ToList();

                foreach (var creditorAccount in creditorAccounts)
                {
                    db.tbl_gnt_creditor_account.DeleteObject(creditorAccount);
                }

                foreach (tbl_gnt_cost_type cost in publicCosts)
                {
                    creditor.tbl_gnt_creditor_account.Add(new tbl_gnt_creditor_account()
                    {
                        gnt_creditor_account_title              = cost.gnt_cost_type_name,
                        gnt_creditor_account_date               = fiscalYear.glb_fiscal_year_start_date.Replace("/", ""),
                        gnt_creditor_account_debt               = RoundPrice(cost.gnt_cost_type_price * creditor.gnt_creditor_sum_credit),
                        gnt_creditor_account_credit             = 0,
                        gnt_creditor_account_description        = "هزینه های عمومی سهامداران",
                        gnt_creditor_account_glb_fiscal_year_id = fiscalYear.glb_fiscal_year_id,
                        gnt_creditor_account_is_public_cost     = true
                    });
                }

                db.SaveChanges();
            }
            catch (Exception exception)
            {
                while (exception.InnerException != null)
                {
                    exception = exception.InnerException;
                }
                throw new Exception("خطا در اعمال هزینه های عمومی در حساب سهامدر. متن خطا : \n" + exception.Message);
            }
        }