示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }
            if (ItemVm.FiscalPeriodId <= 0)
            {
                ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
                LoadCombos();
                return(Page());
            }

            var transToAttach = _mapper.Map <WarehouseTransaction>(ItemVm);
            var docSeries     = await
                                _context.TransWarehouseDocSeriesDefs.SingleOrDefaultAsync(m =>
                                                                                          m.Id == ItemVm.TransWarehouseDocSeriesId);

            if (docSeries is null)
            {
                ModelState.AddModelError(string.Empty, "Δεν βρέθηκε η σειρά παραστατικού");
                LoadCombos();
                return(Page());
            }
            await _context.Entry(docSeries).Reference(t => t.TransWarehouseDocTypeDef).LoadAsync();

            var docTypeDef = docSeries.TransWarehouseDocTypeDef;
            await _context.Entry(docTypeDef)
            .Reference(t => t.TransWarehouseDef)
            .LoadAsync();

            var transWarehouseDef = docTypeDef.TransWarehouseDef;
            var section           = await _context.Sections.SingleOrDefaultAsync(s => s.SystemName == SectionSystemCode);

            if (section == null)
            {
                ModelState.AddModelError(string.Empty, "Δεν υπάρχει το Section");
                LoadCombos();
                return(Page());
            }
            transToAttach.SectionId = section.Id;
            transToAttach.TransWarehouseDocTypeId = docSeries.TransWarehouseDocTypeDefId;
            var material = await _context.WarehouseItems.SingleOrDefaultAsync(p => p.Id == transToAttach.WarehouseItemId);

            if (material is null)
            {
                ModelState.AddModelError(string.Empty, "Δεν βρέθηκε το είδος");
                LoadCombos();
                return(Page());
            }

            switch (material.WarehouseItemNature)
            {
            case WarehouseItemNatureEnum.WarehouseItemNatureUndefined:
                throw new ArgumentOutOfRangeException();

            case WarehouseItemNatureEnum.WarehouseItemNatureMaterial:
                transToAttach.InventoryAction      = transWarehouseDef.MaterialInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.MaterialInventoryValueAction;

                break;

            case WarehouseItemNatureEnum.WarehouseItemNatureService:
                transToAttach.InventoryAction      = transWarehouseDef.ServiceInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.ServiceInventoryValueAction;
                break;

            case WarehouseItemNatureEnum.WarehouseItemNatureExpense:
                transToAttach.InventoryAction      = transWarehouseDef.ExpenseInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.ExpenseInventoryValueAction;
                break;

            case WarehouseItemNatureEnum.WarehouseItemNatureIncome:
                transToAttach.InventoryAction      = transWarehouseDef.IncomeInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.IncomeInventoryValueAction;
                break;

            case WarehouseItemNatureEnum.WarehouseItemNatureFixedAsset:
                transToAttach.InventoryAction      = transWarehouseDef.FixedAssetInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.FixedAssetInventoryValueAction;
                break;

            case WarehouseItemNatureEnum.WarehouseItemNatureRawMaterial:
                transToAttach.InventoryAction      = transWarehouseDef.RawMaterialInventoryAction;
                transToAttach.InventoryValueAction = transWarehouseDef.RawMaterialInventoryValueAction;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (transToAttach.InventoryAction)
            {
            case InventoryActionEnum.InventoryActionEnumNoChange:
                transToAttach.TransactionType =
                    WarehouseTransactionTypeEnum.WarehouseTransactionTypeIgnore;
                transToAttach.TransQ1 = 0;
                transToAttach.TransQ2 = 0;
                break;

            case InventoryActionEnum.InventoryActionEnumImport:

                transToAttach.TransactionType =
                    WarehouseTransactionTypeEnum.WarehouseTransactionTypeImport;
                transToAttach.TransQ1 = (decimal)transToAttach.Quontity1;
                transToAttach.TransQ2 = (decimal)transToAttach.Quontity2;
                break;

            case InventoryActionEnum.InventoryActionEnumExport:

                transToAttach.TransactionType =
                    WarehouseTransactionTypeEnum.WarehouseTransactionTypeExport;
                transToAttach.TransQ1 = (decimal)transToAttach.Quontity1;
                transToAttach.TransQ2 = (decimal)transToAttach.Quontity2;
                break;

            case InventoryActionEnum.InventoryActionEnumNegativeImport:

                transToAttach.TransactionType =
                    WarehouseTransactionTypeEnum.WarehouseTransactionTypeImport;
                transToAttach.TransQ1 = (decimal)transToAttach.Quontity1 * -1;
                transToAttach.TransQ2 = (decimal)transToAttach.Quontity2 * -1;
                break;

            case InventoryActionEnum.InventoryActionEnumNegativeExport:

                transToAttach.TransactionType =
                    WarehouseTransactionTypeEnum.WarehouseTransactionTypeExport;
                transToAttach.TransQ1 = (decimal)transToAttach.Quontity1 * -1;
                transToAttach.TransQ2 = (decimal)transToAttach.Quontity2 * -1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }



            switch (transToAttach.InventoryValueAction)
            {
            case InventoryValueActionEnum.InventoryValueActionEnumNoChange:
                transToAttach.TransNetAmount      = 0;
                transToAttach.TransFpaAmount      = 0;
                transToAttach.TransDiscountAmount = 0;
                break;

            case InventoryValueActionEnum.InventoryValueActionEnumIncrease:
                transToAttach.TransNetAmount      = transToAttach.AmountNet;
                transToAttach.TransFpaAmount      = transToAttach.AmountFpa;
                transToAttach.TransDiscountAmount = transToAttach.AmountDiscount;
                break;

            case InventoryValueActionEnum.InventoryValueActionEnumDecrease:
                transToAttach.TransNetAmount      = transToAttach.AmountNet;
                transToAttach.TransFpaAmount      = transToAttach.AmountFpa;
                transToAttach.TransDiscountAmount = transToAttach.AmountDiscount;
                break;

            case InventoryValueActionEnum.InventoryValueActionEnumNegativeIncrease:
                transToAttach.TransNetAmount      = transToAttach.AmountNet * -1;
                transToAttach.TransFpaAmount      = transToAttach.AmountFpa * -1;
                transToAttach.TransDiscountAmount = transToAttach.AmountDiscount * -1;

                break;

            case InventoryValueActionEnum.InventoryValueActionEnumNegativeDecrease:
                transToAttach.TransNetAmount      = transToAttach.AmountNet * -1;
                transToAttach.TransFpaAmount      = transToAttach.AmountFpa * -1;
                transToAttach.TransDiscountAmount = transToAttach.AmountDiscount * -1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            _context.WarehouseTransactions.Add(transToAttach);

            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("Saved");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _toastNotification.AddErrorToastMessage(e.Message);
                LoadCombos();
                return(Page());
            }


            return(RedirectToPage("./Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }
            if (ItemVm.FiscalPeriodId <= 0)
            {
                ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
                LoadCombos();
                return(Page());
            }
            var spTransactionToAttach = _mapper.Map <TransactorTransaction>(ItemVm);

            #region Fiscal Period
            //var dateOfTrans = ItemVm.TransDate;
            //var fiscalPeriod = await _context.FiscalPeriods.FirstOrDefaultAsync(p =>
            //    p.StartDate.CompareTo(dateOfTrans) > 0 & p.EndDate.CompareTo(dateOfTrans) < 0);
            //if (fiscalPeriod == null)
            //{
            //    ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
            //    LoadCombos();
            //    return Page();
            //}
            #endregion
            var docSeries = _context.TransTransactorDocSeriesDefs.SingleOrDefault(m => m.Id == spTransactionToAttach.TransTransactorDocSeriesId);

            if (docSeries is null)
            {
                ModelState.AddModelError(string.Empty, "Δεν βρέθηκε η σειρά παραστατικού");
                LoadCombos();
                return(Page());
            }
            _context.Entry(docSeries).Reference(t => t.TransTransactorDocTypeDef).Load();

            var docTypeDef = docSeries.TransTransactorDocTypeDef;
            _context.Entry(docTypeDef)
            .Reference(t => t.TransTransactorDef)
            .Load();
            var transTransactorDef = docTypeDef.TransTransactorDef;


            //spTransaction.SectionId = section.Id;
            spTransactionToAttach.TransTransactorDocTypeId = docSeries.TransTransactorDocTypeDefId;
            spTransactionToAttach.FinancialAction          = transTransactorDef.FinancialTransAction;
            switch (transTransactorDef.FinancialTransAction)
            {
            case FinActionsEnum.FinActionsEnumNoChange:
                spTransactionToAttach.TransDiscountAmount = 0;
                spTransactionToAttach.TransFpaAmount      = 0;
                spTransactionToAttach.TransNetAmount      = 0;
                break;

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

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

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

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

            default:
                break;
            }


            _context.Attach(spTransactionToAttach).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactorTransactionExists(ItemVm.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //_context.TransactorTransactions.Add(TransactorTransaction);

            #region Fiscal Period
            //if (ItemVm.FiscalPeriodId <= 0)
            //{
            //    ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
            //    LoadCombos();
            //    return Page();
            //}
            var fiscalPeriod = await _context.FiscalPeriods.FirstOrDefaultAsync(p =>
                                                                                ItemVm.TransDate >= p.StartDate && ItemVm.TransDate <= p.EndDate);

            if (fiscalPeriod == null)
            {
                ModelState.AddModelError(string.Empty, "No Fiscal Period covers Transaction Date");
                return(Page());
            }
            #endregion
            var spTransaction = _mapper.Map <TransactorTransaction>(ItemVm);

            var docSeries = await
                            _context.TransTransactorDocSeriesDefs.SingleOrDefaultAsync(m =>
                                                                                       m.Id == ItemVm.TransTransactorDocSeriesId);

            if (docSeries is null)
            {
                ModelState.AddModelError(string.Empty, "Δεν βρέθηκε η σειρά παραστατικού");
                LoadCombos();
                return(Page());
            }
            await _context.Entry(docSeries).Reference(t => t.TransTransactorDocTypeDef).LoadAsync();

            var docTypeDef = docSeries.TransTransactorDocTypeDef;
            await _context.Entry(docTypeDef)
            .Reference(t => t.TransTransactorDef)
            .LoadAsync();

            var transTransactorDef = docTypeDef.TransTransactorDef;


            var section = await _context.Sections.SingleOrDefaultAsync(s => s.SystemName == _sectionCode);

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

            spTransaction.SectionId = section.Id;
            spTransaction.TransTransactorDocTypeId = docSeries.TransTransactorDocTypeDefId;
            spTransaction.FiscalPeriodId           = fiscalPeriod.Id;
            spTransaction.FinancialAction          = transTransactorDef.FinancialTransAction;
            switch (transTransactorDef.FinancialTransAction)
            {
            case FinActionsEnum.FinActionsEnumNoChange:
                spTransaction.TransDiscountAmount = 0;
                spTransaction.TransFpaAmount      = 0;
                spTransaction.TransNetAmount      = 0;
                break;

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

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

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

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

            default:
                break;
            }


            _context.TransactorTransactions.Add(spTransaction);
            await _context.SaveChangesAsync();

            _toastNotification.AddSuccessToastMessage("Saved");



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