public TblTaxStructure Update(TblTaxStructure taxstructure) { try { using Repository <TblTaxStructure> repo = new Repository <TblTaxStructure>(); var data = repo.TblTaxGroup.Where(x => x.TaxGroupName == taxstructure.TaxGroupName).FirstOrDefault(); // string code = Convert.ToString(repo.TblTaxGroup.SingleOrDefault(obj => obj.TaxGroupName == Convert.ToString(taxstructure.TaxGroupName))?.TaxGroupCode); if (data != null) { taxstructure.TaxGroupCode = data.TaxGroupCode; taxstructure.TaxGroupId = data.TaxGroupId; repo.TblTaxStructure.Update(taxstructure); if (repo.SaveChanges() > 0) { return(taxstructure); } } return(null); } catch (Exception ex) { throw ex; } }
public IActionResult RegisterTaxStructure([FromBody] TblTaxStructure taxstructure) { if (taxstructure == null) { return(Ok(new APIResponse() { status = APIStatus.PASS.ToString(), response = "object can not be null" })); } try { //var taxstructurelist = new TaxgroupHelpers().GetList(taxstructure.TaxGroupCode); //if (taxstructurelist.Count() > 0) // return Ok(new APIResponse() { status = APIStatus.PASS.ToString(), response = $"productpacking Code {nameof(taxstructurelist)} is already exists ,Please Use Different Code " }); var result = new TaxstructureHelpers().Register(taxstructure); APIResponse apiResponse; if (result != null) { apiResponse = new APIResponse() { status = APIStatus.PASS.ToString(), response = result }; } else { apiResponse = new APIResponse() { status = APIStatus.FAIL.ToString(), response = "Registration Failed." }; } return(Ok(apiResponse)); } catch (Exception ex) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = ex.Message })); } }
public IActionResult UpdateTaxStructure([FromBody] TblTaxStructure taxstructure) { if (taxstructure == null) { return(Ok(new APIResponse { status = APIStatus.FAIL.ToString(), response = $"{nameof(taxstructure)} cannot be null" })); } try { var rs = new TaxstructureHelpers().Update(taxstructure); APIResponse apiResponse; if (rs != null) { apiResponse = new APIResponse() { status = APIStatus.PASS.ToString(), response = rs }; } else { apiResponse = new APIResponse() { status = APIStatus.FAIL.ToString(), response = "Updation Failed." }; } return(Ok(apiResponse)); } catch (Exception ex) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = ex.Message })); } }
public bool AddPurchaseRecords(TblPurchaseInvoice purchaseInvoice, List <TblPurchaseInvoiceDetail> purchaseInvoiceDetails) { try { using (ERPContext context = new ERPContext()) { using (var dbTransaction = context.Database.BeginTransaction()) { try { decimal shifId = Convert.ToDecimal(new UserManagmentHelper().GetShiftId(purchaseInvoice.UserId, null)); TblProduct _product = null; TblTaxStructure _taxStructure = null; //add voucher typedetails var _branch = GetBranches(purchaseInvoice.BranchCode).FirstOrDefault(); var _accountLedger = GetAccountLedgers(purchaseInvoice.LedgerCode).FirstOrDefault(); var _vouchertType = GetVoucherType(13).FirstOrDefault(); #region Add voucher master record var _voucherMaster = AddVoucherMaster(context, purchaseInvoice, _branch, _vouchertType.VoucherTypeId, _accountLedger.CrOrDr); #endregion purchaseInvoice.ShiftId = shifId; purchaseInvoice.VoucherNo = _voucherMaster.VoucherMasterId.ToString(); purchaseInvoice.VoucherTypeId = 13; purchaseInvoice.ServerDateTime = DateTime.Now; context.TblPurchaseInvoice.Add(purchaseInvoice); context.SaveChanges(); foreach (var purInv in purchaseInvoiceDetails) { _product = GetProducts(purInv.ProductCode).FirstOrDefault(); _taxStructure = GetTaxStructure(Convert.ToDecimal(_product.TaxStructureId)); _accountLedger = GetAccountLedgersByLedgerId((decimal)_taxStructure.PurchaseAccount).FirstOrDefault(); #region Add voucher Details var _voucherDetail = AddVoucherDetails(context, purchaseInvoice, _branch, _voucherMaster, _accountLedger, purInv.Rate); #endregion #region InvioceDetail purInv.PurchaseInvId = purchaseInvoice.PurchaseInvId; purInv.VoucherNo = purchaseInvoice.VoucherNo; purInv.PurchaseNo = purchaseInvoice.PurchaseInvNo; purInv.StateCode = purchaseInvoice.StateCode; purInv.ShiftId = purchaseInvoice.ShiftId; purInv.UserId = purchaseInvoice.UserId; purInv.EmployeeId = -1; purInv.ServerDateTime = DateTime.Now; purInv.ShiftId = shifId; context.TblPurchaseInvoiceDetail.Add(purInv); context.SaveChanges(); #endregion #region Add stock transaction and Account Ledger Transaction AddStockInformation(context, purchaseInvoice, _branch, _product, purInv.Qty > 0 ? purInv.Qty : purInv.FQty, purInv.Rate); AddAccountLedgerTransactions(context, _voucherDetail, purchaseInvoice.PurchaseInvDate); #endregion } _accountLedger = GetAccountLedgers(purchaseInvoice.LedgerCode).FirstOrDefault(); AddVoucherDetails(context, purchaseInvoice, _branch, _voucherMaster, _accountLedger, purchaseInvoice.GrandTotal, false); //CHech weather igs or sg ,cg st var _stateWiseGsts = GetStateWiseGsts(purchaseInvoice.StateCode).FirstOrDefault(); if (_stateWiseGsts.Igst == 1) { //Add IGST record var _accAL = GetAccountLedgers("243").ToArray().FirstOrDefault(); AddVoucherDetails(context, purchaseInvoice, _branch, _voucherMaster, _accAL, purchaseInvoice.TotalAmount, false); } else { // sgst var _accAL = GetAccountLedgers("240").ToArray().FirstOrDefault(); AddVoucherDetails(context, purchaseInvoice, _branch, _voucherMaster, _accAL, purchaseInvoice.TotalAmount, false); // sgst _accAL = GetAccountLedgers("241").ToArray().FirstOrDefault(); AddVoucherDetails(context, purchaseInvoice, _branch, _voucherMaster, _accAL, purchaseInvoice.TotalAmount, false); } dbTransaction.Commit(); return(true); } catch (Exception e) { dbTransaction.Rollback(); throw e; } } } } catch (Exception ex) { throw ex; } }
/************************* Helper methods For invoice*******************************************/ public bool RegisterBill(TblInvoiceMaster invoice, List <TblInvoiceDetail> invoiceDetails) { try { decimal shifId = Convert.ToDecimal(new UserManagmentHelper().GetShiftId(invoice.UserId, null)); invoice.IsSalesReturned = false; invoice.IsManualEntry = false; TblTaxStructure _taxStructure = null; TblProduct _product = null; using (ERPContext repo = new ERPContext()) { using (var dbTransaction = repo.Database.BeginTransaction()) { try { //add voucher typedetails var _branch = GetBranches(invoice.BranchCode).ToArray().FirstOrDefault(); var _accountLedger = GetAccountLedgers(invoice.LedgerCode).ToArray().FirstOrDefault(); var _vouchertType = GetVoucherType(19).FirstOrDefault(); #region Add voucher master record var _voucherMaster = AddVoucherMaster(repo, invoice, _branch, _vouchertType.VoucherTypeId, _accountLedger.CrOrDr); #endregion invoice.LedgerId = _accountLedger.LedgerId; if (invoice.VehicleRegNo != null && invoice.MemberCode != null) { var vehicleId = GetVehicles(invoice.VehicleRegNo, Convert.ToString(invoice.MemberCode)).ToArray().FirstOrDefault(); invoice.VehicleId = vehicleId.VehicleId == null ? -1 : vehicleId.VehicleId; //vehicleId.VehicleId; } invoice.MemberCode = invoice.MemberCode == null?-1: invoice.MemberCode; invoice.ShiftId = shifId; invoice.VoucherNo = _voucherMaster.VoucherMasterId.ToString(); invoice.BranchName = _branch.BranchName; invoice.VoucherTypeId = 19; invoice.ServerDateTime = DateTime.Now; repo.TblInvoiceMaster.Add(invoice); repo.SaveChanges(); foreach (var invdtl in invoiceDetails) { _product = GetProducts(invdtl.ProductCode).FirstOrDefault(); _taxStructure = GetTaxStructure(Convert.ToDecimal(_product.TaxStructureCode)); _accountLedger = GetAccountLedgersByLedgerId((decimal)_taxStructure?.SalesAccount).FirstOrDefault(); #region Add voucher Details var _voucherDetail = AddVoucherDetails(repo, invoice, _branch, _voucherMaster, _accountLedger, invdtl.Rate); #endregion #region InvioceDetail invdtl.InvoiceMasterId = invoice.InvoiceMasterId; invdtl.VoucherNo = invoice.VoucherNo; invdtl.InvoiceNo = invoice.InvoiceNo; invdtl.StateCode = invoice.StateCode; invdtl.ShiftId = invoice.ShiftId; invdtl.UserId = invoice.UserId; invdtl.EmployeeId = -1; invdtl.ServerDateTime = DateTime.Now; invdtl.ShiftId = shifId; invdtl.PumpId = invdtl.PumpId ?? -1; invdtl.PumpNo = invdtl.PumpNo ?? -1; invdtl.SlipNo = invdtl.SlipNo ?? -1; repo.TblInvoiceDetail.Add(invdtl); repo.SaveChanges(); #endregion #region Add stock transaction and Account Ledger Transaction AddStockInformation(repo, invoice, _branch, _product, invdtl.Qty > 0 ? invdtl.Qty : invdtl.FQty, invdtl.Rate); AddAccountLedgerTransactions(repo, _voucherDetail, invoice.InvoiceDate); #endregion } _accountLedger = GetAccountLedgers(invoice.LedgerCode).ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoice, _branch, _voucherMaster, _accountLedger, invoice.GrandTotal, false); //CHech weather igs or sg ,cg st var _stateWiseGsts = GetStateWiseGsts(invoice.StateCode).FirstOrDefault(); if (_stateWiseGsts.Igst == 1) { //Add IGST record var _accAL = GetAccountLedgers("243").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoice, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); } else { // sgst var _accAL = GetAccountLedgers("240").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoice, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); // sgst _accAL = GetAccountLedgers("241").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoice, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); } dbTransaction.Commit(); return(true); } catch (Exception ex) { dbTransaction.Rollback(); throw ex; } } } } catch (Exception ex) { throw ex; } }
public TblInvoiceMasterReturn RegisterInvoiceReturns(string invoiceReturnNo, decimal invoiceMasterId, out string errorMessage) { try { errorMessage = string.Empty; string _invoiceMasterDetailsjson = string.Empty; TblTaxStructure _taxStructure = null; TblProduct _product = null; TblInvoiceMasterReturn invoiceMasterReturn = null; List <TblInvoiceReturnDetail> invoiceReturnDetailList = null; TblInvoiceMaster invoice = GetInvoiceMaster(invoiceMasterId); List <TblInvoiceDetail> invoiceDetails = GetInvoiceDetail(invoiceMasterId); if (invoice.IsSalesReturned.Value) { errorMessage = $"Sales no:{invoice.InvoiceNo} is already return."; return(null); } invoice.IsSalesReturned = true; invoice.IsManualEntry = false; var _invoiceMasterjson = JsonConvert.SerializeObject(invoice); invoiceMasterReturn = (JsonConvert.DeserializeObject <TblInvoiceMasterReturn>(_invoiceMasterjson)); //details section invoiceReturnDetailList = new List <TblInvoiceReturnDetail>(); foreach (var invd in invoiceDetails) { _invoiceMasterDetailsjson = JsonConvert.SerializeObject(invd); invoiceReturnDetailList.Add(JsonConvert.DeserializeObject <TblInvoiceReturnDetail>(_invoiceMasterDetailsjson)); } using ERPContext repo = new ERPContext(); using var dbTransaction = repo.Database.BeginTransaction(); try { //update invoice master table; repo.TblInvoiceMaster.Update(invoice); repo.SaveChanges(); //add voucher typedetails var _invoiceHelper = new InvoiceHelper(); var _branch = _invoiceHelper.GetBranches(invoice.BranchCode).ToArray().FirstOrDefault(); var _accountLedger = _invoiceHelper.GetAccountLedgers(invoice.LedgerCode).ToArray().FirstOrDefault(); var _vouchertType = GetVoucherType(20).FirstOrDefault(); #region Add voucher master record invoiceMasterReturn.InvoiceReturnNo = invoiceReturnNo; var _voucherMaster = AddVoucherMaster(repo, invoiceMasterReturn, _branch, _vouchertType.VoucherTypeId, _accountLedger.CrOrDr); #endregion invoiceMasterReturn.VoucherNo = _voucherMaster.VoucherMasterId.ToString(); invoiceMasterReturn.InvoiceReturnDate = DateTime.Now; invoiceMasterReturn.ServerDateTime = DateTime.Now; repo.TblInvoiceMasterReturn.Add(invoiceMasterReturn); repo.SaveChanges(); foreach (var invdtl in invoiceReturnDetailList) { _product = _invoiceHelper.GetProducts(invdtl.ProductCode).FirstOrDefault(); _taxStructure = _invoiceHelper.GetTaxStructure(invdtl.TaxStructureId); _accountLedger = _invoiceHelper.GetAccountLedgersByLedgerId((decimal)_taxStructure.SalesAccount).FirstOrDefault(); #region Add voucher Details var _voucherDetail = AddVoucherDetails(repo, invoiceMasterReturn, _branch, _voucherMaster, _accountLedger, invdtl.Rate); #endregion #region InvioceDetail invdtl.InvoiceMasterReturnId = invoiceMasterReturn.InvoiceMasterReturnId; invdtl.InvoiceReturnNo = invoice.InvoiceNo; invdtl.InvoiceReturnDate = DateTime.Now; invdtl.VoucherNo = invoiceMasterReturn.VoucherNo; invdtl.StateCode = invoice.StateCode; invdtl.ShiftId = invoice.ShiftId; invdtl.UserId = invoice.UserId; invdtl.EmployeeId = -1; invdtl.ServerDateTime = DateTime.Now; repo.TblInvoiceReturnDetail.Add(invdtl); repo.SaveChanges(); #endregion #region Add stock transaction and Account Ledger Transaction AddStockInformation(repo, invoiceMasterReturn, _branch, _product, invdtl.Qty > 0 ? invdtl.Qty : invdtl.FQty, invdtl.Rate); AddAccountLedgerTransactions(repo, _voucherDetail, invoice.InvoiceDate); #endregion } _accountLedger = _invoiceHelper.GetAccountLedgers(invoice.LedgerCode).ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoiceMasterReturn, _branch, _voucherMaster, _accountLedger, invoice.GrandTotal, false); //CHech weather igs or sg ,cg st var _stateWiseGsts = _invoiceHelper.GetStateWiseGsts(invoice.StateCode).FirstOrDefault(); if (_stateWiseGsts.Igst == 1) { //Add IGST record var _accAL = _invoiceHelper.GetAccountLedgers("243").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoiceMasterReturn, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); } else { // sgst var _accAL = _invoiceHelper.GetAccountLedgers("240").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoiceMasterReturn, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); // sgst _accAL = _invoiceHelper.GetAccountLedgers("241").ToArray().FirstOrDefault(); AddVoucherDetails(repo, invoiceMasterReturn, _branch, _voucherMaster, _accAL, invoice.TotalAmount, false); } dbTransaction.Commit(); return(invoiceMasterReturn); } catch (Exception ex) { dbTransaction.Rollback(); throw ex; } } catch (Exception ex) { throw ex; } }