Esempio n. 1
0
        private void GenReceipt()
        {
            int    amnt = int.Parse(AmountToBePaid.Content.ToString());
            string OR   = pmsutil.GenerateReceiptNum();

            PdfDocument     pdfDoc  = new PdfDocument();
            PdfPageBase     page    = pdfDoc.Pages.Add();
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("ROMAN CATHOLIC BISHOP OF LEGAZPI, INC.",
                                   new PdfFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 240, 0, format1);

            page.Canvas.DrawString("\n\nThe Chancery, Cathedral Compound,\nAlbay District. Legazpi City 4500\nTel. No. (052) 481-2178 . NON-VAT Reg.TIN No. 000-636-377-000",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 240, 0, format1);

            page.Canvas.DrawString("OFFICIAL RECEIPT",
                                   new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 75);

            page.Canvas.DrawString("\nDate: _______________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 285, 70);

            page.Canvas.DrawString("Received From " + ReceivedFrom.Text +
                                   "\nwith TIN__________________and address at ___________________________" +
                                   "\nengaged in the business style of______________________________________" +
                                   "\nthe sum of__________________________________________________ pesos" +
                                   "\n(P___________) in parial/full payment of the following:",

                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 100);


            String[] data =
            {
                "For; ; ",
                " ;P; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                "Total Sales; ; ",
                "Less: SC/PWD Discount; ; ",
                "Total Due; ; ",
                "Thank you        TOTAL; ; ",
            };
            String[][] dataSource = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }
            PdfTable table = new PdfTable();


            table.Style.CellPadding = 2;
            table.DataSource        = dataSource;
            float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);

            table.Columns[0].Width        = width * 0.1f * width;
            table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[1].Width        = width * 0.02f * width;
            table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[2].Width        = width * 0.03f * width;
            table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Draw(page, new System.Drawing.PointF(40, 170));

            page.Canvas.DrawString("Form of Payment:                        __ Cash    __ Check\n" +
                                   "Check No.:_______________Bank:_______________\n" +
                                   "Sr. Citizen TIN\n" +
                                   "OSCA/PWD ID No.________________Signature_______________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 420);

            page.Canvas.DrawString("No. 161455",
                                   new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 475);

            page.Canvas.DrawString("by:",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 200, 470);;

            page.Canvas.DrawString("__________________________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 200, 500);;

            page.Canvas.DrawString("Cashier",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Italic),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 250, 510);;

            string fname = "test.pdf";

            pdfDoc.SaveToFile(@"Receipts\" + fname);
            //MessageBox.Show("yey");
            System.Diagnostics.Process.Start(@"Receipts\" + fname);
        }
Esempio n. 2
0
        private void ConfirmPayment_Click2(object sender, System.Windows.RoutedEventArgs e)
        {
            //dbman = new DBConnectionManager();
            pmsutil = new PMSUtil();

            int    amnt = int.Parse(AmountToBePaid.Content.ToString());
            string OR   = pmsutil.GenerateReceiptNum();

            using (conn = new MySqlConnection(dbman.GetConnStr()))
            {
                conn.Open();
                if (conn.State == ConnectionState.Open)
                {
                    MySqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT * FROM transactions WHERE transaction_id = @transaction_id LIMIT 1;";
                    cmd.Parameters.AddWithValue("@transaction_id", tid);
                    cmd.Prepare();
                    MySqlDataReader db_reader = cmd.ExecuteReader();
                    while (db_reader.Read())
                    {
                        if (db_reader.GetString("status") == "Unpaid")
                        {
                            ornum = OR;
                            using (conn2 = new MySqlConnection(dbman.GetConnStr()))
                            {
                                conn2.Open();
                                MySqlCommand cmd2 = conn2.CreateCommand();
                                cmd2.CommandText = "SELECT COUNT(*) FROM transactions WHERE or_number = @or_number;";
                                cmd2.Parameters.AddWithValue("@or_number", OR);
                                cmd2.Prepare();
                                int counter = int.Parse(cmd2.ExecuteScalar().ToString());
                                if (counter > 0)
                                {
                                    InfoArea.Foreground = new SolidColorBrush(Colors.Red);
                                    InfoArea.Content    = "Duplicate Receipt Number Detected!";
                                }
                                else
                                {
                                    UpdateTransaction();
                                    trans1.SyncTransactions();
                                    MsgSuccess();
                                    this.Close();
                                }
                            }
                        }
                    }
                }
            }

            Document doc = new Document();

            doc.LoadFromFile("Data\\temp_receipt.docx");
            doc.Replace("date", DateTime.Now.ToString("MM/dd/yyyy"), true, true);
            doc.Replace("name", ReceivedFrom.Text, true, true);
            doc.Replace("wordsum", amnt.ToWords(), true, true);
            doc.Replace("amount", AmountToBePaid.Content.ToString(), true, true);
            doc.Replace("Total1", "P " + AmountToBePaid.Content.ToString(), true, true);
            doc.Replace("cashier", pmsutil.GetEmpName(Application.Current.Resources["uid"].ToString()), true, true);
            doc.Replace("123456", OR, true, true);

            int count1 = 1;

            for (int i = 0; i < _list.Count; i++)
            {
                Transaction ti = (Transaction)_list[i];

                using (conn = new MySqlConnection(dbman.GetConnStr()))
                {
                    conn.Open();
                    if (conn.State == ConnectionState.Open)
                    {
                        MySqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "SELECT * FROM transactions WHERE transaction_id = @transaction_id LIMIT 1;";
                        cmd.Parameters.AddWithValue("@transaction_id", ti.TransactionID);
                        cmd.Prepare();
                        MySqlDataReader db_reader = cmd.ExecuteReader();
                        while (db_reader.Read())
                        {
                            if (db_reader.GetString("status") == "Unpaid")
                            {
                                tid   = ti.TransactionID;
                                ornum = OR;

                                doc.Replace("Item" + count1, db_reader.GetString("type"), true, true);
                                doc.Replace("Amount" + count1, db_reader.GetString("fee"), true, true);
                                count1++;

                                UpdateTransaction();
                            }
                        }
                    }
                }
            }
            for (int xtemp = 12; count1 <= xtemp; count1++)
            {
                doc.Replace("Item" + count1, "", true, true);
                doc.Replace("Amount" + count1, "", true, true);
            }

            string fname = "Receipt-No-" + OR + "-" + DateTime.Now.ToString("MMM_dd_yyyy") + ".pdf";

            doc.SaveToFile("Data\\print_receipt.docx", Spire.Doc.FileFormat.Docx);

            //Load Document
            Document document = new Document();

            document.LoadFromFile(@"Data\\print_receipt.docx");

            //Convert Word to PDF
            document.SaveToFile("Receipts\\" + fname, Spire.Doc.FileFormat.PDF);

            System.Diagnostics.Process.Start("Receipts\\" + fname);
            this.Close();
            trans1.SyncTransactions();
        }