Exemple #1
0
        public virtual int?GetDefaultLaborItem(int?employeeID, string earningType, int?projectID)
        {
            if (employeeID == null)
            {
                return(null);
            }

            int?result = null;

            if (ProjectDefaultAttribute.IsProject(this, projectID))
            {
                result = EPContractRate.GetProjectLaborClassID(this, projectID.Value, employeeID.Value, earningType);
            }

            if (result == null)
            {
                result = EPEmployeeClassLaborMatrix.GetLaborClassID(this, employeeID, earningType);
            }

            if (result == null)
            {
                EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Current <EPTimeCard.employeeID> > > > .Select(this);

                if (employee != null)
                {
                    result = employee.LabourItemID;
                }
            }

            return(result);
        }
Exemple #2
0
        public virtual int?GetLaborClass(PMTimeActivity activity, EPEmployee employee, CRCase refCase)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee", Messages.EmptyEmployeeID);
            }

            int?laborClassID = null;

            if (refCase != null)
            {
                CRCaseClass caseClass = (CRCaseClass)PXSelectorAttribute.Select <CRCase.caseClassID>(graph.Caches[typeof(CRCase)], refCase);
                if (caseClass.PerItemBilling == BillingTypeListAttribute.PerActivity)
                {
                    laborClassID = CRCaseClassLaborMatrix.GetLaborClassID(graph, caseClass.CaseClassID, activity.EarningTypeID);
                }
            }

            if (laborClassID == null && activity.ProjectID != null && employee.BAccountID != null)
            {
                laborClassID = EPContractRate.GetProjectLaborClassID(graph, (int)activity.ProjectID, (int)employee.BAccountID, activity.EarningTypeID);
            }

            if (laborClassID == null)
            {
                laborClassID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, activity.EarningTypeID);
            }

            if (laborClassID == null)
            {
                laborClassID = employee.LabourItemID;
            }

            return(laborClassID);
        }
        protected void EPEarningType_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            EPEarningType row = (EPEarningType)e.Row;

            if (row == null)
            {
                return;
            }

            EPSetup setup = PXSelect <
                EPSetup
                , Where <EPSetup.regularHoursType, Equal <Required <EPEarningType.typeCD> >
                         , Or <EPSetup.holidaysType, Equal <Required <EPEarningType.typeCD> >
                               , Or <EPSetup.vacationsType, Equal <Required <EPEarningType.typeCD> > >
                               >
                         >
                > .Select(this, row.TypeCD, row.TypeCD, row.TypeCD);

            if (setup != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            CRCaseClassLaborMatrix caseClassLabor = PXSelect <CRCaseClassLaborMatrix, Where <CRCaseClassLaborMatrix.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (caseClassLabor != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            EPContractRate contractRate = PXSelect <EPContractRate, Where <EPContractRate.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (contractRate != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            EPEmployeeClassLaborMatrix employeeLabor = PXSelect <EPEmployeeClassLaborMatrix, Where <EPEmployeeClassLaborMatrix.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (employeeLabor != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            PMTimeActivity activity = PXSelect <PMTimeActivity, Where <PMTimeActivity.earningTypeID, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (activity != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            PMTran pmTran = PXSelect <PMTran, Where <PMTran.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (pmTran != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }
        }
Exemple #4
0
        public static int?GetLaborClassID(PXGraph graph, int?employeeID, string earningTypeID)
        {
            EPEmployeeClassLaborMatrix matrix =
                PXSelect <EPEmployeeClassLaborMatrix
                          , Where <
                              EPEmployeeClassLaborMatrix.employeeID, Equal <Required <EPEmployeeClassLaborMatrix.employeeID> >
                              , And <EPEmployeeClassLaborMatrix.earningType, Equal <Required <EPEmployeeClassLaborMatrix.earningType> > >
                              >
                          > .Select(graph, new object[] { employeeID, earningTypeID });

            return(matrix != null ? matrix.LabourItemID : null);
        }
        public virtual int?GetLaborClass(CR.EPActivity activity)
        {
            int?laborClassID = null;

            CR.CRCase refCase = PXSelect <CR.CRCase, Where <CR.CRCase.noteID, Equal <Required <CR.EPActivity.refNoteID> > > > .Select(graph, activity.RefNoteID);

            if (refCase != null)
            {
                CR.CRCaseClass caseClass = (CR.CRCaseClass)PXSelectorAttribute.Select <CR.CRCase.caseClassID>(graph.Caches[typeof(CR.CRCase)], refCase);
                laborClassID = CR.CRCaseClassLaborMatrix.GetLaborClassID(graph, caseClass.CaseClassID, activity.EarningTypeID);
            }

            EPEmployee employee = PXSelect <EPEmployee> .Search <EPEmployee.userID>(graph, activity.Owner);

            if (employee == null)
            {
                throw new Exception(Messages.EmptyEmployeeID);
            }

            if (laborClassID == null && activity.ProjectID != null && employee.BAccountID != null)
            {
                laborClassID = EPContractRate.GetProjectLaborClassID(graph, (int)activity.ProjectID, (int)employee.BAccountID, activity.EarningTypeID);
            }

            if (laborClassID == null)
            {
                laborClassID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, activity.EarningTypeID);
            }

            if (laborClassID == null)
            {
                laborClassID = employee.LabourItemID;
            }

            return(laborClassID);
        }
Exemple #6
0
        ///NO CRM Mode
        public static PMTran CreateContractUsage(RegisterEntry graph, int?contractID, PMTimeActivity timeActivity, int billableMinutes)
        {
            if (timeActivity.ApprovalStatus == ActivityStatusListAttribute.Canceled)
            {
                return(null);
            }

            if (timeActivity.IsBillable != true)
            {
                return(null);
            }

            Contract contract = PXSelect <Contract,
                                          Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(graph, contractID);

            if (contract == null)
            {
                return(null);               //activity has no contract and will be billed through Project using the cost-transaction. Contract-Usage is not created in this case.
            }
            int?laborItemID = GetContractLaborClassID(graph, contractID, timeActivity);;

            if (laborItemID == null)
            {
                EPEmployee employeeSettings = PXSelect <EPEmployee,
                                                        Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, timeActivity.OwnerID);

                if (employeeSettings != null)
                {
                    laborItemID =
                        EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employeeSettings.BAccountID, timeActivity.EarningTypeID) ??
                        employeeSettings.LabourItemID;
                }
            }

            InventoryItem laborItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(graph, laborItemID);

            if (laborItem == null)
            {
                throw new PXException(PX.Objects.CR.Messages.LaborNotConfigured);
            }

            //save the sign of the value and do the rounding against absolute value.
            //reuse sign later when setting value to resulting transaction.
            int sign = billableMinutes < 0 ? -1 : 1;

            billableMinutes = Math.Abs(billableMinutes);


            if (billableMinutes > 0)
            {
                PMTran newLabourTran = new PMTran();
                newLabourTran.ProjectID      = contractID;
                newLabourTran.InventoryID    = laborItem.InventoryID;
                newLabourTran.AccountGroupID = contract.ContractAccountGroup;
                newLabourTran.OrigRefID      = timeActivity.NoteID;
                newLabourTran.BAccountID     = contract.CustomerID;
                newLabourTran.LocationID     = contract.LocationID;
                newLabourTran.Description    = timeActivity.Summary;
                newLabourTran.StartDate      = timeActivity.Date;
                newLabourTran.EndDate        = timeActivity.Date;
                newLabourTran.Date           = timeActivity.Date;
                newLabourTran.UOM            = laborItem.SalesUnit;
                newLabourTran.Qty            = sign * Convert.ToDecimal(TimeSpan.FromMinutes(billableMinutes).TotalHours);
                newLabourTran.BillableQty    = newLabourTran.Qty;
                newLabourTran.Released       = true;
                newLabourTran.Allocated      = true;
                newLabourTran.IsQtyOnly      = true;
                newLabourTran.BillingID      = contract.BillingID;
                return(graph.Transactions.Insert(newLabourTran));
            }
            else
            {
                return(null);
            }
        }