Beispiel #1
0
        public void selectHtrans(int selected)
        {
            if (selected != -1 && selected < htrans.Table.Rows.Count)
            {
                ViewComponent.checkboxTerimaSemua.IsChecked = false;
                this.h_trans_selected = selected;
                DataRow dr = htrans.Table.Rows[selected];
                forselectdata = new D_Trans_ItemModel();
                forselectdata.initAdapter($"select h.KODE, to_char(h.TANGGAL_TRANSAKSI,'dd-mm-yyyy'), k.NAMA, c.NAMA, c.ALAMAT from H_TRANS_ITEM h, D_TRANS_ITEM d, KURIR k, CUSTOMER c, ITEM i where d.ID_ITEM = i.ID and h.ID_CUSTOMER = c.ID and d.ID_H_TRANS_ITEM = h.ID and h.KODE = '{dr[0].ToString()}' {status}");
                dr = forselectdata.Table.Rows[0];
                ViewComponent.labelKodePesanan.Content        = dr[0].ToString();
                ViewComponent.labelTanggalTransaksi.Content   = dr[1].ToString();
                ViewComponent.labelKurir.Content              = dr[2].ToString();
                ViewComponent.labelNamaPembeli.Content        = dr[3].ToString();
                ViewComponent.textboxAlamatPesanan.Text       = dr[4].ToString();
                ViewComponent.textboxAlamatPesanan.IsReadOnly = true;
                dtrans = new D_Trans_ItemModel();
                dtrans.initAdapter($"select d.JUMLAH as \"Jumlah\", i.NAMA as \"Nama Barang\", to_char(i.HARGA) as \"Harga\", to_char(i.HARGA * d.JUMLAH) as \"Total\", case d.STATUS when 'W' then 'Pesanan Baru' when 'P' then 'Siap Kirim' when 'S' then 'Dalam Pengiriman' when 'D' then 'Pesanan Selesai' when 'C' then 'Pesanan Dibatalkan' end as \"Status\" from ITEM i, H_TRANS_ITEM h, D_TRANS_ITEM d where h.ID = d.ID_H_TRANS_ITEM and i.ID = d.ID_ITEM and h.KODE = '{dr[0].ToString()}' and i.ID_SELLER = '{seller["ID"]}' {status}");
                dtrans_helper = new D_Trans_ItemModel();
                dtrans_helper.initAdapter($"select d.ID , d.STATUS, i.STOK, d.JUMLAH, i.ID, to_char(i.HARGA * d.JUMLAH) as \"Total\" from ITEM i, H_TRANS_ITEM h, D_TRANS_ITEM d where h.ID = d.ID_H_TRANS_ITEM and i.ID = d.ID_ITEM and h.KODE = '{dr[0].ToString()}' and i.ID_SELLER = '{seller["ID"]}' {status}");
                ViewComponent.datagridProdukPesanan.ItemsSource = dtrans.Table.DefaultView;

                Utility.toCurrency(dtrans.Table, 2);
                Utility.toCurrency(dtrans.Table, 3);
                ViewComponent.canvasDetailPesanan.Visibility = System.Windows.Visibility.Visible;
                hitungTotal();
            }
        }
Beispiel #2
0
 public PagePesanan(SellerView viewComponent, DataRow seller)
 {
     ViewComponent = viewComponent;
     this.seller   = seller;
     htrans        = new D_Trans_ItemModel();
     forselectdata = new D_Trans_ItemModel();
     dtrans        = new D_Trans_ItemModel();
     dtrans_helper = new D_Trans_ItemModel();
 }
        public DataTable getDTrans()
        {
            DataRow dr = hm_helper.Table.Rows[selected];

            dm = new D_Trans_ItemModel();
            dm.initAdapter($"select i.NAMA as \"Nama Item\"" +
                           $", s.NAMA_SELLER as \"Nama Toko\"" +
                           $", to_char(i.HARGA) as \"Harga\"" +
                           $", to_char(d.JUMLAH) as \"Jumlah\"" +
                           $", to_char(d.JUMLAH * i.HARGA) as \"Total\" " +
                           $"from D_TRANS_ITEM d, ITEM i, SELLER s where d.ID_ITEM = i.ID and s.ID = i.ID_SELLER and d.ID_H_TRANS_ITEM = '{dr[0].ToString()}'");

            return(dm.Table);
        }
