Exemple #1
0
        private void frmBill_Load(object sender, EventArgs e)
        {
            MyBill = new Billing(Program.AccountStatic.LoggingAsLocal);
            MyCommon = new CommonOperations(Program.AccountStatic.LoggingAsLocal);
            MyAccount = new AccountCreation(Program.AccountStatic.LoggingAsLocal);
          
            panel1.Top = (this.Height - panel1.Height) / 2;
            panel1.Left = (this.Width - panel1.Width) / 2;
            //MyAccount.LoadSupplier(cmbSupplier);
            //MyAccount.LoadSupplier(cmbSearchSupplier);
            //Edit by manjula   *** Load suppliers from MRP
            LoadSuppliers();

            MyCommon.LoadStatusComboAccount(cmbStatus, 4);
            EditScreen(false);
        }
        public string DoBillTransaction(BillingDataTypes.BillingDataType _SaveData)
        {
            Billing  MyBill= new Billing(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();
                MySqlCommand oSqlCommand = new MySqlCommand();

                string MainAccountRef = "", TrReference = "", PVNNumber = "";
                MainAccountRef = GetAccReference(_SaveData.AccountID, CurCon);
                int Counter = 0;
                string DrAccRef = "";
                string macAdd = MyGeneral.GetMACAddress();
                foreach (BillingDataTypes.BillingDetailsDataType _OneData in _SaveData.BillingDetails)
                {
                    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.BillDate;
                    _OneTrans.CompanyID = _SaveData.CompanyID;
                    _OneTrans.Cr = 0;
                    _OneTrans.CurRate = _SaveData.CurRate;
                    _OneTrans.Description = _OneData.Description;
                    _OneTrans.Dr = _OneData.Dr;
                    _OneTrans.FCr = 0;
                    _OneTrans.FDr = _OneData.Fdr ;
                    _OneTrans.MainRef = AccRef;
                    _OneTrans.PayMethod = 5;
                    _OneTrans.RelRef = MainAccountRef;
                    _OneTrans.TransType = 2;
                    _OneTrans.TrMachine = macAdd;
                    _OneTrans.TrUser = _SaveData.TrUser;
                    _OneTrans.VoucherID = _SaveData.BillNo;
                    FullPayment = FullPayment + _OneData.Dr;
                    respond = SaveAccountTransaction(_OneTrans, CurCon, out TransRefDr);
                    if (respond != "True")
                    {
                        Mytrans.Rollback();
                        CurCon.Close();
                        return respond;
                    }
                    else
                    {
                        respond = UpdateTranseRefinReleventTable(2, true, TransRefDr, _SaveData.BillNo, _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 = _SaveData.Cr;                     //5
                    _SaveTranData.CurRate = _SaveData.CurRate;           //6
                    _SaveTranData.Dr = 0;                               //7
                    _SaveTranData.FCr = _SaveData.FCr ; //8
                    _SaveTranData.FDr = 0;                              //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.BillNo;       //15
                    _SaveTranData.TrUser = _SaveData.TrUser;          //16
                    _SaveTranData.ActualDate = _SaveData.BillDate;

                    respond = SaveAccountTransaction(_SaveTranData, CurCon, out TrReference);

                    if ( FullPayment != _SaveData.Cr)
                    {
                        Mytrans.Rollback();
                        CurCon.Close();
                        return "Amount Not balance";
                    }

                    if (respond != "True")
                    {
                        Mytrans.Rollback();
                        CurCon.Close();
                        return respond;
                    }
                    else
                    {
                        respond = UpdateTranseRefinReleventTable(2, false, TrReference, _SaveData.BillNo, "", 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
                            {
                                BillingDataTypes.PendingPaymentDataType _SavependingData = new BillingDataTypes.PendingPaymentDataType();
                                _SavependingData.AccountID = _SaveData.AccountID;
                                _SavependingData.AccPeriod = _SaveData.AccPeriod;
                                _SavependingData.BillDate = _SaveData.BillDate;
                                _SavependingData.BillNo = _SaveData.BillNo;
                                _SavependingData.BillStatus = 0;
                                _SavependingData.CompanyID = _SaveData.CompanyID;
                                _SavependingData.Cr = _SaveData.Cr;
                                _SavependingData.CurRate = _SaveData.CurRate;
                                _SavependingData.Description = _SaveData.Description;
                                _SavependingData.FCr = _SaveData.FCr;
                                _SavependingData.PayedAmount = 0;
                                _SavependingData.Supplier = _SaveData.PayToID;
                                _SavependingData.TobePayDate = _SaveData.TobePayDate;
                                _SavependingData.TotalAmount = _SaveData.Cr;
                                 respond = MyBill.SavePP(_SavependingData, CurCon);
                                if (respond != "True")
                                {
                                    Mytrans.Rollback();
                                    CurCon.Close();
                                    return respond;
                                }
                                else
                                {
                                  //respond =  SetBillGetToLog(_SaveData.BillNo, _SaveData.PayToID);

                                    Mytrans.Commit();
                                    CurCon.Close();
                                    return "True";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
               return ex.Message;
            }
           
        }