初始版本
This commit is contained in:
126
application/controllers/scm/backup.php
Executable file
126
application/controllers/scm/backup.php
Executable 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 */
|
||||
1147
application/controllers/scm/invOi.php
Executable file
1147
application/controllers/scm/invOi.php
Executable file
File diff suppressed because it is too large
Load Diff
770
application/controllers/scm/invPu.php
Executable file
770
application/controllers/scm/invPu.php
Executable 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 */
|
||||
913
application/controllers/scm/invSa.php
Executable file
913
application/controllers/scm/invSa.php
Executable 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 */
|
||||
593
application/controllers/scm/invSo.php
Executable file
593
application/controllers/scm/invSo.php
Executable 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 */
|
||||
368
application/controllers/scm/invTf.php
Executable file
368
application/controllers/scm/invTf.php
Executable 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 */
|
||||
526
application/controllers/scm/ori.php
Executable file
526
application/controllers/scm/ori.php
Executable 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 */
|
||||
|
||||
366
application/controllers/scm/payment.php
Executable file
366
application/controllers/scm/payment.php
Executable 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 */
|
||||
31
application/controllers/scm/pdImport.php
Executable file
31
application/controllers/scm/pdImport.php
Executable 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 */
|
||||
387
application/controllers/scm/receipt.php
Executable file
387
application/controllers/scm/receipt.php
Executable 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 */
|
||||
Reference in New Issue
Block a user