-
-
Save anonymous/145c009b07bd8470876c to your computer and use it in GitHub Desktop.
Sage BOI SalesOrderController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ItemCodeLookup.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
using ItemCodeLookup.App_Start; | |
namespace ItemCodeLookup.Controllers | |
{ | |
public class SalesOrderController : ApiController | |
{ | |
[HttpPost] | |
public HttpResponseMessage CreateSalesOrder(SalesOrder newOrder) | |
{ | |
DateTime timestamp = DateTime.Now; | |
string dateString = timestamp.ToString("yyyyMMdd"); | |
using (var pvx = new DispatchObject("ProvideX.Script")) | |
{ | |
pvx.InvokeMethod("Init", @"\\Mcs-erp-100\erp-100-2013\MAS90\Home"); | |
using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session"))) | |
{ | |
int userSuccess = (int)oSS.InvokeMethod("nSetUser", "vi", "<Passwrord redacted>"); | |
int companySuccess = (int)oSS.InvokeMethod("nSetCompany", "OLD"); | |
int moduleSuccess = (int)oSS.InvokeMethod("nSetModule", "S/O"); | |
int dateSuccess = (int)oSS.InvokeMethod("nSetDate", "S/O", dateString); | |
var sessionObj = oSS.GetObject(); | |
var salesOrderObj = pvx.InvokeMethod("NewObject", "SO_SalesOrder_bus", sessionObj); | |
using (var soHeader = new DispatchObject(salesOrderObj)) | |
{ | |
soHeader.InvokeMethod("nSetKey", newOrder.SalesOrderNo); | |
soHeader.InvokeMethod("nSetValue", "ARDivisionNo$", newOrder.ArDivisionNo); | |
soHeader.InvokeMethod("nSetValue", "CustomerNo$", newOrder.CustomerNo); | |
soHeader.InvokeMethod("nSetValue", "BillToName$", newOrder.BillToName); | |
soHeader.InvokeMethod("nSetValue", "BillToAddress1$", newOrder.BillToAddress1); | |
soHeader.InvokeMethod("nSetValue", "BillToAddress2$", newOrder.BillToAddress2); | |
soHeader.InvokeMethod("nSetValue", "BillToAddress3$", newOrder.BillToAddress3); | |
soHeader.InvokeMethod("nSetValue", "BillToCity$", newOrder.BillToCity); | |
soHeader.InvokeMethod("nSetValue", "BillToState$", newOrder.BillToState); | |
soHeader.InvokeMethod("nSetValue", "BillToZipCode$", newOrder.BillToZipCode); | |
soHeader.InvokeMethod("nSetValue", "ShipToName$", newOrder.ShipToName); | |
soHeader.InvokeMethod("nSetValue", "ShipToAddress1$", newOrder.ShipToAddress1); | |
soHeader.InvokeMethod("nSetValue", "ShipToAddress2$", newOrder.ShipToAddress2); | |
soHeader.InvokeMethod("nSetValue", "ShipToAddress3$", newOrder.ShipToAddress3); | |
soHeader.InvokeMethod("nSetValue", "ShipToCity$", newOrder.ShipToCity); | |
soHeader.InvokeMethod("nSetValue", "ShipToState$", newOrder.ShipToState); | |
soHeader.InvokeMethod("nSetValue", "ShipToZipCode$", newOrder.ShipToZipCode); | |
soHeader.InvokeMethod("nSetValue", "TaxSchedule$", newOrder.TaxSchedule); | |
soHeader.InvokeMethod("nSetValue", "FreightAmount", newOrder.FreightAmount); | |
soHeader.InvokeMethod("nSetValue", "ShipVia$", newOrder.ShipVia); | |
soHeader.InvokeMethod("nSetValue", "WarehouseCode$", newOrder.WarehouseCode); | |
bool lineFail = false; | |
var soLines = new DispatchObject(soHeader.GetProperty("oLines")); | |
foreach (LineItem newLine in newOrder.LineItems) | |
{ | |
soLines.InvokeMethod("nAddLine"); | |
soLines.InvokeMethod("nSetValue", "ItemCode$", newLine.ItemCode); | |
soLines.InvokeMethod("nSetValue", "ItemType$", newLine.ItemType); | |
soLines.InvokeMethod("nSetValue", "WarehouseCode$", newLine.WarehouseCode); | |
soLines.InvokeMethod("nSetValue", "QuantityOrdered%", newLine.QuantityOrdered); | |
soLines.InvokeMethod("nSetValue", "UnitPrice", newLine.UnitPrice); | |
soLines.InvokeMethod("nSetValue", "UnitCost", newLine.UnitCost); | |
soLines.InvokeMethod("nSetValue", "CommentText$", newLine.Comment); | |
soLines.InvokeMethod("nSetValue", "ItemCodeDescription$", newLine.ItemCodeDescription); | |
soLines.InvokeMethod("nSetValue", "VendorNo$", newLine.VendorNo); | |
int lineError = (int)soLines.InvokeMethod("nWrite"); | |
if (lineError == 1) | |
{ | |
lineFail = true; | |
} | |
} | |
int orderError = (int)soHeader.InvokeMethod("nWrite"); | |
if (lineFail || orderError == 1) | |
{ | |
return new HttpResponseMessage(HttpStatusCode.NotAcceptable); | |
} | |
else | |
{ | |
return new HttpResponseMessage(HttpStatusCode.Created); | |
} | |
} | |
} | |
} | |
} | |
[HttpGet] | |
public string FindCustomer() | |
{ | |
string dateString = DateTime.Now.ToString("yyyyMMdd"); | |
using (var pvx = new DispatchObject("ProvideX.Script")) | |
{ | |
pvx.InvokeMethod("Init", @"\\Mcs-erp-100\erp-100-2013\MAS90\Home"); | |
using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session"))) | |
{ | |
int userSuccess = (int)oSS.InvokeMethod("nSetUser", "pur", "*theman*"); | |
int companySuccess = (int)oSS.InvokeMethod("nSetCompany", "OLD"); | |
int moduleSuccess = (int)oSS.InvokeMethod("nSetModule", "C/I"); | |
int dateSuccess = (int)oSS.InvokeMethod("nSetDate", "A/R", dateString); | |
var sessionObj = oSS.GetObject(); | |
using (DispatchObject arObjc = new DispatchObject(pvx.InvokeMethod("NewObject", "CI_ItemCode_bus", sessionObj))) | |
{ | |
return "success"; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment