PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/views/admin/body/orders.php

https://bitbucket.org/sharifbaba/snaptitoday-dev
PHP | 426 lines | 368 code | 53 blank | 5 comment | 53 complexity | 1731f3d53e14ae018c41108d8de8985a MD5 | raw file
  1. <?php
  2. $finance_role_const_val=$this->db->query("select value from user_access_roles where const_name='FINANCE_ROLE'")->row()->value;
  3. if(!isset($partial_list))
  4. $partial_list=false;
  5. $trans=array();
  6. foreach($orders as $o)
  7. $trans[]=$o['transid'];
  8. $braw=$this->db->query("select b.batch_id,i.invoice_no,i.transid from king_invoice i join shipment_batch_process_invoice_link b on b.invoice_no=i.invoice_no where i.transid in ('".implode($trans,"','")."') group by i.invoice_no")->result_array();
  9. foreach($braw as $b)
  10. {
  11. if(!isset($batches[$b['transid']]))
  12. $batches[$b['transid']]=array();
  13. if(!isset($invoices[$b['transid']]))
  14. $invoices[$b['transid']]=array();
  15. $batches[$b['transid']][]=$b['batch_id'];
  16. $invoices[$b['transid']][]=$b['invoice_no'];
  17. }
  18. $pending_flag=false;
  19. if($this->uri->segment(3)=="1")
  20. $pending_flag=true;
  21. ?>
  22. <style>
  23. .subdatagrid{width: 100%}
  24. .subdatagrid th{padding:5px;font-size: 11px;background: #F4EB9A;color: maroon}
  25. .subdatagrid td{padding:3px;font-size: 12px;}
  26. .subdatagrid td a{color: #121213;}
  27. .processed_ord td,.shipped_ord td{text-decoration: line-through;color: green !important;}
  28. .processed_ord td a,.shipped_ord td a{text-decoration: line-through;color: green !important;}
  29. .cancelled_ord td{text-decoration: line-through;color: #cd0000 !important;}
  30. .cancelled_ord td a{text-decoration: line-through;color: #cd0000 !important;}
  31. .tgl_ord_prod {display: block;min-width: 300px;padding:5px;background: #fafafa;}
  32. .tgl_ord_prod a{display: block;text-align: center;color: #333;font-size: 12px;text-decoration: underline;}
  33. .tgl_ord_prod_content {display: none;}
  34. </style>
  35. <div class="container">
  36. <div>
  37. <div class="dash_bar">
  38. <a href="<?=site_url("admin/orders/1")?>"></a>
  39. <span><?php $pending=$this->db->query("select count(distinct(a.transid)) as l from king_orders a join king_transactions b on a.transid = b.transid where a.status=0")->row()->l;?><?=$pending?></span>
  40. Pending Orders
  41. </div>
  42. <?php /*?>
  43. <div class="dash_bar">
  44. <span><?=$this->db->query("select count(distinct(transid)) as l from king_orders where status=3")->row()->l?></span>
  45. Shipped Orders
  46. </div>
  47. */ ?>
  48. <div class="dash_bar">
  49. <a href="<?=site_url("admin/orders")?>"></a>
  50. <span><?=$this->db->query("select count(distinct(transid)) as l from king_orders where time>?",mktime(0,0,0,date("n"),1))->row()->l?></span>
  51. Orders this month
  52. </div>
  53. <?php
  54. if($this->erpm->auth(FINANCE_ROLE,true))
  55. {
  56. ?>
  57. <div class="dash_bar">
  58. <span><?=$this->db->query("select count(distinct(transid)) as l from king_orders where time between ? and ?",array(mktime(0,0,0,date("n")-1,1),mktime(0,0,0,date("n"),date("t"))))->row()->l?></span>
  59. Orders prev month
  60. </div>
  61. <div class="dash_bar">
  62. <span>Rs <?=number_format($this->db->query("select sum(i_price*quantity) as l from king_orders where time>?",mktime(0,0,0,date("n"),1))->row()->l)?></span>
  63. Value this month
  64. </div>
  65. <div class="dash_bar">
  66. <span>Rs <?=number_format($this->db->query("select sum(i_price*quantity) as l from king_orders where time between ? and ?",array(mktime(0,0,0,date("n")-1,1),mktime(0,0,0,date("n"),1)))->row()->l)?></span>
  67. Value prev month
  68. </div>
  69. <?php } ?>
  70. <div class="clear"></div>
  71. <div class="dash_bar">
  72. showing <b><?=count($orders)?></b> orders
  73. </div>
  74. <?php if(!$partial_list){?>
  75. <div class="dash_bar" style="padding:7px;">
  76. Date range: <input type="texT" size="8" class="inp" id="ds_range" value="<?=$this->uri->segment(4)?>"> to <input size="8" type="text" class="inp"id="de_range" value="<?=$this->uri->segment(5)?>"> <input type="button" value="Show" onclick='showrange()'>
  77. </div>
  78. <?php }?>
  79. <div class="dash_bar_red">
  80. <a href="<?=site_url("admin/partial_shipment")?>"></a>
  81. Partial Shipment Orders
  82. </div>
  83. <div class="dash_bar">
  84. <a href="<?=site_url("admin/disabled_but_possible_shipment")?>"></a>
  85. Disabled but possible
  86. </div>
  87. <div class="clear"></div>
  88. </div>
  89. <?php if(!$partial_list){?>
  90. Stock Unavailability Report for :
  91. <a target="_blank" href="<?=site_url("admin/stock_unavail_report/".($this->uri->segment(2)=="partial_shipment"?"1":"0")."/".($this->uri->segment(4)?$this->uri->segment(4):0)."/".($this->uri->segment(5)?$this->uri->segment(5):0)."/0")?>">All Orders</a> /
  92. <a target="_blank" href="<?=site_url("admin/stock_unavail_report/".($this->uri->segment(2)=="partial_shipment"?"1":"0")."/".($this->uri->segment(4)?$this->uri->segment(4):0)."/".($this->uri->segment(5)?$this->uri->segment(5):0)."/2")?>">Snapittoday Orders</a> /
  93. <a target="_blank" href="<?=site_url("admin/stock_unavail_report/".($this->uri->segment(2)=="partial_shipment"?"1":"0")."/".($this->uri->segment(4)?$this->uri->segment(4):0)."/".($this->uri->segment(5)?$this->uri->segment(5):0)."/1")?>">PNH Orders</a>
  94. <?php }?>
  95. <div style="overflow: hidden;clear: both;">
  96. <h2 ><?=!isset($pagetitle)?"Recent 50 ":""?>Orders <?=isset($pagetitle)?$pagetitle:""?></h2>
  97. </div>
  98. <?php
  99. if($this->erpm->auth(true,true))
  100. {
  101. $today = false;
  102. $ord_stat_cond = ' and a.init between ? and ? ';
  103. if($this->uri->segment("4"))
  104. {
  105. $st = strtotime($this->uri->segment("4").' 00:00:00');
  106. $en = strtotime($this->uri->segment("5").' 23:59:59');
  107. }else
  108. {
  109. if(!$pending_flag)
  110. {
  111. $st = strtotime(date('Y-m-d').' 00:00:00');
  112. $en = strtotime(date('Y-m-d').' 23:59:59');
  113. $today = true;
  114. }else{
  115. $st = strtotime('2012-01-01 00:00:00');
  116. $en = strtotime(date('Y-m-d').' 23:59:59');
  117. }
  118. }
  119. if($pending_flag)
  120. {
  121. $ord_stat_cond .= ' and b.status = 0 ';
  122. }
  123. $ttl_ord_summ = $this->db->query("select count(distinct(a.transid)) as total,is_pnh,partner_id,c.name as partner_name
  124. from king_transactions a
  125. join king_orders b on a.transid = b.transid
  126. left join partner_info c on c.id = a.partner_id
  127. where 1 $ord_stat_cond
  128. group by is_pnh,partner_id
  129. order by total,is_pnh,partner_id,partner_name ",array($st,$en))->result_array();
  130. //echo $this->db->last_query();
  131. $ord_sum_sites = array('snapittoday'=>0,'paynearhome'=>0);
  132. foreach($ttl_ord_summ as $ttlords)
  133. {
  134. if($ttlords['partner_id'])
  135. {
  136. $ord_sum_sites[$ttlords['partner_name']] = $ttlords['total'];
  137. }else if(!$ttlords['partner_id'] && !$ttlords['is_pnh'])
  138. {
  139. $ord_sum_sites['snapittoday'] = $ttlords['total'];
  140. }
  141. else if(!$ttlords['partner_id'] && $ttlords['is_pnh'])
  142. {
  143. $ord_sum_sites['paynearhome'] = $ttlords['total'];
  144. }
  145. }
  146. ?>
  147. <div style="background: #f9f9f9;overflow: hidden;text-align: right;border;1px solid #cfcfcf">
  148. <div style="clear: both;">
  149. <div style="float: left;background:#ccc;color:#000;padding:7px 10px;width: 80px;height:30px;;text-align: center;" >
  150. <b style="vertical-align: middle;position: relative;top:8px;"><?php echo (!$today)?'Total':'Today';?></b>
  151. </div>
  152. <?php
  153. $colors = array('#cdFFFF','#fffff0','#cc11df','lightblue','lightgreen','lightblue','#cc11df','blue','green','lightblue');
  154. $c = 0;
  155. arsort($ord_sum_sites);
  156. foreach($ord_sum_sites as $oby=>$ttl_ord)
  157. {
  158. if($oby == 'paynearhome')
  159. $clr = '#ef4a37';
  160. else if($oby == 'snapittoday')
  161. $clr = '#feed00';
  162. else
  163. $clr = $colors[$c];
  164. ?>
  165. <div style="float: left;background:<?php echo $clr?>;color:#000;padding:7px 10px;height:30px;width: 80px;text-align: center;" >
  166. <?php echo ucwords($oby)?> <br /><b style="font-size: 16px;"><?php echo $ttl_ord; ?></b>
  167. </div>
  168. <?php
  169. $c++;
  170. }
  171. ?>
  172. </div>
  173. </div>
  174. <?php } ?>
  175. <div style="background:#eee;padding:5px;">
  176. <span style="float: right;padding:3px;">
  177. <a href="javascript:void(0)" style="text-decoration: underline;" id="exp_col_list">Expand/Collapse All</a>
  178. </span>
  179. Show : <label><input type="checkbox" class="pnh_o_c">PNH Orders</label> <label><input type="checkbox" class="n_o_c">Other Orders</label>
  180. </div>
  181. <form action="<?=site_url("admin/bulk_endisable_for_batch")?>" method="post">
  182. <table class="datagrid" width="100%">
  183. <thead>
  184. <tr>
  185. <th><input type="checkbox" id="batch_en_disable_all" value="1"></th>
  186. <th>Trans ID</th>
  187. <?php if($partial_list){?>
  188. <th>Pending</th>
  189. <th>Available</th>
  190. <?php }?>
  191. <th>Deal/Product Details</th>
  192. <th width="120">Ship To</th>
  193. <th width="150">Ordered on</th>
  194. <th>Status</th>
  195. <th>Contact</th>
  196. <?php if(!$partial_list){?>
  197. <th>Invoices</th>
  198. <th><nobr>Process Batches</nobr></th>
  199. <?php }?>
  200. <th style="padding:3px;" width="10"><span style="font-size:68%">Batch Enabled</span></th>
  201. </tr>
  202. </thead>
  203. <tbody>
  204. <?php foreach($orders as $o){?>
  205. <tr <?=$o['priority']?"style='background:#ff8;'":""?> class="<?=$o['is_pnh']?"pnh_o":"n_o"?>">
  206. <td><input type="checkbox" class="batch_en_disable" name="trans[]" value="<?=$o['transid']?>"></td>
  207. <td>
  208. <?php if($o['priority']){?>
  209. <span class="order_high_priority"></span>
  210. <?php }?>
  211. <a href="<?=site_url("admin/trans/{$o['transid']}")?>" class="link"><?=$o['transid']?></a>
  212. <br />
  213. <a href="<?=site_url("admin/user/{$o['userid']}")?>"><?=$o['name']?></a>
  214. </td>
  215. <?php if($partial_list){?>
  216. <td><?=$o['pending']?></td>
  217. <td><?=$o['possible']?></td>
  218. <?php }?>
  219. <td style="padding:0px;background: #fafafa !important;">
  220. <div class="tgl_ord_prod"><a href="tgl_ord_prods">Show Deals</a></div>
  221. <div class="tgl_ord_prod_content">
  222. <table class="subdatagrid" cellpadding="0" cellspacing="0">
  223. <thead>
  224. <th>Slno</th>
  225. <th>OID</th>
  226. <th width="200">ITEM</th>
  227. <th>QTY</th>
  228. <th>MRP</th>
  229. <th>Amount</th>
  230. </thead>
  231. <tbody>
  232. <?php
  233. $o_item_list = $this->db->query("select a.status,a.id,a.itemid,b.name,a.quantity,i_orgprice,i_price,i_discount,i_coup_discount from king_orders a
  234. join king_dealitems b on a.itemid = b.id
  235. where a.transid = ? order by a.status
  236. ",$o['transid'])->result_array();
  237. $oi = 0;
  238. foreach($o_item_list as $o_item)
  239. {
  240. $is_cancelled = ($o_item['status']==3)?1:0;
  241. $ord_stat_txt = '';
  242. if($o_item['status'] == 0)
  243. $ord_stat_txt = 'pending';
  244. else if($o_item['status'] == 1)
  245. $ord_stat_txt = 'processed';
  246. else if($o_item['status'] == 2)
  247. $ord_stat_txt = 'shipped';
  248. else if($o_item['status'] == 3)
  249. $ord_stat_txt = 'cancelled';
  250. ?>
  251. <tr class="<?php echo $ord_stat_txt.'_ord'?>">
  252. <td width="20"><?php echo ++$oi; ?></td>
  253. <td width="40"><?php echo $o_item['id'] ?></td>
  254. <td><?php echo anchor('admin/pnh_deal/'.$o_item['itemid'],$o_item['name']) ?></td>
  255. <td width="20"><?php echo $o_item['quantity'] ?></td>
  256. <td width="40"><?php echo $o_item['i_orgprice'] ?></td>
  257. <td width="40"><?php echo round($o_item['i_orgprice']-($o_item['i_coup_discount']+$o_item['i_discount']),2) ?></td>
  258. </tr>
  259. <?php
  260. }
  261. ?>
  262. </tbody>
  263. </table>
  264. </div>
  265. </td>
  266. <td><?=ucfirst($o['ship_city'])?></td>
  267. <td><?=date("g:ia d M y",$o['init'])?></td>
  268. <td><?php switch($o['status']){
  269. case 0: echo "Pending"; break;
  270. case 1:
  271. if(isset($invoices[$o['transid']]) && $this->db->query("select 1 from shipment_batch_process_invoice_link where packed=1 and invoice_no in ('".implode("','",$invoices[$o['transid']])."')")->num_rows()==0) echo "Invoiced"; else echo "Packed"; break;
  272. case 2: echo "Shipped"; break;
  273. case 3: echo "Canceled"; break;
  274. }?>
  275. </td>
  276. <td><?=$o['ship_phone']?></td>
  277. <?php if(!$partial_list){?>
  278. <td>
  279. <?php
  280. if(!isset($invoices[$o['transid']]))
  281. echo '-';
  282. else {
  283. foreach($invoices[$o['transid']] as $b){?>
  284. <a href="<?=site_url("admin/invoice/{$b}")?>"><?=$b?></a>
  285. <?php }
  286. }
  287. ?>
  288. </td>
  289. <td><?php
  290. if(!isset($batches[$o['transid']]))
  291. echo '-';
  292. else {
  293. foreach($batches[$o['transid']] as $b){?>
  294. <a href="<?=site_url("admin/batch/{$b}")?>">BATCH<?=$b?></a>
  295. <?php }
  296. }
  297. ?>
  298. </td>
  299. <?php }?>
  300. <td align="Center" style="font-size:75%"><?=$o['batch_enabled']?"<span class='green'>YES</span>":"<span class='red'>NO</span>"?></td>
  301. </tr>
  302. <?php } if(empty($orders)){?>
  303. <tr><td colspan="100%">no orders to show</td></tr>
  304. <?php }?>
  305. </tbody>
  306. </table>
  307. <span style="padding:5px 10px 10px 10px;background:#eee;">Batch Process Flag : <input type="submit" name="enable" value="Enable selected"> <input type="submit" name="disable" value="Disable selected"></span>
  308. </form>
  309. </div>
  310. <script>
  311. function do_show_orders()
  312. {
  313. if($(".n_o_c").attr("checked"))
  314. $(".n_o").show();
  315. else
  316. $(".n_o").hide();
  317. if($(".pnh_o_c").attr("checked"))
  318. $(".pnh_o").show();
  319. else
  320. $(".pnh_o").hide();
  321. }
  322. $(function(){
  323. $(".n_o_c,.pnh_o_c").change(function(){
  324. do_show_orders();
  325. }).attr("checked",true);
  326. $("#ds_range,#de_range").datepicker();
  327. $("#batch_en_disable_all").click(function(){
  328. if($(this).attr("checked"))
  329. $(".batch_en_disable").attr("checked",true);
  330. else
  331. $(".batch_en_disable").attr("checked",false);
  332. });
  333. });
  334. function showrange()
  335. {
  336. if($("#ds_range").val().length==0 ||$("#ds_range").val().length==0)
  337. {
  338. alert("Pls enter date range");
  339. return;
  340. }
  341. location='<?=site_url("admin/orders/".(!$this->uri->segment(3)?"0":$this->uri->segment(3)))?>/'+$("#ds_range").val()+"/"+$("#de_range").val();
  342. }
  343. $('.tgl_ord_prod a').click(function(e){
  344. e.preventDefault();
  345. if($(this).parent().next().is(':visible'))
  346. {
  347. $(this).text('Show Deals');
  348. $(this).parent().next().hide();
  349. }else
  350. {
  351. $(this).text('Hide Deals');
  352. $(this).parent().next().show();
  353. }
  354. });
  355. $('#exp_col_list').click(function(e){
  356. e.preventDefault();
  357. if($(this).data('collapse'))
  358. {
  359. $(this).data('collapse',false);
  360. $('.tgl_ord_prod a').text('Hide Deals');
  361. $('.tgl_ord_prod_content').show();
  362. }else
  363. {
  364. $(this).data('collapse',true);
  365. $('.tgl_ord_prod a').text('Show Deals');
  366. $('.tgl_ord_prod_content').hide();
  367. }
  368. }).data('collapse',true);
  369. $(function(){
  370. $('#exp_col_list').trigger('click');
  371. });
  372. </script>
  373. <?php