protected void Page_Command(object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Refund")
     {
         Guid   gPAYMENTS_TRANSACTION_ID = CommonTypeConvert.ToGuid(e.CommandArgument);
         var    oQuery   = new InlineQueryDBManager();
         string innerSql = ApplicationSQL.SQL["PaymentTransactions"].ToString();
         oQuery.CommandText = innerSql;
         TypeConvert.AppendParameter(oQuery, gPAYMENTS_TRANSACTION_ID, "ID", false);
         using (SqlDataReader rdr = oQuery.ExecuteReader(CommandBehavior.SingleRow))
         {
             if (rdr.Read())
             {
                 Guid    gCURRENCY_ID        = CommonTypeConvert.ToGuid(rdr["CURRENCY_ID"]);
                 Guid    gACCOUNT_ID         = CommonTypeConvert.ToGuid(rdr["ACCOUNT_ID"]);
                 Guid    gCREDIT_CARD_ID     = CommonTypeConvert.ToGuid(rdr["CREDIT_CARD_ID"]);
                 string  sINVOICE_NUMBER     = CommonTypeConvert.ToString(rdr["INVOICE_NUMBER"]);
                 Decimal dAMOUNT             = CommonTypeConvert.ToDecimal(rdr["AMOUNT"]);
                 string  sDESCRIPTION        = CommonTypeConvert.ToString(rdr["DESCRIPTION"]);
                 string  sTRANSACTION_NUMBER = CommonTypeConvert.ToString(rdr["TRANSACTION_NUMBER"]);
                 //CRM.Common.Charge.CC.Refund(Application, gID, gCURRENCY_ID, gACCOUNT_ID, gCREDIT_CARD_ID, Request.UserHostAddress, sINVOICE_NUMBER, sDESCRIPTION, dAMOUNT, sTRANSACTION_NUMBER);
                 BindGrid();
             }
         }
     }
 }
        protected void grdMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (dtLineItems != null)
            {
                GridViewRow gr = grdMain.Rows[e.RowIndex];
                var         txtINVOICE_NAME        = gr.FindControl("INVOICE_NAME") as TextBox;
                var         txtINVOICE_ID          = gr.FindControl("INVOICE_ID") as HiddenField;
                var         txtAMOUNT_DUE          = gr.FindControl("AMOUNT_DUE") as TextBox;
                var         txtAMOUNT_DUE_USDOLLAR = gr.FindControl("AMOUNT_DUE_USDOLLAR") as HiddenField;
                var         txtAMOUNT          = gr.FindControl("AMOUNT") as TextBox;
                var         txtAMOUNT_USDOLLAR = gr.FindControl("AMOUNT_USDOLLAR") as HiddenField;

                DataRow row = dtLineItems.Rows[e.RowIndex];
                if (txtINVOICE_NAME != null)
                {
                    row["INVOICE_NAME"] = txtINVOICE_NAME.Text;
                }
                if (txtINVOICE_ID != null)
                {
                    row["INVOICE_ID"] = CommonTypeConvert.ToGuid(txtINVOICE_ID.Value);
                }
                if (txtAMOUNT != null)
                {
                    row["AMOUNT_DUE"] = CommonTypeConvert.ToDecimal(txtAMOUNT_DUE.Text);
                }
                if (txtAMOUNT != null)
                {
                    row["AMOUNT"] = CommonTypeConvert.ToDecimal(txtAMOUNT.Text);
                }

                row["AMOUNT_DUE_USDOLLAR"] =
                    Currency.GetCurrency.FromCurrency(CommonTypeConvert.ToDecimal(txtAMOUNT_DUE.Text));
                row["AMOUNT_USDOLLAR"] = Currency.GetCurrency.FromCurrency(CommonTypeConvert.ToDecimal(txtAMOUNT.Text));

                DataRow[] aCurrentRows = dtLineItems.Select(String.Empty, String.Empty, DataViewRowState.CurrentRows);
                if (aCurrentRows.Length == 0 ||
                    !CommonTypeConvert.IsEmptyString(aCurrentRows[aCurrentRows.Length - 1]["INVOICE_NAME"]))
                {
                    DataRow rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);
                    aCurrentRows = dtLineItems.Select(String.Empty, String.Empty, DataViewRowState.CurrentRows);
                }

                ViewState["LineItems"] = dtLineItems;
                grdMain.DataSource     = dtLineItems;
                grdMain.EditIndex      = aCurrentRows.Length - 1;
                grdMain.DataBind();
                UpdateTotals();
                UpdatePaymentAmount();
            }
        }
