Esempio n. 1
0
 function confirmChuKu($chukubillid)
 {
     $stockoutinfo = returntablefield("stockoutmain", "billid", $chukubillid, "dingdanbillid,storeid,state,outtype");
     $dingdanbillid = $stockoutinfo['dingdanbillid'];
     $storeid = $stockoutinfo['storeid'];
     $outtype = $stockoutinfo['outtype'];
     $sql = "select * from stockoutmain_detail where mainrowid=" . $chukubillid;
     $rs = $this->db->Execute($sql);
     $rs_detail = $rs->GetArray();
     for ($i = 0; $i < sizeof($rs_detail); $i++) {
         if ($outtype == '销售出库') {
             $num = $_POST["recnum_" . $rs_detail[$i]['id']];
         } else {
             $num = $rs_detail[$i]['num'];
         }
         if ($num > $rs_detail[$i]['num']) {
             throw new Exception("产品【" . $rs_detail[$i]['prodid'] . "】的出库数不能大于" . $rs_detail[$i]['num']);
         }
         //扣减库存
         $tmpArray = returntablefield("product", "productid", $rs_detail[$i]['prodid'], "ifkucun,hascolor");
         $ifkucun = $tmpArray['ifkucun'];
         $hascolor = $tmpArray['hascolor'];
         if ($ifkucun == "是" && $num != 0) {
             $sql = "select * from store where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
             $rs = $this->db->Execute($sql);
             $rs_store = $rs->GetArray();
             $kucun = 0;
             if (sizeof($rs_store) > 0) {
                 $kucun = $rs_store[0]['num'];
             }
             if ($kucun - $num < 0) {
                 throw new Exception("产品【" . $rs_detail[$i]['prodname'] . "】的库存不足");
             }
             $chengben = $rs_store[0]['price'];
             $sql = "update store set num=num-(" . $num . ") where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
             $this->db->Execute($sql);
             if ($hascolor == "是") {
                 $sql = "select * from stockoutmain_detail_color where id=" . $rs_detail[$i]['id'];
                 $rs = $this->db->Execute($sql);
                 $rs_color = $rs->GetArray();
                 foreach ($rs_color as $row) {
                     $kucun = returntablefield("store_color", "id", $rs_store[0]['id'], "num", "color", $row['color']);
                     if ($kucun < $row['num']) {
                         throw new Exception($rs_detail[$i]['prodid'] . " 某个颜色的库存不足!");
                     }
                     $sql = "update store_color set num=num-(" . $row['num'] . ") where id=" . $rs_store[0]['id'] . " and color='" . $row['color'] . "'";
                     $this->db->Execute($sql);
                 }
             }
         } else {
             $chengben = 0;
         }
         //更新出库明细
         if ($num != 0) {
             $sql = "update stockoutmain_detail set num={$num},avgprice={$chengben},lirun=round((price*zhekou-{$chengben})*{$num},2) where id=" . $rs_detail[$i]['id'];
         } else {
             $sql = "delete from stockoutmain_detail where id=" . $rs_detail[$i]['id'];
         }
         $this->db->Execute($sql);
         if ($outtype == '销售出库') {
             //取得利润
             $sql = "select lirun from stockoutmain_detail where id=" . $rs_detail[$i]['id'];
             $rs = $this->db->Execute($sql);
             $rs_store = $rs->GetArray();
             $lirun = 0;
             if (sizeof($rs_store) > 0) {
                 $lirun = $rs_store[0]['lirun'];
             }
             //更新订单明细
             $sql = "update sellplanmain_detail set chukunum=chukunum+{$num},lirun=lirun+{$lirun} where mainrowid={$dingdanbillid} and prodid='" . $rs_detail[$i]['prodid'] . "'";
             $this->db->Execute($sql);
         }
     }
     $sql = "delete from store where num=0";
     $this->db->Execute($sql);
     $sql = "select sum(num) as allnum,sum(price*zhekou*num) as allmoney from stockoutmain_detail where mainrowid=" . $chukubillid;
     $rs = $this->db->Execute($sql);
     $rs_all = $rs->GetArray();
     $allnum = $rs_all[0]['allnum'];
     $allmoney = round(floatval($rs_all[0]['allmoney']), 2);
     //改变出库单状态
     $sql = "update stockoutmain set state='已出库',totalnum={$allnum},totalmoney={$allmoney},outstoreshenhe='" . $_SESSION['LOGIN_USER_ID'] . "',outdate='" . date("Y-m-d H:i:s") . "' where billid=" . $chukubillid;
     $this->db->Execute($sql);
     if ($outtype == '返厂出库') {
         //利润变为收益或费用
         $sql = "select sum(lirun) from stockoutmain_detail where mainrowid=" . $dingdanbillid;
         $rs = $this->db->Execute($sql);
         $rs_store = $rs->GetArray();
         $lirun = $rs_store[0]['lirun'];
         if ($lirun != 0) {
             $kind = 1;
             $feiyongname = '返货收益';
             $jine = -$lirun;
             if ($lirun > 0) {
                 $kind = -1;
                 $feiyongname = '返货亏损';
                 $jine = $lirun;
             }
             $feiyongbillid = returnAutoIncrementUnitBillid("feiyongbillid");
             $feiyongtype = returntablefield("feiyongtype", "typename", $feiyongname, "id");
             $sql = "insert into feiyongrecord (billid,typeid,jine,accountid,chanshengdate,createman,createtime,kind) values({$feiyongbillid},{$feiyongtype},{$jine},'','" . date("Y-m-d") . "','" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "',{$kind})";
             $this->db->Execute($sql);
         }
         $this->UpdateCaigouState($dingdanbillid);
     }
 }
