Esempio n. 1
0
        private void PreBill_Click(object sender, RoutedEventArgs e)
        {
            invoive_No p = new invoive_No();

            invoiceno = p.invoice_no();

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connstring))
                {
                    connection.Open();
                    var dateTimeOffset = DateTimeOffset.Parse(DateTime.Now.ToUniversalTime().ToString(), null);
                    var dt             = (dateTimeOffset.DateTime);

                    string command_c_invoice = "insert into c_invoice(c_invoice_id,ad_client_id,ad_org_id,created,createdby,ad_user_id,mobile,discounttype,discountvalue,grandtotal,reason,grandtotal_round_off,total_items_count,balance,order_type,m_warehouse_id,c_bpartner_id,session_id)" +
                                               "OVERRIDING SYSTEM VALUE values('" + invoiceno + "'," + _clientId + "," + _OrgId + ",'" + dt + "'," + _UserID + "," + _UserID + ",0000000,1," + (totalAmount - payableAmount) + "," + payableAmount + ",'" + txtReason.Text + "'," + payableAmount + "," + totalItems + ",0,'Take away'," + _Warehouse_Id + "," + _Bpartner_Id + "," + _sessionID + ")";
                    NpgsqlCommand cmd = new NpgsqlCommand(command_c_invoice, connection);
                    cmd.ExecuteNonQuery();
                    foreach (m_TakeAwayProductRS element in _m_TakeAwayProductRS)
                    {
                        double discountValue = element.Price * element.ItemCount - element.TotalPrice;
                        string c_invoiceline = "insert into c_invoiceline(ad_client_id,ad_org_id,created,createdby,ad_user_id,c_invoice_id,productname,saleprice,qtyinvoiced,discountvalue,linetotalamt)" +
                                               " values(" + _clientId + "," + _OrgId + ",'" + dt + "'," + _UserID + "," + _UserID + "," + invoiceno + ",'" + element.Name + "'," + element.Price + "," + element.ItemCount + "," + discountValue + "," + element.TotalPrice + ")";
                        cmd = new NpgsqlCommand(c_invoiceline, connection);
                        int rowInvoice = cmd.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Pre Bill Generated");
            }
            catch
            {
            }
        }
Esempio n. 2
0
        private void Split_Click(object sender, RoutedEventArgs e)
        {
            invoive_No p = new invoive_No();
            int?       splitinvoiceNo = p.invoice_no();

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connstring))
                {
                    connection.Open();
                    var           dateTimeOffset     = DateTimeOffset.Parse(DateTime.Now.ToUniversalTime().ToString(), null);
                    var           dt                 = (dateTimeOffset.DateTime);
                    NpgsqlCommand cmd                = null;
                    double        totalDiscount      = 0;
                    double        splitPayableamount = 0;
                    double        splitItemCount     = 0;
                    //Updating  c_invoiceline table
                    foreach (m_TakeAwayProductRS element in splitbill)
                    {
                        double discountValue = element.Price * element.ItemCount - element.TotalPrice;
                        totalDiscount      += discountValue;
                        splitPayableamount += element.TotalPrice;
                        splitItemCount     += element.ItemCount;
                        string c_invoiceline = "update c_invoiceline set c_invoice_id = " + splitinvoiceNo + " where c_invoice_id =" + invoiceno + " and productname ='" + element.Name + "'";

                        cmd = new NpgsqlCommand(c_invoiceline, connection);
                        int rowInvoice = cmd.ExecuteNonQuery();
                    }

                    //Updating and adding record to c_invoice table
                    string c_invoice_Update = "update c_invoice set discountvalue= discountvalue - " + totalDiscount + ",grandtotal=grandtotal- " + splitPayableamount + ",grandtotal_round_off=grandtotal_round_off - " + splitPayableamount + ",total_items_count= total_items_count- " + splitItemCount + " where c_invoice_id=" + invoiceno + "";
                    cmd = new NpgsqlCommand(c_invoice_Update, connection);
                    cmd.ExecuteNonQuery();
                    string command_c_invoice = "insert into c_invoice(c_invoice_id,ad_client_id,ad_org_id,created,createdby,ad_user_id,mobile,discounttype,discountvalue,grandtotal,reason,grandtotal_round_off,total_items_count,balance,order_type,m_warehouse_id,c_bpartner_id,session_id)" +
                                               "OVERRIDING SYSTEM VALUE values" +
                                               "('" + splitinvoiceNo + "'," + _clientId + "," + _OrgId + ",'" + dt + "'," +
                                               "" + _UserID + "," + _UserID + ",0000000,1," + totalDiscount + "," +
                                               splitPayableamount + ",'" + txtReason.Text + "'," + splitPayableamount + "," +
                                               splitItemCount +
                                               ",0,'Take away'," + _Warehouse_Id + "," + _Bpartner_Id + "," + _sessionID + ")";
                    cmd = new NpgsqlCommand(command_c_invoice, connection);
                    cmd.ExecuteNonQuery();

                    //updating and adding record to Payment table

                    //INSERT_c_invoicepaymentdetails.ExecuteNonQuery();

                    string c_invoicepaymentdetails_update = "update c_invoicepaymentdetails set cash= cash-" + splitPayableamount + "where c_invoice_id = " + invoiceno + "";
                    cmd = new NpgsqlCommand(c_invoicepaymentdetails_update, connection);
                    cmd.ExecuteNonQuery();

                    string c_invoicepaymentdetails_insert = "INSERT INTO c_invoicepaymentdetails(" +
                                                            " ad_client_id, ad_org_id, c_invoice_id," +
                                                            "cash, card, exchange, redemption, iscomplementary, iscredit, createdby, updatedby)" +
                                                            "VALUES(" + _clientId + "," + _OrgId + "," + splitinvoiceNo + "," + splitPayableamount + ",0,0,0,'N','N'," + _UserID + "," + _UserID + ")";
                    cmd = new NpgsqlCommand(c_invoicepaymentdetails_insert, connection);
                    cmd.ExecuteNonQuery();


                    //END  updating and adding record to Payment table
                    MessageBox.Show("Split Successful");
                }
            }
            catch
            {
            }
        }