Beispiel #4
0
        public static void cancelTrans()
        {
            int idx = idxH_Trans;

            //Check trans apakah sudah dibayar atau belum
            // Kalau sudah bayar tpi mau cancel harus cek kalau d transnya sudah ada yang kirim
            // atau belum, Kemudian kalau cancel h trans, harus cancel di semua dtrans
            //Jika sudah,  tidak boleh di cancel
            if (idx >= 0)
            {
                H_Trans_ItemModel hti = new H_Trans_ItemModel();
                DataRow           row = hti.Table.Select($"ID ='{list_htrans[idx].ID}'").FirstOrDefault();
                if (row["STATUS"].ToString() == "W")
                {
                    //Check kalau sudah ada yang S
                    D_Trans_ItemModel dti = new D_Trans_ItemModel();
                    bool valid            = true;
                    foreach (DataRow rowDTI in dti.Table.Select($"ID_H_TRANS_ITEM = '{row["ID"]}'"))
                    {
                        if (rowDTI["STATUS"].ToString() != "W")
                        {
                            valid = false;
                        }
                    }
                    if (valid)
                    {
                        //Cancel
                        row["STATUS"] = "C";
                        foreach (DataRow rowDTI in dti.Table.Select($"ID_H_TRANS_ITEM = '{row["ID"]}'"))
                        {
                            rowDTI["STATUS"] = "C";
                        }
                        dti.update();
                        hti.update();
                        initH_Trans();
                        loadD_Trans();
                        MessageBox.Show("Transaksi berhasil di cancel !");
                    }
                    else
                    {
                        MessageBox.Show("Tidak bisa dicancel !");
                    }
                }
                else
                {
                    MessageBox.Show("Gagal Cancel !");
                }
            }
        }
