INVTRY.MOD 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. IMPLEMENTATION MODULE Invtry;
  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 ModBase3 IMPORT UpdateDBFile,WriteDBRec,DeleteRecord,ReadDBRec,
  12. AppendBlank;
  13. FROM DBIndxes IMPORT CurrentRec;
  14. FROM PMIGlobals IMPORT PMIScreens;
  15. FROM DBStuff IMPORT MakeKey;
  16. FROM FrameManager IMPORT EraseFrame;
  17. FROM Scrn2DBF IMPORT FrameToDBF, DBFToFrame;
  18. FROM PosUtils IMPORT Equal;
  19. FROM ScrnUtl2 IMPORT CloseDisplayFrame;
  20. FROM StrEdit IMPORT CrunchBlanks,DeleteRightJustified,CAPstr,AssignStr;
  21. FROM M2Strings IMPORT Length;
  22. FROM StrConv IMPORT StrToReal;
  23. FROM LowLevel IMPORT Fill;
  24. FROM StringIO IMPORT PrintMessage,WriteStr,WriteEol,outp;
  25. (* these next two are from stonybrook - the pmi version doesn't work*)
  26. FROM EnvironUtils IMPORT ReadEnvironment;
  27. FROM SmartScreen IMPORT ClearScreen;
  28. FROM VWindows IMPORT ClearPart, CurrentWindow, SetCursorHeight;
  29. FROM ScrnTypes IMPORT DisplayFrame,InitDisplayFrame,AFrameName,
  30. ContinueInput,CancelInput,SubmitInput;
  31. FROM FramePainter IMPORT ShowDisplayFrame;
  32. FROM InputManager IMPORT ControlFrame;
  33. FROM Prompts IMPORT Prompt,PromptStr,PromptYN;
  34. FROM SYSTEM IMPORT ADR,SIZE;
  35. FROM ControlUtils IMPORT ControlSeparately, LoadFrameList,Control,ReadInput;
  36. FROM DspFiles IMPORT ReadDisplayFrame;
  37. FROM HandleIO IMPORT FileExists;
  38. FROM LowLevel IMPORT Fill;
  39. FROM GenLists IMPORT GenList, NewList,ListLength,GetElmt,DisposeList;
  40. FROM ScrnTypes IMPORT AFrameName, InitDisplayFrame,DisplayFile;
  41. FROM DBFInvtry IMPORT InvtryDBF, OpenInvtryDBF,
  42. CloseInvtryDBF,FixInvRec,InvtryRec,MoveInvtryToDBF,MoveInvtryFromDBF,
  43. FindInvtryByInvcode, FindInvtryByOrderfrm, NextInvtry,
  44. PrevInvtry,FirstInvtry,LastInvtry,InvcodeIdx;
  45. IMPORT InitCompilerMods;
  46. FROM NumTypes IMPORT Real8;
  47. FROM UOpsExt IMPORT Lookup,LookupProc;
  48. FROM UserOps IMPORT AKeyHandler,TheKeyHandler;
  49. IMPORT Key;
  50. VAR
  51. Status : INTEGER;
  52. Environ : ARRAY [0..60] OF CHAR;
  53. J : CARDINAL;
  54. TopMenu : GenList;
  55. FirstTime: BOOLEAN;
  56. NextFrame,EndingFrame : AFrameName;
  57. SelChar : CHAR;
  58. NoData : BOOLEAN; (* true when no data is on the screen *)
  59. InvtryDF : DisplayFrame;
  60. PullDnMenu : GenList;
  61. CurrentDF : DisplayFrame; (* used with lookup *)
  62. LookUpOk : BOOLEAN;
  63. InitInvtry : BOOLEAN;
  64. PROCEDURE LookUpInvty(VAR Key : ARRAY OF CHAR);
  65. (* this routine will be called to lookup the database item
  66. and fill in the blanks *)
  67. VAR
  68. Inv : InvtryRec;
  69. CKey : ARRAY[0..10] OF CHAR;
  70. B : BOOLEAN;
  71. BEGIN
  72. CAPstr(Key);
  73. AssignStr(Key,CKey);
  74. MakeKey(CKey);
  75. IF NOT FindInvtryByInvcode(CKey)
  76. THEN
  77. GeneralInventory(CKey)
  78. END;
  79. AssignStr(Key,CKey);
  80. LookUpOk := TRUE;
  81. DBFToFrame(InvtryDBF,CurrentDF); (* fill in the frame and update*)
  82. ShowDisplayFrame(CurrentDF,0,0,0,0);
  83. END LookUpInvty;
  84. PROCEDURE UpdateInvQuant(InvtryNbr : ARRAY OF CHAR; ChangeAmt: Real8);
  85. (* add the change amount to the on hand amount. The change amount could
  86. be positive or negative *)
  87. END UpdateInvQuant;
  88. PROCEDURE AddInvBatch();
  89. (* take the value from the screen and add to the inventory record*)
  90. (* used when new orders come in *)
  91. VAR
  92. OldLookup : Lookup;
  93. FrameName : AFrameName;
  94. AddStr : ARRAY[0..10] OF CHAR;
  95. AddAmt : Real8;
  96. B : BOOLEAN;
  97. InvRec : InvtryRec;
  98. BEGIN
  99. OldLookup := LookupProc; (* save old lookup proc *)
  100. LookupProc :=LookUpInvty;
  101. InitDisplayFrame(CurrentDF,CurrentWindow);
  102. REPEAT
  103. ReadDisplayFrame(PMIScreens,CurrentDF,'InvAdd');
  104. ShowDisplayFrame(CurrentDF,0,0,0,0);
  105. ControlFrame(CurrentDF,0,'',FALSE,FrameName);
  106. IF NOT LookUpOk
  107. THEN
  108. Prompt('Item not found ');
  109. ELSE
  110. ReadInput(CurrentDF,AddStr,'AddAmt');
  111. B := StrToReal(AddStr,0,AddAmt);
  112. B := FrameToDBF(InvtryDBF,CurrentDF);
  113. MoveInvtryFromDBF(InvRec);
  114. InvRec.ONHAND := InvRec.ONHAND + AddAmt;
  115. InvRec.ONORDER := 'N';
  116. MoveInvtryToDBF(InvRec);
  117. WriteDBRec(InvtryDBF);
  118. END;
  119. UNTIL NOT Equal(FrameName,'InvAdd');
  120. CloseDisplayFrame(CurrentDF);
  121. LookupProc := OldLookup;
  122. END AddInvBatch;
  123. PROCEDURE CtlKeyHandler(FrameRec : DisplayFrame; VAR LastKey : CARDINAL;
  124. VAR NextFrame : AFrameName);
  125. VAR
  126. B : BOOLEAN;
  127. BEGIN
  128. NextFrame := ContinueInput;
  129. CASE LastKey OF
  130. Key.PgUp : B:= PrevInvtry();
  131. |Key.PgDn : B:= NextInvtry();
  132. |Key.CtrlPgDn : LastInvtry();
  133. |Key.CtrlPgUp : FirstInvtry();
  134. |Key.Escape : NextFrame := CancelInput;
  135. |Key.Return : NextFrame := SubmitInput;
  136. ELSE
  137. END;
  138. IF NOT (LastKey = Key.Escape) (* update the display *)
  139. THEN
  140. DBFToFrame(InvtryDBF,FrameRec);
  141. ShowDisplayFrame(FrameRec,0,0,0,0);
  142. END;
  143. END CtlKeyHandler;
  144. PROCEDURE GetInvItem( VAR InvItem : InvtryRec): BOOLEAN;
  145. (* this routine controls the problems associated with not finding
  146. the inventory item on a lookup - will allow the user to
  147. go forward, backward in the inventory records till the
  148. correct item is found -
  149. Returns the item in the record
  150. otherwise returns false *)
  151. VAR
  152. OldKeyHandler : AKeyHandler;
  153. NxtFrame : AFrameName;
  154. B : BOOLEAN;
  155. BEGIN
  156. OldKeyHandler := TheKeyHandler;
  157. TheKeyHandler := CtlKeyHandler;
  158. InitDisplayFrame(InvtryDF,CurrentWindow);
  159. ReadDisplayFrame(PMIScreens,InvtryDF,'InvSearch');
  160. ReadDBRec(InvtryDBF,CurrentRec(InvcodeIdx)); (* get closest rec*)
  161. DBFToFrame(InvtryDBF,InvtryDF);
  162. ShowDisplayFrame(InvtryDF,0,0,0,0);
  163. ControlFrame(InvtryDF,1,'',TRUE,NxtFrame);
  164. TheKeyHandler := OldKeyHandler;
  165. B := Equal('SUBMIT',NxtFrame);
  166. CloseDisplayFrame(InvtryDF);
  167. IF B
  168. THEN
  169. MoveInvtryFromDBF(InvItem);
  170. RETURN TRUE;
  171. ELSE
  172. RETURN FALSE;
  173. END;
  174. END GetInvItem;
  175. PROCEDURE UpdateInvBatch();
  176. (* this routine will update the inventory items in a batch mode*)
  177. (* until the user hits esc key*)
  178. VAR
  179. OldLookup : Lookup;
  180. FrameName : AFrameName;
  181. B : BOOLEAN;
  182. BEGIN
  183. OldLookup := LookupProc; (* save old lookup proc *)
  184. LookupProc := LookUpInvty;
  185. InitDisplayFrame(CurrentDF,CurrentWindow);
  186. REPEAT
  187. ReadDisplayFrame(PMIScreens,CurrentDF,'InvUpdate');
  188. ShowDisplayFrame(CurrentDF,0,0,0,0);
  189. ControlFrame(CurrentDF,0,'',FALSE,FrameName);
  190. IF NOT LookUpOk
  191. THEN
  192. Prompt('Item not found ');
  193. ELSE
  194. B := FrameToDBF(InvtryDBF,CurrentDF);
  195. FixInvRec();
  196. WriteDBRec(InvtryDBF);
  197. END;
  198. UNTIL NOT Equal(FrameName,'Update');
  199. CloseDisplayFrame(CurrentDF);
  200. LookupProc := OldLookup;
  201. END UpdateInvBatch;
  202. PROCEDURE FileMenu(SelChar: CHAR);
  203. VAR
  204. B : BOOLEAN;
  205. Str : ARRAY [0..80] OF CHAR;
  206. BEGIN
  207. CASE SelChar OF
  208. 'A' : ReadDisplayFrame(PMIScreens,InvtryDF,'Invtry'); (*Clear out any of the fields *)
  209. ShowDisplayFrame(InvtryDF,0,0,0,0);
  210. Control(InvtryDF); (* alow user input *)
  211. AppendBlank(InvtryDBF);
  212. B := FrameToDBF(InvtryDBF,InvtryDF); (* do something if couldn't add*)
  213. FixInvRec();
  214. WriteDBRec(InvtryDBF);
  215. |'F' : FirstInvtry();
  216. DBFToFrame(InvtryDBF,InvtryDF);
  217. ShowDisplayFrame(InvtryDF,0,0,0,0);
  218. |'L' : LastInvtry();
  219. DBFToFrame(InvtryDBF,InvtryDF);
  220. ShowDisplayFrame(InvtryDF,0,0,0,0);
  221. |'N' : IF NextInvtry()
  222. THEN
  223. DBFToFrame(InvtryDBF,InvtryDF);
  224. ShowDisplayFrame(InvtryDF,0,0,0,0);
  225. END;
  226. |'P' : IF PrevInvtry()
  227. THEN
  228. DBFToFrame(InvtryDBF,InvtryDF);
  229. ShowDisplayFrame(InvtryDF,0,0,0,0);
  230. END;
  231. |'I' : (* The first unused letter in the index name or 'Q' *)
  232. Fill(ADR(Str),SIZE(Str),0);
  233. PromptStr('Enter Invtry Invcode ',Str);
  234. CrunchBlanks(Str);
  235. CAPstr(Str);
  236. IF NOT FindInvtryByInvcode(Str)
  237. THEN
  238. END;
  239. DBFToFrame(InvtryDBF,InvtryDF);
  240. ShowDisplayFrame(InvtryDF,0,0,0,0);
  241. |'O' : (* The first unused letter in the index name or 'Q' *)
  242. Fill(ADR(Str),SIZE(Str),0);
  243. PromptStr('Enter Invtry Orderfrm ',Str);
  244. CrunchBlanks(Str);
  245. IF NOT FindInvtryByOrderfrm(Str)
  246. THEN
  247. Prompt('Invtry Not Found');
  248. ELSE
  249. DBFToFrame(InvtryDBF,InvtryDF);
  250. ShowDisplayFrame(InvtryDF,0,0,0,0);
  251. END;
  252. END; (* end of case *)
  253. END FileMenu;
  254. PROCEDURE EditMenu(SelChar : CHAR);
  255. VAR
  256. B : BOOLEAN;
  257. BEGIN
  258. CASE SelChar OF
  259. 'U' : Control(InvtryDF);
  260. B := FrameToDBF(InvtryDBF,InvtryDF);
  261. FixInvRec();
  262. WriteDBRec(InvtryDBF);
  263. |'D' : IF PromptYN('About to delete inventory ',InvtryDF)
  264. THEN
  265. DeleteRecord(InvtryDBF);
  266. B := NextInvtry(); (* set the index to next - then prev to point to *)
  267. (* the correct item *)
  268. FileMenu('P'); (* display the next customer *)
  269. NoData := TRUE;
  270. END;
  271. END;
  272. END EditMenu;
  273. PROCEDURE Init();
  274. BEGIN
  275. NewList(PullDnMenu);
  276. LoadFrameList(PMIScreens,'InvtryTopMenu',PullDnMenu);
  277. InitInvtry := TRUE;
  278. END Init;
  279. PROCEDURE GeneralInventory(VAR InvtyCode : ARRAY OF CHAR);
  280. VAR
  281. Inv : InvtryRec;
  282. B : BOOLEAN;
  283. BEGIN
  284. InitDisplayFrame(InvtryDF,CurrentWindow);
  285. ReadDisplayFrame(PMIScreens,InvtryDF,'Invtry');
  286. MakeKey(InvtyCode);
  287. IF InvtyCode[0] = CHR(0)
  288. THEN FirstInvtry();
  289. ELSE
  290. IF NOT NextInvtry() (* assume already did a find by number *)
  291. THEN
  292. B := PrevInvtry();
  293. END;
  294. END;
  295. DBFToFrame(InvtryDBF,InvtryDF);
  296. ShowDisplayFrame(InvtryDF,0,0,0,0);
  297. IF NOT InitInvtry
  298. THEN Init();
  299. END;
  300. NoData := TRUE;
  301. REPEAT
  302. NextFrame := 'InvtryTopMenu';
  303. ControlSeparately(PullDnMenu,NextFrame,SelChar,EndingFrame);
  304. IF Equal(EndingFrame,'InvtryFileMenu')
  305. THEN FileMenu(SelChar);
  306. ELSIF Equal(EndingFrame,'InvtEditMenu')
  307. THEN EditMenu(SelChar);
  308. END;
  309. UNTIL SelChar='X'; (* Assumes 'X' is only used to exit *)
  310. MoveInvtryFromDBF(Inv);
  311. AssignStr(Inv.INVCODE,InvtyCode);
  312. CloseDisplayFrame(InvtryDF);
  313. END GeneralInventory;
  314. PROCEDURE ControlInvtry();
  315. VAR
  316. NextFrame : AFrameName;
  317. Str : ARRAY[0..10] OF CHAR;
  318. DF : DisplayFrame;
  319. BEGIN
  320. ClearScreen();
  321. InitDisplayFrame(DF,CurrentWindow);
  322. OpenInvtryDBF(TRUE);
  323. REPEAT
  324. ReadDisplayFrame(PMIScreens,DF,'InvtryMain');
  325. ControlFrame(DF,1,'',TRUE,NextFrame);
  326. IF Equal(NextFrame,'GenInv')
  327. THEN Str := '';
  328. GeneralInventory(Str);
  329. ELSIF Equal(NextFrame,'AddInv')
  330. THEN AddInvBatch();
  331. ELSIF Equal(NextFrame,'UpdateInv')
  332. THEN UpdateInvBatch();
  333. END;
  334. ClearScreen();
  335. UNTIL Equal(NextFrame,'Exit');
  336. CloseDisplayFrame(DF);
  337. END ControlInvtry;
  338. BEGIN
  339. InitInvtry := FALSE;
  340. END Invtry.
  341.