Exemplo n.º 1
0
		protected static FR_Guid Execute(DbConnection Connection,DbTransaction Transaction,P_L3CO_AO_1648 Parameter,CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null){
			//Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var confirmedStatus = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
            new ORM_ORD_CUO_CustomerOrder_Status.Query
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Confirmed),
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted = false
            }).Single().ORD_CUO_CustomerOrder_StatusID;

            var customerOrder = new ORM_ORD_CUO_CustomerOrder_Header();
            customerOrder.Load(Connection, Transaction, Parameter.CustomerOrderHeaderID);
            customerOrder.Current_CustomerOrderStatus_RefID = confirmedStatus;
            customerOrder.IsCustomerOrderFinalized = true;
            customerOrder.WasAutoApprovedUponReceipt = Parameter.IsAutomaticallyApprovedOnReceipt;

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
            newStatusInHistory.CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
            newStatusInHistory.StatusHistoryComment = Parameter.Message;
            newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
            newStatusInHistory.CustomerOrder_Status_RefID = confirmedStatus;
            newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            newStatusInHistory.Save(Connection, Transaction);

            returnValue.Result = new FR_Guid(customerOrder.Save(Connection, Transaction), customerOrder.ORD_CUO_CustomerOrder_HeaderID).Result;

            return returnValue;
            #endregion UserCode
		}
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2SH_SSSH_1313 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var statusPickingFinished = ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction,
                                                                                 new ORM_LOG_SHP_Shipment_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(Parameter.ShipmentHeaderStatus),
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            }).Single();

            var shipmentStatusHistory = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_StatusHistory();
            shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID         = Parameter.ShipmentHeaderID;
            shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID         = statusPickingFinished.LOG_SHP_Shipment_StatusID;
            shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            shipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
            shipmentStatusHistory.Save(Connection, Transaction);

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OF_SOfA_1652 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var userAccount = new ORM_USR_Account();
            userAccount.Load(Connection, Transaction, Parameter.AccountID);

            //Get business participant for current user account
            var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = userAccount.BusinessParticipant_RefID;
            businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;
            var foundBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            //Get employee using business participant
            var employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.BusinessParticipant_RefID = foundBusinessParticipant.CMN_BPT_BusinessParticipantID;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            var foundEmployee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).Single();

            //clear all assignment tables (connection with offices) for found employee before new save
            var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
            if (foundEmployee != null)
            {
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
            }
            else
            {
                return(new FR_Guid("Employee not created", FR_Status.Error_Internal));
            }

            var foundAssignments = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery);

            foreach (var assignment in foundAssignments)
            {
                assignment.IsDeleted = true;
                assignment.Save(Connection, Transaction);
            }

            //save offices
            foreach (var office in Parameter.Offices)
            {
                P_L5OF_SSOfA_1652 officeSaveParam = new P_L5OF_SSOfA_1652();
                officeSaveParam.OfficeID   = office;
                officeSaveParam.EmployeeID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                cls_Save_SingleOffice_for_Account.Invoke(Connection, Transaction, officeSaveParam, securityTicket);
            }

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 4
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3US_SUAI_1642 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            returnValue.Status = FR_Status.Error_Internal;
            //Put your code here

            //EDIT
            if (Parameter.AccountID != null && Parameter.AccountID != Guid.Empty)
            {
                var item = new ORM_USR_Account();
                if (item.Load(Connection, Transaction, Parameter.AccountID) == null)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }

                ORM_CMN_PER_PersonInfo_2_Account.Query searchConnection = new CL1_CMN_PER.ORM_CMN_PER_PersonInfo_2_Account.Query();
                searchConnection.IsDeleted         = false;
                searchConnection.Tenant_RefID      = securityTicket.TenantID;
                searchConnection.USR_Account_RefID = Parameter.AccountID;

                ORM_CMN_PER_PersonInfo_2_Account personInfo2Account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, searchConnection).FirstOrDefault();

                if (personInfo2Account != null)
                {
                    ORM_CMN_PER_PersonInfo PersonInfo = new ORM_CMN_PER_PersonInfo();
                    PersonInfo.Load(Connection, Transaction, personInfo2Account.CMN_PER_PersonInfo_RefID);

                    if (PersonInfo != null)
                    {
                        PersonInfo.FirstName = Parameter.FirstName;
                        PersonInfo.LastName  = Parameter.LastName;

                        PersonInfo.Save(Connection, Transaction);

                        returnValue.Status = FR_Status.Success;
                        return(returnValue);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 5
0
        protected static FR_L5CO_RCO_2302_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_RCO_2302[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_RCO_2302_Array();
            List <L5CO_RCO_2302> rejectedOrders = new List <L5CO_RCO_2302>();
            foreach (var param in Parameter)
            {
                L5CO_RCO_2302 rejectedProcurementOrder = new L5CO_RCO_2302();
                var           orderedStatusID          = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                                       new ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Rejected),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).SingleOrDefault().ORD_CUO_CustomerOrder_StatusID;

                var customerOrderQuery = new ORM_ORD_CUO_CustomerOrder_Header.Query();
                customerOrderQuery.ORD_CUO_CustomerOrder_HeaderID = param.CustomerOrderHeaderID;
                customerOrderQuery.Tenant_RefID = securityTicket.TenantID;
                var foundCustomerOrder = ORM_ORD_CUO_CustomerOrder_Header.Query.Search(Connection, Transaction, customerOrderQuery).SingleOrDefault();

                foundCustomerOrder.Current_CustomerOrderStatus_RefID = orderedStatusID;
                foundCustomerOrder.IsCustomerOrderFinalized          = true;
                foundCustomerOrder.Save(Connection, Transaction);
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
                newStatusInHistory.CustomerOrder_Header_RefID = foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID;
                newStatusInHistory.StatusHistoryComment       = param.Message;
                newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
                newStatusInHistory.CustomerOrder_Status_RefID            = orderedStatusID;
                newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

                //saving new status in history and customer order header
                newStatusInHistory.Save(Connection, Transaction);
                rejectedProcurementOrder.ProcurementOrderITL = foundCustomerOrder.ProcurementOrderITL;
                rejectedProcurementOrder.ProcuringTenatID    = foundCustomerOrder.OrderingCustomer_BusinessParticipant_RefID.ToString();
                rejectedProcurementOrder.Message             = param.Message;
                rejectedOrders.Add(rejectedProcurementOrder);
            }
            returnValue.Result = rejectedOrders.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 6
0
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L3CO_SCONfH_1413 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guids();
            var results     = new List <Guid>();

            #region Get Account Bussiness participant id
            var resultAccount = new ORM_USR_Account();
            resultAccount.Load(Connection, Transaction, securityTicket.AccountID);
            #endregion

            foreach (var note in Parameter.Notes)
            {
                var result = cls_Save_ORD_CUO_CustomerOrder_Note.Invoke(
                    Connection
                    , Transaction
                    , new P_L2CO_SCON_1442()
                {
                    CustomerOrder_Header_RefID           = Parameter.CustomerOrderHeaderId,
                    CustomerOrder_Position_RefID         = note.CustomerOrderPositionId,
                    CMN_BPT_CTM_OrganizationalUnit_RefID = note.OrganizationslUnitId,
                    CreatedBy_BusinessParticipant_RefID  = resultAccount.BusinessParticipant_RefID,
                    Title               = note.Title,
                    Comment             = note.Comment,
                    NotePublishDate     = note.NotePublichDate,
                    SequenceOrderNumber = -1      // TODO:Marko - leve it empty, for now
                }
                    , securityTicket);
                if (result.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = null;
                    return(returnValue);
                }
                results.Add(result.Result);
            }
            returnValue.Status = FR_Status.Success;
            returnValue.Result = results.ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2BN_SBNfBH_1630 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var note = new CL1_BIL.ORM_BIL_Note();
            if (Parameter.NoteID != Guid.Empty)
            {
                var result = note.Load(Connection, Transaction, Parameter.NoteID);
            }
            else
            {
                note.Tenant_RefID       = securityTicket.TenantID;
                note.BIL_Note           = Guid.NewGuid();
                note.Creation_Timestamp = DateTime.Now;
                note.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            }

            if (Parameter.IsDeleted == true)
            {
                note.IsDeleted = true;
                return(new FR_Guid(note.Save(Connection, Transaction), note.BIL_Note));
            }

            if (Parameter.BillHeaderID != Guid.Empty)
            {
                note.BillHeader_RefID = Parameter.BillHeaderID;
            }

            note.NoteText            = Parameter.NoteText == null ? String.Empty : Parameter.NoteText;
            note.Title               = Parameter.NoteTitle == null ? String.Empty : Parameter.NoteTitle;
            note.SequenceOrderNumber = Parameter.SequenceOrderNumber;
            note.Save(Connection, Transaction);

            returnValue.Result = note.BIL_Note;

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 8
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3CO_RO_1101 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var orderedStatusID = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                new ORM_ORD_CUO_CustomerOrder_Status.Query
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Rejected),
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            }).SingleOrDefault().ORD_CUO_CustomerOrder_StatusID;

            var customerOrderQuery = new ORM_ORD_CUO_CustomerOrder_Header.Query();
            customerOrderQuery.ORD_CUO_CustomerOrder_HeaderID = Parameter.CustomerOrderHeaderID;
            customerOrderQuery.Tenant_RefID = securityTicket.TenantID;
            var foundCustomerOrder = ORM_ORD_CUO_CustomerOrder_Header.Query.Search(Connection, Transaction, customerOrderQuery).SingleOrDefault();

            foundCustomerOrder.Current_CustomerOrderStatus_RefID = orderedStatusID;
            foundCustomerOrder.IsCustomerOrderFinalized          = true;

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
            newStatusInHistory.CustomerOrder_Header_RefID = foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID;
            newStatusInHistory.StatusHistoryComment       = Parameter.Message;
            newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
            newStatusInHistory.CustomerOrder_Status_RefID            = orderedStatusID;
            newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            //saving new status in history and customer order header
            newStatusInHistory.Save(Connection, Transaction);
            returnValue.Result = new FR_Guid(foundCustomerOrder.Save(Connection, Transaction), foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID).Result;

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 9
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2SH_SSN_1655 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var item = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Note();
            if (Parameter.LOG_SHP_Shipment_NoteID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.LOG_SHP_Shipment_NoteID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_SHP_Shipment_NoteID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.LOG_SHP_Shipment_NoteID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
            }

            item.Shipment_Header_RefID        = Parameter.Shipment_Header_RefID;
            item.Shipment_Position_RefID      = Parameter.Shipment_Position_RefID;
            item.IsNotePrintedOnDeliveryPaper = Parameter.IsNotePrintedOnDeliveryPaper;
            item.Title               = Parameter.Title;
            item.Comment             = Parameter.Comment;
            item.NotePublishDate     = Parameter.NotePublishDate;
            item.SequenceOrderNumber = Parameter.SequenceOrderNumber;
            item.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_SHP_Shipment_NoteID));

            #endregion UserCode
        }
Exemplo n.º 10
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2P_SPN_1655 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var item = new CL1_CMN_PRO.ORM_CMN_PRO_Product_Note();
            if (Parameter.Product_NoteID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.Product_NoteID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PRO_Product_NoteID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.Product_NoteID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;

                item.CMN_PRO_Product_NoteID = Guid.NewGuid();
            }

            item.Product_RefID = Parameter.Product_RefID;
            item.IsImportant   = Parameter.IsImportant;
            item.NoteContent   = Parameter.NoteContent;
            item.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PRO_Product_NoteID));

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5US_GAOfA_1742 Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_GAOfA_1742 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5US_GAOfA_1742();
            //Put your code here

            var allOfficesForTenant = cls_Get_AllOffices_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            ORM_USR_Account user = new ORM_USR_Account();
            user.Load(Connection, Transaction, Parameter.UserAccountID);

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            var foundEmployee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).FirstOrDefault();

            if (foundEmployee == null)
            {
                foundEmployee = new ORM_CMN_BPT_EMP_Employee();
                foundEmployee.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
                foundEmployee.Tenant_RefID = securityTicket.TenantID;
                foundEmployee.Save(Connection, Transaction);
            }

            List <L5US_GAOfA_1742a> listOfOfficesWithAssignments = new List <L5US_GAOfA_1742a>();

            foreach (var office in allOfficesForTenant)
            {
                var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                assignmentQuery.CMN_STR_Office_RefID       = office.CMN_STR_OfficeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
                assignmentQuery.IsDeleted    = false;
                var foundAssignment = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery);

                L5US_GAOfA_1742a temp = new L5US_GAOfA_1742a();
                if (foundAssignment.Count > 0)
                {
                    temp.AssignmentID = foundAssignment.First().AssignmentID;
                }
                temp.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                temp.CMN_STR_OfficeID           = office.CMN_STR_OfficeID;
                temp.Office_InternalName        = office.Office_InternalName;
                temp.IsOfficeToAccountDeleted   = foundAssignment.Count == 0;
                temp.Office_Description         = office.Office_Description;
                temp.Office_Name  = office.Office_Name;
                temp.Parent_RefID = office.Parent_RefID;

                temp.USR_AccountID = Parameter.UserAccountID;

                listOfOfficesWithAssignments.Add(temp);
            }

            returnValue.Result = new L5US_GAOfA_1742();
            returnValue.Result.OfficesWithAssignedUser = new List <L5US_GAOfA_1742a>().ToArray();
            returnValue.Result.OfficesWithAssignedUser = listOfOfficesWithAssignments.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 12
