Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }

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

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

            return(RedirectToPage("./Index2"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();

                toastNotification.AddSuccessToastMessage("Saved");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BuyDocTypeDefExists(BuyDocTypeDef.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            const string sectionCode = "SYS-SELL-COMBINED-SCN";

            if (id == null)
            {
                return(NotFound());
            }
            #region Section Management

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

            if (section == null)
            {
                return(NotFound(new
                {
                    error = "Could not locate section "
                }));
            }
            #endregion
            SaleDocument = await _context.SellDocuments.FindAsync(id);

            if (SaleDocument != null)
            {
                _context.SellDocLines.RemoveRange(_context.SellDocLines.Where(p => p.SellDocumentId == id));
                _context.TransactorTransactions.RemoveRange(_context.TransactorTransactions.Where(p => p.SectionId == section.Id && p.CreatorId == id));
                _context.WarehouseTransactions.RemoveRange(_context.WarehouseTransactions.Where(p => p.SectionId == section.Id && p.CreatorId == id));

                _context.SellDocuments.Remove(SaleDocument);

                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                _toastNotification.AddAlertToastMessage("Please see errors");
                return(Page());
            }

            var materialToAttach = _mapper.Map <WarehouseItem>(WarehouseItemVm);

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

            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("WarehouseItem changes saved");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MaterialExists(WarehouseItemVm.Id))
                {
                    _toastNotification.AddErrorToastMessage("WarehouseItem was not found");
                    return(NotFound());
                }
                else
                {
                    _toastNotification.AddErrorToastMessage("Concurency error");
                    throw;
                }
            }

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

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

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var transactorToAdd = _mapper.Map <Transactor>(ItemVm);

            _context.Attach(transactorToAdd).State = EntityState.Modified;
            //transactorToAdd.TransactorCompanyMappings.Clear();
            _context.TransactorCompanyMappings.RemoveRange(_context.TransactorCompanyMappings.Where(p => p.TransactorId == transactorToAdd.Id));

            if (!String.IsNullOrEmpty(ItemVm.SelectedCompanies))
            {
                var listOfCompanies = ItemVm.SelectedCompanies.Split(",");
                //bool fl = true;
                foreach (var listOfCompany in listOfCompanies)
                {
                    int.TryParse(listOfCompany, out var companyId);
                    if (companyId > 0)
                    {
                        transactorToAdd.TransactorCompanyMappings.Add(new TransactorCompanyMapping
                        {
                            CompanyId    = companyId,
                            TransactorId = transactorToAdd.Id
                        });
                        //TODO: remove when companyid column removed for transactor entity
                        //if (fl)
                        //{
                        //    transactorToAdd.CompanyId = companyId;
                        //    fl = false;
                        //}
                    }
                }
            }
            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("Modifications saved!");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactorExists(transactorToAdd.Id))
                {
                    return(NotFound());
                }
                else
                {
                    _toastNotification.AddErrorToastMessage("Not saved concurrency exception.");
                }
            }
            catch (Exception e)
            {
                _toastNotification.AddErrorToastMessage(e.Message);
            }

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

            _context.WrItemCodes.Add(ItemVm.MapToEntity());
            await _context.SaveChangesAsync();

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

            _context.TransactorTypes.Add(TransactorType);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.MeasureUnits.Add(MeasureUnit);
            await _context.SaveChangesAsync();

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

            _context.CrCatWarehouseItems.Add(ItemVm);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.FinancialMovements.Add(FinancialMovement);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.BuyDocSeriesDefs.Add(BuyDocSeriesDef);
            await _context.SaveChangesAsync();

            _toastNotification.AddInfoToastMessage("Saved");
            return(RedirectToPage("./Index"));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            var transactorToAdd = _mapper.Map <Transactor>(ItemVm);

            _context.Transactors.Add(transactorToAdd);

            if (!String.IsNullOrEmpty(ItemVm.SelectedCompanies))
            {
                var listOfCompanies = ItemVm.SelectedCompanies.Split(",");
                //bool fl = true;
                foreach (var listOfCompany in listOfCompanies)
                {
                    int companyId;
                    int.TryParse(listOfCompany, out companyId);
                    if (companyId > 0)
                    {
                        transactorToAdd.TransactorCompanyMappings.Add(new TransactorCompanyMapping
                        {
                            CompanyId    = companyId,
                            TransactorId = transactorToAdd.Id
                        });
                        //TODO: remove when companyid column removed for transactor entity
                        //if (fl)
                        //{
                        //    transactorToAdd.CompanyId = companyId;
                        //    fl = false;
                        //}
                    }
                }
            }

            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("Transactor saved!");
            }
            catch (Exception e)
            {
                _toastNotification.AddErrorToastMessage(e.Message);
                Console.WriteLine(e);
            }

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

            var diaryDef = _mapper.Map <DiaryDef>(ItemVm);

            _context.DiaryDefs.Add(diaryDef);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Transactor = await _context.Transactors.FindAsync(id);

            if (Transactor != null)
            {
                _context.Transactors.Remove(Transactor);

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException().GetType() == typeof(SqlException))
                    {
                        Int32 ErrorCode = ((SqlException)ex.InnerException).Number;
                        switch (ErrorCode)
                        {
                        case 2627:      // Unique constraint error
                            break;

                        case 547:       // Constraint check violation
                            _toastNotification.AddErrorToastMessage("Ο συν/νος έχει κινήσεις και δεν μπορεί να διαγραφεί");

                            break;

                        case 2601:      // Duplicated key row error
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        // handle normal exception
                        throw;
                    }
                }
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (id == 0)
            {
                return(NotFound());
            }

            WarehouseItemCode = await _context.WrItemCodes.FindAsync(id);

            if (WarehouseItemCode != null)
            {
                _context.WrItemCodes.Remove(WarehouseItemCode);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MaterialCategory = await _context.MaterialCategories.FindAsync(id);

            if (MaterialCategory != null)
            {
                _context.MaterialCategories.Remove(MaterialCategory);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FinancialMovement = await _context.FinancialMovements.FindAsync(id);

            if (FinancialMovement != null)
            {
                _context.FinancialMovements.Remove(FinancialMovement);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 19
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BuyDocTypeDef = await _context.BuyDocTypeDefs.FindAsync(id);

            if (BuyDocTypeDef != null)
            {
                _context.BuyDocTypeDefs.Remove(BuyDocTypeDef);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TransactorType = await _context.TransactorTypes.FindAsync(id);

            if (TransactorType != null)
            {
                _context.TransactorTypes.Remove(TransactorType);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                LoadCombos();
                return(Page());
            }

            var diaryTransactionToAttach = _mapper.Map <FinDiaryTransaction>(FinDiaryTransaction);

            diaryTransactionToAttach.Kind            = (int)DiaryTransactionsKindEnum.Expence;
            diaryTransactionToAttach.RevenueCentreId = 1;

            _context.FinDiaryTransactions.Add(diaryTransactionToAttach);
            await _context.SaveChangesAsync();

            _toastNotification.AddSuccessToastMessage("Saved!");
            return(RedirectToPage("./Index"));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var materialToAttach = _mapper.Map <WarehouseItem>(WarehouseItemVm);

            _context.WarehouseItems.Add(materialToAttach);
            try
            {
                await _context.SaveChangesAsync();

                _toastNotification.AddSuccessToastMessage("WarehouseItem Created");
                return(RedirectToPage("./Index"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _toastNotification.AddErrorToastMessage(e.Message);
                return(Page());
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            long   uploadedSize         = 0;
            string pathForUploadedFiles = _hostingEnvironment.WebRootPath + "\\productimages\\";
            var    uploadedFiles        = Request.Form.Files;

            int           iCounter       = 0;
            string        sFilesUploaded = "";
            List <string> listFiles      = new List <string>();

            foreach (var uploadedFile in uploadedFiles)
            {
                iCounter++;
                uploadedSize   += uploadedFile.Length;
                sFilesUploaded += "\n" + uploadedFile.FileName;
                listFiles.Add(uploadedFile.FileName);
                //< Filename >
                var    extension           = "." + uploadedFile.FileName.Split('.')[uploadedFile.FileName.Split('.').Length - 1];
                string uploadedFilename    = uploadedFile.FileName;
                string newFileName         = Guid.NewGuid() + extension;
                string newFilenameOnServer = pathForUploadedFiles + "\\" + newFileName;

                using (FileStream stream = new FileStream(newFilenameOnServer, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(stream);
                }

                MediaEntry.MediaFile        = newFileName;
                MediaEntry.OriginalFileName = uploadedFilename;
                _context.MediaEntries.Add(MediaEntry);
            }
            //return new JsonResult(listFiles);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 24
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"));
        }
Exemplo n.º 25
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"));
        }
Exemplo n.º 26
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"));
        }