Beispiel #1
0
        private void syncAllContractsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            clsSqlFactory hSql   = new clsSqlFactory();
            String        strSql = "exec ZSC_SP_SyncContractToAM '" + NWDBName + "', null";

            hSql.NewCommand(strSql);
            hSql.ExecuteNonQuery();
            hSql.Commit();
            hSql.Close();
        }
Beispiel #2
0
 private void syncSelectedContractToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow r in this.gridContract.SelectedRows)
     {
         ContractOid = (int)r.Cells["colCcontractOID"].Value;
     }
     if (ContractOid > 0)
     {
         clsSqlFactory hSql   = new clsSqlFactory();
         String        strSql = "exec ZSC_SP_SyncContractToAM '" + NWDBName + "'," + ContractOid.ToString();
         hSql.NewCommand(strSql);
         hSql.ExecuteNonQuery();
         hSql.Commit();
         hSql.Close();
     }
 }
Beispiel #3
0
        public bool saveOrder(bool bDraft)
        {
            bool            bRet    = true;
            clsSqlFactory   hSql    = new clsSqlFactory();
            clsBaseUtility  objUtil = new clsBaseUtility();
            clsCurrExchange objCurr = new clsCurrExchange();

            objCurr.Init();
            String strSql = "";

            try
            {
                if (bDraft == false)
                {
                    strSql = "select V1 from " + objUtil.getTable("CORW", UnitId) + " where CODAID='VLASKUTYY' and C1=? ";
                    bRet   = bRet && hSql.NewCommand(strSql);
                    hSql.Com.Parameters.AddWithValue("BTYPE", BTYPE);
                    hSql.ExecuteReader();
                    if (hSql.Read())
                    {
                        int NuseId = hSql.Reader.GetInt32(0);
                        strSql = "update " + objUtil.getTable("NUSE", UnitId) + " set RECNO=RECNO+1 where NUSEID=? ";
                        bRet   = bRet && hSql.NewCommand(strSql);
                        hSql.Com.Parameters.AddWithValue("NUSEID", NuseId);
                        hSql.ExecuteNonQuery();
                        strSql = "select RECNO from " + objUtil.getTable("NUSE", UnitId) + " where NUSEID=? ";
                        bRet   = bRet && hSql.NewCommand(strSql);
                        hSql.Com.Parameters.AddWithValue("NUSEID", NuseId);
                        hSql.ExecuteReader();
                        if (hSql.Read())
                        {
                            SRECNO = hSql.Reader.GetInt32(0);
                        }
                        else
                        {
                            bDraft = true;
                        }
                    }
                    else
                    {
                        bDraft = true;
                    }
                }
                strSql = "select top 1 isnull(SSALID,0), isnull(SORDNO,0) from " + objUtil.getTable("SSALSEED", UnitId);
                bRet   = bRet && hSql.ExecuteReader(strSql);
                if (bRet && hSql.Read())
                {
                    SSALID = hSql.Reader.GetInt32(0) + 1;
                    SORDNO = hSql.Reader.GetInt32(1) + 1;

                    strSql = "update " + objUtil.getTable("SSALSEED", UnitId) + " set SSALID = SSALID + 1, SORDNO = SORDNO + 1 ";
                    bRet   = bRet && hSql.ExecuteNonQuery(strSql);
                }
                strSql = "insert into " + objUtil.getTable("SSAL", UnitId) +
                         "(CREATED,SSALID, CUSTNO, SMANID, DEPT, STATUS,RECTYPE, RECORDID, SORDNO, STYPE, " +
                         " DIVISION, ISDIVIDED, BOPRIOR, OUSRSID, CDTRAN,NOTE,RDATE,EXIDNO,VEHIID)" +
                         " values (getdate(),?, ?, ?,?, ?, ?, 0, ?, ?, 0, 0, 0, ?, 0, ?,?,?,?) ";
                bRet = bRet && hSql.NewCommand(strSql);
                hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                hSql.Com.Parameters.AddWithValue("CUSTNO", CustNo);
                hSql.Com.Parameters.AddWithValue("SMANID", SmanId);
                if (DeptId != null)
                {
                    hSql.Com.Parameters.AddWithValue("DEPT", DeptId);
                }
                else
                {
                    hSql.Com.Parameters.AddWithValue("DEPT", DBNull.Value);
                }

                if (bDraft == true)
                {
                    hSql.Com.Parameters.AddWithValue("STATUS", 'A');
                    hSql.Com.Parameters.AddWithValue("RECTYPE", DBNull.Value);
                }
                else
                {
                    hSql.Com.Parameters.AddWithValue("STATUS", 'S');
                    if (BTYPE == "0")
                    {
                        hSql.Com.Parameters.AddWithValue("RECTYPE", 'E');
                    }
                    else
                    {
                        hSql.Com.Parameters.AddWithValue("RECTYPE", 'N');
                    }
                }
                hSql.Com.Parameters.AddWithValue("SORDNO", SORDNO);
                hSql.Com.Parameters.AddWithValue("STYPE", SalesType);
                hSql.Com.Parameters.AddWithValue("OUSRSID", OUserId);
                hSql.Com.Parameters.AddWithValue("NOTE", Note);
                hSql.Com.Parameters.AddWithValue("RDATE", DELD.ToString("yyyy-MM-dd"));
                hSql.Com.Parameters.AddWithValue("EXIDNO", ExtOrderId);
                hSql.Com.Parameters.AddWithValue("VEHIID", VehiId);
                bRet = bRet && hSql.ExecuteNonQuery();


                strSql = "insert into " + objUtil.getTable("SBIL", UnitId) +
                         "(SSALID, SRECNO, CUSTNO, LCUSTNO, DCUSTNO, " +
                         " REFE, DDEL, DWP,  PDEL," +
                         " CURRCD, BTYPE,BILLD,BILLD_WITH_TIME,HSMANID,DELD,TPCODE,TPTIME)" +
                         " values (?, ?, ?, ?, ?," +
                         " ?, 0, 0, 1, " +
                         "?,?,?,?,?,?,?,?) ";
                bRet = bRet && hSql.NewCommand(strSql);
                hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                hSql.Com.Parameters.AddWithValue("SRECNO", SRECNO);
                hSql.Com.Parameters.AddWithValue("CUSTNO", CustNo);
                hSql.Com.Parameters.AddWithValue("LCUSTNO", CustNo);
                hSql.Com.Parameters.AddWithValue("DCUSTNO", DCustNo);
                hSql.Com.Parameters.AddWithValue("REFE", Note.Length > 45 ? Note.Substring(0, 45) : Note);
                hSql.Com.Parameters.AddWithValue("CURRCD", objCurr.BaseCurrency);
                hSql.Com.Parameters.AddWithValue("BTYPE", BTYPE);
                if (bDraft == true)
                {
                    hSql.Com.Parameters.AddWithValue("BILLD", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("BILLD_WITH_TIME", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("HSMANID", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("DELD", DBNull.Value);
                }
                else
                {
                    hSql.Com.Parameters.AddWithValue("BILLD", new DateTime(BILLD.Year, BILLD.Month, BILLD.Day));
                    hSql.Com.Parameters.AddWithValue("BILLD_WITH_TIME", DateTime.Now);
                    hSql.Com.Parameters.AddWithValue("HSMANID", SmanId);
                    hSql.Com.Parameters.AddWithValue("DELD", new DateTime(DELD.Year, DELD.Month, DELD.Day));
                }

                hSql.Com.Parameters.AddWithValue("TPCODE", TPCODE);
                hSql.Com.Parameters.AddWithValue("TPTIME", TPTIME);

                bRet = bRet && hSql.ExecuteNonQuery();

                strSql = "update a set a.AGRP = b.AGRP, a.CUSTNAME = ltrim(isnull(b.FNAME,'')+' ' +isnull(b.LNAME,'')) from " +
                         objUtil.getTable("SBIL", UnitId) + " a, CUST b where a.SSALID=? and a.CUSTNO = b.CUSTNO ";
                bRet = bRet && hSql.NewCommand(strSql);
                hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                bRet = bRet && hSql.ExecuteNonQuery();

                strSql = "update a set a.DADDR1 = b.ADDR1, a.DADDR2 = b.ADDR2,a.DCTRYCD=b.CTRYCD,a.DCOUNTRY=b.COUNTRY," +
                         " a.DNAME= ltrim(isnull(b.FNAME,'')+' ' +isnull(b.LNAME,'')), a.DPO=b.PO,a.DPOSTCD=b.POSTCD,a.DADDR2E=b.ADDR2E from " +
                         objUtil.getTable("SBIL", UnitId) + " a, CUST b where a.SSALID=? and a.DCUSTNO = b.CUSTNO ";
                bRet = bRet && hSql.NewCommand(strSql);
                hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                bRet = bRet && hSql.ExecuteNonQuery();

                strSql = "insert into ZSC_ContractInvoice(ContractOID,InvoiceNo,SSALID,UnitId,InvoiceType,Created,Modified) select  " +
                         "?,?,SSALID,?,0,getdate(),getdate() from " + objUtil.getTable("SBIL", UnitId) + " where SSALID=?";
                bRet = bRet && hSql.NewCommand(strSql);
                hSql.Com.Parameters.AddWithValue("ContractOID", ContractOID);
                hSql.Com.Parameters.AddWithValue("InvoiceNo", InvoiceSeqNr);
                hSql.Com.Parameters.AddWithValue("UnitId", UnitId);
                hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                bRet = bRet && hSql.ExecuteNonQuery();

                strSql = "update ZSC_Contract set LastInvoiceDate = ?,NextInvoiceDate=? where OID=?";
                bRet   = bRet && hSql.NewCommand(strSql);

                hSql.Com.Parameters.AddWithValue("CBILLD", CBILLD);
                hSql.Com.Parameters.AddWithValue("NBILLD", NBILLD);
                hSql.Com.Parameters.AddWithValue("ContractOID", ContractOID);
                bRet = bRet && hSql.ExecuteNonQuery();

                clsTaxHandling objTax = new clsTaxHandling();
                objTax.Init(6);



                foreach (SCInvoiceItem objRow in InvItems)
                {
                    strSql = "insert into " + objUtil.getTable("SROW", UnitId) + "(CREATED,SSALID, SROWID, SRECNO, SMANID, ITEMNO, SUPLNO, BUYPR, " +
                             " DISCPC, ITEM, SUPL, NAME, NUM, RNO, RTYPE, RSUM, UNITPR, VATCD, " +
                             " ONDEDNUM, ORDNUM, IGROUPID,NOTE,RINFO,EXIDNO) values (getdate(),?,?,?,?,?,?,?," +
                             " ?,?,?,?,?,?,?,?,?,?," +
                             "0,?,?,?,?,?)";
                    bRet = bRet && hSql.NewCommand(strSql);
                    hSql.Com.Parameters.AddWithValue("SSALID", SSALID);
                    hSql.Com.Parameters.AddWithValue("SROWID", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("SRECNO", SRECNO);
                    hSql.Com.Parameters.AddWithValue("SMANID", SmanId);
                    hSql.Com.Parameters.AddWithValue("ITEMNO", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("SUPLNO", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("BUYPR", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("DISCPC", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("ITEM", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("SUPL", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("NAME", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("NUM", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("RNO", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("RTYPE", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("RSUM", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("UNITPR", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("VATCD", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("ORDNUM", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("IGROUPID", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("NOTE", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("RINFO", DBNull.Value);
                    hSql.Com.Parameters.AddWithValue("EXIDNO", DBNull.Value);

                    if (objRow.RTYPE != 8)
                    {
                        hSql.Com.Parameters["SROWID"].Value = objRow.SROWID;
                        hSql.Com.Parameters["ITEMNO"].Value = objRow.ITEMNO;
                        hSql.Com.Parameters["SUPLNO"].Value = objRow.SUPLNO;
                        hSql.Com.Parameters["BUYPR"].Value  = objRow.BUYPR;
                        hSql.Com.Parameters["DISCPC"].Value = objRow.DISCPC;
                        hSql.Com.Parameters["ITEM"].Value   = objRow.ITEMNO;
                        hSql.Com.Parameters["SUPL"].Value   = objRow.SUPLNO;
                        hSql.Com.Parameters["NAME"].Value   = objRow.NAME;
                        hSql.Com.Parameters["NUM"].Value    = objRow.NUM;
                        hSql.Com.Parameters["RNO"].Value    = objRow.SROWID;
                        hSql.Com.Parameters["RTYPE"].Value  = objRow.RTYPE;
                        hSql.Com.Parameters["RSUM"].Value   = objRow.RSUM;
                        hSql.Com.Parameters["UNITPR"].Value = objRow.UNITPR;
                        hSql.Com.Parameters["VATCD"].Value  = objRow.VATCD;
                        hSql.Com.Parameters["ORDNUM"].Value = objRow.NUM;
                        if (objRow.IGROUPID > 0)
                        {
                            hSql.Com.Parameters["IGROUPID"].Value = objRow.IGROUPID;
                        }
                        hSql.Com.Parameters["EXIDNO"].Value = objRow.EXIDNO;
                    }
                    else
                    {
                        hSql.Com.Parameters["SROWID"].Value = objRow.SROWID;
                        hSql.Com.Parameters["NAME"].Value   = objRow.NAME;
                        hSql.Com.Parameters["RNO"].Value    = objRow.SROWID;
                        hSql.Com.Parameters["RTYPE"].Value  = objRow.RTYPE;
                        hSql.Com.Parameters["NOTE"].Value   = objRow.NOTE;
                        if ((objRow.RINFO != null) && (objRow.RINFO != ""))
                        {
                            hSql.Com.Parameters["RINFO"].Value = objRow.RINFO;
                        }
                        hSql.Com.Parameters["EXIDNO"].Value = objRow.EXIDNO;
                    }
                    hSql.ExecuteNonQuery();
                }

                hSql.Commit();
            }
            catch (Exception ex)
            {
                hSql.Rollback();
                throw ex;
            }
            finally
            {
                hSql.Close();
            }

            return(bRet);
        }
Beispiel #4
0
        public bool invoiceContract(Contract objContract, bool bDraft, bool bManual)
        {
            bool          bRet         = true;
            int           InvoiceSeqNr = 0;
            clsSqlFactory hSql         = new clsSqlFactory();

            hSql.NewCommand("select isnull(max(InvoiceNo),0) from ZSC_ContractInvoice where ContractOID=? ");
            hSql.Com.Parameters.Add("ContractOID", objContract.ContractOID);
            hSql.ExecuteReader();
            if (hSql.Read())
            {
                InvoiceSeqNr  = hSql.Reader.GetInt32(0);
                InvoiceSeqNr += 1;
            }
            List <String> Payers = new List <String>();

            hSql.NewCommand("select distinct PartialPayer from ZSC_ContractOption where ContractOid = ? and PartialPayer is not null and PartialPayer != '' and SelPr!=0 ");
            hSql.Com.Parameters.Add("ContractOID", objContract.ContractOID);
            hSql.ExecuteReader();
            while (hSql.Read())
            {
                Payers.Add(hSql.Reader.GetString(0));
            }

            if (objContract.ContractPaymentData.PaymentIsInBlock == false)
            {
                if (objContract.LastInvoiceDate <= objContract.ContractDateData.InvoiceEndDate)
                {
                    bRet = invoiceContract(objContract, bDraft, bManual, "", InvoiceSeqNr, false);
                    foreach (String Payer in Payers)
                    {
                        bRet = invoiceContract(objContract, bDraft, bManual, Payer, InvoiceSeqNr, false);
                    }

                    if ((objContract.ContractCapitalData.CapitalMonthAmount != 0) && (objContract.ContractCapitalData.CapitalMonthPayer.strValue1 != ""))
                    {
                        bRet = bRet && invoiceContract(objContract, bDraft, bManual, objContract.ContractCapitalData.CapitalMonthPayer.strValue1, InvoiceSeqNr, true);
                    }
                }
            }
            else
            {
                objContract.calcPaymentBlock(true);
                DateTime dtNextBlockEnd = objContract.ContractPaymentData.PaymentNextBlockEnd;
                if (objContract.NextInvoiceDate == DateTime.MinValue)
                {
                    objContract.NextInvoiceDate = DateTime.Now;
                }

                while ((objContract.NextInvoiceDate <= dtNextBlockEnd) && (objContract.LastInvoiceDate <= objContract.ContractDateData.InvoiceEndDate))
                {
                    bRet = invoiceContract(objContract, bDraft, bManual, "", InvoiceSeqNr, false);
                    foreach (String Payer in Payers)
                    {
                        bRet = invoiceContract(objContract, bDraft, bManual, Payer, InvoiceSeqNr, false);
                    }

                    if ((objContract.ContractCapitalData.CapitalMonthAmount != 0) && (objContract.ContractCapitalData.CapitalMonthPayer.strValue1 != ""))
                    {
                        bRet = bRet && invoiceContract(objContract, bDraft, bManual, objContract.ContractCapitalData.CapitalMonthPayer.strValue1, InvoiceSeqNr, true);
                    }
                    objContract = SCBase.searchContracts(objContract.ContractOID);
                    InvoiceSeqNr++;
                }
                objContract.calcPaymentBlock(true);

                bRet = bRet && hSql.NewCommand("update ZSC_Contract set PaymentNextBlockStart = ?,PaymentNextBlockEnd=? where OID=?");

                hSql.Com.Parameters.AddWithValue("PaymentNextBlockStart", objContract.ContractPaymentData.PaymentNextBlockStart);
                hSql.Com.Parameters.AddWithValue("PaymentNextBlockEnd", objContract.ContractPaymentData.PaymentNextBlockEnd);
                hSql.Com.Parameters.AddWithValue("ContractOID", objContract.ContractOID);
                bRet = bRet && hSql.ExecuteNonQuery();
                if (bRet)
                {
                    hSql.Commit();
                    objContract = SCBase.searchContracts(objContract.ContractOID);
                }
                else
                {
                    hSql.Rollback();
                }
            }
            hSql.Close();
            return(bRet);
        }
Beispiel #5
0
        public bool closeCashBox(string strCashBoxId)
        {
            _log.Debug("closeCashBox >> " + strCashBoxId);
            bool          bRet         = true;
            clsSqlFactory hSql         = new clsSqlFactory();
            clsAppConfig  objAppConfig = new clsAppConfig();

            try
            {
                int     NUSEID     = objAppConfig.getNumberParam("CASHREG", "DEPRECNO", "V1", "");
                DataRow cashbox    = CashBoxes.Select(("CASHBOXID = '" + strCashBoxId + "'"))[0];
                int     EOD_NUSEID = Int32.Parse(cashbox["EODNUSEID"].ToString());

                hSql.NewCommand("select ISOPEN from " + objUtil.getTable("CASHBOX") + " where CASHBOXID=? and ISOPEN=1");
                hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                bRet = bRet && hSql.ExecuteReader();
                if (hSql.Read())
                {
                    hSql.NewCommand("update " + objUtil.getTable("NUSE") + " set RECNO=RECNO+1 where NUSEID=?");
                    hSql.Com.Parameters.AddWithValue("NUSEID", NUSEID);
                    bRet = bRet && hSql.ExecuteNonQuery();

                    hSql.NewCommand("select RECNO from " + objUtil.getTable("NUSE") + " where NUSEID=?");
                    hSql.Com.Parameters.AddWithValue("NUSEID", NUSEID);
                    bRet = bRet && hSql.ExecuteReader();
                    if (hSql.Read())
                    {
                        int RECEIPTNO = hSql.Reader.GetInt32(0);

                        //EOD_NUSEID
                        hSql.NewCommand("update " + objUtil.getTable("NUSE") + " set RECNO=RECNO+1 where NUSEID=?");
                        hSql.Com.Parameters.AddWithValue("NUSEID", EOD_NUSEID);
                        hSql.ExecuteNonQuery();

                        hSql.NewCommand("select RECNO from " + objUtil.getTable("NUSE") + " where NUSEID=?");
                        hSql.Com.Parameters.AddWithValue("NUSEID", EOD_NUSEID);
                        bRet = bRet && hSql.ExecuteReader();

                        if (hSql.Read())
                        {
                            int EOD_RECEIPTNO = hSql.Reader.GetInt32(0);
                            //
                            hSql.NewCommand("update " + objUtil.getTable("CASHBOX") + " set ISOPEN=0 where CASHBOXID=?");
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            hSql.ExecuteNonQuery();
                            hSql.NewCommand("insert into " + objUtil.getTable("CASHREG") + "(CASHBOXID,SMANID,EVENT,UPDATED_DATE,UPDATED_BY,RECEIPTNO,EOD_RECEIPTNO) values(?,?,'C',getdate(),?,?,?)");
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            hSql.Com.Parameters.AddWithValue("SMANID", objGlobal.DefaultSManID);
                            hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                            hSql.Com.Parameters.AddWithValue("RECEIPTNO", RECEIPTNO);
                            hSql.Com.Parameters.AddWithValue("EOD_RECEIPTNO", EOD_RECEIPTNO);
                            hSql.ExecuteNonQuery();
                            hSql.Com.Parameters.Clear();
                            hSql.NewCommand("SELECT @@IDENTITY");
                            bRet = bRet && hSql.ExecuteReader();
                            hSql.Read();
                            int nCashRegRowId = hSql.Reader.GetInt32(0);

                            hSql.NewCommand("select top 1 isnull(b.AMOUNT,0),a.UPDATED_DATE, isnull(b.QTY,0) from " + objUtil.getTable("CASHREG") + " a," +
                                            " CASHREGROW b where a.ROWID = b.CASHREGROWID and a.CASHBOXID = ? and a.EVENT = 'O' " +
                                            " order by a.UPDATED_DATE desc");
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            bRet = bRet && hSql.ExecuteReader();
                            hSql.Read();

                            DateTime dtLastOpen      = hSql.Reader.GetDateTime(1);
                            decimal  nOpeningBalance = hSql.Reader.GetDecimal(0);

                            decimal nOpeningQty = hSql.Reader.GetDecimal(2);

                            hSql.NewCommand("insert into " + objUtil.getTable("CASHREGROW") + "(CASHREGROWID,ROWNO,CASHFORM,CASHTYPE,AMOUNT,QTY,UPDATED_DATE,UPDATED_BY) " +
                                            " select ?, row_number() over (partition by getdate() order by getdate()),CASHFORM,CASHTYPE,isnull(TOTAMOUNT,0),isnull(TOTQTY,0),getdate(),? from " +
                                            "(select b.CASHFORM,case b.CASHFORM when 'CASH' then '" + ConfigurationSettings.AppSettings["DefaultCashType"] + "' else b.CASHTYPE end as CASHTYPE,sum(b.AMOUNT) as TOTAMOUNT,sum(b.QTY) as TOTQTY from " + objUtil.getTable("CASHTRANSH") + " a, " + objUtil.getTable("CASHTRANSR") + " b" +
                                            " where a.CASHBOXID =? and a.RECEIPTNO = b.RECEIPTNO and a.UPDATED_DATE >=? " +
                                            " group by b.CASHFORM,case b.CASHFORM when 'CASH' then '" + ConfigurationSettings.AppSettings["DefaultCashType"] + "' else b.CASHTYPE end ) x");
                            hSql.Com.Parameters.AddWithValue("CASHREGROWID", nCashRegRowId);
                            hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);

                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            hSql.Com.Parameters.AddWithValue("LASTOPEN", dtLastOpen);

                            bRet = bRet && hSql.ExecuteNonQuery();

                            hSql.NewCommand("select 1 from " + objUtil.getTable("CASHREGROW") + " where CASHREGROWID=? and CASHFORM in ('CASH','CURRENCY')");
                            hSql.Com.Parameters.AddWithValue("CASHREGROWID", nCashRegRowId);
                            bRet = bRet && hSql.ExecuteReader();
                            if (hSql.Read())
                            {
                                hSql.NewCommand("update " + objUtil.getTable("CASHREGROW") + " set AMOUNT=AMOUNT+?, QTY=QTY+? where CASHREGROWID=? and CASHFORM in ('CASH','CURRENCY') ");
                                hSql.Com.Parameters.AddWithValue("OPENBALANCE", nOpeningBalance);
                                hSql.Com.Parameters.AddWithValue("OPENQTY", nOpeningQty);
                                hSql.Com.Parameters.AddWithValue("CASHREGROWID", nCashRegRowId);
                                bRet = bRet && hSql.ExecuteNonQuery();
                            }
                            else
                            {
                                hSql.NewCommand("insert into " + objUtil.getTable("CASHREGROW") + "(CASHREGROWID,ROWNO,CASHFORM,CASHTYPE,AMOUNT,QTY,UPDATED_DATE,UPDATED_BY) values(" +
                                                "  ?, (select isnull(max(ROWNO),0)+1 from CASHREGROW where CASHREGROWID=? ),'CASH',?,?,?,getdate(),? )");
                                hSql.Com.Parameters.AddWithValue("CASHREGROWID", nCashRegRowId);
                                hSql.Com.Parameters.AddWithValue("CASHREGROWID2", nCashRegRowId);
                                hSql.Com.Parameters.AddWithValue("CASHTYPE", ConfigurationSettings.AppSettings["DefaultCashType"]);

                                hSql.Com.Parameters.AddWithValue("AMOUNT", nOpeningBalance);
                                hSql.Com.Parameters.AddWithValue("QTY", nOpeningQty);

                                hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);

                                hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                                bRet = bRet && hSql.ExecuteNonQuery();
                            }
                            //Update CASHTRANSH.EOD_RECEIPTNO

                            hSql.NewCommand("update " + objUtil.getTable("CASHTRANSH") + " set EOD_RECEIPTNO =? where CASHBOXID =? and EOD_RECEIPTNO is null and UPDATED_DATE >=?");
                            hSql.Com.Parameters.AddWithValue("EOD_RECEIPTNO", EOD_RECEIPTNO);
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            hSql.Com.Parameters.AddWithValue("LASTOPEN", dtLastOpen);
                            bRet = bRet && hSql.ExecuteNonQuery();
                            //
                            hSql.NewCommand("delete from " + objUtil.getTable("CASHBOXPC") + " where CASHBOXID = ?");
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                            bRet = bRet && hSql.ExecuteNonQuery();
                        }
                        else
                        {
                            bRet = false;
                            throw new Exception("Invalid EODNUSEID (CASHBOXID.V3) ): " + NUSEID);
                        }
                    }
                    else
                    {
                        bRet = false;
                        throw new Exception("Invalid NUSEID (CASHREG.DEPRECNO): " + NUSEID);
                    }
                }
                else
                {
                    bRet = false;
                }
                if (bRet)
                {
                    hSql.Commit();
                }
                else
                {
                    hSql.Rollback();
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                hSql.Rollback();
                bRet = false;
                throw ex;
            }
            finally
            {
                hSql.Close();
            }
            _log.Debug("closeCashBox >> " + bRet.ToString());
            return(bRet);
        }
Beispiel #6
0
        public bool openCashBox(string strCashBoxId, decimal nOpeningBalance, decimal nQty)
        {
            bool bRet = true;

            _log.Debug("openCashBox >> SmanId = " + objGlobal.DefaultSManID + ", UserName  = "******"select ISOPEN from " + objUtil.getTable("CASHBOX") + " where CASHBOXID=?");
                hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                hSql.ExecuteReader();
                if (hSql.Read())
                {
                    if (hSql.Reader.GetInt16(0) == 1)
                    {
                        bRet = false;
                    }
                    else
                    {
                        hSql.NewCommand("update " + objUtil.getTable("CASHBOX") + " set ISOPEN=1 where CASHBOXID=?");
                        hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                        bRet = hSql.ExecuteNonQuery();
                    }
                }
                else
                {
                    hSql.NewCommand("insert into " + objUtil.getTable("CASHBOX") + "(CASHBOXID,ISOPEN) values(?,1)");
                    hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                    bRet = hSql.ExecuteNonQuery();
                }
                string strComputerName = getClientPCName();
                hSql.NewCommand("select 1 from " + objUtil.getTable("CASHBOXPC") + " where CASHBOXID=? and PC=?");
                hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                hSql.Com.Parameters.AddWithValue("PC", strComputerName);
                bRet = bRet && hSql.ExecuteReader();
                //clsGlobalVariable objGlobal = new clsGlobalVariable();
                if (bRet)
                {
                    if (hSql.Read())
                    {
                        hSql.NewCommand("update " + objUtil.getTable("CASHBOXPC") + " set UPDATED_DATE=getdate(),UPDATED_BY=? where CASHBOXID=? and PC=?");
                        hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                        hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                        hSql.Com.Parameters.AddWithValue("PC", strComputerName);
                        bRet = bRet && hSql.ExecuteNonQuery();
                    }
                    else
                    {
                        hSql.NewCommand("insert into " + objUtil.getTable("CASHBOXPC") + "(CASHBOXID,PC,UPDATED_DATE,UPDATED_BY) values(?,?,getdate(),?)");
                        hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                        hSql.Com.Parameters.AddWithValue("PC", strComputerName);
                        hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);

                        bRet = bRet && hSql.ExecuteNonQuery();
                    }
                }
                if (bRet)
                {
                    hSql.NewCommand("insert into " + objUtil.getTable("CASHREG") + "(CASHBOXID,SMANID,EVENT,UPDATED_DATE,UPDATED_BY) values(?,?,'O',getdate(),?)");
                    hSql.Com.Parameters.AddWithValue("CASHBOXID", strCashBoxId);
                    hSql.Com.Parameters.AddWithValue("SMANID", objGlobal.DefaultSManID);
                    hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                    hSql.ExecuteNonQuery();
                    hSql.Com.Parameters.Clear();
                    hSql.NewCommand("SELECT @@IDENTITY");
                    hSql.ExecuteReader();
                    hSql.Read();

                    int nCashRegRowId = hSql.Reader.GetInt32(0);
                    hSql.NewCommand("insert into " + objUtil.getTable("CASHREGROW") + "(CASHREGROWID,ROWNO,CASHFORM,CASHTYPE,AMOUNT,UPDATED_DATE,UPDATED_BY,QTY) values(?,1,'CASH',?,?,getdate(),?,?)");
                    hSql.Com.Parameters.AddWithValue("CASHREGROWID", nCashRegRowId);
                    hSql.Com.Parameters.AddWithValue("CASHTYPE", ConfigurationSettings.AppSettings["DefaultCashType"]);
                    hSql.Com.Parameters.AddWithValue("AMOUNT", nOpeningBalance);
                    hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                    hSql.Com.Parameters.AddWithValue("QTY", nQty);
                    hSql.ExecuteNonQuery();
                }
                if (bRet)
                {
                    hSql.Commit();
                }
                else
                {
                    hSql.Rollback();
                }
            }
            catch (Exception ex)
            {
                hSql.Rollback();
                _log.Error(ex.ToString());
                bRet = false;
            }
            finally
            {
                hSql.Close();
            }
            return(bRet);
        }
Beispiel #7
0
        public bool saveReceipt(clsCashBox CashBox)
        {
            bool              bRet      = true;
            clsSqlFactory     hSql      = new clsSqlFactory();
            clsGlobalVariable objGlobal = new clsGlobalVariable();

            try
            {
                _log.Debug("saveReceipt >> SmanId = " + objGlobal.DefaultSManID);
                List <int>     nVoucherIds    = new List <int>();
                List <int>     nReceiptNos    = new List <int>();
                List <decimal> nReceiptTotals = new List <decimal>();
                int            i             = 0;
                int            nNuseId       = 0;
                int            nReceiptNo    = 0;
                bool           bNeedRounding = false;
                decPaymentSum = getRowsTotal();
                while (i < Rows.Count)
                {
                    DataRow rowPaymentType = CashBox.CashTypes.Select("TYPE = '" + Rows[i].PaymentType.Code + "'")[0];
                    if (rowPaymentType != null)
                    {
                        if (CashBox.getSpecRound(rowPaymentType["TYPE"].ToString()) > 0)
                        {
                            bNeedRounding = true;
                        }

                        nNuseId = CashBox.getVoucherIdOfType(Rows[i].PaymentType.Code, Rows[0].Amount > 0 ? false : true);
                        if (nVoucherIds.IndexOf(nNuseId) < 0)
                        {
                            nVoucherIds.Add(nNuseId);
                            nReceiptNo = getReceiptNUSE(hSql, nNuseId);
                            nReceiptNos.Add(nReceiptNo);
                            nReceiptTotals.Add(0);
                            // insert header

                            _log.Debug("receiptno: " + nReceiptNo.ToString());
                            hSql.NewCommand("insert into " + objUtil.getTable("CASHTRANSH") + "(RECEIPTNO,CASHBOXID,DEPARTMENT,SMANID,UNIT,MODULE," +
                                            "INVOICECATEGORY,CUSTNO,LICNO,AMOUNTTOPAY,TOTPAID,CASHRETURNED," +
                                            "TEXT,INSERTPC,UPDATED_DATE,UPDATED_BY,EXT_BILLD,EXT_ORDERNO,EXT_INVOICENO,INVOICENO,ORDERNO) " +
                                            " values(?,?,?,?,?,?," +
                                            "'1',?,?,?,?,0," +
                                            "?,?,getdate(),?,?,?,?,?,?)");
                            hSql.Com.Parameters.AddWithValue("RECEIPTNO", nReceiptNo);
                            hSql.Com.Parameters.AddWithValue("CASHBOXID", Rows[i].CashBoxId);
                            if (strDeptId != "")
                            {
                                _log.Debug("Department = " + strDeptId);
                                hSql.Com.Parameters.AddWithValue("DEPARTMENT", strDeptId);
                            }
                            else
                            {
                                String strDefDeptId = objConfig.getStringParam("CASHREG", "DEFDEPTID", "C3", "").Trim();
                                if (strDefDeptId == "")
                                {
                                    strDefDeptId = ConfigurationManager.AppSettings["DefDeptId"].ToString();
                                }
                                hSql.Com.Parameters.AddWithValue("DEPARTMENT", strDefDeptId);
                                _log.Debug("Nor department found from invoices, use default department " + strDeptId);
                            }
                            hSql.Com.Parameters.AddWithValue("SMANID", objGlobal.DefaultSManID);
                            hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                            hSql.Com.Parameters.AddWithValue("MODULE", strInvoiceModule);
                            hSql.Com.Parameters.AddWithValue("CUSTNO", strCustNo);
                            hSql.Com.Parameters.AddWithValue("LICNO", strLicno);
                            hSql.Com.Parameters.AddWithValue("AMOUNTTOPAY", decInvoiceSum);
                            hSql.Com.Parameters.AddWithValue("TOTPAID", 0);
                            hSql.Com.Parameters.AddWithValue("TEXT", strRemark);
                            hSql.Com.Parameters.AddWithValue("INSERTEDPC", CashBox.getClientPCName());
                            hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                            hSql.Com.Parameters.AddWithValue("EXT_BILLD", dtInvoiceDate);
                            hSql.Com.Parameters.AddWithValue("EXT_ORDNO", strOrderNo);
                            hSql.Com.Parameters.AddWithValue("EXT_INVOICENO", strInvoiceNo);
                            if (InvoiceFlag != InvoiceFlags.CashRegisterFlag)
                            {
                                hSql.Com.Parameters.AddWithValue("INVOICENO", strInvoiceNo);
                                hSql.Com.Parameters.AddWithValue("ORDERNO", strOrderNo);
                            }
                            else
                            {
                                hSql.Com.Parameters.AddWithValue("INVOICENO", DBNull.Value);
                                hSql.Com.Parameters.AddWithValue("ORDERNO", DBNull.Value);
                            }
                            hSql.ExecuteNonQuery();
                        }
                        else
                        {
                            nReceiptNo = nReceiptNos[nVoucherIds.IndexOf(nNuseId)];
                        }
                        if (nReceiptNo > 0)
                        {
                            hSql.NewCommand("insert into " + objUtil.getTable("CASHTRANSR") + "(RECEIPTNO,ROWNO,CASHFORM,CASHTYPE,QTY,AMOUNT,SALETYPE,FEE,CC_TERMINALID) " +
                                            " values(?,?,?,?,?,?,?,?,?)");
                            hSql.Com.Parameters.AddWithValue("RECEIPTNO", nReceiptNo);
                            hSql.Com.Parameters.AddWithValue("ROWNO", i + 1);
                            hSql.Com.Parameters.AddWithValue("CASHFORM", Rows[i].PaymentForm.Code);
                            hSql.Com.Parameters.AddWithValue("CASHTYPE", Rows[i].PaymentType.Code);
                            hSql.Com.Parameters.AddWithValue("QTY", Rows[i].Quantity);
                            hSql.Com.Parameters.AddWithValue("AMOUNT", Rows[i].Amount);
                            hSql.Com.Parameters.AddWithValue("SALETYPE", Rows[i].SaleType);
                            hSql.Com.Parameters.AddWithValue("FEE", Rows[i].AmountFee);
                            hSql.Com.Parameters.AddWithValue("CC_TERMINALID", Rows[i].CardType.Code);
                            hSql.ExecuteNonQuery();
                            Rows[i].Receiptno = nReceiptNo;
                            nReceiptTotals[nReceiptNos.IndexOf(nReceiptNo)] += Rows[i].Amount;
                        }
                        else
                        {
                            _log.Error("Fail to generate receipt number");
                            Exception ex = new Exception("Fail to generate receipt number, check the voucher id settings !");
                            throw ex;
                        }
                    }
                    else
                    {
                        _log.Error("PaymentType " + Rows[i].PaymentType.Code + " not found in the valid CashTypes !");
                    }
                    i++;
                }
                i = 0;
                while (i < nReceiptNos.Count)
                {
                    hSql.NewCommand("update " + objUtil.getTable("CASHTRANSH") + " set TOTPAID =? where RECEIPTNO=? ");
                    hSql.Com.Parameters.AddWithValue("TOTPAID", nReceiptTotals[i]);
                    hSql.Com.Parameters.AddWithValue("RECEIPTNO", nReceiptNos[i]);
                    hSql.ExecuteNonQuery();
                    i++;
                }
                _log.Debug(strInvoiceModule);
                if ((strInvoiceModule == "VA") || (strInvoiceModule == "SP") || (strInvoiceModule == "WO"))
                {
                    hSql.NewCommand("update TEMPINV set PAYSUM=isnull(PAYSUM,0) + ? where RECNO=?  and UNITID = ?");
                    hSql.Com.Parameters.AddWithValue("PAYSUM", decPaymentSum);
                    hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                    hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                    hSql.ExecuteNonQuery();

                    //
                    if (bNeedRounding)
                    {
                        hSql.NewCommand("update TEMPINV set PAYDATE=getdate() where RECNO=? and PAYDATE is null and abs(PAYSUM-INVSUM) < 3   and UNITID = ?");
                    }
                    else
                    {
                        hSql.NewCommand("update TEMPINV set PAYDATE=getdate() where RECNO=? and PAYDATE is null and abs(PAYSUM-INVSUM) = 0   and UNITID = ?");
                    }
                    hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                    hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                    hSql.ExecuteNonQuery();

                    string strSql = "";
                    if (strInvoiceModule == "VA")
                    {
                        strSql = "update a set a.PAYD=b.PAYDATE,    a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("CBIL") + " a, TEMPINV b where a.CRECNO=b.RECNO " +
                                 //" and a.PAYD is null and b.PAYDATE is not null "+
                                 " and b.RECNO=? and b.UNITID = ?";
                    }
                    if (strInvoiceModule == "SP")
                    {
                        strSql = "update a set a.PAIDDATE=b.PAYDATE,a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("SBIL") + " a, TEMPINV b where a.SRECNO=b.RECNO " +
                                 //"and a.PAIDDATE is null and b.PAYDATE is not null "+
                                 " and b.RECNO=? and b.UNITID = ?";
                    }
                    if (strInvoiceModule == "WO")
                    {
                        strSql = "update a set a.PAIDDATE=b.PAYDATE,a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("GBIL") + " a, TEMPINV b where a.GRECNO=b.RECNO " +
                                 //" and a.PAIDDATE is null and b.PAYDATE is not null"+
                                 " and b.RECNO=? and b.UNITID = ?";
                    }
                    hSql.NewCommand(strSql);
                    hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                    hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                    hSql.ExecuteNonQuery();
                }

                hSql.Commit();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                bRet = false;
                hSql.Rollback();
                throw ex;
            }
            finally {
                hSql.Close();
            }
            return(bRet);
        }
Beispiel #8
0
        public bool undoPayment(clsCashBox CashBox)
        {
            _log.Debug("undoPayment >> " + ReceiptNo.ToString());
            bool              bRet      = true;
            clsSqlFactory     hSql      = new clsSqlFactory();
            clsGlobalVariable objGlobal = new clsGlobalVariable();

            try
            {
                DataRow invoiceCashbox = CashBox.CashBoxes.Select(("CASHBOXID = '" + strCashBoxId + "'"))[0];

                if (invoiceCashbox["ISOPEN"].ToString() == "1" && invoiceCashbox["PC"].ToString() == CashBox.getClientPCName() && nCreditNewNo == 0 && nCreditNote == 0 && nCrediOfNo == 0 && Rows.Count > 0)
                {
                    //Get new Receiptno
                    int nNuseId = CashBox.getVoucherIdOfType(Rows[0].PaymentType.Code, Rows[0].Amount > 0 ? true : false);

                    //Insert new TRANSH row
                    if (nNuseId > 0)
                    {
                        int nNewReceiptNo = getReceiptNUSE(hSql, nNuseId);

                        _log.Debug("New credit receiptno: " + nNewReceiptNo.ToString());
                        hSql.NewCommand("insert into " + objUtil.getTable("CASHTRANSH") + "(CASHBOXID,DEPARTMENT,SMANID,UNIT,MODULE," +
                                        "INVOICECATEGORY,CUSTNO,AMOUNTTOPAY,TOTPAID,CASHRETURNED," +
                                        "EXT_BILLD,EXT_ORDERNO,EXT_INVOICENO,INVOICENO,ORDERNO,LICNO, " +
                                        "UPDATED_DATE,TEXT,INSERTPC,UPDATED_BY, RECEIPTNO,CREDITNOTE,CREDITOFNO )" +
                                        " select a.CASHBOXID,a.DEPARTMENT,a.SMANID,a.UNIT,a.MODULE," +
                                        "a.INVOICECATEGORY,a.CUSTNO,(-1)*a.AMOUNTTOPAY,(-1)*a.TOTPAID,(-1)*a.CASHRETURNED," +
                                        "a.EXT_BILLD,a.EXT_ORDERNO,a.EXT_INVOICENO,a.INVOICENO,a.ORDERNO,a.LICNO," +
                                        "getdate(),?,?,?,?,?,? " +
                                        " from " + objUtil.getTable("CASHTRANSH") + " a where a.RECEIPTNO = ?");

                        hSql.Com.Parameters.AddWithValue("TEXT", "");
                        hSql.Com.Parameters.AddWithValue("INSERTEDPC", CashBox.getClientPCName());
                        hSql.Com.Parameters.AddWithValue("UPDATED_BY", objGlobal.DMSFirstUserName);
                        hSql.Com.Parameters.AddWithValue("RECEIPTNO", nNewReceiptNo);
                        hSql.Com.Parameters.AddWithValue("CREDITNOTE", 1);
                        hSql.Com.Parameters.AddWithValue("CREDITOFNO", ReceiptNo);

                        hSql.Com.Parameters.AddWithValue("RECEIPTNO", ReceiptNo);
                        bRet = bRet && hSql.ExecuteNonQuery();
                        //Update current TRANSH row
                        hSql.NewCommand("update " + objUtil.getTable("CASHTRANSH") + " set CREDITNEWNO = ? where RECEIPTNO =? ");
                        hSql.Com.Parameters.AddWithValue("CREDITNEWNO", nNewReceiptNo);
                        hSql.Com.Parameters.AddWithValue("RECEIPTNO", ReceiptNo);
                        bRet = bRet && hSql.ExecuteNonQuery();

                        nCreditNewNo = nNewReceiptNo;
                        //Get the credited amount
                        Decimal nCreditedPaidAmount = 0;
                        hSql.NewCommand("select a.TOTPAID from " + objUtil.getTable("CASHTRANSH") + " a where a.RECEIPTNO = ?");
                        hSql.Com.Parameters.AddWithValue("RECEIPTNO", nNewReceiptNo);
                        hSql.ExecuteReader();
                        if (hSql.Read())
                        {
                            nCreditedPaidAmount = hSql.Reader.GetDecimal(0);
                        }
                        //Insert new TRANSR row
                        int  i             = 0;
                        bool bNeedRounding = false;
                        while (i < Rows.Count)
                        {
                            hSql.NewCommand("insert into " + objUtil.getTable("CASHTRANSR") + "(RECEIPTNO,ROWNO,CASHFORM,CASHTYPE,QTY,AMOUNT,SALETYPE,FEE, CC_TERMINALID) " +
                                            " values(?,?,?,?,?,?,?,?,?)");

                            hSql.Com.Parameters.AddWithValue("RECEIPTNO", nNewReceiptNo);
                            hSql.Com.Parameters.AddWithValue("ROWNO", Rows[i].Rowno);
                            hSql.Com.Parameters.AddWithValue("CASHFORM", Rows[i].PaymentForm.Code);
                            hSql.Com.Parameters.AddWithValue("CASHTYPE", Rows[i].PaymentType.Code);
                            hSql.Com.Parameters.AddWithValue("QTY", Rows[i].Quantity * (-1));
                            hSql.Com.Parameters.AddWithValue("AMOUNT", Rows[i].Amount * (-1));
                            hSql.Com.Parameters.AddWithValue("SALETYPE", Rows[i].SaleType);
                            hSql.Com.Parameters.AddWithValue("FEE", Rows[i].AmountFee * (-1));
                            hSql.Com.Parameters.AddWithValue("CC_TERMINALID", Rows[i].CardType.Code);
                            bRet = bRet && hSql.ExecuteNonQuery();
                            Rows[i].CreditNewNo = nNewReceiptNo;
                            i++;
                        }
                        _log.Debug(strInvoiceModule);
                        if ((strInvoiceModule == "VA") || (strInvoiceModule == "SP") || (strInvoiceModule == "WO"))
                        {
                            hSql.NewCommand("update TEMPINV set PAYSUM=isnull(PAYSUM,0) + ? where RECNO=?  and UNITID = ?");
                            //hSql.NewCommand("update TEMPINV set PAYSUM= ? where RECNO=?  and UNITID = ?"); //and PAYDATE is not null
                            hSql.Com.Parameters.AddWithValue("PAYSUM", nCreditedPaidAmount);
                            hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                            hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                            hSql.ExecuteNonQuery();

                            hSql.NewCommand("update TEMPINV set PAYDATE=null where RECNO=? and PAYDATE is not null and UNITID = ?");
                            hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                            hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                            hSql.ExecuteNonQuery();

                            string strSql = "";
                            if (strInvoiceModule == "VA")
                            {
                                strSql = "update a set a.PAYD=b.PAYDATE,a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("CBIL") + " a, TEMPINV b where a.CRECNO=b.RECNO and a.PAYD is not null and b.PAYDATE is null and b.RECNO=? and b.UNITID = ?";
                            }
                            if (strInvoiceModule == "SP")
                            {
                                strSql = "update a set a.PAIDDATE=b.PAYDATE,a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("SBIL") + " a, TEMPINV b where a.SRECNO=b.RECNO and a.PAIDDATE is not null and b.PAYDATE is null and b.RECNO=? and b.UNITID = ?";
                            }
                            if (strInvoiceModule == "WO")
                            {
                                strSql = "update a set a.PAIDDATE=b.PAYDATE,a.PAIDSUM=b.PAYSUM from " + objUtil.getTable("GBIL") + " a, TEMPINV b where a.GRECNO=b.RECNO and a.PAIDDATE is not null and b.PAYDATE is null and b.RECNO=? and b.UNITID = ?";
                            }
                            hSql.NewCommand(strSql);
                            hSql.Com.Parameters.AddWithValue("RECNO", strInvoiceNo);
                            hSql.Com.Parameters.AddWithValue("UNITID", objGlobal.CurrentSiteId);
                            hSql.ExecuteNonQuery();
                        }
                    }
                    else
                    {
                        _log.Error("Invalid NUSEID assigned  to the CASHTYPE : " + Rows[0].PaymentType);
                    }
                    //
                    if (bRet)
                    {
                        hSql.Commit();
                    }
                    else
                    {
                        hSql.Rollback();
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                bRet = false;
                hSql.Rollback();
                throw ex;
            }
            finally
            {
                hSql.Close();
            }
            _log.Debug("undoPayment << ");
            return(bRet);
        }