Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing
Imports QueryString
Imports System
Imports System.Decimal

Partial Class ProductTaxInformation
    Inherits System.Web.UI.Page
    Dim prodcode As String
    Dim VAT As Decimal = 0.0
    Dim CST As Decimal = 0.0
    Dim ExciseDuty As Decimal = 0.0
    Dim EduCess As Decimal = 0.0
    Dim HigherEduCess As Decimal = 0.0
    Dim CSTAgainstC As Decimal = 0.0
    Dim TotalPriceVat As Decimal = 0.0
    Dim TotalPriceCST As Decimal = 0.0
    Dim TotalPriceCForm As Decimal = 0.0
    Dim TotalWithOutT As Decimal = 0.0
    Dim Total As Decimal = 0.0
    '  Dim shipingcharge As Decimal = 0.0
    Dim packingcharge As Decimal = 0.0
    Dim totwithoutTAX As Decimal = 0.0
    Dim totwithins As Decimal = 0.0
    Dim flgavat As Integer = 0
    Dim flagcst As Integer = 0
    Dim flagcstcform As Integer = 0
    Dim othercharge As Decimal = 0.0


    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        If Not Page.IsPostBack Then
            btnClose.Attributes.Add("onclick", "javascript:window.close();")
            ddltax.Items.Add("Select TAX")
            ddltax.Items.Add("VAT")
            ddltax.Items.Add("CST")
            ddltax.Items.Add("CST Against C Form")
            ddltax.Items.Add("None")
            DisplayData()
        End If

    End Sub
    Public Sub DisplayData()
        Try
            If Session("ProductCode") <> Nothing Then
                prodcode = RemoveLiterals(Session("ProductCode"))
            End If

            If Session("ProductCode") Is Nothing Then
                ddltax.Enabled = False

            Else
                ddltax.Enabled = True
            End If

            '==========================Installation/Commissioning.
            Dim Install As Decimal = 0.0
            Dim qry6 As String = "SELECT ProductInstallationCommissioning.InstallationComm_IsRequired, ProductInstallationCommissioning.InstallationComm_IsChargeable,ProductInstallationCommissioning.InstallationComm_Amount, ProductInstallationCommissioning.InstallationComm_IsMaintenanceTraining,ProductInstallationCommissioning.InstallationComm_IsAMCAvailable FROM ProductInstallationCommissioning INNER JOIN Product_Master ON ProductInstallationCommissioning.InstallationComm_ProductId = Product_Master.Product_Kid WHERE InstallationComm_ProductId = '" & prodcode & "'"
            Dim dt As DataTable
            dt = ReturnDataTable(qry6)
            Dim insamt As Decimal = 0.0
            If dt.Rows.Count > 0 Then
                insamt = CType(dt.Rows(0).Item("InstallationComm_Amount").ToString, Double)
                If insamt <> 0.0 Then
                    Install = Round(dt.Rows(0).Item("InstallationComm_Amount"), 2)
                    lblins_comm.Text = Install
                Else

                    lblins_comm.Text = "N.A."
                    changedisplay(lblins_comm)
                End If
            Else
                If Session("ProductCode") <> Nothing Then
                    lblins_comm.Text = "N.A."
                    changedisplay(lblins_comm)
                End If

            End If




            '=============================ProductVat/ExciseDuty/EduCess/OtherCharges

            Dim qry7 As String = "SELECT ProductVat.ProductVat_VAT,ProductVat.ProductVat_CST,ProductVat.ProductVat_EduCess, ProductVat.ProductVat_HigherEduCess, ProductVat.ProductVat_ExciseDuty, ProductVat.ProductVat_CSTAgainstC,ProductVat.ProductVat_OtherCharges,ProductVat.ProductVat_OtherChargesRemark,ISNULL(Product_Master.Product_MarketPrice,'0.0') as Product_MarketPrice, ISNULL(Product_Master.Product_PackagingCharge, N'0.0') AS Product_PackagingCharge, ISNULL(Product_Master.Product_ShippingCharges, N'0.0') AS Product_ShippingCharges FROM Product_Master LEFT OUTER JOIN ProductVat ON Product_Master.Product_Kid = ProductVat.ProductVat_ProductId WHERE Product_Master.Product_Kid = '" & prodcode & "' and Product_Isdeleted='0' and Product_Approved='Y'"
            Dim dt1 As DataTable

            dt1 = ReturnDataTable(qry7)


            lblbasicprice.Text = dt1.Rows(0).Item("Product_MarketPrice")

            'If dt1.Rows(0).Item("Product_ShippingCharges").ToString <> "" Then
            '    shipingcharge = dt1.Rows(0).Item("Product_ShippingCharges")
            'End If

            If dt1.Rows(0).Item("ProductVat_OtherCharges").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_OtherCharges").ToString <> "No" Then
                    othercharge = dt1.Rows(0).Item("ProductVat_OtherCharges")
                End If
            End If

            If dt1.Rows(0).Item("Product_PackagingCharge").ToString <> "" Then
                packingcharge = dt1.Rows(0).Item("Product_PackagingCharge")
            End If

            'total with installation price & Other Charges
            Total = Round((dt1.Rows(0).Item("Product_MarketPrice") + packingcharge), 2)
            lbltotprice.Text = Total

            'counting exciseduty
            If dt1.Rows(0).Item("ProductVat_ExciseDuty").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_ExciseDuty").ToString <> "No" Then
                    ExciseDuty = ((dt1.Rows(0).Item("Product_MarketPrice") + packingcharge) * dt1.Rows(0).Item("ProductVat_ExciseDuty")) / 100
                End If
            End If

            'counting educess
            If dt1.Rows(0).Item("ProductVat_EduCess").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_EduCess").ToString <> "No" Then
                    EduCess = (dt1.Rows(0).Item("ProductVat_EduCess") * ExciseDuty) / 100
                End If
            End If

            'counting highereducess
            If dt1.Rows(0).Item("ProductVat_HigherEduCess").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_HigherEduCess").ToString <> "No" Then
                    HigherEduCess = (dt1.Rows(0).Item("ProductVat_HigherEduCess") * ExciseDuty) / 100
                End If
            End If


            'total without installation price & taxes
            totwithoutTAX = (Total + ExciseDuty + EduCess + HigherEduCess)

            'total with installation charge
            totwithins = Total + ExciseDuty + EduCess + HigherEduCess + Install
            ViewState("totwithins") = totwithins

            'counting vat if available 
            If dt1.Rows(0).Item("ProductVat_VAT").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_VAT").ToString <> "No" Then
                    VAT = (totwithoutTAX * dt1.Rows(0).Item("ProductVat_VAT")) / 100
                    ViewState("VAT") = VAT
                    If VAT <> 0.0 Then
                        ViewState("TotalPriceVat") = Round((totwithins + VAT), 2)
                    Else
                        ViewState("TotalPriceVat") = Round((totwithins), 2)
                    End If
                Else
                    ViewState("VAT") = VAT
                    ViewState("TotalPriceVat") = Round((totwithins), 2)
                End If
            Else
                ViewState("TotalPriceVat") = Round((totwithins), 2)
                flgavat = 1
            End If

            'counting cst if available
            If dt1.Rows(0).Item("ProductVat_CST").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_CST").ToString <> "No" Then
                    CST = (totwithoutTAX * dt1.Rows(0).Item("ProductVat_CST")) / 100
                    ViewState("CST") = CST
                    If CST <> 0.0 Then
                        ViewState("TotalPriceCST") = Round((totwithins + CST), 2)
                    Else
                        ViewState("TotalPriceCST") = Round((totwithins), 2)
                    End If
                Else
                    ViewState("CST") = CST
                    ViewState("TotalPriceCST") = Round((totwithins), 2)
                End If

            Else
                ViewState("TotalPriceCST") = Round((totwithins), 2)
                flagcst = 1
            End If

            If dt1.Rows(0).Item("ProductVat_CSTAgainstC").ToString <> "" Then
                If dt1.Rows(0).Item("ProductVat_CSTAgainstC").ToString <> "No" Then
                    CSTAgainstC = (totwithoutTAX * dt1.Rows(0).Item("ProductVat_CSTAgainstC")) / 100
                    ViewState("CSTAgainstC") = CSTAgainstC
                    If CSTAgainstC <> 0.0 Then
                        ViewState("TotalPriceCForm") = Round((totwithins + CSTAgainstC), 2)
                    Else
                        ViewState("TotalPriceCForm") = Round((totwithins), 2)
                    End If
                Else
                    ViewState("CSTAgainstC") = CSTAgainstC
                    ViewState("TotalPriceCForm") = Round((totwithins), 2)
                End If

            Else
                ViewState("TotalPriceCForm") = Round((totwithins), 2)
                flagcstcform = 1
            End If

            'check the shipping charge
            'If shipingcharge <> 0.0 Then
            '    lblshipcharge.Text = Round(shipingcharge, 2)
            'Else
            '    lblshipcharge.Text = "N.A."
            '    changedisplay(lblshipcharge)
            'End If

            'check the packing charge
            If packingcharge <> 0.0 Then
                lblpackcharge.Text = Round(packingcharge, 2)
            Else
                lblpackcharge.Text = "N.A."
                changedisplay(lblpackcharge)
            End If

            lblVAT.Text = "N.A."
            lblCST.Text = "N.A"
            lblCSTCForm.Text = "N.A."

            changedisplay(lblVAT)
            changedisplay(lblCST)
            changedisplay(lblCSTCForm)

            'check the excise duty
            If ExciseDuty <> 0.0 Then
                lblExciseDuty.Text = Round(ExciseDuty, 2)
            Else
                lblExciseDuty.Text = "N.A."
                changedisplay(lblExciseDuty)
            End If

            'check the educess
            If EduCess <> 0.0 Then
                lblEduCess.Text = Round(EduCess, 2)
            Else
                lblEduCess.Text = "N.A."
                changedisplay(lblEduCess)
            End If

            'check the highereducess
            If HigherEduCess <> 0.0 Then
                lblHighEduCess.Text = Round(HigherEduCess, 2)
            Else
                lblHighEduCess.Text = "N.A."
                changedisplay(lblHighEduCess)
            End If

            'check the OtherCharges
            If othercharge <> 0.0 Then
                lblOtherCharge.Text = Round(othercharge, 2)
                ViewState("OtherCharges") = Round(othercharge, 2)
                lblotherDesc.Text = "(" & dt1.Rows(0).Item("ProductVat_OtherChargesRemark").ToString & ")"
            Else
                lblOtherCharge.Text = "N.A."
                changedisplay(lblOtherCharge)
                lblotherDesc.Text = ""
            End If


            lbltotprice.Text = Round(totwithins + ViewState("OtherCharges"), 2)
            'check if VAT,CST & CSTCForm is Not available in database
            If flgavat = 1 And flagcst = 1 And flagcstcform = 1 Then
                ddltax.Enabled = False
            Else
                ddltax.Enabled = True
            End If

        Catch ex As Exception
        End Try
    End Sub
    Protected Sub changedisplay(ByVal lbl As Label)
        lbl.ForeColor = Color.Red
        lbl.Font.Size = 7
    End Sub

    Protected Sub changedisplay1(ByVal lbl As Label)
        lbl.ForeColor = Color.Black
        lbl.Font.Size = 9
    End Sub

    Protected Sub ddltax_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddltax.SelectedIndexChanged
        Try

            lblVAT.Text = "N.A."
            lblCST.Text = "N.A."
            lblCSTCForm.Text = "N.A."
            changedisplay(lblVAT)
            changedisplay(lblCST)
            changedisplay(lblCSTCForm)
            If ddltax.SelectedItem.Text = "Select TAX" Then
                TotalWithOutT = Round(ViewState("totwithins"), 2)
                lbltotprice.Text = TotalWithOutT + ViewState("OtherCharges")
            End If

            If ddltax.SelectedItem.Text = "VAT" Then
                lbltotprice.Text = Round(ViewState("TotalPriceVat") + ViewState("OtherCharges"), 2)
                lblVAT.Text = Round(ViewState("VAT"), 2)
                changedisplay1(lblVAT)
            End If

            If ddltax.SelectedItem.Text = "CST" Then
                lbltotprice.Text = Round(ViewState("TotalPriceCST").ToString + ViewState("OtherCharges"), 2)
                lblCST.Text = Round(ViewState("CST"), 2)
                changedisplay1(lblCST)
            End If

            If ddltax.SelectedItem.Text = "CST Against C Form" Then
                lbltotprice.Text = Round(ViewState("TotalPriceCForm").ToString + ViewState("OtherCharges"), 2)
                lblCSTCForm.Text = Round(ViewState("CSTAgainstC"), 2)
                changedisplay1(lblCSTCForm)
            End If

            If ddltax.SelectedItem.Text = "None" Then
                TotalWithOutT = Round(ViewState("totwithins") + ViewState("OtherCharges"), 2)
                lbltotprice.Text = TotalWithOutT
            End If
        Catch ex As Exception

        End Try

    End Sub
End Class
