public ActionResult Create([Bind(Include = "BillReceiptID,Type,BillReceiptNo,CompanyName,IsPrint,DateCreate,DateUpdate,CreateBy,UpdateBy")] Billing billing)
 {
     if (ModelState.IsValid)
     {
         BillReceipt billreceipt = new BillReceipt();
         billreceipt.Type        = billing.Type;
         billreceipt.CompanyName = billing.CompanyName;
         billreceipt.IsPrint     = billing.IsPrint;
         billreceipt.DateCreate  = billing.DateCreate;
         billreceipt.DateUpdate  = billing.DateUpdate;
         if (billing.Type == "Repair")
         {
             billreceipt.BillReceiptNo = "R" + billing.BillReceiptNo;
         }
         else if (billing.Type == "Sale")
         {
             billreceipt.BillReceiptNo = "S" + billing.BillReceiptNo;
         }
         else if (billing.Type == "Destroy")
         {
             billreceipt.BillReceiptNo = "D" + billing.BillReceiptNo;
         }
         //billreceipt.BillReceiptNo = billing.BillReceiptNo;
         billreceipt.CreateBy = billing.CreateBy;
         billreceipt.UpdateBy = billing.UpdateBy;
         db.BillReceipts.Add(billreceipt);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(billing));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            BillReceipt billreceipt = db.BillReceipts.Find(id);

            db.BillReceipts.Remove(billreceipt);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "BillReceiptID,Type,BillReceiptNo,CompanyName,IsPrint,DateCreate,DateUpdate,CreateBy,UpdateBy")] BillReceipt billreceipt)
 {
     if (ModelState.IsValid)
     {
         db.Entry(billreceipt).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(billreceipt));
 }
Пример #4
0
        private void ViewBillReceiptDetail(BillReceipt billReceipt)
        {
            txtID.Text            = billReceipt.ID.ToString();
            txtBillReceiptId.Text = billReceipt.ID.ToString();
            lblCode.Text          = billReceipt.Code;
            dtpDate.Text          = billReceipt.BillReceiptDate.ToShortDateString();

            txtSalesmanId.Text   = billReceipt.SalesmanId.ToString();
            txtSalesmanName.Text = billReceipt.Salesman.Name;

            txtNotes.Text = billReceipt.Notes;
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillReceipt billreceipt = db.BillReceipts.Find(id);

            if (billreceipt == null)
            {
                return(HttpNotFound());
            }
            return(View(billreceipt));
        }
