· 7 years ago · Feb 21, 2019, 09:34 AM
1Imports DevExpress.XtraEditors
2Imports System.Xml
3Imports System.IO
4
5Public Class frm_Import
6 Dim oDotNet As App_SqlDb
7 Dim oDotNetSave As App_SqlDb
8 Dim oDotNetBaseLine As App_SqlDb
9 Private oDefaultWhs As String
10 Private oImConnectedTo As String
11
12 Dim isClosing As Boolean = False
13 Private Sub frm_Import_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
14 If bgIm.IsBusy AndAlso bgIm.WorkerSupportsCancellation Then
15 isClosing = True
16 bgIm.CancelAsync()
17 oWriteText(lsViewIm, Now & " - Form closing, please wait. Trying to finish this last file.", Color.DodgerBlue, False)
18 isStop = True
19 e.Cancel = True
20 Me.Enabled = False
21 Return
22 End If
23 End Sub
24
25 Private Sub frm_Import_Load(sender As Object, e As EventArgs) Handles MyBase.Load
26
27
28
29
30 Control.CheckForIllegalCrossThreadCalls = False
31 lsViewIm.Columns.Clear()
32 lsViewIm.Columns.Add("Import - Log", 500, HorizontalAlignment.Left)
33
34
35
36 oDotNet.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK)"
37 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
38 For i As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
39 Dim chkbox As String = oDotNet.GetField(i, "U_Name")
40 Dim oValue As Integer = oDotNet.GetField(i, "U_isActive")
41 For Each _chkbox As CheckEdit In Me.GroupControl1.Controls.OfType(Of CheckEdit)()
42 If chkbox = _chkbox.Name Then
43 If oValue = 1 Then
44 _chkbox.Checked = True
45 End If
46 End If
47 Next
48 Next
49 End If
50
51 oRetail = New cloud(oRegistry.GetKeyValue("POSUser"), "")
52
53 Me.DoubleBuffered = True
54 End Sub
55
56 Dim oInterval As Integer
57 Dim tmr As System.Timers.Timer
58 Dim tmrCountDown As System.Timers.Timer
59 Private Sub btImport_Click(sender As Object, e As EventArgs) Handles btImport.Click
60 Dim _Timer As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
61 _Timer.strCommand = "SELECT * FROM [@APP_IMPORT] WHERE U_App_Id = 0"
62
63 Select Case CInt(_Timer.GetField(, "U_DayFreqTime_"))
64 Case -1 'second(s)
65 oInterval = CInt(_Timer.GetField(, "U_DayFreqTime")) * 1000
66 duration = DateTime.Now.AddSeconds(_Timer.GetField(, "U_DayFreqTime"))
67 Case 1 'min(s)
68 oInterval = CInt(_Timer.GetField(, "U_DayFreqTime")) * 60000
69 duration = DateTime.Now.AddMinutes(_Timer.GetField(, "U_DayFreqTime"))
70 Case 2 'hr(s)
71 oInterval = (CInt(_Timer.GetField(, "U_DayFreqTime")) * 60) * 60 * 1000
72 duration = DateTime.Now.AddHours(_Timer.GetField(, "U_DayFreqTime"))
73 End Select
74
75 tmrCountDown = New System.Timers.Timer
76
77 tmrCountDown.Interval = 500
78 AddHandler tmrCountDown.Elapsed, AddressOf tmrCountdown_Tick
79 tmrCountDown.Start()
80
81 tmr = New System.Timers.Timer
82 tmr.Interval = oInterval
83 AddHandler tmr.Elapsed, AddressOf tmr_Tick
84 tmr.Start()
85
86 btImport.Visible = False
87 btStop.Visible = True
88 End Sub
89
90 Private Sub tmr_Tick(sender As Object, e As EventArgs)
91 If bgIm.IsBusy Then
92
93 Else
94 bgIm.WorkerSupportsCancellation = True
95 bgIm.RunWorkerAsync()
96 End If
97 GC.KeepAlive(bgIm)
98 End Sub
99
100 Dim duration As Date
101 Private Sub tmrCountdown_Tick(sender As Object, e As System.EventArgs)
102 Dim ts As TimeSpan = duration - DateTime.Now.AddSeconds(-1)
103 lblTime.Text = ts.Hours.ToString("00") & ":" & ts.Minutes.ToString("00") & ":" & ts.Seconds.ToString("00")
104 If lblTime.Text = "00:00:00" Then
105 lblTime.Text = "00:00:00"
106 tmrCountDown.Stop()
107
108 End If
109 End Sub
110
111 Dim isExporting As Boolean = False
112 Private Sub bgImp_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgIm.DoWork
113
114 If isStop Then
115 e.Cancel = True
116 Exit Sub
117 End If
118
119 If Not isExporting Then
120 isExporting = True
121
122 Import_Orders()
123 Import_PullOut()
124 Import_AdjustmentIn()
125 Import_AdjustmentOut()
126 Import_TIn()
127 Import_Invoice()
128
129
130 isExporting = False
131
132 If isStop Then
133 e.Cancel = True
134 Exit Sub
135 End If
136
137 End If
138
139 End Sub
140
141 Dim oRetail As cloud = New cloud(oRegistry.GetKeyValue("POSUser"), "")
142
143 Private Sub Import_PullOut()
144 If cbPullOut.Checked = True Then
145 Try
146 Dim oDatabase As String = ""
147 '"Get Path
148 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
149 oDatabase = oRegistry.GetKeyValue("Database")
150 Dim oDotNetReceive As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
151 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
152 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 0"
153
154 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
155 Dim ErrorChecker As Boolean = False
156 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
157
158 '"BTG 9/20/2016
159 '"Check if folder has files
160 If Directory.GetFiles(oPath, "pull_out*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
161 GoTo HasFile
162 End If
163
164 Try
165 'oDate = _Path.GetField(, "U_LastExportDate")
166 _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
167 Catch ex As Exception
168 End Try
169
170 Dim ts_Value As Integer = 0
171 pbIMPStockRequest.Properties.Minimum = 0
172
173 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
174 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
175
176 Dim oWhsDT As DataTable
177 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
178
179 Dim oXML As String
180 Dim NewXML As String
181
182 Dim oCount As Integer = 0
183 Dim oPageCount As Integer = 0
184 '"Loop every branches
185
186 For Each WhsDr As DataRowView In oWhsDT.DefaultView
187
188
189 Dim _afterdate As String = ""
190 If Not _Date Is Nothing Then
191 _afterdate = "&after=" & _Date & ""
192 End If
193
194 '"Check document page
195 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=transfer_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
196
197 Dim myXmlDoc As XmlDocument = New XmlDocument
198 myXmlDoc.LoadXml(oXML)
199 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
200 For Each mynode As XmlNode In list
201 oCount = mynode("count").InnerText
202 If oCount = 0 Then GoTo NextDocument
203 oWriteText(lsViewIm, Now & " - " & "Gathering information Pull-Out transaction from branch " & WhsDr("WhsName") & ", please wait...", , False)
204 Next
205
206 '"Create XML
207 oPageCount = PageCount(oCount / 50)
208 For Page As Integer = 1 To oPageCount
209 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=transfer_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
210 'Dim myXmlDoc As XmlDocument = New XmlDocument
211 If oXML = "<documents/>" Then
212 GoTo NextDocument
213 End If
214
215 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
216 Dim oGetFileName As String = "pull_out_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml"
217 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
218 oSaveFile.WriteLine(NewXML)
219 oSaveFile.Close()
220 oSaveFile.Dispose()
221
222 Dim ds As DataSet
223 ds = New DataSet
224 ds.ReadXml(oPath & "\" & oGetFileName)
225
226 Dim oHeader As DataTable
227
228 oHeader = ds.Tables("document").Copy
229
230 For Each oDr As DataRow In oHeader.Rows
231 Dim oUpdateQry As String
232 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 0) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 0) END WHERE U_App_Id = 0"
233 _Path.strCommand = (oUpdateQry)
234 Next
235
236 Next
237
238NextDocument:
239 Next
240
241HasFile:
242 pbIMPStockRequest.Properties.Minimum = 0
243 pbIMPStockRequest.Properties.Maximum = CInt(Directory.GetFiles(oPath, "pull_out*.xml", SearchOption.TopDirectoryOnly).Count)
244 pbIMPStockRequest.Position = 0
245
246 '"Post to SAP
247 Dim oFileName As String
248 For Each oFile As String In Directory.GetFiles(oPath, "pull_out*.xml", SearchOption.TopDirectoryOnly)
249 If isStop Then Exit Sub
250 oFileName = Path.GetFileName(oFile)
251 oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , False)
252
253 Dim _ErrCount As Integer = 1
254Recon:
255 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "pull_out") : Return
256 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "orders_logs") : _ErrCount += 1 : GoTo Recon
257
258 Dim ds As DataSet
259 ds = New DataSet
260 ds.ReadXml(oFile)
261
262 Dim oHeader As DataTable
263 Dim oDetail As DataTable
264
265 oHeader = ds.Tables("document").Copy
266
267 For Each oDr As DataRow In oHeader.Rows
268 Try
269
270 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
271 If Not oChangeDatabase("ACI_FINAL") Then
272 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pull_out")
273 ErrorChecker = True
274 GoTo NextFile
275 End If
276 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
277 If Not oChangeDatabase("AFSI_FINAL") Then
278 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pull_out")
279 ErrorChecker = True
280 GoTo NextFile
281 End If
282 End If
283
284 Dim oDotNetSave As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
285
286 oDotNetSave.strCommand = "SELECT * FROM [APP_AFSI]..[APP_PullOut] WHERE cloud_id = '" & oDr("id") & "' AND update_date = '" & oDr("utc_updated_at") & "'"
287 If oDotNetSave.Ds.Tables(0).Rows.Count <= 0 Then
288 oDotNet.strCommand = "INSERT INTO APP_AFSI..APP_PullOut VALUES ('" & oFileName & "','" & oDr("reference") & "','" & oDr("id") & "','" & oDr("utc_updated_at") & "',GETDATE())"
289 End If
290
291 If Not oCompany.InTransaction Then
292 oCompany.StartTransaction()
293 End If
294
295 oWriteText(lsViewIm, Now & " [Info] - Importing inventory transfer request with cloud reference id#" & oDr("id") & "...", , False)
296
297 TransId = CInt(oDr("id"))
298
299 Dim oDocuments As SAPbobsCOM.StockTransfer = Nothing
300 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
301
302 '"BTG 8/23/2016
303 '"Validate if Transfer is already in SAP
304 If ValidateId("[" & oCompany.CompanyDB & "]..OWTQ", oDr("id")) AndAlso oDr("status") = "V" Then
305 '"BTG 8/25/2016
306 '"For cancelation
307 With oDocuments
308 If .GetByKey(DocEntry) Then
309 Dim oCancelDoc As SAPbobsCOM.Documents
310 oCancelDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest)
311 oCancelDoc = oDocuments.CreateCancellationDocument
312
313 If Not oCancelDoc.Add = 0 Then
314 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "pull_out")
315 Try
316 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
317 Catch ex As Exception
318 End Try
319 End If
320 GoTo NextEntry
321 Else
322 oWriteText(lsViewIm, Now & " [Err] - No record(s) found [Orders].", Color.Red, True, "pull_out")
323 Try
324 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
325 Catch ex As Exception
326 End Try
327 GoTo NextEntry
328 End If
329 End With
330
331 End If
332
333 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OWTR WHERE U_AppPOSRefId = '" & oDr("id") & "'"
334 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
335 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Inventory Transfer with " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "pull_out")
336 GoTo NextEntry
337 End If
338
339
340 Dim oBatchDate As Date
341 With oDocuments
342
343 .DocDate = oDr("utc_document_date")
344 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
345 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
346 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
347 .Comments = oDr("remark") + " | Pull out was made from APPTech & iRipple integration."
348
349 If Not GetWhs("", oDr("branch_id")) Then
350 oWriteText(lsViewIm, Now & " [Err] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "pull_out")
351 ErrorChecker = True
352 GoTo NextEntry
353 End If
354
355 .FromWarehouse = WhsCode
356 oDetail = ds.Tables("document_line").Copy
357 oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
358 Dim oItemCode As String
359 For Each oDrView As DataRowView In oDetail.DefaultView
360 With .Lines
361 Try
362
363 If oCompany.CompanyDB = "ACI_FINAL" Then
364 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
365 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
366 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
367 Else
368 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
369 ErrorChecker = True
370 GoTo NextEntry
371 End If
372 Else
373 oItemCode = oDrView("product_stock_no")
374 End If
375
376 .ItemCode = oItemCode
377 .Quantity = oDrView("unit_quantity")
378 .WarehouseCode = "I-" + WhsCode
379
380 Dim oLineNum As Integer
381 oLineNum = CInt(oDrView("line_no") - 1)
382 Catch ex As Exception
383 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString & " - File: " & oFileName, Color.Red, True, "pull_out")
384 ErrorChecker = True
385 GoTo NextEntry
386 End Try
387
388 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oItemCode & "' AND ManBtchNum = 'Y'"
389
390 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
391 Dim oQuantity As Integer = oDrView("quantity")
392 Dim Qty As Integer = oDrView("quantity")
393
394 oDotNet.strCommand = "SELECT * FROM [" & oCompany.CompanyDB & "]..vwAppGetBatch(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND WhsCode = '" & WhsCode & "'"
395 Dim TotalQuantityHolder As Integer = 0
396 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
397
398 For oQuantityCounter As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
399
400 TotalQuantityHolder += oDotNet.GetField(oQuantityCounter, "Quantity")
401 If oQuantity > TotalQuantityHolder Then
402 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
403 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
404 .BatchNumbers.Add()
405 If oQuantityCounter = oDotNet.Ds.Tables(0).Rows.Count - 1 Then
406 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "pull_out")
407 ErrorChecker = True
408 GoTo NextEntry
409 End If
410 ElseIf oQuantity < TotalQuantityHolder Then
411 .BatchNumbers.Quantity = Qty
412 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
413 .BatchNumbers.Add()
414 Exit For
415 ElseIf oQuantity = TotalQuantityHolder Then
416 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
417 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
418 .BatchNumbers.Add()
419 Exit For
420 End If
421 Qty -= oDotNet.GetField(oQuantityCounter, "Quantity")
422 Next
423
424 Else
425 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "pull_out")
426 ErrorChecker = True
427 GoTo NextEntry
428 End If
429
430 End If
431
432 .Add()
433 End With
434 Next
435
436 If Not .Add = 0 Then
437 'oErrLog()
438 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "pull_out")
439 Try
440 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
441 Catch ex As Exception
442 End Try
443
444 ErrorChecker = True
445 Else
446 ''MGP 09/01/2016 added this portion now commited transaction per header not per file
447 Try
448 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
449 Catch ex As Exception
450 End Try
451 oWriteText(lsViewIm, Now & " - " & "Successfully created Document reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "pull_out")
452 End If
453
454
455 End With
456
457 Catch ex As Exception
458 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & ex.ToString(), Color.Red, True, "pull_out")
459
460 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
461 ErrorChecker = True
462 End Try
463
464NextEntry:
465 '"Update LastExport date
466 Dim oUpdateQry As String
467 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 0) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 0) END WHERE U_App_Id = 0"
468 _Path.strCommand = (oUpdateQry)
469
470 '"Per data each file
471 Next
472NextFile:
473 If ErrorChecker = False Then
474 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
475 Else
476 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
477 End If
478
479 pbIMPStockRequest.Position += 1
480 oWriteText(lsViewIm, Now & " - " & "Done importing Pull-Out.", Color.Green, False)
481 oWriteText(lsViewIm, Now & " - " & "=========================================", , False)
482 Next
483
484 Catch ex As Exception
485 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "pull_out")
486 Return
487 End Try
488 End If
489 End Sub
490
491 Private Sub Import_Orders()
492 If cbStockRequest.Checked = True Then
493 Try
494
495 Dim oDatabase As String = ""
496 Dim r As Random = New Random
497 '"Get Path
498 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
499 oDatabase = oRegistry.GetKeyValue("Database")
500 Dim oDotNetReceive As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
501 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
502
503 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 7"
504
505 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
506
507 Dim ErrorChecker As Boolean = False
508 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
509
510 '"BTG 9/20/2016
511 '"Check if folder has files
512 If Directory.GetFiles(oPath, "stock_request_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
513 GoTo HasFile
514 End If
515
516 Try
517 'oDate = _Path.GetField(, "U_LastExportDate")
518 _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
519 Catch ex As Exception
520 End Try
521
522 Dim ts_Value As Integer = 0
523 pbIMPStockRequest.Properties.Minimum = 0
524
525 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
526 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
527
528 Dim oWhsDT As DataTable
529 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
530
531 Dim oXML As String
532 Dim NewXML As String
533
534 Dim oCount As Integer = 0
535 Dim oPageCount As Integer = 0
536 '"Loop every branches
537
538 For Each WhsDr As DataRowView In oWhsDT.DefaultView
539
540
541 Dim _afterdate As String = ""
542 If Not _Date Is Nothing Then
543 _afterdate = "&after=" & _Date & ""
544 End If
545
546 '"Check document page
547 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/orders.xml?q=count&order_type_code=stock_request&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
548
549 Dim myXmlDoc As XmlDocument = New XmlDocument
550 myXmlDoc.LoadXml(oXML)
551 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
552 For Each mynode As XmlNode In list
553 oCount = mynode("count").InnerText
554 If oCount = 0 Then GoTo NextDocument
555 oWriteText(lsViewIm, Now & " - " & "Gathering information Stock Request Transaction from branch " & WhsDr("WhsName") & ", please wait...", , False)
556 Next
557
558 '"Create XML
559 oPageCount = PageCount(oCount / 50)
560 For Page As Integer = 1 To oPageCount
561 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/orders.xml?page=" & Page & "&order_type_code=stock_request&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
562
563 'Dim myXmlDoc As XmlDocument = New XmlDocument
564 If oXML = "<documents/>" Then
565 GoTo NextDocument
566 End If
567
568 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
569 Dim oGetFileName As String = "stock_request_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
570 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
571 oSaveFile.WriteLine(NewXML)
572 oSaveFile.Close()
573 oSaveFile.Dispose()
574
575 Dim ds As DataSet
576 ds = New DataSet
577 ds.ReadXml(oPath & "\" & oGetFileName)
578
579 Dim oHeader As DataTable
580
581
582 oHeader = ds.Tables("order").Copy
583
584 For Each oDr As DataRow In oHeader.Rows
585 '"Update LastExport date
586 Dim oUpdateQry As String
587 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 7) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 7) END WHERE U_App_Id = 7"
588 _Path.strCommand = (oUpdateQry)
589 Next
590
591 Next
592
593
594NextDocument:
595 Next
596
597HasFile:
598 pbIMPStockRequest.Properties.Minimum = 0
599 pbIMPStockRequest.Properties.Maximum = CInt(Directory.GetFiles(oPath, "stock_request_*.xml", SearchOption.TopDirectoryOnly).Count)
600 pbIMPStockRequest.Position = 0
601
602 '"Post to SAP
603 Dim oFileName As String
604
605 For Each oFile As String In Directory.GetFiles(oPath, "stock_request_*.xml", SearchOption.TopDirectoryOnly)
606 If isStop Then Exit Sub
607 oFileName = Path.GetFileName(oFile)
608 oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , False)
609
610 Dim _ErrCount As Integer = 1
611Recon:
612 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "orders_logs") : Return
613 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "orders_logs") : _ErrCount += 1 : GoTo Recon
614
615 Dim ds As DataSet
616 ds = New DataSet
617 ds.ReadXml(oFile)
618
619 Dim oHeader As DataTable
620 Dim oDetail As DataTable
621
622 oHeader = ds.Tables("order").Copy
623
624 For Each oDr As DataRow In oHeader.Rows
625 Try
626
627 Dim oDotNetSave As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
628 ''MGP 02/28/2017
629 ''Utility can switch to different database depends on the transaction
630 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
631 If Not oChangeDatabase("ACI_FINAL") Then
632 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
633 ErrorChecker = True
634 GoTo NextFile
635 End If
636 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
637 If Not oChangeDatabase("AFSI_FINAL") Then
638 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
639 ErrorChecker = True
640 GoTo NextFile
641 End If
642 End If
643
644 oDotNetSave.strCommand = "SELECT * FROM [APP_AFSI]..[APP_StockRequest] WHERE cloud_id = '" & oDr("id") & "' AND update_date = '" & oDr("utc_updated_at") & "'"
645 If oDotNetSave.Ds.Tables(0).Rows.Count <= 0 Then
646
647 oDotNetSave.strCommand = "INSERT INTO APP_AFSI..APP_StockRequest VALUES ('" & oFileName & "','" & oDr("reference") & "','" & oDr("id") & "','" & oDr("utc_updated_at") & "',GETDATE())"
648 End If
649
650 If Not oCompany.InTransaction Then
651 oCompany.StartTransaction()
652 End If
653
654 oWriteText(lsViewIm, Now & " [Info] - Importing inventory transfer request with cloud reference id#" & oDr("id") & "...", , False)
655
656 TransId = CInt(oDr("id"))
657
658 Dim oDocuments As SAPbobsCOM.StockTransfer = Nothing
659 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest)
660
661 '"BTG 8/23/2016
662 '"Validate if Transfer is already in SAP
663 If ValidateId("[" & oCompany.CompanyDB & "]..OWTQ", oDr("id")) AndAlso oDr("status") = "V" Then
664 '"BTG 8/25/2016
665 '"For cancelation
666 With oDocuments
667 If .GetByKey(DocEntry) Then
668 'Dim oCancelDoc As SAPbobsCOM.StockTransfer
669 'oCancelDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryTransferRequest)
670 .Comments = "Order request cancelled from APPTech & iRipple integration."
671
672 If Not .Update = 0 Then
673 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "orders_logs")
674 Try
675 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
676 Catch ex As Exception
677 End Try
678 ErrorChecker = True
679 Else
680 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Successfully cancelled order#[" & oDr("document_no") & "] - File: " & oFileName, Color.Green, True, "orders_logs")
681 Try
682 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
683 Catch ex As Exception
684 End Try
685 End If
686 GoTo NextEntry
687 Else
688 oWriteText(lsViewIm, Now & " [Err] - No record(s) found [Orders].", Color.Red, True, "orders_logs")
689 Try
690 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
691 Catch ex As Exception
692 End Try
693 GoTo NextEntry
694 End If
695 End With
696
697 End If
698
699 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OWTQ WHERE U_AppPOSRefId = '" & oDr("id") & "'"
700 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
701 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Inventory Transfer Request with " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "orders_logs")
702 GoTo NextEntry
703 End If
704 '"BTG 9/11/2016
705 '"For batch creation, year + 1 and Month
706 Dim oBatchDate As Date
707 With oDocuments
708
709 .DocDate = oDr("document_date")
710 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
711 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
712 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
713 .Comments = oDr("remark") + " | Order request made from APPTech & iRipple integration."
714
715 If Not GetWhs("", oDr("branch_id")) Then
716 oWriteText(lsViewIm, Now & " [Err] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "orders_logs")
717 ErrorChecker = True
718 GoTo NextEntry
719 End If
720 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
721 Dim oTerritory As String = oDotNet.GetField(, "Territory")
722 .UserFields.Fields.Item("U_ToWhs").Value = WhsCode
723 oDetail = ds.Tables("order_line").Copy
724 oDetail.DefaultView.RowFilter = "order_lines_id = '" & oDr("order_id") & "' "
725 Dim oItemCode As String
726 For Each oDrView As DataRowView In oDetail.DefaultView
727 Dim oLineNum As Integer
728 With .Lines
729
730 ''MGP 03/01/2017
731 ''For validation cause itemcode in their databases are not match
732 If oCompany.CompanyDB = "ACI_FINAL" Then
733 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
734 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
735 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
736 Else
737 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
738 ErrorChecker = True
739 GoTo NextEntry
740 End If
741 Else
742 oItemCode = oDrView("product_stock_no")
743 End If
744
745 .ItemCode = oItemCode
746 .Quantity = oDrView("unit_quantity")
747 .WarehouseCode = "I-" + WhsCode
748
749
750 '.CostingCode2 = "RETAIL"
751 '.CostingCode3 = oTerritory
752
753 oLineNum = CInt(oDrView("line_no") - 1)
754
755 .Add()
756 End With
757 If oLineNum = 0 Then
758 oDotNet.strCommand = "SELECT DfltWH FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oItemCode & "' AND ISNULL(DfltWH,'') <> ''"
759 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
760 oWriteText(lsViewIm, Now & " [Err] - Please assign a default warehouse for Itemcode : " & oDrView("product_stock_no") & " - File: " & oFileName, Color.Red, True, "orders_logs")
761 Try
762 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
763 Catch ex As Exception
764 End Try
765 ErrorChecker = True
766 GoTo NextEntry
767 Else
768 oDefaultWhs = oDotNet.GetField(, "DfltWH")
769 End If
770
771 End If
772
773 Next
774
775 .FromWarehouse = oDefaultWhs
776 If Not .Add = 0 Then
777 'oErrLog()
778 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "orders_logs")
779 Try
780 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
781 Catch ex As Exception
782 End Try
783
784 ErrorChecker = True
785 Else
786 ''MGP 09/01/2016 added this portion now commited transaction per header not per file
787 Try
788 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
789 Catch ex As Exception
790 End Try
791 oWriteText(lsViewIm, Now & "[" & oDr("reference") & "] - " & "Successfully created Document reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "orders_logs")
792 End If
793
794
795 End With
796
797 Catch ex As Exception
798 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & ex.ToString(), Color.Red, True, "orders_logs")
799 ErrorChecker = True
800 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
801 End Try
802
803NextEntry:
804 '"Update LastExport date
805 Dim oUpdateQry As String
806 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 7) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 7) END WHERE U_App_Id = 7"
807 _Path.strCommand = (oUpdateQry)
808
809 '"Per data each file
810 Next
811NextFile:
812 If ErrorChecker = False Then
813 pbIMPStockRequest.Position += 1
814 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
815 Else
816 pbIMPStockRequest.Position += 1
817 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
818 End If
819
820 Next
821
822 pbIMPStockRequest.Properties.Minimum = 0
823 pbIMPStockRequest.Properties.Maximum = 99
824 pbIMPStockRequest.Position = 0
825
826
827
828 Catch ex As Exception
829 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "orders_logs")
830 Return
831 End Try
832 End If
833 End Sub
834 Dim oPaymentDate As String
835 Private Sub Import_Invoice()
836
837 If Invoice.Checked = True Then
838 Try
839 Dim r As Random = New Random
840 Dim oDatabase, oCheckQuantity As String
841
842 '"Get Path
843 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
844 Dim oItemGroup As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
845 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
846 Dim oDotNetBaseLine As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
847 oDatabase = oRegistry.GetKeyValue("Database")
848 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 3"
849
850 Console.WriteLine(AppTech.Decrypt(oRegistry.GetKeyValue("SAPpass")))
851
852 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
853 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
854
855 '"BTG 9/20/2016
856 '"Check if folder has files
857 Dim countFiles As Integer = Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly).Count
858 If countFiles > 0 Then
859 GoTo HasFile
860 End If
861
862 Try
863 'oDate = _Path.GetField(, "U_LastExportDate")
864 _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
865 Catch ex As Exception
866 End Try
867
868 Dim ts_Value As Integer = 0
869 pbIMInv.Properties.Minimum = 0
870 Console.WriteLine(oRegistry.GetKeyValue("ServerName") + " " + oRegistry.GetKeyValue("UserName") + " " + AppTech.Decrypt(oRegistry.GetKeyValue("Password")) + " " + oRegistry.GetKeyValue("Database"))
871 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
872
873 '_ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL)"
874 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
875 Dim oWhsDT As DataTable
876 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
877
878 Dim oXML As String
879 Dim NewXML As String
880
881 Dim oCount As Integer = 0
882 Dim oPageCount As Integer = 0
883 '"Loop every branches
884
885 For Each WhsDr As DataRowView In oWhsDT.DefaultView
886 Dim _afterdate As String = ""
887 If Not _Date Is Nothing Then
888 _afterdate = "&after=" & _Date & ""
889 End If
890
891 '"Check document page
892 Console.Write("" & oRegistry.GetKeyValue("POSServer") & "/api/invoices.xml?q=count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "")
893 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/invoices.xml?q=count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
894
895 Dim myXmlDoc As XmlDocument = New XmlDocument
896 myXmlDoc.LoadXml(oXML)
897 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
898 For Each mynode As XmlNode In list
899 oCount = mynode("count").InnerText
900 If oCount = 0 Then GoTo NextDocument
901 oWriteText(lsViewIm, Now & " - " & " [INV] Gathering information Sales Transaction from branch " & WhsDr("WhsName") & ", please wait...", , False)
902 Next
903
904 '"Create XML
905 oPageCount = PageCount(oCount / 50)
906 For Page As Integer = 1 To oPageCount
907 ''MGP 08/31/2016 oPageCount = 2 but it wasn't going in the loop because of the step
908 'For Page As Integer = 1 To oPageCount Step -1
909 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/invoices.xml?page=" & Page & "&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
910
911 'Dim myXmlDoc As XmlDocument = New XmlDocument
912
913 If oXML = "<invoices/>" Then
914 GoTo NextDocument
915 End If
916
917 NewXML = oXML.Replace("</invoices>", "<branch><customer>" & WhsDr("GlblLocNum") & "</customer></branch></invoices>")
918 Dim oGetFileName As String = "invoice_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
919 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
920 oSaveFile.WriteLine(NewXML)
921 oSaveFile.Close()
922 oSaveFile.Dispose()
923
924
925 Dim ds As DataSet
926 ds = New DataSet
927 ds.ReadXml(oPath & "\" & oGetFileName)
928
929 Dim oHeader As DataTable
930 oHeader = ds.Tables("invoice").Copy
931
932 For Each oDr As DataRow In oHeader.Rows
933 '"Update LastExport date
934 Dim oUpdateQry As String
935 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 3) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 3) END WHERE U_App_Id = 3"
936 _Path.strCommand = (oUpdateQry)
937 Next
938
939 Next
940NextDocument:
941 Next
942HasFile:
943 '"Post to SAP
944 Dim oFileName As String
945 Dim oTotalReturn As Decimal, oSubTotal As Decimal
946
947
948 pbIMInv.Properties.Minimum = 0
949 pbIMInv.Properties.Maximum = CInt(Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly).Count)
950 pbIMInv.Position = 0
951
952 For Each oFile As String In Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly)
953 If isStop Then Exit Sub
954 oFileName = Path.GetFileName(oFile)
955 oWriteText(lsViewIm, Now & " [Info] - " & "Importing " & oFileName & " Invoice(s), please wait...", , True, "invoice_logs")
956 Dim ErrorChecker As Boolean = False
957 Dim _ErrCount As Integer = 1
958Recon:
959 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "invoice_logs") : Return
960 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "invoice_logs") : _ErrCount += 1 : GoTo Recon
961
962 Dim ds As DataSet
963 ds = New DataSet
964 ds.ReadXml(oFile)
965
966 Dim oBranch As DataTable
967 Dim oHeader As DataTable
968 Dim oDetail As DataTable
969 Dim oPayment As DataTable
970
971 oBranch = ds.Tables("branch")
972 oHeader = ds.Tables("invoice").Copy
973 oDetail = ds.Tables("invoice_line").Copy
974
975 Try
976 oPayment = ds.Tables("payment").Copy
977 Catch ex As Exception
978 oPayment = Nothing
979 End Try
980
981 Dim oDocEntry As String, oReference As String
982 '"BTG 8/10/2016
983 '"For branch = warehouse
984 For Each Branch As DataRow In oBranch.Rows
985 If Not GetWhs("", Branch("customer")) Then
986 ErrorChecker = True
987 GoTo NextFile
988 End If
989 Next
990 Dim _PaymentSum As Decimal = 0.0, _isLoopCheck As Boolean = False, oRounding As Decimal = 0.0
991 'LoopCheck:
992 Try
993 For Each oDr As DataRow In oHeader.Rows
994
995 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
996 If Not oChangeDatabase("ACI_FINAL") Then
997 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
998 ErrorChecker = True
999 GoTo NextFile
1000 End If
1001 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
1002 If Not oChangeDatabase("AFSI_FINAL") Then
1003 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
1004 ErrorChecker = True
1005 GoTo NextFile
1006 End If
1007 End If
1008
1009
1010
1011 If Not oCompany.InTransaction Then
1012 oCompany.StartTransaction()
1013 End If
1014
1015
1016
1017 Dim oDotNetSave As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
1018
1019 oDotNetSave.strCommand = "SELECT * FROM [APP_AFSI]..[APP_Invoice] WHERE cloud_id = '" & oDr("id") & "' AND update_date = '" & oDr("utc_updated_at") & "'"
1020 If oDotNetSave.Ds.Tables(0).Rows.Count <= 0 Then
1021 oDotNet.strCommand = "INSERT INTO APP_AFSI..APP_Invoice VALUES ('" & oFileName & "','" & oDr("reference") & "','" & oDr("id") & "','" & oDr("utc_updated_at") & "',GETDATE())"
1022 End If
1023
1024 Dim ohas_returns As String
1025
1026 If oDr("has_returns") = "true" Then
1027 ohas_returns = "true"
1028 Else
1029 ohas_returns = "false"
1030 End If
1031
1032 Try
1033 Dim oDocuments As SAPbobsCOM.Documents
1034 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
1035
1036 If oDr("status") = "V" Then
1037 Dim _DocEntry As Long, _PaymentNum As String = ""
1038
1039 ''MGP 02/23/2017
1040 ''Only for TRA credit skip the incoming payment
1041 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..ORCT(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' AND Canceled = 'N'"
1042 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
1043 GoTo noPayment
1044 End If
1045
1046 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..ORCT(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' AND Canceled = 'N'"
1047 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1048
1049 For oCountCancel As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
1050 Try
1051 Dim oCancelPayment As SAPbobsCOM.Payments
1052 oCancelPayment = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments)
1053 With oCancelPayment
1054 If .GetByKey(oDotNet.GetField(oCountCancel, "DocEntry")) Then
1055
1056 If Not .Cancel = 0 Then
1057
1058 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1059 Try
1060 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1061 Catch ex As Exception
1062 End Try
1063
1064 ErrorChecker = True
1065 GoTo NextEntry
1066 Else
1067 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Cancellation of payment for reference id#" & oDr("id") & " is successfully cancelled." & " - File: " & oFileName, Color.Green, False, "invoice_logs")
1068 End If
1069 Else
1070 GoTo NextEntry
1071 End If
1072 End With
1073 Catch ex As Exception
1074
1075 End Try
1076
1077 Next
1078noPayment:
1079 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' AND Canceled = 'N'"
1080 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1081 If ohas_returns = "false" Then
1082 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes)
1083 With oDocuments
1084
1085 If Not GetCardCode("", oDr("customer_id")) Then
1086 ErrorChecker = True
1087 GoTo NextEntry
1088 End If
1089
1090 .CardCode = CardCode
1091 .DocDate = oDr("utc_invoice_date")
1092 .DocDueDate = oDr("utc_invoice_date")
1093 .Comments = oDr("remark") + " | This transaction was made from APPTech & iRipple integration."
1094 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
1095 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
1096 .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
1097 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1098 .NumAtCard = oDr("remark") + "IDC"
1099
1100
1101
1102 Dim oTerritory As String = ""
1103 Dim oCategory As String = ""
1104 '.NumAtCard = oDr("reference") & "|" & oDr("branch_id")
1105 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM [" & oCompany.CompanyDB & "]..OCRD(NOLOCK) WHERE CardCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
1106 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1107 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
1108 oCategory = oDotNet.GetField(, "U_SalesCategory")
1109 Else
1110 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1111 oTerritory = oDotNet.GetField(, "Territory")
1112 End If
1113
1114 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' "
1115 oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
1116 Dim oItemCode As String
1117 For Each oDrView As DataRowView In oDetail.DefaultView
1118 With .Lines
1119
1120 ''MGP 03/01/2017
1121 ''For validation cause itemcode in their databases are not match
1122 If oCompany.CompanyDB = "ACI_FINAL" Then
1123 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
1124 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
1125 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
1126 Else
1127 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
1128 ErrorChecker = True
1129 GoTo NextEntry
1130 End If
1131 Else
1132 oItemCode = oDrView("product_stock_no")
1133 End If
1134
1135 .ItemCode = oItemCode
1136 .Quantity = oDrView("quantity")
1137 .WarehouseCode = WhsCode
1138 'CPA discount amount
1139 .Price = 0
1140 .UnitPrice = 0
1141 .PriceAfterVAT = oDrView("retail_price")
1142 .CostingCode = "SALES"
1143 If oCategory = "" Then
1144 .CostingCode2 = "RETAIL"
1145 .CostingCode3 = oTerritory
1146 Else
1147 .CostingCode2 = oCategory
1148 .CostingCode3 = oTerritory
1149 End If
1150
1151 .BaseEntry = oDotNet.GetField(, "DocEntry")
1152 .BaseType = 13
1153
1154 If Not GetBaseLine(oItemCode, oDotNet.GetField(, "DocEntry"), oFileName) Then
1155 ErrorChecker = True
1156 GoTo NextEntry
1157 End If
1158 .BaseLine = BaseLine
1159
1160 .Add()
1161
1162 End With
1163 Next
1164
1165 If Not .Add = 0 Then
1166 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1167 Try
1168 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1169 Catch ex As Exception
1170 End Try
1171 ErrorChecker = True
1172 GoTo NextEntry
1173 Else
1174 Try
1175 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1176 Catch ex As Exception
1177 End Try
1178 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Successfully created Credit Memo for cancellation of invoice with cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, False, "invoice_logs")
1179 End If
1180
1181 End With
1182
1183 Else
1184 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes)
1185 With oDocuments
1186
1187 If Not GetCardCode("", oDr("customer_id")) Then
1188 ErrorChecker = True
1189 GoTo NextEntry
1190 End If
1191
1192 .CardCode = CardCode
1193 .DocDate = oDr("utc_invoice_date")
1194 .DocDueDate = oDr("utc_invoice_date")
1195 .Comments = oDr("remark") + " | This transaction was made from APPTech & iRipple integration."
1196 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
1197 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
1198 .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
1199 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1200 .NumAtCard = oDr("remark") + "IDC"
1201
1202 'oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1203 'Dim oTerritory As String = oDotNet.GetField(, "Territory")
1204 Dim oTerritory As String = ""
1205 Dim oCategory As String = ""
1206 '.NumAtCard = oDr("reference") & "|" & oDr("branch_id")
1207 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM OCRD WHERE CardCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
1208 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1209 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
1210 oCategory = oDotNet.GetField(, "U_SalesCategory")
1211 Else
1212 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1213 oTerritory = oDotNet.GetField(, "Territory")
1214 End If
1215
1216 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' "
1217 oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
1218 Dim oItemCode As String
1219 For Each oDrView As DataRowView In oDetail.DefaultView
1220 With .Lines
1221
1222 ''MGP 03/01/2017
1223 ''For validation cause itemcode in their databases are not match
1224 If oCompany.CompanyDB = "ACI_FINAL" Then
1225 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
1226 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
1227 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
1228 Else
1229 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
1230 ErrorChecker = True
1231 GoTo NextEntry
1232 End If
1233 Else
1234 oItemCode = oDrView("product_stock_no")
1235 End If
1236
1237 oCheckQuantity = oDrView("quantity")
1238 If oCheckQuantity.Substring(0, 1) = "-" Then
1239 GoTo nextHasReturn
1240 End If
1241
1242 .ItemCode = oItemCode
1243 .Quantity = oDrView("quantity")
1244 .WarehouseCode = WhsCode
1245 'CPA discount amount
1246 .Price = 0
1247 .UnitPrice = 0
1248 .PriceAfterVAT = oDrView("retail_price")
1249 .CostingCode = "SALES"
1250 If oCategory = "" Then
1251 .CostingCode2 = "RETAIL"
1252 .CostingCode3 = oTerritory
1253 Else
1254 .CostingCode2 = oCategory
1255 .CostingCode3 = oTerritory
1256 End If
1257
1258 .BaseEntry = oDotNet.GetField(, "DocEntry")
1259 .BaseType = 13
1260
1261 If Not GetBaseLine(oItemCode, oDotNet.GetField(, "DocEntry"), oFileName) Then
1262 ErrorChecker = True
1263 GoTo NextEntry
1264 End If
1265 .BaseLine = BaseLine
1266
1267 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oItemCode & "' AND ManBtchNum = 'Y'"
1268
1269 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1270 Dim oQuantity As Integer = oDrView("quantity")
1271 Dim Qty As Integer = oDrView("quantity")
1272
1273 oDotNet.strCommand = "SELECT * FROM [" & oCompany.CompanyDB & "]..vwAppGetBatch(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND WhsCode = '" & WhsCode & "'"
1274 Dim TotalQuantityHolder As Integer = 0
1275 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1276
1277 For oQuantityCounter As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
1278
1279 TotalQuantityHolder += oDotNet.GetField(oQuantityCounter, "Quantity")
1280 If oQuantity > TotalQuantityHolder Then
1281 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1282 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1283 .BatchNumbers.Add()
1284 If oQuantityCounter = oDotNet.Ds.Tables(0).Rows.Count - 1 Then
1285 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1286 ErrorChecker = True
1287 GoTo NextEntry
1288 End If
1289 ElseIf oQuantity < TotalQuantityHolder Then
1290 .BatchNumbers.Quantity = Qty
1291 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1292 .BatchNumbers.Add()
1293 Exit For
1294 ElseIf oQuantity = TotalQuantityHolder Then
1295 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1296 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1297 .BatchNumbers.Add()
1298 Exit For
1299 End If
1300 Qty -= oDotNet.GetField(oQuantityCounter, "Quantity")
1301 Next
1302
1303 Else
1304 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1305 ErrorChecker = True
1306 GoTo NextEntry
1307 End If
1308
1309 End If
1310
1311
1312 .Add()
1313nextHasReturn:
1314 End With
1315 Next
1316
1317 If Not .Add = 0 Then
1318 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1319
1320 Try
1321 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1322 Catch ex As Exception
1323 End Try
1324
1325 ErrorChecker = True
1326 GoTo NextEntry
1327 Else
1328
1329 'Else
1330 ' Try
1331 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1332 ' Catch ex As Exception
1333 ' End Try
1334 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Successfully created Credit Memo for cancellation of invoice with cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, False, "invoice_logs")
1335 End If
1336
1337 End With
1338
1339 Dim oCreditMemo As SAPbobsCOM.Documents
1340 oCreditMemo = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes)
1341
1342 With oCreditMemo
1343 oDotNet.strCommand = "SELECT a.DocEntry FROM [" & oCompany.CompanyDB & "]..ORIN(NOLOCK) A INNER JOIN RIN1(NOLOCK) b ON a.Docentry = b.DocEntry WHERE a.U_appPOSRefID = '" & oDr("id") & "' AND b.BaseType = -1"
1344 If .GetByKey(oDotNet.GetField(, "DocEntry")) Then
1345 .Comments = "Document is cancelled from APPTech & iRipple integration."
1346 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1347
1348 If Not .Update = 0 Then
1349
1350 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1351 Try
1352 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1353 Catch ex As Exception
1354 End Try
1355
1356 ErrorChecker = True
1357 GoTo NextEntry
1358 Else
1359 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Cancellation of returns for reference id#" & oDr("id") & " is successfully cancelled." & " - File: " & oFileName, Color.Green, False, "invoice_logs")
1360 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1361 End If
1362 End If
1363 End With
1364
1365 End If
1366 Else
1367 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Transaction for reference id#" & oDr("id") & " is already cancelled or doesn't have any record." & " - File: " & oFileName, Color.Orange, False, "invoice_logs")
1368 End If
1369
1370 Else
1371 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Transaction for reference id#" & oDr("id") & " is already cancelled or doesn't have any record." & " - File: " & oFileName, Color.Orange, False, "invoice_logs")
1372 End If
1373
1374 Else
1375
1376 oDocEntry = ""
1377 oReference = oDr("reference")
1378 Dim DocTotalInv As Decimal = 0.0
1379 Dim isCommit As Boolean = False
1380 oSubTotal = 0
1381 oTotalReturn = 0
1382 oPaymentDate = ""
1383
1384
1385 With oDocuments
1386 '"BTG 8/30/2016
1387 '"If customer_id is blank get default cardcode in Warehouse
1388 If Not GetCardCode("", oDr("customer_id")) Then
1389 ErrorChecker = True
1390 GoTo NextEntry
1391 End If
1392 ''MGP 08/31/2016 added to avoid duplication of record
1393 oDotNet.strCommand = "SELECT TOP 1 DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' AND U_AppLayaways = 'Y'"
1394 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1395 GoTo Layaways
1396 Else
1397 oDotNet.strCommand = "SELECT TOP 1 DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "' AND U_AppLayaways IN ('N','')"
1398 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1399 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, True, "invoice_logs")
1400 GoTo NextEntry
1401 End If
1402 End If
1403
1404 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Importing invoice for cloud reference id#" & oDr("id") & "...", , False)
1405 Dim oSalesman As String
1406
1407 If oCompany.CompanyDB = "ACI_FINAL" Then
1408 Select Case oDr("salesman_id")
1409
1410 Case "3332"
1411 .Series = "56"
1412 oSalesman = "TRA Cash"
1413 ''TRA cash
1414 Case "3334"
1415 .Series = "56"
1416 oSalesman = "TRA Credit"
1417 ''TRA Credit
1418 Case "3336"
1419 .Series = "4"
1420 oSalesman = "Invoice-Ex"
1421 ''Cash Invoice Exempt
1422 Case "3335"
1423 .Series = "4"
1424 oSalesman = "Invoice-Vat"
1425 'Cash Invoice Vat
1426 Case Else
1427 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Unkown salesman id for invoice with cloud reference id#" & oDr("id") & "...", Color.Red, True, "invoice_logs")
1428 ErrorChecker = True
1429 GoTo NextEntry
1430 End Select
1431 Else
1432 Select Case oDr("salesman_id")
1433
1434 Case "3332"
1435 .Series = "51"
1436 oSalesman = "TRA Cash"
1437 ''TRA cash
1438 Case "3334"
1439 .Series = "51"
1440 oSalesman = "TRA Credit"
1441 ''TRA Credit
1442 Case "3336"
1443 .Series = "4"
1444 oSalesman = "Invoice-Ex"
1445 ''Cash Invoice Exempt
1446 Case "3335"
1447 .Series = "4"
1448 oSalesman = "Invoice-Vat"
1449 'Cash Invoice Vat
1450 Case Else
1451 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Unkown salesman id for invoice with cloud reference id#" & oDr("id") & "...", Color.Red, True, "invoice_logs")
1452 ErrorChecker = True
1453 GoTo NextEntry
1454 End Select
1455 End If
1456
1457 If oCompany.CompanyDB = "ACI_FINAL" Then
1458 oDotNetSave.strCommand = "SELECT CardCode FROM [ACI_FINAL]..OCRD WHERE U_BPMCode = '" & CardCode & "'"
1459 If oDotNetSave.Ds.Tables(0).Rows.Count > 0 Then
1460 .CardCode = oDotNetSave.GetField(, )
1461 Else
1462 oDotNetSave.strCommand = "SELECT CardCode FROM [ACI_FINAL]..OCRD WHERE CardCode = '" & CardCode & "'"
1463 If oDotNetSave.Ds.Tables(0).Rows.Count = 0 Then
1464 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Customer code: " & CardCode & " doesn't exists...", Color.Red, True, "invoice_logs")
1465 ErrorChecker = True
1466 GoTo NextEntry
1467 Else
1468 .CardCode = CardCode
1469 End If
1470 End If
1471 Else
1472 .CardCode = CardCode
1473 End If
1474 .DocumentsOwner = 3 'HardCoded 2/21/2019
1475 .DocDate = oDr("utc_invoice_date")
1476 '.DocDueDate = oDr("utc_invoice_date")
1477 .Comments = oSalesman & " | " + oDr("remark") + " | This transaction was made from APPTech & iRipple integration."
1478 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
1479 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference").ToString
1480 .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
1481 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1482 .NumAtCard = oDr("remark") + "ID"
1483
1484 If oDr("status") = "B" Then
1485 .UserFields.Fields.Item("U_AppLayaways").Value = "Y"
1486 Else
1487 .UserFields.Fields.Item("U_AppLayaways").Value = "N"
1488 End If
1489
1490
1491 Dim oRef As String(), _Terminal As Integer, _Ref As Integer
1492 oRef = Split(oDr("reference"), "-")
1493 _Terminal = oRef(0)
1494 _Ref = oRef(1)
1495 '.NumAtCard = _Terminal & "-" & _Ref & "|" & oDr("branch_id")
1496 Dim _ItemCode As String = "", _Qty As Decimal = 0.0
1497 Dim oLineNumber As Integer = 0
1498
1499 Dim oTerritory As String = ""
1500 Dim oCategory As String = ""
1501 '.NumAtCard = oDr("reference") & "|" & oDr("branch_id")
1502 If oCompany.CompanyDB = "ACI_FINAL" Then
1503 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM [" & oCompany.CompanyDB & "]..OCRD WHERE U_BPMCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
1504 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1505 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
1506 oCategory = oDotNet.GetField(, "U_SalesCategory")
1507 Else
1508 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1509 oTerritory = oDotNet.GetField(, "Territory")
1510 End If
1511 Else
1512 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM [" & oCompany.CompanyDB & "]..OCRD WHERE CardCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
1513 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1514 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
1515 oCategory = oDotNet.GetField(, "U_SalesCategory")
1516 Else
1517 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1518 oTerritory = oDotNet.GetField(, "Territory")
1519 End If
1520 End If
1521
1522 oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
1523 Dim oItemCode, GroupType, GroupChecker As String
1524 Dim oMixChecker As Boolean = False
1525 Dim oGrpCode As Integer
1526 For Each oDrView As DataRowView In oDetail.DefaultView
1527 With .Lines
1528
1529 If oSalesman = "TRA Credit" Then
1530 oDotNetItemCode.strCommand = "SELECT ItmsGrpCod FROM OITM WHERE ItemCode = '" & oDrView("product_stock_no") & "'"
1531 GroupType = oDotNetItemCode.GetField(, "ItmsGrpCod")
1532
1533 If oLineNumber = 0 Then
1534 oMixChecker = False
1535 oGrpCode = oDotNetItemCode.GetField(, "ItmsGrpCod")
1536 Else
1537 If oGrpCode <> GroupType Then
1538 oMixChecker = True
1539 End If
1540 End If
1541
1542 'If GroupType = "101" Then
1543 ' GroupChecker = "Chemical"
1544 'ElseIf GroupType = "102" Then
1545 ' GroupChecker = "Fertilizers"
1546 'ElseIf GroupType = "103" Then
1547 ' GroupChecker = "HybridSeeds"
1548 'Else
1549 ' GroupChecker = "Mix"
1550 'End If
1551 End If
1552
1553 ''MGP 03/01/2017
1554 ''For validation cause itemcode in their databases are not match
1555 If oCompany.CompanyDB = "ACI_FINAL" Then
1556 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "' "
1557 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
1558 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
1559 Else
1560 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
1561 ErrorChecker = True
1562 GoTo NextEntry
1563 End If
1564 Else
1565 oItemCode = oDrView("product_stock_no")
1566 End If
1567
1568 oCheckQuantity = oDrView("quantity")
1569 If oCheckQuantity.Substring(0, 1) = "-" Then
1570 oSubTotal = oDrView("subtotal") * -1
1571 oTotalReturn += oSubTotal
1572 GoTo nextInvoiceLine
1573 End If
1574
1575 If oDr("salesman_id") = "3336" Then
1576 .VatGroup = "OVAT-E"
1577 End If
1578
1579 .ItemCode = oItemCode
1580
1581 .Quantity = oDrView("quantity")
1582 'CPA for discount amount
1583 .UnitPrice = 0
1584 .Price = 0
1585 .PriceAfterVAT = oDrView("price")
1586 .WarehouseCode = WhsCode
1587
1588 .CostingCode = "SALES"
1589 If oCategory = "" Then
1590 .CostingCode2 = "RETAIL"
1591 .CostingCode3 = oTerritory
1592 Else
1593 .CostingCode2 = oCategory
1594 .CostingCode3 = oTerritory
1595 End If
1596
1597
1598
1599 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oItemCode & "' AND ManBtchNum = 'Y'"
1600
1601 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1602 Dim oQuantity As Integer = oDrView("quantity")
1603 Dim Qty As Integer = oDrView("quantity")
1604
1605 oDotNet.strCommand = "SELECT * FROM [" & oCompany.CompanyDB & "]..vwAppGetBatch(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND WhsCode = '" & WhsCode & "'"
1606 Dim TotalQuantityHolder As Integer = 0
1607 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1608
1609 For oQuantityCounter As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
1610
1611 TotalQuantityHolder += oDotNet.GetField(oQuantityCounter, "Quantity")
1612 If oQuantity > TotalQuantityHolder Then
1613 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1614 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1615 .BatchNumbers.Add()
1616 If oQuantityCounter = oDotNet.Ds.Tables(0).Rows.Count - 1 Then
1617 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1618 ErrorChecker = True
1619 GoTo NextEntry
1620 End If
1621 ElseIf oQuantity < TotalQuantityHolder Then
1622 .BatchNumbers.Quantity = Qty
1623 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1624 .BatchNumbers.Add()
1625 Exit For
1626 ElseIf oQuantity = TotalQuantityHolder Then
1627 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1628 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1629 .BatchNumbers.Add()
1630 Exit For
1631 End If
1632 Qty -= oDotNet.GetField(oQuantityCounter, "Quantity")
1633 Next
1634
1635 Else
1636 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1637 ErrorChecker = True
1638 GoTo NextEntry
1639 End If
1640
1641 End If
1642
1643 .Add()
1644nextInvoiceLine:
1645 End With
1646 Next
1647
1648
1649
1650 If oSalesman = "TRA Credit" Then
1651
1652 oItemGroup.strCommand = "SELECT ISNULL(U_CreditTermChemical,0) 'U_CreditTermChemical', ISNULL(U_CreditTermFert,0) 'U_CreditTermFert', ISNULL(U_CreditTermHybrid,0) 'U_CreditTermHybrid', ISNULL(U_CreditTermMix,0) 'U_CreditTermMix' FROM [" & oCompany.CompanyDB & "]..OCRD WHERE CardCode = '" & CardCode & "'"
1653
1654 If oMixChecker = False Then
1655
1656 Select Case oGrpCode
1657 Case "101"
1658 oDotNetBaseLine.strCommand = "SELECT GroupNum FROM [" & oCompany.CompanyDB & "]..OCTG WHERE ExtraDays = '" & oItemGroup.GetField(, "U_CreditTermChemical") & "'"
1659 .PaymentGroupCode = oDotNetBaseLine.GetField(, "GroupNum")
1660 .DocDueDate = DateAdd(DateInterval.Day, oItemGroup.GetField(, "U_CreditTermChemical"), oDr("utc_invoice_date"))
1661 Case "102"
1662 oDotNetBaseLine.strCommand = "SELECT GroupNum FROM [" & oCompany.CompanyDB & "]..OCTG WHERE ExtraDays = '" & oItemGroup.GetField(, "U_CreditTermFert") & "'"
1663 .PaymentGroupCode = oDotNetBaseLine.GetField(, "GroupNum")
1664 .DocDueDate = DateAdd(DateInterval.Day, oItemGroup.GetField(, "U_CreditTermFert"), oDr("utc_invoice_date"))
1665 Case "103"
1666 oDotNetBaseLine.strCommand = "SELECT GroupNum FROM [" & oCompany.CompanyDB & "]..OCTG WHERE ExtraDays = '" & oItemGroup.GetField(, "U_CreditTermHybrid") & "'"
1667 .PaymentGroupCode = oDotNetBaseLine.GetField(, "GroupNum")
1668 .DocDueDate = DateAdd(DateInterval.Day, oItemGroup.GetField(, "U_CreditTermHybrid"), oDr("utc_invoice_date"))
1669 End Select
1670 Else
1671 oDotNetBaseLine.strCommand = "SELECT GroupNum FROM [" & oCompany.CompanyDB & "]..OCTG WHERE ExtraDays = '" & oItemGroup.GetField(, "U_CreditTermMix") & "'"
1672 .PaymentGroupCode = oDotNetBaseLine.GetField(, "GroupNum")
1673 .DocDueDate = DateAdd(DateInterval.Day, oItemGroup.GetField(, "U_CreditTermMix"), oDr("utc_invoice_date"))
1674 End If
1675 Else
1676
1677 .DocDueDate = oDr("utc_invoice_date")
1678 End If
1679
1680
1681
1682 If Not .Add = 0 Then
1683 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1684 Try
1685 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1686 Catch ex As Exception
1687 End Try
1688 ErrorChecker = True
1689 GoTo NextEntry
1690 Else
1691 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Successfully created AR Invoice with cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1692 oCompany.GetNewObjectCode(oDocEntry)
1693 oQry = Nothing
1694 oQry = "SELECT DocTotal, DocEntry FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE DocEntry = '" & oDocEntry & "' "
1695 oDotNet.strCommand = oQry
1696 End If
1697
1698
1699 End With
1700
1701Layaways:
1702
1703 ''MGP 02/21/2017
1704 '''For payment
1705 Dim oIncoming As SAPbobsCOM.Payments
1706 oIncoming = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments)
1707
1708 Dim oCash As Decimal = 0.0, oPaymentSum As Decimal = 0.0, oTotalPayment As Decimal = 0.0
1709 Dim oPaymentCount As Integer = 1, oAppPaymentLineId As Integer = 1
1710
1711 With oIncoming
1712
1713 ''MGP 02/21/2017
1714 ''For filtering partial payment
1715 oDotNet.strCommand = "SELECT TOP 1 ISNULL(U_AppPaymentLineId,'0') 'U_AppPaymentLineId' FROM [" & oCompany.CompanyDB & "]..ORCT WHERE U_APPPosREFid = '" & oDr("id") & "' ORDER BY U_AppPaymentLineId DESC"
1716 If oDotNet.Ds.Tables(0).Rows.Count = 0 Then
1717 oAppPaymentLineId = 0
1718 Else
1719 oAppPaymentLineId = oDotNet.GetField(, "U_AppPaymentLineId")
1720 End If
1721
1722 Dim oNoPaymentChecker As Boolean
1723 Dim oCounterPayment As Integer = 0
1724 Dim oPaymentAmountChecker As Decimal
1725 oPayment.DefaultView.RowFilter = "payments_id = '" & oDr("invoice_id") & "' "
1726 oPayment.DefaultView.Sort = "payment_type_id DESC"
1727 For Each oDrViewPayment As DataRowView In oPayment.DefaultView
1728 oPaymentDate = oDrViewPayment("utc_payment_date")
1729 oPaymentAmountChecker = oDrViewPayment("amount")
1730 oCounterPayment += 1
1731 Next
1732
1733 If oPaymentAmountChecker = 0 And oCounterPayment = 1 Then
1734 If ohas_returns = "false" Then
1735 Try
1736 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1737 Catch ex As Exception
1738 End Try
1739
1740 GoTo NextEntry
1741 End If
1742 GoTo Returntrue
1743 End If
1744 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Importing incoming payment for cloud reference id#" & oDr("id") & "...", , False)
1745 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..ORCT WHERE U_APPPosREFid = '" & oDr("id") & "' AND U_APPPaymentDate >= '" & oPaymentDate & "' "
1746 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1747 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "invoice_logs")
1748 GoTo NextEntry
1749 End If
1750
1751
1752 If oCompany.CompanyDB = "ACI_FINAL" Then
1753 oDotNetSave.strCommand = "SELECT CardCode FROM [ACI_FINAL]..OCRD WHERE U_BPMCode = '" & CardCode & "'"
1754 If oDotNetSave.Ds.Tables(0).Rows.Count > 0 Then
1755 .CardCode = oDotNetSave.GetField(, )
1756 End If
1757 Else
1758 .CardCode = CardCode
1759 End If
1760 .DocDate = oPaymentDate
1761 .Remarks = "This transaction was made from APPTech & iRipple integration."
1762 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
1763 .UserFields.Fields.Item("U_AppPaymentDate").Value = oPaymentDate
1764 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1765
1766 For Each oDrViewPayment As DataRowView In oPayment.DefaultView
1767
1768 If oAppPaymentLineId < oPaymentCount Then
1769
1770 Select Case oDrViewPayment("payment_type_name")
1771 Case "Cash"
1772 oCash += oDrViewPayment("amount")
1773 .CashSum = oCash
1774 Case "Check"
1775 .Checks.CheckNumber = oDrViewPayment("check_number")
1776 .Checks.DueDate = oDrViewPayment("check_date") '"#12/31/2014#" 'TrimDate(oDr("payment_duedate"))
1777 .Checks.CheckSum = oDrViewPayment("amount")
1778 .Checks.Add()
1779 oPaymentSum += oDrViewPayment("amount")
1780 Case Else
1781 oWriteText(lsViewIm, Now & " [Err] - Payment type: " & oDrViewPayment("payment_type_name") & " is invalid. - File: " & oFileName, Color.Red, True, "invoice_logs")
1782 ErrorChecker = True
1783 GoTo NextEntry
1784 End Select
1785 End If
1786nextPayment:
1787 oPaymentCount += 1
1788 Next
1789
1790 oTotalPayment = oCash + oPaymentSum + oTotalReturn
1791 oPaymentCount -= 1
1792
1793 If oDocEntry = "" Then
1794 oDotNet.strCommand = "SELECT DocEntry, CardCode, CardName FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "'"
1795 oDocEntry = oDotNet.GetField(, "DocEntry")
1796 oItemGroup.strCommand = "SELECT County, U_APPBusinessPartner FROM [" & oCompany.CompanyDB & "]..OWHS(NOLOCK) WHERE FedTaxID = '" & oDr("branch_id") & "'"
1797 oDotNet.strCommand = "SELECT CardName FROM [" & oCompany.CompanyDB & "]..OCRD(NOLOCK) WHERE CardCode = '" & oItemGroup.GetField(, "U_APPBusinessPartner") & "'"
1798 .UserFields.Fields.Item("U_StoreKeeper").Value = oDotNet.GetField(, "CardName")
1799 .UserFields.Fields.Item("U_APP_Store_Branch").Value = oItemGroup.GetField(, "County")
1800 Else
1801 oDotNet.strCommand = "SELECT DocEntry, CardCode, CardName FROM [" & oCompany.CompanyDB & "]..OINV(NOLOCK) WHERE DocEntry = '" & oDocEntry & "'"
1802 oDocEntry = oDotNet.GetField(, "DocEntry")
1803 oItemGroup.strCommand = "SELECT County, U_APPBusinessPartner FROM [" & oCompany.CompanyDB & "]..OWHS(NOLOCK) WHERE FedTaxID = '" & oDr("branch_id") & "'"
1804 oDotNet.strCommand = "SELECT CardName FROM [" & oCompany.CompanyDB & "]..OCRD(NOLOCK) WHERE CardCode = '" & oItemGroup.GetField(, "U_APPBusinessPartner") & "'"
1805 .UserFields.Fields.Item("U_StoreKeeper").Value = oDotNet.GetField(, "CardName")
1806 .UserFields.Fields.Item("U_APP_Store_Branch").Value = oItemGroup.GetField(, "County")
1807 End If
1808
1809 .Invoices.DocEntry = oDocEntry
1810 .Invoices.InvoiceType = 13
1811 .Invoices.SumApplied = oTotalPayment
1812 .UserFields.Fields.Item("U_AppPaymentLineId").Value = oPaymentCount.ToString
1813 .Invoices.Add()
1814
1815 If Not .Add = 0 Then
1816 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1817 Try
1818 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1819 Catch ex As Exception
1820 End Try
1821 ErrorChecker = True
1822 GoTo NextEntry
1823 Else
1824 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Successfully created Incoming Payment with cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, False, "invoice_logs")
1825 If ohas_returns = "false" Then
1826 Try
1827 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1828 Catch ex As Exception
1829 End Try
1830
1831 GoTo NextEntry
1832 End If
1833 End If
1834 End With
1835Returntrue:
1836 ''MGP 02/21/2017
1837 ''Credit memo for transaction with returns
1838 ''Partial payment will always go here but no transaction will be made.
1839 If ohas_returns = "true" And oDr("status") <> "V" Then
1840 '"For CM
1841 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes)
1842 With oDocuments
1843
1844
1845 oDotNet.strCommand = "SELECT TOP 1 U_AppPOSRefId FROM [" & oCompany.CompanyDB & "]..ORIN(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "'"
1846 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1847 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Reference id#" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "invoice_logs")
1848 Try
1849 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1850 Catch ex As Exception
1851 End Try
1852 GoTo NextEntry
1853 End If
1854 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Importing returns for cloud reference id#" & oDr("id") & "...", , False)
1855
1856 ''MGPMGPMGPMGP
1857 If Not GetCardCode("", oDr("customer_id")) Then
1858 ErrorChecker = True
1859 GoTo NextEntry
1860 End If
1861
1862 .CardCode = CardCode
1863 .DocDate = oDr("utc_invoice_date")
1864 .DocDueDate = oDr("utc_invoice_date")
1865 .Comments = oDr("remark") + " | This transaction was made from APPTech & iRipple integration."
1866 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
1867 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
1868 .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
1869 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
1870 .NumAtCard = oDr("remark") + "ID"
1871
1872 Dim oTerritory As String = ""
1873 Dim oCategory As String = ""
1874 '.NumAtCard = oDr("reference") & "|" & oDr("branch_id")
1875 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM OCRD WHERE CardCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
1876 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1877 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
1878 oCategory = oDotNet.GetField(, "U_SalesCategory")
1879 Else
1880 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
1881 oTerritory = oDotNet.GetField(, "Territory")
1882 End If
1883
1884 oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
1885 Dim oItemCode As String
1886 For Each oDrView As DataRowView In oDetail.DefaultView
1887 With .Lines
1888
1889 ''MGP 03/01/2017
1890 ''For validation cause itemcode in their databases are not match
1891 If oCompany.CompanyDB = "ACI_FINAL" Then
1892 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
1893 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
1894 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
1895 Else
1896 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
1897 ErrorChecker = True
1898 GoTo NextEntry
1899 End If
1900 Else
1901 oItemCode = oDrView("product_stock_no")
1902 End If
1903
1904 oCheckQuantity = oDrView("quantity")
1905
1906 If oCheckQuantity.Substring(0, 1) <> "-" Then
1907 GoTo nextReturnLine
1908 End If
1909
1910 .ItemCode = oItemCode
1911 .Quantity = oDrView("quantity") * -1
1912 .WarehouseCode = WhsCode
1913 'CPA discount amount
1914 .Price = 0
1915 .UnitPrice = 0
1916 .PriceAfterVAT = oDrView("retail_price")
1917 .CostingCode = "SALES"
1918 If oCategory = "" Then
1919 .CostingCode2 = "RETAIL"
1920 .CostingCode3 = oTerritory
1921 Else
1922 .CostingCode2 = oCategory
1923 .CostingCode3 = oTerritory
1924 End If
1925
1926 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND ManBtchNum = 'Y'"
1927
1928 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1929 Dim oQuantity As Integer = oDrView("quantity") * -1
1930 Dim Qty As Integer = oDrView("quantity") * -1
1931
1932 oDotNet.strCommand = "SELECT * FROM [" & oCompany.CompanyDB & "]..vwAppGetBatch(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND WhsCode = '" & WhsCode & "'"
1933 Dim TotalQuantityHolder As Integer = 0
1934 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
1935
1936 For oQuantityCounter As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
1937
1938 TotalQuantityHolder += oDotNet.GetField(oQuantityCounter, "Quantity")
1939 If oQuantity > TotalQuantityHolder Then
1940 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1941 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1942 .BatchNumbers.Add()
1943 If oQuantityCounter = oDotNet.Ds.Tables(0).Rows.Count - 1 Then
1944 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1945 ErrorChecker = True
1946 GoTo NextEntry
1947 End If
1948 ElseIf oQuantity < TotalQuantityHolder Then
1949 .BatchNumbers.Quantity = Qty
1950 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1951 .BatchNumbers.Add()
1952 Exit For
1953 ElseIf oQuantity = TotalQuantityHolder Then
1954 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
1955 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
1956 .BatchNumbers.Add()
1957 Exit For
1958 End If
1959 Qty -= oDotNet.GetField(oQuantityCounter, "Quantity")
1960 Next
1961
1962 Else
1963 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1964 ErrorChecker = True
1965 GoTo NextEntry
1966 End If
1967
1968 End If
1969
1970 .Add()
1971nextReturnLine:
1972 End With
1973 Next
1974
1975 If Not .Add = 0 Then
1976 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
1977 Try
1978 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
1979 Catch ex As Exception
1980 End Try
1981 ErrorChecker = True
1982 GoTo NextEntry
1983 Else
1984 oWriteText(lsViewIm, Now & "[" & oDr("reference") & "] - " & "Successfully created returns with cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, True, "invoice_logs")
1985 Try
1986 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
1987 Catch ex As Exception
1988 End Try
1989
1990 End If
1991
1992 End With
1993
1994 End If
1995
1996 End If
1997
1998 Catch ex As Exception
1999 ErrorChecker = True
2000 oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & ex.ToString(), Color.Red, True, "invoice_logs")
2001 Try
2002 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2003 Catch exs As Exception
2004 End Try
2005 End Try
2006
2007NextEntry:
2008 '"Update LastExport date
2009 Dim oUpdateQry As String
2010 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 3) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 3) END WHERE U_App_Id = 3"
2011 _Path.strCommand = (oUpdateQry)
2012
2013 Next
2014 Catch ex As Exception
2015 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "invoice_logs")
2016 ErrorChecker = True
2017 End Try
2018
2019NextFile:
2020 If ErrorChecker = False Then
2021 pbIMInv.Position += 1
2022 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
2023 Else
2024 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
2025 pbIMInv.Position += 1
2026 End If
2027
2028 Next
2029
2030 'oWriteText(lsViewIm, Now & " - " & "Done importing Invoices.", Color.Green, False, )
2031 'oWriteText(lsViewIm, Now & " - " & "=========================================", , False, )
2032 pbIMInv.Properties.Minimum = 0
2033 pbIMInv.Position = 0
2034 pbIMInv.Properties.Maximum = 99
2035
2036 Catch ex As Exception
2037 oWriteText(lsViewIm, Now & " [Err] - Please contact the utility provider for this error " & ex.Message, Color.Red, True, "invoice_logs")
2038 End Try
2039 End If
2040 End Sub
2041 ' Private Sub Import_AIn()
2042 ' If AIn.Checked = True Then
2043 ' Try
2044 ' Dim oDatabase As String = ""
2045 ' '"Get Path
2046 ' Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2047 ' oDatabase = oRegistry.GetKeyValue("Database")
2048 ' _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 1"
2049
2050 ' Dim oPath As String, oDate As DateTime, _Date As String = Nothing
2051 ' oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
2052
2053 ' '"BTG 9/20/2016
2054 ' '"Check if folder has files
2055 ' If Directory.GetFiles(oPath, "ain_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
2056 ' GoTo HasFile
2057 ' End If
2058
2059 ' Try
2060 ' _Date = _Path.GetField(, "U_LastExportDate")
2061
2062 ' Catch ex As Exception
2063 ' End Try
2064
2065 ' Dim ts_Value As Integer = 0
2066 ' pbIMAIn.Properties.Minimum = 0
2067
2068 ' Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2069 ' _ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL)"
2070
2071 ' Dim oWhsDT As DataTable
2072 ' oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
2073
2074 ' Dim oXML As String
2075 ' Dim NewXML As String
2076 ' Dim ErrorChecker As Boolean = False
2077
2078 ' Dim oCount As Integer = 0
2079 ' Dim oPageCount As Integer = 0
2080 ' '"Loop every branches
2081 ' oWriteText(lsViewIm, Now & " - " & "Gathering Adjustment In information from each branch, please wait...", , False)
2082 ' For Each WhsDr As DataRowView In oWhsDT.DefaultView
2083 ' Dim _afterdate As String = ""
2084 ' If Not _Date Is Nothing Then
2085 ' _afterdate = "&after=" & _Date & ""
2086 ' End If
2087
2088 ' '"Check document page
2089 ' oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=adjustment_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2090 ' Dim myXmlDoc As XmlDocument = New XmlDocument
2091 ' myXmlDoc.LoadXml(oXML)
2092 ' Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
2093 ' For Each mynode As XmlNode In list
2094 ' oCount = mynode("count").InnerText
2095
2096 ' If oCount = 0 Then GoTo NextDocument
2097 ' Next
2098
2099 ' '"Create XML
2100 ' oPageCount = PageCount(oCount / 50)
2101 ' For Page As Integer = 1 To oPageCount
2102 ' oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=adjustment_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2103
2104 ' 'Dim myXmlDoc As XmlDocument = New XmlDocument
2105 ' If oXML = "<documents/>" Then
2106 ' GoTo NextDocument
2107 ' End If
2108
2109 ' NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
2110
2111 ' Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & "ain_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml")
2112 ' oSaveFile.WriteLine(NewXML)
2113 ' oSaveFile.Close()
2114 ' oSaveFile.Dispose()
2115
2116 ' Next
2117
2118 'NextDocument:
2119 ' Next
2120
2121 'HasFile:
2122 ' pbIMAIn.Properties.Minimum = 0
2123 ' pbIMAIn.Properties.Maximum = CInt(Directory.GetFiles(oPath, "ain_*.xml", SearchOption.TopDirectoryOnly).Count)
2124 ' pbIMAIn.Position = 0
2125
2126 ' '"Post to SAP
2127 ' Dim oFileName As String
2128 ' For Each oFile As String In Directory.GetFiles(oPath, "ain_*.xml", SearchOption.TopDirectoryOnly)
2129 ' If isStop Then Exit Sub
2130 ' oFileName = Path.GetFileName(oFile)
2131 ' oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , True, "ain_logs")
2132
2133 ' Dim _ErrCount As Integer = 1
2134 'Recon:
2135 ' If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "ain_logs") : Return
2136 ' If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "ain_logs") : _ErrCount += 1 : GoTo Recon
2137
2138 ' Dim ds As DataSet
2139 ' ds = New DataSet
2140 ' ds.ReadXml(oFile)
2141
2142 ' Dim oHeader As DataTable
2143 ' Dim oDetail As DataTable
2144
2145 ' oHeader = ds.Tables("document").Copy
2146 ' oDetail = ds.Tables("document_line").Copy
2147
2148 ' '"BTG 9/8/2016
2149 ' '"Transfer inside for each loop
2150 ' 'If Not oCompany.InTransaction Then
2151 ' ' oCompany.StartTransaction()
2152 ' 'End If
2153
2154 ' Dim oDocuments As SAPbobsCOM.Documents
2155 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)
2156
2157 ' For Each oDr As DataRow In oHeader.Rows
2158 ' Try
2159 ' If Not oCompany.InTransaction Then
2160 ' oCompany.StartTransaction()
2161 ' End If
2162
2163 ' With oDocuments
2164
2165 ' '"BTG 9/7/2016
2166 ' '"For Adjustment(s) that has Link, they should be transfer in
2167 ' If oDr("parent_document") <> "" Then
2168 ' Dim oTransfer As SAPbobsCOM.StockTransfer
2169 ' oTransfer = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
2170
2171 ' For i As Integer = 0 To 2 - 1
2172 ' If Not oCompany.InTransaction Then
2173 ' oCompany.StartTransaction()
2174 ' End If
2175
2176 ' With oTransfer
2177
2178 ' .DocDate = oDr("utc_document_date")
2179 ' .Comments = "From Adjustment In"
2180 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2181 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
2182 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
2183
2184 ' If Not GetTransferDetailsAdj(oDatabase, oDr("parent_document")) Then GoTo NextEntry
2185
2186 ' If i = 0 Then
2187 ' .ToWarehouse = "INT"
2188 ' .FromWarehouse = WhsCode
2189 ' .UserFields.Fields.Item("U_ToWhs").Value = ToWhsCode
2190 ' Else
2191 ' .ToWarehouse = ToWhsCode
2192 ' .FromWarehouse = "INT"
2193 ' '.UserFields.Fields.Item("U_ToWhs").Value = ToWhsCode
2194 ' End If
2195 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
2196
2197 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
2198 ' For Each oDrView As DataRowView In oDetail.DefaultView
2199 ' With .Lines
2200 ' .ItemCode = oDrView("product_stock_no")
2201 ' .Quantity = oDrView("unit_quantity")
2202 ' .UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tNO
2203 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
2204
2205 ' If ValidateItemBatch(oDrView("product_stock_no")) Then
2206 ' .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
2207 ' .BatchNumbers.Quantity = oDrView("quantity")
2208 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
2209 ' If Not GetBatch(oDatabase, oDrView("product_stock_no"), WhsCode, CDec(oDrView("quantity"))) Then
2210 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No valid batch number for item " & oDrView("product_stock_no") & ". Moving to next entry document." & " - File: " & oFileName, Color.Red, True, "ain_logs")
2211 ' ErrorChecker = True
2212 ' GoTo NextEntry
2213 ' End If
2214 ' .BatchNumbers.BatchNumber = Batch
2215 ' .BatchNumbers.Add()
2216 ' End If
2217
2218 ' .Add()
2219 ' End With
2220 ' Next
2221
2222 ' If Not .Add = 0 Then
2223 ' 'oErrLog()
2224 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "ain_logs")
2225 ' Try
2226 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2227 ' Catch ex As Exception
2228 ' End Try
2229 ' ErrorChecker = True
2230 ' GoTo NextEntry
2231 ' Else
2232 ' ''MGP 09/01/2016 added this portion now commited transaction per header not per file
2233 ' Try
2234 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2235
2236 ' Catch ex As Exception
2237
2238 ' End Try
2239 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Transfered reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True)
2240
2241 ' End If
2242
2243 ' End With
2244 ' Next
2245
2246 ' GoTo NextEntry
2247 ' End If
2248 ' 'Dim oCustomer As String = oDr("supplier_name")
2249 ' 'Dim _Customer As String()
2250 ' '_Customer = oCustomer.Split("|")
2251 ' '.CardCode = _Customer(0)
2252
2253 ' 'If Not GetCardCode("", oDr("order_id")) Then GoTo NextEntry
2254
2255 ' '.CardCode = CardCode
2256 ' .DocDate = oDr("utc_document_date")
2257 ' .Comments = oDr("remark")
2258 ' .UserFields.Fields.Item("U_PROCESS_TYpe").Value = oDr("document_purpose_code")
2259 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2260 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
2261
2262 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
2263
2264 ' If Not GetAccount("", oDr("document_purpose_code")) Then GoTo NextEntry
2265
2266 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
2267 ' For Each oDrView As DataRowView In oDetail.DefaultView
2268 ' With .Lines
2269 ' .ItemCode = oDrView("product_stock_no")
2270 ' .Quantity = oDrView("quantity")
2271 ' '"BTG 9/7/2016
2272 ' '"Removed, SAP will auto compute price
2273 ' '.PriceAfterVAT = oDrView("subtotal") / oDrView("quantity")
2274 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
2275 ' .WarehouseCode = WhsCode
2276 ' .AccountCode = AccountCodeGR
2277
2278 ' .Add()
2279 ' End With
2280 ' Next
2281
2282 ' If Not .Add = 0 Then
2283 ' 'oErrLog()
2284 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "ain_logs")
2285 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2286 ' ErrorChecker = True
2287 ' Else
2288 ' Try
2289 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2290 ' Catch ex As Exception
2291 ' End Try
2292 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Document reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "ain_logs")
2293 ' End If
2294
2295 ' End With
2296
2297 ' Catch ex As Exception
2298 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "ain_logs")
2299 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2300 ' End Try
2301
2302 'NextEntry:
2303
2304 ' '"Update LastExport date
2305 ' Dim oUpdateQry As String
2306 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 1) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 1) END WHERE U_App_Id = 1"
2307 ' _Path.strCommand = (oUpdateQry)
2308
2309 ' '"Per data each file
2310 ' Next
2311 ' '"Per XML file
2312 ' If ErrorChecker = False Then
2313 ' File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
2314 ' Else
2315 ' File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
2316 ' End If
2317
2318 ' pbIMAIn.Position += 1
2319
2320 ' Next
2321
2322 ' oWriteText(lsViewIm, Now & " - " & "Done importing Adjustment In.", Color.Green, False)
2323 ' oWriteText(lsViewIm, Now & " - " & "=========================================", , False)
2324
2325 ' Catch ex As Exception
2326 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "ain_logs")
2327 ' Return
2328 ' End Try
2329 ' End If
2330 ' End Sub
2331
2332 ' Private Sub Import_AOut()
2333 ' If AOut.Checked = True Then
2334 ' Try
2335 ' Dim oDatabase As String = ""
2336 ' '"Get Path
2337 ' Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2338 ' oDatabase = oRegistry.GetKeyValue("Database")
2339 ' _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 2"
2340
2341 ' Dim ErrorChecker As Boolean = False
2342 ' Dim oPath As String, oDate As DateTime, _Date As String = Nothing
2343 ' oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
2344
2345 ' '"BTG 9/20/2016
2346 ' '"Check if folder has files
2347 ' If Directory.GetFiles(oPath, "aout_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
2348 ' GoTo HasFile
2349 ' End If
2350
2351 ' Try
2352 ' _Date = _Path.GetField(, "U_LastExportDate")
2353
2354 ' Catch ex As Exception
2355 ' End Try
2356
2357 ' Dim ts_Value As Integer = 0
2358 ' pbIMAout.Properties.Minimum = 0
2359
2360 ' Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2361 ' _ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL)"
2362
2363 ' Dim oWhsDT As DataTable
2364 ' oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
2365
2366 ' Dim oXML As String
2367 ' Dim NewXML As String
2368
2369 ' Dim oCount As Integer = 0
2370 ' Dim oPageCount As Integer = 0
2371 ' '"Loop every branches
2372 ' oWriteText(lsViewIm, Now & " - " & "Gathering Adjustment Out information from each branch, please wait...", , False)
2373 ' For Each WhsDr As DataRowView In oWhsDT.DefaultView
2374 ' Dim _afterdate As String = ""
2375 ' If Not _Date Is Nothing Then
2376 ' _afterdate = "&after=" & _Date & ""
2377
2378 ' End If
2379 ' '"Check document page
2380 ' oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=adjustment_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2381 ' Dim myXmlDoc As XmlDocument = New XmlDocument
2382 ' myXmlDoc.LoadXml(oXML)
2383 ' Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
2384 ' For Each mynode As XmlNode In list
2385 ' oCount = mynode("count").InnerText
2386
2387 ' If oCount = 0 Then GoTo NextDocument
2388 ' Next
2389
2390 ' '"Create XML
2391 ' oPageCount = PageCount(oCount / 50)
2392 ' For Page As Integer = 1 To oPageCount
2393 ' oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=adjustment_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2394
2395 ' 'Dim myXmlDoc As XmlDocument = New XmlDocument
2396 ' If oXML = "<documents/>" Then
2397 ' GoTo NextDocument
2398 ' End If
2399
2400 ' NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
2401
2402 ' Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & "aout_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml")
2403 ' oSaveFile.WriteLine(NewXML)
2404 ' oSaveFile.Close()
2405 ' oSaveFile.Dispose()
2406
2407 ' Next
2408
2409 'NextDocument:
2410 ' Next
2411
2412 'HasFile:
2413 ' pbIMAout.Properties.Minimum = 0
2414 ' pbIMAout.Properties.Maximum = CInt(Directory.GetFiles(oPath, "aout_*.xml", SearchOption.TopDirectoryOnly).Count)
2415 ' pbIMAout.Position = 0
2416
2417 ' '"Post to SAP
2418 ' Dim oFileName As String
2419 ' For Each oFile As String In Directory.GetFiles(oPath, "aout_*.xml", SearchOption.TopDirectoryOnly)
2420 ' If isStop Then Exit Sub
2421 ' oFileName = Path.GetFileName(oFile)
2422 ' oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , True, "aout_logs")
2423
2424 ' Dim _ErrCount As Integer = 1
2425 'Recon:
2426 ' If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "aout_logs") : Return
2427 ' If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "aout_logs") : _ErrCount += 1 : GoTo Recon
2428
2429 ' Dim ds As DataSet
2430 ' ds = New DataSet
2431 ' ds.ReadXml(oFile)
2432
2433 ' Dim oHeader As DataTable
2434 ' Dim oDetail As DataTable
2435
2436 ' oHeader = ds.Tables("document").Copy
2437 ' oDetail = ds.Tables("document_line").Copy
2438
2439 ' If Not oCompany.InTransaction Then
2440 ' oCompany.StartTransaction()
2441 ' End If
2442
2443 ' Dim oDocuments As SAPbobsCOM.Documents
2444 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenExit)
2445
2446 ' For Each oDr As DataRow In oHeader.Rows
2447 ' Try
2448
2449 ' With oDocuments
2450 ' If oDr("parent_document") <> "" Then
2451 ' Dim oTransfer As SAPbobsCOM.StockTransfer
2452 ' oTransfer = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
2453
2454 ' For i As Integer = 0 To 2 - 1
2455 ' If Not oCompany.InTransaction Then
2456 ' oCompany.StartTransaction()
2457 ' End If
2458
2459 ' With oTransfer
2460
2461 ' .DocDate = oDr("utc_document_date")
2462 ' .Comments = "From Adjustment Out"
2463 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2464 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
2465 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
2466
2467 ' If Not GetTransferDetailsAdj(oDatabase, oDr("parent_document")) Then GoTo NextEntry
2468
2469 ' If i = 0 Then
2470 ' .ToWarehouse = "INT"
2471 ' .FromWarehouse = ToWhsCode
2472 ' .UserFields.Fields.Item("U_ToWhs").Value = WhsCode
2473 ' Else
2474 ' .ToWarehouse = WhsCode
2475 ' .FromWarehouse = "INT"
2476 ' '.UserFields.Fields.Item("U_ToWhs").Value = ToWhsCode
2477 ' End If
2478 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
2479
2480 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
2481 ' For Each oDrView As DataRowView In oDetail.DefaultView
2482 ' With .Lines
2483 ' .ItemCode = oDrView("product_stock_no")
2484 ' .Quantity = oDrView("unit_quantity")
2485 ' .UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tNO
2486 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
2487
2488 ' If ValidateItemBatch(oDrView("product_stock_no")) Then
2489 ' .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
2490 ' .BatchNumbers.Quantity = oDrView("quantity")
2491 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
2492 ' If Not GetBatch(oDatabase, oDrView("product_stock_no"), WhsCode, CDec(oDrView("quantity"))) Then
2493 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No valid batch number for item " & oDrView("product_stock_no") & ". Moving to next entry document." & " - File: " & oFileName, Color.Red, True, "aout_logs")
2494 ' ErrorChecker = True
2495 ' GoTo NextEntry
2496 ' End If
2497 ' .BatchNumbers.BatchNumber = Batch
2498 ' .BatchNumbers.Add()
2499 ' End If
2500
2501 ' .Add()
2502 ' End With
2503 ' Next
2504
2505 ' If Not .Add = 0 Then
2506 ' 'oErrLog()
2507 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "aout_logs")
2508 ' Try
2509 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2510 ' Catch ex As Exception
2511 ' End Try
2512 ' ErrorChecker = True
2513 ' GoTo NextEntry
2514 ' Else
2515 ' ''MGP 09/01/2016 added this portion now commited transaction per header not per file
2516 ' Try
2517 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2518
2519 ' Catch ex As Exception
2520
2521 ' End Try
2522 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Transfered reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "aout_logs")
2523
2524 ' End If
2525
2526 ' End With
2527 ' Next
2528
2529 ' GoTo NextEntry
2530 ' End If
2531 ' 'Dim oCustomer As String = oDr("supplier_name")
2532 ' 'Dim _Customer As String()
2533 ' '_Customer = oCustomer.Split("|")
2534 ' '.CardCode = _Customer(0)
2535
2536 ' 'If Not GetCardCode("", oDr("order_id")) Then GoTo NextEntry
2537
2538 ' '.CardCode = CardCode
2539 ' .DocDate = oDr("utc_document_date")
2540 ' .Comments = oDr("remark")
2541 ' .UserFields.Fields.Item("U_PROCESS_TYpe").Value = oDr("document_purpose_code")
2542 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2543 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
2544
2545 ' If Not GetAccount("", oDr("document_purpose_code")) Then GoTo NextEntry
2546 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
2547
2548 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
2549 ' For Each oDrView As DataRowView In oDetail.DefaultView
2550 ' With .Lines
2551 ' .ItemCode = oDrView("product_stock_no")
2552 ' .Quantity = oDrView("quantity")
2553 ' '"BTG 9/7/2016
2554 ' '"Removed, SAP will auto compute price
2555 ' '.PriceAfterVAT = oDrView("subtotal") / oDrView("quantity")
2556 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
2557 ' .WarehouseCode = WhsCode
2558 ' .AccountCode = AccountCodeGI
2559
2560 ' .Add()
2561 ' End With
2562 ' Next
2563
2564 ' If Not .Add = 0 Then
2565 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "aout_logs")
2566 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2567 ' '"Insert error table here
2568 ' ErrorChecker = True
2569 ' Else
2570 ' Try
2571 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2572 ' Catch ex As Exception
2573
2574 ' End Try
2575 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Document reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True)
2576 ' End If
2577 ' End With
2578
2579 ' Catch ex As Exception
2580 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "aout_logs")
2581 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2582 ' '"Insert error table here
2583 ' End Try
2584
2585 'NextEntry:
2586 ' '"Update LastExport date
2587 ' Dim oUpdateQry As String
2588 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 2) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 2) END WHERE U_App_Id = 2"
2589 ' _Path.strCommand = (oUpdateQry)
2590
2591 ' '"Per data each file
2592 ' Next
2593
2594 ' '"Per XML file
2595 ' If ErrorChecker = False Then
2596 ' File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
2597 ' Else
2598 ' File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
2599 ' End If
2600
2601 ' pbIMAout.Position += 1
2602
2603 ' Next
2604
2605 ' oWriteText(lsViewIm, Now & " - " & "Done importing Adjustment Out.", Color.Green, False)
2606 ' oWriteText(lsViewIm, Now & " - " & "=========================================", , False)
2607
2608 ' Catch ex As Exception
2609 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "aout_logs")
2610 ' Return
2611 ' End Try
2612 ' End If
2613 ' End Sub
2614
2615 '"BTG 8/9/2016
2616 '"For Invoice
2617 ' Private Sub Import_Invoice()
2618 ' If Invoice.Checked = True Then
2619 ' Try
2620 ' Dim oDatabase, oCheckQuantity As String
2621 ' '"Get Path
2622 ' Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2623 ' oDatabase = oRegistry.GetKeyValue("Database")
2624 ' _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 3"
2625
2626 ' Dim oPath As String, oDate As DateTime, _Date As String = Nothing
2627 ' oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
2628
2629 ' '"BTG 9/20/2016
2630 ' '"Check if folder has files
2631 ' If Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
2632 ' GoTo HasFile
2633 ' End If
2634
2635 ' Try
2636 ' 'oDate = _Path.GetField(, "U_LastExportDate")
2637 ' _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
2638 ' Catch ex As Exception
2639 ' End Try
2640
2641 ' Dim ts_Value As Integer = 0
2642 ' pbIMInv.Properties.Minimum = 0
2643
2644 ' Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
2645 ' '_ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL)"
2646 ' _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
2647 ' Dim oWhsDT As DataTable
2648 ' oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
2649
2650 ' Dim oXML As String
2651 ' Dim NewXML As String
2652
2653 ' Dim oCount As Integer = 0
2654 ' Dim oPageCount As Integer = 0
2655 ' '"Loop every branches
2656 ' oWriteText(lsViewIm, Now & " - " & "Gathering Invoice information from each branch, please wait...", , False)
2657 ' For Each WhsDr As DataRowView In oWhsDT.DefaultView
2658 ' Dim _afterdate As String = ""
2659 ' If Not _Date Is Nothing Then
2660 ' _afterdate = "&after=" & _Date & ""
2661 ' End If
2662
2663 ' '"Check document page
2664 ' oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/invoices.xml?q=count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2665 ' 'oXML = oRetail.HttpGet("http://nagantetrading.iretailcloud.com/api/invoices.xml?q=count&branch_id=1393&after=2016-11-05T07:29:29Z&before=2016-11-05T07:29:49Z", "")
2666 ' Dim myXmlDoc As XmlDocument = New XmlDocument
2667 ' myXmlDoc.LoadXml(oXML)
2668 ' Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
2669 ' For Each mynode As XmlNode In list
2670 ' oCount = mynode("count").InnerText
2671
2672 ' If oCount = 0 Then GoTo NextDocument
2673 ' Next
2674
2675 ' '"Create XML
2676 ' oPageCount = PageCount(oCount / 50)
2677 ' For Page As Integer = 1 To oPageCount
2678 ' ''MGP 08/31/2016 oPageCount = 2 but it wasn't going in the loop because of the step
2679 ' 'For Page As Integer = 1 To oPageCount Step -1
2680 ' oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/invoices.xml?page=" & Page & "&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
2681 ' 'oXML = oRetail.HttpGet("http://nagantetrading.iretailcloud.com/api/invoices.xml?branch_id=1393&after=2016-11-05T07:29:29Z&before=2016-11-05T07:29:49Z", "")
2682 ' 'Dim myXmlDoc As XmlDocument = New XmlDocument
2683
2684 ' If oXML = "<invoices/>" Then
2685 ' GoTo NextDocument
2686 ' End If
2687
2688 ' NewXML = oXML.Replace("</invoices>", "<branch><customer>" & WhsDr("GlblLocNum") & "</customer></branch></invoices>")
2689
2690 ' Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & "invoice_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml")
2691 ' oSaveFile.WriteLine(NewXML)
2692 ' oSaveFile.Close()
2693 ' oSaveFile.Dispose()
2694
2695 ' Next
2696
2697 'NextDocument:
2698 ' Next
2699
2700 'HasFile:
2701
2702 ' '"Post to SAP
2703 ' Dim oFileName As String
2704
2705
2706 ' pbIMInv.Properties.Minimum = 0
2707 ' pbIMInv.Properties.Maximum = CInt(Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly).Count)
2708 ' pbIMInv.Position = 0
2709
2710 ' For Each oFile As String In Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly)
2711 ' If isStop Then Exit Sub
2712 ' oFileName = Path.GetFileName(oFile)
2713 ' oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Invoice(s), please wait...", , True, "invoice_logs")
2714 ' Dim ErrorChecker As Boolean = False
2715 ' Dim _ErrCount As Integer = 1
2716 'Recon:
2717 ' If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "invoice_logs") : Return
2718 ' If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "invoice_logs") : _ErrCount += 1 : GoTo Recon
2719
2720 ' Dim ds As DataSet
2721 ' ds = New DataSet
2722 ' ds.ReadXml(oFile)
2723
2724 ' Dim oBranch As DataTable
2725 ' Dim oHeader As DataTable
2726 ' Dim oDetail As DataTable
2727 ' Dim oPayment As DataTable
2728
2729 ' oBranch = ds.Tables("branch")
2730 ' oHeader = ds.Tables("invoice").Copy
2731 ' oDetail = ds.Tables("invoice_line").Copy
2732
2733 ' Try
2734 ' oPayment = ds.Tables("payment").Copy
2735 ' Catch ex As Exception
2736 ' oPayment = Nothing
2737 ' End Try
2738
2739 ' Dim oDocEntry As String, oReference As String
2740
2741 ' '"BTG 8/10/2016
2742 ' '"For branch = warehouse
2743 ' For Each Branch As DataRow In oBranch.Rows
2744 ' If Not GetWhs("", Branch("customer")) Then
2745 ' ErrorChecker = True
2746 ' GoTo NextFile
2747 ' End If
2748
2749 ' Next
2750
2751 ' Dim _PaymentSum As Decimal = 0.0, _isLoopCheck As Boolean = False, oRounding As Decimal = 0.0
2752 ' 'LoopCheck:
2753 ' For Each oDr As DataRow In oHeader.Rows
2754
2755 ' If Not oCompany.InTransaction Then
2756 ' oCompany.StartTransaction()
2757 ' End If
2758
2759 ' Try
2760
2761 ' Dim oDocuments As SAPbobsCOM.Documents
2762 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
2763
2764 ' oDocEntry = ""
2765 ' oReference = oDr("reference")
2766
2767 ' ''MGP 02/15/2017 this is for ar cm
2768
2769 ' If oDr("has_returns") = "true" And oDr("status") = "S" Then
2770 ' '"For CM
2771 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oCreditNotes)
2772 ' With oDocuments
2773
2774 ' oWriteText(lsViewIm, Now & " [Info] - Importing returns with cloud reference id#" & oDr("id") & "...", , False)
2775
2776 ' oDotNet.strCommand = "SELECT TOP 1 U_AppPOSRefId FROM ORIN(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "'"
2777 ' If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
2778 ' oWriteText(lsViewIm, Now & " [Info] - " & "[" & oDr("reference") & "] " & "Reference id#" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "invoice_logs")
2779 ' GoTo skipARCM
2780 ' End If
2781
2782 ' ''MGPMGPMGPMGP
2783 ' If Not GetCardCode("", oDr("customer_id")) Then
2784 ' ErrorChecker = True
2785 ' GoTo NextEntry
2786 ' End If
2787
2788 ' .CardCode = CardCode
2789 ' .DocDate = oDr("utc_invoice_date")
2790 ' .DocDueDate = oDr("utc_invoice_date")
2791 ' .Comments = oDr("remark")
2792 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2793 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
2794 ' .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
2795 ' .NumAtCard = oDr("reference") & "|" & oDr("branch_id")
2796
2797 ' oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
2798 ' For Each oDrView As DataRowView In oDetail.DefaultView
2799 ' With .Lines
2800 ' oCheckQuantity = oDrView("quantity")
2801
2802 ' If oCheckQuantity.Substring(0, 1) <> "-" Then
2803 ' GoTo nextReturnLine
2804 ' End If
2805 ' '"BTG 8/11/2016
2806 ' '"For validation of unit_quantity
2807 ' '"Temporary
2808
2809 ' .ItemCode = oDrView("product_stock_no")
2810 ' .Quantity = oDrView("quantity") * -1
2811 ' .WarehouseCode = WhsCode
2812 ' .Price = oDrView("retail_price")
2813 ' .CostingCode2 = "RETAIL"
2814 ' .CostingCode3 = "LAMIAN"
2815
2816 ' .Add()
2817 'nextReturnLine:
2818 ' End With
2819 ' Next
2820
2821 ' If Not .Add = 0 Then
2822 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
2823 ' Try
2824 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2825 ' Catch ex As Exception
2826 ' End Try
2827 ' ErrorChecker = True
2828 ' GoTo NextEntry
2829 ' Else
2830 ' Try
2831 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2832 ' Catch ex As Exception
2833 ' End Try
2834 ' oWriteText(lsViewIm, Now & " - " & "[" & oDr("reference") & "] " & "Successfully created credit memo cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, True, "invoice_logs")
2835 ' End If
2836
2837 ' End With
2838
2839 ' '"For void
2840 ' '"BTG 9/8/2016
2841 ' ElseIf oReference.Last = "V" Or oReference.Last = "F" Then
2842 ' oDotNet.strCommand = "SELECT U_AppPOSRefId FROM OINV(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "'"
2843 ' If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
2844 ' oWriteText(lsViewIm, Now & " [Info] - " & "[" & oDr("reference") & "] " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "invoice_logs")
2845 ' GoTo NextEntry
2846 ' End If
2847
2848 ' Dim _DocEntry As Long, _PaymentNum As String = "", _PayEntry As Long
2849 ' Dim _Remark As String(), _ref As String(), _terminal As Integer, _branch_name As String, _reference As String(), _refInt As Integer
2850 ' '"Split remark to get REF#
2851 ' _Remark = Split(oDr("remark"), "|")
2852 ' _ref = Split(_Remark(0), " ")
2853 ' '"BTG 9/15/2016
2854 ' '"For reference in invoice
2855 ' _reference = Split(_ref(1), "-")
2856 ' oReference = _reference(1)
2857 ' _refInt = CInt(oReference)
2858 ' _terminal = _Remark(2).Remove(0, 1)
2859
2860 ' oDotNet.strCommand = "SELECT DocEntry, ReceiptNum FROM OINV(NOLOCK) WHERE NumAtCard = '" & _terminal & "-" & _refInt & "|" & oDr("branch_id") & "'"
2861 ' If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
2862 ' _DocEntry = oDotNet.GetField(, "DocEntry")
2863 ' Try
2864 ' _PaymentNum = oDotNet.GetField(, "ReceiptNum")
2865 ' Catch ex As Exception
2866 ' _PaymentNum = ""
2867 ' End Try
2868 ' End If
2869 ' If _PaymentNum <> "" Then
2870 ' oDotNet.strCommand = "SELECT DocEntry FROM ORCT(NOLOCK) WHERE DocNum = '" & _PaymentNum & "' "
2871 ' If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
2872 ' _PayEntry = oDotNet.GetField(, "DocEntry")
2873 ' End If
2874
2875 ' Dim oCancelPayment As SAPbobsCOM.Payments
2876 ' oCancelPayment = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments)
2877 ' With oCancelPayment
2878 ' If .GetByKey(_PayEntry) Then
2879 ' If Not .Cancel = 0 Then
2880 ' 'oErrLog()
2881 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
2882 ' Try
2883 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2884 ' Catch ex As Exception
2885 ' End Try
2886
2887 ' ErrorChecker = True
2888 ' GoTo NextEntry
2889 ' End If
2890 ' Else
2891 ' GoTo NextEntry
2892 ' End If
2893 ' End With
2894 ' End If
2895
2896 ' '"Cancel Invoice
2897 ' With oDocuments
2898 ' If .GetByKey(_DocEntry) Then
2899 ' Dim oCancelDoc As SAPbobsCOM.Documents
2900 ' oCancelDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
2901 ' oCancelDoc = oDocuments.CreateCancellationDocument
2902
2903 ' If Not oCancelDoc.Add = 0 Then
2904 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
2905 ' Try
2906 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2907 ' Catch ex As Exception
2908 ' End Try
2909 ' GoTo NextEntry
2910 ' End If
2911
2912 ' oCompany.GetNewObjectCode(_DocEntry)
2913
2914 ' If .GetByKey(_DocEntry) Then
2915 ' .NumAtCard = oDr("reference") & "|" & oDr("branch_id")
2916 ' '"BTG 9/23/2016
2917 ' '"For reference
2918 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2919 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
2920 ' .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
2921 ' .Comments = .Comments & " - " & oDr("remark")
2922
2923 ' If Not .Update = 0 Then
2924 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
2925 ' Try
2926 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
2927 ' Catch ex As Exception
2928 ' End Try
2929 ' Else
2930 ' Try
2931 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
2932 ' Catch ex As Exception
2933 ' End Try
2934 ' oWriteText(lsViewIm, Now & " - " & "[" & oDr("reference") & "] " & "Successfully Cancelled Invoices...", Color.Green, True, "invoice_logs")
2935 ' End If
2936 ' End If
2937
2938 ' GoTo NextEntry
2939 ' End If
2940
2941 ' End With
2942
2943 ' ''Start of invoice here
2944 ' Else
2945 ' Dim DocTotalInv As Decimal = 0.0
2946 ' Dim isCommit As Boolean = False
2947
2948 ' With oDocuments
2949
2950 ' '"BTG 8/30/2016
2951 ' '"If customer_id is blank get default cardcode in Warehouse
2952
2953 ' If Not GetCardCode("", oDr("customer_id")) Then
2954 ' ErrorChecker = True
2955 ' GoTo NextEntry
2956 ' End If
2957 ' ''MGP 08/31/2016 added to avoid duplication of record
2958 ' oDotNet.strCommand = "SELECT TOP 1 DocEntry FROM OINV WHERE U_AppPOSRefId = '" & oDr("id") & "'"
2959 ' If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
2960 ' oWriteText(lsViewIm, Now & " [Err] - " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "invoice_logs")
2961 ' GoTo NextEntry
2962 ' End If
2963
2964 ' .CardCode = CardCode
2965 ' .DocDate = oDr("utc_invoice_date")
2966 ' .DocDueDate = oDr("utc_invoice_date")
2967 ' .Comments = oDr("remark")
2968 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
2969 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
2970 ' .UserFields.Fields.Item("U_AppPOSRefBranch").Value = WhsName
2971 ' '.UserFields.Fields.Item("U_WRR").Value = "0407" '"- Hard Coded
2972 ' '.UserFields.Fields.Item("U_Rec_Location").Value = "HO" '"- Hard Coded
2973
2974 ' '"BTG 9/15/2016
2975 ' '"Parsing reference
2976 ' Dim oRef As String(), _Terminal As Integer, _Ref As Integer
2977
2978 ' oRef = Split(oDr("reference"), "-")
2979 ' _Terminal = oRef(0)
2980 ' _Ref = oRef(1)
2981
2982 ' .NumAtCard = _Terminal & "-" & _Ref & "|" & oDr("branch_id")
2983
2984 ' Dim _ItemCode As String = "", _Qty As Decimal = 0.0
2985 ' oDetail.DefaultView.RowFilter = "invoice_lines_id = '" & oDr("invoice_id") & "' "
2986 ' For Each oDrView As DataRowView In oDetail.DefaultView
2987 ' With .Lines
2988
2989 ' .ItemCode = oDrView("product_stock_no")
2990
2991 ' .Quantity = oDrView("quantity")
2992 ' .Price = oDrView("price")
2993 ' .WarehouseCode = WhsCode
2994
2995 ' '"For testing - Hard coded
2996 ' .CostingCode2 = "RETAIL"
2997 ' .CostingCode3 = "LAMIAN"
2998
2999 ' .ItemCode = oDrView("product_stock_no")
3000
3001 ' .Add()
3002 ' End With
3003 ' Next
3004
3005 ' If Not .Add = 0 Then
3006 ' 'oErrLog()
3007 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3008
3009 ' Try
3010 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3011 ' Catch ex As Exception
3012 ' End Try
3013 ' ErrorChecker = True
3014 ' GoTo NextEntry
3015 ' End If
3016
3017 ' oCompany.GetNewObjectCode(oDocEntry)
3018
3019 ' oQry = Nothing
3020 ' oQry = "SELECT DocTotal, DocEntry FROM OINV(NOLOCK) WHERE DocEntry = '" & oDocEntry & "' "
3021 ' oDotNet.strCommand = oQry
3022 ' DocTotalInv = oDotNet.GetField(, "DocTotal")
3023
3024 ' End With
3025
3026 ' '"For payment
3027 ' Dim oIncoming As SAPbobsCOM.Payments
3028 ' oIncoming = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments)
3029
3030 ' Dim oCash As Decimal = 0.0, oPaymentSum As Decimal = 0.0, oCM As Decimal = 0.0
3031
3032 ' Dim _CMOnly As Boolean = False
3033 ' Dim _ChargeOnly As Boolean = False
3034 ' With oIncoming
3035 ' .CardCode = CardCode
3036 ' .DocDate = oDr("utc_invoice_date")
3037 ' .Remarks = "From iRC"
3038 ' oPayment.DefaultView.RowFilter = "payments_id = '" & oDr("invoice_id") & "' "
3039 ' oPayment.DefaultView.Sort = "payment_type_id DESC"
3040 ' For Each oDrViewPayment As DataRowView In oPayment.DefaultView
3041 ' Select Case oDrViewPayment("payment_type_name")
3042 ' Case "Cash"
3043 ' .CashSum = oDrViewPayment("amount")
3044 ' Case "Credit Card"
3045 ' .CreditCards.CardValidUntil = "12/2099" 'CDate(oDrPayment("card_expiry")) '"12/2013" (MM/DD/YYYY)
3046 ' .CreditCards.CreditCard = 1
3047 ' .CreditCards.CreditType = SAPbobsCOM.BoRcptCredTypes.cr_Regular
3048 ' .CreditCards.CreditCardNumber = oDrViewPayment("card_last_4_digits")
3049 ' .CreditCards.CreditSum = oDrViewPayment("amount")
3050 ' .CreditCards.PaymentMethodCode = 1
3051 ' .CreditCards.VoucherNum = "123"
3052 ' .CreditCards.Add()
3053 ' oPaymentSum += oDrViewPayment("amount")
3054
3055 ' _CMOnly = False
3056 ' _ChargeOnly = False
3057 ' Case "Gift Certificate"
3058
3059 ' .CreditCards.CardValidUntil = "12/2099" 'CDate(oDrPayment("card_expiry")) '"12/2013" (MM/DD/YYYY)
3060 ' .CreditCards.CreditCard = 2
3061 ' .CreditCards.CreditType = SAPbobsCOM.BoRcptCredTypes.cr_Regular
3062 ' .CreditCards.CreditCardNumber = "1234"
3063 ' .CreditCards.CreditSum = oDrViewPayment("amount")
3064 ' .CreditCards.PaymentMethodCode = 1
3065 ' .CreditCards.VoucherNum = "123"
3066 ' .CreditCards.Add()
3067
3068 ' oPaymentSum += oDrViewPayment("amount")
3069
3070 ' _CMOnly = False
3071 ' _ChargeOnly = False
3072 ' Case "Debit Card"
3073
3074 ' .CreditCards.CardValidUntil = "12/2099" 'CDate(oDrPayment("card_expiry")) '"12/2013" (MM/DD/YYYY)
3075 ' .CreditCards.CreditCard = 3
3076 ' .CreditCards.CreditType = SAPbobsCOM.BoRcptCredTypes.cr_Regular
3077 ' .CreditCards.CreditCardNumber = "1234"
3078 ' .CreditCards.CreditSum = oDrViewPayment("amount")
3079 ' .CreditCards.PaymentMethodCode = 1
3080 ' .CreditCards.VoucherNum = "123"
3081 ' .CreditCards.Add()
3082
3083 ' oPaymentSum += oDrViewPayment("amount")
3084
3085 ' _CMOnly = False
3086 ' _ChargeOnly = False
3087 ' Case "Check"
3088
3089 ' .CheckAccount = CheckAcc
3090 ' .Checks.DueDate = oDrViewPayment("date") '"#12/31/2014#" 'TrimDate(oDr("payment_duedate"))
3091 ' .Checks.CheckSum = oDrViewPayment("amount")
3092
3093 ' Dim oChecks As String = oDrViewPayment("reference")
3094 ' If oChecks.Length > 6 Then
3095 ' .Checks.CheckNumber = oChecks.Substring(0, 6)
3096
3097 ' Else
3098 ' .Checks.CheckNumber = oDrViewPayment("reference")
3099 ' End If
3100
3101 ' .Checks.BankCode = oDrViewPayment("bank")
3102 ' .Checks.Add()
3103
3104 ' oPaymentSum += oDrViewPayment("amount")
3105
3106 ' _CMOnly = False
3107 ' _ChargeOnly = False
3108 ' Case "Credit Memo"
3109 ' 'Dim xWhsName As String, _WhsName As String()
3110 ' Dim xReference As String, _Reference As String()
3111
3112 ' 'xWhsName = oDr("remark") : _WhsName = xWhsName.Split("|")
3113 ' xReference = oDrViewPayment("reference") : _Reference = xReference.Split("|")
3114
3115 ' '"Get CM DocEntry
3116 ' 'GetInvDocEntry("", _Reference(0).Replace("CM#", ""), _Reference(1))
3117 ' GetInvDocEntry("", _Reference(0).Replace("CM#", ""), WhsName)
3118
3119 ' .Invoices.DocEntry = InvDocEntry
3120 ' .Invoices.InvoiceType = 14
3121 ' .Invoices.SumApplied = (oDrViewPayment("amount") * -1)
3122 ' .Invoices.Add()
3123
3124 ' oCM += oDrViewPayment("amount")
3125 ' oPaymentSum += oDrViewPayment("amount")
3126
3127 ' _CMOnly = True
3128 ' _ChargeOnly = False
3129
3130 ' End Select
3131 ' Next
3132
3133 ' .Invoices.DocEntry = oDocEntry
3134 ' .Invoices.InvoiceType = 13
3135 ' .Invoices.Add()
3136
3137 ' If Not .Add = 0 Then
3138 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3139 ' Try
3140 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3141 ' Catch ex As Exception
3142 ' End Try
3143
3144 ' ErrorChecker = True
3145 ' GoTo NextEntry
3146 ' Else
3147
3148 ' ''MGP 09/01/2016 added this portion now commited transaction per header not per file
3149 ' Try
3150 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
3151 ' Catch ex As Exception
3152 ' End Try
3153 ' oWriteText(lsViewIm, Now & " - " & "[" & oDr("reference") & "] " & "Successfully created Invoice cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, True, "invoice_logs")
3154 ' End If
3155
3156 ' End With
3157
3158 ' End If
3159
3160 ' Catch ex As Exception
3161 ' oWriteText(lsViewIm, Now & " [Err] - " & "[" & oDr("reference") & "] " & ex.ToString(), Color.Red, True, "invoice_logs")
3162 ' Try
3163 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3164 ' Catch exs As Exception
3165 ' End Try
3166 ' End Try
3167
3168 'NextEntry:
3169 ' '"Update LastExport date
3170 ' Dim oUpdateQry As String
3171 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 3) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 3) END WHERE U_App_Id = 3"
3172 ' _Path.strCommand = (oUpdateQry)
3173
3174 ' Next
3175
3176 'NextFile:
3177 ' If ErrorChecker = False Then
3178 ' File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
3179 ' Else
3180 ' File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
3181 ' End If
3182
3183 ' pbIMInv.Position += 1
3184
3185 ' Next
3186
3187 ' oWriteText(lsViewIm, Now & " - " & "Done importing Invoices.", Color.Green, False, )
3188 ' oWriteText(lsViewIm, Now & " - " & "=========================================", , False, )
3189
3190 ' Catch ex As Exception
3191 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "invoice_logs")
3192 ' 'Return
3193 ' End Try
3194 ' End If
3195 ' End Sub
3196
3197 '"BTG 8/15/2016
3198 '"For Transfer In
3199 Private Sub Import_TIn()
3200 If TIn.Checked Then
3201 Try
3202 Dim oDatabase As String = ""
3203 Dim r As Random = New Random
3204 '"Get Path
3205 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3206 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3207 oDatabase = oRegistry.GetKeyValue("Database")
3208 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 4"
3209 Dim ErrorChecker As Boolean = False
3210 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
3211 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
3212
3213 '"BTG 9/20/2016
3214 '"Check if folder has files
3215 If Directory.GetFiles(oPath, "tin_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
3216 GoTo HasFile
3217 End If
3218
3219 Try
3220 _Date = _Path.GetField(, "U_LastExportDate")
3221
3222 Catch ex As Exception
3223 End Try
3224
3225 Dim ts_Value As Integer = 0
3226 pbIMTin.Properties.Minimum = 0
3227
3228 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3229
3230 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
3231
3232 Dim oWhsDT As DataTable
3233 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
3234
3235 Dim oXML As String
3236 Dim NewXML As String
3237
3238 Dim oCount As Integer = 0
3239 Dim oPageCount As Integer = 0
3240 '"Loop every branches
3241
3242 For Each WhsDr As DataRowView In oWhsDT.DefaultView
3243 Dim _afterdate As String = ""
3244 If Not _Date Is Nothing Then
3245 _afterdate = "&after=" & _Date & ""
3246 End If
3247
3248 '"Check document page
3249
3250 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=transfer_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
3251 'oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=transfer_in&branch_id=1078" & _afterdate & "", "")
3252
3253 Dim myXmlDoc As XmlDocument = New XmlDocument
3254 myXmlDoc.LoadXml(oXML)
3255 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
3256 For Each mynode As XmlNode In list
3257 oCount = mynode("count").InnerText
3258
3259 If oCount = 0 Then
3260 GoTo NextDocument
3261 End If
3262 oWriteText(lsViewIm, Now & " - " & "Gathering information Transfer In transaction from branch " & WhsDr("WhsName") & ", please wait...", , False)
3263
3264 Next
3265
3266 '"Create XML
3267 oPageCount = PageCount(oCount / 50)
3268 For Page As Integer = 1 To oPageCount
3269 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=transfer_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
3270
3271 'Dim myXmlDoc As XmlDocument = New XmlDocument
3272 If oXML = "<documents/>" Then
3273 GoTo NextDocument
3274 End If
3275
3276 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
3277 Dim oGetFileName As String = "tin_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
3278 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
3279 oSaveFile.WriteLine(NewXML)
3280 oSaveFile.Close()
3281 oSaveFile.Dispose()
3282
3283 Dim ds As DataSet
3284 ds = New DataSet
3285 ds.ReadXml(oPath & "\" & oGetFileName)
3286
3287 Dim oHeader As DataTable
3288
3289
3290 oHeader = ds.Tables("document").Copy
3291
3292 For Each oDr As DataRow In oHeader.Rows
3293 '"Update LastExport date
3294 Dim oUpdateQry As String
3295 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 4) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 4) END WHERE U_App_Id = 4"
3296 _Path.strCommand = (oUpdateQry)
3297 Next
3298
3299 Next
3300NextDocument:
3301 Next
3302
3303HasFile:
3304 pbIMTin.Properties.Minimum = 0
3305 pbIMTin.Properties.Maximum = CInt(Directory.GetFiles(oPath, "tin_*.xml", SearchOption.TopDirectoryOnly).Count)
3306 pbIMTin.Position = 0
3307
3308 '"Post to SAP
3309 Dim oFileName As String
3310 For Each oFile As String In Directory.GetFiles(oPath, "tin_*.xml", SearchOption.TopDirectoryOnly)
3311 If isStop Then Exit Sub
3312 oFileName = Path.GetFileName(oFile)
3313 oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Transfer In, please wait...", , True, "transferin_logs")
3314
3315 Dim _ErrCount As Integer = 1
3316Recon:
3317 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "transferin_logs") : Return
3318 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "transferin_logs") : _ErrCount += 1 : GoTo Recon
3319
3320 Dim ds As DataSet
3321 ds = New DataSet
3322 ds.ReadXml(oFile)
3323
3324 Dim oHeader As DataTable
3325 Dim oDetail As DataTable
3326
3327 oHeader = ds.Tables("document").Copy
3328
3329 Dim _reference() As String
3330 For Each oDr As DataRow In oHeader.Rows
3331 Try
3332
3333 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
3334 If Not oChangeDatabase("ACI_FINAL") Then
3335 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
3336 ErrorChecker = True
3337 GoTo NextFile
3338 End If
3339 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
3340 If Not oChangeDatabase("AFSI_FINAL") Then
3341 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
3342 ErrorChecker = True
3343 GoTo NextFile
3344 End If
3345 End If
3346
3347 Dim oDotNetSave As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3348
3349 oDotNetSave.strCommand = "SELECT * FROM [APP_AFSI]..[APP_TransferIn] WHERE cloud_id = '" & oDr("id") & "' AND update_date = '" & oDr("utc_updated_at") & "'"
3350 If oDotNetSave.Ds.Tables(0).Rows.Count <= 0 Then
3351 oDotNetSave.strCommand = "INSERT INTO APP_AFSI..APP_TransferIn VALUES ('" & oFileName & "','" & oDr("reference") & "','" & oDr("id") & "','" & oDr("utc_updated_at") & "',GETDATE())"
3352 End If
3353
3354 If Not oCompany.InTransaction Then
3355 oCompany.StartTransaction()
3356 End If
3357
3358 Dim oDocuments As SAPbobsCOM.StockTransfer
3359 oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
3360
3361 If ValidateTransferId("[" & oCompany.CompanyDB & "]..OWTR", oDr("id")) AndAlso oDr("status") = "V" Then
3362 '"BTG 8/25/2016
3363 '"For cancelation
3364 With oDocuments
3365 If .GetByKey(DocEntry) Then
3366 If Not .Cancel = 0 Then
3367 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "transferin_logs")
3368 Try
3369 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3370 Catch ex As Exception
3371 End Try
3372 End If
3373 GoTo NextEntry
3374 Else
3375 oWriteText(lsViewIm, Now & " [Err] - No record(s) found [TOut]." & " - File: " & oFileName, Color.Red, True, "transferin_logs")
3376 Try
3377 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3378 Catch ex As Exception
3379 End Try
3380 ErrorChecker = True
3381 GoTo NextEntry
3382 End If
3383 End With
3384
3385 End If
3386
3387
3388 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OWTR WHERE U_APPPosRefId = '" & oDr("id") & "'"
3389
3390 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
3391 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Inventory Transfer with " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "orders_logs")
3392 GoTo NextEntry
3393 End If
3394
3395 With oDocuments
3396 .DocDate = oDr("utc_document_date")
3397 If Not GetWhs("", oDr("branch_id")) Then
3398 ErrorChecker = True
3399 GoTo NextEntry
3400 End If
3401
3402 oDotNet.strCommand = "SELECT U_ToWhs FROM [" & oCompany.CompanyDB & "]..OWTR WHERE U_AppPOSRefId = '" & oDr("parent_document") & "'"
3403
3404 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
3405 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Parent document of Transfer in with " & "Reference id #" & oDr("id") & " is not yet posted" & " - File: " & oFileName, Color.Red, False, "orders_logs")
3406 ErrorChecker = True
3407 GoTo NextEntry
3408 End If
3409
3410 .Comments = oDr("remark") & " | " & oDr("parent_document") & " | " & WhsCode
3411 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
3412 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference")
3413 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
3414 .FromWarehouse = "I-" + oDotNet.GetField(, "U_ToWhs")
3415 '.UserFields.Fields.Item("U_ToWhs").Value = WhsCode
3416 .UserFields.Fields.Item("U_AppIsExported").Value = "1"
3417 oDetail = ds.Tables("document_line").Copy
3418 oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
3419 Dim oItemCode As String
3420 For Each oDrView As DataRowView In oDetail.DefaultView
3421 With .Lines
3422
3423 ''MGP 03/01/2017
3424 ''For validation cause itemcode in their databases are not match
3425 If oCompany.CompanyDB = "ACI_FINAL" Then
3426 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
3427 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
3428 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
3429 Else
3430 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
3431 ErrorChecker = True
3432 GoTo NextEntry
3433 End If
3434 Else
3435 oItemCode = oDrView("product_stock_no")
3436 End If
3437
3438 .ItemCode = oItemCode
3439 .Quantity = oDrView("unit_quantity")
3440 If Not GetWhs("", oDr("branch_id")) Then
3441 ErrorChecker = True
3442 GoTo NextEntry
3443 End If
3444 .WarehouseCode = WhsCode
3445
3446 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oItemCode & "' AND ManBtchNum = 'Y'"
3447
3448 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
3449 Dim oQuantity As Integer = oDrView("quantity")
3450 Dim Qty As Integer = oDrView("quantity")
3451
3452 oDotNet.strCommand = "SELECT * FROM [" & oCompany.CompanyDB & "]..vwAppGetBatch(NOLOCK) WHERE ItemCode = '" & oItemCode & "' AND WhsCode = 'I-" & WhsCode & "'"
3453 Dim TotalQuantityHolder As Integer = 0
3454 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
3455
3456 For oQuantityCounter As Integer = 0 To oDotNet.Ds.Tables(0).Rows.Count - 1
3457
3458 TotalQuantityHolder += oDotNet.GetField(oQuantityCounter, "Quantity")
3459 If oQuantity > TotalQuantityHolder Then
3460 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
3461 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
3462 .BatchNumbers.Add()
3463 If oQuantityCounter = oDotNet.Ds.Tables(0).Rows.Count - 1 Then
3464 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3465 ErrorChecker = True
3466 GoTo NextEntry
3467 End If
3468 ElseIf oQuantity < TotalQuantityHolder Then
3469 .BatchNumbers.Quantity = Qty
3470 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
3471 .BatchNumbers.Add()
3472 Exit For
3473 ElseIf oQuantity = TotalQuantityHolder Then
3474 .BatchNumbers.Quantity = oDotNet.GetField(oQuantityCounter, "Quantity")
3475 .BatchNumbers.BatchNumber = oDotNet.GetField(oQuantityCounter, "BatchNum")
3476 .BatchNumbers.Add()
3477 Exit For
3478 End If
3479 Qty -= oDotNet.GetField(oQuantityCounter, "Quantity")
3480 Next
3481
3482 Else
3483 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no valid or available batchnumber for ItemCode : " & oItemCode & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3484 ErrorChecker = True
3485 GoTo NextEntry
3486 End If
3487
3488 End If
3489
3490 .Add()
3491 End With
3492 Next
3493
3494 If Not .Add = 0 Then
3495
3496 oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "transferin_logs")
3497 Try
3498 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3499 Catch ex As Exception
3500 End Try
3501 ErrorChecker = True
3502 GoTo NextEntry
3503 Else
3504 Try
3505 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
3506 Catch ex As Exception
3507 End Try
3508 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & "Successfully created Transfer In cloud id# " & oDr("id") & " " & " - File: " & oFileName, Color.Green, True)
3509 End If
3510
3511 End With
3512
3513 Catch ex As Exception
3514 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString() & " - File: " & oFileName, Color.Red, True, "transferin_logs")
3515 Try
3516 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3517 Catch exs As Exception
3518 End Try
3519 ErrorChecker = True
3520 End Try
3521
3522NextEntry:
3523
3524 '"Update LastExport date
3525 Dim oUpdateQry As String
3526 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 4) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 4) END WHERE U_App_Id = 4"
3527 _Path.strCommand = (oUpdateQry)
3528
3529 '"Per data each file
3530 Next
3531NextFile:
3532 If ErrorChecker = False Then
3533 pbIMTin.Position += 1
3534 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
3535 Else
3536 pbIMTin.Position += 1
3537 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
3538 End If
3539
3540 Next
3541
3542 pbIMTin.Properties.Minimum = 0
3543 pbIMTin.Properties.Maximum = 99
3544 pbIMTin.Position = 0
3545
3546 Catch ex As Exception
3547 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "transferin_logs")
3548 Return
3549 End Try
3550 End If
3551 End Sub
3552
3553 '"BTG 8/23/2016
3554 '"For Transfer Out
3555 ' Private Sub Import_TOut()
3556 ' If TOut.Checked Then
3557
3558 ' Try
3559 ' Dim oDatabase As String = ""
3560 ' '"Get Path
3561 ' Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3562 ' oDatabase = oRegistry.GetKeyValue("Database")
3563 ' Dim oDotnetTOut As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3564 ' Dim oDotNetCheckStore As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3565 ' _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 5"
3566 ' Dim ErrorChecker As Boolean
3567 ' Dim oPath As String, oDate As DateTime, _Date As String = Nothing
3568 ' Dim oFromStore, oToStore As String
3569 ' oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
3570
3571 ' '"BTG 9/20/2016
3572 ' '"Check if folder has files
3573 ' If Directory.GetFiles(oPath, "tout_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
3574 ' GoTo HasFile
3575 ' End If
3576
3577 ' Try
3578 ' _Date = _Path.GetField(, "U_LastExportDate")
3579
3580 ' ''MGP 08/23/2016 comment this
3581 ' 'oDate = _Path.GetField(, "U_LastExportDate")
3582 ' '_Date = oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
3583
3584 ' Catch ex As Exception
3585 ' End Try
3586
3587 ' Dim ts_Value As Integer = 0
3588 ' pbIMTout.Properties.Minimum = 0
3589
3590 ' Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
3591 ' _ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL) AND GlblLocNum = 1219"
3592
3593 ' Dim oWhsDT As DataTable
3594 ' oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
3595
3596 ' Dim oXML As String
3597 ' Dim NewXML As String
3598
3599 ' Dim oCount As Integer = 0
3600 ' Dim oPageCount As Integer = 0
3601 ' '"Loop every branches
3602 ' oWriteText(lsViewIm, Now & " - " & "Gathering Transfer Out information from each branch, please wait...", , False)
3603 ' For Each WhsDr As DataRowView In oWhsDT.DefaultView
3604 ' Dim _afterdate As String = ""
3605 ' If Not _Date Is Nothing Then
3606 ' _afterdate = "&after=" & _Date
3607 ' End If
3608
3609 ' '"Check document page
3610 ' oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=transfer_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
3611 ' Dim myXmlDoc As XmlDocument = New XmlDocument
3612 ' myXmlDoc.LoadXml(oXML)
3613 ' Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
3614 ' For Each mynode As XmlNode In list
3615 ' oCount = mynode("count").InnerText
3616 ' If oCount = 0 Then GoTo NextDocument
3617
3618 ' Next
3619
3620 ' Console.WriteLine(WhsDr("GlblLocNum"))
3621
3622 ' '"Create XML
3623 ' oPageCount = PageCount(oCount / 50)
3624 ' For Page As Integer = 1 To oPageCount
3625 ' oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=transfer_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
3626
3627 ' 'Dim myXmlDoc As XmlDocument = New XmlDocument
3628 ' If oXML = "<documents/>" Then
3629 ' GoTo NextDocument
3630 ' End If
3631
3632 ' NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
3633
3634 ' Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & "tout_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml")
3635 ' oSaveFile.WriteLine(NewXML)
3636 ' oSaveFile.Close()
3637 ' oSaveFile.Dispose()
3638
3639 ' Next
3640
3641 'NextDocument:
3642 ' Next
3643
3644 'HasFile:
3645 ' pbIMTout.Properties.Minimum = 0
3646 ' pbIMTout.Properties.Maximum = CInt(Directory.GetFiles(oPath, "tout_*.xml", SearchOption.TopDirectoryOnly).Count)
3647 ' pbIMTout.Position = 0
3648
3649 ' '"Post to SAP
3650 ' Dim oFileName As String
3651 ' For Each oFile As String In Directory.GetFiles(oPath, "tout_*.xml", SearchOption.TopDirectoryOnly)
3652 ' If isStop Then Exit Sub
3653 ' oFileName = Path.GetFileName(oFile)
3654 ' oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Transfer Out, please wait...", , True, "transferout_logs")
3655
3656 ' Dim _ErrCount As Integer = 1
3657 'Recon:
3658 ' If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "transferout_logs") : Return
3659 ' If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "transferout_logs") : _ErrCount += 1 : GoTo Recon
3660
3661 ' Dim ds As DataSet
3662 ' ds = New DataSet
3663 ' ds.ReadXml(oFile)
3664
3665 ' Dim oHeader As DataTable
3666 ' Dim oDetail As DataTable
3667
3668 ' oHeader = ds.Tables("document").Copy
3669 ' oDetail = ds.Tables("document_line").Copy
3670
3671 ' '"BTG 9/8/2016
3672 ' '"Transfer inside for each loop
3673 ' 'If Not oCompany.InTransaction Then
3674 ' ' oCompany.StartTransaction()
3675 ' 'End If
3676
3677 ' Dim _reference() As String
3678 ' For Each oDr As DataRow In oHeader.Rows
3679 ' Try
3680
3681 ' If Not oCompany.InTransaction Then
3682 ' oCompany.StartTransaction()
3683 ' End If
3684
3685 ' Dim oDocuments As SAPbobsCOM.StockTransfer
3686 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
3687
3688
3689 ' '"BTG 8/25/2016
3690 ' '"Validate if transaction is from SAP. If SAP skip
3691
3692 ' Try
3693 ' _reference = Split(oDr("remark"), "|")
3694 ' If _reference(1) = "from-SAP" Then GoTo NextEntry
3695 ' Catch ex As Exception
3696 ' End Try
3697
3698
3699 ' '"GoTo NextEntry
3700
3701 ' ''MGP 09/02/2016 added to identify whether the transfer is store to store or not.
3702 ' oDotNetCheckStore.strCommand = "SELECT isNULL(StreetNo,'') 'StreetNo' FROM OWHS(NOLOCK) WHERE GlblLocNum = '" & oDr("branch_id") & "'"
3703 ' If oDotNetCheckStore.GetField(, "StreetNo") = "" Then
3704 ' oWriteText(lsViewIm, Now & " [Info] - [" & oDr("document_no") & "] Skipping transaction no StreetNo applied on WhsCode " & oDr("branch_id") & " with cloud reference id#" & oDr("id") & "..." & " - File: " & oFileName, , True, "transferout_logs")
3705 ' GoTo NextEntry
3706 ' Else
3707 ' oFromStore = oDotNetCheckStore.GetField(, "StreetNo")
3708 ' End If
3709
3710 ' oDotNetCheckStore.strCommand = "SELECT isNULL(StreetNo,'') 'StreetNo' FROM OWHS(NOLOCK) WHERE GlblLocNum = '" & oDr("target_branch_id") & "'"
3711 ' If oDotNetCheckStore.GetField(, "StreetNo") = "" Then
3712 ' oWriteText(lsViewIm, Now & " [Info] - [" & oDr("document_no") & "] Skipping transaction no StreetNo applied on WhsCode " & oDr("target_branch_id") & " with cloud reference id#" & oDr("id") & "..." & " - File: " & oFileName, , True, "transferout_logs")
3713 ' GoTo NextEntry
3714 ' Else
3715 ' oToStore = oDotNetCheckStore.GetField(, "StreetNo")
3716 ' End If
3717
3718 ' If oFromStore = "Store" And oToStore = "Store" Then
3719
3720 ' oWriteText(lsViewIm, Now & " [Info] - Importing Store to Intransit-Store transfer Cloud reference id#" & oDr("id") & "...", , False)
3721
3722 ' ''MGP 08/31/2016 added to avoid duplication of record
3723 ' oDotnetTOut.strCommand = "SELECT U_AppPOSRefId FROM OWTR(NOLOCK) WHERE U_AppPOSRefId = '" & oDr("id") & "'"
3724 ' If oDotnetTOut.Ds.Tables(0).Rows.Count > 0 Then
3725 ' oWriteText(lsViewIm, Now & " [Err] - " & "Cloud reference id#" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "transferout_logs")
3726 ' GoTo NextEntry
3727 ' End If
3728
3729 ' If oDr("intransit_status") = "Intransit" Then GoTo NextEntry
3730
3731 ' '"BTG 8/23/2016
3732 ' '"Validate if Transfer is already in SAP
3733 ' If ValidateTransferId(oDatabase, oDr("id")) AndAlso oDr("status") = "V" Then
3734 ' '"BTG 8/25/2016
3735 ' '"For cancelation
3736 ' With oDocuments
3737 ' If .GetByKey(DocEntry) Then
3738 ' If Not .Cancel = 0 Then
3739 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3740 ' Try
3741 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3742 ' Catch ex As Exception
3743 ' End Try
3744 ' End If
3745 ' GoTo NextEntry
3746 ' Else
3747 ' oWriteText(lsViewIm, Now & " [Err] - No record(s) found [TOut]." & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3748 ' Try
3749 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3750 ' Catch ex As Exception
3751 ' End Try
3752 ' GoTo NextEntry
3753 ' End If
3754 ' End With
3755 ' ElseIf Not ValidateTransferId(oDatabase, oDr("id")) AndAlso oDr("status") = "S" Then
3756 ' Else : GoTo NextEntry
3757 ' End If
3758
3759 ' With oDocuments
3760 ' .DocDate = oDr("utc_document_date")
3761 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
3762 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
3763
3764 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3765
3766 ' .ToWarehouse = "INT"
3767 ' .FromWarehouse = WhsCode
3768 ' .Comments = _reference(0) & " " & oDr("reference") & " - " & "Transfer: Store to Store" & "|" & WhsCode
3769
3770 ' If Not GetWhs("", oDr("target_branch_id")) Then GoTo NextEntry
3771 ' .UserFields.Fields.Item("U_ToWhs").Value = WhsCode
3772 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
3773
3774
3775 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
3776 ' For Each oDrView As DataRowView In oDetail.DefaultView
3777 ' With .Lines
3778 ' .ItemCode = oDrView("product_stock_no")
3779 ' .Quantity = oDrView("unit_quantity")
3780 ' '"BTG 9/7/2016
3781 ' '"Removed, SAP will auto compute price
3782 ' '.UnitPrice = oDrView("unit_retail_price")
3783 ' 'If oDrView("discount_text") <> "" Then
3784 ' ' .DiscountPercent = Replace(oDrView("discount_text"), "%", "")
3785 ' 'End If
3786 ' .UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tNO
3787 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
3788 ' '.AccountCode = AccountCodeGR
3789
3790 ' If ValidateItemBatch(oDrView("product_stock_no")) Then
3791 ' .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
3792 ' .BatchNumbers.Quantity = oDrView("quantity")
3793 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3794 ' If Not GetBatch(oDatabase, oDrView("product_stock_no"), WhsCode, CDec(oDrView("quantity"))) Then
3795 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No valid batch number for item " & oDrView("product_stock_no") & ". Moving to next entry transfer." & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3796 ' ErrorChecker = True
3797 ' GoTo NextEntry
3798 ' End If
3799 ' .BatchNumbers.BatchNumber = Batch
3800 ' .BatchNumbers.Add()
3801 ' End If
3802
3803 ' .Add()
3804 ' End With
3805 ' Next
3806
3807
3808 ' If Not .Add = 0 Then
3809 ' 'oErrLog()
3810 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3811 ' Try
3812 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3813 ' Catch ex As Exception
3814 ' End Try
3815 ' ErrorChecker = True
3816 ' GoTo NextEntry
3817 ' Else
3818 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Transfer Out cloud reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "transferout_logs")
3819
3820 ' End If
3821
3822 ' oDocuments = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
3823 ' '"Intransit to Store
3824 ' With oDocuments
3825 ' .DocDate = oDr("utc_document_date")
3826 ' .Comments = _reference(0) & " " & oDr("reference") & " - " & "Transfer: Store to Store"
3827 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = "-" & oDr("id")
3828 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
3829
3830 ' ''MGP 09/03/2016 for intransit warehouse to warehouse
3831 ' If Not GetWhs("", oDr("target_branch_id")) Then GoTo NextEntry
3832 ' 'If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3833 ' .ToWarehouse = WhsCode
3834 ' .FromWarehouse = "INT"
3835
3836 ' 'If Not GetWhs("", oDr("target_branch_id")) Then GoTo NextEntry
3837 ' '.UserFields.Fields.Item("U_ToWhs").Value = WhsCode
3838 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
3839
3840 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
3841 ' For Each oDrView As DataRowView In oDetail.DefaultView
3842 ' With .Lines
3843 ' .ItemCode = oDrView("product_stock_no")
3844 ' .Quantity = oDrView("unit_quantity")
3845 ' '"BTG 9/7/2016
3846 ' '"Removed, SAP will auto compute price
3847 ' '.UnitPrice = oDrView("unit_retail_price")
3848 ' 'If oDrView("discount_text") <> "" Then
3849 ' ' .DiscountPercent = Replace(oDrView("discount_text"), "%", "")
3850 ' 'End If
3851 ' .UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tNO
3852 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
3853 ' '.AccountCode = AccountCodeGR
3854
3855 ' If ValidateItemBatch(oDrView("product_stock_no")) Then
3856 ' .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
3857 ' .BatchNumbers.Quantity = oDrView("quantity")
3858 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3859 ' If Not GetBatch(oDatabase, oDrView("product_stock_no"), "INT", CDec(oDrView("quantity"))) Then
3860 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No valid batch number for item " & oDrView("product_stock_no") & ". Moving to next entry transfer." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3861 ' ErrorChecker = True
3862 ' GoTo NextEntry
3863 ' End If
3864 ' .BatchNumbers.BatchNumber = Batch
3865 ' .BatchNumbers.Add()
3866 ' End If
3867
3868 ' .Add()
3869 ' End With
3870 ' Next
3871
3872 ' If Not .Add = 0 Then
3873 ' 'oErrLog()
3874 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3875 ' Try
3876 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3877 ' Catch ex As Exception
3878 ' End Try
3879 ' ErrorChecker = True
3880 ' GoTo NextEntry
3881 ' Else
3882 ' Try
3883 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
3884 ' Catch ex As Exception
3885
3886 ' End Try
3887 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Transfer Out cloud reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "transferout_logs")
3888 ' End If
3889 ' End With
3890
3891 ' End With
3892
3893 ' ElseIf oFromStore = "Store" And oToStore = "Warehouse" Then
3894
3895 ' oWriteText(lsViewIm, Now & " [Info] - Importing Store to Intransit-warehouse transfer Cloud reference id#" & oDr("id") & "...", , False)
3896
3897 ' '"BTG 8/23/2016
3898 ' '"Validate if Transfer is already in SAP
3899 ' If ValidateTransferId(oDatabase, oDr("id")) AndAlso oDr("status") = "V" Then
3900 ' '"BTG 8/25/2016
3901 ' '"For cancelation
3902 ' With oDocuments
3903 ' If .GetByKey(DocEntry) Then
3904 ' If Not .Cancel = 0 Then
3905 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3906 ' Try
3907 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3908 ' Catch ex As Exception
3909 ' End Try
3910 ' End If
3911 ' GoTo NextEntry
3912 ' Else
3913 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No record(s) found [TOut]." & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3914 ' Try
3915 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3916 ' Catch ex As Exception
3917 ' End Try
3918 ' GoTo NextEntry
3919 ' End If
3920 ' End With
3921 ' ElseIf Not ValidateTransferId(oDatabase, oDr("id")) AndAlso oDr("status") = "S" Then
3922 ' Else : GoTo NextEntry
3923 ' End If
3924
3925 ' With oDocuments
3926 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3927
3928 ' .DocDate = oDr("utc_document_date")
3929 ' .Comments = _reference(0) & " " & oDr("reference") & " - " & "Transfer: Store to Warehouse" & "|" & WhsCode
3930 ' .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id")
3931 ' .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("document_no")
3932
3933 ' .ToWarehouse = "INT"
3934 ' .FromWarehouse = WhsCode
3935
3936 ' If Not GetWhs("", oDr("target_branch_id")) Then GoTo NextEntry
3937 ' .UserFields.Fields.Item("U_ToWhs").Value = WhsCode
3938 ' .UserFields.Fields.Item("U_AppIsExported").Value = "1"
3939
3940 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
3941 ' For Each oDrView As DataRowView In oDetail.DefaultView
3942 ' With .Lines
3943 ' .ItemCode = oDrView("product_stock_no")
3944 ' .Quantity = oDrView("unit_quantity")
3945 ' '.UnitPrice = oDrView("unit_retail_price")
3946 ' 'If oDrView("discount_text") <> "" Then
3947 ' ' .DiscountPercent = Replace(oDrView("discount_text"), "%", "")
3948 ' 'End If
3949 ' .UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tNO
3950 ' .UoMEntry = GetUomEntry("", oDrView("unit_name"))
3951 ' '.AccountCode = AccountCodeGR
3952
3953 ' ''MGP 09/03/2016 for item with batch
3954 ' If ValidateItemBatch(oDrView("product_stock_no")) Then
3955 ' .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
3956 ' .BatchNumbers.Quantity = oDrView("quantity")
3957 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
3958 ' If Not GetBatch(oDatabase, oDrView("product_stock_no"), WhsCode, CDec(oDrView("quantity"))) Then
3959 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] No valid batch number for item " & oDrView("product_stock_no") & ". Moving to next entry invoice." & " - File: " & oFileName, Color.Red, True, "invoice_logs")
3960 ' ErrorChecker = True
3961 ' GoTo NextEntry
3962 ' End If
3963 ' .BatchNumbers.BatchNumber = Batch
3964 ' .BatchNumbers.Add()
3965 ' End If
3966
3967 ' .Add()
3968 ' End With
3969 ' Next
3970
3971 ' If Not .Add = 0 Then
3972 ' 'oErrLog()
3973 ' oWriteText(lsViewIm, Now & " [Err] - [" & oDr("document_no") & "] " & oCompany.GetLastErrorDescription & " - File: " & oFileName, Color.Red, True, "transferout_logs")
3974 ' Try
3975 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
3976 ' Catch ex As Exception
3977 ' End Try
3978 ' ErrorChecker = True
3979 ' GoTo NextEntry
3980 ' Else
3981 ' Try
3982 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)
3983 ' Catch ex As Exception
3984
3985 ' End Try
3986 ' oWriteText(lsViewIm, Now & " - " & "Successfully created Transfer Out cloud reference id# " & oDr("id") & "." & " - File: " & oFileName, Color.Green, True, "transferout_logs")
3987 ' End If
3988 ' End With
3989 ' '==========================================================================================================================================================================================
3990
3991 ' ''MGP 08/31/2016 added to avoid duplication of record
3992 ' 'oDotnetTOut.strCommand = "SELECT U_AppPOSRefId FROM OWTR WHERE U_AppPOSRefId = '" & oDr("id") & "'"
3993 ' 'If oDotnetTOut.Ds.Tables(0).Rows.Count > 0 Then
3994 ' ' oWriteText(lsViewIm, Now & " [Err] - " & "Cloud reference id#" & oDr("id") & " is already exist...", , True)
3995 ' ' GoTo NextEntry
3996 ' 'End If
3997
3998 ' End If
3999
4000 ' Catch ex As Exception
4001 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "transferout_logs")
4002 ' Try
4003 ' oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack)
4004 ' Catch exs As Exception
4005 ' End Try
4006 ' End Try
4007 'NextEntry:
4008 ' '"Update LastExport date
4009 ' ''MGP 09/03/2016 no update if transaction is warehouse to branch
4010
4011 ' If oFromStore = "Warehouse" And oToStore = "Store" Then
4012
4013 ' Else
4014 ' Dim oUpdateQry As String
4015 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 5) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 5) END WHERE U_App_Id = 5"
4016 ' _Path.strCommand = (oUpdateQry)
4017 ' Console.WriteLine(oUpdateQry)
4018 ' End If
4019
4020 ' Next
4021
4022
4023 ' oWriteText(lsViewIm, Now & " - " & "Done!", Color.Green)
4024 'NextFile:
4025 ' If ErrorChecker = False Then
4026 ' File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
4027 ' Else
4028 ' File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
4029 ' End If
4030
4031 ' pbIMTout.Position += 1
4032
4033 ' Next
4034
4035 ' oWriteText(lsViewIm, Now & " - " & "Done importing Transfer Out.", Color.Green, False)
4036 ' oWriteText(lsViewIm, Now & " - " & "=========================================", , False)
4037
4038 ' Catch ex As Exception
4039 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "transferout_logs")
4040 ' 'Return
4041 ' End Try
4042
4043 ' End If
4044 ' End Sub
4045
4046
4047 Private Sub Import_PCount()
4048 If PCount.Checked = True Then
4049 Try
4050 Dim oDatabase As String = ""
4051 Dim r As Random = New Random
4052 '"Get Path
4053 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4054 Dim oDotnetExist As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4055 Dim oDotNet As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4056 Dim oDotNetCountGR As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4057 Dim oDotNetCountAR As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4058 Dim oDotNetFilter As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4059 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4060
4061 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6"
4062 oDatabase = oRegistry.GetKeyValue("Database")
4063 Dim ErrorChecker As Boolean = False
4064 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
4065 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
4066
4067 '"BTG 9/20/2016
4068 '"Check if folder has files
4069 If Directory.GetFiles(oPath, "pcount_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
4070 GoTo HasFile
4071 End If
4072
4073 Try
4074 _Date = _Path.GetField(, "U_LastExportDate")
4075 Catch ex As Exception
4076 End Try
4077
4078 Dim ts_Value As Integer = 0
4079 'pbIMAout.Properties.Minimum = 0
4080
4081 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4082 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
4083
4084 Dim oWhsDT As DataTable
4085 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
4086
4087 Dim oXML As String
4088 Dim NewXML As String
4089
4090 Dim oCount, oLineNum As Integer
4091 Dim oPageCount As Integer = 0
4092 '"Loop every branches
4093
4094 For Each WhsDr As DataRowView In oWhsDT.DefaultView
4095
4096
4097 Dim _afterdate As String = ""
4098 If Not _Date Is Nothing Then
4099 _afterdate = "&after=" & _Date & ""
4100 End If
4101
4102 '"Check document page
4103 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=physical_count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4104 Dim myXmlDoc As XmlDocument = New XmlDocument
4105 myXmlDoc.LoadXml(oXML)
4106 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
4107 For Each mynode As XmlNode In list
4108 oCount = mynode("count").InnerText
4109 If oCount = 0 Then
4110 GoTo NextDocument
4111 End If
4112 oWriteText(lsViewIm, Now & " - " & "Gathering information from branch " & WhsDr("WhsName") & ", please wait...", , False)
4113 Next
4114
4115 '"Create XML
4116 oPageCount = PageCount(oCount / 50)
4117 For Page As Integer = 1 To oPageCount
4118 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?document_type=physical_count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4119
4120 'Dim myXmlDoc As XmlDocument = New XmlDocument
4121 If oXML = "<documents/>" Then
4122 GoTo NextDocument
4123 End If
4124
4125 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
4126 Dim oGetFileName As String = "pcount_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
4127 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
4128 oSaveFile.WriteLine(NewXML)
4129 oSaveFile.Close()
4130 oSaveFile.Dispose()
4131 Dim ds As DataSet
4132 ds = New DataSet
4133 ds.ReadXml(oPath & "\" & oGetFileName)
4134
4135 Dim oHeader As DataTable
4136
4137 oHeader = ds.Tables("document").Copy
4138
4139 For Each oDr As DataRow In oHeader.Rows
4140 Dim oUpdateQry As String
4141 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
4142 _Path.strCommand = (oUpdateQry)
4143 Next
4144
4145 Next
4146NextDocument:
4147 Next
4148
4149HasFile:
4150
4151 pbIMPCount.Properties.Minimum = 0
4152 pbIMPCount.Properties.Maximum = CInt(Directory.GetFiles(oPath, "pcount_*.xml", SearchOption.TopDirectoryOnly).Count)
4153 pbIMPCount.Position = 0
4154
4155 Try
4156 '"Post to SAP
4157 Dim oFileName As String
4158 For Each oFile As String In Directory.GetFiles(oPath, "pcount_*.xml", SearchOption.TopDirectoryOnly)
4159 If isStop Then Exit Sub
4160
4161
4162 ErrorChecker = False
4163 oDotNet.strCommand = "DELETE FROM [APP_AFSI]..[APP_GRGI]"
4164 oDotNet.strCommand = "DELETE FROM [APP_AFSI]..[APP_GRGI1]"
4165
4166 oFileName = Path.GetFileName(oFile)
4167 oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , False)
4168
4169 Dim _ErrCount As Integer = 1
4170Recon:
4171 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Info] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "pcount_logs") : Return
4172 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Info] - Cannot connect in DI API", , True, "pcount_logs") : _ErrCount += 1 : GoTo Recon
4173
4174 Dim ds As DataSet
4175 ds = New DataSet
4176 ds.ReadXml(oFile)
4177
4178 Dim oHeader As DataTable
4179 Dim oDetail As DataTable
4180
4181 oHeader = ds.Tables("document").Copy
4182
4183 For Each oDr As DataRow In oHeader.Rows
4184
4185
4186 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
4187 If Not oChangeDatabase("ACI_FINAL") Then
4188 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4189 ErrorChecker = True
4190 GoTo NextXML
4191 End If
4192 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
4193 If Not oChangeDatabase("AFSI_FINAL") Then
4194 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4195 ErrorChecker = True
4196 GoTo NextXML
4197 End If
4198 End If
4199
4200 Dim oDotNetSave As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4201
4202 oDotNetSave.strCommand = "SELECT * FROM [APP_AFSI]..[APP_PhysicalCount] WHERE cloud_id = '" & oDr("id") & "' AND update_date = '" & oDr("utc_updated_at") & "'"
4203 If oDotNetSave.Ds.Tables(0).Rows.Count <= 0 Then
4204 oDotNet.strCommand = "INSERT INTO APP_AFSI..APP_PhysicalCount VALUES ('" & oFileName & "','" & oDr("reference") & "','" & oDr("id") & "','" & oDr("utc_updated_at") & "',GETDATE())"
4205 End If
4206
4207 oDotNet.strCommand = "INSERT INTO [APP_AFSI]..[APP_GRGI] VALUES('" & oDr("document_id") & "', '" & oDr("branch_id") & "', '" & oDr("id") & "','" & oDr("order_id") & "', '" & oDr("reference") & "', '" & oDr("remark") & "','" & oDr("status") & "', '" & oDr("target_branch_id") & "', '" & oDr("user_id") & "','" & oDr("utc_document_date") & "', '" & oDr("utc_created_at") & "','" & oDr("utc_updated_at") & "', '" & oDr("document_no") & "')"
4208
4209 oDetail = ds.Tables("document_line").Copy
4210 oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
4211
4212 For Each oDrView As DataRowView In oDetail.DefaultView
4213
4214 GetWhs(oCompany.CompanyDB, oDr("branch_id"))
4215
4216 If oCompany.CompanyDB = "ACI_FINAL" Then
4217 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
4218 Else
4219 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oDrView("product_stock_no") & "'"
4220 End If
4221
4222
4223 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
4224 oDotNetFilter.strCommand = "SELECT OnHand FROM [" & oCompany.CompanyDB & "]..OITW WHERE ItemCode = '" & oDotNetItemCode.GetField(, "ItemCode") & "' AND WhsCode = '" & WhsCode & "'"
4225 If oDotNetFilter.Ds.Tables(0).Rows.Count > 0 Then
4226 Dim StockCount As Integer
4227 StockCount = oDrView("quantity") - oDotNetFilter.GetField(, "OnHand")
4228
4229 If StockCount <> 0 Then
4230 If StockCount.ToString.Substring(0, 1) = "-" Then
4231 oDotNet.strCommand = "INSERT INTO [APP_AFSI]..[APP_GRGI1] VALUES('" & oDrView("document_lines_id") & "', '" & oDrView("product_id") & "', '" & StockCount * -1 & "', '" & oDrView("retail_price") & "','" & oDrView("price") & "', '" & oDrView("subtotal") & "','" & oDrView("line_no") & "', '" & oDrView("unit_name") & "','" & oDrView("unit_quantity") & "', '" & oDrView("unit_content_quantity") & "','" & oDrView("unit_retail_price") & "', '" & oDrView("quantity_variance") & "','APPTECH', '" & oDotNetItemCode.GetField(, "ItemCode") & "', 'GI')"
4232 Else
4233 oDotNet.strCommand = "INSERT INTO [APP_AFSI]..[APP_GRGI1] VALUES('" & oDrView("document_lines_id") & "', '" & oDrView("product_id") & "', '" & StockCount & "', '" & oDrView("retail_price") & "','" & oDrView("price") & "', '" & oDrView("subtotal") & "','" & oDrView("line_no") & "', '" & oDrView("unit_name") & "','" & oDrView("unit_quantity") & "', '" & oDrView("unit_content_quantity") & "','" & oDrView("unit_retail_price") & "', '" & oDrView("quantity_variance") & "','APPTECH', '" & oDotNetItemCode.GetField(, "ItemCode") & "', 'GR')"
4234 End If
4235 End If
4236 Else
4237 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - ItemCode : " & oDotNetItemCode.GetField(, "ItemCode") & " doesn't exists to database - File: " & oFileName, Color.Red, True, "pcount_logs")
4238 ErrorChecker = True
4239 GoTo NextXML
4240 End If
4241 End If
4242
4243
4244
4245 Next
4246
4247 Next
4248
4249 oDotNet.strCommand = "SELECT DISTINCT a.* FROM [APP_AFSI]..[APP_GRGI] a LEFT JOIN [APP_AFSI]..[APP_GRGI1] b ON a.ID = b.ID WHERE status = 'V'"
4250 oHeader = oDotNet.Ds.Tables(0).Copy
4251 For Each oDr As DataRow In oHeader.Rows
4252
4253 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..ODRF WHERE DocStatus = 'O' AND U_AppPosRefId = '" & oDr("pos_id") & "-AR'"
4254 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4255 Dim oCancelDraft As SAPbobsCOM.Documents
4256 oCancelDraft = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
4257
4258 With oCancelDraft
4259 If .GetByKey(oDotNet.GetField(, "DocEntry")) Then
4260 If .Cancel Then
4261 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "pcount_logs")
4262 ErrorChecker = True
4263 Else
4264 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Successfully cancelled order#[" & oDr("reference") & "] - File: " & oFileName, Color.Green, False, "pcount_logs")
4265 End If
4266 Else
4267 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found [Orders].", Color.Black, False, "pcount_logs")
4268 End If
4269 End With
4270 Else
4271 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Physical Count AR reference id#[" & oDr("reference") & "] is already closed/cancelled - File: " & oFileName, Color.Orange, False, "pcount_logs")
4272 End If
4273
4274
4275 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..ODRF WHERE DocStatus = 'O' AND U_AppPosRefId = '" & oDr("pos_id") & "-GR'"
4276 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4277 Dim oCancelDraft As SAPbobsCOM.Documents
4278 oCancelDraft = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
4279
4280 With oCancelDraft
4281 If .GetByKey(oDotNet.GetField(, "DocEntry")) Then
4282 If .Cancel Then
4283 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "- Cannot cancel document." & " - File: " & oFileName, Color.Red, True, "orders_logs")
4284 ErrorChecker = True
4285 Else
4286 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Successfully cancelled order#[" & oDr("reference") & "] - File: " & oFileName, Color.Green, False, "pcount_logs")
4287 End If
4288 Else
4289 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found [Orders].", Color.Black, False, "pcount_logs")
4290 End If
4291 End With
4292 Else
4293 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Physical Count GR reference id#[" & oDr("reference") & "] is already closed/cancelled - File: " & oFileName, Color.Orange, False, "pcount_logs")
4294 End If
4295
4296
4297 Dim oUpdateQry As String
4298
4299 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
4300 _Path.strCommand = (oUpdateQry)
4301 Next
4302
4303 '' for good receipt
4304 Try
4305 oDotNet.strCommand = "SELECT a.ID FROM [APP_AFSI]..[APP_GRGI1] a INNER JOIN APP_AFSI..APP_GRGI b ON a.ID = b.ID WHERE a.document_type = 'GR' AND b.status = 'S'"
4306 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4307
4308 oDotNet.strCommand = "SELECT DISTINCT a.* FROM [APP_AFSI]..[APP_GRGI] a INNER JOIN [APP_AFSI]..[APP_GRGI1] b ON a.ID = b.ID WHERE status = 'S'"
4309 oHeader = oDotNet.Ds.Tables(0).Copy
4310
4311 For Each oDr As DataRow In oHeader.Rows
4312
4313 oDotNet.strCommand = "SELECT * FROM [APP_AFSI]..[APP_GRGI1] WHERE document_type = 'GR' AND ID = '" & oDr("ID") & "'"
4314 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
4315 GoTo NextEntryGR
4316 End If
4317
4318
4319
4320 Dim GoodReceipt As SAPbobsCOM.Documents
4321 GoodReceipt = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
4322
4323 oDetail = oDotNet.Ds.Tables(0).Copy
4324 'ValidateId("OIGN", oDr("ID"))
4325
4326 oDotnetExist.strCommand = "SELECT U_APPPOSREFID FROM [" & oCompany.CompanyDB & "]..ODRF WHERE U_APPPOSREFID = '" & oDr("pos_id") & "-GR' "
4327 If oDotnetExist.Ds.Tables(0).Rows.Count > 0 Then
4328 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Good Receipt draft with reference id#" & oDr("pos_id") & " is already exist " & " - File: " & oFileName, Color.Orange, False, "pcount_logs")
4329 GoTo NextEntryGR
4330 End If
4331 '"BTG 9/11/2016
4332 '"For batch creation, year + 1 and Month
4333 Dim oBatchDate As Date
4334 With GoodReceipt
4335 .DocObjectCode = SAPbobsCOM.BoObjectTypes.oInventoryGenEntry
4336 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference").ToString.ToString
4337 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("pos_id").ToString + "-GR"
4338 .DocDate = oDr("utc_document_date")
4339 .Comments = oDr("remark")
4340
4341 oBatchDate = oDr("utc_document_date")
4342 For Each oDrView As DataRowView In oDetail.DefaultView
4343 With .Lines
4344
4345 .ItemCode = oDrView("product_stock_no")
4346 If Not GetWhs(oCompany.CompanyDB, oDr("branch_id")) Then
4347 ErrorChecker = True
4348 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "pcount_logs")
4349 GoTo NextEntryGR
4350 End If
4351 .Quantity = oDrView("quantity")
4352 .WarehouseCode = WhsCode
4353
4354
4355
4356
4357 oDotNet.strCommand = "SELECT ItmsGrpCod FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oDrView("product_stock_no") & "' "
4358 Select Case oDotNet.GetField(, "ItmsGrpCod")
4359 Case "102", "110"
4360 .AccountCode = "5111000"
4361 Case "103"
4362 .AccountCode = "5112000"
4363 Case "106"
4364 .AccountCode = "5113000"
4365 Case "101", "111"
4366 .AccountCode = "5114000"
4367 Case "104"
4368 .AccountCode = "5115000"
4369 Case "105"
4370 .AccountCode = "5116000"
4371 Case Else
4372 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - There is no Account Code for Item Group " & oDotNet.GetField(, "ItmsGrpCod") & "" & " - File: " & oFileName, Color.Red, True, "adjustment_in")
4373 ErrorChecker = True
4374 GoTo NextEntryGR
4375 End Select
4376
4377 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OITM WHERE ItemCode = '" & oDrView("product_stock_no") & "' AND ManBtchNum = 'Y'"
4378
4379 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4380 .BatchNumbers.BaseLineNumber = oDrView("line_no") - 1
4381 .BatchNumbers.Quantity = oDrView("quantity")
4382 .BatchNumbers.BatchNumber = oBatchDate.Year + 1 & UCase(MonthName(oBatchDate.Month, True))
4383 .BatchNumbers.Add()
4384 End If
4385
4386 .Add()
4387 oLineNum += 1
4388
4389 End With
4390 Next
4391
4392 If Not GoodReceipt.Add = 0 Then
4393 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "", Color.Red, True, "pcount_logs")
4394 ErrorChecker = True
4395 Else
4396 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Sucessfully created Good Receipt draft with reference id# " & oDr("reference") & "", Color.Green, False, "pcount_logs")
4397 End If
4398
4399 End With
4400 '"Update LastExport date
4401 Dim oUpdateQry As String
4402 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
4403 _Path.strCommand = (oUpdateQry)
4404NextEntryGR:
4405 Next
4406
4407 End If
4408
4409
4410
4411 Catch ex As Exception
4412 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString & "", Color.Red, True, "pcount_logs")
4413 ErrorChecker = True
4414 End Try
4415
4416
4417 ''for good issue
4418 Try
4419 oDotNet.strCommand = "SELECT a.ID FROM [APP_AFSI]..[APP_GRGI1] a INNER JOIN APP_AFSI..APP_GRGI b ON a.ID = b.ID WHERE a.document_type = 'GI' AND b.status = 'S'"
4420 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4421
4422 oDotNet.strCommand = "SELECT DISTINCT a.* FROM [APP_AFSI]..[APP_GRGI] a INNER JOIN [APP_AFSI]..[APP_GRGI1] b ON a.ID = b.ID WHERE status = 'S'"
4423 oHeader = oDotNet.Ds.Tables(0).Copy
4424
4425 For Each oDr As DataRow In oHeader.Rows
4426
4427 oDotNet.strCommand = "SELECT * FROM [APP_AFSI]..[APP_GRGI1] WHERE document_type = 'GI' AND ID = '" & oDr("ID") & "' "
4428
4429 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
4430 GoTo NextEntryGI
4431 End If
4432
4433 oDetail = oDotNet.Ds.Tables(0).Copy
4434
4435 Dim oInvoice As SAPbobsCOM.Documents
4436 oInvoice = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)
4437
4438 oDotnetExist.strCommand = "SELECT U_APPPOSREFID FROM [" & oCompany.CompanyDB & "]..ODRF WHERE U_APPPOSREFID = '" & oDr("pos_id") & "-AR'"
4439 If oDotnetExist.Ds.Tables(0).Rows.Count > 0 Then
4440 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - AR Invoice draft with reference #" & oDr("pos_id") & " is already exist " & " - File: " & oFileName, Color.Orange, False, "pcount_logs")
4441 GoTo NextEntryGI
4442 End If
4443
4444 With oInvoice
4445
4446 oDotNet.strCommand = "SELECT U_APPBusinessPartner, WhsName FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxID = '" & oDr("branch_id") & "' AND ISNULL(U_APPBusinessPartner,'') <> ''"
4447
4448 If oDotNet.Ds.Tables(0).Rows.Count <= 0 Then
4449 oDotNet.strCommand = "SELECT WhsName FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxID = '" & oDr("branch_id") & "' "
4450 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Please assign a BAE for warehouse " & oDotNet.GetField(, "WhsName") & ". " & " - File: " & oFileName, Color.Red, True, "pcount_logs")
4451 ErrorChecker = True
4452 GoTo NextEntryGI
4453 End If
4454
4455 .CardCode = oDotNet.GetField(, "U_APPBusinessPartner")
4456 .DocObjectCode = SAPbobsCOM.BoObjectTypes.oInvoices
4457
4458 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference").ToString
4459 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("pos_id").ToString + "-AR"
4460 .DocDate = oDr("utc_document_date")
4461 .Comments = oDr("remark")
4462
4463 If Not GetWhs(oCompany.CompanyDB, oDr("branch_id")) Then
4464 ErrorChecker = True
4465 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "pcount_logs")
4466 GoTo NextEntryGI
4467 End If
4468
4469 'oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
4470
4471 'Dim oTerritory As String = oDotNet.GetField(, "Territory")
4472 Dim oTerritory, oCategory As String
4473 '.NumAtCard = oDr("reference") & "|" & oDr("branch_id")
4474 oDotNet.strCommand = "SELECT ISNULL(U_SalesCategory,'') 'U_SalesCategory',ISNULL(U_SalesTerritory,'') 'U_SalesTerritory' FROM [" & oCompany.CompanyDB & "]..OCRD WHERE CardCode = '" & CardCode & "' AND ISNULL(U_SalesCategory,'') <> '' AND ISNULL(U_SalesTerritory,'') <> '' "
4475 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4476 oTerritory = oDotNet.GetField(, "U_SalesTerritory")
4477 oCategory = oDotNet.GetField(, "U_SalesCategory")
4478 Else
4479 oDotNet.strCommand = "SELECT Substring(WhsName,1,CHARINDEX(' ', WhsName)-1) 'Territory' FROM [" & oCompany.CompanyDB & "]..OWHS WHERE FedTaxId = '" & oDr("branch_id") & "' "
4480 oTerritory = oDotNet.GetField(, "Territory")
4481 End If
4482
4483 For Each oDrView As DataRowView In oDetail.DefaultView
4484 With .Lines
4485
4486 .ItemCode = oDrView("product_stock_no")
4487 .Quantity = oDrView("quantity")
4488 .WarehouseCode = WhsCode
4489 .PriceAfterVAT = oDrView("price")
4490 .CostingCode = "SALES"
4491 If oCategory = "" Then
4492 .CostingCode2 = "RETAIL"
4493 .CostingCode3 = oTerritory
4494 Else
4495 .CostingCode2 = oCategory
4496 .CostingCode3 = oTerritory
4497 End If
4498
4499 .Add()
4500 oLineNum += 1
4501
4502 End With
4503 Next
4504
4505 If Not .Add = 0 Then
4506 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "", Color.Red, True, "pcount_logs")
4507 ErrorChecker = True
4508 Else
4509 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Sucessfully created Ar Invoice draft with reference id# " & oDr("reference") & "", Color.Green, False, "pcount_logs")
4510 End If
4511
4512 End With
4513NextEntryGI:
4514 '"Update LastExport date
4515 Dim oUpdateQry As String
4516
4517 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
4518 _Path.strCommand = (oUpdateQry)
4519
4520 Next
4521
4522 End If
4523 Catch ex As Exception
4524 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString & "", Color.Red, True, "pcount_logs")
4525 ErrorChecker = True
4526 End Try
4527
4528 'oDotNetCountGR.strCommand = "SELECT a.ID FROM [APP_AFSI]..[APP_GRGI1] a INNER JOIN APP_AFSI..APP_GRGI b ON a.ID = b.ID WHERE a.document_type = 'GR' AND b.status = 'S'"
4529 'oDotNetCountAR.strCommand = "SELECT a.ID FROM [APP_AFSI]..[APP_GRGI1] a INNER JOIN APP_AFSI..APP_GRGI b ON a.ID = b.ID WHERE a.document_type = 'GI' AND b.status = 'S'"
4530 'If oDotNetCountAR.Ds.Tables(0).Rows.Count = 0 And oDotNetCountGR.Ds.Tables(0).Rows.Count = 0 Then
4531 ' oDotNet.strCommand = "SELECT DISTINCT a.* FROM [APP_AFSI]..[APP_GRGI] a INNER JOIN [APP_AFSI]..[APP_GRGI1] b ON a.ID = b.ID WHERE status = 'S'"
4532 ' oHeader = oDotNet.Ds.Tables(0).Copy
4533 ' For Each oDr As DataRow In oHeader.Rows
4534 ' Dim oUpdateQry As String
4535 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
4536 ' _Path.strCommand = (oUpdateQry)
4537 ' Next
4538 'End If
4539
4540NextXML:
4541 '"Per XML file
4542 If ErrorChecker = False Then
4543 pbIMPCount.Position += 1
4544 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
4545 Else
4546 pbIMPCount.Position += 1
4547 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
4548 End If
4549
4550
4551
4552 Next
4553
4554
4555 Catch ex As Exception
4556 oWriteText(lsViewIm, Now & " [Err] - " & oCompany.GetLastErrorDescription & "", , True, "pcount_logs")
4557 ErrorChecker = True
4558 End Try
4559
4560 pbIMPCount.Properties.Minimum = 0
4561 pbIMPCount.Position = 0
4562 pbIMPCount.Properties.Maximum = 99
4563
4564 Catch ex As Exception
4565 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "pcount_logs")
4566 End Try
4567 End If
4568
4569 End Sub
4570
4571
4572 Private Sub Import_AdjustmentIn()
4573 Try
4574 If cbAdjustmentIn.Checked Then
4575 Dim oDatabase As String = ""
4576 Dim r As Random = New Random
4577 '"Get Path
4578 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4579 oDatabase = oRegistry.GetKeyValue("Database")
4580 Dim oDotNetReceive As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4581 Dim oDotNet As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4582 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4583
4584 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 1"
4585
4586 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
4587
4588 Dim ErrorChecker As Boolean = False
4589 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
4590
4591 '"BTG 9/20/2016
4592 '"Check if folder has files
4593 If Directory.GetFiles(oPath, "AdjustmentIn*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
4594 GoTo HasFile
4595 End If
4596
4597 Try
4598 'oDate = _Path.GetField(, "U_LastExportDate")
4599 _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
4600 Catch ex As Exception
4601 End Try
4602
4603 Dim ts_Value As Integer = 0
4604 pbIMPStockRequest.Properties.Minimum = 0
4605
4606 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4607 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
4608
4609 Dim oWhsDT As DataTable
4610 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
4611
4612 Dim oXML As String
4613 Dim NewXML As String
4614
4615 Dim oCount As Integer = 0
4616 Dim oPageCount As Integer = 0
4617 '"Loop every branches
4618
4619 For Each WhsDr As DataRowView In oWhsDT.DefaultView
4620
4621
4622 Dim _afterdate As String = ""
4623 If Not _Date Is Nothing Then
4624 _afterdate = "&after=" & _Date & ""
4625 End If
4626
4627 '"Check document page
4628 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=adjustment_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4629
4630 Dim myXmlDoc As XmlDocument = New XmlDocument
4631 myXmlDoc.LoadXml(oXML)
4632 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
4633 For Each mynode As XmlNode In list
4634 oCount = mynode("count").InnerText
4635 If oCount = 0 Then GoTo NextDocument
4636 oWriteText(lsViewIm, Now & " - " & "Gathering information from branch " & WhsDr("WhsName") & ", please wait...", , False)
4637 Next
4638
4639 '"Create XML
4640 oPageCount = PageCount(oCount / 50)
4641 For Page As Integer = 1 To oPageCount
4642 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=adjustment_in&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4643
4644 'Dim myXmlDoc As XmlDocument = New XmlDocument
4645 If oXML = "<documents/>" Then
4646 GoTo NextDocument
4647 End If
4648
4649 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
4650 Dim oGetFileName As String = "AdjustmentIn_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
4651 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
4652 oSaveFile.WriteLine(NewXML)
4653 oSaveFile.Close()
4654 oSaveFile.Dispose()
4655
4656 Dim ds As DataSet
4657 ds = New DataSet
4658 ds.ReadXml(oPath & "\" & oGetFileName)
4659
4660 Dim oHeader As DataTable
4661 oHeader = ds.Tables("document").Copy
4662
4663 For Each oDr As DataRow In oHeader.Rows
4664 Dim oUpdateQry As String
4665 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 1) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 1) END WHERE U_App_Id = 1"
4666 _Path.strCommand = (oUpdateQry)
4667 Next
4668
4669 Next
4670NextDocument:
4671 Next
4672
4673HasFile:
4674
4675 pbAdjustmentIn.Properties.Minimum = 0
4676 pbAdjustmentIn.Properties.Maximum = CInt(Directory.GetFiles(oPath, "AdjustmentIn*.xml", SearchOption.TopDirectoryOnly).Count)
4677 pbAdjustmentIn.Position = 0
4678
4679
4680 '"Post to SAP
4681 Dim oFileName As String
4682 For Each oFile As String In Directory.GetFiles(oPath, "AdjustmentIn*.xml", SearchOption.TopDirectoryOnly)
4683 If isStop Then Exit Sub
4684
4685 ErrorChecker = False
4686
4687 oFileName = Path.GetFileName(oFile)
4688
4689 Dim _ErrCount As Integer = 1
4690Recon:
4691 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Info] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "adjustment_in") : Return
4692 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Info] - Cannot connect in DI API", , True, "adjustment_in") : _ErrCount += 1 : GoTo Recon
4693
4694 Dim ds As DataSet
4695 ds = New DataSet
4696 ds.ReadXml(oFile)
4697
4698 Dim oHeader As DataTable
4699 Dim oDetail As DataTable
4700
4701 oHeader = ds.Tables("document").Copy
4702
4703 Try
4704 oWriteText(lsViewIm, Now & " [Info] - " & "Importing " & oFileName & " Documents, please wait...", , False)
4705
4706 For Each oDr As DataRow In oHeader.Rows
4707
4708
4709 ''MGP 02/28/2017
4710 ''Utility can switch to different database depends on the transaction
4711 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
4712 If Not oChangeDatabase("ACI_FINAL") Then
4713 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4714 ErrorChecker = True
4715 GoTo NextFile
4716 End If
4717 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
4718 If Not oChangeDatabase("AFSI_FINAL") Then
4719 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4720 ErrorChecker = True
4721 GoTo NextFile
4722 End If
4723 End If
4724
4725 If oDr("document_purpose_name") <> "Stock Conversion" Then GoTo NextEntry
4726 Dim GoodReceipt As SAPbobsCOM.Documents
4727 GoodReceipt = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)
4728
4729 oDetail = ds.Tables("document_line").Copy
4730 oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
4731
4732 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OIGN WHERE U_AppPOSRefId = '" & oDr("id") & "'"
4733 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4734 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Adjustment In with " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "adjustment_in")
4735 GoTo NextEntry
4736 End If
4737
4738 With GoodReceipt
4739
4740 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference").ToString.ToString
4741 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id").ToString
4742 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
4743 .DocDate = oDr("utc_document_date")
4744 .Comments = oDr("remark") + " | Adjustment In made from APPTech & iRipple integration."
4745
4746 If Not GetWhs(oCompany.CompanyDB, oDr("branch_id")) Then
4747 ErrorChecker = True
4748 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "adjustment_in")
4749 GoTo NextEntry
4750 End If
4751 Dim oItemCode As String
4752 For Each oDrView As DataRowView In oDetail.DefaultView
4753 With .Lines
4754
4755 ''MGP 03/01/2017
4756 ''For validation cause itemcode in their databases are not match
4757 If oCompany.CompanyDB = "ACI_FINAL" Then
4758 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
4759 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
4760 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
4761 Else
4762 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
4763 ErrorChecker = True
4764 GoTo NextEntry
4765 End If
4766 Else
4767 oItemCode = oDrView("product_stock_no")
4768 End If
4769
4770 .ItemCode = oItemCode
4771 .Quantity = oDrView("quantity")
4772 .WarehouseCode = WhsCode
4773 .AccountCode = "1115800"
4774 .Add()
4775
4776 End With
4777 Next
4778
4779 If Not .Add = 0 Then
4780 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "", Color.Red, True, "adjustment_in")
4781 ErrorChecker = True
4782 Else
4783 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Sucessfully created Transfer In with reference id# " & oDr("reference") & "", Color.Green, False, "adjustment_in")
4784 End If
4785
4786 End With
4787 '"Update LastExport date
4788 Dim oUpdateQry As String
4789 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 1) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 1) END WHERE U_App_Id = 1"
4790 _Path.strCommand = (oUpdateQry)
4791NextEntry:
4792 Next
4793
4794 Catch ex As Exception
4795 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString & "", Color.Red, True, "adjustment_in")
4796 ErrorChecker = True
4797 End Try
4798NextFile:
4799 '"Per XML file
4800 If ErrorChecker = False Then
4801 pbAdjustmentIn.Position += 1
4802 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
4803 Else
4804 pbAdjustmentIn.Position += 1
4805 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
4806 End If
4807
4808 Next
4809 pbAdjustmentIn.Properties.Minimum = 0
4810 pbAdjustmentIn.Properties.Maximum = 99
4811 pbAdjustmentIn.Position = 0
4812 End If
4813 Catch ex As Exception
4814 oWriteText(lsViewIm, Now & " [Err] - " & oCompany.GetLastErrorDescription & "", , True, "adjustment_in")
4815 End Try
4816
4817 End Sub
4818
4819 Private Sub Import_AdjustmentOut()
4820 Try
4821 If cbAdjustmentOut.Checked Then
4822 Dim oDatabase As String = ""
4823 Dim r As Random = New Random
4824 '"Get Path
4825 Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4826 oDatabase = oRegistry.GetKeyValue("Database")
4827 Dim oDotNetReceive As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4828 Dim oDotNet As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4829 Dim oDotNetItemCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4830 _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 2"
4831
4832 Dim oPath As String, oDate As DateTime, _Date As String = Nothing
4833
4834 Dim ErrorChecker As Boolean = False
4835 oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
4836
4837 '"BTG 9/20/2016
4838 '"Check if folder has files
4839 If Directory.GetFiles(oPath, "AdjustmentOut*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
4840 GoTo HasFile
4841 End If
4842
4843 Try
4844 'oDate = _Path.GetField(, "U_LastExportDate")
4845 _Date = _Path.GetField(, "U_LastExportDate") 'oDate.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")
4846 Catch ex As Exception
4847 End Try
4848
4849 Dim ts_Value As Integer = 0
4850 pbIMPStockRequest.Properties.Minimum = 0
4851
4852 Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
4853 _ListWhsCode.strCommand = "SELECT FedTaxID 'GlblLocNum', WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (FedTaxID != '' OR FedTaxID IS NOT NULL)"
4854
4855 Dim oWhsDT As DataTable
4856 oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
4857
4858 Dim oXML As String
4859 Dim NewXML As String
4860
4861 Dim oCount As Integer = 0
4862 Dim oPageCount As Integer = 0
4863 '"Loop every branches
4864
4865 For Each WhsDr As DataRowView In oWhsDT.DefaultView
4866
4867
4868 Dim _afterdate As String = ""
4869 If Not _Date Is Nothing Then
4870 _afterdate = "&after=" & _Date & ""
4871 End If
4872
4873 '"Check document page
4874 oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=adjustment_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4875
4876 Dim myXmlDoc As XmlDocument = New XmlDocument
4877 myXmlDoc.LoadXml(oXML)
4878 Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
4879 For Each mynode As XmlNode In list
4880 oCount = mynode("count").InnerText
4881 If oCount = 0 Then GoTo NextDocument
4882 oWriteText(lsViewIm, Now & " - " & "Gathering information from branch " & WhsDr("WhsName") & ", please wait...", , False)
4883 Next
4884
4885 '"Create XML
4886 oPageCount = PageCount(oCount / 50)
4887 For Page As Integer = 1 To oPageCount
4888 oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?page=" & Page & "&document_type=adjustment_out&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
4889
4890 'Dim myXmlDoc As XmlDocument = New XmlDocument
4891 If oXML = "<documents/>" Then
4892 GoTo NextDocument
4893 End If
4894
4895 NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
4896 Dim oGetFileName As String = "AdjustmentOut_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & "_" & r.Next(1, 99999) & ".xml"
4897 Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & oGetFileName)
4898 oSaveFile.WriteLine(NewXML)
4899 oSaveFile.Close()
4900 oSaveFile.Dispose()
4901
4902 Dim ds As DataSet
4903 ds = New DataSet
4904 ds.ReadXml(oPath & "\" & oGetFileName)
4905
4906 Dim oHeader As DataTable
4907 oHeader = ds.Tables("document").Copy
4908
4909 For Each oDr As DataRow In oHeader.Rows
4910 Dim oUpdateQry As String
4911 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 2) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 2) END WHERE U_App_Id = 2"
4912 _Path.strCommand = (oUpdateQry)
4913 Next
4914
4915 Next
4916NextDocument:
4917 Next
4918
4919HasFile:
4920
4921 pbAdjustmentOut.Properties.Minimum = 0
4922 pbAdjustmentOut.Properties.Maximum = CInt(Directory.GetFiles(oPath, "AdjustmentOut*.xml", SearchOption.TopDirectoryOnly).Count)
4923 pbAdjustmentOut.Position = 0
4924
4925
4926 '"Post to SAP
4927 Dim oFileName As String
4928 For Each oFile As String In Directory.GetFiles(oPath, "AdjustmentOut*.xml", SearchOption.TopDirectoryOnly)
4929 If isStop Then Exit Sub
4930
4931 ErrorChecker = False
4932
4933 oFileName = Path.GetFileName(oFile)
4934
4935
4936 Dim _ErrCount As Integer = 1
4937Recon:
4938 If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Info] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "adjustment_out") : Return
4939 If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Info] - Cannot connect in DI API", , True, "adjustment_out") : _ErrCount += 1 : GoTo Recon
4940
4941 Dim ds As DataSet
4942 ds = New DataSet
4943 ds.ReadXml(oFile)
4944
4945 Dim oHeader As DataTable
4946 Dim oDetail As DataTable
4947
4948 oHeader = ds.Tables("document").Copy
4949
4950 Try
4951 oWriteText(lsViewIm, Now & " [Info] - " & "Importing " & oFileName & " Documents, please wait...", , False)
4952
4953 For Each oDr As DataRow In oHeader.Rows
4954
4955 ''MGP 02/28/2017
4956 ''Utility can switch to different database depends on the transaction
4957 If oCompany.CompanyDB <> "ACI_FINAL" And oDr("branch_id") = "1477" Then
4958 If Not oChangeDatabase("ACI_FINAL") Then
4959 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4960 ErrorChecker = True
4961 GoTo NextFile
4962 End If
4963 ElseIf oCompany.CompanyDB <> "AFSI_FINAL" And oDr("branch_id") <> "1477" Then
4964 If Not oChangeDatabase("AFSI_FINAL") Then
4965 oWriteText(lsViewIm, Now & " [Err] - Failed to change company - File: " & oFileName, Color.Red, True, "pcount_logs")
4966 ErrorChecker = True
4967 GoTo NextFile
4968 End If
4969 End If
4970
4971 If oDr("document_purpose_name") <> "Stock Conversion" Then GoTo NextEntry
4972
4973 Dim GoodIssue As SAPbobsCOM.Documents
4974 GoodIssue = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenExit)
4975
4976
4977
4978 oDotNet.strCommand = "SELECT DocEntry FROM [" & oCompany.CompanyDB & "]..OIGE WHERE U_AppPOSRefId = '" & oDr("id") & "'"
4979 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
4980 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Adjustment Out with " & "Reference id #" & oDr("id") & " is already exist..." & " - File: " & oFileName, Color.Orange, False, "adjustment_out")
4981 GoTo NextEntry
4982 End If
4983
4984 With GoodIssue
4985
4986 .UserFields.Fields.Item("U_AppPOSRef").Value = oDr("reference").ToString.ToString
4987 .UserFields.Fields.Item("U_AppPOSRefId").Value = oDr("id").ToString
4988 .UserFields.Fields.Item("U_AppXmlFileName").Value = oFileName
4989 .DocDate = oDr("utc_document_date")
4990 .Comments = oDr("remark") + " | Adjustment In made from APPTech & iRipple integration."
4991
4992
4993 If Not GetWhs(oCompany.CompanyDB, oDr("branch_id")) Then
4994 ErrorChecker = True
4995 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - No record(s) found for this target branch id." & " - File: " & oFileName, Color.Red, True, "adjustment_out")
4996 GoTo NextEntry
4997 End If
4998
4999 oDetail = ds.Tables("document_line").Copy
5000 oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
5001 Dim oItemCode As String
5002 For Each oDrView As DataRowView In oDetail.DefaultView
5003 With .Lines
5004
5005 ''MGP 03/01/2017
5006 ''For validation cause itemcode in their databases are not match
5007 If oCompany.CompanyDB = "ACI_FINAL" Then
5008 oDotNetItemCode.strCommand = "SELECT ItemCode FROM [" & oCompany.CompanyDB & "]..OITM WHERE U_ItemCode = '" & oDrView("product_stock_no") & "'"
5009 If oDotNetItemCode.Ds.Tables(0).Rows.Count > 0 Then
5010 oItemCode = oDotNetItemCode.GetField(, "ItemCode")
5011 Else
5012 oWriteText(lsViewIm, Now & " [Err] - Itemcode : " & oDrView("product_stock_no") & " doesn't exists - File: " & oFileName, Color.Red, True, "orders_logs")
5013 ErrorChecker = True
5014 GoTo NextEntry
5015 End If
5016 Else
5017 oItemCode = oDrView("product_stock_no")
5018 End If
5019
5020 .ItemCode = oItemCode
5021 .Quantity = oDrView("quantity")
5022 .WarehouseCode = WhsCode
5023 .AccountCode = "1115800"
5024
5025 .Add()
5026
5027 End With
5028 Next
5029
5030 If Not .Add = 0 Then
5031 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - " & oCompany.GetLastErrorDescription & "", Color.Red, True, "adjustment_out")
5032 ErrorChecker = True
5033 Else
5034 oWriteText(lsViewIm, Now & " [" & oDr("reference") & "] - Sucessfully created Transfer In with reference id# " & oDr("reference") & "", Color.Green, False, "adjustment_out")
5035 End If
5036
5037 End With
5038 '"Update LastExport date
5039 Dim oUpdateQry As String
5040 oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 2) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 2) END WHERE U_App_Id = 2"
5041 _Path.strCommand = (oUpdateQry)
5042NextEntry:
5043 Next
5044
5045 Catch ex As Exception
5046 oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString & "", Color.Red, True, "adjustment_out")
5047 ErrorChecker = True
5048 End Try
5049NextFile:
5050 '"Per XML file
5051 If ErrorChecker = False Then
5052 pbAdjustmentOut.Position += 1
5053 File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
5054 Else
5055 pbAdjustmentOut.Position += 1
5056 File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
5057 End If
5058
5059 Next
5060 pbAdjustmentOut.Properties.Minimum = 0
5061 pbAdjustmentOut.Properties.Maximum = 99
5062 pbAdjustmentOut.Position = 0
5063 End If
5064 Catch ex As Exception
5065 oWriteText(lsViewIm, Now & " [Err] - " & oCompany.GetLastErrorDescription & "", , True, "adjustment_out")
5066 End Try
5067
5068 End Sub
5069
5070 '"For physical count
5071 ' Private Sub Import_PCount()
5072 ' If PCount.Checked = True Then
5073 ' Try
5074 ' Dim oDatabase As String = ""
5075 ' '"Get Path
5076 ' Dim _Path As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5077 ' Dim oDotnetExist As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5078
5079
5080 ' _Path.strCommand = "SELECT * FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6"
5081 ' oDatabase = oRegistry.GetKeyValue("Database")
5082 ' Dim ErrorChecker As Boolean = False
5083 ' Dim oPath As String, oDate As DateTime, _Date As String = Nothing
5084 ' oPath = _Path.GetField(, "U_Path") & "\" & _Path.GetField(, "U_Name")
5085
5086 ' '"BTG 9/20/2016
5087 ' '"Check if folder has files
5088 ' If Directory.GetFiles(oPath, "pcount_*.xml", SearchOption.TopDirectoryOnly).Count > 0 Then
5089 ' GoTo HasFile
5090 ' End If
5091
5092 ' Try
5093 ' _Date = _Path.GetField(, "U_LastExportDate")
5094
5095 ' Catch ex As Exception
5096 ' End Try
5097
5098 ' Dim ts_Value As Integer = 0
5099 ' pbIMAout.Properties.Minimum = 0
5100
5101 ' Dim _ListWhsCode As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5102 ' _ListWhsCode.strCommand = "SELECT GlblLocNum, WhsCode, WhsName FROM OWHS(NOLOCK) WHERE (GlblLocNum != '' OR GlblLocNum IS NOT NULL)"
5103
5104 ' Dim oWhsDT As DataTable
5105 ' oWhsDT = _ListWhsCode.Ds.Tables(0).Copy
5106
5107 ' Dim oXML As String
5108 ' Dim NewXML As String
5109
5110 ' Dim oCount As Integer = 0
5111 ' Dim oPageCount As Integer = 0
5112 ' '"Loop every branches
5113 ' oWriteText(lsViewIm, Now & " - " & "Gathering PCount information from each branch, please wait...", , False)
5114 ' For Each WhsDr As DataRowView In oWhsDT.DefaultView
5115 ' Dim _afterdate As String = ""
5116 ' If Not _Date Is Nothing Then
5117 ' _afterdate = "&after=" & _Date & ""
5118
5119 ' End If
5120 ' '"Check document page
5121 ' oXML = oRetail.HttpGet("" & oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?q=count&document_type=physical_count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
5122 ' Dim myXmlDoc As XmlDocument = New XmlDocument
5123 ' myXmlDoc.LoadXml(oXML)
5124 ' Dim list As XmlNodeList = myXmlDoc.SelectNodes("/hash")
5125 ' For Each mynode As XmlNode In list
5126 ' oCount = mynode("count").InnerText
5127
5128 ' If oCount = 0 Then GoTo NextDocument
5129 ' Next
5130
5131 ' '"Create XML
5132 ' oPageCount = PageCount(oCount / 50)
5133 ' For Page As Integer = 1 To oPageCount
5134 ' oXML = oRetail.HttpGet(oRegistry.GetKeyValue("POSServer") & "/api/documents.xml?document_type=physical_count&branch_id=" & WhsDr("GlblLocNum") & _afterdate & "", "")
5135
5136 ' 'Dim myXmlDoc As XmlDocument = New XmlDocument
5137 ' If oXML = "<documents/>" Then
5138 ' GoTo NextDocument
5139 ' End If
5140
5141 ' NewXML = oXML.Replace("</document>", "<branch><customer></customer></branch></document>")
5142
5143 ' Dim oSaveFile As New System.IO.StreamWriter(oPath & "\" & "pcount_" & oGetDate(1) & "_" & oGetDate(2) & "_" & oGetDate(3) & "_" & oGetDate(4) & ".xml")
5144 ' oSaveFile.WriteLine(NewXML)
5145 ' oSaveFile.Close()
5146 ' oSaveFile.Dispose()
5147
5148 ' Next
5149
5150 'NextDocument:
5151 ' Next
5152
5153 'HasFile:
5154
5155 ' pbIMPCount.Properties.Minimum = 0
5156 ' pbIMPCount.Properties.Maximum = CInt(Directory.GetFiles(oPath, "invoice_*.xml", SearchOption.TopDirectoryOnly).Count)
5157 ' pbIMPCount.Position = 0
5158
5159 ' '"Post to SAP
5160 ' Dim oFileName As String
5161 ' For Each oFile As String In Directory.GetFiles(oPath, "pcount_*.xml", SearchOption.TopDirectoryOnly)
5162 ' If isStop Then Exit Sub
5163 ' oFileName = Path.GetFileName(oFile)
5164 ' oWriteText(lsViewIm, Now & " - " & "Importing " & oFileName & " Documents, please wait...", , False)
5165
5166 ' Dim _ErrCount As Integer = 1
5167 'Recon:
5168 ' If _ErrCount = 3 Then oWriteText(lsViewIm, Now & " [Err] - Please contact system administrator, check [@APP_ERRLOG] table.", , True, "pcount_logs") : Return
5169 ' If Not oConnectDI() Then oWriteText(lsViewIm, Now & " [Err] - Cannot connect in DI API", , True, "pcount_logs") : _ErrCount += 1 : GoTo Recon
5170
5171 ' Dim ds As DataSet
5172 ' ds = New DataSet
5173 ' ds.ReadXml(oFile)
5174
5175 ' Dim oHeader As DataTable
5176 ' Dim oDetail As DataTable
5177
5178 ' oHeader = ds.Tables("document").Copy
5179
5180
5181 ' '"BTG 9/8/2016
5182 ' '"Transfer inside for each loop
5183 ' 'If Not oCompany.InTransaction Then
5184 ' ' oCompany.StartTransaction()
5185 ' 'End If
5186
5187 ' Dim oCompanyService As SAPbobsCOM.CompanyService
5188 ' Dim oInvCount As SAPbobsCOM.InventoryCounting
5189 ' Dim oInvCount_Lines As SAPbobsCOM.InventoryCountingLine
5190 ' Dim oTest As SAPbobsCOM.InventoryCountingsService
5191
5192 ' oCompanyService = oCompany.GetCompanyService
5193 ' oTest = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryCountingsService)
5194 ' oInvCount = oTest.GetDataInterface(SAPbobsCOM.InventoryCountingsServiceDataInterfaces.icsInventoryCounting)
5195
5196
5197
5198 ' For Each oDr As DataRow In oHeader.Rows
5199 ' Try
5200 ' 'If Not oCompany.InTransaction Then
5201 ' ' oCompany.StartTransaction()
5202 ' 'End If
5203 ' ''MGP 11/15/2016 added this for pcount already exists blockings
5204
5205 ' oDotnetExist.strCommand = "SELECT Ref2 FROM OINC WHERE Ref2 = '" & oDr("id") & "'"
5206 ' If oDotnetExist.Ds.Tables(0).Rows.Count > 0 Then
5207 ' oWriteText(lsViewIm, Now & " [Info] - Reference id#" & oDr("id") & " is already exist..." & " - File: " & oFileName, , True, "pcount_logs")
5208 ' GoTo NextEntry
5209 ' End If
5210
5211 ' If oDr("status") = "V" Then
5212 ' GoTo NextEntry
5213 ' End If
5214
5215 ' With oInvCount
5216 ' .Remarks = oDr("remark") & "|" & "Physical Count from iRC" & "|" & oDr("document_no")
5217 ' .CountDate = oDr("utc_document_date")
5218 ' .Reference2 = oDr("id")
5219
5220 ' If Not GetWhs("", oDr("branch_id")) Then GoTo NextEntry
5221 ' ''MGP 11/15/2016 moved this syntax here
5222 ' oDetail = ds.Tables("document_line").Copy
5223 ' oDetail.DefaultView.RowFilter = "document_lines_id = '" & oDr("document_id") & "' "
5224 ' For Each oDrView As DataRowView In oDetail.DefaultView
5225 ' oInvCount_Lines = oInvCount.InventoryCountingLines.Add()
5226
5227 ' With oInvCount_Lines
5228 ' .ItemCode = oDrView("product_stock_no")
5229 ' .CountedQuantity = oDrView("quantity")
5230 ' .WarehouseCode = WhsCode
5231 ' .UoMCode = GetUomCode(oDatabase, oDrView("unit_name"))
5232 ' .Counted = SAPbobsCOM.BoYesNoEnum.tYES
5233 ' End With
5234 ' Next
5235
5236
5237 ' Try
5238 ' oTest.Add(oInvCount)
5239 ' Catch ex As Exception
5240 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "pcount_logs")
5241 ' ErrorChecker = True
5242 ' End Try
5243 ' End With
5244
5245 ' Catch ex As Exception
5246 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "pcount_logs")
5247 ' ErrorChecker = True
5248 ' End Try
5249 'NextEntry:
5250 ' '"Update LastExport date
5251 ' Dim oUpdateQry As String
5252 ' oUpdateQry = "UPDATE [@APP_Import] SET U_LastExportDate = CASE WHEN '" & oDr("utc_updated_at") & "' > (SELECT isNULL(U_LastExportDate, DATEADD(DAY, -365, GETDATE())) FROM [@APP_IMPORT](NOLOCK) WHERE U_App_Id = 6) THEN '" & oDr("utc_updated_at") & "' ELSE (SELECT U_LastExportDate FROM [@APP_Import](NOLOCK) WHERE U_App_Id = 6) END WHERE U_App_Id = 6"
5253 ' _Path.strCommand = (oUpdateQry)
5254
5255 ' Next
5256 ' '"Per XML file
5257 ' If ErrorChecker = False Then
5258 ' File.Move(oPath + "/" + oFileName, oPath + "/success/" + oFileName)
5259 ' Else
5260 ' File.Move(oPath + "/" + oFileName, oPath + "/error/" + oFileName)
5261 ' End If
5262
5263 ' pbIMPCount.Position += 1
5264
5265 ' Next
5266
5267 ' oWriteText(lsViewIm, Now & " - " & "Done importing PCount.", Color.Green, False, )
5268 ' oWriteText(lsViewIm, Now & " - " & "=========================================", , False)
5269
5270 ' Catch ex As Exception
5271 ' oWriteText(lsViewIm, Now & " [Err] - " & ex.ToString(), Color.Red, True, "pcount_logs")
5272 ' End Try
5273 ' End If
5274
5275 ' End Sub
5276
5277 Private Function GetUomEntry(ByRef DataBase As String, ByRef UoMCode As String) As Integer
5278 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5279
5280 '"For shortname
5281 oDotNet.strCommand = "SELECT UomEntry FROM /*[DBMULTIPLE_HERE]..*/OUOM(NOLOCK) WHERE UomName = '" & UoMCode & "'"
5282 '"If not exist check uom code
5283 If oDotNet.Ds.Tables(0).Rows.Count = 0 Then
5284 oDotNet.strCommand = "SELECT UomEntry FROM /*[DBMULTIPLE_HERE]..*/OUOM(NOLOCK) WHERE UomCode = '" & UoMCode & "'"
5285 End If
5286 If oDotNet.Ds.Tables(0).Rows.Count > 1 Then
5287 oDotNet.strCommand = "SELECT UomEntry FROM /*[DBMULTIPLE_HERE]..*/OUOM(NOLOCK) WHERE UomCode = '" & UoMCode & "'"
5288 End If
5289 Try
5290 Return oDotNet.GetField(, )
5291 Catch ex As Exception
5292 Return -1
5293 End Try
5294 End Function
5295
5296 '"BTG 9/28/2016
5297 '"For PCount
5298 Private Function GetUomCode(ByRef DataBase As String, ByRef UoMName As String) As String
5299 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5300
5301 '"For shortname
5302 oDotNet.strCommand = "SELECT UomCode FROM /*[DBMULTIPLE_HERE]..*/OUOM(NOLOCK) WHERE UomName = '" & UoMName & "'"
5303 '"If not exist check uom code
5304 If oDotNet.Ds.Tables(0).Rows.Count = 0 Then
5305 oDotNet.strCommand = "SELECT UomCode FROM /*[DBMULTIPLE_HERE]..*/OUOM(NOLOCK) WHERE UomCode = '" & UoMName & "'"
5306 End If
5307 Try
5308 Return oDotNet.GetField(, )
5309 Catch ex As Exception
5310 Return -1
5311 End Try
5312 End Function
5313
5314 Private Function GetDocCardCode(ByRef DataBase As String, ByRef OrderId As Integer) As Boolean
5315 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5316
5317 oDotNet.strCommand = "SELECT CardCode, DocEntry FROM /*[DBMULTIPLE_HERE]..*/OPOR(NOLOCK) WHERE U_AppPOSRef = '" & OrderId & "'"
5318 Try
5319 CardCode = oDotNet.GetField(, "CardCode")
5320 DocEntry = oDotNet.GetField(, "DocEntry")
5321
5322 Return True
5323 Catch ex As Exception
5324 Return False
5325 End Try
5326 End Function
5327
5328 Private Function GetCardCode(ByRef DataBase As String, ByRef CustomerId As Integer) As Boolean
5329 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5330
5331 oDotNet.strCommand = "SELECT CardCode, VatStatus FROM AFSI_FINAL..OCRD(NOLOCK) WHERE AddID = '" & CustomerId & "'"
5332 Try
5333 CardCode = oDotNet.GetField(, "CardCode")
5334 '"BTG 9/9/2016
5335 '"Added vat status field for customer
5336 VatStatusCustomer = oDotNet.GetField(, "VatStatus")
5337 Return True
5338 Catch ex As Exception
5339 oWriteText(lsViewIm, Now & " [Err] - There is no customer with AddID #" & CustomerId & "", Color.Red, True, "invoice_logs")
5340 Return False
5341 End Try
5342 End Function
5343
5344 Private Function GetBranchCardCode(ByRef Database As String, ByRef BranchId As Integer) As Boolean
5345 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5346
5347 oDotNet.strCommand = "SELECT U_CardCode FROM /*[DBMULTIPLE_HERE]..*/OWHS(NOLOCK) WHERE GlblLocNum = '" & BranchId & "'"
5348 Try
5349 CardCode = oDotNet.GetField(, "U_CardCode")
5350
5351 Return True
5352 Catch ex As Exception
5353 Return False
5354 End Try
5355 End Function
5356
5357 Private Function GetAccount(ByRef DataBase As String, ByRef ReasonCode As String) As Boolean
5358 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5359
5360 oDotNet.strCommand = "SELECT U_ISSUE_ACCT, U_GR_ACCT FROM /*[DBMULTIPLE_HERE]..*/[@ISSUE_RECPT_TYPE](NOLOCK) WHERE Code = '" & ReasonCode & "'"
5361 Try
5362 AccountCodeGR = oDotNet.GetField(, "U_GR_ACCT")
5363 _AccountCodeGI = oDotNet.GetField(, "U_ISSUE_ACCT")
5364
5365 Return True
5366 Catch ex As Exception
5367 Return False
5368 End Try
5369 End Function
5370
5371 Private Function GetWhs(ByRef DataBase As String, ByRef WhsId As String) As Boolean
5372 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5373
5374 oDotNet.strCommand = "SELECT WhsCode, WhsName FROM [" & oCompany.CompanyDB & "]..[OWHS](NOLOCK) WHERE FedTaxID = '" & WhsId & "'"
5375 Try
5376
5377 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
5378 WhsCode = oDotNet.GetField(, "WhsCode")
5379 WhsName = oDotNet.GetField(, "WhsName")
5380 Else
5381
5382 Return False
5383 End If
5384
5385 Return True
5386
5387 Catch ex As Exception
5388 oWriteText(lsViewIm, Now & ex.ToString, Color.Red, True, )
5389
5390 Return False
5391 End Try
5392 End Function
5393
5394 '"BTG 8/30/2016
5395 '"Get Batch
5396 Private Function GetBatch(ByRef Database As String, ByRef ItemCode As String, ByRef WhsCode As String, ByRef Qty As Decimal) As Boolean
5397 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5398
5399 oDotNet.strCommand = "EXEC spAppCLOUDGetBatch '" & Database & "', '" & ItemCode & "', '" & WhsCode & "', '" & Qty & "' "
5400 Try
5401 Batch = oDotNet.GetField(, "BatchNum")
5402
5403 Return True
5404 Catch ex As Exception
5405 Return False
5406 End Try
5407 End Function
5408
5409
5410
5411
5412 Private Function ValidateItemBatch(ByRef ItemCode As String) As Boolean
5413 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5414
5415 oDotNet.strCommand = "SELECT ManBtchNum, ItemCode FROM /*[DBMULTIPLE_HERE]..*/OITM(NOLOCK) WHERE ItemCode = '" & ItemCode & "' "
5416 Try
5417 If oDotNet.GetField(, "ManBtchNum") = "Y" Then Return True
5418 Catch ex As Exception
5419 End Try
5420 Return False
5421 End Function
5422
5423 ''MGP 09/02/2016 for receiving of PO
5424 Private Function oGetPOInfo(ByRef DocEntry As Integer, ByRef ItemCode As String) As Boolean
5425 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5426 oDotNet.strCommand = "SELECT LineNum FROM POR1(NOLOCK) WHERE DocEntry = '" & DocEntry & "' AND ItemCode = '" & ItemCode & "'"
5427 Try
5428 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
5429 _POLineNum = oDotNet.GetField(, "LineNum")
5430 Return True
5431 End If
5432 Catch ex As Exception
5433 End Try
5434 Return False
5435 End Function
5436
5437 Private Function ValidateTransferId(ByRef DataBase As String, ByRef Id As Integer) As Boolean
5438 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5439
5440 oDotNet.strCommand = "SELECT DocEntry, DocNum FROM " & DataBase & "(NOLOCK) WHERE U_AppPOSRefId = '" & Id & "' "
5441 Try
5442 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
5443 DocEntry = oDotNet.GetField(, "DocEntry")
5444 Return True
5445 End If
5446 Catch ex As Exception
5447 End Try
5448 Return False
5449 End Function
5450
5451 Private Function ValidateId(ByRef Table As String, ByRef Id As Integer) As Boolean
5452 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5453
5454 oDotNet.strCommand = "SELECT DocEntry, DocNum FROM " & Table & "(NOLOCK) WHERE U_AppPOSRefId = '" & Id & "' "
5455 Try
5456 If oDotNet.Ds.Tables(0).Rows.Count > 0 Then
5457 DocEntry = oDotNet.GetField(, "DocEntry")
5458 Return True
5459 End If
5460 Catch ex As Exception
5461 End Try
5462 Return False
5463 End Function
5464
5465 '"BTG 8/10/2016
5466 '"Get valid invoice per branch for CM payment
5467 Private Function GetInvDocEntry(ByRef Database As String, ByRef Ref As String, ByRef WhsName As String) As Boolean
5468 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5469
5470 oDotNet.strCommand = "SELECT DocEntry FROM /*[DBMULTIPLE_HERE]..*/ORIN(NOLOCK) WHERE U_AppPOSRef = '" & Ref & "' AND U_AppPOSRefBranch = '" & WhsName & "' "
5471 Try
5472 InvDocEntry = oDotNet.GetField(, "DocEntry")
5473
5474 Return True
5475 Catch ex As Exception
5476 Return False
5477 End Try
5478 End Function
5479
5480 Private Function GetBaseLine(ByRef ItemCode As String, ByRef DocEntry As Integer, ByRef oFileName As String) As Boolean
5481 oDotNetBaseLine = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5482
5483 Try
5484 oDotNetBaseLine.strCommand = "SELECT LineNum FROM [" & oCompany.CompanyDB & "]..INV1 WHERE DocEntry = " & DocEntry & " AND ItemCode = '" & ItemCode & "'"
5485
5486 BaseLine = oDotNetBaseLine.GetField(, "LineNum")
5487
5488 Return True
5489 Catch ex As Exception
5490 oWriteText(lsViewIm, Now & " [Err] - Cannot cancel invoice one or more item is missing... - File: " & oFileName, Color.Red, True, "invoice_logs")
5491 Return False
5492 End Try
5493
5494 End Function
5495
5496 '"BTG 9/7/2016
5497 '"For adjustments
5498 Private Function GetTransferDetailsAdj(ByRef Database As String, ByRef POSRefId As String) As Boolean
5499 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5500
5501 oDotNet.strCommand = "SELECT DocEntry, Comments, CASE WHEN ToWhsCode = 'INT' THEN U_ToWhs ELSE ToWhsCode END 'ToWhsCode' FROM /*[DBMULTIPLE_HERE]..*/OWTR(NOLOCK) WHERE U_AppPOSRefId = '" & POSRefId & "' "
5502 Try
5503 ToWhsCode = oDotNet.GetField(, "ToWhsCode")
5504
5505 '"Split comments
5506 Dim _WhsCode As String()
5507 _WhsCode = Split(oDotNet.GetField(, "Comments"), "|")
5508
5509 WhsCode = _WhsCode(1)
5510
5511 Return True
5512 Catch ex As Exception
5513 Return False
5514 End Try
5515 End Function
5516
5517 '"BTG 9/9/2016
5518 '"Get VatGroup per item
5519 Private Function GetVatGroup(ByRef Database As String, ByRef ItemCode As String) As Boolean
5520 oDotNet = New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5521
5522 oDotNet.strCommand = "SELECT ItemCode, VatGourpSA FROM /*[DBMULTIPLE HERE]..*/OITM(NOLOCK) WHERE ItemCode = '" & ItemCode & "' "
5523 Try
5524 VatGroup = oDotNet.GetField(, "VatGourpSA")
5525
5526 Return True
5527 Catch ex As Exception
5528 Return False
5529 End Try
5530 End Function
5531
5532 Private Function oChangeDatabase(ByRef oDatabase As String) As Boolean
5533
5534 Try
5535
5536 oCompany = New SAPbobsCOM.Company
5537
5538 oCompany.Server = oRegistry.GetKeyValue("ServerName") ' "192.168.1.33\R2"
5539 oCompany.DbUserName = oRegistry.GetKeyValue("UserName")
5540 oCompany.DbPassword = AppTech.Decrypt(oRegistry.GetKeyValue("Password"))
5541 oCompany.CompanyDB = oDatabase
5542 oCompany.UserName = oRegistry.GetKeyValue("SAPUser")
5543 oCompany.Password = AppTech.Decrypt(oRegistry.GetKeyValue("SAPpass"))
5544 oCompany.LicenseServer = oRegistry.GetKeyValue("LicenseServer") ' "192.168.1.33"
5545 oCompany.DbServerType = oRegistry.GetKeyValue("ServerType")
5546 oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English
5547
5548 If Not oCompany.Connect = 0 Then
5549 Me.Cursor = Cursors.Default
5550 Return False
5551 Else
5552 oImConnectedTo = oDatabase
5553 End If
5554
5555 'cmbServerType.EditValue = oRegistry.GetKeyValue("ServerType") 'Split(GetConn("ServerType"), "|")(0)
5556 'txtServerName.Text = oRegistry.GetKeyValue("ServerName") 'Split(GetConn("ServerName"), "|")(1)
5557 'txtDbName.Text = oRegistry.GetKeyValue("Database") 'Split(GetConn("Database"), "|")(2)
5558 'txtDbUser.Text = oRegistry.GetKeyValue("UserName") 'Split(GetConn("UserName"), "|")(3)
5559 'txtDbPass.Text = 'AppTech.Decrypt(Split(GetConn("Password"), "|")(4))
5560 'txtLicenseServer.Text = oRegistry.GetKeyValue("LicenseServer") 'Split(GetConn("LicServer"), "|")(5)
5561 'txtSAPUser.Text = oRegistry.GetKeyValue("SAPUser")
5562 'txtSAPPass.Text = AppTech.Decrypt(oRegistry.GetKeyValue("SAPpass"))
5563
5564 Return True
5565 Catch ex As Exception
5566 Return False
5567 End Try
5568
5569
5570 End Function
5571
5572 Private _POLineNum As String
5573 Private Property POLineNum As Integer
5574 Get
5575 Return _POLineNum
5576 End Get
5577 Set(value As Integer)
5578 _POLineNum = value
5579 End Set
5580 End Property
5581
5582 Private _CardCode As String
5583 Private Property CardCode As String
5584 Get
5585 Return _CardCode
5586 End Get
5587 Set(value As String)
5588 _CardCode = value
5589 End Set
5590 End Property
5591
5592 Private _DocEntry As String
5593 Private Property DocEntry As Integer
5594 Get
5595 Return _DocEntry
5596 End Get
5597 Set(value As Integer)
5598 _DocEntry = value
5599 End Set
5600 End Property
5601
5602 Private _AccountCodeGR As String
5603 Private Property AccountCodeGR As String
5604 Get
5605 Return _AccountCodeGR
5606 End Get
5607 Set(value As String)
5608 _AccountCodeGR = value
5609 End Set
5610 End Property
5611
5612 Private _AccountCodeGI As String
5613 Private Property AccountCodeGI As String
5614 Get
5615 Return _AccountCodeGI
5616 End Get
5617 Set(value As String)
5618 _AccountCodeGI = value
5619 End Set
5620 End Property
5621
5622 Private _WhsCode As String
5623 Private Property WhsCode As String
5624 Get
5625 Return _WhsCode
5626 End Get
5627 Set(value As String)
5628 _WhsCode = value
5629 End Set
5630 End Property
5631
5632 Private _oCheck As Boolean
5633 Private Property oCheck As Boolean
5634 Get
5635 Return _oCheck
5636 End Get
5637 Set(value As Boolean)
5638 _oCheck = value
5639 End Set
5640 End Property
5641
5642 Private _ToWhsCode As String
5643 Private Property ToWhsCode As String
5644 Get
5645 Return _ToWhsCode
5646 End Get
5647 Set(value As String)
5648 _ToWhsCode = value
5649 End Set
5650 End Property
5651
5652 Private _WhsName As String
5653 Private Property WhsName As String
5654 Get
5655 Return _WhsName
5656 End Get
5657 Set(value As String)
5658 _WhsName = value
5659 End Set
5660 End Property
5661
5662 Private _InvDocEntry As Integer
5663 Private Property InvDocEntry As Integer
5664 Get
5665 Return _InvDocEntry
5666 End Get
5667 Set(value As Integer)
5668 _InvDocEntry = value
5669 End Set
5670 End Property
5671
5672 Private _TransId As Integer
5673 Private Property TransId As Integer
5674 Get
5675 Return _TransId
5676 End Get
5677 Set(value As Integer)
5678 _TransId = value
5679 End Set
5680 End Property
5681
5682 Private _Batch As String
5683 Private Property Batch As String
5684 Get
5685 Return _Batch
5686 End Get
5687 Set(value As String)
5688 _Batch = value
5689 End Set
5690 End Property
5691
5692 Private _CashAcc As String
5693 Private Property CashAcc As String
5694 Get
5695 Return _CashAcc
5696 End Get
5697 Set(value As String)
5698 _CashAcc = value
5699 End Set
5700 End Property
5701
5702 Private _CheckAcc As String
5703 Private Property CheckAcc As String
5704 Get
5705 Return _CheckAcc
5706 End Get
5707 Set(value As String)
5708 _CheckAcc = value
5709 End Set
5710 End Property
5711
5712 Private _VatGroup As String
5713 Private Property VatGroup As String
5714 Get
5715 Return _VatGroup
5716 End Get
5717 Set(value As String)
5718 _VatGroup = value
5719 End Set
5720 End Property
5721
5722 Private _BaseLine As String
5723 Private Property BaseLine As String
5724 Get
5725 Return _BaseLine
5726 End Get
5727 Set(value As String)
5728 _BaseLine = value
5729 End Set
5730 End Property
5731
5732 Private _VatStatusCustomer As String
5733 Private Property VatStatusCustomer As String
5734 Get
5735 Return _VatStatusCustomer
5736 End Get
5737 Set(value As String)
5738 _VatStatusCustomer = value
5739 End Set
5740 End Property
5741
5742 Dim isStop As Boolean = False
5743 Private Sub btStop_Click(sender As Object, e As EventArgs) Handles btStop.Click
5744 If bgIm.IsBusy AndAlso bgIm.WorkerSupportsCancellation Then
5745 bgIm.CancelAsync()
5746 oWriteText(lsViewIm, Now & " - Stopping, please wait. Trying to finish this last file.", Color.DodgerBlue, False)
5747 End If
5748 tmrCountDown.Stop()
5749 isStop = True
5750 End Sub
5751
5752 Private Sub bgIm_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgIm.RunWorkerCompleted
5753 If e.Cancelled Then
5754 tmr.Stop()
5755 tmrCountDown.Stop()
5756 oWriteText(lsViewIm, Now & " - Stopped successfully.", Color.DodgerBlue, False)
5757 isStop = False
5758
5759 If isClosing Then
5760 isClosing = False
5761 Me.Close()
5762 End If
5763
5764 lblTime.Text = "00:00:00"
5765
5766 btImport.Visible = True
5767 btStop.Visible = False
5768 ElseIf Not IsNothing(e.Error) Then
5769 '"
5770 Else
5771 Dim _Timer As New App_SqlDb(oRegistry.GetKeyValue("ServerName"), oRegistry.GetKeyValue("UserName"), AppTech.Decrypt(oRegistry.GetKeyValue("Password")), oRegistry.GetKeyValue("Database"))
5772 _Timer.strCommand = "SELECT * FROM [@APP_IMPORT] WHERE U_App_Id = 0"
5773
5774 Select Case CInt(_Timer.GetField(, "U_DayFreqTime_"))
5775 Case -1 'second(s)
5776 oInterval = CInt(_Timer.GetField(, "U_DayFreqTime")) * 1000
5777 duration = DateTime.Now.AddSeconds(_Timer.GetField(, "U_DayFreqTime"))
5778 Case 1 'min(s)
5779 oInterval = CInt(_Timer.GetField(, "U_DayFreqTime")) * 60000
5780 duration = DateTime.Now.AddMinutes(_Timer.GetField(, "U_DayFreqTime"))
5781 Case 2 'hr(s)
5782 oInterval = (CInt(_Timer.GetField(, "U_DayFreqTime")) * 60) * 60 * 1000
5783 duration = DateTime.Now.AddHours(_Timer.GetField(, "U_DayFreqTime"))
5784 End Select
5785
5786 tmrCountDown = New System.Timers.Timer
5787
5788 tmrCountDown.Interval = 500
5789 AddHandler tmrCountDown.Elapsed, AddressOf tmrCountdown_Tick
5790 tmrCountDown.Start()
5791
5792 End If
5793 End Sub
5794
5795 Private Sub cbStockRequest_CheckedChanged(sender As Object, e As EventArgs) Handles cbStockRequest.CheckedChanged
5796
5797 End Sub
5798 Private Sub pbIMPStockRequest_EditValueChanged(sender As Object, e As EventArgs) Handles pbIMPStockRequest.EditValueChanged
5799
5800 End Sub
5801 Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click
5802
5803 End Sub
5804 Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click
5805
5806 End Sub
5807 Private Sub pbIMPCount_EditValueChanged(sender As Object, e As EventArgs) Handles pbIMPCount.EditValueChanged
5808
5809 End Sub
5810 Private Sub PCount_CheckedChanged(sender As Object, e As EventArgs) Handles PCount.CheckedChanged
5811
5812 End Sub
5813 Private Sub GroupControl1_Paint(sender As Object, e As PaintEventArgs) Handles GroupControl1.Paint
5814
5815 End Sub
5816
5817 Private Sub btnPullout_Click(sender As Object, e As EventArgs) Handles btnPCount.Click
5818 Import_PCount()
5819 End Sub
5820
5821
5822
5823End Class