public FinancialTransaction BuildSupplierFirstEntryRequestObject(cor_paymentterms request, inv_invoice invoice)
        {
            cor_suppliertype suppliertype = new cor_suppliertype();
            var lpo            = _repo.GetLPOsAsync(request.LPOId).Result;
            var supplierDetail = _suprepo.GetSupplierAsync(lpo.WinnerSupplierId).Result;

            if (supplierDetail != null)
            {
                suppliertype = _suprepo.GetSupplierTypeAsync(supplierDetail.SupplierTypeId).Result;
            }
            return(new FinancialTransaction
            {
                Amount = request.NetAmount,
                ApprovedBy = "staff",
                ApprovedDate = DateTime.Now,
                CompanyId = lpo.CompanyId,
                CreditGL = suppliertype.CreditGL,
                DebitGL = suppliertype.DebitGL,
                CurrencyId = 0,
                ReferenceNo = invoice.InvoiceNumber,
                Description = $"Proposal Phase {request.Phase}",
                OperationId = (int)OperationsEnum.PaymentApproval,
                TransactionDate = DateTime.Now,
            });
        }
        public async Task <bool> DeleteSupplierTypeAsync(cor_suppliertype model)
        {
            var itemToDelete = await _dataContext.cor_suppliertype.FindAsync(model.SupplierTypeId);

            if (itemToDelete != null)
            {
                _dataContext.cor_suppliertype.Remove(itemToDelete);
            }
            return(await _dataContext.SaveChangesAsync() > 0);
        }
        public async Task <SuppliertypeRegRespObj> Handle(AddUpdateSuppliertypeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var user = await _serverRequest.UserDataAsync();

                cor_suppliertype sup = new cor_suppliertype();
                sup.Deleted          = true;
                sup.CreatedOn        = request.SupplierTypeId > 0 ? (DateTime?)null : DateTime.Now;
                sup.CreatedBy        = user.UserName;
                sup.UpdatedBy        = user.UserName;
                sup.SupplierTypeName = request.SupplierTypeName;
                sup.TaxApplicable    = string.Join(',', request.TaxApplicable);
                sup.CreditGL         = request.CreditGL;
                sup.DebitGL          = request.DebitGL;
                sup.Deleted          = false;
                sup.SupplierTypeId   = request.SupplierTypeId > 0 ? request.SupplierTypeId : 0;
                await _supRepo.AddUpdateSupplierTypeAsync(sup);

                var actionTaken = request.SupplierTypeId < 1 ? "created" : "updated";
                return(new SuppliertypeRegRespObj
                {
                    SuppliertypeId = sup.SupplierTypeId,
                    Status = new APIResponseStatus
                    {
                        IsSuccessful = true,
                        Message = new APIResponseMessage
                        {
                            FriendlyMessage = $"Successfully  {actionTaken}",
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                #region Log error to file
                var errorCode = ErrorID.Generate(4);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new SuppliertypeRegRespObj
                {
                    Status = new APIResponseStatus
                    {
                        IsSuccessful = false,
                        Message = new APIResponseMessage
                        {
                            FriendlyMessage = "Error occured!! Unable to process request",
                            MessageId = errorCode,
                            TechnicalMessage = $"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"
                        }
                    }
                });

                #endregion
            }
        }
        public async Task <bool> AddUpdateSupplierTypeAsync(cor_suppliertype model)
        {
            if (model.SupplierTypeId > 0)
            {
                var itemToEdit = await _dataContext.cor_suppliertype.FindAsync(model.SupplierTypeId);

                _dataContext.Entry(itemToEdit).CurrentValues.SetValues(model);
            }
            else
            {
                await _dataContext.cor_suppliertype.AddAsync(model);
            }
            return(await _dataContext.SaveChangesAsync() > 0);
        }
        public List <FinancialTransaction> BuildTaxEntryRequestObject(inv_invoice invoice)
        {
            var supplierType = new cor_suppliertype();
            List <cor_taxsetup>         tx  = new List <cor_taxsetup>();
            List <FinancialTransaction> fts = new List <FinancialTransaction>();
            var supplierDetail = _suprepo.GetSupplierAsync(invoice.SupplierId).Result;

            if (supplierDetail != null)
            {
                var phase = _dataContext.cor_paymentterms.FirstOrDefault(d => d.PaymentTermId == invoice.PaymentTermId);
                var lpo   = _dataContext.purch_plpo.FirstOrDefault(r => r.PLPOId == phase.LPOId);
                supplierType = _dataContext.cor_suppliertype.FirstOrDefault(rt => rt.SupplierTypeId == supplierDetail.SupplierTypeId);
                if (!string.IsNullOrEmpty(lpo.Taxes))
                {
                    var applicableTax = lpo.Taxes.Split(',').Select(int.Parse).ToList();
                    tx = _dataContext.cor_taxsetup.Where(q => applicableTax.Contains(q.TaxSetupId)).ToList();
                }
            }
            if (tx.Count() > 0)
            {
                var banks        = _financeServer.GetAllBanksAsync().Result;
                var creditGl     = banks.bank.FirstOrDefault(q => q.BankGlId == invoice.PaymentBankId).SubGl;
                var currentPhase = _dataContext.cor_paymentterms.FirstOrDefault(q => q.PaymentTermId == invoice.PaymentTermId);
                foreach (var tax in tx)
                {
                    var entryobj = new FinancialTransaction
                    {
                        Amount          = currentPhase.Amount / 100 * Convert.ToDecimal(tax.Percentage),
                        ApprovedBy      = "staff",
                        ApprovedDate    = DateTime.Now,
                        CompanyId       = invoice.CompanyId,
                        CreditGL        = tax.SubGL,
                        DebitGL         = supplierType.CreditGL,
                        CurrencyId      = 0,
                        ReferenceNo     = invoice.InvoiceNumber,
                        Description     = $"Invoice {invoice.InvoiceNumber} {tax.TaxName} Tax",
                        OperationId     = (int)OperationsEnum.PaymentApproval,
                        TransactionDate = DateTime.Now,
                    };
                    fts.Add(entryobj);
                }
                return(fts);
            }
            return(new List <FinancialTransaction>());
        }
Ejemplo n.º 6
0
            public async Task <FileUploadRespObj> Handle(UploadSupplierTypeCommand request, CancellationToken cancellationToken)
            {
                try
                {
                    var apiResponse = new FileUploadRespObj {
                        Status = new APIResponseStatus {
                            IsSuccessful = false, Message = new APIResponseMessage()
                        }
                    };

                    var files = _accessor.HttpContext.Request.Form.Files;

                    var byteList = new List <byte[]>();
                    foreach (var fileBit in files)
                    {
                        if (fileBit.Length > 0)
                        {
                            using (var ms = new MemoryStream())
                            {
                                await fileBit.CopyToAsync(ms);

                                byteList.Add(ms.ToArray());
                            }
                        }
                    }
                    var user = await _serverRequest.UserDataAsync();

                    var uploadedRecord = new List <SupplierTypeObj>();
                    ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

                    if (byteList.Count() > 0)
                    {
                        foreach (var byteItem in byteList)
                        {
                            using (MemoryStream stream = new MemoryStream(byteItem))
                                using (ExcelPackage excelPackage = new ExcelPackage(stream))
                                {
                                    ExcelWorksheet workSheet    = excelPackage.Workbook.Worksheets[0];
                                    int            totalRows    = workSheet.Dimension.Rows;
                                    int            totalColumns = workSheet.Dimension.Columns;

                                    if (totalColumns != 2)
                                    {
                                        apiResponse.Status.Message.FriendlyMessage = "2 Columns Expected";
                                        return(apiResponse);
                                    }

                                    for (int i = 2; i <= totalRows; i++)
                                    {
                                        var item = new SupplierTypeObj
                                        {
                                            ExcelLineNumber   = i,
                                            SupplierTypeName  = workSheet.Cells[i, 1]?.Value != null ? workSheet.Cells[i, 1]?.Value.ToString() : string.Empty,
                                            TaxApplicableName = workSheet.Cells[i, 2]?.Value != null ? workSheet.Cells[i, 2]?.Value.ToString() : string.Empty,
                                        };
                                        uploadedRecord.Add(item);
                                    }
                                }
                        }
                    }


                    var ItemList = await _repo.GetAllSupplierTypeAsync();

                    var TaxList = await _repo.GetAllTaxSetupAsync();

                    if (uploadedRecord.Count > 0)
                    {
                        var listOftaxt = new List <int>();

                        foreach (var item in uploadedRecord)
                        {
                            if (string.IsNullOrEmpty(item.TaxApplicableName))
                            {
                                apiResponse.Status.Message.FriendlyMessage = $"No Tax Applicable found Detected on line {item.ExcelLineNumber}";
                                return(apiResponse);
                            }
                            else
                            {
                                var taxNames = item.TaxApplicableName.Trim().ToLower().Split(',');
                                foreach (var tx in taxNames)
                                {
                                    var taxes = TaxList.FirstOrDefault(a => taxNames.Contains(a.TaxName.Trim().ToLower()));
                                    if (taxes == null)
                                    {
                                        apiResponse.Status.Message.FriendlyMessage = $"Unidentified Tax name Detected on line {item.ExcelLineNumber}";
                                        return(apiResponse);
                                    }
                                    listOftaxt.Add(taxes.TaxSetupId);
                                }
                            }
                            if (string.IsNullOrEmpty(item.SupplierTypeName))
                            {
                                apiResponse.Status.Message.FriendlyMessage = $"Empty Supplier Type Name Detected on line {item.ExcelLineNumber}";
                                return(apiResponse);
                            }

                            var itemFrmRepo = ItemList.FirstOrDefault(c => c.SupplierTypeName.ToLower().Trim() == item.SupplierTypeName.ToLower().Trim());

                            if (itemFrmRepo != null)
                            {
                                itemFrmRepo.SupplierTypeName = item?.SupplierTypeName;
                                itemFrmRepo.TaxApplicable    = string.Join(',', listOftaxt);
                                await _repo.AddUpdateSupplierTypeAsync(itemFrmRepo);
                            }
                            else
                            {
                                var newItem = new cor_suppliertype
                                {
                                    SupplierTypeName = item?.SupplierTypeName,
                                    TaxApplicable    = string.Join(',', listOftaxt),
                                };
                                await _repo.AddUpdateSupplierTypeAsync(newItem);
                            }
                        }
                    }
                    apiResponse.Status.IsSuccessful            = true;
                    apiResponse.Status.Message.FriendlyMessage = "Successful";
                    return(apiResponse);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }