Esempio n. 1
0
        private void PrintOrderForKitchens(string order_id, string job_id, string title = "New Order")
        {
            NewOrderReport report = new NewOrderReport();

            try
            {
                report.DataDefinition.FormulaFields["ReportTitle"].Text = "'" + title + "'";


                foreach (DataRow r in kitchen_printers_dt.Rows)
                {
                    NewOrderDataSet ds = generateNewOrderDataSet(order_id, r["Category"].ToString());

                    if (ds.OrderDetail.Rows.Count > 0)
                    {
                        report.SetDataSource(ds);
                        report.PrintOptions.PrinterName = r["Printer"].ToString();
                        report.PrintToPrinter(1, false, 0, 0);
                    }
                }

                MySqlFunctions.SqlNonQuery("update print_jobs set executed_at = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' " +
                                           "where id = '" + job_id + "'", Program.GlobalConn);
            }
            catch (Exception ex)
            {
                MySqlFunctions.SqlNonQuery("update print_jobs set executed_at = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "', " +
                                           " error = '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(ex.Message) + "' " +
                                           "where id = '" + job_id + "'", Program.GlobalConn);
            }
            finally
            {
                report.Dispose();
            }
        }
Esempio n. 2
0
        private NewOrderDataSet generateNewOrderDataSet(string order_id, string category = "")
        {
            NewOrderDataSet ds = new NewOrderDataSet();

            DataTable order = MySqlFunctions.GetTable(
                "select tos.id, order_types.name as order_type, tos.order_datetime, " +
                "tables.portion, tables.name as table_name, tos.deliver_to_name, tos.deliver_to_phone, " +
                "tos.deliver_to_address, tos.received_through, tos.order_amount_ex_st as ex_st, " +
                "tos.sales_tax as st, tos.order_amount_inc_st as inc_st, " +
                "tos.cover, tos.discount, tos.order_amount_before_discount as before_discount " +
                "from tos " +
                "join order_types on order_types.id = tos.order_type_id " +
                "left join tables on tables.id = tos.table_id " +
                "where tos.id = " + order_id + "; ", Program.GlobalConn);


            string detail_query = "select tos_details.to_id as order_id, items.category, items.code as item_code , items.name as item_name, " +
                                  "tos_details.qty, tos_details.rate, tos_details.amount, tos_details.item_notes " +
                                  "from tos_details " +
                                  "join items on items.id = tos_details.item_id " +
                                  " where tos_details.to_id = " + order_id;

            string closingAccountsQuery = @"SELECT id, NAME, sales_tax_rate FROM 
closing_accounts WHERE show_on_print_for_customer = TRUE;";

            if (category != "")
            {
                detail_query += " and items.category = '" + category + "' ";
            }



            DataTable detail = MySqlFunctions.GetTable(detail_query, Program.GlobalConn);

            DataTable closingAccounts = MySqlFunctions.GetTable(closingAccountsQuery, Program.GlobalConn);

            decimal discount        = 0;
            decimal before_discount = 0;

            foreach (DataRow r in order.Rows)
            {
                decimal cover = r["cover"].ToString() == "" ? decimal.Parse("0") : decimal.Parse(r["cover"].ToString());
                discount        = r["discount"].ToString() == "" ? decimal.Parse("0") : decimal.Parse(r["discount"].ToString());
                before_discount = r["before_discount"].ToString() == "" ? decimal.Parse("0") : decimal.Parse(r["before_discount"].ToString());

                ds.Order.AddOrderRow(
                    r["id"].ToString(),
                    r["order_type"].ToString(),
                    (System.DateTime)r["order_datetime"],
                    r["portion"].ToString(),
                    r["table_name"].ToString(),
                    r["deliver_to_name"].ToString(),
                    r["deliver_to_phone"].ToString(),
                    r["deliver_to_address"].ToString(),
                    r["received_through"].ToString(),
                    (decimal)r["ex_st"],
                    (decimal)r["st"],
                    (decimal)r["inc_st"],

                    cover,
                    discount,
                    before_discount
                    );
            }

            decimal after_discount = before_discount - discount;

            foreach (DataRow r in closingAccounts.Rows)
            {
                //NAME, sales_tax_rate
                int     id             = 0;
                string  name           = r["name"].ToString();
                decimal salesTaxRate   = Convert.ToDecimal(r["sales_tax_rate"]);
                decimal salesTaxAmount = Math.Round(after_discount * salesTaxRate / 100);
                decimal totalAmount    = Math.Round(after_discount + salesTaxAmount);
                ds.TaxDetail.AddTaxDetailRow(
                    id,
                    name,
                    salesTaxRate,
                    salesTaxAmount,
                    totalAmount
                    );
            }

            foreach (DataRow r in detail.Rows)
            {
                ds.OrderDetail.AddOrderDetailRow(
                    (NewOrderDataSet.OrderRow)ds.Order.Rows[0],
                    r["category"].ToString(),
                    r["item_code"].ToString(),
                    r["item_name"].ToString(),
                    (decimal)r["qty"],
                    (decimal)r["rate"],
                    (decimal)r["amount"],
                    r["item_notes"].ToString()
                    );
            }

            return(ds);
        }
Esempio n. 3
0
        private void PrintOrder(string order_id, string job_id, bool printInvoice)
        {
            PrintForCustomer report = new PrintForCustomer();

            try
            {
                NewOrderDataSet ds = generateNewOrderDataSet(order_id);

                if (printInvoice)
                {
                    string invoice_id = "";

                    DataTable inv_dt = null;
                    inv_dt = MySqlFunctions.GetTable("select id from invoices where order_id = '" + ds.Order.Rows[0]["id"].ToString() + "' limit 1", Program.GlobalConn);

                    if (inv_dt != null && inv_dt.Rows.Count > 0)
                    {
                        invoice_id = "Invoice:" + inv_dt.Rows[0]["id"].ToString();
                    }

                    inv_dt = MySqlFunctions.GetTable("select id from ent_bills where order_id = '" + ds.Order.Rows[0]["id"].ToString() + "' limit 1", Program.GlobalConn);

                    if (inv_dt != null && inv_dt.Rows.Count > 0)
                    {
                        invoice_id = "Ent Bill:" + inv_dt.Rows[0]["id"].ToString();
                    }

                    if (invoice_id != "")
                    {
                        //report.DataDefinition.FormulaFields["invoice_id"].Text = "'" + invoice_id + "'";
                    }
                }

                report.SetDataSource(ds);

                DataTable restaurant_infoDT = MySqlFunctions.GetTable("select " +
                                                                      "(select `value` from settings where slug = 'restaurant_name') as 'name', " +
                                                                      "(select `value` from settings where slug = 'restaurant_address') as 'address', " +
                                                                      "(select `value` from settings where slug = 'restaurant_ntn') as 'ntn', " +
                                                                      "(select `value` from settings where slug = 'restaurant_stn') as 'stn'; ", Program.GlobalConn);

                if (restaurant_infoDT != null && restaurant_infoDT.Rows.Count > 0)
                {
                    DataRow r = restaurant_infoDT.Rows[0];

                    //report.DataDefinition.FormulaFields["restaurant_name"].Text = "'" + r["name"].ToString() + "'";
                    //report.DataDefinition.FormulaFields["restaurant_address"].Text = "'" + r["address"].ToString() + "'";
                    //report.DataDefinition.FormulaFields["ntn"].Text = "'" + r["ntn"].ToString() + "'";
                    //report.DataDefinition.FormulaFields["stn"].Text = "'" + r["stn"].ToString() + "'";
                }

                var path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
                var rtb  = new RichTextBox();
                rtb.LoadFile(path + "/header.txt");
                var headerLines = rtb.Text.Split('\n');
                for (int i = 0; i < headerLines.Length && i < 5; i++)
                {
                    report.DataDefinition.FormulaFields["header_line" + i.ToString()].Text = "'" + headerLines[i] + "'";
                }

                rtb.LoadFile(path + "/footer.txt");
                var footerLines = rtb.Text.Split('\n');
                for (int i = 0; i < footerLines.Length && i < 5; i++)
                {
                    report.DataDefinition.FormulaFields["footer_line" + i.ToString()].Text = "'" + footerLines[i] + "'";
                }

                foreach (DataRow r in pos_printers_dt.Rows)
                {
                    report.PrintOptions.PrinterName = r["Printer"].ToString();
                    report.PrintToPrinter(1, false, 0, 0);
                }

                MySqlFunctions.SqlNonQuery("update print_jobs set executed_at = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' " +
                                           "where id = '" + job_id + "'", Program.GlobalConn);
            }
            catch (Exception ex)
            {
                MySqlFunctions.SqlNonQuery("update print_jobs set executed_at = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "', " +
                                           " error = '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(ex.Message) + "' " +
                                           "where id = '" + job_id + "'", Program.GlobalConn);
            }
            finally
            {
                report.Dispose();
            }
        }