Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransactorTransaction = await _context.TransactorTransactions.FindAsync(id);

            if (TransactorTransaction != null)
            {
                _context.TransactorTransactions.Remove(TransactorTransaction);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Manipulates Transactor transaction object based on finAction
        /// </summary>
        /// <param name="finAction"></param>
        /// <param name="transaction"></param>
        public static void TransactorFinAction(FinActionsEnum finAction, TransactorTransaction transaction)
        {
            switch (finAction)
            {
            case FinActionsEnum.FinActionsEnumNoChange:
                transaction.FinancialAction     = FinActionsEnum.FinActionsEnumNoChange;
                transaction.TransDiscountAmount = 0;
                transaction.TransFpaAmount      = 0;
                transaction.TransNetAmount      = 0;
                break;

            case FinActionsEnum.FinActionsEnumDebit:
                transaction.FinancialAction     = FinActionsEnum.FinActionsEnumDebit;
                transaction.TransDiscountAmount = transaction.AmountDiscount;
                transaction.TransFpaAmount      = transaction.AmountFpa;
                transaction.TransNetAmount      = transaction.AmountNet;
                break;

            case FinActionsEnum.FinActionsEnumCredit:
                transaction.FinancialAction     = FinActionsEnum.FinActionsEnumCredit;
                transaction.TransDiscountAmount = transaction.AmountDiscount;
                transaction.TransFpaAmount      = transaction.AmountFpa;
                transaction.TransNetAmount      = transaction.AmountNet;
                break;

            case FinActionsEnum.FinActionsEnumNegativeDebit:
                transaction.FinancialAction     = FinActionsEnum.FinActionsEnumNegativeDebit;
                transaction.TransDiscountAmount = transaction.AmountDiscount * -1;
                transaction.TransFpaAmount      = transaction.AmountFpa * -1;
                transaction.TransNetAmount      = transaction.AmountNet * -1;
                break;

            case FinActionsEnum.FinActionsEnumNegativeCredit:
                transaction.FinancialAction     = FinActionsEnum.FinActionsEnumNegativeCredit;
                transaction.TransDiscountAmount = transaction.AmountDiscount * -1;
                transaction.TransFpaAmount      = transaction.AmountFpa * -1;
                transaction.TransNetAmount      = transaction.AmountNet * -1;
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransactorTransaction = await _context.TransactorTransactions
                                    .Include(t => t.Company)
                                    .Include(t => t.FiscalPeriod)
                                    .Include(t => t.Section)
                                    .Include(t => t.TransTransactorDocSeries)
                                    .Include(t => t.TransTransactorDocType)
                                    .Include(t => t.Transactor).FirstOrDefaultAsync(m => m.Id == id);

            if (TransactorTransaction == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }

            #region Fiscal Period

            var fiscalPeriod = await HelperFunctions.GetFiscalPeriod(_context, ItemVm.TransDate);

            if (fiscalPeriod == null)
            {
                ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
                return(Page());
            }

            #endregion

            await using (var transaction = await _context.Database.BeginTransactionAsync())
            {
                #region transaction 1

                var docSeries1 = await
                                 _context.TransTransactorDocSeriesDefs.SingleOrDefaultAsync(m =>
                                                                                            m.Id == ItemVm.DocSeries1Id);

                if (docSeries1 is null)
                {
                    ModelState.AddModelError(string.Empty, "Δεν βρέθηκε η σειρά παραστατικού");
                    LoadCombos();
                    return(Page());
                }

                await _context.Entry(docSeries1).Reference(t => t.TransTransactorDocTypeDef).LoadAsync();

                var docTypeDef1 = docSeries1.TransTransactorDocTypeDef;
                await _context.Entry(docTypeDef1)
                .Reference(t => t.TransTransactorDef)
                .LoadAsync();

                var transTransactorDef1 = docTypeDef1.TransTransactorDef;

                #region Section Management

                int sectionId1 = 0;
                if (docTypeDef1.SectionId == 0)
                {
                    var sectn = await _context.Sections.SingleOrDefaultAsync(s => s.SystemName == _sectionCode);

                    if (sectn == null)
                    {
                        ModelState.AddModelError(string.Empty, "Δεν υπάρχει το Section");
                        LoadCombos();
                        return(Page());
                    }

                    sectionId1 = sectn.Id;
                }
                else
                {
                    sectionId1 = docTypeDef1.SectionId;
                }

                #endregion

                TransactorTransaction spTransaction1 = new TransactorTransaction
                {
                    TransDate    = ItemVm.TransDate,
                    TransactorId = ItemVm.Transactor1Id,
                    SectionId    = sectionId1,
                    TransTransactorDocSeriesId = docSeries1.Id,
                    TransTransactorDocTypeId   = docSeries1.TransTransactorDocTypeDefId,
                    FiscalPeriodId             = fiscalPeriod.Id,
                    CompanyId    = ItemVm.CompanyId,
                    Etiology     = ItemVm.Etiology,
                    AmountNet    = ItemVm.Amount,
                    TransRefCode = ItemVm.RefCode,

                    FinancialAction = transTransactorDef1.FinancialTransAction
                };
                ActionHandlers.TransactorFinAction(transTransactorDef1.FinancialTransAction, spTransaction1);

                #endregion

                #region transaction 2

                var docSeries2 = await
                                 _context.TransTransactorDocSeriesDefs.SingleOrDefaultAsync(m =>
                                                                                            m.Id == ItemVm.DocSeries2Id);

                if (docSeries2 is null)
                {
                    ModelState.AddModelError(string.Empty, "Δεν βρέθηκε η σειρά παραστατικού");
                    LoadCombos();
                    return(Page());
                }

                await _context.Entry(docSeries2).Reference(t => t.TransTransactorDocTypeDef).LoadAsync();

                var docTypeDef2 = docSeries2.TransTransactorDocTypeDef;
                await _context.Entry(docTypeDef2)
                .Reference(t => t.TransTransactorDef)
                .LoadAsync();

                var transTransactorDef2 = docTypeDef2.TransTransactorDef;

                #region Section Management

                int sectionId2 = 0;
                if (docTypeDef2.SectionId == 0)
                {
                    var sectn = await _context.Sections.SingleOrDefaultAsync(s => s.SystemName == _sectionCode);

                    if (sectn == null)
                    {
                        ModelState.AddModelError(string.Empty, "Δεν υπάρχει το Section");
                        LoadCombos();
                        return(Page());
                    }

                    sectionId2 = sectn.Id;
                }
                else
                {
                    sectionId2 = docTypeDef2.SectionId;
                }

                #endregion

                TransactorTransaction spTransaction2 = new TransactorTransaction
                {
                    TransDate    = ItemVm.TransDate,
                    TransactorId = ItemVm.Transactor2Id,
                    SectionId    = sectionId2,
                    TransTransactorDocSeriesId = docSeries2.Id,
                    TransTransactorDocTypeId   = docSeries2.TransTransactorDocTypeDefId,
                    FiscalPeriodId             = fiscalPeriod.Id,
                    CompanyId    = ItemVm.CompanyId,
                    Etiology     = ItemVm.Etiology,
                    AmountNet    = ItemVm.Amount,
                    TransRefCode = ItemVm.RefCode,

                    FinancialAction = transTransactorDef2.FinancialTransAction
                };
                ActionHandlers.TransactorFinAction(transTransactorDef2.FinancialTransAction, spTransaction2);

                #endregion

                try
                {
                    await _context.TransactorTransactions.AddAsync(spTransaction1);

                    await _context.TransactorTransactions.AddAsync(spTransaction2);

                    await _context.SaveChangesAsync();

                    await transaction.CommitAsync();
                }
                catch (Exception e)
                {
                    await transaction.RollbackAsync();

                    string msg = e.InnerException?.Message;
                    ModelState.AddModelError(string.Empty, msg);
                    LoadCombos();
                    return(Page());
                }
            }

            return(RedirectToPage("./Index"));
        }