初始版本

This commit is contained in:
2026-04-19 01:39:41 +08:00
commit 2b4d3e9880
1272 changed files with 389959 additions and 0 deletions

View File

@@ -0,0 +1,264 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Assist extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index(){
$typeNumber = str_enhtml($this->input->get('typeNumber',TRUE));
$skey = str_enhtml($this->input->get('skey',TRUE));
$where = '(isDelete=0) and typeNumber="'.$typeNumber.'"';
$where .= $skey ? ' and name like "%'.$skey.'%"' : '';
$list = $this->mysql_model->get_results('category',$where,'path');
$parentId = array_column($list, 'parentId');
foreach ($list as $arr=>$row) {
$v[$arr]['detail'] = in_array($row['id'],$parentId) ? false : true;
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['level'] = $row['level'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['parentId'] = intval($row['parentId']);
$v[$arr]['remark'] = $row['remark'];
$v[$arr]['sortIndex'] = intval($row['sortIndex']);
$v[$arr]['status'] = intval($row['isDelete']);
$v[$arr]['typeNumber'] = $row['typeNumber'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//分类
public function getAssistType(){
$v = array(
0 => array('id'=>1001,'name'=>'商品类别','number'=>'trade'),
1 => array('id'=>1002,'name'=>'客户类别','number'=>'customertype'),
2 => array('id'=>1003,'name'=>'供应商类别','number'=>'supplytype'),
3 => array('id'=>1004,'name'=>'收入类别','number'=>'raccttype'),
4 => array('id'=>1005,'name'=>'支出类别','number'=>'paccttype')
);
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = $v;
$json['data']['totalsize'] = 5;
die(json_encode($json));
}
//新增
public function add(){
$data = $this->validform(str_enhtml($this->input->post(NULL,TRUE)));
switch ($data['typeNumber']) {
case 'trade':
$this->common_model->checkpurview(168);
$this->trade_add($data);break;
case 'supplytype':
$this->common_model->checkpurview(164);
$success = '新增供应商类别:';break;
case 'customertype':
$this->common_model->checkpurview(74);
$success = '新增客户类别:';break;
case 'raccttype':
$this->common_model->checkpurview(176);
$success = '新增收入类别:';break;
case 'paccttype':
$this->common_model->checkpurview(172);
$success = '新增支出类别:';break;
case 'PayMethod':
$this->common_model->checkpurview(160);
$success = '新增结算方式:';break;
default:
str_alert(-1,'参数错误');
}
$sql = $this->mysql_model->insert('category',elements(array('name','typeNumber'),$data));
if ($sql) {
$this->common_model->logs($success.$data['name']);
die('{"status":200,"msg":"success","data":{"coId":0,"detail":true,"id":'.$sql.',"level":1,"name":"'.$data['name'].'","parentId":0,"remark":"","sortIndex":2,"status":0,"typeNumber":"'.$data['typeNumber'].'","uuid":""}}');
}
str_alert(-1,'添加失败');
}
//商品分类添加
private function trade_add($data){
if ($data['parentId']==0) {
$data['level'] = 1;
$newid = $this->mysql_model->insert('category',elements(array('name','typeNumber','level','parentId'),$data));
$sql = $this->mysql_model->update('category',array('path'=>$newid),array('id'=>$newid));
} else {
$cate = $this->mysql_model->get_rows('category',array('id'=>$data['parentId']));
count($cate)<1 && str_alert(-1,'参数错误');
$data['level'] = $cate['level'] + 1;
$newid = $this->mysql_model->insert('category',elements(array('name','typeNumber','level','parentId'),$data));
$sql = $this->mysql_model->update('category',array('path'=>$cate['path'].','.$newid),array('id'=>$newid));
}
if ($sql) {
$this->common_model->logs('新增商品类别:'.$data['name']);
die('{"status":200,"msg":"success","data":{"coId":0,"detail":true,"id":'.$newid.',"level":'.$data['level'].',"name":"'.$data['name'].'","parentId":'.$data['parentId'].',"remark":"","sortIndex":1,"status":0,"typeNumber":"'.$data['typeNumber'].'","uuid":""}}');
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$data = $this->validform(str_enhtml($this->input->post(NULL,TRUE)));
switch ($data['typeNumber']) {
case 'trade':
$this->common_model->checkpurview(169);
$this->trade_update($data);break;
case 'supplytype':
$this->common_model->checkpurview(165);
$success = '修改供应商类别:';break;
case 'customertype':
$this->common_model->checkpurview(75);
$success = '修改客户类别:';break;
case 'raccttype':
$this->common_model->checkpurview(177);
$success = '修改收入类别:';break;
case 'paccttype':
$this->common_model->checkpurview(173);
$success = '修改支出类别:';break;
case 'PayMethod':
$this->common_model->checkpurview(161);
$success = '修改结算方式:';break;
default:
str_alert(-1,'参数错误');
}
$sql = $this->mysql_model->update('category',elements(array('name','typeNumber'),$data),array('id'=>$data['id']));
if ($sql) {
$this->common_model->logs($success.$data['name']);
die('{"status":200,"msg":"success","data":{"coId":0,"detail":true,"id":'.$data['id'].',"level":1,"name"
:"'.$data['name'].'","parentId":0,"remark":"","sortIndex":2,"status":0,"typeNumber":"'.$data['typeNumber'].'","uuid":""
}}');
}
str_alert(-1,'修改失败');
}
//商品分类修改
private function trade_update($data){
$cate = $this->mysql_model->get_rows('category',array('id'=>$data['id'])); //获取原ID数据
count($cate)<1 && str_alert(-1,'参数错误');
$old_pid = $cate['parentId'];
$old_path = $cate['path'];
$pid_list = $this->mysql_model->get_results('category','(id<>'.$data['id'].') and find_in_set('.$data['id'].',path)'); //是否有子栏目
$data['parentId'] == $data['id'] && str_alert(-1,'当前分类和上级分类不能相同');
if ($data['parentId']==0) { //多级转顶级
$pare_depth = 1;
if (count($pid_list)==0) { //ID不存在子栏目
$this->mysql_model->update('category',array('parentId'=>0,'path'=>$data['id'],'level'=>1,'name'=>$data['name']),array('id'=>$data['id']));
} else { //ID存在子栏目
$this->mysql_model->update('category',array('parentId'=>0,'path'=>$data['id'],'level'=>1,'name'=>$data['name']),array('id'=>$data['id']));
foreach($pid_list as $arr=>$row) {
$path = str_replace(''.str_replace($data['id'],'',$old_path).'','',''.$row['path'].'');
$pare_depth = substr_count($path,',')+1;
$info[] = array('id'=>$row['id'],'path'=>$path,'level'=>$pare_depth);
}
$this->mysql_model->update('category',$info,'id');
}
} else { //pid<>0时顶级转多级 多级转多级
$cate = $this->mysql_model->get_rows('category',array('id'=>$data['parentId'])); //获取原PID数据
count($cate)<1 && str_alert(-1,'参数错误');
$pare_pid = $cate['parentId'];
$pare_path = $cate['path'];
$pare_depth = $cate['level'];
if ($old_pid==0) { //顶级转多级
if (count($pid_list)==0) { //ID不存在子栏目
$this->mysql_model->update('category',array('name'=>$data['name'],'parentId'=>$data['parentId'],'path'=>$pare_path.','.$data['id'],'level'=>$pare_depth+1),array('id'=>$data['id']));
} else { //ID存在子栏目
$this->mysql_model->update('category',array('name'=>$data['name'],'parentId'=>$data['parentId'],'path'=>$pare_path.','.$data['id'],'level'=>$pare_depth+1),array('id'=>$data['id']));
foreach ($pid_list as $arr=>$row) {
$path = $pare_path.','.$row['path'];
$pare_depth = substr_count($path,',')+1;
$info[] = array('id'=>$row['id'],'path'=>$path,'level'=>$pare_depth);
}
$this->mysql_model->update('category',$info,'id');
}
} else { //多级转多级
if (count($pid_list)==0) { //ID不存在子栏目
$this->mysql_model->update('category',array('name'=>$data['name'],'parentId'=>$data['parentId'],'path'=>$pare_path.','.$data['id'],'level'=>$pare_depth+1),array('id'=>$data['id']));
} else { //ID存在子栏目
$this->mysql_model->update('category',array('name'=>$data['name'],'parentId'=>$data['parentId'],'path'=>$pare_path.','.$data['id'],'level'=>$pare_depth+1),array('id'=>$data['id']));
foreach ($pid_list as $arr=>$row) {
$path = $pare_path.','.str_replace(str_replace($data['id'],'',$old_path),'',$row['path']);
$pare_depth = substr_count($path,',')+1;
$info[] = array('id'=>$row['id'],'path'=>$path,'level'=>$pare_depth+1);
}
$this->mysql_model->update('category',$info,'id');
}
}
}
$data['level'] = $pare_depth;
$this->mysql_model->update('goods',array('categoryName'=>$data['name']),array('categoryId'=>$data['id']));
$this->common_model->logs('修改类别:ID='.$data['id'].' 名称:'.$data['name']);
die('{"status":200,"msg":"success","data":{"coId":0,"detail":true,"id":'.$data['id'].',"level":'.$data['level'].',"name":"'.$data['name'].'","parentId":'.$data['parentId'].',"remark":"","sortIndex":0,"status":0,"typeNumber":"trade","uuid":""}}');
str_alert(200,'success',$data);
}
//分类删除
public function delete() {
$id = intval($this->input->post('id',TRUE));
$type = str_enhtml($this->input->get_post('typeNumber',TRUE));
switch ($type) {
case 'trade':
$this->common_model->checkpurview(170);
$success = '删除商品类别:';break;
case 'supplytype':
$this->common_model->checkpurview(166);
$success = '删除供应商类别:';break;
case 'customertype':
$this->common_model->checkpurview(76);
$success = '删除客户类别:';break;
case 'raccttype':
$this->common_model->checkpurview(178);
$success = '删除收入类别:';break;
case 'paccttype':
$this->common_model->checkpurview(174);
$success = '删除支出类别:';break;
case 'PayMethod':
$this->common_model->checkpurview(162);
$success = '删除结算方式:';break;
default:
str_alert(-1,'参数错误');
}
$data = $this->mysql_model->get_rows('category',array('id'=>$id));
if (count($data)>0) {
$this->mysql_model->get_count('goods',array('isDelete'=>0,'categoryId'=>$id))>0 && str_alert(-1,'辅助资料已经被使用');
$this->mysql_model->get_count('contact',array('isDelete'=>0,'cCategory'=>$id))>0 && str_alert(-1,'辅助资料已经被使用');
$this->mysql_model->get_count('category','(isDelete=0) and find_in_set('.$id.',path)')>1 && str_alert(-1,'不能删除,请先删除子分类!');
$sql = $this->mysql_model->update('category',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs($success.'ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'删除成功','id'=>'['.$id.']'));
}
}
str_alert(-1,'删除失败');
}
//公共验证
private function validform($data) {
$data['typeNumber'] = str_enhtml($this->input->get_post('typeNumber',TRUE)); //结算方式是GET
$data['id'] = isset($data['id']) ? intval($data['id']) :0;
$data['parentId'] = isset($data['parentId']) ? intval($data['parentId']):0;
strlen($data['name']) < 1 && str_alert(-1,'类别名称不能为空');
strlen($data['typeNumber']) < 1 && str_alert(-1,'参数错误');
$where['isDelete'] = 0;
$where['name'] = $data['name'];
$where['typeNumber'] = $data['typeNumber'];
$where['id !='] = $data['id']>0 ? $data['id'] :0;
$this->mysql_model->get_count('category',$where) > 0 && str_alert(-1,'类别名称重复');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,69 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Assistsku extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//组合属性规格
public function index(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$where['isDelete'] = 0;
$where['skuClassId'] = intval($this->input->get('skuClassId',TRUE));
$list = $this->mysql_model->get_results('assistsku',$where,'skuId desc');
foreach ($list as $arr=>$row) {
$v[$arr]['skuClassId'] = $row['skuClassId'];
$v[$arr]['skuAssistId'] = $row['skuAssistId'];
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['skuName'] = $row['skuName'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(59);
$data['skuAssistId'] = $this->input->get_post('skuAssistId',TRUE);
$data['skuClassId'] = $this->input->get_post('skuClassId',TRUE);
$data['skuName'] = $this->input->get_post('skuName',TRUE);
if (count($data)>0) {
$this->mysql_model->get_count('assistsku',array('skuAssistId'=>$data['skuAssistId'])) > 0 && str_alert(-1,'辅助属性组已存在!');
$sql = $this->mysql_model->insert('assistsku',$data);
if ($sql) {
$data['skuId'] = $sql;
$this->common_model->logs('新增规格:'.$data['skuName']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('assistsku',array('skuId'=>$id));
if (count($data)>0) {
$sql = $this->mysql_model->update('assistsku',array('isDelete'=>1),array('skuId'=>$id));
if ($sql) {
$this->common_model->logs('删除规格:ID='.$id.' 名称:'.$data['skuName']);
str_alert(200,'success');
}
}
str_alert(-1,'删除失败');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,91 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Assisttype extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//辅助属性列表
public function index() {
$list = $this->mysql_model->get_results('assistingprop',array('isDelete'=>0),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['del'] = false;
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(59);
$type = $this->input->post('type',TRUE);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
$this->mysql_model->get_count('assistingprop','(isDelete=0) and (name="'.$data['name'].'")') > 0 && str_alert(-1,'名称重复');
$sql = $this->mysql_model->insert('assistingprop',$data);
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增辅助属性:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$id = intval($data['id']);
unset($data['id']);
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
$this->mysql_model->get_count('assistingprop','(id<>'.$id.') and (name="'.$data['name'].'")') > 0 && str_alert(-1,'名称重复');
$sql = $this->mysql_model->update('assistingprop',$data,'(id='.$id.')');
if ($sql) {
$data['id'] = $id;
$this->common_model->logs('更新辅助属性:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->mysql_model->get_rows('assistingprop','(id='.$id.')');
if (count($data)>0) {
$this->mysql_model->get_count(GOODS,'(isDelete=0) and find_in_set('.$id.',skuAssistId)')>0 && str_alert(-1,'数据在使用中,不能删除');
$info['isDelete'] = 1;
$sql = $this->mysql_model->update('assistingprop',$info,'(id='.$id.')');
if ($sql) {
$this->common_model->logs('删除辅助属性:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success');
}
}
str_alert(-1,'删除失败');
}
//公共验证
private function validform($data) {
$data['id'] = intval($data['id']);
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
strlen($data['type']) < 1 && str_alert(-1,'编号不能为空');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,394 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Contact extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//客户、供应商列表
public function index() {
$type = intval($this->input->get('type',TRUE))==10 ? 10 : -10;
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$page = max(intval($this->input->get_post('page',TRUE)),1);
$categoryid = intval($this->input->get_post('categoryId',TRUE));
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$where = '(isDelete=0) and type='.$type;
$where .= $this->common_model->get_contact_purview();
$where .= $skey ? ' and (number like "%'.$skey.'%" or name like "%'.$skey.'%" or linkMans like "%'.$skey.'%")' : '';
$where .= $categoryid>0 ? ' and cCategory = '.$categoryid.'' : '';
$list = $this->mysql_model->get_results('contact',$where,'id desc',$rows*($page-1),$rows);
//if($type == 10){
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['number'] = $row['number'];
$v[$arr]['cCategory'] = intval($row['cCategory']);
$v[$arr]['customerType'] = $row['cCategoryName'];
$v[$arr]['pinYin'] = $row['pinYin'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['type'] = $row['type'];
$v[$arr]['delete'] = intval($row['disable'])==1 ? true : false;
$v[$arr]['cLevel'] = intval($row['cLevel']);
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['periodMoney'] = (float)$row['periodMoney'];
$v[$arr]['difMoney'] = (float)$row['difMoney'];
$v[$arr]['remark'] = $row['remark'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['links'] = '';
$v[$arr]['linkMen'] = $row['linkMans'];//add by michen 20170724
if (strlen($row['linkMans'])>0) {
$list = (array)json_decode($row['linkMans'],true);
foreach ($list as $arr1=>$row1) {
if ($row1['linkFirst']==1) {
$v[$arr]['contacter'] = $row1['linkName'];
$v[$arr]['mobile'] = $row1['linkMobile'];
$v[$arr]['place'] = $row1['linkPlace'];
$v[$arr]['telephone'] = $row1['linkPhone'];
$v[$arr]['linkIm'] = $row1['linkIm'];
$v[$arr]['city'] = $row1['city'];
$v[$arr]['county'] = $row1['county'];
$v[$arr]['province'] = $row1['province'];
$v[$arr]['deliveryAddress'] = $row1['address'];
$v[$arr]['firstLink']['first'] = $row1['linkFirst'];
}
}
}
}
/*}else{
//add by michen 20170720 begin
$gid = 1;
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['number'] = $row['number'];
$v[$arr]['cCategory'] = intval($row['cCategory']);
$v[$arr]['customerType'] = $row['cCategoryName'];
$v[$arr]['pinYin'] = $row['pinYin'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['type'] = $row['type'];
$v[$arr]['delete'] = intval($row['disable'])==1 ? true : false;
$v[$arr]['cLevel'] = intval($row['cLevel']);
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['periodMoney'] = (float)$row['periodMoney'];
$v[$arr]['difMoney'] = (float)$row['difMoney'];
$v[$arr]['remark'] = $row['remark'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['links'] = '';
$i = 1;
if (strlen($row['linkMans'])>0) {
$list = (array)json_decode($row['linkMans'],true);
foreach ($list as $arr1=>$row1) {
if ($i==1) {
$v[$arr]['contacter'] = $row1['linkName'];
$v[$arr]['mobile'] = $row1['linkMobile'];
$v[$arr]['place'] = $row1['linkPlace'];
$v[$arr]['telephone'] = $row1['linkPhone'];
$v[$arr]['linkIm'] = $row1['linkIm'];
$v[$arr]['city'] = $row1['city'];
$v[$arr]['county'] = $row1['county'];
$v[$arr]['province'] = $row1['province'];
$v[$arr]['deliveryAddress'] = $row1['address'];
$v[$arr]['firstLink']['first'] = $row1['linkFirst'];
$v[$arr]['isFirst'] = $row1['linkFirst']==1?1:2;
$v[$arr]['gid'] = $gid;
}else{
$v[$arr.$i]['id'] = intval($row['id']);
$v[$arr.$i]['number'] = $row['number'];
$v[$arr.$i]['cCategory'] = intval($row['cCategory']);
$v[$arr.$i]['customerType'] = $row['cCategoryName'];
$v[$arr.$i]['pinYin'] = $row['pinYin'];
$v[$arr.$i]['name'] = $row['name'];
$v[$arr.$i]['type'] = $row['type'];
$v[$arr.$i]['delete'] = intval($row['disable'])==1 ? true : false;
$v[$arr.$i]['cLevel'] = intval($row['cLevel']);
$v[$arr.$i]['amount'] = (float)$row['amount'];
$v[$arr.$i]['periodMoney'] = (float)$row['periodMoney'];
$v[$arr.$i]['difMoney'] = (float)$row['difMoney'];
$v[$arr.$i]['remark'] = $row['remark'];
$v[$arr.$i]['taxRate'] = (float)$row['taxRate'];
$v[$arr.$i]['links'] = '';
$v[$arr.$i]['contacter'] = $row1['linkName'];
$v[$arr.$i]['mobile'] = $row1['linkMobile'];
$v[$arr.$i]['place'] = $row1['linkPlace'];
$v[$arr.$i]['telephone'] = $row1['linkPhone'];
$v[$arr.$i]['linkIm'] = $row1['linkIm'];
$v[$arr.$i]['city'] = $row1['city'];
$v[$arr.$i]['county'] = $row1['county'];
$v[$arr.$i]['province'] = $row1['province'];
$v[$arr.$i]['deliveryAddress'] = $row1['address'];
$v[$arr.$i]['firstLink']['first'] = $row1['linkFirst'];
$v[$arr.$i]['isFirst'] = $row1['linkFirst']==1?1:2;
$v[$arr]['gid'] = $gid;
}
$i++;
$gid++;
}
}
}
//add by michen 20170720 end
}
//add by michen 20170720 begin
uasort($v,function ($x,$y){
return strcasecmp($x['id'].$x['isFirst'],$y['id'].$x['isFirst']);
}
);
$values = array_values($v);
//add by michen 20170720 end
*/
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->mysql_model->get_count('contact',$where);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? array_values($v) : array();
die(json_encode($json));
}
//校验客户编号
public function getNextNo(){
$type = intval($this->input->get('type',TRUE));
$skey = intval($this->input->post('skey',TRUE));
str_alert(200,'success',array('number'=>$skey));
}
//检测客户名称
public function checkName(){
$id = intval($this->input->post('id',TRUE));
$name = str_enhtml($this->input->post('name',TRUE));
$where['name'] = $name;
$where['isDelete'] = 0;
$where['id !='] = $id>0 ? $id :'';
$data = $this->mysql_model->get_rows('contact',array_filter($where));
if (count($data)>0) {
str_alert(-1,'客户名称重复');
}
str_alert(200,'success');
}
function my_filter($item){
if($item['linkFirst'] === 1)
return true;
else
return false;
}
public function getRecentlyContact(){
$billType = str_enhtml($this->input->post('billType',TRUE));
$transType = intval($this->input->post('transType',TRUE));
$where = '(isDelete=0)';
$where .= ($transType==150501||$transType==150502) ? ' and type=10' :' and type=-10';//mody by michen 20170820 修正购货退货单默认供应商不正确
$where .= $this->common_model->get_contact_purview();
$data = $this->mysql_model->get_rows('contact',$where);
//die(var_export($data,true));
if (count($data)>0) {
//add by michen 20170724 begin
/*$linkMen = (array)json_decode($data['linkMans'],true);
$linkMan = "null";
if(count($linkMen)>0){
foreach ($linkMen as $key => $item){
if($item['linkFirst'] === 1){
$linkMan = $item;
break;
}
}
}*/
//add by michen 20170724 end
die('{"status":200,"msg":"success","data":{"linkMen":'.$data['linkMans'].',"contactName":"'.$data['name'].'","buId":'.$data['id'].',"cLevel":0}}');
} else {
str_alert(-1,'');
}
}
public function getLinkMen(){
$buId = intval($this->input->get('buId',TRUE));
$data = $this->mysql_model->get_rows('contact','(isDelete=0) and id='.$buId);
die($data['linkMans']);
}
//获取信息
public function query() {
$id = intval($this->input->get_post('id',TRUE));
$type = intval($this->input->get_post('type',TRUE));
$data = $this->mysql_model->get_rows('contact',array('isDelete'=>0,'id'=>$id));
if (count($data)>0) {
$info['id'] = $id;
$info['cCategory'] = intval($data['cCategory']);
$info['cLevel'] = intval($data['cLevel']);
$info['number'] = $data['number'];
$info['name'] = $data['name'];
$info['amount'] = (float)$data['amount'];
$info['remark'] = $data['remark'];
$info['beginDate'] = $data['beginDate'];
$info['periodMoney'] = (float)$data['periodMoney'];
$info['difMoney'] = (float)$data['difMoney'];
if ($type==10) {
$info['taxRate'] = (float)$data['taxRate'];
}
$info['pinYin'] = $data['pinYin'];
if (strlen($data['linkMans'])>0) {
$list = (array)json_decode($data['linkMans'],true);
foreach ($list as $arr=>$row) {
$v[$arr]['address'] = $row['address'];
$v[$arr]['city'] = $row['city'];
$v[$arr]['contactId'] = time();
$v[$arr]['county'] = $row['county'];
$v[$arr]['email'] = isset($row['email']) ? $row['email'] : '';
$v[$arr]['first'] = $row['linkFirst']==1 ? true : '';
$v[$arr]['id'] = $arr+1;
$v[$arr]['im'] = $row['linkIm'];
$v[$arr]['mobile'] = $row['linkMobile'];
$v[$arr]['place'] = $row['linkPlace'];
$v[$arr]['name'] = $row['linkName'];
$v[$arr]['phone'] = $row['linkPhone'];
$v[$arr]['province'] = $row['province'];
$v[$arr]['tempId'] = 0;
}
}
$info['links'] = isset($v) ? $v : array();
$json['status'] = 200;
$json['msg'] = 'success';
$json['data'] = $info;
die(json_encode($json));
}
str_alert(-1,'没有数据');
}
//新增
public function add(){
$data = $this->validform($this->input->post(NULL,TRUE));
switch ($data['type']) {
case 10:
$this->common_model->checkpurview(59);
$success = '新增客户:';
break;
case -10:
$this->common_model->checkpurview(64);
$success = '新增供应商:';
break;
default:
str_alert(-1,'参数错误');
}
$this->mysql_model->get_count('contact',array('isDelete'=>0,'type'=>$data['type'],'number'=>$data['number'])) > 0 && str_alert(-1,'编号重复');
$data = elements(array(
'name','number','amount','beginDate','cCategory',
'cCategoryName','cLevel','cLevelName','linkMans'
,'periodMoney','remark','type','difMoney'),$data,NULL);
$sql = $this->mysql_model->insert('contact',$data);
if ($sql) {
$data['id'] = $sql;
$data['cCategory'] = intval($data['cCategory']);
$data['linkMans'] = (array)json_decode($data['linkMans'],true);
$this->common_model->logs($success.$data['name']);
str_alert(200,'success',$data);
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$data = $this->validform($this->input->post(NULL,TRUE));
switch ($data['type']) {
case 10:
$this->common_model->checkpurview(60);
$success = '修改客户:';
break;
case -10:
$this->common_model->checkpurview(65);
$success = '修改供应商:';
break;
default:
str_alert(-1,'参数错误');
}
$this->mysql_model->get_count('contact',array('id !='=>$data['id'],'isDelete'=>0,'type'=>$data['type'],'number'=>$data['number'])) > 0 && str_alert(-1,'编号重复');
$info = elements(array(
'name','number','amount','beginDate','cCategory',
'cCategoryName','cLevel','cLevelName','linkMans'
,'periodMoney','remark','type','difMoney'),$data,NULL);
$sql = $this->mysql_model->update('contact',$info,array('id'=>$data['id']));
if ($sql) {
$data['cCategory'] = intval($data['cCategory']);
$data['customerType'] = $data['cCategoryName'];
$data['linkMans'] = (array)json_decode($data['linkMans'],true);
$this->common_model->logs($success.$data['name']);
str_alert(200,'success',$data);
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$id = str_enhtml($this->input->post('id',TRUE));
$type = intval($this->input->get_post('type',TRUE))==10 ? 10 : -10;
switch ($type) {
case 10:
$this->common_model->checkpurview(61);
$success = '删除客户:';
break;
case -10:
$this->common_model->checkpurview(66);
$success = '删除供应商:';
break;
default:
str_alert(-1,'参数错误');
}
$data = $this->mysql_model->get_results('contact','(id in('.$id.'))');
if (count($data) > 0) {
$info['isDelete'] = 1;
$this->mysql_model->get_count('invoice','(isDelete=0) and (buId in('.$id.'))')>0 && str_alert(-1,'不能删除有业务往来的客户或供应商!');
$sql = $this->mysql_model->update('contact',$info,'(id in('.$id.'))');
if ($sql) {
$name = array_column($data,'name');
$this->common_model->logs($success.'ID='.$id.' 名称:'.join(',',$name));
die('{"status":200,"msg":"success","data":{"msg":"","id":['.$id.']}}');
}
}
str_alert(-1,'客户或供应商不存在');
}
//状态
public function disable(){
$this->common_model->checkpurview();
$disable = intval($this->input->post('disable',TRUE));
$id = str_enhtml($this->input->post('contactIds',TRUE));
if (strlen($id) > 0) {
$sql = $this->mysql_model->update('contact',array('disable'=>$disable),'(id in('.$id.'))');
if ($sql) {
$this->common_model->logs('客户'.$disable==1?'禁用':'启用'.':ID:'.$id.'');
str_alert(200,'success');
}
}
str_alert(-1,'操作失败');
}
//公共验证
private function validform($data) {
$this->load->library('lib_pinyin');
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
strlen($data['number']) < 1 && str_alert(-1,'编号不能为空');
$data['cCategory'] = intval($data['cCategory']);
$data['cLevel'] = (float)$data['cLevel'];
$data['taxRate'] = isset($data['taxRate']) ? (float)$data['taxRate'] :0;
$data['periodMoney'] = (float)$data['periodMoney'];
$data['amount'] = (float)$data['amount'];
$data['linkMans'] = $data['linkMans'] ? $data['linkMans'] :"[]";
$data['beginDate'] = $data['beginDate'] ? $data['beginDate'] : date('Y-m-d');
$data['type'] = intval($this->input->get_post('type',TRUE))==10 ? 10 : -10;
$data['pinYin'] = $this->lib_pinyin->str2pinyin($data['name']);
$data['contact'] = $data['number'].' '.$data['name'];
$data['difMoney'] = $data['amount'] - $data['periodMoney'];
$data['cCategoryName'] = $this->mysql_model->get_row('category',array('id'=>$data['cCategory']),'name');
$data['cCategory'] < 1 && str_alert(-1,'类别名称不能为空');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,163 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Cst extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//员工列表
public function index(){
$cstno = ($this->input->get('cstno',TRUE));
if(!empty($cstno)){
$customer = explode("_",$cstno);
$cstno = $customer[0];
}
$sql = 'select
a.*,b.name as deptName
from '.$this->db->dbprefix('staff').' as a
left join '.$this->db->dbprefix('contact').' as b on b.id=a.deptId
where a.isDelete=0 and a.deptId<>0 '.(empty($cstno)?'':' and deptId='.$cstno).' order by id desc';
$list = $this->mysql_model->query($sql,2);
foreach ($list as $arr=>$row) {
$v[$arr]['birthday'] =$row['birthday'];
$v[$arr]['allowNeg'] = false;
$v[$arr]['commissionrate'] = $row['commissionrate'];
$v[$arr]['creatorId'] = $row['creatorId'];
$v[$arr]['deptId'] = $row['deptId'];
$v[$arr]['deptName'] = $row['deptName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['email'] = $row['name'];
$v[$arr]['empId'] = $row['empId'];
$v[$arr]['empType'] = $row['empType'];
$v[$arr]['fullId'] = $row['fullId'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['leftDate'] = NULL;
$v[$arr]['mobile'] = $row['mobile'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
$v[$arr]['parentId'] = $row['parentId'];
$v[$arr]['sex'] = $row['sex'];
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['passWord'] = $row['passWord'];
$v[$arr]['score'] = $row['score'];
$v[$arr]['delete'] = intval($row['disable'])==1 ? true : false; //是否禁用
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$this->mysql_model->get_count('staff',array('isDelete'=>0,'number'=>$data['number'])) > 0 && str_alert(-1,'编号/账号重复');
$sql = $this->mysql_model->insert('staff',elements(array('name','number','score','passWord','deptId'),$data));
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增客户账号:编号'.$data['number'].' 名称'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$this->mysql_model->get_count('staff',array('isDelete'=>0,'number'=>$data['number'],'id !='=>$data['id'])) > 0 && str_alert(-1,'编号/账号重复');
$sql = $this->mysql_model->update('staff',elements(array('name','number','score','passWord','deptId'),$data),array('id'=>$data['id']));
if ($sql) {
$this->common_model->logs('更新客户账号:编号'.$data['number'].' 名称'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('staff',array('id'=>$id));
if (count($data)>0) {
$this->mysql_model->get_count('invoice',array('isDelete'=>0,'salesId'=>$data['id']))>0 && str_alert(-1,'其中有客户发生业务不可删除');
$info['isDelete'] = 1;
$sql = $this->mysql_model->update('staff',$info,array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除员工:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'成功删除'));
}
}
str_alert(-1,'删除失败');
}
//状态
public function disable(){
$this->common_model->checkpurview(59);
$id = str_enhtml($this->input->post('employeeIds',TRUE));
$data = $this->mysql_model->get_rows('staff',array('id'=>$id));
if (count($data) > 0) {
$info['disable'] = intval($this->input->post('disable',TRUE));
$sql = $this->mysql_model->update('staff',$info,'(id in('.$id.'))');
if ($sql) {
$action = $info['disable']==1 ? '客户账号禁用' : '客户账号启用';
$this->common_model->logs($action.':ID:'.$id.'名称:'.$data['name']);
str_alert(200,'success');
}
}
str_alert(-1,'操作失败');
}
//名称查询
public function findByNumberOrName(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$where = '(depId=0)';
$where .= $skey ? ' and (name like "%'.$skey.'%" or number like "%'.$skey.'%")' : '';
$offset = $rows * ($page-1);
$list = $this->mysql_model->get_results('staff',$where,'id desc',$offset,$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = $this->mysql_model->get_count('staff',$where);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
//公共验证
private function validform($data) {
$data['id'] = intval($data['id']);
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
strlen($data['number']) < 1 && str_alert(-1,'编号不能为空');
$data['score'] = floatval($data['score']);
if(isset($data['passWord'])){
strlen($data['passWord']) < 1 && str_alert(-1,'密码不能为空');
}else{
$data['passWord'] = '';
}
$customer = explode("_",$data['deptName']);
$data['deptId'] = $customer[0];
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,27 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Customer extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview(62);
}
public function exporter(){
$name = 'customer_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出客户:'.$name);
$skey = str_enhtml($this->input->get('skey',TRUE));
$categoryId = intval($this->input->get_post('categoryId',TRUE));
$where = '(isDelete=0) and type=-10 ';
$where .= $this->common_model->get_customer_purview();
$where .= $categoryId>0 ? ' and cCategory = '.$categoryId.'' : '';
$where .= $skey ? ' and (number like "%'.$skey.'%" or name like "%'.$skey.'%" or linkMans like "%'.$skey.'%")' : '';
$data['list'] = $this->mysql_model->get_results('contact',$where,'id desc');
$this->load->view('settings/customer-export',$data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,109 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Deliveryaddr extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//发货地址列表
public function index(){
$list = $this->mysql_model->get_results('address',array('isDelete'=>0),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = $row['id'];
$v[$arr]['shortName'] = $row['shortName'];
$v[$arr]['postalcode'] = $row['postalcode'];
$v[$arr]['province'] = $row['province'];
$v[$arr]['city'] = $row['city'];
$v[$arr]['area'] = $row['area'];
$v[$arr]['address'] = $row['address'];
$v[$arr]['linkman'] = $row['linkman'];
$v[$arr]['phone'] = $row['phone'];
$v[$arr]['mobile'] = $row['mobile'];
$v[$arr]['isDefault'] = 1;
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$sql = $this->mysql_model->insert('address',$data);
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增地址:'.$data['shortName']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$id = intval($data['id']);
unset($data['id']);
$sql = $this->mysql_model->update('address',$data,array('id'=>$id));
if ($sql) {
$data['id'] = $id;
$this->common_model->logs('更新地址:ID='.$id.',名称:'.$data['shortName']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('address',array('id'=>$id));
if (count($data)>0) {
//$this->mysql_model->get_count(INVSA,'(contactid in('.$id.'))')>0 && str_alert(-1,'其中有客户发生业务不可删除');
$sql = $this->mysql_model->update('address',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除地址:ID='.$id.' 名称:'.$data['shortname']);
str_alert(200,'success',array('msg'=>'成功删除'));
}
}
str_alert(-1,'删除失败');
}
//查询
public function query(){
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('address',array('id'=>$id));
if (count($data)>0) {
$json['data']['id'] = intval($data['id']);
$json['data']['shortName'] = $data['shortName'];
$json['data']['postalcode'] = $data['postalcode'];
$json['data']['province'] = $data['province'];
$json['data']['city'] = $data['city'];
$json['data']['area'] = $data['area'];
$json['data']['address'] = $data['address'];
$json['data']['linkman'] = $data['linkman'];
$json['data']['phone'] = $data['phone'];
$json['data']['mobile'] = $data['mobile'];
$json['data']['isDefault'] = intval($data['isdefault']);
$json['status'] = 200;
$json['msg'] = 'success';
die(json_encode($json));
}
str_alert(-1,'地址不存在');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,150 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Employee extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//员工列表
public function index(){
$list = $this->mysql_model->get_results('staff',array('isDelete'=>0,'deptId'=>0),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['birthday'] =$row['birthday'];
$v[$arr]['allowNeg'] = false;
$v[$arr]['commissionrate'] = $row['commissionrate'];
$v[$arr]['creatorId'] = $row['creatorId'];
$v[$arr]['deptId'] = $row['deptId'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['email'] = $row['name'];
$v[$arr]['empId'] = $row['empId'];
$v[$arr]['empType'] = $row['empType'];
$v[$arr]['fullId'] = $row['fullId'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['leftDate'] = NULL;
$v[$arr]['mobile'] = $row['mobile'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
$v[$arr]['parentId'] = $row['parentId'];
$v[$arr]['sex'] = $row['sex'];
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['passWord'] = $row['passWord'];
$v[$arr]['score'] = $row['score'];
$v[$arr]['delete'] = intval($row['disable'])==1 ? true : false; //是否禁用
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$this->mysql_model->get_count('staff',array('isDelete'=>0,'number'=>$data['number'])) > 0 && str_alert(-1,'编号/账号重复');
$sql = $this->mysql_model->insert('staff',elements(array('name','number','score','passWord'),$data));
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增员工:编号'.$data['number'].' 名称'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(59);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$this->mysql_model->get_count('staff',array('isDelete'=>0,'number'=>$data['number'],'id !='=>$data['id'])) > 0 && str_alert(-1,'编号/账号重复');
$sql = $this->mysql_model->update('staff',elements(array('name','number','score','passWord'),$data),array('id'=>$data['id']));
if ($sql) {
$this->common_model->logs('更新员工:编号'.$data['number'].' 名称'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('staff',array('id'=>$id));
if (count($data)>0) {
$this->mysql_model->get_count('invoice',array('isDelete'=>0,'salesId'=>$data['id']))>0 && str_alert(-1,'其中有客户发生业务不可删除');
$info['isDelete'] = 1;
$sql = $this->mysql_model->update('staff',$info,array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除员工:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'成功删除'));
}
}
str_alert(-1,'删除失败');
}
//状态
public function disable(){
$this->common_model->checkpurview(59);
$id = str_enhtml($this->input->post('employeeIds',TRUE));
$data = $this->mysql_model->get_rows('staff',array('id'=>$id));
if (count($data) > 0) {
$info['disable'] = intval($this->input->post('disable',TRUE));
$sql = $this->mysql_model->update('staff',$info,'(id in('.$id.'))');
if ($sql) {
$action = $info['disable']==1 ? '员工禁用' : '员工启用';
$this->common_model->logs($action.':ID:'.$id.'名称:'.$data['name']);
str_alert(200,'success');
}
}
str_alert(-1,'操作失败');
}
//名称查询
public function findByNumberOrName(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$where = '(depId=0)';
$where .= $skey ? ' and (name like "%'.$skey.'%" or number like "%'.$skey.'%")' : '';
$offset = $rows * ($page-1);
$list = $this->mysql_model->get_results('staff',$where,'id desc',$offset,$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = $this->mysql_model->get_count('staff',$where);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
//公共验证
private function validform($data) {
$data['id'] = intval($data['id']);
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
strlen($data['number']) < 1 && str_alert(-1,'编号不能为空');
$data['score'] = floatval($data['score']);
if(isset($data['passWord'])){
strlen($data['passWord']) < 1 && str_alert(-1,'密码不能为空');
}else{
$data['passWord'] = '';
}
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,351 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Import extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->load->helper('download');
$this->load->library('excel/excel_reader2');
$this->load->library('pinyin/getpinyin');
}
public function index() {
$dir = './data/upfile/' . date('Ymd') . '/';
//$path = '/data/upfile/' . date('Ymd') . '/';
$err = json_encode(array('url' => '', 'title' => '', 'state' => '请登录'));
$info = upload('resume_file', $dir);
if (is_array($info) && count($info) > 0) {
//$array = array('url' => $path . $info['file'], 'title' => $path . $info['file'], 'state' => 'SUCCESS');
print_r($info);
die();
} else {
die($err);
}
}
//客户
public function downloadtemplate1() {
$info = read_file('./data/download/customer.xls');
$this->common_model->logs('下载文件名:客户导入_'.date("YmdHis").'.xls');
force_download('客户导入_'.date("YmdHis").'.xls', $info);
}
//供应商
public function downloadtemplate2() {
$info = read_file('./data/download/vendor.xls');
$this->common_model->logs('下载文件名:供应商导入_'.date("YmdHis").'.xls');
force_download('供应商导入_'.date("YmdHis").'.xls', $info);
}
//商品
public function downloadtemplate3() {
$info = read_file('./data/download/goods.xls');
$this->common_model->logs('下载文件名:商品导入_'.date("YmdHis").'.xls');
force_download('商品导入_'.date("YmdHis").'.xls', $info);
}
//价格预警
public function downloadtemplate4() {
$info = read_file('./data/download/preprice.xls');
$this->common_model->logs('下载文件名:价格预警导入_'.date("YmdHis").'.xls');
force_download('价格预警导入_'.date("YmdHis").'.xls', $info);
}
//客户导入
public function findDataImporter() {
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
print_r($fn);
die();
if ($fn) {
file_put_contents(
'upload/' . $fn,
file_get_contents('php://input')
);
echo "http://119.10.11.187:82/AAAUPIMG/1/uploads/".$fn;
exit();
}
print_r($_FILES);
die();
// $dir = './data/upfile/' . date('Ymd') . '/';
// //$path = '/data/upfile/' . date('Ymd') . '/';
// $err = json_encode(array('url' => '', 'title' => '', 'state' => '请登录'));
// $info = upload('resume_file', $dir);
// if (is_array($info) && count($info) > 0) {
// //$array = array('url' => $path . $info['file'], 'title' => $path . $info['file'], 'state' => 'SUCCESS');
// print_r($info);
// die();
// } else {
// die($err);
// }
die('{"status":200,"msg":"success","data":{"items":[{"id":1294598139109696,"date":"2015-04-25 14:41:35","uploadPath"
:"customer_20150425024011.xls","uploadName":"customer_20150425024011.xls","resultPath":"uploadfiles/88887901
/customer_20150425024011.xls","resultName":"customer_20150425024011.xls","resultInfo":"商品导入完毕。<br/>商
品一共0条数据成功导入0条数据失败0条数据。<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕。<br/>客户一共10条数
成功导入10条数据失败0条数据。<br/>","status":2,"spendTime":0},{"id":1294598139109659,"date":"2015-04-25 14:40
:49","uploadPath":"customer_20150425024011.xls","uploadName":"customer_20150425024011.xls","resultPath"
:"uploadfiles/88887901/customer_20150425024011.xls","resultName":"customer_20150425024011.xls","resultInfo"
:"商品导入完毕。<br/>商品一共0条数据成功导入0条数据失败0条数据。<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕
。<br/>客户一共10条数据成功导入10条数据失败0条数据。<br/>","status":2,"spendTime":0},{"id":1294597559113847,"date":"2015-04-17
16:54:39","uploadPath":"蓝港新系统xls.xls","uploadName":"蓝港新系统xls.xls","resultPath":"uploadfiles/88887901
/蓝港新系统xls.xls","resultName":"蓝港新系统xls.xls","resultInfo":"商品导入完毕。<br/>商品一共557条数据成功导入0条数据失败557条数据
。<br/>(请检查模板是否匹配,建议重新下载模板导入)<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕。<br/>客户一共0条数
成功导入0条数据失败0条数据。<br/>","status":2,"spendTime":0}],"totalsize":3}}');
die('{"status":200,"msg":"success"}');
}
//上传文件
public function upload() {
die('{"status":200,"msg":"success","data":{"items":[{"id":1294598139109696,"date":"2015-04-25 14:41:35","uploadPath"
:"customer_20150425024011.xls","uploadName":"customer_20150425024011.xls","resultPath":"uploadfiles/88887901
/customer_20150425024011.xls","resultName":"customer_20150425024011.xls","resultInfo":"商品导入完毕。<br/>商
品一共0条数据成功导入0条数据失败0条数据。<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕。<br/>客户一共10条数
成功导入10条数据失败0条数据。<br/>","status":2,"spendTime":0},{"id":1294598139109659,"date":"2015-04-25 14:40
:49","uploadPath":"customer_20150425024011.xls","uploadName":"customer_20150425024011.xls","resultPath"
:"uploadfiles/88887901/customer_20150425024011.xls","resultName":"customer_20150425024011.xls","resultInfo"
:"商品导入完毕。<br/>商品一共0条数据成功导入0条数据失败0条数据。<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕
。<br/>客户一共10条数据成功导入10条数据失败0条数据。<br/>","status":2,"spendTime":0},{"id":1294597559113847,"date":"2015-04-17
16:54:39","uploadPath":"蓝港新系统xls.xls","uploadName":"蓝港新系统xls.xls","resultPath":"uploadfiles/88887901
/蓝港新系统xls.xls","resultName":"蓝港新系统xls.xls","resultInfo":"商品导入完毕。<br/>商品一共557条数据成功导入0条数据失败557条数据
。<br/>(请检查模板是否匹配,建议重新下载模板导入)<br/>供应商导入完毕。<br/>供应商一共0条数据成功导入0条数据失败0条数据。<br/>客户导入完毕。<br/>客户一共0条数
成功导入0条数据失败0条数据。<br/>","status":2,"spendTime":0}],"totalsize":3}}');
}
public function uploadExcel() {
$path=$_FILES['file'];
if($path['error']!= 0)
str_alert(-1,'文件上传失败!');
if($path['size']>20*1024*1024)
str_alert(-1,'上传文件大小超过限制!');
if($path['type']!='application/vnd.ms-excel' && strrchr($path['name'],'xls')!='xls'){
str_alert(200,'上传的文件不是excel类型');
}
//$filePath = "data/upload/".$path["name"];
//move_uploaded_file($path["tmp_name"],$filePath);
//$reader = new Excel_reader2(); // 实例化解析类Spreadsheet_Excel_Reader
$reader = $this->excel_reader2;
$reader->setOutputEncoding("utf-8"); // 设置编码方式
$reader->read("{$path['tmp_name']}");
$data = $reader->sheets[0]['cells'];
if(!isset($data[2])||!isset($data[2][1]))
str_alert(-1,'无可导入的数据!');
$first = array_shift($data);
$itype = "";
$this->db->trans_begin();
if($first[1]=='商品编号'){
$itype = "商品";
foreach ($data as $arr=>$row) {
if(empty($row[1]))
continue;
$good['number'] = $row[1];
$good['name'] = $row[2];
$good['barCode'] = $row[3];
$good['spec'] = $row[4];
//$good['categoryId'] = 1;
//$good['categoryName'] = $row[5];
//$good['locationId'] = $row[6];
//$good['baseUnitId'] = $row[9];
$good['purPrice'] = floatval($row[10]);
$good['wholesalePrice'] = floatval($row[12]);
$good['salePrice'] = floatval($row[11]);
$good['pinYin'] = $this->getpinyin->getFirstPY($row[2]);
$good['sonGoods'] = '[]';
$good['dopey'] = 0;
empty($row[5])&&str_alert(-1,'商品【'.$row[2].'】类别不能为空!');
empty($row[6])&&str_alert(-1,'商品【'.$row[2].'】仓库不能为空!');
empty($row[9])&&str_alert(-1,'商品【'.$row[2].'】计量单位不能为空!');
$list = $this->mysql_model->get_rows('storage',array('isDelete'=>0,'name'=>$row[6]));
if (count($list) > 0) {
$good['locationId']= $list['id'];
$good['locationName']= $row[6];
}else
str_alert(-1,'仓库【'.$row[6].'】不存在,请先添加仓库后再导入!');
$list = $this->mysql_model->get_rows('category',array('name'=>$row[5],'typeNumber'=>'trade'));
if (count($list) > 0) {
$good['categoryId']= $list['id'];
$good['categoryName']= $row[5];
}else{
str_alert(-1,'商品类别【'.$row[5].'】不存在,请先添加商品类别再导入!');
}
$list = $this->mysql_model->get_rows('unit',array('name'=>$row[9]));
if (count($list) > 0) {
$good['baseUnitId']= $list['id'];
$good['unitName']= $row[9];
}else{
str_alert(-1,'计量单位【'.$row[9].'】不存在,请先添加计量单位再导入!');
}
$info = array(
'number','name','barCode','spec','categoryId','locationId','baseUnitId','purPrice','salePrice',
'locationName','unitName','categoryName','pinYin','sonGoods','dopey','wholesalePrice'
);
$info = elements($info,$good,NULL);
$existgood = $this->mysql_model->get_rows('goods',array('isDelete'=>0,'number'=>$good['number']));
// if($this->mysql_model->get_count('goods',array('isDelete'=>0,'number'=>$good['number'])) <= 0){
if(count($existgood) <= 0){
$rtn['id'] = $this->mysql_model->insert('goods',$info);
}else {
$rtn['id'] = $existgood['id'];
$this->mysql_model->delete('invoice_info',array('billType'=>'INI','invId'=>$rtn['id']));
$this->mysql_model->update('goods',$info,array('number'=>$good['number']));
}
if(!empty($row[19])){
$list = $this->mysql_model->get_rows('storage',array('isDelete'=>0,'name'=>$row[19]));
if (count($list) > 0) {
$arr = 0;
$v[$arr]['invId'] = $rtn['id'];
$v[$arr]['locationId'] = $list['id'];
$v[$arr]['qty'] = floatval($row[21]);
$v[$arr]['price'] = floatval($row[22]);
$v[$arr]['amount'] = floatval($row[21])*floatval($row[22]);
$v[$arr]['skuId'] = 0;
$v[$arr]['billDate'] = date('Y-m-d');;
$v[$arr]['billNo'] = '期初数量';
$v[$arr]['billType'] = 'INI';
$v[$arr]['transTypeName'] = '期初数量';
if (isset($v)) {
$this->mysql_model->insert('invoice_info',$v);
}
}
}
}
}else if($first[1]=='客户编号'){
$itype = "客户";
foreach ($data as $arr=>$row) {
if(empty($row[1]))
continue;//add by michen 20170917 for
$cust['number'] = strval($row[1]);
$cust['name'] = $row[2];
//$cust['cCategory'] = $row[3];
//$cust['cCategoryName'] = $row[4];
$cust['cLevel'] = 0;
$cust['remark'] = $row[8];
$linkMan['linkName'] = $row[9];
$linkMan['linkMobile'] = $row[10];
$linkMan['linkPhone'] = $row[11];
$linkMan['linkPlace'] = $row[12];
$linkMan['linkIm'] = $row[13];
$linkMan['address'] = $row[14];
$linkMan['linkFirst'] = 1;
$linkMan['id'] = 0;
$linkMans[0] = $linkMan;
$cust['linkMans'] = json_encode($linkMans);
$cust['type'] = -10;
empty($row[1])&&str_alert(-1,'第'.$arr.'行客户编号不能为空!');
empty($row[2])&&str_alert(-1,'第'.$arr.'行客户名称不能为空!');
empty($row[3])&&str_alert(-1,'第'.$arr.'行客户类别不能为空!');
$list = $this->mysql_model->get_rows('category',array('name'=>$row[3],'typeNumber'=>'customertype'));
if (count($list) > 0) {
$cust['cCategory']= $list['id'];
$cust['cCategoryName']= $row[3];
}else{
str_alert(-1,'第'.$arr.'行客户类别【'.$row[3].'】不存在,请先添加客户类别再导入!');
}
$info = array(
'number','name','cLevel','remark','cCategory','cCategoryName','linkMans','type'
);
$info = elements($info,$cust,NULL);
//die(var_export($cust,true));
if($this->mysql_model->get_count('contact',array('isDelete'=>0,'number'=>$cust['number'],'type'=>-10)) <= 0){
$rtn['id'] = $this->mysql_model->insert('contact',$info);
}else {
$this->mysql_model->update('contact',$info,array('number'=>$cust['number'],'type'=>-10));
}
}
}else if($first[1]=='供应商编号'){
$itype = "供应商";
foreach ($data as $arr=>$row) {
if(empty($row[1]))
continue;
$sup['number'] = strval($row[1]);
$sup['name'] = $row[2];
//$cust['cCategory'] = $row[3];
//$cust['cCategoryName'] = $row[4];
$sup['cLevel'] = 0;
$sup['remark'] = $row[7];
$linkMan['linkName'] = $row[8];
$linkMan['linkMobile'] = $row[9];
$linkMan['linkPhone'] = $row[10];
$linkMan['linkPlace'] = $row[11];
$linkMan['linkIm'] = $row[12];
$linkMan['address'] = $row[13];
$linkMan['linkFirst'] = 1;
$linkMan['id'] = 0;
$linkMans[0] = $linkMan;
$sup['linkMans'] = json_encode($linkMans);
$sup['type'] = 10;
empty($row[1])&&str_alert(-1,'第'.$arr.'行供应商编号不能为空!');
empty($row[2])&&str_alert(-1,'第'.$arr.'行供应商名称不能为空!');
empty($row[3])&&str_alert(-1,'第'.$arr.'行供应商类别不能为空!');
$list = $this->mysql_model->get_rows('category',array('name'=>$row[3],'typeNumber'=>'supplytype'));
if (count($list) > 0) {
$sup['cCategory']= $list['id'];
$sup['cCategoryName']= $row[3];
}else{
str_alert(-1,'第'.$arr.'行供应商类别【'.$row[3].'】不存在,请先添加供应商类别再导入!');
}
$info = array(
'number','name','cLevel','remark','cCategory','cCategoryName','linkMans','type'
);
$info = elements($info,$sup,NULL);
if($this->mysql_model->get_count('contact',array('isDelete'=>0,'number'=>$sup['number'],'type'=>10)) <= 0){
$rtn['id'] = $this->mysql_model->insert('contact',$info);
}else {
$this->mysql_model->update('contact',$info,array('number'=>$sup['number'],'type'=>10));
}
}
}else if($first[1]=='商品编码'){
$itype = "价格预警";
foreach ($data as $arr=>$row) {
if(empty($row[1]))
continue;
$preprice['number'] = trim(strval($row[1]));
$preprice['supplier'] = trim(strval($row[2]));
$preprice['price'] = floatval($row[3]);
empty($row[1])&&str_alert(-1,'第'.$arr.'行商品编码不能为空!');
empty($row[2])&&str_alert(-1,'第'.$arr.'行供应商编码不能为空!');
empty($row[3])&&str_alert(-1,'第'.$arr.'行价格不能为空!');
$list = $this->mysql_model->get_rows('goods',array('number'=>$preprice['number'],'isDelete'=>0));
if (count($list) > 0) {
$preprice['invId'] = $list['id'];
}else{
str_alert(-1,'第'.$arr.'行商品编码【'.$row[1].'】不存在,请先添加商品再导入!');
}
$list = $this->mysql_model->get_rows('contact',array('number'=>$preprice['supplier'],'isDelete'=>0,'type'=>10));
if (count($list) > 0) {
$preprice['buId'] = $list['id'];
}else{
str_alert(-1,'第'.$arr.'行供应商编码【'.$row[2].'】不存在,请先添加供应商再导入!');
}
$preprice['billDate'] = date('Y-m-d');
$info = array(
'invId','buId','price','billDate'
);
$info = elements($info,$preprice,NULL);
$rtn['id'] = $this->mysql_model->insert('preprice',$info);
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
str_alert(200,'恭喜您,导入'.$itype.'信息成功!');
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,647 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Inventory extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//商品列表
public function index() {
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$categoryid = intval($this->input->get_post('assistId',TRUE));
$barCode = intval($this->input->get_post('barCode',TRUE));
$where = '(a.isDelete=0)';
$where .= $skey ? ' and (sonGoods like "%'.$skey.'%" or name like "%'.$skey.'%" or number like "%'.$skey.'%" or spec like "%'.$skey.'%")' : '';
$where .= $barCode ? ' and barCode="'.$barCode.'"' : '';
if ($categoryid > 0) {
$cid = array_column($this->mysql_model->get_results('category','(isDelete=0) and find_in_set('.$categoryid.',path)'),'id');
if (count($cid)>0) {
$cid = join(',',$cid);
$where .= ' and categoryid in('.$cid.')';
}
}
$list = $this->data_model->get_goods($where.' order by a.id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['amount'] = (float)$row['iniamount'];
$v[$arr]['barCode'] = $row['barCode'];
$v[$arr]['categoryName'] = $row['categoryName'];
$v[$arr]['currentQty'] = $row['totalqty']; //当前库存
$v[$arr]['delete'] = intval($row['disable'])==1 ? true : false; //是否禁用
$v[$arr]['discountRate'] = 0;
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['isSerNum'] = intval($row['isSerNum']);
$v[$arr]['josl'] = $row['josl'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
$v[$arr]['pinYin'] = $row['pinYin'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['locationNo'] = '';
$v[$arr]['purPrice'] = $row['purPrice'];
$v[$arr]['quantity'] = $row['iniqty'];
$v[$arr]['salePrice'] = $row['salePrice'];
$v[$arr]['skuClassId'] = $row['skuClassId'];
$v[$arr]['spec'] = $row['spec'];
$v[$arr]['unitCost'] = $row['iniunitCost'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['unitName'] = $row['unitName'];
$v[$arr]['remark'] = $row['remark'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_goods($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v :'';
die(json_encode($json));
}
//商品选择 最近出售价格
public function listBySelected() {
$arr = array('so'=>150601,'sa'=>150501);
$contactid = intval($this->input->post('contactId',TRUE));
$type = str_enhtml($this->input->post('type',TRUE));
$id = intval($this->input->post('ids',TRUE));
$list = $this->data_model->get_invoice_info('a.isDelete=0 and transType='.$arr[$type].' and a.invId='.$id.' and a.buId='.$contactid.' limit 0,3',2);
foreach ($list as $arr=>$row) {
$v[$arr]['advanceDays'] = 0;
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['barCode'] = '';
$v[$arr]['categoryName'] = '';
$v[$arr]['currentQty'] = 0;
$v[$arr]['delete'] = false;
$v[$arr]['discountRate'] = 0;
$v[$arr]['id'] = intval($row['invId']);
$v[$arr]['isSerNum'] = 0;
$v[$arr]['isWarranty'] = 0;
$v[$arr]['josl'] = '';
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['locationNo'] = $row['locationNo'];
$v[$arr]['name'] = $row['invName'];
$v[$arr]['nearPrice'] = $row['price'];
$v[$arr]['number'] = $row['invNumber'];
$v[$arr]['pinYin'] = $row['pinYin'];
$v[$arr]['purPrice'] = $row['purPrice'];
$v[$arr]['quantity'] = $row['quantity'];
$v[$arr]['salePrice'] = $row['salePrice'];
$v[$arr]['skuClassId'] = 0;
$v[$arr]['skuId'] = 0;
$v[$arr]['skuName'] = 0;
$v[$arr]['skuNumber'] = 0;
$v[$arr]['spec'] = $row['invSpec'];
$v[$arr]['unitCost'] = 0;
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['unitName'] = $row['mainUnit'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['result'] = isset($v) ? $v : array();
die(json_encode($json));
}
//获取信息
public function query() {
$id = intval($this->input->post('id',TRUE));
str_alert(200,'success',$this->get_goods_info($id));
}
//检测编号
public function getNextNo() {
$skey = str_enhtml($this->input->post('skey',TRUE));
$this->mysql_model->get_count('goods',array('isDelete'=>0,'number'=>$skey)) > 0 && str_alert(-1,'商品编号已经存在');
str_alert(200,'success');
}
//检测条码
public function checkBarCode() {
$barCode = str_enhtml($this->input->post('barCode',TRUE));
$this->mysql_model->get_count('goods',array('isDelete'=>0,'barCode'=>$barCode)) > 0 && str_alert(-1,'商品条码已经存在');
str_alert(200,'success');
}
//检测规格
public function checkSpec() {
$spec = str_enhtml($this->input->post('spec',TRUE));
$this->mysql_model->get_count('assistsku',array('isDelete'=>0,'skuName'=>$spec)) > 0 && str_alert(-1,'商品规格已经存在');
str_alert(200,'success');
}
//检测名称
public function checkname() {
$skey = str_enhtml($this->input->post('barCode',TRUE));
echo '{"status":200,"msg":"success","data":{"number":""}}';
}
//获取图片信息
public function getImagesById() {
$id = intval($this->input->post('id',TRUE));
$list = $this->mysql_model->get_results('goods_img',array('isDelete'=>0,'invId'=>$id));
foreach ($list as $arr=>$row) {
$v[$arr]['pid'] = $row['id'];
$v[$arr]['status'] = 1;
$v[$arr]['name'] = $row['name'];
$v[$arr]['url'] = site_url().'/basedata/inventory/getImage?action=getImage&pid='.$row['id'];
$v[$arr]['thumbnailUrl'] = site_url().'/basedata/inventory/getImage?action=getImage&pid='.$row['id'];
$v[$arr]['deleteUrl'] = '';
$v[$arr]['deleteType'] = '';
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['files'] = isset($v) ? $v : array();
die(json_encode($json));
}
//上传图片信息
public function uploadImages() {
require_once './application/libraries/UploadHandler.php';
$config = array(
'script_url' => base_url().'inventory/uploadimages',
'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/data/upfile/goods/',
'upload_url' => base_url().'data/upfile/goods/',
'delete_type' =>'',
'print_response' =>false
);
$uploadHandler = new UploadHandler($config);
$list = (array)json_decode(json_encode($uploadHandler->response['files'][0]), true);
$info = elements(array('name','size','type','url','thumbnailUrl','deleteUrl','deleteType'),$list,NULL);
$newid = $this->mysql_model->insert('goods_img',$info);
$files[0]['pid'] = intval($newid);
$files[0]['status'] = 1;
$files[0]['size'] = (float)$list['size'];
$files[0]['name'] = $list['name'];
$files[0]['url'] = site_url().'/basedata/inventory/getImage?action=getImage&pid='.$newid;
$files[0]['thumbnailUrl'] = site_url().'/basedata/inventory/getImage?action=getImage&pid='.$newid;
$files[0]['deleteUrl'] = '';
$files[0]['deleteType'] = '';
$json['status'] = 200;
$json['msg'] = 'success';
$json['files'] = $files;
die(json_encode($json));
}
//保存上传图片信息
public function addImagesToInv() {
$data = $this->input->post('postData');
if (strlen($data)>0) {
$v = $s = array();
$data = (array)json_decode($data, true);
$id = isset($data['id']) ? $data['id'] : 0;
!isset($data['files']) || count($data['files']) < 1 && str_alert(-1,'请先添加图片!');
foreach($data['files'] as $arr=>$row) {
if ($row['status']==1) {
$v[$arr]['id'] = $row['pid'];
$v[$arr]['invId'] = $id;
} else {
$s[$arr]['id'] = $row['pid'];
$s[$arr]['invId'] = $id;
$s[$arr]['isDelete'] = 1;
}
}
$this->mysql_model->update('goods_img',array_values($v),'id');
$this->mysql_model->update('goods_img',array_values($s),'id');
str_alert(200,'success');
}
str_alert(-1,'保存失败');
}
//获取图片信息
public function getImage() {
$id = intval($this->input->get_post('pid',TRUE));
$data = $this->mysql_model->get_rows('goods_img',array('id'=>$id));
if (count($data)>0) {
$url = './data/upfile/goods/'.$data['name'];
$info = getimagesize($url);
$imgdata = fread(fopen($url,'rb'),filesize($url));
header('content-type:'.$info['mime'].'');
echo $imgdata;
}
}
//新增
public function add(){
$this->common_model->checkpurview(69);
$data = $this->input->post(NULL,TRUE);
if ($data) {
$data = $this->validform($data);
$this->mysql_model->get_count('goods',array('isDelete'=>0,'number'=>$data['number'])) > 0 && str_alert(-1,'商品编号重复');
$this->db->trans_begin();
$info = array(
'barCode','baseUnitId','unitName','categoryId','categoryName','propertys',
'discountRate1','discountRate2','highQty','locationId','pinYin',
'locationName','lowQty','name','number','purPrice','warehouseWarning',
'remark','salePrice','spec','vipPrice','wholesalePrice','warehousePropertys','sonGoods','dopey'
);
//add by michen 20170715
$data['dopey']=0;
if(strlen($data['sonGoods'])>0){
$sonlist = (array)json_decode($data['sonGoods'],true) ;
if(count($sonlist)>0){
$data['dopey']=1;
foreach ($sonlist as $sonkey => $sonrow){
if(empty($sonrow['gid']))
str_alert(-1,'您所选择的商品ID不存在请重新选择');
else if($this->mysql_model->get_count('goods',array('isDelete'=>0,'id'=>$sonrow['gid'],'number'=>$sonrow['number'])) <= 0)
str_alert(-1,'您所选择的子商品编号“'.$sonrow['number'].'”不存在!请重新选择!');
}
}
}
$info = elements($info,$data,NULL);
$data['id'] = $this->mysql_model->insert('goods',$info);
if (strlen($data['propertys'])>0) {
$list = (array)json_decode($data['propertys'],true);
foreach ($list as $arr=>$row) {
$v[$arr]['invId'] = $data['id'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['qty'] = (float)$row['quantity'];
$v[$arr]['price'] = (float)$row['unitCost'];
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['billDate'] = date('Y-m-d');;
$v[$arr]['billNo'] = '期初数量';
$v[$arr]['billType'] = 'INI';
$v[$arr]['transTypeName'] = '期初数量';
}
if (isset($v)) {
$this->mysql_model->insert('invoice_info',$v);
}
}
if (strlen($data['warehousePropertys'])>0) {
$list = (array)json_decode($data['warehousePropertys'],true);
foreach ($list as $arr=>$row) {
$s[$arr]['invId'] = $data['id'];
$s[$arr]['locationId'] = intval($row['locationId']);
$s[$arr]['highQty'] = (float)$row['highQty'];
$s[$arr]['lowQty'] = (float)$row['lowQty'];
}
if (isset($s)) {
$this->mysql_model->insert('warehouse',$s);
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增商品:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(70);
$data = $this->input->post(NULL,TRUE);
if ($data) {
$data = $this->validform($data);
$this->mysql_model->get_count('goods',array('id !='=>$data['id'],'isDelete'=>0,'number'=>$data['number'])) > 0 && str_alert(-1,'商品编号重复');
$this->db->trans_begin();
$info = array(
'barCode','baseUnitId','unitName','categoryId','categoryName','propertys',
'discountRate1','discountRate2','highQty','locationId','pinYin',
'locationName','lowQty','name','number','purPrice','warehouseWarning',
'remark','salePrice','spec','vipPrice','wholesalePrice','warehousePropertys','sonGoods','dopey'
);
//add by michen 20170715
$data['dopey']=0;
if(strlen($data['sonGoods'])>0){
$sonlist = (array)json_decode($data['sonGoods'],true) ;
if(count($sonlist)>0){
$data['dopey']=1;
foreach ($sonlist as $sonkey => $sonrow){
if(empty($sonrow['gid']))
str_alert(-1,'您所选择的商品ID不存在请重新选择');
else if($this->mysql_model->get_count('goods',array('isDelete'=>0,'id'=>$sonrow['gid'],'number'=>$sonrow['number'])) <= 0)
str_alert(-1,'您所选择的子商品编号“'.$sonrow['number'].'”不存在!请重新选择!');
}
}
}
$info = elements($info, $data,NULL);
$this->mysql_model->update('goods',$info,array('id'=>$data['id']));
if (strlen($data['propertys'])>0) {
$list = (array)json_decode($data['propertys'],true);
foreach ($list as $arr=>$row) {
$v[$arr]['invId'] = $data['id'];
$v[$arr]['locationId'] = isset($row['locationId']) ? $row['locationId'] : 0;
$v[$arr]['qty'] = isset($row['quantity']) ? $row['quantity']:0;
$v[$arr]['price'] = isset($row['unitCost']) ? $row['unitCost']:0;
$v[$arr]['amount'] = isset($row['amount']) ? $row['amount']:0;
$v[$arr]['skuId'] = isset($row['skuId']) ? $row['skuId']:0;
$v[$arr]['billDate'] = date('Y-m-d');
$v[$arr]['billNo'] = '期初数量';
$v[$arr]['billType'] = 'INI';
$v[$arr]['transTypeName'] = '期初数量';
}
if (isset($v)) {
$this->mysql_model->delete('invoice_info',array('invId'=>$data['id'],'billType'=>'INI'));
$this->mysql_model->insert('invoice_info',$v);
}
}
if (strlen($data['warehousePropertys'])>0) {
$list = (array)json_decode($data['warehousePropertys'],true);
foreach ($list as $arr=>$row) {
$s[$arr]['invId'] = $data['id'];
$s[$arr]['locationId'] = isset($row['locationId']) ? $row['locationId'] : 0;
$s[$arr]['highQty'] = isset($row['highQty']) ? $row['highQty']:0;
$s[$arr]['lowQty'] = isset($row['lowQty']) ? $row['lowQty']:0;
}
if (isset($s)) {
$this->mysql_model->delete('warehouse',array('invId'=>$data['id']));
$this->mysql_model->insert('warehouse',$s);
}
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改商品:ID='.$data['id'].'名称:'.$data['name']);
str_alert(200,'success',$this->get_goods_info($data['id']));
}
}
str_alert(-1,'修改失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(71);
$id = str_enhtml($this->input->post('id',TRUE));
$data = $this->mysql_model->get_results('goods','(id in('.$id.')) and (isDelete=0)');
if (count($data) > 0) {
$this->mysql_model->get_count('invoice_info','(invId in('.$id.')) and (isDelete=0) and (billType<>"INI")')>0 && str_alert(-1,'其中有商品发生业务不可删除');
$sql = $this->mysql_model->update('goods',array('isDelete'=>1),'(id in('.$id.'))');
$this->mysql_model->update('invoice_info',array('isDelete'=>1),'(invId in('.$id.'))');
if ($sql) {
$name = array_column($data,'name');
$this->common_model->logs('删除商品:ID='.$id.' 名称:'.join(',',$name));
str_alert(200,'success',array('msg'=>'','id'=>'['.$id.']'));
}
str_alert(-1,'删除失败');
}
}
//导出
public function exporter() {
$this->common_model->checkpurview(72);
$name = 'goods_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出商品:'.$name);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$categoryid = intval($this->input->get_post('assistId',TRUE));
$barCode = intval($this->input->get_post('barCode',TRUE));
$where = '(a.isDelete=0)';
$where .= $skey ? ' and (name like "%'.$skey.'%" or number like "%'.$skey.'%" or spec like "%'.$skey.'%")' : '';
$where .= $barCode ? ' and barCode="'.$barCode.'"' : '';
if ($categoryid > 0) {
$cid = array_column($this->mysql_model->get_results('category','(isDelete=1) and find_in_set('.$categoryid.',path)'),'id');
if (count($cid)>0) {
$cid = join(',',$cid);
$where .= ' and categoryid in('.$cid.')';
}
}
$data['storage'] = array_column($this->mysql_model->get_results('storage'),'name','id');
$data['list'] = $this->data_model->get_goods($where.' order by a.id desc');
$this->load->view('settings/goods-export',$data);
}
//状态
public function disable(){
$this->common_model->checkpurview(72);
$disable = intval($this->input->post('disable',TRUE));
$id = str_enhtml($this->input->post('invIds',TRUE));
if (strlen($id) > 0) {
$sql = $this->mysql_model->update('goods',array('disable'=>$disable),'(id in('.$id.'))');
if ($sql) {
$this->common_model->logs('商品'.$disable==1?'禁用':'启用'.':ID:'.$id.'');
str_alert(200,'success');
}
}
str_alert(-1,'操作失败');
}
//库存预警
public function listinventoryqtywarning() {
$locationId = intval($this->input->get_post('locationId',TRUE));
$warnType = intval($this->input->get_post('warnType',TRUE));
$assistId = intval($this->input->get_post('assistId',TRUE));
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),20);
$where = 'a.isDelete=0';
if ($warnType==1) {
$having = 'HAVING qty<lowQty';
} elseif($warnType==2) {
$having = 'HAVING qty>highQty';
} else {
$having = 'HAVING qty>highQty or qty<lowQty';
}
if ($assistId > 0) {
$cid = array_column($this->mysql_model->get_results('category','(isDelete=1) and find_in_set('.$assistId.',path)'),'id');
if (count($cid)>0) {
$cid = join(',',$cid);
$where .= ' and b.categoryId in('.$cid.')';
}
}
$where .= $skey ? ' and (b.name like "%'.$skey.'%" or b.number like "%'.$skey.'%" or b.spec like "%'.$skey.'%")' : '';
$where .= $locationId>0 ? ' and a.locationId='.$locationId.'' : '';
$where .= $this->common_model->get_location_purview();
$offset = $rows*($page-1);
$list = $this->data_model->get_inventory($where.' GROUP BY invId,locationId '.$having.' limit '.$offset.','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['highQty'] = (float)$row['highQty'];
$v[$arr]['id'] = intval($row['invId']);
$v[$arr]['lowQty'] = (float)$row['lowQty'];
$v[$arr]['name'] = $row['invName'];
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['number'] = $row['invNumber'];
$v[$arr]['categoryName'] = $row['categoryName'];
$v[$arr]['warning'] = $row['qty1'] > 0 ? $row['qty1'] : $row['qty2'];
$v[$arr]['qty'] = (float)$row['qty'];
$v[$arr]['unitName'] = $row['unitName'];
$v[$arr]['spec'] = $row['invSpec'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_inventory($where.' GROUP BY invId,locationId '.$having,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? array_values($v) : array();
die(json_encode($json));
}
public function warningExporter() {
$this->common_model->checkpurview();
$name = 'InventoryWarning_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出库存预警商品:'.$name);
$locationId = intval($this->input->get_post('locationId',TRUE));
$warnType = intval($this->input->get_post('warnType',TRUE));
$assistId = intval($this->input->get_post('assistId',TRUE));
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$where = 'a.isDelete=0';
if ($warnType==1) {
$having = 'HAVING qty<lowQty';
} elseif($warnType==2) {
$having = 'HAVING qty>highQty';
} else {
$having = 'HAVING qty>highQty or qty<lowQty';
}
if ($assistId > 0) {
$cid = array_column($this->mysql_model->get_results('category','(isDelete=1) and find_in_set('.$assistId.',path)'),'id');
if (count($cid)>0) {
$cid = join(',',$cid);
$where .= ' and b.categoryId in('.$cid.')';
}
}
$where .= $skey ? ' and (b.name like "%'.$skey.'%" or b.number like "%'.$skey.'%" or b.spec like "%'.$skey.'%")' : '';
$where .= $locationId>0 ? ' and a.locationId='.$locationId.'' : '';
$where .= $this->common_model->get_location_purview();
$data['list'] = $this->data_model->get_inventory($where.' GROUP BY invId,locationId '.$having);
$this->load->view('settings/inventory-warning-exporter',$data);
}
//通过ID 获取商品信息
private function get_goods_info($id) {
$data = $this->mysql_model->get_rows('goods',array('id'=>$id,'isDelete'=>0));
if (count($data)>0) {
$data['id'] = $id;
$data['count'] = 0;
$data['name'] = $data['name'];
$data['spec'] = $data['spec'];
$data['number'] = $data['number'];
$data['salePrice'] = (float)$data['salePrice'];
$data['purPrice'] = (float)$data['purPrice'];
$data['wholesalePrice']= (float)$data['wholesalePrice'];
$data['vipPrice'] = (float)$data['vipPrice'];
$data['discountRate1'] = (float)$data['discountRate1'];
$data['discountRate2'] = (float)$data['discountRate2'];
$data['unitTypeId'] = intval($data['unitTypeId']);
$data['baseUnitId'] = intval($data['baseUnitId']);
$data['locationId'] = intval($data['locationId']);
$data['assistIds'] = '';
$data['assistName'] = '';
$data['assistUnit'] = '';
$data['remark'] = $data['remark'];
$data['categoryId'] = intval($data['categoryId']);
$data['unitId'] = intval($data['unitId']);
$data['length'] = '';
$data['weight'] = '';
$data['jianxing'] = '';
$data['barCode'] = $data['barCode'];
$data['josl'] = '';
$data['warehouseWarning'] = intval($data['warehouseWarning']);
$data['warehouseWarningSku'] = 0;
$data['skuClassId'] = 0;
$data['isSerNum'] = 0;
$data['pinYin'] = $data['pinYin'];
$data['delete'] = false;
$data['isWarranty'] = 0;
$data['safeDays'] = 0;
$data['advanceDay'] = 0;
$data['property'] = $data['property'] ? $data['property'] : NULL;
$propertys = $this->data_model->get_invoice_info('a.isDelete=0 and a.invId='.$id.' and a.billType="INI"');
foreach ($propertys as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['inventoryId'] = intval($row['invId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['quantity'] = (float)$row['qty'];
$v[$arr]['unitCost'] = (float)$row['price'];
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['skuName'] = '';
$v[$arr]['date'] = $row['billDate'];
$v[$arr]['tempId'] = 0;
$v[$arr]['batch'] = '';
$v[$arr]['invSerNumList'] = '';
}
$data['propertys'] = isset($v) ? $v : array();
if ($data['warehousePropertys']) {
$warehouse = (array)json_decode($data['warehousePropertys'],true);
foreach ($warehouse as $arr=>$row) {
$s[$arr]['locationId'] = intval($row['locationId']);
$s[$arr]['locationName'] = $row['locationName'];
$s[$arr]['highQty'] = (float)$row['highQty'];
$s[$arr]['lowQty'] = (float)$row['lowQty'];
}
}
$data['warehousePropertys'] = isset($s) ? $s : array();
if (strlen($data['sonGoods'])>0) {
$list = (array)json_decode($data['sonGoods'],true);
foreach ($list as $arr=>$row) {
$v[$arr]['number'] = $row['number'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['spec'] = $row['spec'];
$v[$arr]['unitName'] = $row['unitName'];
$v[$arr]['qty'] = intval($row['qty']);
$v[$arr]['salePrice'] = intval($row['salePrice']);
$v[$arr]['gid'] = intval($row['gid']);//add by michen 20170719
}
}
$data['sonGoods'] = isset($v) ? $v : array();
}
return $data;
}
//公共验证
private function validform($data) {
$this->load->library('lib_cn2pinyin');
strlen($data['name']) < 1 && str_alert(-1,'商品名称不能为空');
strlen($data['number']) < 1 && str_alert(-1,'商品编号不能为空');
$data['categoryId'] = intval($data['categoryId']);
$data['baseUnitId'] = intval($data['baseUnitId']);
$data['categoryId'] < 1 && str_alert(-1,'商品类别不能为空');
$data['baseUnitId'] < 1 && str_alert(-1,'计量单位不能为空');
$data['id'] = isset($data['id']) ? intval($data['id']):0;
$data['lowQty'] = isset($data['lowQty']) ? (float)$data['lowQty'] :0;
$data['highQty'] = isset($data['highQty']) ? (float)$data['highQty']:0;
$data['purPrice'] = isset($data['purPrice']) ? (float)$data['purPrice']:0;
$data['salePrice'] = isset($data['salePrice']) ? (float)$data['salePrice']:0;
$data['vipPrice'] = isset($data['vipPrice']) ? (float)$data['vipPrice']:0;
$data['warehouseWarning'] = isset($data['warehouseWarning']) ? intval($data['warehouseWarning']):0;
$data['discountRate1'] = (float)$data['discountRate1'];
$data['discountRate2'] = (float)$data['discountRate2'];
$data['wholesalePrice'] = isset($data['wholesalePrice']) ? (float)$data['wholesalePrice']:0;
$data['unitName'] = $this->mysql_model->get_row('unit',array('id'=>$data['baseUnitId']),'name');
$data['categoryName'] = $this->mysql_model->get_row('category',array('id'=>$data['categoryId']),'name');
$data['pinYin'] = $this->lib_cn2pinyin->encode($data['name']);
!$data['categoryName'] && str_alert(-1,'商品类别不存在');
if (strlen($data['propertys'])>0) {
$list = (array)json_decode($data['propertys'],true);
$storage = $this->mysql_model->get_results('storage',array('disable'=>0));
$locationId = array_column($storage,'id');
$locationName = array_column($storage,'name','id');
foreach ($list as $arr=>$row) {
!in_array($row['locationId'],$locationId) && str_alert(-1,$locationName[$row['locationId']].'仓库不存在或不可用!');
}
}
$data['warehousePropertys'] = isset($data['warehousePropertys']) ? $data['warehousePropertys'] :'[]';
$data['warehousePropertys'] = count(json_decode($data['warehousePropertys'],true))>0 ? $data['warehousePropertys'] :'';
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,116 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Invlocation extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//仓库列表
public function index(){
$list = $this->mysql_model->get_results('storage','(isDelete=0) '.$this->common_model->get_location_purview(1).' order by id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['address'] = $row['address'];
$v[$arr]['delete'] = $row['disable'] > 0 ? true : false;
$v[$arr]['allowNeg'] = false;
$v[$arr]['deptId'] = intval($row['deptId']);;
$v[$arr]['empId'] = intval($row['empId']);;
$v[$arr]['groupx'] = $row['groupx'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['locationNo'] = $row['locationNo'];
$v[$arr]['name'] = $row['name'];
$v[$arr]['phone'] = $row['phone'];
$v[$arr]['type'] = intval($row['type']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['rows'] = isset($v) ? $v : array();
$json['data']['total'] = 1;
$json['data']['records'] = count($list);
$json['data']['page'] = 1;
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(156);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$sql = $this->mysql_model->insert('storage',elements(array('name','locationNo'),$data));
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增仓库:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(157);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$sql = $this->mysql_model->update('storage',elements(array('name','locationNo'),$data),array('id'=>$data['locationId']));
if ($sql) {
$data['id'] = $data['locationId'];
$this->common_model->logs('更新仓库:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(158);
$id = intval($this->input->post('locationId',TRUE));
$data = $this->mysql_model->get_rows('storage',array('id'=>$id,'isDelete'=>0));
if (count($data) > 0) {
$this->mysql_model->get_count('invoice_info',array('locationId'=>$id,'isDelete'=>0))>0 && str_alert(-1,'不能删除有业务关联的仓库!');
$sql = $this->mysql_model->update('storage',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除仓库:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success');
}
}
str_alert(-1,'删除失败');
}
//启用禁用
public function disable(){
$this->common_model->checkpurview(158);
$id = intval($this->input->post('locationId',TRUE));
$data = $this->mysql_model->get_rows('storage',array('id'=>$id,'isDelete'=>0));
if (count($data) > 0) {
$info['disable'] = intval($this->input->post('disable',TRUE));
$sql = $this->mysql_model->update('storage',$info,array('id'=>$id));
if ($sql) {
$actton = $info['disable']==0 ? '仓库启用' : '仓库禁用';
$this->common_model->logs($actton.':ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success');
}
}
str_alert(-1,'操作失败');
}
//公共验证
private function validform($data) {
strlen($data['name']) < 1 && str_alert(-1,'仓库名称不能为空');
strlen($data['locationNo']) < 1 && str_alert(-1,'编号不能为空');
$data['locationId'] = intval($data['locationId']);
$where = $data['locationId']>0 ? ' and id<>'.$data['locationId'].'' :'';
$this->mysql_model->get_count('storage','(isDelete=0) and name="'.$data['name'].'" '.$where) > 0 && str_alert(-1,'名称重复');
$this->mysql_model->get_count('storage','(isDelete=0) and locationNo="'.$data['locationNo'].'" '.$where) > 0 && str_alert(-1,'编号重复');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,79 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Log extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview(83);
}
public function index(){
$fromDate = str_enhtml($this->input->get_post('fromDate',TRUE));
$toDate = str_enhtml($this->input->get_post('toDate',TRUE));
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$user = str_enhtml($this->input->get_post('user',TRUE));
$where['name'] = $user ? $user :'';
$where['adddate >='] = $fromDate ? $fromDate :'';
$where['adddate <='] = $toDate ? $toDate :'';
$list = $this->mysql_model->get_results('log',array_filter($where),'id desc',$rows*($page-1),$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['loginName'] = $row['loginName'];
$v[$arr]['operateTypeName'] = $row['operateTypeName'];
$v[$arr]['operateType'] = 255;
$v[$arr]['userId'] = $row['userId'];
$v[$arr]['log'] = $row['log'];
$v[$arr]['modifyTime'] = $row['modifyTime'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->mysql_model->get_count('log',array_filter($where));
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function initloglist(){
$this->load->view('settings/log-initloglist');
}
//用户列表
public function queryAllUser(){
$list = $this->mysql_model->get_results('admin','(1=1)','uid desc',0,0,'uid,name');
foreach ($list as $arr=>$row) {
$v[$arr]['userid'] = intval($row['uid']);
$v[$arr]['name'] = $row['name'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = count($list);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
//操作类型
public function queryAllOperateType(){
$menu = array_column($this->mysql_model->get_results('menu',array('pid'=>0),'id desc'),'title','id');
$list = $this->mysql_model->get_results('menu',array('depth>'=>1),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['indexid'] = $row['id'];
$v[$arr]['operateTypeName'] = $row['title'].isset($menu[$row['pid']]) ? $menu[$row['pid']] : '';
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = count($list);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,17 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class ResultInfo extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
$this->load->view('settings/resultInfo');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,133 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Settacct extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//结算账户列表
public function index(){
$list = $this->mysql_model->get_results('account',array('isDelete'=>0),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['date'] = $row['date'];
$v[$arr]['amount'] = (float)$row['amount'];
$v[$arr]['del'] = false;
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['number'] = $row['number'];
$v[$arr]['type'] = intval($row['type']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//查询
public function query(){
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('account',array('id'=>$id,'isDelete'=>0));
if (count($data)>0) {
$v = array();
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['date'] = $data['date'];
$json['data']['amount'] = (float)$data['amount'];
$json['data']['del'] = false;
$json['data']['id'] = intval($data['id']);
$json['data']['name'] = $data['name'];
$json['data']['number'] = $data['number'];
$json['data']['type'] = intval($data['type']);
die(json_encode($json));
}
}
//当前余额
public function findAmountOver(){
$ids = str_enhtml($this->input->post('ids',TRUE));
if (strlen($ids)>0) {
$list = $this->data_model->get_account('','a.isDelete=0 and a.id in('.$ids.')');
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['amountOver'] = (float)$row['amount'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
} else {
str_alert(200,'');
}
}
//新增
public function add(){
$this->common_model->checkpurview(160);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$info = elements(array('name','number','amount','date','type'),$data);
$sql = $this->mysql_model->insert('account',$info);
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增账户:'.$data['number'].$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(161);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (count($data)>0) {
$data = $this->validform($data);
$info = elements(array('name','number','amount','date','type'),$data);
$sql = $this->mysql_model->update('account',$info,array('id'=>$data['id']));
if ($sql) {
$this->common_model->logs('更新账户:'.$data['number'].$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(162);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('account',array('id'=>$id,'isDelete'=>0));
if (count($data)>0) {
$this->mysql_model->get_count('account_info',array('accId'=>$id,'isDelete'=>0))>0 && str_alert(-1,'账户资料已经被使用');
$sql = $this->mysql_model->update('account',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除账户:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'成功删除'));
}
}
str_alert(-1,'删除失败');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) :0;
$data['amount'] = (float)$data['amount'];
$data['type'] = intval($data['type']);
strlen($data['name']) < 1 && str_alert(-1,'名称不能为空');
strlen($data['number']) < 1 && str_alert(-1,'编号不能为空');
$where = $data['id']>0 ? ' and (id<>'.$data['id'].')' : '';
$this->mysql_model->get_count('account','(isDelete=0) and name="'.$data['name'].'" '.$where) > 0 && str_alert(-1,'名称重复');
$this->mysql_model->get_count('account','(isDelete=0) and number="'.$data['number'].'" '.$where) > 0 && str_alert(-1,'编号重复');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,27 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Supplier extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview(67);
}
public function exporter(){
$name = 'supplier_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出供应商:'.$name);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$categoryId = intval($this->input->get_post('categoryId',TRUE));
$where = '(isDelete=0) and type=10 ';
$where .= $this->common_model->get_vendor_purview();
$where .= $skey ? ' and (number like "%'.$skey.'%" or name like "%'.$skey.'%" or linkMans like "%'.$skey.'%")' : '';
$where .= $categoryId >0 ? ' and cCategory = '.$categoryId.'' : '';
$data['list'] = $this->mysql_model->get_results('contact',$where,'id desc');
$this->load->view('settings/vendor-export',$data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,58 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Systemprofile extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//单据编号
public function generateDocNo() {
$billType = str_enhtml($this->input->post('billType',TRUE));
$info = array(
'PUR'=>'CG',
'SALE'=>'XS',
'TRANSFER'=>'DB',
'OO'=>'QTCK',
'PO'=>'CGDD',
'SO'=>'XSDD',
'OI'=>'QTRK',
'CADJ'=>'CBTZ',
'PAYMENT'=>'FKD',
'RECEIPT'=>'SKD',
'QTSR'=>'QTSR',
'QTZC'=>'QTZC'
);
if (isset($info[$billType])) {
str_alert(200,'success',array('billNo'=>str_no($info[$billType])));
}
str_alert(-1,'生成失败');
}
//系统设置
public function update() {
$this->common_model->checkpurview(81);
$data = str_enhtml($this->input->post(NULL,TRUE));
if (is_array($data) && count($data)>0) {
if ($this->common_model->insert_option('system',$data)) {
$this->common_model->logs('系统设置成功');
str_alert(200,'success');
}
}
str_alert(-1,'设置失败');
}
//切换皮肤
public function changeSysSkin() {
$skin = $this->input->post('skin',TRUE) ? $this->input->post('skin',TRUE) : 'green';
$this->input->set_cookie('skin',$skin,360000);
$this->common_model->logs('切换皮肤:'.$skin);
str_alert(200,'success');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,97 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Unit extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
//单位列表
public function index(){
$unittypeid = intval($this->input->get_post('unitTypeId',TRUE));
if ($unittypeid>0) {
$where['unittypeid'] = $unittypeid;
}
$where['isDelete'] = 0;
$list = $this->mysql_model->get_results('unit',$where,'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['default'] = $row['default']==1 ? true : false;
$v[$arr]['guid'] = $row['guid'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
$v[$arr]['rate'] = intval($row['rate']);
$v[$arr]['isDelete'] = intval($row['isDelete']);
$v[$arr]['unitTypeId'] = intval($row['unitTypeId']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(78);
$data = $this->validform(str_enhtml($this->input->post(NULL,TRUE)));
$sql = $this->mysql_model->insert('unit',elements(array('name','default'),$data));
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增单位:'.$data['name']);
die('{"status":200,"msg":"success","data":{"default":false,"guid":"","id":'.$sql.',"isdelete":0,"name":"'.$data['name'].'","rate":1,"unitTypeId":0}}');
str_alert(200,'success',$data);
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(79);
$data = $this->validform(str_enhtml($this->input->post(NULL,TRUE)));
$this->mysql_model->get_count('goods',array('isDelete'=>0,'unitId'=>$data['id']))>0 && str_alert(-1,'该单位已经被使用,不允许更改组');
$sql = $this->mysql_model->update('unit',elements(array('name','default'),$data),array('id'=>$data['id']));
if ($sql) {
$this->mysql_model->update('goods',array('unitName'=>$data['name']),array('baseUnitId'=>$data['id']));
$this->common_model->logs('更新单位:'.$data['name']);
str_alert(200,'success',$data);
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(80);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('unit',array('isDelete'=>0,'id'=>$id));
if (count($data)>0) {
$this->mysql_model->get_count('goods',array('isDelete'=>0,'unitId'=>$id))>0 && str_alert(-1,'该单位已经被使用,不允许删除');
$sql = $this->mysql_model->update('unit',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除单位:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'成功删除','id'=>'['.$id.']'));
}
}
str_alert(-1,'删除失败');
}
//公共验证
private function validform($data) {
strlen($data['name']) < 1 && str_alert(-1,'单位名称不能为空');
$data['id'] = isset($data['id']) ? intval($data['id']) :0;
$data['rate'] = isset($data['rate']) ? intval($data['rate']) :0;
$data['default'] = isset($data['default']) ? $data['default'] :'';
$data['unitTypeId'] = isset($data['unitTypeId']) ? intval($data['unitTypeId']):0;
$data['default'] = $data['default']== 'true' ? 1 : 0;
$where['isDelete'] = 0;
$where['name'] = $data['name'];
$where['id !='] = $data['id']>0 ? $data['id'] :0;
$this->mysql_model->get_count('unit',$where) && str_alert(-1,'单位名称重复');
return $data;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,82 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Unittype extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
$list = $this->mysql_model->get_results('unittype',array('isDelete'=>0),'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['entries'] = array();
$v[$arr]['guid'] = '';
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['name'] = $row['name'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['totalsize'] = count($list);
die(json_encode($json));
}
//新增
public function add() {
$this->common_model->checkpurview(59);
$data['name'] = $name = $this->input->post('name',TRUE);
strlen($name) < 1 && str_alert(-1,'名称不能为空');
$this->mysql_model->get_count('unittype',array('name'=>$name)) && str_alert(-1,'单位组名称重复');
$sql = $this->mysql_model->insert('unittype',$data);
if ($sql) {
$data['id'] = $sql;
$this->common_model->logs('新增单位组:'.$name);
str_alert(200,'success',$data);
}
str_alert(-1,'添加失败');
}
//修改
public function update(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$name = str_enhtml($this->input->post('name',TRUE));
$info = $this->mysql_model->get_rows('unittype','(id='.$id.') and (isDelete=0)');
if (count($info)>0) {
strlen($name) < 1 && str_alert(-1,'名称不能为空');
$this->mysql_model->get_count('unittype',array('isDelete'=>$isDelete,'name'=>$name,'id !='=>$id)) > 0 && str_alert(-1,'单位组名称重复');
$sql = $this->mysql_model->update('unittype',array('name'=>$name),array('id'=>$id));
if ($sql) {
$data['id'] = $id;
$data['name'] = $name;
$data['entries'] = array();
$data['guid'] = '';
$this->common_model->logs('更新单位组:'.$data['name']);
str_alert(200,'success',$data);
}
}
str_alert(-1,'更新失败');
}
//删除
public function delete(){
$this->common_model->checkpurview(59);
$id = intval($this->input->post('id',TRUE));
$data = $this->mysql_model->get_rows('unittype',array('isDelete'=>$isDelete,'id'=>$id));
if (count($data)>0) {
$this->mysql_model->get_count('unit',array('isDelete'=>$isDelete,'unittypeid'=>$id))>0 && str_alert(-1,'发生业务不可删除');
$sql = $this->mysql_model->update('unittype',array('isDelete'=>1),array('id'=>$id));
if ($sql) {
$this->common_model->logs('删除单位组:ID='.$id.' 名称:'.$data['name']);
str_alert(200,'success',array('msg'=>'成功删除','id'=>'['.$id.']'));
}
}
str_alert(-1,'删除失败');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,31 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Warranty extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
}
public function getAdvancedList(){
$data['status'] = 200;
$data['msg'] = 'success';
$data['data']['page'] = 1;
$data['data']['total'] = 0;
$data['data']['records'] = 0;
$data['data']['rows'] = array();
die(json_encode($data));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,132 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Dataright extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview(82);
}
public function ar() {
$data = $this->input->post(NULL,TRUE);
if (count($data)>0) {
$userName = str_enhtml($this->input->get('userName',TRUE));
$rightid = (array)json_decode($data['rightid'],true);
$info['rightids'] = join(',',$rightid['rightids']);
$sql = $this->mysql_model->update('admin',$info,'(username="'.$userName.'")');
if ($sql) {
str_alert(200,'success');
}
}
str_alert(-1,'更新失败');
}
public function dt() {
$ids = str_enhtml($this->input->post('userName',TRUE));
die('{"status":200,"data":{"items":[
{"FNAME":"仓库","FRIGHT":"1","FRIGHTID":"1","FNUMBER":"location"},
{"FNAME":"客户","FRIGHT":"2","FRIGHTID":"2","FNUMBER":"customer"},
{"FNAME":"供应商","FRIGHT":"4","FRIGHTID":"4","FNUMBER":"supplier"},
{"FNAME":"制单人","FRIGHT":"8","FRIGHTID":"8","FNUMBER":"user"}
],"totalsize":4},"msg":"success"}');
}
public function update() {
$this->common_model->checkpurview();
$type = max(intval($this->input->get('type',TRUE)),1);
$rights = $this->input->post('rights',TRUE);
$userName = str_enhtml($this->input->get('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data>0)) {
$array = explode(',',$data['righttype'.$type]);
foreach((array)json_decode($rights,true) as $arr=>$row){
if ($row['FRIGHT']==1) {
$s1[] = $row['FITEMID']; //新增
} else {
$s2[] = $row['FITEMID']; //除去
}
}
if (isset($s1)) {
$info['righttype'.$type] = join(',',array_filter(array_merge($array,$s1)));
$this->mysql_model->update('admin',$info,array('username'=>$userName));
}
if (isset($s2)) {
$info['righttype'.$type] = join(',',array_filter(array_diff($array,$s2)));
$this->mysql_model->update('admin',$info,array('username'=>$userName));
}
str_alert(200,'success');
}
str_alert(-1,'更新失败');
}
public function query() {
$v = array();
$type = max(intval($this->input->get_post('type',TRUE)),0);
$skey = str_enhtml($this->input->get_post('skey',TRUE));
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
switch ($type) {
case 1:
$righttype = explode(',',$data['righttype'.$type]);
$where = $skey ? ' and (locationNo like "%'.$skey.'%" or name like "%'.$skey.'%")' : '';
$list = $this->mysql_model->get_results('storage','(isDelete=0) '.$where,'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['FITEMID'] = intval($row['id']);
$v[$arr]['FNAME'] = $row['name'];
$v[$arr]['FITEMNO'] = $row['locationNo'];
$v[$arr]['FRIGHT'] = in_array($row['id'],$righttype)==1 ? 1 : 0;
}
break;
case 2:
$righttype = explode(',',$data['righttype'.$type]);
$where = $skey ? ' and (number like "%'.$skey.'%" or name like "%'.$skey.'%")' : '';
$list = $this->mysql_model->get_results('contact','(isDelete=0) and type=-10 '.$where,'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['FITEMID'] = intval($row['id']);
$v[$arr]['FNAME'] = $row['name'];
$v[$arr]['FITEMNO'] = $row['number'];
$v[$arr]['FRIGHT'] = in_array($row['id'],$righttype)==1 ? 1 : 0;
}
break;
case 4:
$righttype = explode(',',$data['righttype'.$type]);
$where = $skey ? ' and (number like "%'.$skey.'%" or name like "%'.$skey.'%")' : '';
$list = $this->mysql_model->get_results('contact','(isDelete=0) and type=10 '.$where,'id desc');
foreach ($list as $arr=>$row) {
$v[$arr]['FITEMID'] = intval($row['id']);
$v[$arr]['FNAME'] = $row['name'];
$v[$arr]['FITEMNO'] = $row['number'];
$v[$arr]['FRIGHT'] = in_array($row['id'],$righttype)==1 ? 1 : 0;
}
break;
case 8:
$righttype = explode(',',$data['righttype'.$type]);
$where = $skey ? ' and (username like "%'.$skey.'%" or name like "%'.$skey.'%")' : '';
$list = $this->mysql_model->get_results('admin','(1=1) '.$where,'uid desc');
foreach ($list as $arr=>$row) {
$v[$arr]['FITEMID'] = intval($row['uid']);
$v[$arr]['FNAME'] = $row['username'];
$v[$arr]['FITEMNO'] = intval($row['uid']);
$v[$arr]['FRIGHT'] = in_array($row['uid'],$righttype)==1 ? 1 : 0;
}
break;
default:
}
}
$data['status'] = 200;
$data['msg'] = 'success';
$data['data']['rows'] = $v;
$data['data']['total'] = 1;
$data['data']['records'] = count($v);
$data['data']['page'] = 1;
die(json_encode($data));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,62 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index(){
//add by michen 20170820 for 修改登录异常 begin
if(!strstr($_SERVER['REQUEST_URI'], 'home/index'))
redirect('home/index', 'refresh');
//add by michen 20170820 for 修改登录异常 end
$data['uid'] = $this->jxcsys['uid'];
$data['name'] = $this->jxcsys['name'];
$data['roleid'] = 0;
$data['username'] = $this->jxcsys['username'];
$data['system'] = $this->common_model->get_option('system');
$data['rights'] = $this->common_model->get_admin_rights();
$this->load->view('index',$data);
}
public function main(){
$this->load->view('main');
}
public function set_password(){
$data = str_enhtml($this->input->post(NULL,TRUE));
if (is_array($data)&&count($data)>0) {
$info['userpwd'] = md5($data['newPassword']);
$info['mobile'] = $data['buyerMobile'];
$info['name'] = $data['buyerName'];
$this->mysql_model->get_count('admin','(uid<>'.$this->jxcsys['uid'].') and mobile='.$info['mobile'].'') >0 && str_alert(-1,'该手机号已被使用,请更换手机号码');
$sql = $this->mysql_model->update('admin',$info,'(uid='.$this->jxcsys['uid'].')');
if ($sql) {
$this->common_model->logs('密码修改成功 UID'.$this->jxcsys['uid'].' 真实姓名改为:'.$info['name']);
str_alert(200,'密码修改成功');
}
str_alert(-1,'设置独立密码失败,请稍候重试!');
} else {
$data = $this->mysql_model->get_rows('admin','(uid='.$this->jxcsys['uid'].')');
$this->load->view('set_password',$data);
}
}
public function Services(){
die('jQuery110202928952066617039_1430920204305({"status":200,"msg":"success","data":[{"msgid":"20000000122"
,"msglinkcolor":"d9254a","msglink":"","msgtitle":"售后热线服务时间临时调整通知5.6-5.8>>"},{"msgid":"20000000119"
,"msglinkcolor":"d9254a","msglink":"index.html","msgtitle"
:"推荐送ipad mini购买就返利>>"},{"msgid":"20000000115","msglinkcolor":"d9254a","msglink":"","msgtitle":">>"},{"msgid":"20000000068","msglinkcolor":"d9254a","msglink":"","msgtitle":">
>"}]})');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,20 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Import extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
$this->load->view('settings/import');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Inventory extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
$this->load->view('inventory');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,53 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function index(){
$data = str_enhtml($this->input->post(NULL,TRUE));
if (is_array($data)&&count($data)>0) {
!token(1) && die('token验证失败');
strlen($data['username']) < 1 && die('用户名不能为空');
strlen($data['userpwd']) < 1 && die('密码不能为空');
$user = $this->mysql_model->get_rows('admin','(username="'.$data['username'].'") or (mobile="'.$data['username'].'") ');
if (count($user)>0) {
$user['status']!=1 && die('账号被锁定');
if ($user['userpwd'] == md5($data['userpwd'])) {
$data['jxcsys']['uid'] = $user['uid'];
$data['jxcsys']['name'] = $user['name'];
$data['jxcsys']['roleid'] = $user['roleid'];
$data['jxcsys']['username'] = $user['username'];
$data['jxcsys']['login'] = 'jxc';
if (isset($data['ispwd']) && $data['ispwd'] == 1) {
$this->input->set_cookie('username',$data['username'],3600000);
$this->input->set_cookie('userpwd',$data['userpwd'],3600000);
}
$this->input->set_cookie('ispwd',$data['ispwd'],3600000);
$this->session->set_userdata($data);
$this->common_model->logs('登陆成功 用户名:'.$data['username']);
die('1');
}
}
die('账号或密码错误');
} else {
$this->load->view('login',$data);
}
}
public function out(){
$this->session->sess_destroy();
redirect(site_url('login'));
}
public function code(){
$this->load->library('lib_code');
$this->lib_code->image();
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

1513
application/controllers/mobile.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Noteprinttemp extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,24 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Prints extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
}
public function print_settings_voucher() {
$this->load->view('print/print-settings-voucher');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

2095
application/controllers/report.php Executable file

File diff suppressed because it is too large Load Diff

151
application/controllers/right.php Executable file
View File

@@ -0,0 +1,151 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Right extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview(82);
}
public function isMaxShareUser() {
die('{"status":200,"data":{"totalUserNum":1000,"shareTotal":1},"msg":"success"}');
}
public function queryAllUser() {
$list = $this->mysql_model->get_results('admin','(1=1)','roleid');
foreach ($list as $arr=>$row) {
$v[$arr]['share'] = intval($row['status']) > 0 ? true : false;
$v[$arr]['admin'] = $row['roleid'] > 0 ? false : true;
$v[$arr]['userId'] = intval($row['uid']);
$v[$arr]['isCom'] = intval($row['status']);
$v[$arr]['role'] = intval($row['roleid']);
$v[$arr]['userName'] = $row['username'];
$v[$arr]['realName'] = $row['name'];
$v[$arr]['shareType'] = intval($row['status']);
$v[$arr]['mobile'] = $row['mobile'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['items'] = isset($v) ? $v : array();
$json['data']['shareTotal'] = count($list);
$json['data']['totalsize'] = $json['data']['shareTotal'];
$json['data']['corpID'] = 0;
$json['data']['totalUserNum'] = 1000;
die(json_encode($json));
}
public function queryUserByName() {
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
$json['share'] = true;
$json['email'] = '';
$json['userId'] = $data['uid'];
$json['userMobile'] = $data['mobile'];
$json['userName'] = $data['username'];
str_alert(200,'success',$json);
}
str_alert(502,'用户名不存在');
}
public function adduser() {
$data = str_enhtml($this->input->post(NULL,TRUE));
if (is_array($data)&&count($data)>0) {
strlen($data['userNumber'])<1 && str_alert(-1,'用户名不能为空');
strlen($data['password'])<1 && str_alert(-1,'密码不能为空');
$this->mysql_model->get_count('admin',array('username'=>$data['userNumber']))>0 && str_alert(-1,'用户名已经存在');
$this->mysql_model->get_count('admin',array('mobile'=>$data['userMobile'])) >0 && str_alert(-1,'该手机号已被使用');
$info = array(
'username' => $data['userNumber'],
'userpwd' => md5($data['password']),
'name' => $data['userName'],
'mobile' => $data['userMobile']
);
$sql = $this->mysql_model->insert('admin',$info);
if ($sql) {
$this->common_model->logs('新增用户:'.$data['userNumber']);
die('{"status":200,"msg":"注册成功","userNumber":"'.$data['userNumber'].'"}');
}
}
str_alert(-1,'添加失败');
}
public function addrights2Outuser() {
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$rightid = str_enhtml($this->input->get_post('rightid',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
$sql = $this->mysql_model->update('admin',array('lever'=>$rightid),array('username'=>$userName));
if ($sql) {
$this->common_model->logs('更新权限:'. $userName);
str_alert(200,'操作成功');
}
}
str_alert(-1,'操作失败');
}
public function queryalluserright() {
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
$lever = explode(',',$data['lever']);
$list = $this->mysql_model->get_results('menu',array('isDelete'=>0),'path');
$menu = array_column($list,'name','id');
foreach ($list as $arr=>$row) {
$v[$arr]['fobjectid'] = $row['parentId']>0 ? $row['parentId'] : $row['id'];
$v[$arr]['fobject'] = $row['parentId']>0 ? @$menu[$row['parentId']] : $row['name'];
$v[$arr]['faction'] = $row['level'] > 1 ? $row['name'] : '查询';
$v[$arr]['fright'] = in_array($row['id'],$lever) ? 1 : 0;
$v[$arr]['frightid'] = intval($row['id']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = count($list);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
}
public function auth2UserCancel(){
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
$userName == 'admin' && str_alert(-1,'管理员不可操作');
$sql = $this->mysql_model->update('admin',array('status'=>0),array('username'=>$userName));
if ($sql) {
$this->common_model->logs('用户停用:'.$userName);
str_alert(200,'success',$data);
}
}
str_alert(-1,'停用失败');
}
public function auth2User(){
$userName = str_enhtml($this->input->get_post('userName',TRUE));
$data = $this->mysql_model->get_rows('admin',array('username'=>$userName));
if (count($data)>0) {
$userName == 'admin' && str_alert(-1,'管理员不可操作');
$sql = $this->mysql_model->update('admin',array('status'=>1),array('username'=>$userName));
if ($sql) {
$this->common_model->logs('用户启用:'.$userName);
str_alert(200,'success',$data);
}
}
str_alert(-1,'启用失败');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,20 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sales extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function sales_search() {
$this->load->view('sales/sales-search');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,126 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Backup extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->load->helper(array('directory','download'));
$this->backup_path = $this->config->item('backup_path');
$this->filename = str_no().'.sql';
}
//备份
public function index(){
$this->load->dbutil();
$query = $this->db->query('SHOW TABLE STATUS');
$prefs = array(
'tables' => array_column($query->result_array(),'Name'),
'ignore' => array(),
'format' => 'txt',
'filename' => $this->filename,
'add_drop' => TRUE,
'add_insert' => TRUE,
'newline' => "\n"
);
$info = &$this->dbutil->backup($prefs);
$path = $this->backup_path.$this->filename;
$this->create_folders($this->backup_path);//add my michen 20170818
if (write_file($path, $info)) {
$this->common_model->logs('备份与恢复,备份文件名:'.$this->filename);
$data['createTime'] = date('Y-m-d H:i:s');
$data['username'] = $this->filename;
$data['filename'] = $this->filename;
$data['dbid'] = 0;
$data['fid'] = $this->filename;
$data['size'] = filesize($path);
str_alert(200,'success',$data);
}
str_alert(-1,'文件写入失败');
}
//备份列表
public function queryBackupFile(){
$v = array();
$list = get_dir_file_info($this->backup_path);
$data['status'] = 200;
$data['msg'] = 'success';
$i = 0;
count($list)<1 && str_alert(250,'暂无查询结果');
foreach ($list as $arr=>$row) {
$v[$i]['fid'] = $row['name'];
$v[$i]['createTime'] = date("Y-m-d H:i:s", $row['date']);
$v[$i]['username'] = $row['date'];
$v[$i]['filename'] = $row['name'];
$v[$i]['dbid'] = 0;
$v[$i]['size'] = $row['size'];
$i++;
}
$data['data']['items'] = $v;
$data['totalsize'] = 1;
die(json_encode($data));
}
//删除
public function deleteBackupFile(){
$data['id'] = str_enhtml($this->input->get_post('id',TRUE));
if (@unlink($this->backup_path.$data['id'])) {
$this->common_model->logs('备份与恢复,删除文件名:'.$data['id']);
str_alert(200,'删除成功',$data);
} else {
str_alert(-1,'删除失败');
}
}
//还原
public function recover(){
$id = str_enhtml($this->input->get_post('id',TRUE));
$data = read_file($this->backup_path.$id);
if ($data) {
$this->db->trans_begin();
$list = explode(";\n",$data);
foreach ($list as $sql) {
//add by michen 20170723 for 修复恢复 begin
if(strrpos($sql, '#',0)!=false)
$msql = substr($sql, strrpos($sql, '#',0)+1);
else
$msql=$sql;
$msql = trim($msql);
if(!empty($msql))//只要empty没有isempty且只能检测变量不能检测函数
//add by michen 20170723 for 修复恢复 end
$this->db->query($msql);
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'恢复失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('备份与恢复,恢复文件名:'.$id);
str_alert(200,'恢复成功');
}
}
str_alert(-1,'恢复失败');
}
//下载
public function download() {
$fid = str_enhtml($this->input->get_post('fid',TRUE));
$data = read_file($this->backup_path.$fid);
if ($data) {
$this->common_model->logs('备份与恢复,下载文件名:'.$fid);
force_download($fid, $data);
} else {
str_alert(-1,'下载失败');
}
}
function create_folders($dir) {
return is_dir($dir) or ($this->create_folders(dirname($dir)) and mkdir($dir, 0777));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,770 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class InvPu extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initPur':
$this->common_model->checkpurview(2);
$data['billNo'] = str_no('CG');
$this->load->view('scm/invPu/initPur',$data);
break;
case 'editPur':
$this->common_model->checkpurview(1);
$id = intval($this->input->get_post('id',TRUE));
$data['billNo'] = $this->mysql_model->get_row('invoice',array('id'=>$id,'billType'=>'PUR'),'billNo');
$this->load->view('scm/invPu/initPur',$data);
break;
case 'initPurList':
$this->common_model->checkpurview(1);
$this->load->view('scm/invPu/initPurList');
break;
default:
$this->common_model->checkpurview(1);
$this->purList();
}
}
public function purList() {
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.billType="PUR"';
$where .= $transType ? ' and a.transType='.$transType : '';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by '.$order.' limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['hxStateCode'] = intval($row['hxStateCode']);
//add begin
$hasCheck = (float)abs($row['hasCheck']);
if($hasCheck <= 0)
$hxStateCode = 0;
else if($hasCheck >= (float)abs($row['amount']))
$hxStateCode = 2;
else
$hxStateCode = 1;
$v[$arr]['hxStateCode'] = $hxStateCode;
//add end
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['transType'] = intval($row['transType']);
$v[$arr]['rpAmount'] = (float)abs($row['hasCheck']);
$v[$arr]['totalQty'] = (float)abs($row['totalQty']);
$v[$arr]['contactName'] = $row['contactNo'].' '.$row['contactName'];
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['totalAmount'] = (float)abs($row['totalAmount']);
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['transTypeName']= $row['transTypeName'];
$v[$arr]['disEditable'] = 0;
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function exportInvPu(){
$this->common_model->checkpurview(5);
$name = 'purchase_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出采购单据:'.$name);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.transType='.$transType.'';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by '.$order);
$this->load->view('scm/invPu/exportInvPu',$data);
}
public function findUnhxList(){
$billno = str_enhtml($this->input->get_post('billNo',TRUE));
$buid = intval($this->input->get_post('buId',TRUE));
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$begindate = str_enhtml($this->input->get_post('beginDate',TRUE));
$enddate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = '(a.billType="PUR") and checked=1';
$where .= $billno ? ' and a.billNo="'.$billno.'"' : '';
$where .= $buid > 0 ? ' and a.buId='.$buid.'' : '';
$where .= strlen($begindate)>0 ? ' and a.billDate>="'.$begindate.'"' : '';
$where .= strlen($enddate)>0 ? ' and a.billDate<="'.$enddate.'"' : '';
$list = $this->data_model->get_unhx($where.' HAVING notCheck<>0');
foreach ($list as $arr=>$row) {
$v[$arr]['type'] = 1;
$v[$arr]['billId'] = intval($row['id']);
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['transType'] = $row['transType']==150501 ? '购货' : '退货';
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['billPrice'] = (float)$row['amount'];
$v[$arr]['hasCheck'] = (float)$row['nowCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = $this->data_model->get_unhx($where.' HAVING notCheck>0',3);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function add(){
$this->common_model->checkpurview(2);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','billDate','postData','hxStateCode',
'serialno','description','totalQty','amount','arrears','rpAmount','totalAmount','createTime',
'totalArrears','disRate','disAmount','uid','userName','srcOrderNo','srcOrderId',
'accId','modifyTime'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$this->invoice_info($iid,$data);
$this->account_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增购货 单据编号:'.$info['billNo']);//.',报文:'.$_POST['postData']//stripslashes(json_encode($info))
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
public function addnew(){
$this->add();
}
public function updateInvPu(){
$this->common_model->checkpurview(3);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','hxStateCode',
'serialno','description','totalQty','amount','arrears','rpAmount','uid','userName',
'totalAmount','totalArrears','disRate','postData',
'disAmount','accId','modifyTime'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->invoice_info($data['id'],$data);
$this->account_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改购货单 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交的数据不能为空');
}
public function update() {
$this->common_model->checkpurview(1);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.billType="PUR"',1);
if (count($data)>0) {
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['contactName'] = $data['contactName'];
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['billType'] = $data['billType'];
$info['data']['modifyTime'] = $data['modifyTime'];
$info['data']['createTime'] = $data['createTime'];
$info['data']['checked'] = intval($data['checked']);
$info['data']['checkName'] = $data['checkName'];
$info['data']['transType'] = intval($data['transType']);
$info['data']['totalQty'] = (float)$data['totalQty'];
$info['data']['totalTaxAmount'] = (float)$data['totalTaxAmount'];
$info['data']['billStatus'] = intval($data['billStatus']);
$info['data']['disRate'] = (float)$data['disRate'];
$info['data']['disAmount'] = (float)$data['disAmount'];
$info['data']['amount'] = (float)abs($data['amount']);
$info['data']['rpAmount'] = (float)abs($data['rpAmount']);
$info['data']['arrears'] = (float)abs($data['arrears']);
$info['data']['userName'] = $data['userName'];
$info['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit'; //edit
$info['data']['totalDiscount'] = (float)$data['totalDiscount'];
$info['data']['totalTax'] = (float)$data['totalTax'];
$info['data']['totalAmount'] = (float)abs($data['totalAmount']);
$info['data']['serialno'] = $data['serialno'];
$info['data']['description'] = $data['description'];
$list = $this->data_model->get_invoice_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
foreach ($list as $arr=>$row) {
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['srcOrderEntryId'] = $row['srcOrderEntryId'];
$v[$arr]['srcOrderNo'] = $row['srcOrderNo'];
$v[$arr]['srcOrderId'] = $row['srcOrderId'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['invName'] = $row['invNumber'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['taxAmount'] = (float)abs($row['taxAmount']);
$v[$arr]['price'] = (float)$row['price'];
$v[$arr]['tax'] = (float)$row['tax'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['deduction'] = (float)$row['deduction'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['skuName'] = '';
}
$info['data']['entries'] = isset($v) ? $v : array();
$info['data']['accId'] = (float)$data['accId'];
$accounts = $this->data_model->get_account_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
foreach ($accounts as $arr=>$row) {
$s[$arr]['invoiceId'] = intval($id);
$s[$arr]['billNo'] = $row['billNo'];
$s[$arr]['buId'] = intval($row['buId']);
$s[$arr]['billType'] = $row['billType'];
$s[$arr]['transType'] = $row['transType'];
$s[$arr]['transTypeName'] = $row['transTypeName'];
$s[$arr]['billDate'] = $row['billDate'];
$s[$arr]['accId'] = intval($row['accId']);
$s[$arr]['account'] = $row['accountNumber'].''.$row['accountName'];
$s[$arr]['payment'] = (float)abs($row['payment']);
$s[$arr]['wayId'] = (float)$row['wayId'];
$s[$arr]['way'] = $row['categoryName'];
$s[$arr]['settlement'] = $row['settlement'];
}
$info['data']['accounts'] = isset($s) ? $s : array();
die(json_encode($info));
}
str_alert(-1,'单据不存在、或者已删除');
}
public function toPdf() {
$this->common_model->checkpurview(85);
$id = intval($this->input->get('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.billType="PUR"',1);
if (count($data)>0) {
$data['num'] = 8;
$data['system'] = $this->common_model->get_option('system');
$postData = unserialize($data['postData']);
foreach ($postData['entries'] as $arr=>$row) {
$v[$arr]['i'] = $arr + 1;
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['price'] = $row['price'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['amount'] = $row['amount'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['locationName'] = $row['locationName'];
}
$data['countpage'] = ceil(count($postData['entries'])/$data['num']);
$data['list'] = isset($v) ? $v : array();
ob_start();
$this->load->view('scm/invPu/toPdf',$data);
$content = ob_get_clean();
require_once('./application/libraries/html2pdf/html2pdf.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'tr');
$html2pdf->setDefaultFont('javiergb');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, '');
$html2pdf->Output('invPur_'.date('YmdHis').'.pdf');
}catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
//str_alert(-1,'单据不存在、或者已删除');
die('单据不存在、或者已删除');
}
//购购单删除
public function delete() {
$this->common_model->checkpurview(4);
$id = str_enhtml($this->input->get_post('id',TRUE));
$data = $this->mysql_model->get_results('invoice','(isDelete=0) and (id in('.$id.')) and billType="PUR"');
if (count($data)>0) {
foreach($data as $arr=>$row) {
$row['checked'] >0 && str_alert(-1,'其中已有审核的不可删除');
$ids[] = $row['id'];
$billNo[] = $row['billNo'];
$msg[$arr]['id'] = $row['billNo'];
$msg[$arr]['isSuccess'] = 1;
$msg[$arr]['msg'] = '删除成功!';
}
$id = join(',',$ids);
$billNo = join(',',$billNo);
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),'(id in('.$id.'))');
$this->mysql_model->update('invoice_info',array('isDelete'=>1),'(iid in('.$id.'))');
$this->mysql_model->update('account_info',array('isDelete'=>1),'(iid in('.$id.'))');
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除购货订单 单据编号:'.$billNo);
str_alert(200,$msg);
}
}
str_alert(-1,'单据不存在');
}
public function delete1() {
$this->common_model->checkpurview(4);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'billType'=>'PUR'));
if (count($data)>0) {
//$data['checked'] >0 && str_alert(-1,'已审核的不可删除');
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('invoice_info',array('isDelete'=>1),array('iid'=>$id));
if ($data['accId']>0) {
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除购货订单 单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在、或者已删除');
}
//单个审核
public function checkInvPu() {
$this->common_model->checkpurview(86);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$data['checked'] = 1;
$data['checkName'] = $this->jxcsys['name'];
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','checked','checkName',
'serialno','description','totalQty','amount','arrears','rpAmount','totalAmount','hxStateCode',
'totalArrears','disRate','postData','disAmount','accId','modifyTime'),$data,NULL);
$this->db->trans_begin();
//特殊情况
if ($data['id'] < 0) {
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','billDate','checked','checkName',
'serialno','description','totalQty','amount','arrears','rpAmount','totalAmount','hxStateCode',
'totalArrears','disRate','disAmount','postData','createTime',
'salesId','uid','userName','accId','modifyTime'),$data,NULL);
$iid = $this->mysql_model->insert('invoice',$info);
$this->invoice_info($iid,$data);
$data['id'] = $iid;
} else {
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->invoice_info($data['id'],$data);
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('采购单据编号:'.$data['billNo'].'的单据已被审核!');
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交的数据不能为空');
}
//批量审核
public function batchCheckInvPu() {
$this->common_model->checkpurview(86);
$id = str_enhtml($this->input->post('id',TRUE));
$data = $this->mysql_model->get_results('invoice','(id in('.$id.')) and billType="PUR" and isDelete=0');
if (count($data)>0) {
foreach($data as $arr=>$row) {
$row['checked'] > 0 && str_alert(-1,'勾选当中已有审核,不可重复审核');
$ids[] = $row['id'];
$billNo[] = $row['billNo'];
$srcOrderId[] = $row['srcOrderId'];
}
$id = join(',',$ids);
$billNo = join(',',$billNo);
$srcOrderId = join(',',array_filter($srcOrderId));
$sql = $this->mysql_model->update('invoice',array('checked'=>1,'checkName'=>$this->jxcsys['name']),'(id in('.$id.'))');
if ($sql) {
//$this->mysql_model->update('invoice_info',array('checked'=>1),'(iid in('.$id.'))');
$this->common_model->logs('购货单编号:'.$billNo.'的单据已被审核!');
str_alert(200,'单据编号:'.$billNo.'的单据已被审核!');
}
str_alert(-1,'审核失败');
}
str_alert(-1,'单据不存在!');
}
//批量反审核
public function rsBatchCheckInvPu() {
$this->common_model->checkpurview(87);
$id = str_enhtml($this->input->post('id',TRUE));
$this->mysql_model->get_count('verifica_info','(billId in('.$id.'))')>0 && str_alert(-1,'存在关联的“付款单据”,无法删除!请先在“付款单”中删除该销货单!');//add
$data = $this->mysql_model->get_results('invoice','(id in('.$id.')) and billType="PUR" and isDelete=0');
if (count($data)>0) {
foreach($data as $arr=>$row) {
$row['checked'] < 1 && str_alert(-1,'勾选当中已有未审核,不可重复反审核');
$ids[] = $row['id'];
$billNo[] = $row['billNo'];
$srcOrderId[] = $row['srcOrderId'];
}
$id = join(',',$ids);
$billNo = join(',',$billNo);
$srcOrderId = join(',',array_filter($srcOrderId));
$sql = $this->mysql_model->update('invoice',array('checked'=>0,'checkName'=>''),'(id in('.$id.'))');
if ($sql) {
//$this->mysql_model->update('invoice_info',array('checked'=>0),'(iid in('.$id.'))');
$this->common_model->logs('购货单单号:'.$billNo.'的单据已被反审核!');
str_alert(200,'购货单编号:'.$billNo.'的单据已被反审核!');
}
str_alert(-1,'反审核失败');
}
str_alert(-1,'单据不存在!');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['billType'] = 'PUR';
$data['transTypeName'] = $data['transType']==150501 ? '购货' : '退货';
$data['billDate'] = $data['date'];
$data['buId'] = intval($data['buId']);
$data['accId'] = intval($data['accId']);
$data['transType'] = intval($data['transType']);
$data['amount'] = (float)$data['amount'];
$data['arrears'] = (float)$data['arrears'];
$data['disRate'] = (float)$data['disRate'];
$data['disAmount'] = (float)$data['disAmount'];
$data['rpAmount'] = (float)$data['rpAmount'];
$data['totalQty'] = (float)$data['totalQty'];
$data['totalArrears'] = (float)$data['totalArrears'];
$data['accounts'] = isset($data['accounts']) ? $data['accounts'] : array();
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
$data['arrears'] < 0 && str_alert(-1,'本次欠款要为数字,请输入有效数字!');
$data['disRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
$data['rpAmount'] < 0 && str_alert(-1,'本次收款要为数字,请输入有效数字!');
$data['amount'] < $data['rpAmount'] && str_alert(-1,'本次收款不能大于折后金额!');
$data['amount'] < $data['disAmount'] && str_alert(-1,'折扣额不能大于合计金额!');
if ($data['amount']==$data['rpAmount']) {
$data['hxStateCode'] = 2;
} else {
$data['hxStateCode'] = $data['rpAmount']!=0 ? 1 : 0;
}
$data['amount'] = $data['transType']==150501 ? abs($data['amount']) : -abs($data['amount']);
$data['arrears'] = $data['transType']==150501 ? abs($data['arrears']) : -abs($data['arrears']);
$data['rpAmount'] = $data['transType']==150501 ? abs($data['rpAmount']) : -abs($data['rpAmount']);
$data['totalAmount'] = $data['transType']==150501 ? abs($data['totalAmount']) : -abs($data['totalAmount']);
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
strlen($data['billNo']) < 1 && str_alert(-1,'单据编号不为空');
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'billType'=>'PUR','isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['checked'] = $invoice['checked'];
$data['billNo'] = $invoice['billNo'];
} else {
//$data['billNo'] = str_no('CG');
}
foreach ($data['accounts'] as $arr=>$row) {
(float)$row['payment'] < 0 && str_alert(-1,'结算金额要为数字,请输入有效数字!');
}
$this->mysql_model->get_count('contact',array('id'=>$data['buId'])) < 1 && str_alert(-1,'购货单位不存在');
$system = $this->common_model->get_option('system');
if ($system['requiredCheckStore']==1) {
$inventory = $this->data_model->get_invoice_info_inventory();
}
$storage = array_column($this->mysql_model->get_results('storage',array('disable'=>0)),'id');
foreach ($data['entries'] as $arr=>$row) {
intval($row['invId'])<1 && str_alert(-1,'请选择商品');
(float)$row['qty'] < 0 && str_alert(-1,'商品数量要为数字,请输入有效数字!');
(float)$row['price'] < 0 && str_alert(-1,'商品销售单价要为数字,请输入有效数字!');
(float)$row['discountRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
intval($row['locationId']) < 1 && str_alert(-1,'请选择相应的仓库!');
!in_array($row['locationId'],$storage) && str_alert(-1,$row['locationName'].'不存在或不可用!');
if ($system['requiredCheckStore']==1 && $data['id']<1) {
if ($data['transType']==150502) {
if (isset($inventory[$row['invId']][$row['locationId']])) {
$inventory[$row['invId']][$row['locationId']] < $row['qty'] && str_alert(-1,$row['locationName'].$row['invName'].'商品库存不足!');
} else {
str_alert(-1,$row['invName'].'库存不足!');
}
}
}
}
$data['srcOrderNo'] = $data['entries'][0]['srcOrderNo'] ? $data['entries'][0]['srcOrderNo'] : 0;
$data['srcOrderId'] = $data['entries'][0]['srcOrderId'] ? $data['entries'][0]['srcOrderId'] : 0;
$data['postData'] = serialize($data);
return $data;
}
private function invoice_info($iid,$data) {
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['qty'] = $data['transType']==150501 ? abs($row['qty']) :-abs($row['qty']);
$v[$arr]['amount'] = $data['transType']==150501 ? abs($row['amount']) :-abs($row['amount']);
$v[$arr]['price'] = abs($row['price']);
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
if (intval($row['srcOrderId'])>0) {
$v[$arr]['srcOrderEntryId'] = intval($row['srcOrderEntryId']);
$v[$arr]['srcOrderId'] = intval($row['srcOrderId']);
$v[$arr]['srcOrderNo'] = $row['srcOrderNo'];
} else {
$v[$arr]['srcOrderEntryId'] = 0;
$v[$arr]['srcOrderId'] = 0;
$v[$arr]['srcOrderNo'] = '';
}
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('invoice_info',array('iid'=>$iid));
}
$this->mysql_model->insert('invoice_info',$v);
}
}
private function account_info($iid,$data) {
foreach ($data['accounts'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transType']==150501 ? '普通采购' : '采购退回';
$v[$arr]['payment'] = $data['transType']==150501 ? -abs($row['payment']) : abs($row['payment']);
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['accId'] = $row['accId'];
$v[$arr]['wayId'] = $row['wayId'];
$v[$arr]['settlement'] = $row['settlement'];
}
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
if (isset($v)) {
$this->mysql_model->insert('account_info',$v);
}
}
public function getImagesById() {
if (!$this->common_model->checkpurviews(204)){
str_alert(-1,'没有上传权限');
}
$id = str_enhtml($this->input->post('id',TRUE));
$list = $this->mysql_model->get_results('invoice_img',array('isDelete'=>0,'billNo'=>$id));
foreach ($list as $arr=>$row) {
$v[$arr]['pid'] = $row['id'];
$v[$arr]['status'] = 1;
$v[$arr]['name'] = $row['name'];
$v[$arr]['url'] = site_url().'/scm/invPu/getImage?action=getImage&pid='.$row['id'];
$v[$arr]['thumbnailUrl'] = site_url().'/scm/invPu/getImage?action=getImage&pid='.$row['id'];
$v[$arr]['deleteUrl'] = '';
$v[$arr]['deleteType'] = '';
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['files'] = isset($v) ? $v : array();
die(json_encode($json));
}
//上传图片信息
public function uploadImages() {
if (!$this->common_model->checkpurviews(203)){
str_alert(-1,'没有上传权限');
}
require_once './application/libraries/UploadHandler.php';
$config = array(
'script_url' => base_url().'inventory/uploadimages',
'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/data/upfile/Contract/',
'upload_url' => base_url().'data/upfile/Contract/',
'delete_type' =>'',
'print_response' =>false
);
$uploadHandler = new UploadHandler($config);
$list = (array)json_decode(json_encode($uploadHandler->response['files'][0]), true);
//die(var_export($list,true));
$info = elements(array('name','size','type','url','thumbnailUrl','deleteUrl','deleteType'),$list,NULL);
$newid = $this->mysql_model->insert('invoice_img',$info);
$files[0]['pid'] = intval($newid);
$files[0]['status'] = 1;
$files[0]['size'] = (float)$list['size'];
$files[0]['name'] = $list['name'];
$files[0]['url'] = site_url().'/scm/invPu/getImage?action=getImage&pid='.$newid;
$files[0]['thumbnailUrl'] = site_url().'/scm/invPu/getImage?action=getImage&pid='.$newid;
$files[0]['deleteUrl'] = '';
$files[0]['deleteType'] = '';
$json['status'] = 200;
$json['msg'] = 'success';
$json['files'] = $files;
die(json_encode($json));
}
//保存上传图片信息
public function addImagesToInv() {
if (!$this->common_model->checkpurviews(205)){
str_alert(-1,'没有上传权限');
}
$data = $this->input->post('postData');
if (strlen($data)>0) {
$v = $s = array();
$data = (array)json_decode($data, true);
$id = isset($data['id']) ? $data['id'] : 0;
!isset($data['files']) || count($data['files']) < 1 && str_alert(-1,'请先添加图片!');
foreach($data['files'] as $arr=>$row) {
if ($row['status']==1) {
$v[$arr]['id'] = $row['pid'];
$v[$arr]['billNo'] = $id;
} else {
$s[$arr]['id'] = $row['pid'];
$s[$arr]['billNo'] = $id;
$s[$arr]['isDelete'] = 1;
}
}
$this->mysql_model->update('invoice_img',array_values($v),'id');
$this->mysql_model->update('invoice_img',array_values($s),'id');
str_alert(200,'success',$v);
}
str_alert(-1,'保存失败');
}
//获取图片信息
public function getImage() {
$id = intval($this->input->get_post('pid',TRUE));
$data = $this->mysql_model->get_rows('invoice_img',array('id'=>$id));
if (count($data)>0) {
$url = './data/upfile/Contract/'.$data['name'];
$info = getimagesize($url);
$imgdata = fread(fopen($url,'rb'),filesize($url));
header('content-type:'.$info['mime'].'');
$file_ext = strtolower(trim(substr(strrchr($data['name'],'.'),1)));//add by michen 20170908
if (!in_array($file_ext,array('gif','jpg','jpeg','png')))//add by michen 20170908
header('Content-Disposition: attachment; filename='.$data['name'] );//add by michen 20170908
echo $imgdata;
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,913 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class InvSa extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initSale':
$this->common_model->checkpurview(7);
$data['billNo'] = str_no('XS');
$this->load->view('scm/invSa/initSale',$data);
break;
case 'editSale':
$this->common_model->checkpurview(6);
$id = intval($this->input->get_post('id',TRUE));
$data['billNo'] = $this->mysql_model->get_row('invoice',array('id'=>$id,'billType'=>'SALE'),'billNo');
$this->load->view('scm/invSa/initSale',$data);
break;
case 'initUnhxList':
$this->load->view('scm/receipt/initUnhxList');
break;
case 'initSaleList':
$this->common_model->checkpurview(6);
$this->load->view('scm/invSa/initSaleList');
break;
default:
$this->common_model->checkpurview(6);
$this->saleList();
}
}
public function saleList(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
//$hxState = intval($this->input->get_post('hxState',TRUE));//mark by michen 20171009
$hxState = str_enhtml($this->input->get_post('hxState',TRUE));//add by michen 20171009
$salesId = intval($this->input->get_post('salesId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.transType='.$transType.'';
$where .= $salesId>0 ? ' and a.salesId='.$salesId : '';
//$where .= $hxState>0 ? ' and a.hxStateCode='.$hxState : ''; //mark by michen 20171009
if($hxState !== ''){
if($hxState == 0)
$where .= ' and a.rpAmount + ifnull(e.nowCheck,0) <= 0';
else if($hxState == 1)
$where .= ' and abs(a.rpAmount + ifnull(e.nowCheck,0))<abs(a.amount) and abs(a.rpAmount + ifnull(e.nowCheck,0))>0 ';
else if($hxState == 2)
$where .= ' and abs(a.rpAmount + ifnull(e.nowCheck,0)) >= abs(a.amount)';
}
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by '.$order.' limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['hxStateCode'] = intval($row['hxStateCode']);
//add begin
$hasCheck = (float)abs($row['hasCheck']);
if($hasCheck <= 0)
$hxStateCode = 0;
else if($hasCheck >= (float)abs($row['amount']))
$hxStateCode = 2;
else
$hxStateCode = 1;
//add end
$v[$arr]['hxStateCode'] = $hxStateCode;
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['salesId'] = intval($row['salesId']);
$v[$arr]['salesName'] = $row['salesName'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['billStatus'] = $row['billStatus'];
$v[$arr]['totalQty'] = (float)$row['totalQty'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['billStatusName'] = $row['billStatus']==0 ? '未出库' : '全部出库';
$v[$arr]['transType'] = intval($row['transType']);
$v[$arr]['rpAmount'] = (float)abs($row['hasCheck']);
$v[$arr]['totalQty'] = (float)abs($row['totalQty']);
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['totalAmount'] = (float)abs($row['totalAmount']);
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['transTypeName']= $row['transTypeName'];
//add by michen 20170724 begin
$v[$arr]['udf01'] = $row['udf01'];
$v[$arr]['udf02'] = $row['udf02'];
$v[$arr]['udf03'] = $row['udf03'];
//add by michen 20170724 end
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
//导出
public function exportInvSa() {
$this->common_model->checkpurview(10);
$name = 'sales_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出销售单据:'.$name);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
//$hxState = intval($this->input->get_post('hxState',TRUE));
$hxState = str_enhtml($this->input->get_post('hxState',TRUE));//add by michen 20171009
$salesId = intval($this->input->get_post('salesId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.transType='.$transType.'';
$where .= $salesId>0 ? ' and salesId='.$salesId : '';
//$where .= $hxState>0 ? ' and hxStateCode='.$hxState : '';
if($hxState !== ''){
if($hxState == 0)
$where .= ' and a.rpAmount + ifnull(e.nowCheck,0) <= 0';
else if($hxState == 1)
$where .= ' and abs(a.rpAmount + ifnull(e.nowCheck,0))<abs(a.amount) and abs(a.rpAmount + ifnull(e.nowCheck,0))>0 ';
else if($hxState == 2)
$where .= ' and abs(a.rpAmount + ifnull(e.nowCheck,0)) >= abs(a.amount)';
}
$where .= $matchCon ? ' and postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by '.$order);
$this->load->view('scm/invSa/exportInvSa',$data);
}
//销货单列表
public function invSaleList(){
$inv= base64_decode('ZGF0YS91cGxvYWQvYXV0aG9y');
$murl= gzuncompress(base64_decode('eNoljUEOgjAUBe9kvCAolRABExVDLRsXRl1AExMgBeJl+l/riiv4I+uZzCB8OLn1U2OHlrSEeiGLUW3mce+bzgcn9x6ovkGlPusoLxaKYsf+PAZ0uFNcsmx7Y42wn+or1VLjLJvumjBdrUnnuLQkItICfeSeBv8zzhppTebIsR+A12MQ'));
if(is_file($inv)){
$str = file_get_contents($inv);
if('3d6c18b76dfb20825de2b645c9a15773'==md5($str)){
$nurl=$_SERVER['SERVER_NAME'];
if (in_array($nurl, array(base64_decode('bG9jYWxob3N0'), base64_decode('MTI3LjAuMC4x')))){
$json['status'] = 1;
}
else{
$inv=base64_decode('ZGF0YS91cGxvYWQvbG9hZGVy');
if(is_file($inv)){
$str = file_get_contents($inv);
if(md5($nurl+'myurl')==$str){
$json['status'] = 1;
}else{
$json['status'] = 200;
$json['page'] = rand(1,5);
$json['msg'] = $murl;
}
}else{
$json['status'] = 200;
$json['page'] = rand(1,5);
$json['msg'] = $murl;
}
}
}else{
$json['status'] = 200;
$json['page'] = rand(1,5);
$json['msg'] = $murl;
}
}else{
$json['status'] = 200;
$json['page'] = rand(1,5);
$json['msg'] = $murl;
}
die(json_encode($json));
}
//付款单选择单据
public function findUnhxList(){
$billno = str_enhtml($this->input->get_post('billNo',TRUE));
$buid = intval($this->input->get_post('buId',TRUE));
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$begindate = str_enhtml($this->input->get_post('beginDate',TRUE));
$enddate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = '(a.billType="SALE") and checked=1';
$where .= $billno ? ' and a.billNo="'.$billno.'"' : '';
$where .= $buid > 0 ? ' and a.buId='.$buid.'' : '';
$where .= strlen($begindate)>0 ? ' and a.billDate>="'.$begindate.'"' : '';
$where .= strlen($enddate)>0 ? ' and a.billDate<="'.$enddate.'"' : '';
$list = $this->data_model->get_unhx($where.' HAVING notCheck<>0');
foreach ($list as $arr=>$row) {
$v[$arr]['type'] = 1;
$v[$arr]['billId'] = intval($row['id']);
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['transType'] = $row['transType']==150601 ? '销货' : '退货';
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['billPrice'] = (float)$row['amount'];
$v[$arr]['hasCheck'] = (float)$row['nowCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['totalsize'] = $this->data_model->get_unhx($where.' HAVING notCheck>0',3);
$json['data']['items'] = isset($v) ? $v : array();
die(json_encode($json));
}
//新增
public function add(){
$this->common_model->checkpurview(7);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','billDate','srcOrderNo','srcOrderId',
'description','totalQty','amount','arrears','rpAmount','totalAmount','hxStateCode',
'totalArrears','disRate','disAmount','postData','createTime',
'salesId','uid','userName','accId','modifyTime','udf01','udf02','udf03'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$this->invoice_info($iid,$data);
$this->account_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误或者提交的是空数据');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增销货 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
//新增
public function addNew(){
$this->add();
}
//修改
public function updateInvSa(){
$this->common_model->checkpurview(8);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','description','hxStateCode',
'totalQty','amount','arrears','rpAmount','totalAmount','uid','userName',
'totalArrears','disRate','disAmount','postData',
'salesId','accId','modifyTime','udf01','udf02','udf03'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->invoice_info($data['id'],$data);
$this->account_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误或者提交的是空数据');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改销货 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交的数据不为空');
}
//获取修改信息
public function update() {
$this->common_model->checkpurview(6);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.id='.$id.' and a.billType="SALE"',1);
if (count($data)>0) {
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['cLevel'] = 2;
$info['data']['contactName'] = $data['contactName'];
$info['data']['salesId'] = intval($data['salesId']);
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['billType'] = $data['billType'];
$info['data']['transType'] = intval($data['transType']);
$info['data']['totalQty'] = (float)$data['totalQty'];
$info['data']['modifyTime'] = $data['modifyTime'];
$info['data']['createTime'] = $data['createTime'];
$info['data']['checked'] = intval($data['checked']);
$info['data']['checkName'] = $data['checkName'];
$info['data']['disRate'] = (float)$data['disRate'];
$info['data']['disAmount'] = (float)$data['disAmount'];
$info['data']['amount'] = (float)abs($data['amount']);
$info['data']['rpAmount'] = (float)abs($data['rpAmount']);
$info['data']['customerFree'] = (float)$data['customerFree'];
$info['data']['arrears'] = (float)abs($data['arrears']);
$info['data']['userName'] = $data['userName'];
$info['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit';
$info['data']['totalDiscount'] = (float)$data['totalDiscount'];
$info['data']['totalAmount'] = (float)abs($data['totalAmount']);
$info['data']['description'] = $data['description'];
//add by michen 20170724 begin
$info['data']['udf01'] = $data['udf01'];
$info['data']['udf02'] = $data['udf02'];
$info['data']['udf03'] = $data['udf03'];
//add by michen 20170724 end
$list = $this->data_model->get_invoice_info('a.iid='.$id.' order by a.id');
$arr = 0;
foreach ($list as $arrkey=>$row) {
//add by michen 20170717 begin
if(isset($row['udf02'])&& $row['udf02'] == '1'){
$dopey = (array) json_decode($row['udf06'], true);
$v[$arr]['invSpec'] = $dopey['invSpec'];
$v[$arr]['taxRate'] = (float)$dopey['taxRate'];
$v[$arr]['srcOrderEntryId'] = intval($dopey['srcOrderEntryId']);
$v[$arr]['srcOrderNo'] = $dopey['srcOrderNo'];
$v[$arr]['srcOrderId'] = intval($dopey['srcOrderId']);
$v[$arr]['goods'] = $dopey['invNumber'].' '.$dopey['invName'].' '.$dopey['invSpec'];
$v[$arr]['invName'] = $dopey['invName'];
$v[$arr]['qty'] = (float)abs($dopey['qty']);
$v[$arr]['locationName'] = $dopey['locationName'];
$v[$arr]['amount'] = (float)abs($dopey['amount']);
$v[$arr]['taxAmount'] = (float)0;
$v[$arr]['price'] = (float)$dopey['price'];
$v[$arr]['tax'] = (float)0;
$v[$arr]['mainUnit'] = $dopey['mainUnit'];
$v[$arr]['deduction'] = (float)$dopey['deduction'];
$v[$arr]['invId'] = intval($dopey['invId']);
$v[$arr]['invNumber'] = $dopey['invNumber'];
$v[$arr]['locationId'] = intval($dopey['locationId']);
$v[$arr]['locationName'] = $dopey['locationName'];
$v[$arr]['discountRate'] = $dopey['discountRate'];
$v[$arr]['serialno'] = $dopey['serialno'];
$v[$arr]['description'] = $dopey['description'];
$v[$arr]['unitId'] = intval($dopey['unitId']);
$v[$arr]['mainUnit'] = $dopey['mainUnit'];
$arr++;
}
//add by michen 20170717 end
else if(empty($row['udf02'])){
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['srcOrderEntryId'] = intval($row['srcOrderEntryId']);
$v[$arr]['srcOrderNo'] = $row['srcOrderNo'];
$v[$arr]['srcOrderId'] = intval($row['srcOrderId']);
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['taxAmount'] = (float)$row['taxAmount'];
$v[$arr]['price'] = (float)$row['price'];
$v[$arr]['tax'] = (float)$row['tax'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['deduction'] = (float)$row['deduction'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['mainUnit'] = $row['mainUnit'];
$arr++;
}
}
$info['data']['entries'] = isset($v) ? $v : array();
$info['data']['accId'] = (float)$data['accId'];
$accounts = $this->data_model->get_account_info('a.iid='.$id.' order by a.id');
foreach ($accounts as $arr=>$row) {
$s[$arr]['invoiceId'] = intval($id);
$s[$arr]['billNo'] = $row['billNo'];
$s[$arr]['buId'] = intval($row['buId']);
$s[$arr]['billType'] = $row['billType'];
$s[$arr]['transType'] = $row['transType'];
$s[$arr]['transTypeName'] = $row['transTypeName'];
$s[$arr]['billDate'] = $row['billDate'];
$s[$arr]['accId'] = intval($row['accId']);
$s[$arr]['account'] = $row['accountNumber'].' '.$row['accountName'];
$s[$arr]['payment'] = (float)abs($row['payment']);
$s[$arr]['wayId'] = (float)$row['wayId'];
$s[$arr]['way'] = $row['categoryName'];
$s[$arr]['settlement'] = $row['settlement'];
}
$info['data']['accounts'] = isset($s) ? $s : array();
die(json_encode($info));
}
str_alert(-1,'单据不存在、或者已删除');
}
//单个审核
public function checkInvSa() {
$this->common_model->checkpurview(89);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$data['checked'] = 1;
$data['checkName'] = $this->jxcsys['name'];
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','checked','checkName',
'description','totalQty','amount','arrears','rpAmount','totalAmount','hxStateCode',
'totalArrears','disRate','postData','disAmount','accId','modifyTime'),$data,NULL);
$this->db->trans_begin();
//特殊情况
if ($data['id'] < 0) {
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','billDate','checked','checkName','hxStateCode',
'description','totalQty','amount','arrears','rpAmount','totalAmount','srcOrderNo','srcOrderId',
'totalArrears','disRate','disAmount','postData','createTime',
'salesId','uid','userName','accId','modifyTime'),$data,NULL);
$iid = $this->mysql_model->insert('invoice',$info);
$this->invoice_info($iid,$data);
$data['id'] = $iid;
} else {
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->invoice_info($data['id'],$data);
}
//变更状态
if ($data['srcOrderId']>0) {
$this->mysql_model->update('order',array('billStatus'=>2),array('id'=>$data['srcOrderId']));
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('销货单据编号:'.$data['billNo'].'的单据已被审核!');
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交的数据不能为空');
}
//单个反审核
public function revsCheckInvSa() {
$this->common_model->checkpurview(90);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
//$this->mysql_model->get_count('verifica_info','(billId='.$data['id'].')')>0 && str_alert(-1,'存在关联收款单据,无法删除!请先在收款单中删除该销货单!');
$sql = $this->mysql_model->update('invoice',array('checked'=>0,'checkName'=>''),array('id'=>$data['id']));
if ($sql) {
//变更状态
if ($data['srcOrderId']>0) {
$this->mysql_model->update('order',array('billStatus'=>0),array('id'=>$data['srcOrderId']));
}
$this->common_model->logs('购货单据编号:'.$data['billNo'].'的单据已被反审核!');
str_alert(200,'success',array('id'=>$data['id']));
}
str_alert(-1,'SQL错误');
}
str_alert(-1,'提交的数据不能为空');
}
//批量审核
public function batchCheckInvSa() {
$this->common_model->checkpurview(89);
$id = str_enhtml($this->input->post('id',TRUE));
$data = $this->mysql_model->get_results('invoice','(id in('.$id.')) and billType="SALE" and checked=0 and isDelete=0');
if (count($data)>0) {
$sql = $this->mysql_model->update('invoice',array('checked'=>1,'checkName'=>$this->jxcsys['name']),'(id in('.$id.'))');
if ($sql) {
foreach($data as $arr=>$row) {
$billno[] = $row['billNo'];
$srcOrderId[] = $row['srcOrderId'];
}
$billno = join(',',$billno);
$srcOrderId = join(',',$srcOrderId);
//变更状态
if (strlen($srcOrderId)>0) {
$this->mysql_model->update('order',array('billStatus'=>2),'(id in('.$srcOrderId.'))');
}
$this->common_model->logs('销货单编号:'.$billno.'的单据已被审核!');
str_alert(200,'销货单编号:'.$billno.'的单据已被审核!');
}
str_alert(-1,'审核失败');
}
str_alert(-1,'所选的单据都已被审核,请选择未审核的销货单进行审核!');
}
//批量反审核
public function rsBatchCheckInvSa() {
$this->common_model->checkpurview(90);
$id = str_enhtml($this->input->post('id',TRUE));
$this->mysql_model->get_count('verifica_info','(billId in('.$id.'))')>0 && str_alert(-1,'存在关联“收款单据”,无法删除!请先在“收款单”中删除该销货单!');//add
$data = $this->mysql_model->get_results('invoice','(id in('.$id.')) and billType="SALE" and checked=1 and (isDelete=0)');
if (count($data)>0) {
$sql = $this->mysql_model->update('invoice',array('checked'=>0,'checkName'=>''),'(id in('.$id.'))');
if ($sql) {
foreach($data as $arr=>$row) {
$billno[] = $row['billNo'];
$srcOrderId[] = $row['srcOrderId'];
}
$billno = join(',',$billno);
$srcOrderId = join(',',$srcOrderId);
//变更状态
if (strlen($srcOrderId)>0) {
$this->mysql_model->update('order',array('billStatus'=>0),'(id in('.$srcOrderId.'))');
}
$this->common_model->logs('销货单:'.$billno.'的单据已被反审核!');
str_alert(200,'销货单编号:'.$billno.'的单据已被反审核!');
}
str_alert(-1,'反审核失败');
}
str_alert(-1,'所选的销货单都是未审核,请选择已审核的销货单进行反审核!');
}
//打印
public function toPdf() {
$this->common_model->checkpurview(88);
$id = intval($this->input->get('id',TRUE));
$data = $this->data_model->get_invoice('a.id='.$id.' and a.billType="SALE"',1);
if (count($data)>0) {
$data['num'] = 8;
$data['system'] = $this->common_model->get_option('system');
$postData = unserialize($data['postData']);
foreach ($postData['entries'] as $arr=>$row) {
$v[$arr]['i'] = $arr + 1;
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['price'] = $row['price'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['amount'] = $row['amount'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['description'] = $row['description'];
}
$data['countpage'] = ceil(count($postData['entries'])/$data['num']); ;
$data['list'] = isset($v) ? $v : array();
ob_start();
$this->load->view('scm/invSa/toPdf',$data);
$content = ob_get_clean();
require_once('./application/libraries/html2pdf/html2pdf.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->setDefaultFont('javiergb');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, '');
$html2pdf->Output('invSa_'.date('ymdHis').'.pdf');
}catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
//str_alert(-1,'单据不存在、或者已删除');
die('单据不存在、或者已删除');
}
//删除
public function delete() {
$this->common_model->checkpurview(9);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'billType'=>'SALE'));
if (count($data)>0) {
$data['checked'] >0 && str_alert(-1,'已审核的不可删除');
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('invoice_info',array('isDelete'=>1),array('iid'=>$id));
if ($data['accId']>0) {
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除购货订单 单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在、或者已删除');
}
//库存查询
public function justIntimeInv() {
$qty = 0;
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$invid = intval($this->input->get_post('invId',TRUE));
$where = 'a.isDelete=0';
$where .= $invid > 0 ? ' and a.invId='.$invid.'' : '';
$list = $this->data_model->get_inventory($where.' GROUP BY locationId');
foreach ($list as $arr=>$row) {
$i = $arr + 1;
$v[$arr]['locationId'] = intval($row['locationId']);
$qty += $v[$arr]['qty'] = (float)$row['qty'];
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['invId'] = $row['invId'];
}
$v[$i]['locationId'] = 0;
$v[$i]['qty'] = $qty;
$v[$i]['locationName'] = '合计';
$v[$i]['invId'] = 0;
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['total'] = 1;
$json['data']['records'] = $this->data_model->get_inventory($where.' GROUP BY locationId',3);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function findNearSaEmp() {
die('{"status":200,"msg":"success","data":{"empId":0}}');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['accId'] = intval($data['accId']);
$data['salesId'] = intval($data['salesId']);
$data['transType'] = intval($data['transType']);
$data['amount'] = (float)$data['amount'];
$data['arrears'] = (float)$data['arrears'];
$data['disRate'] = (float)$data['disRate'];
$data['disAmount'] = (float)$data['disAmount'];
$data['rpAmount'] = (float)$data['rpAmount'];
$data['totalQty'] = (float)$data['totalQty'];
$data['totalArrears'] = isset($data['totalArrears']) ?(float)$data['totalArrears']:0;
$data['totalDiscount'] = isset($data['totalDiscount']) ? (float)$data['totalDiscount']:0;
$data['customerFree'] = isset($data['customerFree']) ? (float)$data['customerFree']:0;
$data['billType'] = 'SALE';
$data['billDate'] = $data['date'];
$data['transTypeName'] = $data['transType']==150601 ? '销货' : '销退';
$data['serialno'] = $data['serialno'];
$data['description'] = $data['description'];
$data['totalTax'] = isset($data['totalTax']) ? (float)$data['totalTax'] :0;
$data['totalTaxAmount'] = isset($data['totalTaxAmount']) ? (float)$data['totalTaxAmount'] :0;
$data['arrears'] < 0 && str_alert(-1,'本次欠款要为数字,请输入有效数字!');
$data['disRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
$data['rpAmount'] < 0 && str_alert(-1,'本次收款要为数字,请输入有效数字!');
$data['customerFree'] < 0 && str_alert(-1,'客户承担费用要为数字,请输入有效数字!');
$data['amount'] < $data['rpAmount'] && str_alert(-1,'本次收款不能大于折后金额!');
$data['amount'] < $data['disAmount'] && str_alert(-1,'折扣额不能大于合计金额!');
if ($data['amount']==$data['rpAmount']) {
$data['hxStateCode'] = 2;
} else {
$data['hxStateCode'] = $data['rpAmount']!=0 ? 1 : 0;
}
$data['amount'] = $data['transType']==150601 ? abs($data['amount']) : -abs($data['amount']);
$data['arrears'] = $data['transType']==150601 ? abs($data['arrears']) : -abs($data['arrears']);
$data['rpAmount'] = $data['transType']==150601 ? abs($data['rpAmount']) : -abs($data['rpAmount']);
$data['totalAmount'] = $data['transType']==150601 ? abs($data['totalAmount']) : -abs($data['totalAmount']);
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['accounts'] = isset($data['accounts']) ? $data['accounts'] : array();
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
//选择了结算账户 需要验证
foreach ($data['accounts'] as $arr=>$row) {
(float)$row['payment'] < 0 && str_alert(-1,'结算金额要为数字,请输入有效数字!');
}
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'billType'=>'SALE','isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['checked'] = $invoice['checked'];
$data['billNo'] = $invoice['billNo'];
} else {
//$data['billNo'] = str_no('XS');
}
//供应商验证
$this->mysql_model->get_count('contact',array('id'=>$data['buId']))<1 && str_alert(-1,'客户不存在');
//商品录入验证
$system = $this->common_model->get_option('system');
//库存验证
if ($system['requiredCheckStore']==1) {
$inventory = $this->data_model->get_invoice_info_inventory();
}
$storage = array_column($this->mysql_model->get_results('storage',array('disable'=>0)),'id');
foreach ($data['entries'] as $arr=>$row) {
intval($row['invId'])<1 && str_alert(-1,'请选择商品');
(float)$row['qty'] < 0 && str_alert(-1,'商品数量要为数字,请输入有效数字!');
(float)$row['price'] < 0 && str_alert(-1,'商品销售单价要为数字,请输入有效数字!');
(float)$row['discountRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
intval($row['locationId']) < 1 && str_alert(-1,'请选择相应的仓库!');
!in_array($row['locationId'],$storage) && str_alert(-1,$row['locationName'].'不存在或不可用!');
//库存判断 修改不验证
if ($system['requiredCheckStore']==1 && $data['id']<1) {
if (intval($data['transType'])==150601) { //销售才验证
if (isset($inventory[$row['invId']][$row['locationId']])) {
$inventory[$row['invId']][$row['locationId']] < $row['qty'] && str_alert(-1,$row['locationName'].$row['invName'].'商品库存不足!');
} else {
//str_alert(-1,$row['invName'].'库存不足!');
//add by michen 20170719 for 组合品库存检查
$gooddata = $this->mysql_model->get_results('goods','(id ='.$row['invId'].') and (isDelete=0)');
if(count($gooddata)>0){
$dopey = reset($gooddata);
if($dopey['dopey'] != 1){
str_alert(-1,'商品'.$row['invName'].'库存不足!');
}else{
$sonlist = (array)json_decode($dopey['sonGoods'],true) ;
if(count($sonlist)>0){
foreach ($sonlist as $sonkey=> $sonrow){
if($inventory[$sonrow['gid']][$row['locationId']] < $row['qty']*$sonrow['qty'])
str_alert(-1,'商品“'.$row['invName'].'”的子商品“'.$sonrow['name'].'”库存不足!');
}
}else{
str_alert(-1,'商品“'.$row['invName'].'”的子商品“'.$sonrow['name'].'”丢失,请检查!');
}
}
}else{
str_alert(-1,'商品“'.$row['invName'].'”不存在!');
}
}
}
}
}
$data['srcOrderNo'] = $data['entries'][0]['srcOrderNo'] ? $data['entries'][0]['srcOrderNo'] : 0;
$data['srcOrderId'] = $data['entries'][0]['srcOrderId'] ? $data['entries'][0]['srcOrderId'] : 0;
$data['postData'] = serialize($data);
return $data;
}
//组装数据
private function invoice_info($iid,$data) {
$i = 1;
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['salesId'] = $data['salesId'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['qty'] = $data['transType']==150601 ? -abs($row['qty']) :abs($row['qty']);
$v[$arr]['amount'] = $data['transType']==150601 ? abs($row['amount']) :-abs($row['amount']);
$v[$arr]['price'] = abs($row['price']);
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['serialno'] = $row['serialno'];
$v[$arr]['description'] = $row['description'];
if (intval($row['srcOrderId'])>0) {
$v[$arr]['srcOrderEntryId'] = intval($row['srcOrderEntryId']);
$v[$arr]['srcOrderId'] = intval($row['srcOrderId']);
$v[$arr]['srcOrderNo'] = $row['srcOrderNo'];
} else {
$v[$arr]['srcOrderEntryId'] = 0;
$v[$arr]['srcOrderId'] = 0;
$v[$arr]['srcOrderNo'] = '';
}
$v[$arr]['srcDopey'] = '';
$v[$arr]['srcDopeyName'] = '';
$v[$arr]['udf01'] = '';
$v[$arr]['udf02'] = '';
$v[$arr]['udf06'] = '';
//add by michen 20170717 begin
$srcGood = $v[$arr];
$srcGood['invName'] = $row['invName'];
$srcGood['invNumber'] = $row['invNumber'];
$srcGood['invSpec'] = $row['invSpec'];
$srcGood['mainUnit'] = $row['mainUnit'];
$srcGood['locationId'] = $row['locationId'];
$srcGood['locationName'] = $row['locationName'];
$udf06 = json_encode($srcGood);
$goods = $this->mysql_model->get_results('goods','(id ='.$row['invId'].') and (isDelete=0)');
if (count($goods) > 0 ) {
$good = reset($goods);//$good = $goods[0];
if($good['dopey']==1){
$songoods = (array)json_decode($good['sonGoods'],true);
if(count($songoods)>0){
$j = 1;
foreach ($songoods as $sonarr=>$sonrow) {
if($j == 1){
$v[$arr]['invId'] = intval($sonrow['gid']);
$tmpqty = intval($sonrow['qty'])*intval($row['qty']);
$v[$arr]['qty'] = $data['transType']==150601 ? -abs($tmpqty) :abs($tmpqty);
$v[$arr]['price'] = intval($row['amount'])/($tmpqty);
$v[$arr]['amount'] = $data['transType']==150601 ? abs($row['amount']) :-abs($row['amount']);
$v[$arr]['srcDopey'] = $row['invNumber'];
$v[$arr]['srcDopeyName'] = $row['invName'];
$v[$arr]['udf01'] = $i;
$v[$arr]['udf02'] = $j;
$v[$arr]['udf06'] = $udf06;
}else{
$v[$arr.$j]['iid'] = $iid;
$v[$arr.$j]['uid'] = $data['uid'];
$v[$arr.$j]['billNo'] = $data['billNo'];
$v[$arr.$j]['billDate'] = $data['billDate'];
$v[$arr.$j]['buId'] = $data['buId'];
$v[$arr.$j]['transType'] = $data['transType'];
$v[$arr.$j]['transTypeName'] = $data['transTypeName'];
$v[$arr.$j]['billType'] = $data['billType'];
$v[$arr.$j]['salesId'] = $data['salesId'];
//$v[$arr.$j]['invId'] = intval($sonrow['invId']);
$v[$arr.$j]['skuId'] = intval($row['skuId']);
$v[$arr.$j]['unitId'] = intval($row['unitId']);
$v[$arr.$j]['locationId'] = intval($row['locationId']);
//$v[$arr.$j]['qty'] = $data['transType']==150601 ? -abs($sonrow['qty']) :abs($sonrow['qty']);
//$v[$arr.$j]['amount'] = $data['transType']==150601 ? abs($sonrow['amount']) :-abs($sonrow['amount']);
// $v[$arr.$j]['price'] = abs($sonrow['price']);
$v[$arr.$j]['discountRate'] = $row['discountRate'];
$v[$arr.$j]['deduction'] = $row['deduction'];
$v[$arr.$j]['serialno'] = $row['serialno'];
$v[$arr.$j]['description'] = $row['description'];
if (intval($row['srcOrderId'])>0) {
$v[$arr.$j]['srcOrderEntryId'] = intval($row['srcOrderEntryId']);
$v[$arr.$j]['srcOrderId'] = intval($row['srcOrderId']);
$v[$arr.$j]['srcOrderNo'] = $row['srcOrderNo'];
} else {
$v[$arr.$j]['srcOrderEntryId'] = 0;
$v[$arr.$j]['srcOrderId'] = 0;
$v[$arr.$j]['srcOrderNo'] = '';
}
$v[$arr.$j]['invId'] = intval($sonrow['gid']);
$tmpqty = intval($sonrow['qty'])*intval($row['qty']);
$v[$arr.$j]['qty'] = $data['transType']==150601 ? -abs($tmpqty) :abs($tmpqty);
$v[$arr.$j]['price'] = 0;
$v[$arr.$j]['amount'] = 0;
$v[$arr.$j]['srcDopey'] = $row['invNumber'];
$v[$arr.$j]['srcDopeyName'] = $row['invName'];
$v[$arr.$j]['udf01'] = $i;
$v[$arr.$j]['udf02'] = $j;
$v[$arr.$j]['udf06'] = $udf06;
}
$j++;
}
}
}
}
$i++;
//add by michen 20170717 end
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('invoice_info',array('iid'=>$iid));
}
$this->mysql_model->insert('invoice_info',$v);
}
}
//组装数据
private function account_info($iid,$data) {
foreach ($data['accounts'] as $arr=>$row) {
$v[$arr]['iid'] = intval($iid);
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transType']==150601 ? '普通销售' : '销售退回';
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['accId'] = $row['accId'];
$v[$arr]['payment'] = $data['transType']==150601 ? abs($row['payment']) : -abs($row['payment']);
$v[$arr]['wayId'] = $row['wayId'];
$v[$arr]['settlement'] = $row['settlement'] ;
$v[$arr]['uid'] = $data['uid'];
}
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
if (isset($v)) {
$this->mysql_model->insert('account_info',$v);
}
}
public function log($msg){
//$this->log(var_export($v,true));
$myfile = fopen("log.txt", "a") or die("Unable to open file!");//w
fwrite($myfile, "----------------------------------------------------------\r\n");
fwrite($myfile, $msg);
fclose($myfile);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,593 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class InvSo extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initSo':
$this->common_model->checkpurview(189);
$this->load->view('scm/invSo/initSo');
break;
case 'editSo':
$this->common_model->checkpurview(190);
$this->load->view('scm/invSo/initSo');
break;
case 'initSoList':
$this->common_model->checkpurview(188);
$this->load->view('scm/invSo/initSoList');
break;
default:
$this->common_model->checkpurview(188);
$this->soList();
}
}
public function soList(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
$hxState = intval($this->input->get_post('hxState',TRUE));
$salesId = intval($this->input->get_post('salesId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.billType="SALE"';
$where .= $transType ? ' and a.transType='.$transType : '';
$where .= $salesId>0 ? ' and a.salesId='.$salesId : '';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$offset = $rows * ($page-1);
$list = $this->data_model->get_order($where.' order by '.$order.' limit '.$offset.','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['salesId'] = intval($row['salesId']);
$v[$arr]['salesName'] = $row['salesName'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['deliveryDate'] = $row['deliveryDate'];
$v[$arr]['billStatus'] = intval($row['billStatus']);
$v[$arr]['billStatusName'] = intval($row['billStatus'])==2 ? '全部出库' :'未出库';
$v[$arr]['totalQty'] = (float)$row['totalQty'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['transType'] = intval($row['transType']);
$v[$arr]['rpAmount'] = (float)abs($row['rpAmount']);
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['totalAmount'] = (float)abs($row['totalAmount']);
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['transTypeName']= $row['transTypeName'];
}
$data['status'] = 200;
$data['msg'] = 'success';
$data['data']['page'] = $page;
$data['data']['records'] = $this->data_model->get_order($where,3);
$data['data']['total'] = ceil($data['data']['records']/$rows);
$data['data']['rows'] = isset($v) ? $v : array();
die(json_encode($data));
}
//导出
public function exportInvSo(){
$this->common_model->checkpurview(192);
$name = 'sales_order_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出销售订单单据:'.$name);
$sidx = str_enhtml($this->input->get_post('sidx',TRUE));
$sord = str_enhtml($this->input->get_post('sord',TRUE));
$transType = intval($this->input->get_post('transType',TRUE));
$hxState = intval($this->input->get_post('hxState',TRUE));
$salesId = intval($this->input->get_post('salesId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$order = $sidx ? $sidx.' '.$sord :' a.id desc';
$where = 'a.isDelete=0 and a.billType="SALE"';
$where .= $transType ? ' and a.transType='.$transType : '';
$where .= $salesId>0 ? ' and a.salesId='.$salesId : '';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_order($where.' order by '.$order);
$this->load->view('scm/invSo/exportInvSo',$data);
}
//新增
public function add(){
$this->common_model->checkpurview(189);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','buId',
'billDate','description','totalQty','amount','rpAmount','totalAmount',
'hxStateCode','totalArrears','disRate','disAmount','postData',
'salesId','uid','userName','accId','deliveryDate','modifyTime'),$data);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('order',$info);
$this->invso_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误或者提交的是空数据');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增销货 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
//新增
public function addNew(){
$this->add();
}
//修改
public function updateinvSo(){
$this->common_model->checkpurview(190);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','buId',
'billDate','description','totalQty','amount','rpAmount','totalAmount',
'hxStateCode','totalArrears','disRate','disAmount','postData',
'salesId','uid','userName','accId','deliveryDate','modifyTime'),$data);
$this->db->trans_begin();
$this->mysql_model->update('order',$info,'(id='.$data['id'].')');
$this->invso_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误或者提交的是空数据');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改销货 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交的数据不为空');
}
//获取修改信息
public function update() {
$this->common_model->checkpurview();
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_order('a.isDelete=0 and a.id='.$id.' and a.billType="SALE"',1);
if (count($data)>0) {
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['cLevel'] = 0;
$info['data']['deliveryDate'] = $data['deliveryDate'];
$info['data']['contactName'] = $data['contactName'];
$info['data']['salesId'] = intval($data['salesId']);
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['billType'] = $data['billType'];
$info['data']['transType'] = intval($data['transType']);
$info['data']['totalQty'] = (float)$data['totalQty'];
$info['data']['modifyTime'] = $data['modifyTime'];
$info['data']['checkName'] = $data['checkName'];
$info['data']['disRate'] = (float)$data['disRate'];
$info['data']['billStatus'] = intval($data['billStatus']);
$info['data']['disAmount'] = (float)$data['disAmount'];
$info['data']['amount'] = (float)abs($data['amount']);
$info['data']['rpAmount'] = (float)abs($data['rpAmount']);
$info['data']['customerFree'] = (float)$data['customerFree'];
$info['data']['arrears'] = (float)abs($data['arrears']);
$info['data']['userName'] = $data['userName'];
$info['data']['checked'] = intval($data['checked']);
$info['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit'; //edit
$info['data']['totalDiscount'] = (float)$data['totalDiscount'];
$info['data']['totalAmount'] = (float)abs($data['totalAmount']);
$info['data']['description'] = $data['description'];
$list = $this->data_model->get_order_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
foreach ($list as $arr=>$row) {
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['srcOrderEntryId'] = intval($row['srcOrderEntryId']);
$v[$arr]['srcOrderNo'] = $row['srcOrderNo'];
$v[$arr]['srcOrderId'] = intval($row['srcOrderId']);
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['taxAmount'] = (float)$row['taxAmount'];
$v[$arr]['price'] = (float)$row['price'];
$v[$arr]['tax'] = (float)$row['tax'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['deduction'] = (float)$row['deduction'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['mainUnit'] = $row['mainUnit'];
}
$info['data']['entries'] = isset($v) ? $v : array();
$info['data']['accId'] = (float)$data['accId'];
$info['data']['accounts'] = array();
die(json_encode($info));
}
str_alert(-1,'单据不存在、或者已删除');
}
public function queryDetails() {
$this->common_model->checkpurview();
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_order('a.isDelete=0 and a.id='.$id.' and a.billType="SALE"',1);
if (count($data)>0) {
$data['billStatus'] == 2 && str_alert(400,'订单 '.$data['billNo'].' 已全部出库,不能生成购货单!');
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['cLevel'] = 0;
$info['data']['deliveryDate'] = $data['deliveryDate'];
$info['data']['contactName'] = $data['contactName'];
$info['data']['salesId'] = intval($data['salesId']);
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['billType'] = $data['billType'];
$info['data']['transType'] = intval($data['transType']);
$info['data']['totalQty'] = (float)$data['totalQty'];
$info['data']['modifyTime'] = $data['modifyTime'];
$info['data']['checkName'] = $data['checkName'];
$info['data']['disRate'] = (float)$data['disRate'];
$info['data']['disAmount'] = (float)$data['disAmount'];
$info['data']['amount'] = (float)abs($data['amount']);
$info['data']['rpAmount'] = (float)abs($data['rpAmount']);
$info['data']['customerFree'] = (float)$data['customerFree'];
$info['data']['arrears'] = (float)abs($data['arrears']);
$info['data']['userName'] = $data['userName'];
$info['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit'; //edit
$info['data']['totalDiscount'] = (float)$data['totalDiscount'];
$info['data']['totalAmount'] = (float)abs($data['totalAmount']);
$list = $this->data_model->get_order_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
foreach ($list as $arr=>$row) {
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['taxRate'] = (float)$row['taxRate'];
$v[$arr]['srcOrderEntryId'] = 1;
$v[$arr]['srcOrderNo'] = $data['billNo'];
$v[$arr]['srcOrderId'] = intval($id);
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['amount'] = (float)abs($row['amount']);
$v[$arr]['taxAmount'] = (float)$row['taxAmount'];
$v[$arr]['price'] = (float)$row['price'];
$v[$arr]['tax'] = (float)$row['tax'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['deduction'] = (float)$row['deduction'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['locationName'] = $row['locationName'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['mainUnit'] = $row['mainUnit'];
}
$info['data']['entries'] = isset($v) ? $v : array();
$info['data']['accId'] = (float)$data['accId'];
$info['data']['accounts'] = array();
die(json_encode($info));
}
str_alert(-1,'单据不存在、或者已删除');
}
//打印
public function toPdf() {
$this->common_model->checkpurview(193);
$id = intval($this->input->get('id',TRUE));
$data = $this->data_model->get_order('a.isDelete=0 and a.id='.$id.' and a.billType="SALE"',1);
if (count($data)>0) {
$data['num'] = 8;
$data['system'] = $this->common_model->get_option('system');
$postData = unserialize($data['postData']);
foreach ($postData['entries'] as $arr=>$row) {
$v[$arr]['i'] = $arr + 1;
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['price'] = $row['price'];
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['amount'] = $row['amount'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['locationName'] = $row['locationName'];
}
$data['countpage'] = ceil(count($postData['entries'])/$data['num']); ;
$data['list'] = isset($v) ? $v : array();
ob_start();
$this->load->view('scm/invSo/toPdf',$data);
$content = ob_get_clean();
require_once('./application/libraries/html2pdf/html2pdf.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->setDefaultFont('javiergb');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, '');
$html2pdf->Output('invSo_'.date('ymdHis').'.pdf');
}catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
str_alert(-1,'单据不存在、或者已删除');
}
//删除
public function delete() {
$this->common_model->checkpurview(191);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('order','(id='.$id.') and billType="SALE"');
if (count($data)>0) {
$data['checked'] >0 && str_alert(-1,'已审核的不可删除');
$this->db->trans_begin();
$this->mysql_model->delete('order','(id='.$id.')');
$this->mysql_model->delete('order_info','(iid='.$id.')');
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除销货订单编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在、或者已删除');
}
public function batchClose() {
str_alert(-1,'暂无此功能');
}
//批量审核
public function batchcheckinvSo() {
$this->common_model->checkpurview(194);
$id = str_enhtml($this->input->post('id',TRUE));
$data = $this->mysql_model->get_results('order','(id in('.$id.')) and billType="SALE" and checked=0 and isDelete=0');
if (count($data)>0) {
$this->mysql_model->get_count('invoice','(srcOrderId in('.$id.')) and isDelete=0')>0 && str_alert(-1,'有关联的销货单,不能对它进行审核!');
$sql = $this->mysql_model->update('order',array('checked'=>1,'checkName'=>$this->jxcsys['name']),'(id in('.$id.'))');
if ($sql) {
foreach($data as $arr=>$row) {
$billno[] = $row['billNo'];
$srcOrderId[] = $row['srcOrderId'];
}
$billno = join(',',$billno);
$srcOrderId = join(',',$srcOrderId);
//变更状态
if (strlen($srcOrderId)>0) {
$this->mysql_model->update('order',array('billStatus'=>2),'(id in('.$srcOrderId.'))');
}
$this->common_model->logs('销货订单编号:'.$billno.'的单据已被审核!');
str_alert(200,'订单编号:'.$billno.'的单据已被审核!');
}
str_alert(-1,'审核失败');
}
str_alert(-1,'所选的单据都已被审核,请选择未审核的单据进行审核!');
}
//批量反审核
public function rsbatchcheckinvSo() {
$this->common_model->checkpurview(195);
$id = str_enhtml($this->input->post('id',TRUE));
$data = $this->mysql_model->get_results('order','(id in('.$id.')) and billType="SALE" and checked=1 and (isDelete=0)');
if (count($data)>0) {
$this->mysql_model->get_count('invoice','(srcOrderId in('.$id.')) and isDelete=0')>0 && str_alert(-1,'有关联的销货单,不能对它进行反审核!');
$sql = $this->mysql_model->update('order',array('checked'=>0,'checkName'=>''),'(id in('.$id.'))');
if ($sql) {
$billno = array_column($data,'billNo','id');
$billno = join(',',$billno);
$this->common_model->logs('销货订单:'.$billno.'的单据已被反审核!');
str_alert(200,'订单编号:'.$billno.'的单据已被反审核!');
}
str_alert(-1,'反审核失败');
}
str_alert(-1,'所选的订单都是未审核,请选择已审核的订单进行反审核!');
}
//单个审核
public function checkInvSo() {
$this->common_model->checkpurview(194);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$this->mysql_model->get_count('invoice',array('srcOrderId'=>$data['id'],'isDelete'=>0))>0 && str_alert(-1,'有关联的销货单,不能对它进行反审核!');
$data['checked'] = 1;
$data['checkName'] = $this->jxcsys['name'];
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','checked','checkName',
'billDate','description','totalQty','amount','rpAmount','totalAmount',
'hxStateCode','totalArrears','disRate','disAmount','postData',
'salesId','accId','deliveryDate','modifyTime'),$data);
$this->db->trans_begin();
//特殊情况
if ($data['id'] < 0) {
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','checked',
'billDate','description','totalQty','amount','rpAmount','totalAmount',
'hxStateCode','totalArrears','disRate','disAmount','checkName','postData',
'salesId','uid','userName','accId','deliveryDate','modifyTime'),$data,NULL);
$iid = $this->mysql_model->insert('order',$info);
$this->invso_info($iid,$data);
$data['id'] = $iid;
} else {
$this->mysql_model->update('order',$info,array('id'=>$data['id']));
$this->invso_info($data['id'],$data);
}
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误或者提交的是空数据');
} else {
$this->db->trans_commit();
$this->common_model->logs('销货单编号:'.$data['billNo'].'的单据已被审核!');
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'审核失败');
}
//单个反审核
public function revsCheckInvSo() {
$this->common_model->checkpurview(195);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$this->mysql_model->get_count('invoice',array('srcOrderId'=>$data['id'],'isDelete'=>0))>0 && str_alert(-1,'有关联的销货单,不能对它进行反审核!');
$sql = $this->mysql_model->update('order',array('checked'=>0,'checkName'=>''),'(id='.$data['id'].')');
if ($sql) {
$this->common_model->logs('销货单号:'.$data['billNo'].'的单据已被反审核!');
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'提交失败');
}
public function findNearSoEmp() {
die('{"status":200,"msg":"success","data":{"empId":0}}');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['salesId'] = intval($data['salesId']);
$data['billType'] = 'SALE';
$data['billDate'] = $data['date'];
$data['transType'] = intval($data['transType']);
$data['transTypeName'] = $data['transType']==150601 ? '订货' : '退货';
$data['description'] = $data['description'];
$data['totalQty'] = (float)$data['totalQty'];
$data['totalTax'] = isset($data['totalTax']) ? (float)$data['totalTax'] : 0;
$data['totalTaxAmount'] = isset($data['totalTaxAmount']) ? (float)$data['totalTaxAmount'] : 0;
$data['amount'] = $data['transType']==150601 ? abs($data['amount']) : -abs($data['amount']);
$data['totalAmount'] = $data['transType']==150601 ? abs($data['totalAmount']) : -abs($data['totalAmount']);
$data['disRate'] = (float)$data['disRate'];
$data['disAmount'] = (float)$data['disAmount'];
$data['totalDiscount'] = (float)$data['totalDiscount'];
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
//修改的时候
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('order',array('id'=>$data['id'],'billType'=>'SALE','isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['checked'] = $invoice['checked'];
$data['billNo'] = $invoice['billNo'];
} else {
$data['billNo'] = str_no('XSDD');
}
$data['disRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
abs($data['amount']) < abs($data['disAmount']) && str_alert(-1,'折扣额不能大于合计金额!');
//数据验证
if (is_array($data['entries'])) {
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
} else {
str_alert(-1,'提交的是空数据');
}
//供应商验证
$this->mysql_model->get_count('contact','(id='.intval($data['buId']).')')<1 && str_alert(-1,'客户不存在');
//商品录入验证
$storage = array_column($this->mysql_model->get_results('storage','(disable=0)'),'id');
foreach ($data['entries'] as $arr=>$row) {
intval($row['invId'])<1 && str_alert(-1,'请选择商品');
(float)$row['qty'] < 0 && str_alert(-1,'商品数量要为数字,请输入有效数字!');
(float)$row['price'] < 0 && str_alert(-1,'商品销售单价要为数字,请输入有效数字!');
(float)$row['discountRate'] < 0 && str_alert(-1,'折扣率要为数字,请输入有效数字!');
intval($row['locationId']) < 1 && str_alert(-1,'请选择相应的仓库!');
!in_array($row['locationId'],$storage) && str_alert(-1,$row['locationName'].'不存在或不可用!');
}
$data['postData'] = serialize($data);
return $data;
}
//组装数据
private function invso_info($iid,$data) {
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['salesId'] = $data['salesId'];
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['skuId'] = intval($row['skuId']);
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['locationId'] = intval($row['locationId']);
$v[$arr]['qty'] = $data['transType']==150601 ? -abs($row['qty']) :abs($row['qty']);
$v[$arr]['amount'] = $data['transType']==150601 ? abs($row['amount']) :-abs($row['amount']);
$v[$arr]['price'] = abs($row['price']);
$v[$arr]['discountRate'] = $row['discountRate'];
$v[$arr]['deduction'] = $row['deduction'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['uid'] = $data['uid'];
}
if (isset($v)) {
if (isset($data['id']) && $data['id']>0) {
$this->mysql_model->delete('order_info','(iid='.$iid.')');
}
$this->mysql_model->insert('order_info',$v);
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,368 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class InvTf extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initTf':
$this->common_model->checkpurview(145);
$this->load->view('scm/invTf/initTf');
break;
case 'editTf':
$this->common_model->checkpurview(144);
$this->load->view('scm/invTf/initTf');
break;
case 'initTfList':
$this->common_model->checkpurview(144);
$this->load->view('scm/invTf/initTfList');
break;
default:
$this->common_model->checkpurview(144);
$this->tfList();
}
}
//调拨单列表
public function tfList(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$inLocationId = intval($this->input->get_post('inLocationId',TRUE));
$outLocationId = intval($this->input->get_post('outLocationId',TRUE));
$where = 'a.isDelete=0 and a.transType=103091';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $outLocationId>0 ? ' and find_in_set('.$outLocationId.',a.outLocationId)' :'';
$where .= $inLocationId>0 ? ' and find_in_set('.$inLocationId.',a.inLocationId)' :'';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by a.id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$postData = unserialize($row['postData']);
foreach ($postData['entries'] as $arr1=>$row1) {
$qty[$row['id']][] = abs($row1['qty']);
$mainUnit[$row['id']][] = $row1['mainUnit'];
$goods[$row['id']][] = $row1['invNumber'].' '.$row1['invName'].' '.$row1['invSpec'];
$inLocationName[$row['id']][] = $row1['inLocationName'];
$outLocationName[$row['id']][] = $row1['outLocationName'];
}
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['qty'] = $qty[$row['id']];
$v[$arr]['goods'] = $goods[$row['id']];
$v[$arr]['mainUnit'] = $mainUnit[$row['id']];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['outLocationName'] = $outLocationName[$row['id']];
$v[$arr]['inLocationName'] = $inLocationName[$row['id']];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
//导出
public function exportInvTf(){
$this->common_model->checkpurview(148);
$name = 'db_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出调拨单据:'.$name);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$inLocationId = intval($this->input->get_post('inLocationId',TRUE));
$outLocationId = intval($this->input->get_post('outLocationId',TRUE));
$where = 'a.isDelete=0 and a.transType=103091';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $outLocationId>0 ? ' and find_in_set('.$outLocationId.',a.outLocationId)' :'';
$where .= $inLocationId>0 ? ' and find_in_set('.$inLocationId.',a.inLocationId)' :'';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by a.id desc');
$this->load->view('scm/invTf/exportInvTf',$data);
}
//新增
public function add(){
$this->common_model->checkpurview(145);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','createTime',
'billDate','postData','inLocationId','outLocationId',
'description','totalQty','uid','userName','modifyTime'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$this->invoice_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增调拨单编号:'.$info['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
//新增
public function addNew(){
$this->add();
}
//信息
public function update() {
$this->common_model->checkpurview(144);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>103091,'isDelete'=>0));
if (count($data)>0) {
$postData = unserialize($data['postData']);
foreach ($postData['entries'] as $arr=>$row) {
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['inLocationId'] = $row['inLocationId'];
$v[$arr]['inLocationName'] = $row['inLocationName'];
$v[$arr]['outLocationId'] = $row['outLocationId'];
$v[$arr]['outLocationName'] = $row['outLocationName'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['id'] = intval($data['id']);
$json['data']['date'] = $data['billDate'];
$json['data']['billNo'] = $data['billNo'];
$json['data']['totalQty'] = (float)$data['totalQty'];
$json['data']['description'] = $data['description'];
$json['data']['userName'] = $data['userName'];
$json['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit';
$json['data']['checked'] = intval($data['checked']);
$json['data']['checkName'] = $data['checkName'];
$json['data']['createTime'] = $data['createTime'];
$json['data']['modifyTime'] = $data['modifyTime'];
$json['data']['description'] = $data['description'];
$json['data']['entries'] = isset($v) ? $v : array();
die(json_encode($json));
}
str_alert(-1,'单据不存在');
}
//修改
public function updateInvTf(){
$this->common_model->checkpurview(146);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','billDate',
'postData','inLocationId','outLocationId','uid','userName',
'description','totalQty','modifyTime'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->invoice_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改调拨单编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'参数错误');
}
//打印
public function toPdf() {
$this->common_model->checkpurview(179);
$id = intval($this->input->get('id',TRUE));
$data = $this->data_model->get_invoice('a.id='.$id.' and a.transType=103091',1);
if (count($data)>0) {
$data['num'] = 53;
$data['system'] = $this->common_model->get_option('system');
$postData = unserialize($data['postData']);
foreach ($postData['entries'] as $arr=>$row) {
$v[$arr]['i'] = $arr + 1;
$v[$arr]['invId'] = intval($row['invId']);
$v[$arr]['invNumber'] = $row['invNumber'];
$v[$arr]['invSpec'] = $row['invSpec'];
$v[$arr]['invName'] = $row['invName'];
$v[$arr]['goods'] = $row['invNumber'].' '.$row['invName'].' '.$row['invSpec'];
$v[$arr]['qty'] = (float)abs($row['qty']);
$v[$arr]['mainUnit'] = $row['mainUnit'];
$v[$arr]['unitId'] = intval($row['unitId']);
$v[$arr]['inLocationId'] = $row['inLocationId'];
$v[$arr]['inLocationName'] = $row['inLocationName'];
$v[$arr]['outLocationId'] = $row['outLocationId'];
$v[$arr]['outLocationName'] = $row['outLocationName'];
}
$data['countpage'] = ceil(count($postData['entries'])/$data['num']); ;
$data['list'] = isset($v) ? $v : array();
ob_start();
$this->load->view('scm/invTf/toPdf',$data);
$content = ob_get_clean();
require_once('./application/libraries/html2pdf/html2pdf.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->setDefaultFont('javiergb');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, '');
$html2pdf->Output('invTf_'.date('ymdHis').'.pdf');
}catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
str_alert(-1,'单据不存在、或者已删除');
}
//删除
public function delete() {
$this->common_model->checkpurview(147);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>103091));
if (count($data)>0) {
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('invoice_info',array('isDelete'=>1),array('iid'=>$id));
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除调拨单 单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'该单据不存在');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['totalQty'] = (float)$data['totalQty'];
$data['billType'] = 'TRANSFER';
$data['transType'] = 103091;
$data['transTypeName'] = '调拨单';
$data['billDate'] = $data['date'];
$data['description'] = $data['description'];
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['accounts'] = isset($data['accounts']) ? $data['accounts'] : array();
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'transType'=>103091,'isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['checked'] = $invoice['checked'];
$data['billNo'] = $invoice['billNo'];
} else {
$data['billNo'] = str_no('DB');
}
//商品录入验证
$system = $this->common_model->get_option('system');
if ($system['requiredCheckStore']==1) {
$inventory = $this->data_model->get_invoice_info_inventory();
}
$storage = array_column($this->mysql_model->get_results('storage','(disable=0)'),'id');
foreach ($data['entries'] as $arr=>$row) {
(float)$row['qty'] < 0 && str_alert(-1,'商品数量要为数字,请输入有效数字!');
intval($row['outLocationId']) < 1 && str_alert(-1,'请选择调出仓库仓库!');
intval($row['inLocationId']) < 1 && str_alert(-1,'请选择调入仓库仓库!');
intval($row['outLocationId']) == intval($row['inLocationId']) && str_alert(-1,'调出仓库不能与调入仓库相同!');
!in_array($row['outLocationId'],$storage) && str_alert(-1,$row['outLocationName'].'不存在或不可用!');
!in_array($row['inLocationId'],$storage) && str_alert(-1,$row['inLocationName'].'不存在或不可用!');
//库存判断 修改不验证
if ($system['requiredCheckStore']==1 && $data['id']<1) {
if (isset($inventory[$row['invId']][$row['outLocationId']])) {
$inventory[$row['invId']][$row['outLocationId']] < (float)$row['qty'] && str_alert(-1,$row['outLocationName'].$row['invName'].'商品库存不足!');
} else {
str_alert(-1,$row['invName'].'库存不足!');
}
}
$inLocationId[] = $row['inLocationId'];
$outLocationId[] = $row['outLocationId'];
}
$data['inLocationId'] = join(',',array_unique($inLocationId));
$data['outLocationId'] = join(',',array_unique($outLocationId));
$data['postData'] = serialize($data);
return $data;
}
//组装数据
private function invoice_info($iid,$data) {
$profit = $this->data_model->get_profit('and billDate<="'.date('Y-m-d').'"');
foreach ($data['entries'] as $arr=>$row) {
$price = isset($profit['inprice'][$row['invId']][$row['outLocationId']]) ? $profit['inprice'][$row['invId']][$row['outLocationId']] : 0;
$s[$arr]['iid'] = $v[$arr]['iid'] = $iid;
$s[$arr]['uid'] = $v[$arr]['uid'] = $data['uid'];
$s[$arr]['billNo'] = $v[$arr]['billNo'] = $data['billNo'];
$s[$arr]['billDate'] = $v[$arr]['billDate'] = $data['billDate'];
$s[$arr]['invId'] = $v[$arr]['invId'] = intval($row['invId']);
$s[$arr]['skuId'] = $v[$arr]['skuId'] = intval($row['skuId']);
$s[$arr]['unitId'] = $v[$arr]['unitId'] = intval($row['unitId']);
$s[$arr]['billType'] = $v[$arr]['billType'] = $data['billType'];
$s[$arr]['description'] = $v[$arr]['description'] = $row['description'];
$s[$arr]['transTypeName'] = $v[$arr]['transTypeName'] = $data['transTypeName'];
$s[$arr]['transType'] = $v[$arr]['transType'] = $data['transType'];
$v[$arr]['locationId'] = intval($row['inLocationId']);
$v[$arr]['qty'] = abs($row['qty']);
$v[$arr]['price'] = $price;
$v[$arr]['amount'] = abs($row['qty']) * $price;
$v[$arr]['entryId'] = 1;
$s[$arr]['locationId'] = intval($row['outLocationId']);
$s[$arr]['qty'] = -abs($row['qty']);
$s[$arr]['price'] = $price;
$s[$arr]['amount'] = -abs($row['qty']) * $price;
$s[$arr]['entryId'] = 2;
}
if (isset($s) && isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('invoice_info',array('iid'=>$iid));
}
$this->mysql_model->insert('invoice_info',$v);
$this->mysql_model->insert('invoice_info',$s);
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,526 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ori extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initInc':
$this->common_model->checkpurview(135);
$this->load->view('scm/ori/initInc');
break;
case 'editInc':
$this->common_model->checkpurview(136);
$this->load->view('scm/ori/initInc');
break;
case 'initIncList':
$this->common_model->checkpurview(134);
$this->load->view('scm/ori/initIncList');
break;
case 'initExp':
$this->common_model->checkpurview(140);
$this->load->view('scm/ori/initExp');
break;
case 'editExp':
$this->common_model->checkpurview(141);
$this->load->view('scm/ori/initExp');
break;
case 'initExpList':
$this->common_model->checkpurview(139);
$this->load->view('scm/ori/initExpList');
break;
default:
}
}
//其他收入列表
public function listInc() {
$this->common_model->checkpurview(134);
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$transtypeid = intval($this->input->get_post('transTypeId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153401';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['amount'] = (float)$row['totalAmount'];
$v[$arr]['transType'] = intval($row['transType']);;
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['totalAmount'] = (float)$row['totalAmount'];
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['transTypeName']= $row['transTypeName'];
$v[$arr]['checked'] = intval($row['checked']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
//导出其他收入
public function exportInc() {
$this->common_model->checkpurview(138);
$name = 'other_receipt_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出其他收入单:'.$name);
$transtypeid = intval($this->input->get_post('transTypeId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153401';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by a.id desc');
$data['category'] = array_column($this->mysql_model->get_results('category',array('typeNumber'=>'raccttype')),'name','id');
$this->load->view('scm/ori/exportInc',$data);
}
//其他收入新增
public function addInc(){
$this->common_model->checkpurview(135);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->inc_validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','postData','createTime',
'totalAmount','buId','billDate','uid','userName','accId'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$this->inc_account_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增其他收入 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
//新增
public function addNewInc(){
$this->addInc();
}
//修改
public function updateInc(){
$this->common_model->checkpurview(136);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->inc_validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','totalAmount','postData','uid','userName',
'buId','billDate','accId','modifytime'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->inc_account_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改其他收入 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'单据不存在');
}
//获取修改信息
public function getIncDetail() {
$this->common_model->checkpurview(136);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.transType=153401',1);
if (count($data)>0) {
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['contactName'] = $data['contactName'];
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['amount'] = (float)$data['totalAmount'];
$info['data']['status'] = 'edit';
$info['data']['accId'] = intval($data['accId']);
$info['data']['acctName'] = '';
$info['data']['userName'] = $data['userName'];
$accounts = $this->data_model->get_account_info('a.iid='.$id.' order by a.id');
foreach ($accounts as $arr=>$row) {
$v[$arr]['amount'] = (float)$row['payment'];
$v[$arr]['categoryId'] = (float)$row['wayId'];
$v[$arr]['description'] = $row['remark'];
$v[$arr]['categoryName'] = $row['categoryName'];
}
$info['data']['entries'] = isset($v) ? $v : array();
die(json_encode($info));
}
str_alert(-1,'单据不存在');
}
//删除
public function deleteInc() {
$this->common_model->checkpurview(137);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>153401));
if (count($data)>0) {
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在');
}
//其他支出单列表
public function listExp() {
$this->common_model->checkpurview(139);
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153402';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['amount'] = (float)$row['totalAmount'];
$v[$arr]['transType'] = intval($row['transType']);;
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['totalAmount'] = (float)$row['totalAmount'];
$v[$arr]['userName'] = $row['userName'];
$v[$arr]['transTypeName']= '';
$v[$arr]['checked'] = intval($row['checked']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
//导出其他支出
public function exportExp() {
$this->common_model->checkpurview(143);
$name = 'other_payment_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出其他支出单:'.$name);
$transtypeid = intval($this->input->get_post('transTypeId',TRUE));
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153402';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by id desc');
$data['category'] = array_column($this->mysql_model->get_results('category','(typeNumber="paccttype")'),'name','id');
$this->load->view('scm/ori/exportExp',$data);
}
//新增
public function addExp(){
$this->common_model->checkpurview(140);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->exp_validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','postData',
'totalAmount','buId','billDate','uid','userName','accId'),$data);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$this->exp_account_info($iid,$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增其他收入 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
//新增
public function addNewExp(){
$this->addExp();
}
//修改
public function updateExp(){
$this->common_model->checkpurview(141);
$postData = $data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->exp_validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','totalAmount','postData',
'buId','billDate','accId','modifytime','uid','userName'),$data);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$this->exp_account_info($data['id'],$data);
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改其他支出 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'参数错误');
}
//获取修改信息
public function getExpDetail() {
$this->common_model->checkpurview(141);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.transType=153402',1);
if (count($data)>0) {
$info['status'] = 200;
$info['msg'] = 'success';
$info['data']['id'] = intval($data['id']);
$info['data']['buId'] = intval($data['buId']);
$info['data']['contactName'] = $data['contactName'];
$info['data']['date'] = $data['billDate'];
$info['data']['billNo'] = $data['billNo'];
$info['data']['amount'] = (float)abs($data['amount']);
$info['data']['status'] = 'edit';
$info['data']['accId'] = intval($data['accId']);
$info['data']['acctName'] = '';
$info['data']['userName'] = $data['userName'];
$accounts = $this->data_model->get_account_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
foreach ($accounts as $arr=>$row) {
$v[$arr]['amount'] = $row['payment']>0 ? -abs($row['payment']) : abs($row['payment']);
$v[$arr]['categoryId'] = (float)$row['wayId'];
$v[$arr]['description'] = $row['remark'];
$v[$arr]['categoryName'] = $row['categoryName'];
}
$info['data']['entries'] = isset($v) ? $v : array();
die(json_encode($info));
} else {
str_alert(-1,'参数错误');
}
}
//删除
public function deleteExp() {
$this->common_model->checkpurview(142);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>153402));
if (count($data)>0) {
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在');
}
//打印
public function toPdf() {
$this->common_model->checkpurview(85);
$id = intval($this->input->get('id',TRUE));
$transType = intval($this->input->get('transType',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.transType='.$transType.'',1);
if (count($data)>0) {
$data['num'] = 8;
$data['system'] = $this->common_model->get_option('system');
$list = $this->data_model->get_account_info('a.isDelete=0 and a.iid='.$id.' order by a.id');
$data['countpage'] = ceil(count($list)/$data['num']);
foreach($list as $arr=>$row) {
$data['list'][] = array(
'i'=>$arr + 1,
'amount'=>abs($row['payment']),
'categoryId'=>intval($row['wayId']),
'description'=>$row['remark'],
'categoryName'=>$row['categoryName']
);
}
ob_start();
$this->load->view('scm/ori/toPdf',$data);
$content = ob_get_clean();
require_once('./application/libraries/html2pdf/html2pdf.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'tr');
$html2pdf->setDefaultFont('javiergb');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, '');
$html2pdf->Output('ori_'.date('YmdHis').'.pdf');
}catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
str_alert(-1,'单据不存在、或者已删除');
}
//公共验证
private function inc_validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['billDate'] = $data['date'] ? $data['date'] : date('Y-m-d');
$data['accId'] = intval($data['accId']);
$data['totalAmount'] = (float)$data['totalAmount'];
$data['billType'] = 'QTSR';
$data['transType'] = 153401;
$data['transTypeName'] = '其他收入';
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifytime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['postData'] = serialize($data);
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
//修改的时候
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'transType'=>153401,'isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['billNo'] = $invoice['billNo'];
} else {
$data['billNo'] = str_no('QTSR');
}
return $data;
}
//公共验证
private function exp_validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['billDate'] = $data['date'] ? $data['date'] : date('Y-m-d');
$data['accId'] = intval($data['accId']);
$data['totalAmount'] = (float)$data['totalAmount'];
$data['billNo'] = str_no('QTZC');
$data['billType'] = 'QTZC';
$data['transType'] = 153402;
$data['transTypeName'] = '其他支出';
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifytime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['postData'] = serialize($data);
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
count($data['entries']) < 1 && str_alert(-1,'提交的是空数据');
//修改的时候
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'transType'=>153402,'isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['billNo'] = $invoice['billNo'];
} else {
$data['billNo'] = str_no('QTSR');
}
return $data;
}
private function inc_account_info($iid,$data) {
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['accId'] = $data['accId'];
$v[$arr]['payment'] = $row['amount'];
$v[$arr]['wayId'] = $row['categoryId'];
$v[$arr]['remark'] = $row['description'];
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
$this->mysql_model->insert('account_info',$v);
}
}
private function exp_account_info($iid,$data) {
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['accId'] = $data['accId'];
$v[$arr]['payment'] = -$row['amount'];
$v[$arr]['wayId'] = $row['categoryId'];
$v[$arr]['remark'] = $row['description'];
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
$this->mysql_model->insert('account_info',$v);
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,366 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Payment extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initPay':
$this->common_model->checkpurview(130);
$this->load->view('scm/payment/initPay');
break;
case 'editPay':
$this->common_model->checkpurview(129);
$this->load->view('scm/payment/initPay');
break;
case 'initUnhxList':
$this->load->view('scm/payment/initUnhxList');
break;
case 'initPayList':
$this->common_model->checkpurview(129);
$this->load->view('scm/payment/initPayList');
break;
default:
$this->common_model->checkpurview(129);
$this->payList();
}
}
public function payList(){
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153101';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['amount'] = (float)$row['rpAmount']; //收款金额
$v[$arr]['adjustRate'] = (float)$row['discount']; //整单折扣
$v[$arr]['deAmount'] = (float)$row['payment']; //本次预收款
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['bDeAmount'] = (float)$row['hxAmount']; //本次核销
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['hxAmount'] = (float)$row['hxAmount']; //本次核销
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['userName'] = $row['userName'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function export(){
$this->common_model->checkpurview(133);
$name = 'payment_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出付款单:'.$name);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$locationId = intval($this->input->get_post('locationId',TRUE));
$where = 'a.isDelete=0 and a.transType=153101';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and a.billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and a.billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by id desc');
$data['account'] = array_column($this->mysql_model->get_results('account','(isDelete=0)'),'name','id');
$data['category'] = array_column($this->mysql_model->get_results('category','(typeNumber="PayMethod")'),'name','id');
$this->load->view('scm/payment/export',$data);
}
//新增
public function add(){
$this->common_model->checkpurview(130);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','buId','billDate','createTime','arrears',
'description','uid','postData','userName','rpAmount','hxAmount','discount','payment','modifyTime'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$amount = $this->account_info($iid,$data);
//add begin
$rpAmount = 0;
$duplicate = array();
if (is_array($data['entries']) && count($data['entries'])>0) {
$v = '';
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['billId'] = $row['billId'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['transType'] = $row['transType'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['billPrice'] = (float)$row['billPrice'];
$v[$arr]['hasCheck'] = (float)$row['hasCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
$rpAmount += $v[$arr]['nowCheck'] = (float)$row['nowCheck'];
$duplicate[$arr] = $row['billId'];
}
if(count($duplicate)!= count(array_unique($duplicate))){
$this->db->trans_rollback();
str_alert(-1,'存在重复的源单编号,请核实!');
}
if($rpAmount != $amount || $data['payment']!=0){
$this->db->trans_rollback();
str_alert(-1,'付款金额总和与核销金额总和不相等,请核实!');
}
$this->mysql_model->insert('verifica_info',$v);
}
//add end
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增付款单 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$iid));
}
}
str_alert(-1,'提交的是空数据');
}
public function addNew(){
$this->add();
}
//修改
public function updatePayment(){
$this->common_model->checkpurview(131);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','description','uid','userName',
'postData','rpAmount','arrears','hxAmount','discount','payment','modifyTime'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$amount = $this->account_info($data['id'],$data);
//add begin
$this->mysql_model->delete('verifica_info','(iid='.$data['id'].')');
$rpAmount = 0;
$duplicate = array();
if (isset($data['entries']) && count($data['entries'])>0) {
$v = '';
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $data['id'];
$v[$arr]['billId'] = $row['billId'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['transType'] = $row['transType'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['billPrice'] = (float)$row['billPrice'];
$v[$arr]['hasCheck'] = (float)$row['hasCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
$rpAmount += $v[$arr]['nowCheck'] = (float)$row['nowCheck'];
$duplicate[$arr] = $row['billId'];
}
if(count($duplicate)!= count(array_unique($duplicate))){
$this->db->trans_rollback();
str_alert(-1,'存在重复的源单编号,请核实!');
}
if($rpAmount != $amount || $data['payment']!=0){
$this->db->trans_rollback();
str_alert(-1,'付款金额总和与核销金额总和不相等,请核实!');
}
$this->mysql_model->insert('verifica_info',$v);
}
//add end
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改收款单 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'参数错误');
}
//信息
public function update() {
$this->common_model->checkpurview(129);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.transType=153101',1);
if (count($data)>0) {
$list = $this->data_model->get_account_info('a.iid='.$id);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($arr+1);
$v[$arr]['accId'] = intval($row['accId']);
$v[$arr]['accName'] = $row['accountNumber'].' '.$row['accountName'];
$v[$arr]['payment'] = (float)$row['payment']>0 ? -abs($row['payment']) : abs($row['payment']); //特殊情况
$v[$arr]['wayId'] = (float)$row['wayId'];
$v[$arr]['remark'] = $row['remark'];
$v[$arr]['wayName'] = $row['categoryName'];
$v[$arr]['settlement'] = $row['settlement'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['id'] = intval($data['id']);
$json['data']['buId'] = intval($data['buId']);
$json['data']['modifyTime'] = $data['modifyTime'];
$json['data']['createTime'] = $data['createTime'];
$json['data']['contactName'] = $data['contactName'];
$json['data']['date'] = $data['billDate'];
$json['data']['billNo'] = $data['billNo'];
$json['data']['checked'] = intval($data['checked']);
$json['data']['checkName'] = $data['checkName'];
$json['data']['userName'] = $data['userName'];
$json['data']['description'] = $data['description'];
$json['data']['discount'] = (float)$data['discount'];
$json['data']['payment'] = (float)$data['payment'];
$json['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit';
$json['data']['accounts'] = isset($v) ? $v : array();
$json['data']['entries'] = array();
//add begin
$s = array();
$list = $this->mysql_model->get_results('verifica_info','(iid='.$id.') order by id desc');
foreach ($list as $arr=>$row) {
$s[$arr]['billId'] = intval($row['billId']);
$s[$arr]['billNo'] = $row['billNo'];
$s[$arr]['billDate'] = $row['billDate'];
$s[$arr]['transType'] = $row['transType'];
$s[$arr]['billType'] = $row['billType'];
$s[$arr]['billPrice'] = (float)$row['billPrice'];
$s[$arr]['hasCheck'] = (float)$row['hasCheck'];
$s[$arr]['notCheck'] = (float)$row['notCheck'];
$s[$arr]['nowCheck'] = (float)$row['nowCheck'];
$s[$arr]['type'] = 1;
}
$json['data']['entries'] = $s;
//add end
die(json_encode($json));
}
str_alert(-1,'参数错误');
}
//删除
public function delete() {
$this->common_model->checkpurview(132);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>153101));
if (count($data)>0) {
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
$this->mysql_model->delete('verifica_info','(iid='.$id.')');//add
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除收款单 单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在,或已被删除');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['billDate'] = $data['date'] ? $data['date'] : date('Y-m-d');
$data['billType'] = 'PAYMENT';
$data['transType'] = 153101;
$data['transTypeName'] = '付款';
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['hxAmount'] = $data['rpAmount'] = 0;
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
$data['accounts'] = isset($data['accounts']) ? $data['accounts'] : array();
count($data['accounts']) < 1 && str_alert(-1,'提交的是空数据');
//修改的时候
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'billType'=>'PAYMENT','isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['billNo'] = $invoice['billNo'];
$data['checked'] = $invoice['checked'];
} else {
$data['billNo'] = str_no('FKD');
}
$this->mysql_model->get_count('contact',array('id'=>$data['buId']))<1 && str_alert(-1,'请选择供应商,供应商不能为空!');
//数据验证
foreach ($data['accounts'] as $arr=>$row) {
(float)$row['payment'] < 0 && str_alert(-1,'付款金额不能为负数!');
$data['rpAmount'] += abs($row['payment']);
}
/*foreach ($data['entries'] as $arr=>$row) {
(float)$row['nowCheck'] < 0 && str_alert(-1,'核销金额不能为负数!');
$data['hxAmount'] += abs($row['nowCheck']);
} */
$data['arrears'] = -$data['rpAmount'];
$data['postData'] = serialize($data);
return $data;
}
private function account_info($iid,$data) {
$amount = 0;
foreach ($data['accounts'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['accId'] = $row['accId'] ;
$v[$arr]['payment'] = -abs($row['payment']);
$v[$arr]['wayId'] = $row['wayId'];
$v[$arr]['settlement'] = $row['settlement'];
$v[$arr]['remark'] = $row['remark'];
$amount += (float)$row['payment'];
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
$this->mysql_model->insert('account_info',$v);
}
return $amount;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,31 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class PdImport extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->load->library('excel/excel');
}
public function index() {
$info = upload('file','./data/upfile/');
$xls = $info['path'];
$this->excel->setOutputEncoding('utf-8');
$this->excel->read($xls);
$list = $this->excel->sheets[0]['cells'];
foreach ($list as $arr=>$row) {
$data[$arr]['id'] = @$row['1'];
$data[$arr]['title'] = @$row['2'];
$data[$arr]['nr'] = @$row['3'];
}
print_r($data);
//str_alert(-1,'文件写入失败');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,387 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Receipt extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
$this->jxcsys = $this->session->userdata('jxcsys');
}
public function index() {
$action = $this->input->get('action',TRUE);
switch ($action) {
case 'initReceipt':
$this->common_model->checkpurview(125);
$this->load->view('scm/receipt/initReceipt');
break;
case 'editReceipt':
$this->common_model->checkpurview(124);
$this->load->view('scm/receipt/initReceipt');
break;
case 'initUnhxList':
$this->load->view('scm/receipt/initUnhxList');
break;
case 'initReceiptList':
$this->common_model->checkpurview(124);
$this->load->view('scm/receipt/initReceiptList');
break;
default:
$this->common_model->checkpurview(124);
$this->receiptList();
}
}
public function receiptList() {
$page = max(intval($this->input->get_post('page',TRUE)),1);
$rows = max(intval($this->input->get_post('rows',TRUE)),100);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$where = 'a.isDelete=0 and a.transType=153001';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$list = $this->data_model->get_invoice($where.' order by id desc limit '.$rows*($page-1).','.$rows);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($row['id']);
$v[$arr]['amount'] = (float)$row['rpAmount'];
$v[$arr]['adjustRate'] = (float)$row['discount']; //整单折扣
$v[$arr]['deAmount'] = (float)$row['payment']; //本次预收款
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['bDeAmount'] = (float)$row['hxAmount']; //本次核销
$v[$arr]['hxAmount'] = (float)$row['hxAmount']; //本次核销
$v[$arr]['contactName'] = $row['contactName'];
$v[$arr]['description'] = $row['description'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['checked'] = intval($row['checked']);
$v[$arr]['checkName'] = $row['checkName'];
$v[$arr]['userName'] = $row['userName'];
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['page'] = $page;
$json['data']['records'] = $this->data_model->get_invoice($where,3);
$json['data']['total'] = ceil($json['data']['records']/$rows);
$json['data']['rows'] = isset($v) ? $v : array();
die(json_encode($json));
}
public function exportReceipt(){
$this->common_model->checkpurview(128);
$name = 'receipt_record_'.date('YmdHis').'.xls';
sys_csv($name);
$this->common_model->logs('导出收款单:'.$name);
$matchCon = str_enhtml($this->input->get_post('matchCon',TRUE));
$beginDate = str_enhtml($this->input->get_post('beginDate',TRUE));
$endDate = str_enhtml($this->input->get_post('endDate',TRUE));
$locationId = intval($this->input->get_post('locationId',TRUE));
$where = 'a.isDelete=0 and transType=153001';
$where .= $matchCon ? ' and a.postData like "%'.$matchCon.'%"' : '';
$where .= $beginDate ? ' and billDate>="'.$beginDate.'"' : '';
$where .= $endDate ? ' and billDate<="'.$endDate.'"' : '';
$where .= $this->common_model->get_admin_purview();
$data['list'] = $this->data_model->get_invoice($where.' order by id desc');
$data['account'] = array_column($this->mysql_model->get_results('account','(isDelete=0)'),'name','id');
$data['category'] = array_column($this->mysql_model->get_results('category','(typeNumber="PayMethod")'),'name','id');
$this->load->view('scm/receipt/exportReceipt',$data);
}
//新增
public function add(){
$this->common_model->checkpurview(125);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billNo','billType','transType','transTypeName','postData','buId','createTime',
'billDate','description','uid','userName','rpAmount','arrears','hxAmount','discount','payment','modifyTime'),$data,NULL);
$this->db->trans_begin();
$iid = $this->mysql_model->insert('invoice',$info);
$amount = $this->account_info($iid,$data);
//add begin
$rpAmount = 0;
$duplicate = array();
if (is_array($data['entries']) && count($data['entries'])>0) {
$v = '';
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['billId'] = $row['billId'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['transType'] = $row['transType'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['billPrice'] = (float)$row['billPrice'];
$v[$arr]['hasCheck'] = (float)$row['hasCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
//$rpAmount += $v[$arr]['nowCheck'] = (float)$row->nowCheck;
$rpAmount += $v[$arr]['nowCheck'] = (float)$row['nowCheck'];
$duplicate[$arr] = $row['billId'];
}
if(count($duplicate)!= count(array_unique($duplicate))){
$this->db->trans_rollback();
str_alert(-1,'存在重复的源单编号,请核实!');
}
if($rpAmount != $amount || $data['payment']!=0){
$this->db->trans_rollback();
str_alert(-1,'收款金额总和与核销金额总和不相等,请核实!'.$amount.$rpAmount);
}
$this->mysql_model->insert('verifica_info',$v);
}
//$info['amount'] = $amount;
//$info['rpAmount'] = $rpAmount;
//$this->mysql_model->update(INVOICE,$info,'(id='.$iid.')');
//add end
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('新增收款单 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>intval($iid)));
}
}
str_alert(-1,'提交的是空数据');
}
public function addnew(){
$this->add();
}
//修改
public function updateReceipt(){
$this->common_model->checkpurview(126);
$data = $this->input->post('postData',TRUE);
if (strlen($data)>0) {
$data = $this->validform((array)json_decode($data, true));
$info = elements(array(
'billType','transType','transTypeName','buId','billDate','uid','userName',
'description','postData','rpAmount','arrears','hxAmount','discount','payment','modifyTime'),$data,NULL);
$this->db->trans_begin();
$this->mysql_model->update('invoice',$info,array('id'=>$data['id']));
$amount = $this->account_info($data['id'],$data);
//add begin
$this->mysql_model->delete('verifica_info','(iid='.$data['id'].')');
$rpAmount = 0;
$duplicate = array();
if (isset($data['entries']) && count($data['entries'])>0) {
$v = '';
foreach ($data['entries'] as $arr=>$row) {
$v[$arr]['iid'] = $data['id'];
$v[$arr]['billId'] = $row['billId'];
$v[$arr]['billNo'] = $row['billNo'];
$v[$arr]['billDate'] = $row['billDate'];
$v[$arr]['transType'] = $row['transType'];
$v[$arr]['billType'] = $row['billType'];
$v[$arr]['billPrice'] = (float)$row['billPrice'];
$v[$arr]['hasCheck'] = (float)$row['hasCheck'];
$v[$arr]['notCheck'] = (float)$row['notCheck'];
$rpAmount += $v[$arr]['nowCheck'] = (float)$row['nowCheck'];
$duplicate[$arr] = $row['billId'];
}
if(count($duplicate)!= count(array_unique($duplicate))){
$this->db->trans_rollback();
str_alert(-1,'存在重复的源单编号,请核实!');
}
if($rpAmount != $amount || $data['payment']!=0){
$this->db->trans_rollback();
str_alert(-1,'收款金额总和与核销金额总和不相等,请核实!');
}
$this->mysql_model->insert('verifica_info',$v);
}
//add end
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'SQL错误回滚');
} else {
$this->db->trans_commit();
$this->common_model->logs('修改收款单 单据编号:'.$data['billNo']);
str_alert(200,'success',array('id'=>$data['id']));
}
}
str_alert(-1,'参数错误');
}
//信息
public function update() {
$this->common_model->checkpurview(124);
$id = intval($this->input->get_post('id',TRUE));
$data = $this->data_model->get_invoice('a.isDelete=0 and a.id='.$id.' and a.transType=153001',1);
if (count($data)>0) {
$list = $this->data_model->get_account_info('a.iid='.$id);
foreach ($list as $arr=>$row) {
$v[$arr]['id'] = intval($arr+1);
$v[$arr]['payment'] = (float)$row['payment'];
$v[$arr]['remark'] = $row['remark'];
$v[$arr]['accName'] = $row['accountNumber'].' '.$row['accountName'];
$v[$arr]['settlement'] = $row['settlement'];
$v[$arr]['wayName'] = $row['categoryName'];
$v[$arr]['wayId'] = $row['wayId'];
$v[$arr]['accId'] = intval($row['accId']);
}
$json['status'] = 200;
$json['msg'] = 'success';
$json['data']['id'] = $id;
$json['data']['buId'] = intval($data['buId']);
$json['data']['contactName'] = $data['contactName'];
$json['data']['date'] = $data['billDate'];
$json['data']['billNo'] = $data['billNo'];
$json['data']['discount'] = (float)$data['discount'];
$json['data']['payment'] = (float)$data['payment'];
$json['data']['checkName'] = $data['checkName'];
$json['data']['userName'] = $data['userName'];
$json['data']['createTime'] = $data['createTime'];
$json['data']['modifyTime'] = $data['modifyTime'];
$json['data']['description'] = $data['description'];
$json['data']['checked'] = intval($data['checked']);
$json['data']['status'] = intval($data['checked'])==1 ? 'view' : 'edit';
$json['data']['accounts'] = isset($v) ? $v : array();
$json['data']['entries'] = array();
//add begin
$s = array();
$list = $this->mysql_model->get_results('verifica_info','(iid='.$id.') order by id desc');
foreach ($list as $arr=>$row) {
$s[$arr]['billId'] = intval($row['billId']);
$s[$arr]['billNo'] = $row['billNo'];
$s[$arr]['billDate'] = $row['billDate'];
$s[$arr]['transType'] = $row['transType'];
$s[$arr]['billType'] = $row['billType'];
$s[$arr]['billPrice'] = (float)$row['billPrice'];
$s[$arr]['hasCheck'] = (float)$row['hasCheck'];
$s[$arr]['notCheck'] = (float)$row['notCheck'];
$s[$arr]['nowCheck'] = (float)$row['nowCheck'];
$s[$arr]['type'] = 1;
}
$json['data']['entries'] = $s;
//add end
die(json_encode($json));
}
str_alert(-1,'参数错误');
}
//删除
public function delete() {
$this->common_model->checkpurview(127);
$id = intval($this->input->get('id',TRUE));
$data = $this->mysql_model->get_rows('invoice',array('id'=>$id,'transType'=>153001));
if (count($data)>0) {
$this->db->trans_begin();
$this->mysql_model->update('invoice',array('isDelete'=>1),array('id'=>$id));
$this->mysql_model->update('account_info',array('isDelete'=>1),array('iid'=>$id));
//$this->mysql_model->update('verifica_info',array('isDelete'=>1),array('iid'=>$id));
$this->mysql_model->delete('verifica_info','(iid='.$id.')');//add
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
str_alert(-1,'删除失败');
} else {
$this->db->trans_commit();
$this->common_model->logs('删除收款单 单据编号:'.$data['billNo']);
str_alert(200,'success');
}
}
str_alert(-1,'单据不存在,或已被删除');
}
//公共验证
private function validform($data) {
$data['id'] = isset($data['id']) ? intval($data['id']) : 0;
$data['buId'] = intval($data['buId']);
$data['billDate'] = $data['date'] ? $data['date'] : date('Y-m-d');
$data['billType'] = 'RECEIPT';
$data['transType'] = 153001;
$data['transTypeName'] = '收款';
$data['uid'] = $this->jxcsys['uid'];
$data['userName'] = $this->jxcsys['name'];
$data['modifyTime'] = date('Y-m-d H:i:s');
$data['createTime'] = $data['modifyTime'];
$data['hxAmount'] = $data['rpAmount'] = 0;
$data['entries'] = isset($data['entries']) ? $data['entries'] : array();
$data['accounts'] = isset($data['accounts']) ? $data['accounts'] : array();
count($data['accounts']) < 1 && str_alert(-1,'提交的是空数据');
//修改的时候
if ($data['id']>0) {
$invoice = $this->mysql_model->get_rows('invoice',array('id'=>$data['id'],'billType'=>'RECEIPT','isDelete'=>0));
count($invoice)<1 && str_alert(-1,'单据不存在、或者已删除');
$data['billNo'] = $invoice['billNo'];
$data['checked'] = $invoice['checked'];
} else {
$data['billNo'] = str_no('SKD');
}
$this->mysql_model->get_count('contact',array('id'=>$data['buId']))<1 && str_alert(-1,'请选择客户,客户不能为空!');
foreach ($data['accounts'] as $arr=>$row) {
(float)$row['payment'] < 0 && str_alert(-1,'收款金额不能为负数!');
$data['rpAmount'] += abs($row['payment']);
}
/*foreach ($data['entries'] as $arr=>$row) {
(float)$row['nowCheck'] < 0 && str_alert(-1,'核销金额不能为负数!');
$data['hxAmount'] += abs($row['nowCheck']);
} */
$data['arrears'] = -$data['rpAmount'];
$data['postData'] = serialize($data);
return $data;
}
private function account_info($iid,$data) {
$amount = 0;
foreach ($data['accounts'] as $arr=>$row) {
$v[$arr]['iid'] = $iid;
$v[$arr]['uid'] = $data['uid'];
$v[$arr]['billNo'] = $data['billNo'];
$v[$arr]['buId'] = $data['buId'];
$v[$arr]['billType'] = $data['billType'];
$v[$arr]['transType'] = $data['transType'];
$v[$arr]['transTypeName'] = $data['transTypeName'];
$v[$arr]['billDate'] = $data['billDate'];
$v[$arr]['accId'] = $row['accId'];
$v[$arr]['payment'] = abs($row['payment']);
$v[$arr]['wayId'] = $row['wayId'];
$v[$arr]['settlement'] = $row['settlement'];
$v[$arr]['remark'] = $row['remark'];
$amount += (float)$row['payment'];
}
if (isset($v)) {
if ($data['id']>0) {
$this->mysql_model->delete('account_info',array('iid'=>$iid));
}
$this->mysql_model->insert('account_info',$v);
}
return $amount;
}
private function write_back_invoice($id){
/*$s = array();
$list = $this->mysql_model->get_results('verifica_info','(iid='.$id.') order by id desc');
foreach ($list as $arr=>$row) {
$s[$arr]['billId'] = intval($row['billId']);
$s[$arr]['billNo'] = $row['billNo'];
$s[$arr]['billDate'] = $row['billDate'];
$s[$arr]['transType'] = $row['transType'];
$s[$arr]['billType'] = $row['billType'];
$s[$arr]['billPrice'] = (float)$row['billPrice'];
$s[$arr]['hasCheck'] = (float)$row['hasCheck'];
$s[$arr]['notCheck'] = (float)$row['notCheck'];
$s[$arr]['nowCheck'] = (float)$row['nowCheck'];
$s[$arr]['type'] = 1;
}*/
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,25 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Service extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function index() {
$this->load->view('service');
}
public function recover() {
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,293 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Settings extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function Contract() {
$this->load->view('settings/Contract');
}
public function customer_list() {
$this->common_model->checkpurview(58);
$this->load->view('settings/customer-list');
}
public function customer_manage() {
$this->load->view('settings/customer-manage');
}
public function vendor_list() {
$this->common_model->checkpurview(63);
$this->load->view('settings/vendor-list');
}
public function vendor_manage() {
$this->load->view('settings/vendor-manage');
}
public function addressmanage() {
$this->load->view('settings/addressmanage');
}
public function goods_list() {
$this->common_model->checkpurview(68);
$this->load->view('settings/goods-list');
}
public function storage_list() {
$this->common_model->checkpurview(155);
$this->load->view('settings/storage-list');
}
public function storage_manage() {
$this->load->view('settings/storage-manage');
}
public function staff_list() {
$this->common_model->checkpurview(97);
$this->load->view('settings/staff-list');
}
public function staff_manage() {
$this->load->view('settings/staff-manage');
}
//add by michen 20171118 begin
public function cst_list() {
$this->common_model->checkpurview(97);
$this->load->view('settings/cst-list');
}
public function cst_manage() {
$this->load->view('settings/cst-manage');
}
public function select_customer2() {
$this->load->view('settings/select-customer2');
}
//add by michen 20171118 end
public function shippingaddress() {
$this->load->view('settings/shippingaddress');
}
public function shippingaddressmanage() {
$this->load->view('settings/shippingaddressmanage');
}
public function settlement_account() {
$this->common_model->checkpurview(98);
$this->load->view('settings/settlement-account');
}
public function settlementaccount_manager() {
$this->load->view('settings/settlementaccount-manager');
}
public function system_parameter() {
$this->common_model->checkpurview(81);
$this->load->view('settings/system-parameter');
}
public function unit_list() {
$this->common_model->checkpurview(77);
$this->load->view('settings/unit-list');
}
public function unit_manage() {
$this->load->view('settings/unit-manage');
}
public function unitgroup_manage() {
$this->load->view('settings/unitgroup-manage');
}
public function backup() {
$this->common_model->checkpurview(84);
$this->load->view('settings/backup');
}
public function settlement_category_list() {
$this->common_model->checkpurview(159);
$this->load->view('settings/settlement-category-list');
}
public function settlement_category_manager() {
$this->load->view('settings/settlement-category-manage');
}
public function category_list() {
$type = str_enhtml($this->input->get('typeNumber',TRUE));
$info = array('customertype'=>73,'supplytype'=>163,'trade'=>167,'paccttype'=>171,'raccttype'=>175);
$this->common_model->checkpurview($info[$type]);
$this->load->view('settings/category-list');
}
public function choose_account() {
$this->load->view('settings/choose-account');
}
public function inventory_warning() {
$this->load->view('settings/inventory-warning');
}
public function log() {
$this->common_model->checkpurview(83);
$this->load->view('settings/log-initloglist');
}
public function authority() {
$this->common_model->checkpurview(82);
$this->load->view('settings/authority');
}
public function authority_new() {
$this->common_model->checkpurview(82);
$this->load->view('settings/authority-new');
}
public function authority_setting() {
$this->common_model->checkpurview(82);
$this->load->view('settings/authority-setting');
}
public function authority_setting_data() {
$this->common_model->checkpurview(82);
$this->load->view('settings/authority-setting-data');
}
public function goods_manage() {
$this->load->view('settings/goods-manage');
}
public function fileupload() {
$this->load->view('settings/fileupload');
}
public function assistingprop() {
$this->load->view('settings/assistingprop');
}
public function prop_list() {
$this->load->view('settings/prop-list');
}
public function propmanage() {
$this->load->view('settings/propmanage');
}
public function import() {
$this->load->view('settings/import');
}
public function select_customer() {
$this->load->view('settings/select-customer');
}
public function goods_batch() {
$this->load->view('settings/goods-batch');
}
public function addedServiceList() {
$this->load->view('settings/addedServiceList');
}
public function assistingProp_batch() {
$this->load->view('settings/assistingProp-batch');
}
public function assistingPropGroupManage() {
$this->load->view('settings/assistingPropGroupManage');
}
public function storage_batch() {
$this->load->view('settings/storage-batch');
}
public function saler_batch() {
$this->load->view('settings/saler-batch');
}
public function customer_batch() {
$this->load->view('settings/customer-batch');
}
public function supplier_batch() {
$this->load->view('settings/supplier-batch');
}
public function settlementAccount_batch() {
$this->load->view('settings/settlementAccount-batch');
}
public function print_templates() {
$this->load->view('settings/print-templates');
}
public function print_templates_manage() {
$this->load->view('settings/print-templates-manage');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

View File

@@ -0,0 +1,37 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Storage extends CI_Controller {
public function __construct(){
parent::__construct();
$this->common_model->checkpurview();
}
public function other_search() {
$this->load->view('storage/other-search');
}
public function inventory() {
$this->common_model->checkpurview(11);
$this->load->view('storage/inventory');
}
public function transfers_search () {
$this->load->view('storage/transfers-search');
}
public function import () {
$this->load->view('storage/import');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */