public NAS.DAL.Invoice.PurchaseInvoice GetAllocatedPurchaseInvoiceByInventoryCommand(Session session, Guid inventoryCommandId) { NAS.DAL.Invoice.PurchaseInvoice ret = null; try { InventoryCommand command = session.GetObjectByKey <InventoryCommand>(inventoryCommandId); InventoryCommandObject commandObject = command.InventoryCommandObjects.First(); if (commandObject == null) { return(null); } ObjectTypeCustomField objectTypeCustomField = ObjectTypeCustomField.GetDefault(session, DefaultObjectTypeCustomFieldEnum.INVENTORY_IN_PURCHASE_INVOICE); ObjectCustomField objectCustomField = commandObject.ObjectId.ObjectCustomFields.Where( r => r.ObjectTypeCustomFieldId.ObjectTypeCustomFieldId == objectTypeCustomField.ObjectTypeCustomFieldId).FirstOrDefault(); if (objectCustomField == null) { return(null); } ObjectCustomFieldData objectCustomFieldData = objectCustomField.ObjectCustomFieldDatas.FirstOrDefault(); if (objectCustomFieldData == null) { return(null); } PredefinitionData predefinitionData = (PredefinitionData)objectCustomFieldData.CustomFieldDataId; ret = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(predefinitionData.RefId); return(ret); } catch (Exception) { throw; } }
/// <summary> /// Tạo dữ liệu cho CMS Object Inventory /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uow"></param> /// <param name="InventoryObjectId"></param> /// <param name="CMSObjectType"></param> public void PopulateCMSObjecForInventoryObject <T>( UnitOfWork uow, Guid InventoryObjectId, DAL.CMS.ObjectDocument.ObjectTypeEnum CMSObjectType) { ObjectBO bo = new ObjectBO(); if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommand))) { NAS.DAL.Inventory.Command.InventoryCommand inventoryObject = uow.GetObjectByKey <NAS.DAL.Inventory.Command.InventoryCommand>(InventoryObjectId); NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType); InventoryCommandObject ICO = new InventoryCommandObject(uow); ICO.ObjectId = o; ICO.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand); ICO.Save(); NAS.DAL.CMS.ObjectDocument.ObjectType type = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType); if (type == null) { throw new Exception("The ObjectType is not exist in system"); } InventoryCommandCustomType ICCT = new InventoryCommandCustomType(uow); ICCT.ObjectTypeId = type; ICCT.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand); ICCT.Save(); } else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction))) { InventoryCommandItemTransaction transactionObject = uow.GetObjectByKey <InventoryCommandItemTransaction>(InventoryObjectId); NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType); InventoryTransactionObject ITO = new InventoryTransactionObject(uow); ITO.ObjectId = o; ITO.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction); ITO.Save(); NAS.DAL.CMS.ObjectDocument.ObjectType type = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType); InventoryTransactionCustomType ITCT = new InventoryTransactionCustomType(uow); ITCT.ObjectTypeId = type; ITCT.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction); ITCT.Save(); } else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction))) { InventoryCommandFinancialTransaction transactionObject = uow.GetObjectByKey <InventoryCommandFinancialTransaction>(InventoryObjectId); NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType); TransactionObject TO = new TransactionObject(uow); TO.ObjectId = o; TO.TransactionId = (transactionObject as Transaction); TO.Save(); } else if (typeof(T).Equals(typeof(NAS.DAL.Accounting.Journal.GeneralJournal))) { GeneralJournal journalObject = uow.GetObjectByKey <GeneralJournal>(InventoryObjectId); NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType); GeneralJournalObject GJO = new GeneralJournalObject(uow); GJO.ObjectId = o; GJO.GeneralJournalId = (journalObject as GeneralJournal); GJO.Save(); NAS.DAL.CMS.ObjectDocument.ObjectType type = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType); GeneralJournalCustomType GJCT = new GeneralJournalCustomType(uow); GJCT.ObjectTypeId = type; GJCT.GeneralJournalId = (journalObject as GeneralJournal); GJCT.Save(); } else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Journal.InventoryJournal))) { InventoryJournal journalObject = uow.GetObjectByKey <InventoryJournal>(InventoryObjectId); NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType); InventoryJournalObject ITO = new InventoryJournalObject(uow); ITO.ObjectId = o; ITO.InventoryJournalId = (journalObject as InventoryJournal); ITO.Save(); NAS.DAL.CMS.ObjectDocument.ObjectType type = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType); InventoryJournalCustomType ITCT = new InventoryJournalCustomType(uow); ITCT.ObjectTypeId = type; ITCT.InventoryJournalId = (journalObject as InventoryJournal); ITCT.Save(); } uow.FlushChanges(); }