Пример #6
0
        private void PopulateBillReceipt(BillReceipt billReceipt)
        {
            var item = new ListViewItem(billReceipt.ID.ToString());

            item.SubItems.Add(billReceipt.BillReceiptDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(billReceipt.Code);
            item.SubItems.Add(billReceipt.Salesman.Name);
            item.SubItems.Add(billReceipt.GrandTotal.ToString("N0").Replace(",", "."));
            item.SubItems.Add(billReceipt.CreatedDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(billReceipt.CreatedBy);
            item.SubItems.Add(billReceipt.ModifiedDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(billReceipt.ModifiedBy);

            lvwBillReceipt.Items.Add(item);
        }
Пример #7
0
        public void UpdatePrintCounter(string billReceiptCode)
        {
            int printCounter = 0;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                BillReceipt billReceipt = GetByCode(billReceiptCode);
                if (billReceipt != null)
                {
                    printCounter = billReceipt.PrintCounter + 1;
                    string sql = "UPDATE " + tableName + " SET PrintCounter = " + printCounter + " WHERE BillReceiptCode='" + billReceiptCode + "'";
                    em.ExecuteNonQuery(sql);
                }
            }
        }
Пример #8
0
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "TTNT" && u.IsDelete);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat menghapus", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    BillReceipt billReceipt = billReceiptRepository.GetById(new Guid(txtID.Text));
                    if (billReceipt.Notes.Contains("DIBATALKAN"))
                    {
                        MessageBox.Show("Sudah pernah di hapus ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (MessageBox.Show("Anda yakin ingin menghapus '" + lblCode.Text + "'", "Perhatian",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            var billReceipt1 = new BillReceipt();
                            billReceipt1.ID    = new Guid(txtID.Text);
                            billReceipt1.Notes = txtNotes.Text;

                            billReceiptRepository.Delete(billReceipt1);
                            GetLastBillReceipt();
                        }

                        if (lvwBillReceipt.Items.Count == 0)
                        {
                            tsbEdit.Enabled   = false;
                            tsbDelete.Enabled = false;
                        }
                    }
                }
            }
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BillReceipt billreceipt = db.BillReceipts.Find(id);

            billreceipt.DateUpdate = DateTime.Now;
            billreceipt.UpdateBy   = System.Web.HttpContext.Current.User.Identity.Name;
            if (billreceipt == null)
            {
                return(HttpNotFound());
            }
            return(View(billreceipt));
        }
        public ActionResult ExportListSale(string id)
        {
            var receipts  = from receipt in db.BillReceiptLists where receipt.BillReceiptNo == id group receipt by receipt.Type into dv let m = dv.FirstOrDefault() select m;
            var totalitem = db.BillReceiptLists.Where(b => b.BillReceiptNo == id);

            var billID = db.BillReceipts.Where(b => b.BillReceiptNo == id).Select(b => b.BillReceiptID).DefaultIfEmpty().First();

            BillReceipt billreceipt = db.BillReceipts.Find(billID);

            billreceipt.IsPrint         = 1;
            db.Entry(billreceipt).State = EntityState.Modified;
            db.SaveChanges();
            ViewBag.ReceiptNo = id;
            ViewBag.TotalItem = totalitem.Count();
            return(new Rotativa.ActionAsPdf("ExportListSalePdf", new { id }));
        }
Пример #11
0
        public void Delete(BillReceipt billReceipt)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    String notes = "";
                    if (billReceipt.Notes != "")
                    {
                        notes = "DIBATALKAN - " + billReceipt.Notes;
                    }
                    else
                    {
                        notes = "DIBATALKAN";
                    }

                    string[] columns = { "GrandTotal", "Notes", "ModifiedDate", "ModifiedBy" };

                    object[] values = { 0, notes, DateTime.Now.ToShortDateString(), Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Update(values)
                            .Where("ID").Equal("{" + billReceipt.ID + "}");

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    var itemList = billReceiptItemRepository.GetByBillReceiptId(billReceipt.ID);

                    foreach (var billReceiptItem in itemList)
                    {
                        billReceiptItemRepository.Delete(em, tx, billReceiptItem);
                    }

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
Пример #12
0
        public void Update(BillReceipt billReceipt)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    string[] columns = { "BillReceiptCode", "BillReceiptDate", "SalesmanId", "Notes", "GrandTotal",
                                         "ModifiedDate",    "ModifiedBy" };

                    object[] values = { billReceipt.Code,                 billReceipt.BillReceiptDate, billReceipt.SalesmanId,
                                        billReceipt.Notes,                billReceipt.GrandTotal,
                                        DateTime.Now.ToShortDateString(), Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Update(values)
                            .Where("ID").Equal("{" + billReceipt.ID + "}");

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    billReceiptItemRepository.Delete(em, tx, billReceipt.ID);

                    foreach (var billReceiptItem in billReceipt.BillReceiptItems)
                    {
                        billReceiptItem.BillReceiptId = billReceipt.ID;
                        billReceiptItemRepository.Save(em, tx, billReceiptItem);
                    }

                    UpdateGrandTotal(em, tx, billReceipt.ID, billReceipt.GrandTotal);

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();

                throw ex;
            }
        }
