Example #1
0
 function insertBankZhuruAccount($jine, $accountid, $memo, $inouttype)
 {
     $billid = returnAutoIncrement("billid", "bankzhuru");
     if ($inouttype == 23) {
         $jine = -$jine;
     }
     $sql = "insert into bankzhuru (billid,jine,accountid,memo,userid,opertime,inouttype) values({$billid},{$jine},{$accountid},'{$memo}','" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "','{$inouttype}')";
     $this->db->Execute($sql);
     $oldjine = returntablefield("bank", "rowid", $accountid, "jine");
     $sql = "update bank set jine=jine+(" . $jine . ") where rowid={$accountid}";
     $this->db->Execute($sql);
     $accesstype = returntablefield("accesstype", "id", $inouttype, "name");
     $sql = "insert into accessbank (bankid,oldjine,jine,opertype,guanlianbillid,createman,createtime) values ({$accountid},{$oldjine}," . $jine . ",'{$accesstype}','{$billid},','" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "')";
     $this->db->Execute($sql);
 }
 $id = $rs_a[0]['max'] + 1;
 $sql = "insert into exchange(rowid,customid,prodid,integral,createtime,createman,prodname,xinghao,guige,exchangenum,stockid,beizhu) value({$id}," . $_POST[customid] . ",'" . $_POST[prodid] . "'," . $_POST[integral] . ",'" . date("Y-m-d H:i:s") . "','" . $_SESSION[LOGIN_USER_ID] . "','" . $productinfo[0] . "','" . $productinfo[1] . "','" . $productinfo[2] . "'," . intval($_POST[exchangenum]) . ",'" . $_POST[stockid] . "','" . $_POST[beizhu] . "')";
 $db->Execute($sql);
 // 更新积分
 $sql = "update customer set integral=integral-" . intval($_POST[integral]) . " where ROWID=" . $_POST[customid];
 $db->Execute($sql);
 //		// 添加费用
 //		$feiyongbillid = returnAutoIncrementUnitBillid("feiyongbillid");
 //		$sql="insert into feiyongrecord (billid,typeid,jine,accountid,chanshengdate,createman,createtime,kind) values($feiyongbillid,32,$feiyong,1,'".date("Y-m-d")."','".$_SESSION[LOGIN_USER_ID]."','".date("Y-m-d H:i:s")."',-1)";
 //		$this->db->Execute($sql);
 // 创建出库
 // 更新库存
 $sql = "update store set num=num-" . intval($_POST[exchangenum]) . " where prodid='" . $_POST[prodid] . "' and storeid='" . $_POST[stockid] . "'";
 $db->Execute($sql);
 // 添加出库单
 $chukubillid = returnAutoIncrement("billid", "stockoutmain");
 //插入新出库单
 $sql = "insert into stockoutmain (billid,zhuti,storeid,createman,createtime,dingdanbillid,state,totalnum,totalmoney,outdate,outtype,outstoreshenhe) values(" . $chukubillid . ",'积分兑换-" . $chukubillid . "'," . $_POST[stockid] . ",'" . $_SESSION[LOGIN_USER_ID] . "','" . date("Y-m-d H:i:s") . "'," . $id . ",'已出库'," . intval($_POST[exchangenum]) . ",0,'" . date("Y-m-d H:i:s") . "','积分兑换出库','" . $_SESSION[LOGIN_USER_ID] . "')";
 $db->Execute($sql);
 //添加出库明细
 $sql = "select max(id) as max from stockoutmain_detail";
 $rs = $db->Execute($sql);
 $rs_a = $rs->GetArray();
 $insertid = $rs_a[0][max] + 1;
 $sql = "insert into stockoutmain_detail(id,prodid,prodname,prodxinghao,prodguige,proddanwei,price,zhekou,num,beizhu,mainrowid,jine,avgprice,lirun) value({$insertid},'" . $_POST[prodid] . "','" . $productinfo[0] . "','" . $productinfo[1] . "','" . $productinfo[2] . "','',0,0," . intval($_POST[exchangenum]) . ",'',{$chukubillid},0,{$avgprice}" . "," . -$avgprice * intval($_POST[exchangenum]) . ")";
 $db->Execute($sql);
 if ($db->HasFailedTrans()) {
     print "<script language=javascript>alert('错误:" . str_replace("'", "\\'", $db->ErrorMsg()) . "');window.history.back(-1);</script>";
     exit;
 }
 $db->CompleteTrans();
            $endtimenode->appendChild($doc->createTextNode(substr($rs_a[$i]['endtime'], 0, 16)));
            $contentnode->appendChild($doc->createTextNode(iconv("GBK", "UTF-8", cutStr($rs_a[$i]['content'], 10))));
            $resultnode->appendChild($doc->createTextNode($rs_a[$i]['result']));
        }
    }
    echo $doc->saveXML();
    exit;
}
if ($_GET['action'] == "add_default_data") {
    require_once "../Framework/uploadFile.php";
    uploadFile();
    $nextcontent = $_POST["nextcontent"];
    $nexttime = $_POST["nexttime"];
    $zhuti = $_POST['mainrowid_ID'];
    $db->StartTrans();
    $maxid = returnAutoIncrement("id", "workplanmain_detail");
    $sql = "insert into workplanmain_detail values({$maxid}," . $_POST['mainrowid'] . ",'" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "','" . $_POST['begintime'] . "','" . $_POST['endtime'] . "','" . htmlspecialchars($_POST['content']) . "','" . $_POST['result'] . "',";
    if ($nexttime == '') {
        $sql .= "null,'";
    } else {
        $sql .= "'" . $nexttime . "','";
    }
    $sql .= htmlspecialchars($nextcontent) . "','" . $_POST['fujian'] . "')";
    $db->Execute($sql);
    updateWorkplanmain($_POST['mainrowid']);
    if ($nextcontent != "" && $_POST["nexttime"] != '') {
        $url = '../CRM/workplanmain_newai.php?' . base64_encode('action=view_default&id=' . $_POST['mainrowid']);
        newMessage($_SESSION['LOGIN_USER_ID'], $zhuti . "-" . $nextcontent, '工作任务', $url, $_POST['mainrowid'], $_POST['nexttime']);
        $EndTime = strtotime("{$nexttime} +1 hour");
        $EndTime = date("Y-m-d H:i:s", $EndTime);
        $url = "../" . $url;
function SaveAll()
{
    global $db;
    global $rowid;
    global $tablename;
    $sql = "select count(*) as allcount,sum(num*price*zhekou) as allmoney from " . $tablename . " where mainrowid=" . $rowid;
    $rs = $db->Execute($sql);
    $rs_a = $rs->GetArray();
    $allcount = $rs_a[0]['allcount'];
    $allmoney = round($rs_a[0]['allmoney'], 2);
    if ($tablename == "customerproduct_detail") {
        $sql = "update customerproduct set 金额=" . $allmoney . " where ROWID=" . $rowid;
        $db->Execute($sql);
        $sql = "update customerproduct_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
        $db->Execute($sql);
    } else {
        if ($tablename == "sellplanmain_detail") {
            $sql = "update sellplanmain set totalmoney=" . $allmoney . " where billid=" . $rowid;
            $db->Execute($sql);
            $sql = "update sellplanmain_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
            $db->Execute($sql);
        } else {
            if ($tablename == "v_sellonedetail") {
                $sql = "update sellplanmain set totalmoney=" . $allmoney . " where billid=" . $rowid;
                $db->Execute($sql);
                $sql = "update sellplanmain_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
                $db->Execute($sql);
            } else {
                if ($tablename == "buyplanmain_detail") {
                    $sql = "select count(*) as allcount,sum(num*price*zhekou) as allmoney from {$tablename} where mainrowid=" . $rowid;
                    $rs = $db->Execute($sql);
                    $rs_a = $rs->GetArray();
                    $allcount = $rs_a[0]['allcount'];
                    $allmoney = round($rs_a[0]['allmoney'], 2);
                    $totalmoney = returntablefield("buyplanmain", "billid", $_GET['rowid'], "totalmoney");
                    if ($totalmoney != $allmoney) {
                        print "明细金额合计必须为:" . $totalmoney;
                        exit;
                    }
                    $state = 1;
                    if ($allcount > 0) {
                        $state = 2;
                    }
                    $sql = "update buyplanmain set totalmoney=" . $allmoney . ",state={$state} where billid='" . $rowid . "'";
                    $db->Execute($sql);
                    $sql = "update buyplanmain_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
                    $db->Execute($sql);
                } else {
                    if ($tablename == "stockchangemain_detail") {
                        $sql = "update stockchangemain set totalmoney=" . $allmoney . ",state=2 where billid=" . $rowid;
                        $db->Execute($sql);
                        $sql = "update stockchangemain_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
                        $db->Execute($sql);
                    } else {
                        if ($tablename == "storecheck_detail") {
                            //开启事务
                            try {
                                $db->StartTrans();
                                //$db->debug=true;
                                $Store = new Store($db);
                                $Store->insertStoreCheck($rowid, $allmoney);
                                //是否事务出现错误
                                if ($db->HasFailedTrans()) {
                                    print $db->ErrorMsg();
                                }
                                $db->CompleteTrans();
                            } catch (Exception $e) {
                                print $e->getMessage();
                                exit;
                            }
                        } else {
                            if ($tablename == "productzuzhuang_detail") {
                                //开启事务
                                try {
                                    $db->StartTrans();
                                    $storeid = returntablefield("productzuzhuang", "billid", $rowid, "outstoreid");
                                    $sql = "select * from productzuzhuang_detail where mainrowid=" . $rowid;
                                    $rs = $db->Execute($sql);
                                    $rs_detail = $rs->GetArray();
                                    for ($i = 0; $i < sizeof($rs_detail); $i++) {
                                        $sql = "select * from store where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
                                        $rs = $db->Execute($sql);
                                        $rs_store = $rs->GetArray();
                                        $kucun = 0;
                                        if (sizeof($rs_store) > 0) {
                                            $kucun = $rs_store[0]['num'];
                                        }
                                        if ($kucun - $rs_detail[$i]['num'] < 0) {
                                            throw new Exception("编号为:" . $rs_detail[$i]['prodid'] . " 的产品库存不足");
                                        }
                                        if (sizeof($rs_store) == 0) {
                                            $maxid = returnAutoIncrement("id", "store");
                                            $sql = "insert into store (id,prodid,storeid,num,price) values({$maxid},'" . $rs_detail[$i]['prodid'] . "'," . $storeid . "," . $rs_detail[$i]['num'] . "," . $rs_detail[$i]['price'] . ")";
                                            $db->Execute($sql);
                                        } else {
                                            $junjia = $rs_store[0]['price'];
                                            $sql = "update store set num=num-(" . $rs_detail[$i]['num'] . ") where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
                                            $db->Execute($sql);
                                            $sql = "update productzuzhuang_detail set price=" . $junjia . " where id=" . $rs_detail[$i]['id'];
                                            $db->Execute($sql);
                                        }
                                    }
                                    $sql = "delete from store where num=0";
                                    $db->Execute($sql);
                                    $sql = "update productzuzhuang set totalmoney=" . $allmoney . ",state=2,outshenhetime='" . date("Y-m-d H:i:s") . "',outstoreshenhe='" . $_SESSION['LOGIN_USER_ID'] . "' where billid=" . $rowid;
                                    $db->Execute($sql);
                                    $sql = "update productzuzhuang_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
                                    $db->Execute($sql);
                                    //是否事务出现错误
                                    $db->CompleteTrans();
                                } catch (Exception $e) {
                                    print $e->getMessage();
                                    exit;
                                }
                            } else {
                                if ($tablename == "productzuzhuang2_detail") {
                                    $totalmoney = returntablefield("productzuzhuang", "billid", $_GET['rowid'], "totalmoney");
                                    if ($totalmoney != $allmoney) {
                                        print "入库金额合计必须为:" . $totalmoney;
                                        exit;
                                    }
                                    //开启事务
                                    try {
                                        $db->StartTrans();
                                        $storeid = returntablefield("productzuzhuang", "billid", $rowid, "instoreid");
                                        $sql = "select * from productzuzhuang2_detail where mainrowid=" . $rowid;
                                        $rs = $db->Execute($sql);
                                        $rs_detail = $rs->GetArray();
                                        for ($i = 0; $i < sizeof($rs_detail); $i++) {
                                            $sql = "select * from store where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
                                            $rs = $db->Execute($sql);
                                            $rs_store = $rs->GetArray();
                                            $kucun = 0;
                                            if (sizeof($rs_store) > 0) {
                                                $kucun = $rs_store[0]['num'];
                                            }
                                            if ($kucun + $rs_detail[$i]['num'] < 0) {
                                                throw new Exception("编号为:" . $rs_detail[$i]['prodid'] . " 的产品库存不足");
                                            }
                                            if (sizeof($rs_store) == 0) {
                                                $maxid = returnAutoIncrement("id", "store");
                                                $sql = "insert into store (id,prodid,storeid,num,price) values({$maxid},'" . $rs_detail[$i]['prodid'] . "'," . $storeid . "," . $rs_detail[$i]['num'] . "," . $rs_detail[$i]['price'] . ")";
                                                $db->Execute($sql);
                                            } else {
                                                if ($kucun + $rs_detail[$i]['num'] != 0) {
                                                    $junjia = round(($rs_store[0]['price'] * $kucun + $rs_detail[$i]['price'] * $rs_detail[$i]['num']) / ($kucun + $rs_detail[$i]['num']), 2);
                                                } else {
                                                    if ($rs_store[0]['price'] * $kucun + $rs_detail[$i]['price'] * $rs_detail[$i]['num'] == 0) {
                                                        $junjia = 0;
                                                    } else {
                                                        throw new Exception("编号为:" . $rs_detail[$i]['prodid'] . " 的产品库存数量为零,但金额不为零,无法计算加权平均价");
                                                    }
                                                }
                                                $sql = "update store set num=num+(" . $rs_detail[$i]['num'] . "),price=" . $junjia . " where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
                                                $db->Execute($sql);
                                            }
                                        }
                                        $sql = "delete from store where num=0";
                                        $db->Execute($sql);
                                        $sql = "update productzuzhuang set state=3,inshenhetime='" . date("Y-m-d H:i:s") . "',instoreshenhe='" . $_SESSION['LOGIN_USER_ID'] . "' where billid=" . $rowid;
                                        $db->Execute($sql);
                                        $sql = "update productzuzhuang2_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
                                        $db->Execute($sql);
                                        //是否事务出现错误
                                        $db->CompleteTrans();
                                    } catch (Exception $e) {
                                        print $e->getMessage();
                                        exit;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    print "Save";
    exit;
}
 for ($i = 0; $i < sizeof($rs_detail); $i++) {
     $num = intval($_POST["num_" . $rs_detail[$i]['id']]);
     $price = floatvalue($_POST["price_" . $rs_detail[$i]['id']]);
     $jine = floatvalue($_POST["jine_" . $rs_detail[$i]['id']]);
     $memo = $_POST["beizhu_" . $rs_detail[$i]['id']];
     //插入库存
     if ($num != 0) {
         $sql = "select max(id) as maxid from stockinmain_detail";
         $rs = $db->Execute($sql);
         $rs_a = $rs->GetArray();
         $maxid = $rs_a[0]['maxid'] + 1;
         $sql = "insert into stockinmain_detail (id,prodid,prodname,prodguige,prodxinghao,proddanwei,price,zhekou,num,mainrowid,jine) values('{$maxid}','" . $rs_detail[$i]['prodid'] . "','" . $rs_detail[$i]['prodname'] . "','" . $rs_detail[$i]['guige'] . "','" . $rs_detail[$i]['xinghao'] . "','" . $rs_detail[$i]['danwei'] . "'," . $price . ",1," . $num . "," . $billid . "," . $jine . ")";
         $db->Execute($sql);
         $sql = "update store_init set num={$num},price={$price},jine={$jine},memo='{$memo}' where id=" . $rs_detail[$i]['id'];
         $db->Execute($sql);
         $maxid = returnAutoIncrement("id", "store");
         $sql = "insert into store (id,prodid,num,price,storeid,memo) values({$maxid},'" . $rs_detail[$i]['prodid'] . "',{$num},{$price},{$storeid},'{$memo}')";
         $db->Execute($sql);
     }
 }
 $sql = "delete from store_init where storeid=" . $storeid . " and flag=0 and num=0";
 $db->Execute($sql);
 //更新初始化状态
 $sql = "update store_init set flag=1 where storeid=" . $storeid . " and flag=0";
 $db->Execute($sql);
 //是否事务出现错误
 if ($db->HasFailedTrans()) {
     print "<script language=javascript>alert('错误:" . str_replace("'", "\\'", $db->ErrorMsg()) . "');window.history.back(-1);</script>";
 } else {
     page_css("库存初始化");
     $return = FormPageAction("action", "init_default");
Example #6
0
 function insertStoreCheck($rowid, $allmoney)
 {
     $storeid = returntablefield("storecheck", "billid", $rowid, "storeid");
     $sql = "select * from storecheck_detail where mainrowid=" . $rowid;
     $rs = $this->db->Execute($sql);
     $rs_detail = $rs->GetArray();
     for ($i = 0; $i < sizeof($rs_detail); $i++) {
         $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 + $rs_detail[$i]['num'] < 0) {
             throw new Exception("编号为:" . $rs_detail[$i]['prodid'] . " 的产品库存不足");
         }
         if (sizeof($rs_store) == 0) {
             $maxid = returnAutoIncrement("id", "store");
             $sql = "insert into store (id,prodid,storeid,num,price) values({$maxid},'" . $rs_detail[$i]['prodid'] . "'," . $storeid . "," . $rs_detail[$i]['num'] . "," . $rs_detail[$i]['price'] . ")";
             $this->db->Execute($sql);
         } else {
             $junjia = $rs_store[0]['price'];
             $sql = "update store set num=num+(" . $rs_detail[$i]['num'] . ") where storeid=" . $storeid . " and prodid='" . $rs_detail[$i]['prodid'] . "'";
             $this->db->Execute($sql);
             $sql = "update storecheck_detail set price=" . $junjia . " where id=" . $rs_detail[$i]['id'];
             $this->db->Execute($sql);
         }
     }
     $sql = "delete from store where num=0";
     $this->db->Execute($sql);
     $sql = "update storecheck set totalmoney=" . $allmoney . ",state='盘点结束' where billid=" . $rowid;
     $this->db->Execute($sql);
     $sql = "update storecheck_detail set jine=round(price*zhekou*num,2) where mainrowid=" . $rowid;
     $this->db->Execute($sql);
 }
function addProduct($oldproductid, $supplyid)
{
    global $db;
    global $rowid;
    global $tablename;
    global $storeid;
    try {
        //是否已存在
        $sql = "select * from {$tablename} where oldprodid='{$oldproductid}' and mainrowid='{$rowid}'";
        $rs = $db->Execute($sql);
        $rs_a = $rs->GetArray();
        if (count($rs_a) > 0) {
            throw new Exception("采购单中原厂码为 {$oldproductid} 的产品已存在");
        }
        $sql = "select * from product where oldproductid='{$oldproductid}' and supplyid={$supplyid}";
        $rs = $db->Execute($sql);
        $rs_a = $rs->GetArray();
        if (count($rs_a) != 0) {
            $productid = $rs_a[0]['productid'];
            $prodguige = $rs_a[0]['standard'];
            $prodxinghao = $rs_a[0]['mode'];
            $proddanwei = $rs_a[0]['measureid'];
            $id = returnAutoIncrement("id", $tablename);
            $lastprice = getlastprice($productid);
            $prodname = $rs_a[0]['productname'];
            $sql = "insert into {$tablename}(id,oldprodid,prodid,prodguige,prodxinghao,proddanwei,lastprice,prodname,mainrowid,zhekou) values({$id},'{$oldproductid}','{$productid}','{$prodguige}','{$prodxinghao}','{$proddanwei}',{$lastprice},'{$prodname}',{$rowid},1)";
            $db->Execute($sql);
        } else {
            print "add|{$oldproductid}|{$supplyid}";
            exit;
        }
    } catch (Exception $e) {
        print $e->getMessage();
        exit;
    }
}
if ($_GET['action'] == "foujue") {
    page_css();
    $sql = "update customerproduct set `是否审核`=3,`审核时间`='" . date("Y-m-d H:i:s") . "',审核人='" . $_SESSION['LOGIN_USER_ID'] . "' where ROWID=" . $_GET['ROWID'];
    $db->Execute($sql);
    $billinfo = returntablefield("customerproduct", "ROWID", $_GET['ROWID'], "主题,创建人");
    newMessage($billinfo['创建人'], $billinfo['主题'] . '--被否决!', '报价单审核', '../JXC/customerproduct_newai.php?' . base64_encode('action=view_default&ROWID=' . $_GET['ROWID']), $_GET['ROWID']);
    $return = FormPageAction("action", "init_default");
    print_infor("已否决!", 'trip', "location='?{$return}'", "?{$return}", 0);
    exit;
}
if ($_GET['action'] == "edit_default2") {
    $rowid = $_GET['ROWID'];
    //开启事务
    $db->StartTrans();
    //获取订单号
    $billid = returnAutoIncrement("billid", "sellplanmain");
    $sql = "select * from customerproduct where ROWID=" . $rowid;
    $rs = $db->Execute($sql);
    $rs_a = $rs->GetArray();
    if (count($rs_a) == 0) {
        throw new Exception("找不到此报价单");
    }
    $zhuti = $rs_a[0]['主题'];
    $customerid = $rs_a[0]['客户'];
    $jieshouren = $rs_a[0]['接收人'];
    $address = returntablefield("linkman", "rowid", $jieshouren, "address");
    $tel = returntablefield("linkman", "rowid", $jieshouren, "phone");
    $jine = $rs_a[0]['金额'];
    $chance = $rs_a[0]['销售机会'];
    $beizhu = "交付说明:" . $rs_a[0]['交付说明'] . " 付款说明:" . $rs_a[0]['付款说明'] . " 包装运输说明:" . $rs_a[0]['包装运输说明'] . " 备注:" . $rs_a[0]['备注'];
    //插入新订单
 $createman = $_SESSION['LOGIN_USER_ID'];
 $createtime = date('Y-m-d H:i:m');
 $totalmoney = floatval($_POST['totalmoney']);
 $oddment = floatval($_POST['oddment']);
 $realmoney = floatval($_POST['paymoney']);
 $accountid = $_POST['accountid'];
 try {
     if ($totalmoney > 0 && $totalmoney < $oddment + $realmoney) {
         throw new Exception("去零加已付金额不能大于总金额 {$totalmoney}");
     }
     if ($totalmoney < 0 && $totalmoney > $oddment + $realmoney) {
         throw new Exception("去零加已付金额不能小于总金额 {$totalmoney}");
     }
     //开启事务
     $db->StartTrans();
     $billid = returnAutoIncrement("billid", "buyplanmain");
     //插入新纪录
     $sql = "insert into buyplanmain (billid,zhuti,supplyid,linkman,caigoudate,daohuodate,createman,createtime,totalmoney,\n\t\toddment,paymoney,accountid,guanliandingdan,guanliankehu,beizhu,user_flag) values({$billid},'" . $_POST['zhuti'] . "','{$supplyid}',\n\t\t'{$linkman}','{$caigoudate}','{$daohuodate}','{$createman}','{$createtime}',{$totalmoney},0,0,{$accountid},\n\t\t'" . $_POST['guanliandingdan'] . "','" . $_POST['guanliankehu'] . "','" . $_POST['beizhu'] . "',1)";
     $db->Execute($sql);
     $CaiWu = new CaiWu($db);
     if ($realmoney != 0) {
         $CaiWu->insertFukuanReocord($supplyid, $billid, $realmoney, $accountid, $createman, '货款支付', $oddment, '', '', '');
     }
     //是否事务出现错误
     page_css();
     $db->CompleteTrans();
     if ($db->HasFailedTrans()) {
         throw new Exception($db->ErrorMsg());
     } else {
         $return = FormPageAction("action", "init_default");
         print_infor("采购单已生成,请录入明细", 'trip', "location='?{$return}'", "?{$return}", 0);
 $caigoudate = $_POST['caigoudate'];
 $daohuodate = $_POST['daohuodate'];
 $createman = $_SESSION['LOGIN_USER_ID'];
 $createtime = date('Y-m-d H:i:m');
 $state = 0;
 $totalmoney = floatval($_POST['totalmoney']);
 $oddment = floatval($_POST['oddment']);
 $realmoney = floatval($_POST['realmoney']);
 $accountid = $_POST['accountid'];
 try {
     if ($totalmoney < $oddment + $realmoney) {
         throw new Exception("去零加已付金额不能大于总金额 {$totalmoney}");
     }
     //开启事务
     $db->StartTrans();
     $billid = returnAutoIncrement("billid", "caigouorder");
     //插入新纪录
     $sql = "insert into caigouorder values({$billid},'{$supplyid}','{$linkman}','{$caigoudate}','{$daohuodate}','{$createman}','{$createtime}',\n\t\t\t{$totalmoney},{$oddment},{$realmoney},{$accountid},{$state})";
     $db->Execute($sql);
     $CaiWu = new CaiWu($db);
     if ($accountid > 0) {
         $CaiWu->operateAccount($accountid, $realmoney, '采购订金', $billid);
     } else {
         $CaiWu->operatePrepay($supplyid, $realmoney, '采购订金', $billid);
     }
     if ($oddment != 0) {
         $CaiWu->insertFeiYong(1, $oddment, $accountid, $_SESSION['LOGIN_USER_ID'], 1, $billid, '');
     }
     //是否事务出现错误
     if ($db->HasFailedTrans()) {
         print "<script language=javascript>alert('错误:" . str_replace("'", "\\'", $db->ErrorMsg()) . "');window.history.back(-1);</script>";