public async Task <ActionResult <CreditNoteModel> > Post(int invoiceId, CreditNoteModel model) { try { //Make sure CreditNoteId is not already taken var existing = await _repository.GetCreditNoteAsync(invoiceId, model.Id); if (existing != null) { return(BadRequest("CreditNote Id in Use")); } //map var CreditNote = _mapper.Map <CreditNote>(model); //save and return if (!await _repository.StoreNewCreditNoteAsync(invoiceId, CreditNote)) { return(BadRequest("Bad request, could not create record!")); } else { var location = _linkGenerator.GetPathByAction("Get", "CreditNote", new { invoiceId = CreditNote.InvoiceId, CreditNote.Id }); return(Created(location, _mapper.Map <CreditNoteModel>(CreditNote))); } } catch (Exception e) { _logger.LogError(e, e.Message); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
internal DataTable LoadPartyAccount(CreditNoteModel objCNModel) { try { ClsCon.cmd = new SqlCommand(); ClsCon.cmd.CommandType = CommandType.StoredProcedure; ClsCon.cmd.CommandText = "SPMasters"; ClsCon.cmd.Parameters.AddWithValue("@DataInd", objCNModel.Ind); ClsCon.cmd.Parameters.AddWithValue("@OrgID", objCNModel.OrgID); ClsCon.cmd.Parameters.AddWithValue("@BrID", objCNModel.BrID); ClsCon.cmd.Parameters.AddWithValue("@YrCD", objCNModel.YrCD); ClsCon.cmd.Parameters.AddWithValue("@VchType", objCNModel.VchType); con = ClsCon.SqlConn(); ClsCon.cmd.Connection = con; dtCreditNote = new DataTable(); ClsCon.da = new SqlDataAdapter(ClsCon.cmd); ClsCon.da.Fill(dtCreditNote); dtCreditNote.TableName = "success"; } catch (Exception) { dtCreditNote = new DataTable(); dtCreditNote.TableName = "error"; return(dtCreditNote); } finally { con.Close(); con.Dispose(); ClsCon.da.Dispose(); ClsCon.cmd.Dispose(); } return(dtCreditNote); }
private void btnUpdate_Click(object sender, EventArgs e) { CreditNoteModel objcredit = new CreditNoteModel(); if (tbxVoucherNumber.Text.Trim() == "") { MessageBox.Show("Voucher Number Can Not Be Blank!"); return; } objcredit.Voucher_Series = tbxVoucherSeries.Text.Trim() == null ? string.Empty : tbxVoucherSeries.Text.Trim(); objcredit.Voucher_Number = Convert.ToInt32(tbxVoucherNumber.Text.Trim()); objcredit.CN_Date = Convert.ToDateTime(dtDate.Text); objcredit.Type = tbxType.Text.Trim(); objcredit.PDCDate = Convert.ToDateTime(dtPDCDate.Text); objcredit.Narration = tbxLogNarration.Text.Trim(); objcredit.TotalCreditAmt = Convert.ToDecimal(colCredit.SummaryItem.SummaryValue); objcredit.TotalDebitAmt = Convert.ToDecimal(colDebit.SummaryItem.SummaryValue); //Credit Note Account details AccountModel objacc; List <AccountModel> lstAccounts = new List <AccountModel>(); for (int i = 0; i < gdvCredit.DataRowCount; i++) { DataRow row = gdvCredit.GetDataRow(i); objacc = new AccountModel(); objacc.DC = row["DC"].ToString(); objacc.Account = row["Account"].ToString() == null ? string.Empty : row["Account"].ToString(); objacc.LedgerId = objAccBL.GetLedgerIdByAccountName(row["Account"].ToString() == null ? string.Empty : row["Account"].ToString()); objacc.Debit = row["Debit"].ToString().Length > 0 ? Convert.ToDecimal(row["Debit"].ToString()) : 0; objacc.Credit = row["Credit"].ToString().Length > 0 ? Convert.ToDecimal(row["Credit"].ToString()) : 0; objacc.Narration = row["Narration"].ToString() == null ? string.Empty : row["Narration"].ToString(); objacc.AC_Id = row["AC_Id"].ToString().Length > 0 ? Convert.ToInt32(row["AC_Id"].ToString()) : 0; objacc.ParentId = row["ParentId"].ToString().Length > 0 ? Convert.ToInt32(row["ParentId"].ToString()) : 0; lstAccounts.Add(objacc); } objcredit.CreditAccountModel = lstAccounts; objcredit.CN_Id = CNId; bool isSuccess = objBl.UpdateCreditNote(objcredit); if (isSuccess) { MessageBox.Show("Update Successfully!"); CNId = 0; ClearControls(); Transaction.List.CreditNotesList frmList = new Transaction.List.CreditNotesList(); frmList.StartPosition = FormStartPosition.CenterScreen; frmList.ShowDialog(); FillCreditNote(); } }
public List <CreditNoteModel> GetCreditNotebyId(long id) { List <CreditNoteModel> lstCredit = new List <CreditNoteModel>(); CreditNoteModel objcredit; string Query = "SELECT * FROM Credit_Note_Master WHERE Credit_Id=" + id; System.Data.IDataReader dr = _dbHelper.ExecuteDataReader(Query, _dbHelper.GetConnObject()); while (dr.Read()) { objcredit = new CreditNoteModel(); objcredit.CN_Id = DataFormat.GetInteger(dr["CREDIT_ID"]); objcredit.Voucher_Series = dr["Series"].ToString(); objcredit.CN_Date = DataFormat.GetDateTime(dr["CN_Date"]); objcredit.Voucher_Number = DataFormat.GetInteger(dr["VoucherNo"]); objcredit.Narration = dr["LongNarration"].ToString(); objcredit.Type = dr["Type"].ToString(); if (dr["PDC_Date"].ToString() != "") { objcredit.PDCDate = Convert.ToDateTime(dr["PDC_Date"]); } //SELECT Credit Note Accounts string itemQuery = "SELECT * FROM Credit_Note_Details WHERE Credit_Id=" + objcredit.CN_Id; System.Data.IDataReader drAcc = _dbHelper.ExecuteDataReader(itemQuery, _dbHelper.GetConnObject()); objcredit.CreditAccountModel = new List <AccountModel>(); AccountModel objAcc; while (drAcc.Read()) { objAcc = new AccountModel(); objAcc.AC_Id = Convert.ToInt32(drAcc["AC_Id"]); objAcc.ParentId = DataFormat.GetInteger(drAcc["Credit_Id"]); objAcc.DC = drAcc["DC"].ToString(); objAcc.Account = drAcc["Account"].ToString(); objAcc.LedgerId = Convert.ToInt64(drAcc["LegderId"].ToString()); objAcc.Debit = Convert.ToDecimal(drAcc["Debit"]); objAcc.Credit = Convert.ToDecimal(drAcc["Credit"]); objAcc.Narration = drAcc["Narration"].ToString(); objcredit.CreditAccountModel.Add(objAcc); } lstCredit.Add(objcredit); } return(lstCredit); }
internal DataTable SaveCreditNote(CreditNoteModel objCNModel) { try { ClsCon.cmd = new SqlCommand(); ClsCon.cmd.CommandType = CommandType.StoredProcedure; ClsCon.cmd.CommandText = "SPCreditNote"; ClsCon.cmd.Parameters.AddWithValue("@Ind", objCNModel.Ind); ClsCon.cmd.Parameters.AddWithValue("@OrgID", objCNModel.OrgID); ClsCon.cmd.Parameters.AddWithValue("@BrID", objCNModel.BrID); ClsCon.cmd.Parameters.AddWithValue("@VchType", objCNModel.VchType); ClsCon.cmd.Parameters.AddWithValue("@DocDate", objCNModel.VoucherDate); ClsCon.cmd.Parameters.AddWithValue("@GSTOpted", objCNModel.GSTOpted); ClsCon.cmd.Parameters.AddWithValue("@DocDesc", objCNModel.DocDesc); ClsCon.cmd.Parameters.AddWithValue("@EntryType", objCNModel.EntryType); ClsCon.cmd.Parameters.AddWithValue("@User", objCNModel.User); ClsCon.cmd.Parameters.AddWithValue("@IP", objCNModel.IP); ClsCon.cmd.Parameters.AddWithValue("@YrCD", objCNModel.YrCD); ClsCon.cmd.Parameters.AddWithValue("@IssueReasonId", objCNModel.issueReasonId); ClsCon.cmd.Parameters.AddWithValue("@PreGstId", objCNModel.PreGstId); ClsCon.cmd.Parameters.AddWithValue("@CCCode", objCNModel.CCCode); ClsCon.cmd.Parameters.AddWithValue("@TblCredit", objCNModel.DtCreditNote); ClsCon.cmd.Parameters.AddWithValue("@TblItems", objCNModel.DtItems); con = ClsCon.SqlConn(); ClsCon.cmd.Connection = con; dtCreditNote = new DataTable(); ClsCon.da = new SqlDataAdapter(ClsCon.cmd); ClsCon.da.Fill(dtCreditNote); dtCreditNote.TableName = "success"; } catch (Exception) { dtCreditNote = new DataTable(); dtCreditNote.TableName = "error"; return(dtCreditNote); } finally { con.Close(); con.Dispose(); ClsCon.da.Dispose(); ClsCon.cmd.Dispose(); } return(dtCreditNote); }
public bool SaveCreditNote(CreditNoteModel objCredit) { string Query = string.Empty; bool isSaved = true; try { DBParameterCollection paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@VoucherNumber", objCredit.Voucher_Number)); paramCollection.Add(new DBParameter("@Series", objCredit.Voucher_Series)); paramCollection.Add(new DBParameter("@CNDate", objCredit.CN_Date, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@CNType", objCredit.Type)); paramCollection.Add(new DBParameter("@PDCDate", objCredit.PDCDate, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@LongNarration", objCredit.Narration)); paramCollection.Add(new DBParameter("@TotalCreditAmount", objCredit.TotalCreditAmt, System.Data.DbType.Decimal)); paramCollection.Add(new DBParameter("@TotalDebitAmount", objCredit.TotalDebitAmt, System.Data.DbType.Decimal)); paramCollection.Add(new DBParameter("@CreatedBy", "Admin")); paramCollection.Add(new DBParameter("@CreatedDate", DateTime.Now, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@ModifiedBy", "")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now, System.Data.DbType.DateTime)); System.Data.IDataReader dr = _dbHelper.ExecuteDataReader("spInsertCreditNoteMaster", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure); int id = 0; dr.Read(); id = Convert.ToInt32(dr[0]); SaveCreditAccounts(objCredit.CreditAccountModel, id); } catch (Exception ex) { isSaved = false; throw ex; } return(isSaved); }
public int SaveCreditNote(CreditNoteModel objCredit) { string Query = string.Empty; int creditid = 0; try { DBParameterCollection paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@Series", objCredit.Voucher_Series)); paramCollection.Add(new DBParameter("@Date", objCredit.CN_Date)); paramCollection.Add(new DBParameter("@Voucher_Number", objCredit.Voucher_Number)); paramCollection.Add(new DBParameter("@Type", objCredit.Type)); paramCollection.Add(new DBParameter("@PDDate", objCredit.PDCDate)); //paramCollection.Add(new DBParameter("@LongNarrtion",objCredit.l)) paramCollection.Add(new DBParameter("@CreatedBy", "Admin")); //paramCollection.Add(new DBParameter("@CreatedDate", DateTime.Now)); Query = "INSERT INTO Credit_Note([Series],[CN_Date],[VoucherNo],[Type],[PDC_Date]," + "[CreatedBy]) VALUES " + "(@Series,@Date,@Voucher_Number,@Type,@PDDate, " + " @CreatedBy)"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { SaveCreditAccounts(objCredit.CreditAccountModel); creditid = GetCreditId(); } } catch (Exception ex) { creditid = 0; throw ex; } return(creditid); }
//UPDATE CREDIT NOTE public bool UpdateCreditNote(CreditNoteModel objCredit) { string Query = string.Empty; bool isUpdated = true; try { //UPDATE CREDIT NOTE TABLE - PARENT TABLE DBParameterCollection paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@Series", objCredit.Voucher_Series)); paramCollection.Add(new DBParameter("@Date", objCredit.CN_Date, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@VoucherNumber", objCredit.Voucher_Number)); paramCollection.Add(new DBParameter("@Type", objCredit.Type)); paramCollection.Add(new DBParameter("@PCDate", objCredit.PDCDate, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@Narration", objCredit.Narration)); paramCollection.Add(new DBParameter("@TotalCreditAmt", objCredit.TotalCreditAmt)); paramCollection.Add(new DBParameter("@TotalDebitAmt", objCredit.TotalDebitAmt)); paramCollection.Add(new DBParameter("@ModifiedBy", "Admin")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@id", objCredit.CN_Id)); Query = "UPDATE Credit_Note_Master SET Series=@Series,CN_Date=@Date,VoucherNo=@VoucherNumber," + "Type=@Type,PDC_Date=@PDDate,LongNarration=@Narration,TotalCreditAmt=@TotalCreditAmt,TotalDebitAmt=@TotalDebitAmt,ModifiedBy=@ModifiedBy," + "ModifiedDate=@ModifiedDate " + "WHERE Credit_Id=@id"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { List <AccountModel> lstAcct = new List <AccountModel>(); //UPDATE CREDIT NOTE ACCOUNT -CHILD TABLE UPDATES foreach (AccountModel act in objCredit.CreditAccountModel) { act.ParentId = objCredit.CN_Id; if (act.AC_Id > 0) { paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@DC", (act.DC))); paramCollection.Add(new DBParameter("@Account", act.Account)); paramCollection.Add(new DBParameter("@Debit", act.Debit)); paramCollection.Add(new DBParameter("@Credit", act.Credit)); paramCollection.Add(new DBParameter("@Narration", act.Narration)); paramCollection.Add(new DBParameter("@ModifiedBy", "Admin")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@ACT_ID", act.AC_Id)); paramCollection.Add(new DBParameter("@ParentId", act.ParentId)); Query = "UPDATE Credit_Note_Details SET DC=@DC," + "Account=@Account,Debit=@Debit,Credit=@Credit,Narration=@Narration,ModifiedBy=@ModifiedBy,ModifiedDate=@ModifiedDate " + "WHERE AC_Id=@ACT_ID AND Credit_Id=@ParentId"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { isUpdated = true; } } else { paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@CreditId", (act.ParentId))); paramCollection.Add(new DBParameter("@DC", (act.DC))); paramCollection.Add(new DBParameter("@Account", act.Account)); paramCollection.Add(new DBParameter("@LegderId", act.LedgerId)); paramCollection.Add(new DBParameter("@DebitAmount", act.Debit, System.Data.DbType.Decimal)); paramCollection.Add(new DBParameter("@CreditAmount", act.Credit, System.Data.DbType.Decimal)); paramCollection.Add(new DBParameter("@Narration", act.Narration)); paramCollection.Add(new DBParameter("@CreatedBy", "Admin")); paramCollection.Add(new DBParameter("@CreatedDate", DateTime.Now, System.Data.DbType.DateTime)); paramCollection.Add(new DBParameter("@ModifiedBy", "")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now, System.Data.DbType.DateTime)); System.Data.IDataReader dr = _dbHelper.ExecuteDataReader("spInsertCreditDetails", _dbHelper.GetConnObject(), paramCollection, System.Data.CommandType.StoredProcedure); } } } } catch (Exception ex) { isUpdated = false; // throw ex; } return(isUpdated); }
//UPDATE CREDIT NOTE public bool UpdateCreditNote(CreditNoteModel objCredit) { string Query = string.Empty; bool isUpdated = true; try { //UPDATE CREDIT NOTE TABLE - PARENT TABLE DBParameterCollection paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@Series", objCredit.Voucher_Series)); paramCollection.Add(new DBParameter("@Date", objCredit.CN_Date)); paramCollection.Add(new DBParameter("@Voucher_Number", objCredit.Voucher_Number)); paramCollection.Add(new DBParameter("@Type", objCredit.Type)); paramCollection.Add(new DBParameter("@PDDate", objCredit.PDCDate)); paramCollection.Add(new DBParameter("@TotalCreditAmt", "0")); paramCollection.Add(new DBParameter("@TotalDebitAmt", "0")); paramCollection.Add(new DBParameter("@ModifiedBy", "Admin")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now)); paramCollection.Add(new DBParameter("@id", objCredit.CN_Id)); Query = "UPDATE Credit_Note SET [Series]=@Series,[CN_Date]=@Date,[VoucherNo]=@Voucher_Number," + "[Type]=@Type,[PDC_Date]=@PDDate,[TotalCreditAmt]=@TotalCreditAmt,[TotalDebitAmt]=@TotalDebitAmt,[ModifiedBy]=@ModifiedBy," + "[ModifiedDate]=@ModifiedDate " + "WHERE Credit_Id=@id"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { List <AccountModel> lstAcct = new List <AccountModel>(); //UPDATE CREDIT NOTE ACCOUNT -CHILD TABLE UPDATES foreach (AccountModel act in objCredit.CreditAccountModel) { if (act.AC_Id > 0) { paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@DC", (act.DC))); paramCollection.Add(new DBParameter("@Account", act.Account)); paramCollection.Add(new DBParameter("@Debit", act.Debit)); paramCollection.Add(new DBParameter("@Credit", act.Credit)); paramCollection.Add(new DBParameter("@Narration", act.Narration)); paramCollection.Add(new DBParameter("@ModifiedBy", "Admin")); paramCollection.Add(new DBParameter("@ModifiedDate", DateTime.Now)); paramCollection.Add(new DBParameter("@ACT_ID", act.AC_Id)); Query = "UPDATE Credit_Note_Accounts SET [DC]=@DC," + "[Account]=@Account,[Debit]=@Debit,[Credit]=@Credit,[Narration]=@Narration,[ModifiedBy]=@ModifiedBy,[ModifiedDate]=@ModifiedDate " + "WHERE [AC_Id]=@ACT_ID"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { isUpdated = true; } } else { paramCollection = new DBParameterCollection(); paramCollection.Add(new DBParameter("@CN_ID", (act.ParentId))); paramCollection.Add(new DBParameter("@DC", (act.DC))); paramCollection.Add(new DBParameter("@Account", act.Account)); paramCollection.Add(new DBParameter("@Debit", act.Debit)); paramCollection.Add(new DBParameter("@Credit", act.Credit)); paramCollection.Add(new DBParameter("@Narration", act.Narration)); paramCollection.Add(new DBParameter("@CreatedBy", "Admin")); paramCollection.Add(new DBParameter("@CreatedDate", DateTime.Now)); Query = "INSERT INTO Credit_Note_Accounts([Credit_Id],[DC],[Account],[Debit],[Credit]," + "[Narration],[CreatedBy],[CreatedDate]) VALUES " + "(@CN_ID,@DC,@Account,@Debit,@Credit,@Narration,@CreatedBy,@CreatedDate)"; if (_dbHelper.ExecuteNonQuery(Query, paramCollection) > 0) { } ; } } } } catch (Exception ex) { isUpdated = false; throw ex; } return(isUpdated); }
public async Task <ActionResult <CreditNoteModel> > Put(int invoiceId, int Id, CreditNoteModel updatedModel) { try { var currentCreditNote = await _repository.GetCreditNoteAsync(invoiceId, Id); if (currentCreditNote == null) { return(NotFound($"Could not find CreditNote with Id of {Id}")); } _mapper.Map(updatedModel, currentCreditNote); if (await _repository.UpdateCreditNoteAsync(invoiceId, currentCreditNote)) { return(_mapper.Map <CreditNoteModel>(currentCreditNote)); } } catch (Exception e) { _logger.LogError(e, e.Message); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public DataTable SaveCreditNote(CreditNoteModel objCNModel) { DataTable dtNarration = objCNDA.SaveCreditNote(objCNModel); return(dtNarration); }
public DataTable FillGistnNo(CreditNoteModel objCNModel) { DataTable dtNarration = objCNDA.FillGistnNo(objCNModel); return(dtNarration); }
public DataTable LoadPartyAccount(CreditNoteModel objDNModel) { DataTable dtPartyAccount = objCNDA.LoadPartyAccount(objDNModel); return(dtPartyAccount); }