/// <summary> /// Method to load GST exempt /// </summary> /// <param name="taxExemptSale">Tax exempt sale</param> /// <param name="sn">Sale number</param> /// <param name="tillId">Till number</param> /// <param name="db">Data source</param> /// <returns>True or false</returns> public bool LoadGstExempt(ref TaxExemptSale taxExemptSale, int sn, byte tillId, DataSource db) { var rsLine = GetRecords("select * from SALELINE " + " where SALE_NO=" + Convert.ToString(sn) + " AND TILL_NUM=" + Convert.ToString(tillId), db); if (rsLine.Rows.Count == 0) { return(false); } foreach (DataRow line in rsLine.Rows) { var rsTaxCreditLine = GetRecords("SELECT * from TaxCreditLine where TILL_NUM=" + Convert.ToString(tillId) + " AND SALE_NO=" + Convert.ToString(sn) + " AND Line_No=" + Convert.ToString(line["Line_Num"]), db); if (rsTaxCreditLine.Rows.Count == 0) { continue; } var tx = new TaxCreditLine { Line_Num = CommonUtility.GetShortValue(line["Line_Num"]) }; foreach (DataRow taxCreditLine in rsTaxCreditLine.Rows) { var lt = new Line_Tax { Tax_Name = CommonUtility.GetStringValue(taxCreditLine["Tax_Name"]), Tax_Code = CommonUtility.GetStringValue(taxCreditLine["Tax_Code"]), Tax_Rate = CommonUtility.GetFloatValue(taxCreditLine["Tax_Rate"]), Tax_Included = CommonUtility.GetBooleanValue(taxCreditLine["Tax_Included"]), Tax_Added_Amount = CommonUtility.GetFloatValue(taxCreditLine["Tax_Added_Amount"]), Tax_Incl_Amount = CommonUtility.GetFloatValue(taxCreditLine["Tax_Included_Amount"]) }; tx.Line_Taxes.AddTaxLine(lt, ""); } taxExemptSale.TaxCreditLines.AddLine(tx.Line_Num, tx, ""); } var rsTaxCredit = GetRecords("SELECT * from TaxCredit where TILL_NUM=" + Convert.ToString(tillId) + " AND SALE_NO=" + Convert.ToString(sn), db); foreach (DataRow taxCredit in rsTaxCredit.Rows) { var sx = new Sale_Tax { Tax_Name = CommonUtility.GetStringValue(taxCredit["Tax_Name"]), Tax_Code = CommonUtility.GetStringValue(taxCredit["Tax_Code"]), Tax_Rate = CommonUtility.GetFloatValue(taxCredit["Tax_Rate"]), Taxable_Amount = CommonUtility.GetDecimalValue(taxCredit["Taxable_Amount"]), Tax_Added_Amount = CommonUtility.GetDecimalValue(taxCredit["Tax_Added_Amount"]), Tax_Included_Amount = CommonUtility.GetDecimalValue(taxCredit["Tax_Included_Amount"]), Tax_Included_Total = CommonUtility.GetDecimalValue(taxCredit["Tax_Included_Total"]) }; taxExemptSale.TaxCredit.Add(sx.Tax_Name, sx.Tax_Code, sx.Tax_Rate, sx.Taxable_Amount, sx.Tax_Added_Amount, sx.Tax_Included_Amount, sx.Tax_Included_Amount, sx.Tax_Rebate_Rate, sx.Tax_Rebate, sx.Tax_Name + sx.Tax_Code); // - gave mismatch type error for AITE } return(true); }
/// <summary> /// Method to add sale line tax /// </summary> /// <param name="lineTax">Line tax</param> public void AddSaleLineTax(Line_Tax lineTax) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,SaleLineService,AddSaleLineTax,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}"); _connection = new SqlConnection(GetConnectionString(DataSource.CSCTills)); if (_connection.State == ConnectionState.Closed) { _connection.Open(); } _dataTable = new DataTable(); _adapter = new SqlDataAdapter("SELECT * from S_LineTax where TILL_NUM=" + lineTax.TillNumber + " and Sale_No = " + lineTax.SaleNumber + " and Line_No = " + lineTax.LineNumber + " and Tax_Name = " + lineTax.Tax_Name, _connection); _adapter.Fill(_dataTable); if (_dataTable.Rows.Count == 0) { var fields = _dataTable.NewRow(); fields["TILL_NUM"] = lineTax.TillNumber; fields["Sale_No"] = lineTax.SaleNumber; fields["Line_No"] = lineTax.LineNumber; fields["Tax_Name"] = lineTax.Tax_Name; fields["Tax_Code"] = lineTax.Tax_Code; fields["Tax_Rate"] = lineTax.Tax_Rate; fields["Tax_Included"] = lineTax.Tax_Included; fields["Tax_Added_Amount"] = lineTax.Tax_Added_Amount; fields["Tax_Included_Amount"] = lineTax.Tax_Incl_Amount; fields["Tax_Rebate"] = lineTax.Tax_Rebate; fields["Tax_Rebate_Rate"] = lineTax.Tax_Rebate_Rate; _dataTable.Rows.Add(fields); SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.InsertCommand = builder.GetInsertCommand(); _adapter.Update(_dataTable); _connection.Close(); _adapter?.Dispose(); } _performancelog.Debug($"End,SaleLineService,AddSaleLineTax,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); }
/// <summary> /// Method to update tax exempt sale /// </summary> /// <param name="taxExemptSale">Tax exempt sale</param> /// <param name="gasLessQuota">Gas less quota</param> /// <param name="propaneLessQuota">Propane less quota</param> /// <param name="tobaccoLessQuota">Tobacco less quota</param> public void UpdateSale(TaxExemptSale taxExemptSale, float gasLessQuota, float propaneLessQuota, float tobaccoLessQuota) { Line_Tax lt = default(Line_Tax); _connection = new SqlConnection(GetConnectionString(DataSource.CSCTills)); if (_connection.State == ConnectionState.Closed) { _connection.Open(); } _dataTable = new DataTable(); var query = "select * from TaxExemptSaleHead " + " where SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND TILL_NUM=" + Convert.ToString(taxExemptSale.TillNumber); _adapter = new SqlDataAdapter(query, _connection); _adapter.Fill(_dataTable); if (_dataTable.Rows.Count != 0) { var rsTeSaleHead = _dataTable.Rows[0]; rsTeSaleHead["SaleAmount"] = taxExemptSale.Amount; if (!taxExemptSale.GasOverLimit) { rsTeSaleHead["GasReason"] = ""; rsTeSaleHead["GasReasonDesp"] = ""; rsTeSaleHead["GasReasonDetail"] = ""; } if (!taxExemptSale.PropaneOverLimit) { rsTeSaleHead["PropaneReason"] = ""; rsTeSaleHead["PropaneReasonDesp"] = ""; rsTeSaleHead["PropaneReasonDetail"] = ""; } if (!taxExemptSale.TobaccoOverLimit) { rsTeSaleHead["TobaccoReason"] = ""; rsTeSaleHead["TobaccoReasonDesp"] = ""; rsTeSaleHead["TobaccoReasonDetail"] = ""; } rsTeSaleHead["TotalExemptedTax"] = taxExemptSale.TotalExemptedTax; SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.UpdateCommand = builder.GetUpdateCommand(); _adapter.Update(_dataTable); } foreach (TaxExemptSaleLine tempLoopVarTesl in taxExemptSale.Te_Sale_Lines) { var tesl = tempLoopVarTesl; _dataTable = new DataTable(); query = "select * from TaxExemptSaleLine " + " where SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND LINE_NUM=" + Convert.ToString(taxExemptSale.TillNumber) + " AND LINE_NUM=" + Convert.ToString(tesl.Line_Num); _adapter = new SqlDataAdapter(query, _connection); _adapter.Fill(_dataTable); if (_dataTable.Rows.Count != 0) { var rsTeSaleLine = _dataTable.Rows[0]; rsTeSaleLine["Quantity"] = tesl.Quantity; rsTeSaleLine["EquvQuantity"] = tesl.EquvQuantity; rsTeSaleLine["TaxIncludedAmount"] = tesl.TaxInclPrice; rsTeSaleLine["Amount"] = tesl.Amount; rsTeSaleLine["ExemptedTax"] = tesl.ExemptedTax; rsTeSaleLine["OverLimit"] = tesl.OverLimit; rsTeSaleLine["RunningQuota"] = tesl.RunningQuota.ToString("#0.00"); if (tesl.StockIsChanged) { rsTeSaleLine["Stock_Code"] = tesl.StockCode; rsTeSaleLine["ProductType"] = tesl.ProductType; rsTeSaleLine["ProductCode"] = tesl.ProductCode; rsTeSaleLine["Description"] = tesl.Description; rsTeSaleLine["price"] = tesl.TaxFreePrice; rsTeSaleLine["OriginalPrice"] = tesl.OriginalPrice; } SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.UpdateCommand = builder.GetUpdateCommand(); _adapter.Update(_dataTable); } } bool addNew; foreach (Sale_Tax tempLoopVarSx in taxExemptSale.TaxCredit) { var sx = tempLoopVarSx; if (sx.Taxable_Amount != 0 | sx.Tax_Included_Amount != 0) { addNew = false; _dataTable = new DataTable(); query = "SELECT * from TaxCredit where TILL_NUM=" + taxExemptSale.TillNumber + " AND SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND Tax_Name=\'" + sx.Tax_Name + "\' AND " + " Tax_Code=\'" + sx.Tax_Code + "\' "; _adapter = new SqlDataAdapter(query, _connection); _adapter.Fill(_dataTable); DataRow taxCredit; if (_dataTable.Rows.Count == 0) { addNew = true; taxCredit = _dataTable.NewRow(); taxCredit["Till_Num"] = taxExemptSale.TillNumber; taxCredit["sale_no"] = taxExemptSale.Sale_Num; taxCredit["Tax_Name"] = sx.Tax_Name; taxCredit["Tax_Code"] = sx.Tax_Code; SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.InsertCommand = builder.GetInsertCommand(); } else { taxCredit = _dataTable.Rows[0]; SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.UpdateCommand = builder.GetUpdateCommand(); } taxCredit["Tax_Rate"] = sx.Tax_Rate; taxCredit["Taxable_Amount"] = sx.Taxable_Amount; taxCredit["Tax_Added_Amount"] = sx.Tax_Added_Amount; taxCredit["Tax_Included_Amount"] = sx.Tax_Included_Amount; taxCredit["Tax_Included_Total"] = sx.Tax_Included_Total; if (addNew) { _dataTable.Rows.Add(taxCredit); } _adapter.Update(_dataTable); } } foreach (TaxCreditLine tempLoopVarTx in taxExemptSale.TaxCreditLines) { var tx = tempLoopVarTx; foreach (Line_Tax tempLoopVarLt in tx.Line_Taxes) { addNew = false; _dataTable = new DataTable(); query = "SELECT * from TaxCreditLine where TILL_NUM=" + taxExemptSale.TillNumber + " AND SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND Tax_Name=\'" + lt.Tax_Name + "\' AND " + " Line_No=" + Convert.ToString(tx.Line_Num); _adapter = new SqlDataAdapter(query, _connection); _adapter.Fill(_dataTable); DataRow taxCreditLine; lt = tempLoopVarLt; if (_dataTable.Rows.Count == 0) { addNew = true; taxCreditLine = _dataTable.NewRow(); taxCreditLine["Till_Num"] = taxExemptSale.TillNumber; taxCreditLine["sale_no"] = taxExemptSale.Sale_Num; taxCreditLine["Line_No"] = tx.Line_Num; taxCreditLine["Tax_Name"] = lt.Tax_Name; SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.InsertCommand = builder.GetInsertCommand(); } else { taxCreditLine = _dataTable.Rows[0]; SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.UpdateCommand = builder.GetUpdateCommand(); } taxCreditLine["Tax_Code"] = lt.Tax_Code; taxCreditLine["Tax_Rate"] = lt.Tax_Rate; taxCreditLine["Tax_Included"] = lt.Tax_Included; taxCreditLine["Tax_Added_Amount"] = lt.Tax_Added_Amount; taxCreditLine["Tax_Included_Amount"] = lt.Tax_Incl_Amount; if (addNew) { _dataTable.Rows.Add(taxCreditLine); } _adapter.Update(_dataTable); } } _connection.Close(); _connection = new SqlConnection(GetConnectionString(DataSource.CSCMaster)); if (_connection.State == ConnectionState.Closed) { _connection.Open(); } var rsCardHolder = new DataTable(); query = "select * from TaxExemptCardRegistry " + " where CardholderID=\'" + taxExemptSale.teCardholder.CardholderID + "\'"; _adapter = new SqlDataAdapter(query, _connection); _adapter.Fill(_dataTable); if (rsCardHolder.Rows.Count != 0) { rsCardHolder.Rows[0]["TobaccoQuota"] = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["TobaccoQuota"]) - tobaccoLessQuota).ToString("#0.00"); rsCardHolder.Rows[0]["GasQuota"] = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["GasQuota"]) - gasLessQuota).ToString("#0.00"); rsCardHolder.Rows[0]["PropaneQuota"] = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["PropaneQuota"]) - propaneLessQuota).ToString("#0.00"); SqlCommandBuilder builder = new SqlCommandBuilder(_adapter); _adapter.UpdateCommand = builder.GetUpdateCommand(); _adapter.Update(rsCardHolder); } _connection.Close(); _adapter?.Dispose(); }