PRICETAB.MOD 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. IMPLEMENTATION MODULE PriceTable;
  2. (*
  3. * ModBase
  4. * Release 3.0
  5. * (c) Copyright 1986 - 1991 PMI
  6. * P.O. Box 8402
  7. * Green Bay Wi 53308
  8. * All Rights Reserved
  9. * by Ed Ross
  10. *)
  11. FROM NumTypes IMPORT Real8;
  12. FROM Numbers IMPORT Max;
  13. FROM Hash IMPORT HashTable,Define,Dispose,Insert,GetData,KeyFind;
  14. FROM StrConv IMPORT RealToStr,CardinalToStr;
  15. FROM ScrnUtl1 IMPORT GetFieldImageRec;
  16. FROM Tables IMPORT Table,CellValue,GetCell,PutCell,BuildTable,
  17. DefineTextCol,DefineIntegerCol,DefineRealCol,DefineTable,ControlTable,
  18. DeleteTable,ShowTable,NumberOfRows;
  19. FROM GenLists IMPORT GenList,ListLength,GetElmtAdr,BlockToList,
  20. GetElmt, ListInsertAdr,NewList,DisposeList,ListInsert,ShellSortList;
  21. FROM StringIO IMPORT ErrorMessage,NoError,WriteEol,WriteStr,outp;
  22. FROM PosUtils IMPORT Equal,Present,Pos;
  23. FROM Prompts IMPORT PromptStr,PromptYN;
  24. FROM M2Strings IMPORT Length,CompareStr,Assign;
  25. FROM StrEdit IMPORT CAPstr,CrunchBlanks,Append,SetLength,AssignStr,LowerStr,
  26. DeleteRightJustified,CAPstr;
  27. FROM ControlUtils IMPORT AddMenuItem,ChangeField,ReadInput,Control;
  28. FROM FramePainter IMPORT ShowDisplayFrame;
  29. FROM InputManager IMPORT ControlFrame;
  30. FROM ScrnTypes IMPORT InitDisplayFrame,DisplayFrame,AFrameName,ImageElement;
  31. FROM ScrnUtl2 IMPORT CloseDisplayFrame;
  32. FROM LowLevel IMPORT Fill;
  33. FROM SYSTEM IMPORT TSIZE,ADR,ADDRESS;
  34. IMPORT VWindows;
  35. FROM VStorage IMPORT DosAlloc,DosDealloc;
  36. IMPORT InitCompilerMods;
  37. FROM HandleIO IMPORT FileExists, OpenFile,CreateFile,CloseHandle,
  38. BlockRead,BlockWrite;
  39. TYPE
  40. PriceTblItem = RECORD
  41. Quantity : ARRAY[1..4] OF CARDINAL;
  42. Price : ARRAY[1 ..4] OF Real8;
  43. Desc : ARRAY[0..30] OF CHAR;
  44. END;
  45. VAR
  46. DF : DisplayFrame;
  47. Tab : Table;
  48. Initialized : BOOLEAN;
  49. SerList : GenList;
  50. FileName : ARRAY[0..20] OF CHAR;
  51. Card : CARDINAL;
  52. EM : ErrorMessage;
  53. Code,J : CARDINAL;
  54. Bool : BOOLEAN;
  55. PriceTbl : POINTER TO ARRAY[0..26] OF PriceTblItem;
  56. GroupCnt : POINTER TO ARRAY[1..20] OF CARDINAL;
  57. NxtGrp : CARDINAL; (* next assigned index into array *)
  58. GrpTab : HashTable;
  59. (* pricing is done on a sliding scale depending on the number of items
  60. purchased. The item count is summed on the group level not the
  61. SKU level at the inventory level *)
  62. PROCEDURE ClearGrpCnt();
  63. (* this procedure will clear out the group count table for a
  64. recompute *)
  65. BEGIN
  66. Fill(GroupCnt,SIZE(GroupCnt^),0);
  67. END ClearGrpCnt;
  68. PROCEDURE GrpTotal(Grp : ARRAY OF CHAR) : CARDINAL;
  69. VAR
  70. Index : CARDINAL;
  71. BEGIN
  72. IF KeyFind(GrpTab,Grp)
  73. THEN
  74. GetData(GrpTab,Index);
  75. RETURN GroupCnt^[Index];
  76. ELSE
  77. RETURN 0;
  78. END;
  79. END GrpTotal;
  80. PROCEDURE AddGrp(Grp : ARRAY OF CHAR; AddAmt : CARDINAL);
  81. VAR Index : CARDINAL;
  82. BEGIN
  83. IF KeyFind(GrpTab,Grp)
  84. THEN
  85. GetData(GrpTab,Index);
  86. GroupCnt^[Index] := GroupCnt^[Index] + AddAmt;
  87. ELSE
  88. Insert(GrpTab,Grp,NxtGrp);
  89. GroupCnt^[NxtGrp] := AddAmt;
  90. INC(NxtGrp);
  91. END;
  92. END AddGrp;
  93. PROCEDURE InitGrp();
  94. BEGIN
  95. NxtGrp := 1;
  96. Define(GrpTab,100,2);
  97. DosAlloc(GroupCnt,SIZE(GroupCnt^));
  98. ClearGrpCnt();
  99. END InitGrp;
  100. (* Table should look like this
  101. 1234567890123456789012345678901234567890123456789012345678901234567890123456
  102. 1 2 3 4 5 6 7
  103. Nbr Min 1 Price 1 Min 2 Price 2 Min 3 Price 3 Min 4 Price 4 Desc
  104. xx xxxxx xxxx.xx xxxxx xxxx.xx xxxxx xxxx.xx xxxxx xxxx.xx xxxxxxxxxxxxxxxxxxxxxx
  105. *)
  106. PROCEDURE SetupTable();
  107. BEGIN
  108. DefineTable(Tab,'Price Table');
  109. DefineTextCol(Tab,3,2,'Nbr',TRUE);
  110. DefineIntegerCol(Tab,7,6,'Min 1',0,9999);
  111. DefineRealCol(Tab,14,8,'Price 1',0.0,9999.99);
  112. DefineIntegerCol(Tab,23,6,'Min 2',0,99999);
  113. DefineRealCol(Tab,30,8,'Price 2',0.0,9999.99);
  114. DefineIntegerCol(Tab,39,6,'Min 3',0,99999);
  115. DefineRealCol(Tab,46,8,'Price 3',0.0,9999.99);
  116. DefineIntegerCol(Tab,55,6,'Min 4',0,99999);
  117. DefineRealCol(Tab,62,8,'Price 4',0.0,9999.99);
  118. DefineTextCol(Tab,71,20,'Desc',FALSE);
  119. END SetupTable;
  120. PROCEDURE GetPriceTbl();
  121. (* return a list of all products *)
  122. VAR
  123. H : CARDINAL;
  124. EM : ErrorMessage;
  125. Size : CARDINAL;
  126. J : CARDINAL;
  127. BEGIN
  128. J := SIZE(PriceTbl^);
  129. DosAlloc(PriceTbl,SIZE(PriceTbl^));
  130. IF FileExists('Price.tbl')
  131. THEN
  132. EM := OpenFile(H,'Price.Tbl');
  133. EM := BlockRead(H,PriceTbl,SIZE(PriceTbl^));
  134. EM := CloseHandle(H);
  135. ELSE
  136. Fill(PriceTbl,SIZE(PriceTbl^),0);
  137. END;
  138. END GetPriceTbl;
  139. PROCEDURE DefinePriceTbl();
  140. VAR
  141. H : CARDINAL;
  142. EM : CARDINAL;
  143. J : CARDINAL;
  144. Cell : CellValue;
  145. Row : CARDINAL;
  146. Str : ARRAY [0..5] OF CHAR;
  147. Nbr : ARRAY[0..4] OF CHAR;
  148. Size,Code : CARDINAL;
  149. BEGIN
  150. IF NOT Initialized
  151. THEN
  152. InitGrp();
  153. GetPriceTbl();
  154. Initialized := TRUE;
  155. END;
  156. WriteEol(outp,'..This may take a few minutes .. standby..');
  157. SetupTable();
  158. BuildTable(Tab,26); (* increase table size by *)
  159. FOR Row := 1 TO 25 DO
  160. CardinalToStr(Row,3,Nbr);
  161. Assign( Nbr,Cell.Str);
  162. PutCell(Tab,1,Row,Cell); (* indexed *)
  163. Cell.I := PriceTbl^[Row].Quantity[1]; (* min 1 *)
  164. PutCell(Tab,2,Row,Cell);
  165. Cell.R := PriceTbl^[Row].Price[1]; (* min price *)
  166. PutCell(Tab,3,Row,Cell);
  167. Cell.I := PriceTbl^[Row].Quantity[2]; (* min 2 *)
  168. PutCell(Tab,4,Row,Cell);
  169. Cell.R := PriceTbl^[Row].Price[2]; (* min price *)
  170. PutCell(Tab,5,Row,Cell);
  171. Cell.I := PriceTbl^[Row].Quantity[3]; (* min 3 *)
  172. PutCell(Tab,6,Row,Cell);
  173. Cell.R := PriceTbl^[Row].Price[3]; (* min price *)
  174. PutCell(Tab,7,Row,Cell);
  175. Cell.I := PriceTbl^[Row].Quantity[4]; (* min 3 *)
  176. PutCell(Tab,8,Row,Cell);
  177. Cell.R := PriceTbl^[Row].Price[4]; (* min price *)
  178. PutCell(Tab,9,Row,Cell);
  179. Assign(PriceTbl^[Row].Desc,Cell.Str);
  180. PutCell(Tab,10,Row,Cell);
  181. END;
  182. ControlTable(Tab,2,5,79,20);
  183. (* now read the table in and save values *)
  184. FOR Row := 1 TO 25 DO
  185. GetCell(Tab,2,Row,Cell);
  186. PriceTbl^[Row].Quantity[1] := Cell.I;
  187. GetCell(Tab,3,Row,Cell);
  188. PriceTbl^[Row].Price[1] := Cell.R;
  189. GetCell(Tab,4,Row,Cell);
  190. PriceTbl^[Row].Quantity[2] := Cell.I;
  191. GetCell(Tab,5,Row,Cell);
  192. PriceTbl^[Row].Price[2] := Cell.R;
  193. GetCell(Tab,6,Row,Cell);
  194. PriceTbl^[Row].Quantity[3] := Cell.I;
  195. GetCell(Tab,7,Row,Cell);
  196. PriceTbl^[Row].Price[3] := Cell.R;
  197. GetCell(Tab,8,Row,Cell);
  198. PriceTbl^[Row].Quantity[4] := Cell.I;
  199. GetCell(Tab,9,Row,Cell);
  200. PriceTbl^[Row].Price[4] := Cell.R;
  201. GetCell(Tab,10,Row,Cell);
  202. Assign( Cell.Str,PriceTbl^[Row].Desc);
  203. END;
  204. (* now save the price table in the file *)
  205. DeleteTable(Tab);
  206. IF NOT FileExists('Price.Tbl')
  207. THEN EM := CreateFile(H,'Price.tbl');
  208. ELSE EM := OpenFile(H,'Price.tbl');
  209. END;
  210. EM := BlockWrite(H,PriceTbl,SIZE(PriceTbl^));
  211. EM := CloseHandle(H);
  212. END DefinePriceTbl;
  213. PROCEDURE GetPrice(Line : CARDINAL; Quantity : CARDINAL;
  214. StartAtLvl : CARDINAL) : Real8;
  215. VAR
  216. ItemCnt : CARDINAL;
  217. BEGIN
  218. IF NOT Initialized
  219. THEN
  220. GetPriceTbl();
  221. Initialized := TRUE;
  222. END;
  223. IF ((Line = 0 ) OR (Line > 25))
  224. THEN RETURN 0.0
  225. END;
  226. IF StartAtLvl < 1
  227. THEN
  228. StartAtLvl := 1;
  229. END;
  230. IF StartAtLvl > 4
  231. THEN
  232. StartAtLvl := 4;
  233. END;
  234. (* get either the actual count or the count for the quantity specified*)
  235. ItemCnt := Max(Quantity,PriceTbl^[Line].Quantity[StartAtLvl]);
  236. IF ItemCnt < PriceTbl^[Line].Quantity[2]
  237. THEN RETURN PriceTbl^[Line].Price[1]
  238. ELSIF ItemCnt < PriceTbl^[Line].Quantity[3]
  239. THEN RETURN PriceTbl^[Line].Price[2]
  240. ELSIF ItemCnt < PriceTbl^[Line].Quantity[4]
  241. THEN RETURN PriceTbl^[Line].Price[3]
  242. ELSE RETURN PriceTbl^[Line].Price[4];
  243. END;
  244. END GetPrice;
  245. PROCEDURE GetPriceTable(TblNbr : CARDINAL;
  246. VAR Q1,Q2,Q3,Q4 : CARDINAL;
  247. VAR P1,P2,P3,P4 : Real8);
  248. (* return the price table for a line
  249. so the invoice routine can display *)
  250. BEGIN
  251. IF (TblNbr = 0) OR (TblNbr > 25)
  252. THEN
  253. P1 := 0.0;
  254. P2 := 0.0;
  255. P3 := 0.0;
  256. P4 := 0.0;
  257. Q1 := 0;
  258. Q2 := 0;
  259. Q3 := 0;
  260. Q4 := 0;
  261. RETURN;
  262. END;
  263. Q1 := PriceTbl^[TblNbr].Quantity[1];
  264. Q2 := PriceTbl^[TblNbr].Quantity[2];
  265. Q3 := PriceTbl^[TblNbr].Quantity[3];
  266. Q4 := PriceTbl^[TblNbr].Quantity[4];
  267. P1 := PriceTbl^[TblNbr].Price[1];
  268. P2 := PriceTbl^[TblNbr].Price[2];
  269. P3 := PriceTbl^[TblNbr].Price[3];
  270. P4 := PriceTbl^[TblNbr].Price[4];
  271. END GetPriceTable;
  272. PROCEDURE InitializePrice();
  273. BEGIN
  274. GetPriceTbl();
  275. InitGrp();
  276. Initialized := TRUE;
  277. END InitializePrice;
  278. BEGIN
  279. Initialized := FALSE;
  280. END PriceTable.
  281.