Пример #1
0
        public string DoInvoice(InvoiceDataTypes.InvoiceDataType _SaveData)
        {
            Invoice MyInvoice = new Invoice(IsLocalLoging);
            //===================================================================
            try
                {
                MySql.Data.MySqlClient.MySqlTransaction Mytrans;
                MySqlConnection CurCon = new MySqlConnection();
                CurCon = Mycommon.AccountConnection;
                string respond = "";
                decimal FullPayment = 0;
                if (CurCon.State == ConnectionState.Open)
                    {
                    CurCon.Close();
                    CurCon.Open();
                    }
                else
                    {
                    CurCon.Open();
                    }
                Mytrans = Mycommon.AccountConnection.BeginTransaction();
                //===============================================================
                
                string MainAccountRef = "", TrReference = "", PVNNumber = "";
                MainAccountRef = GetAccReference(_SaveData.AccountID, CurCon);
                int Counter = 0;
                string DrAccRef = "";
                string macAdd = MyGeneral.GetMACAddress();

                if (_SaveData.InvoiceDtails.Count > 0)
                    {
                    foreach (InvoiceDataTypes.InvoiceDetailsDataType _OneData in _SaveData.InvoiceDtails)
                        {
                            AccountTransactionType.AccountTransactionDataType _OneTrans = new AccountTransactionType.AccountTransactionDataType();
                            string TransRefDr = "";

                            string AccRef = GetAccReference(_OneData.AccID, CurCon);
                            Counter += 1;
                            if (Counter < 5)
                                DrAccRef = DrAccRef + "," + AccRef;
                            _OneTrans.AccountID = _OneData.AccID;
                            _OneTrans.AccountYear = _SaveData.AccPeriod;
                            _OneTrans.ActualDate = _SaveData.InvoiceDate;
                            _OneTrans.CompanyID = _SaveData.CompanyID;
                            _OneTrans.Cr =  _OneData.Cr;
                            _OneTrans.CurRate = _SaveData.CurRate;
                            _OneTrans.Description = _OneData.Description;
                            _OneTrans.Dr =0;
                            _OneTrans.FDr = 0;
                            _OneTrans.FCr = _OneData.FCr;
                            _OneTrans.MainRef = AccRef;
                            _OneTrans.PayMethod = 5;
                            _OneTrans.RelRef = MainAccountRef;
                            _OneTrans.TransType = 4;
                            _OneTrans.TrMachine = macAdd;
                            _OneTrans.TrUser = _SaveData.TrUser;
                            _OneTrans.VoucherID = _SaveData.InvoiceNo;
                            FullPayment = FullPayment + _OneData.Cr;
                            respond = SaveAccountTransaction(_OneTrans, CurCon, out TransRefDr);
                            if (respond != "True")
                                {
                                    Mytrans.Rollback();
                                    CurCon.Close();
                                    return respond;
                                }
                            else
                            {
                            respond = UpdateTranseRefinReleventTable(4, false, TransRefDr, _SaveData.InvoiceNo , _OneData.ItemNo.ToString(), CurCon);
                            if (respond != "True")
                                {
                                    Mytrans.Rollback();
                                    CurCon.Close();
                                    return respond;
                                }
                            else
                                {
                                respond = UpdateLastRefonAccount(_OneTrans.AccountID, AccRef, CurCon);
                                if (respond != "True")
                                    {
                                        Mytrans.Rollback();
                                        CurCon.Close();
                                        return respond;
                                    }
                                }
                            }
                        }

                        if (respond != "True")
                            {
                                Mytrans.Rollback();
                                CurCon.Close();
                                return respond;
                            }
                            else
                            {
                            AccountTransactionType.AccountTransactionDataType _SaveTranData = new AccountTransactionType.AccountTransactionDataType();

                                _SaveTranData.AccountID = _SaveData.AccountID;       //1
                                _SaveTranData.AccountYear = _SaveData.AccPeriod;     //2
                                _SaveTranData.Description = _SaveData.Description;   //3
                                _SaveTranData.CompanyID = _SaveData.CompanyID;       //4
                                _SaveTranData.Cr = 0;                                //5
                                _SaveTranData.CurRate = _SaveData.CurRate;           //6
                                _SaveTranData.Dr = _SaveData.Dr;                     //7
                                _SaveTranData.FCr = 0;                               //8
                                _SaveTranData.FDr = _SaveData.FDr; ;                 //9
                                _SaveTranData.MainRef = MainAccountRef;              //10
                                _SaveTranData.PayMethod = 5;                         //11
                                _SaveTranData.TrID = TrReference;                    //12
                                _SaveTranData.TransType = 2;                         //13
                                _SaveTranData.RelRef = DrAccRef;                     //14
                                _SaveTranData.TrMachine = macAdd;                    //14
                                _SaveTranData.VoucherID = _SaveData.InvoiceNo ;      //15
                                _SaveTranData.TrUser = _SaveData.TrUser;             //16
                                _SaveTranData.ActualDate = _SaveData.InvoiceDate;    //17
                                respond = SaveAccountTransaction(_SaveTranData, CurCon, out TrReference);
                                if (respond != "True")
                                    {
                                        Mytrans.Rollback();
                                        CurCon.Close();
                                        return respond;
                                    }
                                else
                                    {
                                    respond = UpdateTranseRefinReleventTable(4, true, MainAccountRef, _SaveData.InvoiceNo, "", CurCon);
                                    if (respond != "True")
                                        {
                                        Mytrans.Rollback();
                                        CurCon.Close();
                                        return respond;
                                        }
                                    else
                                        {
                                        respond = UpdateLastRefonAccount(_SaveData.AccountID, MainAccountRef, CurCon);
                                        if (respond != "True")
                                            {
                                            Mytrans.Rollback();
                                            CurCon.Close();
                                            return respond;
                                            }
                                        else
                                            { 
                                                //=====================================
                                                InvoiceDataTypes.PendingInvoiceDataType _PendingInvoice = new InvoiceDataTypes.PendingInvoiceDataType();
                                                _PendingInvoice.AccountID = _SaveData.AccountID;
                                                _PendingInvoice.AccPeriod = _SaveData.AccPeriod;
                                                _PendingInvoice.BillStatus = 0;
                                                _PendingInvoice.CompanyID = _SaveData.CompanyID;
                                                _PendingInvoice.CurRate = _SaveData.CurRate;
                                                _PendingInvoice.Customer = _SaveData.RcvFromID;
                                                _PendingInvoice.Description = _SaveData.Description;
                                                _PendingInvoice.Dr = _SaveData.Dr;
                                                _PendingInvoice.FDr = _SaveData.FDr;
                                                _PendingInvoice.InvoiceNo = _SaveData.InvoiceNo;
                                                _PendingInvoice.InvoiceNoDate = _SaveData.InvoiceDate;
                                                _PendingInvoice.RevievedAmount = 0;
                                                _PendingInvoice.TobeRcvDate = _SaveData.TobeRcvDate;
                                                _PendingInvoice.TotalAmount = _SaveData.Dr;
                                                respond = MyInvoice.SavePending(_PendingInvoice, CurCon);
                                                if (respond != "True")
                                                    {
                                                    Mytrans.Rollback();
                                                    CurCon.Close();
                                                    return respond;
                                                    }
                                                else
                                                    {
                                                        if (respond != "True")
                                                        {
                                                            Mytrans.Rollback();
                                                            CurCon.Close();
                                                            return respond;
                                                        }
                                                        else
                                                        {
                                                            respond =MyInvoice .InvoiceAccountUpdated( _SaveData.InvoiceNo, _SaveData.TrUser,CurCon);
                                                            if (respond == "True")
                                                            {
                                                                Mytrans.Commit();
                                                                CurCon.Close();
                                                                return "True";
                                                            }
                                                            else
                                                            {
                                                                Mytrans.Rollback();
                                                                CurCon.Close();
                                                                return respond;
                                                            }
                                                           
                                                        }
                                                      
                                                    }
                                                //=====================================
                                            }
                                        }
                                    }
                            }
                    }
                else
                    {
                    Mytrans.Rollback();
                    CurCon.Close();
                    return "No Details to save";
                    }

                }
            catch (Exception ex)
                {
                return ex.Message;
                }
        }
