Finance.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Finance extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_finance','finance');
  7. $this->load->_model('Model_fullorder','fullorder');
  8. $this->load->_model('Model_fullordertt','fullordertt');
  9. $this->load->_model('Model_fullordersmt','fullordersmt');
  10. $this->load->_model('Model_shop','shop');
  11. $this->load->_model('Model_typeclass','typeclass');
  12. $this->load->_model('Model_express','express');
  13. $this->load->_model('Model_country','country');
  14. $this->load->_model('Model_productdescribe','productdescribe');
  15. $this->load->_model('Model_customs','customs');
  16. $this->load->_model('Model_detailed','detailed');
  17. $this->load->_model('Model_productdescription','productdescription');
  18. $this->load->_model('Model_logistics','logistics');
  19. $this->load->_model('Model_hl','hl');
  20. $this->load->_model('Model_excel','excel');
  21. $this->load->_model('Model_warehouse','warehouse');
  22. $this->load->_model('Model_systemwigsout','systemwigsout');
  23. $this->load->_model('Model_classid','classid');
  24. }
  25. //定义方法的调用规则 获取URI第二段值
  26. public function _remap($arg,$arg_array)
  27. {
  28. if($arg == 'excel')
  29. {
  30. $this->_excel();
  31. }
  32. else if($arg == 'ckexcel')
  33. {
  34. $this->_ckexcel();
  35. }
  36. else if($arg == 'caiwu')
  37. {
  38. $this->_caiwu($arg_array);
  39. }
  40. else if($arg == 'ckcaiwu')
  41. {
  42. $this->_ckcaiwu();
  43. }
  44. else if($arg == 'product')
  45. {
  46. $this->_product($arg_array);
  47. }
  48. else if($arg == 'dhlfp')
  49. {
  50. $this->_dhlfp();
  51. }
  52. else if($arg == 'ouout')
  53. {
  54. $this->_ouout();
  55. }
  56. else if($arg == 'cksize')
  57. {
  58. $this->_cksize();
  59. }
  60. else
  61. {
  62. $this->_index($arg);
  63. }
  64. }
  65. //店铺统计
  66. public function _index($arg)
  67. {
  68. $fu = (isset($arg))?($arg=="smt"?"fullordersmt":"fullorder"):"fullorder";
  69. $user = $this->user->get_api($_SESSION['api']);
  70. if($user)
  71. {
  72. $fgshop = "";$sid = "";
  73. $user = explode('|',trim($user['shop'],'|'));
  74. foreach ($user as $value)
  75. {
  76. $fgshop .= " shop = ".$value." or";
  77. $sid .= " id = ".$value." or";
  78. }
  79. }
  80. $post = $this->input->post(NULL, TRUE);
  81. if(isset($post['page']))
  82. {
  83. $page = $this->input->post('page',true);
  84. $perpage = $this->input->post('perpage',true);
  85. $timetk = $this->input->post('timetk',true);
  86. $timetj = $this->input->post('timetj',true);
  87. $shop = $this->input->post('shop',true);
  88. $source = $this->input->post('source',true);
  89. $library = $this->input->post('library',true);
  90. $warehouse = $this->input->post('warehouse',true);
  91. $orderinfo = $this->input->post('orderinfo',true);
  92. $user = $this->input->post('user',true);
  93. $name = $this->input->post('name',true);
  94. $timetk = strtotime($timetk);
  95. $timetj = strtotime($timetj);
  96. $where = "mergeid = 0";
  97. if($timetk && $timetj)
  98. {
  99. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  100. }
  101. if($shop)
  102. {
  103. $where .= " and shop = '$shop'";
  104. }
  105. if($source)
  106. {
  107. $where .= " and source = '$source'";
  108. }
  109. if($library)
  110. {
  111. $where .= " and library = '$library'";
  112. }
  113. if($warehouse)
  114. {
  115. $where .= " and type = '$warehouse'";
  116. }
  117. if($orderinfo)
  118. {
  119. $where .= " and orderinfo = '$orderinfo'";
  120. }
  121. if($user)
  122. {
  123. $where .= " and user = '$user'";
  124. }
  125. if($name)
  126. {
  127. $where .= " and name = '$name'";
  128. }
  129. //数据排序
  130. $order_str = "id desc";
  131. if(empty($page))
  132. {
  133. $start = 0;
  134. $perpage = 1;
  135. }
  136. else
  137. {
  138. $start = ($page - 1)*$perpage;
  139. }
  140. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;
  141. //取得信息列表
  142. $info_list = $this->$fu->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,orderremarks,hl',$order_str,$start,$perpage);
  143. //格式化数据
  144. foreach ($info_list as $key=>$value)
  145. {
  146. $order = $this->$fu->read($value['id']);
  147. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  148. $shop = $this->shop->read($value['shop']);
  149. $info_list[$key]['shop'] = $shop['shopname'];
  150. $info_list[$key]['user'] = $shop['shopuser'];
  151. $warehouse = $this->warehouse->read($value['type']);
  152. $info_list[$key]['type'] = $warehouse['title'];
  153. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  154. $shouldmoney += $info_list[$key]['shouldmoney'];
  155. $expressmoney += $info_list[$key]['expressmoney'];
  156. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  157. $budget += $info_list[$key]['budget'];
  158. $refundj += $info_list[$key]['refundj'];
  159. }
  160. $money = $this->$fu->find_all($where);
  161. $shouldmoney = sprintf("%.2f",$shouldmoney);
  162. $expressmoney = sprintf("%.2f",$expressmoney);
  163. $budget = sprintf("%.2f",$budget);
  164. $refundj = sprintf("%.2f",$refundj);
  165. $total = $this->$fu->find_count($where);
  166. $pagenum = ceil($total/$perpage);
  167. $over = $total-($start+$perpage);
  168. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj)));
  169. echo json_encode($rows);exit;
  170. }
  171. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  172. $this->data['wlshop'] = $wlshop;
  173. $this->data['arg'] = $arg;
  174. $this->_Template('finance',$this->data);
  175. }
  176. public function _caiwu($arg_array)
  177. {
  178. $user = $this->user->get_api($_SESSION['api']);
  179. if($user)
  180. {
  181. $fgshop = "";$sid = "";
  182. $user = explode('|',trim($user['shop'],'|'));
  183. foreach ($user as $value)
  184. {
  185. $fgshop .= " shop = ".$value." or";
  186. $sid .= " id = ".$value." or";
  187. }
  188. }
  189. $post = $this->input->post(NULL, TRUE);
  190. if(isset($post['page']))
  191. {
  192. $page = $this->input->post('page',true);
  193. $perpage = $this->input->post('perpage',true);
  194. $timetk = $this->input->post('timetk',true);
  195. $timetj = $this->input->post('timetj',true);
  196. $shop = $this->input->post('shop',true);
  197. $source = $this->input->post('source',true);
  198. $library = $this->input->post('library',true);
  199. $warehouse = $this->input->post('warehouse',true);
  200. $orderinfo = $this->input->post('orderinfo',true);
  201. $number = $this->input->post('number',true);
  202. $user = $this->input->post('user',true);
  203. $name = $this->input->post('name',true);
  204. $xztime = $this->input->post('xztime',true);
  205. $country = $this->input->post('country',true);
  206. $paypal = $this->input->post('paypal',true);
  207. $fullorder = $this->input->post('fullorder',true);
  208. $timetk = strtotime($timetk);
  209. $timetj = strtotime($timetj);
  210. $where = "mergeid = 0";
  211. if($timetk && $timetj)
  212. {
  213. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  214. }
  215. if($shop)
  216. {
  217. $where .= " and shop = '$shop'";
  218. }
  219. if($source)
  220. {
  221. $where .= " and source = '$source'";
  222. }
  223. if($library)
  224. {
  225. $where .= " and library = '$library'";
  226. }
  227. if($warehouse)
  228. {
  229. $where .= " and type = '$warehouse'";
  230. }
  231. if($orderinfo)
  232. {
  233. $where .= " and orderinfo = '$orderinfo'";
  234. }
  235. if($number)
  236. {
  237. $where .= " and number = '$number'";
  238. }
  239. if($user)
  240. {
  241. $where .= " and user = '$user'";
  242. }
  243. if($name)
  244. {
  245. $where .= " and name = '$name'";
  246. }
  247. if($country)
  248. {
  249. $where .= " and country = '$country'";
  250. }
  251. if($paypal)
  252. {
  253. $where .= " and paypal = '$paypal'";
  254. }
  255. //数据排序
  256. $order_str = "id desc";
  257. if(empty($page))
  258. {
  259. $start = 0;
  260. $perpage = 1;
  261. }
  262. else
  263. {
  264. $start = ($page - 1)*$perpage;
  265. }
  266. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$cost=0;$lr=0;
  267. //取得信息列表
  268. if($fullorder == 'fullordersmt')
  269. {
  270. $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  271. $total = $this->fullordersmt->find_count($where);
  272. }
  273. else if($fullorder == 'fullorder')
  274. {
  275. $info_list = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  276. $total = $this->fullorder->find_count($where);
  277. }
  278. else if($fullorder == 'fullordertt')
  279. {
  280. $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  281. $total = $this->fullordertt->find_count($where);
  282. }
  283. else
  284. {
  285. $info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  286. $info_listb = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  287. $info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  288. $info_list = array_merge($info_lista,$info_listb);
  289. $total = $this->fullordersmt->find_count($where);
  290. $total += $this->fullorder->find_count($where);
  291. $total += $this->fullordertt->find_count($where);
  292. }
  293. //格式化数据
  294. foreach ($info_list as $key=>$value)
  295. {
  296. $shop = $this->shop->read($value['shop']);
  297. $fu = ($shop['type'] == "269")?'fullorder':'fullordersmt';
  298. $order = $this->$fu->read($value['id']);
  299. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  300. $info_list[$key]['shop'] = $shop['shopname'];
  301. $info_list[$key]['user'] = $shop['shopuser'];
  302. $warehouse = $this->warehouse->read($value['type']);
  303. $info_list[$key]['type'] = $warehouse['title'];
  304. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$order['hl']-$info_list[$key]['expressmoney'];
  305. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  306. $currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  307. $info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
  308. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  309. $shouldmoney += $info_list[$key]['shouldmoney'];
  310. $expressmoney += $info_list[$key]['expressmoney'];
  311. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  312. $budget += $info_list[$key]['budget'];
  313. $refundj += $info_list[$key]['refundj'];
  314. $cost += $info_list[$key]['cost'];
  315. $lr += $merge;
  316. }
  317. $shouldmoney = sprintf("%.2f",$shouldmoney);
  318. $expressmoney = sprintf("%.2f",$expressmoney);
  319. $budget = sprintf("%.2f",$budget);
  320. $refundj = sprintf("%.2f",$refundj);
  321. $cost = sprintf("%.2f",$cost);
  322. $lr = sprintf("%.2f",$lr);
  323. $pagenum = ceil($total/$perpage);
  324. $over = $total-($start+$perpage);
  325. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$cost,$lr)));
  326. echo json_encode($rows);exit;
  327. }
  328. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  329. $this->data['wlshop'] = $wlshop;
  330. if(isset($arg_array[0]))
  331. {
  332. $is = ($arg_array[0] == 'dlz')?'1':'2';
  333. $arg = $arg_array[0];
  334. }
  335. else
  336. {
  337. $is = '1';
  338. $arg = 'dlz';
  339. }
  340. $this->data['is'] = $is;
  341. $this->data['arg'] =$arg;
  342. $this->_Template('finance_cw',$this->data);
  343. }
  344. public function _ckcaiwu()//仓库财务
  345. {
  346. $user = $this->user->get_api($_SESSION['api']);
  347. if($user)
  348. {
  349. $fgshop = "";$sid = "";
  350. $user = explode('|',trim($user['shop'],'|'));
  351. foreach ($user as $value)
  352. {
  353. $fgshop .= " shop = ".$value." or";
  354. $sid .= " id = ".$value." or";
  355. }
  356. }
  357. $post = $this->input->post(NULL, TRUE);
  358. if(isset($post['page']))
  359. {
  360. $page = $this->input->post('page',true);
  361. $perpage = $this->input->post('perpage',true);
  362. $timetk = $this->input->post('timetk',true);
  363. $timetj = $this->input->post('timetj',true);
  364. $shop = $this->input->post('shop',true);
  365. $source = $this->input->post('source',true);
  366. $library = $this->input->post('library',true);
  367. $warehouse = $this->input->post('warehouse',true);
  368. $orderinfo = $this->input->post('orderinfo',true);
  369. $user = $this->input->post('user',true);
  370. $name = $this->input->post('name',true);
  371. $timetk = strtotime($timetk);
  372. $timetj = strtotime($timetj);
  373. $fullorder = $this->input->post('fullorder',true);
  374. $where = "mergeid = 0";
  375. if($timetk && $timetj)
  376. {
  377. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  378. }
  379. if($shop)
  380. {
  381. $where .= " and shop = '$shop'";
  382. }
  383. if($source)
  384. {
  385. $where .= " and source = '$source'";
  386. }
  387. if($library)
  388. {
  389. $where .= " and library = '$library'";
  390. }
  391. if($warehouse)
  392. {
  393. $where .= " and type = '$warehouse'";
  394. }
  395. if($orderinfo)
  396. {
  397. $where .= " and orderinfo = '$orderinfo'";
  398. }
  399. if($user)
  400. {
  401. $where .= " and user = '$user'";
  402. }
  403. if($name)
  404. {
  405. $where .= " and name = '$name'";
  406. }
  407. //数据排序
  408. $order_str = "id desc";
  409. if(empty($page))
  410. {
  411. $start = 0;
  412. $perpage = 1;
  413. }
  414. else
  415. {
  416. $start = ($page - 1)*$perpage;
  417. }
  418. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$purchase=0;$lr=0;
  419. //取得信息列表
  420. $info_list = $this->$fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,purchase,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  421. //格式化数据
  422. foreach ($info_list as $key=>$value)
  423. {
  424. $order = $this->$fullorder->read($value['id']);
  425. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  426. $shop = $this->shop->read($value['shop']);
  427. $info_list[$key]['shop'] = $shop['shopname'];
  428. $info_list[$key]['user'] = $shop['shopuser'];
  429. $warehouse = $this->warehouse->read($value['type']);
  430. $info_list[$key]['type'] = $warehouse['title'];
  431. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['purchase']/$order['hl']-$info_list[$key]['expressmoney'];
  432. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  433. $currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  434. $info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
  435. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  436. $shouldmoney += $info_list[$key]['shouldmoney'];
  437. $expressmoney += $info_list[$key]['expressmoney'];
  438. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  439. $budget += $info_list[$key]['budget'];
  440. $refundj += $info_list[$key]['refundj'];
  441. $purchase += $info_list[$key]['purchase'];
  442. $lr += $merge;
  443. }
  444. $money = $this->$fullorder->find_all($where);
  445. $shouldmoney = sprintf("%.2f",$shouldmoney);
  446. $expressmoney = sprintf("%.2f",$expressmoney);
  447. $budget = sprintf("%.2f",$budget);
  448. $refundj = sprintf("%.2f",$refundj);
  449. $purchase = sprintf("%.2f",$purchase);
  450. $lr = sprintf("%.2f",$lr);
  451. $total = $this->$fullorder->find_count($where);
  452. $pagenum = ceil($total/$perpage);
  453. $over = $total-($start+$perpage);
  454. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$purchase,$lr)));
  455. echo json_encode($rows);exit;
  456. }
  457. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  458. $this->data['wlshop'] = $wlshop;
  459. $this->_Template('finance_ckcw',$this->data);
  460. }
  461. //导出资金统计excel
  462. public function _excel()
  463. {
  464. if(isset($_GET['excel']))
  465. {
  466. $timetk = $this->input->get('timetk',true);
  467. $timetj = $this->input->get('timetj',true);
  468. $shop = $this->input->get('shop',true);
  469. $source = $this->input->get('source',true);
  470. $library = $this->input->get('library',true);
  471. $warehouse = $this->input->get('warehouse',true);
  472. $orderinfo = $this->input->get('orderinfo',true);
  473. $user = $this->input->get('user',true);
  474. $name = $this->input->get('name',true);
  475. $xztime = $this->input->get('xztime',true);
  476. $country = $this->input->get('country',true);
  477. $fullorder = $this->input->get('fullorder',true);
  478. $timetk = strtotime($timetk);
  479. $timetj = strtotime($timetj);
  480. $where = "mergeid = 0";
  481. if($timetk && $timetj)
  482. {
  483. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  484. }
  485. if($shop)
  486. {
  487. $where .= " and shop = '$shop'";
  488. }
  489. if($source)
  490. {
  491. $where .= " and source = '$source'";
  492. }
  493. if($library)
  494. {
  495. $where .= " and library = '$library'";
  496. }
  497. if($warehouse)
  498. {
  499. $where .= " and type = '$warehouse'";
  500. }
  501. if($orderinfo)
  502. {
  503. $where .= " and orderinfo = '$orderinfo'";
  504. }
  505. if($user)
  506. {
  507. $where .= " and user = '$user'";
  508. }
  509. if($name)
  510. {
  511. $where .= " and name = '$name'";
  512. }
  513. if($country)
  514. {
  515. $where .= " and country = '$country'";
  516. }
  517. /* 匹配ID加入 */
  518. $tc = array();$typeclass = array();
  519. $tclass = $this->typeclass->find_all();
  520. foreach ($tclass as $v)
  521. {
  522. $tc[$v['id']] = $v['title'];
  523. $typeclass[$v['id']] = $v;
  524. }
  525. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$refundj=0;$cost=0;$lr=0;
  526. //取得信息列表
  527. if($fullorder == 'fullordersmt')
  528. {
  529. $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  530. }
  531. else if($fullorder == 'fullorder')
  532. {
  533. $info_list = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  534. }
  535. else if($fullorder == 'fullordertt')
  536. {
  537. $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  538. }
  539. else
  540. {
  541. $info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  542. $info_listb = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  543. $info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  544. $info_list = array_merge($info_lista,$info_listb,$info_listc);
  545. }
  546. //格式化数据
  547. $i = 0;
  548. $classid = $this->classid->sku();
  549. foreach ($info_list as $key=>$value)
  550. {
  551. $value['hl'] = $value['hl']!=0?$value['hl']:6.71;
  552. $shop = $this->shop->read($value['shop']);
  553. $info_list[$key]['shop'] = $shop['shopname'];
  554. $info_list[$key]['user'] = $shop['shopuser'];
  555. $warehouse = $this->warehouse->read($value['type']);
  556. $info_list[$key]['type'] = $warehouse['title'];
  557. $country = $this->country->read($value['country']);
  558. $info_list[$key]['country'] = $country['ename'];
  559. $express = $this->express->read($value['express']);
  560. $info_list[$key]['express'] = $express['servicename'];
  561. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$value['hl']-$info_list[$key]['expressmoney'];
  562. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  563. $mergeid = ($value['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  564. $info_list[$key]['mergeid'] = sprintf("%.2f",$mergeid)."%";//利润百分比
  565. $info_list[$key]['shouldmoney'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['shouldmoney']/$value['hl']):$value['shouldmoney'];
  566. $shouldmoney += $info_list[$key]['shouldmoney'];
  567. $expressmoney += $info_list[$key]['expressmoney'];
  568. $info_list[$key]['budget'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['budget']/$value['hl']):$value['budget'];
  569. $budget += $info_list[$key]['budget'];
  570. $refundj += $info_list[$key]['refundj'];
  571. $cost += $info_list[$key]['cost'];
  572. $lr += $info_list[$key]['merge'];
  573. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  574. $fpdata = array();
  575. if(stripos($value['fpdata'],';') !== false)
  576. {
  577. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  578. foreach ($fpdata as $ke=>$va)
  579. {
  580. $dj = '';$ys = '';$hx = '';
  581. $pm = $classid;
  582. $jm = $classid;
  583. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  584. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  585. $ts = explode('|',trim($features,'|'));
  586. if(stripos($ts[0],',') !== false)
  587. {
  588. $ft = explode(',',$ts[0]);
  589. $features = explode('-',trim($ft[1],'-'));
  590. $features[] = $ft[0];
  591. }
  592. else
  593. {
  594. $features = explode('-',trim($ts[0],'-'));
  595. }
  596. foreach($features as $k=>$v)
  597. {
  598. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  599. {
  600. if($typeclass[$v]['bm'] != '')
  601. {
  602. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  603. }
  604. }
  605. if($v != 0)
  606. {
  607. if($typeclass[$v]['classid'] == 13)
  608. {
  609. $dj = $typeclass[$v]['title'];
  610. }
  611. if($typeclass[$v]['classid'] == 8)
  612. {
  613. $ys = $typeclass[$v]['title'];
  614. }
  615. if($typeclass[$v]['classid'] == 15)
  616. {
  617. $hx = $typeclass[$v]['title'];
  618. }
  619. if(isset($pm[$typeclass[$v]['classid']]))
  620. {
  621. if($typeclass[$v]['title'] == '9A')
  622. {
  623. $pm[$typeclass[$v]['classid']] = '9A';
  624. }
  625. else if($typeclass[$v]['title'] == '10A')
  626. {
  627. $pm[$typeclass[$v]['classid']] = '10A';
  628. }
  629. else
  630. {
  631. $clzh = $typeclass[$v]['zh'];
  632. if(stripos($typeclass[$v]['zh'],'|') !== false)
  633. {
  634. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  635. $clzh = $clzh[0];
  636. }
  637. $pm[$typeclass[$v]['classid']] = $clzh;
  638. }
  639. }
  640. if(isset($jm[$typeclass[$v]['classid']]))
  641. {
  642. if($typeclass[$v]['jm'])
  643. {
  644. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  645. }
  646. }
  647. }
  648. }
  649. $jm = array_filter($jm);//去除空值
  650. $jm = implode("-",$jm);
  651. $pm = array_filter($pm);//去除空值
  652. $zh = implode(" ",$pm);
  653. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  654. $fpdata[$ke] = array($ts[5],$dj,$ys,$hx,$jm,'03'.implode("",$bmpx),$ts[2]);//内容,尺寸,等级,颜色,数量
  655. }
  656. }
  657. $info_list[$key]['fpdata'] = $fpdata;
  658. $i++;
  659. }
  660. $shouldmoney = sprintf("%.2f",$shouldmoney);
  661. $expressmoney = sprintf("%.2f",$expressmoney);
  662. $budget = sprintf("%.2f",$budget);
  663. $refundj = sprintf("%.2f",$refundj);
  664. $cost = sprintf("%.2f",$cost);
  665. $lr = sprintf("%.2f",$lr);
  666. $data = array($shouldmoney.' USD',$budget.' USD',$expressmoney.' USD',$cost.' CNY',$refundj.' USD',$lr.' USD');
  667. $title = "财务统计信息";
  668. $titlename = "<table border=1>
  669. <tr><th colspan='25' align='left'><h3>".$title."<h3></th></tr>
  670. <tr>
  671. <td>NO.</td>
  672. <td>店铺名称</td>
  673. <td>负责人</td>
  674. <td>发货仓库</td>
  675. <td>客户名称</td>
  676. <td>订单号</td>
  677. <td>编号</td>
  678. <td>订单金额 USD</td>
  679. <td>预估金额 USD</td>
  680. <td>运费 USD</td>
  681. <td>成本 CNY</td>
  682. <td>补/退原额 USD</td>
  683. <td>补/退净额 USD</td>
  684. <td>补/退款交易号</td>
  685. <td>线下交易号</td>
  686. <td>原因</td>
  687. <td>利润 USD</td>
  688. <td>利润率</td>
  689. <td>订单备注</td>
  690. <td>客户备注</td>
  691. <td>发货备注</td>
  692. <td>国家</td>
  693. <td>物流</td>
  694. <td>出库时间</td>
  695. <td>
  696. <table border=1>
  697. <tr><td colspan='5' align='center'>订单产品信息</td></tr>
  698. <tr>
  699. <td>尺寸</td>
  700. <td>等级</td>
  701. <td>颜色</td>
  702. <td>花型</td>
  703. <td>料号</td>
  704. <td>编码</td>
  705. <td>数量</td>
  706. </tr>
  707. </table>
  708. </td>
  709. <td>总条数</td>
  710. </tr>
  711. </table>";
  712. $filename = $title.".xls";
  713. $tail = "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td>合计:</td><td>".$data[0]."</td><td>".$data[1]."</td><td>".$data[2]."</td><td>".$data[3]."</td><td>".$data[4]."</td><td></td><td></td><td></td><td></td><td>".$data[5]."</td><td></td><td></td></tr>\n";
  714. $this->excel->get_fz($info_list,$titlename,$filename,$tail);
  715. }
  716. }
  717. //仓库导出资金统计excel
  718. public function _ckexcel()
  719. {
  720. if(isset($_GET['excel']))
  721. {
  722. $timetk = $this->input->get('timetk',true);
  723. $timetj = $this->input->get('timetj',true);
  724. $shop = $this->input->get('shop',true);
  725. $source = $this->input->get('source',true);
  726. $library = $this->input->get('library',true);
  727. $warehouse = $this->input->get('warehouse',true);
  728. $orderinfo = $this->input->get('orderinfo',true);
  729. $user = $this->input->get('user',true);
  730. $name = $this->input->get('name',true);
  731. $timetk = strtotime($timetk);
  732. $timetj = strtotime($timetj);
  733. $fullorder = $this->input->get('fullorder',true);
  734. $where = "mergeid = 0";
  735. if($timetk && $timetj)
  736. {
  737. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  738. }
  739. if($shop)
  740. {
  741. $where .= " and shop = '$shop'";
  742. }
  743. if($source)
  744. {
  745. $where .= " and source = '$source'";
  746. }
  747. if($library)
  748. {
  749. $where .= " and library = '$library'";
  750. }
  751. if($warehouse)
  752. {
  753. $where .= " and type = '$warehouse'";
  754. }
  755. if($orderinfo)
  756. {
  757. $where .= " and orderinfo = '$orderinfo'";
  758. }
  759. if($user)
  760. {
  761. $where .= " and user = '$user'";
  762. }
  763. if($name)
  764. {
  765. $where .= " and name = '$name'";
  766. }
  767. /* 匹配ID加入 */
  768. $tc = array();
  769. $typeclass = $this->typeclass->find_all();
  770. foreach ($typeclass as $v)
  771. {
  772. if($_GET['excel'] == 2)
  773. {
  774. if($v['zh'] == '')
  775. {
  776. $tc[$v['id']] = $v['title'];
  777. }
  778. else
  779. {
  780. $tc[$v['id']] = $v['zh'];
  781. }
  782. }
  783. else
  784. {
  785. $tc[$v['id']] = $v['title'];
  786. }
  787. }
  788. $purchase=0;$cost=0;$lr=0;
  789. //取得信息列表
  790. $info_list = $this->$fullorder->find_all($where,'id,type,orderinfo,number,purchase,cost,merge,shipremarks,fpdata,hl,currencytitle');
  791. //格式化数据
  792. $i = 0;
  793. foreach ($info_list as $key=>$value)
  794. {
  795. $order = $this->$fullorder->read($value['id']);
  796. $warehouse = $this->warehouse->read($value['type']);
  797. $info_list[$key]['type'] = $warehouse['title'];
  798. $merge = $info_list[$key]['cost']-$info_list[$key]['purchase'];
  799. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  800. $purchase += $info_list[$key]['purchase'];
  801. $cost += $info_list[$key]['cost'];
  802. $lr += $info_list[$key]['merge'];
  803. $fpdata = array();
  804. if(stripos($value['fpdata'],';') !== false)
  805. {
  806. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  807. foreach ($fpdata as $ke=>$va)
  808. {
  809. $title = '';
  810. $fg = explode('|',$va);
  811. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  812. $cp = explode('-',rtrim($fg[0],'-'));
  813. $dj = (isset($cp[2]) && isset($tc[$cp[2]]))?$tc[$cp[2]]:'0';
  814. $ys = isset($cp[3])?(isset($tc[$cp[3]])?$tc[$cp[3]]:'没有此颜色'):'0';
  815. unset($cp[0],$cp[1],$cp[2],$cp[3]);
  816. foreach ($cp as $v)
  817. {
  818. if(isset($tc[$v]))
  819. {
  820. $title .= $tc[$v].' ';
  821. }
  822. }
  823. $fpdata[$ke] = array($fg[5],$dj,$ys,$title,$fg[2]);//内容,尺寸,等级,颜色,数量
  824. }
  825. }
  826. $info_list[$key]['fpdata'] = $fpdata;
  827. $i++;
  828. }
  829. $purchase = sprintf("%.2f",$purchase);
  830. $cost = sprintf("%.2f",$cost);
  831. $lr = sprintf("%.2f",$lr);
  832. $data = array($purchase.' CNY',$cost.' CNY',$lr.' CNY');
  833. $title = "财务统计信息";
  834. $titlename = "<table border=1>
  835. <tr><th colspan='10' align='left'><h3>".$title."<h3></th></tr>
  836. <tr>
  837. <td>NO.</td>
  838. <td>发货仓库</td>
  839. <td>订单号</td>
  840. <td>编号</td>
  841. <td>成本</td>
  842. <td>外贸成本</td>
  843. <td>利润</td>
  844. <td>发货备注</td>
  845. <td>
  846. <table border=1>
  847. <tr><td colspan='5' align='center'>订单产品信息</td></tr>
  848. <tr>
  849. <td>尺寸</td>
  850. <td>等级</td>
  851. <td>颜色</td>
  852. <td>花型</td>
  853. <td>数量</td>
  854. </tr>
  855. </table>
  856. </td>
  857. <td>总条数</td>
  858. </tr>
  859. </table>";
  860. $filename = $title.".xls";
  861. $tail = "<tr><td></td><td></td><td></td><td>合计:</td><td>".$data[0]."</td><td>".$data[1]."</td><td>".$data[2]."</td><td></td><td></td><td></td></tr>\n";
  862. $this->excel->get_fz($info_list,$titlename,$filename,$tail);
  863. }
  864. }
  865. //导出DHL发货清单统计excel
  866. public function _dhlfp()
  867. {
  868. if(isset($_GET['excel']))
  869. {
  870. $timetk = $this->input->get('timetk',true);
  871. $timetj = $this->input->get('timetj',true);
  872. $timetk = strtotime($timetk);
  873. $timetj = strtotime($timetj);
  874. $fullorder = $this->input->get('fullorder',true);
  875. $where = "mergeid = 0 and express = 1 and printtype = 1 and library = 2 and print = 3";
  876. if($timetk && $timetj)
  877. {
  878. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  879. }
  880. //取得信息列表
  881. $info_list = $this->$fullorder->find_all($where,'id,librarytime,waybill,country,al,zwpm,zsbjz');
  882. //格式化数据
  883. $i = 1;
  884. foreach ($info_list as $key=>$value)
  885. {
  886. $country = $this->country->read($value['country']);
  887. $info_list[$key]['country'] = $country['zname'];
  888. $info_list[$key]['id'] = $i;
  889. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  890. $i++;
  891. }
  892. $title = "CN PLT- 发票导出清单";
  893. $titlename = "<table border=1>
  894. <tr>
  895. <td>序号</td>
  896. <td>业务日期</td>
  897. <td>转单号码</td>
  898. <td>目的地</td>
  899. <td>二字码</td>
  900. <td>中文品名</td>
  901. <td>申报价</td>
  902. </table>";
  903. $filename = $title.".xls";
  904. $tail = "";
  905. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  906. }
  907. }
  908. public function _product($arg_array)
  909. {
  910. $post = $this->input->post(NULL, TRUE);
  911. if(isset($post['id']))
  912. {
  913. $id = $this->input->post('id',true);
  914. $post['fpdata'] = $this->input->post('fpdata');
  915. $post['expressmoney'] = $this->input->post('expressmoney',true);
  916. $post['cost'] = $this->input->post('cost',true);
  917. $post['purchase'] = $this->input->post('purchase',true);
  918. $fullorder = $this->input->post('fullorder',true);
  919. /**
  920. if($post['state'] == 216 && $ud['state'] != 216)
  921. {
  922. echo json_encode(array('msg'=>'不可修改为完成状态','success'=>false));exit;
  923. }
  924. **/
  925. if($this->$fullorder->save($post,$id))
  926. {
  927. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  928. }
  929. else
  930. {
  931. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  932. }
  933. }
  934. $fullorder = $arg_array[0];
  935. $is = ($fullorder == 'fullorder')?'1':'2';
  936. $fpdata = array();
  937. $fullorder = $this->$fullorder->read($arg_array[1]);
  938. $fullorder['parameter'] = str_replace(",","---",$fullorder['parameter']);
  939. $e = $fullorder['express'];//快递信息
  940. $c = $fullorder['country'];//国家信息
  941. $data = $this->logistics->find_all('express = "'.$e.'" and country = "'.$c.'"');
  942. if($data)
  943. {
  944. $fullorder['expressmoney'] = sprintf("%.2f",$data[0]['firstmoney']);
  945. }
  946. $this->data['fullorder'] = $fullorder;
  947. $this->data['countrys'] = $this->country->find_all();
  948. $this->data['express'] = $this->express->find_all();
  949. if(stripos($fullorder['fpdata'],';') !== false)
  950. {
  951. $fpdata = explode(';',rtrim($fullorder['fpdata'],';'));
  952. foreach ($fpdata as $k=>$v)
  953. {
  954. $fpdata[$k] = explode('|',$v);
  955. }
  956. }
  957. $this->data['fpdata'] = $fpdata;
  958. $shop = $this->shop->read($fullorder['shop']);
  959. $this->data['et'] = $shop['estimaterate'];//此店铺配置预计到帐金额比例
  960. //单项开始
  961. $warehouse = $this->warehouse->read($fullorder['warehouse']);//发货仓库
  962. $state = $this->typeclass->read($fullorder['state']);//订单状态
  963. $country = $this->country->read($fullorder['country']);//国家
  964. if($fullorder['capital'] == 1)
  965. {
  966. $capital = '暂未支付';
  967. }
  968. else if($fullorder['capital'] == 2)
  969. {
  970. $capital = '部分支付';
  971. }
  972. else if($fullorder['capital'] == 3)
  973. {
  974. $capital = '全部支付';
  975. }
  976. if($fullorder['printtype'] == 1)
  977. {
  978. $printtype = '运单';
  979. }
  980. else if($fullorder['printtype'] == 2)
  981. {
  982. $printtype = '发货单';
  983. }
  984. else if($fullorder['printtype'] == 3)
  985. {
  986. $printtype = '不打印单据';
  987. }
  988. else
  989. {
  990. $printtype = '未选择';
  991. }
  992. $this->data['warehouse'] = $warehouse['title'];
  993. $this->data['state'] = $state['title'];
  994. $this->data['capital'] = $capital;
  995. $this->data['country'] = $country['ename'];
  996. $this->data['printtype'] = $printtype;
  997. $this->data['is'] = $is;
  998. $systemwigsout = $this->systemwigsout->get_number($fullorder['number']);
  999. $wigsout = array();
  1000. if($systemwigsout)
  1001. {
  1002. $cz = explode('|',trim($systemwigsout['cz'],'|'));
  1003. $cztime = explode('|',trim($systemwigsout['cztime'],'|'));
  1004. $zw = array(1=>'配货',2=>'高针',3=>'完成',4=>'曲发',5=>'前处理',6=>'后处理',7=>'发型师',8=>'包装');
  1005. if($systemwigsout['cz'] != '' && count($cz) > 0)
  1006. {
  1007. for($i=0;$i<count($cz);$i++)
  1008. {
  1009. if(!isset($cztime[$i]))
  1010. {
  1011. $wigsout[] = $zw[$cz[$i]];
  1012. }
  1013. else
  1014. {
  1015. $wigsout[] = $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]);
  1016. }
  1017. }
  1018. }
  1019. }
  1020. $this->data['systemwigsout'] = $wigsout;
  1021. //单项结束
  1022. $this->_Template('finance_product',$this->data);
  1023. }
  1024. public function _ouout() //财务汇总导出
  1025. {
  1026. if(isset($_GET['excel']))
  1027. {
  1028. $timetk = $this->input->get('timetk',true);
  1029. $timetj = $this->input->get('timetj',true);
  1030. $shop = $this->input->get('shop',true);
  1031. $source = $this->input->get('source',true);
  1032. $library = $this->input->get('library',true);
  1033. $warehouse = $this->input->get('warehouse',true);
  1034. $orderinfo = $this->input->get('orderinfo',true);
  1035. $user = $this->input->get('user',true);
  1036. $name = $this->input->get('name',true);
  1037. $xztime = $this->input->get('xztime',true);
  1038. $country = $this->input->get('country',true);
  1039. $fullorder = $this->input->get('fullorder',true);
  1040. $timetk = strtotime($timetk);
  1041. $timetj = strtotime($timetj);
  1042. $where = "mergeid = 0";
  1043. if($timetk && $timetj)
  1044. {
  1045. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  1046. }
  1047. if($fullorder == 'sd')
  1048. {
  1049. echo '此功能只能单独导出独立站或速卖通数据';exit;
  1050. }
  1051. if($shop)
  1052. {
  1053. $where .= " and shop = '$shop'";
  1054. }
  1055. if($source)
  1056. {
  1057. $where .= " and source = '$source'";
  1058. }
  1059. if($library)
  1060. {
  1061. $where .= " and library = '$library'";
  1062. }
  1063. if($warehouse)
  1064. {
  1065. $where .= " and type = '$warehouse'";
  1066. }
  1067. if($orderinfo)
  1068. {
  1069. $where .= " and orderinfo = '$orderinfo'";
  1070. }
  1071. if($user)
  1072. {
  1073. $where .= " and user = '$user'";
  1074. }
  1075. if($name)
  1076. {
  1077. $where .= " and name = '$name'";
  1078. }
  1079. if($country)
  1080. {
  1081. $where .= " and country = '$country'";
  1082. }
  1083. //数据排序
  1084. $order_str = "id desc";
  1085. if(empty($page))
  1086. {
  1087. $start = 0;
  1088. $perpage = 1;
  1089. }
  1090. else
  1091. {
  1092. $start = ($page - 1)*$perpage;
  1093. }
  1094. //取得信息列表
  1095. $info_list = $this->$fullorder->find_all($where,'fpdata,library');
  1096. $rowsc = array();$rowst = array();
  1097. foreach ($info_list as $key=>$value)
  1098. {
  1099. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  1100. foreach ($fpdata as $va)
  1101. {
  1102. $fpdatason = explode('|',$va);
  1103. $fpdatason[1] = rtrim($fpdatason[1],' ');
  1104. str_replace(array('Peruvian','Indian','Brazilian','Malaysian'),array('','','',''),$fpdatason[1]);
  1105. if($value['library'] == 2)
  1106. {
  1107. $c = 1; $t = 0;
  1108. }
  1109. else
  1110. {
  1111. $c = 0; $t = 1;
  1112. }
  1113. if(isset($rows[$fpdatason[1]]))
  1114. {
  1115. $rows[$fpdatason[1]]['c'] += $c;
  1116. $rows[$fpdatason[1]]['t'] += $t;
  1117. }
  1118. else
  1119. {
  1120. $rows[$fpdatason[1]]['a'] = $fpdatason[1];
  1121. $rows[$fpdatason[1]]['c'] = $c;
  1122. $rows[$fpdatason[1]]['t'] = $t;
  1123. }
  1124. }
  1125. }
  1126. $title = date('Y-m-d',$timetk).'至'.date('Y-m-d',$timetj).'汇总详情';
  1127. $titlename = "<table border=1>
  1128. <tr><th colspan='3' align='center'><h3>".$title."<h3></th></tr>
  1129. <tr align='center'>
  1130. <td>产品名称</td>
  1131. <td>销售数量</td>
  1132. <td>退货数量</td>
  1133. </tr>
  1134. </table>";
  1135. $filename = $title.".xls";
  1136. $tail = "";
  1137. $this->excel->get_fz2($rows,$titlename,$filename,$tail);
  1138. }
  1139. }
  1140. public function _cksize()
  1141. {
  1142. if(isset($_GET['excel']))
  1143. {
  1144. $type = $this->input->get('excel',true);
  1145. $category = $this->input->get('category',true);
  1146. $size = $this->input->get('size',true);
  1147. $grade = $this->input->get('grade',true);
  1148. $color = $this->input->get('color',true);
  1149. $lowe = $this->input->get('lowe',true);
  1150. $sku = $this->input->get('sku',true);
  1151. $warehouse = $this->input->get('warehouse',true);
  1152. $shop = $this->input->get('shop',true);
  1153. $sid = $this->input->get('sid',true);
  1154. $ktime = $this->input->get('ktime',true);
  1155. $jtime = $this->input->get('jtime',true);
  1156. $ktime = strtotime($ktime);
  1157. $jtime = strtotime($jtime);
  1158. $where = "1=1 and shop != 9 and shop != 26";$gj = "";$ck = "";
  1159. if($category)
  1160. {
  1161. $where .= " and fpdata like '%-$category-%'";
  1162. }
  1163. if($size)
  1164. {
  1165. $where .= " and fpdata like '%-$size-%'";
  1166. }
  1167. if($grade)
  1168. {
  1169. $where .= " and fpdata like '%-$grade-%'";
  1170. }
  1171. if($color)
  1172. {
  1173. $where .= " and fpdata like '%-$color-%'";
  1174. }
  1175. if($lowe)
  1176. {
  1177. $where .= " and fpdata like '%-$lowe-%'";
  1178. }
  1179. if($shop)
  1180. {
  1181. $shopdata = '';
  1182. $sd = explode(',',rtrim($shop,','));
  1183. foreach ($sd as $v)
  1184. {
  1185. $shopdata .= "shop = '$v' or ";
  1186. }
  1187. $where .= " and (".rtrim($shopdata,'or ').")";
  1188. }
  1189. if($warehouse)
  1190. {
  1191. $warehousedata = '';
  1192. $wd = explode(',',rtrim($warehouse,','));
  1193. foreach ($wd as $v)
  1194. {
  1195. $warehousedata .= "warehouse = '$v' or ";
  1196. }
  1197. $where .= " and (".rtrim($warehousedata,'or ').")";
  1198. }
  1199. if($sku)
  1200. {
  1201. $where .= " and sku like '%$sku%'";
  1202. }
  1203. if($ktime && $jtime)
  1204. {
  1205. $where .= " and librarytime > '$ktime' and librarytime < '$jtime'";
  1206. }
  1207. $sidwhere = '';
  1208. if($sid)
  1209. {
  1210. $sd = "";
  1211. $s = explode(',',trim($sid,','));
  1212. foreach ($s as $value)
  1213. {
  1214. $sd .= " id = ".$value." or";
  1215. }
  1216. $sidwhere .= " and (".rtrim($sd,'or').")";
  1217. }
  1218. $typeclass = array();
  1219. $tc = $this->typeclass->find_all();
  1220. foreach ($tc as $v)
  1221. {
  1222. $typeclass[$v['id']] = array('ae'=>$v['spare'],'zh'=>$v['zh']);
  1223. }
  1224. //取得信息列表
  1225. $timeread = $ktime;
  1226. $timenum = ceil(($jtime - $ktime) / (24*3600));
  1227. $timelist = array();
  1228. for($i=4;$i<41;$i++)
  1229. {
  1230. if ($i%2==0)
  1231. {
  1232. $timelist[$i] = 0;
  1233. }
  1234. }
  1235. $info_lista = $this->fullorder->find_all($where.$sidwhere,'fpdata,number');
  1236. $info_listb = $this->fullordersmt->find_all($where.$sidwhere,'fpdata,number');
  1237. $info_list = array_merge($info_lista,$info_listb);
  1238. //echo "<pre>";
  1239. //print_r($info_list);
  1240. //exit();
  1241. $rows = array();$list = array();$cw = array();
  1242. foreach ($info_list as $key=>$value)
  1243. {
  1244. $thistime = $timelist;
  1245. $zdata = explode(';',trim($value['fpdata'],';'));
  1246. foreach ($zdata as $v)
  1247. {
  1248. if(stripos($v,'-131-') !== false || ($category != '' && stripos($v,'-'.$category.'-') === false))
  1249. {
  1250. continue;
  1251. }
  1252. $fpdata = explode('|',trim($v,'|'));
  1253. $xqdata = explode(',',trim($fpdata[0],','));
  1254. $cc = $typeclass[$xqdata[0]]['spare'];
  1255. if(!isset($xqdata[1]))
  1256. {
  1257. $cw[] = array($value['fpdata'],$value['number']);
  1258. }
  1259. $sku = $xqdata[1];
  1260. if(isset($rows[$sku]))
  1261. {
  1262. $rows[$sku][2][$cc] += 1;
  1263. }
  1264. else
  1265. {
  1266. $zh = '';
  1267. $zhdata = explode('-',trim($sku,'-'));
  1268. foreach ($zhdata as $kk => $vv)
  1269. {
  1270. if(isset($typeclass[$vv]['zh']) && $kk != 0)
  1271. {
  1272. $zh .= $typeclass[$vv]['zh'].' ';
  1273. }
  1274. }
  1275. $rows[$sku][0] = preg_replace('/ (\d+)inch/','',$fpdata[1]);
  1276. $rows[$sku][1] = trim($zh,' ');
  1277. $rows[$sku][2] = $thistime;
  1278. $rows[$sku][2][$cc] += 1;
  1279. }
  1280. }
  1281. }
  1282. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1283. <head>
  1284. <!--[if gte mso 9]><xml>
  1285. <x:ExcelWorkbook>
  1286. <x:ExcelWorksheets>
  1287. <x:ExcelWorksheet>
  1288. <x:Name>EXCEL</x:Name>
  1289. <x:WorksheetOptions>
  1290. <x:Print>
  1291. <x:ValidPrinterInfo />
  1292. </x:Print>
  1293. </x:WorksheetOptions>
  1294. </x:ExcelWorksheet>
  1295. </x:ExcelWorksheets>
  1296. </x:ExcelWorkbook>
  1297. </xml>
  1298. <![endif]-->
  1299. </head><body>";
  1300. $str .= "<table border=1><tr>";
  1301. $str .="<td>英文</td>";
  1302. $str .="<td>中文</td>";
  1303. foreach ($timelist as $k=>$v)
  1304. {
  1305. $str .="<td>".$k."</td>";
  1306. }
  1307. $str .= "</tr></table>";
  1308. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1309. foreach ($rows as $key=>$val)
  1310. {
  1311. $str .= "<tr><td>".$val[0]."</td>";
  1312. $str .= "<td>".$val[1]."</td>";
  1313. foreach ($val[2] as $k=>$v)
  1314. {
  1315. $str .= "<td>".$v."</td>";
  1316. }
  1317. $str .= "</tr>";
  1318. }
  1319. $str .= "</table>";
  1320. $str .= "</body></html>";
  1321. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1322. header( "Content-type: application/octet-stream" );
  1323. header( "Content-Disposition: attachment; filename=".time().'.xls' );
  1324. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1325. header( "Pragma: no-cache" );
  1326. header( "Expires: 0" );
  1327. exit($str);
  1328. }
  1329. if(isset($_SESSION['api']))
  1330. {
  1331. $user = $this->user->get_api($_SESSION['api']);
  1332. $usp = $user;
  1333. $fgshop = "";$sid = "";
  1334. $usersp = explode('|',trim($user['shop'],'|'));
  1335. foreach ($usersp as $value)
  1336. {
  1337. $fgshop .= " shop = ".$value." or";
  1338. $sid .= " id = ".$value." or";
  1339. }
  1340. }
  1341. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1342. $this->data['wlshop'] = $wlshop;
  1343. $this->_Template('finance_cksize',$this->data);
  1344. }
  1345. }