コード例 #1
0
        public static void generateInvoice()
        {
            int idx = idxH_Trans;
            H_Trans_ItemModel hti = new H_Trans_ItemModel();
            DataRow           row = hti.Table.Select($"ID ='{list_htrans[idx].ID}'").FirstOrDefault();

            if (row["STATUS"].ToString() == "P")
            {
                CustomerInvoice customerInvoice = new CustomerInvoice();
                ReportView      rv = new ReportView(customerInvoice);

                rv.setParam("kodeH_Trans", row["KODE"].ToString());
                if (row["ID_PROMO"].ToString() == "")
                {
                    rv.setParam("kodePromo", "-");
                }
                else
                {
                    PromoModel pm       = new PromoModel();
                    DataRow    rowPromo = pm.Table.Select($"ID = '{row["ID_PROMO"]}'").First();
                    rv.setParam("kodePromo", rowPromo["KODE"].ToString());
                }
                string path = (ImageHelper.getDebugPath() + "\\Resource\\Items\\");
                rv.setParam("imagePath", path);
                rv.ShowDialog();
            }
            else
            {
                MessageBox.Show("Transaksi yang belum dibayar!");
            }
        }
コード例 #2
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 !");
                }
            }
        }
コード例 #3
0
        public static void initH_Trans()
        {
            resetItem();
            list_htrans = new List <Header_Trans_Item>();
            H_Trans_ItemModel hti = new H_Trans_ItemModel();

            foreach (DataRow item in hti.Table.Select($"ID_CUSTOMER ='{Session.User["ID"]}'", "TANGGAL_TRANSAKSI ASC"))
            {
                Header_Trans_Item row = new Header_Trans_Item(
                    iD: item["ID"].ToString(),
                    kODE: item["KODE"].ToString(),
                    tANGGAL_TRANSAKSI: Utility.formatDate(item["TANGGAL_TRANSAKSI"].ToString()),
                    sTATUS: item["STATUS"].ToString()
                    );
                list_htrans.Add(row);
            }
            ViewComponent.grid_H_Trans.ItemsSource           = null;
            ViewComponent.grid_H_Trans.ItemsSource           = list_htrans;
            ViewComponent.grid_H_Trans.Columns[0].Header     = "ID";
            ViewComponent.grid_H_Trans.Columns[0].Visibility = Visibility.Hidden;
            ViewComponent.grid_H_Trans.Columns[1].Header     = "Kode Transaksi";
            ViewComponent.grid_H_Trans.Columns[2].Header     = "Tanggal Transaksi";
            ViewComponent.grid_H_Trans.Columns[3].Header     = "Status";
        }
コード例 #4
0
        public static void bayarTrans()
        {
            //Check trans apakah sudah dibayar atau belum
            //Jika sudah,  buat btn enable false?
            int idx = idxH_Trans;

            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")
                {
                    //Bayar
                    row["STATUS"] = "P";
                    hti.update();
                    initH_Trans();
                    MessageBox.Show("Transaksi berhasil di bayar !");
                }
                else
                {
                    MessageBox.Show("Gagal membayar!");
                }
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
0
 public TransactionViewModel()
 {
     hm        = new H_Trans_ItemModel();
     hm_helper = new H_Trans_ItemModel();
     reloadHtrans();
 }