Пример #2
0
 public string GetExistPendingReceivebleInvoice(int Customer, string InvoiceNo, out InvoiceDataTypes.PendingInvoiceDataType  _ExistData)
     {
     _ExistData = new InvoiceDataTypes.PendingInvoiceDataType();
     
     MySqlCommand oSqlCommand = new MySqlCommand();
     string sqlQuery = "Select "
   + "CompanyID,"
   + "Customer,"
   + "InvoiceNo,"
   + "Description,"
   + "AccountID,"
   + "CurRate,"
   + "Dr,"
   + "FDr,"
   + "BillStatus,"
   + "AccPeriod,"
   + "TotalAmount,"
   + "RevievedAmount,"
   + "TobeRcvDate,"
   + "InvoiceNoDate"
   + " from tblpendingrecievebleinvoice"
   + " Where 1=1 "
         + " and Customer=@Customer"
         + " and InvoiceNo=@InvoiceNo";
     oSqlCommand.Parameters.AddWithValue("@Customer", Customer);
     oSqlCommand.Parameters.AddWithValue("@InvoiceNo", InvoiceNo);
     DataRow r = Mycommon.GetDataRow(sqlQuery, oSqlCommand, null, "Get Exist data PendingReceivebleInvoice");
     if (r != null)
         {
         try
             {
             bool resp = false;
             int inCompanyID = 0;
             resp = int.TryParse(r["CompanyID"].ToString(), out inCompanyID);
             _ExistData.CompanyID = inCompanyID;
             int inCustomer = 0;
             resp = int.TryParse(r["Customer"].ToString(), out inCustomer);
             _ExistData.Customer = inCustomer;
             _ExistData.InvoiceNo = r["InvoiceNo"].ToString();
             _ExistData.Description = r["Description"].ToString();
             _ExistData.AccountID = r["AccountID"].ToString();
             decimal deCurRate = 0;
             resp = decimal.TryParse(r["CurRate"].ToString(), out deCurRate);
             _ExistData.CurRate = deCurRate;
             decimal deDr = 0;
             resp = decimal.TryParse(r["Dr"].ToString(), out deDr);
             _ExistData.Dr = deDr;
             decimal deFDr = 0;
             resp = decimal.TryParse(r["FDr"].ToString(), out deFDr);
             _ExistData.FDr = deFDr;
             int inBillStatus = 0;
             resp = int.TryParse(r["BillStatus"].ToString(), out inBillStatus);
             _ExistData.BillStatus = inBillStatus;
             int inAccPeriod = 0;
             resp = int.TryParse(r["AccPeriod"].ToString(), out inAccPeriod);
             _ExistData.AccPeriod = inAccPeriod;
             decimal deTotalAmount = 0;
             resp = decimal.TryParse(r["TotalAmount"].ToString(), out deTotalAmount);
             _ExistData.TotalAmount = deTotalAmount;
             decimal deRevievedAmount = 0;
             resp = decimal.TryParse(r["RevievedAmount"].ToString(), out deRevievedAmount);
             _ExistData.RevievedAmount = deRevievedAmount;
             DateTime dtTobeRcvDate = new DateTime(1900, 1, 1);
             resp = DateTime.TryParse(r["TobeRcvDate"].ToString(), out dtTobeRcvDate);
             if (resp)
                 _ExistData.TobeRcvDate = dtTobeRcvDate;
             else
                 _ExistData.TobeRcvDate = new DateTime(1900, 1, 1);
             DateTime dtInvoiceNoDate = new DateTime(1900, 1, 1);
             resp = DateTime.TryParse(r["InvoiceNoDate"].ToString(), out dtInvoiceNoDate);
             if (resp)
                 _ExistData.InvoiceNoDate = dtInvoiceNoDate;
             else
                 _ExistData.InvoiceNoDate = new DateTime(1900, 1, 1);
             return "True";
             }
         catch (Exception ex)
             {
             return ex.Message;
             }
         }
     else
         return "data not found ";
     }