Example #1
0
        public static bool GenerateUngeneratedReport()
        {
            try
            {
                DateTime minsalesdate = DataHandler.GetMinimumSaleDate();
                DateTime lastZread    = DataHandler.GetLastZReadDate();

                if (lastZread.Date == DateTime.Now.Date)
                {
                    return(true);
                }
                if (lastZread.Date == DateTime.Now.AddDays(-1).Date)
                {
                    return(true);
                }
                else
                {
                    DataBaseHelper.SetDB(@"DELETE FROM Reports WHERE transdate >= '" + lastZread.Date.ToString("yyyy-MM-dd") + "'");
                    foreach (DateTime day in EachDay(lastZread, DateTime.Now.AddDays(-1)))
                    {
                        GenerateReport.XRead(day);
                        GenerateReport.ZRead(day);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
 public static bool VoidTransaction(Transaction trans)
 {
     try
     {
         DataBaseHelper.SetDB(string.Format(@"UPDATE TransactionHead
                                 SET sales = '0',
                                     date = '{0}'
                                 WHERE id = '{1}'", DateTime.Now, trans.ID));
         return(true);
     }
     catch (Exception exe)
     {
         MessageBox.Show(exe.Message);
         return(false);
     }
 }
Example #3
0
 public static bool SaveAdjustments(List <Inventory> adjustments)
 {
     try
     {
         foreach (Inventory adj in adjustments)
         {
             DataBaseHelper.SetDB(string.Format(@"INSERT INTO InventoryAdjust(productid, quantity, headid, date, transdate, manual)
             VALUES('{0}','{1}','{2}', '{3}', '{4}', '{5}')", adj.ProductID, adj.Quantity, 0, adj.Date, adj.Date.ToString("yyyy-MM-dd"), "1"));
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #4
0
        public static bool SaveProduct(Product prod)
        {
            try
            {
                string barcode = GetNextBarcode();

                DataBaseHelper.SetDB(string.Format(@"INSERT INTO Product(barcode, productname, stockno, price)
                    VALUES('{0}','{1}','{2}','{3}')", barcode, prod.Name, prod.StockNo, prod.Price));
                return(true);
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.Message);
                return(false);
            }
        }
Example #5
0
        public static bool SaveReport(Report report)
        {
            try
            {
                DataBaseHelper.SetDB(@"DELETE FROM Reports WHERE readtype = '" + report.Type + "' AND transdate = '" + report.Date.ToString("yyyy-MM-dd") + "'");

                DataBaseHelper.SetDB(string.Format(@"INSERT INTO Reports(oldgrandtotal, newgrandtotal, date, readtype, readcount, transdate, voiditemqty, salesitemqty, grossamount, salescount, transcount, voidcount, voidamount, vat, vatablesales, minor, maxor)
                    VALUES('{0}','{1}','{2}', '{3}', '{4}', '{5}','{6}','{7}', '{8}', '{9}', '{10}','{11}','{12}', '{13}', '{14}', '{15}', '{16}')",
                                                   report.OldGrandTotal, report.NewGrandTotal, report.Date, report.Type, report.ReadCount, report.Date.ToString("yyyy-MM-dd"), report.VoidItemQty, report.SalesItemQty, report.GrossAmount, report.SalesTransCount, report.TransCount, report.VoidTransCount,
                                                   report.VoidAmount, report.Vat, report.VatableSales, report.MinOR, report.MaxOR));

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #6
0
        public static bool UpdateProduct(Product prod)
        {
            try
            {
                DataBaseHelper.SetDB(string.Format(@"UPDATE Product
                                        SET productname = '{0}',
	                                        stockno ='{1}',
	                                        price = '{2}',
                                            discontinued = '{3}'
                                        WHERE id = '{4}'", prod.Name, prod.StockNo, prod.Price, prod.Show, prod.ID));
                return(true);
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.Message);
                return(false);
            }
        }
Example #7
0
        public static bool SaveTransaction(Transaction trans)
        {
            try
            {
                string transNo = GetNextTransNumber();
                string idNo    = GetNextID("TransactionHead");

                DataBaseHelper.SetDB(string.Format(@"INSERT INTO TransactionHead(transactionnumber, invoicenumber, transdate, sales, tenderamount, date)
                    VALUES('{0}','{1}','{2}', '{3}', '{4}', '{5}')", transNo, trans.InvoiceNumber, trans.Date.ToString("yyyy-MM-dd"), trans.Sales ? "1": "0", trans.TenderAmount, trans.Date));

                foreach (Product prod in trans.productlist)
                {
                    DataBaseHelper.SetDB(string.Format(@"INSERT INTO TransactionDetail(headid, productid, quantity, price)
                    VALUES('{0}','{1}','{2}', '{3}')", idNo, prod.ID, prod.Qty, prod.Price));
                    DataBaseHelper.SetDB(string.Format(@"INSERT INTO InventoryAdjust(productid, quantity, headid, date, transdate)
                    VALUES('{0}','{1}','{2}', '{3}', '{4}')", prod.ID, prod.Qty * -1, idNo, trans.Date, trans.Date.ToString("yyyy-MM-dd")));
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #8
0
        private static bool Generate(int type, DateTime date)
        {
            try
            {
                Report report = new Report();
                report.Date = date;
                report.Type = type;

                report.MinOR = DataHandler.GetOR(true, date);
                report.MaxOR = DataHandler.GetOR(false, date);

                report.OldGrandTotal = DataHandler.GetOldGrandTotal(type);

                DataTable dt     = DataBaseHelper.GetDB(string.Format(@"SELECT 
	                                                SUM(TD.price * TD.quantity) AS sales, 
	                                                COUNT(*) AS itemcount,
	                                                TH.transdate
                                                FROM TransactionHead TH
                                                LEFT JOIN TransactionDetail TD ON TD.headid = TH.id
                                                WHERE  
                                                    transdate = '{0}' 
                                                    AND sales = 1 GROUP By TH.transdate", date.ToString("yyyy-MM-dd")));
                DataTable dtvoid = DataBaseHelper.GetDB(string.Format(@"SELECT 
	                                                SUM(TD.price * TD.quantity) AS voidsales, 
	                                                COUNT(*) AS itemcount,
	                                                TH.transdate
                                                FROM TransactionHead TH
                                                LEFT JOIN TransactionDetail TD ON TD.headid = TH.id
                                                WHERE  
                                                    transdate = '{0}' 
                                                    AND sales = 0 GROUP By TH.transdate", date.ToString("yyyy-MM-dd")));
                if (dt.Rows.Count == 0)
                {
                    report.VatableSales    = 0;
                    report.NewGrandTotal   = report.OldGrandTotal;
                    report.Vat             = 0;
                    report.TransCount      = 0;
                    report.SalesTransCount = 0;
                    report.VatableSales    = 0;
                    report.SalesItemQty    = 0;
                }
                else
                {
                    report.VatableSales  = Convert.ToDecimal(dt.Rows[0]["Sales"]);
                    report.NewGrandTotal = report.OldGrandTotal + report.VatableSales;
                    report.Vat           = (report.VatableSales / 1.12M) * 0.12M;
                    report.TransCount    = 0;
                    report.SalesItemQty  = Convert.ToDecimal(dt.Rows[0]["itemcount"]);

                    DataTable dtcounts = DataBaseHelper.GetDB(string.Format(@"SELECT COUNT(*) AS cnt FROM TransactionHead WHERE sales = 1 and transdate = '{0}'", date.ToString("yyyy-MM-dd")));

                    report.SalesTransCount = Convert.ToDecimal(dtcounts.Rows[0]["cnt"]);
                }
                if (dtvoid.Rows.Count == 0)
                {
                    report.VoidAmount     = 0;
                    report.VoidTransCount = 0;
                    report.VoidItemQty    = 0;
                }
                else
                {
                    report.VoidAmount  = Convert.ToDecimal(dtvoid.Rows[0]["voidsales"]);
                    report.VoidItemQty = Convert.ToDecimal(dtvoid.Rows[0]["itemcount"]);

                    DataTable dtcountsvoid = DataBaseHelper.GetDB(string.Format(@"SELECT COUNT(*) AS cnt FROM TransactionHead WHERE sales = 0 and transdate = '{0}'", date.ToString("yyyy-MM-dd")));
                    report.VoidTransCount = Convert.ToDecimal(dtcountsvoid.Rows[0]["cnt"]);
                }

                report.GrossAmount = report.VoidAmount + report.VatableSales;
                report.TransCount  = report.SalesTransCount + report.VoidTransCount;
                DataBaseHelper.SetDB(@"DELETE FROM Reports WHERE readtype = '" + report.Type + "' AND transdate = '" + report.Date.ToString("yyyy-MM-dd") + "'");
                report.ReadCount = DataHandler.GetNextReadCount(report.Type);
                HardwareHelper.PrintReport(null, null, null, report);
                return(DataHandler.SaveReport(report));
            }
            catch
            {
                return(false);
            }
        }