예제 #1
0
        //=====================select do line======================
        public void get_do_line(String id_do)
        {
            string  command;
            koneksi ckon = new koneksi();

            do_id = id_do;
            //String sql = "SELECT * FROM deliveryorder_line WHERE DELIVERY_ORDER_ID = '" + do_id + "'";
            //ckon3.cmd3 = new MySqlCommand(sql, ckon3.con3);
            //ckon3.con3.Open();
            //ckon3.myReader3 = ckon3.cmd3.ExecuteReader();
            //while (ckon3.myReader3.Read())
            //{
            //    art_id_do = ckon3.myReader3.GetString("ARTICLE_ID");
            //    qty_receive = ckon3.myReader3.GetInt32("QTY_RECEIVE");
            //    cek_qty_inv(art_id_do);
            //    cek_inv_line(do_id, qty_receive);
            //}

            //ckon3.con3.Close();

            try
            {
                ckon.sqlCon().Open();
                command = "SELECT a.QTY_RECEIVE, b._id FROM deliveryorder_line a JOIN article b "
                          + "ON a.ARTICLE_ID = b.ARTICLE_ID WHERE DELIVERY_ORDER_ID = '" + do_id + "' AND QTY_RECEIVE > 0";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        art_id_do   = ckon.sqlDataRd["_id"].ToString();
                        qty_receive = Convert.ToInt32(ckon.sqlDataRd["QTY_RECEIVE"].ToString());
                        cek_qty_inv(art_id_do);
                        cek_inv_line(do_id, qty_receive);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #2
0
        //======================================================================
        public void get_id(String id)
        {
            string  command;
            koneksi ckon = new koneksi();

            //ckon.con.Close();
            //string sql = "SELECT * FROM article WHERE ARTICLE_ID = '" + id +"'";
            //ckon.cmd = new MySqlCommand(sql, ckon.con);
            //ckon.con.Open();
            //ckon.myReader = ckon.cmd.ExecuteReader();
            //while(ckon.myReader.Read())
            //{
            //    id_from_article = ckon.myReader.GetString("_id");
            //}
            //cek_qty_inv(id_from_article);
            //ckon.con.Close();

            try
            {
                ckon.sqlCon().Open();
                command = "SELECT * FROM article WHERE ARTICLE_ID = '" + id + "'";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        id_from_article = ckon.sqlDataRd["_id"].ToString();
                    }

                    cek_qty_inv(id_from_article);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #3
0
        //======================AMBIL TOTAL ARTICLE ID DARI INVENTORY, LALU DIKURANGI DAN DIUPDATE====================
        public void cek_qty_inv(String art_id)
        {
            string  command;
            koneksi ckon = new koneksi();

            article_id = art_id;
            try
            {
                ckon.sqlCon().Open();
                command = "SELECT * FROM inventory WHERE ARTICLE_ID = '" + art_id + "' AND GOOD_QTY > 0";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        status_inv = "YES";
                        qty_inv    = Convert.ToInt32(ckon.sqlDataRd["GOOD_QTY"].ToString());
                    }
                }
                else
                {
                    status_inv = "NO";
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #4
0
        //====================FROM VOID TRANSACTION==========================
        public void void_trans(String id)
        {
            string  command;
            koneksi ckon = new koneksi();

            void_id = id;
            //String sql = "SELECT * FROM transaction_line WHERE TRANSACTION_ID = '" + void_id + "'";
            //ckon3.cmd3 = new MySqlCommand(sql, ckon3.con3);
            //ckon3.con3.Open();
            //ckon3.myReader3 = ckon3.cmd3.ExecuteReader();
            //while(ckon3.myReader3.Read())
            //{
            //    art_id = ckon3.myReader3.GetString("ARTICLE_ID");
            //    qty_trans_line = ckon3.myReader3.GetInt32("QUANTITY");
            //    String sql2 = "SELECT * FROM article WHERE ARTICLE_ID = '" + art_id + "'";
            //    ckon4.cmd4 = new MySqlCommand(sql2, ckon4.con4);
            //    ckon4.con4.Open();
            //    ckon4.myReader4 = ckon4.cmd4.ExecuteReader();
            //    while(ckon4.myReader4.Read())
            //    {
            //        inv_id = ckon4.myReader4.GetString("_id");
            //        cek_qty_inv(inv_id);//mengambil good qty dari inventory sesuai id
            //        cek_inv_line(void_id, qty_trans_line);
            //    }

            //    ckon4.con4.Close();
            //}
            //ckon3.con3.Close();

            try
            {
                ckon.sqlCon().Open();
                command = "SELECT article._id as artId, * FROM transaction_line INNER JOIN article "
                          + "ON article.ARTICLE_ID = transaction_line.ARTICLE_ID "
                          + "WHERE transaction_line.TRANSACTION_ID = '" + void_id + "'";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        qty_trans_line = Convert.ToInt32(ckon.sqlDataRd["QUANTITY"].ToString());
                        inv_id         = ckon.sqlDataRd["artId"].ToString();
                        cek_qty_inv(inv_id);//mengambil good qty dari inventory sesuai id
                        cek_inv_line(void_id, qty_trans_line);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #5
0
        //======Cek Di inventory Line, kalo kosong input, kalo ada update==============
        public void cek_inv_line(String trans_id, int qty)
        {
            string  command;
            koneksi ckon  = new koneksi();
            int     count = 0;

            transaksi_id  = trans_id;
            qty_min_plus2 = qty;

            try
            {
                ckon.sqlCon().Open();
                command = "SELECT * FROM inventory_line WHERE TRANS_REF_ID = '" + transaksi_id + "' AND ARTICLE_ID = '" + article_id + "'";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        count    = count + 1;
                        qty_line = Convert.ToInt32(ckon.sqlDataRd["QTY"].ToString());
                    }
                }

                if (count == 0)
                {
                    if (type_id == "1")
                    {
                        int    I     = 1;
                        String sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '-" + I + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv - 1;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                    else if (type_id == "2")
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        //==========JIKA INVENTORY TELAH ADA
                        if (status_inv == "YES")
                        {
                            qty_total_inv_fix = qty_inv + qty_min_plus2;
                            String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                            CRUD   UPDATE = new CRUD();
                            UPDATE.ExecuteNonQuery(sql3);
                        }
                        //=====JIKA INVENTORY BELOM ADA====
                        else
                        {
                            String input_inv  = "INSERT INTO inventory (ARTICLE_ID,GOOD_QTY) VALUES ('" + article_id + "','" + qty_min_plus2 + "')";
                            CRUD   input_baru = new CRUD();
                            input_baru.ExecuteNonQuery(input_inv);
                        }
                    }
                    else if (type_id == "4")
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv + qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                    else if (type_id == "3" || type_id == "10")
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv - qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                    else
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv - qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                }
                else
                {
                    if (type_id == "1")
                    {
                        qty_line = qty_line + (qty_min_plus2);
                        String sql3   = "UPDATE inventory_line SET QTY='" + qty_line + "' WHERE TRANS_REF_ID='" + transaksi_id + "' AND ARTICLE_ID = '" + article_id + "'";
                        CRUD   update = new CRUD();
                        update.ExecuteNonQuery(sql3);

                        qty_total_inv_fix = qty_inv + (qty_min_plus2);
                        String sql4   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql4);
                    }
                    else if (type_id == "2")
                    {
                        //qty_line = qty_line + 1;
                        String sql3   = "UPDATE inventory_line SET QTY='" + qty_line + "' WHERE TRANS_REF_ID='" + transaksi_id + "' AND ARTICLE_ID = '" + article_id + "'";
                        CRUD   update = new CRUD();
                        update.ExecuteNonQuery(sql3);
                        //==========JIKA INVENTORY TELAH ADA
                        if (status_inv == "YES")
                        {
                            qty_total_inv_fix = qty_inv + qty_min_plus2;
                            String sql3A  = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                            CRUD   UPDATE = new CRUD();
                            UPDATE.ExecuteNonQuery(sql3A);
                        }
                        //=====JIKA INVENTORY BELOM ADA====
                        else
                        {
                            String input_inv  = "INSERT INTO inventory (_id,ARTICLE_ID,GOOD_QTY) VALUES ('" + article_id + "','" + article_id + "','" + qty_min_plus2 + "')";
                            CRUD   input_baru = new CRUD();
                            input_baru.ExecuteNonQuery(input_inv);
                        }
                    }
                    else if (type_id == "4")
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv + qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                    else if (type_id == "3" || type_id == "10")
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv - qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                    else
                    {
                        string sql2  = "INSERT INTO inventory_line (TRANS_TYPE, TRANS_TYPE_NAME, TRANS_REF_ID, QTY,ARTICLE_ID) VALUES ('" + type_id + "','" + type_name + "', '" + transaksi_id + "', '" + qty_min_plus2 + "', '" + article_id + "')";
                        CRUD   input = new CRUD();
                        input.ExecuteNonQuery(sql2);

                        qty_total_inv_fix = qty_inv - qty_min_plus2;
                        String sql3   = "UPDATE inventory SET GOOD_QTY='" + qty_total_inv_fix + "' WHERE ARTICLE_ID='" + article_id + "'";
                        CRUD   UPDATE = new CRUD();
                        UPDATE.ExecuteNonQuery(sql3);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #6
0
        //=======RETURN ORDER OUT========
        public void return_order(String id)
        {
            string  command;
            koneksi ckon = new koneksi();

            return_id = id;
            //String sql = "SELECT * FROM returnorder_line WHERE RETURN_ORDER_ID = '" + return_id + "'";
            //ckon3.cmd3 = new MySqlCommand(sql, ckon3.con3);
            //ckon3.con3.Open();
            //ckon3.myReader3 = ckon3.cmd3.ExecuteReader();
            //while (ckon3.myReader3.Read())
            //{
            //    art_id = ckon3.myReader3.GetString("ARTICLE_ID");
            //    qty_trans_line = ckon3.myReader3.GetInt32("QUANTITY");
            //    String sql2 = "SELECT * FROM article WHERE ARTICLE_ID = '" + art_id + "'";
            //    ckon4.cmd4 = new MySqlCommand(sql2, ckon4.con4);
            //    ckon4.con4.Open();
            //    ckon4.myReader4 = ckon4.cmd4.ExecuteReader();
            //    while (ckon4.myReader4.Read())
            //    {
            //        inv_id = ckon4.myReader4.GetString("_id");
            //        cek_qty_inv(inv_id);
            //        cek_inv_line(return_id, qty_trans_line);
            //    }

            //    ckon4.con4.Close();
            //}
            //ckon3.con3.Close();

            try
            {
                ckon.sqlCon().Open();
                command = "SELECT article._Id, returnorder_line.QUANTITY FROM returnorder_line INNER JOIN article "
                          + "ON article.ARTICLE_ID = returnorder_line.ARTICLE_ID "
                          + "WHERE RETURN_ORDER_ID = '" + return_id + "'";
                CRUD sql = new CRUD();
                ckon.sqlDataRd = sql.ExecuteDataReader(command, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        qty_trans_line = Convert.ToInt32(ckon.sqlDataRd["QUANTITY"].ToString());
                        inv_id         = ckon.sqlDataRd["_id"].ToString();
                        cek_qty_inv(inv_id);
                        cek_inv_line(return_id, qty_trans_line);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
예제 #7
0
        public void retreive(String transaksi, String code_store, String id_cust)
        {
            koneksi  ckon  = new koneksi();
            koneksi2 ckon2 = new koneksi2();

            String art_id, art_name, spg_id, size, color, qty, disc_desc, sub_total2, discount_code, discount_code_get;
            int    price, sub_total, disc, disc_type_new, status_diskon_api;


            Transaction transaction = new Transaction();

            transaction.storeCode  = code_store;
            transaction.customerId = id_cust;
            List <TransactionLine> transLine = new List <TransactionLine>();


            String sql = "SELECT transaction_line._id ,transaction_line.ARTICLE_ID ,transaction_line.QUANTITY, transaction_line.SUBTOTAL, transaction_line.SPG_ID, transaction_line.DISCOUNT, transaction_line.DISCOUNT_DESC,transaction_line.DISCOUNT_TYPE,transaction_line.DISCOUNT_CODE, article.ARTICLE_NAME, article.SIZE, article.COLOR, article.PRICE FROM transaction_line, article  WHERE article.ARTICLE_ID = transaction_line.ARTICLE_ID AND transaction_line.TRANSACTION_ID='" + transaksi + "' ORDER BY transaction_line._id ASC";

            ckon.cmd = new MySqlCommand(sql, ckon.con);
            try
            {
                ckon.con.Open();
                //=====================================================================================
                ckon.myReader = ckon.cmd.ExecuteReader();
                while (ckon.myReader.Read())
                {
                    art_id        = ckon.myReader.GetString("ARTICLE_ID");
                    art_name      = ckon.myReader.GetString("ARTICLE_NAME");
                    spg_id        = ckon.myReader.GetString("SPG_ID");
                    size          = ckon.myReader.GetString("SIZE");
                    color         = ckon.myReader.GetString("COLOR");
                    price         = ckon.myReader.GetInt32("PRICE");
                    qty           = ckon.myReader.GetString("QUANTITY");
                    disc_desc     = ckon.myReader.GetString("DISCOUNT_DESC");
                    sub_total     = ckon.myReader.GetInt32("SUBTOTAL");
                    disc          = ckon.myReader.GetInt32("DISCOUNT");
                    disc_type_new = ckon.myReader.GetInt32("DISCOUNT_TYPE");
                    discount_code = ckon.myReader.GetString("DISCOUNT_CODE");


                    //==============================================================================
                    string query = "SELECT * FROM ARTICLE WHERE ARTICLE_ID='" + art_id + "'";
                    ckon2.cmd2 = new MySqlCommand(query, ckon2.con2);
                    ckon2.con2.Open();
                    ckon2.myReader2 = ckon2.cmd2.ExecuteReader();
                    Article articleFromDb = new Article();
                    while (ckon2.myReader2.Read())
                    {
                        articleFromDb.articleId      = ckon2.myReader2.GetString("ARTICLE_ID");
                        articleFromDb.articleName    = ckon2.myReader2.GetString("ARTICLE_NAME");
                        articleFromDb.brand          = ckon2.myReader2.GetString("BRAND");
                        articleFromDb.color          = ckon2.myReader2.GetString("COLOR");
                        articleFromDb.department     = ckon2.myReader2.GetString("DEPARTMENT");
                        articleFromDb.departmentType = ckon2.myReader2.GetString("DEPARTMENT_TYPE");
                        articleFromDb.gender         = ckon2.myReader2.GetString("GENDER");
                        articleFromDb.id             = ckon2.myReader2.GetInt32("_id");
                        articleFromDb.price          = ckon2.myReader2.GetInt32("PRICE");
                        articleFromDb.size           = ckon2.myReader2.GetString("SIZE");
                        articleFromDb.unit           = ckon2.myReader2.GetString("UNIT");
                        articleFromDb.articleIdAlias = ckon2.myReader2.GetString("ARTICLE_ID_ALIAS");
                    }
                    ckon2.con2.Close();
                    //======================================================================
                    TransactionLine t = new TransactionLine();

                    t.discount     = disc;
                    t.subtotal     = sub_total;
                    t.quantity     = Int32.Parse(qty);
                    t.price        = price;
                    t.discountType = disc_type_new;
                    t.discountCode = discount_code;
                    t.article      = articleFromDb;
                    transLine.Add(t);
                }
                //=====================================================================================

                transaction.transactionLines = transLine;
                ckon.con.Close();

                BiensiPosDbContext.BiensiPosDbDataContext contex = new BiensiPosDbContext.BiensiPosDbDataContext();
                DiscountCalculate dc         = new DiscountCalculate(contex);
                DiscountMaster    resultData = dc.Post(transaction);
                Console.WriteLine(JsonConvert.SerializeObject(transaction));
                //=================================================
                //for (int i = 0; i < resultData.discounts.Count; i++)
                //{
                //    discount_code_get = resultData.discounts[i].discountCode;
                //    data_diskon(discount_code_get);
                //}
                foreach (var c in resultData.discounts)
                {
                    var b = c.discountApiItems.ToList();

                    discount_code_get = c.discountCode;
                    status_diskon_api = c.status;
                    String art_diskon = c.articleId;
                    int    disc_type  = c.discountType;
                    //=================insert ke table disctype2 saat type diskon 2 dan status 1===========
                    if (c.status == 1 && c.discountType == 2)
                    {
                        String del    = "delete from disctype2";
                        CRUD   update = new CRUD();
                        update.ExecuteNonQuery(del);
                        foreach (var a in b)
                        {
                            var hasil = a.price - a.amountDiscount;

                            String input  = "Insert into disctype2 (TransId, articleid, Price, Discount, TotHarga, DiscountRetailId, DiscPersent) values ('" + transaksi + "','" + a.articleId + "','" + a.price + "','" + a.amountDiscount + "','" + hasil + "','" + a.discountCode + "','" + a.discountDesc + "')";
                            CRUD   insert = new CRUD();
                            insert.ExecuteNonQuery(input);
                        }
                    }
                    if (c.status == 1 && c.discountType == 3)
                    {
                        if (resultData.discountItems != null)
                        {
                            foreach (var a in resultData.discountItems)
                            {
                                int    price_real = 0, qty_real = 0, result_real = 0;
                                String search = "Select * from transaction_line where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + a.articleId + "'";
                                ckon.cmd = new MySqlCommand(search, ckon.con);
                                ckon.con.Open();
                                ckon.myReader = ckon.cmd.ExecuteReader();
                                while (ckon.myReader.Read())
                                {
                                    price_real = ckon.myReader.GetInt32("PRICE");
                                    qty_real   = ckon.myReader.GetInt32("QUANTITY");
                                }
                                ckon.con.Close();
                                result_real = qty_real * price_real;

                                String update_transline = "UPDATE transaction_line SET SUBTOTAL = '" + result_real + "', Discount = '0', DISCOUNT_TYPE = '" + a.discountType + "', DISCOUNT_CODE = '" + a.discountCode + "', DISCOUNT_DESC = '" + a.discountCode + "' where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + a.articleId + "'";
                                CRUD   new_query        = new CRUD();
                                new_query.ExecuteNonQuery(update_transline);
                            }
                        }
                        if (c.discountApiItems != null)
                        {
                            foreach (var aa in c.discountApiItems)
                            {
                                int    price_real = 0, qty_real = 0, result_real = 0;
                                String coodee = ""; String article_id_update = "";
                                String search = "Select * from transaction_line where TRANSACTION_ID = '" + transaksi + "' ";
                                ckon.cmd = new MySqlCommand(search, ckon.con);
                                ckon.con.Open();
                                ckon.myReader = ckon.cmd.ExecuteReader();
                                while (ckon.myReader.Read())
                                {
                                    //price_real = ckon.myReader.GetInt32("PRICE");
                                    //qty_real = ckon.myReader.GetInt32("QUANTITY");
                                    coodee            = ckon.myReader.GetString("DISCOUNT_CODE");
                                    article_id_update = ckon.myReader.GetString("ARTICLE_ID");
                                    result_real       = price_real * qty_real;
                                    if (coodee == aa.discountCode)
                                    {
                                        result_real = aa.qty * Convert.ToInt32(aa.price);

                                        String update_transline = "UPDATE transaction_line SET SUBTOTAL = '" + result_real + "', Discount = '0', DISCOUNT_TYPE = '" + aa.discountType + "', DISCOUNT_CODE = '" + aa.discountCode + "', DISCOUNT_DESC = '" + aa.discountCode + "' where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + aa.articleId + "'";
                                        CRUD   new_query        = new CRUD();
                                        new_query.ExecuteNonQuery(update_transline);
                                    }
                                }
                                ckon.con.Close();
                            }
                        }
                    }
                    //=================UPADTE STATUS DISKON KE DATABASE LOKAL(PROMOTION HEADER)=============
                }
                ckon.con.Close();
            }

            catch (Exception ex)
            { MessageBox.Show(ex.ToString()); }
        }
예제 #8
0
        public void cek_article(string _articleId, int _qty)
        {
            CRUD    sql       = new CRUD();
            koneksi ckonCheck = new koneksi();
            String  cmd_article;
            String  cmd_invent;
            Boolean hasRows = false;

            try
            {
                ckon.sqlCon().Open();
                ckonCheck.sqlCon().Open();

                cmd_article         = "SELECT * FROM article WHERE article.ARTICLE_ID_ALIAS = '" + _articleId + "'";
                ckonCheck.sqlDataRd = sql.ExecuteDataReader(cmd_article, ckonCheck.sqlCon());

                if (ckonCheck.sqlDataRd.HasRows)
                {
                    while (ckonCheck.sqlDataRd.Read())
                    {
                        artIdLoc = ckonCheck.sqlDataRd["ARTICLE_ID"].ToString();
                        hasRows  = true;
                    }
                }

                if (hasRows)
                {
                    if (ckon.sqlDataRd != null)
                    {
                        ckon.sqlDataRd.Close();
                    }

                    cmd_article          = "SELECT * FROM article WHERE ARTICLE_ID = '" + artIdLoc + "'";
                    ckon.sqlDataRdHeader = sql.ExecuteDataReader(cmd_article, ckon.sqlCon());

                    if (ckon.sqlDataRdHeader.HasRows)
                    {
                        while (ckon.sqlDataRdHeader.Read())
                        {
                            id_inv = ckon.sqlDataRdHeader["_id"].ToString();
                        }

                        cmd_invent     = "SELECT * FROM inventory WHERE ARTICLE_ID = " + id_inv + " AND GOOD_QTY >= 1";
                        ckon.sqlDataRd = sql.ExecuteDataReader(cmd_invent, ckon.sqlCon());

                        if (ckon.sqlDataRd.HasRows)
                        {
                            //MEMOTONG ARTICLE
                            Inv_Line inv          = new Inv_Line();
                            int      qty_min_plus = _qty;
                            String   type_trans   = "10";
                            inv.cek_qty_inv(id_inv);
                            inv.cek_type_trans(type_trans);
                            inv.cek_inv_line(t_delivCustId.Text, qty_min_plus);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Article Not Found");
                    }
                }
                else
                {
                    if (ckon.sqlDataRd != null)
                    {
                        ckon.sqlDataRd.Close();
                    }

                    cmd_article          = "SELECT * FROM article WHERE ARTICLE_ID = '" + artIdLoc + "'";
                    ckon.sqlDataRdHeader = sql.ExecuteDataReader(cmd_article, ckon.sqlCon());

                    if (ckon.sqlDataRdHeader.HasRows)
                    {
                        while (ckon.sqlDataRdHeader.Read())
                        {
                            id_inv = ckon.sqlDataRdHeader["_id"].ToString();
                        }

                        cmd_invent     = "SELECT * FROM inventory WHERE ARTICLE_ID = " + id_inv + " AND GOOD_QTY >= 1";
                        ckon.sqlDataRd = sql.ExecuteDataReader(cmd_invent, ckon.sqlCon());

                        if (ckon.sqlDataRd.HasRows)
                        {
                            //MEMOTONG ARTICLE
                            Inv_Line inv          = new Inv_Line();
                            int      qty_min_plus = _qty;
                            String   type_trans   = "10";
                            inv.cek_qty_inv(id_inv);
                            inv.cek_type_trans(type_trans);
                            inv.cek_inv_line(t_delivCustId.Text, qty_min_plus);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Article Not Found");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }
        public void retreive(String transaksi, String code_store, String id_cust)
        {
            koneksi ckon = new koneksi();

            String art_id, art_name, spg_id, size, color, qty, disc_desc, sub_total2, discount_code, discount_code_get;
            int    price, sub_total, disc, disc_type_new, status_diskon_api;

            CRUD        sql         = new CRUD();
            Transaction transaction = new Transaction();

            transaction.storeCode  = code_store;
            transaction.customerId = id_cust;
            List <TransactionLine> transLine = new List <TransactionLine>();
            Article articleFromDb            = new Article();

            try
            {
                ckon.sqlCon().Open();
                String cmd = "SELECT article._id ,transaction_line.ARTICLE_ID ,transaction_line.QUANTITY, transaction_line.SUBTOTAL, transaction_line.SPG_ID, transaction_line.DISCOUNT, "
                             + "transaction_line.DISCOUNT_DESC,transaction_line.DISCOUNT_TYPE,transaction_line.DISCOUNT_CODE, article.ARTICLE_NAME, article.SIZE, article.COLOR, article.PRICE, "
                             + "article.BRAND, article.DEPARTMENT, article.DEPARTMENT_TYPE, article.GENDER, article.UNIT, article.ARTICLE_ID_ALIAS FROM transaction_line, article "
                             + "WHERE article.ARTICLE_ID = transaction_line.ARTICLE_ID AND transaction_line.TRANSACTION_ID = '" + transaksi + "' ORDER BY transaction_line._id ASC";
                ckon.sqlDataRd = sql.ExecuteDataReader(cmd, ckon.sqlCon());

                if (ckon.sqlDataRd.HasRows)
                {
                    while (ckon.sqlDataRd.Read())
                    {
                        art_id        = ckon.sqlDataRd["ARTICLE_ID"].ToString();
                        art_name      = ckon.sqlDataRd["ARTICLE_NAME"].ToString();
                        spg_id        = ckon.sqlDataRd["SPG_ID"].ToString();
                        size          = ckon.sqlDataRd["SIZE"].ToString();
                        color         = ckon.sqlDataRd["COLOR"].ToString();
                        price         = Convert.ToInt32(ckon.sqlDataRd["PRICE"].ToString());
                        qty           = ckon.sqlDataRd["QUANTITY"].ToString();
                        disc_desc     = ckon.sqlDataRd["DISCOUNT_DESC"].ToString();
                        sub_total     = Convert.ToInt32(ckon.sqlDataRd["SUBTOTAL"].ToString());
                        disc          = Convert.ToInt32(ckon.sqlDataRd["DISCOUNT"].ToString());
                        disc_type_new = Convert.ToInt32(ckon.sqlDataRd["DISCOUNT_TYPE"].ToString());
                        discount_code = ckon.sqlDataRd["DISCOUNT_CODE"].ToString();

                        articleFromDb.articleId      = ckon.sqlDataRd["ARTICLE_ID"].ToString();
                        articleFromDb.articleName    = ckon.sqlDataRd["ARTICLE_NAME"].ToString();
                        articleFromDb.brand          = ckon.sqlDataRd["BRAND"].ToString();
                        articleFromDb.color          = ckon.sqlDataRd["COLOR"].ToString();
                        articleFromDb.department     = ckon.sqlDataRd["DEPARTMENT"].ToString();
                        articleFromDb.departmentType = ckon.sqlDataRd["DEPARTMENT_TYPE"].ToString();
                        articleFromDb.gender         = ckon.sqlDataRd["GENDER"].ToString();
                        articleFromDb.id             = Convert.ToInt32(ckon.sqlDataRd["_id"].ToString());
                        articleFromDb.price          = Convert.ToInt32(ckon.sqlDataRd["PRICE"].ToString());
                        articleFromDb.size           = ckon.sqlDataRd["SIZE"].ToString();
                        articleFromDb.unit           = ckon.sqlDataRd["UNIT"].ToString();
                        articleFromDb.articleIdAlias = ckon.sqlDataRd["ARTICLE_ID_ALIAS"].ToString();

                        //======================================================================
                        TransactionLine t = new TransactionLine();

                        t.discount     = disc;
                        t.subtotal     = sub_total;
                        t.quantity     = Int32.Parse(qty);
                        t.price        = price;
                        t.discountType = disc_type_new;
                        t.discountCode = discount_code;
                        t.article      = articleFromDb;
                        transLine.Add(t);
                    }
                }
                //=====================================================================================

                transaction.transactionLines = transLine;

                BiensiPOSContext.BiensiPOSDataContext contex = new BiensiPOSContext.BiensiPOSDataContext();
                DiscountCalculateNew dc         = new DiscountCalculateNew(contex);
                DiscountMaster       resultData = dc.Post(transaction);
                Console.WriteLine(JsonConvert.SerializeObject(transaction));
                //=================================================
                //for (int i = 0; i < resultData.discounts.Count; i++)
                //{
                //    discount_code_get = resultData.discounts[i].discountCode;
                //    data_diskon(discount_code_get);
                //}
                foreach (var c in resultData.discounts)
                {
                    var b = c.discountApiItems.ToList();

                    discount_code_get = c.discountCode;
                    status_diskon_api = c.status;
                    String art_diskon = c.articleId;
                    int    disc_type  = c.discountType;
                    //=================insert ke table disctype2 saat type diskon 2 dan status 1===========
                    if (c.status == 1 && c.discountType == 2)
                    {
                        String cmd_delete = "delete from disctype2";
                        sql.ExecuteNonQuery(cmd_delete);
                        foreach (var a in b)
                        {
                            var hasil = a.price - a.amountDiscount;

                            String cmd_insert = "Insert into disctype2 (TransId, articleid, Price, Discount, TotHarga, DiscountRetailId, DiscPersent) values ('" + transaksi + "','" + a.articleId + "','" + a.price + "','" + a.amountDiscount + "','" + hasil + "','" + a.discountCode + "','" + a.discountDesc + "')";
                            sql.ExecuteNonQuery(cmd_insert);
                        }
                    }
                    if (c.status == 1 && c.discountType == 3)
                    {
                        if (resultData.discountItems != null)
                        {
                            foreach (var a in resultData.discountItems)
                            {
                                int    price_real = 0, qty_real = 0, result_real = 0;
                                String cmd_transLine = "Select * from transaction_line where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + a.articleId + "'";
                                ckon.sqlDataRd = sql.ExecuteDataReader(cmd_transLine, ckon.sqlCon());

                                if (ckon.sqlDataRd.HasRows)
                                {
                                    while (ckon.sqlDataRd.Read())
                                    {
                                        price_real = Convert.ToInt32(ckon.sqlDataRd["PRICE"].ToString());
                                        qty_real   = Convert.ToInt32(ckon.sqlDataRd["QUANTITY"].ToString());
                                    }
                                }
                                result_real = qty_real * price_real;

                                String cmd_update = "UPDATE transaction_line SET SUBTOTAL = '" + result_real + "', Discount = '0', DISCOUNT_TYPE = '" + a.discountType + "', DISCOUNT_CODE = '" + a.discountCode + "', DISCOUNT_DESC = '" + a.discountCode + "' where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + a.articleId + "'";
                                sql.ExecuteNonQuery(cmd_update);
                            }
                        }
                        if (c.discountApiItems != null)
                        {
                            foreach (var aa in c.discountApiItems)
                            {
                                int    price_real = 0, qty_real = 0, result_real = 0;
                                String coodee = ""; String article_id_update = "";
                                String cmd_transLine = "Select * from transaction_line where TRANSACTION_ID = '" + transaksi + "' ";
                                ckon.sqlDataRd = sql.ExecuteDataReader(cmd_transLine, ckon.sqlCon());

                                if (ckon.sqlDataRd.HasRows)
                                {
                                    while (ckon.sqlDataRd.Read())
                                    {
                                        coodee            = ckon.sqlDataRd["DISCOUNT_CODE"].ToString();
                                        article_id_update = ckon.sqlDataRd["ARTICLE_ID"].ToString();
                                        result_real       = price_real * qty_real;
                                        if (coodee == aa.discountCode)
                                        {
                                            result_real = aa.qty * Convert.ToInt32(aa.price);

                                            String cmd_update = "UPDATE transaction_line SET SUBTOTAL = '" + result_real + "', Discount = '0', DISCOUNT_TYPE = '" + aa.discountType + "', DISCOUNT_CODE = '" + aa.discountCode + "', DISCOUNT_DESC = '" + aa.discountCode + "' where TRANSACTION_ID = '" + transaksi + "' AND ARTICLE_ID = '" + aa.articleId + "'";
                                            sql.ExecuteNonQuery(cmd_update);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //=================UPADTE STATUS DISKON KE DATABASE LOKAL(PROMOTION HEADER)=============
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ckon.sqlDataRd != null)
                {
                    ckon.sqlDataRd.Close();
                }

                if (ckon.sqlCon().State == ConnectionState.Open)
                {
                    ckon.sqlCon().Close();
                }
            }
        }