public byte[] PrepareDatHang(PhieuNhapHang_NCCViewModel datHangs) { #region _datHang = datHangs; //_totalColumn = 6; _document = new Document(PageSize.A4, 0f, 0f, 0f, 0f); _document.SetPageSize(PageSize.A4); _document.SetMargins(20f, 20f, 20f, 20f); BaseFont bf = BaseFont.CreateFont("C:/windows/fonts/Arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); _fontStyle = new Font(bf, 12); PdfWriter.GetInstance(_document, _memoryStream); _document.Open(); //render Dathang RenderDatHang(); //render chi tiet dat hang RenderChiTietDatHang(); //add description var description = ""; var para = new Paragraph(description, _fontStyle); _document.Add(para); // Add signature RenderSignature(); _document.Close(); return(_memoryStream.ToArray()); }
public ActionResult Create(int id, PhieuNhapHang_NCCViewModel model) { var result = new ReponseMessage(); try { if (model == null || model.ChiTietPhieuNhaps?.Count == 0 || model.TongTien == 0) { result.Message = "Dữ liệu truyền vào không chính xác"; result.StatusCode = HttpStatusCode.BadRequest; return(Json(result)); } // TODO: Add add logic here // PNHService.UpdateTrangThaiDonHang(id); var kq = PNHService.AddPhieuNhapHangNCC(id, model); if (kq == false) { result.Message = "Có lỗi trong qúa trình xử lý"; result.StatusCode = HttpStatusCode.BadRequest; } result.StatusCode = HttpStatusCode.OK; return(Json(result)); } catch (Exception ex) { result.Message = "Có lỗi trong quá trình"; result.StatusCode = HttpStatusCode.ExpectationFailed; return(Json(result)); } }
// Lập phiếu nhập hàng từ phiếu đặt public bool AddPhieuNhapHangNCC(int id, PhieuNhapHang_NCCViewModel model) { var tongTien = model.ChiTietPhieuNhaps.Sum(t => t.SL * t.GiaNhap); var phieuDat = new PHIEUNHAP_NCC() { MAPHIEUDAT = id, NGAYNHAP = DateTime.Now, NGUOINHAP = HttpContext.Current.User.Identity.Name, TONGTIEN = tongTien.Value, TRANGTHAI = 2, }; context.PHIEUNHAP_NCCs.Add(phieuDat); context.SaveChanges(); foreach (var detail in model.ChiTietPhieuNhaps) { var chiTiet = new CTPHIEUNHAP_NCC() { MAPHIEUNHAP = phieuDat.MAPHIEUNHAP, MASANPHAM = detail.MaSP, SOLUONGNHAP = detail.SL, GIANHAP = detail.GiaNhap, THANHTIEN = detail.SL * detail.GiaNhap, }; var sp = context.SANPHAMs.Where(t => t.Id_SanPham == detail.MaSP).FirstOrDefault(); var slTon = sp.SoLuongTon ?? 0; // nếu là null thì gán mặc định = 0; sp.SoLuongTon = detail.SL + slTon; context.CTPHIEUNHAP_NCCs.Add(chiTiet); } UpdateTrangThaiDonHang(id); // CapNhatSLTon(nhapHang); context.SaveChanges(); return(true); }