Example #3
0
        public LineItem GetItemDetailsByNumber(Guid gCURRENCY_ID, string sMFT_PART_NUM)
        {
            var item = new LineItem();

            {
                if (Security.USER_ID == Guid.Empty)
                {
                    throw (new Exception("Authentication required"));
                }

                var oQuery = new InlineQueryDBManager();
                oQuery.CommandText = ApplicationSQL.SQL["ProductCatalog_AutoComplete_63"].ToString();

                CRMSecurity.Filter(oQuery, "ProductTemplates", "list");
                TypeConvert.AppendParameter(oQuery, sMFT_PART_NUM, CommonTypeConvert.SqlFilterMode.StartsWith,
                                            "MFT_PART_NUM");
                oQuery.CommandText += " order by MFT_PART_NUM" + ControlChars.CrLf;
                using (SqlDataReader rdr = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                {
                    if (rdr.Read())
                    {
                        item.ID              = CommonTypeConvert.ToGuid(rdr["ID"]);
                        item.NAME            = CommonTypeConvert.ToString(rdr["NAME"]);
                        item.MFT_PART_NUM    = CommonTypeConvert.ToString(rdr["MFT_PART_NUM"]);
                        item.VENDOR_PART_NUM = CommonTypeConvert.ToString(rdr["VENDOR_PART_NUM"]);
                        item.TAX_CLASS       = CommonTypeConvert.ToString(rdr["TAX_CLASS"]);
                        item.COST_PRICE      = CommonTypeConvert.ToDecimal(rdr["COST_PRICE"]);
                        item.COST_USDOLLAR   = CommonTypeConvert.ToDecimal(rdr["COST_USDOLLAR"]);
                        item.LIST_PRICE      = CommonTypeConvert.ToDecimal(rdr["LIST_PRICE"]);
                        item.LIST_USDOLLAR   = CommonTypeConvert.ToDecimal(rdr["LIST_USDOLLAR"]);
                        item.UNIT_PRICE      = CommonTypeConvert.ToDecimal(rdr["UNIT_PRICE"]);
                        item.UNIT_USDOLLAR   = CommonTypeConvert.ToDecimal(rdr["UNIT_USDOLLAR"]);
                        if (gCURRENCY_ID != CommonTypeConvert.ToGuid(rdr["CURRENCY_ID"]))
                        {
                            Currency C10n = Currency.CreateCurrency(gCURRENCY_ID);
                            item.COST_PRICE = Currency.GetCurrency.ToCurrency(item.COST_USDOLLAR);
                            item.LIST_PRICE = Currency.GetCurrency.ToCurrency(item.LIST_USDOLLAR);
                            item.UNIT_PRICE = Currency.GetCurrency.ToCurrency(item.UNIT_USDOLLAR);
                        }
                    }
                }
                if (CommonTypeConvert.IsEmptyGuid(item.ID))
                {
                    throw (new Exception("Item not found"));
                }
            }
            return(item);
        }
        public void CURRENCY_ID_Changed(object sender, EventArgs e)
        {
            Guid gCURRENCY_ID = CommonTypeConvert.ToGuid(CURRENCY_ID.SelectedValue);

            SetCurrency(gCURRENCY_ID);
            EXCHANGE_RATE.Value = Currency.GetCurrency.CONVERSION_RATE.ToString();

            foreach (DataRow row in dtLineItems.Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    row["AMOUNT"] = Currency.GetCurrency.ToCurrency(CommonTypeConvert.ToDecimal(row["AMOUNT_USDOLLAR"]));
                }
            }
            grdMain.DataBind();

            UpdateTotals();
            UpdatePaymentAmount();
        }
