private void SavePRMMaterialReceiveEntity() { if (IsValid) { try { PRMMaterialReceiveEntity pRMMaterialReceiveEntity = BuildPRMMaterialReceiveEntity(); #region Requisition String RequisitionNo = String.Empty; if (txtRequisition.Text.IsNotNullOrEmpty()) { RequisitionNo = "BL-" + txtRequisition.Text.ToString(); } Int64 resultRequisition = -1; Int64 resultRequisitionItem = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(REQRequisitionEntity.FLD_NAME_RequisitionNo, RequisitionNo, SQLMatchType.Equal); IList <REQRequisitionEntity> lstRequisition = FCCREQRequisition.GetFacadeCreate().GetIL(null, null, String.Empty, fe, DatabaseOperationType.LoadWithFilterExpression); REQRequisitionItemEntity rEQRequisitionItemEntity = null; if (lstRequisition != null && lstRequisition.Count > 0) { rEQRequisitionItemEntity = BuildREQRequisitionItemEntity(lstRequisition[0].RequisitionID); pRMMaterialReceiveEntity.RequisitionID = lstRequisition[0].RequisitionID; } else { REQRequisitionEntity rEQRequisitionEntity = BuildREQRequisitionEntity(); resultRequisition = FCCREQRequisition.GetFacadeCreate().Add(rEQRequisitionEntity, DatabaseOperationType.Add, TransactionRequired.No); pRMMaterialReceiveEntity.RequisitionID = resultRequisition; if (resultRequisition > 0) { rEQRequisitionItemEntity = BuildREQRequisitionItemEntity(resultRequisition); } } if (rEQRequisitionItemEntity != null) { resultRequisitionItem = FCCREQRequisitionItem.GetFacadeCreate().Add(rEQRequisitionItemEntity, DatabaseOperationType.Add, TransactionRequired.No); } #endregion #region MRR Int64 resultOne = -1; if (pRMMaterialReceiveEntity.IsNew) { resultOne = FCCPRMMaterialReceive.GetFacadeCreate().Add(pRMMaterialReceiveEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(PRMMaterialReceiveEntity.FLD_NAME_MaterialReceiveID, pRMMaterialReceiveEntity.MaterialReceiveID.ToString(), SQLMatchType.Equal); resultOne = FCCPRMMaterialReceive.GetFacadeCreate().Update(pRMMaterialReceiveEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } #endregion if (resultOne > 0 && resultRequisitionItem > 0) { #region Material Receive Item Map Int64 resultTwo = -1; PRMMaterialReceiveItemMapEntity pRMMaterialReceiveItemMapEntity = BuildPRMMaterialReceiveItemMapEntity(resultOne, resultRequisitionItem); resultTwo = FCCPRMMaterialReceiveItemMap.GetFacadeCreate().Add(pRMMaterialReceiveItemMapEntity, DatabaseOperationType.Add, TransactionRequired.No); #endregion try { #region Inventory Int64 _employeeID = MiscUtil.GetCurrentEmployeeByMemberID(CurrentMember); Int64 _projectID = Int64.Parse(ddlProjectID.SelectedValue); INVStoreEntity storeEntity = INVManager.GetDefaultStore(_projectID); Int64 storeID = storeEntity.StoreID; INVStoreUnitEntity storeUnitEntity = INVManager.GetDefaultStoreUnit(storeID); Int64 storeUnitID = storeUnitEntity.StoreUnitID; String fe_requisitionItem = SqlExpressionBuilder.PrepareFilterExpression("REQRequisitionItem." + REQRequisitionItemEntity.FLD_NAME_RequisitionItemID, resultRequisitionItem.ToString(), SQLMatchType.Equal); IList <REQRequisitionItem_DetailedEntity> lst = FCCREQRequisitionItem_Detailed.GetFacadeCreate().GetIL(10000, 1, String.Empty, fe_requisitionItem); Int64 _itemID = 0; Decimal _rate = 0; Int64 brandID = MasterDataConstants.ItemDefaults.DEFAULT_BRAD; Int64 regionID = MasterDataConstants.ItemDefaults.DEFAULT_REGION; Int64 countryID = MasterDataConstants.ItemDefaults.DEFAULT_COUNTRY; if (lst != null && lst.Count > 0) { _itemID = lst[0].ItemID; brandID = (Int64)lst[0].BrandID; regionID = (Int64)lst[0].RegionID; countryID = (Int64)lst[0].CountryID; _rate = lst[0].Rate; } Boolean invResult = INVManager.AddItemsToStoreUnit(_itemID, brandID, regionID, countryID, "", Int64.Parse(txtReceiveQty.Text.ToString()), MiscUtil.GetLocalIP(), _employeeID, _rate, txtRequisition.Text, ddlWorkOrderID.SelectedItem.Text, resultOne.ToString(), "", Int64.Parse(ddlProjectID.SelectedValue), storeID, storeUnitID); #endregion } catch (Exception ex) { } _MaterialReceiveID = resultOne; PrepareInitialViewSave(); btnAddNew.Visible = true; if (pRMMaterialReceiveEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Material Receive Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Material Receive Information has been updated successfully.", false); } } else { if (pRMMaterialReceiveEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Material Receive Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Material Receive Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private void BuildINVStoreIssueNoteItemMapEntity(Int64 sinID, Int64 projectID) { try { String fe_itemMap = SqlExpressionBuilder.PrepareFilterExpression(PRMMaterialReceiveItemMapEntity.FLD_NAME_MaterialReceiveID, ddlMaterialReceiveID.SelectedValue.ToString(), SQLMatchType.Equal); IList <PRMMaterialReceiveItemMapEntity> lst = FCCPRMMaterialReceiveItemMap.GetFacadeCreate().GetIL(null, null, String.Empty, fe_itemMap, DatabaseOperationType.LoadWithFilterExpression); if (lst != null && lst.Count > 0) { foreach (PRMMaterialReceiveItemMapEntity ent in lst) { INVStoreIssueNoteItemMapEntity iNVStoreIssueNoteItemMapEntity = new INVStoreIssueNoteItemMapEntity(); REQRequisitionItemEntity rEQRequisitionItemEntity = FCCREQRequisitionItem.GetFacadeCreate().GetByID(ent.RequisitionItemID); if (rEQRequisitionItemEntity != null && rEQRequisitionItemEntity.ItemID > 0) { iNVStoreIssueNoteItemMapEntity.StoreIssueNoteID = sinID; iNVStoreIssueNoteItemMapEntity.ItemID = rEQRequisitionItemEntity.ItemID; iNVStoreIssueNoteItemMapEntity.FolioNo = String.Empty; iNVStoreIssueNoteItemMapEntity.RequestQty = ent.ReceiveQty; iNVStoreIssueNoteItemMapEntity.IssueQty = ent.ReceiveQty; } String fe_transaction1 = SqlExpressionBuilder.PrepareFilterExpression(INVTransactionEntity.FLD_NAME_ItemID, rEQRequisitionItemEntity.ItemID.ToString(), SQLMatchType.Equal); String fe_transaction2 = SqlExpressionBuilder.PrepareFilterExpression(INVTransactionEntity.FLD_NAME_MRRNumber, ddlMaterialReceiveID.Text.ToString(), SQLMatchType.Equal); String fe_transaction = SqlExpressionBuilder.PrepareFilterExpression(fe_transaction1, SQLJoinType.AND, fe_transaction2); IList <INVTransactionEntity> lstINVTransactionEntity = FCCINVTransaction.GetFacadeCreate().GetIL(null, null, String.Empty, fe_transaction, DatabaseOperationType.LoadWithFilterExpression); if (lstINVTransactionEntity != null && lstINVTransactionEntity.Count > 0) { iNVStoreIssueNoteItemMapEntity.BatchNo = lstINVTransactionEntity[0].BatchNumber; } // iNVStoreIssueNoteItemMapEntity.BatchNo = txtBatchNo.Text.Trim(); String fe_store1 = SqlExpressionBuilder.PrepareFilterExpression(INVStoreEntity.FLD_NAME_ProjectID, projectID.ToString(), SQLMatchType.Equal); String fe_store2 = SqlExpressionBuilder.PrepareFilterExpression(INVStoreEntity.FLD_NAME_IsDefault, "1", SQLMatchType.Equal); String fe_store = SqlExpressionBuilder.PrepareFilterExpression(fe_store1, SQLJoinType.AND, fe_store2); IList <INVStoreEntity> lstINVStoreEntity = FCCINVStore.GetFacadeCreate().GetIL(null, null, String.Empty, fe_store, DatabaseOperationType.LoadWithFilterExpression); if (lstINVStoreEntity != null && lstINVStoreEntity.Count > 0) { iNVStoreIssueNoteItemMapEntity.IssuedFromStoreID = lstINVStoreEntity[0].StoreID; String fe_storeUnit1 = SqlExpressionBuilder.PrepareFilterExpression(INVStoreUnitEntity.FLD_NAME_StoreID, lstINVStoreEntity[0].StoreID.ToString(), SQLMatchType.Equal); String fe_storeUnit2 = SqlExpressionBuilder.PrepareFilterExpression(INVStoreUnitEntity.FLD_NAME_IsDefault, "1", SQLMatchType.Equal); String fe_storeUnit = SqlExpressionBuilder.PrepareFilterExpression(fe_storeUnit1, SQLJoinType.AND, fe_storeUnit2); IList <INVStoreUnitEntity> lstINVStoreUnitEntity = FCCINVStoreUnit.GetFacadeCreate().GetIL(null, null, String.Empty, fe_storeUnit, DatabaseOperationType.LoadWithFilterExpression); if (lstINVStoreUnitEntity != null && lstINVStoreUnitEntity.Count > 0) { iNVStoreIssueNoteItemMapEntity.IssuedFromStoreUnitID = lstINVStoreUnitEntity[0].StoreUnitID; } } iNVStoreIssueNoteItemMapEntity.ReceivedDate = System.DateTime.Now; iNVStoreIssueNoteItemMapEntity.ReceivedByEmployeeID = 168; iNVStoreIssueNoteItemMapEntity.ReturnQty = null; iNVStoreIssueNoteItemMapEntity.ReturnDate = null; iNVStoreIssueNoteItemMapEntity.ReturnToStoreID = null; iNVStoreIssueNoteItemMapEntity.ReturnToStoreUnitID = null; iNVStoreIssueNoteItemMapEntity.ReturnedByEmployeeID = null; iNVStoreIssueNoteItemMapEntity.ActualUse = null; iNVStoreIssueNoteItemMapEntity.Amount = ent.WOItemTotalRate / ent.ReceiveQty; iNVStoreIssueNoteItemMapEntity.PurposeOfWorks = "Adjustment Entry"; INVStoreEntity storeEntity = INVManager.GetDefaultStore(projectID); INVStoreUnitEntity storeUnitEntity = INVManager.GetDefaultStoreUnit(storeEntity.StoreID); iNVStoreIssueNoteItemMapEntity.IssuedFromStoreID = storeEntity.StoreID; iNVStoreIssueNoteItemMapEntity.IssuedFromStoreID = storeUnitEntity.StoreUnitID; FCCINVStoreIssueNoteItemMap.GetFacadeCreate().Add(iNVStoreIssueNoteItemMapEntity, DatabaseOperationType.Add, TransactionRequired.No); #region Inventory String batchNumber = String.Empty; Decimal transactionQty = 0; Boolean invResult = false; invResult = INVManager.RemoveItemsFromStoreUnit(rEQRequisitionItemEntity.ItemID, rEQRequisitionItemEntity.BrandID, rEQRequisitionItemEntity.RegionID, rEQRequisitionItemEntity.CountryID, lstINVTransactionEntity[0].BatchNumber, Int64.Parse(transactionQty.ToString()), MiscUtil.GetLocalIP(), MiscUtil.GetCurrentEmployeeByMemberID(CurrentMember), 0, String.Empty, String.Empty, String.Empty, "", projectID, storeEntity.StoreID, storeUnitEntity.StoreUnitID); #endregion } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, "Some Error Occured " + ex.Message, true); } }