Пример #13
0
        public void Save(BillReceipt billReceipt)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    Guid ID = Guid.NewGuid();

                    string[] columns = { "ID",          "BillReceiptCode", "BillReceiptDate", "SalesmanId", "Notes", "GrandTotal", "PrintCounter",
                                         "CreatedDate", "ModifiedDate",    "CreatedBy",       "ModifiedBy" };

                    object[] values = { ID,                               billReceipt.Code,  billReceipt.BillReceiptDate.ToShortDateString(),
                                        billReceipt.SalesmanId,           billReceipt.Notes, billReceipt.GrandTotal, 0,
                                        DateTime.Now.ToShortDateString(),
                                        DateTime.Now.ToShortDateString(), Store.ActiveUser,  Store.ActiveUser };

                    var q = new Query().Select(columns).From(tableName).Insert(values);

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    foreach (var billReceiptItem in billReceipt.BillReceiptItems)
                    {
                        billReceiptItem.BillReceiptId = ID;
                        billReceiptItemRepository.Save(em, tx, billReceiptItem);
                    }

                    recordCounterRepository.UpdateBillReceiptCounter(billReceipt.BillReceiptDate.Month, billReceipt.BillReceiptDate.Year);

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
Пример #14
0
        public BillReceipt GetLast(int month, int year)
        {
            BillReceipt billReceipt = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT TOP 1 b.ID, b.BillReceiptCode, b.BillReceiptDate, "
                             + "b.GrandTotal, b.Notes, b.PrintCounter, "
                             + "b.CreatedDate, b.ModifiedDate, b.CreatedBy, b.ModifiedBy, "
                             + "b.SalesmanId, s.SalesmanName "
                             + "FROM "
                             + "BillReceipt b INNER JOIN Salesman s ON b.SalesmanId = s.ID "
                             + "WHERE "
                             + "Month(BillReceiptDate)=" + month + " AND Year(BillReceiptDate)=" + year
                             + " ORDER BY b.BillReceiptCode DESC";

                billReceipt = em.ExecuteObject <BillReceipt>(sql, new BillReceiptMapper());
            }

            return(billReceipt);
        }
Пример #15
0
        public BillReceipt GetByCode(string code)
        {
            BillReceipt billReceipt = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT b.ID, b.BillReceiptCode, b.BillReceiptDate, "
                             + "b.GrandTotal, b.Notes, b.PrintCounter, "
                             + "b.CreatedDate, b.ModifiedDate, b.CreatedBy, b.ModifiedBy, "
                             + "b.SalesmanId, s.SalesmanName "
                             + "FROM "
                             + "BillReceipt b INNER JOIN Salesman s ON b.SalesmanId = s.ID "
                             + "WHERE "
                             + "b.BillReceiptCode='" + code + "'";


                billReceipt = em.ExecuteObject <BillReceipt>(sql, new BillReceiptMapper());
            }

            return(billReceipt);
        }
Пример #16
0
        private void tsbEdit_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "TTNT" && u.IsEdit);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat merubah", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    BillReceipt billReceipt = billReceiptRepository.GetById(new Guid(txtID.Text));
                    if (billReceipt.Notes.Contains("DIBATALKAN"))
                    {
                        MessageBox.Show("Sudah pernah di hapus ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        formMode  = FormMode.Edit;
                        this.Text = "TTNT - Edit";

                        EnableFormForEdit();
                    }
                }
            }
        }
Пример #17
0
        public BillReceipt GetById(Guid id)
        {
            BillReceipt billReceipt = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                string sql = "SELECT b.ID, b.BillReceiptCode, b.BillReceiptDate, "
                             + "b.GrandTotal, b.Notes, b.PrintCounter, "
                             + "b.SalesmanId, s.SalesmanName, "
                             + "b.CreatedDate, b.ModifiedDate, b.CreatedBy, b.ModifiedBy "
                             + "FROM "
                             + "BillReceipt b INNER JOIN Salesman s ON b.SalesmanId = s.ID "
                             + "WHERE b.ID='{" + id + "}'";

                billReceipt = em.ExecuteObject <BillReceipt>(sql, new BillReceiptMapper());

                if (billReceipt != null)
                {
                    billReceipt.BillReceiptItems = billReceiptItemRepository.GetByBillReceiptId(billReceipt.ID);
                }
            }

            return(billReceipt);
        }