Esempio n. 2
0
 function operatePrepay($supplyid, $totalmoney, $opertype, $billid)
 {
     $yue = returntablefield("supply", "ROWID", $supplyid, "yufukuan");
     if ($yue < $totalmoney) {
         throw new Exception("预付款余额不足以支付 {$totalmoney}");
     }
     $sql = "update supply set yufukuan=yufukuan-{$totalmoney} where rowid={$supplyid}";
     $this->db->Execute($sql);
     $id = returnAutoIncrementUnitBillid("prepaybillid");
     $sql = "insert into accessprepay (id,supplyid,curchuzhi,jine,opertype,guanlianbillid,createman,createtime) values(\n\t\t" . $id . "," . $supplyid . "," . $yue . "," . -$totalmoney . ",'{$opertype}'," . $billid . ",'" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "')";
     $this->db->Execute($sql);
 }
*/
require_once "lib.inc.php";
$sessionkey = returnsesskey();
$GLOBAL_SESSION = returnsession();
$SUNSHINE_USER_NAME = $_SESSION['SUNSHINE_USER_NAME'];
validateMenuPriv("库存盘点单");
//只有此仓库管理员才能创建盘点单
if ($_GET['action'] == "add_default_data") {
    $storeid = $_POST['storeid'];
    $userid = returntablefield("stock", "rowid", $storeid, "user_id");
    $useridArray = explode(",", $userid);
    if (!in_array($_SESSION['LOGIN_USER_ID'], $useridArray)) {
        print "<script language=javascript>alert('错误:只有此仓库的库管有权限创建盘点单');window.history.back(-1);</script>";
        exit;
    }
    $_POST['billid'] = returnAutoIncrementUnitBillid("storecheckbillid");
}
if ($_GET['action'] == "edit_default2") {
    print "<script>location='DataQuery/productFrame.php?tablename=storecheck_detail&deelname=库存盘点差异&rowid=" . $_GET['billid'] . "'</script>";
    exit;
}
//撤销盘点单
if ($_GET['action'] == "delete_array") {
    $selectid = $_GET['selectid'];
    $selectid = explode(",", $selectid);
    try {
        //开启事务
        $Store = new Store($db);
        $db->StartTrans();
        for ($i = 0; $i < sizeof($selectid); $i++) {
            if ($selectid[$i] != "") {