0
        protected static FR_L5RS_CSaRSH_0244 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSH_0244 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5RS_CSaRSH_0244();

            returnValue.Result = new L5RS_CSaRSH_0244();

            #region New ShipmentHeader
            var newShipmentHeaderId = Guid.NewGuid();

            #region Get Tenant Curency ID
            var defaultCurrency = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            #endregion

            #region Create Shipment Status History
            #region Get 'Returned' Shipment status
            var returnedStatusId = ORM_LOG_SHP_Shipment_Status.Query.Search(
                Connection,
                Transaction,
                new ORM_LOG_SHP_Shipment_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Returned),
                Tenant_RefID             = securityTicket.TenantID
            }).FirstOrDefault().LOG_SHP_Shipment_StatusID;
            #endregion

            #region Fetch Status History 'performed by' User Account
            var performedByAccount = new ORM_USR_Account();
            performedByAccount.Load(Connection, Transaction, securityTicket.AccountID);
            #endregion

            #region Get ShipmentHeader Number
            var shipmentHeaderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(
                Connection,
                Transaction,
                new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.SupplierReturnShipmentNumber)
            },
                securityTicket).Result.Current_IncreasingNumber;
            #endregion

            var newShipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
            newShipmentStatusHistory.Creation_Timestamp                    = DateTime.Now;
            newShipmentStatusHistory.IsDeleted                             = false;
            newShipmentStatusHistory.LOG_SHP_Shipment_Header_RefID         = newShipmentHeaderId;
            newShipmentStatusHistory.LOG_SHP_Shipment_Status_RefID         = returnedStatusId;
            newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID      = Guid.NewGuid();
            newShipmentStatusHistory.PerformedBy_BusinessParticipant_RefID =
                performedByAccount == null
                ? Guid.Empty
                : performedByAccount.BusinessParticipant_RefID;
            newShipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Create Shipment Header Object
            var newShipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            newShipmentHeader.Creation_Timestamp                 = DateTime.Now;
            newShipmentHeader.LOG_SHP_Shipment_HeaderID          = newShipmentHeaderId;
            newShipmentHeader.RecipientBusinessParticipant_RefID = Parameter.SupplierID;
            newShipmentHeader.ShipmentHeader_Currency_RefID      = defaultCurrency.CMN_CurrencyID;
            newShipmentHeader.ShipmentHeader_Number              = shipmentHeaderNumber;
            newShipmentHeader.ShipmentHeader_ValueWithoutTax     = 0;
            newShipmentHeader.ShipmentPriority   = 0;
            newShipmentHeader.ShipmentType_RefID = newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID;
            newShipmentHeader.Tenant_RefID       = securityTicket.TenantID;
            #endregion
            #endregion

            #region New ReturnShipment Header
            var newReturnShipmentHeaderId = Guid.NewGuid();
            var newReturnShipmentHeader   = new ORM_LOG_SHP_ReturnShipment_Header();
            newReturnShipmentHeader.Creation_Timestamp              = DateTime.Now;
            newReturnShipmentHeader.Ext_Shipment_Header_RefID       = newShipmentHeaderId;
            newReturnShipmentHeader.LOG_SHP_ReturnShipment_HeaderID = newReturnShipmentHeaderId;
            newReturnShipmentHeader.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Save
            var resultHistory        = newShipmentStatusHistory.Save(Connection, Transaction);
            var resultHeader         = newShipmentHeader.Save(Connection, Transaction);
            var resultShipmentHeader = newReturnShipmentHeader.Save(Connection, Transaction);
            if (resultHistory.Status != FR_Status.Success || resultHeader.Status != FR_Status.Success || resultShipmentHeader.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
            }
            else
            {
                returnValue.Status = FR_Status.Success;
                returnValue.Result.ShipmentHeaderID       = newShipmentHeaderId;
                returnValue.Result.ShipmentHeaderNumber   = newShipmentHeader.ShipmentHeader_Number;
                returnValue.Result.ReturnShipmentHeaderID = newReturnShipmentHeaderId;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_ACER_1055 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests();
            var fetched = request.Load(Connection, Transaction, Parameter.RequestID);
            if (fetched.Status != FR_Status.Success || request.CMN_BPT_CTM_CatalogProductExtensionRequestID == Parameter.RequestID)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            request.IsAnswerSent = true;
            request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            request.IfAnswerSent_Date = DateTime.Now;
            request.Request_Answer    = Parameter.RequestAnswer;
            request.Save(Connection, Transaction);

            ArticleRequestAnswerCreation answer = new ArticleRequestAnswerCreation();
            answer.IntendedFor_TenantID = DBCrossTenantReader.Instance.GetPracticeTenantID();
            answer.CreatedBy_TenantID   = securityTicket.TenantID;
            answer.ArticleRequestITL    = Guid.Parse(request.CatalogProductExtensionRequestITL);

            #region Add products
            ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null;

            if (Parameter.Products != null)
            {
                foreach (P_L5CA_ACER_1055a item in Parameter.Products)
                {
                    product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product();
                    product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid();
                    product.CMN_PRO_Product_RefID = item.ProductID;
                    product.Creation_Timestamp    = DateTime.Now;
                    product.Tenant_RefID          = securityTicket.TenantID;
                    product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                    product.Comment = "";
                    product.Save(Connection, Transaction);

                    var cmnProProduct = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction,
                                                                         new ORM_CMN_PRO_Product.Query()
                    {
                        CMN_PRO_ProductID = item.ProductID,
                        Tenant_RefID      = securityTicket.TenantID,
                        IsDeleted         = false
                    }).Single();

                    Product prod = new Product();
                    prod.Product_ITL = cmnProProduct.ProductITL;
                    answer.Products.Add(prod);
                }
            }
            #endregion

            returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 14
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3QT_SQT_0905 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            var item = new ORM_TMS_QuickTask();
            if (Parameter.TMS_QuickTaskID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.TMS_QuickTaskID);
                if (result.Status != FR_Status.Success || item.TMS_QuickTaskID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            if (Parameter.IsDeleted == true)
            {
                #region Delete ORM_CMN_BPT_InvestedWorkTime

                var qtinv_query = new ORM_TMS_QuickTask_InvestedWorkTime.Query();
                qtinv_query.TMS_QuickTasks_RefID = item.TMS_QuickTaskID;
                qtinv_query.IsDeleted            = false;

                var qtinv = ORM_TMS_QuickTask_InvestedWorkTime.Query.Search(Connection, Transaction, qtinv_query);

                foreach (var qt in qtinv)
                {
                    qt.IsDeleted = true;
                    qt.Save(Connection, Transaction);

                    var inv_query = new ORM_CMN_BPT_InvestedWorkTime.Query();
                    inv_query.CMN_BPT_InvestedWorkTimeID = qt.CMN_BPT_InvestedWorkTime_RefID;
                    inv_query.IsDeleted = false;

                    ORM_CMN_BPT_InvestedWorkTime.Query.SoftDelete(Connection, Transaction, inv_query);
                }

                #endregion

                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.TMS_QuickTaskID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.TMS_QuickTaskID == Guid.Empty)
            {
                item.QuickTask_CreatedByAccount_RefID = securityTicket.AccountID;
                item.Tenant_RefID = securityTicket.TenantID;

                #region Define IdentificationNumber

                ORM_TMS_QuickTask.Query query = new ORM_TMS_QuickTask.Query();
                query.Tenant_RefID = securityTicket.TenantID;
                var    count      = ORM_TMS_QuickTask.Query.Search(Connection, Transaction, query).Count() + 1;
                String identifier = "000000" + count.ToString();
                item.IdentificationNumber = identifier.Substring(identifier.Length - 6);

                #endregion


                #region Define DocumentsL3FE_GFIfF_1455

                var structureHeader = new ORM_DOC_Structure_Header();
                structureHeader.DOC_Structure_HeaderID = Guid.NewGuid();

                structureHeader.Label = Parameter.QuickTask_Title.GetContent(Parameter.LanguageID);

                structureHeader.Tenant_RefID = securityTicket.TenantID;
                var structureStatusSave = structureHeader.Save(Connection, Transaction);

                item.QuickTask_DocumentStructureHeader_RefID = structureHeader.DOC_Structure_HeaderID;

                #endregion

                #region BusinessParticipient

                ORM_USR_Account userAcc = new ORM_USR_Account();
                userAcc.Load(Connection, Transaction, securityTicket.AccountID);

                #endregion

                #region Invested work times

                ORM_CMN_BPT_InvestedWorkTime iwt = new ORM_CMN_BPT_InvestedWorkTime();
                iwt.BusinessParticipant_RefID = userAcc.BusinessParticipant_RefID;
                iwt.WorkTime_Source           = "DanuTask - [W" + item.IdentificationNumber + "] " + Parameter.QuickTask_Title.GetContent(Parameter.LanguageID);

                iwt.CMN_BPT_InvestedWorkTimeID  = Guid.NewGuid();
                iwt.WorkTime_Start              = Parameter.QuickTask_StartTime;
                iwt.WorkTime_Amount_min         = (long)Parameter.R_QuickTask_InvestedTime_min;
                iwt.WorkTime_InternalIdentifier = cls_Get_NewInvestedWTimeIdentifier.Invoke(Connection, Transaction, securityTicket).Result.Identifier;
                iwt.Tenant_RefID = securityTicket.TenantID;
                iwt.Save(Connection, Transaction);

                ORM_TMS_QuickTask_InvestedWorkTime qtiwt = new ORM_TMS_QuickTask_InvestedWorkTime();
                qtiwt.CMN_BPT_InvestedWorkTime_RefID = iwt.CMN_BPT_InvestedWorkTimeID;
                qtiwt.Creation_Timestamp             = DateTime.Now;
                qtiwt.Tenant_RefID = securityTicket.TenantID;
                qtiwt.TMS_QuickTask_InvestedWorkTimeID = Guid.NewGuid();
                qtiwt.TMS_QuickTasks_RefID             = item.TMS_QuickTaskID;
                qtiwt.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                var query = new ORM_TMS_QuickTask_InvestedWorkTime.Query();
                query.TMS_QuickTasks_RefID = item.TMS_QuickTaskID;
                query.IsDeleted            = false;

                var result = ORM_TMS_QuickTask_InvestedWorkTime.Query.Search(Connection, Transaction, query).ToArray();

                if (result.Count() == 1)
                {
                    ORM_CMN_BPT_InvestedWorkTime iwt = new ORM_CMN_BPT_InvestedWorkTime();
                    iwt.Load(Connection, Transaction, result[0].CMN_BPT_InvestedWorkTime_RefID);
                    iwt.WorkTime_Source             = "DanuTask - [W" + item.IdentificationNumber + "] " + Parameter.QuickTask_Title.GetContent(Parameter.LanguageID);
                    iwt.WorkTime_Start              = Parameter.QuickTask_StartTime;
                    iwt.WorkTime_Amount_min         = (long)Parameter.R_QuickTask_InvestedTime_min;
                    iwt.WorkTime_InternalIdentifier = cls_Get_NewInvestedWTimeIdentifier.Invoke(Connection, Transaction, securityTicket).Result.Identifier;
                    iwt.Save(Connection, Transaction);
                }
            }

            if (item.QuickTask_StartTime != Parameter.QuickTask_StartTime)
            {
                item.IsManuallyEntered = true;
            }

            if (item.R_QuickTask_InvestedTime_min != Parameter.R_QuickTask_InvestedTime_min)
            {
                item.IsManuallyEntered = true;
            }

            item.QuickTask_Title                = Parameter.QuickTask_Title;
            item.QuickTask_Description          = Parameter.QuickTask_Description;
            item.QuickTask_Type_RefID           = Parameter.QuickTask_Type_RefID;
            item.R_QuickTask_InvestedTime_min   = Parameter.R_QuickTask_InvestedTime_min;
            item.AssignedTo_Project_RefID       = Parameter.AssignedTo_Project_RefID;
            item.AssignedTo_BusinessTask_RefID  = Parameter.AssignedTo_BusinessTask_RefID;
            item.AssignedTo_Feature_RefID       = Parameter.AssignedTo_Feature_RefID;
            item.AssignedTo_DeveloperTask_RefID = Parameter.AssignedTo_DeveloperTask_RefID;
            item.QuickTask_StartTime            = Parameter.QuickTask_StartTime;

            return(new FR_Guid(item.Save(Connection, Transaction), item.TMS_QuickTaskID));

            #endregion UserCode
        }
