You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

678 lines
28 KiB

  1. Ext.define("App.view.OrderForm", {
  2. extend: "Ext.form.Panel",
  3. xtype: "orderForm",
  4. params: {},
  5. layout: "vbox",
  6. scrollable: true,
  7. onSave: function() {
  8. var me = this,
  9. f = me.getForm();
  10. if (f.isValid()) {
  11. f.submit({
  12. url: App.url("/order/save") + "?_csrf=" + App.csrf,
  13. method: "POST",
  14. submitEmptyText: false,
  15. success: function(form, action) {
  16. App.showMsg("Saved");
  17. if (me.callbackOnSave) {
  18. me.callbackOnSave(action.result.id);
  19. }
  20. }
  21. });
  22. }else{
  23. App.showError(App.localeRes("Invalid information"));
  24. }
  25. },
  26. loadForm: function(params) {
  27. if (!params) return;
  28. var me = this;
  29. me.getForm().load({
  30. url: App.url("/order/load"),
  31. method: "POST",
  32. params: {
  33. id: params.id
  34. },
  35. success: function(form, action) {
  36. Ext.apply(me.params, {id: params.id});
  37. me.down('#refId').setValue(params.id);
  38. me.down("filefield").setDisabled(false);
  39. me.down("#newSheetBtn").setDisabled(false);
  40. me.down("#trackSheetBtn").setDisabled(false);
  41. me.down("#removeSheetBtn").setDisabled(false);
  42. me.down('#photoList').loadPanel();
  43. if (me.callbackOnLoad) {
  44. me.callbackOnLoad(form.getValues());
  45. }
  46. }
  47. });
  48. },
  49. uploadFile: function() {
  50. var me = this;
  51. if (me.down("filefield").getValue() == "") return;
  52. me.getForm().submit({
  53. method: "POST",
  54. waitMsg: "Uploading...",
  55. url: App.url("/file/measurement-sheet/ul") + "?orderId="+me.params.id+"&_csrf=" + App.csrf,
  56. success: function(f, action) {
  57. App.showMsg("Uploaded");
  58. me.down("filefield").setValue("");
  59. me.down('#photoList').loadPanel();
  60. },
  61. failure: function(f, action) {
  62. alert("Uploaded failure");
  63. me.down("filefield").setValue("");
  64. }
  65. });
  66. console.log(App.url("/file/measurement-sheet/ul") + "?orderId="+me.params.id+"&_csrf=" + App.csrf)
  67. },
  68. initComponent: function() {
  69. var me = this;
  70. Ext.apply(me, {
  71. bbar: {
  72. defaultButtonUI: "default",
  73. layout: "hbox",
  74. padding: 0,
  75. items: [
  76. "->",
  77. /*
  78. {
  79. xtype: 'checkbox',
  80. fieldLabel: App.localeRes('Ignored'),
  81. //name: 'ignoreC',
  82. inputValue: '1',
  83. uncheckedValue: '0',
  84. },
  85. */
  86. {
  87. xtype: "button",
  88. text: App.localeRes("Save"),
  89. ui: "blue",
  90. margin: "0 0 16 0",
  91. formBind: true,
  92. handler: function(button, event) {
  93. me.onSave();
  94. }
  95. }
  96. ]
  97. },
  98. items: [
  99. {
  100. xtype: "hidden",
  101. itemId: 'idfield',
  102. name: "id"
  103. },
  104. {
  105. xtype: "fieldcontainer",
  106. width: "100%",
  107. margin: "0 0 10 0",
  108. layout: "hbox",
  109. items: [
  110. {
  111. xtype: "orderTypeCombo",
  112. fieldLabel: App.localeRes("Order No.")+" * ",
  113. name: "type",
  114. width: "40%",
  115. value: 'S-',
  116. allowBlank: false,
  117. listeners:{
  118. change: function(combo, newValue,oldValue){
  119. me.down("#orderCodeField").checkValidOrderNo();
  120. }
  121. }
  122. },
  123. {
  124. xtype: "textfield",
  125. fieldLabel: "&nbsp",
  126. labelSeparator: "",
  127. itemId: 'orderCodeField',
  128. labelWidth: 5,
  129. name: "code",
  130. flex: 1,
  131. maxLength: 30,
  132. allowBlank: false,
  133. enableKeyEvents: true,
  134. isPressing: false,
  135. checkValidOrderNo: function(){
  136. var field = me.down("#orderCodeField");
  137. var type = me.down("orderTypeCombo").getValue();
  138. var code = me.down("#orderCodeField").getValue();
  139. var id = me.down("#idfield").getValue();
  140. if(!code){
  141. me.down('#validResult').setHtml('<i class="fas fa-exclamation-circle" style="color:red" ></i>');
  142. return;
  143. }
  144. Ext.Ajax.request({
  145. url: App.url("/order/check-order-no"),
  146. params:{
  147. id: id,
  148. type: type,
  149. code: code
  150. },
  151. success: function(response, opts) {
  152. var result = Ext.decode(response.responseText);
  153. if(result.success){
  154. me.down('#validResult').setHtml('<i class="fas fa-check-circle" style="color:green" ></i>');
  155. field.setValidation();
  156. }else{
  157. me.down('#validResult').setHtml('<i class="fas fa-exclamation-circle" style="color:red" ></i>');
  158. field.setValidation("Order No. has been used.");
  159. }
  160. },
  161. failure: function(response, opts) {
  162. me.down('#validResult').setHtml('<i class="fas fa-exclamation-circle" style="color:red" ></i>');
  163. field.setValidation(response);
  164. },
  165. });
  166. },
  167. listeners:{
  168. change: {
  169. fn:function(field, newValue, oldValue){
  170. field.checkValidOrderNo();
  171. field.isPressing = false;
  172. },
  173. buffer: 1000,
  174. },
  175. keydown: function(field){
  176. if(field.isPressing) return;
  177. me.down('#validResult').setHtml('<i class="fas fa-spinner fa-pulse"></i>');
  178. field.isPressing = true;
  179. }
  180. }
  181. },{
  182. xtype: 'label',
  183. html: '<i class="fas fa-spinner fa-pulse" style="color:white"></i>',
  184. itemId: 'validResult',
  185. padding: '8 4 8 4',
  186. }
  187. ]
  188. },
  189. {
  190. xtype: "orderCombo",
  191. fieldLabel: App.localeRes("Ref. To"),
  192. width: '100%',
  193. name: "ref",
  194. listeners: {
  195. change: function(combo, newValue, oldValue) {
  196. if (combo.getSelection()) {
  197. me.down("#refNoField").setValue(combo.getSelection().get("orderNo"));
  198. } else {
  199. me.down("#refNoField").setValue(null);
  200. }
  201. }
  202. }
  203. },
  204. {
  205. xtype: "hidden",
  206. itemId: "refNoField",
  207. name: "refNo"
  208. },
  209. {
  210. xtype: 'fieldcontainer',
  211. layout: 'hbox',
  212. margin: "0 0 10 0",
  213. width: '100%',
  214. items: [
  215. {
  216. xtype: "customerCombo",
  217. fieldLabel: App.localeRes("Customer")+" * ",
  218. name: "custId",
  219. flex: 1,
  220. allowBlank: false
  221. },
  222. {
  223. xtype: 'button',
  224. text: 'New',
  225. handler: function(button){
  226. App.loadModuleWin('orderForm_CreateCustomerWindow', App.localeRes("Quick Create Customer Window"), {
  227. callbackOnClose: function (isSave, customerId) {
  228. if(isSave){
  229. me.down("customerCombo").getStore().load();
  230. me.down("customerCombo").setValue(customerId);
  231. }
  232. }
  233. });
  234. }
  235. }
  236. ]
  237. },
  238. {
  239. xtype: "datefield",
  240. fieldLabel: App.localeRes("Order Date")+" * ",
  241. name: "date",
  242. width: "100%",
  243. value: new Date(),
  244. allowBlank: false
  245. },
  246. {
  247. xtype: "orderStatusCombo",
  248. fieldLabel: App.localeRes("Status")+" * ",
  249. name: "status",
  250. width: "100%",
  251. value: 0,
  252. allowBlank: false
  253. },
  254. {
  255. xtype: "textarea",
  256. fieldLabel: App.localeRes("Remarks"),
  257. name: "remarks",
  258. width: "100%",
  259. height: 80,
  260. maxLength: 200
  261. },
  262. {
  263. xtype: "datefield",
  264. fieldLabel: App.localeRes("Target Date"),
  265. name: "targetCompleteDate",
  266. width: "100%",
  267. },
  268. {
  269. xtype: 'fieldset',
  270. title: App.localeRes("Item(s)"),
  271. width: '100%',
  272. items: [
  273. {
  274. xtype: 'container',
  275. width: '100%',
  276. layout: 'hbox',
  277. items: [
  278. {
  279. xtype: "datefield",
  280. fieldLabel: App.localeRes("Stock Out"),
  281. name: "outDate",
  282. labelAlign: 'top',
  283. flex:1,
  284. },
  285. {
  286. xtype: "datefield",
  287. fieldLabel: App.localeRes("Stock In"),
  288. labelAlign: 'top',
  289. name: "inDate",
  290. flex:1,
  291. },
  292. ]
  293. },
  294. {
  295. xtype: 'container',
  296. width: '100%',
  297. layout: 'hbox',
  298. items: [
  299. {
  300. xtype: "textarea",
  301. name: "outRemark",
  302. emptyText: App.localeRes("Remarks"),
  303. submitEmptyText: false,
  304. width: "100%",
  305. height: 60,
  306. flex:1,
  307. },
  308. {
  309. xtype: "textarea",
  310. name: "inRemark",
  311. emptyText: App.localeRes("Remarks"),
  312. submitEmptyText: false,
  313. width: "100%",
  314. height: 60,
  315. flex:1,
  316. },
  317. ]
  318. },
  319. {
  320. xtype: 'container',
  321. width: '100%',
  322. layout: 'hbox',
  323. items: [
  324. {
  325. xtype: "stockInOutStatusCombo",
  326. name: "outStatus",
  327. width: "100%",
  328. flex:1,
  329. },
  330. {
  331. xtype: "stockInOutStatusCombo",
  332. name: "inStatus",
  333. width: "100%",
  334. flex:1,
  335. },
  336. ]
  337. },
  338. ]
  339. },
  340. {
  341. xtype: 'hidden',
  342. name: 'refType',
  343. value: 'order'
  344. },
  345. {
  346. xtype: 'hidden',
  347. name: 'refId',
  348. itemId: 'refId'
  349. },
  350. {
  351. xtype: 'label',
  352. html: '<b>'+App.localeRes("Measurement Sheet")+'</b>',
  353. },
  354. {
  355. xtype: 'container',
  356. layout: 'hbox',
  357. width: '100%',
  358. items: [
  359. {
  360. xtype: "filefield",
  361. disabled: true,
  362. buttonText: App.localeRes("Upload"),
  363. buttonConfig:{
  364. iconCls: 'fas fa-upload',
  365. },
  366. ui: "soft-blue",
  367. name: "multipartFile",
  368. margin: 4,
  369. buttonOnly: true,
  370. accept: "image/*",
  371. listeners: {
  372. change: function(field, value, eOpts) {
  373. me.uploadFile();
  374. }
  375. }
  376. },
  377. {
  378. xtype: 'button',
  379. itemId: 'newSheetBtn',
  380. disabled: true,
  381. ui: 'soft-purple',
  382. iconCls: 'fas fa-download',
  383. margin: 4,
  384. text: App.localeRes("Measurement Sheet"),
  385. handler: function(button, event){
  386. if(!me.params.id) return;
  387. window.open( App.url("/report/measurement-sheet.pdf")+'?orderId=' + me.params.id);
  388. }
  389. },
  390. {
  391. xtype: 'button',
  392. itemId: 'trackSheetBtn',
  393. disabled: true,
  394. ui: 'soft-blue',
  395. margin: 4,
  396. iconCls: "fas fa-history",
  397. text: App.localeRes('Track'),
  398. handler: function(button, event){
  399. if(!me.params.id) return;
  400. App.loadModuleWin('orderSheetWindow', App.localeRes("Track Window"), {
  401. params: {
  402. id: me.params.id
  403. },
  404. callbackOnClose: function (isSave) {
  405. me.down('#photoList').loadPanel();
  406. }
  407. });
  408. }
  409. },
  410. {
  411. xtype: 'container',
  412. flex: 1,
  413. },
  414. {
  415. xtype: 'button',
  416. itemId: 'removeSheetBtn',
  417. disabled: true,
  418. iconCls: 'fas fa-trash',
  419. ui: 'soft-red',
  420. margin: 4,
  421. text: App.localeRes('Remove'),
  422. handler: function(button, event){
  423. if(!me.params.id) return;
  424. var deleteRecord = [];
  425. me.down('#photoList').items.items
  426. .forEach(function(item, index, array){
  427. if(item.selected){
  428. deleteRecord.push({
  429. fileId: item.fileId,
  430. refId: me.refId,
  431. refType: me.refType,
  432. skey: item.skey,
  433. });
  434. }
  435. });
  436. if(deleteRecord.length<=0) return;
  437. Ext.Ajax.request({
  438. url: App.url("/order/save"),
  439. params: {
  440. id: me.params.id,
  441. fileId:'',
  442. },
  443. success: function(response, opts) {
  444. App.showMsg('Removed');
  445. me.down('#photoList').loadPanel();
  446. },
  447. failure: function(response, opts) {
  448. App.showError('Message : ' + response.status);
  449. },
  450. scope: this
  451. });
  452. }
  453. },
  454. ]
  455. },
  456. {
  457. xtype: "container",
  458. itemId: "photoList",
  459. items: [],
  460. loadPanel: function() {
  461. var container = this;
  462. if(!me.params.id) return;
  463. Ext.Ajax.request({
  464. url: App.url("/order/get-current-ms.json"),
  465. params: {
  466. orderId: me.params.id
  467. },
  468. success: function(response, opts) {
  469. var result = Ext.decode(response.responseText);
  470. container.removeAll(true);
  471. result.records.forEach(function(item, index, array) {
  472. container.add({
  473. xtype: 'imagefield',
  474. name: item.filename,
  475. thumbnailPath: App.url("/file/thumbnail/"+item.id+"/"+item.skey+"/"+item.filename),
  476. path: App.url("/file/dl/"+item.id+"/"+item.skey+"/"+item.filename),
  477. imageWidth: item.imageWidth,
  478. imageHeight: item.imageHeight,
  479. fileId: item.id,
  480. skey: item.skey,
  481. });
  482. });
  483. },
  484. failure: function(response, opts) {
  485. App.showError('Message : ' + response.status);
  486. },
  487. scope: this
  488. });
  489. }
  490. },
  491. {
  492. xtype: 'label',
  493. width: '100%',
  494. html: '<br/><hr />',
  495. },
  496. {
  497. xtype: 'photoPanel',
  498. itemId: 'orderPhotoPanel2',
  499. width: '100%',
  500. refType: 'order',
  501. url: App.url("/order/image-list.json"),
  502. },
  503. ]
  504. });
  505. me.callParent(arguments);
  506. }
  507. });
  508. Ext.define("App.view.OrderForm_CreateCustomerWindow", {
  509. extend: "Ext.window.Window",
  510. alias: "widget.orderItemWindow",
  511. xtype: "orderForm_CreateCustomerWindow",
  512. title: App.localeRes("Quick Create Customer"),
  513. width: 600,
  514. modal: true,
  515. resizable: true,
  516. layout: "fit",
  517. constrainHeader: true,
  518. onSave: function(){
  519. var me = this;
  520. var form = me.down('form');
  521. form.submit({
  522. waitMsg: 'Please wait...',
  523. url: App.url('/order/create-cust'),
  524. success: function(f, action) {
  525. App.showMsg('Created');
  526. me.savedId = action.result.id;
  527. me.isSave = true;
  528. me.close();
  529. },
  530. failure: function(f, action) {
  531. alert('Action failure');
  532. }
  533. });
  534. },
  535. initComponent: function () {
  536. var me = this;
  537. Ext.apply(me, {
  538. items: [
  539. {
  540. xtype: "form",
  541. width: '100%',
  542. layout: 'vbox',
  543. padding: 4,
  544. bbar: {
  545. defaultButtonUI: "default",
  546. layout: "hbox",
  547. padding: 0,
  548. items: [
  549. "->",
  550. {
  551. xtype: "button",
  552. text: App.localeRes("Save"),
  553. ui: "blue",
  554. margin: "0 0 16 0",
  555. formBind: true,
  556. handler: function(button, event) {
  557. me.onSave();
  558. }
  559. }
  560. ]
  561. },
  562. items: [
  563. {
  564. xtype: 'container',
  565. width: '100%',
  566. margin: '20 0 10 0',
  567. layout: 'hbox',
  568. items: [
  569. {
  570. xtype: 'textfield',
  571. fieldLabel: App.localeRes("Name"),
  572. emptyText: App.localeRes("Surname")+" *",
  573. name: 'surname',
  574. width: '100%',
  575. flex: 5,
  576. maxLength: 200,
  577. allowBlank: false
  578. },
  579. {
  580. xtype: 'textfield',
  581. emptyText: App.localeRes("First Name"),
  582. fieldLabel: App.localeRes("&nbsp"),
  583. labelSeparator: '',
  584. labelWidth: 5,
  585. name: 'firstName',
  586. width: '100%',
  587. flex: 4,
  588. maxLength: 200
  589. },
  590. ]
  591. },
  592. {
  593. xtype: 'textfield',
  594. fieldLabel: App.localeRes("Chinese Name"),
  595. name: 'nameCh',
  596. width: '100%',
  597. maxLength: 200
  598. },
  599. {
  600. xtype: 'container',
  601. width: '100%',
  602. margin: '0 0 10 0',
  603. layout: 'hbox',
  604. items: [
  605. {
  606. xtype: 'textfield',
  607. fieldLabel: App.localeRes("Mobile"),
  608. name: 'phone1',
  609. flex: 5,
  610. maxLength: 200
  611. },
  612. {
  613. xtype: 'textfield',
  614. name: 'phone2',
  615. fieldLabel: App.localeRes("/"),
  616. labelWidth: 5,
  617. labelSeparator: '',
  618. flex: 4,
  619. maxLength: 200
  620. }
  621. ]
  622. },
  623. {
  624. xtype: 'textfield',
  625. fieldLabel: App.localeRes("Email"),
  626. name: 'email',
  627. width: '100%',
  628. maxLength: 200
  629. },
  630. {
  631. xtype: 'textarea',
  632. fieldLabel: App.localeRes("Address"),
  633. name: 'address',
  634. width: '100%',
  635. height: 80,
  636. maxLength: 200
  637. },
  638. ],
  639. },
  640. ],
  641. listeners: {
  642. show: function () {
  643. if(me.params && me.params.record){
  644. me.down('orderItemForm').loadRecord(me.params.record);
  645. }else if(me.params && me.params.orderId){
  646. me.down('#orderId').setValue(me.params.orderId);
  647. }
  648. },
  649. close: function (window, opts) {
  650. if (me.callbackOnClose) {
  651. me.callbackOnClose(window.isSave, window.savedId);
  652. }
  653. }
  654. }
  655. });
  656. me.callParent(arguments);
  657. }
  658. });