> 백엔드 개발 > PHP 튜토리얼 > ECSHOP 자재재고관리

ECSHOP 자재재고관리

WBOY
풀어 주다: 2016-08-08 09:30:15
원래의
956명이 탐색했습니다.

1、创建물류库存表。sql语句:

`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 기본값 '0',
`stock_in` smallint(5) unsigned NOT NULL 기본값 '0',
`stock_out` smallint(5) unsigned NOT NULL 기본값 '0',
`safe_day` smallint(5) unsigned NOT NULL 기본값 '0',
`intent_day` smallint(5) unsigned NOT NULL 기본값 '0',
`is_buy`tinyint (1) unsigned NOT NULL 기본값 '1',
`buy_url` varchar(60) NOT NULL,
`price` 소수(10,2) NOT NULL,
`weight` smallint(5) unsigned NOT NULL 기본값 '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> < 0<span>)
</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> < 0<span>)
</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 < '".<span>$end_time</span>."' 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' , '이름');
$_REQUEST['act']=!empty($_REQUEST['act']) ? $_REQUEST['act']:'list';
admin_priv('stock_alert');//权限:库存数weight修改
if($_REQUEST['act'] == 'list')
{
    $stock_list=material_list();
    $smarty->asset('ur_here',      '물料库存列表');
    $smarty->ass('stock_list',     $stock_list[' stock_list']);
    $smarty->asse('filter',       $stock_list['filter']);
    $smarty->ass('record_count', $stock_list['record_count']) ;
    $smarty->ass('page_count',   $stock_list['page_count']);
    
    $smarty->ass('shelf_list',     $shelf_list);
    $smarty ->할당('full_page',    1);
    $smarty->할당('action_link',  array('href' => 'goods_stock.php?act=list', 'text' => '商品库存列表'));
    $smarty->할당('action_link2',  array('href' => 'materials.php?act=export', 'text' => '导出采购单'));
    $smarty->할당('action_link3',  array('href' => 'materials.php?act=add', 'text' => '添加물料'));
    
    $smarty->display('material_list.htm');
}
elseif($_REQUEST['act'] == 'add')
{    
    $smarty ->할당('ur_here',      "添加물料");
    $smarty->할당('action_link', array('href' => 'materials.php?act=list', 'text' => '返回물料库存列表'));
    $smarty->할당('form_action', "insert");
    할당_query_info();
    $smarty->display('material_info.htm' );
}
elseif($_REQUEST['act'] == '삽입')
{
    $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']) || 비어 있음($material['modulus']) || 비어 있음($material['safe_day']) || 비어 있음($material['intent_day' ]))
    {
        sys_msg('name称、系数、안심천数、目标天数,空不能为或者格式不正确', 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'] == '업데이트')
{
    $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 ']) || 비어 있음($material['modulus']) || 비어 있음($material['intent_day']))
    {
        sys_msg(' name称、系数、안전천数、目标天数,不能为공간或者格式不正确', 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'] =='편집')
{
    $sql = "SELECT * FROM " .$ecs->table('재료'). " WHERE";
    $material = $db->GetRow($sql);
    $smarty->ass('ur_here',     "编辑물料");
    $smarty-> ('action_link', array('href' => 'materials.php?act=list', 'text' => '返回物料库存列表'));
    $smarty->할당('재료 ',    $material);
    $smarty->ass('form_action', 'updata');
    할당_query_info();
    $smarty->display('material_info.htm');
}
elseif ($_REQUEST['act'] == '제거')
{
    $id = intval($_GET['id']);
    $exc-> drop($id);
    $url = 'materials.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
    ecs_header("위치: $urln");
    종료;
}
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 = "업데이트" .$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 < 0)
{
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 < 0)
{
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 재고_번호 = 재고_번호 + 재고_인 - 재고_아웃, 재고_아웃 = 0, 재고_인 = 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);
$obj드로잉 = new PHPExcel_Worksheet_드로잉();
$obj드로잉->setName(' 상품 엄지손가락');
$obj드로잉->setDescription('Pgoods 엄지손가락');
$img_path = file_exists('../data/material/'.$v['img']) '. . /data/material/'.$v['img'] : '../images/no_img.jpg';
$obj드로잉->setPath($img_path);
$obj드로잉->setWidth ( 100);
$obj드로잉->setCoordinates('B'.$i);
$obj드로잉->setWorksheet($objPHPExcel->getActiveSheet());
}
       else
{
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, '')
}
$objPHPExcel->set ActiveSheetIndex(0)
->setCellValue('A'.$i, $v['name'])
                                                                                                                                                        ('D'. $ I, $ v [ 'stock_number'])
-& gt; 'e'. $ I, $ v ['stock_day']
-& gt; setCellValue ('f' . $ i, $ v ['stock_safe'])
-& gt; . $ i, $ v ['stock_intent']
-& gt; setcellvalue ('h'. $ i, $ i, $ v ['proposal_buy'])
-& gt; . $ i, $ v ['가격'])
-& gt; setCellValue ('j'. $ i, '') >getFont()->getColor()-> setARGB(PHPExcel_Style_Color::COLOR_RED);
}
if($v['buy_url'] != 'http://')
                                                                                                     사용              $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->setActiveSheet Index(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'] == '쿼리')
{    
    $stock_list = Material_list();
    $smarty->할당('stock_list',     $stock_list['stock_list']);
    $smarty-> ;할당('필터',       $stock_list['필터']);
    $smarty->할당('record_count', $stock_list['record_count']);
    $smarty->할당(' 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'] = 비어 있음($_REQUEST['sort_by']) ? 'id' : Trim($_REQUEST['sort_by']);
        $filter['sort_order'] = 비어 있음($_REQUEST['sort_order']) ? 'desc' : Trim($_REQUEST['sort_order']);
        $where = " WHERE 1 = 1 ";
        $sql = ''.$ecs->에서 개수(t.id) 선택 테이블('재료'). ' as t '.$where;
        
        $filter['record_count'] = $db->getOne($sql);
        
        /* 分页大小 */
        $filter = page_and_size($filter);
        
        $sql = ''.
에서 t.*, au.user_name을 선택하세요.                $ecs->table('materials').' 왼쪽으로 '.
                $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['시작'] . ',' . $filter['page_size'];
        }
        
        $end_time   = strtotime(date("Y-m-d",gmtime()));
        $start_time = $end_time - 7 * 86400;
        $query = "".$GLOBALS['ecs']->table('order_info')에서 총 개수(order_id)를 선택하세요." WHERE synch_time < '".$end_time."' 및 synch_time >= '".$start_time."'";
        $filter['orders'] = round($GLOBALS['db']->getOne($query) / 7);//7하늘평均订单数    
        $filter['orders'] = $filter['orders'] ? $filter['주문'] : 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]);
            계속;
        }

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