Ejemplo n.º 1
0
        protected void lnkBtnSave_Click(object sender, EventArgs e)
        {
            string msg = string.Empty; bool bflag = false; double IssueQty = 0, IssueWT = 0;

            if (grdMain.Rows.Count <= 0)
            {
                ShowMessage("Please Enter Challan Details");
            }
            else
            {
                DtTemp = (DataTable)ViewState["dt"];
                DtTemp = CreateDt();
                ChallanDelverdDAL objChallanDelverdDAL = new ChallanDelverdDAL();
                Int64             MtrlRcptId = 0, MtrlRcptDetlId = 0;
                string            strMsgTyp = String.Empty;
                int yearIdno = Convert.ToInt32(ddlDateRange.SelectedValue);

                Int64           Value           = 0;
                tblChlnDelvHead ObjMtrlRcptHead = new tblChlnDelvHead();
                ObjMtrlRcptHead.ChlnDelv_Date   = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDate.Text));
                ObjMtrlRcptHead.ToCity_Idno     = Convert.ToInt32(ddlToCity.SelectedValue);
                ObjMtrlRcptHead.ChlnTransf_Idno = Convert.ToInt32(ddlChallanDetl.SelectedValue);
                ObjMtrlRcptHead.Date_Added      = ApplicationFunction.GetIndianDateTime().Date; // DateTime.Now.Date;
                ObjMtrlRcptHead.Date_Modified   = ApplicationFunction.GetIndianDateTime().Date;
                ObjMtrlRcptHead.ChlnDelv_No     = MaxRcptHeadNo(Convert.ToInt32(ddlToCity.SelectedValue), Convert.ToInt32(ddlDateRange.SelectedValue));
                ObjMtrlRcptHead.CrsngGR_Amnt    = Convert.ToDouble(txtoutGrAmnt.Text);
                ObjMtrlRcptHead.LocGR_Amnt      = Convert.ToDouble(txtLocGrAmnt.Text);
                ObjMtrlRcptHead.Net_Amnt        = Convert.ToDouble(txtNetAmnt.Text);
                ObjMtrlRcptHead.Year_Idno       = Convert.ToInt32(ddlDateRange.SelectedValue);
                foreach (GridViewRow row in grdMain.Rows)
                {
                    HiddenField hidGrIdno   = (HiddenField)row.FindControl("hidGridno");
                    HiddenField hidItemidno = (HiddenField)row.FindControl("hidItemidno");
                    HiddenField hidUnitidno = (HiddenField)row.FindControl("hidUnitidno");
                    Label       lblrateType = (Label)row.FindControl("lblrateType");
                    Label       lblQty      = (Label)row.FindControl("lblQty");
                    Label       lblWeight   = (Label)row.FindControl("lblWeight");
                    Label       lblAmount   = (Label)row.FindControl("lblAmount");
                    TextBox     txtRecQty   = (TextBox)row.FindControl("txtRecQty");
                    TextBox     txtRecWT    = (TextBox)row.FindControl("txtRecWT");
                    TextBox     txtRecWt    = (TextBox)row.FindControl("txtRecWt");
                    TextBox     txtRemark   = (TextBox)row.FindControl("txtRemark");
                    TextBox     txtRecAmt   = (TextBox)row.FindControl("txtRecAmt");
                    if (lblrateType.Text == "Rate")
                    {
                        if (txtRecQty.Text == "")
                        {
                            ShowMessageErr("Please Enter Receiving QTY!");
                            return;
                        }
                        if (Convert.ToDouble(txtRecQty.Text) < 0.00)
                        {
                            ShowMessageErr("You Cannot Enter Receiving QTY Less than 1!");
                            return;
                        }

                        IssueQty = Convert.ToDouble(lblQty.Text);
                        if (IssueQty < Convert.ToDouble(txtRecQty.Text))
                        {
                            txtRecQty.Focus();
                            txtRecQty.Text = "0.00";
                            ShowMessageErr("You Cannot Enter Receiving QTY more than GR QTY!");
                            return;
                        }
                    }
                    else
                    {
                        if (txtRecWT.Text == "")
                        {
                            ShowMessageErr("Please Enter Receiving Weight!");
                            return;
                        }
                        if (Convert.ToDouble(txtRecWT.Text) < 0.00)
                        {
                            ShowMessageErr("You Cannot Enter Receiving Weight Less than 1!");
                            return;
                        }
                        IssueWT = Convert.ToDouble(lblWeight.Text);
                        if (IssueWT < Convert.ToDouble(txtRecWT.Text))
                        {
                            txtRecWT.Focus(); txtRecWT.Text = "0.00";
                            ShowMessageErr("You Cannot Enter Receiving Weight more than GR Weight!");
                            return;
                        }
                    }
                    ApplicationFunction.DatatableAddRow(DtTemp, hidGrIdno.Value, hidItemidno.Value, hidUnitidno.Value, ((lblrateType.Text) == "Rate") ? "1" : "2", lblQty.Text, lblWeight.Text,
                                                        lblAmount.Text, txtRecQty.Text, txtRecWt.Text, txtRecAmt.Text, txtRemark.Text);
                }
                using (TransactionScope tScope = new TransactionScope(TransactionScopeOption.Required))
                {
                    try
                    {
                        ChallanDelverdDAL obj     = new ChallanDelverdDAL();
                        DateTime          dMtrlDt = obj.MtrlTransfDate(Convert.ToInt64(ddlChallanDetl.SelectedValue));
                        hidMtrlTrnsfDt.Value = dMtrlDt.ToString("dd-MM-yyyy");
                        if (Convert.ToDateTime(ApplicationFunction.mmddyyyy(hidMtrlTrnsfDt.Value)) > Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDate.Text)))
                        {
                            txtDate.Focus();
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmsg", "PassMessageError('Delivery Date must be greater than or equal to Challan Date [" + dMtrlDt.Date.ToString("dd-MMM-yyyy") + "].')", true);
                            return;
                        }
                        if (string.IsNullOrEmpty(hidMtrlRcptid.Value) == true)
                        {
                            MtrlRcptId = obj.InsertMtrlRcptHOHead(ObjMtrlRcptHead, DtTemp);
                            if (MtrlRcptId > 0)
                            {
                                tScope.Complete();
                            }
                        }
                        else
                        {
                            tblChlnDelvHead ObjMtrlRcptHeadU = new tblChlnDelvHead();
                            ObjMtrlRcptHeadU.ChlnDelv_Date   = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtDate.Text));
                            ObjMtrlRcptHeadU.ToCity_Idno     = Convert.ToInt32(ddlToCity.SelectedValue);
                            ObjMtrlRcptHeadU.ChlnTransf_Idno = Convert.ToInt32(ddlChallanDetl.SelectedValue);
                            ObjMtrlRcptHeadU.Date_Modified   = ApplicationFunction.GetIndianDateTime().Date;
                            ObjMtrlRcptHeadU.CrsngGR_Amnt    = Convert.ToDouble(txtoutGrAmnt.Text);
                            ObjMtrlRcptHeadU.LocGR_Amnt      = Convert.ToDouble(txtLocGrAmnt.Text);
                            ObjMtrlRcptHeadU.Net_Amnt        = Convert.ToDouble(txtNetAmnt.Text);
                            ObjMtrlRcptHeadU.Year_Idno       = Convert.ToInt32(ddlDateRange.SelectedValue);
                            MtrlRcptId = obj.UpdateMtrlRcptHOHead(ObjMtrlRcptHeadU, DtTemp, Convert.ToInt32(hidMtrlRcptid.Value));
                            if ((MtrlRcptId > 0))
                            {
                                tScope.Complete();
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        // ApplicationFunction.ErrorLog(ex.ToString());
                    }
                }
                if (string.IsNullOrEmpty(hidMtrlRcptid.Value) == true)
                {
                    if (MtrlRcptId > 0)
                    {
                        ShowMessage("Record Saved Successffully");
                    }
                }
                else
                {
                    if ((MtrlRcptId > 0))
                    {
                        ShowMessage("Record Update successfully");
                    }
                }
                if (MtrlRcptId == -1)
                {
                    ShowMessage("Challan No. already  Delivered !");
                    bflag     = false;
                    strMsgTyp = "RecExst";
                    ddlChallanDetl.Focus();
                }
                else
                {
                    ClearControls();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.UrlReferrer == null)
            {
                base.AutoRedirect();
            }
            if (!Page.IsPostBack)
            {
                //if (base.CheckUserRights(intFormId) == false)
                //{
                //    Response.Redirect("PermissionDenied.aspx");
                //}
                //if (base.ADD == false)
                //{
                //    lnkbtnSave.Visible = false;
                //}
                //if (base.View == false)
                //{
                //    lblViewList.Visible = false;
                //}

                txtDate.Text = ApplicationFunction.GetIndianDateTime().Date.ToString("dd-MM-yyyy");
                this.BindCity();
                if (Convert.ToString(Session["Userclass"]) == "Admin")
                {
                    BindDropdownDAL obj = new BindDropdownDAL();
                    var             lst = obj.BindLocFrom();
                    drpBaseCity.DataSource     = lst;
                    drpBaseCity.DataTextField  = "City_Name";
                    drpBaseCity.DataValueField = "City_Idno";
                    drpBaseCity.DataBind();
                    drpBaseCity.Items.Insert(0, new ListItem("--Select--", "0"));

                    drpDeliveryPlace.DataSource     = lst;
                    drpDeliveryPlace.DataTextField  = "City_Name";
                    drpDeliveryPlace.DataValueField = "City_Idno";
                    drpDeliveryPlace.DataBind();
                    drpDeliveryPlace.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select--", "0"));
                }
                else
                {
                    this.BindCity(Convert.ToInt64(Session["UserIdno"]));
                }
                drpBaseCity.SelectedValue = Convert.ToString(base.UserFromCity);

                this.BindDateRange(); this.BindItemType();
                ddlDateRange.SelectedValue = Convert.ToString(base.UserDateRng);
                Int32 intYearIdno = Convert.ToInt32(ddlDateRange.SelectedValue);
                ddlDateRange_SelectedIndexChanged(null, null);
                ddlDateRange.SelectedIndex = 0;
                StockTransferDAL objstck = new StockTransferDAL();
                if (drpBaseCity.SelectedIndex > 0)
                {
                    txtIssueNo.Text = Convert.ToString(objstck.SelectMaxNo(Convert.ToInt32(ddlDateRange.SelectedValue), Convert.ToInt32(drpBaseCity.SelectedValue)));
                }
                if (Request.QueryString["q"] != null)
                {
                    Populate(Convert.ToInt64(Request.QueryString["q"]));
                    hidStckid.Value = Convert.ToString(Request.QueryString["q"]);
                    //btnNew.Visible = true;
                    imgPrint.Visible     = true;
                    lnkbtnAdd.Visible    = true;
                    ddlDateRange.Enabled = false;
                }

                else
                {
                    lnkbtnAdd.Visible    = false;
                    ddlDateRange.Enabled = true;
                    imgPrint.Visible     = false;
                }
                txtQty.Text = "1";
                txtRate.Attributes.Add("onkeypress", "return allowOnlyFloatNumber(event);");
                txtQty.Attributes.Add("onkeypress", "return allowOnlyFloatNumber(event);");
                txtDate.Attributes.Add("onkeypress", "return notAllowAnything(event);");
                txtRemark.Attributes.Add("onkeypress", "return notAllowSpecialCharacters_Spaceallow(event);");
                txtNetAmnt.Attributes.Add("onkeypress", "return allowOnlyFloatNumber(event);");
            }
        }
        private bool RecPostIntoAccounts(double AdvAmount, Int64 intDocIdno, string strDocType, double dblRndOff, Int32 intCompIdno, Int32 intUserIdno, Int32 intUserType, Int32 intVchrForIdno, Int32 YearIdno, Int32 TruckIdno, string InstDate, string InstNo, Int32 DriverIdno, string strDate, Int32 intChlnNo, Int32 intRcptType, Int32 intCustBIdno, double dGrossAmnt, double dCommissionAmnt, double dTdsAmnt, double dDiesel)
        {
            #region Variables Declaration...
            Int64             intVchrIdno = 0; Int64 intValue = 0; Int32 IAcntIdno = 0; DateTime?dtBankDate = null;
            clsAccountPosting objclsAccountPosting = new clsAccountPosting();
            ChlnBookingDAL    objAcnt = new ChlnBookingDAL();
            BindDropdownDAL   objDal  = new BindDropdownDAL();
            #endregion
            #region Start Ac/Posting.........
            AcntLinkDS = objAcnt.DtAcntDS(ApplicationFunction.ConnectionString());
            DsHire     = objAcnt.DsHireAcnt(ApplicationFunction.ConnectionString());
            DataSet dsLD = objDal.GetLorryDetails(ApplicationFunction.ConnectionString(), "GetLorryDetails", TruckIdno, strDate);
            if (dsLD != null && dsLD.Tables.Count > 0 && dsLD.Tables[0].Rows.Count > 0)
            {
                Int32  intLtype   = string.IsNullOrEmpty(dsLD.Tables[0].Rows[0]["Lorry_Type"].ToString()) ? 0 : Convert.ToInt32(dsLD.Tables[0].Rows[0]["Lorry_Type"]);
                string strLorryNo = Convert.ToString(dsLD.Tables[0].Rows[0]["Lorry_No"]);
                Int32  PartyIdno  = Convert.ToInt32(dsLD.Tables[0].Rows[0]["Acnt_Idno"]);
                IAcntIdno = PartyIdno;
                #region Account link Validations...

                if (AcntLinkDS == null || AcntLinkDS.Rows.Count <= 0)
                {
                    ShowMessageErr("Account link is not defined. Kindly define.");
                    return(false);
                }

                ICAcnt_Idno = Convert.ToInt32(Convert.ToString(AcntLinkDS.Rows[0]["CAcnt_Idno"]) == "" ? 0 : Convert.ToInt32(AcntLinkDS.Rows[0]["CAcnt_Idno"]));
                if (ICAcnt_Idno <= 0)
                {
                    ShowMessageErr("Commission Account is not defined. Kindly define.");
                    return(false);
                }
                if (DsHire == null || DsHire.Rows.Count <= 0)
                {
                    ShowMessageErr("Transport Account is not defined. Kindly define.");
                    return(false);
                }
                else
                {
                    IHireAcntIdno = Convert.ToInt32(DsHire.Rows[0]["HireAccountID"]);
                }
                IntTDSAcntIdno = Convert.ToInt32(Convert.ToString(AcntLinkDS.Rows[0]["TDS_Idno"]) == "" ? 0 : Convert.ToInt32(AcntLinkDS.Rows[0]["TDS_Idno"]));
                if (IntTDSAcntIdno <= 0)
                {
                    ShowMessageErr("TDS Account is not defined. Kindly define.");
                    return(false);
                }
                //IntDieselAcc_Idno = Convert.ToInt32(ddlAcntLink.SelectedValue);
                //if (IntDieselAcc_Idno <= 0)
                //{
                //    hidpostingmsg.Value = "Diesel Account is not defined. Kindly define.";
                //    return false;
                //}

                #endregion
                #region Amount Posting............
                intValue = objclsAccountPosting.DeleteAccountPosting(intDocIdno, strDocType);
                #region Commission Account Posting ................
                if (dCommissionAmnt > 0)
                {
                    if (intValue > 0)
                    {
                        Int64 VchrNo = objclsAccountPosting.GetMaxVchrNo(4, 0, YearIdno);
                        intValue = objclsAccountPosting.InsertInVchrHead(
                            Convert.ToDateTime(ApplicationFunction.mmddyyyy(strDate)),
                            4,
                            0,
                            "Challan No: " + Convert.ToString(intChlnNo) + " Challan Date: " + strDate + " Lorry: " + strLorryNo + "Commission Posting",
                            true,
                            0,
                            strDocType,
                            0,
                            0,
                            Convert.ToInt64(intChlnNo),
                            ApplicationFunction.GetIndianDateTime().Date,
                            VchrNo,
                            0,
                            YearIdno,
                            0, intUserIdno);
                        if (intValue > 0)
                        {
                            intVchrIdno = intValue;
                            #region Commission Amount  Posting...
                            intValue = 0;
                            /*Insert In VchrDetl*/
                            intValue = objclsAccountPosting.InsertInVchrDetl(
                                intVchrIdno,
                                Convert.ToInt64(ICAcnt_Idno),
                                "Challan No: " + Convert.ToString(intChlnNo) + " Challan Date: " + strDate + " Lorry: " + strLorryNo + "Commission Posting",
                                dCommissionAmnt,
                                Convert.ToByte(1),
                                Convert.ToByte(0),
                                "",
                                true,
                                null, //please check here if date is Blank
                                "", 0);
                            if (intValue > 0)
                            {
                                intValue = 0;
                                intValue = objclsAccountPosting.InsertInVchrDetl(
                                    intVchrIdno,
                                    Convert.ToInt64(PartyIdno),
                                    "Challan No: " + Convert.ToString(intChlnNo) + " Challan Date: " + strDate + " Lorry: " + strLorryNo + "Commission Posting",
                                    Convert.ToDouble(dCommissionAmnt),
                                    Convert.ToByte(2),
                                    Convert.ToByte(0),
                                    "",
                                    false,
                                    null,     //please check here if date is Blank
                                    "", 0);

                                if (intValue == 0)
                                {
                                    return(false);
                                }

                                if (intValue > 0)
                                {
                                    intValue = 0; /*Insert In VchrIdDetl*/
                                    intValue = objclsAccountPosting.InsertInVchrIdDetl(intVchrIdno, intDocIdno, strDocType);
                                    if (intValue == 0)
                                    {
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                return(false);
                            }

                            #endregion
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                #endregion
                #region  TDS Account Posting..................

                if (dTdsAmnt > 0 && IAcntIdno > 0)
                {
                    if (intValue > 0)
                    {
                        Int64 VchrNo = objclsAccountPosting.GetMaxVchrNo(4, 0, YearIdno);
                        intValue = objclsAccountPosting.InsertInVchrHead(
                            Convert.ToDateTime(ApplicationFunction.mmddyyyy(strDate)), 4, 0, "Challan No: " + Convert.ToString(intChlnNo) + " Challan Date: " + strDate + " Lorry: " + strLorryNo + "TDS Posting",
                            true, 0, strDocType, 0, 0, Convert.ToInt64(intChlnNo), ApplicationFunction.GetIndianDateTime().Date, VchrNo, 0,
                            YearIdno, 0, intUserIdno);
                        if (intValue > 0)
                        {
                            intVchrIdno = intValue;

                            #region TDS Account Posting .........

                            intValue = 0;
                            /*Insert In VchrDetl*/
                            intValue = objclsAccountPosting.InsertInVchrDetl(
                                intVchrIdno, Convert.ToInt64(IAcntIdno), "Challan No: " + Convert.ToString(intChlnNo) + " Challan Date: " + strDate + " Lorry: " + strLorryNo + "TDS Posting",
                                dTdsAmnt, Convert.ToByte(2), Convert.ToByte(0), "", true, null, //please check here if date is Blank
                                "", 0);
                            if (intValue > 0)
                            {
                                intValue = 0;
                                intValue = objclsAccountPosting.InsertInVchrDetl(
                                    intVchrIdno, IntTDSAcntIdno, "Challan. No: " + Convert.ToString(intChlnNo) + " Challan. Date: " + strDate + " Lorry: " + strLorryNo + "TDS Posting",
                                    Convert.ToDouble(dTdsAmnt), Convert.ToByte(1), Convert.ToByte(0), "", false,
                                    null,     //please check here if date is Blank
                                    "", 0);

                                if (intValue == 0)
                                {
                                    return(false);
                                }

                                if (intValue > 0)
                                {
                                    intValue = 0; /*Insert In VchrIdDetl*/
                                    intValue = objclsAccountPosting.InsertInVchrIdDetl(intVchrIdno, intDocIdno, strDocType);
                                    if (intValue == 0)
                                    {
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                return(false);
                            }

                            #endregion
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                #endregion

                #endregion
                objclsAccountPosting = null;
                return(true);
            }
            else
            {
                objclsAccountPosting = null;
                return(true);
            }
            #endregion
        }