Beispiel #5
0
 public static void terimaBarang()
 {
     if (idxItem >= 0)
     {
         int idx = idxItem;
         Detail_Trans_Item dti = list_dtrans[idx];
         //Check kalau DTRANS HARUS SUDAH SELESAI
         if (dti.status == "SHIPPING")
         {
             D_Trans_ItemModel dtim = new D_Trans_ItemModel();
             DataRow           row  = dtim.Table.Select($"ID = '{dti.id}'").FirstOrDefault();
             row["STATUS"] = "D";
             dtim.update();
             //Check if status D_Trans sudah D semua ato blm
             // Kalau D semua nanti penjual dpt duit
             bool valid = true;
             foreach (DataRow item in dtim.Table.Select($"ID_H_TRANS_ITEM = '{row["ID_H_TRANS_ITEM"]}'"))
             {
                 if (item["STATUS"].ToString() != "D")
                 {
                     valid = false;
                 }
             }
             if (valid)
             {
                 foreach (DataRow rowDTI in dtim.Table.Select($"ID_H_TRANS_ITEM = '{row["ID_H_TRANS_ITEM"]}'"))
                 {
                     ItemModel   im     = new ItemModel();
                     DataRow     item   = im.Table.Select($"ID = '{rowDTI["ID_ITEM"]}'").FirstOrDefault();
                     SellerModel sm     = new SellerModel();
                     DataRow     seller = sm.Table.Select($"ID = '{item["ID_SELLER"]}'").FirstOrDefault();;
                     int         saldo  = Convert.ToInt32(row["JUMLAH"]) * Convert.ToInt32(item["HARGA"]);
                     saldo          += Convert.ToInt32(seller["SALDO"]);
                     seller["SALDO"] = saldo;
                     sm.update();
                 }
             }
             loadD_Trans();
             loadItem();
         }
         else
         {
             // Selain Shipping
             MessageBox.Show("ERROR");
         }
     }
 }
        public static void proceedToCheckout()
        {
            //Validasi Promo + Validasi Ada checked + kurir + payment
            //Validasi Ada barang,
            string message = validateProceedCheckout();

            if (message == "Success")
            {
                App.openConnection(out _);
                using (OracleTransaction Transaction = App.connection.BeginTransaction())
                {
                    try
                    {
                        Dictionary <string, int> updateStok  = new Dictionary <string, int>();
                        List <string>            id_items    = new List <string>();
                        H_Trans_ItemModel        hti         = new H_Trans_ItemModel();
                        DataRow                rowHTI        = hti.Table.NewRow();
                        ComboBoxItem           cbiPembayaran = (ComboBoxItem)ViewComponent.cbPaymentMethod.SelectedItem;
                        Metode_PembayaranModel mpm           = new Metode_PembayaranModel();
                        DataRow                dr            = mpm.Table.Select($"NAMA = '{cbiPembayaran.Content}'").First();
                        rowHTI["ID"]                = 0;
                        rowHTI["ID_CUSTOMER"]       = Session.User["ID"].ToString();
                        rowHTI["TANGGAL_TRANSAKSI"] = DateTime.Now;
                        if (checkPromotion(promo, false))
                        {
                            rowHTI["ID_PROMO"] = promo.ID;
                            if (promo.JENIS_POTONGAN == "P")
                            {
                                diskon = Convert.ToInt32((Convert.ToDouble(promo.POTONGAN) * Convert.ToDouble(hargaSebelumOngkir)) / 100.0);
                                diskon = Math.Min(promo.POTONGAN_MAX, diskon);
                            }
                            else
                            {
                                diskon = promo.POTONGAN;
                            }
                        }
                        else
                        {
                            diskon = 0;
                        }
                        //grandtotal = hargasebelumongkir + ongkir - diskon
                        rowHTI["GRANDTOTAL"]           = grandTotal - diskon;
                        rowHTI["SUBTOTAL"]             = hargaSebelumOngkir;
                        rowHTI["ONGKOS_KIRIM"]         = ongkos_kirim;
                        rowHTI["DISKON"]               = diskon;
                        rowHTI["ID_METODE_PEMBAYARAN"] = dr["ID"].ToString();
                        rowHTI["STATUS"]               = "W";
                        hti.insert(rowHTI);
                        D_Trans_ItemModel dti = new D_Trans_ItemModel();
                        int id_hti            = generateID_H_Trans();
                        foreach (ShopCartComponent scc in list_shopcart)
                        {
                            foreach (CartComponent cc in scc.getCarts())
                            {
                                DataRow rowDTI = dti.Table.NewRow();
                                rowDTI["ID"] = 0;
                                rowDTI["ID_H_TRANS_ITEM"] = id_hti;
                                rowDTI["ID_ITEM"]         = cc.getItemID();
                                id_items.Add(cc.getItemID());
                                rowDTI["JUMLAH"]   = cc.getQuantity();
                                rowDTI["ID_KURIR"] = scc.getIDKurir();
                                rowDTI["STATUS"]   = "W";
                                if (updateStok.ContainsKey(cc.getItemID()))
                                {
                                    updateStok[cc.getItemID()] += Convert.ToInt32(cc.getQuantity());
                                }
                                else
                                {
                                    updateStok.Add(cc.getItemID(), Convert.ToInt32(cc.getQuantity()));
                                }
                                dti.insert(rowDTI);
                            }
                        }
                        Transaction.Commit();
                        //Update Stok
                        foreach (var val in updateStok)
                        {
                            string id_item = val.Key;
                            int    qty     = val.Value;
                            // MessageBox.Show(id_item + " - " + qty);
                            ItemModel im   = new ItemModel();
                            DataRow   item = im.Table.Select($"ID ='{id_item}'").FirstOrDefault();
                            if (item != null)
                            {
                                item["STOK"] = Convert.ToInt32(item["STOK"]) - qty;
                            }
                            im.update();
                        }
                        //TODO tambah ke history trans :)
                        foreach (string id_item in id_items)
                        {
                            deleteItemFromCart(Convert.ToInt32(id_item), false);
                        }
                        loadCartItem();
                        updateGrandTotal();
                        TransactionViewModel.initH_Trans();
                        CustomerViewModel.loadItems();
                    }
                    catch (OracleException e)
                    {
                        Transaction.Rollback();
                        MessageBox.Show(e.Message);
                    }
                };
                App.closeConnection(out _);
            }
            else
            {
                MessageBox.Show(message);
            }
        }
