public void DeleteSt_PurchaseOrderHeader(St_PurchaseOrderHeader ObjToDelete) { var ObjDelete = _context.St_PurchaseOrderHeaders.FirstOrDefault(m => m.CompanyID == ObjToDelete.CompanyID && m.CompanyTransactionKindNo == ObjToDelete.CompanyTransactionKindNo && m.TransactionKindNo == ObjToDelete.TransactionKindNo && m.VoucherNumber == ObjToDelete.VoucherNumber && m.CompanyYear == ObjToDelete.CompanyYear); if (ObjDelete != null) { _context.St_PurchaseOrderHeaders.Remove(ObjDelete); } }
public JsonResult DeleteSt_PurchaseOrder(St_PurchaseOrderVM ObjToDelete) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); var Company = _unitOfWork.Company.GetMyCompany(UserInfo.fCompanyId); var DeleteHeader = new St_PurchaseOrderHeader(); DeleteHeader.CompanyTransactionKindNo = ObjToDelete.CompanyTransactionKindNo; DeleteHeader.TransactionKindNo = ObjToDelete.TransactionKindNo; DeleteHeader.CompanyID = UserInfo.fCompanyId; DeleteHeader.CompanyYear = ObjToDelete.CompanyYear; DeleteHeader.VoucherNumber = ObjToDelete.VoucherNumber; _unitOfWork.St_PurchaseOrder.DeleteSt_PurchaseOrderHeader(DeleteHeader); _unitOfWork.NativeSql.DeleteSt_PurchaseOrderTransactionLocal(ObjToDelete.VoucherNumber, ObjToDelete.CompanyTransactionKindNo, UserInfo.fCompanyId, ObjToDelete.TransactionKindNo, ObjToDelete.CompanyYear); if (!ModelState.IsValid) { string Err = " "; var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError error in errors) { Err = Err + error.ErrorMessage + " * "; } Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + Err; Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.DeletedSuccessfully; return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public JsonResult UpdateSt_PurchaseOrder(St_PurchaseOrderVM ObjToUpdate) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); var Company = _unitOfWork.Company.GetMyCompany(UserInfo.fCompanyId); var UpdateHeader = new St_PurchaseOrderHeader(); UpdateHeader.InsDateTime = DateTime.Now; UpdateHeader.InsUserID = userId; UpdateHeader.CompanyTransactionKindNo = ObjToUpdate.CompanyTransactionKindNo; UpdateHeader.TransactionKindNo = ObjToUpdate.TransactionKindNo; UpdateHeader.CompanyID = UserInfo.fCompanyId; UpdateHeader.CompanyYear = ObjToUpdate.CompanyYear; UpdateHeader.TaxType = ObjToUpdate.TaxType; UpdateHeader.VoucherCase = ObjToUpdate.VoucherCase; UpdateHeader.VoucherDate = ObjToUpdate.VoucherDate; UpdateHeader.CurrencyID = ObjToUpdate.CurrencyID; UpdateHeader.ConversionFactor = ObjToUpdate.ConversionFactor; UpdateHeader.SupplierAccountNumber = ObjToUpdate.SupplierAccountNumber; UpdateHeader.TotalQuantity = ObjToUpdate.TotalQuantity; UpdateHeader.NetTotal = ObjToUpdate.NetTotal; UpdateHeader.Remark = ObjToUpdate.Remark; UpdateHeader.Hint = ObjToUpdate.Hint; UpdateHeader.LinkWithVoucher = 0; UpdateHeader.VoucherNumber = ObjToUpdate.VoucherNumber; UpdateHeader.VHI = ObjToUpdate.VHI; _unitOfWork.St_PurchaseOrder.DeleteSt_PurchaseOrderHeader(UpdateHeader); _unitOfWork.NativeSql.DeleteSt_PurchaseOrderTransactionLocal(ObjToUpdate.VoucherNumber, ObjToUpdate.CompanyTransactionKindNo, UserInfo.fCompanyId, ObjToUpdate.TransactionKindNo, ObjToUpdate.CompanyYear); _unitOfWork.Complete(); int iRow = 0; foreach (var UpdateItems in ObjToUpdate.St_PurchaseOrderTransaction) { if (!String.IsNullOrWhiteSpace(UpdateItems.ItemCode)) { try { iRow = iRow + 1; UpdateItems.CompanyID = UserInfo.fCompanyId; UpdateItems.CompanyYear = UpdateHeader.CompanyYear; UpdateItems.CompanyTransactionKindNo = UpdateHeader.CompanyTransactionKindNo; UpdateItems.TransactionKindNo = UpdateHeader.TransactionKindNo; UpdateItems.VoucherDate = UpdateHeader.VoucherDate; UpdateItems.VoucherNumber = UpdateHeader.VoucherNumber; UpdateItems.VHI = UpdateHeader.VHI; UpdateItems.IsDeleted = 0; UpdateItems.ItemCode = UpdateItems.ItemCode; UpdateItems.SimilarItemCode = UpdateItems.SimilarItemCode; UpdateItems.Quantity = UpdateItems.Quantity; UpdateItems.Price = UpdateItems.Price; UpdateItems.Total = UpdateItems.Price * UpdateItems.Quantity; UpdateItems.LinkVoucherNumber = ""; UpdateItems.LinkWithVoucher = 0; UpdateItems.UsingQuantity = 0; UpdateItems.RowNumber = iRow; UpdateItems.InsDateTime = DateTime.Now; UpdateItems.InsUserID = userId; _unitOfWork.St_PurchaseOrder.AddSt_PurchaseOrderTransaction(UpdateItems); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } } } if (!ModelState.IsValid) { string Err = " "; var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError error in errors) { Err = Err + error.ErrorMessage + " * "; } Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + Err; Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } UpdateHeader.RowCount = iRow; _unitOfWork.St_PurchaseOrder.AddSt_PurchaseOrderHeader(UpdateHeader); _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.UpdatedSuccessfully; Msg.Year = UpdateHeader.CompanyYear; Msg.FCompanyId = UpdateHeader.CompanyID; Msg.VoucherNumber = UpdateHeader.VoucherNumber; Msg.TransactionKindNo = UpdateHeader.TransactionKindNo.ToString(); Msg.CompanyTransactionKindNo = UpdateHeader.CompanyTransactionKindNo.ToString(); return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public JsonResult Save(St_PurchaseOrderVM ObjToSave) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); var Company = _unitOfWork.Company.GetMyCompany(UserInfo.fCompanyId); var SaveHeader = new St_PurchaseOrderHeader(); SaveHeader.InsDateTime = DateTime.Now; SaveHeader.InsUserID = userId; SaveHeader.CompanyTransactionKindNo = ObjToSave.CompanyTransactionKindNo; SaveHeader.TransactionKindNo = ObjToSave.TransactionKindNo; SaveHeader.CompanyID = UserInfo.fCompanyId; SaveHeader.CompanyYear = ObjToSave.CompanyYear; SaveHeader.TaxType = ObjToSave.TaxType; SaveHeader.VoucherCase = ObjToSave.VoucherCase; SaveHeader.VoucherDate = ObjToSave.VoucherDate; SaveHeader.CurrencyID = ObjToSave.CurrencyID; SaveHeader.ConversionFactor = ObjToSave.ConversionFactor; SaveHeader.SupplierAccountNumber = ObjToSave.SupplierAccountNumber; SaveHeader.TotalQuantity = ObjToSave.TotalQuantity; SaveHeader.NetTotal = ObjToSave.NetTotal; SaveHeader.Remark = ObjToSave.Remark; SaveHeader.Hint = ObjToSave.Hint; SaveHeader.LinkWithVoucher = 0; var ObjComapnyTransactionKind = _unitOfWork.St_CompanyTransactionKind.GetSt_CompanyTransactionKindByID(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo); if (ObjComapnyTransactionKind.AutoSerial) { SaveHeader.VoucherNumber = _unitOfWork.St_PurchaseOrder.GetMaxVoucher(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo, SaveHeader.TransactionKindNo, ObjToSave.CompanyYear).ToString(); SaveHeader.VHI = int.Parse(SaveHeader.VoucherNumber); } else { string SerialNumber = ""; int Serial = ObjComapnyTransactionKind.Serial; string Symbol = ObjComapnyTransactionKind.Symbol; int LengthLastSerial = _unitOfWork.St_CompanyTransactionKindSymbolSerial.GetMaxSerial(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo, "*").ToString().Length; Serial = Serial - LengthLastSerial; for (int i = 0; i <= Serial; i++) { if (i < Serial) { SerialNumber = SerialNumber + "0"; } else if (i == Serial) { SerialNumber = SerialNumber + _unitOfWork.St_CompanyTransactionKindSymbolSerial.GetMaxSerial(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo, "*").ToString(); } } SaveHeader.VoucherNumber = Symbol + SerialNumber; SaveHeader.VHI = _unitOfWork.St_CompanyTransactionKindSymbolSerial.GetMaxSerial(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo, "*"); _unitOfWork.St_CompanyTransactionKindSymbolSerial.Update(UserInfo.fCompanyId, SaveHeader.CompanyTransactionKindNo, "*"); } int iRow = 0; foreach (var SaveItems in ObjToSave.St_PurchaseOrderTransaction) { if (!String.IsNullOrWhiteSpace(SaveItems.ItemCode)) { try { iRow = iRow + 1; SaveItems.CompanyID = UserInfo.fCompanyId; SaveItems.CompanyYear = SaveHeader.CompanyYear; SaveItems.CompanyTransactionKindNo = SaveHeader.CompanyTransactionKindNo; SaveItems.TransactionKindNo = SaveHeader.TransactionKindNo; SaveItems.VoucherDate = SaveHeader.VoucherDate; SaveItems.VoucherNumber = SaveHeader.VoucherNumber; SaveItems.VHI = SaveHeader.VHI; SaveItems.IsDeleted = 0; SaveItems.ItemCode = SaveItems.ItemCode; SaveItems.SimilarItemCode = SaveItems.SimilarItemCode; SaveItems.Quantity = SaveItems.Quantity; SaveItems.Price = SaveItems.Price; SaveItems.Total = SaveItems.Quantity * SaveItems.Price; SaveItems.LinkVoucherNumber = ""; SaveItems.LinkWithVoucher = 0; SaveItems.UsingQuantity = 0; SaveItems.RowNumber = iRow; SaveItems.InsDateTime = DateTime.Now; SaveItems.InsUserID = userId; _unitOfWork.St_PurchaseOrder.AddSt_PurchaseOrderTransaction(SaveItems); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } } } if (!ModelState.IsValid) { string Err = " "; var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError error in errors) { Err = Err + error.ErrorMessage + " * "; } Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + Err; Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } SaveHeader.RowCount = iRow; _unitOfWork.St_PurchaseOrder.AddSt_PurchaseOrderHeader(SaveHeader); _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.AddedSuccessfully; Msg.Year = SaveHeader.CompanyYear; Msg.FCompanyId = SaveHeader.CompanyID; Msg.VoucherNumber = SaveHeader.VoucherNumber; Msg.TransactionKindNo = SaveHeader.TransactionKindNo.ToString(); Msg.CompanyTransactionKindNo = SaveHeader.CompanyTransactionKindNo.ToString(); return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public void AddSt_PurchaseOrderHeader(St_PurchaseOrderHeader ObjToSave) { _context.St_PurchaseOrderHeaders.Add(ObjToSave); }