⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acc_gcbrzw.php

📁 自己实现一个实用的商店应用系统
💻 PHP
字号:
<?php
////////////////////////////////////////////////////////
// Author by Shuweich
// Date : 2007.11.18
// 建站支持: http://www.shuweich.net
// 作者: Shuweich
// QQ: 1502384
// ICQ: 190492112
// MSN: shuweich@hotmail.com
// E-mail: root@shuweich.net
// E-mail: shuweich@163.com
////////////////////////////////////////////////////////
// 模块管理 by txdyz
// For 轧帐
////////////////////////////////////////////////////////
include_once '../../mainfile.php';
include_once 'head_inc.php';
include_once 'head_win.php';

## TRUNCATE TABLE Table_Name  // 清空表文件
## 检查库存商品信息,若空则从公用商品信息表引入商品信息
$Squ = "select bybz from ".$xoopsDB->prefix("market_store")." where store_id='".$_REQUEST['s_id0']."' limit 0,1";
$ssp0 = $xoopsDB->fetchrow( $xoopsDB->query($Squ) );
$S_ID = substr($ssp0[0],23,1)=='7'?'696':$_REQUEST['s_id0'];

$que = "select sp_id from ".$xoopsDB->prefix("market_spkc")." where store_id='".$_REQUEST['s_id0']."'";
$rnm = $xoopsDB->getRowsNum( $xoopsDB->query($que) );
if ( $rnm < 1 ) {
  $del = "delete from ".$xoopsDB->prefix("market_spkc");
  $del.= " where store_id='".$_REQUEST['s_id0']."'";
  $de0 = $xoopsDB->queryF($del);
  $ins = "insert into ".$xoopsDB->prefix("market_spkc")." (sp_id,store_id,sp_code,sp_barcode) ";
  $ins.= " select 0,'".$_REQUEST['s_id0']."',sp_code,sp_barcode from ".$xoopsDB->prefix("market_spinfo");
  $ins.= " where store_id='".$S_ID."'";
  $in0 = $xoopsDB->queryF($ins);
}

## 提取记帐数据
$que  = "select sp_code,sp_barcode,zy,sum(xssl) hjsl,date_q from ";
$que .= $xoopsDB->prefix("market_mdseri");
$que .= " where store_id='".$_REQUEST['s_id0']."' and sp_code!='' and shbz!='2'";
$que .= " group by zy,sp_code";
$res = $xoopsDB->query($que);
## 商品库存明细及商品库存
while ( $row = $xoopsDB->fetchrow($res) ) {
  ## 借贷方交易分类
  if       ( array_search($row[2],$_Akc) ) {
    $_mx_cols = 'jf';		## 借记库存
    $fse = $row[3];
  } elseif ( array_search($row[2],$_Skc) ) {
    $_mx_cols = 'df';		## 贷记库存
    $fse = 0 - $row[3];
  } else {
    echo "交易未定义!";
    $_mx_cols = 'jd';		## 未知交易,贷记库存
    $fse = 0 - $row[3];
  }
  ## 登记单品库存帐
  ## 若记录不存在,则先插入
  $din = "select store_id,sp_code from  ".$xoopsDB->prefix("market_spkc");
  $din .=" where store_id='".$_REQUEST['s_id0']."' and sp_code='".$row[0]."'";
  $din = $xoopsDB->getRowsNum( $xoopsDB->query($din) );
  if ( $din != 1 ) {
    $del = "delete from ".$xoopsDB->prefix("market_spkc");
    $del.= " where store_id='".$_REQUEST['s_id0']."' and sp_code='".$row[0]."'";
    $de0 = $xoopsDB->queryF($del);
    $ins = "insert into ".$xoopsDB->prefix("market_spkc")." (sp_id,store_id,sp_code,sp_barcode) ";
    $ins.= " select 0,'".$_REQUEST['s_id0']."',sp_code,sp_barcode from ".$xoopsDB->prefix("market_spinfo");
    $ins.= " where store_id='".$S_ID."' and sp_code='".$row[0]."'";
    $in0 = $xoopsDB->queryF($ins);
  }
  ## 库存记帐
  $upd = "update ".$xoopsDB->prefix("market_spkc");
  ## $upd.= " set sp_date=now(),jzzy='".$row[2]."',sp_kc=sp_kc+(".$fse."),rz_user_id='".$xoopsUser->getVar("uid")."' ";
  $upd.= " set sp_date='".$row[4]."',jzzy='".$row[2]."',sp_kc=sp_kc+(".$fse."),rz_user_id='".$xoopsUser->getVar("uid")."' ";
  $upd.= " where store_id='".$_REQUEST['s_id0']."' and sp_code='".$row[0]."'";
  // echo "<hr /> update:".$upd;
  $upd0 = $xoopsDB->queryF($upd);

  ## 登记单品库存明细帐
  $jy0 = "select store_id,sp_code,sp_kc from ".$xoopsDB->prefix("market_spkc")." where store_id='".$_REQUEST['s_id0']."' and sp_code='".$row[0]."'";
  $jy9 = $xoopsDB->fetchrow( $xoopsDB->query($jy0) );
  $ins = "insert into ".$xoopsDB->prefix("market_spkcmx");
  $ins.= "(sp_id,store_id,sp_code,sp_barcode,sp_indate,sp_date,jzzy,".$_mx_cols.",sp_kc,rz_user_id) values (";
  $ins.= "0,";
  $ins.= "'".$_REQUEST['s_id0']."',";
  $ins.= "'".$row[0]."',";
  $ins.= "'".$row[1]."',";
  $ins.= "'".$row[4]."',";
  $ins.= "now(),";
  $ins.= "'".$row[2]."',";
  $ins.= "'".$row[3]."',";
  $ins.= "'".$jy9[2]."',";
  $ins.= $xoopsUser->getVar("uid");
  $ins.= ")";
  // echo "<hr /> insert:".$ins;
  $ins0 = $xoopsDB->queryF($ins);
}