Пример #18
0
        private void SaveBillReceipt()
        {
            if (dtpDate.Value.Month != Store.ActiveMonth || dtpDate.Value.Year != Store.ActiveYear)
            {
                MessageBox.Show("Tanggal diluar periode aktif", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else if (txtSalesmanName.Text == "")
            {
                MessageBox.Show("Salesman tidak boleh kosong", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnBrowseSalesman.Focus();
            }
            else if (lvwBillReceipt.Items.Count == 0)
            {
                MessageBox.Show("Detail tidak boleh kosong", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                var billReceipt = new BillReceipt();

                billReceipt.Code            = lblCode.Text;
                billReceipt.BillReceiptDate = dtpDate.Value;
                billReceipt.Notes           = txtNotes.Text;
                billReceipt.SalesmanId      = new Guid(txtSalesmanId.Text);
                billReceipt.GrandTotal      = decimal.Parse(lblTotal.Text.Replace(".", ""));


                var billReceiptItems = new List <BillReceiptItem>();

                foreach (ListViewItem item in lvwBillReceipt.Items)
                {
                    string salesId = item.SubItems[0].Text;
                    string total   = item.SubItems[5].Text;

                    BillReceiptItem si = new BillReceiptItem();

                    if (si.Sales == null)
                    {
                        si.Sales = new Sales();
                    }
                    si.Sales.Code = item.SubItems[2].Text;

                    si.SalesId = new Guid(salesId);
                    si.Notes   = "";
                    si.Total   = decimal.Parse(total.Replace(".", ""));

                    billReceiptItems.Add(si);
                }


                billReceipt.BillReceiptItems = billReceiptItems;


                if (formMode == FormMode.Add)
                {
                    billReceiptRepository.Save(billReceipt);
                    ShowBillReceiptReport();
                    GetLastBillReceipt();
                }
                else if (formMode == FormMode.Edit)
                {
                    billReceipt.ID         = new Guid(txtID.Text);
                    billReceipt.GrandTotal = decimal.Parse(lblTotal.Text.Replace(".", ""));
                    billReceiptRepository.Update(billReceipt);
                    ShowBillReceiptReport();
                }

                LoadBillReceiptItems(new Guid(txtID.Text));
                DisableForm();
                formMode = FormMode.View;

                FillCode();
                this.Text = "TTNT";
            }
        }
        public ActionResult PrintListSale(string id, int?lid)
        {
            if (ModelState.IsValid)
            {
                LocalReport lr   = new LocalReport();
                string      path = Path.Combine(Server.MapPath("~/Reports"), "SentSaleListReport.rdlc");
                if (System.IO.File.Exists(path))
                {
                    lr.ReportPath = path;
                }
                else
                {
                    return(View("Index"));
                }

                List <BillReceiptList> cm = new List <BillReceiptList>();
                cm = db.BillReceiptLists.Where(d => d.BillReceiptNo == id).ToList();
                var groupedCustomerList = cm
                                          .GroupBy(u => u.Type)
                                          .Select(grp => new { Type = grp.Key, cm = grp.ToList() })
                                          .ToList();

                BillReceipt billreceipt = db.BillReceipts.Find(lid);
                billreceipt.IsPrint         = 1;
                db.Entry(billreceipt).State = EntityState.Modified;
                db.SaveChanges();

                ReportDataSource rd = new ReportDataSource("DataSet1", groupedCustomerList);
                lr.DataSources.Add(rd);
                string reportType = "pdf";
                string mimeType;
                string encoding;
                string fileNameExtension;



                string deviceInfo =

                    "<DeviceInfo>" +
                    "  <OutputFormat>" + "Pdf" + "</OutputFormat>" +
                    "  <PageWidth>11.7in</PageWidth>" +
                    "  <PageHeight>16.5in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>1in</MarginLeft>" +
                    "  <MarginRight>1in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;

                renderedBytes = lr.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);


                return(File(renderedBytes, mimeType));
            }
            return(View(id));
        }