Guest User

orders8.hpp

a guest
Dec 16th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.86 KB | None | 0 0
  1. <?php
  2.  
  3. include 'home.php';
  4.  
  5. $is_admin = false;
  6. $user_home = new USER();
  7.  
  8. /* test */
  9.  
  10. $servername = "localhost";
  11. $username = "root";
  12. $password = "Outthinking123@";
  13. $dbname = "designer6";
  14.  
  15. // Create connection
  16. $conn = new mysqli($servername, $username, $password, $dbname);
  17. // Check connection
  18. if ($conn->connect_error) {
  19. die("Connection failed: " . $conn->connect_error);
  20. }
  21.  
  22.  
  23. $sql = "SELECT dorder_id, designer_id, designerorder_id , dproduct_id, dpaid_status , delivery_status , due_date, commission FROM order_details";
  24. $result = $conn->query($sql);
  25.  
  26. if ($result->num_rows > 0) {
  27. echo "<table><tr><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th></tr>";
  28. // output data of each row
  29. while($row = $result->fetch_assoc()) {
  30. echo "<tr><td>" . $row["dorder_id"]. "</td><td>" . $row["designer_id"]. " " . $row["designerorder_id"]. "</td>
  31. <td>" . $row["dproduct_id"]. " " . $row["dpaid_status"]. "</td>
  32. <td>" . $row["delivery_status"]. " " . $row["due_date"]. "</td>
  33. <td>" . $row["commission"]. " " . $row["commission"]. "</td>
  34. </tr>";
  35. }
  36. echo "</table>";
  37. } else {
  38. echo "0 results";
  39. }
  40.  
  41. $conn->close();
  42.  
  43. /* test end */
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /* to show selected date */
  50.  
  51. if (isset($_POST['post_at']) && $_POST['post_at'] != '')
  52. {
  53. $orderFromDate = $_POST['post_at'] . " 00:00:00 ";
  54. }
  55. else
  56. {
  57. $orderFromDate = '';
  58. }
  59.  
  60. if (isset($_POST['post_at_to_date']) && $_POST['post_at_to_date'] != '')
  61. {
  62. $orderToDate = $_POST['post_at_to_date'] . " 23:59:59 ";
  63. }
  64. else
  65. {
  66. $orderToDate = '';
  67. }
  68.  
  69. /* to show selected date end*/
  70.  
  71. function getDesignerName($designerId)
  72. {
  73. $user_home = new USER();
  74. if (!$user_home->is_logged_in())
  75. {
  76. $user_home->redirect('index.php');
  77. }
  78.  
  79. $stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
  80. $stmt->execute(array(
  81. ":uid" => $designerId
  82. ));
  83. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  84. return $row['name'];
  85. }
  86.  
  87. /* Fetching magento db details end */
  88.  
  89. function getDesignerCollection()
  90. {
  91. global $is_admin;
  92. $user_home = new USER();
  93. require_once '../../app/Mage.php';
  94.  
  95. Mage::app();
  96.  
  97. $stmts = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
  98. $stmts->execute(array(
  99. ":uid" => $_SESSION['userSession']
  100. ));
  101. $rows = $stmts->fetch(PDO::FETCH_ASSOC);
  102.  
  103. $stmt = $user_home->runQuery("SELECT * FROM order_details");
  104. $stmt->execute(array(":uid" => $_SESSION['userSession']));
  105. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  106. $stmt->execute();
  107.  
  108. /* date search */
  109. if (isset($_POST['post_at']) && $_POST['post_at'] != '')
  110. {
  111. $orderFromDate = $_POST['post_at'] . " 00:00:00 ";
  112.  
  113. }
  114. else
  115. {
  116. $orderFromDate = '';
  117. }
  118.  
  119. if (isset($_POST['post_at_to_date']) && $_POST['post_at_to_date'] != '')
  120. {
  121. $orderToDate = $_POST['post_at_to_date'] . " 23:59:59 ";
  122.  
  123. }
  124. else
  125. {
  126. $orderToDate = '';
  127. }
  128. /* date search end*/
  129.  
  130. $accountType = $rows['type'];
  131. if ($accountType == "admin")
  132. {
  133. $is_admin = true;
  134. $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
  135. 'nin' => '0'
  136. ));
  137. if ($orderFromDate != '') $order->addFieldToFilter('created_at', array(
  138. 'gteq' => $orderFromDate
  139. ));
  140. if ($orderToDate != '') $order->addFieldToFilter('created_at', array(
  141. 'lteq' => $orderToDate
  142. ));
  143. }
  144. else
  145. {
  146. $order = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('designer_id', array(
  147. 'like' => '%' . $_SESSION['userSession'] . '%'
  148. ));
  149. if ($orderFromDate != '') $order->addFieldToFilter('created_at', array(
  150. 'gteq' => $orderFromDate
  151. ));
  152. if ($orderToDate != '') $order->addFieldToFilter('created_at', array(
  153. 'lteq' => $orderToDate
  154. ));
  155. }
  156.  
  157. /* Fetching magento db details end */
  158.  
  159. $i = 0;
  160. foreach($order as $orderData)
  161. {
  162. $k = 0;
  163. $orderitems = $orderData['dproduct_id'];
  164. $orderitemsarray = explode(",", $orderitems);
  165.  
  166. $oDate = new DateTime($orderData['created_at']);
  167. $sDate = $oDate->format("M d, Y");
  168.  
  169.  
  170.  
  171. while ($k < count($orderitemsarray))
  172. //while (($k < count($orderitemsarray)) && ($data = $stmt->fetch()))
  173. {
  174.  
  175. if ($orderitemsarray[$k] != '0')
  176. {
  177.  
  178.  
  179. $stmtorders = $user_home->runQuery("SELECT * FROM order_details");
  180. $stmtorders->execute(array(":dorder_id" => $orderData['entity_id']));
  181.  
  182. $roworders = $stmtorders->fetch(PDO::FETCH_ASSOC);
  183.  
  184. $dorderStatus = $roworders['dpaid_status'];
  185.  
  186.  
  187.  
  188. $productdetail = Mage::getModel('catalog/product')->load($orderitemsarray[$k]);
  189. $designer_id = $productdetail->getDesignerID() ;
  190.  
  191. if($accountType == "admin")
  192. {
  193. $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
  194.  
  195. $stmt1 = $user_home->runQuery("SELECT * FROM order_details WHERE dproduct_id=:pid and designerorder_id=:doid");
  196. $stmt1->execute(array(
  197. ":doid" => $orderData->getIncrementId(),
  198. ":pid" => $orderitemsarray[$k],
  199. ));
  200. $paid_status='';
  201. while($datas = $stmt1->fetch())
  202.  
  203. {
  204. if ($roworders['dpaid_status'] != '')
  205. {
  206. $paid_status=$datas['dpaid_status'];
  207. }
  208. else
  209. {
  210. $paid_status='unpaid';
  211. }
  212. }
  213.  
  214. $responce[] = array(
  215. $orderData->getIncrementId() ,
  216. $orderData->getIncrementId() ,
  217. $orderitemsarray[$k],
  218. $productdetail->getName() ,
  219. $designerName,
  220. $orderData['status'], // magento [ pending / processing/complete]
  221. $orderData['grand_total'], // magento
  222. $orderData['customer_email'], // magento
  223. $data['commission'],
  224. $paid_status,
  225. $sDate // magento
  226. );
  227.  
  228. }
  229.  
  230. else
  231. {
  232.  
  233. if( $designer_id== $_SESSION['userSession'] )
  234.  
  235. {
  236. $designerName = getDesignerName($productdetail->getDesignerID()) . " -(" . $productdetail->getDesignerID() . ")";
  237.  
  238. $stmt1 = $user_home->runQuery("SELECT * FROM order_details WHERE dproduct_id=:pid and designerorder_id=:doid");
  239. $stmt1->execute(array(
  240. ":doid" => $orderData->getIncrementId(),
  241. ":pid" => $orderitemsarray[$k],
  242. ));
  243. $paid_status='';
  244. while($datas = $stmt1->fetch())
  245.  
  246. {
  247. if ($roworders['dpaid_status'] != '')
  248. {
  249. $paid_status=$datas['dpaid_status'];
  250. }
  251. else
  252. {
  253. $paid_status='unpaid';
  254. }
  255.  
  256. }
  257.  
  258.  
  259. $responce[] = array(
  260. $orderData->getIncrementId() ,
  261. $orderData->getIncrementId() ,
  262. $orderitemsarray[$k],
  263. $productdetail->getName() ,
  264. $designerName,
  265. $orderData['status'], // magento [ pending / processing/complete]
  266. $orderData['grand_total'], // magento
  267. $orderData['customer_email'], // magento
  268. $data['commission'],
  269. $paid_status,
  270. $sDate // magento
  271. );
  272. }
  273.  
  274. }
  275.  
  276. }
  277.  
  278. $k++;
  279. $i++;
  280. }
  281.  
  282.  
  283. /* paid */
  284. /*
  285. $stmt = $user_home->runQuery("SELECT * FROM tbl_users");
  286. $stmt->execute(array(":uid" => $_SESSION['userSession']));
  287. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  288. $stmt->execute();
  289. */
  290. while($data = $stmt->fetch())
  291.  
  292. {
  293.  
  294. $responce1[] = array(
  295. $data['designerorder_id'] ,
  296. $data['designerorder_id'] ,
  297. $orderitemsarray[$k],
  298. $productdetail->getName() ,
  299. $designerName,
  300. $orderData['status'], // magento [ pending / processing/complete]
  301. $orderData['grand_total'], // magento
  302. $orderData['customer_email'], // magento
  303. $data['commission'],
  304. $data['dpaid_status'],
  305. $sDate // magento
  306. );
  307. $k++;
  308. }
  309.  
  310. /*paid end */
  311.  
  312. } // foreach
  313.  
  314. //json_encode($responce);
  315. //array_push($responce,$responce1);
  316. //json_encode($responce);
  317.  
  318. //$result = array_merge($responce, $responce1);
  319. return json_encode($responce);
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326. } // designer collection
  327.  
  328.  
  329.  
  330.  
  331. ?>
  332.  
  333. <head>
  334.  
  335. <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  336. <script src= "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js"></script>
  337.  
  338. <link rel="stylesheet" href="assets/css/jquery-ui.css">
  339. <script src="assets/js/jquery-1.10.2.js"></script>
  340. <script src="assets/js/jquery-ui.js"></script>
  341. <script src="assets/js/jquery-ui.js"></script>
  342.  
  343.  
  344. <script type="text/javascript" language="javascript" src="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/js/outthinking/gt_msg_en.js"></script>
  345. <script type="text/javascript" language="javascript" src="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/js/outthinking/gt_grid_all.js"></script>
  346.  
  347.  
  348. <link rel="stylesheet" type="text/css" href="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/css/outthinking/css/skinstyle.css"/>
  349. <link rel="stylesheet" type="text/css" href="http://sbdev2.kidsdial.com:81/php/site6/bootstrap/css/outthinking/css/gt_grid.css"/>
  350. <h2> Orders</h2><div id="msgresult" style="display:none;color:blue;text-align:center;">Paid status changed.</div>
  351.  
  352. </head>
  353.  
  354.  
  355. <div>
  356. <div class="delete_grid" >
  357.  
  358. <form>
  359. Search:
  360. <select id="f_value2">
  361. <option value="entity_id">Order Id</option>
  362. <option value="designer_id">Designer Id</option>
  363. </select>
  364. <input type="text" onkeyup="doFilter()" value="" id="f_value1" >
  365. <input type="reset" value="Reset" onClick="window.location.reload()">
  366. </form>
  367.  
  368. <br/>
  369.  
  370.  
  371.  
  372. <form name="frmSearch" method="post" action="">
  373. <input type="text" placeholder="From Date" id="post_at"
  374.  
  375. value="<?php
  376.  
  377. if ($orderFromDate != '')
  378. {
  379.  
  380. $newPostStartDate = date('Y-m-d', strtotime($_POST['post_at']));
  381. echo $newPostStartDate;
  382.  
  383. } ?>" name="post_at" />
  384.  
  385. <input type="text" placeholder="To Date" id="post_at_to_date"
  386.  
  387.  
  388. value="<?php
  389.  
  390. if ($orderToDate != '')
  391. {
  392.  
  393.  
  394. $newPostEndDate = date('Y-m-d', strtotime($_POST['post_at_to_date']));
  395. echo $newPostEndDate;
  396.  
  397. } ?>"name="post_at_to_date" />
  398.  
  399. <input type="submit" name="search" value="search" id="searchButton">
  400.  
  401.  
  402.  
  403. <input type="button" value="Reset" id="clear-dates">
  404. </form>
  405.  
  406.  
  407. <br/>
  408.  
  409.  
  410. <div class="delete_grid_select">
  411.  
  412. <form action='' method="post" enctype="multipart/form-data">
  413. <input type="hidden" name="delete_package_id" id="delete_package_id" value=""/>
  414. Action:
  415.  
  416. <select name="massaction" id="massaction">
  417. <option value="">Select</option>
  418. <option value="P">Paid</option>
  419. <option value="U">Unpaid</option>
  420. </select>
  421.  
  422. <input type="button" value="Submit" id="delete-grid-button" onclick="massAction()" />
  423. </form>
  424.  
  425. </div>
  426.  
  427.  
  428. </div>
  429. </div>
  430. <div id="myGrid"></div>
  431.  
  432. <script type="text/javascript">
  433.  
  434. var __TEST_DATA__=eval('<?php
  435. echo getDesignerCollection(); ?>');
  436. var grid_demo_id = "myGrid" ;
  437. var dsOption= {
  438. fields :[
  439. {name : 'entity_id' },
  440. {name : 'entity_id' },
  441. {name : 'product_id' },
  442. {name : 'product_name'},
  443. {name : 'designer_id' },
  444. {name : 'status' },
  445. {name : 'grand_total' },
  446. {name : 'customer_email' },
  447. {name : 'commission' },
  448. {name : 'dpaid_status' },
  449. {name : 'created_at'},
  450. ],
  451. recordType : 'array',
  452. data : __TEST_DATA__
  453. }
  454.  
  455.  
  456. function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
  457. {
  458. var no= record[columnObj.fieldIndex];
  459.  
  460. return "<input type='checkbox' value='"+record[0]+"-"+record[3]+"' name='userID[]'/>";
  461. }
  462.  
  463. var colsOption = [
  464. {id: '' , header: "" , width :"15",renderer : my_renderId , width :"60"},
  465. {id: 'created_at' , header: "Order Date" , width :"120"},
  466. {id: 'entity_id' , header: "Order Id" , width :"75"},
  467. {id: 'product_id' , header: "Product Id" , width :"70"},
  468. {id: 'product_name' , header: "Product Name" , width :"200"},
  469. <?php if ($is_admin) echo "{id: 'designer_id' , header: 'Designer' , width :'110'},"; ?>
  470. // {id: 'status' , header: "Order Status" , width :"100"},
  471. // {id: 'grand_total' , header: " Order Amount" , width :"120"},
  472. // {id: 'customer_email' , header: "User Email" , width :"150"},
  473. {id: 'dpaid_status' , header: "Paid status" , width :"80"},
  474. // {id: 'commission' , header: "commission" , width :"80"},
  475. {id: 'dpaid_status1' , header: "Deliver Status" , width :"130"},
  476. {id: 'dpaid_status2' , header: "Payment Due Date" , width :"140"},
  477.  
  478. ];
  479.  
  480. var gridOption={
  481. id : grid_demo_id,
  482.  
  483. // height: "285", //"100%", // 330,
  484.  
  485. pageSize:30,
  486. pageSizeList : [5,10,15,20],
  487. container : 'myGrid',
  488. replaceContainer : true,
  489. sortable : false,
  490.  
  491. dataset : dsOption ,
  492. columns : colsOption ,
  493. toolbarContent : 'nav goto | pagesize | filter state | sortable | search',
  494. onRowClick:function(value, record , cell, row, colNO, rowNO,columnObj,grid){
  495. }
  496. };
  497. var mygrid=new Sigma.Grid(gridOption);
  498. Sigma.Util.onLoad( Sigma.Grid.render(mygrid) );
  499.  
  500. function doFilter() {
  501. var filterInfo=[
  502. {
  503. fieldName : $('select[id=f_value2]').val(),
  504. logic : "startWith",
  505. value : Sigma.Util.getValue("f_value1")
  506. },
  507. {
  508. fieldName : Sigma.Util.getValue("f_fieldName12"),
  509. logic : "greatEqual",
  510. value : Sigma.Util.getValue("f_value12")
  511. }
  512. ]
  513. var grid=Sigma.$grid("myGrid");
  514. var rowNOs=grid.applyFilter(filterInfo);
  515. }
  516. function doUnfilter(){
  517. var grid=Sigma.$grid("myGrid1");
  518. var rowNOs=grid.unfilterGrid();
  519.  
  520. }
  521.  
  522.  
  523. function doUnfilter(){
  524. var grid=Sigma.$grid("myGrid1");
  525. var rowNOs=grid.unfilterGrid();
  526.  
  527. }
  528.  
  529. function massAction()
  530. {
  531. var e=document.getElementById("massaction");
  532. var strUser = e.options[e.selectedIndex].value;
  533.  
  534. massStatusChangeVerified(strUser);
  535. /*
  536. switch(strUser)
  537. {
  538. case "paid":
  539. retactiveVal=confirm("Are you sure want to Change the Paid status");
  540. if( retactiveVal == true )
  541. {
  542. massdesignerpaidstatus();
  543. return true;
  544. }else{
  545. return false;
  546. }
  547.  
  548. return false;
  549. }
  550. */
  551. }
  552.  
  553.  
  554. function massStatusChangeVerified(status)
  555. {
  556. var vals = "";
  557. var checkboxes=$("input[name='userID[]']:checked").each( function () {
  558.  
  559. vals += ","+$(this).val();
  560.  
  561. })
  562. alert(vals);
  563. //var checkboxes = document.getElementsByName('userID');
  564.  
  565. //for (var i=0, n=checkboxes.length;i<n;i++) {
  566. // if (checkboxes[i].checked)
  567. //{
  568. //vals += ","+checkboxes[i].value;
  569. // }
  570. //}
  571. if(vals=='')
  572. {
  573. alert("No record selected");
  574. return false;
  575. }
  576. retactiveVal=confirm("Are you sure want to Change the status");
  577. if( retactiveVal == true )
  578. {
  579. if (vals) vals = vals.substring(1);
  580. document.getElementsByName('delete_package_id').value=vals;
  581. var url="http://sbdev2.kidsdial.com:81/php/site6/update_order_status.php?designer_id="+vals+"&order_status="+status;
  582. var request = jQuery.ajax( {
  583. url: url ,
  584. type: 'POST',
  585. } );
  586.  
  587. request.done( function (result)
  588. {
  589. document.getElementById('msgresult').style.display="block";
  590. var explode = function(){
  591. location.reload();
  592. };
  593. setTimeout(explode, 2000);
  594.  
  595.  
  596. } );
  597. request.fail( function ( error )
  598. {
  599. console.dir(error);
  600. } );return true;
  601. }else{
  602. return false;
  603. }
  604.  
  605. }
  606.  
  607. function massdesignerpaidstatus()
  608. {
  609.  
  610. var checkboxes = document.getElementsByName('userID');
  611. var vals = "";
  612. for (var i=0, n=checkboxes.length;i<n;i++) {
  613. if (checkboxes[i].checked)
  614. {
  615. vals += ","+checkboxes[i].value;
  616. }
  617. }
  618. if(vals=='')
  619. {
  620. alert("No record selected");
  621. return false;
  622. }
  623. if (vals) vals = vals.substring(1);
  624. document.getElementsByName('delete_package_id').value=vals;
  625. var url="http://sbdev2.kidsdial.com:81/php/site6/designerpaidstatus.php?order_id="+vals+"&designer_dpaid_status='Paid'";
  626. var request = jQuery.ajax( {
  627. url: url ,
  628. type: 'POST',
  629. } );
  630.  
  631. request.done( function (result)
  632. {
  633. location.reload();
  634.  
  635. } );
  636. request.fail( function ( error )
  637. {
  638. console.dir(error);
  639. } );
  640.  
  641. }
  642.  
  643. <!-- Date Picker -->
  644.  
  645.  
  646. jQuery.datepicker.setDefaults({
  647. showOn: "button",
  648. buttonImage: "assets/img/datepicker.png",
  649. buttonText: "Date Picker",
  650. buttonImageOnly: true,
  651. dateFormat: 'yy-mm-dd'
  652. });
  653. $(function() {
  654. $("#post_at").datepicker();
  655. $("#post_at_to_date").datepicker();
  656. });
  657.  
  658.  
  659. <!-- reset date -->
  660. var $dates = $('#post_at, #post_at_to_date').datepicker();
  661.  
  662.  
  663. $("#clear-dates").click(function(){
  664. location.reload();
  665. $("#post_at").removeAttr('value');
  666. $("#post_at_to_date").removeAttr('value');
  667. if(!$("#post_at_to_date").val()) {
  668. $( "#searchButton" ).trigger( "click" );
  669. }
  670. });
  671.  
  672.  
  673. </script>
Add Comment
Please, Sign In to add comment