Beispiel #1
0
 protected virtual void CreateNew()
 {
     using (new PXPreserveScope())
     {
         ExpenseClaimEntry graph = (ExpenseClaimEntry)PXGraph.CreateInstance(typeof(ExpenseClaimEntry));
         graph.Clear(PXClearOption.ClearAll);
         EPExpenseClaim claim = (EPExpenseClaim)graph.ExpenseClaim.Cache.CreateInstance();
         graph.ExpenseClaim.Insert(claim);
         graph.ExpenseClaim.Cache.IsDirty = false;
         PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.InlineWindow);
     }
 }
Beispiel #2
0
 protected void Submit()
 {
     if (Claim.Current != null)
     {
         ExpenseClaimEntry graph = (ExpenseClaimEntry)PXGraph.CreateInstance(typeof(ExpenseClaimEntry));
         graph.Clear(PXClearOption.ClearAll);
         graph.ExpenseClaim.Current = graph.ExpenseClaim.Search <EPExpenseClaim.refNbr>(Claim.Current.RefNbr);
         var a = new PXAdapter(graph.ExpenseClaim);
         a.SortColumns = new string[] { typeof(EPExpenseClaim.refNbr).Name };
         a.Searches    = new object[] { Claim.Current.RefNbr };
         a.Menu        = Messages.Submit;
         a.MaximumRows = 1;
         foreach (var r in graph.action.Press(a))
         {
         }
     }
 }
        protected void Delete()
        {
            if (Claim.Current == null)
            {
                return;
            }

            if (Claim.Current.Released == true)
            {
                throw new PXException(Messages.ReleasedDocumentMayNotBeDeleted);
            }

            using (new PXPreserveScope())
            {
                ExpenseClaimEntry graph = (ExpenseClaimEntry)PXGraph.CreateInstance(typeof(ExpenseClaimEntry));
                graph.Clear(PXClearOption.ClearAll);
                graph.ExpenseClaim.Current = Claim.Current;
                graph.Delete.Press();
            }
        }
Beispiel #4
0
        private static void ClaimDetail(List <EPExpenseClaimDetails> details, bool isApiContext, bool singleOperation)
        {
            ExpenseClaimEntry expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
            PXSetup <EPSetup> epsetup           = new PXSetup <EPSetup>(PXGraph.CreateInstance(typeof(ExpenseClaimDetailEntry)));
            bool enabledApprovalReceipt         = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null;
            bool isError        = false;
            bool notAllApproved = false;
            Dictionary <string, EPExpenseClaim> result = new Dictionary <string, EPExpenseClaim>();

            IEnumerable <Receipts> List;

            if (epsetup.Current.AllowMixedTaxSettingInClaims == true)
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                    ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item)
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    claimCuryID      = key.ClaimCuryID,
                    details          = item
                }
                    );
            }
            else
            {
                List = details.Where(item => string.IsNullOrEmpty(item.RefNbr)).OrderBy(detail => detail.ClaimDetailID).GroupBy(
                    item => new
                {
                    item.EmployeeID,
                    item.BranchID,
                    item.CustomerID,
                    item.CustomerLocationID,
                    item.TaxZoneID,
                    item.TaxCalcMode,
                    ClaimCuryID = GetClaimCuryID(expenseClaimEntry, item)
                },
                    (key, item) => new Receipts
                {
                    employee         = key.EmployeeID,
                    branch           = key.BranchID,
                    customer         = key.CustomerID,
                    customerLocation = key.CustomerLocationID,
                    claimCuryID      = key.ClaimCuryID,
                    details          = item
                }
                    );
            }

            string errorMessage = null;

            foreach (Receipts item in List)
            {
                isError        = false;
                notAllApproved = false;
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    expenseClaimEntry.Clear();
                    expenseClaimEntry.SelectTimeStamp();
                    EPExpenseClaim expenseClaim = (EPExpenseClaim)expenseClaimEntry.ExpenseClaim.Cache.CreateInstance();
                    expenseClaim.EmployeeID         = item.employee;
                    expenseClaim.BranchID           = item.branch;
                    expenseClaim.CustomerID         = item.customer;
                    expenseClaim.DocDesc            = EP.Messages.SubmittedReceipt;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CuryID             = item.claimCuryID;
                    expenseClaim                    = expenseClaimEntry.ExpenseClaim.Update(expenseClaim);
                    expenseClaim.CustomerLocationID = item.customerLocation;
                    expenseClaim.TaxCalcMode        = item.details.First().TaxCalcMode;
                    expenseClaim.TaxZoneID          = item.details.First().TaxZoneID;

                    foreach (EPExpenseClaimDetails detail in item.details)
                    {
                        PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(detail);

                        if (detail.Approved ?? false)
                        {
                            try
                            {
                                if (detail.IsPaidWithCard)
                                {
                                    EPEmployee employee =
                                        PXSelect <EPEmployee,
                                                  Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > >
                                        .Select(expenseClaimEntry, item.employee);

                                    if (employee.AllowOverrideCury != true && detail.CardCuryID != employee.CuryID)
                                    {
                                        errorMessage = PXMessages.Localize(Messages.ClaimCannotBeCreatedForReceiptBecauseCuryCannotBeOverriden);

                                        isError = true;
                                    }
                                }

                                if (!isError && detail.TipAmt != 0 && epsetup.Current.NonTaxableTipItem == null)
                                {
                                    errorMessage = Messages.TipItemIsNotDefined;
                                    isError      = true;
                                }

                                if (!isError)
                                {
                                    expenseClaimEntry.ReceiptEntryExt.SubmitReceiptExt(expenseClaimEntry.ExpenseClaim.Cache,
                                                                                       expenseClaimEntry.ExpenseClaimDetails.Cache, expenseClaimEntry.ExpenseClaim.Current, detail);

                                    expenseClaimEntry.Save.Press();
                                    if (!result.ContainsKey(expenseClaim.RefNbr))
                                    {
                                        result.Add(expenseClaim.RefNbr, expenseClaim);
                                    }
                                    detail.RefNbr = expenseClaim.RefNbr;

                                    PXProcessing <EPExpenseClaimDetails> .SetProcessed();
                                }
                            }
                            catch (Exception ex)
                            {
                                errorMessage = ex.Message;
                                isError      = true;
                            }
                        }
                        else
                        {
                            errorMessage = enabledApprovalReceipt
                                                                ? Messages.ReceiptNotApproved
                                                                : Messages.ReceiptTakenOffHold;

                            notAllApproved = true;
                        }

                        if (errorMessage != null)
                        {
                            PXProcessing <EPExpenseClaimDetails> .SetError(errorMessage);
                        }
                    }
                    if (!isError)
                    {
                        ts.Complete();
                    }
                }
            }

            if (!isError && !notAllApproved)
            {
                if (result.Count == 1 && isApiContext == false)
                {
                    expenseClaimEntry = CreateInstance <ExpenseClaimEntry>();
                    PXRedirectHelper.TryRedirect(expenseClaimEntry, result.First().Value, PXRedirectHelper.WindowMode.InlineWindow);
                }
            }
            else
            {
                PXProcessing <EPExpenseClaimDetails> .SetCurrentItem(null);

                if (singleOperation)
                {
                    throw new PXException(errorMessage);
                }
                else
                {
                    throw new PXException(Messages.ErrorProcessingReceipts);
                }
            }
        }