public void SaveHoaDonNhap(HoaDonNhapModel value) { var sanPhamCtrl = app.Resolve <ISanPhamController <SanPhamModel> >(); var hdEntity = value.ToEntity(); hdEntity.NhanVienID = nhanVienService.GetByMa(hdEntity.MaNV).ID; hdEntity.NhaCungCapID = nhaCungCapService.GetByMa(hdEntity.MaNCC).ID; hoaDonNhapService.Insert(hdEntity); foreach (var hds in value.ChiTietHDNModel) { if (hds.SanPham != null) { var sp = hds.SanPham; sp.DonGiaBan = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1)); sp.DonGiaNhap = hds.DonGia; sp.SoLuong = hds.SoLuong; sanPhamService.Insert(sp); hds.SanPhamID = sp.ID; } else { var sp = sanPhamService.GetByMa(hds.MaGiayDep); sp.DonGiaBan = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1)); sp.DonGiaNhap = hds.DonGia; sp.SoLuong = sp.SoLuong + hds.SoLuong; hds.SanPhamID = sp.ID; sanPhamService.Update(sp); } hds.SoHDN = hdEntity.SoHDN; hds.HoaDonNhapID = hdEntity.ID; chiTietHdnService.Insert(hds.ToEntity()); } // update UI on SanPham View hoaDonNhapView.HideForm(); sanPhamCtrl.ReviewGrid(); PostView(); }
public void SaveHoaDonBan(HoaDonBanModel value) { var sanPhamCtrl = app.Resolve <ISanPhamController <SanPhamModel> >(); var hdEntity = value.ToEntity(); hdEntity.NhanVienID = nhanVienService.GetByMa(hdEntity.MaNV).ID; hdEntity.KhachHangID = khachHangService.GetByMa(hdEntity.MaKhach).ID; hoaDonNhapService.Insert(hdEntity); foreach (var hds in value.ChiTietHDBModel) { //if(hds.SanPham != null) { // var sp = hds.SanPham; // sp.DonGiaBan = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1)); // sp.DonGiaNhap = hds.DonGia; // sp.SoLuong = hds.SoLuong; // sanPhamService.Insert(sp); // hds.SanPhamID = sp.ID; //} else //{ var sp = sanPhamService.GetByMa(hds.MaGiayDep); //sp.DonGiaBan = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1)); sp.DonGiaNhap = hds.DonGia; sp.SoLuong = sp.SoLuong - hds.SoLuong; hds.SanPhamID = sp.ID; sanPhamService.Update(sp); //} hds.SoHDB = hdEntity.SoHDB; hds.HoaDonBanID = hdEntity.ID; chiTietHdbService.Insert(hds.ToEntity()); } // update UI on SanPham View hoaDonNhapView.HideForm(); sanPhamCtrl.ReviewGrid(); PostView(); }