-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
1541 lines (1327 loc) · 79.8 KB
/
Copy pathProgram.cs
File metadata and controls
1541 lines (1327 loc) · 79.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Text;
using pcAmerica.DesktopPOS.API.Client;
using pcAmerica.DesktopPOS.API.Client.PaymentService;
using pcAmerica.DesktopPOS.API.Client.CustomerService;
using pcAmerica.DesktopPOS.API.Client.CompanyInformationService;
using pcAmerica.DesktopPOS.API.Client.EmployeeService;
using pcAmerica.DesktopPOS.API.Client.InventoryService;
using pcAmerica.DesktopPOS.API.Client.SalesService;
using pcAmerica.DesktopPOS.API.Client.MenuService;
using pcAmerica.DesktopPOS.API.Client.TableService;
namespace APITester
{
class Program
{
Random random = new Random();
static void Main(string[] args)
{
//TestCreditCard();
//TestCustomers();
//TestEmployee();
//TestInventory();
//TestSales();
//TestMenus();
//TestTables();
//TestBurgerExpress();
//deleteItemsTest();
//TestVoidInvoice();
//TestSectionsAndTables();
//TestSplits();
//TestPreAuthInvoice();
//TestGetStoreIDsAndGetStationIDs();
//AddItemsOutOfOrderTest();
//TestDBInfo();
//testSendToKitchen();
TestSaleWithCreditCardPayment();
}
static void NewTest()
{
try
{
SalesAPI api = new SalesAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context salesContext = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
salesContext.CashierID = "100101";
salesContext.StoreID = "1001";
salesContext.StationID = "07";
pcAmerica.DesktopPOS.API.Client.SalesService.Context context =
new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "07";
InventoryAPI InvApi = new InventoryAPI();
pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
InvContext.CashierID = "100101";
InvContext.StationID = "07";
InvContext.StoreID = "1001";
// StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
Invoice inv = api.StartNewInvoice(context, "Luigi" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));
// getting invoice to show locked status should be locked by this station(7)
inv = api.GetInvoice(context, inv.InvoiceNumber);
if (inv.Locked == true)
{
Console.WriteLine("Invoice #{0} is locked by Station: {1}", inv.InvoiceNumber.ToString(), inv.LockedByStation);
}
else
{
Console.WriteLine("Invoice #{0} is unlocked", inv.InvoiceNumber.ToString());
}
//setting party size
api.SetPartySizeForInvoice(context, inv.InvoiceNumber, 3);
InventoryItem itemToAdd = InvApi.GetItem(InvContext, "SALAD1");
Guid itemToAddID = Guid.NewGuid();
LineItem LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "42" };
inv.LineItems.Add(LineItemToAdd);
itemToAdd.ModifierGroups = InvApi.GetModiferGroupsForItem(InvContext, itemToAdd.ItemNumber);
foreach (ModifierGroup ModGroup in itemToAdd.ModifierGroups)
{
Console.WriteLine("ModifierGroup:{0}", ModGroup.ItemName);
Console.WriteLine("{0}", ModGroup.Prompt);
int i = 1;
if (ModGroup.Forced == false)
{
Console.WriteLine("{0} - NONE", i);
i++;
}
//NOTE THIS HAS CHANGED Modifier Items for Groups now are retrieved by calling GetModiferItemsForModiferGroups
ModGroup.ModifierItems = InvApi.GetModifierItemsForModifierGroup(InvContext, ModGroup.ItemNumber);
foreach (ModifierItem ModItem in ModGroup.ModifierItems)
{
Console.WriteLine("{0} - {1} : {2}", i, ModItem.ItemNumber, ModItem.ItemName);
i++;
}
string answer = Console.ReadLine();
if (answer.Length > 1)
{
Console.WriteLine("Invalid answer i Choose option 1 is chosen by default");
answer = "1";
}
else if (char.IsDigit(answer[0]) == false)
{
Console.WriteLine("Invalid answer i Choose option 1 chosen by defualt");
answer = "1";
}
InventoryItem dressing = InvApi.GetItem(InvContext, ModGroup.ModifierItems[Convert.ToInt32(answer) - 1].ItemNumber);
decimal Price = 0;
if (ModGroup.Charged == true) { Price = dressing.Price; }
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = itemToAdd.ItemName, ItemNumber = dressing.ItemNumber, Price = dressing.Price, Quantity = 1, State = EntityState.Added, Guest = "42" });
}
// I created this item with the prompt description status set.
itemToAdd = InvApi.GetItem(InvContext, "MiscItem");
itemToAddID = Guid.NewGuid();
LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = "Keychain", ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "11" };
inv.LineItems.Add(LineItemToAdd);
api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
api.UnLockInvoice(context, inv.InvoiceNumber);
inv = api.GetInvoice(context, inv.InvoiceNumber);
Console.WriteLine("The invoice has {0} guests", inv.PartySize);
foreach (LineItem individualItem in inv.LineItems)
{
Console.WriteLine("Guest {0} has ordered: {1}-{2}", individualItem.Guest, individualItem.ItemNumber, individualItem.ItemName);
}
//should show this invoice as locked by this station
api.LockInvoice(context, inv.InvoiceNumber);
List<OnHoldInfo> onHoldInfos = api.GetAllOnHoldInvoices(context);
Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetAllOnHoldInvoices",
onHoldInfos.Count));
foreach (OnHoldInfo onHoldInfo in onHoldInfos)
{
foreach (OnHoldInfo OHI in onHoldInfos)
{
if (OHI.Locked == true)
{
Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}",
OHI.InvoiceNumber, OHI.LockedByStation));
}
}
}
//checking locked status should be locked by this station
inv = api.GetInvoice(context, inv.InvoiceNumber);
if (inv.Locked == true)
{
Console.WriteLine("Invoice #{0} is locked by Station: {1}", inv.InvoiceNumber.ToString(), inv.LockedByStation);
}
else
{
Console.WriteLine("Invoice #{0} is unlocked", inv.InvoiceNumber.ToString());
}
api.UnLockInvoice(context, inv.InvoiceNumber);
onHoldInfos.Clear();
onHoldInfos = api.GetAllOnHoldInvoices(context);
//should show this invoice as unlocked.
Console.WriteLine(String.Format("Retrieved {0} OnHoldInfo from GetAllOnHoldInvoices",
onHoldInfos.Count));
foreach (OnHoldInfo onHoldInfo in onHoldInfos)
{
foreach (OnHoldInfo OHI in onHoldInfos)
{
if (OHI.Locked == true)
{
Console.WriteLine(String.Format("Invoice {0} is locked by Station {1}",
OHI.InvoiceNumber, OHI.LockedByStation));
}
}
}
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestPreAuthInvoice()
{
try
{
SalesAPI salesAPI = new SalesAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context salesContext = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
salesContext.CashierID = "100101";
salesContext.StoreID = "1001";
salesContext.StationID = "01";
PaymentAPI paymentAPI = new PaymentAPI();
// first create the credit card object
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest creditCard1 = new pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest();
creditCard1.Amount = 5.00M;
creditCard1.CardNumber = "5454545454545454";
creditCard1.ExpirationMonth = 05;
creditCard1.ExpirationYear = 13;
creditCard1.BarTab = true;// set this for a pre authed bar tab
creditCard1.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PreAuth;
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardPaymentProcessingResponse ProcessingResponse1 = paymentAPI.ProcessCreditCard(creditCard1);
// create an invoice to apply your payment to
Invoice inv = salesAPI.StartNewInvoice(salesContext, "Jane", "XXOPEN TABS");
// use paymentIndex of -1 since the card isn't attached to the invoice yet
AppliedPaymentResponse paymentResponse1 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PreAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, -1);
// some time passes and items are added to the invoice
InventoryAPI invAPI = new InventoryAPI();
pcAmerica.DesktopPOS.API.Client.InventoryService.Context invContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
invContext.CashierID = "100101";
invContext.StationID = "01";
invContext.StoreID = "1001";
salesAPI.LockInvoice(salesContext, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "2" });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "3" });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "4" });
inv = salesAPI.ModifyItems(salesContext, inv.InvoiceNumber, inv.LineItems);
//to complete the earlier pre auth card you must call CompletePreAuth and pass it the PaymentIndex you got back from ApplyCardPayment earlier
creditCard1.Amount = inv.GrandTotal - 7.98M;
creditCard1.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PostAuth;
creditCard1.PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber;
creditCard1.ReferenceNumber = ProcessingResponse1.ReferenceNumber;
creditCard1.PaymentIndex = paymentResponse1.PaymentIndex;
ProcessingResponse1 = paymentAPI.CompletePreAuth(creditCard1, inv.InvoiceNumber);
paymentResponse1 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, paymentResponse1.PaymentIndex);
// create a second credit card object
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest creditCard2 = new pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest();
creditCard2.Amount = 7.98M;
creditCard2.CardNumber = "4545454545454545";
creditCard2.ExpirationMonth = 05;
creditCard2.ExpirationYear = 13;
creditCard2.BarTab = false;// this card is not a bar tab
creditCard2.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PreAuth;
//process and apply the 2nd card
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardPaymentProcessingResponse ProcessingResponse2 = paymentAPI.ProcessCreditCard(creditCard2);
AppliedPaymentResponse paymentResponse2 = salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse2.Amount, ApprovalCode = ProcessingResponse2.ApprovalCode, CardNumber = ProcessingResponse2.CardNumber, ExpirationMonth = ProcessingResponse2.ExpirationMonth, ExpirationYear = ProcessingResponse2.ExpirationYear, ExtensionData = ProcessingResponse2.ExtensionData, IsPrePaidCard = ProcessingResponse2.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PreAuth, ReferenceNumber = ProcessingResponse2.ReferenceNumber, Result = ProcessingResponse2.Result, TipAmount = ProcessingResponse2.TipAmount, TransactionNumber = ProcessingResponse2.TransactionNumber }, -1);
//update the invoice object and end the transaction
inv = salesAPI.GetInvoice(salesContext, inv.InvoiceNumber);
salesAPI.EndInvoice(salesContext, inv.InvoiceNumber);
//salesAPI.PrintReceipt(salesContext, inv.InvoiceNumber,-1);
//add a tips to the invoice
creditCard1.TipAmount = 1.5M;
creditCard1.BarTab = false;
ProcessingResponse1 = paymentAPI.CompletePreAuth(creditCard1, inv.InvoiceNumber);
salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse1.Amount, ApprovalCode = ProcessingResponse1.ApprovalCode, CardNumber = ProcessingResponse1.CardNumber, ExpirationMonth = ProcessingResponse1.ExpirationMonth, ExpirationYear = ProcessingResponse1.ExpirationYear, ExtensionData = ProcessingResponse1.ExtensionData, IsPrePaidCard = ProcessingResponse1.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse1.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse1.ReferenceNumber, Result = ProcessingResponse1.Result, TipAmount = ProcessingResponse1.TipAmount, TransactionNumber = ProcessingResponse1.TransactionNumber }, paymentResponse1.PaymentIndex);
//to complete the earlier pre auth card you must call CompletePreAuth and pass it the PaymentIndex you got back from ApplyCardPayment earlier
creditCard2.Amount = 7.98M;
creditCard2.TipAmount = 1.77M;
creditCard2.ProcessingType = pcAmerica.DesktopPOS.API.Client.PaymentService.ProcessingType.PostAuth;
creditCard2.PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber;
creditCard2.ReferenceNumber = ProcessingResponse2.ReferenceNumber;
creditCard2.PaymentIndex = paymentResponse2.PaymentIndex;
ProcessingResponse2 = paymentAPI.CompletePreAuth(creditCard2, inv.InvoiceNumber);
salesAPI.ApplyCardPayment(salesContext, inv.InvoiceNumber, -1, new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse() { Amount = ProcessingResponse2.Amount, ApprovalCode = ProcessingResponse2.ApprovalCode, CardNumber = ProcessingResponse2.CardNumber, ExpirationMonth = ProcessingResponse2.ExpirationMonth, ExpirationYear = ProcessingResponse2.ExpirationYear, ExtensionData = ProcessingResponse2.ExtensionData, IsPrePaidCard = ProcessingResponse2.IsPrePaidCard, PostAuthReferenceNumber = ProcessingResponse2.PostAuthReferenceNumber, ProcessType = pcAmerica.DesktopPOS.API.Client.SalesService.ProcessingType.PostAuth, ReferenceNumber = ProcessingResponse2.ReferenceNumber, Result = ProcessingResponse2.Result, TipAmount = ProcessingResponse2.TipAmount, TransactionNumber = ProcessingResponse2.TransactionNumber }, paymentResponse2.PaymentIndex);
salesAPI.PrintReceipt(salesContext, inv.InvoiceNumber, -1);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void DoItemsNeedToBeSentToKitchen(pcAmerica.DesktopPOS.API.Client.SalesService.Context context, long invoiceNumber)
{
SalesAPI api = new SalesAPI();
Invoice inv = api.GetInvoice(context, invoiceNumber);
int i = 0, count = 0;
for (i = 0; i <= inv.LineItems.Count - 1; i++)
{
if (inv.LineItems[i].SentToKitchen == false)
{
Console.WriteLine(String.Format("Line#{0} needs to be sent to the Kitchen", i + 1));
count++;
}
}
if (count == 0) { Console.WriteLine("No items need to be sent to the Kitchen"); }
}
static void TestSplits()
{
try
{
SalesAPI api = new SalesAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
Invoice inv = api.StartNewInvoice(context, "Rich", "XXOPEN TABS");
api.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 3, State = EntityState.Added, Guest = "1" });
api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
api.UnLockInvoice(context, inv.InvoiceNumber);
inv = api.SplitInvoice(context, inv.InvoiceNumber, 3);
for (int i = 0; i <= inv.SplitInfo.NumberOfSplitChecks - 1; i++)
{
Console.WriteLine(String.Format("Rich - Guest #{0}: ${1}", i + 1, inv.SplitInfo.GrandTotalForSplit[i]));
}
inv = api.StartNewInvoice(context, "Steve", "XXOPEN TABS");
api.SetPartySizeForInvoice(context, inv.InvoiceNumber, 3);
api.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "2" });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "3" });
api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
api.UnLockInvoice(context, inv.InvoiceNumber);
inv = api.SplitInvoice(context, inv.InvoiceNumber, 3);
api.ApplyCashPayment(context, inv.InvoiceNumber, 1, 2.00M);
api.ApplyCashPayment(context, inv.InvoiceNumber, 2, 50.00M);
//updates the split information so it has the payment info
inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
// shows split info grand total and if it is completly paid
// NOTE: Even if you have fully paid a sub check it won't be marked as paid until you run EndSubCheck on it
for (int i = 0; i <= inv.SplitInfo.NumberOfSplitChecks - 1; i++)
{
Console.WriteLine(String.Format("Steve - Grand Total SPLIT #{0}: ${1}", i + 1, inv.SplitInfo.GrandTotalForSplit[i]));
Console.WriteLine(String.Format("Steve - Paid SPLIT #{0}: {1}", i + 1, inv.SplitInfo.IsSplitPaid[i]));
}
api.EndSubCheck(context, inv.InvoiceNumber, 2);
inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
for (int i = 0; i <= inv.SplitInfo.NumberOfSplitChecks - 1; i++)
{
Console.WriteLine(String.Format("Steve - Grand Total SPLIT #{0}: ${1}", i + 1, inv.SplitInfo.GrandTotalForSplit[i]));
Console.WriteLine(String.Format("Steve - Paid SPLIT #{0}: {1}", i + 1, inv.SplitInfo.IsSplitPaid[i]));
}
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestSectionsAndTables()
{
try
{
SalesAPI salesAPI = new SalesAPI();
TableAPI tableAPI = new TableAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
pcAmerica.DesktopPOS.API.Client.TableService.Context tableContext = new pcAmerica.DesktopPOS.API.Client.TableService.Context();
tableContext.CashierID = "100101";
tableContext.StationID = "01";
tableContext.StoreID = "1001";
Invoice inv;
List<TableInfo> tables = tableAPI.GetAllTablesAndOpenInvoices(tableContext);
if (tables.Count > 0)
{
int i = 0;
for (i = 0; i < tables.Count - 1; i++)
{
if (tables[i].SectionID.StartsWith("XX") && !tables[i].Occupied) { continue; }
inv = salesAPI.StartNewInvoice(context, tables[i].TableNumber, tables[i].SectionID);
salesAPI.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
salesAPI.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
salesAPI.UnLockInvoice(context, inv.InvoiceNumber);
break;
}
}
inv = salesAPI.StartNewInvoice(context, "Dave", "XXTAKEOUT");
salesAPI.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
salesAPI.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
salesAPI.UnLockInvoice(context, inv.InvoiceNumber);
inv = salesAPI.StartNewInvoice(context, "Jay", "XXOPEN TABS");
salesAPI.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
salesAPI.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
salesAPI.UnLockInvoice(context, inv.InvoiceNumber);
//NOTE: Delivery invoices will be put into the delivery tab section however the will not be put
//into Delivery Tracking as there is curently no way to provide customer numbers or a time promised
inv = salesAPI.StartNewInvoice(context, "Sara", "XXDELIVERY");
salesAPI.LockInvoice(context, inv.InvoiceNumber);
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
salesAPI.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
salesAPI.UnLockInvoice(context, inv.InvoiceNumber);
Console.WriteLine("There should now be open invoices on the first empty table in the list as well as in the Delivery, Takeout and Open Tabs sections.");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestVoidInvoice()
{
try
{
SalesAPI api = new SalesAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
Console.WriteLine("Enter an invoice number to void: ");
string answer = Console.ReadLine();
Console.WriteLine("Send voided invoice to the kitchen printer?" + Environment.NewLine + "1 for YES" + Environment.NewLine + "0 for NO");
string answer2 = Console.ReadLine();
api.VoidInvoice(context, Convert.ToInt64(answer), answer2 == "1" ? true : false );
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void deleteItemsTest()
{
try
{
SalesAPI api = new SalesAPI();
pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
// StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
Invoice inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Ticks.ToString(), "XXOPEN TABS");
Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));
// Unlock Invoice
/*if (api.UnLockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));*/
// Lock Invoice
if (api.LockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber));
// GetInvoiceHeader
inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber));
// GetInvoice
inv = api.GetInvoice(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber));
InventoryAPI InvApi = new InventoryAPI();
pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
InvContext.CashierID = "100101";
InvContext.StationID = "01";
InvContext.StoreID = "1001";
Guid parentGuid = new Guid();
// ModifyItems
inv.LineItems.Add(new LineItem() { Id = parentGuid, ItemName = "BURGER", ItemNumber = "SAND1", Price = 1.99M, Quantity = 2, State = EntityState.Added });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "Add Tomato", ItemNumber = "SANDMod3", Price = 0.10M, Quantity = 1, State = EntityState.Added, ParentId = parentGuid });
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "BURGER", ItemNumber = "SAND1", Price = 1.99M, Quantity = 1, State = EntityState.Added });
api.UnLockInvoice(context, inv.InvoiceNumber);
api.LockInvoice(context, inv.InvoiceNumber);
inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
Invoice inv2 = api.GetInvoice(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv2.GrandTotal));
//inv2.LineItems[0].State = EntityState.Deleted;
//inv2.LineItems[1].State = EntityState.Deleted;
inv2 = api.ModifyItems(context, inv2.InvoiceNumber, inv2.LineItems);
Console.WriteLine(String.Format("ModifyItems new invoice value after deleting burger with tomato: {0}", inv2.GrandTotal));
api.LockInvoice(context, inv2.InvoiceNumber);
// ApplyCashPayment - applying grand total minus 1 dollar
AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv2.InvoiceNumber, -1, inv2.GrandTotal);
if (payResponse.Success)
Console.WriteLine(String.Format("Applied cash payment, change due {0}", payResponse.ChangeAmount));
else
Console.WriteLine("***ERROR*** Could not apply payment");
// EndInvoice
if (api.EndInvoice(context, inv2.InvoiceNumber))
Console.WriteLine("Ended invoice successfully");
else
Console.WriteLine("***ERROR*** Could not end invoice");
// PrintReceipt - providing -1 for the split check # when there are no split checks
if (api.PrintReceipt(context, inv2.InvoiceNumber, -1))
Console.WriteLine("Receipt was printed");
else
Console.WriteLine("***ERROR*** Receive was NOT printed");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
// more examples to work specificly with the sample database Burger Express that comes bundled with Resturant Pro Express
// shows getting list of all inventory items, adding items two different ways, selecting a modifier for an item and splitting a check by guest
static void TestBurgerExpress()
{
try
{
SalesAPI api = new SalesAPI();
DateTime startDateTime = DateTime.Parse("1/1/2010");
DateTime endDateTime = DateTime.Parse("12/31/2010");
SalesTotals totals = api.GetTotals(startDateTime, endDateTime);
Console.WriteLine(String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}", startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal));
List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime);
Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold", startDateTime, endDateTime, sales.Count));
pcAmerica.DesktopPOS.API.Client.SalesService.Context context = new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
// StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
Invoice inv = api.StartNewInvoice(context, "Dan" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));
// Unlock Invoice
if (api.UnLockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));
// Lock Invoice
if (api.LockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber));
// GetInvoiceHeader
inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber));
// GetInvoice
inv = api.GetInvoice(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("GetInvoice with #: {0}", inv.InvoiceNumber));
InventoryAPI InvApi = new InventoryAPI();
pcAmerica.DesktopPOS.API.Client.InventoryService.Context InvContext = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
InvContext.CashierID = "100101";
InvContext.StationID = "01";
InvContext.StoreID = "1001";
api.SetPartySizeForInvoice(context, inv.InvoiceNumber, 2);
List<InventoryItem> items = InvApi.GetItemListExtended(InvContext);
Console.WriteLine("*******************All Inventory Items************************");
foreach (InventoryItem singleItem in items)
{
Console.WriteLine(String.Format("Item#: {0} ItemName:{1}", singleItem.ItemNumber, singleItem.ItemName));
}
Console.WriteLine("***************************************************************");
// ModifyItems
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = "TRIPPLE CHEESE BURGER", ItemNumber = "SAND4", Price = 3.99M, Quantity = 1, State = EntityState.Added, Guest = "1" });
InventoryItem itemToAdd = InvApi.GetItem(InvContext, "SALAD3");
Guid itemToAddID = Guid.NewGuid();
LineItem LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
inv.LineItems.Add(LineItemToAdd);
itemToAdd.ModifierGroups = InvApi.GetModiferGroupsForItem(InvContext, itemToAdd.ItemNumber);
foreach (ModifierGroup ModGroup in itemToAdd.ModifierGroups)
{
Console.WriteLine("ModifierGroup:{0}", ModGroup.ItemName);
Console.WriteLine("{0}", ModGroup.Prompt);
int i = 1;
if (ModGroup.Forced == false)
{
Console.WriteLine("{0} - NONE", i);
i++;
}
//NOTE THIS HAS CHANGED Modifier Items for Groups now are retrieved by calling GetModiferItemsForModiferGroups
ModGroup.ModifierItems = InvApi.GetModifierItemsForModifierGroup(InvContext, ModGroup.ItemNumber);
foreach (ModifierItem ModItem in ModGroup.ModifierItems)
{
Console.WriteLine("{0} - {1} : {2}", i, ModItem.ItemNumber, ModItem.ItemName);
i++;
}
string answer = Console.ReadLine();
if (answer.Length > 1)
{
Console.WriteLine("Invalid answer i Choose option 1 is chosen by default");
answer = "1";
}
else if (char.IsDigit(answer[0]) == false)
{
Console.WriteLine("Invalid answer i Choose option 1 chosen by defualt");
answer = "1";
}
InventoryItem dressing = InvApi.GetItem(InvContext, ModGroup.ModifierItems[Convert.ToInt32(answer) - 1].ItemNumber);
decimal Price = 0;
if (ModGroup.Charged == true) { Price = dressing.Price; }
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = dressing.ItemName, ItemNumber = dressing.ItemNumber, Price = dressing.Price, Quantity = 1, State = EntityState.Added, Guest = "2" });
}
itemToAdd = InvApi.GetItem(InvContext, "DaveBurger");
itemToAddID = Guid.NewGuid();
LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
inv.LineItems.Add(LineItemToAdd);
itemToAdd.ModifierItems = InvApi.GetIndividualModifiers(InvContext, itemToAdd.ItemNumber);
if (itemToAdd.ModifierItems.Count > 0)
inv.LineItems.Add(new LineItem() { Id = Guid.NewGuid(), ItemName = itemToAdd.ModifierItems[0].ItemName, ItemNumber = itemToAdd.ModifierItems[0].ItemNumber, Price = 0.00M, Quantity = 1, State = EntityState.Added, Guest = "1" });
// This is a sample Kit Item I made that i added some items to you just have to ring up the base item(test) and the kit items will add along with it automaticly
itemToAdd = InvApi.GetItem(InvContext, "test");
itemToAddID = Guid.NewGuid();
LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
inv.LineItems.Add(LineItemToAdd);
itemToAdd = InvApi.GetItem(InvContext, "test");
itemToAddID = Guid.NewGuid();
LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "2" };
inv.LineItems.Add(LineItemToAdd);
itemToAdd = InvApi.GetItem(InvContext, "DRINKCHOICE");
int j = 1;
Console.WriteLine(itemToAdd.ItemName2);
InventoryItem Choice;
foreach (String choiceItemNumber in itemToAdd.ChoiceItems)
{
Choice = InvApi.GetItem(InvContext, choiceItemNumber);
Console.WriteLine(string.Format("{0}: ", Choice.ItemName));
j++;
}
int choiceItemSelection = Convert.ToInt32(Console.ReadLine()) - 1;
itemToAdd = InvApi.GetItem(InvContext, itemToAdd.ChoiceItems[choiceItemSelection]);
itemToAddID = Guid.NewGuid();
LineItemToAdd = new LineItem() { Id = itemToAddID, ItemName = itemToAdd.ItemName, ItemNumber = itemToAdd.ItemNumber, Price = itemToAdd.Price, Quantity = 1, State = EntityState.Added, Guest = "1" };
inv.LineItems.Add(LineItemToAdd);
inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
Console.WriteLine(String.Format("ModifyItems new invoice value: {0}", inv.GrandTotal));
inv.LineItems[0].Quantity = 2;
inv.LineItems[0].State = EntityState.Modified;
inv = api.ModifyItems(context, inv.InvoiceNumber, inv.LineItems);
Console.WriteLine(String.Format("ModifyItems CHANGED 1st item QUANTITY, new invoice value: {0}", inv.GrandTotal));
// SendToKitchen
if (api.SendToKitchen(context, inv.InvoiceNumber))
Console.WriteLine("Invoice was printed in kitchen");
else
Console.WriteLine("***ERROR*** Invoice was NOT printed in kitchen");
// Splitcheck
inv = api.SplitInvoiceByGuest(context, inv.InvoiceNumber);
if (inv.SplitInfo.NumberOfSplitChecks == 2)
Console.WriteLine("Split invoice by guest");
else
Console.WriteLine("***ERROR*** Invoice could be split");
// ApplyCashPayment - applying grand total minus 1 dollar (NOTE SPLITS Starts counting at 0 not 1)
AppliedPaymentResponse payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 0, inv.SplitInfo.GrandTotalForSplit[0] - 1);
if (payResponse.Success)
Console.WriteLine(String.Format("Applied cash payment to split 1, change due {0}", payResponse.ChangeAmount));
else
Console.WriteLine("***ERROR*** Could not apply payment");
// ApplyCardPayment - applying remaining 1 dollar as a credit card
payResponse = api.ApplyCardPayment(context,
inv.InvoiceNumber,
0,
new pcAmerica.DesktopPOS.API.Client.SalesService.CreditCardPaymentProcessingResponse()
{
Amount = 1,
CardNumber = "4***********1",
ReferenceNumber = "123456",
Result = true,
TipAmount = 1,
TransactionNumber = 1234
}, -1);
if (payResponse.Success)
Console.WriteLine(String.Format("Applied card payment to split 1, change due {0}", payResponse.ChangeAmount));
else
Console.WriteLine("***ERROR*** Could not apply card payment");
payResponse = api.ApplyCashPayment(context, inv.InvoiceNumber, 1, inv.SplitInfo.GrandTotalForSplit[1] + 13);
if (payResponse.Success)
Console.WriteLine(String.Format("Applied cash payment to split 2, change due {0}", payResponse.ChangeAmount));
else
Console.WriteLine("***ERROR*** Could not apply payment");
// EndInvoice
if (api.EndInvoice(context, inv.InvoiceNumber))
Console.WriteLine("Ended invoice successfully");
else
Console.WriteLine("***ERROR*** Could not end invoice");
// looping and printing receipt for all splits
for (int i = 0; i < inv.SplitInfo.NumberOfSplitChecks; i++)
{
if (api.PrintReceipt(context, inv.InvoiceNumber, i))
Console.WriteLine("Receipt was printed");
else
Console.WriteLine("***ERROR*** Receive was NOT printed");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestCreditCard()
{
try
{
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest request = new pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardRequest();
request.Amount = 1.00M;
request.CardNumber = "4012888888881";
request.ExpirationMonth = 12;
request.ExpirationYear = 12;
PaymentAPI api = new PaymentAPI();
pcAmerica.DesktopPOS.API.Client.PaymentService.CreditCardPaymentProcessingResponse response = api.ProcessCreditCard(request);
Console.WriteLine(String.Format("Response: Result={0}, CardNumber={1}, Amount={2}, Reference={3}, TransactionNumber={4}", response.Result, response.CardNumber, response.Amount, response.ReferenceNumber, response.TransactionNumber));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestCustomers()
{
CustomerAPI api = new CustomerAPI();
try
{
string customerNumber = "abcd1234";
bool result = false;
Customer customer = api.FindRecord(customerNumber);
Console.WriteLine(String.Format("Customer {0} found = {1}", customerNumber, customer != null));
if (customer == null)
{
customer = new Customer();
customer.CustomerNumber = customerNumber;
customer.FirstName = "Test";
customer.LastName = "Tester";
result = api.UpdateRecord(MessageAction.CreateOrUpdate, customer);
Console.WriteLine(String.Format("Add/Update customer {0} result = {1}", customerNumber, result));
customer = api.FindRecord(customerNumber);
Console.WriteLine(String.Format("Customer {0} found = {1}", customerNumber, customer != null));
}
result = api.UpdateRecord(MessageAction.Delete, customer);
Console.WriteLine(String.Format("Delete customer {0} result = {1}", customer.CustomerNumber, result));
customer = api.FindRecord(customerNumber);
Console.WriteLine(String.Format("Customer {0} found = {1}", customerNumber, customer != null));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestEmployee()
{
EmployeeAPI api = new EmployeeAPI();
try
{
Employee employee = api.GetCurrentUser();
if (employee == null)
Console.WriteLine("No employee is currently logged into the POS application.");
else
Console.WriteLine(String.Format("Employee ID:{0} FirstName:{1} LastName:{2} AccessLevel:{3}", employee.CashierID, employee.FirstName, employee.LastName, employee.AccessLevel));
employee = api.AuthenticateEmployee("100101", "cashier");
if (employee == null)
Console.WriteLine("***ERROR*** Invalid username/password");
else
Console.WriteLine(String.Format("Authenticated employee: Employee ID:{0} FirstName:{1} LastName:{2} AccessLevel:{3}", employee.CashierID, employee.FirstName, employee.LastName, employee.AccessLevel));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestInventory()
{
InventoryAPI api = new InventoryAPI();
try
{
List<InventoryItem> items = api.GetItemList();
Console.WriteLine(String.Format("There are currently {0} items in the POS database.", items.Count));
pcAmerica.DesktopPOS.API.Client.InventoryService.Context context = new pcAmerica.DesktopPOS.API.Client.InventoryService.Context();
context.StoreID = "1001";
context.StationID = "01";
context.CashierID = "100101";
InventoryItem item = api.GetItem(context, "Non_Inventory");
if (item == null)
Console.WriteLine("***ERROR*** Could not retrieve Non_Inventory item");
else
Console.WriteLine("Retrieved Non_Inventory item");
Console.WriteLine(string.Format("The Non_Inventory item has Item Type of {0}", item.ItemType));
List<ModifierGroup> modGroups = api.GetModiferGroupsForItem(context, "Non_Inventory");
if (modGroups == null || modGroups.Count == 0)
Console.WriteLine("No modifier groups exist for the Non_Inventory item!");
else
Console.WriteLine(String.Format("Found {0} modifier groups for the Non_Inventory item!", modGroups.Count));
List<ModifierItem> modifiers = api.GetIndividualModifiers(context, "Non_Inventory");
if (modifiers == null || modifiers.Count == 0)
Console.WriteLine("No modifiers exist for the Non_Inventory item!");
else
Console.WriteLine(String.Format("Found {0} modifiers for the Non_Inventory item!", modifiers.Count));
if (item.KitItems == null || item.KitItems.Count == 0)
Console.WriteLine("The Non_Inventory has no Kit Items!");
else
Console.WriteLine(String.Format("Found {0} Kit Item(s) for the Non_Inventory item!", item.KitItems.Count));
InventoryItem kitTest = api.GetItem(context, "kit1");
if (kitTest.KitItems == null || kitTest.KitItems.Count == 0)
Console.WriteLine("kit1 has no Kit Items!");
else
Console.WriteLine(String.Format("Found {0} Kit Item(s) for kit1!", kitTest.KitItems.Count));
if (item.ChoiceItems == null || item.ChoiceItems.Count == 0)
Console.WriteLine("The Non_Inventory has no Choice Items!");
else
Console.WriteLine(String.Format("Found {0} Choice Item(s) for the Non_Inventory item!", item.ChoiceItems.Count));
InventoryItem choiceTest = api.GetItem(context, "Choice Item One");
if (choiceTest.ChoiceItems == null || choiceTest.ChoiceItems.Count == 0)
Console.WriteLine("Choice Item One has no Choice Items!");
else
Console.WriteLine(String.Format("Found {0} Choice Item(s) for Choice Item One!", choiceTest.ChoiceItems.Count));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("PRESS ENTER TO CONTINUE...");
Console.ReadLine();
}
}
static void TestSales()
{
try
{
SalesAPI api = new SalesAPI();
DateTime startDateTime = DateTime.Parse("1/1/2010");
DateTime endDateTime = DateTime.Parse("12/31/2010");
SalesTotals totals = api.GetTotals(startDateTime, endDateTime);
Console.WriteLine(
String.Format("Sales totals between {0}-{1} -- NetSales:{2} TotalTax:{3} GrandTotal:{4}",
startDateTime, endDateTime, totals.NetSales, totals.TotalTax, totals.GrandTotal));
List<ItemSale> sales = api.GetItemsSold(startDateTime, endDateTime);
Console.WriteLine(String.Format("Between {0}-{1}, there are {2} records of items being sold",
startDateTime, endDateTime, sales.Count));
pcAmerica.DesktopPOS.API.Client.SalesService.Context context =
new pcAmerica.DesktopPOS.API.Client.SalesService.Context();
context.CashierID = "100101";
context.StoreID = "1001";
context.StationID = "01";
// StartNewInvoice - this also automatically locks an invoice so it can't be opened by a terminal
Invoice inv = api.StartNewInvoice(context, "ROB" + DateTime.Now.Second.ToString(), "XXOPEN TABS");
Console.WriteLine(String.Format("Started new invoice with #: {0}", inv.InvoiceNumber));
// Unlock Invoice
if (api.UnLockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Unlocked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to unlock invoice # {0}", inv.InvoiceNumber));
// Lock Invoice
if (api.LockInvoice(context, inv.InvoiceNumber))
Console.WriteLine(String.Format("Locked invoice # {0}", inv.InvoiceNumber));
else
Console.WriteLine(String.Format("Failed to lock invoice # {0}", inv.InvoiceNumber));
// GetInvoiceHeader
inv = api.GetInvoiceHeader(context, inv.InvoiceNumber);
Console.WriteLine(String.Format("GetInvoiceHeader with #: {0}", inv.InvoiceNumber));
// GetInvoice
inv = api.GetInvoice(context, inv.InvoiceNumber);