while ( list($dj,$jym)=each($_TXjy) ) {
  ## 登记现金日记总帐
  ## 上次结余
  $_dj = explode(":",$dj);	$_h = $_dj[0];	$_m = $_dj[1];
  $que = "select jy from ".$xoopsDB->prefix("market_cash")." where store_id='".$_REQUEST['s_id0']."'";
  $que .=" order by ca_id desc limit 0,1";
  $zrjy = $xoopsDB->fetchrow( $xoopsDB->query($que) );
  $zrjy[0] = floatval($zrjy[0]);
  ## 今日营业额
  $que = "select sum(spzkj) xsje ";
  $que.= " from ".$xoopsDB->prefix("market_mdseri");
  $que.= " where store_id='".$_REQUEST['s_id0']."' and shbz!='2' and zy in (".$jym.")";
  $yye = $xoopsDB->fetchrow( $xoopsDB->query($que) );
  ## 本次结余
  $yye[0] = floatval($yye[0]);
  if ( $yye[0] === 0.0 ) continue;
  $jrjy = $zrjy[0] + $yye[0];
  $ins = "insert into ".$xoopsDB->prefix("market_cash");
  $ins .=" (ca_id,store_id,ca_date,ca_djh,ca_zy,jf,jy,ca_shbz,jz_user_id) values (";
  $ins .="0,'".$_REQUEST['s_id0']."',now(),'".$_h."','".$_m."',".$yye[0].",".$jrjy.",'0',".$xoopsUser->getVar("uid").")";
  $ins1 = $xoopsDB->queryF($ins);
}

## 将流水帐转移到历史流水帐表中,以备后查
$ins = "insert into ".$xoopsDB->prefix("market_mdseri_history");
$ins.= " select 0,store_id,sdbh,bdxh,date_q,now(),user_card,user_disc,sp_fl,sp_barcode,sp_code,zy,xssl,sj,spzkj,zkl,zke,mle,tach,rz_user_id,shbz,sh_user_id,oth_read from ".$xoopsDB->prefix("market_mdseri");
$ins.= " where store_id='".$_REQUEST['s_id0']."'";
$in0 = $xoopsDB->queryF($ins);

## 清本日流水帐
if ($in0 && $ins0 && $upd0 && $ins1 ) {
  $del = "delete from ".$xoopsDB->prefix("market_mdseri");
  $del.= " where store_id='".$_REQUEST['s_id0']."'";
  $de0 = $xoopsDB->queryF($del);
}
if ( $de0 ) {
  echo "<script language='javascript'><!--\n";
  echo "  alert('轧帐完毕,本店当日流水帐已经汇入历史账中!');\n";
  echo "  window.close();\n";
  echo "</script>\n";
} else {
  $msgg = '';
  if ( !$in0 ) $msgg .= '流水帐转存出错,';
  if ( !$ins0 ) $msgg .= '登记单品库存帐出错,';
  if ( !$upd0 ) $msgg .= '登记单品库存明细帐出错,';
  if ( !$ins1 ) $msgg .= '登记现金日记帐出错,';
  if ( !$de0 ) $msgg .= '清空流水帐出错,';
  $msgg = substr($msgg,0,-1)."!";
  echo "<script language='javascript'><!--\n";
  echo '  alert("轧帐失败:\n'.$msgg.'");';
  echo "\n  window.close();\n";
  echo "</script>\n";
}

include_once '../../footer.php';
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -