Мы выполняем настройку для создания счетов-фактур сторонних производителей для одного из моих клиентов.
мы настроили таблицу вкладок (Сведения о плательщике) на экране продаж (SO301000)
нам нужно создать счета на основе количества строк на вкладке «Сведения о плательщике», при нажатии кнопки «Подготовить счет».
Я могу создать несколько счетов.
мы сталкиваемся с одной проблемой:
Если товар имеет Распределение (Lot serialnbr), то я не могу перенести qty поданные данные из SO в Invoice. Он изменяет qty на 1, даже если в SOLine у нас больше одного qty.
Я остановил создание базового счета ERP, я реализовал пользовательский код для создания счетов.
Я должен переопределить метод PrepareInvoice.
открытый делегат IEnumerable PrepareInvoiceDelegate (адаптер PXAdapter);
Пожалуйста, помогите мне, как реализовать распределение в этом или как переопределить метод счета создания.
Пожалуйста, найдите прикрепленные скриншоты.
Настраиваемая таблица: TSCustomPayerDetails
Код:
public delegate IEnumerable PrepareInvoiceDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable PrepareInvoice(PXAdapter adapter, PrepareInvoiceDelegate baseMethod)
{
// bool SelfPayer = false;
SOInvoiceEntry graph = PXGraph.CreateInstance<SOInvoiceEntry>();
SOOrderEntry ord = PXGraph.CreateInstance<SOOrderEntry>();
SOOrderEntryTSExtension ordext = ord.GetExtension<SOOrderEntryTSExtension>();
ServiceOrderEntry Sergraph = PXGraph.CreateInstance<ServiceOrderEntry>();
ServiceOrderEntryTSExtension SergraphExt = Sergraph.GetExtension<ServiceOrderEntryTSExtension>();
var row = (SOOrder)Base.Document.Current;
if (this.SalesPayer != null && this.SalesPayer.Select().Count > 0)
{
AccountMaint Accountgraph = PXGraph.CreateInstance<AccountMaint>();
TSCustomPayerDetails SelfBussinessAccountAmount = PXSelect<TSCustomPayerDetails,
Where<TSCustomPayerDetails.sONbr, Equal<Required<TSCustomPayerDetails.sONbr>>, And<TSCustomPayerDetails.selfPay, IsNotNull>>>.Select(Base, row.OrderNbr);
#region Self Payer with 0 invoice
if (SelfBussinessAccountAmount == null)
{
var proj = new ARInvoice();
proj = graph.Document.Insert(proj);
proj.DocDesc = row.OrderDesc;
proj.CustomerID = row.CustomerID;
proj = graph.Document.Update(proj);
graph.Persist();
if (Base.Transactions.Select().Count > 0)
{
foreach (SOLine arTranBase in Base.Transactions.Select())
{
var arTran1 = new ARTran();
arTran1 = graph.Transactions.Insert(arTran1);
arTran1.RefNbr = graph.Document.Current.RefNbr;
arTran1.TranType = "INV";
// arTran1.SOOrderType = "IN";
// arTran1.TranDesc = "Self Payer Business Account Name" + row.OrderDesc;
//if (arTranBase.OrderNbr != null)
// arTran1.SOOrderNbr = arTranBase.OrderNbr;
arTran1.UOM = arTranBase.UOM;
arTran1.InventoryID = arTranBase.InventoryID;
arTran1.LocationID = arTranBase.LocationID;
// arTran1.LotSerialNbr = arTranBase.LotSerialNbr;
arTran1.SiteID = arTranBase.SiteID;
arTran1.TranDesc = arTranBase.TranDesc;
arTran1.Qty = arTranBase.OrderQty;
// arTran1.CuryUnitPrice = arTranBase.CuryUnitPrice;
arTran1.CuryUnitPrice = arTranBase.CuryLineAmt;
arTran1.ManualDisc = arTranBase.ManualDisc;
//arTran1.SOOrderNbr = arTranBase.OrderNbr;
// arTran.UnitPrice = salesPayer.Amount;
// arTran.AccountID = salesPayer.Account;
arTran1 = graph.Transactions.Update(arTran1);
graph.Persist();
}
}
foreach (TSCustomPayerDetails PayerBussinessAccount in PXSelect<TSCustomPayerDetails,
Where<TSCustomPayerDetails.sONbr, Equal<Required<TSCustomPayerDetails.sONbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Base, row.OrderNbr))
{
if (PayerBussinessAccount != null)
{
//var arTran = new ARTran();
//arTran = graph.Transactions.Insert(arTran);
//arTran.RefNbr = graph.Document.Current.RefNbr;
var arTran = new ARTran();
ARTran TranItem = PXSelectOrderBy<ARTran,
OrderBy<
Desc<ARTran.refNbr>>>
.SelectWindowed(graph, 0, 1);
{
graph.Document.Current = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>.Select(Base, TranItem.RefNbr);
arTran = graph.Transactions.Insert(arTran);
arTran.RefNbr = TranItem.RefNbr;
}
BAccount Customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<SOOrder.customerID>>>>.Select(Base, row.CustomerID);
if (Customer != null)
{
if (SelfBussinessAccountAmount != null)
{
SelfBussinessAccountAmount.Account = Customer.AcctCD;
SelfBussinessAccountAmount.AccountName = Customer.AcctName;
}
// SelfPayerBussinessAccountName = Customer.AcctName;
if (PayerBussinessAccount != null)
arTran.TranDesc = "Less Payment made by " + PayerBussinessAccount.AccountName;
}
Account tsAccountID = PXSelect<Account, Where<Account.accountCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsAccountID != null)
{
arTran.AccountID = tsAccountID.AccountID;
}
Sub tsSubAccountData = PXSelect<Sub, Where<Sub.subCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsSubAccountData != null)
{
arTran.SubID = tsSubAccountData.SubID;
}
arTran.TranType = "INV";
// arTran.TranDesc = "Self Payer Business Account Name" + row.OrderDesc;
arTran.Qty = 1;
if (PayerBussinessAccount != null)
// arTran.CuryUnitPrice = -1 * SelfBussinessAccountAmount.Amount;
arTran.CuryUnitPrice = -1 * PayerBussinessAccount.Amount;
arTran = graph.Transactions.Update(arTran);
graph.Persist();
//// TSCustomPayerDetails PayerBussinessAccount1 = PXSelect<TSCustomPayerDetails,
////Where<TSCustomPayerDetails.sONbr, Equal<Required<TSCustomPayerDetails.sONbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Base, row.OrderNbr);
TSCustomPayerDetails customPayer = new TSCustomPayerDetails();
customPayer = this.SalesPayer.Insert(customPayer);
customPayer.InvoiceNbr = graph.Document.Current.RefNbr;
customPayer.SelfPay = true;
customPayer.Amount = 0;
BAccount Customer1 = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<SOOrder.customerID>>>>.Select(Base, row.CustomerID);
if (Customer1 != null)
{
if (customPayer != null)
{
customPayer.Account = Customer.AcctCD;
customPayer.AccountName = Customer.AcctName;
}
}
customPayer = this.SalesPayer.Update(customPayer);
Base.Persist();
}
}
}
#endregion
#region Self Payer invoice
if (SelfBussinessAccountAmount != null)
{
var proj = new ARInvoice();
proj = graph.Document.Insert(proj);
proj.DocDesc = row.OrderDesc;
proj.CustomerID = row.CustomerID;
proj = graph.Document.Update(proj);
graph.Persist();
if (Base.Transactions.Select().Count > 0)
{
foreach (SOLine arTranBase in Base.Transactions.Select())
{
var arTran1 = new ARTran();
arTran1 = graph.Transactions.Insert(arTran1);
arTran1.RefNbr = graph.Document.Current.RefNbr;
arTran1.TranType = "INV";
// arTran1.SOOrderType = "IN";
// arTran1.TranDesc = "Self Payer Business Account Name" + row.OrderDesc;
//if (arTranBase.OrderNbr != null)
// arTran1.SOOrderNbr = arTranBase.OrderNbr;
arTran1.UOM = arTranBase.UOM;
arTran1.InventoryID = arTranBase.InventoryID;
arTran1.LocationID = arTranBase.LocationID;
// arTran1.LotSerialNbr = arTranBase.LotSerialNbr;
arTran1.SiteID = arTranBase.SiteID;
arTran1.Qty = arTranBase.OrderQty;
arTran1.TranDesc = arTranBase.TranDesc;
//arTran1.CuryUnitPrice = arTranBase.CuryUnitPrice;
arTran1.CuryUnitPrice = arTranBase.CuryLineAmt;
arTran1.ManualDisc = arTranBase.ManualDisc;
//arTran1.SOOrderNbr = arTranBase.OrderNbr;
// arTran.UnitPrice = salesPayer.Amount;
// arTran.AccountID = salesPayer.Account;
arTran1 = graph.Transactions.Update(arTran1);
graph.Persist();
}
}
graph = PXGraph.CreateInstance<SOInvoiceEntry>();
foreach (TSCustomPayerDetails PayerBussinessAccount in PXSelect<TSCustomPayerDetails,
Where<TSCustomPayerDetails.sONbr, Equal<Required<TSCustomPayerDetails.sONbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Base, row.OrderNbr))
{
if (PayerBussinessAccount != null)
{
var arTran = new ARTran();
ARTran TranItem = PXSelectOrderBy<ARTran,
OrderBy<
Desc<ARTran.refNbr>>>
.SelectWindowed(graph, 0, 1);
{
graph.Document.Current = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>.Select(Base, TranItem.RefNbr);
arTran = graph.Transactions.Insert(arTran);
arTran.RefNbr = TranItem.RefNbr;
}
BAccount Customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<SOOrder.customerID>>>>.Select(Base, row.CustomerID);
if (Customer != null)
{
if (SelfBussinessAccountAmount != null)
{
SelfBussinessAccountAmount.Account = Customer.AcctCD;
SelfBussinessAccountAmount.AccountName = Customer.AcctName;
}
// SelfPayerBussinessAccountName = Customer.AcctName;
if (PayerBussinessAccount != null)
arTran.TranDesc = "Less Payment made by " + PayerBussinessAccount.AccountName;
}
// arTran.Qty = 1;
Account tsAccountID = PXSelect<Account, Where<Account.accountCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsAccountID != null)
{
arTran.AccountID = tsAccountID.AccountID;
}
Sub tsSubAccountData = PXSelect<Sub, Where<Sub.subCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsSubAccountData != null)
{
arTran.SubID = tsSubAccountData.SubID;
}
arTran.TranType = "INV";
// arTran.TranDesc = "Self Payer Business Account Name" + row.OrderDesc;
arTran.Qty = 1;
if (PayerBussinessAccount != null)
// arTran.CuryUnitPrice = -1 * SelfBussinessAccountAmount.Amount;
arTran.CuryUnitPrice = -1 * PayerBussinessAccount.Amount;
arTran = graph.Transactions.Update(arTran);
graph.Persist();
// TSCustomPayerDetails PayerBussinessAccount1 = PXSelect<TSCustomPayerDetails,
//Where<TSCustomPayerDetails.sONbr, Equal<Required<TSCustomPayerDetails.sONbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Base, row.OrderNbr);
SelfBussinessAccountAmount.InvoiceNbr = graph.Document.Current.RefNbr;
SalesPayer.Update(SelfBussinessAccountAmount);
Base.Persist();
}
}
}
#endregion
#region 3rdparty payer invoice
foreach (TSCustomPayerDetails PartyPayerBussinessAccount in PXSelect<TSCustomPayerDetails,
Where<TSCustomPayerDetails.sONbr, Equal<Required<SOOrder.orderNbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Sergraph, row.OrderNbr))
{
if (PartyPayerBussinessAccount != null)
{
var proj1 = new ARInvoice();
proj1 = graph.Document.Insert(proj1);
proj1.DocDesc = row.OrderDesc;
// proj1.CustomerID = row.CustomerID;
BAccount PayerContact = PXSelect<BAccount, Where<BAccount.acctCD, Equal<Required<BAccount.acctCD>>>>.Select(Base, PartyPayerBussinessAccount.Account);
if (PayerContact != null)
{
proj1.CustomerID = PayerContact.BAccountID;
// proj1.BillContactID = PayerContact.BAccountID;
//arContact.ContactID = PayerContact.BAccountID;
//graph.Billing_Contact.Update(arContact);
//graph.Actions.PressSave();
}
proj1 = graph.Document.Update(proj1);
graph.Persist();
var arTran = new ARTran();
arTran = graph.Transactions.Insert(arTran);
arTran.RefNbr = graph.Document.Current.RefNbr;
// arTran.SOOrderNbr = PartyPayerBussinessAccount.SONbr;
// string SelfPayerBussinessAccountName1 = string.Empty;
BAccount Customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<SOOrder.customerID>>>>.Select(Base, row.CustomerID);
if (Customer != null)
{
// SelfPayerBussinessAccountName1 = Customer.AcctName;
// arTran.TranDesc = SelfPayerBussinessAccountName1 + "," + row.OrderDesc;
if (PartyPayerBussinessAccount != null)
{
if (row.OrderDesc != null)
arTran.TranDesc = PartyPayerBussinessAccount.AccountName + " , " + row.OrderDesc;
else
arTran.TranDesc = PartyPayerBussinessAccount.AccountName;
}
//PartyPayerBussinessAccount.Account = Customer.AcctCD;
//PartyPayerBussinessAccount.AccountName = Customer.AcctName;
}
//if (PartyPayerBussinessAccount != null)
//{
// arTran.TranDesc = PartyPayerBussinessAccount + " " + row.OrderDesc;
//}
arTran.Qty = 1;
Account tsAccountID = PXSelect<Account, Where<Account.accountCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsAccountID != null)
{
arTran.AccountID = tsAccountID.AccountID;
}
Sub tsSubAccountData = PXSelect<Sub, Where<Sub.subCD, Equal<tsAccount>>>.Select(Accountgraph);
if (tsSubAccountData != null)
{
arTran.SubID = tsSubAccountData.SubID;
}
// arTran.CuryUnitPrice = PartyPayerBussinessAccount.Amount;
if (PartyPayerBussinessAccount != null)
arTran.CuryUnitPrice = PartyPayerBussinessAccount.Amount;
arTran.TaxCategoryID = "EXEMPT";
arTran = graph.Transactions.Update(arTran);
graph.Persist();
// TSCustomPayerDetails PartyPayerBussinessAccount1 = PXSelect<TSCustomPayerDetails,
//Where<TSCustomPayerDetails.sONbr, Equal<Required<SOOrder.orderNbr>>, And<TSCustomPayerDetails.selfPay, IsNull>>>.Select(Base, row.OrderNbr);
PartyPayerBussinessAccount.InvoiceNbr = graph.Document.Current.RefNbr;
SergraphExt.ServicePayer.Update(PartyPayerBussinessAccount);
Sergraph.Actions.PressSave();
}
}
#endregion
SOInvoiceEntry ie = PXGraph.CreateInstance<SOInvoiceEntry>();
ie.Document.Current = ie.Document.Search<ARInvoice.docType, ARInvoice.refNbr>(((ARInvoice)graph.Document.Current).DocType, ((ARInvoice)graph.Document.Current).RefNbr, ((ARInvoice)graph.Document.Current).DocType);
throw new PXRedirectRequiredException(ie, "Invoice");
}
else
{
baseMethod(adapter);
}
return adapter.Get();
}
Пожалуйста, помогите мне в этом, где я иду не так или как справиться с этим сканированием.