Example #5
0
        public Invoice GetInvoiceByName(Guid gCURRENCY_ID, string sNAME)
        {
            var item = new Invoice();

            {
                if (Security.USER_ID == Guid.Empty)
                {
                    throw (new Exception("Authentication required"));
                }

                var    oQuery   = new InlineQueryDBManager();
                string innerSql = ApplicationSQL.SQL["Invoices_AutoComplete_50"].ToString();

                oQuery.CommandText = innerSql;
                CRMSecurity.Filter(oQuery, "Invoices", "list");
                TypeConvert.AppendParameter(oQuery, sNAME, CommonTypeConvert.SqlFilterMode.StartsWith, "NAME");
                using (SqlDataReader rdr = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                {
                    if (rdr.Read())
                    {
                        item.ID                  = CommonTypeConvert.ToGuid(rdr["ID"]);
                        item.NAME                = CommonTypeConvert.ToString(rdr["NAME"]);
                        item.AMOUNT_DUE          = CommonTypeConvert.ToDecimal(rdr["AMOUNT_DUE"]);
                        item.AMOUNT_DUE_USDOLLAR = CommonTypeConvert.ToDecimal(rdr["AMOUNT_DUE_USDOLLAR"]);
                        if (gCURRENCY_ID != CommonTypeConvert.ToGuid(rdr["CURRENCY_ID"]))
                        {
                            Currency C10n = Currency.CreateCurrency(gCURRENCY_ID);
                            item.AMOUNT_DUE = Currency.GetCurrency.ToCurrency(item.AMOUNT_DUE_USDOLLAR);
                        }
                    }
                }
                if (CommonTypeConvert.IsEmptyGuid(item.ID))
                {
                    throw (new Exception("Item not found"));
                }
            }
            return(item);
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save" || e.CommandName == "Charge")
            {
                ValidateEditViewFields(m_sMODULE + ".EditView");
                bool bIsValid = Page.IsValid;

                Decimal dAMOUNT = new DynamicControl(this, "AMOUNT").DecimalValue;
                if (dAMOUNT != ctlAllocationsView.ALLOCATED_TOTAL)
                {
                    ctlDynamicButtons.ErrorText =
                        Translation.GetTranslation.Term("Payments.ERR_AMOUNT_MUST_MATCH_ALLOCATION");
                    bIsValid = false;
                }
                if (bIsValid)
                {
                    string    sCUSTOM_MODULE = "PAYMENTS";
                    DataTable dtCustomFields = CRMCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    var       oQuery         = new InlineQueryDBManager();
                    DataRow   rowCurrent     = null;
                    if (!CommonTypeConvert.IsEmptyGuid(gID))
                    {
                        string innerSql = ApplicationSQL.SQL["Payments_EditView_259"].ToString();
                        oQuery.CommandText = innerSql;
                        CRMSecurity.Filter(oQuery, m_sMODULE, "edit");
                        TypeConvert.AppendParameter(oQuery, gID, "ID", false);
                        DataTable dtCurrent = oQuery.GetTable();
                        if (dtCurrent.Rows.Count > 0)
                        {
                            rowCurrent = dtCurrent.Rows[0];
                        }
                        else
                        {
                            gID = Guid.Empty;
                        }
                    }

                    Guid     gASSIGNED_USER_ID   = new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID;
                    Guid     gACCOUNT_ID         = new DynamicControl(this, rowCurrent, "ACCOUNT_ID").ID;
                    DateTime dtPAYMENT_DATE      = new DynamicControl(this, rowCurrent, "PAYMENT_DATE").DateValue;
                    string   sPAYMENT_TYPE       = new DynamicControl(this, rowCurrent, "PAYMENT_TYPE").SelectedValue;
                    string   sCUSTOMER_REFERENCE = new DynamicControl(this, rowCurrent, "CUSTOMER_REFERENCE").Text;
                    Guid     gCURRENCY_ID        = new DynamicControl(this, rowCurrent, "CURRENCY_ID").ID;
                    string   sDESCRIPTION        = new DynamicControl(this, rowCurrent, "DESCRIPTION").Text;
                    Guid     gTEAM_ID            = new DynamicControl(this, rowCurrent, "TEAM_ID").ID;
                    Guid     gCREDIT_CARD_ID     = new DynamicControl(this, rowCurrent, "CREDIT_CARD_ID").ID;
                    if (sPAYMENT_TYPE != "Credit Card")
                    {
                        gCREDIT_CARD_ID = Guid.Empty;
                    }
                    float fEXCHANGE_RATE =
                        new DynamicControl(ctlAllocationsView, rowCurrent, "EXCHANGE_RATE").FloatValue;
                    var sbINVOICE_NUMBER = new StringBuilder();
                    if (dtPAYMENT_DATE == ((DateTime)SqlDateTime.MinValue) || e.CommandName == "Charge")
                    {
                        dtPAYMENT_DATE = DateTime.Now;
                    }

                    CommonProcedure.PatmentsUpdate
                        (ref gID
                        , gASSIGNED_USER_ID
                        , gACCOUNT_ID
                        , dtPAYMENT_DATE
                        , sPAYMENT_TYPE
                        , sCUSTOMER_REFERENCE
                        , fEXCHANGE_RATE
                        , gCURRENCY_ID
                        , dAMOUNT
                        , sDESCRIPTION
                        , gTEAM_ID
                        , gCREDIT_CARD_ID
                        );
                    CRMDynamic.UpdateCustomFields(this, gID, sCUSTOM_MODULE, dtCustomFields);

                    DataTable dtLineItems = ctlAllocationsView.LineItems;
                    foreach (DataRow row in dtLineItems.Rows)
                    {
                        if (row.RowState == DataRowState.Deleted)
                        {
                            Guid gITEM_ID = CommonTypeConvert.ToGuid(row["ID", DataRowVersion.Original]);
                            if (!CommonTypeConvert.IsEmptyGuid(gITEM_ID))
                            {
                                CommonProcedure.InvoicesPAYMENTS_Delete(gITEM_ID);
                            }
                        }
                    }
                    foreach (DataRow row in dtLineItems.Rows)
                    {
                        if (row.RowState != DataRowState.Deleted)
                        {
                            Guid    gITEM_ID        = CommonTypeConvert.ToGuid(row["ID"]);
                            Guid    gINVOICE_ID     = CommonTypeConvert.ToGuid(row["INVOICE_ID"]);
                            Decimal dINVOICE_AMOUNT = CommonTypeConvert.ToDecimal(row["AMOUNT"]);
                            if (!CommonTypeConvert.IsEmptyGuid(gINVOICE_ID))
                            {
                                CommonProcedure.InvoicesPAYMENTS_Update
                                    (ref gITEM_ID
                                    , gINVOICE_ID
                                    , gID
                                    , dINVOICE_AMOUNT
                                    );
                                if (sbINVOICE_NUMBER.Length > 0)
                                {
                                    sbINVOICE_NUMBER.Append(",");
                                }
                                sbINVOICE_NUMBER.Append(gINVOICE_ID.ToString());
                            }
                        }
                    }

                    ViewState["ID"] = gID;


                    if (e.CommandName == "Charge")
                    {
                        sbINVOICE_NUMBER.Append(" " + DateTime.UtcNow);
                        //CRM.Common.Charge.CC.Charge(Application, gID, gCURRENCY_ID, gACCOUNT_ID, gCREDIT_CARD_ID, Request.UserHostAddress, sbINVOICE_NUMBER.ToString(), sDESCRIPTION, dAMOUNT);
                    }

                    Response.Redirect("view.aspx?ID=" + gID);
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (CommonTypeConvert.IsEmptyGuid(gID))
                {
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SetPageTitle(Translation.GetTranslation.Term(".moduleList." + m_sMODULE));
            Visible = (Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!Visible)
            {
                return;
            }

            gID = CommonTypeConvert.ToGuid(Request["ID"]);
            if (CommonTypeConvert.IsEmptyGuid(gID))
            {
                gID = CommonTypeConvert.ToGuid(ViewState["ID"]);
            }
            if (!IsPostBack)
            {
                Guid gDuplicateID = CommonTypeConvert.ToGuid(Request["DuplicateID"]);
                if (!CommonTypeConvert.IsEmptyGuid(gID) || !CommonTypeConvert.IsEmptyGuid(gDuplicateID))
                {
                    var    oQuery   = new InlineQueryDBManager();
                    string innerSql = ApplicationSQL.SQL["Payments_EditView_259"].ToString();
                    oQuery.CommandText = innerSql;
                    CRMSecurity.Filter(oQuery, m_sMODULE, "edit");
                    if (!CommonTypeConvert.IsEmptyGuid(gDuplicateID))
                    {
                        TypeConvert.AppendParameter(oQuery, gDuplicateID, "ID", false);
                        gID = Guid.Empty;
                    }
                    else
                    {
                        TypeConvert.AppendParameter(oQuery, gID, "ID", false);
                    }
                    using (SqlDataReader rdr = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (rdr.Read())
                        {
                            ctlModuleHeader.Title = CommonTypeConvert.ToString(rdr["PAYMENT_NUM"]);
                            SetPageTitle(Translation.GetTranslation.Term(".moduleList." + m_sMODULE) + " - " +
                                         ctlModuleHeader.Title);
                            Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                            ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                            AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                            ctlDynamicButtons.AppendButtons(m_sMODULE + ".EditView",
                                                            CommonTypeConvert.ToGuid(rdr["ASSIGNED_USER_ID"]), rdr);

                            var CURRENCY_ID = tblMain.FindControl("CURRENCY_ID") as DropDownList;
                            if (CURRENCY_ID != null)
                            {
                                CURRENCY_ID.AutoPostBack          = true;
                                CURRENCY_ID.SelectedIndexChanged += CURRENCY_ID_Changed;
                            }
                            var PAYMENT_TYPE = tblMain.FindControl("PAYMENT_TYPE") as DropDownList;
                            if (PAYMENT_TYPE != null)
                            {
                                PAYMENT_TYPE.AutoPostBack          = true;
                                PAYMENT_TYPE.SelectedIndexChanged += PAYMENT_TYPE_Changed;
                                PAYMENT_TYPE_Changed(null, null);
                            }
                            Guid gACCOUNT_ID = CommonTypeConvert.ToGuid(rdr["ACCOUNT_ID"]);
                            ctlAllocationsView.LoadLineItems(gID, gACCOUNT_ID, gDuplicateID, oQuery, rdr);
                        }
                        else
                        {
                            Guid gPARENT_ID = CommonTypeConvert.ToGuid(Request["PARENT_ID"]);
                            ctlAllocationsView.LoadLineItems(gID, gPARENT_ID, gDuplicateID, oQuery, null);
                            ctlDynamicButtons.AppendButtons(m_sMODULE + ".EditView", Guid.Empty, null);
                            ctlDynamicButtons.DisableAll();
                            ctlDynamicButtons.ErrorText = Translation.GetTranslation.Term("ACL.LBL_NO_ACCESS");
                        }
                    }
                }
                else
                {
                    AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                    ctlDynamicButtons.AppendButtons(m_sMODULE + ".EditView", Guid.Empty, null);

                    var CURRENCY_ID = tblMain.FindControl("CURRENCY_ID") as DropDownList;
                    if (CURRENCY_ID != null)
                    {
                        CURRENCY_ID.AutoPostBack          = true;
                        CURRENCY_ID.SelectedIndexChanged += CURRENCY_ID_Changed;
                    }
                    Guid gACCOUNT_ID = Guid.Empty;
                    Guid gPARENT_ID  = CommonTypeConvert.ToGuid(Request["PARENT_ID"]);
                    new DynamicControl(this, "PAYMENT_DATE").DateValue = DateTime.Today;
                    Guid gINVOICE_ID = gPARENT_ID;
                    if (!CommonTypeConvert.IsEmptyGuid(gPARENT_ID))
                    {
                        string sMODULE      = String.Empty;
                        string sPARENT_TYPE = String.Empty;
                        string sPARENT_NAME = String.Empty;
                        CommonProcedure.ParentGet(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
                        if (!CommonTypeConvert.IsEmptyGuid(gPARENT_ID) && sMODULE == "Accounts")
                        {
                            gACCOUNT_ID = gPARENT_ID;
                            new DynamicControl(this, "ACCOUNT_ID").ID     = gPARENT_ID;
                            new DynamicControl(this, "ACCOUNT_NAME").Text = sPARENT_NAME;
                            var oQuery = new InlineQueryDBManager();
                            ctlAllocationsView.LoadLineItems(gID, gACCOUNT_ID, gDuplicateID, oQuery, null);
                        }
                        else if (!CommonTypeConvert.IsEmptyGuid(gINVOICE_ID))
                        {
                            var    oQuery   = new InlineQueryDBManager();
                            string innerSql = ApplicationSQL.SQL["Payments_EditView"].ToString();
                            oQuery.CommandText = innerSql;
                            CRMSecurity.Filter(oQuery, "Invoices", "edit");
                            TypeConvert.AppendParameter(oQuery, gINVOICE_ID, "ID", false);
                            using (SqlDataReader rdr = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                            {
                                if (rdr.Read())
                                {
                                    gACCOUNT_ID = CommonTypeConvert.ToGuid(rdr["BILLING_ACCOUNT_ID"]);
                                    new DynamicControl(this, "ACCOUNT_ID").ID =
                                        CommonTypeConvert.ToGuid(rdr["BILLING_ACCOUNT_ID"]);
                                    new DynamicControl(this, "ACCOUNT_NAME").Text =
                                        CommonTypeConvert.ToString(rdr["BILLING_ACCOUNT_NAME"]);

                                    ctlAllocationsView.LoadLineItems(gID, gACCOUNT_ID, gDuplicateID, oQuery, null);
                                    new DynamicControl(this, "AMOUNT").Text =
                                        Currency.GetCurrency.ToCurrency(
                                            CommonTypeConvert.ToDecimal(rdr["AMOUNT_DUE_USDOLLAR"])).ToString("0.00");
                                }
                            }
                        }
                    }
                    var PAYMENT_TYPE = tblMain.FindControl("PAYMENT_TYPE") as DropDownList;
                    if (PAYMENT_TYPE != null)
                    {
                        PAYMENT_TYPE.AutoPostBack          = true;
                        PAYMENT_TYPE.SelectedIndexChanged += PAYMENT_TYPE_Changed;
                        PAYMENT_TYPE_Changed(null, null);
                    }
                }
            }
            else
            {
                ctlModuleHeader.Title = CommonTypeConvert.ToString(ViewState["ctlModuleHeader.Title"]);
                SetPageTitle(Translation.GetTranslation.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
            }
        }
Example #8
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            Guid   gORDER_ID    = CommonTypeConvert.ToGuid(Request["ORDER_ID"]);
            Guid   gQUOTE_ID    = CommonTypeConvert.ToGuid(Request["QUOTE_ID"]);
            Guid   gPARENT_ID   = CommonTypeConvert.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            CommonProcedure.ParentGet(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            if (e.CommandName == "Save")
            {
                ValidateEditViewFields(m_sMODULE + ".EditView");
                ValidateEditViewFields(m_sMODULE + ".EditAddress");
                ValidateEditViewFields(m_sMODULE + ".EditDescription");
                if (Page.IsValid)
                {
                    string    sCUSTOM_MODULE    = "INVOICES";
                    DataTable dtCustomFields    = CRMCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DataTable dtCustomLineItems =
                        CRMCache.FieldsMetaData_UnvalidatedCustomFields(sCUSTOM_MODULE + "_LINE_ITEMS");

                    DataRow rowCurrent = null;
                    var     dtCurrent  = new DataTable();
                    if (!CommonTypeConvert.IsEmptyGuid(gID))
                    {
                        string innerSql = ApplicationSQL.SQL["Invoices_EditView_323"].ToString();
                        var    oQuery   = new InlineQueryDBManager();

                        oQuery.CommandText = innerSql;
                        CRMSecurity.Filter(oQuery, m_sMODULE, "edit");
                        TypeConvert.AppendParameter(oQuery, gID, "ID", false);
                        dtCurrent = oQuery.GetTable();

                        if (dtCurrent.Rows.Count > 0)
                        {
                            rowCurrent = dtCurrent.Rows[0];
                        }
                        else
                        {
                            gID = Guid.Empty;
                        }
                    }


                    ctlEditLineItemsView.UpdateTotals();
                    CommonProcedure.InvoicesUpdate
                        (ref gID
                        , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                        , new DynamicControl(this, rowCurrent, "NAME").Text
                        , new DynamicControl(this, rowCurrent, "QUOTE_ID").ID
                        , new DynamicControl(this, rowCurrent, "ORDER_ID").ID
                        , new DynamicControl(this, rowCurrent, "OPPORTUNITY_ID").ID
                        , new DynamicControl(this, rowCurrent, "PAYMENT_TERMS").SelectedValue
                        , new DynamicControl(this, rowCurrent, "INVOICE_STAGE").SelectedValue
                        , new DynamicControl(this, rowCurrent, "PURCHASE_ORDER_NUM").Text
                        , new DynamicControl(this, rowCurrent, "DUE_DATE").DateValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "EXCHANGE_RATE").FloatValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "CURRENCY_ID").ID
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "TAXRATE_ID").ID
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "SHIPPER_ID").ID
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "SUBTOTAL").DecimalValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "DISCOUNT").DecimalValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "SHIPPING").DecimalValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "TAX").DecimalValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "TOTAL").DecimalValue
                        , new DynamicControl(ctlEditLineItemsView, rowCurrent, "AMOUNT_DUE").DecimalValue
                        , new DynamicControl(this, rowCurrent, "BILLING_ACCOUNT_ID").ID
                        , new DynamicControl(this, rowCurrent, "BILLING_CONTACT_ID").ID
                        , new DynamicControl(this, rowCurrent, "BILLING_ADDRESS_STREET").Text
                        , new DynamicControl(this, rowCurrent, "BILLING_ADDRESS_CITY").Text
                        , new DynamicControl(this, rowCurrent, "BILLING_ADDRESS_STATE").Text
                        , new DynamicControl(this, rowCurrent, "BILLING_ADDRESS_POSTALCODE").Text
                        , new DynamicControl(this, rowCurrent, "BILLING_ADDRESS_COUNTRY").Text
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ACCOUNT_ID").ID
                        , new DynamicControl(this, rowCurrent, "SHIPPING_CONTACT_ID").ID
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ADDRESS_STREET").Text
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ADDRESS_CITY").Text
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ADDRESS_STATE").Text
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ADDRESS_POSTALCODE").Text
                        , new DynamicControl(this, rowCurrent, "SHIPPING_ADDRESS_COUNTRY").Text
                        , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                        , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                        );
                    CRMDynamic.UpdateCustomFields(this, gID, sCUSTOM_MODULE, dtCustomFields);

                    DataTable dtLineItems = ctlEditLineItemsView.LineItems;
                    foreach (DataRow row in dtLineItems.Rows)
                    {
                        if (row.RowState == DataRowState.Deleted)
                        {
                            Guid gITEM_ID = CommonTypeConvert.ToGuid(row["ID", DataRowVersion.Original]);
                            if (!CommonTypeConvert.IsEmptyGuid(gITEM_ID))
                            {
                                CommonProcedure.InvoicesLINE_ITEMS_Delete(gITEM_ID);
                            }
                        }
                    }
                    int nPOSITION = 1;
                    foreach (DataRow row in dtLineItems.Rows)
                    {
                        if (row.RowState != DataRowState.Deleted)
                        {
                            Guid    gITEM_ID             = CommonTypeConvert.ToGuid(row["ID"]);
                            Guid    gLINE_GROUP_ID       = CommonTypeConvert.ToGuid(row["LINE_GROUP_ID"]);
                            string  sLINE_ITEM_TYPE      = CommonTypeConvert.ToString(row["LINE_ITEM_TYPE"]);
                            string  sNAME                = CommonTypeConvert.ToString(row["NAME"]);
                            string  sMFT_PART_NUM        = CommonTypeConvert.ToString(row["MFT_PART_NUM"]);
                            string  sVENDOR_PART_NUM     = CommonTypeConvert.ToString(row["VENDOR_PART_NUM"]);
                            Guid    gPRODUCT_TEMPLATE_ID = CommonTypeConvert.ToGuid(row["PRODUCT_TEMPLATE_ID"]);
                            string  sTAX_CLASS           = CommonTypeConvert.ToString(row["TAX_CLASS"]);
                            int     nQUANTITY            = CommonTypeConvert.ToInteger(row["QUANTITY"]);
                            Decimal dCOST_PRICE          = CommonTypeConvert.ToDecimal(row["COST_PRICE"]);
                            Decimal dLIST_PRICE          = CommonTypeConvert.ToDecimal(row["LIST_PRICE"]);
                            Decimal dUNIT_PRICE          = CommonTypeConvert.ToDecimal(row["UNIT_PRICE"]);
                            string  sDESCRIPTION         = CommonTypeConvert.ToString(row["DESCRIPTION"]);
                            if (!CommonTypeConvert.IsEmptyGuid(gPRODUCT_TEMPLATE_ID) ||
                                !CommonTypeConvert.IsEmptyString(sNAME))
                            {
                                CommonProcedure.InvoicesLINE_ITEMS_Update
                                    (ref gITEM_ID
                                    , gID
                                    , gLINE_GROUP_ID
                                    , sLINE_ITEM_TYPE
                                    , nPOSITION
                                    , sNAME
                                    , sMFT_PART_NUM
                                    , sVENDOR_PART_NUM
                                    , gPRODUCT_TEMPLATE_ID
                                    , sTAX_CLASS
                                    , nQUANTITY
                                    , dCOST_PRICE
                                    , dLIST_PRICE
                                    , dUNIT_PRICE
                                    , sDESCRIPTION
                                    );
                                CRMDynamic.UpdateCustomFields(row, gITEM_ID, sCUSTOM_MODULE + "_LINE_ITEMS",
                                                              dtCustomLineItems);
                                nPOSITION++;
                            }
                        }
                    }
                    CommonProcedure.InvoicesUpdateAmountDue(gID);


                    if (!CommonTypeConvert.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/CRM/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID);
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID);
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!CommonTypeConvert.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/CRM/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID);
                }
                else if (!CommonTypeConvert.IsEmptyGuid(gORDER_ID))
                {
                    Response.Redirect("~/CRM/Orders/view.aspx?ID=" + gORDER_ID);
                }
                else if (!CommonTypeConvert.IsEmptyGuid(gQUOTE_ID))
                {
                    Response.Redirect("~/CRM/Quotes/view.aspx?ID=" + gQUOTE_ID);
                }
                else if (CommonTypeConvert.IsEmptyGuid(gID))
                {
                    Response.Redirect("Index.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID);
                }
            }
        }
        public void LoadLineItems(Guid gID, Guid gACCOUNT_ID, Guid gDuplicateID, InlineQueryDBManager oQuery,
                                  SqlDataReader rdr)
        {
            this.gACCOUNT_ID = gACCOUNT_ID;
            if (!IsPostBack)
            {
                GetCurrencyControl();
                CURRENCY_ID.SelectedValue = Currency.GetCurrency.ID.ToString();
                EXCHANGE_RATE.Value       = Currency.GetCurrency.CONVERSION_RATE.ToString();
                foreach (DataControlField col in grdMain.Columns)
                {
                    if (!CommonTypeConvert.IsEmptyString(col.HeaderText))
                    {
                        col.HeaderText = Translation.GetTranslation.Term(col.HeaderText);
                    }
                    var cf = col as CommandField;
                    if (cf != null)
                    {
                        cf.EditText   = Translation.GetTranslation.Term(cf.EditText);
                        cf.DeleteText = Translation.GetTranslation.Term(cf.DeleteText);
                        cf.UpdateText = Translation.GetTranslation.Term(cf.UpdateText);
                        cf.CancelText = Translation.GetTranslation.Term(cf.CancelText);
                    }
                }

                if ((!CommonTypeConvert.IsEmptyGuid(gID) || !CommonTypeConvert.IsEmptyGuid(gDuplicateID)) &&
                    (oQuery != null) && (rdr != null))
                {
                    CURRENCY_ID.SelectedValue = CommonTypeConvert.ToString(rdr["CURRENCY_ID"]);
                    EXCHANGE_RATE.Value       = Currency.GetCurrency.CONVERSION_RATE.ToString();
                    float fEXCHANGE_RATE = CommonTypeConvert.ToFloat(rdr["EXCHANGE_RATE"]);
                    if (fEXCHANGE_RATE == 0.0f)
                    {
                        fEXCHANGE_RATE = 1.0f;
                    }
                    EXCHANGE_RATE.Value = fEXCHANGE_RATE.ToString();
                    if (CURRENCY_ID.Items.Count > 0)
                    {
                        Guid gCURRENCY_ID = CommonTypeConvert.ToGuid(CURRENCY_ID.SelectedValue);
                        SetCurrency(gCURRENCY_ID, fEXCHANGE_RATE);
                        EXCHANGE_RATE.Value = Currency.GetCurrency.CONVERSION_RATE.ToString();
                    }
                    ALLOCATED.Text =
                        Currency.GetCurrency.ToCurrency(CommonTypeConvert.ToDecimal(rdr["TOTAL_ALLOCATED_USDOLLAR"])).
                        ToString("c");
                    ALLOCATED_USDOLLAR.Value =
                        CommonTypeConvert.ToDecimal(rdr["TOTAL_ALLOCATED_USDOLLAR"]).ToString("0.00");
                    rdr.Close();
                    string innerSql = ApplicationSQL.SQL["Payments_AllocationsView_233"].ToString();

                    oQuery.CommandText = innerSql;
                    TypeConvert.AppendParameter(oQuery, gID, "PAYMENT_ID", false);
                    oQuery.CommandText += " order by DATE_MODIFIED asc" + ControlChars.CrLf;
                    DataTable dtLineItems = oQuery.GetTable();
                    if (!CommonTypeConvert.IsEmptyGuid(gDuplicateID))
                    {
                        foreach (DataRow row in dtLineItems.Rows)
                        {
                            row["ID"] = Guid.NewGuid();
                        }
                    }
                    DataRow rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);

                    ViewState["LineItems"] = dtLineItems;
                    grdMain.DataSource     = dtLineItems;
                    grdMain.EditIndex      = dtLineItems.Rows.Count - 1;
                    grdMain.DataBind();
                }
                else
                {
                    dtLineItems = new DataTable();
                    var colID                  = new DataColumn("ID", Type.GetType("System.Guid"));
                    var colINVOICE_NAME        = new DataColumn("INVOICE_NAME", Type.GetType("System.String"));
                    var colINVOICE_ID          = new DataColumn("INVOICE_ID", Type.GetType("System.Guid"));
                    var colAMOUNT_DUE          = new DataColumn("AMOUNT_DUE", Type.GetType("System.Decimal"));
                    var colAMOUNT_DUE_USDOLLAR = new DataColumn("AMOUNT_DUE_USDOLLAR", Type.GetType("System.Decimal"));
                    var colAMOUNT              = new DataColumn("AMOUNT", Type.GetType("System.Decimal"));
                    var colAMOUNT_USDOLLAR     = new DataColumn("AMOUNT_USDOLLAR", Type.GetType("System.Decimal"));
                    dtLineItems.Columns.Add(colID);
                    dtLineItems.Columns.Add(colINVOICE_NAME);
                    dtLineItems.Columns.Add(colINVOICE_ID);
                    dtLineItems.Columns.Add(colAMOUNT_DUE);
                    dtLineItems.Columns.Add(colAMOUNT_DUE_USDOLLAR);
                    dtLineItems.Columns.Add(colAMOUNT);
                    dtLineItems.Columns.Add(colAMOUNT_USDOLLAR);
                    DataRow rowNew   = null;
                    string  innerSql = ApplicationSQL.SQL["Payments_AllocationsView"].ToString();

                    oQuery.CommandText = innerSql;
                    Guid gPARENT_ID = CommonTypeConvert.ToGuid(Request["PARENT_ID"]);
                    TypeConvert.AppendParameter(oQuery, gPARENT_ID, "ID", false);
                    using (SqlDataReader rdrInvoice = oQuery.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (rdrInvoice.Read())
                        {
                            rowNew = dtLineItems.NewRow();
                            rowNew["INVOICE_NAME"]        = CommonTypeConvert.ToString(rdrInvoice["NAME"]);
                            rowNew["INVOICE_ID"]          = CommonTypeConvert.ToGuid(rdrInvoice["ID"]);
                            rowNew["AMOUNT_DUE"]          = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE"]);
                            rowNew["AMOUNT_DUE_USDOLLAR"] =
                                CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE_USDOLLAR"]);
                            rowNew["AMOUNT"]          = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE"]);
                            rowNew["AMOUNT_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["AMOUNT_DUE_USDOLLAR"]);
                            if (rdrInvoice["AMOUNT_DUE"] == DBNull.Value)
                            {
                                rowNew["AMOUNT_DUE"]          = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL"]);
                                rowNew["AMOUNT_DUE_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL_USDOLLAR"]);
                                rowNew["AMOUNT"]          = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL"]);
                                rowNew["AMOUNT_USDOLLAR"] = CommonTypeConvert.ToDecimal(rdrInvoice["TOTAL_USDOLLAR"]);
                            }
                            dtLineItems.Rows.Add(rowNew);
                        }
                    }
                    rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);

                    ViewState["LineItems"] = dtLineItems;
                    grdMain.DataSource     = dtLineItems;
                    grdMain.EditIndex      = dtLineItems.Rows.Count - 1;
                    grdMain.DataBind();

                    UpdateTotals();
                }
            }
        }
 private void UpdatePaymentAmount()
 {
     new DynamicControl(Parent as CRMControl, "AMOUNT").Text =
         Currency.GetCurrency.ToCurrency(CommonTypeConvert.ToDecimal(ALLOCATED_USDOLLAR.Value)).ToString("0.00");
 }