diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 802adb7..3dd1483 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -1841,7 +1841,8 @@ namespace AyaNova.PlugIn.V8 dItem.vendorPartNumber = pi.WorkorderItemPartRequestID.ToString();//temp holder for guid, not used in v7 so available PoItemPartRequestMap.Add(new poitemtowoitempartrequest() { v7woitempartrequestid = pi.WorkorderItemPartRequestID, v7poid = c.ID }); } - + + foreach (PurchaseOrderReceipt r in receipts) { @@ -1856,7 +1857,7 @@ namespace AyaNova.PlugIn.V8 { //Note: in v7 must receive to same warehouse as ordered, no option otherwise so no need //to worry about that here - //No, use the poitem value above, this one can be wonky dItem.quantityReceived += ri.QuantityReceived; + //No, use the poitem value above, this one can be wonky dItem.quantityReceived += ri.QuantityReceived; dItem.receivedCost = ri.ReceiptCost;//yes, last receipt wins for cost foreach (PartSerial sn in ri.SerialNumbers) sbSerials.Append(sn.SerialNumber + ", "); @@ -2907,6 +2908,8 @@ namespace AyaNova.PlugIn.V8 progress.SubOp("WorkorderItemPartRequest " + wipr.ID.ToString()); if (wipr.Quantity == 0) continue; + JObject dPO = null; + JObject v8poitemtoupdate = null; dynamic dwipr = new JObject(); dwipr.workOrderId = RavenId; dwipr.workorderItemId = ravenwoitemid; @@ -2919,15 +2922,47 @@ namespace AyaNova.PlugIn.V8 else dwipr.partId = tryPartId; dwipr.partWarehouseId = Getv7v8IdMap(wipr.PartWarehouseID, "warehouse"); + + poitemtowoitempartrequest pto = PoItemPartRequestMap.FirstOrDefault(z => z.v7woitempartrequestid == wipr.ID); + if (pto != null) + { + //tag this part request with the v8 poitem id that matches + //get v8 po id + //fetch po + //iterate po and look for item with the vendorpartnumber set to this woitempartid by guid string + //update the po item with the raven partrequestid + //save po + long? v8poid = Getv7v8IdMapNullOk(pto.v7poid); + if (v8poid != null) + { + var a = await util.GetAsync("purchase-order/" + v8poid.ToString()); + dPO = (JObject)a.ObjectResponse["data"]; + if (dPO != null) + { + v8poitemtoupdate = (JObject)dPO["items"].FirstOrDefault(z => (string)z["vendorPartNumber"] == wipr.ID.ToString()); + if (v8poitemtoupdate != null) + { + //update the woitempart request purchase order item id + dwipr.purchaseOrderItemId = (long)v8poitemtoupdate["id"]; + + } + } + } + } + //TODO: if migrate purchase orders this is reqd // dwipr.purchaseOrderItemId = Getv7v8IdMapNullOk(wipr.PurchaseOrderItemID); - await util.PostAsync("workorder/items/part-requests", dwipr.ToString()); - //todo: consult map to see if this workorderitempart requet has any poitems to tag and - //if so fetch the po from v8, look in the vnedorpartnumber of items for the mtching guid of this v7woitempart request - //clear that vendpartnumber but set the long?woitempartrequestid and save the po - //also it apears needs reverse here as well to back link so need to update this part request with the poitem id I think + long v8partrequestid = util.IdFromResponse(await util.PostAsync("workorder/items/part-requests", dwipr.ToString())); + + //SAVE PO if fetched and updated here + if (dPO != null && v8poitemtoupdate != null) + { + //save the PO + v8poitemtoupdate["workorderItemPartRequestId"] = v8partrequestid; + v8poitemtoupdate["vendorPartNumber"] = null; + await util.PutAsync("purchase-order", dPO.ToString()); + } - //todo: this PoItemPartRequestMap } //##### WORKORDER ITEM LOANERS diff --git a/source/WinFormApp/config.txt b/source/WinFormApp/config.txt index 479af94..5929bf1 100644 --- a/source/WinFormApp/config.txt +++ b/source/WinFormApp/config.txt @@ -1,19 +1,19 @@ - + - DataBase FireBird ServerType=1;DataBase=C:\data\AyaNova\database\AYANOVA.fdb;Dialect=3; - --> +