Exemplo n.º 15
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3NT_SN_0921 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here
            ORM_USR_Account noteCreatorAccount = new ORM_USR_Account();
            noteCreatorAccount.Load(Connection, Transaction, Parameter.CreatorID);
            if (Parameter.ProjectNoteID != Guid.Empty)
            {
                if (Parameter.IsDeleted)
                {
                    ORM_CMN_NoteRevision.Query noteRevisionsQuery = new ORM_CMN_NoteRevision.Query();
                    noteRevisionsQuery.Note_RefID = Parameter.NoteID;
                    noteRevisionsQuery.IsDeleted  = false;


                    List <ORM_CMN_NoteRevision> existingRevisions = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, noteRevisionsQuery);
                    if (existingRevisions.Count > 1)
                    {
                        existingRevisions = existingRevisions.Where(er => er.CMN_NoteRevisionID != Parameter.NoteRevisionID).OrderBy(er => er.Version).ToList();
                        noteRevisionsQuery.CMN_NoteRevisionID = Parameter.NoteRevisionID;
                        ORM_CMN_NoteRevision.Query.SoftDelete(Connection, Transaction, noteRevisionsQuery);

                        ORM_CMN_Note parentNote = new ORM_CMN_Note();
                        parentNote.Load(Connection, Transaction, Parameter.NoteID);
                        parentNote.Current_NoteRevision_RefID = existingRevisions.Last().CMN_NoteRevisionID;
                        parentNote.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_Note.Query cmnNoteQuery = new ORM_CMN_Note.Query();
                        cmnNoteQuery.CMN_NoteID = Parameter.NoteID;
                        ORM_CMN_Note.Query.SoftDelete(Connection, Transaction, cmnNoteQuery);

                        ORM_TMS_PRO_Project_Notes.Query projectNotesQuery = new ORM_TMS_PRO_Project_Notes.Query();
                        projectNotesQuery.Ext_CMN_Note_RefID = Parameter.NoteID;
                        ORM_TMS_PRO_Project_Notes.Query.SoftDelete(Connection, Transaction, projectNotesQuery);

                        ORM_CMN_NoteRevision.Query.SoftDelete(Connection, Transaction, noteRevisionsQuery);

                        ORM_TMS_PRO_Project_Note_Collaborators.Query notesCollaboratorQuery = new ORM_TMS_PRO_Project_Note_Collaborators.Query();
                        notesCollaboratorQuery.ProjectNote_RefID = Parameter.ProjectNoteID;
                        ORM_TMS_PRO_Project_Note_Collaborators.Query.SoftDelete(Connection, Transaction, notesCollaboratorQuery);

                        ORM_TMS_PRO_Project_Note_2_Tag.Query note2tagQuery = new ORM_TMS_PRO_Project_Note_2_Tag.Query();
                        note2tagQuery.Project_Note_RefID = Parameter.ProjectNoteID;
                        ORM_TMS_PRO_Project_Note_2_Tag.Query.SoftDelete(Connection, Transaction, note2tagQuery);
                    }
                }
                else
                {
                    ORM_TMS_PRO_Project_Notes existingProjectNote = new ORM_TMS_PRO_Project_Notes();
                    existingProjectNote.Load(Connection, Transaction, Parameter.ProjectNoteID);
                    ORM_CMN_NoteRevision existingNoteVersion = new ORM_CMN_NoteRevision();
                    existingNoteVersion.Load(Connection, Transaction, Parameter.NoteRevisionID);
                    if (Parameter.SaveAsNewVersion)
                    {
                        ORM_CMN_NoteRevision.Query RevisionCountQuery = new ORM_CMN_NoteRevision.Query();
                        RevisionCountQuery.Note_RefID = Parameter.NoteID;

                        ORM_CMN_NoteRevision newNoteVersion = new ORM_CMN_NoteRevision();
                        newNoteVersion.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                        newNoteVersion.Content      = Parameter.Content;
                        newNoteVersion.Note_RefID   = Parameter.NoteID;
                        newNoteVersion.Tenant_RefID = securityTicket.TenantID;
                        newNoteVersion.Version      = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, RevisionCountQuery).Count + 1;
                        newNoteVersion.Title        = Parameter.Title;
                        newNoteVersion.Save(Connection, Transaction);
                        if (Parameter.ReplaceCreator)
                        {
                            //Find current creator of note and make him a collaborator to this note
                            ORM_USR_Account.Query currentCreatorQuery = new ORM_USR_Account.Query();
                            currentCreatorQuery.BusinessParticipant_RefID = existingNoteVersion.CreatedBy_BusinessParticipant_RefID;
                            currentCreatorQuery.IsDeleted    = false;
                            currentCreatorQuery.Tenant_RefID = securityTicket.TenantID;
                            ORM_USR_Account currentCreator = ORM_USR_Account.Query.Search(Connection, Transaction, currentCreatorQuery).FirstOrDefault();

                            ORM_TMS_PRO_Project_Note_Collaborators.Query noteCollaboratorQuery = new ORM_TMS_PRO_Project_Note_Collaborators.Query();
                            noteCollaboratorQuery.ProjectNote_RefID = Parameter.ProjectNoteID;
                            noteCollaboratorQuery.IsDeleted         = false;
                            noteCollaboratorQuery.Account_RefID     = noteCreatorAccount.USR_AccountID;
                            if (ORM_TMS_PRO_Project_Note_Collaborators.Query.Exists(Connection, Transaction, noteCollaboratorQuery))
                            {
                                //If current creator was collaborator on existing note, delete him, because he has the role of creator now, and
                                //old creator will be added to collaborators.
                                ORM_TMS_PRO_Project_Note_Collaborators.Query.SoftDelete(Connection, Transaction, noteCollaboratorQuery);
                            }
                            ORM_TMS_PRO_Project_Note_Collaborators newNoteCollaborator = new ORM_TMS_PRO_Project_Note_Collaborators();
                            newNoteCollaborator.Account_RefID     = currentCreator.USR_AccountID;
                            newNoteCollaborator.ProjectNote_RefID = Parameter.ProjectNoteID;
                            newNoteCollaborator.Tenant_RefID      = securityTicket.TenantID;
                            newNoteCollaborator.Save(Connection, Transaction);

                            ORM_CMN_Note.Query cmnNoteCreatorUpdateFind = new ORM_CMN_Note.Query();
                            cmnNoteCreatorUpdateFind.CMN_NoteID = Parameter.NoteID;
                            ORM_CMN_Note.Query cmnNoteCreatorUpdate = new ORM_CMN_Note.Query();
                            cmnNoteCreatorUpdate.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                            ORM_CMN_Note.Query.Update(Connection, Transaction, cmnNoteCreatorUpdateFind, cmnNoteCreatorUpdate);
                        }
                    }
                    else
                    {
                        existingNoteVersion.Content = Parameter.Content;
                        existingNoteVersion.Title   = Parameter.Title;
                        existingNoteVersion.Save(Connection, Transaction);

                        if (existingProjectNote.Project_RefID != Parameter.ProjectID)
                        {
                            existingProjectNote.Project_RefID = Parameter.ProjectID;
                            existingProjectNote.Save(Connection, Transaction);
                        }
                    }

                    //Update note tags (Delete existing ones and save new ones)
                    P_L3TG_ATtN_1738 tagParameter = new P_L3TG_ATtN_1738();
                    tagParameter.ProjectNoteID = Parameter.ProjectNoteID;
                    List <P_L3TG_ATtN_1738a> tagListParameter = new List <P_L3TG_ATtN_1738a>();
                    foreach (var currentTag in Parameter.Tags)
                    {
                        P_L3TG_ATtN_1738a tempTag = new P_L3TG_ATtN_1738a();
                        tempTag.TagValue      = currentTag.TagValue;
                        tempTag.TMS_PRO_TagID = currentTag.TagID;
                        tagListParameter.Add(tempTag);
                    }
                    tagParameter.NoteTags = tagListParameter.ToArray();
                    cls_Add_Tags_to_Note.Invoke(Connection, Transaction, tagParameter, securityTicket);
                }
            }
            else
            {
                ORM_CMN_Note              newCmnNote      = new ORM_CMN_Note();
                ORM_CMN_NoteRevision      newNoteRevision = new ORM_CMN_NoteRevision();
                ORM_TMS_PRO_Project_Notes newProjectNote  = new ORM_TMS_PRO_Project_Notes();

                newNoteRevision.Note_RefID = newCmnNote.CMN_NoteID;
                newNoteRevision.Content    = Parameter.Content;
                newNoteRevision.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                newNoteRevision.Tenant_RefID = securityTicket.TenantID;
                newNoteRevision.Title        = Parameter.Title;
                newNoteRevision.Version      = 1;
                newNoteRevision.Save(Connection, Transaction);

                newCmnNote.Current_NoteRevision_RefID          = newNoteRevision.CMN_NoteRevisionID;
                newCmnNote.CreatedBy_BusinessParticipant_RefID = noteCreatorAccount.BusinessParticipant_RefID;
                newCmnNote.Tenant_RefID = securityTicket.TenantID;
                newCmnNote.Save(Connection, Transaction);

                newProjectNote.Ext_CMN_Note_RefID = newCmnNote.CMN_NoteID;
                newProjectNote.Project_RefID      = Parameter.ProjectID;
                newProjectNote.Tenant_RefID       = securityTicket.TenantID;
                newProjectNote.Save(Connection, Transaction);

                //Update note tags (Delete existing ones and save new ones)
                P_L3TG_ATtN_1738 tagParameter = new P_L3TG_ATtN_1738();
                tagParameter.ProjectNoteID = newProjectNote.TMS_PRO_Project_NoteID;
                List <P_L3TG_ATtN_1738a> tagListParameter = new List <P_L3TG_ATtN_1738a>();
                foreach (var currentTag in Parameter.Tags)
                {
                    P_L3TG_ATtN_1738a tempTag = new P_L3TG_ATtN_1738a();
                    tempTag.TagValue      = currentTag.TagValue;
                    tempTag.TMS_PRO_TagID = currentTag.TagID;
                    tagListParameter.Add(tempTag);
                }
                tagParameter.NoteTags = tagListParameter.ToArray();
                cls_Add_Tags_to_Note.Invoke(Connection, Transaction, tagParameter, securityTicket);
            }
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 16
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PS_ST_1157 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            #region Get Account By AccountID

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #endregion

            #region PrescriptionTransaction_InternalNubmer

            var qtransaction = new ORM_HEC_Patient_Prescription_Transaction.Query();
            qtransaction.Tenant_RefID = securityTicket.TenantID;

            var count          = ORM_HEC_Patient_Prescription_Transaction.Query.Search(Connection, Transaction, qtransaction).Count();
            var internalnumber = "0000000" + count;
            internalnumber = internalnumber.Substring(internalnumber.Length - 7, 7);

            #endregion

            var transaction = new ORM_HEC_Patient_Prescription_Transaction();
            transaction.HEC_Patient_Prescription_TransactionID = Guid.NewGuid();
            transaction.PrescriptionTransaction_InternalNubmer = internalnumber;
            transaction.PrescriptionTransaction_IsComplete     = false;
            transaction.PrescriptionTransaction_RequestedDateOfDeliveryFrom       = Parameter.PrescriptionTransaction_RequestedDateOfDeliveryFrom;
            transaction.PrescriptionTransaction_RequestedDateOfDeliveryTo         = Parameter.PrescriptionTransaction_RequestedDateOfDeliveryTo;
            transaction.PrescriptionTransaction_CreatedByBusinessParticpant_RefID = account.BusinessParticipant_RefID;
            transaction.PrescriptionTransaction_Comment                       = Parameter.PrescriptionTransaction_Comment;
            transaction.PrescriptionTransaction_Patient_RefID                 = Parameter.PrescriptionTransaction_Patient_RefID;
            transaction.PerscriptionTransaction_DeliveryAddress_RefID         = Parameter.PrescriptionTransaction_Address_RefID;
            transaction.PrescriptionTransaction_UseParticipationPolicyAddress = false;
            transaction.PrescriptionTransaction_UsePatientAddress             = true;
            transaction.PrescriptionTransaction_UseReceiptAddress             = false;
            transaction.Creation_Timestamp = DateTime.Now;
            transaction.Tenant_RefID       = securityTicket.TenantID;
            transaction.Save(Connection, Transaction);

            if (Parameter.Prescriptions != null)
            {
                var header = new ORM_HEC_Patient_Prescription_Header();
                header.HEC_Patient_Prescription_HeaderID = Guid.NewGuid();
                header.Patient_RefID               = Parameter.PrescriptionTransaction_Patient_RefID;
                header.PrescribedBy_Doctor_RefID   = Guid.Empty;
                header.Prescription_Date           = new DateTime();
                header.Prescription_Comment        = "";
                header.Prescription_InternalNumber = transaction.PrescriptionTransaction_InternalNubmer + "/" + 1;
                header.Perscription_UploadedByBusinessParticipant_RefID = account.BusinessParticipant_RefID;
                header.Creation_Timestamp = DateTime.Now;
                header.Tenant_RefID       = securityTicket.TenantID;
                header.Save(Connection, Transaction);

                var transaction2header = new ORM_HEC_Patient_Prescription_2_PrescriptionTransaction();
                transaction2header.AssignmentID = Guid.NewGuid();
                transaction2header.HEC_Patient_Prescription_Header_RefID      = header.HEC_Patient_Prescription_HeaderID;
                transaction2header.HEC_Patient_Prescription_Transaction_RefID = transaction.HEC_Patient_Prescription_TransactionID;
                transaction2header.Creation_Timestamp = DateTime.Now;
                transaction2header.Tenant_RefID       = securityTicket.TenantID;
                transaction2header.Save(Connection, Transaction);

                var prescriptionDocument = new ORM_HEC_Patient_Prescription_Document();
                prescriptionDocument.HEC_Patient_Prescription_DocumentID = Guid.NewGuid();
                prescriptionDocument.PrescriptionHeader_RefID            = header.HEC_Patient_Prescription_HeaderID;
                prescriptionDocument.Comment            = "";
                prescriptionDocument.Document_RefID     = Guid.NewGuid();
                prescriptionDocument.Creation_Timestamp = DateTime.Now;
                prescriptionDocument.Tenant_RefID       = securityTicket.TenantID;
                prescriptionDocument.Save(Connection, Transaction);

                var document = new ORM_DOC_Document();
                document.DOC_DocumentID     = prescriptionDocument.Document_RefID;
                document.Alias              = Parameter.Prescriptions.File_Name;
                document.PrimaryType        = Parameter.Prescriptions.File_Extension;
                document.Creation_Timestamp = DateTime.Now;
                document.Tenant_RefID       = securityTicket.TenantID;
                document.Save(Connection, Transaction);

                var revision = new ORM_DOC_DocumentRevision();
                revision.DOC_DocumentRevisionID = Guid.NewGuid();
                revision.Document_RefID         = prescriptionDocument.Document_RefID;
                revision.Revision            = 1;
                revision.IsLastRevision      = true;
                revision.UploadedByAccount   = securityTicket.AccountID;
                revision.File_Name           = Parameter.Prescriptions.File_Name;
                revision.File_ServerLocation = Parameter.Prescriptions.File_ServerLocation;
                revision.File_Extension      = Parameter.Prescriptions.File_Extension;
                revision.File_Size_Bytes     = Parameter.Prescriptions.File_Size_Bytes;
                revision.Creation_Timestamp  = DateTime.Now;
                revision.Tenant_RefID        = securityTicket.TenantID;
                revision.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5CO_ACOaCS_2108_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_ACOaCS_2108[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_ACOaCS_2108_Array();
            List <L5CO_ACOaCS_2108> confirmedProcurementOrders = new List <L5CO_ACOaCS_2108>();
            foreach (var param in Parameter)
            {
                L5CO_ACOaCS_2108 procurementOrderITL = new L5CO_ACOaCS_2108();
                var confirmedStatus = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                    new ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Confirmed),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).Single().ORD_CUO_CustomerOrder_StatusID;

                var customerOrder = new ORM_ORD_CUO_CustomerOrder_Header();
                customerOrder.Load(Connection, Transaction, param.CustomerOrderHeaderID);
                customerOrder.Current_CustomerOrderStatus_RefID = confirmedStatus;
                customerOrder.IsCustomerOrderFinalized          = true;
                customerOrder.Save(Connection, Transaction);

                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
                newStatusInHistory.CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                newStatusInHistory.StatusHistoryComment       = param.Message;
                newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
                newStatusInHistory.CustomerOrder_Status_RefID            = confirmedStatus;
                newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                newStatusInHistory.Save(Connection, Transaction);


                procurementOrderITL.ProcurementOrderITL = customerOrder.ProcurementOrderITL;
                procurementOrderITL.ProcuringTenatID    = customerOrder.OrderingCustomer_BusinessParticipant_RefID.ToString();



                ORM_CMN_NumberRange_UsageArea numberRangeUsageArea = ORM_CMN_NumberRange_UsageArea.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange_UsageArea.Query()
                {
                    IsDeleted              = false,
                    Tenant_RefID           = securityTicket.TenantID,
                    GlobalStaticMatchingID = NumberRangeGlobalPropertyMatchingID
                }).FirstOrDefault();


                if (numberRangeUsageArea == null)
                {
                    throw new Exception(String.Format("Number range usage area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                ORM_CMN_NumberRange numberRange = ORM_CMN_NumberRange.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID
                }).FirstOrDefault();

                if (numberRange == null)
                {
                    throw new Exception(String.Format("Number range for area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                numberRange.Value_Current++;
                numberRange.Save(Connection, Transaction);
                string shipmentNumber = numberRange.FixedPrefix + numberRange.Value_Current.ToString().PadLeft(numberRange.Formatting_NumberLength, numberRange.Formatting_LeadingFillCharacter[0]);

                ORM_LOG_SHP_Shipment_Header shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
                shipmentHeader.LOG_SHP_Shipment_HeaderID          = Guid.NewGuid();
                shipmentHeader.RecipientBusinessParticipant_RefID = customerOrder.OrderingCustomer_BusinessParticipant_RefID;
                shipmentHeader.ShipmentHeaderITL              = shipmentHeader.LOG_SHP_Shipment_HeaderID.ToString();
                shipmentHeader.ShipmentHeader_Number          = shipmentNumber;
                shipmentHeader.Shippipng_AddressUCD_RefID     = customerOrder.ShippingAddressUCD_RefID;
                shipmentHeader.ShipmentPriority               = 0;
                shipmentHeader.ShipmentHeader_ValueWithoutTax = customerOrder.TotalValue_BeforeTax;
                shipmentHeader.ShipmentHeader_Currency_RefID  = customerOrder.CustomerOrder_Currency_RefID;
                shipmentHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentHeader.IsDeleted    = false;
                shipmentHeader.Save(Connection, Transaction);

                var customerOrderPositions = ORM_ORD_CUO_CustomerOrder_Position.Query.Search(Connection, Transaction, new ORM_ORD_CUO_CustomerOrder_Position.Query()
                {
                    CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                if (customerOrderPositions != null)
                {
                    foreach (var customerOrderPosition in customerOrderPositions)
                    {
                        ORM_LOG_SHP_Shipment_Position shipmentPosition = new ORM_LOG_SHP_Shipment_Position();
                        shipmentPosition.LOG_SHP_Shipment_PositionID   = Guid.NewGuid();
                        shipmentPosition.ShipmentPositionITL           = shipmentPosition.LOG_SHP_Shipment_PositionID.ToString();
                        shipmentPosition.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                        shipmentPosition.CMN_PRO_Product_RefID         = customerOrderPosition.CMN_PRO_Product_RefID;
                        shipmentPosition.CMN_PRO_ProductVariant_RefID  = customerOrderPosition.CMN_PRO_Product_Variant_RefID;
                        shipmentPosition.CMN_PRO_ProductRelease_RefID  = customerOrderPosition.CMN_PRO_Product_Release_RefID;
                        shipmentPosition.QuantityToShip = customerOrderPosition.Position_Quantity;
                        shipmentPosition.ShipmentPosition_PricePerUnitValueWithoutTax = customerOrderPosition.Position_ValuePerUnit;
                        shipmentPosition.ShipmentPosition_ValueWithoutTax             = customerOrderPosition.Position_ValueTotal;
                        shipmentPosition.IsCancelled  = false;
                        shipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        shipmentPosition.IsDeleted    = false;
                        shipmentPosition.Save(Connection, Transaction);
                        ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition customerOrderPositionToShipmentPosition = new ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition();
                        customerOrderPositionToShipmentPosition.AssignmentID = Guid.NewGuid();
                        customerOrderPositionToShipmentPosition.LOG_SHP_Shipment_Position_RefID      = shipmentPosition.LOG_SHP_Shipment_PositionID;
                        customerOrderPositionToShipmentPosition.ORD_CUO_CustomerOrder_Position_RefID = customerOrderPosition.ORD_CUO_CustomerOrder_PositionID;
                        customerOrderPositionToShipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        customerOrderPositionToShipmentPosition.IsDeleted    = false;
                        customerOrderPositionToShipmentPosition.Save(Connection, Transaction);
                    }
                }


                //TO DO: UNCOMMENT AFTER JANKO ADD STATUSES
                //var shipmentStatusHistoryStatusID = ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Status.Query()
                //{
                //    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Created),
                //    Tenant_RefID = securityTicket.TenantID,
                //    IsDeleted = false
                //}).Single().LOG_SHP_Shipment_StatusID;

                //ORM_LOG_SHP_Shipment_StatusHistory shipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
                //shipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID = Guid.NewGuid();
                //shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                //shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID = shipmentStatusHistoryStatusID;
                //shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.IsDeleted = false;
                //shipmentStatusHistory.Save(Connection, Transaction);

                ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader shipmentToCustomerOrderHeader = new ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader();
                shipmentToCustomerOrderHeader.AssignmentID = Guid.NewGuid();
                shipmentToCustomerOrderHeader.LOG_SHP_Shipment_Header_RefID      = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                shipmentToCustomerOrderHeader.ORD_CUO_CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                shipmentToCustomerOrderHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentToCustomerOrderHeader.IsDeleted    = false;
                shipmentToCustomerOrderHeader.Save(Connection, Transaction);


                confirmedProcurementOrders.Add(procurementOrderITL);
            }
            returnValue.Result = confirmedProcurementOrders.ToArray();
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5CA_PNCV_1603 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_PNCV_1603 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CA_PNCV_1603();
            returnValue.Result = new L5CA_PNCV_1603();

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #region Update active catalog revision

            ORM_CMN_PRO_Catalog_Revision rev = new ORM_CMN_PRO_Catalog_Revision();
            rev.Load(Connection, Transaction, Parameter.CMN_PRO_Catalog_RevisionID);
            rev.Valid_From    = Parameter.Valid_From;
            rev.Valid_Through = Parameter.Valid_Through;
            rev.Default_PricelistRelease_RefID        = Parameter.Default_PricelistRelease_RefID;
            rev.PublishedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            rev.PublishedOn_Date = DateTime.Now;

            rev.Save(Connection, Transaction);

            #endregion

            #region Create new catalog revision

            ORM_CMN_PRO_Catalog_Revision newRev = new ORM_CMN_PRO_Catalog_Revision();
            newRev.CMN_PRO_Catalog_RevisionID = Guid.NewGuid();
            newRev.CMN_PRO_Catalog_RefID      = rev.CMN_PRO_Catalog_RefID;
            newRev.Tenant_RefID                = securityTicket.TenantID;
            newRev.Creation_Timestamp          = DateTime.Now;
            newRev.CatalogRevision_Description = "Revision for Catalog";
            newRev.CatalogRevision_Name        = "New Catalog Revision";
            newRev.IsDeleted      = false;
            newRev.RevisionNumber = rev.RevisionNumber + 1;
            newRev.Save(Connection, Transaction);

            #endregion


            #region Products

            var oldProducts = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query()
            {
                CMN_PRO_Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            if (oldProducts.Count == 0)
            {
                returnValue.Result.Status_Code    = -1;     // -1 no products in revision
                returnValue.Result.Status_Message = "no products in revision";
                return(returnValue);
            }

            //oldProductID - newProductID
            Dictionary <Guid, Guid> productsMapping = new Dictionary <Guid, Guid>();

            foreach (var item in oldProducts)
            {
                ORM_CMN_SLS_Pricelist_Release plr = new ORM_CMN_SLS_Pricelist_Release();
                plr.Load(Connection, Transaction, Parameter.Default_PricelistRelease_RefID);

                var pricelistPriceQry = new ORM_CMN_SLS_Price.Query()
                {
                    CMN_PRO_Product_RefID  = item.CMN_PRO_Product_RefID,
                    PricelistRelease_RefID = plr.CMN_SLS_Pricelist_ReleaseID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                };

                var prices = ORM_CMN_SLS_Price.Query.Search(Connection, Transaction, pricelistPriceQry);
                if (prices.Count == 0)
                {
                    ORM_CMN_PRO_Product pr = new ORM_CMN_PRO_Product();
                    pr.Load(Connection, Transaction, item.CMN_PRO_Product_RefID);
                    returnValue.Result.Status_Code    = -2;                         // -2 => pricelist does not have price for product
                    returnValue.Result.Status_Message = pr.Product_Number;
                    return(returnValue);
                }

                var newProduct = new ORM_CMN_PRO_Catalog_Product()
                {
                    CMN_PRO_Catalog_ProductID     = Guid.NewGuid(),
                    CMN_PRO_Product_Variant_RefID = item.CMN_PRO_Product_Variant_RefID,
                    Creation_Timestamp            = DateTime.Now,
                    Tenant_RefID = item.Tenant_RefID,
                    CMN_PRO_Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID,
                    CMN_PRO_Product_RefID          = item.CMN_PRO_Product_RefID,
                };

                newProduct.Save(Connection, Transaction);

                productsMapping.Add(item.CMN_PRO_Catalog_ProductID, newProduct.CMN_PRO_Catalog_ProductID);
            }

            #endregion

            #region ProductGroups

            var oldGroups = ORM_CMN_PRO_Catalog_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_ProductGroup.Query()
            {
                Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            //oldGroupID - newGroupID
            Dictionary <Guid, Guid> groupsMapping = new Dictionary <Guid, Guid>();
            groupsMapping.Add(Guid.Empty, Guid.Empty);

            foreach (var item in oldGroups)
            {
                groupsMapping.Add(item.CMN_PRO_Catalog_ProductGroupID, Guid.NewGuid());
            }

            foreach (var item in oldGroups)
            {
                var newGroup = new ORM_CMN_PRO_Catalog_ProductGroup()
                {
                    CMN_PRO_Catalog_ProductGroupID   = groupsMapping[item.CMN_PRO_Catalog_ProductGroupID],
                    Catalog_Revision_RefID           = newRev.CMN_PRO_Catalog_RevisionID,
                    CatalogProductGroup_Name         = item.CatalogProductGroup_Name,
                    CatalogProductGroup_Parent_RefID = groupsMapping[item.CatalogProductGroup_Parent_RefID],
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = item.Tenant_RefID
                };

                newGroup.Save(Connection, Transaction);

                var oldProductsInGroup = ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query()
                {
                    CMN_PRO_Catalog_ProductGroup_RefID = item.CMN_PRO_Catalog_ProductGroupID,
                    IsDeleted = false
                });

                foreach (var product in oldProductsInGroup)
                {
                    var newProduct = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup()
                    {
                        AssignmentID = Guid.NewGuid(),
                        CMN_PRO_Catalog_ProductGroup_RefID = groupsMapping[product.CMN_PRO_Catalog_ProductGroup_RefID],
                        CMN_PRO_Catalog_Product_RefID      = productsMapping[product.CMN_PRO_Catalog_Product_RefID],
                        Creation_Timestamp = DateTime.Now,
                        Tenant_RefID       = item.Tenant_RefID
                    };

                    newProduct.Save(Connection, Transaction);
                }
            }


            #endregion

            returnValue.Result.Status_Code    = 1;
            returnValue.Result.Status_Message = "Success";
            returnValue.Result.ID             = newRev.CMN_PRO_Catalog_RevisionID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 19
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5ZW_SDfNC_1707 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();
            returnValue.Result = false;

            //Put your code here
            #region get securityTicket and businessParticipantID by Paramter.AccountID and set defaultLanguageID
            Guid tenantID;
            Guid businessParticipantID;

            if (Parameter.AccountID == Guid.Empty)
            {
                return(returnValue);
            }

            ORM_USR_Account orm_account = new ORM_USR_Account();
            var             result      = orm_account.Load(Connection, Transaction, Parameter.AccountID);
            if (result.Status != FR_Status.Success || orm_account.USR_AccountID == Guid.Empty)
            {
                return(returnValue);
            }

            tenantID       = orm_account.Tenant_RefID;
            securityTicket = new CSV2Core.SessionSecurity.SessionSecurityTicket()
            {
                TenantID = tenantID
            };

            ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.IfTenant_Tenant_RefID = tenantID;
            businessParticipantQuery.IsDeleted             = false;
            ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).FirstOrDefault();

            if (businessParticipant == null)
            {
                return(returnValue);
            }

            businessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
            #endregion

            #region get languages for tenant and set parameter dict values
            P_L2LN_GALFTID_1530 languageParam = new P_L2LN_GALFTID_1530()
            {
                Tenant_RefID = tenantID
            };
            L2LN_GALFTID_1530[] languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, languageParam, securityTicket).Result;
            SetParameterDictValues(Parameter, languages);

            List <ISOLanguage> languagesISOs = new List <ISOLanguage>();
            languagesISOs.AddRange(languages.Select(l => new ISOLanguage()
            {
                ISO        = l.ISO_639_1,
                LanguageID = l.CMN_LanguageID
            }).ToList());
            #endregion

            #region save defaultLanguage

            // We are setting language for bp and acc
            var defaultLanguage = languages.FirstOrDefault(i => i.ISO_639_1.ToLower().Contains(Parameter.DefaultLanguageCode.ToLower()));
            if (defaultLanguage != null)
            {
                businessParticipant.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID;
                businessParticipant.Save(Connection, Transaction);

                orm_account.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID;
                orm_account.Save(Connection, Transaction);
            }

            #endregion

            #region save default country

            if (Parameter.DefaultCountry != null)
            {
                ORM_CMN_Country country = new ORM_CMN_Country();
                country.CMN_CountryID          = Guid.NewGuid();
                country.Country_ISOCode_Alpha3 = Parameter.DefaultCountry.Code;
                country.Country_Name           = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                country.Creation_Timestamp     = DateTime.Now;
                country.Default_Currency_RefID = Guid.Empty;
                country.Default_Language_RefID = Guid.Empty;
                country.Tenant_RefID           = tenantID;
                country.IsDeleted = false;
                country.IsDefault = true;

                foreach (var languageItem in languages)
                {
                    country.Country_Name.UpdateEntry(languageItem.CMN_LanguageID, Parameter.DefaultCountry.Name);
                }

                country.Save(Connection, Transaction);
            }

            #endregion

            #region save default currency

            //asign currency
            if (Parameter.DefaultCurrency != null)
            {
                ORM_CMN_Currency currency = new ORM_CMN_Currency();
                currency.CMN_CurrencyID     = Guid.NewGuid();
                currency.Creation_Timestamp = DateTime.Now;
                currency.IsDeleted          = false;
                currency.ISO4127            = Parameter.DefaultCurrency.Code;
                currency.Name = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                currency.Tenant_RefID = tenantID;

                foreach (var language in languages)
                {
                    currency.Name.UpdateEntry(language.CMN_LanguageID, Parameter.DefaultCurrency.Name);
                }

                currency.Save(Connection, Transaction);

                //set default currency
                ORM_CMN_BPT_BusinessParticipant businessPart = new ORM_CMN_BPT_BusinessParticipant();
                businessPart.Load(Connection, Transaction, businessParticipantID);

                businessPart.DefaultCurrency_RefID = currency.CMN_CurrencyID;
                businessPart.Save(Connection, Transaction);
            }

            #endregion

            #region save organisational units
            if (Parameter.OrganisationalUnitParameters.Length > 0)
            {
                foreach (var item in Parameter.OrganisationalUnitParameters)
                {
                    cls_Save_Office.Invoke(Connection, Transaction, item, securityTicket);
                }
            }
            #endregion

            #region save cost centers
            if (Parameter.CostCenterParameters.Length > 0)
            {
                foreach (var item in Parameter.CostCenterParameters)
                {
                    cls_Save_CostCenter.Invoke(Connection, Transaction, item, securityTicket);
                }
            }
            #endregion

            #region save warehouses
            if (Parameter.WarehousesParameters.Length > 0)
            {
                #region save warehouse group
                P_L2WH_SWHG_1327 warehouseGroupParam = new P_L2WH_SWHG_1327();
                warehouseGroupParam.Parent_RefID               = Guid.Empty;
                warehouseGroupParam.WarehouseGroup_Name        = "Waregouse group";
                warehouseGroupParam.WarehouseGroup_Description = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                foreach (var language in languages)
                {
                    warehouseGroupParam.WarehouseGroup_Description.UpdateEntry(language.CMN_LanguageID, String.Empty);
                }

                var warehouseGroupID = cls_Save_Warehouse_Group.Invoke(Connection, Transaction, warehouseGroupParam, securityTicket).Result;
                #endregion

                foreach (var item in Parameter.WarehousesParameters)
                {
                    item.LOG_WRH_WarehouseGroupID = warehouseGroupID;
                    cls_Save_Warehouse.Invoke(Connection, Transaction, item, securityTicket);
                }
            }
            #endregion

            #region create dimension templates
            string           jsonTemplates      = ReadFromFile.LoadContentFromFile(@"Dimensions.json");
            List <Dimension> dimensionTemplates = JsonConvert.DeserializeObject <List <Dimension> >(jsonTemplates);

            int orderSequence = 1;
            ORM_CMN_PRO_Dimension       orm_dimension;
            ORM_CMN_PRO_Dimension_Value orm_dimensionValue;
            foreach (var template in dimensionTemplates)
            {
                orderSequence = 1;

                #region save dimension
                orm_dimension = new ORM_CMN_PRO_Dimension();
                orm_dimension.Product_RefID = Guid.Empty;
                orm_dimension.DimensionName = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                orm_dimension.IsDimensionTemplate = true;
                orm_dimension.Tenant_RefID        = tenantID;

                foreach (var language in languages)
                {
                    orm_dimension.DimensionName.UpdateEntry(language.CMN_LanguageID, template.Name);
                }

                orm_dimension.Save(Connection, Transaction);
                #endregion

                #region save dimension values
                foreach (var templateValue in template.DimansionValues)
                {
                    orm_dimensionValue = new ORM_CMN_PRO_Dimension_Value();
                    orm_dimensionValue.Dimensions_RefID    = orm_dimension.CMN_PRO_DimensionID;
                    orm_dimensionValue.DimensionValue_Text = new Dict()
                    {
                        DictionaryID = Guid.NewGuid()
                    };
                    orm_dimensionValue.Tenant_RefID  = tenantID;
                    orm_dimensionValue.OrderSequence = orderSequence;

                    foreach (var language in languages)
                    {
                        orm_dimensionValue.DimensionValue_Text.UpdateEntry(language.CMN_LanguageID, templateValue);
                    }

                    orm_dimensionValue.Save(Connection, Transaction);

                    orderSequence++;
                }
                #endregion
            }
            #endregion

            #region create shipment types
            string shipmentTypesJson           = ReadFromFile.LoadContentFromFile(@"ShipmentTypes.json");
            List <ShipmentTypes> shipmentTypes = JsonConvert.DeserializeObject <List <ShipmentTypes> >(shipmentTypesJson);

            ORM_LOG_SHP_Shipment_Type orm_shipmentType;
            foreach (var type in shipmentTypes)
            {
                #region save LOG_SHP_Shipment_Type
                orm_shipmentType = new ORM_LOG_SHP_Shipment_Type();
                orm_shipmentType.ShipmentType_Name = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                orm_shipmentType.ShipmentType_Description = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                orm_shipmentType.Tenant_RefID = tenantID;

                foreach (var language in languages)
                {
                    orm_shipmentType.ShipmentType_Name.UpdateEntry(language.CMN_LanguageID, type.Name);
                    orm_shipmentType.ShipmentType_Description.UpdateEntry(language.CMN_LanguageID, string.Empty);
                }

                orm_shipmentType.Save(Connection, Transaction);
                #endregion
            }
            #endregion

            #region create number ranges

            string      numberRangesJson = ReadFromFile.LoadContentFromFile(@"NumberRanges.json");
            NumberRange numberRanges     = JsonConvert.DeserializeObject <NumberRange>(numberRangesJson);


            ORM_CMN_NumberRange_UsageArea numberRangeUsageArea;
            ORM_CMN_NumberRange           orm_numberRanges;
            foreach (var item in numberRanges.NumberRanges)
            {
                if (Parameter.IsCustomerRegistration && item.Name == "Customer orders")
                {
                    continue;
                }

                if (!Parameter.IsCustomerRegistration && item.Name == "Distribution orders")
                {
                    continue;
                }

                if (!Parameter.IsCustomerRegistration && item.Name == "Procurement orders")
                {
                    continue;
                }

                numberRangeUsageArea = new ORM_CMN_NumberRange_UsageArea();
                numberRangeUsageArea.UsageArea_Name = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                numberRangeUsageArea.UsageArea_Description = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                foreach (var language in languages)
                {
                    numberRangeUsageArea.UsageArea_Name.UpdateEntry(language.CMN_LanguageID, item.Name);
                    numberRangeUsageArea.UsageArea_Description.UpdateEntry(language.CMN_LanguageID, string.Empty);
                }
                numberRangeUsageArea.Tenant_RefID           = tenantID;
                numberRangeUsageArea.GlobalStaticMatchingID = item.GlobalStaticMatchingID;
                numberRangeUsageArea.Save(Connection, Transaction);

                orm_numberRanges = new ORM_CMN_NumberRange();
                orm_numberRanges.NumberRange_Name            = item.Name;
                orm_numberRanges.Tenant_RefID                = tenantID;
                orm_numberRanges.NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID;
                orm_numberRanges.FixedPrefix = item.FixedPrefix;
                orm_numberRanges.Formatting_LeadingFillCharacter = item.FillCharacter;
                orm_numberRanges.Formatting_NumberLength         = item.Length;
                orm_numberRanges.Value_Current = item.CurrentValue;
                orm_numberRanges.Value_Start   = item.StartValue;
                orm_numberRanges.Value_End     = item.EndValue;
                orm_numberRanges.Save(Connection, Transaction);
            }


            #endregion

            #region create inventory change reasons

            string inventoryChangeReasonsJson = ReadFromFile.LoadContentFromFile(@"InventoryChangeReasons.json");
            List <InventoryChangeReasons> inventoryChangeReasons = JsonConvert.DeserializeObject <List <InventoryChangeReasons> >(inventoryChangeReasonsJson);

            ORM_LOG_WRH_InventoryChangeReason orm_inventoryChangeReason;
            foreach (var reason in inventoryChangeReasons)
            {
                #region save inventory change reason

                orm_inventoryChangeReason = new ORM_LOG_WRH_InventoryChangeReason();
                orm_inventoryChangeReason.GlobalPropertyMatchingID = InventoryChangeReasons.InventoryChangeReasonGlobalPropertyMatchingID + "-" + reason.Name;
                orm_inventoryChangeReason.InventoryChange_Name     = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                orm_inventoryChangeReason.InventoryChange_Description = new Dict()
                {
                    DictionaryID = Guid.NewGuid()
                };
                orm_inventoryChangeReason.Tenant_RefID = tenantID;

                foreach (var language in languages)
                {
                    orm_inventoryChangeReason.InventoryChange_Name.UpdateEntry(language.CMN_LanguageID, reason.Name);
                    orm_inventoryChangeReason.InventoryChange_Description.UpdateEntry(language.CMN_LanguageID, string.Empty);
                }

                orm_inventoryChangeReason.Save(Connection, Transaction);

                #endregion
            }

            #endregion

            #region create shipment statuses
            var shipmentStatuses = Enum.GetValues(typeof(EShipmentStatus));

            var shipmentStatusDicts = EnumUtils.GetDictObjectsForStaticListData <EShipmentStatus>(
                ResourceFilePath.ShipmentStatus, ORM_LOG_SHP_Shipment_Status.TableName, languagesISOs);

            var statusCodeCount = 1;
            ORM_LOG_SHP_Shipment_Status shipmentStatus;
            foreach (EShipmentStatus status in shipmentStatuses)
            {
                shipmentStatus = new ORM_LOG_SHP_Shipment_Status();
                shipmentStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((EShipmentStatus)status);
                shipmentStatus.Status_Code  = statusCodeCount++;
                shipmentStatus.Status_Name  = shipmentStatusDicts[EnumUtils.GetEnumDescription((EShipmentStatus)status)];
                shipmentStatus.Tenant_RefID = tenantID;

                shipmentStatus.Save(Connection, Transaction);
            }
            #endregion

            if (Parameter.IsCustomerRegistration)
            {
                #region create procurement order statuses
                var procurementStatuses = Enum.GetValues(typeof(EProcurementStatus));
                ORM_ORD_PRC_ProcurementOrder_Status procurementOrderStatus;
                foreach (EProcurementStatus status in procurementStatuses)
                {
                    procurementOrderStatus = new ORM_ORD_PRC_ProcurementOrder_Status();
                    procurementOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(status);
                    procurementOrderStatus.Tenant_RefID             = tenantID;

                    procurementOrderStatus.Save(Connection, Transaction);
                }
                #endregion
            }
            else
            {
                #region create customer order statuses
                var customerOrderStatuses = Enum.GetValues(typeof(ECustomerOrderStatus));

                var customerOrderStatusesDicts = EnumUtils.GetDictObjectsForStaticListData <ECustomerOrderStatus>(
                    ResourceFilePath.CustomerOrderStatus, ORM_ORD_CUO_CustomerOrder_Status.TableName, languagesISOs);

                var count = 1;
                ORM_ORD_CUO_CustomerOrder_Status customerOrderStatus;
                foreach (var status in customerOrderStatuses)
                {
                    customerOrderStatus = new ORM_ORD_CUO_CustomerOrder_Status();
                    customerOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((ECustomerOrderStatus)status);
                    customerOrderStatus.Status_Code  = count++;
                    customerOrderStatus.Status_Name  = customerOrderStatusesDicts[EnumUtils.GetEnumDescription((ECustomerOrderStatus)status)];
                    customerOrderStatus.Tenant_RefID = tenantID;

                    customerOrderStatus.Save(Connection, Transaction);
                }
                #endregion
            }

            returnValue.Result = true;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 20
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3DT_SDT_1808 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            #region StatusID's

            var Parameter_StoppedStatus = new P_L2DT_GDTSfGPM_1121();
            Parameter_StoppedStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.Stopped);
            var StoppedStatus_ID = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_StoppedStatus, securityTicket).Result;

            #endregion

            #region Involvement
            ORM_TMS_PRO_DeveloperTask_Involvement DeveloperTask_Involvement = new ORM_TMS_PRO_DeveloperTask_Involvement();
            DeveloperTask_Involvement.Load(Connection, Transaction, Parameter.DeveloperTask_InvolvementID);

            //Update invested time on involvement
            DeveloperTask_Involvement.R_InvestedWorkingTime_min += Parameter.DeveloperTask_InvestedTime;
            DeveloperTask_Involvement.Save(Connection, Transaction);

            #endregion

            #region Developer task
            ORM_TMS_PRO_DeveloperTask DeveloperTask = new ORM_TMS_PRO_DeveloperTask();
            DeveloperTask.Load(Connection, Transaction, Parameter.DeveloperTask_ID);

            DeveloperTask.IsIncompleteInformation              = Parameter.DeveloperTask_IsMissingInfo;
            DeveloperTask.PercentageComplete                   = Parameter.DeveloperTask_PercentageComplete.ToString();
            DeveloperTask.DeveloperTime_CurrentInvestment_min += Parameter.DeveloperTask_InvestedTime;

            DeveloperTask.Save(Connection, Transaction);

            #endregion

            #region Update developer task status history

            ORM_TMS_PRO_DeveloperTask_StatusHistory DeveloperTask_StatusHistory = new ORM_TMS_PRO_DeveloperTask_StatusHistory();

            DeveloperTask_StatusHistory.DeveloperTask_RefID             = Parameter.DeveloperTask_ID;
            DeveloperTask_StatusHistory.DeveloperTask_Status_RefID      = StoppedStatus_ID.TMS_PRO_DeveloperTask_StatusID;
            DeveloperTask_StatusHistory.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvement.ProjectMember_RefID;
            DeveloperTask_StatusHistory.CreatedFor_ProjectMember_RefID  = Guid.Empty;
            DeveloperTask_StatusHistory.Comment  = Parameter.DeveloperTask_StopComment != "" ? "Comment: " + Parameter.DeveloperTask_StopComment + "</br>" : "";
            DeveloperTask_StatusHistory.Comment += "Total invested time:  " + DeveloperTask_Involvement.R_InvestedWorkingTime_min +
                                                   " minutes" + "</br>" +
                                                   "Current invested time:  " + Parameter.DeveloperTask_InvestedTime +
                                                   " minutes" + "</br>" +
                                                   " Percentage complete: " + Parameter.DeveloperTask_PercentageComplete + "%\n";
            DeveloperTask_StatusHistory.Tenant_RefID = securityTicket.TenantID;
            DeveloperTask_StatusHistory.Save(Connection, Transaction);

            if (Parameter.DeveloperTask_IsMissingInfo)
            {
                //TODO: Change active developer task


                var Parameter_MissingInfoStatus = new P_L2DT_GDTSfGPM_1121();
                Parameter_MissingInfoStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.MissingInfo);
                var MissingInfoStatus_ID = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_MissingInfoStatus, securityTicket).Result;


                DeveloperTask_StatusHistory = new ORM_TMS_PRO_DeveloperTask_StatusHistory();
                DeveloperTask_StatusHistory.DeveloperTask_RefID             = Parameter.DeveloperTask_ID;
                DeveloperTask_StatusHistory.DeveloperTask_Status_RefID      = MissingInfoStatus_ID.TMS_PRO_DeveloperTask_StatusID;
                DeveloperTask_StatusHistory.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvement.ProjectMember_RefID;
                DeveloperTask_StatusHistory.CreatedFor_ProjectMember_RefID  = Guid.Empty;
                DeveloperTask_StatusHistory.Comment      = Parameter.DeveloperTask_StopComment;
                DeveloperTask_StatusHistory.Tenant_RefID = securityTicket.TenantID;
                DeveloperTask_StatusHistory.Save(Connection, Transaction);
            }


            #endregion

            #region Load user account

            ORM_USR_Account UserAccount = new ORM_USR_Account();
            UserAccount.Load(Connection, Transaction, securityTicket.AccountID);

            #endregion

            #region Default charging level
            ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel DefaultChargingLevel = null;
            ORM_TMS_PRO_ProjectMember DeveloperTask_GrabbedByMember = new ORM_TMS_PRO_ProjectMember();
            DeveloperTask_GrabbedByMember.Load(Connection, Transaction, DeveloperTask.GrabbedByMember_RefID);
            if (DeveloperTask_GrabbedByMember != null)
            {
                ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query SelectChargingLevel = new ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query();
                SelectChargingLevel.ProjectMember_Type_RefID = DeveloperTask_GrabbedByMember.ProjectMember_Type_RefID;
                SelectChargingLevel.IsDeleted = false;

                List <ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel> AvailableChargingLevels =
                    ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query.Search(Connection, Transaction, SelectChargingLevel);

                if (AvailableChargingLevels.Count > 0)
                {
                    if (AvailableChargingLevels.Exists(acl => acl.IsDefault))
                    {
                        DefaultChargingLevel = AvailableChargingLevels.Where(acl => acl.IsDefault).FirstOrDefault();
                    }
                    else
                    {
                        DefaultChargingLevel = AvailableChargingLevels.FirstOrDefault();
                    }
                }
            }
            #endregion

            #region Invested work times
            ORM_CMN_BPT_InvestedWorkTime InvestedWorkTimes = new ORM_CMN_BPT_InvestedWorkTime();
            InvestedWorkTimes.BusinessParticipant_RefID = UserAccount.BusinessParticipant_RefID;
            InvestedWorkTimes.ChargingLevel_RefID       = DefaultChargingLevel != null ? DefaultChargingLevel.ChargingLevel_RefID : Guid.Empty;
            InvestedWorkTimes.Tenant_RefID        = securityTicket.TenantID;
            InvestedWorkTimes.WorkTime_Amount_min = Parameter.DeveloperTask_InvestedTime;
            InvestedWorkTimes.WorkTime_Comment.AddEntry(Parameter.LanguageID, Parameter.DeveloperTask_StopComment);
            InvestedWorkTimes.WorkTime_Start = DateTime.Now.AddMinutes(-Parameter.DeveloperTask_InvestedTime);
            InvestedWorkTimes.WorkTime_InternalIdentifier = cls_Get_New_InvestedWorkTime_Identifier.Invoke(Connection, Transaction, securityTicket).Result.IWT_Identifier;
            InvestedWorkTimes.WorkTime_Source             = "Danutask - [D" + DeveloperTask.IdentificationNumber + "] " + DeveloperTask.Name;
            InvestedWorkTimes.Tenant_RefID = securityTicket.TenantID;
            InvestedWorkTimes.WorkTime_Comment.AddEntry(Parameter.LanguageID, Parameter.DeveloperTask_StopComment);
            InvestedWorkTimes.Save(Connection, Transaction);
            #endregion



            #region Developer task invested work times
            ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime DeveloperTaskInvolvement_InvestedTime = new ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime();
            DeveloperTaskInvolvement_InvestedTime.CMN_BPT_InvestedWorkTime_RefID          = InvestedWorkTimes.CMN_BPT_InvestedWorkTimeID;
            DeveloperTaskInvolvement_InvestedTime.TMS_PRO_DeveloperTask_Involvement_RefID = DeveloperTask_Involvement.TMS_PRO_DeveloperTask_InvolvementID;
            DeveloperTaskInvolvement_InvestedTime.Tenant_RefID = securityTicket.TenantID;
            DeveloperTaskInvolvement_InvestedTime.Save(Connection, Transaction);
            #endregion


            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 21
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
Exemplo n.º 22
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SE_1657 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


            ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty)
            {
                var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID);
                if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employmentRelationship.Work_StartDate = Parameter.Work_StartDate;

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 23
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3DT_FDT_1646 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            #region Finished Status ID

            var Parameter_StatusFinished = new P_L2DT_GDTSfGPM_1121();
            Parameter_StatusFinished.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.Finished);
            var StatusFinished = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_StatusFinished, securityTicket).Result;

            var Parameter_StatusStarted = new P_L2DT_GDTSfGPM_1121();
            Parameter_StatusStarted.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.Started);
            var StatusStarted = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_StatusStarted, securityTicket).Result;

            #endregion

            #region Developer Task involvement
            ORM_TMS_PRO_DeveloperTask_Involvement DeveloperTask_Involvemnet = new ORM_TMS_PRO_DeveloperTask_Involvement();
            DeveloperTask_Involvemnet.Load(Connection, Transaction, Parameter.DeveloperTask_InvolvementID);

            DeveloperTask_Involvemnet.IsActive   = false;
            DeveloperTask_Involvemnet.IsArchived = true;
            DeveloperTask_Involvemnet.R_InvestedWorkingTime_min += Parameter.DeveloperTask_InvestedTime;

            DeveloperTask_Involvemnet.Save(Connection, Transaction);
            #endregion

            #region Developer Task

            //ORM_TMS_PRO_DeveloperTask_Involvement.Query InvolvementQuery = new ORM_TMS_PRO_DeveloperTask_Involvement.Query();
            //InvolvementQuery.DeveloperTask_RefID = DeveloperTask_Involvemnet.DeveloperTask_RefID;

            //var InvestedTime = ORM_TMS_PRO_DeveloperTask_Involvement.Query.Search(Connection, Transaction, InvolvementQuery).Sum(i => i.R_InvestedWorkingTime_min);

            ORM_TMS_PRO_DeveloperTask DeveloperTask = new ORM_TMS_PRO_DeveloperTask();
            DeveloperTask.Load(Connection, Transaction, DeveloperTask_Involvemnet.DeveloperTask_RefID);
            DeveloperTask.DeveloperTime_CurrentInvestment_min += Parameter.DeveloperTask_InvestedTime;
            DeveloperTask.Completion_Timestamp = DateTime.Now;
            DeveloperTask.PercentageComplete   = "100";
            DeveloperTask.IsComplete           = true;
            DeveloperTask.Save(Connection, Transaction);

            //Retrieve start task timestamp
            ORM_TMS_PRO_DeveloperTask_StatusHistory.Query DeveloperTask_History_Query = new ORM_TMS_PRO_DeveloperTask_StatusHistory.Query();
            DeveloperTask_History_Query.DeveloperTask_Status_RefID      = StatusStarted.TMS_PRO_DeveloperTask_StatusID;
            DeveloperTask_History_Query.DeveloperTask_RefID             = DeveloperTask.TMS_PRO_DeveloperTaskID;
            DeveloperTask_History_Query.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvemnet.ProjectMember_RefID;
            List <ORM_TMS_PRO_DeveloperTask_StatusHistory> statusHistoryResult = ORM_TMS_PRO_DeveloperTask_StatusHistory.Query.Search(Connection, Transaction, DeveloperTask_History_Query);


            //Status History
            ORM_TMS_PRO_DeveloperTask_StatusHistory DeveloperTask_StatusHistory = new ORM_TMS_PRO_DeveloperTask_StatusHistory();
            DeveloperTask_StatusHistory.DeveloperTask_RefID             = DeveloperTask.TMS_PRO_DeveloperTaskID;
            DeveloperTask_StatusHistory.DeveloperTask_Status_RefID      = StatusFinished.TMS_PRO_DeveloperTask_StatusID;
            DeveloperTask_StatusHistory.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvemnet.ProjectMember_RefID;
            DeveloperTask_StatusHistory.Comment = Parameter.DeveloperTask_Comment != ""? "Comment: " + Parameter.DeveloperTask_Comment + "</br>" + "Invested time : "
                                                  + DeveloperTask_Involvemnet.R_InvestedWorkingTime_min + " minutes":
                                                  "Invested time: " + DeveloperTask_Involvemnet.R_InvestedWorkingTime_min + " minutes";
            DeveloperTask_StatusHistory.Tenant_RefID = securityTicket.TenantID;
            DeveloperTask_StatusHistory.Save(Connection, Transaction);

            #endregion

            #region Charging Level
            ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel DefaultChargingLevel = null;
            ORM_TMS_PRO_ProjectMember GrabbedByMember = new ORM_TMS_PRO_ProjectMember();
            GrabbedByMember.Load(Connection, Transaction, DeveloperTask.GrabbedByMember_RefID);

            if (GrabbedByMember != null)
            {
                ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query ChargingLevelQuery = new ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query();
                ChargingLevelQuery.ProjectMember_Type_RefID = GrabbedByMember.ProjectMember_Type_RefID;
                ChargingLevelQuery.IsDeleted = false;

                List <ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel> AvailbaleChargingLevels =
                    ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query.Search(Connection, Transaction, ChargingLevelQuery);

                if (AvailbaleChargingLevels.Exists(acl => acl.IsDefault))
                {
                    DefaultChargingLevel = AvailbaleChargingLevels.Where(acl => acl.IsDefault).FirstOrDefault();
                }
                else if (AvailbaleChargingLevels.Count > 0)
                {
                    DefaultChargingLevel = AvailbaleChargingLevels.FirstOrDefault();
                }
            }

            #endregion

            #region Invested WorkTimes

            //User Account
            ORM_USR_Account UserAccount = new ORM_USR_Account();
            UserAccount.Load(Connection, Transaction, securityTicket.AccountID);


            ORM_CMN_BPT_InvestedWorkTime InvestedWorkTimes = new ORM_CMN_BPT_InvestedWorkTime();
            InvestedWorkTimes.BusinessParticipant_RefID   = UserAccount.BusinessParticipant_RefID;
            InvestedWorkTimes.WorkTime_Start              = statusHistoryResult.OrderBy(c => c.Creation_Timestamp).LastOrDefault().Creation_Timestamp;
            InvestedWorkTimes.WorkTime_Amount_min         = Parameter.DeveloperTask_InvestedTime;
            InvestedWorkTimes.WorkTime_InternalIdentifier = cls_Get_New_InvestedWorkTime_Identifier.Invoke(Connection, Transaction, securityTicket).Result.IWT_Identifier;
            InvestedWorkTimes.WorkTime_Source             = "DanuTask - [D" + DeveloperTask.IdentificationNumber + "] " + DeveloperTask.Name;
            InvestedWorkTimes.WorkTime_Comment.AddEntry(Parameter.LanguageID, Parameter.DeveloperTask_Comment);
            InvestedWorkTimes.ChargingLevel_RefID = DefaultChargingLevel != null ? DefaultChargingLevel.ChargingLevel_RefID : Guid.Empty;
            InvestedWorkTimes.Tenant_RefID        = securityTicket.TenantID;
            InvestedWorkTimes.Save(Connection, Transaction);
            #endregion

            #region Developer Task Involvements Invested time
            ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime DeveloperTaskInvolvements_InvestedTime = new ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime();
            DeveloperTaskInvolvements_InvestedTime.CMN_BPT_InvestedWorkTime_RefID          = InvestedWorkTimes.CMN_BPT_InvestedWorkTimeID;
            DeveloperTaskInvolvements_InvestedTime.TMS_PRO_DeveloperTask_Involvement_RefID = DeveloperTask_Involvemnet.TMS_PRO_DeveloperTask_InvolvementID;
            DeveloperTaskInvolvements_InvestedTime.Tenant_RefID = securityTicket.TenantID;
            DeveloperTaskInvolvements_InvestedTime.Save(Connection, Transaction);
            #endregion

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 24
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID);
                    if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    person.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                            {
                                var error = new FR_Guid();
                                error.ErrorMessage = "No Such ID";
                                error.Status       = FR_Status.Error_Internal;
                                return(error);
                            }
                            contact.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID);
                    if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    asossBParticipant.IsDeleted = true;
                    asossBParticipant.Save(Connection, Transaction);
                }


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 25
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CBH_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_BIL_BillHeader billHeader = null;
            ORM_BIL_BillHeader_2_BillStatus billHeader2BillStatus  = null;
            ORM_CMN_UniversalContactDetail  universalContactDetail = null;

            var BillParam = Parameter.Bill_Parameter.BillHeaderData;

            #region Preloading data

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_BPT_CTM_Customer.Query()
            {
                CMN_BPT_CTM_CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }).SingleOrDefault();

            List <L3ACAAD_GCAfT_1612> customerAddresses = cls_Get_CustomerAddresses_for_CustomerID.Invoke(Connection, Transaction, new P_L3ACAAD_GCAfCID_1612 {
                CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }, securityTicket).Result.ToList();
            L3ACAAD_GCAfT_1612 customerAddress = customerAddresses.Where(x => x.AddressID == BillParam.BillingAddressID).SingleOrDefault();

            var incrNumberParam = new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.BillNumber)
            };
            var billNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber;

            #endregion

            #region Universal Contact Detail

            universalContactDetail = new ORM_CMN_UniversalContactDetail()
            {
                CMN_UniversalContactDetailID = Guid.NewGuid(),
                Country_639_1_ISOCode        = customerAddress.Country_639_1_ISOCode,
                Country_Name      = customerAddress.Country_Name,
                Street_Name       = customerAddress.Street_Name,
                Street_Number     = customerAddress.Street_Number,
                Town              = customerAddress.Town,
                ZIP               = customerAddress.ZIP,
                Tenant_RefID      = account.Tenant_RefID,
                CompanyName_Line1 = BillParam.BillingReceiverCustomer.DisplayName,
                First_Name        = BillParam.BillingReceiverCustomer.FirstName,
                Last_Name         = BillParam.BillingReceiverCustomer.LastName,
                IsCompany         = BillParam.BillingReceiverCustomer.IsCompany
            };
            universalContactDetail.Save(Connection, Transaction);
            #endregion

            #region Bill Header

            billHeader = new ORM_BIL_BillHeader
            {
                BIL_BillHeaderID = Guid.NewGuid(),
                BillNumber       = billNumber,
                CreatedBy_BusinessParticipant_RefID     = account.BusinessParticipant_RefID,
                BillRecipient_BuisnessParticipant_RefID = customer.Ext_BusinessParticipant_RefID,
                TotalValue_BeforeTax     = 0,
                TotalValue_IncludingTax  = 0,
                BillingAddress_UCD_RefID = universalContactDetail.CMN_UniversalContactDetailID,
                DateOnBill     = BillParam.BillingDate,
                BillComment    = BillParam.Comment,
                Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID,
                BillHeader_PaymentCondition_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTargetID,
                Tenant_RefID = securityTicket.TenantID
            };

            billHeader.Save(Connection, Transaction);

            #endregion

            #region Method of Payment

            var methodOfPayment = new CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment
            {
                BIL_BillHeader_MethodOfPaymentID = Guid.NewGuid(),
                ACC_PAY_Type_RefID         = Parameter.Bill_Parameter.BillHeaderData.PaymentTypeID,
                BIL_BillHeader_RefID       = billHeader.BIL_BillHeaderID,
                IsPreferredMethodOfPayment = true,
                SequenceNumber             = 0,
                Tenant_RefID = securityTicket.TenantID
            };
            methodOfPayment.Save(Connection, Transaction);

            #endregion

            #region Bill Status - Created

            var statusCreated = ORM_BIL_BillStatus.Query.Search(Connection, Transaction,
                                                                new ORM_BIL_BillStatus.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EBillStatus.Created),
                Tenant_RefID             = account.Tenant_RefID,
                IsDeleted = false
            }).Single();

            billHeader2BillStatus = new ORM_BIL_BillHeader_2_BillStatus
            {
                AssignmentID         = Guid.NewGuid(),
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID,
                BIL_BillStatus_RefID = statusCreated.BIL_BillStatusID,
                Tenant_RefID         = account.Tenant_RefID,
                IsCurrentStatus      = true
            };
            billHeader2BillStatus.Save(Connection, Transaction);

            #endregion

            returnValue.Result = billHeader.BIL_BillHeaderID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 26
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SCER_0931 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests();
            request.Load(Connection, Transaction, Parameter.RequestID);

            if (Parameter.SendAnswer)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                request.IfAnswerSent_Date = DateTime.Now;
            }
            request.IsAnswerSent   = Parameter.SendAnswer;
            request.Request_Answer = Parameter.RequestAnswer;
            request.Save(Connection, Transaction);

            #region Add products
            ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null;

            if (Parameter.Products != null)
            {
                foreach (P_L5CA_SCER_0931a item in Parameter.Products)
                {
                    ORM_CMN_PRO_Product.Query prodQuery = new ORM_CMN_PRO_Product.Query()
                    {
                        CMN_PRO_ProductID = item.ProductID,
                        IsDeleted         = false,
                        Tenant_RefID      = securityTicket.TenantID
                    };
                    var prod = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, prodQuery).Single();
                    if (String.IsNullOrEmpty(prod.ProductITL))
                    {
                        prod.ProductITL = prod.CMN_PRO_ProductID.ToString();
                        prod.Save(Connection, Transaction);
                    }

                    if (item.IsDeleted)
                    {
                        ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query query = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query();
                        query.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                        query.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = item.Request_ProductID;
                        //query.Tenant_RefID = securityTicket.TenantID;
                        //ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.SoftDelete(Connection, Transaction, query);
                        var itemToDelete = ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.Search(Connection, Transaction, query).SingleOrDefault();
                        if (itemToDelete != default(ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product))
                        {
                            itemToDelete.IsDeleted = true;
                            itemToDelete.Save(Connection, Transaction);
                        }
                        continue;
                    }

                    product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product();
                    product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid();
                    product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                    product.CMN_PRO_Product_RefID = prod.CMN_PRO_ProductID;
                    product.Creation_Timestamp    = DateTime.Now;
                    product.Tenant_RefID          = securityTicket.TenantID;
                    product.Comment = "";
                    product.Save(Connection, Transaction);
                }
            }
            #endregion

            #region Save products in Catalog Products for Catalog Revision

            if (Parameter.Products != null)
            {
                // Find catalog revision
                var catalogRevision = ORM_CMN_PRO_Catalog_Revision.Query.Search(Connection, Transaction,
                                                                                new ORM_CMN_PRO_Catalog_Revision.Query
                {
                    PublishedBy_BusinessParticipant_RefID = Guid.Empty,
                    CMN_PRO_Catalog_RefID = request.RequestedFor_Catalog_RefID,
                    Tenant_RefID          = securityTicket.TenantID,
                    IsDeleted             = false
                }).OrderByDescending(x => x.PublishedOn_Date).FirstOrDefault();

                if (catalogRevision != null)
                {
                    foreach (P_L5CA_SCER_0931a item in Parameter.Products)
                    {
                        // Find product
                        var p = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_PRO_Product.Query()
                        {
                            CMN_PRO_ProductID = item.ProductID,
                            IsDeleted         = false,
                            Tenant_RefID      = securityTicket.TenantID
                        }).Single();

                        // Find catalog product for product
                        var catalogProduct = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction,
                                                                                      new ORM_CMN_PRO_Catalog_Product.Query
                        {
                            CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID,
                            CMN_PRO_Product_RefID          = p.CMN_PRO_ProductID,
                            Tenant_RefID = p.Tenant_RefID,
                            IsDeleted    = false
                        }).SingleOrDefault();


                        // If product not exist then add product to catalog products
                        if (catalogProduct == null)
                        {
                            // Find product variant for product
                            ORM_CMN_PRO_Product_Variant productVariant = null;
                            if (p.HasProductVariants)
                            {
                                productVariant = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction,
                                                                                          new ORM_CMN_PRO_Product_Variant.Query
                                {
                                    CMN_PRO_Product_RefID    = p.CMN_PRO_ProductID,
                                    Tenant_RefID             = p.Tenant_RefID,
                                    IsStandardProductVariant = true,
                                    IsDeleted = false
                                }).OrderByDescending(x => x.Creation_Timestamp).FirstOrDefault();
                            }

                            // Create catalog product for product
                            catalogProduct = new ORM_CMN_PRO_Catalog_Product();
                            catalogProduct.CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID;
                            catalogProduct.CMN_PRO_Product_RefID          = p.CMN_PRO_ProductID;
                            catalogProduct.CMN_PRO_Product_Variant_RefID  = p.HasProductVariants ? productVariant.CMN_PRO_Product_VariantID : Guid.Empty;
                            catalogProduct.Tenant_RefID = securityTicket.TenantID;
                            catalogProduct.Save(Connection, Transaction);
                        }
                        else
                        {
                            if (item.IsDeleted)
                            {
                                catalogProduct.IsDeleted = true;
                                catalogProduct.Save(Connection, Transaction);
                            }
                        }
                    }
                }
            }

            #endregion

            returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;

            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 27
