PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/opensourcepos/application/views/procurement/purchaseorder/purchase_order_grid_1.php

https://bitbucket.org/jit_bec/shopifine
PHP | 1094 lines | 880 code | 144 blank | 70 comment | 44 complexity | 8067da63a47fce7760dcd32be7bd0f9c MD5 | raw file
Possible License(s): LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <html>
  2. <head>
  3. <?php $this->load->view("common/header"); ?>
  4. <!-- <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>-->
  5. <style>
  6. .column {
  7. float: left;
  8. padding: 1em;
  9. width:45%;
  10. }
  11. .extra-wide{
  12. width:95%;
  13. }
  14. .field{
  15. width:100%;
  16. }
  17. .ui-widget-header {height:12px;}
  18. .quote-column {
  19. float: left;
  20. padding-bottom: 0.5em;
  21. width: 95%;
  22. }
  23. .ui-combobox {
  24. width:14em;
  25. }
  26. .ui-combobox-input{
  27. width:12em;
  28. }
  29. #supplierOp-input{
  30. width:10em;
  31. }
  32. #warehouseOp-input{
  33. width:10em;
  34. }
  35. .calculated {
  36. color: green;
  37. font-size: 90%;
  38. }
  39. .row{
  40. width:95%;
  41. }
  42. .shopifine-ro-label {
  43. float: left;
  44. padding-right: 0.5em;
  45. width: 50%;
  46. word-wrap: break-word;
  47. color:#2E6E9E;
  48. }
  49. .shopifine-output {
  50. float: right;
  51. width: 45%;
  52. word-wrap: break-word;
  53. font-weight:bold;
  54. }
  55. .ui-tabs {
  56. height: 80%;
  57. margin: 0 auto;
  58. width: 70%;
  59. left:0;
  60. }
  61. #notetab {
  62. height:30em;
  63. }
  64. #details {
  65. height:12em;
  66. }
  67. .ui-tabs-nav{
  68. height:22px;
  69. }
  70. .labeldiv {
  71. color: #2E6E9E;
  72. float: left;
  73. font-size: 110%;
  74. font-weight: bold;
  75. margin-right: .5em;
  76. width: 35%;
  77. word-wrap: break-word;
  78. }
  79. .valuediv {
  80. float: left;
  81. font-weight: bold;
  82. width: 45%;
  83. word-wrap: break-word;
  84. }
  85. label.error {
  86. margin-right: .5em;
  87. }
  88. #status-message-li{
  89. color: red;
  90. font-size: 110%;
  91. font-style: italic;
  92. margin: 0 auto;
  93. width: 80%;
  94. }
  95. .help-message-left{
  96. color: green;
  97. font-size: 90%;
  98. font-style: italic;
  99. margin: 0 auto;
  100. width: 90%;
  101. float:left
  102. }
  103. </style>
  104. <script type="text/javascript">
  105. $(function() {
  106. $.validator.addMethod('comboBoxrequired', function(value, element) {
  107. var selectId = element.id;
  108. var inputIdSelector = "#" + selectId + "-input";
  109. if (value == ""){
  110. inputVal = $(inputIdSelector).val();
  111. if (inputVal == "" || inputVal == null){
  112. return false;
  113. }
  114. }
  115. return true;
  116. }, 'Please select from the dropdown or add new element in box');
  117. $.validator.addMethod('noBlank', function (value, el, param) {
  118. if ($.trim(value).length==0){
  119. return false;
  120. }
  121. return true;
  122. },"Blank values are not acceptable. Use 0 instead");
  123. $.validator.addMethod('tallyquantity', function(value, element) {
  124. var ordered_quantity = parseInt($("#quantity").text());
  125. var already_received = parseInt($("#already_received").text());
  126. var received_quantity = parseInt($("#received_quantity").val());
  127. var returned_quantity = parseInt($("#returned_quantity").val());
  128. var subgrid=$("#subgrid_ref").val();
  129. var receipt_line_id = $("#receipt_line_ref").val();
  130. var action = $("#action").val();
  131. var oper = $("#oper").val();
  132. console.log("already_received" + already_received + "received_quantity" + received_quantity + "returned_quantity" + returned_quantity);
  133. var total_received = already_received + received_quantity + returned_quantity;
  134. if (action=='edit'){
  135. // for edit actionold values need to be subtracted
  136. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'received_quantity')
  137. //}
  138. //else if (oper=="return"){
  139. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  140. //}
  141. }
  142. console.log("total_received/returned" + total_received);
  143. console.log("ordered_quantity" + ordered_quantity);
  144. if (total_received>ordered_quantity){
  145. return false;
  146. }
  147. return true;
  148. }, 'Total Received And Returned Can Not Be More Than Ordered');
  149. //form validation
  150. $("#quoteForm").validate();
  151. $("#itemForm").validate({
  152. ignore:".ignore-fields",
  153. rules:{
  154. received_quantity:{
  155. required:true,
  156. //noBlank:true,
  157. digits:true,
  158. min:1
  159. },
  160. received_value:{
  161. required:true,
  162. //noBlank:true,
  163. number:true,
  164. minStrict:0
  165. },
  166. returned_quantity:{
  167. required:true,
  168. //noBlank:true,
  169. digits:true,
  170. min:1
  171. },
  172. returned_value:{
  173. required:true,
  174. //noBlank:true,
  175. number:true,
  176. minStrict:0
  177. }
  178. }
  179. }
  180. );
  181. // datepicker for Add Form
  182. function quotegriddates(id){
  183. jQuery("#"+id+"_needed_by_date","#orders").datepicker({dateFormat:"yy-mm-dd",minDate:0});
  184. }
  185. //end datepicker
  186. var myGridPkd = $("#lineItems");
  187. $( "#dialog-form" ).dialog({
  188. autoOpen: false,
  189. height: 'auto',
  190. width: '65%',
  191. position:[220,25],
  192. modal: true,
  193. buttons: {
  194. "DoneButton": {
  195. id:"doneBtn",
  196. text:"Done",
  197. click:function() {
  198. var isValid = $("#quoteForm").valid();
  199. if (isValid){
  200. $( this ).dialog( "close" );
  201. } //end ifvalid
  202. }}, //end of Create button
  203. Cancel: function() {
  204. //in cancel just recset notes
  205. $("#receivingNotes").val("");
  206. $( this ).dialog( "close" );
  207. }
  208. },//end buttons
  209. open: function(){
  210. $( "#tabs" ).tabs({
  211. //cache
  212. beforeLoad: function( event, ui ) {
  213. var tabcache = $("#tabcache").val();
  214. if (tabcache==1){
  215. if ( ui.tab.data( "loaded" ) ) {
  216. event.preventDefault();
  217. return;
  218. }
  219. ui.jqXHR.success(function() {
  220. ui.tab.data( "loaded", true );
  221. });
  222. }
  223. },
  224. beforeActivate: function (event,ui){
  225. console.log(ui.newTab[0].id);
  226. console.log(ui.oldTab[0].id);
  227. if (ui.oldTab[0].id=="notesLink"){
  228. $("#tabcache").val("1");
  229. }
  230. },
  231. //load contents after the tab loading is complete
  232. load: function(event,ui){
  233. $.ajax({
  234. method:"POST",
  235. url:'index.php/procurement/getOrderDetails',
  236. data:{orderId: myGrid.getGridParam('selrow')},
  237. success:function(response){
  238. //console.log(response);
  239. var resJson = JSON.parse(response);
  240. //console.log(resJson);
  241. $("#orderRef").text(resJson.reference);
  242. $("#supplierOP").text(resJson.supplier_name);
  243. $("#warehouseOP").text(resJson.warehouse);
  244. $("#quoteOP").text(resJson.quote_reference);
  245. $("#raisedByOP").text(resJson.raised_by_name);
  246. $("#approvedByOP").text(resJson.approved_by_name);
  247. $("#estValueOP").text(resJson.estimated_value);
  248. $("#receivingNotes").val(resJson.receiving_notes);
  249. //$("#receivingNotes").val("abcc");
  250. }
  251. })
  252. $("#lineItems").jqGrid({
  253. url:'index.php/procurement/populateOrderItems',
  254. datatype: 'json',
  255. mtype: 'POST',
  256. postData:{orderId: myGrid.getGridParam('selrow')},
  257. colNames:['Product id','Product','Quantity','Received','Returned','Need By Date','Price','Ordered Value','Received Value','Returned Value'/*'Notes'*/],
  258. colModel :[
  259. {name:'product_id', index:'product_id',editable:false, hidden:true},
  260. {name:'name', index:'name',editable:false, width:160, align:'right'},
  261. {name:'quoted_quantity', index:'quoted_quantity', editable:false,width:60, align:'right'},
  262. {name:'received_quantity', index:'received_quantity', editable:false,width:60, align:'right'},
  263. {name:'returned_quantity', index:'returned_quantity', editable:false,width:60, align:'right'},
  264. {name:'needed_by_date',index:'needed_by_date',editable:false, width:80, align:'right',hidden:true},
  265. {name:'expected_price',index:'expected_price',editable:false, width:60, align:'right',hidden:true},
  266. {name:'estimated_value', index:'estimated_value',editable:false, width:100, align:'right'},
  267. {name:'received_value', index:'received_value',editable:false, width:100, align:'right'},
  268. {name:'returned_value', index:'returned_value',editable:false, width:100, align:'right'},
  269. // {name:'comments', index:'comments',editable:true, width:180, align:'right'}
  270. ],
  271. pager: '#pagerPk',
  272. rowNum:10,
  273. rowList:[5,10,20],
  274. sortname: 'id',
  275. sortorder: 'desc',
  276. viewrecords: true,
  277. gridview: true,
  278. ignoreCase:true,
  279. rownumbers:true,
  280. multiselect:true,
  281. height:'auto',
  282. width:'60%',
  283. caption: 'Line Items',
  284. jsonReader : {
  285. root:"orderitemdata",
  286. page: "page",
  287. total: "total",
  288. records: "records",
  289. cell: "dprow",
  290. id: "id"
  291. },
  292. //receipt Item subgrid
  293. subGrid:true,
  294. subGridRowExpanded: function(subgrid_id, row_id) {
  295. var subgrid_table_id, pager_id;
  296. subgrid_table_id = subgrid_id+"_t";
  297. pager_id = "p_"+subgrid_table_id;
  298. $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
  299. jQuery("#"+subgrid_table_id).jqGrid({
  300. url:'index.php/procurement/populateReceiptItems?oper='+"orderline"+'&orderLineId='+row_id,
  301. datatype: 'json',
  302. colNames:['Supplier Receipt','Reference','Receipt Id','Order Line Id','Product Id','Product','Qty','Qty Rcvd','Rcvd Value','Qty Rtrnd','Rtrnd Value','Rcvd Notes','Rtrnd Notes'],
  303. colModel :[
  304. {name:'supplier_receipt_number', index:'supplier_receipt_number',editable:false,width:120, align:'right'},
  305. {name:'reference', index:'reference',editable:false,width:60, align:'right'},
  306. {name:'receipt_id', index:'receipt_id',editable:false, hidden:true},
  307. {name:'order_line_id', index:'order_line_id',editable:false, hidden:true},
  308. {name:'product_id', index:'product_id',editable:false, hidden:true},
  309. {name:'name', index:'name',editable:false, width:100, align:'right',hidden:true},
  310. {name:'ordered_quantity', index:'ordered_quantity', editable:false,width:60, align:'right'},
  311. {name:'received_quantity', index:'received_quantity', editable:false,width:60, align:'right'},
  312. {name:'received_value', index:'received_value',editable:false, width:80, align:'right'},
  313. {name:'returned_quantity', index:'returned_quantity', editable:false,width:60, align:'right'},
  314. {name:'returned_value', index:'returned_value',editable:false, width:80, align:'right'},
  315. {name:'receiving_notes', index:'receiving_notes',editable:false, width:160, align:'right',hidden:true},
  316. {name:'returned_notes', index:'returned_notes', editable:false,width:160, align:'right',hidden:true}
  317. // {name:'comments', index:'comments',editable:false, width:160, align:'right'}
  318. ],
  319. rowNum:20,
  320. pager: pager_id,
  321. sortname: 'id',
  322. sortorder: "asc",
  323. height: '100%',
  324. multiselect:true,
  325. jsonReader : {
  326. root:"receiptitemdata",
  327. page: "page",
  328. total: "total",
  329. records: "records",
  330. cell: "dprow",
  331. id: "id"
  332. }
  333. });
  334. $("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false,search:false,view:true});
  335. // subgrid custom buttin navigation bar
  336. $("#"+subgrid_table_id).jqGrid ('navButtonAdd', "#"+pager_id,
  337. {
  338. caption:"",
  339. title:"Edit Received For This Receipt",
  340. buttonicon:"ui-icon-newwin",
  341. id:"receive_lineItems",
  342. onClickButton : function () {
  343. //need to pass grid id for dynamic reload;
  344. var noOfRows = $("#"+subgrid_table_id).getGridParam("selarrrow").length;
  345. if (noOfRows == 1){
  346. var lineId = $("#"+subgrid_table_id).getGridParam("selrow");
  347. // grid id would help us in getting order line related info from lineItem grid using order_line_id
  348. // Sub grid would help us in getting receipt related information using receipt id
  349. var gridData ={'grid_id':'lineItems','sub_grid_id':subgrid_table_id,'order_line_id':$("#"+subgrid_table_id).getCell(lineId,'order_line_id'),
  350. 'receipt_line_id':$("#"+subgrid_table_id).getGridParam("selrow"),'action':'edit','oper':'receive'}
  351. $( "#dialog-form-item" ).data('grid_data',gridData).dialog( "open" );
  352. }
  353. else {
  354. $( "#modal-warning" ).dialog("open") ;
  355. }
  356. }
  357. });
  358. $("#"+subgrid_table_id).jqGrid ('navButtonAdd', "#"+pager_id,
  359. {
  360. caption:"",
  361. title:"Edit Returned For This Receipt",
  362. buttonicon:"ui-icon-arrowreturnthick-1-w",
  363. id:"return_lineItems",
  364. onClickButton : function () {
  365. //need to pass grid id for dynamic reload;
  366. var noOfRows = $("#"+subgrid_table_id).getGridParam("selarrrow").length;
  367. if (noOfRows == 1){
  368. var lineId = $("#"+subgrid_table_id).getGridParam("selrow");
  369. // grid id would help us in getting order line related info from lineItem grid using order_line_id
  370. // Sub grid would help us in getting receipt related information using receipt id
  371. var gridData ={'grid_id':'lineItems','sub_grid_id':subgrid_table_id,'order_line_id':$("#"+subgrid_table_id).getCell(lineId,'order_line_id'),
  372. 'receipt_line_id':$("#"+subgrid_table_id).getGridParam("selrow"),'action':'edit','oper':'return'}
  373. $( "#dialog-form-item" ).data('grid_data',gridData).dialog( "open" );
  374. }
  375. else {
  376. $( "#modal-warning" ).dialog("open") ;
  377. }
  378. }
  379. });
  380. $("#"+subgrid_table_id).jqGrid ('navButtonAdd', "#"+pager_id,
  381. { caption: "", buttonicon: "ui-icon-calculator",
  382. title: "Choose Columns",
  383. onClickButton: function() {
  384. $("#"+subgrid_table_id).jqGrid('columnChooser');
  385. }
  386. });
  387. //end sub grid navigator custom buttons
  388. }
  389. }).navGrid("#pagerPk",{edit:false,add:false,del:false,search:false,view:true},{},{},{},{},{});
  390. $("#lineItems").jqGrid('navButtonAdd','#pagerPk',{
  391. caption:"",
  392. title:"Receive Items",
  393. buttonicon:"ui-icon-newwin",
  394. id:"receive_lineItems",
  395. onClickButton : function () {
  396. //need to pass grid id for dynamic reload;
  397. var noOfRows = $("#lineItems").getGridParam("selarrrow").length;
  398. if (noOfRows == 1){
  399. var gridData ={'grid_id':'lineItems','order_line_id':$("#lineItems").getGridParam("selrow"),'action':'add','oper':'receive'}
  400. $( "#dialog-form-item" ).data('grid_data',gridData).dialog( "open" );
  401. $("#receiptOp").combobox();
  402. }
  403. else {
  404. $( "#modal-warning" ).dialog("open") ;
  405. }
  406. }
  407. });
  408. $("#lineItems").jqGrid('navButtonAdd','#pagerPk',{
  409. caption:"",
  410. title:"Return Items",
  411. buttonicon:"ui-icon-arrowreturnthick-1-w",
  412. id:"return_lineItems",
  413. onClickButton : function () {
  414. //need to pass grid id for dynamic reload;
  415. var noOfRows = $("#lineItems").getGridParam("selarrrow").length;
  416. if (noOfRows == 1){
  417. var gridData ={'grid_id':'lineItems','order_line_id':$("#lineItems").getGridParam("selrow"),'action':'add','oper':'return'}
  418. $( "#dialog-form-item" ).data('grid_data',gridData).dialog( "open" );
  419. $("#receiptOp").combobox();
  420. }
  421. else {
  422. $( "#modal-warning" ).dialog("open") ;
  423. }
  424. }
  425. });
  426. }
  427. });
  428. },
  429. close: function() {
  430. //allFields.val( "" ).removeClass( "ui-state-error"
  431. var receiving_notes = $("#receivingNotes").val();
  432. console.log(receiving_notes);
  433. $("#tabcache").val("0");
  434. $.ajax({url:"index.php/procurement/validateReceiving",
  435. type:"POST",
  436. data:{
  437. receiving_notes:$("#receivingNotes").val(),
  438. order_id: $("#orders").getGridParam('selrow')
  439. },
  440. success:function(response)
  441. {}
  442. }); //end ajax
  443. $("#quoteForm").data('validator').resetForm();
  444. $('#quoteForm')[0].reset();
  445. $("#lineItems").jqGrid("GridUnload");
  446. $("#tabs").tabs("destroy");
  447. $("#orders").trigger("reloadGrid");
  448. }
  449. });
  450. // Main Request For Quotation Grid
  451. var myGrid = $("#orders");
  452. myGrid.jqGrid({
  453. url:'index.php/procurement/populatePOToReceive',
  454. datatype: 'json',
  455. mtype: 'GET',
  456. colNames:['Reference','Supplier Id','Supplier','Estimated Value',/*'Owner',*/'Status','Raised By',/*'Owner',*/'Needed By Date'],
  457. colModel :[
  458. {name:'reference', index:'reference', width:80, align:'right',editable:false},
  459. {name:'supplier_id', index:'supplier_id',hidden:true},
  460. {name:'supplier_name', index:'supplier_name', width:140, align:'right',editable:false},
  461. {name:'estimated_value', index:'estimated_value', width:100, align:'right',editable:false,editoptions:{size:"20",maxlength:"30"}},
  462. // {name:'owner', index:'owner', width:140, align:'right',editable:true,editoptions:{size:"20",maxlength:"30"}},
  463. {name:'status', index:'status', width:60, align:'right',editable:false,editoptions:{size:"20",maxlength:"30"}},
  464. {name:'raised_by_name', index:'raised_by_name',editable:false, width:80, align:'right'},
  465. // {name:'owner_name', index:'owner_name',editable:false, width:80, align:'right'},
  466. {name:'needed_by_date', index:'needed_by_date',editable:false, width:120, sorttype:'date'}
  467. ],
  468. pager: '#pager',
  469. rowNum:10,
  470. rowList:[5,10,20],
  471. sortname: 'id',
  472. sortorder: 'desc',
  473. viewrecords: true,
  474. gridview: true,
  475. multiselect:true,
  476. ignoreCase:true,
  477. rownumbers:true,
  478. height:'auto',
  479. width:680,
  480. caption: 'Purchase Orders',
  481. jsonReader : {
  482. root:"quotedata",
  483. page: "page",
  484. total: "total",
  485. records: "records",
  486. cell: "dprow",
  487. id: "id"
  488. },
  489. subGrid:true,
  490. subGridRowExpanded: function(subgrid_id, row_id) {
  491. var subgrid_table_id, pager_id;
  492. subgrid_table_id = subgrid_id+"_t";
  493. pager_id = "p_"+subgrid_table_id;
  494. $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
  495. jQuery("#"+subgrid_table_id).jqGrid({
  496. url:'index.php/procurement/populateOrderItems?q=2&orderId='+row_id,
  497. datatype: 'json',
  498. colNames:['Product Id','Product','Quantity','Received','Returned','Need By Date','Unit Price','Estimated Value','Received Value','Returned Value','Notes'],
  499. colModel :[
  500. {name:'product_id', index:'product_id',editable:false, hidden:true},
  501. {name:'name', index:'name',editable:false, width:120, align:'right'},
  502. {name:'quoted_quantity', index:'quoted_quantity', editable:false,width:50, align:'right'},
  503. {name:'received_quantity', index:'received_quantity', editable:false,width:50, align:'right'},
  504. {name:'returned_quantity', index:'returned_quantity', editable:false,width:50, align:'right'},
  505. {name:'needed_by_date',index:'needed_by_date',editable:false, width:60, align:'right',hidden:true},
  506. {name:'expected_price',index:'expected_price',hidden:true, width:50, align:'right'},
  507. {name:'estimated_value', index:'estimated_value',editable:false, width:60, align:'right'},
  508. {name:'received_value', index:'received_value',editable:false, width:60, align:'right'},
  509. {name:'returned_value', index:'returned_value',editable:false, width:60, align:'right',hidden:true},
  510. {name:'comments', index:'comments',editable:false, width:160, align:'right'}
  511. ],
  512. rowNum:20,
  513. pager: pager_id,
  514. sortname: 'id',
  515. sortorder: "asc",
  516. height: '100%',
  517. jsonReader : {
  518. root:"orderitemdata",
  519. page: "page",
  520. total: "total",
  521. records: "records",
  522. cell: "dprow",
  523. id: "id"
  524. }
  525. });
  526. jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false,search:false,view:true});
  527. }
  528. }).navGrid("#pager",{edit:false,add:false,view:false,del:false,search:false},{height:280,reloadAfterSubmit:false,closeAfterEdit:true,recreateForm:true,checkOnSubmit:true},{},{},{},{});
  529. myGrid.jqGrid('navButtonAdd','#pager',{
  530. caption:"",
  531. title:"Match With Received Goods",
  532. buttonicon:"ui-icon-circle-check",
  533. id:"add_orders",
  534. onClickButton : function () {
  535. var selectRows = myGrid.getGridParam('selarrrow');
  536. var noOfRows = selectRows.length;
  537. if (noOfRows != 1){
  538. $( "#modal-warning" ).dialog("open");
  539. }
  540. else {
  541. $( "#dialog-form" ).dialog( "open" );
  542. }
  543. }
  544. });
  545. myGrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
  546. //$("#del_orders").insertAfter("#add_orders");
  547. //line item dialog
  548. $( "#dialog-form-item" ).dialog({
  549. autoOpen: false,
  550. height: 'auto',
  551. width: '35%',
  552. position:[450,25],
  553. modal: true,
  554. buttons: {
  555. "Done": {
  556. id:"processItems",
  557. text:"Confirm",
  558. click:function() {
  559. var isvalid = $("#itemForm").valid();
  560. var grid = $(this).data('grid_data').grid_id;
  561. var order_line_id = $(this).data('grid_data').order_line_id;
  562. var oper = $(this).data('grid_data').oper;
  563. var order_id = myGrid.getGridParam('selrow');
  564. //relevant only in case of edit
  565. var subgrid = $(this).data('grid_data').sub_grid_id;
  566. var receipt_line_id = $(this).data('grid_data').receipt_line_id;
  567. var action = $(this).data('grid_data').action;
  568. // by default assume action is "add"
  569. var total_received_quantity = parseInt($("#received_quantity").val())+parseInt($("#already_received").text());
  570. var total_received_value = parseFloat($("#received_value").val())+parseFloat($("#already_received_value").text());
  571. var total_returned_quantity=parseInt($("#returned_quantity").val())+parseInt($("#already_returned").text());
  572. var total_returned_value=parseFloat($("#returned_value").val())+parseFloat($("#already_returned_value").text());
  573. if (action=='edit'){
  574. //if (oper=='receive'){
  575. //subtract old received
  576. total_received_value = total_received_value - $("#"+subgrid).getCell(receipt_line_id,'received_value');
  577. total_received_quantity = total_received_quantity - $("#"+subgrid).getCell(receipt_line_id,'received_quantity');
  578. //}
  579. //else if (oper=='return'){
  580. //subtract old returned
  581. total_returned_value = total_returned_value - $("#"+subgrid).getCell(receipt_line_id,'returned_value');
  582. total_returned_quantity = total_returned_quantity - $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  583. //}
  584. }
  585. if (isvalid){
  586. $.ajax({
  587. url:"index.php/procurement/receiveItems",
  588. type:"POST",
  589. data:{
  590. order_id:order_id,
  591. order_line_id:order_line_id,
  592. product_id:$("#"+grid).getCell(order_line_id,'product_id'),
  593. supplier_id:myGrid.getCell(order_id,'supplier_id'),
  594. receipt:$("#receiptOp").val(),
  595. receipt_ip:$("#receiptOp-input").val(),
  596. total_received_quantity:total_received_quantity,
  597. received_value:$("#received_value").val(),
  598. total_received_value:total_received_value,
  599. received_quantity:$("#received_quantity").val(),
  600. quantity:parseInt($("#quantity").text()),
  601. returned_quantity:$("#returned_quantity").val(),
  602. returned_value:$("#returned_value").val(),
  603. total_returned_quantity:total_returned_quantity,
  604. total_returned_value:total_returned_value,
  605. receiving_notes:$("#receiving_notes").val(),
  606. returned_notes:$("#returned_notes").val(),
  607. oper:$("#oper").val(),
  608. action:$("#action").val()
  609. },
  610. success:function (response){
  611. //console.log("grid " + grid);
  612. $("#"+grid).trigger("reloadGrid");
  613. //reload Main Grid
  614. }
  615. })
  616. $( this ).dialog( "close" );
  617. }
  618. }},
  619. Cancel: function() {
  620. $( this ).dialog( "close" );
  621. }
  622. },
  623. open: function(event,ui){
  624. var grid = $(this).data('grid_data').grid_id;
  625. var order_line_id = $(this).data('grid_data').order_line_id;
  626. var oper = $(this).data('grid_data').oper;
  627. var order_id = myGrid.getGridParam('selrow');
  628. //relevant only in case of edit
  629. var subgrid = $(this).data('grid_data').sub_grid_id;
  630. var receipt_line_id = $(this).data('grid_data').receipt_line_id;
  631. var action = $(this).data('grid_data').action;
  632. $.ajax({
  633. url:"index.php/procurement/populateReceiptOptions",
  634. method:"get",
  635. data:{order_id:order_id},
  636. success : function (response){
  637. $("#receiptOp option").remove();
  638. var opts = '<option value="">Choose ';
  639. opts +=response;
  640. console.log(opts);
  641. $("#receiptOp").html(opts);
  642. if (action=="edit"){
  643. var selVal =$("#"+subgrid).getCell(receipt_line_id,'receipt_id') ;
  644. $("#receiptOp").val(selVal);
  645. $("#receiptOp").attr("disabled",true);
  646. }
  647. }
  648. })
  649. if (oper == "receive"){
  650. $("#received_quantity_cntnr,#received_value_cntnr,#receiving_notes_cntnr").show();
  651. $("#returned_quantity,#returned_value").val("0");
  652. //to be ignored by validation
  653. $("#returned_quantity,#returned_value").addClass("ignore-fields");
  654. $("#formHeaderItem").text("Receive Items");
  655. }
  656. else if (oper=="return"){
  657. $("#returned_quantity_cntnr,#returned_value_cntnr,#returned_notes_cntnr").show();
  658. $("#received_quantity,#received_value").val("0");
  659. //to be ignored by validation
  660. $("#received_quantity,#received_value").addClass("ignore-fields");
  661. $("#formHeaderItem").text("Return Items");
  662. }
  663. if (action=="edit"){
  664. $("#status-message-li").text("Warning!! You are about to edit earlier receive/return entry.This will \n\
  665. override previous entry. This is not for NEW entry.Use main grid buttons to add entries");
  666. $("#received_value").val($("#"+subgrid).getCell(receipt_line_id,'received_value'));
  667. $("#received_quantity").val($("#"+subgrid).getCell(receipt_line_id,'received_quantity'));
  668. //$("#receiving_notes").val($("#"+subgrid).getCell(receipt_line_id,'receiving_notes'));
  669. $("#returned_value").val($("#"+subgrid).getCell(receipt_line_id,'returned_value'));
  670. $("#returned_quantity").val($("#"+subgrid).getCell(receipt_line_id,'returned_quantity'));
  671. //$("#returned_notes").val($("#"+subgrid).getCell(receipt_line_id,'returned_notes'));
  672. // we need to store these for tally quantity validation
  673. $("#subgrid_ref").val(subgrid);
  674. $("#receipt_line_ref").val(receipt_line_id);
  675. }
  676. $("#oper").val(oper);
  677. $("#action").val(action);
  678. $("#product").text($("#"+grid).getCell(order_line_id,'name'));
  679. $("#neededdate").text($("#"+grid).getCell(order_line_id,'needed_by_date'));
  680. $("#quantity").text($("#"+grid).getCell(order_line_id,'quoted_quantity'));
  681. $("#already_received").text($("#"+grid).getCell(order_line_id,'received_quantity'));
  682. $("#already_returned").text($("#"+grid).getCell(order_line_id,'returned_quantity'));
  683. //$("#already_received").text(100);
  684. $("#orderprice").text($("#"+grid).getCell(order_line_id,'expected_price'));
  685. $("#estimated_value").text($("#"+grid).getCell(order_line_id,'estimated_value'));
  686. $("#already_received_value").text($("#"+grid).getCell(order_line_id,'received_value'));
  687. $("#already_returned_value").text($("#"+grid).getCell(order_line_id,'returned_value'));
  688. },
  689. close: function(event,ui) {
  690. $("#itemForm").data('validator').resetForm();
  691. $('#itemForm')[0].reset();
  692. $("#estValue").text("");
  693. $("#curPrice").text("");
  694. $("#status-message-li").empty();
  695. $("#received_quantity,#received_value,#returned_quantity,#returned_value").removeClass("ignore-fields");
  696. $("#received_quantity_cntnr,#received_value_cntnr,\n\
  697. #returned_quantity_cntnr,#returned_value_cntnr\n\
  698. ,#receiving_notes_cntnr,#returned_notes_cntnr").hide();
  699. $("#receiptOp").attr("disbled",false);
  700. //try to destroy only if action is not edit as we are not using this during edit action
  701. if ($(this).data('grid_data').action!='edit'){
  702. $("#receiptOp").combobox("destroy");
  703. }
  704. }
  705. });
  706. $( "#modal-warning" ).dialog({
  707. autoOpen:false,
  708. height: 80,
  709. modal: true
  710. });
  711. $("#received_value, #returned_value").change(function (){
  712. var ordered_quantity = parseInt($("#quantity").text());
  713. //
  714. var already_received = parseInt($("#already_received").text());
  715. var received_quantity = parseInt($("#received_quantity").val());
  716. var returned_quantity = parseInt($("#returned_quantity").val());
  717. // var subgrid=$("#subgrid_ref").val();
  718. // var receipt_line_id = $("#receipt_line_ref").val();
  719. // var action = $("#action").val();
  720. // var oper = $("#oper").val();
  721. // console.log("already_received" + already_received + "received_quantity" + received_quantity + "returned_quantity" + returned_quantity);
  722. var total_received = already_received + received_quantity + returned_quantity;
  723. if (action=='edit'){
  724. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'received_quantity')- $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  725. }
  726. //
  727. //
  728. // if (total_received>=ordered_quantity){
  729. var action = $("#action").val();
  730. var oper = $("#oper").val();
  731. var subgrid=$("#subgrid_ref").val();
  732. var receipt_line_id = $("#receipt_line_ref").val();
  733. var received = parseFloat($("#received_value").val());
  734. var returned = parseFloat($("#returned_value").val());
  735. var already_received_value = parseFloat($("#already_received_value").text());

Large files files are truncated, but you can click here to view the full file