protected void Page_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Request.Form["creditnoteid"])) { int OrderID = Int32.Parse(Request.Form["creditnoteid"].ToString()); CreditNotesDAL creditdal = new CreditNotesDAL(strConnSitring); CommissionDAL dal_Commision = new DeltoneCRM_DAL.CommissionDAL(strConnSitring); String pre_status = creditdal.getCurrentCreditNoteStatus(OrderID); //Fetch the PRevious Status String strCreditNoteGuid = creditdal.getCreditNote_XeroGuid(OrderID); //Fetch the credit note Xero Guid String Result = String.Empty; if (!String.IsNullOrEmpty(strCreditNoteGuid)) { xero = new XeroIntergration(); Repository repos = xero.CreateRepository(); XeroApi.Model.CreditNote cancelCreditNote = xero.CancelCreditNote(OrderID, repos, pre_status, strCreditNoteGuid); String connectionstring = ConfigurationManager.ConnectionStrings["ConnStringDeltoneCRM"].ConnectionString; //CANCEL THE CREDIT NOTE IN DELTONE SYSTEM Result = (cancelCreditNote != null) ? "SUCCESS" : "ERROR"; var previousValues = pre_status; if (Result.Equals("SUCCESS")) { var columnName = "Status"; var talbeName = "CreditNote"; var ActionType = "CANCELLED"; int primaryKey = OrderID; var orderIdForCreditNote = new CreditNotesDAL(connectionstring).getOrderIDFromCreditID(OrderID); var newvalues = " CreditNote Id " + OrderID + " :Credit Ortder Status changed from " + previousValues + " to CANCELLED"; var loggedInUserId = Convert.ToInt32(Session["LoggedUserID"].ToString()); SqlConnection conn = new SqlConnection(); conn.ConnectionString = connectionstring; var strCompanyID = new CreditNotesDAL(connectionstring).getCompanyIDFromCreditID(OrderID); new DeltoneCRM_DAL.CompanyDAL(connectionstring).CreateActionONAuditLog(previousValues, newvalues, loggedInUserId, conn, 0, columnName, talbeName, ActionType, primaryKey, Convert.ToInt32(strCompanyID)); creditdal.CancelCreditNote(OrderID); dal_Commision.RemoveCommissionEntry(OrderID, "CREDITNOTE"); } } else { Result = "ERROR"; } Response.Write(Result); } }
protected void btnOrderSubmit_Click(object sender, EventArgs e) { String strDelCost = String.Empty; float Total = 0;; float SubTotal = 0; float SplitVolume = 0; String strCreditItems = String.Empty; String strCreatedBy = String.Empty; String ACCOUNT_OWNER_ID_VALUE = ACCOUNT_OWNER_ID.Value;; String ACCOUNT_OWNER_TXT_VALUE = ACCOUNT_OWNER_TXT.Value; String SALESPERSON_ID_VALUE = SALESPERON_ID.Value; String SALESPERSON_TXT_VALUE = SALESPERSON_TXT.Value; String CommishSplit = COMMISH_SPLIT.Value; if (CommishSplit == "1") { SplitVolume = float.Parse(VOLUME_SPLIT_AMOUNT.Value); } else { SplitVolume = 0; } if (!String.IsNullOrEmpty(Session["LoggedUser"] as String)) { strCreatedBy = Session["LoggedUser"].ToString(); } if (!String.IsNullOrEmpty(CusDelCostItems.Value)) { strDelCost = CusDelCostItems.Value.ToString(); } if (!String.IsNullOrEmpty(hdnTotal.Value)) { Total = float.Parse(hdnTotal.Value); } if (!String.IsNullOrEmpty(hdnSubTotal.Value)) { SubTotal = float.Parse(hdnSubTotal.Value); } if (!String.IsNullOrEmpty(OrderItems.Value)) { strCreditItems = OrderItems.Value.ToString(); } if (COMMISH_SPLIT.Value == "1") { SplitVolume = float.Parse(VOLUME_SPLIT_AMOUNT.Value); } else { SplitVolume = 0; } String CreditNoteReason = txtCreditReason.Text; String Notes = OrderNotes.Text; String strConnectionString = ConfigurationManager.ConnectionStrings["ConnStringDeltoneCRM"].ConnectionString; creditNoteDAL = new CreditNotesDAL(strConnectionString); ContactDAL cdal = new ContactDAL(strConnectionString); String strGuid = cdal.getXeroGuid_ForContact(Int32.Parse(CONTACTID)); ///Create the XERO Entry first XeroIntergration xero = new XeroIntergration(); Repository res = xero.CreateRepository(); List <DeltoneItem> cr_items = CreateCreaitItems(strCreditItems); XeroApi.Model.CreditNote deltone_CreditNote = xero.CreateCreditNote(res, strGuid, String.Empty, String.Empty, cr_items); //CreditNoteReason= txtCreditReason.Text; CreditNoteReason = TYPEOFCREDIT.Value; //Get Customer delcost items and suppleir delcost items given by OrderID OrderDAL ordal = new OrderDAL(CONNSTRING); String CustomerDelItems = ordal.getCustomerDelItems(Int32.Parse(ORDERID)); String SuppDelItems = ordal.getSupplierDelItems(Int32.Parse(ORDERID)); var creditNoteMainString = ""; if (deltone_CreditNote != null) { //Write to Deltone DB Modified here if (creditNoteDAL.CreateCreditNote(Int32.Parse(COMPNAYID), Int32.Parse(CONTACTID), Total, strDelCost, strCreatedBy, Int32.Parse(ORDERID), "PENDING", CreditNoteReason, Notes, SuppDelItems, CustomerDelItems, SubTotal, SplitVolume, ACCOUNT_OWNER_ID_VALUE, ACCOUNT_OWNER_TXT_VALUE, SALESPERSON_ID_VALUE, SALESPERSON_TXT_VALUE, CommishSplit) > 0) { var connectionstring = ConfigurationManager.ConnectionStrings["ConnStringDeltoneCRM"].ConnectionString; var companyName = new CompanyDAL(connectionstring).getCompanyNameByID(COMPNAYID); int CreatedCreditNoteID = creditNoteDAL.FetchLastCreatedCreaditNoteID(strCreatedBy); creditNoteMainString = " CreditNote Id : " + CreatedCreditNoteID + " Created By :" + strCreatedBy + " Notes :" + Notes + " Credit Reason " + CreditNoteReason + " Status: PENDING "; if (!String.IsNullOrEmpty(strCreditItems)) { CreateCreditNoteItems(strCreditItems, CreatedCreditNoteID, creditNoteDAL, strCreatedBy, Convert.ToInt32(COMPNAYID), creditNoteMainString); } // Create entries for the RMAs creditNoteDAL.BuildRMAList(ORDERID, CreatedCreditNoteID.ToString()); //Update the Deltone Table With the Xero Entry creditNoteDAL.UpdateWithXeroEntry(CreatedCreditNoteID, deltone_CreditNote.CreditNoteID.ToString(), deltone_CreditNote.CreditNoteNumber.ToString()); //Add ORder Supplier Notes as Type 'Credit' Dictionary <String, String> di_notes = ordal.getOrderSupplierNotes(Int32.Parse(ORDERID)); //ordal.CreateSupplerNotes(Int32.Parse(ORDERID), deltone_CreditNote.CreditNoteNumber.ToString(), di_notes); creditNoteDAL.CreateSupplerNotes(CreatedCreditNoteID, deltone_CreditNote.CreditNoteNumber.ToString(), di_notes); #region Commission_Calculation CreditNotesDAL cnDal = new CreditNotesDAL(CONNSTRING); float AccountOwnerCommission = 0; float SalespersonCommission = 0; AccountOwnerCommission = float.Parse(ACCOUNT_OWNER_COMMISH.Value); AccountOwnerCommission = -AccountOwnerCommission; if (SALESPERSON_COMMISH.Value != "") { SalespersonCommission = float.Parse(SALESPERSON_COMMISH.Value); SalespersonCommission = -SalespersonCommission; } if (COMMISH_SPLIT.Value == "0") { cnDal.SplitCommission(CreatedCreditNoteID, Int32.Parse(COMPNAYID), Int32.Parse(ACCOUNT_OWNER_ID.Value), AccountOwnerCommission, "PENDING"); } else { cnDal.SplitCommission(CreatedCreditNoteID, Int32.Parse(COMPNAYID), Int32.Parse(ACCOUNT_OWNER_ID.Value), AccountOwnerCommission, "PENDING"); cnDal.SplitCommission(CreatedCreditNoteID, Int32.Parse(COMPNAYID), Int32.Parse(SALESPERON_ID.Value), SalespersonCommission, "PENDING"); } /* * commission = float.Parse(hdnCommision.Value.ToString()); * commission = -commission; * * * * * if (Session["LoggedUserID"] != null) * { * * * cnDal.SplitCommission(CreatedCreditNoteID, Int32.Parse(COMPNAYID), Int32.Parse(Session["LoggedUserID"].ToString()), commission, "PENDING"); * }*/ #endregion Commission_Calculation ///Dialog BOX Stating Success Message and Redirection String Message = "<h2>CREDIT NOTE: " + deltone_CreditNote.CreditNoteNumber + " HAS BEEN CREATED</h2>"; String NavigateUrl = "CreditNotes/AllCreditNotes.aspx"; String PrintURl = String.Empty; string strScript = "<script language='javascript'>$(document).ready(function (){SubmitDialog('" + Message + "','" + NavigateUrl + "','" + PrintURl + "'); });</script>"; ScriptManager.RegisterStartupScript(this, this.GetType(), "PopupCP", strScript, false); //Response.Redirect("CreditNotes/AllCreditNotes.aspx"); } } else { //Couldnt Write in to Xero Message with Dialog BOX String Message = "<h2>ERROR OCCURED CREATING CREDIT NOTE</h2>"; String NavigateUrl = "CreditNotes/AllCreditNotes.aspx"; String PrintURl = String.Empty; string strScript = "<script language='javascript'>$(document).ready(function (){SubmitDialog('" + Message + "','" + NavigateUrl + "','" + PrintURl + "'); });</script>"; ScriptManager.RegisterStartupScript(this, this.GetType(), "PopupCP", strScript, false); } }