0
        protected static FR_L5CA_PNCV_1520 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_PNCV_1520 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5CA_PNCV_1520();
            returnValue.Result = new L5CA_PNCV_1520();

            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #region Update active catalog revision

            ORM_CMN_PRO_Catalog_Revision rev = new ORM_CMN_PRO_Catalog_Revision();
            rev.Load(Connection, Transaction, Parameter.CMN_PRO_Catalog_RevisionID);
            rev.Valid_From    = Parameter.Valid_From;
            rev.Valid_Through = Parameter.Valid_Through;
            rev.Default_PricelistRelease_RefID        = Parameter.Default_PricelistRelease_RefID;
            rev.PublishedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            rev.PublishedOn_Date = DateTime.Now;

            rev.Save(Connection, Transaction);

            #endregion

            #region Update catalog public/private status
            if (rev.RevisionNumber == 1)
            {
                ORM_CMN_PRO_Catalog catalog = new ORM_CMN_PRO_Catalog();
                catalog.Load(Connection, Transaction, rev.CMN_PRO_Catalog_RefID);

                catalog.IsPublicCatalog = Parameter.IsPublic;

                catalog.Save(Connection, Transaction);
            }
            #endregion

            #region Create new catalog revision

            ORM_CMN_PRO_Catalog_Revision newRev = new ORM_CMN_PRO_Catalog_Revision();
            newRev.CMN_PRO_Catalog_RevisionID = Guid.NewGuid();
            newRev.CMN_PRO_Catalog_RefID      = rev.CMN_PRO_Catalog_RefID;
            newRev.Tenant_RefID                = securityTicket.TenantID;
            newRev.Creation_Timestamp          = DateTime.Now;
            newRev.CatalogRevision_Description = "Revision for Catalog";
            newRev.CatalogRevision_Name        = "New Catalog Revision";
            newRev.IsDeleted      = false;
            newRev.RevisionNumber = rev.RevisionNumber + 1;
            newRev.Save(Connection, Transaction);

            #endregion

            #region Products

            var oldProducts = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query()
            {
                CMN_PRO_Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });

            if (oldProducts.Count == 0)
            {
                returnValue.Result.Status_Code    = -1;     // -1 no products in revision
                returnValue.Result.Status_Message = "no products in revision";
                return(returnValue);
            }

            //oldProductID - newProductID
            Dictionary <Guid, Guid> productsMapping = new Dictionary <Guid, Guid>();

            var productsWithoutPrices = ProductWithoutPrices(Connection, Transaction, Parameter, securityTicket, oldProducts);
            if (productsWithoutPrices.Count > 0)
            {
                returnValue.Result.Status_Code    = -2;                         // -2 => pricelist does not have price for product
                returnValue.Result.Status_Message = JsonConvert.SerializeObject(productsWithoutPrices);
                return(returnValue);
            }

            foreach (var item in oldProducts)
            {
                var newProduct = new ORM_CMN_PRO_Catalog_Product()
                {
                    CMN_PRO_Catalog_ProductID     = Guid.NewGuid(),
                    CMN_PRO_Product_Variant_RefID = item.CMN_PRO_Product_Variant_RefID,
                    Creation_Timestamp            = DateTime.Now,
                    Tenant_RefID = item.Tenant_RefID,
                    CMN_PRO_Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID,
                    CMN_PRO_Product_RefID          = item.CMN_PRO_Product_RefID,
                };

                newProduct.Save(Connection, Transaction);

                productsMapping.Add(item.CMN_PRO_Catalog_ProductID, newProduct.CMN_PRO_Catalog_ProductID);
            }

            #endregion

            #region ProductGroups

            var oldGroups = ORM_CMN_PRO_Catalog_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_ProductGroup.Query()
            {
                Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            //oldGroupID - newGroupID
            Dictionary <Guid, Guid> groupsMapping = new Dictionary <Guid, Guid>();
            groupsMapping.Add(Guid.Empty, Guid.Empty);

            foreach (var item in oldGroups)
            {
                groupsMapping.Add(item.CMN_PRO_Catalog_ProductGroupID, Guid.NewGuid());
            }

            foreach (var item in oldGroups)
            {
                var newGroup = new ORM_CMN_PRO_Catalog_ProductGroup()
                {
                    CMN_PRO_Catalog_ProductGroupID   = groupsMapping[item.CMN_PRO_Catalog_ProductGroupID],
                    Catalog_Revision_RefID           = newRev.CMN_PRO_Catalog_RevisionID,
                    CatalogProductGroup_Name         = item.CatalogProductGroup_Name,
                    CatalogProductGroup_Parent_RefID = groupsMapping[item.CatalogProductGroup_Parent_RefID],
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = item.Tenant_RefID
                };

                newGroup.Save(Connection, Transaction);

                var oldProductsInGroup = ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query()
                {
                    CMN_PRO_Catalog_ProductGroup_RefID = item.CMN_PRO_Catalog_ProductGroupID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                foreach (var product in oldProductsInGroup)
                {
                    if (groupsMapping.ContainsKey(product.CMN_PRO_Catalog_ProductGroup_RefID) && productsMapping.ContainsKey(product.CMN_PRO_Catalog_Product_RefID))
                    {
                        var newProduct = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup()
                        {
                            AssignmentID = Guid.NewGuid(),
                            CMN_PRO_Catalog_ProductGroup_RefID = groupsMapping[product.CMN_PRO_Catalog_ProductGroup_RefID],
                            CMN_PRO_Catalog_Product_RefID      = productsMapping[product.CMN_PRO_Catalog_Product_RefID],
                            Creation_Timestamp = DateTime.Now,
                            Tenant_RefID       = item.Tenant_RefID
                        };

                        newProduct.Save(Connection, Transaction);
                    }
                }
            }


            #endregion

            returnValue.Result.Status_Code    = 1;
            returnValue.Result.Status_Message = "Success";
            returnValue.Result.ID             = newRev.CMN_PRO_Catalog_RevisionID;
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 28
0
        protected static FR_L5EM_GEFU_445 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var           returnValue = new FR_L5EM_GEFU_445();
            L5EM_GEFU_445 result      = new L5EM_GEFU_445();


            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            if (account.USR_AccountID == Guid.Empty)
            {
                return(null);
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            employeeQuery.BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);
            if (employeeList.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee employee = employeeList[0];
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;


                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFU_445_EmployeeWorkplaceHistory>       employeeWorkplaceAssignments     = new List <L5EM_GEFU_445_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFU_445_EmployeeWorkplaceHistory item = new L5EM_GEFU_445_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Exemplo n.º 29
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SFE_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();



            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name     = Parameter.City_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Tenant_RefID  = Parameter.TenantID;
            address.Save(Connection, Transaction);

            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = Parameter.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.BirthDate     = Parameter.BirthDate;
            person.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = Parameter.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();


            CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = Parameter.TenantID;

            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved);

            ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty)
            {
                var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID);
                if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employeeRelationship.Work_StartDate = Parameter.Work_StartDate;
            employeeRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employeeRelationship.Tenant_RefID   = Parameter.TenantID;
            employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employeeRelationship.Save(Connection, Transaction);



            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, Parameter.USR_AccountID);
                account.USR_AccountID             = Parameter.USR_AccountID;
                account.Username                  = Parameter.username;
                account.DefaultLanguage_RefID     = Parameter.LanguageID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID              = Parameter.TenantID;
                account.Save(Connection, Transaction);

                var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                personToAccountQuery.IsDeleted         = false;
                var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                if (personToAccounts.Count != 0)
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }

                if (Parameter.Rights != null)
                {
                    foreach (var rightParam in Parameter.Rights)
                    {
                        var right = new ORM_USR_Account_FunctionLevelRight();
                        if (rightParam.RightID != Guid.Empty)
                        {
                            var result = right.Load(Connection, Transaction, rightParam.RightID);
                            if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty)
                            {
                                right.USR_Account_FunctionLevelRightID = rightParam.RightID;
                                right.Tenant_RefID = Parameter.TenantID;
                                right.RightName    = rightParam.RightName;
                                right.FunctionLevelRights_Group_RefID = Guid.Empty;
                                right.Save(Connection, Transaction);
                            }
                        }

                        var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                        right2account.Account_RefID            = account.USR_AccountID;
                        right2account.FunctionLevelRight_RefID = rightParam.RightID;
                        right2account.Tenant_RefID             = Parameter.TenantID;
                        right2account.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L6CN_SCNwSRaQCI_0739 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();

            #region Get Preloading Data

            #region Get StandardPrices for Products
            var priceParam = new P_L3PR_GSPfPIL_1645
            {
                ProductIDList = Parameter.Positions.Select(p => p.ProductId).ToArray()
            };
            var prices = cls_Get_StandardPrices_for_ProductIDList.Invoke(Connection, Transaction, priceParam, securityTicket).Result;
            #endregion
            #endregion

            #region Create Receipt Header
            var resultReceiptHeader = cls_Save_StockReceiptHeader.Invoke(
                Connection,
                Transaction,
                new P_L5SR_SRH_1545()
            {
                ReceiptHeaderID = Guid.Empty,
                SupplierID      = Parameter.SupplierID
            },
                securityTicket);
            if (resultReceiptHeader.Result == Guid.Empty)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = false;
                return(returnValue);
            }
            #endregion

            #region Create Receipt positions for Receipt header
            var receiptPositions = new List <P_L5RS_CNfRS_1119a>();
            foreach (var position in Parameter.Positions)
            {
                #region Get Preloading Data
                #region Get Performed By Account
                var performedByBusinessParticipant = new ORM_USR_Account();
                performedByBusinessParticipant.Load(Connection, Transaction, securityTicket.AccountID);
                if (performedByBusinessParticipant.BusinessParticipant_RefID == Guid.Empty)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                #endregion
                #endregion

                #region Create new Receipt Position object
                var receiptPosition = new ORM_LOG_RCP_Receipt_Position();
                receiptPosition.LOG_RCP_Receipt_PositionID = Guid.NewGuid();
                receiptPosition.Creation_Timestamp         = DateTime.Now;
                receiptPosition.Tenant_RefID                  = securityTicket.TenantID;
                receiptPosition.ReceiptPositionITL            = receiptPosition.LOG_RCP_Receipt_PositionID.ToString();
                receiptPosition.Receipt_Header_RefID          = resultReceiptHeader.Result;
                receiptPosition.ReceiptPosition_Product_RefID = position.ProductId;
                receiptPosition.TotalQuantityFreeOfCharge     = 0.0;
                receiptPosition.TotalQuantityTakenIntoStock   = position.Quantity;
                receiptPosition.ExpectedPositionPrice         = Convert.ToDecimal(position.Quantity) * position.ValuePerUnit;
                receiptPosition.ExpectedPositionPrice         = prices.Where(i => i.ProductID == position.ProductId).Select(j => j.AbdaPrice).SingleOrDefault();
                #endregion

                #region Create new QualityControlItem object
                var qualityControlItem = new ORM_LOG_RCP_Receipt_Position_QualityControlItem();
                qualityControlItem.LOG_RCP_Receipt_Position_QualityControlItem = Guid.NewGuid();
                qualityControlItem.Tenant_RefID           = securityTicket.TenantID;
                qualityControlItem.Creation_Timestamp     = DateTime.Now;
                qualityControlItem.Receipt_Position_RefID = receiptPosition.LOG_RCP_Receipt_PositionID;
                qualityControlItem.Quantity               = position.Quantity;
                qualityControlItem.BatchNumber            = position.BatchNumber;
                qualityControlItem.ExpiryDate             = position.ExpiryDate;
                qualityControlItem.Target_WRH_Shelf_RefID = position.ShelfId;
                qualityControlItem.QualityControl_PerformedByBusinessParticipant_RefID = performedByBusinessParticipant.BusinessParticipant_RefID;
                qualityControlItem.ReceiptPositionCountedItemITL  = string.Empty;
                qualityControlItem.QualityControl_PerformedAtDate = DateTime.Now;
                #endregion

                #region Save objects
                var resultReceiptPosition = receiptPosition.Save(Connection, Transaction);
                if (resultReceiptPosition.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                var resultQualityControlItem = qualityControlItem.Save(Connection, Transaction);
                if (resultQualityControlItem.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = false;
                    return(returnValue);
                }
                #endregion

                receiptPositions.Add(new P_L5RS_CNfRS_1119a()
                {
                    receiptPositionId = receiptPosition.LOG_RCP_Receipt_PositionID,
                    compesationValue  = qualityControlItem.Quantity * Convert.ToDouble(position.ValuePerUnit)
                });
            }
            #endregion

            #region Place articles on stock
            CL3_Warehouse.Complex.Manipulation.cls_StockReceipt_IntakeConfirmation.Invoke(
                Connection,
                Transaction,
                new P_L3WH_SRIC_1421()
            {
                ReceiptHeaderID    = resultReceiptHeader.Result,
                WithoutProcurement = true
            },
                securityTicket);
            #endregion

            #region Create CreditNote
            var resultCreditNote = cls_Save_CreditNote_for_ReturnShipment.Invoke(
                Connection,
                Transaction,
                new P_L5RS_CNfRS_1119()
            {
                headerId                = Parameter.CreditNoteHeaderID,
                headerValue             = Convert.ToDecimal(receiptPositions.Sum(rp => rp.compesationValue)),
                receiptPositions        = receiptPositions.ToArray(),
                returnShipmentPositions = null
            },
                securityTicket);
            if (resultCreditNote.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = false;
                return(returnValue);
            }
            #endregion

            returnValue.Result = true;
            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }