Exemple #1
0
        public ActionResult paymentItemList(PaymentItemList paymentData)
        {
            if (Session["isLogin"] != null)
            {
                if (Convert.ToDecimal(paymentData.totalAmount) == 0)
                {
                    Session["PaymentItemList"] = "Total Amount can't be zero(0). Please select an item ";
                    return(RedirectToAction("PaymentItem"));
                }

                Models.invoice invoiceData = new Models.invoice();
                invoiceData.invoice_id  = RandomNumber().ToString();
                invoiceData.name        = Session["name"].ToString();
                invoiceData.AdmissionNo = Session["AdmissionNo"].ToString();
                invoiceData.IGR_Code    = Session["igr"].ToString();
                invoiceData.amount      = Convert.ToDecimal(paymentData.totalAmount);
                invoiceData.create_at   = DateTime.Now;
                try
                {
                    db.invoices.Add(invoiceData);
                    db.SaveChanges();

                    foreach (var item in paymentData.items)
                    {
                        invoiceschoolitem info = new invoiceschoolitem();
                        info.invoice_id  = invoiceData.invoice_id;
                        info.IGR_CODE    = invoiceData.IGR_Code;
                        info.SubHead_ID  = item;
                        info.AdmissionNo = Session["AdmissionNo"].ToString();
                        info.Created_at  = DateTime.Now;

                        db.invoiceschoolitem.Add(info);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    Session["PaymentItemList"] = ex.Message.ToString() + " | Please contact Admin";
                    return(RedirectToAction("PaymentItem"));
                }

                Session["PaymentItemSuccessful"] = "Invoice generated successfully with ID " + invoiceData.invoice_id + " Total Amount " + invoiceData.amount;
                return(RedirectToAction("PaymentItem"));
            }
            return(RedirectToAction("Index"));
        }
        public static bool insert(Models.invoice data)
        {
            bool result = false;

            try
            {
                using (var db = new Models.jotunContext())
                {
                    db.Entry(data).State = EntityState.Added;
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                Helpers.Generic.MsgError(ex.Message);
            }
            return(result);
        }
        private void btn_simpan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (cbo_no_surat_jalan.EditValue == null)
            {
                Helpers.Generic.MsgEx("No. Surat jalan tidak boleh kosong");
                return;
            }

            var data = new Models.invoice()
            {
                no_invoice     = txt_no_invoice.EditValue.ToString(),
                tgl            = Convert.ToDateTime(dtp_tgl_invoice.EditValue),
                no_surat_jalan = cbo_no_surat_jalan.EditValue.ToString(),
                kd_customer    = txt_kd_customer.EditValue.ToString(),
                total_liter    = Convert.ToDouble(txt_total_ukuran.EditValue),
                total          = Convert.ToInt32(txt_total.EditValue),
                total_bayar    = Convert.ToInt32(txt_total_bayar.EditValue),
                diskon         = Convert.ToInt32(txt_diskon.EditValue)
            };

            for (int i = 0; i < gridView1.RowCount; i++)
            {
                var detail = new Models.detail_invoice()
                {
                    no_invoice = txt_no_invoice.EditValue.ToString(),
                    kd_barang  = gridView1.GetRowCellValue(i, "kd_barang").ToString(),
                    qty        = Convert.ToInt32(gridView1.GetRowCellValue(i, "qty")),
                    liter      = Convert.ToDouble(gridView1.GetRowCellValue(i, "liter")),
                    harga      = Convert.ToInt32(gridView1.GetRowCellValue(i, "harga")),
                    total      = Convert.ToInt32(gridView1.GetRowCellValue(i, "total"))
                };
                data.detail_invoices.Add(detail);
            }

            if (Controllers.Penjualan.CInvoice.insert(data))
            {
                Helpers.Generic.MsgInfo("Invoice berhasil disimpan");
                this.cetak();
            }

            this.init();
        }