Beispiel #7
0
        public static void loadD_Trans()
        {
            if (idxH_Trans >= 0)
            {
                int idx = idxH_Trans;
                //Init Labels
                H_Trans_ItemModel hti = new H_Trans_ItemModel();
                DataRow           row = hti.Table.Select($"ID ='{list_htrans[idx].ID}'").FirstOrDefault();
                if (row["STATUS"].ToString() == "P")
                {
                    ViewComponent.btnCetakInvoice.Visibility = Visibility.Visible;
                }
                else
                {
                    ViewComponent.btnCetakInvoice.Visibility = Visibility.Hidden;
                }
                ViewComponent.tbKodeTrans.Text = row["KODE"].ToString();
                string idPromo = row["ID_PROMO"].ToString() == "" ? "none" : row["ID_PROMO"].ToString();
                if (idPromo != "none")
                {
                    DataRow promo = new DB("PROMO").select().where ("ID", idPromo).getFirst();
                    ViewComponent.tbKodePromo.Text = promo["KODE"].ToString();
                    ViewComponent.tbDiskon.Text    = Utility.formatNumber(Convert.ToInt32(row["DISKON"]));
                }
                else
                {
                    ViewComponent.tbKodePromo.Text = "-";
                    ViewComponent.tbDiskon.Text    = Utility.formatNumber(0);
                }
                ViewComponent.tbStatusTrans.Text = list_htrans[idx].STATUS;
                ViewComponent.tbSubtotal.Text    = Utility.formatNumber(Convert.ToInt32(row["SUBTOTAL"]));
                ViewComponent.tbOngkosKirim.Text = Utility.formatNumber(Convert.ToInt32(row["ONGKOS_KIRIM"]));
                ViewComponent.tbGrandtotal.Text  = Utility.formatMoney(Convert.ToInt32(row["GRANDTOTAL"]));

                // Init Table D Trans

                list_dtrans = new List <Detail_Trans_Item>();
                D_Trans_ItemModel dti = new D_Trans_ItemModel();
                foreach (DataRow rowDTI in dti.Table.Select($"ID_H_TRANS_ITEM = '{row["ID"]}'"))
                {
                    string namaItem = "", namaKurir = "";

                    namaItem = new DB("ITEM")
                               .select()
                               .where ("ID", rowDTI["ID_ITEM"].ToString())
                               .getFirst()
                               ["NAMA"].ToString();
                    namaKurir = new DB("KURIR")
                                .select()
                                .where ("ID", rowDTI["ID_KURIR"].ToString())
                                .getFirst()
                                ["NAMA"].ToString();


                    Detail_Trans_Item dt = new Detail_Trans_Item(
                        id: rowDTI["ID"].ToString(),
                        namaItem: namaItem,
                        jumlah: rowDTI["JUMLAH"].ToString(),
                        namaKurir: namaKurir,
                        status: rowDTI["STATUS"].ToString()
                        );
                    list_dtrans.Add(dt);
                }
                ViewComponent.grid_D_Trans.ItemsSource           = null;
                ViewComponent.grid_D_Trans.ItemsSource           = list_dtrans;
                ViewComponent.grid_D_Trans.Columns[0].Header     = "ID";
                ViewComponent.grid_D_Trans.Columns[1].Header     = "Nama Item";
                ViewComponent.grid_D_Trans.Columns[2].Header     = "Jumlah";
                ViewComponent.grid_D_Trans.Columns[3].Header     = "Kurir";
                ViewComponent.grid_D_Trans.Columns[4].Header     = "Status";
                ViewComponent.grid_D_Trans.Columns[0].Visibility = Visibility.Hidden;
            }
        }