1、创建物流库存表。sql语句:
CREATE TABLE IF NOT EXISTS `emws_materials` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`name` varchar(60) NOT NULL,
`modulus` varchar(60) NOT NULL,
`stock_number` smallint(5) unsigned NOT NULL default '0',
`stock_in` smallint(5) unsigned NOT NULL default '0',
`stock_out` smallint(5) unsigned NOT NULL default '0',
`safe_day` smallint(5) unsigned NOT NULL default '0',
`intent_day` smallint(5) unsigned NOT NULL default '0',
`is_buy` tinyint(1) unsigned NOT NULL default '1',
`buy_url` varchar(60) NOT NULL,
`price` decimal(10,2) NOT NULL,
`weight` smallint(5) unsigned NOT NULL default '0',
`img` varchar(60) NOT NULL,
`desc_info` varchar(60) NOT NULL,
`remark` varchar(60) NOT NULL,
`admin_id` smallint(5) unsigned NOT NULL,
`update_time` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
2、php程序,materials.php:
<span> 1</span> <span>php </span><span> 2</span> <span>define</span>('IN_ECS', <span>true</span><span>); </span><span> 3</span> <span>require</span>(<span>dirname</span>(<span>__FILE__</span>) . '/includes/init.php'<span>); </span><span> 4</span> <span>include_once</span>(ROOT_PATH . 'includes/cls_image.php'<span>); </span><span> 5</span> <span>$image</span> = <span>new</span> cls_image(<span>$_CFG</span>['bgcolor'<span>]); </span><span> 6</span> <span>$exc</span> = <span>new</span> exchange(<span>$ecs</span>->table("materials"), <span>$db</span>, 'id', 'name'<span>); </span><span> 7</span> <span>$_REQUEST</span>['act']=!<span>empty</span>(<span>$_REQUEST</span>['act']) ? <span>$_REQUEST</span>['act']:'list'<span>; </span><span> 8</span> admin_priv('stock_alert');<span>//</span><span>权限:库存数量修改</span> <span> 9</span> <span>if</span>(<span>$_REQUEST</span>['act'] == 'list'<span>) </span><span> 10</span> <span>{ </span><span> 11</span> <span>$stock_list</span>=<span>material_list(); </span><span> 12</span> <span>$smarty</span>->assign('ur_here', '物料库存列表'<span>); </span><span> 13</span> <span>$smarty</span>->assign('stock_list', <span>$stock_list</span>['stock_list'<span>]); </span><span> 14</span> <span>$smarty</span>->assign('filter', <span>$stock_list</span>['filter'<span>]); </span><span> 15</span> <span>$smarty</span>->assign('record_count', <span>$stock_list</span>['record_count'<span>]); </span><span> 16</span> <span>$smarty</span>->assign('page_count', <span>$stock_list</span>['page_count'<span>]); </span><span> 17</span> <span> 18</span> <span>$smarty</span>->assign('shelf_list', <span>$shelf_list</span><span>); </span><span> 19</span> <span>$smarty</span>->assign('full_page', 1<span>); </span><span> 20</span> <span>$smarty</span>->assign('action_link', <span>array</span>('href' => 'goods_stock.php?act=list', 'text' => '商品库存列表'<span>)); </span><span> 21</span> <span>$smarty</span>->assign('action_link2', <span>array</span>('href' => 'materials.php?act=export', 'text' => '导出采购单'<span>)); </span><span> 22</span> <span>$smarty</span>->assign('action_link3', <span>array</span>('href' => 'materials.php?act=add', 'text' => '添加物料'<span>)); </span><span> 23</span> <span> 24</span> <span>$smarty</span>->display('material_list.htm'<span>); </span><span> 25</span> <span>} </span><span> 26</span> <span>elseif</span>(<span>$_REQUEST</span>['act'] == 'add'<span>) </span><span> 27</span> <span>{ </span><span> 28</span> <span>$smarty</span>->assign('ur_here', "添加物料"<span>); </span><span> 29</span> <span>$smarty</span>->assign('action_link', <span>array</span>('href' => 'materials.php?act=list', 'text' => '返回物料库存列表'<span>)); </span><span> 30</span> <span>$smarty</span>->assign('form_action', "insert"<span>); </span><span> 31</span> <span> 32</span> <span> assign_query_info(); </span><span> 33</span> <span>$smarty</span>->display('material_info.htm'<span>); </span><span> 34</span> <span>} </span><span> 35</span> <span>elseif</span>(<span>$_REQUEST</span>['act'] == 'insert'<span>) </span><span> 36</span> <span>{ </span><span> 37</span> <span>$material</span>['is_buy'] = <span>isset</span>(<span>$_REQUEST</span>['is_buy']) ? <span>intval</span>(<span>$_REQUEST</span>['is_buy']) : 1<span>; </span><span> 38</span> <span>$material</span>['name'] = <span>isset</span>(<span>$_REQUEST</span>['name']) ? <span>trim</span>(<span>$_REQUEST</span>['name']) : ''<span>; </span><span> 39</span> <span>$material</span>['modulus'] = <span>isset</span>(<span>$_REQUEST</span>['modulus']) ? <span>trim</span>(<span>$_REQUEST</span>['modulus']) : ''<span>; </span><span> 40</span> <span>$material</span>['safe_day'] = <span>isset</span>(<span>$_REQUEST</span>['safe_day']) ? <span>intval</span>(<span>$_REQUEST</span>['safe_day']) : 0<span>; </span><span> 41</span> <span>$material</span>['intent_day']= <span>isset</span>(<span>$_REQUEST</span>['intent_day']) ? <span>intval</span>(<span>$_REQUEST</span>['intent_day']) : 0<span>; </span><span> 42</span> <span>$material</span>['price'] = <span>isset</span>(<span>$_REQUEST</span>['price']) ? <span>floatval</span>(<span>$_REQUEST</span>['price']) : '0.00'<span>; </span><span> 43</span> <span>$material</span>['weight'] = <span>isset</span>(<span>$_REQUEST</span>['weight']) ? <span>intval</span>(<span>$_REQUEST</span>['weight']) : 0<span>; </span><span> 44</span> <span>$material</span>['desc_info'] = <span>isset</span>(<span>$_REQUEST</span>['desc_info']) ? <span>trim</span>(<span>$_REQUEST</span>['desc_info']) : ''<span>; </span><span> 45</span> <span>$material</span>['remark'] = <span>isset</span>(<span>$_REQUEST</span>['remark']) ? <span>trim</span>(<span>$_REQUEST</span>['remark']) : ''<span>; </span><span> 46</span> <span>$material</span>['update_time']=<span> gmtime(); </span><span> 47</span> <span>$material</span>['admin_id'] = <span>$_SESSION</span>['admin_id'<span>]; </span><span> 48</span> <span> 49</span> <span>if</span>(<span>empty</span>(<span>$material</span>['name']) || <span>empty</span>(<span>$material</span>['modulus']) || <span>empty</span>(<span>$material</span>['safe_day']) || <span>empty</span>(<span>$material</span>['intent_day'<span>])) </span><span> 50</span> <span> { </span><span> 51</span> sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1<span>); </span><span> 52</span> <span> } </span><span> 53</span> <span> 54</span> <span>$is_only</span> = <span>$exc</span>->is_only('name', <span>$material</span>['name'<span>]); </span><span> 55</span> <span>if</span> (!<span>$is_only</span><span>) </span><span> 56</span> <span> { </span><span> 57</span> sys_msg(<span>$material</span>['name'].',已存在', 1<span>); </span><span> 58</span> <span> } </span><span> 59</span> <span> 60</span> <span>/*</span><span>处理图片</span><span>*/</span> <span> 61</span> <span>$material</span>['img'] = <span>basename</span>(<span>$image</span>->upload_image(<span>$_FILES</span>['img'],'material'<span>)); </span><span> 62</span> <span>/*</span><span>处理URL</span><span>*/</span> <span> 63</span> <span>$material</span>['buy_url'] = sanitize_url(<span>$_POST</span>['buy_url'<span>]); </span><span> 64</span> <span>/*</span><span>插入数据</span><span>*/</span> <span> 65</span> <span>$db</span>->autoExecute(<span>$ecs</span>->table('materials'), <span>$material</span>, 'INSERT', '', 'SILENT'<span>); </span><span> 66</span> <span> 67</span> <span>$link</span>[0]['text'] = '继续添加'<span>; </span><span> 68</span> <span>$link</span>[0]['href'] = 'materials.php?act=add'<span>; </span><span> 69</span> <span>$link</span>[1]['text'] = '返回列表'<span>; </span><span> 70</span> <span>$link</span>[1]['href'] = 'materials.php?act=list'<span>; </span><span> 71</span> sys_msg('添加成功', 0, <span>$link</span><span>); </span><span> 72</span> <span>} </span><span> 73</span> <span>elseif</span>(<span>$_REQUEST</span>['act'] == 'updata'<span>) </span><span> 74</span> <span>{ </span><span> 75</span> <span>$id</span> = <span>isset</span>(<span>$_REQUEST</span>['id']) ? <span>intval</span>(<span>$_REQUEST</span>['id']) : 0<span>; </span><span> 76</span> <span>$material</span>['is_buy'] = <span>isset</span>(<span>$_REQUEST</span>['is_buy']) ? <span>intval</span>(<span>$_REQUEST</span>['is_buy']) : 1<span>; </span><span> 77</span> <span>$material</span>['name'] = <span>isset</span>(<span>$_REQUEST</span>['name']) ? <span>trim</span>(<span>$_REQUEST</span>['name']) : ''<span>; </span><span> 78</span> <span>$material</span>['modulus'] = <span>isset</span>(<span>$_REQUEST</span>['modulus']) ? <span>trim</span>(<span>$_REQUEST</span>['modulus']) : ''<span>; </span><span> 79</span> <span>$material</span>['safe_day'] = <span>isset</span>(<span>$_REQUEST</span>['safe_day']) ? <span>intval</span>(<span>$_REQUEST</span>['safe_day']) : 0<span>; </span><span> 80</span> <span>$material</span>['intent_day']= <span>isset</span>(<span>$_REQUEST</span>['intent_day']) ? <span>intval</span>(<span>$_REQUEST</span>['intent_day']) : 0<span>; </span><span> 81</span> <span>$material</span>['price'] = <span>isset</span>(<span>$_REQUEST</span>['price']) ? <span>floatval</span>(<span>$_REQUEST</span>['price']) : '0.00'<span>; </span><span> 82</span> <span>$material</span>['weight'] = <span>isset</span>(<span>$_REQUEST</span>['weight']) ? <span>intval</span>(<span>$_REQUEST</span>['weight']) : 0<span>; </span><span> 83</span> <span>$material</span>['desc_info'] = <span>isset</span>(<span>$_REQUEST</span>['desc_info']) ? <span>trim</span>(<span>$_REQUEST</span>['desc_info']) : ''<span>; </span><span> 84</span> <span>$material</span>['remark'] = <span>isset</span>(<span>$_REQUEST</span>['remark']) ? <span>trim</span>(<span>$_REQUEST</span>['remark']) : ''<span>; </span><span> 85</span> <span>$material</span>['update_time']=<span> gmtime(); </span><span> 86</span> <span>$material</span>['admin_id'] = <span>$_SESSION</span>['admin_id'<span>]; </span><span> 87</span> <span> 88</span> <span>if</span>(<span>empty</span>(<span>$id</span><span>)) </span><span> 89</span> <span> { </span><span> 90</span> sys_msg('ID不能为空', 1<span>); </span><span> 91</span> <span> } </span><span> 92</span> <span> 93</span> <span>if</span>(<span>empty</span>(<span>$material</span>['name']) || <span>empty</span>(<span>$material</span>['modulus']) || <span>empty</span>(<span>$material</span>['safe_day']) || <span>empty</span>(<span>$material</span>['intent_day'<span>])) </span><span> 94</span> <span> { </span><span> 95</span> sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1<span>); </span><span> 96</span> <span> } </span><span> 97</span> <span> 98</span> <span>/*</span><span>处理图片</span><span>*/</span> <span> 99</span> <span>if</span>(!<span>empty</span>(<span>$_FILES</span>['img']['name'<span>])) </span><span>100</span> <span> { </span><span>101</span> <span>$material</span>['img'] = <span>basename</span>(<span>$image</span>->upload_image(<span>$_FILES</span>['img'],'material'<span>)); </span><span>102</span> <span> } </span><span>103</span> <span>/*</span><span>处理URL</span><span>*/</span> <span>104</span> <span>$material</span>['buy_url'] = sanitize_url(<span>$_POST</span>['buy_url'<span>]); </span><span>105</span> <span>/*</span><span>插入数据</span><span>*/</span> <span>106</span> <span>$db</span>->autoExecute(<span>$ecs</span>->table('materials'), <span>$material</span>, 'UPDATE', "id = '<span>$id</span>'"<span>); </span><span>107</span> <span>108</span> <span>$link</span>[0]['text'] = '继续编辑'<span>; </span><span>109</span> <span>$link</span>[0]['href'] = 'materials.php?act=edit&id='.<span>$id</span><span>; </span><span>110</span> <span>$link</span>[1]['text'] = '返回列表'<span>; </span><span>111</span> <span>$link</span>[1]['href'] = 'materials.php?act=list'<span>; </span><span>112</span> sys_msg('编辑成功', 0, <span>$link</span><span>); </span><span>113</span> <span>} </span><span>114</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] =='edit'<span>) </span><span>115</span> <span>{ </span><span>116</span> <span>$sql</span> = "SELECT * FROM " .<span>$ecs</span>->table('materials'). " WHERE"<span>; </span><span>117</span> <span>$material</span> = <span>$db</span>->GetRow(<span>$sql</span><span>); </span><span>118</span> <span>$smarty</span>->assign('ur_here', "编辑物料"<span>); </span><span>119</span> <span>$smarty</span>->assign('action_link', <span>array</span>('href' => 'materials.php?act=list', 'text' => '返回物料库存列表'<span>)); </span><span>120</span> <span>$smarty</span>->assign('material', <span>$material</span><span>); </span><span>121</span> <span>$smarty</span>->assign('form_action', 'updata'<span>); </span><span>122</span> <span> assign_query_info(); </span><span>123</span> <span>$smarty</span>->display('material_info.htm'<span>); </span><span>124</span> <span>} </span><span>125</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'remove'<span>) </span><span>126</span> <span>{ </span><span>127</span> <span>$id</span> = <span>intval</span>(<span>$_GET</span>['id'<span>]); </span><span>128</span> <span>$exc</span>->drop(<span>$id</span><span>); </span><span>129</span> <span>$url</span> = 'materials.php?act=query&' . <span>str_replace</span>('act=remove', '', <span>$_SERVER</span>['QUERY_STRING'<span>]); </span><span>130</span> ecs_header("Location: <span>$url</span>\n"<span>); </span><span>131</span> <span>exit</span><span>; </span><span>132</span> <span>} </span><span>133</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'drop_img'<span>) </span><span>134</span> <span>{ </span><span>135</span> <span>$id</span> = <span>isset</span>(<span>$_GET</span>['id']) ? <span>intval</span>(<span>$_GET</span>['id']) : 0<span>; </span><span>136</span> <span>137</span> <span>$sql</span> = "SELECT img FROM " .<span>$ecs</span>->table('materials'). " WHERE id = '<span>$id</span>'"<span>; </span><span>138</span> <span>$img_name</span> = <span>$db</span>->getOne(<span>$sql</span><span>); </span><span>139</span> <span>140</span> <span>if</span> (!<span>empty</span>(<span>$img_name</span><span>)) </span><span>141</span> <span> { </span><span>142</span> @<span>unlink</span>(ROOT_PATH . DATA_DIR . '/material/' .<span>$img_name</span><span>); </span><span>143</span> <span>$sql</span> = "UPDATE " .<span>$ecs</span>->table('materials'). " SET img = '' WHERE id = '<span>$id</span>'"<span>; </span><span>144</span> <span>$db</span>->query(<span>$sql</span><span>); </span><span>145</span> <span> } </span><span>146</span> <span>$link</span>= <span>array</span>(<span>array</span>('text' => '继续编辑', 'href' => 'materials.php?act=edit&id=' . <span>$id</span>), <span>array</span>('text' => '返回物料库存列表', 'href' => 'materials.php?act=list'<span>)); </span><span>147</span> sys_msg('图片删除成功', 0, <span>$link</span><span>); </span><span>148</span> <span>} </span><span>149</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'edit_stock_in') <span>//</span><span>更改入库</span> <span>150</span> <span>{ </span><span>151</span> <span>$id</span> = <span>intval</span>(<span>$_POST</span>['id'<span>]); </span><span>152</span> <span>$val</span> = json_str_iconv(<span>trim</span>(<span>$_POST</span>['val'<span>])); </span><span>153</span> <span>/*</span><span> 检查格式 </span><span>*/</span> <span>154</span> <span>if</span>(!<span>is_numeric</span>(<span>$val</span>) || <span>$val</span> ) <span>155</span> <span> { </span><span>156</span> make_json_error(<span>sprintf</span>("格式不正确!", <span>$val</span><span>)); </span><span>157</span> <span> } </span><span>158</span> <span>159</span> <span>$exc</span>->edit("stock_in='<span>$val</span>'", <span>$id</span><span>); </span><span>160</span> make_json_result(<span>stripslashes</span>(<span>$val</span><span>)); </span><span>161</span> <span>} </span><span>162</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'edit_stock_out') <span>//</span><span>更改出库</span> <span>163</span> <span>{ </span><span>164</span> <span>$id</span> = <span>intval</span>(<span>$_POST</span>['id'<span>]); </span><span>165</span> <span>$val</span> = json_str_iconv(<span>trim</span>(<span>$_POST</span>['val'<span>])); </span><span>166</span> <span>/*</span><span> 检查格式 </span><span>*/</span> <span>167</span> <span>if</span>(!<span>is_numeric</span>(<span>$val</span>) || <span>$val</span> ) <span>168</span> <span> { </span><span>169</span> make_json_error(<span>sprintf</span>("格式不正确!", <span>$val</span><span>)); </span><span>170</span> <span> } </span><span>171</span> <span>$sql</span>="SELECT * FROM ".<span>$GLOBALS</span>['ecs']->table('materials')." where id = '".<span>$id</span>."'"<span>; </span><span>172</span> <span>$material</span> = <span>$GLOBALS</span>['db']->getRow(<span>$sql</span><span>); </span><span>173</span> <span>if</span>(<span>$val</span> > <span>$material</span>['stock_in'] + <span>$material</span>['stock_number'<span>]) </span><span>174</span> <span> { </span><span>175</span> make_json_error(<span>sprintf</span>("出库数不能大于现有库存与入库总和!", <span>$val</span><span>)); </span><span>176</span> <span> } </span><span>177</span> <span>178</span> <span>$exc</span>->edit("stock_out='<span>$val</span>'", <span>$id</span><span>); </span><span>179</span> make_json_result(<span>stripslashes</span>(<span>$val</span><span>)); </span><span>180</span> <span>} </span><span>181</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'operate') <span>//</span><span>批量入库/出库</span> <span>182</span> <span>{ </span><span>183</span> <span>$sql</span> = "UPDATE " .<span>$ecs</span>->table('materials'). " SET stock_number = stock_number + stock_in - stock_out,stock_out = 0,stock_in = 0,admin_id=<span>$_SESSION</span>[admin_id],update_time = ".<span>gmtime(); </span><span>184</span> <span>$db</span>->query(<span>$sql</span><span>); </span><span>185</span> <span>$link</span>= <span>array</span>(<span>array</span>('text' => '返回物料库存列表', 'href' => 'materials.php?act=list'<span>)); </span><span>186</span> sys_msg('成功批量入库/出库', 0, <span>$link</span><span>); </span><span>187</span> <span>} </span><span>188</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'export') <span>//</span><span>导出采购单</span> <span>189</span> <span>{ </span><span>190</span> <span>include_once</span>('includes/PHPExcel/PHPExcel.php'<span>); </span><span>191</span> <span>include_once</span>('corlor.php'<span>); </span><span>192</span> <span>$objPHPExcel</span> = <span>new</span><span> PHPExcel(); </span><span>193</span> <span>194</span> <span>$filename</span> = '物料采购表_'.<span>date</span>("YmdHi",<span>gmtime()); </span><span>195</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0<span>); </span><span>196</span> <span>$objPHPExcel</span>->getActiveSheet()->setTitle(<span>$filename</span><span>); </span><span>197</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('A')->setWidth(15<span>); </span><span>198</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('B')->setWidth(15<span>); </span><span>199</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('C')->setWidth(10<span>); </span><span>200</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('D')->setWidth(10<span>); </span><span>201</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('E')->setWidth(10<span>); </span><span>202</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('F')->setWidth(10<span>); </span><span>203</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('G')->setWidth(10<span>); </span><span>204</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('H')->setWidth(10<span>); </span><span>205</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('I')->setWidth(10<span>); </span><span>206</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('J')->setWidth(10<span>); </span><span>207</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>208</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>209</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>210</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>211</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>212</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>213</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::<span>HORIZONTAL_RIGHT); </span><span>214</span> <span>$objPHPExcel</span>->getActiveSheet()->getColumnDimension('K')->setWidth(10<span>); </span><span>215</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0<span>) </span><span>216</span> ->setCellValue('A1', '物料名称'<span>) </span><span>217</span> ->setCellValue('B1', '图片'<span>) </span><span>218</span> ->setCellValue('C1', '每天用量'<span>) </span><span>219</span> ->setCellValue('D1', '现有库存'<span>) </span><span>220</span> ->setCellValue('E1', '周转天数'<span>) </span><span>221</span> ->setCellValue('F1', '安全库存'<span>) </span><span>222</span> ->setCellValue('G1', '目标库存'<span>) </span><span>223</span> ->setCellValue('H1', '建议购买'<span>) </span><span>224</span> ->setCellValue('I1', '单价'<span>) </span><span>225</span> ->setCellValue('J1', '实际单价'<span>) </span><span>226</span> ->setCellValue('K1', '采购链接'<span>); </span><span>227</span> <span>$i</span>=2<span>; </span><span>228</span> <span>$stock_list</span> = material_list(<span>false</span><span>); </span><span>229</span> <span>$arr</span> = <span>$stock_list</span>['stock_list'<span>]; </span><span>230</span> <span>foreach</span>(<span>$arr</span> <span>as</span> <span>$v</span><span>) </span><span>231</span> <span> { </span><span>232</span> <span>if</span>(<span>$v</span>['img'<span>]) </span><span>233</span> <span> { </span><span>234</span> <span>$objPHPExcel</span>->getActiveSheet()->getRowDimension(<span>$i</span>)->setRowHeight(50<span>); </span><span>235</span> <span>$objDrawing</span> = <span>new</span><span> PHPExcel_Worksheet_Drawing(); </span><span>236</span> <span>$objDrawing</span>->setName('goods thumb'<span>); </span><span>237</span> <span>$objDrawing</span>->setDescription('Pgoods thumb'<span>); </span><span>238</span> <span>$img_path</span> = <span>file_exists</span>('../data/material/'.<span>$v</span>['img']) ? '../data/material/'.<span>$v</span>['img'] : '../images/no_img.jpg'<span>; </span><span>239</span> <span>$objDrawing</span>->setPath(<span>$img_path</span><span>); </span><span>240</span> <span>$objDrawing</span>->setWidth(100<span>); </span><span>241</span> <span>$objDrawing</span>->setCoordinates('B'.<span>$i</span><span>); </span><span>242</span> <span>$objDrawing</span>->setWorksheet(<span>$objPHPExcel</span>-><span>getActiveSheet()); </span><span>243</span> <span> } </span><span>244</span> <span>else</span> <span>245</span> <span> { </span><span>246</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->setCellValue('B'.<span>$i</span>, ''<span>); </span><span>247</span> <span> } </span><span>248</span> <span>249</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0<span>) </span><span>250</span> ->setCellValue('A'.<span>$i</span>, <span>$v</span>['name'<span>]) </span><span>251</span> ->setCellValue('C'.<span>$i</span>, <span>$v</span>['day_use'<span>]) </span><span>252</span> ->setCellValue('D'.<span>$i</span>, <span>$v</span>['stock_number'<span>]) </span><span>253</span> ->setCellValue('E'.<span>$i</span>, <span>$v</span>['stock_day'<span>]) </span><span>254</span> ->setCellValue('F'.<span>$i</span>, <span>$v</span>['stock_safe'<span>]) </span><span>255</span> ->setCellValue('G'.<span>$i</span>, <span>$v</span>['stock_intent'<span>]) </span><span>256</span> ->setCellValue('H'.<span>$i</span>, <span>$v</span>['proposal_buy'<span>]) </span><span>257</span> ->setCellValue('I'.<span>$i</span>, <span>$v</span>['price'<span>]) </span><span>258</span> ->setCellValue('J'.<span>$i</span>, ''<span>); </span><span>259</span> <span>if</span>(<span>$v</span>['stock_safe'] >= <span>$v</span>['stock_number'<span>]) </span><span>260</span> <span> { </span><span>261</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->getStyle('D'.<span>$i</span>)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::<span>COLOR_RED); </span><span>262</span> <span> } </span><span>263</span> <span>if</span>(<span>$v</span>['buy_url'] != 'http://'<span>) </span><span>264</span> <span> { </span><span>265</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->setCellValue('K'.<span>$i</span>, '采购链接'<span>); </span><span>266</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->getCell('K'.<span>$i</span>)->getHyperlink()->setUrl(<span>$v</span>['buy_url'<span>]); </span><span>267</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->getCell('K'.<span>$i</span>)->getHyperlink()->setTooltip('采购链接'<span>); </span><span>268</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->getStyle('K'.<span>$i</span>)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::<span>COLOR_BLUE); </span><span>269</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->getStyle('K'.<span>$i</span>)->getFont()->setUnderline(PHPExcel_Style_Font::<span>UNDERLINE_SINGLE); </span><span>270</span> <span> } </span><span>271</span> <span>else</span> <span>272</span> <span> { </span><span>273</span> <span>$objPHPExcel</span>->setActiveSheetIndex(0)->setCellValue('K'.<span>$i</span>, ''<span>); </span><span>274</span> <span> } </span><span>275</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('A'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>276</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('B'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>277</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('C'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>278</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('D'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>279</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('E'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>280</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('F'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>281</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('G'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>282</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('H'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>283</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('I'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>284</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('J'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>285</span> <span>$objPHPExcel</span>->getActiveSheet()->getStyle('K'.<span>$i</span>)->getAlignment()->setVertical(PHPExcel_Style_Alignment::<span>VERTICAL_CENTER); </span><span>286</span> <span>$i</span>++<span>; </span><span>287</span> <span> } </span><span>288</span> <span>$file_name</span> = <span>$filename</span>.'.xls'<span>; </span><span>289</span> <span>header</span>('Content-Type: application/vnd.ms-excel'<span>); </span><span>290</span> <span>header</span>('Content-Disposition: attachment;filename="'.<span>$file_name</span>.'"'<span>); </span><span>291</span> <span>header</span>('Cache-Control: max-age=0'<span>); </span><span>292</span> <span>$objWriter</span> = PHPExcel_IOFactory::createWriter(<span>$objPHPExcel</span>, 'Excel5'<span>); </span><span>293</span> <span>$objWriter</span>->save('php://output'<span>); </span><span>294</span> <span>exit</span><span>; </span><span>295</span> <span>} </span><span>296</span> <span>elseif</span> (<span>$_REQUEST</span>['act'] == 'query'<span>) </span><span>297</span> <span>{ </span><span>298</span> <span>$stock_list</span> =<span> material_list(); </span><span>299</span> <span>$smarty</span>->assign('stock_list', <span>$stock_list</span>['stock_list'<span>]); </span><span>300</span> <span>$smarty</span>->assign('filter', <span>$stock_list</span>['filter'<span>]); </span><span>301</span> <span>$smarty</span>->assign('record_count', <span>$stock_list</span>['record_count'<span>]); </span><span>302</span> <span>$smarty</span>->assign('page_count', <span>$stock_list</span>['page_count'<span>]); </span><span>303</span> make_json_result(<span>$smarty</span>->fetch('material_list.htm'), '', <span>array</span>('filter' => <span>$stock_list</span>['filter'], 'page_count' => <span>$stock_list</span>['page_count'<span>])); </span><span>304</span> <span>} </span><span>305</span> <span>306</span> <span>function</span> material_list(<span>$is_pagination</span> = <span>true</span><span>) </span><span>307</span> <span>{ </span><span>308</span> <span>GLOBAL</span> <span>$ecs</span>,<span>$db</span><span>; </span><span>309</span> <span>$result</span> =<span> get_filter(); </span><span>310</span> <span>if</span> (<span>$result</span> === <span>false</span><span>) </span><span>311</span> <span> { </span><span>312</span> <span>$filter</span>['sort_by'] = <span>empty</span>(<span>$_REQUEST</span>['sort_by']) ? 'id' : <span>trim</span>(<span>$_REQUEST</span>['sort_by'<span>]); </span><span>313</span> <span>$filter</span>['sort_order'] = <span>empty</span>(<span>$_REQUEST</span>['sort_order']) ? 'desc' : <span>trim</span>(<span>$_REQUEST</span>['sort_order'<span>]); </span><span>314</span> <span>$where</span> = " WHERE 1 = 1 "<span>; </span><span>315</span> <span>316</span> <span>$sql</span> = 'select count(t.id) from '.<span>$ecs</span>->table('materials'). ' as t '.<span>$where</span><span>; </span><span>317</span> <span>318</span> <span>$filter</span>['record_count'] = <span>$db</span>->getOne(<span>$sql</span><span>); </span><span>319</span> <span>320</span> <span>/*</span><span> 分页大小 </span><span>*/</span> <span>321</span> <span>$filter</span> = page_and_size(<span>$filter</span><span>); </span><span>322</span> <span>323</span> <span>$sql</span> = 'select t.*, au.user_name from '. <span>324</span> <span>$ecs</span>->table('materials').' as t left join '. <span>325</span> <span>$ecs</span>->table('admin_user')." as au on t.admin_id=au.user_id ".<span>$where</span>. <span>326</span> ' order by '.<span>$filter</span>['sort_by']." ".<span>$filter</span>['sort_order'<span>]; </span><span>327</span> <span>328</span> <span>if</span> (<span>$is_pagination</span><span>) </span><span>329</span> <span> { </span><span>330</span> <span>$sql</span> .= " LIMIT " . <span>$filter</span>['start'] . ', ' . <span>$filter</span>['page_size'<span>]; </span><span>331</span> <span> } </span><span>332</span> <span>333</span> <span>$end_time</span> = <span>strtotime</span>(<span>date</span>("Y-m-d",<span>gmtime())); </span><span>334</span> <span>$start_time</span> = <span>$end_time</span> - 7 * 86400<span>; </span><span>335</span> <span>$query</span> = "SELECT count(order_id) as total FROM ".<span>$GLOBALS</span>['ecs']->table('order_info')." WHERE synch_time $end_time."' and synch_time >= '".<span>$start_time</span>."'"<span>; </span><span>336</span> <span>$filter</span>['orders'] = <span>round</span>(<span>$GLOBALS</span>['db']->getOne(<span>$query</span>) / 7);<span>//</span><span>7天平均订单数 </span> <span>337</span> <span>$filter</span>['orders'] = <span>$filter</span>['orders'] ? <span>$filter</span>['orders'] : 1400<span>; </span><span>338</span> set_filter(<span>$filter</span>, <span>$sql</span><span>); </span><span>339</span> <span> } </span><span>340</span> <span>else</span> <span>341</span> <span> { </span><span>342</span> <span>$sql</span> = <span>$result</span>['sql'<span>]; </span><span>343</span> <span>$filter</span> = <span>$result</span>['filter'<span>]; </span><span>344</span> <span> } </span><span>345</span> <span>$row</span> = <span>$GLOBALS</span>['db']->getAll(<span>$sql</span><span>); </span><span>346</span> <span>347</span> <span>$orders</span> = <span>$filter</span>['orders'<span>]; </span><span>348</span> <span>foreach</span>(<span>$row</span> <span>as</span> <span>$k</span>=><span>$val</span><span>) </span><span>349</span> <span> { </span><span>350</span> <span>if</span> (<span>$is_pagination</span> == <span>false</span> && <span>$val</span>['is_buy'] == 0) <span>//</span><span>不购买,不导出</span> <span>351</span> <span> { </span><span>352</span> <span>unset</span>(<span>$row</span>[<span>$k</span><span>]); </span><span>353</span> <span>continue</span><span>; </span><span>354</span> <span> } </span><span>355</span> <span>$row</span>[<span>$k</span>]['update_time'] = local_date('Y-m-d H:i',<span>$val</span>['update_time'<span>]); </span><span>356</span> <span>$row</span>[<span>$k</span>]['day_use'] = <span>$day_use</span> = <span>round</span>(<span>$orders</span> * <span>$val</span>['modulus'],1);<span>//</span><span>每日用量</span> <span>357</span> <span>$row</span>[<span>$k</span>]['stock_day'] = <span>$day_use</span> ? <span>round</span>(<span>$val</span>['stock_number'] / <span>$day_use</span>,1) : 0;<span>//</span><span>周转天数</span> <span>358</span> <span>$row</span>[<span>$k</span>]['stock_safe'] = <span>round</span>(<span>$val</span>['safe_day'] * <span>$day_use</span>,1);<span>//</span><span>安全库存</span> <span>359</span> <span>$row</span>[<span>$k</span>]['stock_intent']= <span>$stock_intent</span> = <span>round</span>(<span>$val</span>['intent_day'] * <span>$day_use</span>,1);<span>//</span><span>目标库存</span> <span>360</span> <span>$row</span>[<span>$k</span>]['proposal_buy']= <span>round</span>(<span>$stock_intent</span> - <span>$val</span>['stock_number'],1);<span>//</span><span>建议购买</span> <span>361</span> <span> } </span><span>362</span> <span>363</span> <span>$stock_list</span> = <span>array</span>('stock_list' => <span>$row</span>, 'filter' => <span>$filter</span>, 'page_count' => <span>$filter</span>['page_count'], 'record_count' => <span>$filter</span>['record_count'<span>]); </span><span>364</span> <span>return</span> <span>$stock_list</span><span>; </span><span>365</span> <span>} </span><span>366</span> ?>
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . 'includes/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);
$exc = new exchange($ecs->table("materials"), $db, 'id', 'name');
$_REQUEST['act']=!empty($_REQUEST['act']) ? $_REQUEST['act']:'list';
admin_priv('stock_alert');//权限:库存数量修改
if($_REQUEST['act'] == 'list')
{
$stock_list=material_list();
$smarty->assign('ur_here', '物料库存列表');
$smarty->assign('stock_list', $stock_list['stock_list']);
$smarty->assign('filter', $stock_list['filter']);
$smarty->assign('record_count', $stock_list['record_count']);
$smarty->assign('page_count', $stock_list['page_count']);
$smarty->assign('shelf_list', $shelf_list);
$smarty->assign('full_page', 1);
$smarty->assign('action_link', array('href' => 'goods_stock.php?act=list', 'text' => '商品库存列表'));
$smarty->assign('action_link2', array('href' => 'materials.php?act=export', 'text' => '导出采购单'));
$smarty->assign('action_link3', array('href' => 'materials.php?act=add', 'text' => '添加物料'));
$smarty->display('material_list.htm');
}
elseif($_REQUEST['act'] == 'add')
{
$smarty->assign('ur_here', "添加物料");
$smarty->assign('action_link', array('href' => 'materials.php?act=list', 'text' => '返回物料库存列表'));
$smarty->assign('form_action', "insert");
assign_query_info();
$smarty->display('material_info.htm');
}
elseif($_REQUEST['act'] == 'insert')
{
$material['is_buy'] = isset($_REQUEST['is_buy']) ? intval($_REQUEST['is_buy']) : 1;
$material['name'] = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : '';
$material['modulus'] = isset($_REQUEST['modulus']) ? trim($_REQUEST['modulus']) : '';
$material['safe_day'] = isset($_REQUEST['safe_day']) ? intval($_REQUEST['safe_day']) : 0;
$material['intent_day']= isset($_REQUEST['intent_day']) ? intval($_REQUEST['intent_day']) : 0;
$material['price'] = isset($_REQUEST['price']) ? floatval($_REQUEST['price']) : '0.00';
$material['weight'] = isset($_REQUEST['weight']) ? intval($_REQUEST['weight']) : 0;
$material['desc_info'] = isset($_REQUEST['desc_info']) ? trim($_REQUEST['desc_info']) : '';
$material['remark'] = isset($_REQUEST['remark']) ? trim($_REQUEST['remark']) : '';
$material['update_time']= gmtime();
$material['admin_id'] = $_SESSION['admin_id'];
if(empty($material['name']) || empty($material['modulus']) || empty($material['safe_day']) || empty($material['intent_day']))
{
sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1);
}
$is_only = $exc->is_only('name', $material['name']);
if (!$is_only)
{
sys_msg($material['name'].',已存在', 1);
}
/*处理图片*/
$material['img'] = basename($image->upload_image($_FILES['img'],'material'));
/*处理URL*/
$material['buy_url'] = sanitize_url($_POST['buy_url']);
/*插入数据*/
$db->autoExecute($ecs->table('materials'), $material, 'INSERT', '', 'SILENT');
$link[0]['text'] = '继续添加';
$link[0]['href'] = 'materials.php?act=add';
$link[1]['text'] = '返回列表';
$link[1]['href'] = 'materials.php?act=list';
sys_msg('添加成功', 0, $link);
}
elseif($_REQUEST['act'] == 'updata')
{
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$material['is_buy'] = isset($_REQUEST['is_buy']) ? intval($_REQUEST['is_buy']) : 1;
$material['name'] = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : '';
$material['modulus'] = isset($_REQUEST['modulus']) ? trim($_REQUEST['modulus']) : '';
$material['safe_day'] = isset($_REQUEST['safe_day']) ? intval($_REQUEST['safe_day']) : 0;
$material['intent_day']= isset($_REQUEST['intent_day']) ? intval($_REQUEST['intent_day']) : 0;
$material['price'] = isset($_REQUEST['price']) ? floatval($_REQUEST['price']) : '0.00';
$material['weight'] = isset($_REQUEST['weight']) ? intval($_REQUEST['weight']) : 0;
$material['desc_info'] = isset($_REQUEST['desc_info']) ? trim($_REQUEST['desc_info']) : '';
$material['remark'] = isset($_REQUEST['remark']) ? trim($_REQUEST['remark']) : '';
$material['update_time']= gmtime();
$material['admin_id'] = $_SESSION['admin_id'];
if(empty($id))
{
sys_msg('ID不能为空', 1);
}
if(empty($material['name']) || empty($material['modulus']) || empty($material['safe_day']) || empty($material['intent_day']))
{
sys_msg('名称、系数、安全天数、目标天数,不能为空或者格式不正确', 1);
}
/*处理图片*/
if(!empty($_FILES['img']['name']))
{
$material['img'] = basename($image->upload_image($_FILES['img'],'material'));
}
/*处理URL*/
$material['buy_url'] = sanitize_url($_POST['buy_url']);
/*插入数据*/
$db->autoExecute($ecs->table('materials'), $material, 'UPDATE', "id = '$id'");
$link[0]['text'] = '继续编辑';
$link[0]['href'] = 'materials.php?act=edit&id='.$id;
$link[1]['text'] = '返回列表';
$link[1]['href'] = 'materials.php?act=list';
sys_msg('编辑成功', 0, $link);
}
elseif ($_REQUEST['act'] =='edit')
{
$sql = "SELECT * FROM " .$ecs->table('materials'). " WHERE";
$material = $db->GetRow($sql);
$smarty->assign('ur_here', "编辑物料");
$smarty->assign('action_link', array('href' => 'materials.php?act=list', 'text' => '返回物料库存列表'));
$smarty->assign('material', $material);
$smarty->assign('form_action', 'updata');
assign_query_info();
$smarty->display('material_info.htm');
}
elseif ($_REQUEST['act'] == 'remove')
{
$id = intval($_GET['id']);
$exc->drop($id);
$url = 'materials.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
ecs_header("Location: $url\n");
exit;
}
elseif ($_REQUEST['act'] == 'drop_img')
{
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sql = "SELECT img FROM " .$ecs->table('materials'). " WHERE id = '$id'";
$img_name = $db->getOne($sql);
if (!empty($img_name))
{
@unlink(ROOT_PATH . DATA_DIR . '/material/' .$img_name);
$sql = "UPDATE " .$ecs->table('materials'). " SET img = '' WHERE id = '$id'";
$db->query($sql);
}
$link= array(array('text' => '继续编辑', 'href' => 'materials.php?act=edit&id=' . $id), array('text' => '返回物料库存列表', 'href' => 'materials.php?act=list'));
sys_msg('图片删除成功', 0, $link);
}
elseif ($_REQUEST['act'] == 'edit_stock_in') //更改入库
{
$id = intval($_POST['id']);
$val = json_str_iconv(trim($_POST['val']));
/* 检查格式 */
if(!is_numeric($val) || $val {
make_json_error(sprintf("格式不正确!", $val));
}
$exc->edit("stock_in='$val'", $id);
make_json_result(stripslashes($val));
}
elseif ($_REQUEST['act'] == 'edit_stock_out') //更改出库
{
$id = intval($_POST['id']);
$val = json_str_iconv(trim($_POST['val']));
/* 检查格式 */
if(!is_numeric($val) || $val {
make_json_error(sprintf("格式不正确!", $val));
}
$sql="SELECT * FROM ".$GLOBALS['ecs']->table('materials')." where id = '".$id."'";
$material = $GLOBALS['db']->getRow($sql);
if($val > $material['stock_in'] + $material['stock_number'])
{
make_json_error(sprintf("出库数不能大于现有库存与入库总和!", $val));
}
$exc->edit("stock_out='$val'", $id);
make_json_result(stripslashes($val));
}
elseif ($_REQUEST['act'] == 'operate') //批量入库/出库
{
$sql = "UPDATE " .$ecs->table('materials'). " SET stock_number = stock_number + stock_in - stock_out,stock_out = 0,stock_in = 0,admin_id=$_SESSION[admin_id],update_time = ".gmtime();
$db->query($sql);
$link= array(array('text' => '返回物料库存列表', 'href' => 'materials.php?act=list'));
sys_msg('成功批量入库/出库', 0, $link);
}
elseif ($_REQUEST['act'] == 'export') //导出采购单
{
include_once('includes/PHPExcel/PHPExcel.php');
include_once('corlor.php');
$objPHPExcel = new PHPExcel();
$filename = '物料采购表_'.date("YmdHi",gmtime());
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle($filename);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(10);
$objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '物料名称')
->setCellValue('B1', '图片')
->setCellValue('C1', '每天用量')
->setCellValue('D1', '现有库存')
->setCellValue('E1', '周转天数')
->setCellValue('F1', '安全库存')
->setCellValue('G1', '目标库存')
->setCellValue('H1', '建议购买')
->setCellValue('I1', '单价')
->setCellValue('J1', '实际单价')
->setCellValue('K1', '采购链接');
$i=2;
$stock_list = material_list(false);
$arr = $stock_list['stock_list'];
foreach($arr as $v)
{
if($v['img'])
{
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(50);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('goods thumb');
$objDrawing->setDescription('Pgoods thumb');
$img_path = file_exists('../data/material/'.$v['img']) ? '../data/material/'.$v['img'] : '../images/no_img.jpg';
$objDrawing->setPath($img_path);
$objDrawing->setWidth(100);
$objDrawing->setCoordinates('B'.$i);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
}
else
{
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, '');
}
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $v['name'])
->setCellValue('C'.$i, $v['day_use'])
->setCellValue('D'.$i, $v['stock_number'])
->setCellValue('E'.$i, $v['stock_day'])
->setCellValue('F'.$i, $v['stock_safe'])
->setCellValue('G'.$i, $v['stock_intent'])
->setCellValue('H'.$i, $v['proposal_buy'])
->setCellValue('I'.$i, $v['price'])
->setCellValue('J'.$i, '');
if($v['stock_safe'] >= $v['stock_number'])
{
$objPHPExcel->setActiveSheetIndex(0)->getStyle('D'.$i)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
}
if($v['buy_url'] != 'http://')
{
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('K'.$i, '采购链接');
$objPHPExcel->setActiveSheetIndex(0)->getCell('K'.$i)->getHyperlink()->setUrl($v['buy_url']);
$objPHPExcel->setActiveSheetIndex(0)->getCell('K'.$i)->getHyperlink()->setTooltip('采购链接');
$objPHPExcel->setActiveSheetIndex(0)->getStyle('K'.$i)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLUE);
$objPHPExcel->setActiveSheetIndex(0)->getStyle('K'.$i)->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
}
else
{
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('K'.$i, '');
}
$objPHPExcel->getActiveSheet()->getStyle('A'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('B'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('C'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('D'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('E'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('F'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('G'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('H'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('I'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('J'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('K'.$i)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$i++;
}
$file_name = $filename.'.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$file_name.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
elseif ($_REQUEST['act'] == 'query')
{
$stock_list = material_list();
$smarty->assign('stock_list', $stock_list['stock_list']);
$smarty->assign('filter', $stock_list['filter']);
$smarty->assign('record_count', $stock_list['record_count']);
$smarty->assign('page_count', $stock_list['page_count']);
make_json_result($smarty->fetch('material_list.htm'), '', array('filter' => $stock_list['filter'], 'page_count' => $stock_list['page_count']));
}
function material_list($is_pagination = true)
{
GLOBAL $ecs,$db;
$result = get_filter();
if ($result === false)
{
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'desc' : trim($_REQUEST['sort_order']);
$where = " WHERE 1 = 1 ";
$sql = 'select count(t.id) from '.$ecs->table('materials'). ' as t '.$where;
$filter['record_count'] = $db->getOne($sql);
/* 分页大小 */
$filter = page_and_size($filter);
$sql = 'select t.*, au.user_name from '.
$ecs->table('materials').' as t left join '.
$ecs->table('admin_user')." as au on t.admin_id=au.user_id ".$where.
' order by '.$filter['sort_by']." ".$filter['sort_order'];
if ($is_pagination)
{
$sql .= " LIMIT " . $filter['start'] . ', ' . $filter['page_size'];
}
$end_time = strtotime(date("Y-m-d",gmtime()));
$start_time = $end_time - 7 * 86400;
$query = "SELECT count(order_id) as total FROM ".$GLOBALS['ecs']->table('order_info')." WHERE synch_time = '".$start_time."'";
$filter['orders'] = round($GLOBALS['db']->getOne($query) / 7);//7天平均订单数
$filter['orders'] = $filter['orders'] ? $filter['orders'] : 1400;
set_filter($filter, $sql);
}
else
{
$sql = $result['sql'];
$filter = $result['filter'];
}
$row = $GLOBALS['db']->getAll($sql);
$orders = $filter['orders'];
foreach($row as $k=>$val)
{
if ($is_pagination == false && $val['is_buy'] == 0) //不购买,不导出
{
unset($row[$k]);
continue;
}