Exemplo n.º 1
0
        protected virtual void EPTaxTran_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            EPTaxTran             row = (EPTaxTran)e.Row;
            EPExpenseClaimDetails doc = ClaimDetails.Current;

            if (row != null && doc != null && e.Operation != PXDBOperation.Delete)
            {
                if (row.CuryTaxAmt > 0 && doc.CuryExtCost < 0 || row.CuryTaxAmt < 0 && doc.CuryExtCost > 0)
                {
                    cache.RaiseExceptionHandling <EPTaxTran.curyTaxAmt>(row,
                                                                        row.CuryTaxAmt,
                                                                        new PXSetPropertyException(Messages.TaxSign));
                }
                if (row.CuryTaxableAmt > 0 && doc.CuryExtCost < 0 || row.CuryTaxableAmt < 0 && doc.CuryExtCost > 0)
                {
                    cache.RaiseExceptionHandling <EPTaxTran.curyTaxableAmt>(row,
                                                                            row.CuryTaxableAmt,
                                                                            new PXSetPropertyException(Messages.TaxableSign));
                }
            }
        }
        protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, decimal signOperation, decimal tipQty = 1m, bool isTipTransaction = false)
        {
            CurrencyInfo curyInfo = PXSelect <CurrencyInfo> .Search <CurrencyInfo.curyInfoID>(arGraph, row.CuryInfoID);

            EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(arGraph);


            ARTran tran = arGraph.Transactions.Insert();

            if (isTipTransaction)
            {
                IN.InventoryItem tipItem = PXSelect <IN.InventoryItem,
                                                     Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(arGraph, epsetup.NonTaxableTipItem);

                tran.InventoryID = epsetup.NonTaxableTipItem;
                tran.Qty         = tipQty;
                tran.UOM         = tipItem.BaseUnit;
                tran.TranDesc    = tipItem.Descr;

                SetAmount(arGraph, row.CuryTipAmt, row.TipAmt, tipQty, signOperation, curyInfo, tran);
                tran = arGraph.Transactions.Update(tran);

                if (epsetup.UseReceiptAccountForTips == true)
                {
                    tran.AccountID = row.SalesAccountID;
                    tran.SubID     = row.SalesSubID;
                }
                else
                {
                    Location companyloc = (Location)PXSelectJoin <Location,
                                                                  InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>,
                                                                                            And <Location.locationID, Equal <BAccountR.defLocationID> > >,
                                                                             InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >,
                                                                  Where <GL.Branch.branchID, Equal <Current <ARTran.branchID> > > > .Select(arGraph);

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

                    PMTask task = PXSelect <PMTask,
                                            Where <PMTask.projectID, Equal <Required <PMTask.projectID> >,
                                                   And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(arGraph, row.ContractID, row.TaskID);

                    EPEmployee employee = (EPEmployee)PXSelect <EPEmployee> .Search <EPEmployee.bAccountID>(this, row != null?row.EmployeeID : null);

                    Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(arGraph.Caches[typeof(EPExpenseClaimDetails)], row);

                    int?employee_SubID = (int?)arGraph.Caches[typeof(EPEmployee)].GetValue <EPEmployee.salesSubID>(employee);
                    int?item_SubID     = (int?)arGraph.Caches[typeof(IN.InventoryItem)].GetValue <IN.InventoryItem.salesSubID>(tipItem);
                    int?company_SubID  = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(companyloc);
                    int?project_SubID  = (int?)arGraph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract);
                    int?task_SubID     = (int?)arGraph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task);
                    int?location_SubID = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation);

                    object value = SubAccountMaskAttribute.MakeSub <EPSetup.salesSubMask>(arGraph, epsetup.SalesSubMask,
                                                                                          new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID },
                                                                                          new Type[] { typeof(EPEmployee.salesSubID), typeof(IN.InventoryItem.salesSubID), typeof(Location.cSalesSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) });

                    arGraph.Caches[typeof(ARTran)].RaiseFieldUpdating <ARTran.subID>(tran, ref value);
                    tran.SubID = (int?)value;
                }
            }
            else
            {
                tran.InventoryID = row.InventoryID;
                tran.Qty         = row.Qty * signOperation;
                tran.UOM         = row.UOM;
                tran             = arGraph.Transactions.Update(tran);
                tran.AccountID   = row.SalesAccountID;
                tran.SubID       = row.SalesSubID;
                tran.TranDesc    = row.TranDesc;

                //For gross taxes we can't put tranAmt. So we should use taxable amount
                EPTaxTran firstLevelTaxTran = null;
                foreach (EPTaxTran taxRow in PXSelect <EPTaxTran,
                                                       Where <EPTaxTran.claimDetailID, Equal <Required <EPTaxTran.claimDetailID> >,
                                                              And <EPTaxTran.isTipTax, Equal <False> > > > .Select(this, row.ClaimDetailID))
                {
                    if (firstLevelTaxTran == null || Math.Abs(firstLevelTaxTran.CuryTaxableAmt ?? 0m) > Math.Abs(taxRow.CuryTaxableAmt ?? 0m))
                    {
                        firstLevelTaxTran = taxRow;
                    }
                }
                decimal?curyAmt = firstLevelTaxTran?.CuryTaxableAmt ?? row.CuryTaxableAmt;
                decimal?amt     = firstLevelTaxTran?.TaxableAmt ?? row.TaxableAmt;
                SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran);
                tran = arGraph.Transactions.Update(tran);
                if (tran.CuryTaxableAmt != 0 && tran.CuryTaxableAmt != curyAmt)                 // indicates that we have gross/ iclusive taxes. In this case recalculation is required
                {
                    curyAmt = row.CuryTaxableAmt;
                    amt     = row.TaxableAmt;
                    SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran);
                }
            }
            tran.Date        = row.ExpenseDate;
            tran.ManualPrice = true;
            tran             = arGraph.Transactions.Update(tran);
            PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(EPExpenseClaimDetails)], row, arGraph.Transactions.Cache, tran, Setup.Current.GetCopyNoteSettings <PXModule.ar>());
        }