public void createReturnOrder(PurchTable _purchtable)
{
SalesLine salesLine;
SalesTable salesTable, salesTableloc;
SalesParameters salesParameters;
ReturnPeriodOfValidity periodofValid;
SON_AttachmentELMOInvoice attachmentELMOInvoiceloc, attachmentELMOSumQty,SON_AttachmentELMOInvoice;
SON_ELMOSummaryInvoice SON_ELMOSummaryInvoice;
AxSalesTable axsalesTable;
AxSalesLine axSalesLine;
SalesFormLetter salesFormLetter;
PurchTable PurchTableLocal;
PurchFormLetter purchFormLetter;
SON_ELMOISalesTable SON_ELMOISalesTable;
SON_DeliveryNote SON_DeliveryNote;
try
{
salesParameters = SalesParameters::find();
periodofValid = salesParameters.ReturnPeriodOfValidity;
select SON_ELMOSummaryInvoice where SON_ELMOSummaryInvoice.AXPONumber == _purchtable.PurchId;
while select SON_AttachmentELMOInvoice group by StoreID
where SON_AttachmentELMOInvoice.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& SON_AttachmentELMOInvoice.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
{
//insert sales table
{
salesParameters = SalesParameters::find();
periodofValid = salesParameters.ReturnPeriodOfValidity;
salesTable.SON_StoreId = SON_AttachmentELMOInvoice.StoreID;
salesTable.SON_VendAccount = _purchTable.OrderAccount;
salesTable.SON_PBSalesOrder=NoYes::Yes;
salesTable.CustAccount = RetailStoreTable::find(SON_AttachmentELMOInvoice.StoreID).SON_DefaultCustAccount;
salesTable.InvoiceAccount = salesTable.CustAccount;
salesTable.SalesId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
salesTable.ReturnItemNum = salesTable.SalesId;
salesTable.SalesType = SalesType::ReturnItem;
salesTable.ReturnStatus = ReturnStatusHeader::Created;
salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::None;
salesTable.SON_InvStkTrans = NoYes::Yes;
salesTable.ShippingDateRequested = today();
salesTable.ShippingDateConfirmed = salesTable.ShippingDateRequested;
salesTable.ReceiptDateConfirmed = salesTable.ShippingDateRequested;
salesTable.ReceiptDateRequested = salesTable.ShippingDateRequested;
salesTable.initFromCustTable();
salesTable.ReturnDeadline = salesTable.ShippingDateRequested;
salesTable.InventLocationId = InventParameters::find().SON_DD;
salesTable.InventSiteId = InventLocation::find(salesTable.InventLocationId).InventSiteId;
salesTable.DefaultDimension = SON_InventStockTransfer::getStoreCostCenter(salesTable.SON_StoreId);
axsalesTable = AxSalesTable::newSalesTable(salesTable);
axsalesTable.parmSON_StoreOrderType(SON_StoreOrderType::ELMO);
axsalesTable.doSave();
SON_ELMOISalesTable.clear();
SON_ELMOISalesTable.PurchId = _purchTable.PurchId;
SON_ELMOISalesTable.SalesId = salesTable.SalesId;
SON_ELMOISalesTable.CustAccount = salesTable.CustAccount;
SON_ELMOISalesTable.insert();
}
//insert lines
while select attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.StoreID == SON_AttachmentELMOInvoice.StoreID
&& attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
{
//insert saleslines
salesLine.clear();
salesLine.initValue();
salesLine.initFromSalesTable(salesTable);
salesLine.initFromCustTable();
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = this.GetEANCode(attachmentELMOInvoiceloc);
salesLine.SON_EANCode = attachmentELMOInvoiceloc.EANCode;
salesLine.SalesUnit = InventTableModule::find(salesLine.ItemId, ModuleInventPurchSales::Invent).UnitId;
salesLine.DefaultDimension = SON_InventStockTransfer::salesLineDefaultDimension(salesTable, InventTable::find(salesLine.ItemId));
salesLine.SalesQty = attachmentELMOInvoiceloc.InvoicedQty;
salesLine.ExpectedRetQty = salesLine.SalesQty;
salesLine.LineAmount = attachmentELMOInvoiceloc.VendorInvoiceAmt;
salesLine.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
axSalesLine = AxSalesLine::newSalesLine(salesLine);
axSalesLine.Save();
}//while select attachmentELMOInvoiceloc
attachmentELMOInvoiceloc.clear();
select firstOnly attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate;
// for client testing
delete_from SON_DeliveryNote;
SON_DeliveryNote.DeliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
SON_DeliveryNote.insert();
// for client testing
ttsBegin;
select forUpdate salesTableloc where salesTableloc.SalesId == salesTable.SalesId;
salesTableloc.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
salesTableloc.doUpdate();
ttsCommit;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(SalesTable::find(salesTable.SalesId), today());
changeCompany (salesTable.InterCompanyCompanyId)
{
select crossCompany PurchTableLocal
where PurchTableLocal.dataAreaId == salesTable.InterCompanyCompanyId
&& PurchTableLocal.PurchId == salesTable.InterCompanyPurchId;
// PO confirmation
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(PurchTableLocal, strFmt("POConfirm_%1",PurchTableLocal.PurchId));
info(strFmt("purchase order %1 confirmed succssfully.",PurchTableLocal.PurchId));
// PO packing slip
// purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
// purchFormLetter.update(PurchTableLocal, strFmt("POPack_%1", PurchTableLocal.PurchId));
// this.partialPOPacking(PurchTableLocal.PurchId);
// info(strFmt("purchase order %1 packing slip posted succssfully.",PurchTableLocal.PurchId));
}//change company
this.createRegisterline(salesTable);
this.partialSOPacking(salesTable, _purchTable );
}
}
catch
{
warning("error found while creating sales order for purchase order");
}
// return isSuccess;
}
{
SalesLine salesLine;
SalesTable salesTable, salesTableloc;
SalesParameters salesParameters;
ReturnPeriodOfValidity periodofValid;
SON_AttachmentELMOInvoice attachmentELMOInvoiceloc, attachmentELMOSumQty,SON_AttachmentELMOInvoice;
SON_ELMOSummaryInvoice SON_ELMOSummaryInvoice;
AxSalesTable axsalesTable;
AxSalesLine axSalesLine;
SalesFormLetter salesFormLetter;
PurchTable PurchTableLocal;
PurchFormLetter purchFormLetter;
SON_ELMOISalesTable SON_ELMOISalesTable;
SON_DeliveryNote SON_DeliveryNote;
try
{
salesParameters = SalesParameters::find();
periodofValid = salesParameters.ReturnPeriodOfValidity;
select SON_ELMOSummaryInvoice where SON_ELMOSummaryInvoice.AXPONumber == _purchtable.PurchId;
while select SON_AttachmentELMOInvoice group by StoreID
where SON_AttachmentELMOInvoice.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& SON_AttachmentELMOInvoice.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
{
//insert sales table
{
salesParameters = SalesParameters::find();
periodofValid = salesParameters.ReturnPeriodOfValidity;
salesTable.SON_StoreId = SON_AttachmentELMOInvoice.StoreID;
salesTable.SON_VendAccount = _purchTable.OrderAccount;
salesTable.SON_PBSalesOrder=NoYes::Yes;
salesTable.CustAccount = RetailStoreTable::find(SON_AttachmentELMOInvoice.StoreID).SON_DefaultCustAccount;
salesTable.InvoiceAccount = salesTable.CustAccount;
salesTable.SalesId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
salesTable.ReturnItemNum = salesTable.SalesId;
salesTable.SalesType = SalesType::ReturnItem;
salesTable.ReturnStatus = ReturnStatusHeader::Created;
salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::None;
salesTable.SON_InvStkTrans = NoYes::Yes;
salesTable.ShippingDateRequested = today();
salesTable.ShippingDateConfirmed = salesTable.ShippingDateRequested;
salesTable.ReceiptDateConfirmed = salesTable.ShippingDateRequested;
salesTable.ReceiptDateRequested = salesTable.ShippingDateRequested;
salesTable.initFromCustTable();
salesTable.ReturnDeadline = salesTable.ShippingDateRequested;
salesTable.InventLocationId = InventParameters::find().SON_DD;
salesTable.InventSiteId = InventLocation::find(salesTable.InventLocationId).InventSiteId;
salesTable.DefaultDimension = SON_InventStockTransfer::getStoreCostCenter(salesTable.SON_StoreId);
axsalesTable = AxSalesTable::newSalesTable(salesTable);
axsalesTable.parmSON_StoreOrderType(SON_StoreOrderType::ELMO);
axsalesTable.doSave();
SON_ELMOISalesTable.clear();
SON_ELMOISalesTable.PurchId = _purchTable.PurchId;
SON_ELMOISalesTable.SalesId = salesTable.SalesId;
SON_ELMOISalesTable.CustAccount = salesTable.CustAccount;
SON_ELMOISalesTable.insert();
}
//insert lines
while select attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.StoreID == SON_AttachmentELMOInvoice.StoreID
&& attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
{
//insert saleslines
salesLine.clear();
salesLine.initValue();
salesLine.initFromSalesTable(salesTable);
salesLine.initFromCustTable();
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = this.GetEANCode(attachmentELMOInvoiceloc);
salesLine.SON_EANCode = attachmentELMOInvoiceloc.EANCode;
salesLine.SalesUnit = InventTableModule::find(salesLine.ItemId, ModuleInventPurchSales::Invent).UnitId;
salesLine.DefaultDimension = SON_InventStockTransfer::salesLineDefaultDimension(salesTable, InventTable::find(salesLine.ItemId));
salesLine.SalesQty = attachmentELMOInvoiceloc.InvoicedQty;
salesLine.ExpectedRetQty = salesLine.SalesQty;
salesLine.LineAmount = attachmentELMOInvoiceloc.VendorInvoiceAmt;
salesLine.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
axSalesLine = AxSalesLine::newSalesLine(salesLine);
axSalesLine.Save();
}//while select attachmentELMOInvoiceloc
attachmentELMOInvoiceloc.clear();
select firstOnly attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
&& attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate;
// for client testing
delete_from SON_DeliveryNote;
SON_DeliveryNote.DeliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
SON_DeliveryNote.insert();
// for client testing
ttsBegin;
select forUpdate salesTableloc where salesTableloc.SalesId == salesTable.SalesId;
salesTableloc.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
salesTableloc.doUpdate();
ttsCommit;
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(SalesTable::find(salesTable.SalesId), today());
changeCompany (salesTable.InterCompanyCompanyId)
{
select crossCompany PurchTableLocal
where PurchTableLocal.dataAreaId == salesTable.InterCompanyCompanyId
&& PurchTableLocal.PurchId == salesTable.InterCompanyPurchId;
// PO confirmation
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(PurchTableLocal, strFmt("POConfirm_%1",PurchTableLocal.PurchId));
info(strFmt("purchase order %1 confirmed succssfully.",PurchTableLocal.PurchId));
// PO packing slip
// purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
// purchFormLetter.update(PurchTableLocal, strFmt("POPack_%1", PurchTableLocal.PurchId));
// this.partialPOPacking(PurchTableLocal.PurchId);
// info(strFmt("purchase order %1 packing slip posted succssfully.",PurchTableLocal.PurchId));
}//change company
this.createRegisterline(salesTable);
this.partialSOPacking(salesTable, _purchTable );
}
}
catch
{
warning("error found while creating sales order for purchase order");
}
// return isSuccess;
}
No comments:
Post a Comment