PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/magehelp/application/views/procurement/purchaseorder/purchase_order_grid_b4.php

https://bitbucket.org/jit_bec/shopifine
PHP | 1256 lines | 1027 code | 172 blank | 57 comment | 52 complexity | fb525ef08dd156e979c4bd55c9224966 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:100%;
  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. font-size: 110%
  49. }
  50. .shopifine-output {
  51. float: right;
  52. width: 45%;
  53. word-wrap: break-word;
  54. font-weight:bold;
  55. }
  56. .ui-tabs {
  57. height: 80%;
  58. margin: 0 auto;
  59. width: 55%;
  60. left:0;
  61. }
  62. #notetab {
  63. height:30em;
  64. }
  65. #details {
  66. height:12em;
  67. }
  68. .ui-tabs-nav{
  69. height:22px;
  70. }
  71. .labeldiv {
  72. color: #2E6E9E;
  73. float: left;
  74. font-size: 110%;
  75. font-weight: bold;
  76. margin-right: .5em;
  77. width: 35%;
  78. word-wrap: break-word;
  79. }
  80. .valuediv {
  81. float: left;
  82. font-weight: bold;
  83. width: 45%;
  84. word-wrap: break-word;
  85. }
  86. label.error {
  87. width:8em ;
  88. margin-right: 0;
  89. }
  90. #status-message-li{
  91. color: red;
  92. font-size: 110%;
  93. font-style: italic;
  94. margin: 0 auto;
  95. width: 80%;
  96. }
  97. .help-message-left{
  98. color: green;
  99. font-size: 90%;
  100. font-style: italic;
  101. margin: 0 auto;
  102. width: 90%;
  103. float:left
  104. }
  105. .single-column-row{
  106. margin-left:0;
  107. }
  108. </style>
  109. <script type="text/javascript">
  110. $(function() {
  111. $.validator.addMethod('comboBoxrequired', function(value, element) {
  112. var selectId = element.id;
  113. var inputIdSelector = "#" + selectId + "-input";
  114. if (value == ""){
  115. inputVal = $(inputIdSelector).val();
  116. if (inputVal == "" || inputVal == null){
  117. return false;
  118. }
  119. }
  120. return true;
  121. }, 'Please select from the dropdown or add new element in box');
  122. $.validator.addMethod("threshold", function(value, element, params) {
  123. console.log("param"+ params + $(params).text());
  124. var hi = typeof params == "string" ?
  125. parseFloat($(params).text(), 10) :
  126. params;
  127. if (hi===""){
  128. hi=1;
  129. }
  130. console.log("limit"+hi);
  131. params=hi;
  132. if (isNaN(hi))
  133. return true;
  134. else
  135. return parseInt(value) >= hi;
  136. }, $.validator.format("{1} Can Not Be Less Than Than {0},The {1} Already in Partpayment Process "));
  137. $.validator.addMethod('lessthanallowednotdelivered', function (value, element, param) {
  138. var order_line_id= $("#order_line_ref_cnbd").val();
  139. var ordered = 0;
  140. if (order_line_id!=""){
  141. var already_received = parseInt($("#lineItems").getCell(order_line_id,'received_quantity'));
  142. var already_returned = parseInt($("#lineItems").getCell(order_line_id,'returned_quantity'));
  143. ordered = parseInt($("#lineItems").getCell(order_line_id,'quoted_quantity'));
  144. var total = already_received+already_returned + value;
  145. console.log("tital = " + total);
  146. if (total>ordered){
  147. return false;
  148. }
  149. }
  150. return true;
  151. },"{0} Quantity Can Not Be More Than Total Ordered For This Line Item");
  152. $.validator.addMethod('tallyquantity', function(value, element) {
  153. var ordered_quantity = parseInt($("#quantity").text());
  154. var already_received = parseInt($("#already_received").text());
  155. var already_returned = parseInt($("#already_returned").text());
  156. var undelivered = parseInt($("#cnbd_quantity").text());
  157. var received_quantity = parseInt($("#received_quantity").val());
  158. var returned_quantity = parseInt($("#returned_quantity").val());
  159. var subgrid=$("#subgrid_ref").val();
  160. var receipt_line_id = $("#receipt_line_ref").val();
  161. var action = $("#action").val();
  162. var oper = $("#oper").val();
  163. console.log("already_received" + already_received + "received_quantity" + received_quantity + "returned_quantity" + returned_quantity);
  164. var total_received = already_received + already_returned + undelivered + received_quantity + returned_quantity;
  165. if (action=='edit'){
  166. // for edit actionold values need to be subtracted
  167. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'received_quantity')
  168. //}
  169. //else if (oper=="return"){
  170. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  171. //}
  172. }
  173. // console.log("total_received/returned/notdelivered" + total_received);
  174. // console.log("ordered_quantity" + ordered_quantity);
  175. if (total_received>ordered_quantity){
  176. return false;
  177. }
  178. return true;
  179. }, 'Total Received And Returned Can Not Be More Than Ordered');
  180. //form validation
  181. $("#quoteForm").validate();
  182. $("#cnbdItemForm").validate({
  183. rules:{
  184. cnbd_qty:{
  185. required:true,
  186. digits:true,
  187. min:1,
  188. lessthanallowednotdelivered:"Sum of Received/Returned/Not Delivered "
  189. }
  190. }
  191. });
  192. $("#itemForm").validate({
  193. ignore:".ignore-fields",
  194. rules:{
  195. received_quantity:{
  196. required:true,
  197. //noBlank:true,
  198. digits:true,
  199. min:1//,
  200. //threshold:'#pp_quantity_receipt'
  201. },
  202. received_value:{
  203. required:true,
  204. //noBlank:true,
  205. number:true,
  206. minStrict:0//,
  207. //threshold:'#pp_amount_receipt'
  208. },
  209. returned_quantity:{
  210. required:true,
  211. //noBlank:true,
  212. digits:true,
  213. min:1
  214. },
  215. returned_value:{
  216. required:true,
  217. //noBlank:true,
  218. number:true,
  219. minStrict:0
  220. },
  221. vat:{
  222. required:true,
  223. number:true,
  224. minStrict:0
  225. }
  226. }
  227. }
  228. );
  229. $("#paymentForm").validate({rules:{
  230. amount:{
  231. required:true,
  232. number:true,
  233. minStrict:0
  234. }
  235. }}
  236. );
  237. // datepicker for Add Form
  238. $( "#expiry_date" ).datepicker({
  239. showOn: "button",
  240. buttonImage: "images/calendar.gif",
  241. buttonImageOnly: true,
  242. dateFormat:"dd/mm/yy",
  243. minDate:0
  244. });
  245. function quotegriddates(id){
  246. jQuery("#"+id+"_needed_by_date","#orders").datepicker({dateFormat:"yy-mm-dd",minDate:0});
  247. }
  248. //end datepicker
  249. var myGridPkd = $("#lineItems");
  250. $( "#dialog-form" ).dialog({
  251. autoOpen: false,
  252. height: 'auto',
  253. width: '70%',
  254. position:[220,25],
  255. modal: true,
  256. buttons: {
  257. "DoneButton": {
  258. id:"doneBtn",
  259. text:"Done",
  260. click:function() {
  261. var isValid = $("#quoteForm").valid();
  262. if (isValid){
  263. $( this ).dialog( "close" );
  264. } //end ifvalid
  265. }}, //end of Create button
  266. Cancel: function() {
  267. //in cancel just recset notes
  268. $("#receivingNotes").val("");
  269. $( this ).dialog( "close" );
  270. }
  271. },//end buttons
  272. open: function(){
  273. $( "#tabs" ).tabs({
  274. //cache
  275. beforeLoad: function( event, ui ) {
  276. var tabcache = $("#tabcache").val();
  277. if (tabcache==1){
  278. if ( ui.tab.data( "loaded" ) ) {
  279. event.preventDefault();
  280. return;
  281. }
  282. ui.jqXHR.success(function() {
  283. ui.tab.data( "loaded", true );
  284. });
  285. }
  286. },
  287. beforeActivate: function (event,ui){
  288. if (ui.oldTab[0].id=="notesLink"){
  289. $("#tabcache").val("1");
  290. }
  291. },
  292. load: function(event,ui){
  293. $.ajax({
  294. method:"POST",
  295. url:'index.php/procurement/getOrderDetails',
  296. data:{orderId: myGrid.getGridParam('selrow')},
  297. success:function(response){
  298. //console.log(response);
  299. var resJson = JSON.parse(response);
  300. //console.log(resJson);
  301. $("#orderRef").text(resJson.reference);
  302. $("#supplierOP").text(resJson.supplier_name);
  303. $("#warehouseOP").text(resJson.warehouse);
  304. $("#quoteOP").text(resJson.quote_reference);
  305. $("#raisedByOP").text(resJson.raised_by_name);
  306. $("#approvedByOP").text(resJson.approved_by_name);
  307. $("#estValueOP").text(resJson.estimated_value);
  308. $("#receivingNotes").val(resJson.receiving_notes);
  309. //$("#receivingNotes").val("abcc");
  310. }
  311. });
  312. var settingsObj ={grid_id:'lineItems',pager:'pagerPk',multiselect:true};
  313. var subgridSettingsObj = {customButtons:{edit_received:true,edit_returned:true,columnchooser:true}};
  314. prepareOrderItemsGrid(settingsObj,{orderId: myGrid.getGridParam('selrow')},true,{},{needed_by_date:true,expected_price:true,comments:true},subgridSettingsObj)
  315. $("#lineItems").navGrid("#pagerPk",{edit:false,add:false,del:false,search:false,view:true},{},{},{},{},{});
  316. addCustomButtonsToOrderItemGrid('lineItems','pagerPk');
  317. var order_id = myGrid.getGridParam('selrow');
  318. var settingsObj ={grid_id:'payments',pager:'pagerPayments'};
  319. var postData={orderId: order_id,type:'advance'};
  320. preparePaymentsGrid(settingsObj,postData);
  321. $("#payments").navGrid("#pagerPayments",{edit:false,add:false,del:false,search:false,view:true},{},{},{},{},{});
  322. var btns = {add:true,edit:true,data:{type:'advance',order_id:order_id}};
  323. addCustomButtonsInPaymentsGrid('payments','pagerPayments',null,btns);
  324. $("#payments").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
  325. }
  326. });
  327. },
  328. close: function() {
  329. $("#tabcache").val("0");
  330. $.ajax({url:"index.php/procurement/validateReceiving",
  331. type:"POST",
  332. data:{
  333. receiving_notes:$("#receivingNotes").val(),
  334. order_id: $("#orders").getGridParam('selrow')
  335. },
  336. success:function(response)
  337. {}
  338. }); //end ajax
  339. $("#quoteForm").data('validator').resetForm();
  340. $('#quoteForm')[0].reset();
  341. $("#lineItems").jqGrid("GridUnload");
  342. $("#tabs").tabs("destroy");
  343. $("#orders").trigger("reloadGrid");
  344. }
  345. });
  346. // Main Request For Quotation Grid
  347. var myGrid = $("#orders");
  348. myGrid.jqGrid({
  349. url:'index.php/procurement/populatePOToReceive',
  350. datatype: 'json',
  351. mtype: 'GET',
  352. colNames:['Reference','Supplier Id','Supplier','Estimated Value',/*'Owner',*/'Status','Raised By',/*'Owner',*/'Needed By Date'],
  353. colModel :[
  354. {name:'reference', index:'reference', width:80, align:'right',editable:false},
  355. {name:'supplier_id', index:'supplier_id',hidden:true},
  356. {name:'supplier_name', index:'supplier_name', width:140, align:'right',editable:false},
  357. {name:'estimated_value', index:'estimated_value', width:100, align:'right',editable:false,editoptions:{size:"20",maxlength:"30"}},
  358. // {name:'owner', index:'owner', width:140, align:'right',editable:true,editoptions:{size:"20",maxlength:"30"}},
  359. {name:'status', index:'status', width:60, align:'right',editable:false,editoptions:{size:"20",maxlength:"30"}},
  360. {name:'raised_by_name', index:'raised_by_name',editable:false, width:80, align:'right'},
  361. // {name:'owner_name', index:'owner_name',editable:false, width:80, align:'right'},
  362. {name:'needed_by_date', index:'needed_by_date',editable:false, width:120, sorttype:'date'}
  363. ],
  364. pager: '#pager',
  365. rowNum:10,
  366. rowList:[5,10,20],
  367. sortname: 'id',
  368. sortorder: 'desc',
  369. viewrecords: true,
  370. gridview: true,
  371. multiselect:true,
  372. ignoreCase:true,
  373. rownumbers:true,
  374. height:'auto',
  375. width:680,
  376. caption: 'Purchase Orders',
  377. jsonReader : {
  378. root:"quotedata",
  379. page: "page",
  380. total: "total",
  381. records: "records",
  382. cell: "dprow",
  383. id: "id"
  384. },
  385. subGrid:true,
  386. subGridRowExpanded: function(subgrid_id, row_id) {
  387. var subgrid_table_id, pager_id;
  388. subgrid_table_id = subgrid_id+"_t";
  389. pager_id = "p_"+subgrid_table_id;
  390. $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
  391. var settingsObj ={grid_id:subgrid_table_id,pager:pager_id};
  392. prepareOrderItemsGrid(settingsObj,{orderId:row_id},false,{},{needed_by_date:true,returned_value:true});
  393. $("#"+subgrid_table_id).navGrid("#"+pager_id,{edit:false,add:false,del:false,search:false,view:true},{},{},{},{},{});
  394. }
  395. }).navGrid("#pager",{edit:false,add:false,view:false,del:false,search:false},{height:280,reloadAfterSubmit:false,closeAfterEdit:true,recreateForm:true,checkOnSubmit:true},{},{},{},{});
  396. myGrid.jqGrid('navButtonAdd','#pager',{
  397. caption:"",
  398. title:"Match With Received Goods",
  399. buttonicon:"ui-icon-newwin",
  400. id:"add_orders",
  401. onClickButton : function () {
  402. var selectRows = myGrid.getGridParam('selarrrow');
  403. var noOfRows = selectRows.length;
  404. if (noOfRows != 1){
  405. $( "#modal-warning-one" ).dialog("open");
  406. }
  407. else {
  408. $( "#dialog-form" ).dialog( "open" );
  409. }
  410. }
  411. });
  412. myGrid.jqGrid('navButtonAdd','#pager',{
  413. caption:"",
  414. title:"Ready For Invoice",
  415. buttonicon:"ui-icon-tag",
  416. id:"ready_orders",
  417. onClickButton : function () {
  418. var selectRows = myGrid.getGridParam('selarrrow');
  419. var noOfRows = selectRows.length;
  420. var mismatch = 0;
  421. if (noOfRows == 0){
  422. $( "#modal-warning-none" ).dialog("open");
  423. }
  424. else {
  425. for (i=0;i<noOfRows;i++){
  426. //console.log(selectRows[i]);
  427. var status = myGrid.getCell(selectRows[i],'status');
  428. if (status!='received'){
  429. $( "#modal-warning-status" ).dialog("open");
  430. mismatch = 1;
  431. break;
  432. }
  433. }
  434. if (mismatch==0){
  435. $( "#dialog-confirm" ).dialog( "open" );
  436. }
  437. }
  438. }
  439. });
  440. myGrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
  441. //line item dialog
  442. $( "#dialog-form-item" ).dialog({
  443. autoOpen: false,
  444. height: 'auto',
  445. width: '60%',
  446. position:[250,25],
  447. modal: true,
  448. buttons: {
  449. "Done": {
  450. id:"processItems",
  451. text:"Confirm",
  452. click:function() {
  453. var isvalid = $("#itemForm").valid();
  454. var grid = $(this).data('grid_data').grid_id;
  455. var order_line_id = $(this).data('grid_data').order_line_id;
  456. var oper = $(this).data('grid_data').oper;
  457. var url = $(this).data('grid_data').url;
  458. var order_id = myGrid.getGridParam('selrow');
  459. //relevant only in case of edit
  460. var subgrid = $(this).data('grid_data').sub_grid_id;
  461. var receipt_line_id = $(this).data('grid_data').receipt_line_id;
  462. var action = $(this).data('grid_data').action;
  463. // by default assume action is "add"
  464. var total_received_quantity = parseInt($("#received_quantity").val())+parseInt($("#already_received").text());
  465. var total_received_value = parseFloat($("#received_value").val())+parseFloat($("#already_received_value").text());
  466. var total_returned_quantity=parseInt($("#returned_quantity").val())+parseInt($("#already_returned").text());
  467. var total_returned_value=parseFloat($("#returned_value").val())+parseFloat($("#already_returned_value").text());
  468. if (action=='edit'){
  469. //if (oper=='receive'){
  470. //subtract old received
  471. total_received_value = total_received_value - $("#"+subgrid).getCell(receipt_line_id,'received_value');
  472. total_received_quantity = total_received_quantity - $("#"+subgrid).getCell(receipt_line_id,'received_quantity');
  473. //}
  474. //else if (oper=='return'){
  475. //subtract old returned
  476. total_returned_value = total_returned_value - $("#"+subgrid).getCell(receipt_line_id,'returned_value');
  477. total_returned_quantity = total_returned_quantity - $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  478. //}
  479. }
  480. if (isvalid){
  481. $.ajax({
  482. url:url,
  483. type:"POST",
  484. data:{
  485. order_id:order_id,
  486. order_line_id:order_line_id,
  487. product_id:$("#"+grid).getCell(order_line_id,'product_id'),
  488. supplier_id:myGrid.getCell(order_id,'supplier_id'),
  489. receipt:$("#receiptOp").val(),
  490. receipt_ip:$("#receiptOp-input").val(),
  491. receipt_line_id:receipt_line_id,
  492. vat:$("#vat").val(),
  493. expiry_date:$("#expiry_date").val(),
  494. batch_number:$("#batch_number").val(),
  495. total_received_quantity:total_received_quantity,
  496. received_value:$("#received_value").val(),
  497. total_received_value:total_received_value,
  498. received_quantity:$("#received_quantity").val(),
  499. quantity:parseInt($("#quantity").text()),
  500. returned_quantity:$("#returned_quantity").val(),
  501. returned_value:$("#returned_value").val(),
  502. cnbd_quantity : parseInt($("#cnbd_quantity").text()),
  503. total_returned_quantity:total_returned_quantity,
  504. total_returned_value:total_returned_value,
  505. receiving_notes:$("#receiving_notes").val(),
  506. returned_notes:$("#returned_notes").val(),
  507. oper:$("#oper").val(),
  508. action:$("#action").val()
  509. },
  510. success:function (response){
  511. //console.log("grid " + grid);
  512. $("#"+grid).trigger("reloadGrid");
  513. //reload Main Grid
  514. }
  515. })
  516. $( this ).dialog( "close" );
  517. }
  518. }},
  519. Cancel: function() {
  520. $( this ).dialog( "close" );
  521. }
  522. },
  523. open: function(event,ui){
  524. var grid = $(this).data('grid_data').grid_id;
  525. var order_line_id = $(this).data('grid_data').order_line_id;
  526. var oper = $(this).data('grid_data').oper;
  527. var order_id = myGrid.getGridParam('selrow');
  528. //relevant only in case of edit
  529. var subgrid = $(this).data('grid_data').sub_grid_id;
  530. var receipt_line_id = $(this).data('grid_data').receipt_line_id;
  531. var action = $(this).data('grid_data').action;
  532. $.ajax({
  533. url:"index.php/procurement/populateReceiptOptions",
  534. method:"get",
  535. data:{order_id:order_id},
  536. success : function (response){
  537. $("#receiptOp option").remove();
  538. var opts = '<option value="">Choose ';
  539. opts +=response;
  540. $("#receiptOp").html(opts);
  541. if (action=="edit"){
  542. var selVal =$("#"+subgrid).getCell(receipt_line_id,'receipt_id') ;
  543. $("#receiptOp").val(selVal);
  544. $("#receiptOp").attr("disabled",true);
  545. }
  546. }
  547. })
  548. if (oper == "receive"){
  549. $("#received_quantity_cntnr,#received_value_cntnr,#receiving_notes_cntnr").show();
  550. $("#returned_quantity,#returned_value").val("0");
  551. //to be ignored by validation
  552. $("#returned_quantity,#returned_value").addClass("ignore-fields");
  553. $("#formHeaderItem").text("Receive Items");
  554. }
  555. else if (oper=="return"){
  556. $("#returned_quantity_cntnr,#returned_value_cntnr,#returned_notes_cntnr").show();
  557. $("#received_quantity,#received_value").val("0");
  558. //to be ignored by validation
  559. $("#received_quantity,#received_value").addClass("ignore-fields");
  560. $("#formHeaderItem").text("Return Items");
  561. }
  562. if (action=="edit"){
  563. $("#status-message-li").text("Warning!! You are about to edit earlier receive/return entry.This will \n\
  564. override previous entry. This is not for NEW entry.Use main grid buttons to add entries");
  565. $("#received_value").val($("#"+subgrid).getCell(receipt_line_id,'received_value'));
  566. $("#received_quantity").val($("#"+subgrid).getCell(receipt_line_id,'received_quantity'));
  567. $("#returned_value").val($("#"+subgrid).getCell(receipt_line_id,'returned_value'));
  568. $("#returned_quantity").val($("#"+subgrid).getCell(receipt_line_id,'returned_quantity'));
  569. var expDate = $("#"+subgrid).getCell(receipt_line_id,'expiry_date');
  570. if (expDate!=null && expDate!=""){
  571. var d1 = Date.parse(expDate);
  572. $("#expiry_date").val(d1.toString('dd/MM/yyyy'));
  573. }
  574. $("#batch_number").val($("#"+subgrid).getCell(receipt_line_id,'batch_number'));
  575. $("#vat").val($("#"+subgrid).getCell(receipt_line_id,'vat'));
  576. var pp_qty = parseInt($("#"+subgrid).getCell(receipt_line_id,'pp_quantity'));
  577. $("#autogen-batch,#batch-help").hide();
  578. if (pp_qty>0){
  579. $("#pp_cntnr").show();
  580. var pp_amt = $("#"+subgrid).getCell(receipt_line_id,'pp_value');
  581. $("#pp_amount_receipt").text(pp_amt);
  582. $("#pp_quantity_receipt").text(pp_qty);
  583. $("#received_quantity").rules("add", {
  584. threshold: '#pp_quantity_receipt',
  585. messages: {
  586. threshold: $.format("Quantity Can Not Be Less Than "+ pp_qty + ",The Quantity Already in Partpayment Process ")
  587. }
  588. });
  589. $("#received_value").rules("add", {
  590. threshold: '#pp_amount_receipt',
  591. messages: {
  592. threshold: $.format("Amount Can Not Be Less Than Than "+ pp_amt+ ",The Amount Already in Partpayment Process ")
  593. }
  594. });
  595. }
  596. // we need to store these for tally quantity validation
  597. $("#subgrid_ref").val(subgrid);
  598. $("#receipt_line_ref").val(receipt_line_id);
  599. }
  600. console.log($("#"+grid).getCell(order_line_id,'cnbd_quantity'));
  601. $("#cnbd_quantity").text($("#"+grid).getCell(order_line_id,'cnbd_quantity'));
  602. $("#oper").val(oper);
  603. $("#action").val(action);
  604. $("#product").text($("#"+grid).getCell(order_line_id,'name'));
  605. $("#neededdate").text($("#"+grid).getCell(order_line_id,'needed_by_date'));
  606. $("#quantity").text($("#"+grid).getCell(order_line_id,'quoted_quantity'));
  607. $("#already_received").text($("#"+grid).getCell(order_line_id,'received_quantity'));
  608. $("#already_returned").text($("#"+grid).getCell(order_line_id,'returned_quantity'));
  609. $("#pp_quantity").text($("#"+grid).getCell(order_line_id,'pp_quantity'));
  610. $("#pp_value").text($("#"+grid).getCell(order_line_id,'pp_value'));
  611. //$("#already_received").text(100);
  612. $("#orderprice").text($("#"+grid).getCell(order_line_id,'expected_price'));
  613. $("#estimated_value").text($("#"+grid).getCell(order_line_id,'estimated_value'));
  614. $("#already_received_value").text($("#"+grid).getCell(order_line_id,'received_value'));
  615. $("#already_returned_value").text($("#"+grid).getCell(order_line_id,'returned_value'));
  616. },
  617. close: function(event,ui) {
  618. $("#itemForm").data('validator').resetForm();
  619. $('#itemForm')[0].reset();
  620. $("#estValue,#pp_quantity_receipt,#pp_amount_receipt").text("");
  621. $("#curPrice").text("");
  622. $("#status-message-li").empty();
  623. $("#received_quantity,#received_value,#returned_quantity,#returned_value").removeClass("ignore-fields");
  624. $("#received_quantity_cntnr,#received_value_cntnr,\n\
  625. #returned_quantity_cntnr,#returned_value_cntnr\n\
  626. ,#receiving_notes_cntnr,#returned_notes_cntnr").hide();
  627. $(".inithide").hide();
  628. $("#autogen-batch,#batch-help").show();
  629. $("#receiptOp").attr("disbled",false);
  630. $("#received_quantity,#received_value").rules("remove", "threshold");
  631. //try to destroy only if action is not edit as we are not using this during edit action
  632. if ($(this).data('grid_data').action!='edit'){
  633. $("#receiptOp").combobox("destroy");
  634. }
  635. }
  636. });
  637. $( "#dialog-form-cnbd" ).dialog({
  638. autoOpen: false,
  639. height: 'auto',
  640. width: '35%',
  641. position:[450,25],
  642. modal: true,
  643. buttons: {
  644. "Done": {
  645. id:"processItems",
  646. text:"Register",
  647. click:function() {
  648. var isvalid = $("#cnbdItemForm").valid();
  649. var grid = $(this).data('grid_data').grid_id;
  650. var order_line_id = $(this).data('grid_data').order_line_id;
  651. if (isvalid){
  652. $.ajax({
  653. url:'index.php/procurement/registerUndelivered',
  654. type:"POST",
  655. data:{
  656. order_line_id:order_line_id,
  657. cnbd_quantity:$("#cnbd_qty").val(),
  658. received_quantity:$("#"+grid).getCell(order_line_id,'received_quantity'),
  659. returned_quantity:$("#"+grid).getCell(order_line_id,'returned_quantity'),
  660. ordered_quantity:$("#"+grid).getCell(order_line_id,'quoted_quantity'),
  661. cnbd_notes:$("#cnbd_notes").val()
  662. },
  663. success:function (response){
  664. //console.log("grid " + grid);
  665. $("#"+grid).trigger("reloadGrid");
  666. }
  667. })
  668. $( this ).dialog( "close" );
  669. }
  670. }},
  671. Cancel: function() {
  672. $( this ).dialog( "close" );
  673. }
  674. },
  675. open: function(event,ui){
  676. var grid = $(this).data('grid_data').grid_id;
  677. var order_line_id = $(this).data('grid_data').order_line_id;
  678. var oper = $(this).data('grid_data').oper;
  679. console.log("cnbd" + $("#"+grid).getCell(order_line_id,'cnbd_quantity'));
  680. $("#order_line_ref_cnbd").val(order_line_id);
  681. $("#cnbd_qty").val($("#"+grid).getCell(order_line_id,'cnbd_quantity'));
  682. },
  683. close: function(event,ui) {
  684. $("#cnbdItemForm").data('validator').resetForm();
  685. $('#cnbdItemForm')[0].reset();
  686. $("#status-message-li-cnbd").empty();
  687. //try to destroy only if action is not edit as we are not using this during edit action
  688. if ($(this).data('grid_data').action!='edit'){
  689. $("#receiptOp").combobox("destroy");
  690. }
  691. }
  692. });
  693. $("#received_value, #returned_value").change(function (){
  694. var ordered_quantity = parseInt($("#quantity").text());
  695. //
  696. var already_received = parseInt($("#already_received").text());
  697. var already_returned = parseInt($("#already_returned").text());
  698. var cnbd_quantity = parseInt($("#cnbd_quantity").text());
  699. var received_quantity = parseInt($("#received_quantity").val());
  700. var returned_quantity = parseInt($("#returned_quantity").val());
  701. var total_received = already_received + already_returned + cnbd_quantity+ received_quantity + returned_quantity;
  702. if (action=='edit'){
  703. if (returned_quantity>0){
  704. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'returned_quantity');
  705. }
  706. else if (received_quantity>0){
  707. total_received = total_received - $("#"+subgrid).getCell(receipt_line_id,'received_quantity');
  708. }
  709. }
  710. //
  711. //
  712. // if (total_received>=ordered_quantity){
  713. var action = $("#action").val();
  714. var oper = $("#oper").val();
  715. var subgrid=$("#subgrid_ref").val();
  716. var receipt_line_id = $("#receipt_line_ref").val();
  717. var received = parseFloat($("#received_value").val());
  718. var returned = parseFloat($("#returned_value").val());
  719. var already_received_value = parseFloat($("#already_received_value").text());
  720. var estimated = parseFloat($("#estimated_value").text());
  721. var total = already_received_value + received + returned;
  722. console.log("already_received val " + already_received_value + "received_val" + received + "returned_val" + returned);
  723. if (action=='edit'){
  724. total = total - $("#"+subgrid).getCell(receipt_line_id,'received_value')- $("#"+subgrid).getCell(receipt_line_id,'returned_value');
  725. }
  726. console.log(total);
  727. var unit_price = total/total_received;
  728. var order_init_price = parseFloat($("#orderprice").text());
  729. if (unit_price>order_init_price){
  730. $("#status-message-li").text("Warning!! Current Unit Price Of Received/Returned Goods > Ordered");
  731. }
  732. else if (unit_price<order_init_price){
  733. $("#status-message-li").text("Warning!! Current Unit Price Of Received/Returned Goods < Ordered");
  734. }
  735. else {
  736. $("#status-message-li").empty();
  737. }
  738. //}
  739. });
  740. $( "#dialog-confirm" ).dialog({
  741. resizable: false,
  742. height:200,
  743. width:500,
  744. modal: true,
  745. autoOpen:false,
  746. buttons: {
  747. "I Am Sure": function() {
  748. $.ajax({
  749. url:"index.php/procurement/markForInvoicing",
  750. type:"POST",
  751. data:{orderIds:myGrid.getGridParam('selarrrow')
  752. },
  753. success:function (response){
  754. emptyMessages();
  755. showSuccessMessage("The Selected Orders Are Now Ready To Invoice")
  756. myGrid.trigger("reloadGrid");
  757. },
  758. error:function (response){
  759. emptyMessages();
  760. showErrorMessage("The Selected Orders Could Not Be Processed Due To Internal Error")
  761. }
  762. });
  763. $( this ).dialog( "close" );
  764. },
  765. Cancel: function() {
  766. $( this ).dialog( "close" );
  767. }
  768. }
  769. });
  770. $("#autogen-batch").change(
  771. function (){
  772. if (this.checked){
  773. $("#batch_number").removeClass("required");
  774. }
  775. else {
  776. $("#batch_number").addClass("required");
  777. }
  778. }
  779. );
  780. });
  781. $(window).load(function(){
  782. var warningDialogs={one:true,none:true,status:true};
  783. initDialogs(warningDialogs);
  784. initPaymentDialog();
  785. //initErrorDialogs({total:true,advance:true});
  786. //this is from payment dialog.The Select Inout is in dialogs.php
  787. });
  788. </script>
  789. </head>
  790. <body>
  791. <?php $this->load->view("common/menubar"); ?>
  792. <?php $this->load->view("common/dialogs"); ?>
  793. <div id="dialog-confirm" title="Warning">
  794. <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
  795. Once Marked As "Ready For Invoice" Signifies All The Items For This Order Are
  796. Dispatched By The Supplier And Marked As Received/Returned.
  797. # Of Returned And Received Quantities Can Be Edited ONLY If REJECTED In Due Approval Process But Total Quantity Should Always Match Ordered.Are You Sure?</p>
  798. </div>
  799. <div id ="dialog-form">
  800. <h1 id="formHeader">Purchase Order # <span id="orderRef"></span> Details</h1>
  801. <form id="quoteForm">
  802. <fieldset>
  803. <div id="tabs">
  804. <ul>
  805. <li id="baseLink"><a id="basic" href="<?php echo site_url('procurement/loadFormFragment') ?>">Basic Details</a></li>
  806. <li id="notesLink"><a id="notes" href="<?php echo site_url('procurement/loadNotesFragment') ?>">Notes</a></li>
  807. </ul>
  808. </div>
  809. </fieldset>
  810. </form>
  811. <div class="table-grid" style="padding-top:2em;">
  812. <h1 id="pkdheader_item">Line Items For This Purchase Order</h1>
  813. <table id="lineItems"><tr><td/></tr></table>
  814. <div id="pagerPk"></div>
  815. </div>
  816. <div class="table-grid" style="padding-top:2em;">
  817. <h1 id="pkdheader_advance">Manage Advance Payments</h1>
  818. <table id="payments"><tr><td/></tr></table>
  819. <div id="pagerPayments"></div>
  820. </div>
  821. </div>
  822. <div style="display: block;height: 100%;" class="shopifine-ui-dialog ui-widget ui-widget-content ui-corner-all" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog-form">
  823. <?php $this->load->view("common/message"); ?>
  824. <div class="table-grid">
  825. <h1 id="table header">Open Purchase Orders</h1>
  826. <table id="orders"><tr><td/></tr></table>
  827. <div id="pager"></div>
  828. </div>
  829. </div>
  830. <div id ="dialog-form-item">
  831. <div id ="status-message-li" class="ui-corner-all">
  832. </div>
  833. <h1 id="formHeaderItem">Receive Items <div id="neededdate" name ="neededdate" style="float:right;color:green;font-style: italic;text-decoration: underline" ></div></h1>
  834. <form id="itemForm">
  835. <fieldset style="border:1px solid #A6C9E2">
  836. <legend style="color: #2E6E9E;font-size: 110%;font-weight: bold;margin-left: 15px;">
  837. Order Line Related Info </legend>
  838. <div class="row">
  839. <div class="column">
  840. <div class="field">
  841. <div class="labeldiv">Products:</div>
  842. <div class="valuediv" id="product" name ="product" class="required"></div>
  843. </div>
  844. </div>
  845. <div class="column">
  846. <div class="field">
  847. <div class="labeldiv">Unit Price:</div>
  848. <div class="valuediv" id="orderprice" name="orderprice" ></div>
  849. </div>
  850. </div>
  851. </div>
  852. <div class="row">
  853. <div class="column">
  854. <div class="field">
  855. <div class="labeldiv">Ordered Quantity:</div>
  856. <div class="valuediv" name="quantity" id="quantity" ></div>
  857. </div>
  858. </div>
  859. <div class="column">
  860. <div class="field">
  861. <div class="labeldiv">Ordered Value :</div>
  862. <div class="valuediv" id="estimated_value" name="estimated_value" ></div>
  863. </div>
  864. </div>
  865. </div>
  866. <div class="row">
  867. <div class="column">
  868. <div class="field">
  869. <div class="labeldiv">Received Quantity Till Date:</div>
  870. <div class="valuediv" name="already_received" id="already_received" ></div>
  871. <div id ="return-help" class="ui-corner-all help-message-left">
  872. (Ready For Payment Subject To Appropriate Approval)
  873. </div>
  874. </div>
  875. </div>
  876. <div class="column">
  877. <div class="field">
  878. <div class="labeldiv">Received Value Till Date:</div>
  879. <div class="valuediv" id="already_received_value" name="already_received_value" ></div>
  880. <div id ="return-help" class="ui-corner-all help-message-left">
  881. (Payment Amount Subject To Appropriate Approval)
  882. </div>
  883. </div>
  884. </div>
  885. </div>
  886. <div class="row">
  887. <div class="column">
  888. <div class="field">
  889. <div class="labeldiv">Quantity In Part Payment Process:</div>
  890. <div class="valuediv" name="pp_quantity" id="pp_quantity" ></div>
  891. <div id ="pp_quantity-help" class="ui-corner-all help-message-left">

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