private static void UpdateTrackingNumberDetails(SOGetFBATrackingNumberProcess graph, List <SOProcessOrder> list, SOAmazonSetup objSOAmazonSetupDetails, SOOrderEntry orderEntry, SOPartialMaint objPartialMaint, InvokeReporstServicesCallResponse liShipmentResponse) { string trackingNumber = string.Empty; string carrier = string.Empty; foreach (SOProcessOrder currentRecord in list) { try { if (liShipmentResponse != null && liShipmentResponse.objShipmentResponse != null && liShipmentResponse.objShipmentResponse.Count > 0) { trackingNumber = SOHelper.GetTrackingForFBAOrders(currentRecord.AmazonOrderID, liShipmentResponse.objShipmentResponse, out carrier); currentRecord.AmazonTrackingNumber = !string.IsNullOrEmpty(trackingNumber) ? trackingNumber : null; currentRecord.Carrier = !string.IsNullOrEmpty(carrier) ? carrier : null; graph.TrackingNumberOrdersList.Cache.Update(currentRecord); SOOrder objSOOrder = objPartialMaint.SOOrderView.Select(objSOAmazonSetupDetails.OrderType, currentRecord.AmazonOrderID); if (objSOOrder != null) { PXNoteAttribute.SetNote(orderEntry.Document.Cache, objSOOrder, trackingNumber); orderEntry.Document.Cache.Update(objSOOrder); orderEntry.Actions.PressSave(); } } } catch (Exception ex) { throw new PXException(ex.Message); } } }
protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, bool copyNotes, bool copyFiles) { ARTran tran = (ARTran)arGraph.Transactions.Cache.CreateInstance(); tran.InventoryID = row.InventoryID; tran.TranDesc = row.TranDesc; tran.TranCost = row.ExtCost; tran.Qty = row.Qty; tran.UOM = row.UOM; tran.CuryTranAmt = row.CuryTranAmt; tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; tran.Date = row.ExpenseDate; tran = arGraph.Transactions.Insert(tran); if (copyNotes) { string note = PXNoteAttribute.GetNote(Caches[typeof(EPExpenseClaimDetails)], row); if (note != null) { PXNoteAttribute.SetNote(arGraph.Transactions.Cache, tran, note); } } if (copyFiles) { Guid[] files = PXNoteAttribute.GetFileNotes(Caches[typeof(EPExpenseClaimDetails)], row); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(arGraph.Transactions.Cache, tran, files); } } }
protected virtual void InsertPMTran(RegisterEntry pmGraph, EPExpenseClaimDetails row, EPExpenseClaim doc, bool copyNotes, bool copyFiles) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(pmGraph, row.ContractID); Account account = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(this, row.ExpenseAccountID); if (account.AccountGroupID == null && project.BaseType == PMProject.ProjectBaseType.Project) { throw new PXException(Messages.AccountGroupIsNotAssignedForAccount, account.AccountCD); } PMTran tran = (PMTran)pmGraph.Transactions.Cache.Insert(); tran.AccountGroupID = account.AccountGroupID; tran.BAccountID = row.CustomerID; tran.LocationID = row.CustomerLocationID; tran.ProjectID = row.ContractID; tran.TaskID = row.TaskID; tran.InventoryID = row.InventoryID; tran.Qty = row.Qty; tran.Billable = true; tran.BillableQty = row.Qty; tran.UOM = row.UOM; tran.UnitRate = row.UnitCost; tran.Amount = row.TranAmt; tran.AccountID = row.ExpenseAccountID; tran.SubID = row.ExpenseSubID; tran.StartDate = row.ExpenseDate; tran.EndDate = row.ExpenseDate; tran.Date = row.ExpenseDate; tran.ResourceID = doc.EmployeeID; tran.Released = project.BaseType == PMProject.ContractBaseType.Contract; //contract trans are created as released pmGraph.Transactions.Update(tran); pmGraph.Document.Current.Released = project.BaseType == PMProject.ContractBaseType.Contract; if (copyNotes) { string note = PXNoteAttribute.GetNote(Caches[typeof(EPExpenseClaimDetails)], row); if (note != null) { PXNoteAttribute.SetNote(pmGraph.Transactions.Cache, tran, note); } } if (copyFiles) { Guid[] files = PXNoteAttribute.GetFileNotes(Caches[typeof(EPExpenseClaimDetails)], row); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(pmGraph.Transactions.Cache, tran, files); } } }
public static SOOrder GetSOOrder(SOOrderEntry orderGraph, KCAPIOrder order, SOOrder acumaticaOrder, int?branchID, bool FBA) { KCSiteMasterMaint graph = PXGraph.CreateInstance <KCSiteMasterMaint>(); var customer = KCGeneralDataHelper.GetCustomerByCAOrder(graph, order); var paymentmethod = KCGeneralDataHelper.GetPaymenthMethodId(graph, order); var mapper = new KCDynamicOrderMapper(KCMappingEntitiesConstants.Order); var conversionGraph = PXGraph.CreateInstance <KCOrderConversionDataMaint>(); mapper.Mapping.MappingValues = conversionGraph.GetEntity(); mapper.MapOrder(acumaticaOrder, order); if (paymentmethod == null) { KCPaymentMethodsMappingMaint paymentMethodMappingGraph = PXGraph.CreateInstance <KCPaymentMethodsMappingMaint>(); CustomerPaymentMethodMaint paymentMethodGraph = PXGraph.CreateInstance <CustomerPaymentMethodMaint>(); try { KCGeneralDataHelper.CreatePaymentMethod(paymentMethodGraph, paymentMethodMappingGraph, customer.BAccountID, order); paymentmethod = KCGeneralDataHelper.GetPaymenthMethodId(graph, order); } catch { } } acumaticaOrder.CustomerID = customer.BAccountID; acumaticaOrder.PMInstanceID = paymentmethod?.PMInstanceID; acumaticaOrder.Status = SOOrderStatus.Open; acumaticaOrder.CreatePMInstance = true; KCSOOrderEntryExt orderext = orderGraph.GetExtension <KCSOOrderEntryExt>(); string orderType = new KCMarketplaceHelper().GetOrderType(order, orderGraph); acumaticaOrder.OrderType = orderType ?? acumaticaOrder.OrderType; if (order.EstimatedShipDateUtc == null) { acumaticaOrder.RequestDate = acumaticaOrder.OrderDate; } orderGraph.CurrentDocument.Current = acumaticaOrder; PXNoteAttribute.SetNote(orderGraph.CurrentDocument.Cache, orderGraph.CurrentDocument.Current, order.PrivateNotes); string firstName = orderext.AccountCD.SelectSingle(acumaticaOrder.CustomerID).AcctName; bool isFBAFirstName = firstName.Contains("FBA"); KCSOOrderExt orderExt = acumaticaOrder.GetExtension <KCSOOrderExt>(); orderExt = mapper.MapOrderCaExt(orderExt, order); orderExt.UsrKCSyncDate = DateTime.Now; orderExt.UsrKCSiteName += FBA ? "/FBA" : "/Non-FBA"; if ((FBA && orderExt.UsrKCSiteName.Contains("Amazon")) || isFBAFirstName) { acumaticaOrder.Status = KCCheckoutStatus.CCompleted; } return(acumaticaOrder); }
protected void SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) { var row = (SOOrder)e.Row; if (row == null) { return; } Note CustomerNote = SelectFrom <Note> . LeftJoin <BAccountR> .On <BAccountR.noteID.IsEqual <Note.noteID> > . Where <BAccountR.bAccountID.IsEqual <P.AsInt> > .View.ReadOnly.Select((PXGraph)this.Base, row.CustomerID); if (CustomerNote != null && CustomerNote?.NotePopupText?.Length > 0) { PXNoteAttribute.SetNote(Base.Document.Cache, Base.Document.Current, CustomerNote.NotePopupText); } else { PXNoteAttribute.SetNote(Base.Document.Cache, Base.Document.Current, ""); } }
protected virtual IEnumerable CreateDCLShipment(PXAdapter adapter) { List <SOOrder> list = adapter.Get <SOOrder>().ToList(); var adapterSlice = (adapter.MassProcess, adapter.QuickProcessFlow, adapter.AllowRedirect); for (int i = 0; i < list.Count; i++) { var order = list[i]; if (adapterSlice.MassProcess) { PXProcessing <SOOrder> .SetCurrentItem(order); } DCLShipmentRequestEntity model = new DCLShipmentRequestEntity(); CombineDLCShipmentEntity(model, order); PXNoteAttribute.SetNote(Base.Document.Cache, order, APIHelper.GetJsonString(model)); order.GetExtension <SOOrderExt>().UsrDCLShipmentCreated = true; #region Send Data to DCL for Create Shipment(Implement) //var dclResult = DCLHelper.CallDCLToCreateShipment(this.DCLSetup.Select().RowCast<LUMVendCntrlSetup>().FirstOrDefault(), model); //var response = APIHelper.GetObjectFromString<DCLShipmentResponseEntity>(dclResult.ContentResult); //if (dclResult.StatusCode == System.Net.HttpStatusCode.OK) // order.GetExtension<SOOrderExt>().UsrDCLShipmentCreated = true; //else // throw new PXException(response.error_message); #endregion Base.Document.Cache.Update(order); } Base.Persist(); return(adapter.Get()); }
public virtual bool Bill(int?projectID, DateTime?invoiceDate) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, projectID); ContractBillingSchedule schedule = PXSelect <ContractBillingSchedule> .Search <ContractBillingSchedule.contractID>(this, project.ContractID); DateTime billingDate; if (invoiceDate == null) { if (schedule.Type == BillingType.OnDemand) { billingDate = Accessinfo.BusinessDate ?? DateTime.Now; } else { billingDate = schedule.NextDate.Value; } } else { billingDate = invoiceDate.Value; } Customer customer = null; if (project.CustomerID != null) { customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(this, project.CustomerID); } if (customer == null) { throw new PXException(Messages.NoCustomer); } List <BillingData> list = new List <BillingData>(); List <PMTran> reversalTrans = new List <PMTran>(); PXSelectBase <PMTask> selectTasks = new PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.billingID, IsNotNull, And <PMTask.isActive, Equal <True> > > > >(this); foreach (PMTask task in selectTasks.Select(project.ContractID)) { if ((task.BillingOption == PMBillingOption.OnTaskCompletion && task.IsCompleted == true) || (task.BillingOption == PMBillingOption.OnProjectCompetion && project.IsCompleted == true) || task.BillingOption == PMBillingOption.OnBilling) { list.AddRange(BillTask(task, billingDate)); reversalTrans.AddRange(ReverseWipTask(task, billingDate)); } } //Regroup by Invoices: Dictionary <string, List <BillingData> > invoices = new Dictionary <string, List <BillingData> >(); string emptyInvoiceDescriptionKey = "!@#$%^&"; foreach (BillingData data in list) { if (string.IsNullOrEmpty(data.Rule.InvoiceDescription)) { if (invoices.ContainsKey(emptyInvoiceDescriptionKey)) { invoices[emptyInvoiceDescriptionKey].Add(data); } else { invoices.Add(emptyInvoiceDescriptionKey, new List <BillingData>(new BillingData[] { data })); } } else { if (invoices.ContainsKey(data.Rule.InvoiceDescription)) { invoices[data.Rule.InvoiceDescription].Add(data); } else { invoices.Add(data.Rule.InvoiceDescription, new List <BillingData>(new BillingData[] { data })); } } //Reverse On Billing: if (data.PMTran != null) { bool reverseOnBilling = false; if (data.PMTran.Reverse == PMReverse.OnBilling) { reverseOnBilling = true; } else if (data.PMTran.Reverse != PMReverse.Never && IsNonGL(data.PMTran)) { reverseOnBilling = true; } if (reverseOnBilling) { reversalTrans.AddRange(ReverseTran(data.PMTran)); } } } //Schedule update: schedule.NextDate = GetNextBillingDate(this, schedule, schedule.NextDate); schedule.LastDate = this.Accessinfo.BusinessDate; BillingSchedule.Update(schedule); //ContractDetail update: PXSelectBase <ContractDetailExt> cis = new PXSelect <ContractDetailExt, Where <ContractDetailExt.contractID, Equal <Required <ContractDetailExt.contractID> >, And <ContractDetailExt.resetUsage, Equal <ResetUsageOption.onBilling> > > >(this); foreach (ContractDetailExt ci in cis.Select(project.ContractID)) { ci.Used = 0; ContractDetail.Update(ci); } List <ARRegister> doclist = new List <ARRegister>(); PMRegister reversalDoc = null; if (invoices.Count > 0) { using (PXTransactionScope ts = new PXTransactionScope()) { ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>(); invoiceEntry.FieldVerifying.AddHandler <ARInvoice.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); invoiceEntry.FieldVerifying.AddHandler <ARTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); invoiceEntry.FieldVerifying.AddHandler <ARTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); foreach (KeyValuePair <string, List <BillingData> > kv in invoices) { invoiceEntry.Clear(PXClearOption.ClearAll); string description = kv.Key == emptyInvoiceDescriptionKey ? null : kv.Key; string docDesc = description ?? string.Format(PXMessages.LocalizeNoPrefix(CT.Messages.BillingFor), project.ContractCD, project.Description); ARInvoice invoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].CreateInstance(); invoice.DocType = GetDocType(kv.Value); int mult = 1; if (invoice.DocType == ARDocType.CreditMemo) { mult = -1; } invoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].Insert(invoice); invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.customerID>(invoice, customer.AcctCD); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.customerLocationID>(invoice, project.LocationID); invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.docDate>(invoice, billingDate); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.docDesc>(invoice, docDesc); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.projectID>(invoice, project.ContractID); CurrencyInfo curyinfo = (CurrencyInfo)invoiceEntry.Caches[typeof(CurrencyInfo)].Current; foreach (BillingData data in kv.Value) { data.Tran.ExtPrice = data.Tran.ExtPrice.GetValueOrDefault() * mult; data.Tran.Qty = data.Tran.Qty.GetValueOrDefault() * mult; data.Tran.TranAmt = data.Tran.TranAmt.GetValueOrDefault() * mult; decimal curyamount; PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, data.Tran.UnitPrice.GetValueOrDefault(), out curyamount); data.Tran.CuryUnitPrice = curyamount; PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, data.Tran.ExtPrice.GetValueOrDefault(), out curyamount); data.Tran.CuryExtPrice = curyamount; data.Tran.CuryTranAmt = data.Tran.CuryExtPrice; data.Tran.FreezeManualDisc = true; data.Tran.CuryInfoID = curyinfo.CuryInfoID; ARTran newTran = (ARTran)invoiceEntry.Caches[typeof(ARTran)].Insert(data.Tran); if (data.Tran.TranAmt > newTran.TranAmt) { newTran.PMDeltaOption = ARTran.pMDeltaOption.CompleteLine; //autocomplete when currency descrepency exists. } if (data.Tran.AccountID != null) { ARTran copy = (ARTran)invoiceEntry.Caches[typeof(ARTran)].CreateCopy(newTran); copy.AccountID = data.Tran.AccountID; copy = (ARTran)invoiceEntry.Caches[typeof(ARTran)].Update(copy); if (data.SubCD != null) { invoiceEntry.Caches[typeof(ARTran)].SetValueExt <ARTran.subID>(copy, data.SubCD); } } if (data.Note != null) { PXNoteAttribute.SetNote(invoiceEntry.Caches[typeof(ARTran)], newTran, data.Note); } if (data.Files != null && data.Files.Length > 0) { PXNoteAttribute.SetFileNotes(invoiceEntry.Caches[typeof(ARTran)], newTran, data.Files); } //item.RefLineNbr = newTran.LineNbr; } ARInvoice oldInvoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].CreateCopy(invoice); invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoiceEntry.Caches[typeof(ARInvoice)].RaiseRowUpdated(invoice, oldInvoice); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.curyOrigDocAmt>(invoice, invoice.CuryDocBal); if (project.AutomaticReleaseAR == true) { invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.hold>(invoice, false); } doclist.Add((ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].Current); invoiceEntry.Save.Press(); } Actions.PressSave(); if (reversalTrans.Count > 0) { RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>(); pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); //Project can be completed. pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); //Task can be completed. pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert(); reversalDoc.OrigDocType = PMOrigDocType.AllocationReversal; reversalDoc.Description = "Allocation Reversal on Billing"; pmEntry.Document.Current = reversalDoc; foreach (PMTran tran in reversalTrans) { pmEntry.Transactions.Insert(tran); } pmEntry.Save.Press(); } ts.Complete(); } } else { this.Persist(typeof(ContractBillingSchedule), PXDBOperation.Update); this.Persist(typeof(Contract), PXDBOperation.Update); } if (project.AutomaticReleaseAR == true) { try { ARDocumentRelease.ReleaseDoc(doclist, false); } catch (Exception ex) { throw new PXException(Messages.AutoReleaseARFailed, ex); } if (reversalDoc != null) { try { RegisterRelease.Release(reversalDoc); } catch (Exception ex) { throw new PXException(Messages.AutoReleaseOfReversalFailed, ex); } } } return(doclist.Count > 0); }
public virtual void GenerateProc(Schedule s, short Times, DateTime runDate) { string LastBatchNbr = "0000000000"; Int64 LastInfoID = -1; List <ScheduleDet> sd = MakeSchedule(s, Times, runDate); using (PXTransactionScope ts = new PXTransactionScope()) { foreach (ScheduleDet d in sd) { foreach (BatchNew b in PXSelect <BatchNew, Where <BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >, And <BatchNew.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID)) { BatchNew copy = PXCache <BatchNew> .CreateCopy(b); copy.OrigBatchNbr = copy.BatchNbr; copy.OrigModule = copy.Module; copy.CuryInfoID = null; copy.NumberCode = "GLREC"; copy.NoteID = null; CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(this, b.CuryInfoID); if (info != null) { CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info); infocopy.CuryInfoID = LastInfoID; copy.CuryInfoID = LastInfoID; CuryInfo_Created.Cache.Insert(infocopy); } copy.Posted = false; copy.Released = false; copy.Status = "B"; copy.Scheduled = false; copy.DateEntered = d.ScheduledDate; copy.FinPeriodID = d.ScheduledPeriod; copy.TranPeriodID = null; copy.BatchNbr = LastBatchNbr; copy.RefBatchNbr = LastBatchNbr; LastBatchNbr = AutoNumberAttribute.NextNumber(LastBatchNbr); LastInfoID--; copy = (BatchNew)Batch_Created.Cache.Insert(copy); CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false)); PXNoteAttribute.SetNote(Batch_Created.Cache, copy, PXNoteAttribute.GetNote(Caches[typeof(BatchNew)], b)); PXNoteAttribute.SetFileNotes(Batch_Created.Cache, copy, PXNoteAttribute.GetFileNotes(Caches[typeof(BatchNew)], b)); foreach (GLTranNew tran in PXSelect <GLTranNew, Where <GLTranNew.module, Equal <Required <GLTranNew.module> >, And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > > .Select(this, b.Module, b.BatchNbr)) { GLTranNew trancopy = PXCache <GLTranNew> .CreateCopy(tran); trancopy.OrigBatchNbr = trancopy.BatchNbr; trancopy.OrigModule = trancopy.Module; trancopy.BatchNbr = copy.BatchNbr; trancopy.RefBatchNbr = copy.RefBatchNbr; trancopy.CuryInfoID = copy.CuryInfoID; trancopy.CATranID = null; trancopy.TranDate = d.ScheduledDate; trancopy.FinPeriodID = d.ScheduledPeriod; trancopy.TranPeriodID = d.ScheduledPeriod; Tran_Created.Cache.Insert(trancopy); } } s.LastRunDate = d.ScheduledDate; Running_Schedule.Cache.Update(s); } Running_Schedule.Cache.Persist(PXDBOperation.Update); Batch_Created.Cache.Persist(PXDBOperation.Insert); Batch_Created.Cache.Persist(PXDBOperation.Update); foreach (GLTranNew tran in Tran_Created.Cache.Inserted) { foreach (BatchNew batch in Batch_Created.Cache.Cached) { if (object.Equals(batch.RefBatchNbr, tran.RefBatchNbr)) { tran.BatchNbr = batch.BatchNbr; tran.CuryInfoID = batch.CuryInfoID; if (!string.IsNullOrEmpty(batch.RefNbr)) { tran.RefNbr = batch.RefNbr; } break; } } } Tran_Created.Cache.Normalize(); Tran_Created.Cache.Persist(PXDBOperation.Insert); Tran_Created.Cache.Persist(PXDBOperation.Update); Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert); ts.Complete(this); } Running_Schedule.Cache.Persisted(false); Batch_Created.Cache.Persisted(false); Tran_Created.Cache.Persisted(false); Caches[typeof(CA.CADailySummary)].Persisted(false); }
public static void ReleaseDoc(EPExpenseClaim claim) { APInvoiceEntry docgraph = PXGraph.CreateInstance <APInvoiceEntry>(); ExpenseClaimEntry expenseclaim = PXGraph.CreateInstance <ExpenseClaimEntry>(); if (claim.FinPeriodID == null) { throw new PXException(Messages.ReleaseClaimWithoutFinPeriod); } //docgraph.FieldVerifying.AddHandler<APInvoice.vendorLocationID>(APInterceptor); EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID); Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph); APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph); docgraph.vendor.Current = employee; docgraph.location.Current = emplocation; CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID); CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal); info.CuryInfoID = null; info = docgraph.currencyinfo.Insert(info); APInvoice invoice = new APInvoice(); invoice.CuryInfoID = info.CuryInfoID; invoice.Hold = true; invoice.Released = false; invoice.Printed = false; invoice.OpenDoc = true; invoice.DocDate = claim.DocDate; invoice.InvoiceNbr = claim.RefNbr; invoice.DocDesc = claim.DocDesc; invoice.VendorID = claim.EmployeeID; invoice.CuryID = info.CuryID; invoice.VendorLocationID = claim.LocationID; invoice.APAccountID = emplocation != null ? emplocation.APAccountID : null; invoice.APSubID = emplocation != null ? emplocation.APSubID : null; invoice.TaxZoneID = claim.TaxZoneID; invoice = docgraph.Document.Insert(invoice); PXCache claimcache = docgraph.Caches[typeof(EPExpenseClaim)]; PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)]; if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimcache, claim); if (note != null) { PXNoteAttribute.SetNote(docgraph.Document.Cache, invoice, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimcache, claim); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, invoice, files); } } using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); foreach (PXResult <EPExpenseClaimDetails, Contract> res in PXSelectJoin <EPExpenseClaimDetails, LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID> > >, Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr)) { EPExpenseClaimDetails claimdetail = (EPExpenseClaimDetails)res; Contract contract = (Contract)res; if (claimdetail.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseclaim, claimdetail.TaskID); if (task != null && !(bool)task.VisibleInAP) { throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP); } } APTran tran = new APTran(); tran.InventoryID = claimdetail.InventoryID; tran.TranDesc = claimdetail.TranDesc; tran.CuryUnitCost = claimdetail.CuryUnitCost; tran.Qty = claimdetail.Qty; tran.UOM = claimdetail.UOM; tran.NonBillable = claimdetail.Billable != true; tran.CuryLineAmt = claimdetail.CuryTranAmt; tran.Date = claimdetail.ExpenseDate; if (contract.BaseType == PM.PMProject.ProjectBaseType.Project) { tran.ProjectID = claimdetail.ContractID; } else { tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(docgraph); } tran.TaskID = claimdetail.TaskID; tran.AccountID = claimdetail.ExpenseAccountID; tran.SubID = claimdetail.ExpenseSubID; tran.TaxCategoryID = claimdetail.TaxCategoryID; tran = docgraph.Transactions.Insert(tran); if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimdetailcache, claimdetail); if (note != null) { PXNoteAttribute.SetNote(docgraph.Transactions.Cache, tran, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimdetailcache, claimdetail); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Transactions.Cache, tran, files); } } claimdetail.Released = true; expenseclaim.ExpenseClaimDetails.Update(claimdetail); } foreach (EPTaxTran tax in PXSelect <EPTaxTran, Where <EPTaxTran.refNbr, Equal <Required <EPTaxTran.refNbr> > > > .Select(docgraph, claim.RefNbr)) { APTaxTran new_aptax = new APTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = docgraph.Taxes.Insert(new_aptax); if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt; new_aptax.CuryTaxAmt = tax.CuryTaxAmt; new_aptax = docgraph.Taxes.Update(new_aptax); } } invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoice.Hold = false; docgraph.Document.Update(invoice); docgraph.Save.Press(); claim.Status = EPClaimStatus.Released; claim.Released = true; claim.APRefNbr = invoice.RefNbr; claim.APDocType = invoice.DocType; expenseclaim.ExpenseClaim.Update(claim); #region EP History Update EPHistory hist = new EPHistory(); hist.EmployeeID = invoice.VendorID; hist.FinPeriodID = invoice.FinPeriodID; hist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(hist); hist.FinPtdClaimed += invoice.DocBal; hist.FinYtdClaimed += invoice.DocBal; if (invoice.FinPeriodID == invoice.TranPeriodID) { hist.TranPtdClaimed += invoice.DocBal; hist.TranYtdClaimed += invoice.DocBal; } else { EPHistory tranhist = new EPHistory(); tranhist.EmployeeID = invoice.VendorID; tranhist.FinPeriodID = invoice.TranPeriodID; tranhist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(tranhist); tranhist.TranPtdClaimed += invoice.DocBal; tranhist.TranYtdClaimed += invoice.DocBal; } expenseclaim.Views.Caches.Add(typeof(EPHistory)); #endregion expenseclaim.Save.Press(); ts.Complete(); } } if ((bool)epsetup.AutomaticReleaseAP == true) { List <APRegister> doclist = new List <APRegister>(); doclist.Add(docgraph.Document.Current); APDocumentRelease.ReleaseDoc(doclist, false); } }
public static PXRedirectRequiredException CreatePOOrders2( System.Collections.Generic.List <POFixedDemand> list, DateTime?PurchDate, bool extSort) { POOrderEntry docgraph = PXGraph.CreateInstance <POOrderEntry>(); docgraph.Views.Caches.Add(typeof(POOrderEntry.SOLineSplit3)); POSetup current = docgraph.POSetup.Current; DocumentList <POOrder> documentList1 = new DocumentList <POOrder>((PXGraph)docgraph); Dictionary <string, DocumentList <POLine> > dictionary = new Dictionary <string, DocumentList <POLine> >(); list.Sort((Comparison <POFixedDemand>)((a, b) => { string empty1 = string.Empty; string empty2 = string.Empty; string str; if (a.PlanType == "90") { PX.Objects.IN.InventoryItem inventoryItem = PX.Objects.IN.InventoryItem.PK.Find((PXGraph)docgraph, a.InventoryID); str = string.Format("ZZ.{0}", inventoryItem == null ? (object)string.Empty : (object)inventoryItem.InventoryCD); } else { POOrderEntry.SOLineSplit3 soLineSplit3 = (POOrderEntry.SOLineSplit3)PXSelectBase <POOrderEntry.SOLineSplit3, PXSelect <POOrderEntry.SOLineSplit3, Where <POOrderEntry.SOLineSplit3.planID, Equal <Required <POOrderEntry.SOLineSplit3.planID> > > > .Config> .Select((PXGraph)docgraph, (object)a.PlanID); str = soLineSplit3 == null ? string.Empty : string.Format("{0}.{1}.{2:D7}", (object)soLineSplit3.OrderType, (object)soLineSplit3.OrderNbr, (object)soLineSplit3.SortOrder.GetValueOrDefault()); } string strB; if (b.PlanType == "90") { PX.Objects.IN.InventoryItem inventoryItem = PX.Objects.IN.InventoryItem.PK.Find((PXGraph)docgraph, b.InventoryID); strB = string.Format("ZZ.{0}", inventoryItem == null ? (object)string.Empty : (object)inventoryItem.InventoryCD); } else { POOrderEntry.SOLineSplit3 soLineSplit3 = (POOrderEntry.SOLineSplit3)PXSelectBase <POOrderEntry.SOLineSplit3, PXSelect <POOrderEntry.SOLineSplit3, Where <POOrderEntry.SOLineSplit3.planID, Equal <Required <POOrderEntry.SOLineSplit3.planID> > > > .Config> .Select((PXGraph)docgraph, (object)b.PlanID); strB = soLineSplit3 == null ? string.Empty : string.Format("{0}.{1}.{2:D7}", (object)soLineSplit3.OrderType, (object)soLineSplit3.OrderNbr, (object)soLineSplit3.SortOrder.GetValueOrDefault()); } return(str.CompareTo(strB)); })); POOrder poOrder1 = (POOrder)null; bool flag1 = false; foreach (POFixedDemand demand in list) { if (!(demand.FixedSource != "P")) { string OrderType = demand.PlanType == "6D" ? "DP" : (demand.PlanType == "6E" ? "DP" : "RO"); string str1 = (string)null; int? nullable1 = demand.VendorID; int num1; if (nullable1.HasValue) { nullable1 = demand.VendorLocationID; num1 = !nullable1.HasValue ? 1 : 0; } else { num1 = 1; } if (num1 != 0) { PXProcessing <POFixedDemand> .SetWarning(list.IndexOf(demand), "Vendor and vendor location should be defined."); } else { PXErrorLevel pxErrorLevel = PXErrorLevel.RowInfo; string empty = string.Empty; try { PX.Objects.SO.SOOrder soOrder = (PX.Objects.SO.SOOrder) PXSelectBase <PX.Objects.SO.SOOrder, PXSelect <PX.Objects.SO.SOOrder, Where <PX.Objects.SO.SOOrder.noteID, Equal <Required <PX.Objects.SO.SOOrder.noteID> > > > .Config> .Select((PXGraph)docgraph, (object)demand.RefNoteID); POOrderEntry.SOLineSplit3 soLineSplit3 = (POOrderEntry.SOLineSplit3) PXSelectBase <POOrderEntry.SOLineSplit3, PXSelect <POOrderEntry.SOLineSplit3, Where <POOrderEntry.SOLineSplit3.planID, Equal <Required <POOrderEntry.SOLineSplit3.planID> > > > .Config> .Select((PXGraph)docgraph, (object)demand.PlanID); string str2 = (string)null; string str3 = (string)null; if (demand.PlanType == "6B" || demand.PlanType == "6E") { str2 = soLineSplit3.POType; str3 = soLineSplit3.PONbr; } System.Collections.Generic.List <FieldLookup> fieldLookupList1 = new System.Collections.Generic.List <FieldLookup>() { (FieldLookup) new FieldLookup <POOrder.orderType>((object)OrderType), (FieldLookup) new FieldLookup <POOrder.vendorID>((object)demand.VendorID), (FieldLookup) new FieldLookup <POOrder.vendorLocationID>((object)demand.VendorLocationID), (FieldLookup) new FieldLookup <POOrder.bLOrderNbr>((object)str3) }; if (OrderType == "RO") { bool?projectPerDocument = docgraph.apsetup.Current.RequireSingleProjectPerDocument; bool flag2 = true; if (projectPerDocument.GetValueOrDefault() == flag2 & projectPerDocument.HasValue) { nullable1 = demand.ProjectID; int?nullable2 = nullable1.HasValue ? nullable1 : ProjectDefaultAttribute.NonProject(); fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.projectID>((object)nullable2)); } int num2; if (poOrder1 != null && poOrder1.ShipDestType == "L") { nullable1 = poOrder1.SiteID; num2 = !nullable1.HasValue ? 1 : 0; } else { num2 = 0; } if (num2 == 0) { fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.siteID>((object)demand.POSiteID)); } } else if (OrderType == "DP") { fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.sOOrderType>((object)soLineSplit3.OrderType)); fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.sOOrderNbr>((object)soLineSplit3.OrderNbr)); } else { fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.shipToBAccountID>((object)soOrder.CustomerID)); fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.shipToLocationID>((object)soOrder.CustomerLocationID)); fieldLookupList1.Add((FieldLookup) new FieldLookup <POOrder.siteID>((object)demand.POSiteID)); } poOrder1 = documentList1.Find(fieldLookupList1.ToArray()) ?? new POOrder(); if (poOrder1.OrderNbr == null) { docgraph.Clear(); poOrder1.OrderType = OrderType; poOrder1 = PXCache <POOrder> .CreateCopy(docgraph.Document.Insert(poOrder1)); poOrder1.VendorID = demand.VendorID; poOrder1.VendorLocationID = demand.VendorLocationID; poOrder1.SiteID = demand.POSiteID; nullable1 = demand.ProjectID; if (nullable1.HasValue) { poOrder1.ProjectID = demand.ProjectID; } poOrder1.OrderDate = PurchDate; poOrder1.BLType = str2; poOrder1.BLOrderNbr = str3; if (OrderType == "DP" | extSort) { poOrder1.SOOrderType = soLineSplit3.OrderType; poOrder1.SOOrderNbr = soLineSplit3.OrderNbr; } if (!string.IsNullOrEmpty(poOrder1.BLOrderNbr)) { POOrder poOrder2 = (POOrder)PXSelectBase <POOrder, PXSelect <POOrder, Where <POOrder.orderType, Equal <Current <POOrder.bLType> >, And <POOrder.orderNbr, Equal <Current <POOrder.bLOrderNbr> > > > > .Config> .SelectSingleBound((PXGraph)docgraph, new object[1] { (object)poOrder1 }); if (poOrder2 != null) { poOrder1.VendorRefNbr = poOrder2.VendorRefNbr; } } if (OrderType == "DP") { poOrder1.ShipDestType = "C"; poOrder1.ShipToBAccountID = soOrder.CustomerID; poOrder1.ShipToLocationID = soOrder.CustomerLocationID; } else if (current.ShipDestType == "S") { poOrder1.ShipDestType = "S"; poOrder1.SiteID = demand.POSiteID; } if (PXAccess.FeatureInstalled <PX.Objects.CS.FeaturesSet.multicurrency>()) { docgraph.currencyinfo.Current.CuryID = (string)null; } poOrder1 = docgraph.Document.Update(poOrder1); if (OrderType == "DP") { SOAddress soAddress = (SOAddress)PXSelectBase <SOAddress, PXSelect <SOAddress, Where <SOAddress.addressID, Equal <Required <PX.Objects.SO.SOOrder.shipAddressID> > > > .Config> .Select((PXGraph)docgraph, (object)soOrder.ShipAddressID); bool?isDefaultAddress = soAddress.IsDefaultAddress; bool flag2 = false; if (isDefaultAddress.GetValueOrDefault() == flag2 & isDefaultAddress.HasValue) { SharedRecordAttribute.CopyRecord <POOrder.shipAddressID>(docgraph.Document.Cache, (object)poOrder1, (object)soAddress, true); } SOContact soContact = (SOContact)PXSelectBase <SOContact, PXSelect <SOContact, Where <SOContact.contactID, Equal <Required <PX.Objects.SO.SOOrder.shipContactID> > > > .Config> .Select((PXGraph)docgraph, (object)soOrder.ShipContactID); bool?isDefaultContact = soContact.IsDefaultContact; bool flag3 = false; if (isDefaultContact.GetValueOrDefault() == flag3 & isDefaultContact.HasValue) { SharedRecordAttribute.CopyRecord <POOrder.shipContactID>(docgraph.Document.Cache, (object)poOrder1, (object)soContact, true); } DateTime?expectedDate = poOrder1.ExpectedDate; DateTime?requestDate = soOrder.RequestDate; if (expectedDate.HasValue & requestDate.HasValue && expectedDate.GetValueOrDefault() < requestDate.GetValueOrDefault()) { poOrder1 = PXCache <POOrder> .CreateCopy(poOrder1); poOrder1.ExpectedDate = soOrder.RequestDate; poOrder1 = docgraph.Document.Update(poOrder1); } } } else if (!docgraph.Document.Cache.ObjectsEqual((object)docgraph.Document.Current, (object)poOrder1)) { docgraph.Document.Current = (POOrder)docgraph.Document.Search <POOrder.orderNbr>((object)poOrder1.OrderNbr, (object)poOrder1.OrderType); } poOrder1.UpdateVendorCost = new bool?(false); POLine poLine1 = (POLine)null; DocumentList <POLine> documentList2; if (!dictionary.TryGetValue(demand.PlanType, out documentList2)) { documentList2 = dictionary[demand.PlanType] = new DocumentList <POLine>((PXGraph)docgraph); } if (OrderType == "RO" && demand.PlanType != "6B") { System.Collections.Generic.List <FieldLookup> fieldLookupList2 = new System.Collections.Generic.List <FieldLookup>(); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.vendorID>((object)demand.VendorID)); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.vendorLocationID>((object)demand.VendorLocationID)); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.siteID>((object)demand.POSiteID)); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.inventoryID>((object)demand.InventoryID)); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.subItemID>((object)demand.SubItemID)); fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.requestedDate>((object)(DateTime?)soLineSplit3?.ShipDate)); int?nullable2; if (soLineSplit3 == null) { nullable1 = new int?(); nullable2 = nullable1; } else { nullable2 = soLineSplit3.ProjectID; } fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.projectID>((object)nullable2)); int?nullable3; if (soLineSplit3 == null) { nullable1 = new int?(); nullable3 = nullable1; } else { nullable3 = soLineSplit3.TaskID; } fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.taskID>((object)nullable3)); int?nullable4; if (soLineSplit3 == null) { nullable1 = new int?(); nullable4 = nullable1; } else { nullable4 = soLineSplit3.CostCodeID; } fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.costCodeID>((object)nullable4)); int?nullable5; if (soLineSplit3 == null) { nullable1 = new int?(); nullable5 = nullable1; } else { nullable5 = soLineSplit3.LineNbr; } fieldLookupList2.Add((FieldLookup) new FieldLookup <POLine.lineNbr>((object)nullable5)); System.Collections.Generic.List <FieldLookup> fieldLookupList3 = fieldLookupList2; bool?nullable6 = current.CopyLineDescrSO; bool flag2 = true; if (nullable6.GetValueOrDefault() == flag2 & nullable6.HasValue && soLineSplit3 != null) { fieldLookupList3.Add((FieldLookup) new FieldLookup <POLine.tranDesc>((object)soLineSplit3.TranDesc)); poLine1 = documentList2.Find(fieldLookupList3.ToArray()); int num2; if (poLine1 != null) { nullable6 = current.CopyLineNoteSO; bool flag3 = true; if (nullable6.GetValueOrDefault() == flag3 & nullable6.HasValue) { num2 = PXNoteAttribute.GetNote(docgraph.Caches[typeof(POLine)], (object)poLine1) != null ? 1 : (PXNoteAttribute.GetNote(docgraph.Caches[typeof(POOrderEntry.SOLineSplit3)], (object)soLineSplit3) != null ? 1 : 0); goto label_67; } } num2 = 0; label_67: if (num2 != 0) { poLine1 = (POLine)null; } } else { poLine1 = documentList2.Find(fieldLookupList3.ToArray()); } } POLine dest = poLine1 ?? new POLine(); POLine copy1; if (dest.OrderNbr == null) { docgraph.FillPOLineFromDemand(dest, demand, OrderType, soLineSplit3); POLine line = docgraph.Transactions.Insert(dest); bool? copyLineNoteSo = current.CopyLineNoteSO; bool flag2 = true; if (copyLineNoteSo.GetValueOrDefault() == flag2 & copyLineNoteSo.HasValue && soLineSplit3 != null) { PXNoteAttribute.SetNote(docgraph.Transactions.Cache, (object)line, PXNoteAttribute.GetNote(docgraph.Caches[typeof(POOrderEntry.SOLineSplit3)], (object)soLineSplit3)); } if (docgraph.onCopyPOLineFields != null) { docgraph.onCopyPOLineFields(demand, line); } copy1 = PXCache <POLine> .CreateCopy(line); documentList2.Add(copy1); } else { copy1 = PXCache <POLine> .CreateCopy((POLine)PXSelectBase <POLine, PXSelect <POLine, Where <POLine.orderType, Equal <Current <POOrder.orderType> >, And <POLine.orderNbr, Equal <Current <POOrder.orderNbr> >, And <POLine.lineNbr, Equal <Current <POLine.lineNbr> > > > > > .Config> .SelectSingleBound((PXGraph)docgraph, new object[1] { (object)dest })); POLine poLine2 = copy1; Decimal?orderQty1 = poLine2.OrderQty; Decimal?orderQty2 = demand.OrderQty; poLine2.OrderQty = orderQty1.HasValue & orderQty2.HasValue ? new Decimal?(orderQty1.GetValueOrDefault() + orderQty2.GetValueOrDefault()) : new Decimal?(); } if (demand.PlanType == "6B" || demand.PlanType == "6E") { str1 = demand.PlanType == "6B" ? "66" : "6D"; demand.FixedSource = "P"; copy1.POType = soLineSplit3.POType; copy1.PONbr = soLineSplit3.PONbr; copy1.POLineNbr = soLineSplit3.POLineNbr; POLine poLine2 = (POLine)PXSelectBase <POLine, PXSelect <POLine, Where <POLine.orderType, Equal <Current <POLine.pOType> >, And <POLine.orderNbr, Equal <Current <POLine.pONbr> >, And <POLine.lineNbr, Equal <Current <POLine.pOLineNbr> > > > > > .Config> .SelectSingleBound((PXGraph)docgraph, new object[1] { (object)copy1 }); if (poLine2 != null) { Decimal?nullable2 = demand.PlanQty; Decimal?baseOpenQty = poLine2.BaseOpenQty; if (nullable2.GetValueOrDefault() > baseOpenQty.GetValueOrDefault() & (nullable2.HasValue & baseOpenQty.HasValue)) { POLine poLine3 = copy1; Decimal?orderQty = poLine3.OrderQty; nullable2 = demand.OrderQty; poLine3.OrderQty = orderQty.HasValue & nullable2.HasValue ? new Decimal?(orderQty.GetValueOrDefault() - nullable2.GetValueOrDefault()) : new Decimal?(); if (string.Equals(copy1.UOM, poLine2.UOM)) { POLine poLine4 = copy1; nullable2 = poLine4.OrderQty; Decimal?openQty = poLine2.OpenQty; poLine4.OrderQty = nullable2.HasValue & openQty.HasValue ? new Decimal?(nullable2.GetValueOrDefault() + openQty.GetValueOrDefault()) : new Decimal?(); } else { PXDBQuantityAttribute.CalcBaseQty <POLine.orderQty>(docgraph.Transactions.Cache, (object)copy1); POLine poLine4 = copy1; Decimal?baseOrderQty = poLine4.BaseOrderQty; nullable2 = poLine2.BaseOpenQty; poLine4.BaseOrderQty = baseOrderQty.HasValue & nullable2.HasValue ? new Decimal?(baseOrderQty.GetValueOrDefault() + nullable2.GetValueOrDefault()) : new Decimal?(); PXDBQuantityAttribute.CalcTranQty <POLine.orderQty>(docgraph.Transactions.Cache, (object)copy1); } pxErrorLevel = PXErrorLevel.RowWarning; empty += PXMessages.LocalizeFormatNoPrefixNLA("Order Quantity reduced to Blanket Order: '{0}' Open Qty. for this item", (object)copy1.PONbr); } copy1.CuryUnitCost = poLine2.CuryUnitCost; copy1.UnitCost = poLine2.UnitCost; } } copy1.SiteID = POCreate_Extension.GetWasrehouseByBranch((PXGraph)docgraph, copy1.BranchID); short? vleadTime = docgraph.location.Current.VLeadTime; POLine poLine5 = copy1; DateTime dateTime = soLineSplit3.ShipDate.Value; ref DateTime local = ref dateTime; short? nullable7 = vleadTime; nullable1 = nullable7.HasValue ? new int?((int)nullable7.GetValueOrDefault()) : new int?(); int num3 = 0; double num4 = nullable1.GetValueOrDefault() > num3 & nullable1.HasValue ? (double)-vleadTime.Value : -14.0; DateTime?nullable8 = new DateTime?(local.AddDays(num4)); poLine5.RequestedDate = nullable8; POLine poLine6 = docgraph.Transactions.Update(copy1); PXCache cach = docgraph.Caches[typeof(INItemPlan)]; POCreate_Extension.CreateSplitDemand2(cach, demand); cach.SetStatus((object)demand, PXEntryStatus.Updated); demand.SupplyPlanID = poLine6.PlanID; if (str1 != null) { cach.RaiseRowDeleted((object)demand); demand.PlanType = str1; cach.RaiseRowInserted((object)demand); } if (soLineSplit3 != null) { int num2; if (demand.AlternateID != null) { nullable1 = demand.InventoryID; num2 = nullable1.HasValue ? 1 : 0; } else { num2 = 0; } if (num2 != 0) { PXSelectBase <INItemXRef> pxSelectBase = (PXSelectBase <INItemXRef>) new PXSelect <INItemXRef, Where <INItemXRef.inventoryID, Equal <Required <INItemXRef.inventoryID> >, And <INItemXRef.alternateID, Equal <Required <INItemXRef.alternateID> > > > >((PXGraph)docgraph); INItemXRef inItemXref1 = (INItemXRef)pxSelectBase.Select((object)demand.InventoryID, (object)demand.AlternateID); if (inItemXref1 != null && inItemXref1.AlternateType == "GLBL") { int num5; if (poLine6.AlternateID != null) { nullable1 = poLine6.InventoryID; num5 = nullable1.HasValue ? 1 : 0; } else { num5 = 0; } if (num5 != 0) { INItemXRef inItemXref2 = (INItemXRef)pxSelectBase.Select((object)poLine6.InventoryID, (object)poLine6.AlternateID); if (inItemXref2 != null && inItemXref2.AlternateType == "GLBL") { poLine6.AlternateID = demand.AlternateID; } } else { poLine6.AlternateID = demand.AlternateID; } } } soLineSplit3.POType = poLine6.OrderType; soLineSplit3.PONbr = poLine6.OrderNbr; soLineSplit3.POLineNbr = poLine6.LineNbr; soLineSplit3.RefNoteID = docgraph.Document.Current.NoteID; PX.Objects.SO.SOLine soLine = SelectFrom <PX.Objects.SO.SOLine> .Where <PX.Objects.SO.SOLine.orderType.IsEqual <P.AsString> .And <PX.Objects.SO.SOLine.orderNbr.IsEqual <P.AsString> .And <PX.Objects.SO.SOLine.lineNbr.IsEqual <P.AsInt> > > > .View.ReadOnly.Select((PXGraph)docgraph, (object)soLineSplit3.OrderType, (object)soLineSplit3.OrderNbr, (object)soLineSplit3.LineNbr); POLineExt extension1 = poLine6.GetExtension <POLineExt>(); SOLineExt extension2 = soLine.GetExtension <SOLineExt>(); extension1.UsrEndCustomerID = extension2.UsrEndCustomerID; extension1.UsrNonStockItem = extension2.UsrNonStockItem; extension1.UsrProjectNbr = extension2.UsrProjectNbr; if (!string.IsNullOrEmpty(extension2.UsrProjectNbr)) { FLXProject flxProject = SelectFrom <FLXProject> .Where <FLXProject.projectNbr.IsEqual <P.AsString> > .View.ReadOnly.Select((PXGraph)docgraph, (object)extension2.UsrProjectNbr); extension1.UsrCust2Factory = flxProject.Cust2Factory; extension1.UsrFactoryPN = flxProject.FactoryPN; } docgraph.GetExtension <POOrderEntry_Extension>().UpdateSOLine(soLineSplit3, docgraph.Document.Current.VendorID, true); docgraph.FixedDemand.Cache.SetStatus((object)soLineSplit3, PXEntryStatus.Updated); } if (docgraph.Transactions.Cache.IsInsertedUpdatedDeleted) { using (PXTransactionScope transactionScope = new PXTransactionScope()) { docgraph.Save.Press(); if (demand.PlanType == "90") { docgraph.Replenihment.Current = (INReplenishmentOrder)docgraph.Replenihment.Search <INReplenishmentOrder.noteID>((object)demand.RefNoteID); if (docgraph.Replenihment.Current != null) { INReplenishmentLine copy2 = PXCache <INReplenishmentLine> .CreateCopy(docgraph.ReplenishmentLines.Insert(new INReplenishmentLine())); copy2.InventoryID = poLine6.InventoryID; copy2.SubItemID = poLine6.SubItemID; copy2.UOM = poLine6.UOM; copy2.VendorID = poLine6.VendorID; copy2.VendorLocationID = poLine6.VendorLocationID; copy2.Qty = poLine6.OrderQty; copy2.POType = poLine6.OrderType; copy2.PONbr = docgraph.Document.Current.OrderNbr; copy2.POLineNbr = poLine6.LineNbr; copy2.SiteID = demand.POSiteID; copy2.PlanID = demand.PlanID; docgraph.ReplenishmentLines.Update(copy2); docgraph.Caches[typeof(INItemPlan)].Delete((object)demand); docgraph.Save.Press(); } } transactionScope.Complete(); } if (pxErrorLevel == PXErrorLevel.RowInfo) { PXProcessing <POFixedDemand> .SetInfo(list.IndexOf(demand), PXMessages.LocalizeFormatNoPrefixNLA("Purchase Order '{0}' created.", (object)docgraph.Document.Current.OrderNbr) + "\r\n" + empty); } else { PXProcessing <POFixedDemand> .SetWarning(list.IndexOf(demand), PXMessages.LocalizeFormatNoPrefixNLA("Purchase Order '{0}' created.", (object)docgraph.Document.Current.OrderNbr) + "\r\n" + empty); } if (documentList1.Find((object)docgraph.Document.Current) == null) { documentList1.Add(docgraph.Document.Current); } } }
protected virtual IEnumerable UpdateOpenInvoice(PXAdapter adapter) { var order = Base.CurrentDocument.Current; if (order != null) { string noteInfo = PXNoteAttribute.GetNote(Base.CurrentDocument.Cache, order); APILibrary.Model.Root root = JsonConvert.DeserializeObject <APILibrary.Model.Root>(noteInfo); if (root != null) { using (PXTransactionScope ts = new PXTransactionScope()) { if (root.description == null) { goto Item; } order.OrderDesc = root.description; Base.CurrentDocument.Cache.MarkUpdated(order); PXUpdateJoin <Set <ARInvoice.docDesc, Required <SOOrder.orderDesc> >, ARInvoice, InnerJoin <SOOrderShipment, On <SOOrderShipment.invoiceType, Equal <ARInvoice.docType>, And <SOOrderShipment.invoiceNbr, Equal <ARInvoice.refNbr> > > >, Where <SOOrderShipment.orderNoteID, Equal <Required <SOOrder.noteID> > > > .Update(Base, root.description, order.NoteID); Item: for (int i = 0; i < root.item.Count; i++) { if (root.item[i].sku == null) { goto Invoice; } foreach (SOLine row in Base.Transactions.Select()) { if (string.Format("{0}-{1}", (int)row.OrderQty, InventoryItem.PK.Find(Base, row.InventoryID).InventoryCD.TrimEnd()).CompareTo(root.item[i].qty + "-" + root.item[i].sku) == 0) { row.GetExtension <SOLineExt>().UsrAmazWHTaxAmt = (decimal)root.item[i].whTax; Base.Transactions.Cache.MarkUpdated(row); } } } Base.Save.Press(); Invoice: if (root.taxAmount != 0) { PXUpdateJoin <Set <TaxTran.curyTaxAmt, Required <TaxTran.curyTaxAmt> >, TaxTran, LeftJoin <ARInvoice, On <TaxTran.module, Equal <PX.Objects.GL.BatchModule.moduleAR>, And <ARInvoice.docType, Equal <TaxTran.tranType>, And <ARInvoice.refNbr, Equal <TaxTran.refNbr> > > >, InnerJoin <SOOrderShipment, On <SOOrderShipment.invoiceType, Equal <ARInvoice.docType>, And <SOOrderShipment.invoiceNbr, Equal <ARInvoice.refNbr> > > > >, Where <SOOrderShipment.orderNoteID, Equal <Required <SOOrder.noteID> > > > .Update(Base, (decimal)root.taxAmount, order.NoteID); PXUpdateJoin <Set <ARInvoice.curyTaxTotal, Required <ARInvoice.curyTaxTotal> >, ARInvoice, InnerJoin <SOOrderShipment, On <SOOrderShipment.invoiceType, Equal <ARInvoice.docType>, And <SOOrderShipment.invoiceNbr, Equal <ARInvoice.refNbr> > > >, Where <SOOrderShipment.orderNoteID, Equal <Required <SOOrder.noteID> > > > .Update(Base, (decimal)root.taxAmount, order.NoteID); } PXNoteAttribute.SetNote(Base.CurrentDocument.Cache, order, null); ts.Complete(); } } } return(adapter.Get()); }
public virtual void GenerateProc(Schedule s, short Times, DateTime runDate) { List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate); ARInvoiceEntry docgraph = CreateGraph(); foreach (ScheduleDet sdet in sd) { foreach (PXResult <ARInvoice, Customer, CurrencyInfo> res in PXSelectJoin <ARInvoice, InnerJoin <Customer, On <Customer.bAccountID, Equal <ARInvoice.customerID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <ARInvoice.curyInfoID> > > >, Where <ARInvoice.scheduleID, Equal <Required <ARInvoice.scheduleID> >, And <ARInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID)) { docgraph.Clear(); docgraph.customer.Current = (Customer)res; ARInvoice apdoc = (ARInvoice)res; CurrencyInfo info = (CurrencyInfo)res; CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info); new_info.CuryInfoID = null; new_info = docgraph.currencyinfo.Insert(new_info); ARInvoice new_ardoc = PXCache <ARInvoice> .CreateCopy(apdoc); new_ardoc.CuryInfoID = new_info.CuryInfoID; new_ardoc.DocDate = sdet.ScheduledDate; new_ardoc.FinPeriodID = sdet.ScheduledPeriod; new_ardoc.TranPeriodID = null; new_ardoc.DueDate = null; new_ardoc.DiscDate = null; new_ardoc.CuryOrigDiscAmt = null; new_ardoc.OrigDiscAmt = null; new_ardoc.RefNbr = null; new_ardoc.Scheduled = false; new_ardoc.CuryLineTotal = 0m; new_ardoc.CuryVatTaxableTotal = 0m; new_ardoc.CuryVatExemptTotal = 0m; new_ardoc.NoteID = null; bool forceClear = false; bool clearPM = false; if (new_ardoc.PMInstanceID.HasValue) { PXResult <CustomerPaymentMethod, CA.PaymentMethod> pmiResult = (PXResult <CustomerPaymentMethod, CA.PaymentMethod>) PXSelectJoin <CustomerPaymentMethod, InnerJoin <CA.PaymentMethod, On <CA.PaymentMethod.paymentMethodID, Equal <CustomerPaymentMethod.paymentMethodID> > >, Where <CustomerPaymentMethod.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(docgraph, new_ardoc.PMInstanceID); if (pmiResult != null) { CustomerPaymentMethod pmInstance = pmiResult; CA.PaymentMethod paymentMethod = pmiResult; if (pmInstance == null || pmInstance.IsActive != true || paymentMethod.IsActive != true || paymentMethod.UseForAR != true) { clearPM = true; forceClear = true; } } else { clearPM = true; forceClear = true; } } else { if (string.IsNullOrEmpty(new_ardoc.PaymentMethodID) == false) { CA.PaymentMethod pm = PXSelect <CA.PaymentMethod, Where <CA.PaymentMethod.paymentMethodID, Equal <Required <CA.PaymentMethod.paymentMethodID> > > > .Select(docgraph, new_ardoc.PaymentMethodID); if (pm == null || pm.IsActive != true || pm.UseForAR != true) { clearPM = true; forceClear = true; } } } if (clearPM) { new_ardoc.PMInstanceID = null; new_ardoc.PaymentMethodID = null; new_ardoc.CashAccountID = null; } new_ardoc = docgraph.Document.Insert(new_ardoc); //force creditrule back docgraph.customer.Current = (Customer)res; if (forceClear == true) { ARInvoice copy = PXCache <ARInvoice> .CreateCopy(new_ardoc); copy.PMInstanceID = null; copy.PaymentMethodID = null; copy.CashAccountID = null; new_ardoc = docgraph.Document.Update(copy); } AddressAttribute.CopyRecord <ARInvoice.billAddressID>(docgraph.Document.Cache, new_ardoc, apdoc, false); ContactAttribute.CopyRecord <ARInvoice.billContactID>(docgraph.Document.Cache, new_ardoc, apdoc, false); TaxAttribute.SetTaxCalc <ARTran.taxCategoryID, ARTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); PXNoteAttribute.SetNote(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetNote(Caches[typeof(ARInvoice)], apdoc)); PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_ardoc, PXNoteAttribute.GetFileNotes(Caches[typeof(ARInvoice)], apdoc)); foreach (ARTran aptran in PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr)) { ARTran new_aptran = PXCache <ARTran> .CreateCopy(aptran); new_aptran.RefNbr = null; new_aptran.CuryInfoID = null; docgraph.Transactions.Insert(new_aptran); } foreach (ARTaxTran tax in PXSelect <ARTaxTran, Where <ARTaxTran.tranType, Equal <Required <ARTaxTran.tranType> >, And <ARTaxTran.refNbr, Equal <Required <ARTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr)) { ARTaxTran new_artax = new ARTaxTran(); new_artax.TaxID = tax.TaxID; new_artax = docgraph.Taxes.Insert(new_artax); if (new_artax != null) { new_artax = PXCache <ARTaxTran> .CreateCopy(new_artax); new_artax.TaxRate = tax.TaxRate; new_artax.CuryTaxableAmt = tax.CuryTaxableAmt; new_artax.CuryTaxAmt = tax.CuryTaxAmt; new_artax = docgraph.Taxes.Update(new_artax); } } docgraph.Save.Press(); } s.LastRunDate = sdet.ScheduledDate; Running_Schedule.Cache.Update(s); } using (PXTransactionScope ts = new PXTransactionScope()) { Running_Schedule.Cache.Persist(PXDBOperation.Update); ts.Complete(this); } Running_Schedule.Cache.Persisted(false); }
public virtual void GenerateProc(Schedule s, short Times, DateTime runDate) { List <ScheduleDet> sd = GL.ScheduleProcess.MakeSchedule(this, s, Times, runDate); APInvoiceEntry docgraph = CreateGraph(); foreach (ScheduleDet sdet in sd) { foreach (PXResult <APInvoice, Vendor, CurrencyInfo> res in PXSelectJoin <APInvoice, InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >, Where <APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >, And <APInvoice.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID)) { docgraph.Clear(); docgraph.vendor.Current = (Vendor)res; APInvoice apdoc = (APInvoice)res; CurrencyInfo info = (CurrencyInfo)res; CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info); new_info.CuryInfoID = null; new_info = docgraph.currencyinfo.Insert(new_info); APInvoice new_apdoc = PXCache <APInvoice> .CreateCopy(apdoc); new_apdoc.CuryInfoID = new_info.CuryInfoID; new_apdoc.DocDate = sdet.ScheduledDate; new_apdoc.FinPeriodID = sdet.ScheduledPeriod; new_apdoc.TranPeriodID = null; new_apdoc.DueDate = null; new_apdoc.DiscDate = null; new_apdoc.PayDate = null; new_apdoc.CuryOrigDiscAmt = null; new_apdoc.OrigDiscAmt = null; new_apdoc.RefNbr = null; new_apdoc.Scheduled = false; new_apdoc.CuryLineTotal = 0m; new_apdoc.CuryVatTaxableTotal = 0m; new_apdoc.CuryVatExemptTotal = 0m; new_apdoc.NoteID = null; new_apdoc = docgraph.Document.Insert(new_apdoc); TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); PXNoteAttribute.SetNote(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetNote(Caches[typeof(APInvoice)], apdoc)); PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, new_apdoc, PXNoteAttribute.GetFileNotes(Caches[typeof(APInvoice)], apdoc)); foreach (APTran aptran in PXSelect <APTran, Where <APTran.tranType, Equal <Required <APTran.tranType> >, And <APTran.refNbr, Equal <Required <APTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr)) { APTran new_aptran = PXCache <APTran> .CreateCopy(aptran); new_aptran.RefNbr = null; new_aptran.CuryInfoID = null; docgraph.Transactions.Insert(new_aptran); } foreach (APTaxTran tax in PXSelect <APTaxTran, Where <APTaxTran.tranType, Equal <Required <APTaxTran.tranType> >, And <APTaxTran.refNbr, Equal <Required <APTaxTran.refNbr> > > > > .Select(docgraph, apdoc.DocType, apdoc.RefNbr)) { APTaxTran new_aptax = new APTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = docgraph.Taxes.Insert(new_aptax); if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt; new_aptax.CuryTaxAmt = tax.CuryTaxAmt; new_aptax = docgraph.Taxes.Update(new_aptax); } } docgraph.Save.Press(); } s.LastRunDate = sdet.ScheduledDate; Running_Schedule.Cache.Update(s); } using (PXTransactionScope ts = new PXTransactionScope()) { Running_Schedule.Cache.Persist(PXDBOperation.Update); ts.Complete(this); } Running_Schedule.Cache.Persisted(false); }