Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
KGOrders
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cam Hayes
KGOrders
Commits
e344a789
Commit
e344a789
authored
Feb 03, 2025
by
Mac Stephens
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cam2' into mac3
parents
d00d0c68
ad1fa378
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
+112
-0
Lookup.ServiceImpl.pas
kgOrdersServer/Source/Lookup.ServiceImpl.pas
+112
-0
No files found.
kgOrdersServer/Source/Lookup.ServiceImpl.pas
View file @
e344a789
...
...
@@ -43,6 +43,7 @@ type
function
GenerateSubQuery
(
currStatus
:
string
):
string
;
function
AddCorrugatedOrder
(
orderInfo
:
string
):
TJSONObject
;
function
AddWebOrder
(
orderInfo
:
string
):
TJSONObject
;
function
AddCuttingDieOrder
(
orderInfo
:
string
):
TJSONObject
;
function
AddStatusSchedule
(
StatusType
:
string
;
order
:
TJSONObject
;
ORDER_ID
:
integer
):
string
;
function
GenerateOrdersSQL
(
searchOptions
:
string
):
TSQLQuery
;
function
GetColorCount
(
colors
:
string
):
string
;
...
...
@@ -1689,6 +1690,117 @@ begin
end
;
end
;
function
TLookupService
.
AddCuttingDieOrder
(
orderInfo
:
string
):
TJSONObject
;
var
JSONData
,
ResponseData
:
TJSONObject
;
SQL
:
string
;
Pair
:
TJSONPair
;
Field
:
TField
;
DateFormat
:
TFormatSettings
;
CurrDate
:
TDateTime
;
ORDER_ID
:
integer
;
mode
:
string
;
temp
:
string
;
begin
DateFormat
:=
TFormatSettings
.
Create
;
DateFormat
.
ShortDateFormat
:=
'yyyy-mm-dd'
;
DateFormat
.
DateSeparator
:=
'-'
;
JSONData
:=
TJSONObject
.
ParseJSONValue
(
orderInfo
)
as
TJSONObject
;
if
JSONData
=
nil
then
raise
Exception
.
Create
(
'Invalid JSON format'
);
// If parsing fails, raise an exception
mode
:=
JSONData
.
GetValue
<
string
>(
'mode'
);
if
mode
=
'ADD'
then
begin
SQL
:=
'select * from orders where ORDER_ID = 0 and ORDER_ID <> 0'
;
doQuery
(
ordersDB
.
UniQuery1
,
SQL
);
ordersDB
.
UniQuery1
.
Insert
;
end
else
begin
SQL
:=
'select * from orders where ORDER_ID = '
+
IntToStr
(
ORDER_ID
);
doQuery
(
ordersDB
.
UniQuery1
,
SQL
);
ordersDB
.
UniQuery1
.
Edit
;
end
;
temp
:=
JSONData
.
GetValue
<
string
>(
'COMPANY_ID'
);
ordersDB
.
UniQuery1
.
FieldByName
(
'COMPANY_ID'
).
AsString
:=
JSONData
.
GetValue
<
string
>(
'COMPANY_ID'
);
ordersDB
.
UniQuery1
.
FieldByName
(
'ORDER_TYPE'
).
AsString
:=
'web_plate'
;
if
mode
=
'ADD'
then
ordersDB
.
UniQuery1
.
FieldByName
(
'ORDER_DATE'
).
AsDateTime
:=
Now
else
begin
// No idea why I need this line but without it an error gets thrown
ordersDB
.
UniQuery1
.
FieldByName
(
'ORDER_DATE'
).
AsDateTime
:=
ordersDB
.
UniQuery1
.
FieldByName
(
'ORDER_DATE'
).
AsDateTime
;
end
;
if
JSONData
.
GetValue
<
string
>(
'staff_fields_price'
)
=
''
then
ordersDB
.
UniQuery1
.
FieldByName
(
'PRICE'
).
AsString
:=
'0'
else
ordersDB
.
UniQuery1
.
FieldByName
(
'PRICE'
).
AsString
:=
JSONData
.
GetValue
<
string
>(
'staff_fields_price'
);
ordersDB
.
UniQuery1
.
FieldByName
(
'JOB_NAME'
).
AsString
:=
JSONData
.
GetValue
<
string
>(
'staff_fields_job_name'
);
ordersDB
.
UniQuery1
.
FieldByName
(
'USER_ID'
).
AsString
:=
JSONData
.
GetValue
<
string
>(
'USER_ID'
);
ordersDB
.
UniQuery1
.
FieldByName
(
'LOCATION'
).
AsString
:=
JSONData
.
GetValue
<
string
>(
'staff_fields_art_location'
);
ordersDB
.
UniQuery1
.
Post
;
ordersDB
.
UniQuery1
.
Close
;
if
mode
=
'ADD'
then
begin
ordersDB
.
UniQuery1
.
SQL
.
Text
:=
'SELECT LAST_INSERT_ID() AS OrderID'
;
// Use database's method to get the last inserted ID
ordersDB
.
UniQuery1
.
Open
;
ORDER_ID
:=
ordersDB
.
UniQuery1
.
FieldByName
(
'OrderID'
).
AsInteger
;
end
;
if
mode
=
'ADD'
then
SQL
:=
'select * from cutting_die_orders where ORDER_ID = 0 and ORDER_ID <> 0'
else
begin
ORDER_ID
:=
JSONData
.
GetValue
<
integer
>(
'ORDER_ID'
);
SQL
:=
'select * from cutting_die_orders where ORDER_ID = '
+
IntToStr
(
ORDER_ID
);
end
;
doQuery
(
ordersDB
.
UniQuery1
,
SQL
);
try
if
mode
=
'ADD'
then
ordersDB
.
UniQuery1
.
Insert
else
ordersDB
.
UniQuery1
.
Edit
;
for
Pair
in
JSONData
do
begin
Field
:=
ordersDB
.
UniQuery1
.
FindField
(
Pair
.
JsonString
.
Value
);
// Checks if the field exists in the dataset
if
Assigned
(
Field
)
then
begin
// handles any dates or datetimes
if
(
Field
is
TDateTimeField
)
and
(
Pair
.
JsonValue
.
Value
<>
''
)
then
TDateTimeField
(
Field
).
AsDateTime
:=
StrToDate
(
Pair
.
JsonValue
.
Value
)
else
if
Pair
.
JsonValue
.
Value
<>
''
then
Field
.
AsString
:=
Pair
.
JsonValue
.
Value
;
end
;
end
;
ordersDB
.
UniQuery1
.
FieldByName
(
'ORDER_ID'
).
AsInteger
:=
ORDER_ID
;
// Post the record to the database
ordersDB
.
UniQuery1
.
Post
;
if
JSONData
.
GetValue
<
string
>(
'staff_fields_proof_date'
)
<>
''
then
AddStatusSchedule
(
'PROOF'
,
JSONData
,
ORDER_ID
);
if
JSONData
.
GetValue
<
string
>(
'staff_fields_ship_date'
)
<>
''
then
AddStatusSchedule
(
'SHIP'
,
JSONData
,
ORDER_ID
);
Result
:=
TJSONObject
.
Create
.
AddPair
(
'status'
,
'success'
);
TXDataOperationContext
.
Current
.
Handler
.
ManagedObjects
.
Add
(
Result
);
except
on
E
:
Exception
do
begin
Result
:=
TJSONObject
.
Create
.
AddPair
(
'error'
,
E
.
Message
);
end
;
end
;
end
;
initialization
RegisterServiceType
(
TLookupService
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment