-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBill.cpp
More file actions
1247 lines (1096 loc) · 30.9 KB
/
Bill.cpp
File metadata and controls
1247 lines (1096 loc) · 30.9 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
#include "Bill.h"
void dslk_Initialize(LIST_BILL &lb)
{
lb.pHead = lb.pTail = NULL;
}
NODE_BILL* dslk_CreateNodeBill(BILL data)
{
NODE_BILL *p = new NODE_BILL;
if (p == NULL)
return NULL;
p->data = data;
p->pNext = NULL;
return p;
}
void dslk_addHead(LIST_BILL &lb, NODE_BILL *itemAdd)
{
if (lb.pHead == NULL) // empty
{
lb.pHead = lb.pTail = itemAdd;
}
else
{
itemAdd->pNext = lb.pHead;
lb.pHead = itemAdd;
}
}
void dslk_addTail(LIST_BILL &lb, NODE_BILL *itemAdd)
{
if (lb.pHead == NULL) //Danh sách đang rỗng.
{
lb.pHead = lb.pTail = itemAdd; // item vừa là đầu vừa là cuối.
}
else
{
lb.pTail->pNext = itemAdd; //Cho pTail trỏ tới pNext tới item
lb.pTail = itemAdd; //Cập nhật lại pTail la item;
}
}
void dslk_addHead( NODE_BILL* &lb, NODE_BILL *itemAdd)
{
if (lb == NULL)
{
lb = itemAdd;
}
else
{
itemAdd->pNext = lb;
lb = itemAdd;
}
}
bool dslk_removeNode(LIST_BILL &lb, NODE_BILL *itemDelete)
{
if (lb.pHead == NULL)
{
return false;
}
else
{
for (NODE_BILL *p = lb.pHead; p->pNext != NULL; p = p->pNext)
{
if (strcmp(((p->pNext)->data).billNumber, itemDelete->data.billNumber) == 0)
{
NODE_BILL *temp = p->pNext;
p->pNext = (p->pNext)->pNext;
delete temp;
return true;
}
}
return false;
}
}
int dslk_Count(struct NODE_BILL* lb)
{
int count = 0;
for (NODE_BILL *p = lb; p != NULL; p = p->pNext)
{
count++;
}
return count;
}
string getCodeBill(LIST_BILL lb)
{
time_t rawtime = time(0);
struct tm now;
localtime_s(&now, &rawtime);
string text = "";
text += "CB";
// "CB"
if (now.tm_mday < 10)
{
text += "0";
text += to_string(now.tm_mday);
}
else
{
text += to_string(now.tm_mday);
}
if (now.tm_mon + 1 < 10)
{
text += "0";
text += to_string(now.tm_mon + 1);
}
else
{
text += to_string(now.tm_mon + 1);
}
text += to_string(now.tm_year + 1900);
// "CB.day.month.year"
//add code random
if (lb.pHead != NULL)
{
time_t rawtime = time(0);
struct tm now;
localtime_s(&now, &rawtime);
char *temp = _strdup(lb.pTail->data.billNumber);
char *cut = char_substr(temp, 10, 10);
int num = atoi(cut);
int sl = (int)log10(num) + 1;
num++;
int slnew = (int)log10(num) + 1;
if (slnew > sl)
{
for (int i = 0; i < 10 - (sl + 1); i++)
{
text += "0";
}
}
else
{
for (int i = 0; i < 10 - sl; i++)
{
text += "0";
}
}
text += to_string(num);
}
else
{
text += "0000000001"; // first
}
// "CB.day.month.year.0000000000"
return text;
}
string getDateNow()
{
time_t rawtime = time(0);
struct tm now;
localtime_s(&now, &rawtime);
string text = "";
if (now.tm_mday < 10)
{
text += "0";
text += to_string(now.tm_mday);
text += "/";
}
else
{
text += to_string(now.tm_mday);
text += "/";
}
if (now.tm_mon + 1 < 10)
{
text += "0";
text += to_string(now.tm_mon + 1);
text += "/";
}
else
{
text += to_string(now.tm_mon + 1);
text += "/";
}
text += to_string(1900 + now.tm_year);
return text;
}
char* getCodeEmployeesNow()
{
return "D16CQCN02";
}
void bill_SortUpByCode(LIST_BILL &lb)
{
for (NODE_BILL *p = lb.pHead; p != lb.pTail; p = p->pNext)
{
for (NODE_BILL *q = p->pNext; q != NULL; q = q->pNext)
{
if (atoi(char_substr(p->data.billNumber, 10, 10)) > atoi(char_substr(p->data.billNumber, 10, 10)))
{
BILL temp = q->data;
q->data = p->data;
p->data = temp;
}
}
}
}
double bill_CalMoney(NBD p)
{
double money = 0;
for (; p != NULL; p = p->pNext)
{
double moneyNoVAT = p->data.quantity * p->data.unitPrice;
double moneyVAT = moneyNoVAT * (0.1 * p->data.percentVAT / 100);
money += (moneyNoVAT + moneyVAT);
}
return money;
}
int bill_GetQuantity(LIST_BILL lb)
{
int count = 0;
for (NODE_BILL *p = lb.pHead; p !=NULL; p = p->pNext )
{
count++;
}
return count;
}
void bill_initProperties(LIST_PROPERTIES &prop, LIST_BILL lb)
{
PROPERTIES p;
strcpy_s(p.variables.data, getCodeBill(lb).c_str());
strcpy_s(p.variables.name, "Ma Hoa Don");
strcpy_s(p.variables.notify, "Format: Random");
p.maxLength = bill_maxSize_Code;
p.variables.color = ColorCode_DarkWhite;
p.mode.enable = false;
p.mode.modeImport = UPPER_NUMBER;
List_InsertItem(prop, prop.size, p);
strcpy_s(p.variables.data, "");
strcpy_s(p.variables.name, "Ma Nhan Vien Lap");
strcpy_s(p.variables.notify, "A-Z, 0-9");
p.variables.color = ColorCode_DarkWhite;
p.maxLength = employees_maxSize_Code;
p.mode.enable = true;
p.mode.modeImport = UPPER_NUMBER;
List_InsertItem(prop, prop.size, p);
strcpy_s(p.variables.data, getDateNow().c_str());
strcpy_s(p.variables.name, "Ngay Lap Hoa Don");
strcpy_s(p.variables.notify, "Auto Update");
p.maxLength = bill_maxSize_invoiceDate;
p.variables.color = ColorCode_DarkWhite;
p.mode.enable = false;
p.mode.modeImport = UPPER_NUMBER;
List_InsertItem(prop, prop.size, p);
strcpy_s(p.variables.data, "");
strcpy_s(p.variables.name, "Loai Hoa Don");
strcpy_s(p.variables.notify, "Format: (N : Nhap, X : Xuat)");
p.variables.color = ColorCode_DarkWhite;
p.maxLength = 1;
p.mode.enable = true;
p.mode.modeImport = TYPEBILL;
List_InsertItem(prop, prop.size, p);
}
void bill_buildBill(LIST_BILL &lb, struct LIST_EMPLOYEES &le, LIST_MATERIAL &lm)
{
LOCATION lc; lc.x = lc.y = 5;
LIST_PROPERTIES prop;
LIST_ARRAY_CHAR arrData;;
while (true)
{
bill_initProperties(prop, lb);
while (true)
{
enterDataToVariable(arrData, prop, lc);
if (strcmp(arrData.listSTR[arrData.size - 1].str, "CANCEL") == 0)
{
break;
}
else
{
if (employees_search(le, arrData.listSTR[1].str) == -1)
{
strcpy_s(prop.lprop[1].variables.data, "");
strcpy_s(prop.lprop[1].variables.notify, "Employees not exist");
prop.lprop[1].variables.color = ColorCode_Red;
}
else
{
break;
}
}
}
if (strcmp(arrData.listSTR[arrData.size - 1].str, "CANCEL") == 0)
{
system("cls");
messagebox("Ban da huy qua trinh lap hoa don", YES, lc);
return;
}
else
{
NBD listBD;
dslk_InitBD(listBD);
char *type = arrData.listSTR[arrData.size - 2].str;
bool isContinue = true;
while (isContinue)
{
bd_Add(listBD, lm, type[0]);
if (listBD == NULL)
{
system("cls");
isContinue = messagebox("Danh sach chi tiet hoa don trong. Ban co muon nhap lai khong?", YES_NO, LOCATION(LOCATION()));
if (!isContinue)
return;
system("cls");
}
else
{
break;
}
}
if (listBD != NULL)
{
//Copy data
BILL item;
strcpy_s(item.billNumber, arrData.listSTR[0].str);
strcpy_s(item.employeesCode, arrData.listSTR[1].str);
strcpy_s(item.invoiceDate, arrData.listSTR[2].str);
item.type = type[0];
item.list_BillDetail = listBD;
// add to list Bill;
dslk_addTail(lb, dslk_CreateNodeBill(item));
// add to list bill of employees
employees_InsertListBill(le, arrData.listSTR[1].str, dslk_CreateNodeBill(item));
system("cls");
if (!messagebox("Ban da tao hoa don thanh cong. Ban co muon tao hoa don tiep khong?", YES_NO, lc))
{
List_Clear(prop);
List_Clear(arrData);
system("cls");
return;
}
}
}
system("cls");
List_Reset(prop);
List_Reset(arrData);
}
}
void bill_InitTiTle(LIST_TITLE &title)
{
TITLE t;
strcpy_s(t.data, "Ma Hoa Don");
int size = strlen(t.data);
t.width = (size > bill_maxSize_Code ? size : bill_maxSize_Code) + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Ma Nhan Vien");
size = strlen(t.data);
t.width = (size > employees_maxSize_Code ? size : employees_maxSize_Code) + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Ngay Lap");
size = strlen(t.data);
t.width = (size > bill_maxSize_invoiceDate ? size : bill_maxSize_invoiceDate) + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Loai");
size = strlen(t.data);
t.width = (size > 1 ? size : 1) + 4;
List_InsertItem(title, title.size, t);
}
void bill_ViewDetail(LIST_BILL lb, LIST_MATERIAL lm, char *code, LOCATION lcDisPlay, Size &size)
{
bool isExist = false;
NODE_BILL *p;
for (p = lb.pHead; p != NULL; p = p->pNext)
{
if (strcmp(p->data.billNumber, code) == 0)
{
isExist = true;
break;
}
}
if (isExist)
{
int bottom = 0;
bd_Show(p->data.list_BillDetail, lm, lcDisPlay, bottom, 0);
}
}
STR dis_chooseViewDetail( LIST_BILL lb, NBD bd, LIST_EMPLOYEES le,LOCATION lcDis, int widthGird, LIST_ARRAY_CHAR notify, int modeMore)
{
//return DONE => SUCCESS
//return code => do something with code
STR codeCheck;
LIST_TITLE listTitle;
LOCATION lcGird, lcDisplay, lcGetCode;
LOCATION lcBtnDone, lcBtnView, lcTxtCode;
Size sBtnDone, sBtnView, sTxtCode;
lcGird = { lcDis.x, lcDis.y };
lcBtnDone = { lcGird.x + 3, lcGird.y + 3};
sBtnDone = { static_cast<int>(strlen("XONG") + 4), 5 };
lcTxtCode = { lcBtnDone.x + sBtnDone.width + 15, lcGird.y + 3 };
if (lb.pHead != NULL)
{
sTxtCode = { bill_maxSize_Code + 4 , 5 };
}
else if (bd != NULL)
{
sTxtCode = { material_maxSize_Code + 4 , 5 };
}
else
{
sTxtCode = { material_maxSize_Code + 4 , 5 };
}
lcBtnView = { lcTxtCode.x + sTxtCode.width + 2, lcGird.y + 3 };
sBtnView = { static_cast<int>(strlen("XEM") + 4), 5 };
lcDisplay = { lcGird.x + 3, lcBtnDone.y + sBtnDone.height + 4 };
if (modeMore == 1)
{
button(false, "XEM", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
else if (modeMore == 0)
{
button(false, "XOA", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
button(true, "XONG", lcBtnDone, sBtnDone, ColorCode_Blue, ColorCode_Black);
drawRectangle(lcGetCode, lcTxtCode, sTxtCode, ColorCode_DarkWhite, ColorCode_DarkWhite);
gotoxy(lcGetCode.x - 11, lcGetCode.y); std::cout << notify.listSTR[0].str;
gotoxy(lcGetCode.x, lcGetCode.y - 2); ColorText(notify.listSTR[1].str, ColorCode_DarkWhite);
//margin = { (lcBtnView.x + sBtnView.width + 3) - lcGird.x , lcBtnDone.x + sBtnDone.height + 1 };
int index = 0;
char code[30] = {'\0'};
bool isControl = false;
while (true)
{
if (_kbhit())
{
char key = _getch();
if ((key >= '0' && key <= '9' || key >= 'a' && key <= 'z' || key >= 'A' && key <= 'Z') && !isControl)
{
//cout << "not is control" << endl;
if (index == 1)
{
//codeDel = strdup(dataEntry("", ))
}
}
else if (key == -32)
{
isControl = true;
}
else if (isControl)
{
if (key == 80)
{
//cout << "DOWN";
}
else if (key == 72)
{
//cout << "UP";
}
else if (key == 75)
{
//cout << "LEFT";
index--;
if (index < 0)
{
index = 2;
button(false, "XONG", lcBtnDone, sBtnDone, ColorCode_Blue, ColorCode_Black);
if (modeMore == 1)
{
button(true, "XEM", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
else if (modeMore == 0)
{
button(true, "XOA", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
}
else if (index == 1) // focus txt
{
if (modeMore == 1)
{
button(false, "XEM", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
else if (modeMore == 0)
{
button(false, "XOA", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
drawRectangle(lcGetCode, lcTxtCode, sTxtCode, ColorCode_DarkWhite, ColorCode_Blue);
if (lb.pHead != NULL)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, bill_maxSize_Code));
}
else if (le.size != 0)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, employees_maxSize_Code));
}
else if (bd != NULL)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, material_maxSize_Code));
}
}
else if (index == 0)
{
drawRectangle(lcGetCode, lcTxtCode, sTxtCode, ColorCode_DarkWhite, ColorCode_Blue);
button(true, "XONG", lcBtnDone, sBtnDone, ColorCode_Blue, ColorCode_Black);
}
}
else if (key == 77)
{
//cout << "RIGHT";
index++;
if (index > 2)
{
index = 0;
button(true, "XONG", lcBtnDone, sBtnDone, ColorCode_Blue, ColorCode_Black);
if (modeMore == 1)
{
button(false, "XEM", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
else if (modeMore == 0)
{
button(false, "XOA", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
}
else if (index == 2)
{
if (modeMore == 1)
{
button(true, "XEM", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
else if (modeMore == 0)
{
button(true, "XOA", lcBtnView, sBtnView, ColorCode_Blue, ColorCode_Black);
}
drawRectangle(lcGetCode, lcTxtCode, sTxtCode, ColorCode_DarkWhite, ColorCode_DarkWhite);
}
else if (index == 1)
{
button(false, "XONG", lcBtnDone, sBtnDone, ColorCode_Blue, ColorCode_Black);
drawRectangle(lcGetCode, lcTxtCode, sTxtCode, ColorCode_DarkWhite, ColorCode_Blue);
if (lb.pHead != NULL)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, bill_maxSize_Code));
}
else if (le.size != 0)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, employees_maxSize_Code));
}
else if (bd != NULL)
{
strcpy_s(code, dataEntry(code, lcGetCode, UPPER_NUMBER, material_maxSize_Code));
}
}
}
isControl = false;
}
else
{
if (key == 8) // backSpace
{
}
if (key == 13)
{
if (index == 0)
{
strcpy_s(codeCheck.str, "DONE");
return codeCheck;
}
else if (index == 2)
{
// check code bill
if (lb.pHead != NULL)
{
for (NODE_BILL *p = lb.pHead; p != NULL; p = p->pNext)
{
if (strcmp(p->data.billNumber, code) == 0)
{
strcpy_s(codeCheck.str, p->data.billNumber);
return codeCheck;
}
}
}
else if (bd != NULL)
{
for (NBD bd_run = bd; bd_run != NULL; bd_run = bd_run->pNext)
{
if (strcmp(bd_run->data.materialsCode, code) == 0)
{
strcpy_s(codeCheck.str, bd_run->data.materialsCode);
return codeCheck;
}
}
}
else if (le.size != 0)
{
for (int run = 0; run < le.size; run++)
{
if (strcmp(le.arr[run].employeesCode, code) == 0)
{
strcpy_s(codeCheck.str, le.arr[run].employeesCode);
return codeCheck;
}
}
}
//check code material
//not exist
LOCATION lcWait;
lcWait = { static_cast<int>(lcGird.x + ((widthGird / 2) - (strlen(notify.listSTR[2].str) / 2))), lcBtnDone.y + sBtnDone.height};
dis_wait(lcWait, notify.listSTR[2].str, 3, ColorCode_Red);
}
}
}
}
}
}
void bill_Show(LIST_BILL lb, LIST_MATERIAL lm, LOCATION lcShow)
{
LIST_LOCATION listLcResult;
LIST_TITLE listTitle;
LOCATION lcDisplay, lcChoose, lcGird;
LIST_ARRAY_CHAR notify;
Size sizeGird;
Size sClearView = { 0, 0 };
LOCATION bottom;
STR codeBill;
strcpy_s(codeBill.str, "");
int quantity = bill_GetQuantity(lb);
List_InsertItem(notify, notify.size, "Code Bill");
List_InsertItem(notify, notify.size, "Format: 0-9, A-Z");
List_InsertItem(notify, notify.size, "Ma hoa don khong ton tai.");
lcGird = lcShow;
lcChoose = { lcGird.x, lcGird.y};
lcDisplay = { lcGird.x + 3, lcGird.y + 10 };
bill_InitTiTle(listTitle);
drawBorder(listLcResult, lcDisplay, quantity, 5, listTitle);
if (listLcResult.size > 0)
{
bottom = { listLcResult.lloca[listLcResult.size - 1].x + listTitle.ltitle[3].width, listLcResult.lloca[listLcResult.size - 1].y + 4 };
}
else
{
bottom = { 67, lcDisplay.y + 7 };
}
if (lb.pHead == NULL)
{
sizeGird = { 64, 18 };
}
else
{
sizeGird = { bottom.x - lcGird.x , bottom.y - lcGird.y };
}
drawBox(lcGird, sizeGird, "Hoa Don");
int count = 0;
for (NODE_BILL *p = lb.pHead; p != NULL; p = p->pNext)
{
int indexNow = count * bill_quantityFields;
gotoxy(listLcResult.lloca[indexNow].x, listLcResult.lloca[indexNow].y); BGColorText(p->data.billNumber, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLcResult.lloca[indexNow + 1].x, listLcResult.lloca[indexNow + 1].y); BGColorText(p->data.employeesCode, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLcResult.lloca[indexNow + 2].x, listLcResult.lloca[indexNow + 2].y); BGColorText(p->data.invoiceDate, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(listLcResult.lloca[indexNow + 3].x, listLcResult.lloca[indexNow + 3].y); BGColorText((to_string(p->data.type)).c_str(), ColorCode_Black, ColorCode_DarkWhite);
count++;
}
//action
while (true)
{
STR codeBill;
NBD bd = NULL;
LIST_EMPLOYEES le;
codeBill = dis_chooseViewDetail(lb, bd, le, lcChoose, sizeGird.width, notify, 1);
if (strcmp(codeBill.str, "DONE") == 0)
{
break;
}
else
{
//view detail
LOCATION lcView;
lcView = { lcGird.x + sizeGird.width + 2 , lcGird.y };
bill_ViewDetail(lb, lm, codeBill.str, lcView, sClearView);
}
}
}
#pragma region Show Bill by Date
void bill_EntryDate(LIST_ARRAY_CHAR &data)
{
LIST_LOCATION lLocationGet;
LIST_ARRAY_CHAR fields;
LOCATION lcTemp;
List_InsertItem(fields, fields.size, "Tu Ngay");
List_InsertItem(fields, fields.size, "Den Ngay");
Size sBox = { 9, 3 };
Size sButton = {8, 5};
dis_drawEntryDate(lLocationGet, fields);
//init data
for (int i = 0; i < lLocationGet.size - 2; i++)
{
List_InsertItem(data, data.size, "");
}
int index = 0;
//focus box 1;
lcTemp = { lLocationGet.lloca[index].x - 2, lLocationGet.lloca[index].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 2));
bool isCancle = false;
bool isControl = false;
while (true)
{
if (_kbhit())
{
char key = _getch();
if ((key >= '0' && key <= '9' || key >= 'a' && key <= 'z' || key >= 'A' && key <= 'Z') && !isControl)
{
//cout << "not is control" << endl;
/*if (index != lLocationGet.size - 1 || index != lLocationGet.size - 2)
{
if (index == 2 || index == 5)
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 4));
}
else
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 2));
}
}*/
}
else if (key == -32)
{
isControl = true;
}
else if (isControl)
{
if (key == 80)
{
//cout << "DOWN";
}
else if (key == 72)
{
//cout << "UP";
}
else if (key == 75)
{
//cout << "LEFT";
index--;
if (index < 0)
{
lcTemp = { lLocationGet.lloca[0].x - 2, lLocationGet.lloca[0].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[0].str;
index = lLocationGet.size - 1;
button(true, "HUY.", lLocationGet.lloca[index], sButton, ColorCode_Blue, ColorCode_Black);
}
else if (index == lLocationGet.size - 2)
{
button(false, "HUY.", lLocationGet.lloca[index + 1], sButton, ColorCode_Blue, ColorCode_Black);
button(true, "XONG", lLocationGet.lloca[index], sButton, ColorCode_Blue, ColorCode_Black);
}
else if (index == lLocationGet.size - 3)
{
button(false, "XONG", lLocationGet.lloca[index + 1], sButton, ColorCode_Blue, ColorCode_Black);
lcTemp = { lLocationGet.lloca[index].x - 2, lLocationGet.lloca[index].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 4));
}
else
{
lcTemp = { lLocationGet.lloca[index + 1].x - 2, lLocationGet.lloca[index + 1].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[index + 1].str;
//focus
lcTemp = { lLocationGet.lloca[index].x - 2, lLocationGet.lloca[index].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[index].str;
if (index == 2 || index == 5)
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 4));
}
else
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 2));
}
}
}
else if (key == 77)
{
//cout << "RIGHT";
index++;
if (index >= lLocationGet.size)
{
button(false, "HUY.", lLocationGet.lloca[lLocationGet.size - 1], sButton, ColorCode_Blue, ColorCode_Black);
index = 0;
lcTemp = { lLocationGet.lloca[index].x - 2, lLocationGet.lloca[index].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[index].str;
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 2));
}
else if (index == lLocationGet.size - 1)
{
button(true, "HUY.", lLocationGet.lloca[index], sButton, ColorCode_Blue, ColorCode_Black);
button(false, "XONG", lLocationGet.lloca[index - 1], sButton, ColorCode_Blue, ColorCode_Black);
}
else if (index == lLocationGet.size - 2)
{
lcTemp = { lLocationGet.lloca[index - 1].x - 2, lLocationGet.lloca[index - 1].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[index - 1].str;
button(true, "XONG", lLocationGet.lloca[index], sButton, ColorCode_Blue, ColorCode_Black);
}
else
{
lcTemp = { lLocationGet.lloca[index - 1].x - 2, lLocationGet.lloca[index - 1].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_DarkWhite);
gotoxy(lcTemp.x, lcTemp.y); std::cout << data.listSTR[index - 1].str;
lcTemp = { lLocationGet.lloca[index].x - 2, lLocationGet.lloca[index].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
if (index == 2 || index == 5)
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 4));
}
else
{
strcpy_s(data.listSTR[index].str, dataEntry(data.listSTR[index].str, lLocationGet.lloca[index], NUMBER, 2));
}
}
}
isControl = false;
}
else
{
if (key == 13) // press enter
{
if (index == lLocationGet.size - 2)//OK
{
for (int i = 0; i < data.size; i++)
{
if (strlen(data.listSTR[i].str) == 0)
{
lcTemp = { lLocationGet.lloca[i].x - 2, lLocationGet.lloca[i].y - 1 };
drawRectangle(lcTemp, lcTemp, sBox, ColorCode_Black, ColorCode_Blue);
if (i == 2 || i == 5)
{
strcpy_s(data.listSTR[i].str, dataEntry(data.listSTR[i].str, lLocationGet.lloca[i], NUMBER, 4));
}
else
{
strcpy_s(data.listSTR[i].str, dataEntry(data.listSTR[i].str, lLocationGet.lloca[i], NUMBER, 2));
}
}
}
if (!conf_checkDATE(data)) // error
{
LOCATION lcDis = { (bill_Location_Gird_x + (75 / 2) - (static_cast<int>(strlen("Dinh Dang Khong Hop Le. Vui Long Nhap Lai!")) / 2)), bill_Location_Gird_y + 1 };
dis_wait(lcDis, "Dinh Dang Khong Hop Le. Vui Long Nhap Lai!", 3, ColorCode_Red);
}
else
{
break;
}
}
else if (index == lLocationGet.size - 1)
{
isCancle = true;
break;
}
}
}
}
}
List_Clear(fields);
List_Clear(lLocationGet);
if (isCancle)
{
List_InsertItem(data, data.size, "CANCEL");
}
else
{
List_InsertItem(data, data.size, "DONE");
}
}
void bill_InitTitleShowByDay(LIST_TITLE &title)
{
TITLE t;
strcpy_s(t.data, "Ma Hoa Don");
t.width = bill_maxSize_Code + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Ngay lap hoa Don");
int size = strlen(t.data);
t.width = size > bill_maxSize_invoiceDate ? size + 4 : bill_maxSize_invoiceDate + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Loai");
size = strlen("Nhap");
t.width = size > bill_maxSize_invoiceDate ? size + 4 : bill_maxSize_invoiceDate + 4;
List_InsertItem(title, title.size, t);
strcpy_s(t.data, "Ho & Ten");
size = strlen(t.data);
t.width = size > (employees_maxSize_FirstName + employees_maxSize_FirstName) ? size + 4 : (employees_maxSize_FirstName + employees_maxSize_FirstName) + 4;
List_InsertItem(title, title.size, t);