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); } }
protected void Page_Load(object sender, EventArgs e) { xero = new XeroIntergration(); ContactDAL contactdal = new ContactDAL(strConnString); CompanyDAL companydal = new CompanyDAL(strConnString); int ContactID = Int32.Parse(Request.Form["ContactID"].ToString()); String FirstName = Request.Form["NewFirstName"].ToString(); String LastName = Request.Form["NewLastName"].ToString(); String DefaultAreaCode = Request.Form["NewDefaultAreaCode"].ToString(); String DefaultNumber = Request.Form["NewDefaultNumber"].ToString(); String MobileNumber = Request.Form["NewMobileNumber"].ToString(); String EmailAddy = Request.Form["NewEmailAddy"].ToString(); String ShipLine1 = Request.Form["NewShipLine1"].ToString(); String ShipLine2 = Request.Form["NewShipLine2"].ToString(); String ShipCity = Request.Form["NewShipCity"].ToString(); String ShipState = Request.Form["NewShipState"].ToString(); String ShipPostcode = Request.Form["NewShipPostcode"].ToString(); String BillLine1 = Request.Form["NewBillLine1"].ToString(); String BillLine2 = Request.Form["NewBillLine2"].ToString(); String BillCity = Request.Form["NewBillCity"].ToString(); String BillState = Request.Form["NewBillState"].ToString(); String BillPostcode = Request.Form["NewBillPostcode"].ToString(); String PrimaryContact = Request.Form["PrimaryContact"].ToString(); String ActINact = Request.Form["ActInact"].ToString(); string finalActInact = ""; if (ActINact == "false") { finalActInact = "N"; } else { finalActInact = "Y"; } String finalPrimaryContact = ""; if (PrimaryContact == "true") { finalPrimaryContact = "Y"; } else { finalPrimaryContact = "N"; } var userId = Convert.ToInt32(Session["LoggedUserID"].ToString()); String str = contactdal.UpdateContact(ContactID, FirstName, LastName, DefaultAreaCode, DefaultNumber, MobileNumber, EmailAddy, ShipLine1, ShipLine2, ShipCity, ShipState, ShipPostcode, BillLine1, BillLine2, BillCity, BillState, BillPostcode, finalPrimaryContact, finalActInact, userId); if (Int32.Parse(str) > 0) { //Ge the XeroGuid and Update the Details in Xero String contactGuid = contactdal.getXeroGuid_ForContact(ContactID); if (!String.IsNullOrEmpty(contactGuid) && !(DBNull.Value.Equals(contactGuid))) { //Fetch the CompanyName for the Contact String strCompanyName = companydal.GetCompanybyContactID(ContactID); String strDefaultCountryCode = "+61"; //Should have entries in AddContactUI String strDefaultCountry = "Australia"; //Should have entries in AddContactUI Repository res = xero.CreateRepository();//Create the Repository XeroApi.Model.Contact delContact = xero.UpdateContact(res, contactGuid, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, ShipPostcode, BillState); if (delContact != null) { } // Repository res = xero.CreateRepository(); // XeroApi.Model.Contact delContact = xero.CreateContact(res, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, BillPostcode, BillState); //if (delContact != null) // { //Update the ContactGuid in the DataBase Table // contactdal.UpdateWithXeroDetails(23538, delContact.ContactID.ToString()); // } } else { //Entry hasn't been created in the Xero System .Create the Entry and Update the Tables } } Response.Write(str); }